Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the softmac's association logic. |
| 3 | * |
Johannes Berg | 7985905 | 2006-01-31 19:31:41 +0100 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net> |
| 5 | * Joseph Jezak <josejx@gentoo.org> |
| 6 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 7 | * Danny van Dyk <kugelfang@gentoo.org> |
| 8 | * Michael Buesch <mbuesch@freenet.de> |
Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * |
| 23 | * The full GNU General Public License is included in this distribution in the |
| 24 | * file called COPYING. |
| 25 | */ |
| 26 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 27 | #include "ieee80211softmac_priv.h" |
| 28 | |
| 29 | /* |
| 30 | * Overview |
| 31 | * |
| 32 | * Before you can associate, you have to authenticate. |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 33 | * |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | /* Sends out an association request to the desired AP */ |
| 37 | static void |
| 38 | ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net) |
| 39 | { |
| 40 | unsigned long flags; |
John W. Linville | 9a107aa | 2006-03-22 17:29:32 -0500 | [diff] [blame] | 41 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 42 | /* Switch to correct channel for this network */ |
| 43 | mac->set_channel(mac->dev, net->channel); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 44 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 45 | /* Send association request */ |
| 46 | ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_ASSOC_REQ, 0); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 47 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 48 | dprintk(KERN_INFO PFX "sent association request!\n"); |
| 49 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 50 | spin_lock_irqsave(&mac->lock, flags); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 51 | mac->associnfo.associated = 0; /* just to make sure */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 52 | |
| 53 | /* Set a timer for timeout */ |
| 54 | /* FIXME: make timeout configurable */ |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 55 | if (likely(mac->running)) |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 56 | queue_delayed_work(mac->wq, &mac->associnfo.timeout, 5 * HZ); |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 57 | spin_unlock_irqrestore(&mac->lock, flags); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 61 | ieee80211softmac_assoc_timeout(struct work_struct *work) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 62 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 63 | struct ieee80211softmac_device *mac = |
| 64 | container_of(work, struct ieee80211softmac_device, |
| 65 | associnfo.timeout.work); |
Joseph Jezak | 9f101fc | 2006-06-11 12:01:03 -0400 | [diff] [blame] | 66 | struct ieee80211softmac_network *n; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 67 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 68 | mutex_lock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 69 | /* we might race against ieee80211softmac_handle_assoc_response, |
| 70 | * so make sure only one of us does something */ |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 71 | if (!mac->associnfo.associating) |
| 72 | goto out; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 73 | mac->associnfo.associating = 0; |
| 74 | mac->associnfo.bssvalid = 0; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 75 | mac->associnfo.associated = 0; |
Joseph Jezak | 9f101fc | 2006-06-11 12:01:03 -0400 | [diff] [blame] | 76 | |
| 77 | n = ieee80211softmac_get_network_by_bssid_locked(mac, mac->associnfo.bssid); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 78 | |
| 79 | dprintk(KERN_INFO PFX "assoc request timed out!\n"); |
Joseph Jezak | 9f101fc | 2006-06-11 12:01:03 -0400 | [diff] [blame] | 80 | ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, n); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 81 | out: |
| 82 | mutex_unlock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Johannes Berg | 9a1771e8 | 2006-04-20 20:02:02 +0200 | [diff] [blame] | 85 | void |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 86 | ieee80211softmac_disassoc(struct ieee80211softmac_device *mac) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 87 | { |
| 88 | unsigned long flags; |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 89 | |
| 90 | spin_lock_irqsave(&mac->lock, flags); |
| 91 | if (mac->associnfo.associating) |
| 92 | cancel_delayed_work(&mac->associnfo.timeout); |
| 93 | |
| 94 | netif_carrier_off(mac->dev); |
| 95 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 96 | mac->associnfo.associated = 0; |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 97 | mac->associnfo.bssvalid = 0; |
| 98 | mac->associnfo.associating = 0; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 99 | ieee80211softmac_init_bss(mac); |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 100 | ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_DISASSOCIATED, NULL); |
| 101 | spin_unlock_irqrestore(&mac->lock, flags); |
| 102 | } |
| 103 | |
| 104 | /* Sends out a disassociation request to the desired AP */ |
| 105 | void |
| 106 | ieee80211softmac_send_disassoc_req(struct ieee80211softmac_device *mac, u16 reason) |
| 107 | { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 108 | struct ieee80211softmac_network *found; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 109 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 110 | if (mac->associnfo.bssvalid && mac->associnfo.associated) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 111 | found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); |
| 112 | if (found) |
| 113 | ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 116 | ieee80211softmac_disassoc(mac); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | static inline int |
| 120 | we_support_all_basic_rates(struct ieee80211softmac_device *mac, u8 *from, u8 from_len) |
| 121 | { |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 122 | int idx; |
| 123 | u8 rate; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 124 | |
| 125 | for (idx = 0; idx < (from_len); idx++) { |
| 126 | rate = (from)[idx]; |
| 127 | if (!(rate & IEEE80211_BASIC_RATE_MASK)) |
| 128 | continue; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 129 | rate &= ~IEEE80211_BASIC_RATE_MASK; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 130 | if (!ieee80211softmac_ratesinfo_rate_supported(&mac->ratesinfo, rate)) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | return 1; |
| 134 | } |
| 135 | |
| 136 | static int |
| 137 | network_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_network *net) |
| 138 | { |
| 139 | /* we cannot associate to networks whose name we don't know */ |
| 140 | if (ieee80211_is_empty_essid(net->ssid, net->ssid_len)) |
| 141 | return 0; |
| 142 | /* do not associate to a network whose BSSBasicRateSet we cannot support */ |
| 143 | if (!we_support_all_basic_rates(mac, net->rates, net->rates_len)) |
| 144 | return 0; |
| 145 | /* do we really need to check the ex rates? */ |
| 146 | if (!we_support_all_basic_rates(mac, net->rates_ex, net->rates_ex_len)) |
| 147 | return 0; |
| 148 | |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 149 | /* assume that users know what they're doing ... |
| 150 | * (note we don't let them select a net we're incompatible with) */ |
| 151 | if (mac->associnfo.bssfixed) { |
| 152 | return !memcmp(mac->associnfo.bssid, net->bssid, ETH_ALEN); |
| 153 | } |
| 154 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 155 | /* if 'ANY' network requested, take any that doesn't have privacy enabled */ |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 156 | if (mac->associnfo.req_essid.len == 0 |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 157 | && !(net->capability & WLAN_CAPABILITY_PRIVACY)) |
| 158 | return 1; |
| 159 | if (net->ssid_len != mac->associnfo.req_essid.len) |
| 160 | return 0; |
| 161 | if (!memcmp(net->ssid, mac->associnfo.req_essid.data, mac->associnfo.req_essid.len)) |
| 162 | return 1; |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static void |
Daniel Drake | 6ae15df | 2006-06-01 15:37:22 +0100 | [diff] [blame] | 167 | ieee80211softmac_assoc_notify_scan(struct net_device *dev, int event_type, void *context) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 168 | { |
| 169 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
Ulrich Kunitz | 6f07a8a | 2006-12-10 18:39:08 +0100 | [diff] [blame] | 170 | ieee80211softmac_assoc_work(&mac->associnfo.work.work); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Daniel Drake | 6ae15df | 2006-06-01 15:37:22 +0100 | [diff] [blame] | 173 | static void |
| 174 | ieee80211softmac_assoc_notify_auth(struct net_device *dev, int event_type, void *context) |
| 175 | { |
| 176 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 177 | |
| 178 | switch (event_type) { |
| 179 | case IEEE80211SOFTMAC_EVENT_AUTHENTICATED: |
Ulrich Kunitz | 6f07a8a | 2006-12-10 18:39:08 +0100 | [diff] [blame] | 180 | ieee80211softmac_assoc_work(&mac->associnfo.work.work); |
Daniel Drake | 6ae15df | 2006-06-01 15:37:22 +0100 | [diff] [blame] | 181 | break; |
| 182 | case IEEE80211SOFTMAC_EVENT_AUTH_FAILED: |
| 183 | case IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT: |
| 184 | ieee80211softmac_disassoc(mac); |
| 185 | break; |
| 186 | } |
| 187 | } |
| 188 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 189 | /* This function is called to handle userspace requests (asynchronously) */ |
| 190 | void |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 191 | ieee80211softmac_assoc_work(struct work_struct *work) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 192 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 193 | struct ieee80211softmac_device *mac = |
| 194 | container_of(work, struct ieee80211softmac_device, |
| 195 | associnfo.work.work); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 196 | struct ieee80211softmac_network *found = NULL; |
| 197 | struct ieee80211_network *net = NULL, *best = NULL; |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 198 | int bssvalid; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 199 | unsigned long flags; |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 200 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 201 | mutex_lock(&mac->associnfo.mutex); |
| 202 | |
| 203 | if (!mac->associnfo.associating) |
| 204 | goto out; |
| 205 | |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 206 | /* ieee80211_disassoc might clear this */ |
| 207 | bssvalid = mac->associnfo.bssvalid; |
| 208 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 209 | /* meh */ |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 210 | if (mac->associnfo.associated) |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 211 | ieee80211softmac_send_disassoc_req(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 212 | |
| 213 | /* try to find the requested network in our list, if we found one already */ |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 214 | if (bssvalid || mac->associnfo.bssfixed) |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 215 | found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); |
| 216 | |
Johannes Berg | 1dc0977 | 2006-01-11 10:46:16 +0100 | [diff] [blame] | 217 | /* Search the ieee80211 networks for this network if we didn't find it by bssid, |
| 218 | * but only if we've scanned at least once (to get a better list of networks to |
| 219 | * select from). If we have not scanned before, the !found logic below will be |
| 220 | * invoked and will scan. */ |
| 221 | if (!found && (mac->associnfo.scan_retry < IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT)) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 222 | { |
Johannes Berg | 78e4f36 | 2006-01-10 18:56:32 +0100 | [diff] [blame] | 223 | s8 rssi = -128; /* if I don't initialise, gcc emits an invalid warning |
| 224 | because it cannot follow the best pointer logic. */ |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 225 | spin_lock_irqsave(&mac->ieee->lock, flags); |
| 226 | list_for_each_entry(net, &mac->ieee->network_list, list) { |
| 227 | /* we're supposed to find the network with |
| 228 | * the best signal here, as we're asked to join |
| 229 | * any network with a specific ESSID, and many |
| 230 | * different ones could have that. |
| 231 | * |
Johannes Berg | 78e4f36 | 2006-01-10 18:56:32 +0100 | [diff] [blame] | 232 | * I'll for now just go with the reported rssi. |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 233 | * |
| 234 | * We also should take into account the rateset |
| 235 | * here to find the best BSSID to try. |
| 236 | */ |
| 237 | if (network_matches_request(mac, net)) { |
| 238 | if (!best) { |
| 239 | best = net; |
Johannes Berg | 78e4f36 | 2006-01-10 18:56:32 +0100 | [diff] [blame] | 240 | rssi = best->stats.rssi; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 241 | continue; |
| 242 | } |
| 243 | /* we already had a matching network, so |
| 244 | * compare their properties to get the |
| 245 | * better of the two ... (see above) |
| 246 | */ |
Johannes Berg | 78e4f36 | 2006-01-10 18:56:32 +0100 | [diff] [blame] | 247 | if (rssi < net->stats.rssi) { |
| 248 | best = net; |
| 249 | rssi = best->stats.rssi; |
| 250 | } |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | /* if we unlock here, we might get interrupted and the `best' |
| 254 | * pointer could go stale */ |
| 255 | if (best) { |
| 256 | found = ieee80211softmac_create_network(mac, best); |
| 257 | /* if found is still NULL, then we got -ENOMEM somewhere */ |
| 258 | if (found) |
| 259 | ieee80211softmac_add_network(mac, found); |
| 260 | } |
| 261 | spin_unlock_irqrestore(&mac->ieee->lock, flags); |
| 262 | } |
| 263 | |
| 264 | if (!found) { |
| 265 | if (mac->associnfo.scan_retry > 0) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 266 | mac->associnfo.scan_retry--; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 267 | |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 268 | /* We know of no such network. Let's scan. |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 269 | * NB: this also happens if we had no memory to copy the network info... |
| 270 | * Maybe we can hope to have more memory after scanning finishes ;) |
| 271 | */ |
Johannes Berg | 1dc0977 | 2006-01-11 10:46:16 +0100 | [diff] [blame] | 272 | dprintk(KERN_INFO PFX "Associate: Scanning for networks first.\n"); |
Daniel Drake | 6ae15df | 2006-06-01 15:37:22 +0100 | [diff] [blame] | 273 | ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify_scan, NULL); |
Jean Tourrilhes | 4cf92a3 | 2007-07-09 20:37:36 -0500 | [diff] [blame] | 274 | if (ieee80211softmac_start_scan(mac)) { |
Johannes Berg | 1dc0977 | 2006-01-11 10:46:16 +0100 | [diff] [blame] | 275 | dprintk(KERN_INFO PFX "Associate: failed to initiate scan. Is device up?\n"); |
Jean Tourrilhes | 4cf92a3 | 2007-07-09 20:37:36 -0500 | [diff] [blame] | 276 | } |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 277 | goto out; |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 278 | } else { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 279 | mac->associnfo.associating = 0; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 280 | mac->associnfo.associated = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 281 | |
Johannes Berg | 1dc0977 | 2006-01-11 10:46:16 +0100 | [diff] [blame] | 282 | dprintk(KERN_INFO PFX "Unable to find matching network after scan!\n"); |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 283 | /* reset the retry counter for the next user request since we |
| 284 | * break out and don't reschedule ourselves after this point. */ |
| 285 | mac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 286 | ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND, NULL); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 287 | goto out; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 288 | } |
| 289 | } |
Johannes Berg | 818667f | 2006-04-20 20:02:03 +0200 | [diff] [blame] | 290 | |
| 291 | /* reset the retry counter for the next user request since we |
| 292 | * now found a net and will try to associate to it, but not |
| 293 | * schedule this function again. */ |
| 294 | mac->associnfo.scan_retry = IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 295 | mac->associnfo.bssvalid = 1; |
| 296 | memcpy(mac->associnfo.bssid, found->bssid, ETH_ALEN); |
| 297 | /* copy the ESSID for displaying it */ |
| 298 | mac->associnfo.associate_essid.len = found->essid.len; |
| 299 | memcpy(mac->associnfo.associate_essid.data, found->essid.data, IW_ESSID_MAX_SIZE + 1); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 300 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 301 | /* we found a network! authenticate (if necessary) and associate to it. */ |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 302 | if (found->authenticating) { |
| 303 | dprintk(KERN_INFO PFX "Already requested authentication, waiting...\n"); |
| 304 | if(!mac->associnfo.assoc_wait) { |
| 305 | mac->associnfo.assoc_wait = 1; |
John W. Linville | 4a232e7 | 2006-06-26 16:34:29 -0400 | [diff] [blame] | 306 | ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL); |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 307 | } |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 308 | goto out; |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 309 | } |
| 310 | if (!found->authenticated && !found->authenticating) { |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 311 | /* This relies on the fact that _auth_req only queues the work, |
| 312 | * otherwise adding the notification would be racy. */ |
| 313 | if (!ieee80211softmac_auth_req(mac, found)) { |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 314 | if(!mac->associnfo.assoc_wait) { |
| 315 | dprintk(KERN_INFO PFX "Cannot associate without being authenticated, requested authentication\n"); |
| 316 | mac->associnfo.assoc_wait = 1; |
John W. Linville | 4a232e7 | 2006-06-26 16:34:29 -0400 | [diff] [blame] | 317 | ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify_auth, NULL, GFP_KERNEL); |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 318 | } |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 319 | } else { |
| 320 | printkl(KERN_WARNING PFX "Not authenticated, but requesting authentication failed. Giving up to associate\n"); |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 321 | mac->associnfo.assoc_wait = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 322 | ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, found); |
| 323 | } |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 324 | goto out; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 325 | } |
| 326 | /* finally! now we can start associating */ |
Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 327 | mac->associnfo.assoc_wait = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 328 | ieee80211softmac_assoc(mac, found); |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 329 | |
| 330 | out: |
| 331 | mutex_unlock(&mac->associnfo.mutex); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /* call this to do whatever is necessary when we're associated */ |
| 335 | static void |
| 336 | ieee80211softmac_associated(struct ieee80211softmac_device *mac, |
| 337 | struct ieee80211_assoc_response * resp, |
| 338 | struct ieee80211softmac_network *net) |
| 339 | { |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 340 | u16 cap = le16_to_cpu(resp->capability); |
| 341 | u8 erp_value = net->erp_value; |
| 342 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 343 | mac->associnfo.associating = 0; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 344 | mac->bssinfo.supported_rates = net->supported_rates; |
Daniel Drake | 8462fe3 | 2006-05-01 22:45:50 +0100 | [diff] [blame] | 345 | ieee80211softmac_recalc_txrates(mac); |
| 346 | |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 347 | mac->associnfo.associated = 1; |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 348 | |
| 349 | mac->associnfo.short_preamble_available = |
| 350 | (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0; |
| 351 | ieee80211softmac_process_erp(mac, erp_value); |
| 352 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 353 | if (mac->set_bssid_filter) |
| 354 | mac->set_bssid_filter(mac->dev, net->bssid); |
| 355 | memcpy(mac->ieee->bssid, net->bssid, ETH_ALEN); |
Johannes Berg | 2dd5080 | 2006-01-06 18:11:23 +0100 | [diff] [blame] | 356 | netif_carrier_on(mac->dev); |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 357 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 358 | mac->association_id = le16_to_cpup(&resp->aid); |
| 359 | } |
| 360 | |
| 361 | /* received frame handling functions */ |
| 362 | int |
| 363 | ieee80211softmac_handle_assoc_response(struct net_device * dev, |
| 364 | struct ieee80211_assoc_response * resp, |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 365 | struct ieee80211_network * _ieee80211_network) |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 366 | { |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 367 | /* NOTE: the network parameter has to be mostly ignored by |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 368 | * this code because it is the ieee80211's pointer |
| 369 | * to the struct, not ours (we made a copy) |
| 370 | */ |
| 371 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 372 | u16 status = le16_to_cpup(&resp->status); |
| 373 | struct ieee80211softmac_network *network = NULL; |
| 374 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 375 | DECLARE_MAC_BUF(mac2); |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 376 | |
| 377 | if (unlikely(!mac->running)) |
| 378 | return -ENODEV; |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 379 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 380 | spin_lock_irqsave(&mac->lock, flags); |
| 381 | |
| 382 | if (!mac->associnfo.associating) { |
| 383 | /* we race against the timeout function, so make sure |
| 384 | * only one of us can do work */ |
| 385 | spin_unlock_irqrestore(&mac->lock, flags); |
| 386 | return 0; |
| 387 | } |
| 388 | network = ieee80211softmac_get_network_by_bssid_locked(mac, resp->header.addr3); |
| 389 | |
| 390 | /* someone sending us things without us knowing him? Ignore. */ |
| 391 | if (!network) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 392 | dprintk(KERN_INFO PFX "Received unrequested assocation response from %s\n", |
| 393 | print_mac(mac2, resp->header.addr3)); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 394 | spin_unlock_irqrestore(&mac->lock, flags); |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | /* now that we know it was for us, we can cancel the timeout */ |
| 399 | cancel_delayed_work(&mac->associnfo.timeout); |
| 400 | |
Daniel Drake | 5acd0c41 | 2006-07-18 21:33:27 +0100 | [diff] [blame] | 401 | /* if the association response included an ERP IE, update our saved |
| 402 | * copy */ |
| 403 | if (_ieee80211_network->flags & NETWORK_HAS_ERP_VALUE) |
| 404 | network->erp_value = _ieee80211_network->erp_value; |
| 405 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 406 | switch (status) { |
| 407 | case 0: |
| 408 | dprintk(KERN_INFO PFX "associated!\n"); |
| 409 | ieee80211softmac_associated(mac, resp, network); |
| 410 | ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATED, network); |
| 411 | break; |
| 412 | case WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH: |
| 413 | if (!network->auth_desynced_once) { |
| 414 | /* there seem to be a few rare cases where our view of |
| 415 | * the world is obscured, or buggy APs that don't DEAUTH |
| 416 | * us properly. So we handle that, but allow it only once. |
| 417 | */ |
| 418 | printkl(KERN_INFO PFX "We were not authenticated during association, retrying...\n"); |
| 419 | network->authenticated = 0; |
| 420 | /* we don't want to do this more than once ... */ |
| 421 | network->auth_desynced_once = 1; |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 422 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | default: |
| 426 | dprintk(KERN_INFO PFX "associating failed (reason: 0x%x)!\n", status); |
| 427 | mac->associnfo.associating = 0; |
| 428 | mac->associnfo.bssvalid = 0; |
Michael Buesch | 7c28ad2 | 2006-09-27 15:26:33 +0300 | [diff] [blame] | 429 | mac->associnfo.associated = 0; |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 430 | ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, network); |
| 431 | } |
YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 432 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 433 | spin_unlock_irqrestore(&mac->lock, flags); |
| 434 | return 0; |
| 435 | } |
| 436 | |
Ulrich Kunitz | 2b50c24 | 2006-12-03 16:32:00 +0100 | [diff] [blame] | 437 | void |
| 438 | ieee80211softmac_try_reassoc(struct ieee80211softmac_device *mac) |
| 439 | { |
| 440 | unsigned long flags; |
| 441 | |
| 442 | spin_lock_irqsave(&mac->lock, flags); |
| 443 | mac->associnfo.associating = 1; |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 444 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); |
Ulrich Kunitz | 2b50c24 | 2006-12-03 16:32:00 +0100 | [diff] [blame] | 445 | spin_unlock_irqrestore(&mac->lock, flags); |
| 446 | } |
| 447 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 448 | int |
| 449 | ieee80211softmac_handle_disassoc(struct net_device * dev, |
| 450 | struct ieee80211_disassoc *disassoc) |
| 451 | { |
| 452 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 453 | |
| 454 | if (unlikely(!mac->running)) |
| 455 | return -ENODEV; |
| 456 | |
Johannes Berg | 48b2e4c | 2006-01-10 19:12:19 +0100 | [diff] [blame] | 457 | if (memcmp(disassoc->header.addr2, mac->associnfo.bssid, ETH_ALEN)) |
| 458 | return 0; |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 459 | |
Johannes Berg | 48b2e4c | 2006-01-10 19:12:19 +0100 | [diff] [blame] | 460 | if (memcmp(disassoc->header.addr1, mac->dev->dev_addr, ETH_ALEN)) |
| 461 | return 0; |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 462 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 463 | dprintk(KERN_INFO PFX "got disassoc frame\n"); |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 464 | ieee80211softmac_disassoc(mac); |
| 465 | |
Ulrich Kunitz | 2b50c24 | 2006-12-03 16:32:00 +0100 | [diff] [blame] | 466 | ieee80211softmac_try_reassoc(mac); |
Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 467 | |
Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 468 | return 0; |
| 469 | } |
Johannes Berg | b6c7658 | 2006-01-31 19:49:42 +0100 | [diff] [blame] | 470 | |
| 471 | int |
| 472 | ieee80211softmac_handle_reassoc_req(struct net_device * dev, |
| 473 | struct ieee80211_reassoc_request * resp) |
| 474 | { |
| 475 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); |
| 476 | struct ieee80211softmac_network *network; |
| 477 | |
Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 478 | if (unlikely(!mac->running)) |
| 479 | return -ENODEV; |
| 480 | |
Johannes Berg | b6c7658 | 2006-01-31 19:49:42 +0100 | [diff] [blame] | 481 | network = ieee80211softmac_get_network_by_bssid(mac, resp->header.addr3); |
| 482 | if (!network) { |
| 483 | dprintkl(KERN_INFO PFX "reassoc request from unknown network\n"); |
| 484 | return 0; |
| 485 | } |
Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 486 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); |
Michael Buesch | 9b0b4d8 | 2006-04-07 01:42:55 +0200 | [diff] [blame] | 487 | |
Johannes Berg | b6c7658 | 2006-01-31 19:49:42 +0100 | [diff] [blame] | 488 | return 0; |
| 489 | } |