Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
| 3 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <linux/netdevice.h> |
| 18 | #include <linux/if_arp.h> |
| 19 | #include <linux/wireless.h> |
| 20 | #include <linux/random.h> |
| 21 | #include <linux/etherdevice.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 22 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 23 | #include <net/iw_handler.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 24 | #include <net/mac80211.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 25 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 27 | #include "rate.h" |
| 28 | #include "led.h" |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 29 | #include "mesh.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 31 | #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 33 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 34 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 35 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 36 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 37 | #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 38 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) |
| 39 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) |
| 40 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) |
| 41 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) |
Dan Williams | 872ba53 | 2008-06-04 13:59:34 -0400 | [diff] [blame] | 42 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 43 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 44 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
| 45 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 46 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 47 | |
| 48 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 49 | |
| 50 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 51 | /* utils */ |
| 52 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 53 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 54 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 58 | { |
| 59 | u8 *end, *pos; |
| 60 | |
| 61 | pos = bss->ies; |
| 62 | if (pos == NULL) |
| 63 | return NULL; |
| 64 | end = pos + bss->ies_len; |
| 65 | |
| 66 | while (pos + 1 < end) { |
| 67 | if (pos + 2 + pos[1] > end) |
| 68 | break; |
| 69 | if (pos[0] == ie) |
| 70 | return pos; |
| 71 | pos += 2 + pos[1]; |
| 72 | } |
| 73 | |
| 74 | return NULL; |
| 75 | } |
| 76 | |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 77 | static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss, |
| 78 | struct ieee80211_supported_band *sband, |
| 79 | u64 *rates) |
| 80 | { |
| 81 | int i, j, count; |
| 82 | *rates = 0; |
| 83 | count = 0; |
| 84 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 85 | int rate = (bss->supp_rates[i] & 0x7F) * 5; |
| 86 | |
| 87 | for (j = 0; j < sband->n_bitrates; j++) |
| 88 | if (sband->bitrates[j].bitrate == rate) { |
| 89 | *rates |= BIT(j); |
| 90 | count++; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return count; |
| 96 | } |
| 97 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 98 | /* frame sending functions */ |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 99 | static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
| 100 | struct ieee80211_if_sta *ifsta, |
| 101 | int transaction, u8 *extra, size_t extra_len, |
| 102 | int encrypt) |
| 103 | { |
| 104 | struct ieee80211_local *local = sdata->local; |
| 105 | struct sk_buff *skb; |
| 106 | struct ieee80211_mgmt *mgmt; |
| 107 | |
| 108 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 109 | sizeof(*mgmt) + 6 + extra_len); |
| 110 | if (!skb) { |
| 111 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " |
| 112 | "frame\n", sdata->dev->name); |
| 113 | return; |
| 114 | } |
| 115 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 116 | |
| 117 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); |
| 118 | memset(mgmt, 0, 24 + 6); |
| 119 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 120 | IEEE80211_STYPE_AUTH); |
| 121 | if (encrypt) |
| 122 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 123 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 124 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 125 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 126 | mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); |
| 127 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); |
| 128 | ifsta->auth_transaction = transaction + 1; |
| 129 | mgmt->u.auth.status_code = cpu_to_le16(0); |
| 130 | if (extra) |
| 131 | memcpy(skb_put(skb, extra_len), extra, extra_len); |
| 132 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame^] | 133 | ieee80211_tx_skb(sdata, skb, encrypt); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 136 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
| 137 | u8 *ssid, size_t ssid_len) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 138 | { |
| 139 | struct ieee80211_local *local = sdata->local; |
| 140 | struct ieee80211_supported_band *sband; |
| 141 | struct sk_buff *skb; |
| 142 | struct ieee80211_mgmt *mgmt; |
| 143 | u8 *pos, *supp_rates, *esupp_rates = NULL; |
| 144 | int i; |
| 145 | |
| 146 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); |
| 147 | if (!skb) { |
| 148 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " |
| 149 | "request\n", sdata->dev->name); |
| 150 | return; |
| 151 | } |
| 152 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 153 | |
| 154 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 155 | memset(mgmt, 0, 24); |
| 156 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 157 | IEEE80211_STYPE_PROBE_REQ); |
| 158 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 159 | if (dst) { |
| 160 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 161 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
| 162 | } else { |
| 163 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 164 | memset(mgmt->bssid, 0xff, ETH_ALEN); |
| 165 | } |
| 166 | pos = skb_put(skb, 2 + ssid_len); |
| 167 | *pos++ = WLAN_EID_SSID; |
| 168 | *pos++ = ssid_len; |
| 169 | memcpy(pos, ssid, ssid_len); |
| 170 | |
| 171 | supp_rates = skb_put(skb, 2); |
| 172 | supp_rates[0] = WLAN_EID_SUPP_RATES; |
| 173 | supp_rates[1] = 0; |
| 174 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 175 | |
| 176 | for (i = 0; i < sband->n_bitrates; i++) { |
| 177 | struct ieee80211_rate *rate = &sband->bitrates[i]; |
| 178 | if (esupp_rates) { |
| 179 | pos = skb_put(skb, 1); |
| 180 | esupp_rates[1]++; |
| 181 | } else if (supp_rates[1] == 8) { |
| 182 | esupp_rates = skb_put(skb, 3); |
| 183 | esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; |
| 184 | esupp_rates[1] = 1; |
| 185 | pos = &esupp_rates[2]; |
| 186 | } else { |
| 187 | pos = skb_put(skb, 1); |
| 188 | supp_rates[1]++; |
| 189 | } |
| 190 | *pos = rate->bitrate / 5; |
| 191 | } |
| 192 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame^] | 193 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 194 | } |
| 195 | |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 196 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
| 197 | struct ieee80211_if_sta *ifsta) |
| 198 | { |
| 199 | struct ieee80211_local *local = sdata->local; |
| 200 | struct sk_buff *skb; |
| 201 | struct ieee80211_mgmt *mgmt; |
| 202 | u8 *pos, *ies, *ht_add_ie; |
| 203 | int i, len, count, rates_len, supp_rates_len; |
| 204 | u16 capab; |
| 205 | struct ieee80211_sta_bss *bss; |
| 206 | int wmm = 0; |
| 207 | struct ieee80211_supported_band *sband; |
| 208 | u64 rates = 0; |
| 209 | |
| 210 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 211 | sizeof(*mgmt) + 200 + ifsta->extra_ie_len + |
| 212 | ifsta->ssid_len); |
| 213 | if (!skb) { |
| 214 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " |
| 215 | "frame\n", sdata->dev->name); |
| 216 | return; |
| 217 | } |
| 218 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 219 | |
| 220 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 221 | |
| 222 | capab = ifsta->capab; |
| 223 | |
| 224 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { |
| 225 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 226 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 227 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 228 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 229 | } |
| 230 | |
| 231 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
| 232 | local->hw.conf.channel->center_freq, |
| 233 | ifsta->ssid, ifsta->ssid_len); |
| 234 | if (bss) { |
| 235 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 236 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 237 | if (bss->wmm_used) |
| 238 | wmm = 1; |
| 239 | |
| 240 | /* get all rates supported by the device and the AP as |
| 241 | * some APs don't like getting a superset of their rates |
| 242 | * in the association request (e.g. D-Link DAP 1353 in |
| 243 | * b-only mode) */ |
| 244 | rates_len = ieee80211_compatible_rates(bss, sband, &rates); |
| 245 | |
| 246 | if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
| 247 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 248 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 249 | |
| 250 | ieee80211_rx_bss_put(local, bss); |
| 251 | } else { |
| 252 | rates = ~0; |
| 253 | rates_len = sband->n_bitrates; |
| 254 | } |
| 255 | |
| 256 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 257 | memset(mgmt, 0, 24); |
| 258 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 259 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 260 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 261 | |
| 262 | if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) { |
| 263 | skb_put(skb, 10); |
| 264 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 265 | IEEE80211_STYPE_REASSOC_REQ); |
| 266 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 267 | mgmt->u.reassoc_req.listen_interval = |
| 268 | cpu_to_le16(local->hw.conf.listen_interval); |
| 269 | memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, |
| 270 | ETH_ALEN); |
| 271 | } else { |
| 272 | skb_put(skb, 4); |
| 273 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 274 | IEEE80211_STYPE_ASSOC_REQ); |
| 275 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 276 | mgmt->u.reassoc_req.listen_interval = |
| 277 | cpu_to_le16(local->hw.conf.listen_interval); |
| 278 | } |
| 279 | |
| 280 | /* SSID */ |
| 281 | ies = pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 282 | *pos++ = WLAN_EID_SSID; |
| 283 | *pos++ = ifsta->ssid_len; |
| 284 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 285 | |
| 286 | /* add all rates which were marked to be used above */ |
| 287 | supp_rates_len = rates_len; |
| 288 | if (supp_rates_len > 8) |
| 289 | supp_rates_len = 8; |
| 290 | |
| 291 | len = sband->n_bitrates; |
| 292 | pos = skb_put(skb, supp_rates_len + 2); |
| 293 | *pos++ = WLAN_EID_SUPP_RATES; |
| 294 | *pos++ = supp_rates_len; |
| 295 | |
| 296 | count = 0; |
| 297 | for (i = 0; i < sband->n_bitrates; i++) { |
| 298 | if (BIT(i) & rates) { |
| 299 | int rate = sband->bitrates[i].bitrate; |
| 300 | *pos++ = (u8) (rate / 5); |
| 301 | if (++count == 8) |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (rates_len > count) { |
| 307 | pos = skb_put(skb, rates_len - count + 2); |
| 308 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 309 | *pos++ = rates_len - count; |
| 310 | |
| 311 | for (i++; i < sband->n_bitrates; i++) { |
| 312 | if (BIT(i) & rates) { |
| 313 | int rate = sband->bitrates[i].bitrate; |
| 314 | *pos++ = (u8) (rate / 5); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 320 | /* 1. power capabilities */ |
| 321 | pos = skb_put(skb, 4); |
| 322 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 323 | *pos++ = 2; |
| 324 | *pos++ = 0; /* min tx power */ |
| 325 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ |
| 326 | |
| 327 | /* 2. supported channels */ |
| 328 | /* TODO: get this in reg domain format */ |
| 329 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 330 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 331 | *pos++ = 2 * sband->n_channels; |
| 332 | for (i = 0; i < sband->n_channels; i++) { |
| 333 | *pos++ = ieee80211_frequency_to_channel( |
| 334 | sband->channels[i].center_freq); |
| 335 | *pos++ = 1; /* one channel in the subband*/ |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | if (ifsta->extra_ie) { |
| 340 | pos = skb_put(skb, ifsta->extra_ie_len); |
| 341 | memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); |
| 342 | } |
| 343 | |
| 344 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
| 345 | pos = skb_put(skb, 9); |
| 346 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 347 | *pos++ = 7; /* len */ |
| 348 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 349 | *pos++ = 0x50; |
| 350 | *pos++ = 0xf2; |
| 351 | *pos++ = 2; /* WME */ |
| 352 | *pos++ = 0; /* WME info */ |
| 353 | *pos++ = 1; /* WME ver */ |
| 354 | *pos++ = 0; |
| 355 | } |
| 356 | |
| 357 | /* wmm support is a must to HT */ |
| 358 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) && |
| 359 | sband->ht_info.ht_supported && |
| 360 | (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) { |
| 361 | struct ieee80211_ht_addt_info *ht_add_info = |
| 362 | (struct ieee80211_ht_addt_info *)ht_add_ie; |
| 363 | u16 cap = sband->ht_info.cap; |
| 364 | __le16 tmp; |
| 365 | u32 flags = local->hw.conf.channel->flags; |
| 366 | |
| 367 | switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) { |
| 368 | case IEEE80211_HT_IE_CHA_SEC_ABOVE: |
| 369 | if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { |
| 370 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; |
| 371 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 372 | } |
| 373 | break; |
| 374 | case IEEE80211_HT_IE_CHA_SEC_BELOW: |
| 375 | if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { |
| 376 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; |
| 377 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 378 | } |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | tmp = cpu_to_le16(cap); |
| 383 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); |
| 384 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 385 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 386 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); |
| 387 | memcpy(pos, &tmp, sizeof(u16)); |
| 388 | pos += sizeof(u16); |
| 389 | /* TODO: needs a define here for << 2 */ |
| 390 | *pos++ = sband->ht_info.ampdu_factor | |
| 391 | (sband->ht_info.ampdu_density << 2); |
| 392 | memcpy(pos, sband->ht_info.supp_mcs_set, 16); |
| 393 | } |
| 394 | |
| 395 | kfree(ifsta->assocreq_ies); |
| 396 | ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; |
| 397 | ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL); |
| 398 | if (ifsta->assocreq_ies) |
| 399 | memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); |
| 400 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame^] | 401 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 405 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
| 406 | u16 stype, u16 reason) |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 407 | { |
| 408 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 409 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 410 | struct sk_buff *skb; |
| 411 | struct ieee80211_mgmt *mgmt; |
| 412 | |
| 413 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
| 414 | if (!skb) { |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 415 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
| 416 | "deauth/disassoc frame\n", sdata->dev->name); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 417 | return; |
| 418 | } |
| 419 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 420 | |
| 421 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 422 | memset(mgmt, 0, 24); |
| 423 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 424 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 425 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 426 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 427 | skb_put(skb, 2); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 428 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 429 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
| 430 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame^] | 431 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 432 | } |
| 433 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 434 | /* MLME */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 435 | static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | b079ada | 2008-09-09 09:32:59 +0200 | [diff] [blame] | 436 | struct ieee80211_sta_bss *bss) |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 437 | { |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 438 | struct ieee80211_local *local = sdata->local; |
| 439 | int i, have_higher_than_11mbit = 0; |
| 440 | |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 441 | /* cf. IEEE 802.11 9.2.12 */ |
| 442 | for (i = 0; i < bss->supp_rates_len; i++) |
| 443 | if ((bss->supp_rates[i] & 0x7f) * 5 > 110) |
| 444 | have_higher_than_11mbit = 1; |
| 445 | |
| 446 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 447 | have_higher_than_11mbit) |
| 448 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 449 | else |
| 450 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 451 | |
Johannes Berg | 3d35f7c | 2008-09-09 12:54:11 +0200 | [diff] [blame] | 452 | ieee80211_set_wmm_default(sdata); |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 455 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 456 | struct ieee80211_if_sta *ifsta, |
| 457 | u8 *wmm_param, size_t wmm_param_len) |
| 458 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 459 | struct ieee80211_tx_queue_params params; |
| 460 | size_t left; |
| 461 | int count; |
| 462 | u8 *pos; |
| 463 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 464 | if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED)) |
| 465 | return; |
| 466 | |
| 467 | if (!wmm_param) |
| 468 | return; |
| 469 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 470 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
| 471 | return; |
| 472 | count = wmm_param[6] & 0x0f; |
| 473 | if (count == ifsta->wmm_last_param_set) |
| 474 | return; |
| 475 | ifsta->wmm_last_param_set = count; |
| 476 | |
| 477 | pos = wmm_param + 8; |
| 478 | left = wmm_param_len - 8; |
| 479 | |
| 480 | memset(¶ms, 0, sizeof(params)); |
| 481 | |
| 482 | if (!local->ops->conf_tx) |
| 483 | return; |
| 484 | |
| 485 | local->wmm_acm = 0; |
| 486 | for (; left >= 4; left -= 4, pos += 4) { |
| 487 | int aci = (pos[0] >> 5) & 0x03; |
| 488 | int acm = (pos[0] >> 4) & 0x01; |
| 489 | int queue; |
| 490 | |
| 491 | switch (aci) { |
| 492 | case 1: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 493 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 494 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 495 | local->wmm_acm |= BIT(0) | BIT(3); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 496 | break; |
| 497 | case 2: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 498 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 499 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 500 | local->wmm_acm |= BIT(4) | BIT(5); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 501 | break; |
| 502 | case 3: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 503 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 504 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 505 | local->wmm_acm |= BIT(6) | BIT(7); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 506 | break; |
| 507 | case 0: |
| 508 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 509 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 510 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 511 | local->wmm_acm |= BIT(1) | BIT(2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 512 | break; |
| 513 | } |
| 514 | |
| 515 | params.aifs = pos[0] & 0x0f; |
| 516 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 517 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 518 | params.txop = get_unaligned_le16(pos + 2); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 519 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 520 | printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 521 | "cWmin=%d cWmax=%d txop=%d\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 522 | local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 523 | params.cw_max, params.txop); |
| 524 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 525 | /* TODO: handle ACM (block TX, fallback to next lowest allowed |
| 526 | * AC for now) */ |
| 527 | if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { |
| 528 | printk(KERN_DEBUG "%s: failed to set TX queue " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 529 | "parameters for queue %d\n", local->mdev->name, queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 534 | static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata, |
| 535 | bool use_protection, |
| 536 | bool use_short_preamble) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 537 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 538 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 539 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 540 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 541 | DECLARE_MAC_BUF(mac); |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 542 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 543 | u32 changed = 0; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 544 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 545 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 546 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 547 | if (net_ratelimit()) { |
| 548 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 549 | "%s)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 550 | sdata->dev->name, |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 551 | use_protection ? "enabled" : "disabled", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 552 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 553 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 554 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 555 | bss_conf->use_cts_prot = use_protection; |
| 556 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 557 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 558 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 559 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 560 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 561 | if (net_ratelimit()) { |
| 562 | printk(KERN_DEBUG "%s: switched to %s barker preamble" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 563 | " (BSSID=%s)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 564 | sdata->dev->name, |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 565 | use_short_preamble ? "short" : "long", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 566 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 567 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 568 | #endif |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 569 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 570 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 571 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 572 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 573 | return changed; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 574 | } |
| 575 | |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 576 | static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata, |
| 577 | u8 erp_value) |
| 578 | { |
| 579 | bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; |
| 580 | bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 581 | |
| 582 | return ieee80211_handle_protect_preamb(sdata, |
| 583 | use_protection, use_short_preamble); |
| 584 | } |
| 585 | |
| 586 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 587 | struct ieee80211_sta_bss *bss) |
| 588 | { |
| 589 | u32 changed = 0; |
| 590 | |
| 591 | if (bss->has_erp_value) |
| 592 | changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value); |
| 593 | else { |
| 594 | u16 capab = bss->capability; |
| 595 | changed |= ieee80211_handle_protect_preamb(sdata, false, |
| 596 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); |
| 597 | } |
| 598 | |
| 599 | return changed; |
| 600 | } |
| 601 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 602 | static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata, |
| 603 | struct ieee80211_if_sta *ifsta) |
| 604 | { |
| 605 | union iwreq_data wrqu; |
| 606 | memset(&wrqu, 0, sizeof(wrqu)); |
| 607 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
| 608 | memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 609 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 610 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
| 611 | } |
| 612 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 613 | static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 614 | struct ieee80211_if_sta *ifsta) |
| 615 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 616 | union iwreq_data wrqu; |
| 617 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 618 | if (ifsta->assocreq_ies) { |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 619 | memset(&wrqu, 0, sizeof(wrqu)); |
| 620 | wrqu.data.length = ifsta->assocreq_ies_len; |
David S. Miller | b171e19 | 2008-08-29 23:06:00 -0700 | [diff] [blame] | 621 | wireless_send_event(sdata->dev, IWEVASSOCREQIE, &wrqu, |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 622 | ifsta->assocreq_ies); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 623 | } |
| 624 | if (ifsta->assocresp_ies) { |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 625 | memset(&wrqu, 0, sizeof(wrqu)); |
| 626 | wrqu.data.length = ifsta->assocresp_ies_len; |
David S. Miller | b171e19 | 2008-08-29 23:06:00 -0700 | [diff] [blame] | 627 | wireless_send_event(sdata->dev, IWEVASSOCRESPIE, &wrqu, |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 628 | ifsta->assocresp_ies); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 629 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 633 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 634 | struct ieee80211_if_sta *ifsta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 635 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 636 | struct ieee80211_local *local = sdata->local; |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 637 | struct ieee80211_conf *conf = &local_to_hw(local)->conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 638 | u32 changed = BSS_CHANGED_ASSOC; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 639 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 640 | struct ieee80211_sta_bss *bss; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 641 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 642 | ifsta->flags |= IEEE80211_STA_ASSOCIATED; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 643 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 644 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
| 645 | return; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 646 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 647 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
| 648 | conf->channel->center_freq, |
| 649 | ifsta->ssid, ifsta->ssid_len); |
| 650 | if (bss) { |
| 651 | /* set timing information */ |
| 652 | sdata->bss_conf.beacon_int = bss->beacon_int; |
| 653 | sdata->bss_conf.timestamp = bss->timestamp; |
| 654 | sdata->bss_conf.dtim_period = bss->dtim_period; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 655 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 656 | changed |= ieee80211_handle_bss_capability(sdata, bss); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 657 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 658 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 659 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 660 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 661 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
| 662 | changed |= BSS_CHANGED_HT; |
| 663 | sdata->bss_conf.assoc_ht = 1; |
| 664 | sdata->bss_conf.ht_conf = &conf->ht_conf; |
| 665 | sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf; |
| 666 | } |
| 667 | |
| 668 | ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET; |
| 669 | memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); |
| 670 | ieee80211_sta_send_associnfo(sdata, ifsta); |
| 671 | |
| 672 | ifsta->last_probe = jiffies; |
| 673 | ieee80211_led_assoc(local, 1); |
| 674 | |
| 675 | sdata->bss_conf.assoc = 1; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 676 | ieee80211_bss_info_change_notify(sdata, changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 677 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 678 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 679 | netif_carrier_on(sdata->dev); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 680 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 681 | ieee80211_sta_send_apinfo(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 684 | static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, |
| 685 | struct ieee80211_if_sta *ifsta) |
| 686 | { |
| 687 | DECLARE_MAC_BUF(mac); |
| 688 | |
| 689 | ifsta->direct_probe_tries++; |
| 690 | if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { |
| 691 | printk(KERN_DEBUG "%s: direct probe to AP %s timed out\n", |
| 692 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
| 693 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 694 | return; |
| 695 | } |
| 696 | |
| 697 | printk(KERN_DEBUG "%s: direct probe to AP %s try %d\n", |
| 698 | sdata->dev->name, print_mac(mac, ifsta->bssid), |
| 699 | ifsta->direct_probe_tries); |
| 700 | |
| 701 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 702 | |
| 703 | set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request); |
| 704 | |
| 705 | /* Direct probe is sent to broadcast address as some APs |
| 706 | * will not answer to direct packet in unassociated state. |
| 707 | */ |
| 708 | ieee80211_send_probe_req(sdata, NULL, |
| 709 | ifsta->ssid, ifsta->ssid_len); |
| 710 | |
| 711 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
| 712 | } |
| 713 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 714 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 715 | static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 716 | struct ieee80211_if_sta *ifsta) |
| 717 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 718 | DECLARE_MAC_BUF(mac); |
| 719 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 720 | ifsta->auth_tries++; |
| 721 | if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 722 | printk(KERN_DEBUG "%s: authentication with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 723 | " timed out\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 724 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 725 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 726 | return; |
| 727 | } |
| 728 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 729 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 730 | printk(KERN_DEBUG "%s: authenticate with AP %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 731 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 732 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 733 | ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 734 | |
| 735 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
| 736 | } |
| 737 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 738 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
| 739 | struct ieee80211_if_sta *ifsta, bool deauth, |
| 740 | bool self_disconnected, u16 reason) |
| 741 | { |
| 742 | struct ieee80211_local *local = sdata->local; |
| 743 | struct sta_info *sta; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 744 | u32 changed = BSS_CHANGED_ASSOC; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 745 | |
| 746 | rcu_read_lock(); |
| 747 | |
| 748 | sta = sta_info_get(local, ifsta->bssid); |
| 749 | if (!sta) { |
| 750 | rcu_read_unlock(); |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | if (deauth) { |
| 755 | ifsta->direct_probe_tries = 0; |
| 756 | ifsta->auth_tries = 0; |
| 757 | } |
| 758 | ifsta->assoc_scan_tries = 0; |
| 759 | ifsta->assoc_tries = 0; |
| 760 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 761 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 762 | netif_carrier_off(sdata->dev); |
| 763 | |
| 764 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); |
| 765 | |
| 766 | if (self_disconnected) { |
| 767 | if (deauth) |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 768 | ieee80211_send_deauth_disassoc(sdata, |
| 769 | IEEE80211_STYPE_DEAUTH, reason); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 770 | else |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 771 | ieee80211_send_deauth_disassoc(sdata, |
| 772 | IEEE80211_STYPE_DISASSOC, reason); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 773 | } |
| 774 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 775 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 776 | changed |= ieee80211_reset_erp_info(sdata); |
| 777 | |
| 778 | if (sdata->bss_conf.assoc_ht) |
| 779 | changed |= BSS_CHANGED_HT; |
| 780 | |
| 781 | sdata->bss_conf.assoc_ht = 0; |
| 782 | sdata->bss_conf.ht_conf = NULL; |
| 783 | sdata->bss_conf.ht_bss_conf = NULL; |
| 784 | |
| 785 | ieee80211_led_assoc(local, 0); |
| 786 | sdata->bss_conf.assoc = 0; |
| 787 | |
| 788 | ieee80211_sta_send_apinfo(sdata, ifsta); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 789 | |
| 790 | if (self_disconnected) |
| 791 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 792 | |
| 793 | sta_info_unlink(&sta); |
| 794 | |
| 795 | rcu_read_unlock(); |
| 796 | |
| 797 | sta_info_destroy(sta); |
| 798 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 799 | |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 800 | static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) |
| 801 | { |
| 802 | if (!sdata || !sdata->default_key || |
| 803 | sdata->default_key->conf.alg != ALG_WEP) |
| 804 | return 0; |
| 805 | return 1; |
| 806 | } |
| 807 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 808 | static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 809 | struct ieee80211_if_sta *ifsta) |
| 810 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 811 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 812 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 813 | int bss_privacy; |
| 814 | int wep_privacy; |
| 815 | int privacy_invoked; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 816 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 817 | if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 818 | return 0; |
| 819 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 820 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 821 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 822 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 823 | if (!bss) |
| 824 | return 0; |
| 825 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 826 | bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 827 | wep_privacy = !!ieee80211_sta_wep_configured(sdata); |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 828 | privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 829 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 830 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 831 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 832 | if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked)) |
| 833 | return 0; |
| 834 | |
| 835 | return 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 838 | static void ieee80211_associate(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 839 | struct ieee80211_if_sta *ifsta) |
| 840 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 841 | DECLARE_MAC_BUF(mac); |
| 842 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 843 | ifsta->assoc_tries++; |
| 844 | if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 845 | printk(KERN_DEBUG "%s: association with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 846 | " timed out\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 847 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 848 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 849 | return; |
| 850 | } |
| 851 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 852 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 853 | printk(KERN_DEBUG "%s: associate with AP %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 854 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
| 855 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 856 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 857 | "mixed-cell disabled - abort association\n", sdata->dev->name); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 858 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 859 | return; |
| 860 | } |
| 861 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 862 | ieee80211_send_assoc(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 863 | |
| 864 | mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); |
| 865 | } |
| 866 | |
| 867 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 868 | static void ieee80211_associated(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 869 | struct ieee80211_if_sta *ifsta) |
| 870 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 871 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 872 | struct sta_info *sta; |
| 873 | int disassoc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 874 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 875 | |
| 876 | /* TODO: start monitoring current AP signal quality and number of |
| 877 | * missed beacons. Scan other channels every now and then and search |
| 878 | * for better APs. */ |
| 879 | /* TODO: remove expired BSSes */ |
| 880 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 881 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 882 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 883 | rcu_read_lock(); |
| 884 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 885 | sta = sta_info_get(local, ifsta->bssid); |
| 886 | if (!sta) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 887 | printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 888 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 889 | disassoc = 1; |
| 890 | } else { |
| 891 | disassoc = 0; |
| 892 | if (time_after(jiffies, |
| 893 | sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 894 | if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 895 | printk(KERN_DEBUG "%s: No ProbeResp from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 896 | "current AP %s - assume out of " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 897 | "range\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 898 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 899 | disassoc = 1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 900 | } else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 901 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 902 | local->scan_ssid, |
| 903 | local->scan_ssid_len); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 904 | ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 905 | } else { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 906 | ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 907 | if (time_after(jiffies, ifsta->last_probe + |
| 908 | IEEE80211_PROBE_INTERVAL)) { |
| 909 | ifsta->last_probe = jiffies; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 910 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 911 | ifsta->ssid, |
| 912 | ifsta->ssid_len); |
| 913 | } |
| 914 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 915 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 916 | |
| 917 | rcu_read_unlock(); |
| 918 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 919 | if (disassoc) |
| 920 | ieee80211_set_disassoc(sdata, ifsta, true, true, |
| 921 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 922 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 923 | mod_timer(&ifsta->timer, jiffies + |
| 924 | IEEE80211_MONITORING_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 928 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 929 | struct ieee80211_if_sta *ifsta) |
| 930 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 931 | printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 932 | ifsta->flags |= IEEE80211_STA_AUTHENTICATED; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 933 | ieee80211_associate(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 937 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 938 | struct ieee80211_if_sta *ifsta, |
| 939 | struct ieee80211_mgmt *mgmt, |
| 940 | size_t len) |
| 941 | { |
| 942 | u8 *pos; |
| 943 | struct ieee802_11_elems elems; |
| 944 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 945 | pos = mgmt->u.auth.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 946 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 947 | if (!elems.challenge) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 948 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 949 | ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 950 | elems.challenge_len + 2, 1); |
| 951 | } |
| 952 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 953 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 954 | struct ieee80211_if_sta *ifsta, |
| 955 | struct ieee80211_mgmt *mgmt, |
| 956 | size_t len) |
| 957 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 958 | u16 auth_alg, auth_transaction, status_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 959 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 960 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 961 | if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 962 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 963 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 964 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 965 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 966 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 967 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 968 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 969 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 970 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 971 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 972 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 973 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 974 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 975 | |
| 976 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 977 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 978 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 979 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 980 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Johannes Berg | 135a211 | 2008-06-16 20:55:29 +0200 | [diff] [blame] | 981 | /* |
| 982 | * IEEE 802.11 standard does not require authentication in IBSS |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 983 | * networks and most implementations do not seem to use it. |
| 984 | * However, try to reply to authentication attempts if someone |
| 985 | * has actually implemented this. |
Johannes Berg | 135a211 | 2008-06-16 20:55:29 +0200 | [diff] [blame] | 986 | */ |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 987 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 988 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 989 | ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | if (auth_alg != ifsta->auth_alg || |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 993 | auth_transaction != ifsta->auth_transaction) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 994 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 995 | |
| 996 | if (status_code != WLAN_STATUS_SUCCESS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 997 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
| 998 | u8 algs[3]; |
| 999 | const int num_algs = ARRAY_SIZE(algs); |
| 1000 | int i, pos; |
| 1001 | algs[0] = algs[1] = algs[2] = 0xff; |
| 1002 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 1003 | algs[0] = WLAN_AUTH_OPEN; |
| 1004 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 1005 | algs[1] = WLAN_AUTH_SHARED_KEY; |
| 1006 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 1007 | algs[2] = WLAN_AUTH_LEAP; |
| 1008 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) |
| 1009 | pos = 0; |
| 1010 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) |
| 1011 | pos = 1; |
| 1012 | else |
| 1013 | pos = 2; |
| 1014 | for (i = 0; i < num_algs; i++) { |
| 1015 | pos++; |
| 1016 | if (pos >= num_algs) |
| 1017 | pos = 0; |
| 1018 | if (algs[pos] == ifsta->auth_alg || |
| 1019 | algs[pos] == 0xff) |
| 1020 | continue; |
| 1021 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1022 | !ieee80211_sta_wep_configured(sdata)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1023 | continue; |
| 1024 | ifsta->auth_alg = algs[pos]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | } |
| 1028 | return; |
| 1029 | } |
| 1030 | |
| 1031 | switch (ifsta->auth_alg) { |
| 1032 | case WLAN_AUTH_OPEN: |
| 1033 | case WLAN_AUTH_LEAP: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1034 | ieee80211_auth_completed(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1035 | break; |
| 1036 | case WLAN_AUTH_SHARED_KEY: |
| 1037 | if (ifsta->auth_transaction == 4) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1038 | ieee80211_auth_completed(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1039 | else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1040 | ieee80211_auth_challenge(sdata, ifsta, mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1041 | break; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1046 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1047 | struct ieee80211_if_sta *ifsta, |
| 1048 | struct ieee80211_mgmt *mgmt, |
| 1049 | size_t len) |
| 1050 | { |
| 1051 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1052 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1053 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1054 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1055 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1056 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1057 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1058 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1059 | |
| 1060 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1061 | |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1062 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1063 | printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1064 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1065 | if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || |
| 1066 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || |
| 1067 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1068 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1069 | mod_timer(&ifsta->timer, jiffies + |
| 1070 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1071 | } |
| 1072 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1073 | ieee80211_set_disassoc(sdata, ifsta, true, false, 0); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1074 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1078 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1079 | struct ieee80211_if_sta *ifsta, |
| 1080 | struct ieee80211_mgmt *mgmt, |
| 1081 | size_t len) |
| 1082 | { |
| 1083 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1084 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1085 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1086 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1087 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1088 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1089 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1090 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1091 | |
| 1092 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 1093 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1094 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1095 | printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1096 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1097 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
| 1098 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1099 | mod_timer(&ifsta->timer, jiffies + |
| 1100 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1101 | } |
| 1102 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1103 | ieee80211_set_disassoc(sdata, ifsta, false, false, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1107 | static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1108 | struct ieee80211_if_sta *ifsta, |
| 1109 | struct ieee80211_mgmt *mgmt, |
| 1110 | size_t len, |
| 1111 | int reassoc) |
| 1112 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1113 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1114 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1115 | struct sta_info *sta; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1116 | u64 rates, basic_rates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1117 | u16 capab_info, status_code, aid; |
| 1118 | struct ieee802_11_elems elems; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1119 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1120 | u8 *pos; |
| 1121 | int i, j; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1122 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1123 | bool have_higher_than_11mbit = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1124 | |
| 1125 | /* AssocResp and ReassocResp have identical structure, so process both |
| 1126 | * of them in this function. */ |
| 1127 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1128 | if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1129 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1130 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1131 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1132 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1133 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1134 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1135 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1136 | |
| 1137 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 1138 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 1139 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1140 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1141 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1142 | "status=%d aid=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1143 | sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
Johannes Berg | ddd6858 | 2007-10-22 14:51:37 +0200 | [diff] [blame] | 1144 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1145 | |
| 1146 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1147 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1148 | sdata->dev->name, status_code); |
Daniel Drake | 8a69aa9 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1149 | /* if this was a reassociation, ensure we try a "full" |
| 1150 | * association next time. This works around some broken APs |
| 1151 | * which do not correctly reject reassociation requests. */ |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1152 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1153 | return; |
| 1154 | } |
| 1155 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1156 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 1157 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1158 | "set\n", sdata->dev->name, aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1159 | aid &= ~(BIT(15) | BIT(14)); |
| 1160 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1161 | pos = mgmt->u.assoc_resp.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1162 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1163 | |
| 1164 | if (!elems.supp_rates) { |
| 1165 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1166 | sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1167 | return; |
| 1168 | } |
| 1169 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1170 | printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1171 | ifsta->aid = aid; |
| 1172 | ifsta->ap_capab = capab_info; |
| 1173 | |
| 1174 | kfree(ifsta->assocresp_ies); |
| 1175 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1176 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1177 | if (ifsta->assocresp_ies) |
| 1178 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); |
| 1179 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1180 | rcu_read_lock(); |
| 1181 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1182 | /* Add STA entry for the AP */ |
| 1183 | sta = sta_info_get(local, ifsta->bssid); |
| 1184 | if (!sta) { |
| 1185 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1186 | int err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1187 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1188 | sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); |
| 1189 | if (!sta) { |
| 1190 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1191 | " the AP\n", sdata->dev->name); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1192 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1193 | return; |
| 1194 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1195 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1196 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1197 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1198 | if (bss) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1199 | sta->last_signal = bss->signal; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1200 | sta->last_qual = bss->qual; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1201 | sta->last_noise = bss->noise; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1202 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1203 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1204 | |
| 1205 | err = sta_info_insert(sta); |
| 1206 | if (err) { |
| 1207 | printk(KERN_DEBUG "%s: failed to insert STA entry for" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1208 | " the AP (error %d)\n", sdata->dev->name, err); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1209 | rcu_read_unlock(); |
| 1210 | return; |
| 1211 | } |
Ron Rindjunsky | a61dae1 | 2008-08-10 00:54:34 +0300 | [diff] [blame] | 1212 | /* update new sta with its last rx activity */ |
| 1213 | sta->last_rx = jiffies; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1216 | /* |
| 1217 | * FIXME: Do we really need to update the sta_info's information here? |
| 1218 | * We already know about the AP (we found it in our list) so it |
| 1219 | * should already be filled with the right info, no? |
| 1220 | * As is stands, all this is racy because typically we assume |
| 1221 | * the information that is filled in here (except flags) doesn't |
| 1222 | * change while a STA structure is alive. As such, it should move |
| 1223 | * to between the sta_info_alloc() and sta_info_insert() above. |
| 1224 | */ |
| 1225 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1226 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
| 1227 | WLAN_STA_AUTHORIZED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1228 | |
| 1229 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1230 | basic_rates = 0; |
| 1231 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1232 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1233 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 1234 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1235 | |
| 1236 | if (rate > 110) |
| 1237 | have_higher_than_11mbit = true; |
| 1238 | |
| 1239 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1240 | if (sband->bitrates[j].bitrate == rate) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1241 | rates |= BIT(j); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1242 | if (elems.supp_rates[i] & 0x80) |
| 1243 | basic_rates |= BIT(j); |
| 1244 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1245 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1246 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1247 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 1248 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1249 | |
| 1250 | if (rate > 110) |
| 1251 | have_higher_than_11mbit = true; |
| 1252 | |
| 1253 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1254 | if (sband->bitrates[j].bitrate == rate) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1255 | rates |= BIT(j); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1256 | if (elems.ext_supp_rates[i] & 0x80) |
| 1257 | basic_rates |= BIT(j); |
| 1258 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1259 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1260 | |
| 1261 | sta->supp_rates[local->hw.conf.channel->band] = rates; |
| 1262 | sdata->basic_rates = basic_rates; |
| 1263 | |
| 1264 | /* cf. IEEE 802.11 9.2.12 */ |
| 1265 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 1266 | have_higher_than_11mbit) |
| 1267 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 1268 | else |
| 1269 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1270 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1271 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
| 1272 | (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1273 | struct ieee80211_ht_bss_info bss_info; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1274 | ieee80211_ht_cap_ie_to_ht_info( |
| 1275 | (struct ieee80211_ht_cap *) |
| 1276 | elems.ht_cap_elem, &sta->ht_info); |
| 1277 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 1278 | (struct ieee80211_ht_addt_info *) |
| 1279 | elems.ht_info_elem, &bss_info); |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 1280 | ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1281 | } |
| 1282 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1283 | rate_control_rate_init(sta, local); |
| 1284 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1285 | if (elems.wmm_param) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1286 | set_sta_flags(sta, WLAN_STA_WME); |
Johannes Berg | e5f98f2 | 2008-03-05 20:39:31 +0100 | [diff] [blame] | 1287 | rcu_read_unlock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1288 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1289 | elems.wmm_param_len); |
Johannes Berg | e5f98f2 | 2008-03-05 20:39:31 +0100 | [diff] [blame] | 1290 | } else |
| 1291 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1292 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1293 | /* set AID and assoc capability, |
| 1294 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1295 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1296 | bss_conf->assoc_capability = capab_info; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1297 | ieee80211_set_associated(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1298 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1299 | ieee80211_associated(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1303 | static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1304 | struct ieee80211_if_sta *ifsta, |
| 1305 | struct ieee80211_sta_bss *bss) |
| 1306 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1307 | struct ieee80211_local *local = sdata->local; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1308 | int res, rates, i, j; |
| 1309 | struct sk_buff *skb; |
| 1310 | struct ieee80211_mgmt *mgmt; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1311 | u8 *pos; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1312 | struct ieee80211_supported_band *sband; |
Dan Williams | 507b06d | 2008-06-03 23:39:55 -0400 | [diff] [blame] | 1313 | union iwreq_data wrqu; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1314 | |
| 1315 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1316 | |
| 1317 | /* Remove possible STA entries from other IBSS networks. */ |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 1318 | sta_info_flush_delayed(sdata); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1319 | |
| 1320 | if (local->ops->reset_tsf) { |
| 1321 | /* Reset own TSF to allow time synchronization work. */ |
| 1322 | local->ops->reset_tsf(local_to_hw(local)); |
| 1323 | } |
| 1324 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1325 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1326 | if (res) |
| 1327 | return res; |
| 1328 | |
| 1329 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; |
| 1330 | |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1331 | sdata->drop_unencrypted = bss->capability & |
| 1332 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
| 1333 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1334 | res = ieee80211_set_freq(sdata, bss->freq); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1335 | |
Assaf Krauss | be038b3 | 2008-06-05 19:55:21 +0300 | [diff] [blame] | 1336 | if (res) |
| 1337 | return res; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1338 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1339 | /* Build IBSS probe response */ |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1340 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1341 | if (skb) { |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1342 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1343 | |
| 1344 | mgmt = (struct ieee80211_mgmt *) |
| 1345 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
| 1346 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1347 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1348 | IEEE80211_STYPE_PROBE_RESP); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1349 | memset(mgmt->da, 0xff, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1350 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1351 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 1352 | mgmt->u.beacon.beacon_int = |
| 1353 | cpu_to_le16(local->hw.conf.beacon_int); |
Assaf Krauss | 4faeb86 | 2008-06-30 17:23:16 +0800 | [diff] [blame] | 1354 | mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1355 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
| 1356 | |
| 1357 | pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 1358 | *pos++ = WLAN_EID_SSID; |
| 1359 | *pos++ = ifsta->ssid_len; |
| 1360 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 1361 | |
| 1362 | rates = bss->supp_rates_len; |
| 1363 | if (rates > 8) |
| 1364 | rates = 8; |
| 1365 | pos = skb_put(skb, 2 + rates); |
| 1366 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1367 | *pos++ = rates; |
| 1368 | memcpy(pos, bss->supp_rates, rates); |
| 1369 | |
| 1370 | if (bss->band == IEEE80211_BAND_2GHZ) { |
| 1371 | pos = skb_put(skb, 2 + 1); |
| 1372 | *pos++ = WLAN_EID_DS_PARAMS; |
| 1373 | *pos++ = 1; |
| 1374 | *pos++ = ieee80211_frequency_to_channel(bss->freq); |
| 1375 | } |
| 1376 | |
| 1377 | pos = skb_put(skb, 2 + 2); |
| 1378 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 1379 | *pos++ = 2; |
| 1380 | /* FIX: set ATIM window based on scan results */ |
| 1381 | *pos++ = 0; |
| 1382 | *pos++ = 0; |
| 1383 | |
| 1384 | if (bss->supp_rates_len > 8) { |
| 1385 | rates = bss->supp_rates_len - 8; |
| 1386 | pos = skb_put(skb, 2 + rates); |
| 1387 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1388 | *pos++ = rates; |
| 1389 | memcpy(pos, &bss->supp_rates[8], rates); |
| 1390 | } |
| 1391 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1392 | ifsta->probe_resp = skb; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1393 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1394 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1395 | } |
| 1396 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1397 | rates = 0; |
| 1398 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1399 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 1400 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; |
| 1401 | for (j = 0; j < sband->n_bitrates; j++) |
| 1402 | if (sband->bitrates[j].bitrate == bitrate) |
| 1403 | rates |= BIT(j); |
| 1404 | } |
| 1405 | ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates; |
| 1406 | |
Johannes Berg | b079ada | 2008-09-09 09:32:59 +0200 | [diff] [blame] | 1407 | ieee80211_sta_def_wmm_params(sdata, bss); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1408 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1409 | ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1410 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 1411 | |
Dan Williams | 507b06d | 2008-06-03 23:39:55 -0400 | [diff] [blame] | 1412 | memset(&wrqu, 0, sizeof(wrqu)); |
| 1413 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1414 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1415 | |
| 1416 | return res; |
| 1417 | } |
| 1418 | |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1419 | u64 ieee80211_sta_get_rates(struct ieee80211_local *local, |
| 1420 | struct ieee802_11_elems *elems, |
| 1421 | enum ieee80211_band band) |
| 1422 | { |
| 1423 | struct ieee80211_supported_band *sband; |
| 1424 | struct ieee80211_rate *bitrates; |
| 1425 | size_t num_rates; |
| 1426 | u64 supp_rates; |
| 1427 | int i, j; |
| 1428 | sband = local->hw.wiphy->bands[band]; |
| 1429 | |
| 1430 | if (!sband) { |
| 1431 | WARN_ON(1); |
| 1432 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1433 | } |
| 1434 | |
| 1435 | bitrates = sband->bitrates; |
| 1436 | num_rates = sband->n_bitrates; |
| 1437 | supp_rates = 0; |
| 1438 | for (i = 0; i < elems->supp_rates_len + |
| 1439 | elems->ext_supp_rates_len; i++) { |
| 1440 | u8 rate = 0; |
| 1441 | int own_rate; |
| 1442 | if (i < elems->supp_rates_len) |
| 1443 | rate = elems->supp_rates[i]; |
| 1444 | else if (elems->ext_supp_rates) |
| 1445 | rate = elems->ext_supp_rates |
| 1446 | [i - elems->supp_rates_len]; |
| 1447 | own_rate = 5 * (rate & 0x7f); |
| 1448 | for (j = 0; j < num_rates; j++) |
| 1449 | if (bitrates[j].bitrate == own_rate) |
| 1450 | supp_rates |= BIT(j); |
| 1451 | } |
| 1452 | return supp_rates; |
| 1453 | } |
| 1454 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1455 | static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local, |
| 1456 | enum ieee80211_band band) |
| 1457 | { |
| 1458 | struct ieee80211_supported_band *sband; |
| 1459 | struct ieee80211_rate *bitrates; |
| 1460 | u64 mandatory_rates; |
| 1461 | enum ieee80211_rate_flags mandatory_flag; |
| 1462 | int i; |
| 1463 | |
| 1464 | sband = local->hw.wiphy->bands[band]; |
| 1465 | if (!sband) { |
| 1466 | WARN_ON(1); |
| 1467 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1468 | } |
| 1469 | |
| 1470 | if (band == IEEE80211_BAND_2GHZ) |
| 1471 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 1472 | else |
| 1473 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 1474 | |
| 1475 | bitrates = sband->bitrates; |
| 1476 | mandatory_rates = 0; |
| 1477 | for (i = 0; i < sband->n_bitrates; i++) |
| 1478 | if (bitrates[i].flags & mandatory_flag) |
| 1479 | mandatory_rates |= BIT(i); |
| 1480 | return mandatory_rates; |
| 1481 | } |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 1482 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1483 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1484 | struct ieee80211_mgmt *mgmt, |
| 1485 | size_t len, |
| 1486 | struct ieee80211_rx_status *rx_status, |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1487 | struct ieee802_11_elems *elems, |
| 1488 | bool beacon) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1489 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1490 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1491 | int freq; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1492 | struct ieee80211_sta_bss *bss; |
| 1493 | struct sta_info *sta; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 1494 | struct ieee80211_channel *channel; |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1495 | u64 beacon_timestamp, rx_timestamp; |
| 1496 | u64 supp_rates = 0; |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1497 | enum ieee80211_band band = rx_status->band; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1498 | DECLARE_MAC_BUF(mac); |
| 1499 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1500 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 1501 | if (elems->ds_params && elems->ds_params_len == 1) |
| 1502 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); |
| 1503 | else |
| 1504 | freq = rx_status->freq; |
| 1505 | |
| 1506 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 1507 | |
| 1508 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 1509 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1510 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1511 | if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1512 | elems->mesh_config && mesh_matches_local(elems, sdata)) { |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1513 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1514 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1515 | mesh_neighbour_update(mgmt->sa, supp_rates, sdata, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1516 | mesh_peer_accepts_plinks(elems)); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 1517 | } |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1518 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1519 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates && |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1520 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1521 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
| 1522 | |
Johannes Berg | 69e6c01 | 2008-09-08 11:05:08 +0200 | [diff] [blame] | 1523 | rcu_read_lock(); |
| 1524 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1525 | sta = sta_info_get(local, mgmt->sa); |
| 1526 | if (sta) { |
| 1527 | u64 prev_rates; |
| 1528 | |
| 1529 | prev_rates = sta->supp_rates[band]; |
| 1530 | /* make sure mandatory rates are always added */ |
| 1531 | sta->supp_rates[band] = supp_rates | |
| 1532 | ieee80211_sta_get_mandatory_rates(local, band); |
| 1533 | |
| 1534 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1535 | if (sta->supp_rates[band] != prev_rates) |
| 1536 | printk(KERN_DEBUG "%s: updated supp_rates set " |
| 1537 | "for %s based on beacon info (0x%llx | " |
| 1538 | "0x%llx -> 0x%llx)\n", |
| 1539 | sdata->dev->name, print_mac(mac, sta->addr), |
| 1540 | (unsigned long long) prev_rates, |
| 1541 | (unsigned long long) supp_rates, |
| 1542 | (unsigned long long) sta->supp_rates[band]); |
| 1543 | #endif |
| 1544 | } else { |
| 1545 | ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, |
| 1546 | mgmt->sa, supp_rates); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1547 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1548 | |
Johannes Berg | 69e6c01 | 2008-09-08 11:05:08 +0200 | [diff] [blame] | 1549 | rcu_read_unlock(); |
| 1550 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1551 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1552 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
| 1553 | freq, beacon); |
| 1554 | if (!bss) |
| 1555 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1556 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1557 | /* was just updated in ieee80211_bss_info_update */ |
| 1558 | beacon_timestamp = bss->timestamp; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1559 | |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 1560 | /* |
| 1561 | * In STA mode, the remaining parameters should not be overridden |
| 1562 | * by beacons because they're not necessarily accurate there. |
| 1563 | */ |
| 1564 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1565 | bss->last_probe_resp && beacon) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1566 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 1567 | return; |
| 1568 | } |
| 1569 | |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1570 | /* check if we need to merge IBSS */ |
| 1571 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && |
Johannes Berg | fba4a1e | 2008-02-21 11:08:33 +0100 | [diff] [blame] | 1572 | bss->capability & WLAN_CAPABILITY_IBSS && |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1573 | bss->freq == local->oper_channel->center_freq && |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1574 | elems->ssid_len == sdata->u.sta.ssid_len && |
| 1575 | memcmp(elems->ssid, sdata->u.sta.ssid, |
| 1576 | sdata->u.sta.ssid_len) == 0) { |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1577 | if (rx_status->flag & RX_FLAG_TSFT) { |
| 1578 | /* in order for correct IBSS merging we need mactime |
| 1579 | * |
| 1580 | * since mactime is defined as the time the first data |
| 1581 | * symbol of the frame hits the PHY, and the timestamp |
| 1582 | * of the beacon is defined as "the time that the data |
| 1583 | * symbol containing the first bit of the timestamp is |
| 1584 | * transmitted to the PHY plus the transmitting STA’s |
| 1585 | * delays through its local PHY from the MAC-PHY |
| 1586 | * interface to its interface with the WM" |
| 1587 | * (802.11 11.1.2) - equals the time this bit arrives at |
| 1588 | * the receiver - we have to take into account the |
| 1589 | * offset between the two. |
| 1590 | * e.g: at 1 MBit that means mactime is 192 usec earlier |
| 1591 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. |
| 1592 | */ |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1593 | int rate = local->hw.wiphy->bands[band]-> |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1594 | bitrates[rx_status->rate_idx].bitrate; |
| 1595 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); |
| 1596 | } else if (local && local->ops && local->ops->get_tsf) |
| 1597 | /* second best option: get current TSF */ |
| 1598 | rx_timestamp = local->ops->get_tsf(local_to_hw(local)); |
| 1599 | else |
| 1600 | /* can't merge without knowing the TSF */ |
| 1601 | rx_timestamp = -1LLU; |
| 1602 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1603 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" |
| 1604 | "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", |
| 1605 | print_mac(mac, mgmt->sa), |
| 1606 | print_mac(mac2, mgmt->bssid), |
| 1607 | (unsigned long long)rx_timestamp, |
| 1608 | (unsigned long long)beacon_timestamp, |
| 1609 | (unsigned long long)(rx_timestamp - beacon_timestamp), |
| 1610 | jiffies); |
| 1611 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1612 | if (beacon_timestamp > rx_timestamp) { |
John W. Linville | 576fdea | 2008-08-26 20:33:34 -0400 | [diff] [blame] | 1613 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1614 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
| 1615 | "local TSF - IBSS merge with BSSID %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1616 | sdata->dev->name, print_mac(mac, mgmt->bssid)); |
Johannes Berg | fba4a1e | 2008-02-21 11:08:33 +0100 | [diff] [blame] | 1617 | #endif |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1618 | ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss); |
| 1619 | ieee80211_ibss_add_sta(sdata, NULL, |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 1620 | mgmt->bssid, mgmt->sa, |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 1621 | supp_rates); |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1625 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1629 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1630 | struct ieee80211_mgmt *mgmt, |
| 1631 | size_t len, |
| 1632 | struct ieee80211_rx_status *rx_status) |
| 1633 | { |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1634 | size_t baselen; |
| 1635 | struct ieee802_11_elems elems; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1636 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1637 | |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 1638 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
| 1639 | return; /* ignore ProbeResp to foreign address */ |
| 1640 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1641 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 1642 | if (baselen > len) |
| 1643 | return; |
| 1644 | |
| 1645 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 1646 | &elems); |
| 1647 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1648 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1649 | |
| 1650 | /* direct probe may be part of the association flow */ |
| 1651 | if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, |
| 1652 | &ifsta->request)) { |
| 1653 | printk(KERN_DEBUG "%s direct probe responded\n", |
| 1654 | sdata->dev->name); |
| 1655 | ieee80211_authenticate(sdata, ifsta); |
| 1656 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1660 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1661 | struct ieee80211_mgmt *mgmt, |
| 1662 | size_t len, |
| 1663 | struct ieee80211_rx_status *rx_status) |
| 1664 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1665 | struct ieee80211_if_sta *ifsta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1666 | size_t baselen; |
| 1667 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1668 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1669 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1670 | u32 changed = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1671 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1672 | /* Process beacon from the current BSS */ |
| 1673 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1674 | if (baselen > len) |
| 1675 | return; |
| 1676 | |
| 1677 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
| 1678 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1679 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1680 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1681 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1682 | return; |
| 1683 | ifsta = &sdata->u.sta; |
| 1684 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1685 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1686 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
| 1687 | return; |
| 1688 | |
Johannes Berg | fe3fa82 | 2008-09-08 11:05:09 +0200 | [diff] [blame] | 1689 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
| 1690 | elems.wmm_param_len); |
| 1691 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1692 | if (elems.erp_info && elems.erp_info_len >= 1) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1693 | changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 1694 | else { |
| 1695 | u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info); |
| 1696 | changed |= ieee80211_handle_protect_preamb(sdata, false, |
| 1697 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); |
| 1698 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1699 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1700 | if (elems.ht_cap_elem && elems.ht_info_elem && |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 1701 | elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1702 | struct ieee80211_ht_bss_info bss_info; |
| 1703 | |
| 1704 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 1705 | (struct ieee80211_ht_addt_info *) |
| 1706 | elems.ht_info_elem, &bss_info); |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 1707 | changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf, |
| 1708 | &bss_info); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1709 | } |
| 1710 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1711 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1715 | static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1716 | struct ieee80211_if_sta *ifsta, |
| 1717 | struct ieee80211_mgmt *mgmt, |
| 1718 | size_t len, |
| 1719 | struct ieee80211_rx_status *rx_status) |
| 1720 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1721 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1722 | int tx_last_beacon; |
| 1723 | struct sk_buff *skb; |
| 1724 | struct ieee80211_mgmt *resp; |
| 1725 | u8 *pos, *end; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1726 | DECLARE_MAC_BUF(mac); |
| 1727 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1728 | DECLARE_MAC_BUF(mac2); |
| 1729 | DECLARE_MAC_BUF(mac3); |
| 1730 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1731 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1732 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1733 | ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1734 | len < 24 + 2 || !ifsta->probe_resp) |
| 1735 | return; |
| 1736 | |
| 1737 | if (local->ops->tx_last_beacon) |
| 1738 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); |
| 1739 | else |
| 1740 | tx_last_beacon = 1; |
| 1741 | |
| 1742 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1743 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
| 1744 | "%s (tx_last_beacon=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1745 | sdata->dev->name, print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->da), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1746 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1747 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 1748 | |
| 1749 | if (!tx_last_beacon) |
| 1750 | return; |
| 1751 | |
| 1752 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && |
| 1753 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 1754 | return; |
| 1755 | |
| 1756 | end = ((u8 *) mgmt) + len; |
| 1757 | pos = mgmt->u.probe_req.variable; |
| 1758 | if (pos[0] != WLAN_EID_SSID || |
| 1759 | pos + 2 + pos[1] > end) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1760 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 1761 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
| 1762 | "from %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1763 | sdata->dev->name, print_mac(mac, mgmt->sa)); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1764 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1765 | return; |
| 1766 | } |
| 1767 | if (pos[1] != 0 && |
| 1768 | (pos[1] != ifsta->ssid_len || |
| 1769 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { |
| 1770 | /* Ignore ProbeReq for foreign SSID */ |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | /* Reply with ProbeResp */ |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1775 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1776 | if (!skb) |
| 1777 | return; |
| 1778 | |
| 1779 | resp = (struct ieee80211_mgmt *) skb->data; |
| 1780 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 1781 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1782 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1783 | sdata->dev->name, print_mac(mac, resp->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1784 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame^] | 1785 | ieee80211_tx_skb(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1788 | static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 4e20cb2 | 2007-12-19 01:31:24 +0100 | [diff] [blame] | 1789 | struct ieee80211_if_sta *ifsta, |
| 1790 | struct ieee80211_mgmt *mgmt, |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1791 | size_t len, |
| 1792 | struct ieee80211_rx_status *rx_status) |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1793 | { |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1794 | /* currently we only handle mesh interface action frames here */ |
| 1795 | if (!ieee80211_vif_is_mesh(&sdata->vif)) |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1796 | return; |
| 1797 | |
| 1798 | switch (mgmt->u.action.category) { |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1799 | case PLINK_CATEGORY: |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1800 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1801 | break; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1802 | case MESH_PATH_SEL_CATEGORY: |
Johannes Berg | 39192c0 | 2008-09-09 14:49:03 +0200 | [diff] [blame] | 1803 | mesh_rx_path_sel_frame(sdata, mgmt, len); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1804 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1805 | } |
| 1806 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1807 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1808 | void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1809 | struct ieee80211_rx_status *rx_status) |
| 1810 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1811 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1812 | struct ieee80211_if_sta *ifsta; |
| 1813 | struct ieee80211_mgmt *mgmt; |
| 1814 | u16 fc; |
| 1815 | |
| 1816 | if (skb->len < 24) |
| 1817 | goto fail; |
| 1818 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1819 | ifsta = &sdata->u.sta; |
| 1820 | |
| 1821 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1822 | fc = le16_to_cpu(mgmt->frame_control); |
| 1823 | |
| 1824 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1825 | case IEEE80211_STYPE_PROBE_REQ: |
| 1826 | case IEEE80211_STYPE_PROBE_RESP: |
| 1827 | case IEEE80211_STYPE_BEACON: |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1828 | case IEEE80211_STYPE_ACTION: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1829 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
| 1830 | case IEEE80211_STYPE_AUTH: |
| 1831 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1832 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1833 | case IEEE80211_STYPE_DEAUTH: |
| 1834 | case IEEE80211_STYPE_DISASSOC: |
| 1835 | skb_queue_tail(&ifsta->skb_queue, skb); |
| 1836 | queue_work(local->hw.workqueue, &ifsta->work); |
| 1837 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | fail: |
| 1841 | kfree_skb(skb); |
| 1842 | } |
| 1843 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1844 | static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1845 | struct sk_buff *skb) |
| 1846 | { |
| 1847 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1848 | struct ieee80211_if_sta *ifsta; |
| 1849 | struct ieee80211_mgmt *mgmt; |
| 1850 | u16 fc; |
| 1851 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1852 | ifsta = &sdata->u.sta; |
| 1853 | |
| 1854 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 1855 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1856 | fc = le16_to_cpu(mgmt->frame_control); |
| 1857 | |
| 1858 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1859 | case IEEE80211_STYPE_PROBE_REQ: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1860 | ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1861 | rx_status); |
| 1862 | break; |
| 1863 | case IEEE80211_STYPE_PROBE_RESP: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1864 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1865 | break; |
| 1866 | case IEEE80211_STYPE_BEACON: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1867 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1868 | break; |
| 1869 | case IEEE80211_STYPE_AUTH: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1870 | ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1871 | break; |
| 1872 | case IEEE80211_STYPE_ASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1873 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1874 | break; |
| 1875 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1876 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1877 | break; |
| 1878 | case IEEE80211_STYPE_DEAUTH: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1879 | ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1880 | break; |
| 1881 | case IEEE80211_STYPE_DISASSOC: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1882 | ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1883 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1884 | case IEEE80211_STYPE_ACTION: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1885 | ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1886 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1887 | } |
| 1888 | |
| 1889 | kfree_skb(skb); |
| 1890 | } |
| 1891 | |
| 1892 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1893 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1894 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1895 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1896 | int active = 0; |
| 1897 | struct sta_info *sta; |
| 1898 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1899 | rcu_read_lock(); |
| 1900 | |
| 1901 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 1902 | if (sta->sdata == sdata && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1903 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 1904 | jiffies)) { |
| 1905 | active++; |
| 1906 | break; |
| 1907 | } |
| 1908 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1909 | |
| 1910 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1911 | |
| 1912 | return active; |
| 1913 | } |
| 1914 | |
| 1915 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1916 | static void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, unsigned long exp_time) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1917 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1918 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1919 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1920 | LIST_HEAD(tmp_list); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1921 | DECLARE_MAC_BUF(mac); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1922 | unsigned long flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1923 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1924 | spin_lock_irqsave(&local->sta_lock, flags); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1925 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1926 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1927 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1928 | printk(KERN_DEBUG "%s: expiring inactive STA %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1929 | sdata->dev->name, print_mac(mac, sta->addr)); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1930 | #endif |
Luis Carlos Cobo | cb585bc | 2008-03-31 15:21:23 -0700 | [diff] [blame] | 1931 | __sta_info_unlink(&sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1932 | if (sta) |
| 1933 | list_add(&sta->list, &tmp_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1934 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1935 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1936 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1937 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) |
| 1938 | sta_info_destroy(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1942 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1943 | struct ieee80211_if_sta *ifsta) |
| 1944 | { |
| 1945 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 1946 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1947 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
| 1948 | if (ieee80211_sta_active_ibss(sdata)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1949 | return; |
| 1950 | |
| 1951 | printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1952 | "IBSS networks with same SSID (merge)\n", sdata->dev->name); |
| 1953 | ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1957 | #ifdef CONFIG_MAC80211_MESH |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1958 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1959 | struct ieee80211_if_sta *ifsta) |
| 1960 | { |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1961 | bool free_plinks; |
| 1962 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1963 | ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); |
| 1964 | mesh_path_expire(sdata); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1965 | |
| 1966 | free_plinks = mesh_plink_availables(sdata); |
| 1967 | if (free_plinks != sdata->u.sta.accepting_plinks) |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 1968 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1969 | |
| 1970 | mod_timer(&ifsta->timer, jiffies + |
| 1971 | IEEE80211_MESH_HOUSEKEEPING_INTERVAL); |
| 1972 | } |
| 1973 | |
| 1974 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1975 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1976 | { |
| 1977 | struct ieee80211_if_sta *ifsta; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1978 | ifsta = &sdata->u.sta; |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1979 | ifsta->state = IEEE80211_STA_MLME_MESH_UP; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1980 | ieee80211_sta_timer((unsigned long)sdata); |
Luis Carlos Cobo | 56a6d13 | 2008-07-29 19:59:31 +0200 | [diff] [blame] | 1981 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 1982 | } |
| 1983 | #endif |
| 1984 | |
| 1985 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1986 | void ieee80211_sta_timer(unsigned long data) |
| 1987 | { |
| 1988 | struct ieee80211_sub_if_data *sdata = |
| 1989 | (struct ieee80211_sub_if_data *) data; |
| 1990 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1991 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1992 | |
| 1993 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 1994 | queue_work(local->hw.workqueue, &ifsta->work); |
| 1995 | } |
| 1996 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1997 | static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1998 | struct ieee80211_if_sta *ifsta) |
| 1999 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2000 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2001 | |
| 2002 | if (local->ops->reset_tsf) { |
| 2003 | /* Reset own TSF to allow time synchronization work. */ |
| 2004 | local->ops->reset_tsf(local_to_hw(local)); |
| 2005 | } |
| 2006 | |
| 2007 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ |
| 2008 | |
| 2009 | |
| 2010 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 2011 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 2012 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 2013 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 2014 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 2015 | ifsta->auth_alg = WLAN_AUTH_LEAP; |
| 2016 | else |
| 2017 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2018 | ifsta->auth_transaction = -1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2019 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 2020 | ifsta->assoc_scan_tries = 0; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2021 | ifsta->direct_probe_tries = 0; |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 2022 | ifsta->auth_tries = 0; |
| 2023 | ifsta->assoc_tries = 0; |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 2024 | netif_tx_stop_all_queues(sdata->dev); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2025 | netif_carrier_off(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2029 | void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2030 | struct ieee80211_if_sta *ifsta) |
| 2031 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2032 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2033 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2034 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2035 | return; |
| 2036 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2037 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
Tomas Winkler | 3b7ee69 | 2008-09-08 17:33:38 +0200 | [diff] [blame] | 2038 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2039 | (ifsta->flags & (IEEE80211_STA_SSID_SET | |
Tomas Winkler | 3b7ee69 | 2008-09-08 17:33:38 +0200 | [diff] [blame] | 2040 | IEEE80211_STA_AUTO_SSID_SEL))) { |
| 2041 | |
| 2042 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) |
| 2043 | ieee80211_set_disassoc(sdata, ifsta, true, true, |
| 2044 | WLAN_REASON_DEAUTH_LEAVING); |
| 2045 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2046 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2047 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, |
| 2052 | const char *ssid, int ssid_len) |
| 2053 | { |
| 2054 | int tmp, hidden_ssid; |
| 2055 | |
Michael Wu | 4822570 | 2007-10-19 17:14:36 -0400 | [diff] [blame] | 2056 | if (ssid_len == ifsta->ssid_len && |
| 2057 | !memcmp(ifsta->ssid, ssid, ssid_len)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2058 | return 1; |
| 2059 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2060 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2061 | return 0; |
| 2062 | |
| 2063 | hidden_ssid = 1; |
| 2064 | tmp = ssid_len; |
| 2065 | while (tmp--) { |
| 2066 | if (ssid[tmp] != '\0') { |
| 2067 | hidden_ssid = 0; |
| 2068 | break; |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | if (hidden_ssid && ifsta->ssid_len == ssid_len) |
| 2073 | return 1; |
| 2074 | |
| 2075 | if (ssid_len == 1 && ssid[0] == ' ') |
| 2076 | return 1; |
| 2077 | |
| 2078 | return 0; |
| 2079 | } |
| 2080 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2081 | static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2082 | struct ieee80211_if_sta *ifsta) |
| 2083 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2084 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2085 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2086 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2087 | u8 bssid[ETH_ALEN], *pos; |
| 2088 | int i; |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 2089 | int ret; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2090 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2091 | |
| 2092 | #if 0 |
| 2093 | /* Easier testing, use fixed BSSID. */ |
| 2094 | memset(bssid, 0xfe, ETH_ALEN); |
| 2095 | #else |
| 2096 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 2097 | * own MAC address to make sure that devices that do not have proper |
| 2098 | * random number generator get different BSSID. */ |
| 2099 | get_random_bytes(bssid, ETH_ALEN); |
| 2100 | for (i = 0; i < ETH_ALEN; i++) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2101 | bssid[i] ^= sdata->dev->dev_addr[i]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2102 | bssid[0] &= ~0x01; |
| 2103 | bssid[0] |= 0x02; |
| 2104 | #endif |
| 2105 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2106 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2107 | sdata->dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2108 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2109 | bss = ieee80211_rx_bss_add(local, bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2110 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 2111 | sdata->u.sta.ssid, sdata->u.sta.ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2112 | if (!bss) |
| 2113 | return -ENOMEM; |
| 2114 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2115 | bss->band = local->hw.conf.channel->band; |
| 2116 | sband = local->hw.wiphy->bands[bss->band]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2117 | |
| 2118 | if (local->hw.conf.beacon_int == 0) |
Tomas Winkler | dc0ae30 | 2008-06-12 22:38:37 +0300 | [diff] [blame] | 2119 | local->hw.conf.beacon_int = 100; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2120 | bss->beacon_int = local->hw.conf.beacon_int; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2121 | bss->last_update = jiffies; |
| 2122 | bss->capability = WLAN_CAPABILITY_IBSS; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2123 | |
| 2124 | if (sdata->default_key) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2125 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2126 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2127 | sdata->drop_unencrypted = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2128 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2129 | bss->supp_rates_len = sband->n_bitrates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2130 | pos = bss->supp_rates; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2131 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2132 | int rate = sband->bitrates[i].bitrate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2133 | *pos++ = (u8) (rate / 5); |
| 2134 | } |
| 2135 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2136 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2137 | ieee80211_rx_bss_put(local, bss); |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 2138 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2142 | static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2143 | struct ieee80211_if_sta *ifsta) |
| 2144 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2145 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2146 | struct ieee80211_sta_bss *bss; |
| 2147 | int found = 0; |
| 2148 | u8 bssid[ETH_ALEN]; |
| 2149 | int active_ibss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2150 | DECLARE_MAC_BUF(mac); |
| 2151 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2152 | |
| 2153 | if (ifsta->ssid_len == 0) |
| 2154 | return -EINVAL; |
| 2155 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2156 | active_ibss = ieee80211_sta_active_ibss(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2157 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2158 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2159 | sdata->dev->name, active_ibss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2160 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2161 | spin_lock_bh(&local->sta_bss_lock); |
| 2162 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2163 | if (ifsta->ssid_len != bss->ssid_len || |
| 2164 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 |
| 2165 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) |
| 2166 | continue; |
| 2167 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2168 | printk(KERN_DEBUG " bssid=%s found\n", |
| 2169 | print_mac(mac, bss->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2170 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2171 | memcpy(bssid, bss->bssid, ETH_ALEN); |
| 2172 | found = 1; |
| 2173 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) |
| 2174 | break; |
| 2175 | } |
| 2176 | spin_unlock_bh(&local->sta_bss_lock); |
| 2177 | |
| 2178 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Vladimir Koutny | 6e43829 | 2008-07-07 14:23:01 +0200 | [diff] [blame] | 2179 | if (found) |
| 2180 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " |
| 2181 | "%s\n", print_mac(mac, bssid), |
| 2182 | print_mac(mac2, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2183 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 2184 | |
| 2185 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 2186 | int ret; |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 2187 | int search_freq; |
| 2188 | |
| 2189 | if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) |
| 2190 | search_freq = bss->freq; |
| 2191 | else |
| 2192 | search_freq = local->hw.conf.channel->center_freq; |
| 2193 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2194 | bss = ieee80211_rx_bss_get(local, bssid, search_freq, |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 2195 | ifsta->ssid, ifsta->ssid_len); |
| 2196 | if (!bss) |
| 2197 | goto dont_join; |
| 2198 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2199 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2200 | " based on configured SSID\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2201 | sdata->dev->name, print_mac(mac, bssid)); |
| 2202 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2203 | ieee80211_rx_bss_put(local, bss); |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 2204 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2205 | } |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 2206 | |
| 2207 | dont_join: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2208 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2209 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 2210 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2211 | |
| 2212 | /* Selected IBSS not found in current scan results - try to scan */ |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2213 | if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2214 | !ieee80211_sta_active_ibss(sdata)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2215 | mod_timer(&ifsta->timer, jiffies + |
| 2216 | IEEE80211_IBSS_MERGE_INTERVAL); |
| 2217 | } else if (time_after(jiffies, local->last_scan_completed + |
| 2218 | IEEE80211_SCAN_INTERVAL)) { |
| 2219 | printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2220 | "join\n", sdata->dev->name); |
| 2221 | return ieee80211_sta_req_scan(sdata, ifsta->ssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2222 | ifsta->ssid_len); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2223 | } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2224 | int interval = IEEE80211_SCAN_INTERVAL; |
| 2225 | |
| 2226 | if (time_after(jiffies, ifsta->ibss_join_req + |
| 2227 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2228 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2229 | (!(local->oper_channel->flags & |
| 2230 | IEEE80211_CHAN_NO_IBSS))) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2231 | return ieee80211_sta_create_ibss(sdata, ifsta); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2232 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2233 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2234 | " %d MHz\n", sdata->dev->name, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2235 | local->hw.conf.channel->center_freq); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | /* No IBSS found - decrease scan interval and continue |
| 2239 | * scanning. */ |
| 2240 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 2241 | } |
| 2242 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2243 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2244 | mod_timer(&ifsta->timer, jiffies + interval); |
| 2245 | return 0; |
| 2246 | } |
| 2247 | |
| 2248 | return 0; |
| 2249 | } |
| 2250 | |
| 2251 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2252 | int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2253 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2254 | struct ieee80211_if_sta *ifsta; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2255 | int res; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2256 | |
| 2257 | if (len > IEEE80211_MAX_SSID_LEN) |
| 2258 | return -EINVAL; |
| 2259 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2260 | ifsta = &sdata->u.sta; |
| 2261 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2262 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) { |
| 2263 | memset(ifsta->ssid, 0, sizeof(ifsta->ssid)); |
| 2264 | memcpy(ifsta->ssid, ssid, len); |
| 2265 | ifsta->ssid_len = len; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2266 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2267 | |
| 2268 | res = 0; |
| 2269 | /* |
| 2270 | * Hack! MLME code needs to be cleaned up to have different |
| 2271 | * entry points for configuration and internal selection change |
| 2272 | */ |
| 2273 | if (netif_running(sdata->dev)) |
| 2274 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID); |
| 2275 | if (res) { |
| 2276 | printk(KERN_DEBUG "%s: Failed to config new SSID to " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2277 | "the low-level driver\n", sdata->dev->name); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2278 | return res; |
| 2279 | } |
| 2280 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2281 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2282 | if (len) |
| 2283 | ifsta->flags |= IEEE80211_STA_SSID_SET; |
| 2284 | else |
| 2285 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2286 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2287 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2288 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2289 | ifsta->ibss_join_req = jiffies; |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2290 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2291 | return ieee80211_sta_find_ibss(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2292 | } |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2293 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2294 | return 0; |
| 2295 | } |
| 2296 | |
| 2297 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2298 | int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2299 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2300 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2301 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); |
| 2302 | *len = ifsta->ssid_len; |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2307 | int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2308 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2309 | struct ieee80211_if_sta *ifsta; |
| 2310 | int res; |
| 2311 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2312 | ifsta = &sdata->u.sta; |
| 2313 | |
| 2314 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
| 2315 | memcpy(ifsta->bssid, bssid, ETH_ALEN); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2316 | res = 0; |
| 2317 | /* |
| 2318 | * Hack! See also ieee80211_sta_set_ssid. |
| 2319 | */ |
| 2320 | if (netif_running(sdata->dev)) |
| 2321 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2322 | if (res) { |
| 2323 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2324 | "the low-level driver\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2325 | return res; |
| 2326 | } |
| 2327 | } |
| 2328 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2329 | if (is_valid_ether_addr(bssid)) |
| 2330 | ifsta->flags |= IEEE80211_STA_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2331 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2332 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; |
| 2333 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2334 | return 0; |
| 2335 | } |
| 2336 | |
| 2337 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2338 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2339 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2340 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2341 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2342 | kfree(ifsta->extra_ie); |
| 2343 | if (len == 0) { |
| 2344 | ifsta->extra_ie = NULL; |
| 2345 | ifsta->extra_ie_len = 0; |
| 2346 | return 0; |
| 2347 | } |
| 2348 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); |
| 2349 | if (!ifsta->extra_ie) { |
| 2350 | ifsta->extra_ie_len = 0; |
| 2351 | return -ENOMEM; |
| 2352 | } |
| 2353 | memcpy(ifsta->extra_ie, ie, len); |
| 2354 | ifsta->extra_ie_len = len; |
| 2355 | return 0; |
| 2356 | } |
| 2357 | |
| 2358 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2359 | struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2360 | struct sk_buff *skb, u8 *bssid, |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 2361 | u8 *addr, u64 supp_rates) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2362 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2363 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2364 | struct sta_info *sta; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2365 | DECLARE_MAC_BUF(mac); |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 2366 | int band = local->hw.conf.channel->band; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2367 | |
| 2368 | /* TODO: Could consider removing the least recently used entry and |
| 2369 | * allow new one to be added. */ |
| 2370 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
| 2371 | if (net_ratelimit()) { |
| 2372 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2373 | "entry %s\n", sdata->dev->name, print_mac(mac, addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2374 | } |
| 2375 | return NULL; |
| 2376 | } |
| 2377 | |
Emmanuel Grumbach | 1e18863 | 2008-07-10 17:54:14 +0300 | [diff] [blame] | 2378 | if (compare_ether_addr(bssid, sdata->u.sta.bssid)) |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 2379 | return NULL; |
| 2380 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2381 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2382 | printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2383 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2384 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2385 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2386 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
| 2387 | if (!sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2388 | return NULL; |
| 2389 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 2390 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
Johannes Berg | 238814f | 2008-01-28 17:19:37 +0100 | [diff] [blame] | 2391 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2392 | /* make sure mandatory rates are always added */ |
| 2393 | sta->supp_rates[band] = supp_rates | |
| 2394 | ieee80211_sta_get_mandatory_rates(local, band); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2395 | |
| 2396 | rate_control_rate_init(sta, local); |
| 2397 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 2398 | if (sta_info_insert(sta)) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2399 | return NULL; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2400 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2401 | return sta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2402 | } |
| 2403 | |
| 2404 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2405 | static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata, |
| 2406 | struct ieee80211_if_sta *ifsta) |
| 2407 | { |
| 2408 | struct ieee80211_local *local = sdata->local; |
| 2409 | struct ieee80211_sta_bss *bss, *selected = NULL; |
| 2410 | int top_rssi = 0, freq; |
| 2411 | |
| 2412 | spin_lock_bh(&local->sta_bss_lock); |
| 2413 | freq = local->oper_channel->center_freq; |
| 2414 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 2415 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) |
| 2416 | continue; |
| 2417 | |
| 2418 | if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
| 2419 | IEEE80211_STA_AUTO_BSSID_SEL | |
| 2420 | IEEE80211_STA_AUTO_CHANNEL_SEL)) && |
| 2421 | (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ |
| 2422 | !!sdata->default_key)) |
| 2423 | continue; |
| 2424 | |
| 2425 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && |
| 2426 | bss->freq != freq) |
| 2427 | continue; |
| 2428 | |
| 2429 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && |
| 2430 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) |
| 2431 | continue; |
| 2432 | |
| 2433 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && |
| 2434 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) |
| 2435 | continue; |
| 2436 | |
| 2437 | if (!selected || top_rssi < bss->signal) { |
| 2438 | selected = bss; |
| 2439 | top_rssi = bss->signal; |
| 2440 | } |
| 2441 | } |
| 2442 | if (selected) |
| 2443 | atomic_inc(&selected->users); |
| 2444 | spin_unlock_bh(&local->sta_bss_lock); |
| 2445 | |
| 2446 | if (selected) { |
| 2447 | ieee80211_set_freq(sdata, selected->freq); |
| 2448 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) |
| 2449 | ieee80211_sta_set_ssid(sdata, selected->ssid, |
| 2450 | selected->ssid_len); |
| 2451 | ieee80211_sta_set_bssid(sdata, selected->bssid); |
Johannes Berg | b079ada | 2008-09-09 09:32:59 +0200 | [diff] [blame] | 2452 | ieee80211_sta_def_wmm_params(sdata, selected); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2453 | |
| 2454 | /* Send out direct probe if no probe resp was received or |
| 2455 | * the one we have is outdated |
| 2456 | */ |
| 2457 | if (!selected->last_probe_resp || |
| 2458 | time_after(jiffies, selected->last_probe_resp |
| 2459 | + IEEE80211_SCAN_RESULT_EXPIRE)) |
| 2460 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 2461 | else |
| 2462 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
| 2463 | |
| 2464 | ieee80211_rx_bss_put(local, selected); |
| 2465 | ieee80211_sta_reset_auth(sdata, ifsta); |
| 2466 | return 0; |
| 2467 | } else { |
| 2468 | if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { |
| 2469 | ifsta->assoc_scan_tries++; |
| 2470 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) |
| 2471 | ieee80211_sta_start_scan(sdata, NULL, 0); |
| 2472 | else |
| 2473 | ieee80211_sta_start_scan(sdata, ifsta->ssid, |
| 2474 | ifsta->ssid_len); |
| 2475 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
| 2476 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 2477 | } else |
| 2478 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 2479 | } |
| 2480 | return -1; |
| 2481 | } |
| 2482 | |
| 2483 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2484 | int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2485 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2486 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2487 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2488 | printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2489 | sdata->dev->name, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2490 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2491 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 2492 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2493 | return -EINVAL; |
| 2494 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2495 | ieee80211_set_disassoc(sdata, ifsta, true, true, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2496 | return 0; |
| 2497 | } |
| 2498 | |
| 2499 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2500 | int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2501 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2502 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 2503 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2504 | printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2505 | sdata->dev->name, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2506 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2507 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2508 | return -EINVAL; |
| 2509 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2510 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2511 | return -1; |
| 2512 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2513 | ieee80211_set_disassoc(sdata, ifsta, false, true, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2514 | return 0; |
| 2515 | } |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2516 | |
| 2517 | void ieee80211_notify_mac(struct ieee80211_hw *hw, |
| 2518 | enum ieee80211_notification_types notif_type) |
| 2519 | { |
| 2520 | struct ieee80211_local *local = hw_to_local(hw); |
| 2521 | struct ieee80211_sub_if_data *sdata; |
| 2522 | |
| 2523 | switch (notif_type) { |
| 2524 | case IEEE80211_NOTIFY_RE_ASSOC: |
| 2525 | rcu_read_lock(); |
| 2526 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2527 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
| 2528 | continue; |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2529 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2530 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2531 | } |
| 2532 | rcu_read_unlock(); |
| 2533 | break; |
| 2534 | } |
| 2535 | } |
| 2536 | EXPORT_SYMBOL(ieee80211_notify_mac); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2537 | |
| 2538 | void ieee80211_sta_work(struct work_struct *work) |
| 2539 | { |
| 2540 | struct ieee80211_sub_if_data *sdata = |
| 2541 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); |
| 2542 | struct ieee80211_local *local = sdata->local; |
| 2543 | struct ieee80211_if_sta *ifsta; |
| 2544 | struct sk_buff *skb; |
| 2545 | |
| 2546 | if (!netif_running(sdata->dev)) |
| 2547 | return; |
| 2548 | |
| 2549 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
| 2550 | return; |
| 2551 | |
| 2552 | if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 2553 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
| 2554 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) |
| 2555 | return; |
| 2556 | ifsta = &sdata->u.sta; |
| 2557 | |
| 2558 | while ((skb = skb_dequeue(&ifsta->skb_queue))) |
| 2559 | ieee80211_sta_rx_queued_mgmt(sdata, skb); |
| 2560 | |
| 2561 | #ifdef CONFIG_MAC80211_MESH |
| 2562 | if (ifsta->preq_queue_len && |
| 2563 | time_after(jiffies, |
| 2564 | ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval))) |
| 2565 | mesh_path_start_discovery(sdata); |
| 2566 | #endif |
| 2567 | |
| 2568 | if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE && |
| 2569 | ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
| 2570 | ifsta->state != IEEE80211_STA_MLME_ASSOCIATE && |
| 2571 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { |
Johannes Berg | a0fe8b3 | 2008-09-08 17:58:23 +0200 | [diff] [blame] | 2572 | ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2573 | return; |
| 2574 | } |
| 2575 | |
| 2576 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { |
| 2577 | if (ieee80211_sta_config_auth(sdata, ifsta)) |
| 2578 | return; |
| 2579 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 2580 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) |
| 2581 | return; |
| 2582 | |
| 2583 | switch (ifsta->state) { |
| 2584 | case IEEE80211_STA_MLME_DISABLED: |
| 2585 | break; |
| 2586 | case IEEE80211_STA_MLME_DIRECT_PROBE: |
| 2587 | ieee80211_direct_probe(sdata, ifsta); |
| 2588 | break; |
| 2589 | case IEEE80211_STA_MLME_AUTHENTICATE: |
| 2590 | ieee80211_authenticate(sdata, ifsta); |
| 2591 | break; |
| 2592 | case IEEE80211_STA_MLME_ASSOCIATE: |
| 2593 | ieee80211_associate(sdata, ifsta); |
| 2594 | break; |
| 2595 | case IEEE80211_STA_MLME_ASSOCIATED: |
| 2596 | ieee80211_associated(sdata, ifsta); |
| 2597 | break; |
| 2598 | case IEEE80211_STA_MLME_IBSS_SEARCH: |
| 2599 | ieee80211_sta_find_ibss(sdata, ifsta); |
| 2600 | break; |
| 2601 | case IEEE80211_STA_MLME_IBSS_JOINED: |
| 2602 | ieee80211_sta_merge_ibss(sdata, ifsta); |
| 2603 | break; |
| 2604 | #ifdef CONFIG_MAC80211_MESH |
| 2605 | case IEEE80211_STA_MLME_MESH_UP: |
| 2606 | ieee80211_mesh_housekeeping(sdata, ifsta); |
| 2607 | break; |
| 2608 | #endif |
| 2609 | default: |
| 2610 | WARN_ON(1); |
| 2611 | break; |
| 2612 | } |
| 2613 | |
| 2614 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { |
| 2615 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " |
| 2616 | "mixed-cell disabled - disassociate\n", sdata->dev->name); |
| 2617 | |
| 2618 | ieee80211_set_disassoc(sdata, ifsta, false, true, |
| 2619 | WLAN_REASON_UNSPECIFIED); |
| 2620 | } |
| 2621 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2622 | |
| 2623 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 2624 | { |
| 2625 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
| 2626 | struct ieee80211_if_sta *ifsta; |
| 2627 | |
| 2628 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
| 2629 | ifsta = &sdata->u.sta; |
| 2630 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || |
| 2631 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && |
| 2632 | !ieee80211_sta_active_ibss(sdata))) |
| 2633 | ieee80211_sta_find_ibss(sdata, ifsta); |
| 2634 | } |
| 2635 | } |