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