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