📄 ieee80211softmac_assoc.c
字号:
/* * This file contains the softmac's association logic. * * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net> * Joseph Jezak <josejx@gentoo.org> * Larry Finger <Larry.Finger@lwfinger.net> * Danny van Dyk <kugelfang@gentoo.org> * Michael Buesch <mbuesch@freenet.de> * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * The full GNU General Public License is included in this distribution in the * file called COPYING. */#include "ieee80211softmac_priv.h"/* * Overview * * Before you can associate, you have to authenticate. * *//* Sends out an association request to the desired AP */static voidieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net){ unsigned long flags; /* Switch to correct channel for this network */ mac->set_channel(mac->dev, net->channel); /* Send association request */ ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_ASSOC_REQ, 0); dprintk(KERN_INFO PFX "sent association request!\n"); spin_lock_irqsave(&mac->lock, flags); mac->associnfo.associated = 0; /* just to make sure */ /* Set a timer for timeout */ /* FIXME: make timeout configurable */ if (likely(mac->running)) queue_delayed_work(mac->wq, &mac->associnfo.timeout, 5 * HZ); spin_unlock_irqrestore(&mac->lock, flags);}voidieee80211softmac_assoc_timeout(struct work_struct *work){ struct ieee80211softmac_device *mac = container_of(work, struct ieee80211softmac_device, associnfo.timeout.work); struct ieee80211softmac_network *n; mutex_lock(&mac->associnfo.mutex); /* we might race against ieee80211softmac_handle_assoc_response, * so make sure only one of us does something */ if (!mac->associnfo.associating) goto out; mac->associnfo.associating = 0; mac->associnfo.bssvalid = 0; mac->associnfo.associated = 0; n = ieee80211softmac_get_network_by_bssid_locked(mac, mac->associnfo.bssid); dprintk(KERN_INFO PFX "assoc request timed out!\n"); ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, n);out: mutex_unlock(&mac->associnfo.mutex);}voidieee80211softmac_disassoc(struct ieee80211softmac_device *mac){ unsigned long flags; spin_lock_irqsave(&mac->lock, flags); if (mac->associnfo.associating) cancel_delayed_work(&mac->associnfo.timeout); netif_carrier_off(mac->dev); mac->associnfo.associated = 0; mac->associnfo.bssvalid = 0; mac->associnfo.associating = 0; ieee80211softmac_init_bss(mac); ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL); spin_unlock_irqrestore(&mac->lock, flags);}/* Sends out a disassociation request to the desired AP */voidieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reason){ struct ieee80211softmac_network *found; if (mac->associnfo.bssvalid && mac->associnfo.associated) { found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); if (found) ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason); } ieee80211softmac_disassoc(mac);}static inline intwe_support_all_basic_rates(struct ieee80211softmac_device *mac, u8 *from, u8 from_len){ int idx; u8 rate; for (idx = 0; idx < (from_len); idx++) { rate = (from)[idx]; if (!(rate & IEEE80211_BASIC_RATE_MASK)) continue; rate &= ~IEEE80211_BASIC_RATE_MASK; if (!ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate)) return 0; } return 1;}static intnetwork_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_network *net){ /* we cannot associate to networks whose name we don't know */ if (ieee80211_is_empty_essid(net->ssid, net->ssid_len)) return 0; /* do not associate to a network whose BSSBasicRateSet we cannot support */ if (!we_support_all_basic_rates(mac, net->rates, net->rates_len)) return 0; /* do we really need to check the ex rates? */ if (!we_support_all_basic_rates(mac, net->rates_ex, net->rates_ex_len)) return 0; /* assume that users know what they're doing ... * (note we don't let them select a net we're incompatible with) */ if (mac->associnfo.bssfixed) { return !memcmp(mac->associnfo.bssid, net->bssid, ETH_ALEN); } /* if 'ANY' network requested, take any that doesn't have privacy enabled */ if (mac->associnfo.req_essid.len == 0 && !(net->capability & WLAN_CAPABILITY_PRIVACY)) return 1; if (net->ssid_len != mac->associnfo.req_essid.len) return 0; if (!memcmp(net->ssid, mac->associnfo.req_essid.data, mac->associnfo.req_essid.len)) return 1; return 0;}static voidieee80211softmac_assoc_notify_scan(struct net_device *dev, int event_type, void *context){ struct ieee80211softmac_device *mac = ieee80211_priv(dev); ieee80211softmac_assoc_work(&mac->associnfo.work.work);}static voidieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void *context){ struct ieee80211softmac_device *mac = ieee80211_priv(dev); switch (event_type) { case IEEE80211SOFTMAC_EVENT_AUTHENTICATED: ieee80211softmac_assoc_work(&mac->associnfo.work.work); break; case IEEE80211SOFTMAC_EVENT_AUTH_FAILED: case IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT: ieee80211softmac_disassoc(mac); break; }}/* This function is called to handle userspace requests (asynchronously) */voidieee80211softmac_assoc_work(struct work_struct *work){ struct ieee80211softmac_device *mac = container_of(work, struct ieee80211softmac_device, associnfo.work.work); struct ieee80211softmac_network *found = NULL; struct ieee80211_network *net = NULL, *best = NULL; int bssvalid; unsigned long flags; mutex_lock(&mac->associnfo.mutex); if (!mac->associnfo.associating) goto out; /* ieee80211_disassoc might clear this */ bssvalid = mac->associnfo.bssvalid; /* meh */ if (mac->associnfo.associated) ieee80211softmac_send_disassoc_req(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT); /* try to find the requested network in our list, if we found one already */ if (bssvalid || mac->associnfo.bssfixed) found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); /* Search the ieee80211 networks for this network if we didn't find it by bssid, * but only if we've scanned at least once (to get a better list of networks to * select from). If we have not scanned before, the !found logic below will be * invoked and will scan. */ if (!found && (mac->associnfo.scan_retry < IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT)) { s8 rssi = -128; /* if I don't initialise, gcc emits an invalid warning because it cannot follow the best pointer logic. */ spin_lock_irqsave(&mac->ieee->lock, flags); list_for_each_entry(net, &mac->ieee->network_list, list) { /* we're supposed to find the network with * the best signal here, as we're asked to join * any network with a specific ESSID, and many * different ones could have that. * * I'll for now just go with the reported rssi. * * We also should take into account the rateset * here to find the best BSSID to try. */ if (network_matches_request(mac, net)) { if (!best) { best = net; rssi = best->stats.rssi; continue; } /* we already had a matching network, so * compare their properties to get the * better of the two ... (see above)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -