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