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 | |
| 14 | /* TODO: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | * order BSS list by RSSI(?) ("quality of AP") |
| 16 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, |
| 17 | * SSID) |
| 18 | */ |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 19 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 20 | #include <linux/if_ether.h> |
| 21 | #include <linux/skbuff.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/if_arp.h> |
| 24 | #include <linux/wireless.h> |
| 25 | #include <linux/random.h> |
| 26 | #include <linux/etherdevice.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 27 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #include <net/iw_handler.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 29 | #include <net/mac80211.h> |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 30 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 31 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 32 | #include "rate.h" |
| 33 | #include "led.h" |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 34 | #include "mesh.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 36 | #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 37 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 38 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 39 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 40 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 41 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 42 | #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 43 | #define IEEE80211_PROBE_INTERVAL (60 * HZ) |
| 44 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) |
| 45 | #define IEEE80211_SCAN_INTERVAL (2 * HZ) |
| 46 | #define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ) |
Dan Williams | 872ba53 | 2008-06-04 13:59:34 -0400 | [diff] [blame] | 47 | #define IEEE80211_IBSS_JOIN_TIMEOUT (7 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 48 | |
| 49 | #define IEEE80211_PROBE_DELAY (HZ / 33) |
| 50 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
| 51 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
| 52 | #define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) |
| 53 | #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) |
| 54 | #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 55 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 56 | |
| 57 | #define IEEE80211_IBSS_MAX_STA_ENTRIES 128 |
| 58 | |
| 59 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 60 | /* mgmt header + 1 byte category code */ |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 61 | #define IEEE80211_MIN_ACTION_SIZE (24 + 1) |
| 62 | |
| 63 | #define IEEE80211_ADDBA_PARAM_POLICY_MASK 0x0002 |
| 64 | #define IEEE80211_ADDBA_PARAM_TID_MASK 0x003C |
| 65 | #define IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK 0xFFA0 |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 66 | #define IEEE80211_DELBA_PARAM_TID_MASK 0xF000 |
| 67 | #define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800 |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 68 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 69 | /* next values represent the buffer size for A-MPDU frame. |
| 70 | * According to IEEE802.11n spec size varies from 8K to 64K (in powers of 2) */ |
| 71 | #define IEEE80211_MIN_AMPDU_BUF 0x8 |
| 72 | #define IEEE80211_MAX_AMPDU_BUF 0x40 |
| 73 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 74 | /* BSS handling */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 75 | static struct ieee80211_sta_bss * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 76 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 77 | u8 *ssid, u8 ssid_len) |
| 78 | { |
| 79 | struct ieee80211_sta_bss *bss; |
| 80 | |
| 81 | spin_lock_bh(&local->sta_bss_lock); |
| 82 | bss = local->sta_bss_hash[STA_HASH(bssid)]; |
| 83 | while (bss) { |
| 84 | if (!bss_mesh_cfg(bss) && |
| 85 | !memcmp(bss->bssid, bssid, ETH_ALEN) && |
| 86 | bss->freq == freq && |
| 87 | bss->ssid_len == ssid_len && |
| 88 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { |
| 89 | atomic_inc(&bss->users); |
| 90 | break; |
| 91 | } |
| 92 | bss = bss->hnext; |
| 93 | } |
| 94 | spin_unlock_bh(&local->sta_bss_lock); |
| 95 | return bss; |
| 96 | } |
| 97 | |
| 98 | /* Caller must hold local->sta_bss_lock */ |
| 99 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, |
| 100 | struct ieee80211_sta_bss *bss) |
| 101 | { |
| 102 | u8 hash_idx; |
| 103 | |
| 104 | if (bss_mesh_cfg(bss)) |
| 105 | hash_idx = mesh_id_hash(bss_mesh_id(bss), |
| 106 | bss_mesh_id_len(bss)); |
| 107 | else |
| 108 | hash_idx = STA_HASH(bss->bssid); |
| 109 | |
| 110 | bss->hnext = local->sta_bss_hash[hash_idx]; |
| 111 | local->sta_bss_hash[hash_idx] = bss; |
| 112 | } |
| 113 | |
| 114 | /* Caller must hold local->sta_bss_lock */ |
| 115 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, |
| 116 | struct ieee80211_sta_bss *bss) |
| 117 | { |
| 118 | struct ieee80211_sta_bss *b, *prev = NULL; |
| 119 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; |
| 120 | while (b) { |
| 121 | if (b == bss) { |
| 122 | if (!prev) |
| 123 | local->sta_bss_hash[STA_HASH(bss->bssid)] = |
| 124 | bss->hnext; |
| 125 | else |
| 126 | prev->hnext = bss->hnext; |
| 127 | break; |
| 128 | } |
| 129 | prev = b; |
| 130 | b = b->hnext; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | static struct ieee80211_sta_bss * |
| 135 | ieee80211_rx_bss_add(struct ieee80211_sub_if_data *sdata, u8 *bssid, int freq, |
| 136 | u8 *ssid, u8 ssid_len) |
| 137 | { |
| 138 | struct ieee80211_local *local = sdata->local; |
| 139 | struct ieee80211_sta_bss *bss; |
| 140 | |
| 141 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
| 142 | if (!bss) |
| 143 | return NULL; |
| 144 | atomic_inc(&bss->users); |
| 145 | atomic_inc(&bss->users); |
| 146 | memcpy(bss->bssid, bssid, ETH_ALEN); |
| 147 | bss->freq = freq; |
| 148 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { |
| 149 | memcpy(bss->ssid, ssid, ssid_len); |
| 150 | bss->ssid_len = ssid_len; |
| 151 | } |
| 152 | |
| 153 | spin_lock_bh(&local->sta_bss_lock); |
| 154 | /* TODO: order by RSSI? */ |
| 155 | list_add_tail(&bss->list, &local->sta_bss_list); |
| 156 | __ieee80211_rx_bss_hash_add(local, bss); |
| 157 | spin_unlock_bh(&local->sta_bss_lock); |
| 158 | return bss; |
| 159 | } |
| 160 | |
| 161 | #ifdef CONFIG_MAC80211_MESH |
| 162 | static struct ieee80211_sta_bss * |
| 163 | ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, |
| 164 | u8 *mesh_cfg, int freq) |
| 165 | { |
| 166 | struct ieee80211_sta_bss *bss; |
| 167 | |
| 168 | spin_lock_bh(&local->sta_bss_lock); |
| 169 | bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; |
| 170 | while (bss) { |
| 171 | if (bss_mesh_cfg(bss) && |
| 172 | !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && |
| 173 | bss->freq == freq && |
| 174 | mesh_id_len == bss->mesh_id_len && |
| 175 | (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id, |
| 176 | mesh_id_len))) { |
| 177 | atomic_inc(&bss->users); |
| 178 | break; |
| 179 | } |
| 180 | bss = bss->hnext; |
| 181 | } |
| 182 | spin_unlock_bh(&local->sta_bss_lock); |
| 183 | return bss; |
| 184 | } |
| 185 | |
| 186 | static struct ieee80211_sta_bss * |
| 187 | ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, |
| 188 | u8 *mesh_cfg, int mesh_config_len, int freq) |
| 189 | { |
| 190 | struct ieee80211_sta_bss *bss; |
| 191 | |
| 192 | if (mesh_config_len != MESH_CFG_LEN) |
| 193 | return NULL; |
| 194 | |
| 195 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
| 196 | if (!bss) |
| 197 | return NULL; |
| 198 | |
| 199 | bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC); |
| 200 | if (!bss->mesh_cfg) { |
| 201 | kfree(bss); |
| 202 | return NULL; |
| 203 | } |
| 204 | |
| 205 | if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) { |
| 206 | bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC); |
| 207 | if (!bss->mesh_id) { |
| 208 | kfree(bss->mesh_cfg); |
| 209 | kfree(bss); |
| 210 | return NULL; |
| 211 | } |
| 212 | memcpy(bss->mesh_id, mesh_id, mesh_id_len); |
| 213 | } |
| 214 | |
| 215 | atomic_inc(&bss->users); |
| 216 | atomic_inc(&bss->users); |
| 217 | memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); |
| 218 | bss->mesh_id_len = mesh_id_len; |
| 219 | bss->freq = freq; |
| 220 | spin_lock_bh(&local->sta_bss_lock); |
| 221 | /* TODO: order by RSSI? */ |
| 222 | list_add_tail(&bss->list, &local->sta_bss_list); |
| 223 | __ieee80211_rx_bss_hash_add(local, bss); |
| 224 | spin_unlock_bh(&local->sta_bss_lock); |
| 225 | return bss; |
| 226 | } |
| 227 | #endif |
| 228 | |
| 229 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) |
| 230 | { |
| 231 | kfree(bss->ies); |
| 232 | kfree(bss_mesh_id(bss)); |
| 233 | kfree(bss_mesh_cfg(bss)); |
| 234 | kfree(bss); |
| 235 | } |
| 236 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 237 | static void ieee80211_rx_bss_put(struct ieee80211_local *local, |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 238 | struct ieee80211_sta_bss *bss) |
| 239 | { |
| 240 | local_bh_disable(); |
| 241 | if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) { |
| 242 | local_bh_enable(); |
| 243 | return; |
| 244 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 245 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 246 | __ieee80211_rx_bss_hash_del(local, bss); |
| 247 | list_del(&bss->list); |
| 248 | spin_unlock_bh(&local->sta_bss_lock); |
| 249 | ieee80211_rx_bss_free(bss); |
| 250 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 251 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 252 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) |
| 253 | { |
| 254 | spin_lock_init(&local->sta_bss_lock); |
| 255 | INIT_LIST_HEAD(&local->sta_bss_list); |
| 256 | } |
| 257 | |
| 258 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) |
| 259 | { |
| 260 | struct ieee80211_sta_bss *bss, *tmp; |
| 261 | |
| 262 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) |
| 263 | ieee80211_rx_bss_put(local, bss); |
| 264 | } |
| 265 | |
| 266 | 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] | 267 | { |
| 268 | u8 *end, *pos; |
| 269 | |
| 270 | pos = bss->ies; |
| 271 | if (pos == NULL) |
| 272 | return NULL; |
| 273 | end = pos + bss->ies_len; |
| 274 | |
| 275 | while (pos + 1 < end) { |
| 276 | if (pos + 2 + pos[1] > end) |
| 277 | break; |
| 278 | if (pos[0] == ie) |
| 279 | return pos; |
| 280 | pos += 2 + pos[1]; |
| 281 | } |
| 282 | |
| 283 | return NULL; |
| 284 | } |
| 285 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 286 | /* utils */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 287 | static int ecw2cw(int ecw) |
| 288 | { |
Johannes Berg | ac2bf32 | 2008-02-14 00:30:35 +0100 | [diff] [blame] | 289 | return (1 << ecw) - 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 292 | /* frame sending functions */ |
| 293 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 294 | int encrypt) |
| 295 | { |
| 296 | skb->dev = sdata->local->mdev; |
| 297 | skb_set_mac_header(skb, 0); |
| 298 | skb_set_network_header(skb, 0); |
| 299 | skb_set_transport_header(skb, 0); |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 300 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 301 | skb->iif = sdata->dev->ifindex; |
| 302 | skb->do_not_encrypt = !encrypt; |
| 303 | |
| 304 | dev_queue_xmit(skb); |
| 305 | } |
| 306 | |
| 307 | static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
| 308 | struct ieee80211_if_sta *ifsta, |
| 309 | int transaction, u8 *extra, size_t extra_len, |
| 310 | int encrypt) |
| 311 | { |
| 312 | struct ieee80211_local *local = sdata->local; |
| 313 | struct sk_buff *skb; |
| 314 | struct ieee80211_mgmt *mgmt; |
| 315 | |
| 316 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 317 | sizeof(*mgmt) + 6 + extra_len); |
| 318 | if (!skb) { |
| 319 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " |
| 320 | "frame\n", sdata->dev->name); |
| 321 | return; |
| 322 | } |
| 323 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 324 | |
| 325 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); |
| 326 | memset(mgmt, 0, 24 + 6); |
| 327 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 328 | IEEE80211_STYPE_AUTH); |
| 329 | if (encrypt) |
| 330 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 331 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
| 332 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 333 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 334 | mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg); |
| 335 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); |
| 336 | ifsta->auth_transaction = transaction + 1; |
| 337 | mgmt->u.auth.status_code = cpu_to_le16(0); |
| 338 | if (extra) |
| 339 | memcpy(skb_put(skb, extra_len), extra, extra_len); |
| 340 | |
| 341 | ieee80211_sta_tx(sdata, skb, encrypt); |
| 342 | } |
| 343 | |
| 344 | static void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
| 345 | u8 *ssid, size_t ssid_len) |
| 346 | { |
| 347 | struct ieee80211_local *local = sdata->local; |
| 348 | struct ieee80211_supported_band *sband; |
| 349 | struct sk_buff *skb; |
| 350 | struct ieee80211_mgmt *mgmt; |
| 351 | u8 *pos, *supp_rates, *esupp_rates = NULL; |
| 352 | int i; |
| 353 | |
| 354 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200); |
| 355 | if (!skb) { |
| 356 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " |
| 357 | "request\n", sdata->dev->name); |
| 358 | return; |
| 359 | } |
| 360 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 361 | |
| 362 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 363 | memset(mgmt, 0, 24); |
| 364 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 365 | IEEE80211_STYPE_PROBE_REQ); |
| 366 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 367 | if (dst) { |
| 368 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 369 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
| 370 | } else { |
| 371 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 372 | memset(mgmt->bssid, 0xff, ETH_ALEN); |
| 373 | } |
| 374 | pos = skb_put(skb, 2 + ssid_len); |
| 375 | *pos++ = WLAN_EID_SSID; |
| 376 | *pos++ = ssid_len; |
| 377 | memcpy(pos, ssid, ssid_len); |
| 378 | |
| 379 | supp_rates = skb_put(skb, 2); |
| 380 | supp_rates[0] = WLAN_EID_SUPP_RATES; |
| 381 | supp_rates[1] = 0; |
| 382 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 383 | |
| 384 | for (i = 0; i < sband->n_bitrates; i++) { |
| 385 | struct ieee80211_rate *rate = &sband->bitrates[i]; |
| 386 | if (esupp_rates) { |
| 387 | pos = skb_put(skb, 1); |
| 388 | esupp_rates[1]++; |
| 389 | } else if (supp_rates[1] == 8) { |
| 390 | esupp_rates = skb_put(skb, 3); |
| 391 | esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES; |
| 392 | esupp_rates[1] = 1; |
| 393 | pos = &esupp_rates[2]; |
| 394 | } else { |
| 395 | pos = skb_put(skb, 1); |
| 396 | supp_rates[1]++; |
| 397 | } |
| 398 | *pos = rate->bitrate / 5; |
| 399 | } |
| 400 | |
| 401 | ieee80211_sta_tx(sdata, skb, 0); |
| 402 | } |
| 403 | |
| 404 | /* MLME */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 405 | static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 406 | struct ieee80211_sta_bss *bss, |
| 407 | int ibss) |
| 408 | { |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 409 | struct ieee80211_local *local = sdata->local; |
| 410 | int i, have_higher_than_11mbit = 0; |
| 411 | |
| 412 | |
| 413 | /* cf. IEEE 802.11 9.2.12 */ |
| 414 | for (i = 0; i < bss->supp_rates_len; i++) |
| 415 | if ((bss->supp_rates[i] & 0x7f) * 5 > 110) |
| 416 | have_higher_than_11mbit = 1; |
| 417 | |
| 418 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 419 | have_higher_than_11mbit) |
| 420 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 421 | else |
| 422 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 423 | |
| 424 | |
| 425 | if (local->ops->conf_tx) { |
| 426 | struct ieee80211_tx_queue_params qparam; |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 427 | |
| 428 | memset(&qparam, 0, sizeof(qparam)); |
| 429 | |
| 430 | qparam.aifs = 2; |
| 431 | |
| 432 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 433 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) |
| 434 | qparam.cw_min = 31; |
| 435 | else |
| 436 | qparam.cw_min = 15; |
| 437 | |
| 438 | qparam.cw_max = 1023; |
| 439 | qparam.txop = 0; |
| 440 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 441 | for (i = 0; i < local_to_hw(local)->queues; i++) |
| 442 | local->ops->conf_tx(local_to_hw(local), i, &qparam); |
Vladimir Koutny | e2839d8 | 2008-03-18 21:14:07 +0100 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 446 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 447 | struct ieee80211_if_sta *ifsta, |
| 448 | u8 *wmm_param, size_t wmm_param_len) |
| 449 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 450 | struct ieee80211_tx_queue_params params; |
| 451 | size_t left; |
| 452 | int count; |
| 453 | u8 *pos; |
| 454 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 455 | if (!(ifsta->flags & IEEE80211_STA_WMM_ENABLED)) |
| 456 | return; |
| 457 | |
| 458 | if (!wmm_param) |
| 459 | return; |
| 460 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 461 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
| 462 | return; |
| 463 | count = wmm_param[6] & 0x0f; |
| 464 | if (count == ifsta->wmm_last_param_set) |
| 465 | return; |
| 466 | ifsta->wmm_last_param_set = count; |
| 467 | |
| 468 | pos = wmm_param + 8; |
| 469 | left = wmm_param_len - 8; |
| 470 | |
| 471 | memset(¶ms, 0, sizeof(params)); |
| 472 | |
| 473 | if (!local->ops->conf_tx) |
| 474 | return; |
| 475 | |
| 476 | local->wmm_acm = 0; |
| 477 | for (; left >= 4; left -= 4, pos += 4) { |
| 478 | int aci = (pos[0] >> 5) & 0x03; |
| 479 | int acm = (pos[0] >> 4) & 0x01; |
| 480 | int queue; |
| 481 | |
| 482 | switch (aci) { |
| 483 | case 1: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 484 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 485 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 486 | local->wmm_acm |= BIT(0) | BIT(3); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 487 | break; |
| 488 | case 2: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 489 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 490 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 491 | local->wmm_acm |= BIT(4) | BIT(5); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 492 | break; |
| 493 | case 3: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 494 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 495 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 496 | local->wmm_acm |= BIT(6) | BIT(7); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 497 | break; |
| 498 | case 0: |
| 499 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 500 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 501 | if (acm) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 502 | local->wmm_acm |= BIT(1) | BIT(2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | |
| 506 | params.aifs = pos[0] & 0x0f; |
| 507 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 508 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 509 | params.txop = get_unaligned_le16(pos + 2); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 510 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 511 | 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] | 512 | "cWmin=%d cWmax=%d txop=%d\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 513 | local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 514 | params.cw_max, params.txop); |
| 515 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 516 | /* TODO: handle ACM (block TX, fallback to next lowest allowed |
| 517 | * AC for now) */ |
| 518 | if (local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { |
| 519 | printk(KERN_DEBUG "%s: failed to set TX queue " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 520 | "parameters for queue %d\n", local->mdev->name, queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 525 | static u32 ieee80211_handle_protect_preamb(struct ieee80211_sub_if_data *sdata, |
| 526 | bool use_protection, |
| 527 | bool use_short_preamble) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 528 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 529 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 530 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 531 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 532 | DECLARE_MAC_BUF(mac); |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 533 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 534 | u32 changed = 0; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 535 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 536 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 537 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 538 | if (net_ratelimit()) { |
| 539 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 540 | "%s)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 541 | sdata->dev->name, |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 542 | use_protection ? "enabled" : "disabled", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 543 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 544 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 545 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 546 | bss_conf->use_cts_prot = use_protection; |
| 547 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 548 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 549 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 550 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 551 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 552 | if (net_ratelimit()) { |
| 553 | printk(KERN_DEBUG "%s: switched to %s barker preamble" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 554 | " (BSSID=%s)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 555 | sdata->dev->name, |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 556 | use_short_preamble ? "short" : "long", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 557 | print_mac(mac, ifsta->bssid)); |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 558 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 559 | #endif |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 560 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 561 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 562 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 563 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 564 | return changed; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 565 | } |
| 566 | |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 567 | static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata, |
| 568 | u8 erp_value) |
| 569 | { |
| 570 | bool use_protection = (erp_value & WLAN_ERP_USE_PROTECTION) != 0; |
| 571 | bool use_short_preamble = (erp_value & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 572 | |
| 573 | return ieee80211_handle_protect_preamb(sdata, |
| 574 | use_protection, use_short_preamble); |
| 575 | } |
| 576 | |
| 577 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 578 | struct ieee80211_sta_bss *bss) |
| 579 | { |
| 580 | u32 changed = 0; |
| 581 | |
| 582 | if (bss->has_erp_value) |
| 583 | changed |= ieee80211_handle_erp_ie(sdata, bss->erp_value); |
| 584 | else { |
| 585 | u16 capab = bss->capability; |
| 586 | changed |= ieee80211_handle_protect_preamb(sdata, false, |
| 587 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); |
| 588 | } |
| 589 | |
| 590 | return changed; |
| 591 | } |
| 592 | |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 593 | int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie, |
| 594 | struct ieee80211_ht_info *ht_info) |
| 595 | { |
| 596 | |
| 597 | if (ht_info == NULL) |
| 598 | return -EINVAL; |
| 599 | |
| 600 | memset(ht_info, 0, sizeof(*ht_info)); |
| 601 | |
| 602 | if (ht_cap_ie) { |
| 603 | u8 ampdu_info = ht_cap_ie->ampdu_params_info; |
| 604 | |
| 605 | ht_info->ht_supported = 1; |
| 606 | ht_info->cap = le16_to_cpu(ht_cap_ie->cap_info); |
| 607 | ht_info->ampdu_factor = |
| 608 | ampdu_info & IEEE80211_HT_CAP_AMPDU_FACTOR; |
| 609 | ht_info->ampdu_density = |
| 610 | (ampdu_info & IEEE80211_HT_CAP_AMPDU_DENSITY) >> 2; |
| 611 | memcpy(ht_info->supp_mcs_set, ht_cap_ie->supp_mcs_set, 16); |
| 612 | } else |
| 613 | ht_info->ht_supported = 0; |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | int ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 619 | struct ieee80211_ht_addt_info *ht_add_info_ie, |
| 620 | struct ieee80211_ht_bss_info *bss_info) |
| 621 | { |
| 622 | if (bss_info == NULL) |
| 623 | return -EINVAL; |
| 624 | |
| 625 | memset(bss_info, 0, sizeof(*bss_info)); |
| 626 | |
| 627 | if (ht_add_info_ie) { |
| 628 | u16 op_mode; |
| 629 | op_mode = le16_to_cpu(ht_add_info_ie->operation_mode); |
| 630 | |
| 631 | bss_info->primary_channel = ht_add_info_ie->control_chan; |
| 632 | bss_info->bss_cap = ht_add_info_ie->ht_param; |
| 633 | bss_info->bss_op_mode = (u8)(op_mode & 0xff); |
| 634 | } |
| 635 | |
| 636 | return 0; |
| 637 | } |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 638 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 639 | static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata, |
| 640 | struct ieee80211_if_sta *ifsta) |
| 641 | { |
| 642 | union iwreq_data wrqu; |
| 643 | memset(&wrqu, 0, sizeof(wrqu)); |
| 644 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
| 645 | memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN); |
| 646 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 647 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
| 648 | } |
| 649 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 650 | static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 651 | struct ieee80211_if_sta *ifsta) |
| 652 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 653 | union iwreq_data wrqu; |
| 654 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 655 | if (ifsta->assocreq_ies) { |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 656 | memset(&wrqu, 0, sizeof(wrqu)); |
| 657 | wrqu.data.length = ifsta->assocreq_ies_len; |
David S. Miller | b171e19 | 2008-08-29 23:06:00 -0700 | [diff] [blame] | 658 | wireless_send_event(sdata->dev, IWEVASSOCREQIE, &wrqu, |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 659 | ifsta->assocreq_ies); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 660 | } |
| 661 | if (ifsta->assocresp_ies) { |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 662 | memset(&wrqu, 0, sizeof(wrqu)); |
| 663 | wrqu.data.length = ifsta->assocresp_ies_len; |
David S. Miller | b171e19 | 2008-08-29 23:06:00 -0700 | [diff] [blame] | 664 | wireless_send_event(sdata->dev, IWEVASSOCRESPIE, &wrqu, |
Jouni Malinen | 087d833 | 2008-08-19 10:54:32 +0300 | [diff] [blame] | 665 | ifsta->assocresp_ies); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 666 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 670 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 671 | struct ieee80211_if_sta *ifsta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 672 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 673 | struct ieee80211_local *local = sdata->local; |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 674 | struct ieee80211_conf *conf = &local_to_hw(local)->conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 675 | u32 changed = BSS_CHANGED_ASSOC; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 676 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 677 | struct ieee80211_sta_bss *bss; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 678 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 679 | ifsta->flags |= IEEE80211_STA_ASSOCIATED; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 680 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 681 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
| 682 | return; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 683 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 684 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
| 685 | conf->channel->center_freq, |
| 686 | ifsta->ssid, ifsta->ssid_len); |
| 687 | if (bss) { |
| 688 | /* set timing information */ |
| 689 | sdata->bss_conf.beacon_int = bss->beacon_int; |
| 690 | sdata->bss_conf.timestamp = bss->timestamp; |
| 691 | sdata->bss_conf.dtim_period = bss->dtim_period; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 692 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 693 | changed |= ieee80211_handle_bss_capability(sdata, bss); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 694 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 695 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 696 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 697 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 698 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
| 699 | changed |= BSS_CHANGED_HT; |
| 700 | sdata->bss_conf.assoc_ht = 1; |
| 701 | sdata->bss_conf.ht_conf = &conf->ht_conf; |
| 702 | sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf; |
| 703 | } |
| 704 | |
| 705 | ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET; |
| 706 | memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN); |
| 707 | ieee80211_sta_send_associnfo(sdata, ifsta); |
| 708 | |
| 709 | ifsta->last_probe = jiffies; |
| 710 | ieee80211_led_assoc(local, 1); |
| 711 | |
| 712 | sdata->bss_conf.assoc = 1; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 713 | ieee80211_bss_info_change_notify(sdata, changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 714 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 715 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 716 | netif_carrier_on(sdata->dev); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 717 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 718 | ieee80211_sta_send_apinfo(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 721 | static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata, |
| 722 | struct ieee80211_if_sta *ifsta) |
| 723 | { |
| 724 | DECLARE_MAC_BUF(mac); |
| 725 | |
| 726 | ifsta->direct_probe_tries++; |
| 727 | if (ifsta->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { |
| 728 | printk(KERN_DEBUG "%s: direct probe to AP %s timed out\n", |
| 729 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
| 730 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 731 | return; |
| 732 | } |
| 733 | |
| 734 | printk(KERN_DEBUG "%s: direct probe to AP %s try %d\n", |
| 735 | sdata->dev->name, print_mac(mac, ifsta->bssid), |
| 736 | ifsta->direct_probe_tries); |
| 737 | |
| 738 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 739 | |
| 740 | set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifsta->request); |
| 741 | |
| 742 | /* Direct probe is sent to broadcast address as some APs |
| 743 | * will not answer to direct packet in unassociated state. |
| 744 | */ |
| 745 | ieee80211_send_probe_req(sdata, NULL, |
| 746 | ifsta->ssid, ifsta->ssid_len); |
| 747 | |
| 748 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
| 749 | } |
| 750 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 751 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 752 | static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 753 | struct ieee80211_if_sta *ifsta) |
| 754 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 755 | DECLARE_MAC_BUF(mac); |
| 756 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 757 | ifsta->auth_tries++; |
| 758 | if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 759 | printk(KERN_DEBUG "%s: authentication with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 760 | " timed out\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 761 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 762 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 766 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 767 | printk(KERN_DEBUG "%s: authenticate with AP %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 768 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 769 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 770 | ieee80211_send_auth(sdata, ifsta, 1, NULL, 0, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 771 | |
| 772 | mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
| 773 | } |
| 774 | |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 775 | static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss, |
| 776 | struct ieee80211_supported_band *sband, |
| 777 | u64 *rates) |
| 778 | { |
| 779 | int i, j, count; |
| 780 | *rates = 0; |
| 781 | count = 0; |
| 782 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 783 | int rate = (bss->supp_rates[i] & 0x7F) * 5; |
| 784 | |
| 785 | for (j = 0; j < sband->n_bitrates; j++) |
| 786 | if (sband->bitrates[j].bitrate == rate) { |
| 787 | *rates |= BIT(j); |
| 788 | count++; |
| 789 | break; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | return count; |
| 794 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 795 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 796 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 797 | struct ieee80211_if_sta *ifsta) |
| 798 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 799 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 800 | struct sk_buff *skb; |
| 801 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 802 | u8 *pos, *ies, *ht_add_ie; |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 803 | int i, len, count, rates_len, supp_rates_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 804 | u16 capab; |
| 805 | struct ieee80211_sta_bss *bss; |
| 806 | int wmm = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 807 | struct ieee80211_supported_band *sband; |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 808 | u64 rates = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 809 | |
| 810 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 811 | sizeof(*mgmt) + 200 + ifsta->extra_ie_len + |
| 812 | ifsta->ssid_len); |
| 813 | if (!skb) { |
| 814 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 815 | "frame\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 819 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 820 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 821 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 822 | capab = ifsta->capab; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 823 | |
| 824 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { |
| 825 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 826 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 827 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 828 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 829 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 830 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 831 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 832 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 833 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 834 | if (bss) { |
| 835 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 836 | capab |= WLAN_CAPABILITY_PRIVACY; |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 837 | if (bss->wmm_used) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 838 | wmm = 1; |
Helmut Schaa | 0d580a7 | 2008-05-20 09:56:37 +0200 | [diff] [blame] | 839 | |
| 840 | /* get all rates supported by the device and the AP as |
| 841 | * some APs don't like getting a superset of their rates |
| 842 | * in the association request (e.g. D-Link DAP 1353 in |
| 843 | * b-only mode) */ |
| 844 | rates_len = ieee80211_compatible_rates(bss, sband, &rates); |
| 845 | |
Tomas Winkler | 06ff47b | 2008-06-18 17:53:44 +0300 | [diff] [blame] | 846 | if ((bss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
| 847 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 848 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 849 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 850 | ieee80211_rx_bss_put(local, bss); |
Helmut Schaa | 0d580a7 | 2008-05-20 09:56:37 +0200 | [diff] [blame] | 851 | } else { |
| 852 | rates = ~0; |
| 853 | rates_len = sband->n_bitrates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 857 | memset(mgmt, 0, 24); |
| 858 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 859 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 860 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 861 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 862 | if (ifsta->flags & IEEE80211_STA_PREV_BSSID_SET) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 863 | skb_put(skb, 10); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 864 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 865 | IEEE80211_STYPE_REASSOC_REQ); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 866 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
Tomas Winkler | ea95bba | 2008-07-18 13:53:00 +0800 | [diff] [blame] | 867 | mgmt->u.reassoc_req.listen_interval = |
| 868 | cpu_to_le16(local->hw.conf.listen_interval); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 869 | memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid, |
| 870 | ETH_ALEN); |
| 871 | } else { |
| 872 | skb_put(skb, 4); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 873 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 874 | IEEE80211_STYPE_ASSOC_REQ); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 875 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
Tomas Winkler | ea95bba | 2008-07-18 13:53:00 +0800 | [diff] [blame] | 876 | mgmt->u.reassoc_req.listen_interval = |
| 877 | cpu_to_le16(local->hw.conf.listen_interval); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /* SSID */ |
| 881 | ies = pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 882 | *pos++ = WLAN_EID_SSID; |
| 883 | *pos++ = ifsta->ssid_len; |
| 884 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 885 | |
Helmut Schaa | 0d580a7 | 2008-05-20 09:56:37 +0200 | [diff] [blame] | 886 | /* add all rates which were marked to be used above */ |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 887 | supp_rates_len = rates_len; |
| 888 | if (supp_rates_len > 8) |
| 889 | supp_rates_len = 8; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 890 | |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 891 | len = sband->n_bitrates; |
| 892 | pos = skb_put(skb, supp_rates_len + 2); |
| 893 | *pos++ = WLAN_EID_SUPP_RATES; |
| 894 | *pos++ = supp_rates_len; |
| 895 | |
| 896 | count = 0; |
| 897 | for (i = 0; i < sband->n_bitrates; i++) { |
| 898 | if (BIT(i) & rates) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 899 | int rate = sband->bitrates[i].bitrate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 900 | *pos++ = (u8) (rate / 5); |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 901 | if (++count == 8) |
| 902 | break; |
| 903 | } |
| 904 | } |
| 905 | |
Jan-Espen Pettersen | 8ab65b0 | 2008-08-25 20:29:22 +0200 | [diff] [blame] | 906 | if (rates_len > count) { |
Helmut Schaa | 36d16ae | 2008-05-08 13:34:07 +0200 | [diff] [blame] | 907 | pos = skb_put(skb, rates_len - count + 2); |
| 908 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 909 | *pos++ = rates_len - count; |
| 910 | |
| 911 | for (i++; i < sband->n_bitrates; i++) { |
| 912 | if (BIT(i) & rates) { |
| 913 | int rate = sband->bitrates[i].bitrate; |
| 914 | *pos++ = (u8) (rate / 5); |
| 915 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Tomas Winkler | 06ff47b | 2008-06-18 17:53:44 +0300 | [diff] [blame] | 919 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 920 | /* 1. power capabilities */ |
| 921 | pos = skb_put(skb, 4); |
| 922 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 923 | *pos++ = 2; |
| 924 | *pos++ = 0; /* min tx power */ |
| 925 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ |
| 926 | |
| 927 | /* 2. supported channels */ |
| 928 | /* TODO: get this in reg domain format */ |
| 929 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 930 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 931 | *pos++ = 2 * sband->n_channels; |
| 932 | for (i = 0; i < sband->n_channels; i++) { |
| 933 | *pos++ = ieee80211_frequency_to_channel( |
| 934 | sband->channels[i].center_freq); |
| 935 | *pos++ = 1; /* one channel in the subband*/ |
| 936 | } |
| 937 | } |
| 938 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 939 | if (ifsta->extra_ie) { |
| 940 | pos = skb_put(skb, ifsta->extra_ie_len); |
| 941 | memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len); |
| 942 | } |
| 943 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 944 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 945 | pos = skb_put(skb, 9); |
| 946 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 947 | *pos++ = 7; /* len */ |
| 948 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 949 | *pos++ = 0x50; |
| 950 | *pos++ = 0xf2; |
| 951 | *pos++ = 2; /* WME */ |
| 952 | *pos++ = 0; /* WME info */ |
| 953 | *pos++ = 1; /* WME ver */ |
| 954 | *pos++ = 0; |
| 955 | } |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 956 | |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 957 | /* wmm support is a must to HT */ |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 958 | if (wmm && (ifsta->flags & IEEE80211_STA_WMM_ENABLED) && |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 959 | sband->ht_info.ht_supported && |
| 960 | (ht_add_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_EXTRA_INFO))) { |
Emmanuel Grumbach | 9306102 | 2008-05-29 16:35:23 +0800 | [diff] [blame] | 961 | struct ieee80211_ht_addt_info *ht_add_info = |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 962 | (struct ieee80211_ht_addt_info *)ht_add_ie; |
Emmanuel Grumbach | 9306102 | 2008-05-29 16:35:23 +0800 | [diff] [blame] | 963 | u16 cap = sband->ht_info.cap; |
| 964 | __le16 tmp; |
| 965 | u32 flags = local->hw.conf.channel->flags; |
| 966 | |
| 967 | switch (ht_add_info->ht_param & IEEE80211_HT_IE_CHA_SEC_OFFSET) { |
| 968 | case IEEE80211_HT_IE_CHA_SEC_ABOVE: |
| 969 | if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { |
| 970 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; |
| 971 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 972 | } |
| 973 | break; |
| 974 | case IEEE80211_HT_IE_CHA_SEC_BELOW: |
| 975 | if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { |
| 976 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH; |
| 977 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 978 | } |
| 979 | break; |
| 980 | } |
| 981 | |
| 982 | tmp = cpu_to_le16(cap); |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 983 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); |
| 984 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 985 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 986 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); |
| 987 | memcpy(pos, &tmp, sizeof(u16)); |
| 988 | pos += sizeof(u16); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 989 | /* TODO: needs a define here for << 2 */ |
| 990 | *pos++ = sband->ht_info.ampdu_factor | |
| 991 | (sband->ht_info.ampdu_density << 2); |
| 992 | memcpy(pos, sband->ht_info.supp_mcs_set, 16); |
Ron Rindjunsky | c715350 | 2007-11-26 16:14:31 +0200 | [diff] [blame] | 993 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 994 | |
| 995 | kfree(ifsta->assocreq_ies); |
| 996 | ifsta->assocreq_ies_len = (skb->data + skb->len) - ies; |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 997 | ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 998 | if (ifsta->assocreq_ies) |
| 999 | memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len); |
| 1000 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1001 | ieee80211_sta_tx(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1005 | static void ieee80211_send_deauth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1006 | struct ieee80211_if_sta *ifsta, u16 reason) |
| 1007 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1008 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1009 | struct sk_buff *skb; |
| 1010 | struct ieee80211_mgmt *mgmt; |
| 1011 | |
| 1012 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
| 1013 | if (!skb) { |
| 1014 | printk(KERN_DEBUG "%s: failed to allocate buffer for deauth " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1015 | "frame\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1019 | |
| 1020 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1021 | memset(mgmt, 0, 24); |
| 1022 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1023 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1024 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1025 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1026 | IEEE80211_STYPE_DEAUTH); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1027 | skb_put(skb, 2); |
| 1028 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
| 1029 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1030 | ieee80211_sta_tx(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 1033 | static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) |
| 1034 | { |
| 1035 | if (!sdata || !sdata->default_key || |
| 1036 | sdata->default_key->conf.alg != ALG_WEP) |
| 1037 | return 0; |
| 1038 | return 1; |
| 1039 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1040 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1041 | static void ieee80211_send_disassoc(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1042 | struct ieee80211_if_sta *ifsta, u16 reason) |
| 1043 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1044 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1045 | struct sk_buff *skb; |
| 1046 | struct ieee80211_mgmt *mgmt; |
| 1047 | |
| 1048 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
| 1049 | if (!skb) { |
| 1050 | printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1051 | "frame\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1052 | return; |
| 1053 | } |
| 1054 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1055 | |
| 1056 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1057 | memset(mgmt, 0, 24); |
| 1058 | memcpy(mgmt->da, ifsta->bssid, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1059 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1060 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1061 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1062 | IEEE80211_STYPE_DISASSOC); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1063 | skb_put(skb, 2); |
| 1064 | mgmt->u.disassoc.reason_code = cpu_to_le16(reason); |
| 1065 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1066 | ieee80211_sta_tx(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1069 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
| 1070 | struct ieee80211_if_sta *ifsta, bool deauth, |
| 1071 | bool self_disconnected, u16 reason) |
| 1072 | { |
| 1073 | struct ieee80211_local *local = sdata->local; |
| 1074 | struct sta_info *sta; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1075 | u32 changed = BSS_CHANGED_ASSOC; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1076 | |
| 1077 | rcu_read_lock(); |
| 1078 | |
| 1079 | sta = sta_info_get(local, ifsta->bssid); |
| 1080 | if (!sta) { |
| 1081 | rcu_read_unlock(); |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | if (deauth) { |
| 1086 | ifsta->direct_probe_tries = 0; |
| 1087 | ifsta->auth_tries = 0; |
| 1088 | } |
| 1089 | ifsta->assoc_scan_tries = 0; |
| 1090 | ifsta->assoc_tries = 0; |
| 1091 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 1092 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1093 | netif_carrier_off(sdata->dev); |
| 1094 | |
| 1095 | ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); |
| 1096 | |
| 1097 | if (self_disconnected) { |
| 1098 | if (deauth) |
| 1099 | ieee80211_send_deauth(sdata, ifsta, reason); |
| 1100 | else |
| 1101 | ieee80211_send_disassoc(sdata, ifsta, reason); |
| 1102 | } |
| 1103 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1104 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 1105 | changed |= ieee80211_reset_erp_info(sdata); |
| 1106 | |
| 1107 | if (sdata->bss_conf.assoc_ht) |
| 1108 | changed |= BSS_CHANGED_HT; |
| 1109 | |
| 1110 | sdata->bss_conf.assoc_ht = 0; |
| 1111 | sdata->bss_conf.ht_conf = NULL; |
| 1112 | sdata->bss_conf.ht_bss_conf = NULL; |
| 1113 | |
| 1114 | ieee80211_led_assoc(local, 0); |
| 1115 | sdata->bss_conf.assoc = 0; |
| 1116 | |
| 1117 | ieee80211_sta_send_apinfo(sdata, ifsta); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1118 | |
| 1119 | if (self_disconnected) |
| 1120 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 1121 | |
| 1122 | sta_info_unlink(&sta); |
| 1123 | |
| 1124 | rcu_read_unlock(); |
| 1125 | |
| 1126 | sta_info_destroy(sta); |
| 1127 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1128 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1129 | static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1130 | struct ieee80211_if_sta *ifsta) |
| 1131 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1132 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1133 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 1134 | int bss_privacy; |
| 1135 | int wep_privacy; |
| 1136 | int privacy_invoked; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1137 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 1138 | if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1139 | return 0; |
| 1140 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1141 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1142 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 1143 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1144 | if (!bss) |
| 1145 | return 0; |
| 1146 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 1147 | bss_privacy = !!(bss->capability & WLAN_CAPABILITY_PRIVACY); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1148 | wep_privacy = !!ieee80211_sta_wep_configured(sdata); |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 1149 | privacy_invoked = !!(ifsta->flags & IEEE80211_STA_PRIVACY_INVOKED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1150 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1151 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1152 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 1153 | if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked)) |
| 1154 | return 0; |
| 1155 | |
| 1156 | return 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1159 | static void ieee80211_associate(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1160 | struct ieee80211_if_sta *ifsta) |
| 1161 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1162 | DECLARE_MAC_BUF(mac); |
| 1163 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1164 | ifsta->assoc_tries++; |
| 1165 | if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1166 | printk(KERN_DEBUG "%s: association with AP %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1167 | " timed out\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1168 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1169 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1170 | return; |
| 1171 | } |
| 1172 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1173 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1174 | printk(KERN_DEBUG "%s: associate with AP %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1175 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
| 1176 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1177 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1178 | "mixed-cell disabled - abort association\n", sdata->dev->name); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1179 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1180 | return; |
| 1181 | } |
| 1182 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1183 | ieee80211_send_assoc(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1184 | |
| 1185 | mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); |
| 1186 | } |
| 1187 | |
| 1188 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1189 | static void ieee80211_associated(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1190 | struct ieee80211_if_sta *ifsta) |
| 1191 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1192 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1193 | struct sta_info *sta; |
| 1194 | int disassoc; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1195 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1196 | |
| 1197 | /* TODO: start monitoring current AP signal quality and number of |
| 1198 | * missed beacons. Scan other channels every now and then and search |
| 1199 | * for better APs. */ |
| 1200 | /* TODO: remove expired BSSes */ |
| 1201 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1202 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1203 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1204 | rcu_read_lock(); |
| 1205 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1206 | sta = sta_info_get(local, ifsta->bssid); |
| 1207 | if (!sta) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1208 | 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] | 1209 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1210 | disassoc = 1; |
| 1211 | } else { |
| 1212 | disassoc = 0; |
| 1213 | if (time_after(jiffies, |
| 1214 | sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1215 | if (ifsta->flags & IEEE80211_STA_PROBEREQ_POLL) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1216 | printk(KERN_DEBUG "%s: No ProbeResp from " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1217 | "current AP %s - assume out of " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1218 | "range\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1219 | sdata->dev->name, print_mac(mac, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1220 | disassoc = 1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1221 | } else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1222 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1223 | local->scan_ssid, |
| 1224 | local->scan_ssid_len); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1225 | ifsta->flags ^= IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1226 | } else { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1227 | ifsta->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1228 | if (time_after(jiffies, ifsta->last_probe + |
| 1229 | IEEE80211_PROBE_INTERVAL)) { |
| 1230 | ifsta->last_probe = jiffies; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1231 | ieee80211_send_probe_req(sdata, ifsta->bssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1232 | ifsta->ssid, |
| 1233 | ifsta->ssid_len); |
| 1234 | } |
| 1235 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1236 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1237 | |
| 1238 | rcu_read_unlock(); |
| 1239 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1240 | if (disassoc) |
| 1241 | ieee80211_set_disassoc(sdata, ifsta, true, true, |
| 1242 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1243 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1244 | mod_timer(&ifsta->timer, jiffies + |
| 1245 | IEEE80211_MONITORING_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1249 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1250 | struct ieee80211_if_sta *ifsta) |
| 1251 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1252 | printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1253 | ifsta->flags |= IEEE80211_STA_AUTHENTICATED; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1254 | ieee80211_associate(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1258 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1259 | struct ieee80211_if_sta *ifsta, |
| 1260 | struct ieee80211_mgmt *mgmt, |
| 1261 | size_t len) |
| 1262 | { |
| 1263 | u8 *pos; |
| 1264 | struct ieee802_11_elems elems; |
| 1265 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1266 | pos = mgmt->u.auth.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1267 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1268 | if (!elems.challenge) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1269 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1270 | ieee80211_send_auth(sdata, ifsta, 3, elems.challenge - 2, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1271 | elems.challenge_len + 2, 1); |
| 1272 | } |
| 1273 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1274 | static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid, |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1275 | u8 dialog_token, u16 status, u16 policy, |
| 1276 | u16 buf_size, u16 timeout) |
| 1277 | { |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1278 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1279 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1280 | struct sk_buff *skb; |
| 1281 | struct ieee80211_mgmt *mgmt; |
| 1282 | u16 capab; |
| 1283 | |
Ester Kummer | 3acea5b | 2008-04-17 16:05:14 -0700 | [diff] [blame] | 1284 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
| 1285 | |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1286 | if (!skb) { |
| 1287 | printk(KERN_DEBUG "%s: failed to allocate buffer " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1288 | "for addba resp frame\n", sdata->dev->name); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1289 | return; |
| 1290 | } |
| 1291 | |
| 1292 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1293 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1294 | memset(mgmt, 0, 24); |
| 1295 | memcpy(mgmt->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1296 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1297 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1298 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1299 | else |
| 1300 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1301 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1302 | IEEE80211_STYPE_ACTION); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1303 | |
| 1304 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp)); |
| 1305 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 1306 | mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP; |
| 1307 | mgmt->u.action.u.addba_resp.dialog_token = dialog_token; |
| 1308 | |
| 1309 | capab = (u16)(policy << 1); /* bit 1 aggregation policy */ |
| 1310 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ |
| 1311 | capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */ |
| 1312 | |
| 1313 | mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab); |
| 1314 | mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout); |
| 1315 | mgmt->u.action.u.addba_resp.status = cpu_to_le16(status); |
| 1316 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1317 | ieee80211_sta_tx(sdata, skb, 0); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1318 | |
| 1319 | return; |
| 1320 | } |
| 1321 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1322 | void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, const u8 *da, |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1323 | u16 tid, u8 dialog_token, u16 start_seq_num, |
| 1324 | u16 agg_size, u16 timeout) |
| 1325 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1326 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1327 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 1328 | struct sk_buff *skb; |
| 1329 | struct ieee80211_mgmt *mgmt; |
| 1330 | u16 capab; |
| 1331 | |
Ester Kummer | 3acea5b | 2008-04-17 16:05:14 -0700 | [diff] [blame] | 1332 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1333 | |
| 1334 | if (!skb) { |
| 1335 | printk(KERN_ERR "%s: failed to allocate buffer " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1336 | "for addba request frame\n", sdata->dev->name); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1337 | return; |
| 1338 | } |
| 1339 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1340 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1341 | memset(mgmt, 0, 24); |
| 1342 | memcpy(mgmt->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1343 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1344 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1345 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1346 | else |
| 1347 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 1348 | |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1349 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1350 | IEEE80211_STYPE_ACTION); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1351 | |
| 1352 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req)); |
| 1353 | |
| 1354 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 1355 | mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ; |
| 1356 | |
| 1357 | mgmt->u.action.u.addba_req.dialog_token = dialog_token; |
| 1358 | capab = (u16)(1 << 1); /* bit 1 aggregation policy */ |
| 1359 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ |
| 1360 | capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */ |
| 1361 | |
| 1362 | mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab); |
| 1363 | |
| 1364 | mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout); |
| 1365 | mgmt->u.action.u.addba_req.start_seq_num = |
| 1366 | cpu_to_le16(start_seq_num << 4); |
| 1367 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1368 | ieee80211_sta_tx(sdata, skb, 0); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 1371 | /* |
| 1372 | * After accepting the AddBA Request we activated a timer, |
| 1373 | * resetting it after each frame that arrives from the originator. |
| 1374 | * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed. |
| 1375 | */ |
| 1376 | static void sta_rx_agg_session_timer_expired(unsigned long data) |
| 1377 | { |
| 1378 | /* not an elegant detour, but there is no choice as the timer passes |
| 1379 | * only one argument, and various sta_info are needed here, so init |
| 1380 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
| 1381 | * array gives the sta through container_of */ |
| 1382 | u8 *ptid = (u8 *)data; |
| 1383 | u8 *timer_to_id = ptid - *ptid; |
| 1384 | struct sta_info *sta = container_of(timer_to_id, struct sta_info, |
| 1385 | timer_to_tid[0]); |
| 1386 | |
| 1387 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1388 | printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); |
| 1389 | #endif |
| 1390 | ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr, |
| 1391 | (u16)*ptid, WLAN_BACK_TIMER, |
| 1392 | WLAN_REASON_QSTA_TIMEOUT); |
| 1393 | } |
| 1394 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1395 | static void ieee80211_sta_process_addba_request(struct ieee80211_local *local, |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1396 | struct ieee80211_mgmt *mgmt, |
| 1397 | size_t len) |
| 1398 | { |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1399 | struct ieee80211_hw *hw = &local->hw; |
| 1400 | struct ieee80211_conf *conf = &hw->conf; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1401 | struct sta_info *sta; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1402 | struct tid_ampdu_rx *tid_agg_rx; |
| 1403 | u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1404 | u8 dialog_token; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1405 | int ret = -EOPNOTSUPP; |
| 1406 | DECLARE_MAC_BUF(mac); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1407 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1408 | rcu_read_lock(); |
| 1409 | |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1410 | sta = sta_info_get(local, mgmt->sa); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1411 | if (!sta) { |
| 1412 | rcu_read_unlock(); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1413 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1414 | } |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1415 | |
| 1416 | /* extract session parameters from addba request frame */ |
| 1417 | dialog_token = mgmt->u.action.u.addba_req.dialog_token; |
| 1418 | timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1419 | start_seq_num = |
| 1420 | 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] | 1421 | |
| 1422 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 1423 | ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1; |
| 1424 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1425 | buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6; |
| 1426 | |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1427 | status = WLAN_STATUS_REQUEST_DECLINED; |
| 1428 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1429 | /* sanity check for incoming parameters: |
| 1430 | * check if configuration can support the BA policy |
| 1431 | * and if buffer size does not exceeds max value */ |
| 1432 | if (((ba_policy != 1) |
| 1433 | && (!(conf->ht_conf.cap & IEEE80211_HT_CAP_DELAY_BA))) |
| 1434 | || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { |
| 1435 | status = WLAN_STATUS_INVALID_QOS_PARAM; |
| 1436 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1437 | if (net_ratelimit()) |
Ron Rindjunsky | 7b9d44c | 2008-03-18 15:00:31 -0700 | [diff] [blame] | 1438 | printk(KERN_DEBUG "AddBA Req with bad params from " |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1439 | "%s on tid %u. policy %d, buffer size %d\n", |
| 1440 | print_mac(mac, mgmt->sa), tid, ba_policy, |
| 1441 | buf_size); |
| 1442 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1443 | goto end_no_lock; |
| 1444 | } |
| 1445 | /* determine default buffer size */ |
| 1446 | if (buf_size == 0) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1447 | struct ieee80211_supported_band *sband; |
| 1448 | |
| 1449 | sband = local->hw.wiphy->bands[conf->channel->band]; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1450 | buf_size = IEEE80211_MIN_AMPDU_BUF; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1451 | buf_size = buf_size << sband->ht_info.ampdu_factor; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1452 | } |
| 1453 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1454 | |
| 1455 | /* examine state machine */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1456 | spin_lock_bh(&sta->lock); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1457 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1458 | if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) { |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1459 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1460 | if (net_ratelimit()) |
Ron Rindjunsky | 7b9d44c | 2008-03-18 15:00:31 -0700 | [diff] [blame] | 1461 | printk(KERN_DEBUG "unexpected AddBA Req from " |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1462 | "%s on tid %u\n", |
| 1463 | print_mac(mac, mgmt->sa), tid); |
| 1464 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1465 | goto end; |
| 1466 | } |
| 1467 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1468 | /* prepare A-MPDU MLME for Rx aggregation */ |
| 1469 | sta->ampdu_mlme.tid_rx[tid] = |
| 1470 | kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC); |
| 1471 | if (!sta->ampdu_mlme.tid_rx[tid]) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1472 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1473 | if (net_ratelimit()) |
| 1474 | printk(KERN_ERR "allocate rx mlme to tid %d failed\n", |
| 1475 | tid); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1476 | #endif |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1477 | goto end; |
| 1478 | } |
| 1479 | /* rx timer */ |
| 1480 | sta->ampdu_mlme.tid_rx[tid]->session_timer.function = |
| 1481 | sta_rx_agg_session_timer_expired; |
| 1482 | sta->ampdu_mlme.tid_rx[tid]->session_timer.data = |
| 1483 | (unsigned long)&sta->timer_to_tid[tid]; |
| 1484 | init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer); |
| 1485 | |
| 1486 | tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; |
| 1487 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1488 | /* prepare reordering buffer */ |
| 1489 | tid_agg_rx->reorder_buf = |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 1490 | kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC); |
Johannes Berg | 03147df | 2008-02-26 00:39:28 +0100 | [diff] [blame] | 1491 | if (!tid_agg_rx->reorder_buf) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1492 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 03147df | 2008-02-26 00:39:28 +0100 | [diff] [blame] | 1493 | if (net_ratelimit()) |
| 1494 | printk(KERN_ERR "can not allocate reordering buffer " |
| 1495 | "to tid %d\n", tid); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1496 | #endif |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1497 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1498 | goto end; |
| 1499 | } |
| 1500 | memset(tid_agg_rx->reorder_buf, 0, |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 1501 | buf_size * sizeof(struct sk_buff *)); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1502 | |
| 1503 | if (local->ops->ampdu_action) |
| 1504 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, |
Ron Rindjunsky | 0df3ef4 | 2008-01-28 14:07:15 +0200 | [diff] [blame] | 1505 | sta->addr, tid, &start_seq_num); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1506 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Ron Rindjunsky | 513a102 | 2008-04-07 10:16:56 -0700 | [diff] [blame] | 1507 | 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] | 1508 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1509 | |
| 1510 | if (ret) { |
| 1511 | kfree(tid_agg_rx->reorder_buf); |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1512 | kfree(tid_agg_rx); |
| 1513 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1514 | goto end; |
| 1515 | } |
| 1516 | |
| 1517 | /* change state and send addba resp */ |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1518 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1519 | tid_agg_rx->dialog_token = dialog_token; |
| 1520 | tid_agg_rx->ssn = start_seq_num; |
| 1521 | tid_agg_rx->head_seq_num = start_seq_num; |
| 1522 | tid_agg_rx->buf_size = buf_size; |
| 1523 | tid_agg_rx->timeout = timeout; |
| 1524 | tid_agg_rx->stored_mpdu_num = 0; |
| 1525 | status = WLAN_STATUS_SUCCESS; |
| 1526 | end: |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1527 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1528 | |
| 1529 | end_no_lock: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1530 | ieee80211_send_addba_resp(sta->sdata, sta->addr, tid, |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1531 | dialog_token, status, 1, buf_size, timeout); |
| 1532 | rcu_read_unlock(); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 1533 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1534 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1535 | static void ieee80211_sta_process_addba_resp(struct ieee80211_local *local, |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1536 | struct ieee80211_mgmt *mgmt, |
| 1537 | size_t len) |
| 1538 | { |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1539 | struct ieee80211_hw *hw = &local->hw; |
| 1540 | struct sta_info *sta; |
| 1541 | u16 capab; |
| 1542 | u16 tid; |
| 1543 | u8 *state; |
| 1544 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1545 | rcu_read_lock(); |
| 1546 | |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1547 | sta = sta_info_get(local, mgmt->sa); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1548 | if (!sta) { |
| 1549 | rcu_read_unlock(); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1550 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1551 | } |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1552 | |
| 1553 | capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); |
| 1554 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1555 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1556 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1557 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1558 | spin_lock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1559 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1560 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1561 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1562 | goto addba_resp_exit; |
| 1563 | } |
| 1564 | |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1565 | if (mgmt->u.action.u.addba_resp.dialog_token != |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1566 | sta->ampdu_mlme.tid_tx[tid]->dialog_token) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1567 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1568 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1569 | printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid); |
| 1570 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1571 | goto addba_resp_exit; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1574 | del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1575 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1576 | printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid); |
| 1577 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1578 | if (le16_to_cpu(mgmt->u.action.u.addba_resp.status) |
| 1579 | == WLAN_STATUS_SUCCESS) { |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1580 | *state |= HT_ADDBA_RECEIVED_MSK; |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1581 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1582 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1583 | if (*state == HT_AGG_STATE_OPERATIONAL) |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1584 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1585 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1586 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1587 | } else { |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1588 | sta->ampdu_mlme.addba_req_num[tid]++; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1589 | /* this will allow the state check in stop_BA_session */ |
| 1590 | *state = HT_AGG_STATE_OPERATIONAL; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1591 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1592 | ieee80211_stop_tx_ba_session(hw, sta->addr, tid, |
| 1593 | WLAN_BACK_INITIATOR); |
| 1594 | } |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1595 | |
| 1596 | addba_resp_exit: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1597 | rcu_read_unlock(); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1598 | } |
| 1599 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1600 | void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, const u8 *da, u16 tid, |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1601 | u16 initiator, u16 reason_code) |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1602 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1603 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1604 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 1605 | struct sk_buff *skb; |
| 1606 | struct ieee80211_mgmt *mgmt; |
| 1607 | u16 params; |
| 1608 | |
Ester Kummer | 3acea5b | 2008-04-17 16:05:14 -0700 | [diff] [blame] | 1609 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1610 | |
| 1611 | if (!skb) { |
| 1612 | printk(KERN_ERR "%s: failed to allocate buffer " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1613 | "for delba frame\n", sdata->dev->name); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1614 | return; |
| 1615 | } |
| 1616 | |
| 1617 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1618 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 1619 | memset(mgmt, 0, 24); |
| 1620 | memcpy(mgmt->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1621 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1622 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1623 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1624 | else |
| 1625 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1626 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 1627 | IEEE80211_STYPE_ACTION); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1628 | |
| 1629 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba)); |
| 1630 | |
| 1631 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 1632 | mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 1633 | params = (u16)(initiator << 11); /* bit 11 initiator */ |
| 1634 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
| 1635 | |
| 1636 | mgmt->u.action.u.delba.params = cpu_to_le16(params); |
| 1637 | mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code); |
| 1638 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1639 | ieee80211_sta_tx(sdata, skb, 0); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1640 | } |
| 1641 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1642 | void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1643 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1644 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1645 | struct sk_buff *skb; |
| 1646 | struct ieee80211_bar *bar; |
| 1647 | u16 bar_control = 0; |
| 1648 | |
| 1649 | skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); |
| 1650 | if (!skb) { |
| 1651 | printk(KERN_ERR "%s: failed to allocate buffer for " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1652 | "bar frame\n", sdata->dev->name); |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1653 | return; |
| 1654 | } |
| 1655 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1656 | bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar)); |
| 1657 | memset(bar, 0, sizeof(*bar)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1658 | bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 1659 | IEEE80211_STYPE_BACK_REQ); |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1660 | memcpy(bar->ra, ra, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1661 | memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1662 | bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; |
| 1663 | bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; |
| 1664 | bar_control |= (u16)(tid << 12); |
| 1665 | bar->control = cpu_to_le16(bar_control); |
| 1666 | bar->start_seq_num = cpu_to_le16(ssn); |
| 1667 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1668 | ieee80211_sta_tx(sdata, skb, 0); |
Ron Rindjunsky | 429a380 | 2008-07-01 14:16:03 +0300 | [diff] [blame] | 1669 | } |
| 1670 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1671 | void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1672 | u16 initiator, u16 reason) |
| 1673 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1674 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1675 | struct ieee80211_hw *hw = &local->hw; |
| 1676 | struct sta_info *sta; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1677 | int ret, i; |
Ron Rindjunsky | 513a102 | 2008-04-07 10:16:56 -0700 | [diff] [blame] | 1678 | DECLARE_MAC_BUF(mac); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1679 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1680 | rcu_read_lock(); |
| 1681 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1682 | sta = sta_info_get(local, ra); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1683 | if (!sta) { |
| 1684 | rcu_read_unlock(); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1685 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1686 | } |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1687 | |
| 1688 | /* check if TID is in operational state */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1689 | spin_lock_bh(&sta->lock); |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1690 | if (sta->ampdu_mlme.tid_state_rx[tid] |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1691 | != HT_AGG_STATE_OPERATIONAL) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1692 | spin_unlock_bh(&sta->lock); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1693 | rcu_read_unlock(); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1694 | return; |
| 1695 | } |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1696 | sta->ampdu_mlme.tid_state_rx[tid] = |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1697 | HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 1698 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1699 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1700 | |
| 1701 | /* stop HW Rx aggregation. ampdu_action existence |
| 1702 | * already verified in session init so we add the BUG_ON */ |
| 1703 | BUG_ON(!local->ops->ampdu_action); |
| 1704 | |
Ron Rindjunsky | 513a102 | 2008-04-07 10:16:56 -0700 | [diff] [blame] | 1705 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1706 | printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n", |
| 1707 | print_mac(mac, ra), tid); |
| 1708 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1709 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1710 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, |
Ron Rindjunsky | 0df3ef4 | 2008-01-28 14:07:15 +0200 | [diff] [blame] | 1711 | ra, tid, NULL); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1712 | if (ret) |
| 1713 | printk(KERN_DEBUG "HW problem - can not stop rx " |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1714 | "aggregation for tid %d\n", tid); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1715 | |
| 1716 | /* shutdown timer has not expired */ |
| 1717 | if (initiator != WLAN_BACK_TIMER) |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1718 | del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1719 | |
| 1720 | /* check if this is a self generated aggregation halt */ |
| 1721 | if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1722 | ieee80211_send_delba(sdata, ra, tid, 0, reason); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1723 | |
| 1724 | /* free the reordering buffer */ |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1725 | for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) { |
| 1726 | if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) { |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1727 | /* release the reordered frames */ |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1728 | dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]); |
| 1729 | sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--; |
| 1730 | sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL; |
Ron Rindjunsky | b580781 | 2007-12-25 17:00:35 +0200 | [diff] [blame] | 1731 | } |
| 1732 | } |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1733 | /* free resources */ |
| 1734 | kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf); |
| 1735 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
| 1736 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
| 1737 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE; |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1738 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1739 | rcu_read_unlock(); |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1740 | } |
| 1741 | |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1742 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1743 | static void ieee80211_sta_process_delba(struct ieee80211_sub_if_data *sdata, |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1744 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1745 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1746 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1747 | struct sta_info *sta; |
| 1748 | u16 tid, params; |
| 1749 | u16 initiator; |
| 1750 | DECLARE_MAC_BUF(mac); |
| 1751 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1752 | rcu_read_lock(); |
| 1753 | |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1754 | sta = sta_info_get(local, mgmt->sa); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1755 | if (!sta) { |
| 1756 | rcu_read_unlock(); |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1757 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1758 | } |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1759 | |
| 1760 | params = le16_to_cpu(mgmt->u.action.u.delba.params); |
| 1761 | tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; |
| 1762 | initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11; |
| 1763 | |
| 1764 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1765 | if (net_ratelimit()) |
Ron Rindjunsky | d92684e | 2008-01-28 14:07:22 +0200 | [diff] [blame] | 1766 | printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n", |
| 1767 | print_mac(mac, mgmt->sa), |
Ron Rindjunsky | 2e354ed | 2008-03-18 15:00:30 -0700 | [diff] [blame] | 1768 | initiator ? "initiator" : "recipient", tid, |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1769 | mgmt->u.action.u.delba.reason_code); |
| 1770 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1771 | |
| 1772 | if (initiator == WLAN_BACK_INITIATOR) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1773 | ieee80211_sta_stop_rx_ba_session(sdata, sta->addr, tid, |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1774 | WLAN_BACK_INITIATOR, 0); |
Ron Rindjunsky | d92684e | 2008-01-28 14:07:22 +0200 | [diff] [blame] | 1775 | else { /* WLAN_BACK_RECIPIENT */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1776 | spin_lock_bh(&sta->lock); |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1777 | sta->ampdu_mlme.tid_state_tx[tid] = |
Ron Rindjunsky | d92684e | 2008-01-28 14:07:22 +0200 | [diff] [blame] | 1778 | HT_AGG_STATE_OPERATIONAL; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1779 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | d92684e | 2008-01-28 14:07:22 +0200 | [diff] [blame] | 1780 | ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid, |
| 1781 | WLAN_BACK_RECIPIENT); |
| 1782 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1783 | rcu_read_unlock(); |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 1784 | } |
| 1785 | |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1786 | /* |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1787 | * After sending add Block Ack request we activated a timer until |
| 1788 | * add Block Ack response will arrive from the recipient. |
| 1789 | * If this timer expires sta_addba_resp_timer_expired will be executed. |
| 1790 | */ |
| 1791 | void sta_addba_resp_timer_expired(unsigned long data) |
| 1792 | { |
| 1793 | /* not an elegant detour, but there is no choice as the timer passes |
| 1794 | * only one argument, and both sta_info and TID are needed, so init |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1795 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1796 | * array gives the sta through container_of */ |
Senthil Balasubramanian | 70d251b | 2008-05-28 20:08:12 +0530 | [diff] [blame] | 1797 | u16 tid = *(u8 *)data; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1798 | struct sta_info *temp_sta = container_of((void *)data, |
| 1799 | struct sta_info, timer_to_tid[tid]); |
| 1800 | |
| 1801 | struct ieee80211_local *local = temp_sta->local; |
| 1802 | struct ieee80211_hw *hw = &local->hw; |
| 1803 | struct sta_info *sta; |
| 1804 | u8 *state; |
| 1805 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1806 | rcu_read_lock(); |
| 1807 | |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1808 | sta = sta_info_get(local, temp_sta->addr); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1809 | if (!sta) { |
| 1810 | rcu_read_unlock(); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1811 | return; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1812 | } |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1813 | |
Ron Rindjunsky | cee24a3 | 2008-03-26 20:36:03 +0200 | [diff] [blame] | 1814 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1815 | /* check if the TID waits for addBA response */ |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1816 | spin_lock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1817 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1818 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1819 | *state = HT_AGG_STATE_IDLE; |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1820 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1821 | printk(KERN_DEBUG "timer expired on tid %d but we are not " |
| 1822 | "expecting addBA response there", tid); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1823 | #endif |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1824 | goto timer_expired_exit; |
| 1825 | } |
| 1826 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1827 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1828 | printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1829 | #endif |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1830 | |
| 1831 | /* go through the state check in stop_BA_session */ |
| 1832 | *state = HT_AGG_STATE_OPERATIONAL; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1833 | spin_unlock_bh(&sta->lock); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1834 | ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid, |
| 1835 | WLAN_BACK_INITIATOR); |
| 1836 | |
| 1837 | timer_expired_exit: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1838 | rcu_read_unlock(); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1841 | void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr) |
Ron Rindjunsky | 85249e5 | 2008-03-18 15:00:32 -0700 | [diff] [blame] | 1842 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1843 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | 85249e5 | 2008-03-18 15:00:32 -0700 | [diff] [blame] | 1844 | int i; |
| 1845 | |
| 1846 | for (i = 0; i < STA_TID_NUM; i++) { |
| 1847 | ieee80211_stop_tx_ba_session(&local->hw, addr, i, |
| 1848 | WLAN_BACK_INITIATOR); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1849 | ieee80211_sta_stop_rx_ba_session(sdata, addr, i, |
Ron Rindjunsky | 85249e5 | 2008-03-18 15:00:32 -0700 | [diff] [blame] | 1850 | WLAN_BACK_RECIPIENT, |
| 1851 | WLAN_REASON_QSTA_LEAVE_QBSS); |
| 1852 | } |
| 1853 | } |
Ron Rindjunsky | 07db218 | 2007-12-25 17:00:33 +0200 | [diff] [blame] | 1854 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1855 | static void ieee80211_send_refuse_measurement_request(struct ieee80211_sub_if_data *sdata, |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1856 | struct ieee80211_msrment_ie *request_ie, |
| 1857 | const u8 *da, const u8 *bssid, |
| 1858 | u8 dialog_token) |
| 1859 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1860 | struct ieee80211_local *local = sdata->local; |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1861 | struct sk_buff *skb; |
| 1862 | struct ieee80211_mgmt *msr_report; |
| 1863 | |
| 1864 | skb = dev_alloc_skb(sizeof(*msr_report) + local->hw.extra_tx_headroom + |
| 1865 | sizeof(struct ieee80211_msrment_ie)); |
| 1866 | |
| 1867 | if (!skb) { |
| 1868 | printk(KERN_ERR "%s: failed to allocate buffer for " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1869 | "measurement report frame\n", sdata->dev->name); |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1870 | return; |
| 1871 | } |
| 1872 | |
| 1873 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1874 | msr_report = (struct ieee80211_mgmt *)skb_put(skb, 24); |
| 1875 | memset(msr_report, 0, 24); |
| 1876 | memcpy(msr_report->da, da, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1877 | memcpy(msr_report->sa, sdata->dev->dev_addr, ETH_ALEN); |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1878 | memcpy(msr_report->bssid, bssid, ETH_ALEN); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 1879 | msr_report->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1880 | IEEE80211_STYPE_ACTION); |
| 1881 | |
| 1882 | skb_put(skb, 1 + sizeof(msr_report->u.action.u.measurement)); |
| 1883 | msr_report->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT; |
| 1884 | msr_report->u.action.u.measurement.action_code = |
| 1885 | WLAN_ACTION_SPCT_MSR_RPRT; |
| 1886 | msr_report->u.action.u.measurement.dialog_token = dialog_token; |
| 1887 | |
| 1888 | msr_report->u.action.u.measurement.element_id = WLAN_EID_MEASURE_REPORT; |
| 1889 | msr_report->u.action.u.measurement.length = |
| 1890 | sizeof(struct ieee80211_msrment_ie); |
| 1891 | |
| 1892 | memset(&msr_report->u.action.u.measurement.msr_elem, 0, |
| 1893 | sizeof(struct ieee80211_msrment_ie)); |
| 1894 | msr_report->u.action.u.measurement.msr_elem.token = request_ie->token; |
| 1895 | msr_report->u.action.u.measurement.msr_elem.mode |= |
| 1896 | IEEE80211_SPCT_MSR_RPRT_MODE_REFUSED; |
| 1897 | msr_report->u.action.u.measurement.msr_elem.type = request_ie->type; |
| 1898 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1899 | ieee80211_sta_tx(sdata, skb, 0); |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1900 | } |
| 1901 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1902 | 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] | 1903 | struct ieee80211_mgmt *mgmt, |
| 1904 | size_t len) |
| 1905 | { |
| 1906 | /* |
| 1907 | * Ignoring measurement request is spec violation. |
| 1908 | * Mandatory measurements must be reported optional |
| 1909 | * measurements might be refused or reported incapable |
| 1910 | * For now just refuse |
| 1911 | * TODO: Answer basic measurement as unmeasured |
| 1912 | */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1913 | ieee80211_send_refuse_measurement_request(sdata, |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 1914 | &mgmt->u.action.u.measurement.msr_elem, |
| 1915 | mgmt->sa, mgmt->bssid, |
| 1916 | mgmt->u.action.u.measurement.dialog_token); |
| 1917 | } |
| 1918 | |
| 1919 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1920 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1921 | struct ieee80211_if_sta *ifsta, |
| 1922 | struct ieee80211_mgmt *mgmt, |
| 1923 | size_t len) |
| 1924 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1925 | u16 auth_alg, auth_transaction, status_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1926 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1927 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 1928 | if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1929 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1930 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1931 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1932 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1933 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1934 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1935 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1936 | memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1937 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1938 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1939 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1940 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1941 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1942 | |
| 1943 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 1944 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 1945 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 1946 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 1947 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Johannes Berg | 135a211 | 2008-06-16 20:55:29 +0200 | [diff] [blame] | 1948 | /* |
| 1949 | * IEEE 802.11 standard does not require authentication in IBSS |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1950 | * networks and most implementations do not seem to use it. |
| 1951 | * However, try to reply to authentication attempts if someone |
| 1952 | * has actually implemented this. |
Johannes Berg | 135a211 | 2008-06-16 20:55:29 +0200 | [diff] [blame] | 1953 | */ |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1954 | if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1955 | return; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1956 | ieee80211_send_auth(sdata, ifsta, 2, NULL, 0, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | if (auth_alg != ifsta->auth_alg || |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1960 | auth_transaction != ifsta->auth_transaction) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1961 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1962 | |
| 1963 | if (status_code != WLAN_STATUS_SUCCESS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1964 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
| 1965 | u8 algs[3]; |
| 1966 | const int num_algs = ARRAY_SIZE(algs); |
| 1967 | int i, pos; |
| 1968 | algs[0] = algs[1] = algs[2] = 0xff; |
| 1969 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 1970 | algs[0] = WLAN_AUTH_OPEN; |
| 1971 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 1972 | algs[1] = WLAN_AUTH_SHARED_KEY; |
| 1973 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 1974 | algs[2] = WLAN_AUTH_LEAP; |
| 1975 | if (ifsta->auth_alg == WLAN_AUTH_OPEN) |
| 1976 | pos = 0; |
| 1977 | else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY) |
| 1978 | pos = 1; |
| 1979 | else |
| 1980 | pos = 2; |
| 1981 | for (i = 0; i < num_algs; i++) { |
| 1982 | pos++; |
| 1983 | if (pos >= num_algs) |
| 1984 | pos = 0; |
| 1985 | if (algs[pos] == ifsta->auth_alg || |
| 1986 | algs[pos] == 0xff) |
| 1987 | continue; |
| 1988 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1989 | !ieee80211_sta_wep_configured(sdata)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1990 | continue; |
| 1991 | ifsta->auth_alg = algs[pos]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1992 | break; |
| 1993 | } |
| 1994 | } |
| 1995 | return; |
| 1996 | } |
| 1997 | |
| 1998 | switch (ifsta->auth_alg) { |
| 1999 | case WLAN_AUTH_OPEN: |
| 2000 | case WLAN_AUTH_LEAP: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2001 | ieee80211_auth_completed(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2002 | break; |
| 2003 | case WLAN_AUTH_SHARED_KEY: |
| 2004 | if (ifsta->auth_transaction == 4) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2005 | ieee80211_auth_completed(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2006 | else |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2007 | ieee80211_auth_challenge(sdata, ifsta, mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2008 | break; |
| 2009 | } |
| 2010 | } |
| 2011 | |
| 2012 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2013 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2014 | struct ieee80211_if_sta *ifsta, |
| 2015 | struct ieee80211_mgmt *mgmt, |
| 2016 | size_t len) |
| 2017 | { |
| 2018 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2019 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2020 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2021 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2022 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2023 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2024 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2025 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2026 | |
| 2027 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 2028 | |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 2029 | if (ifsta->flags & IEEE80211_STA_AUTHENTICATED) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2030 | printk(KERN_DEBUG "%s: deauthenticated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2031 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2032 | if (ifsta->state == IEEE80211_STA_MLME_AUTHENTICATE || |
| 2033 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATE || |
| 2034 | ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2035 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2036 | mod_timer(&ifsta->timer, jiffies + |
| 2037 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 2038 | } |
| 2039 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2040 | ieee80211_set_disassoc(sdata, ifsta, true, false, 0); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2041 | ifsta->flags &= ~IEEE80211_STA_AUTHENTICATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2045 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2046 | struct ieee80211_if_sta *ifsta, |
| 2047 | struct ieee80211_mgmt *mgmt, |
| 2048 | size_t len) |
| 2049 | { |
| 2050 | u16 reason_code; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2051 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2052 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2053 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2054 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2055 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2056 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2057 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2058 | |
| 2059 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 2060 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2061 | if (ifsta->flags & IEEE80211_STA_ASSOCIATED) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2062 | printk(KERN_DEBUG "%s: disassociated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2063 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2064 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) { |
| 2065 | ifsta->state = IEEE80211_STA_MLME_ASSOCIATE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2066 | mod_timer(&ifsta->timer, jiffies + |
| 2067 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 2068 | } |
| 2069 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 2070 | ieee80211_set_disassoc(sdata, ifsta, false, false, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2074 | 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] | 2075 | struct ieee80211_if_sta *ifsta, |
| 2076 | struct ieee80211_mgmt *mgmt, |
| 2077 | size_t len, |
| 2078 | int reassoc) |
| 2079 | { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2080 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2081 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2082 | struct sta_info *sta; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2083 | u64 rates, basic_rates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2084 | u16 capab_info, status_code, aid; |
| 2085 | struct ieee802_11_elems elems; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2086 | struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2087 | u8 *pos; |
| 2088 | int i, j; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2089 | DECLARE_MAC_BUF(mac); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2090 | bool have_higher_than_11mbit = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2091 | |
| 2092 | /* AssocResp and ReassocResp have identical structure, so process both |
| 2093 | * of them in this function. */ |
| 2094 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2095 | if (ifsta->state != IEEE80211_STA_MLME_ASSOCIATE) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2096 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2097 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2098 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2099 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2100 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2101 | if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2102 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2103 | |
| 2104 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 2105 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 2106 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2107 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2108 | printk(KERN_DEBUG "%s: RX %sssocResp from %s (capab=0x%x " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2109 | "status=%d aid=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2110 | sdata->dev->name, reassoc ? "Rea" : "A", print_mac(mac, mgmt->sa), |
Johannes Berg | ddd6858 | 2007-10-22 14:51:37 +0200 | [diff] [blame] | 2111 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2112 | |
| 2113 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 2114 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2115 | sdata->dev->name, status_code); |
Daniel Drake | 8a69aa9 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 2116 | /* if this was a reassociation, ensure we try a "full" |
| 2117 | * association next time. This works around some broken APs |
| 2118 | * which do not correctly reject reassociation requests. */ |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2119 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2120 | return; |
| 2121 | } |
| 2122 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2123 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 2124 | 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] | 2125 | "set\n", sdata->dev->name, aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2126 | aid &= ~(BIT(15) | BIT(14)); |
| 2127 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2128 | pos = mgmt->u.assoc_resp.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 2129 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2130 | |
| 2131 | if (!elems.supp_rates) { |
| 2132 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2133 | sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2134 | return; |
| 2135 | } |
| 2136 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2137 | printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2138 | ifsta->aid = aid; |
| 2139 | ifsta->ap_capab = capab_info; |
| 2140 | |
| 2141 | kfree(ifsta->assocresp_ies); |
| 2142 | ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt); |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2143 | ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2144 | if (ifsta->assocresp_ies) |
| 2145 | memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); |
| 2146 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2147 | rcu_read_lock(); |
| 2148 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2149 | /* Add STA entry for the AP */ |
| 2150 | sta = sta_info_get(local, ifsta->bssid); |
| 2151 | if (!sta) { |
| 2152 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2153 | int err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2155 | sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); |
| 2156 | if (!sta) { |
| 2157 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2158 | " the AP\n", sdata->dev->name); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2159 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2160 | return; |
| 2161 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2162 | bss = ieee80211_rx_bss_get(local, ifsta->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2163 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 2164 | ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2165 | if (bss) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2166 | sta->last_signal = bss->signal; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2167 | sta->last_qual = bss->qual; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2168 | sta->last_noise = bss->noise; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2169 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2170 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2171 | |
| 2172 | err = sta_info_insert(sta); |
| 2173 | if (err) { |
| 2174 | printk(KERN_DEBUG "%s: failed to insert STA entry for" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2175 | " the AP (error %d)\n", sdata->dev->name, err); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2176 | rcu_read_unlock(); |
| 2177 | return; |
| 2178 | } |
Ron Rindjunsky | a61dae1 | 2008-08-10 00:54:34 +0300 | [diff] [blame] | 2179 | /* update new sta with its last rx activity */ |
| 2180 | sta->last_rx = jiffies; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 2183 | /* |
| 2184 | * FIXME: Do we really need to update the sta_info's information here? |
| 2185 | * We already know about the AP (we found it in our list) so it |
| 2186 | * should already be filled with the right info, no? |
| 2187 | * As is stands, all this is racy because typically we assume |
| 2188 | * the information that is filled in here (except flags) doesn't |
| 2189 | * change while a STA structure is alive. As such, it should move |
| 2190 | * to between the sta_info_alloc() and sta_info_insert() above. |
| 2191 | */ |
| 2192 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 2193 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
| 2194 | WLAN_STA_AUTHORIZED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2195 | |
| 2196 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2197 | basic_rates = 0; |
| 2198 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 2199 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2200 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 2201 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2202 | |
| 2203 | if (rate > 110) |
| 2204 | have_higher_than_11mbit = true; |
| 2205 | |
| 2206 | for (j = 0; j < sband->n_bitrates; j++) { |
| 2207 | if (sband->bitrates[j].bitrate == rate) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2208 | rates |= BIT(j); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2209 | if (elems.supp_rates[i] & 0x80) |
| 2210 | basic_rates |= BIT(j); |
| 2211 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2212 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2213 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2214 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 2215 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2216 | |
| 2217 | if (rate > 110) |
| 2218 | have_higher_than_11mbit = true; |
| 2219 | |
| 2220 | for (j = 0; j < sband->n_bitrates; j++) { |
| 2221 | if (sband->bitrates[j].bitrate == rate) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2222 | rates |= BIT(j); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2223 | if (elems.ext_supp_rates[i] & 0x80) |
| 2224 | basic_rates |= BIT(j); |
| 2225 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2226 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2227 | |
| 2228 | sta->supp_rates[local->hw.conf.channel->band] = rates; |
| 2229 | sdata->basic_rates = basic_rates; |
| 2230 | |
| 2231 | /* cf. IEEE 802.11 9.2.12 */ |
| 2232 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 2233 | have_higher_than_11mbit) |
| 2234 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 2235 | else |
| 2236 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2237 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2238 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
| 2239 | (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2240 | struct ieee80211_ht_bss_info bss_info; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2241 | ieee80211_ht_cap_ie_to_ht_info( |
| 2242 | (struct ieee80211_ht_cap *) |
| 2243 | elems.ht_cap_elem, &sta->ht_info); |
| 2244 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 2245 | (struct ieee80211_ht_addt_info *) |
| 2246 | elems.ht_info_elem, &bss_info); |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 2247 | ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2248 | } |
| 2249 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2250 | rate_control_rate_init(sta, local); |
| 2251 | |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 2252 | if (elems.wmm_param) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 2253 | set_sta_flags(sta, WLAN_STA_WME); |
Johannes Berg | e5f98f2 | 2008-03-05 20:39:31 +0100 | [diff] [blame] | 2254 | rcu_read_unlock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2255 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2256 | elems.wmm_param_len); |
Johannes Berg | e5f98f2 | 2008-03-05 20:39:31 +0100 | [diff] [blame] | 2257 | } else |
| 2258 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2259 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2260 | /* set AID and assoc capability, |
| 2261 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2262 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2263 | bss_conf->assoc_capability = capab_info; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 2264 | ieee80211_set_associated(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2265 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2266 | ieee80211_associated(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2270 | static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2271 | struct ieee80211_if_sta *ifsta, |
| 2272 | struct ieee80211_sta_bss *bss) |
| 2273 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2274 | struct ieee80211_local *local = sdata->local; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2275 | int res, rates, i, j; |
| 2276 | struct sk_buff *skb; |
| 2277 | struct ieee80211_mgmt *mgmt; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2278 | u8 *pos; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2279 | struct ieee80211_supported_band *sband; |
Dan Williams | 507b06d | 2008-06-03 23:39:55 -0400 | [diff] [blame] | 2280 | union iwreq_data wrqu; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2281 | |
| 2282 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 2283 | |
| 2284 | /* Remove possible STA entries from other IBSS networks. */ |
Johannes Berg | dc6676b | 2008-03-31 19:23:03 +0200 | [diff] [blame] | 2285 | sta_info_flush_delayed(sdata); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2286 | |
| 2287 | if (local->ops->reset_tsf) { |
| 2288 | /* Reset own TSF to allow time synchronization work. */ |
| 2289 | local->ops->reset_tsf(local_to_hw(local)); |
| 2290 | } |
| 2291 | memcpy(ifsta->bssid, bss->bssid, ETH_ALEN); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2292 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2293 | if (res) |
| 2294 | return res; |
| 2295 | |
| 2296 | local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10; |
| 2297 | |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2298 | sdata->drop_unencrypted = bss->capability & |
| 2299 | WLAN_CAPABILITY_PRIVACY ? 1 : 0; |
| 2300 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2301 | res = ieee80211_set_freq(sdata, bss->freq); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2302 | |
Assaf Krauss | be038b3 | 2008-06-05 19:55:21 +0300 | [diff] [blame] | 2303 | if (res) |
| 2304 | return res; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2305 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2306 | /* Build IBSS probe response */ |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2307 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2308 | if (skb) { |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2309 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2310 | |
| 2311 | mgmt = (struct ieee80211_mgmt *) |
| 2312 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); |
| 2313 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 2314 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 2315 | IEEE80211_STYPE_PROBE_RESP); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2316 | memset(mgmt->da, 0xff, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2317 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2318 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 2319 | mgmt->u.beacon.beacon_int = |
| 2320 | cpu_to_le16(local->hw.conf.beacon_int); |
Assaf Krauss | 4faeb86 | 2008-06-30 17:23:16 +0800 | [diff] [blame] | 2321 | mgmt->u.beacon.timestamp = cpu_to_le64(bss->timestamp); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2322 | mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability); |
| 2323 | |
| 2324 | pos = skb_put(skb, 2 + ifsta->ssid_len); |
| 2325 | *pos++ = WLAN_EID_SSID; |
| 2326 | *pos++ = ifsta->ssid_len; |
| 2327 | memcpy(pos, ifsta->ssid, ifsta->ssid_len); |
| 2328 | |
| 2329 | rates = bss->supp_rates_len; |
| 2330 | if (rates > 8) |
| 2331 | rates = 8; |
| 2332 | pos = skb_put(skb, 2 + rates); |
| 2333 | *pos++ = WLAN_EID_SUPP_RATES; |
| 2334 | *pos++ = rates; |
| 2335 | memcpy(pos, bss->supp_rates, rates); |
| 2336 | |
| 2337 | if (bss->band == IEEE80211_BAND_2GHZ) { |
| 2338 | pos = skb_put(skb, 2 + 1); |
| 2339 | *pos++ = WLAN_EID_DS_PARAMS; |
| 2340 | *pos++ = 1; |
| 2341 | *pos++ = ieee80211_frequency_to_channel(bss->freq); |
| 2342 | } |
| 2343 | |
| 2344 | pos = skb_put(skb, 2 + 2); |
| 2345 | *pos++ = WLAN_EID_IBSS_PARAMS; |
| 2346 | *pos++ = 2; |
| 2347 | /* FIX: set ATIM window based on scan results */ |
| 2348 | *pos++ = 0; |
| 2349 | *pos++ = 0; |
| 2350 | |
| 2351 | if (bss->supp_rates_len > 8) { |
| 2352 | rates = bss->supp_rates_len - 8; |
| 2353 | pos = skb_put(skb, 2 + rates); |
| 2354 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 2355 | *pos++ = rates; |
| 2356 | memcpy(pos, &bss->supp_rates[8], rates); |
| 2357 | } |
| 2358 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2359 | ifsta->probe_resp = skb; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2360 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2361 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2362 | } |
| 2363 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2364 | rates = 0; |
| 2365 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 2366 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 2367 | int bitrate = (bss->supp_rates[i] & 0x7f) * 5; |
| 2368 | for (j = 0; j < sband->n_bitrates; j++) |
| 2369 | if (sband->bitrates[j].bitrate == bitrate) |
| 2370 | rates |= BIT(j); |
| 2371 | } |
| 2372 | ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates; |
| 2373 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2374 | ieee80211_sta_def_wmm_params(sdata, bss, 1); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 2375 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2376 | ifsta->state = IEEE80211_STA_MLME_IBSS_JOINED; |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2377 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 2378 | |
Dan Williams | 507b06d | 2008-06-03 23:39:55 -0400 | [diff] [blame] | 2379 | memset(&wrqu, 0, sizeof(wrqu)); |
| 2380 | memcpy(wrqu.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2381 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2382 | |
| 2383 | return res; |
| 2384 | } |
| 2385 | |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2386 | u64 ieee80211_sta_get_rates(struct ieee80211_local *local, |
| 2387 | struct ieee802_11_elems *elems, |
| 2388 | enum ieee80211_band band) |
| 2389 | { |
| 2390 | struct ieee80211_supported_band *sband; |
| 2391 | struct ieee80211_rate *bitrates; |
| 2392 | size_t num_rates; |
| 2393 | u64 supp_rates; |
| 2394 | int i, j; |
| 2395 | sband = local->hw.wiphy->bands[band]; |
| 2396 | |
| 2397 | if (!sband) { |
| 2398 | WARN_ON(1); |
| 2399 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 2400 | } |
| 2401 | |
| 2402 | bitrates = sband->bitrates; |
| 2403 | num_rates = sband->n_bitrates; |
| 2404 | supp_rates = 0; |
| 2405 | for (i = 0; i < elems->supp_rates_len + |
| 2406 | elems->ext_supp_rates_len; i++) { |
| 2407 | u8 rate = 0; |
| 2408 | int own_rate; |
| 2409 | if (i < elems->supp_rates_len) |
| 2410 | rate = elems->supp_rates[i]; |
| 2411 | else if (elems->ext_supp_rates) |
| 2412 | rate = elems->ext_supp_rates |
| 2413 | [i - elems->supp_rates_len]; |
| 2414 | own_rate = 5 * (rate & 0x7f); |
| 2415 | for (j = 0; j < num_rates; j++) |
| 2416 | if (bitrates[j].bitrate == own_rate) |
| 2417 | supp_rates |= BIT(j); |
| 2418 | } |
| 2419 | return supp_rates; |
| 2420 | } |
| 2421 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2422 | static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local, |
| 2423 | enum ieee80211_band band) |
| 2424 | { |
| 2425 | struct ieee80211_supported_band *sband; |
| 2426 | struct ieee80211_rate *bitrates; |
| 2427 | u64 mandatory_rates; |
| 2428 | enum ieee80211_rate_flags mandatory_flag; |
| 2429 | int i; |
| 2430 | |
| 2431 | sband = local->hw.wiphy->bands[band]; |
| 2432 | if (!sband) { |
| 2433 | WARN_ON(1); |
| 2434 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 2435 | } |
| 2436 | |
| 2437 | if (band == IEEE80211_BAND_2GHZ) |
| 2438 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 2439 | else |
| 2440 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 2441 | |
| 2442 | bitrates = sband->bitrates; |
| 2443 | mandatory_rates = 0; |
| 2444 | for (i = 0; i < sband->n_bitrates; i++) |
| 2445 | if (bitrates[i].flags & mandatory_flag) |
| 2446 | mandatory_rates |= BIT(i); |
| 2447 | return mandatory_rates; |
| 2448 | } |
Bruno Randolf | a607268 | 2008-02-18 11:21:15 +0900 | [diff] [blame] | 2449 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2450 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2451 | struct ieee80211_mgmt *mgmt, |
| 2452 | size_t len, |
| 2453 | struct ieee80211_rx_status *rx_status, |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2454 | struct ieee802_11_elems *elems) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2455 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2456 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2457 | int freq, clen; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2458 | struct ieee80211_sta_bss *bss; |
| 2459 | struct sta_info *sta; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 2460 | struct ieee80211_channel *channel; |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2461 | u64 beacon_timestamp, rx_timestamp; |
| 2462 | u64 supp_rates = 0; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2463 | bool beacon = ieee80211_is_beacon(mgmt->frame_control); |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2464 | enum ieee80211_band band = rx_status->band; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2465 | DECLARE_MAC_BUF(mac); |
| 2466 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2467 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2468 | if (elems->ds_params && elems->ds_params_len == 1) |
| 2469 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); |
| 2470 | else |
| 2471 | freq = rx_status->freq; |
| 2472 | |
| 2473 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 2474 | |
| 2475 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 2476 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2477 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2478 | if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2479 | elems->mesh_config && mesh_matches_local(elems, sdata)) { |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2480 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 2481 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2482 | mesh_neighbour_update(mgmt->sa, supp_rates, sdata, |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2483 | mesh_peer_accepts_plinks(elems)); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 2484 | } |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2485 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2486 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates && |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2487 | memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2488 | supp_rates = ieee80211_sta_get_rates(local, elems, band); |
| 2489 | |
Johannes Berg | 69e6c01 | 2008-09-08 11:05:08 +0200 | [diff] [blame] | 2490 | rcu_read_lock(); |
| 2491 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2492 | sta = sta_info_get(local, mgmt->sa); |
| 2493 | if (sta) { |
| 2494 | u64 prev_rates; |
| 2495 | |
| 2496 | prev_rates = sta->supp_rates[band]; |
| 2497 | /* make sure mandatory rates are always added */ |
| 2498 | sta->supp_rates[band] = supp_rates | |
| 2499 | ieee80211_sta_get_mandatory_rates(local, band); |
| 2500 | |
| 2501 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2502 | if (sta->supp_rates[band] != prev_rates) |
| 2503 | printk(KERN_DEBUG "%s: updated supp_rates set " |
| 2504 | "for %s based on beacon info (0x%llx | " |
| 2505 | "0x%llx -> 0x%llx)\n", |
| 2506 | sdata->dev->name, print_mac(mac, sta->addr), |
| 2507 | (unsigned long long) prev_rates, |
| 2508 | (unsigned long long) supp_rates, |
| 2509 | (unsigned long long) sta->supp_rates[band]); |
| 2510 | #endif |
| 2511 | } else { |
| 2512 | ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, |
| 2513 | mgmt->sa, supp_rates); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2514 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2515 | |
Johannes Berg | 69e6c01 | 2008-09-08 11:05:08 +0200 | [diff] [blame] | 2516 | rcu_read_unlock(); |
| 2517 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 2518 | |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2519 | #ifdef CONFIG_MAC80211_MESH |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2520 | if (elems->mesh_config) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2521 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2522 | elems->mesh_id_len, elems->mesh_config, freq); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2523 | else |
| 2524 | #endif |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2525 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2526 | elems->ssid, elems->ssid_len); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2527 | if (!bss) { |
| 2528 | #ifdef CONFIG_MAC80211_MESH |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2529 | if (elems->mesh_config) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2530 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2531 | elems->mesh_id_len, elems->mesh_config, |
| 2532 | elems->mesh_config_len, freq); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2533 | else |
| 2534 | #endif |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2535 | bss = ieee80211_rx_bss_add(sdata, mgmt->bssid, freq, |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2536 | elems->ssid, elems->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2537 | if (!bss) |
| 2538 | return; |
| 2539 | } else { |
| 2540 | #if 0 |
| 2541 | /* TODO: order by RSSI? */ |
| 2542 | spin_lock_bh(&local->sta_bss_lock); |
| 2543 | list_move_tail(&bss->list, &local->sta_bss_list); |
| 2544 | spin_unlock_bh(&local->sta_bss_lock); |
| 2545 | #endif |
| 2546 | } |
| 2547 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2548 | /* save the ERP value so that it is available at association time */ |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2549 | if (elems->erp_info && elems->erp_info_len >= 1) { |
| 2550 | bss->erp_value = elems->erp_info[0]; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2551 | bss->has_erp_value = 1; |
| 2552 | } |
| 2553 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2554 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); |
| 2555 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2556 | |
Emmanuel Grumbach | 98f7dfd | 2008-07-18 13:52:59 +0800 | [diff] [blame] | 2557 | if (elems->tim) { |
| 2558 | struct ieee80211_tim_ie *tim_ie = |
| 2559 | (struct ieee80211_tim_ie *)elems->tim; |
| 2560 | bss->dtim_period = tim_ie->dtim_period; |
| 2561 | } |
| 2562 | |
| 2563 | /* set default value for buggy APs */ |
| 2564 | if (!elems->tim || bss->dtim_period == 0) |
| 2565 | bss->dtim_period = 1; |
| 2566 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2567 | bss->supp_rates_len = 0; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2568 | if (elems->supp_rates) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2569 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2570 | if (clen > elems->supp_rates_len) |
| 2571 | clen = elems->supp_rates_len; |
| 2572 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2573 | clen); |
| 2574 | bss->supp_rates_len += clen; |
| 2575 | } |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2576 | if (elems->ext_supp_rates) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2577 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2578 | if (clen > elems->ext_supp_rates_len) |
| 2579 | clen = elems->ext_supp_rates_len; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2580 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2581 | elems->ext_supp_rates, clen); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2582 | bss->supp_rates_len += clen; |
| 2583 | } |
| 2584 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2585 | bss->band = band; |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 2586 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2587 | beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
| 2588 | |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 2589 | bss->timestamp = beacon_timestamp; |
| 2590 | bss->last_update = jiffies; |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 2591 | bss->signal = rx_status->signal; |
| 2592 | bss->noise = rx_status->noise; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2593 | bss->qual = rx_status->qual; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2594 | if (!beacon) |
| 2595 | bss->last_probe_resp = jiffies; |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 2596 | /* |
| 2597 | * In STA mode, the remaining parameters should not be overridden |
| 2598 | * by beacons because they're not necessarily accurate there. |
| 2599 | */ |
| 2600 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2601 | bss->last_probe_resp && beacon) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2602 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | 30b89b0 | 2008-04-16 17:43:20 +0200 | [diff] [blame] | 2603 | return; |
| 2604 | } |
| 2605 | |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 2606 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { |
| 2607 | kfree(bss->ies); |
| 2608 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2609 | } |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 2610 | if (bss->ies) { |
| 2611 | memcpy(bss->ies, elems->ie_start, elems->total_len); |
| 2612 | bss->ies_len = elems->total_len; |
| 2613 | } else |
| 2614 | bss->ies_len = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2615 | |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 2616 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2617 | |
| 2618 | /* check if we need to merge IBSS */ |
| 2619 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && |
| 2620 | !local->sta_sw_scanning && !local->sta_hw_scanning && |
Johannes Berg | fba4a1e | 2008-02-21 11:08:33 +0100 | [diff] [blame] | 2621 | bss->capability & WLAN_CAPABILITY_IBSS && |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2622 | bss->freq == local->oper_channel->center_freq && |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2623 | elems->ssid_len == sdata->u.sta.ssid_len && |
| 2624 | memcmp(elems->ssid, sdata->u.sta.ssid, |
| 2625 | sdata->u.sta.ssid_len) == 0) { |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2626 | if (rx_status->flag & RX_FLAG_TSFT) { |
| 2627 | /* in order for correct IBSS merging we need mactime |
| 2628 | * |
| 2629 | * since mactime is defined as the time the first data |
| 2630 | * symbol of the frame hits the PHY, and the timestamp |
| 2631 | * of the beacon is defined as "the time that the data |
| 2632 | * symbol containing the first bit of the timestamp is |
| 2633 | * transmitted to the PHY plus the transmitting STA’s |
| 2634 | * delays through its local PHY from the MAC-PHY |
| 2635 | * interface to its interface with the WM" |
| 2636 | * (802.11 11.1.2) - equals the time this bit arrives at |
| 2637 | * the receiver - we have to take into account the |
| 2638 | * offset between the two. |
| 2639 | * e.g: at 1 MBit that means mactime is 192 usec earlier |
| 2640 | * (=24 bytes * 8 usecs/byte) than the beacon timestamp. |
| 2641 | */ |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2642 | int rate = local->hw.wiphy->bands[band]-> |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2643 | bitrates[rx_status->rate_idx].bitrate; |
| 2644 | rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); |
| 2645 | } else if (local && local->ops && local->ops->get_tsf) |
| 2646 | /* second best option: get current TSF */ |
| 2647 | rx_timestamp = local->ops->get_tsf(local_to_hw(local)); |
| 2648 | else |
| 2649 | /* can't merge without knowing the TSF */ |
| 2650 | rx_timestamp = -1LLU; |
| 2651 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2652 | printk(KERN_DEBUG "RX beacon SA=%s BSSID=" |
| 2653 | "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", |
| 2654 | print_mac(mac, mgmt->sa), |
| 2655 | print_mac(mac2, mgmt->bssid), |
| 2656 | (unsigned long long)rx_timestamp, |
| 2657 | (unsigned long long)beacon_timestamp, |
| 2658 | (unsigned long long)(rx_timestamp - beacon_timestamp), |
| 2659 | jiffies); |
| 2660 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2661 | if (beacon_timestamp > rx_timestamp) { |
John W. Linville | 576fdea | 2008-08-26 20:33:34 -0400 | [diff] [blame] | 2662 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2663 | printk(KERN_DEBUG "%s: beacon TSF higher than " |
| 2664 | "local TSF - IBSS merge with BSSID %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2665 | sdata->dev->name, print_mac(mac, mgmt->bssid)); |
Johannes Berg | fba4a1e | 2008-02-21 11:08:33 +0100 | [diff] [blame] | 2666 | #endif |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2667 | ieee80211_sta_join_ibss(sdata, &sdata->u.sta, bss); |
| 2668 | ieee80211_ibss_add_sta(sdata, NULL, |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 2669 | mgmt->bssid, mgmt->sa, |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 2670 | supp_rates); |
Bruno Randolf | 9d9bf77 | 2008-02-18 11:21:36 +0900 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 2674 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2675 | } |
| 2676 | |
| 2677 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2678 | 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] | 2679 | struct ieee80211_mgmt *mgmt, |
| 2680 | size_t len, |
| 2681 | struct ieee80211_rx_status *rx_status) |
| 2682 | { |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2683 | size_t baselen; |
| 2684 | struct ieee802_11_elems elems; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2685 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2686 | |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 2687 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
| 2688 | return; /* ignore ProbeResp to foreign address */ |
| 2689 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2690 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 2691 | if (baselen > len) |
| 2692 | return; |
| 2693 | |
| 2694 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 2695 | &elems); |
| 2696 | |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2697 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); |
| 2698 | |
| 2699 | /* direct probe may be part of the association flow */ |
| 2700 | if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, |
| 2701 | &ifsta->request)) { |
| 2702 | printk(KERN_DEBUG "%s direct probe responded\n", |
| 2703 | sdata->dev->name); |
| 2704 | ieee80211_authenticate(sdata, ifsta); |
| 2705 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2709 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2710 | struct ieee80211_mgmt *mgmt, |
| 2711 | size_t len, |
| 2712 | struct ieee80211_rx_status *rx_status) |
| 2713 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2714 | struct ieee80211_if_sta *ifsta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2715 | size_t baselen; |
| 2716 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2717 | struct ieee80211_local *local = sdata->local; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2718 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2719 | u32 changed = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2720 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2721 | /* Process beacon from the current BSS */ |
| 2722 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 2723 | if (baselen > len) |
| 2724 | return; |
| 2725 | |
| 2726 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
| 2727 | |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2728 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2729 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2730 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2731 | return; |
| 2732 | ifsta = &sdata->u.sta; |
| 2733 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2734 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED) || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2735 | memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) |
| 2736 | return; |
| 2737 | |
Reinette Chatre | d18ef29 | 2008-04-09 16:56:15 -0700 | [diff] [blame] | 2738 | /* Do not send changes to driver if we are scanning. This removes |
Johannes Berg | fe3fa82 | 2008-09-08 11:05:09 +0200 | [diff] [blame] | 2739 | * requirement that a driver's bss_info_changed/conf_tx functions |
| 2740 | * need to be atomic. |
| 2741 | * This is really ugly code, we should rewrite scanning and make |
| 2742 | * all this more understandable for humans. |
| 2743 | */ |
Reinette Chatre | d18ef29 | 2008-04-09 16:56:15 -0700 | [diff] [blame] | 2744 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
| 2745 | return; |
| 2746 | |
Johannes Berg | fe3fa82 | 2008-09-08 11:05:09 +0200 | [diff] [blame] | 2747 | ieee80211_sta_wmm_params(local, ifsta, elems.wmm_param, |
| 2748 | elems.wmm_param_len); |
| 2749 | |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 2750 | if (elems.erp_info && elems.erp_info_len >= 1) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2751 | changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]); |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2752 | else { |
| 2753 | u16 capab = le16_to_cpu(mgmt->u.beacon.capab_info); |
| 2754 | changed |= ieee80211_handle_protect_preamb(sdata, false, |
| 2755 | (capab & WLAN_CAPABILITY_SHORT_PREAMBLE) != 0); |
| 2756 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2757 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2758 | if (elems.ht_cap_elem && elems.ht_info_elem && |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 2759 | elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) { |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2760 | struct ieee80211_ht_bss_info bss_info; |
| 2761 | |
| 2762 | ieee80211_ht_addt_info_ie_to_ht_bss_info( |
| 2763 | (struct ieee80211_ht_addt_info *) |
| 2764 | elems.ht_info_elem, &bss_info); |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 2765 | changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf, |
| 2766 | &bss_info); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2767 | } |
| 2768 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2769 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2773 | 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] | 2774 | struct ieee80211_if_sta *ifsta, |
| 2775 | struct ieee80211_mgmt *mgmt, |
| 2776 | size_t len, |
| 2777 | struct ieee80211_rx_status *rx_status) |
| 2778 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2779 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2780 | int tx_last_beacon; |
| 2781 | struct sk_buff *skb; |
| 2782 | struct ieee80211_mgmt *resp; |
| 2783 | u8 *pos, *end; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2784 | DECLARE_MAC_BUF(mac); |
| 2785 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2786 | DECLARE_MAC_BUF(mac2); |
| 2787 | DECLARE_MAC_BUF(mac3); |
| 2788 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2789 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2790 | if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 2791 | ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2792 | len < 24 + 2 || !ifsta->probe_resp) |
| 2793 | return; |
| 2794 | |
| 2795 | if (local->ops->tx_last_beacon) |
| 2796 | tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local)); |
| 2797 | else |
| 2798 | tx_last_beacon = 1; |
| 2799 | |
| 2800 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2801 | printk(KERN_DEBUG "%s: RX ProbeReq SA=%s DA=%s BSSID=" |
| 2802 | "%s (tx_last_beacon=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2803 | 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] | 2804 | print_mac(mac3, mgmt->bssid), tx_last_beacon); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2805 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 2806 | |
| 2807 | if (!tx_last_beacon) |
| 2808 | return; |
| 2809 | |
| 2810 | if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 && |
| 2811 | memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0) |
| 2812 | return; |
| 2813 | |
| 2814 | end = ((u8 *) mgmt) + len; |
| 2815 | pos = mgmt->u.probe_req.variable; |
| 2816 | if (pos[0] != WLAN_EID_SSID || |
| 2817 | pos + 2 + pos[1] > end) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2818 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 2819 | printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " |
| 2820 | "from %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2821 | sdata->dev->name, print_mac(mac, mgmt->sa)); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2822 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2823 | return; |
| 2824 | } |
| 2825 | if (pos[1] != 0 && |
| 2826 | (pos[1] != ifsta->ssid_len || |
| 2827 | memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) { |
| 2828 | /* Ignore ProbeReq for foreign SSID */ |
| 2829 | return; |
| 2830 | } |
| 2831 | |
| 2832 | /* Reply with ProbeResp */ |
Michael Wu | 0ec0b7a | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2833 | skb = skb_copy(ifsta->probe_resp, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2834 | if (!skb) |
| 2835 | return; |
| 2836 | |
| 2837 | resp = (struct ieee80211_mgmt *) skb->data; |
| 2838 | memcpy(resp->da, mgmt->sa, ETH_ALEN); |
| 2839 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2840 | printk(KERN_DEBUG "%s: Sending ProbeResp to %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2841 | sdata->dev->name, print_mac(mac, resp->da)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2842 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2843 | ieee80211_sta_tx(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2846 | static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 4e20cb2 | 2007-12-19 01:31:24 +0100 | [diff] [blame] | 2847 | struct ieee80211_if_sta *ifsta, |
| 2848 | struct ieee80211_mgmt *mgmt, |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2849 | size_t len, |
| 2850 | struct ieee80211_rx_status *rx_status) |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2851 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2852 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2853 | |
Johannes Berg | 9c80d3d | 2008-09-08 15:41:59 +0200 | [diff] [blame] | 2854 | /* all categories we currently handle have action_code */ |
| 2855 | if (len < IEEE80211_MIN_ACTION_SIZE + 1) |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2856 | return; |
| 2857 | |
| 2858 | switch (mgmt->u.action.category) { |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 2859 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
| 2860 | if (local->hw.conf.channel->band != IEEE80211_BAND_5GHZ) |
| 2861 | break; |
Johannes Berg | 5fd12d4 | 2008-09-08 16:31:48 +0200 | [diff] [blame] | 2862 | switch (mgmt->u.action.u.measurement.action_code) { |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 2863 | case WLAN_ACTION_SPCT_MSR_REQ: |
| 2864 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2865 | sizeof(mgmt->u.action.u.measurement))) |
| 2866 | break; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2867 | ieee80211_sta_process_measurement_req(sdata, mgmt, len); |
Assaf Krauss | b662348 | 2008-06-16 16:09:49 +0300 | [diff] [blame] | 2868 | break; |
| 2869 | } |
| 2870 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2871 | case WLAN_CATEGORY_BACK: |
| 2872 | switch (mgmt->u.action.u.addba_req.action_code) { |
| 2873 | case WLAN_ACTION_ADDBA_REQ: |
| 2874 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2875 | sizeof(mgmt->u.action.u.addba_req))) |
| 2876 | break; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2877 | ieee80211_sta_process_addba_request(local, mgmt, len); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2878 | break; |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 2879 | case WLAN_ACTION_ADDBA_RESP: |
| 2880 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2881 | sizeof(mgmt->u.action.u.addba_resp))) |
| 2882 | break; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2883 | ieee80211_sta_process_addba_resp(local, mgmt, len); |
Ron Rindjunsky | eadc8d9 | 2008-01-28 14:07:17 +0200 | [diff] [blame] | 2884 | break; |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 2885 | case WLAN_ACTION_DELBA: |
| 2886 | if (len < (IEEE80211_MIN_ACTION_SIZE + |
| 2887 | sizeof(mgmt->u.action.u.delba))) |
| 2888 | break; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2889 | ieee80211_sta_process_delba(sdata, mgmt, len); |
Ron Rindjunsky | 688b88a | 2007-12-25 17:00:37 +0200 | [diff] [blame] | 2890 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2891 | } |
| 2892 | break; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2893 | case PLINK_CATEGORY: |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 2894 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2895 | mesh_rx_plink_frame(sdata, mgmt, len, rx_status); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2896 | break; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2897 | case MESH_PATH_SEL_CATEGORY: |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 2898 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2899 | mesh_rx_path_sel_frame(sdata, mgmt, len); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2900 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2901 | } |
| 2902 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2903 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2904 | 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] | 2905 | struct ieee80211_rx_status *rx_status) |
| 2906 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2907 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2908 | struct ieee80211_if_sta *ifsta; |
| 2909 | struct ieee80211_mgmt *mgmt; |
| 2910 | u16 fc; |
| 2911 | |
| 2912 | if (skb->len < 24) |
| 2913 | goto fail; |
| 2914 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2915 | ifsta = &sdata->u.sta; |
| 2916 | |
| 2917 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2918 | fc = le16_to_cpu(mgmt->frame_control); |
| 2919 | |
| 2920 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2921 | case IEEE80211_STYPE_PROBE_REQ: |
| 2922 | case IEEE80211_STYPE_PROBE_RESP: |
| 2923 | case IEEE80211_STYPE_BEACON: |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 2924 | case IEEE80211_STYPE_ACTION: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2925 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
| 2926 | case IEEE80211_STYPE_AUTH: |
| 2927 | case IEEE80211_STYPE_ASSOC_RESP: |
| 2928 | case IEEE80211_STYPE_REASSOC_RESP: |
| 2929 | case IEEE80211_STYPE_DEAUTH: |
| 2930 | case IEEE80211_STYPE_DISASSOC: |
| 2931 | skb_queue_tail(&ifsta->skb_queue, skb); |
| 2932 | queue_work(local->hw.workqueue, &ifsta->work); |
| 2933 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | fail: |
| 2937 | kfree_skb(skb); |
| 2938 | } |
| 2939 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2940 | 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] | 2941 | struct sk_buff *skb) |
| 2942 | { |
| 2943 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2944 | struct ieee80211_if_sta *ifsta; |
| 2945 | struct ieee80211_mgmt *mgmt; |
| 2946 | u16 fc; |
| 2947 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2948 | ifsta = &sdata->u.sta; |
| 2949 | |
| 2950 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 2951 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2952 | fc = le16_to_cpu(mgmt->frame_control); |
| 2953 | |
| 2954 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2955 | case IEEE80211_STYPE_PROBE_REQ: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2956 | ieee80211_rx_mgmt_probe_req(sdata, ifsta, mgmt, skb->len, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2957 | rx_status); |
| 2958 | break; |
| 2959 | case IEEE80211_STYPE_PROBE_RESP: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2960 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2961 | break; |
| 2962 | case IEEE80211_STYPE_BEACON: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2963 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2964 | break; |
| 2965 | case IEEE80211_STYPE_AUTH: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2966 | ieee80211_rx_mgmt_auth(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2967 | break; |
| 2968 | case IEEE80211_STYPE_ASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2969 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2970 | break; |
| 2971 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2972 | ieee80211_rx_mgmt_assoc_resp(sdata, ifsta, mgmt, skb->len, 1); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2973 | break; |
| 2974 | case IEEE80211_STYPE_DEAUTH: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2975 | ieee80211_rx_mgmt_deauth(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2976 | break; |
| 2977 | case IEEE80211_STYPE_DISASSOC: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2978 | ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2979 | break; |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2980 | case IEEE80211_STYPE_ACTION: |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2981 | ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status); |
Ron Rindjunsky | 9f985b0 | 2007-11-26 16:14:32 +0200 | [diff] [blame] | 2982 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
| 2985 | kfree_skb(skb); |
| 2986 | } |
| 2987 | |
| 2988 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 2989 | ieee80211_rx_result |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2990 | ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2991 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2992 | { |
| 2993 | struct ieee80211_mgmt *mgmt; |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 2994 | __le16 fc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2995 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 2996 | if (skb->len < 2) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 2997 | return RX_DROP_UNUSABLE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2998 | |
| 2999 | mgmt = (struct ieee80211_mgmt *) skb->data; |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3000 | fc = mgmt->frame_control; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3001 | |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3002 | if (ieee80211_is_ctl(fc)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 3003 | return RX_CONTINUE; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3004 | |
| 3005 | if (skb->len < 24) |
Johannes Berg | e4c26ad | 2008-01-31 19:48:21 +0100 | [diff] [blame] | 3006 | return RX_DROP_MONITOR; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3007 | |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3008 | if (ieee80211_is_probe_resp(fc)) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3009 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, rx_status); |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3010 | dev_kfree_skb(skb); |
| 3011 | return RX_QUEUED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3012 | } |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3013 | |
| 3014 | if (ieee80211_is_beacon(fc)) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3015 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3016 | dev_kfree_skb(skb); |
| 3017 | return RX_QUEUED; |
| 3018 | } |
| 3019 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 3020 | return RX_CONTINUE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3024 | static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3025 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3026 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3027 | int active = 0; |
| 3028 | struct sta_info *sta; |
| 3029 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3030 | rcu_read_lock(); |
| 3031 | |
| 3032 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 3033 | if (sta->sdata == sdata && |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3034 | time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, |
| 3035 | jiffies)) { |
| 3036 | active++; |
| 3037 | break; |
| 3038 | } |
| 3039 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3040 | |
| 3041 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3042 | |
| 3043 | return active; |
| 3044 | } |
| 3045 | |
| 3046 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3047 | 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] | 3048 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3049 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3050 | struct sta_info *sta, *tmp; |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 3051 | LIST_HEAD(tmp_list); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3052 | DECLARE_MAC_BUF(mac); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3053 | unsigned long flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3054 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3055 | spin_lock_irqsave(&local->sta_lock, flags); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3056 | list_for_each_entry_safe(sta, tmp, &local->sta_list, list) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3057 | if (time_after(jiffies, sta->last_rx + exp_time)) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3058 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3059 | printk(KERN_DEBUG "%s: expiring inactive STA %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3060 | sdata->dev->name, print_mac(mac, sta->addr)); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 3061 | #endif |
Luis Carlos Cobo | cb585bc | 2008-03-31 15:21:23 -0700 | [diff] [blame] | 3062 | __sta_info_unlink(&sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3063 | if (sta) |
| 3064 | list_add(&sta->list, &tmp_list); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3065 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3066 | spin_unlock_irqrestore(&local->sta_lock, flags); |
Michael Wu | be8755e | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 3067 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 3068 | list_for_each_entry_safe(sta, tmp, &tmp_list, list) |
| 3069 | sta_info_destroy(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3073 | static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3074 | struct ieee80211_if_sta *ifsta) |
| 3075 | { |
| 3076 | mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); |
| 3077 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3078 | ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); |
| 3079 | if (ieee80211_sta_active_ibss(sdata)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3080 | return; |
| 3081 | |
| 3082 | 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] | 3083 | "IBSS networks with same SSID (merge)\n", sdata->dev->name); |
| 3084 | ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3088 | #ifdef CONFIG_MAC80211_MESH |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3089 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3090 | struct ieee80211_if_sta *ifsta) |
| 3091 | { |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3092 | bool free_plinks; |
| 3093 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3094 | ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); |
| 3095 | mesh_path_expire(sdata); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3096 | |
| 3097 | free_plinks = mesh_plink_availables(sdata); |
| 3098 | if (free_plinks != sdata->u.sta.accepting_plinks) |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3099 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3100 | |
| 3101 | mod_timer(&ifsta->timer, jiffies + |
| 3102 | IEEE80211_MESH_HOUSEKEEPING_INTERVAL); |
| 3103 | } |
| 3104 | |
| 3105 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3106 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3107 | { |
| 3108 | struct ieee80211_if_sta *ifsta; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3109 | ifsta = &sdata->u.sta; |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3110 | ifsta->state = IEEE80211_STA_MLME_MESH_UP; |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3111 | ieee80211_sta_timer((unsigned long)sdata); |
Luis Carlos Cobo | 56a6d13 | 2008-07-29 19:59:31 +0200 | [diff] [blame] | 3112 | ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3113 | } |
| 3114 | #endif |
| 3115 | |
| 3116 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3117 | void ieee80211_sta_timer(unsigned long data) |
| 3118 | { |
| 3119 | struct ieee80211_sub_if_data *sdata = |
| 3120 | (struct ieee80211_sub_if_data *) data; |
| 3121 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3122 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3123 | |
| 3124 | set_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 3125 | queue_work(local->hw.workqueue, &ifsta->work); |
| 3126 | } |
| 3127 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3128 | static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3129 | struct ieee80211_if_sta *ifsta) |
| 3130 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3131 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3132 | |
| 3133 | if (local->ops->reset_tsf) { |
| 3134 | /* Reset own TSF to allow time synchronization work. */ |
| 3135 | local->ops->reset_tsf(local_to_hw(local)); |
| 3136 | } |
| 3137 | |
| 3138 | ifsta->wmm_last_param_set = -1; /* allow any WMM update */ |
| 3139 | |
| 3140 | |
| 3141 | if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 3142 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
| 3143 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 3144 | ifsta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 3145 | else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 3146 | ifsta->auth_alg = WLAN_AUTH_LEAP; |
| 3147 | else |
| 3148 | ifsta->auth_alg = WLAN_AUTH_OPEN; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3149 | ifsta->auth_transaction = -1; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3150 | ifsta->flags &= ~IEEE80211_STA_ASSOCIATED; |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 3151 | ifsta->assoc_scan_tries = 0; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 3152 | ifsta->direct_probe_tries = 0; |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 3153 | ifsta->auth_tries = 0; |
| 3154 | ifsta->assoc_tries = 0; |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 3155 | netif_tx_stop_all_queues(sdata->dev); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3156 | netif_carrier_off(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3160 | void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3161 | struct ieee80211_if_sta *ifsta) |
| 3162 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3163 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3164 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3165 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3166 | return; |
| 3167 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3168 | if ((ifsta->flags & (IEEE80211_STA_BSSID_SET | |
Tomas Winkler | 3b7ee69 | 2008-09-08 17:33:38 +0200 | [diff] [blame] | 3169 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3170 | (ifsta->flags & (IEEE80211_STA_SSID_SET | |
Tomas Winkler | 3b7ee69 | 2008-09-08 17:33:38 +0200 | [diff] [blame] | 3171 | IEEE80211_STA_AUTO_SSID_SEL))) { |
| 3172 | |
| 3173 | if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED) |
| 3174 | ieee80211_set_disassoc(sdata, ifsta, true, true, |
| 3175 | WLAN_REASON_DEAUTH_LEAVING); |
| 3176 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3177 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 3178 | queue_work(local->hw.workqueue, &ifsta->work); |
| 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, |
| 3183 | const char *ssid, int ssid_len) |
| 3184 | { |
| 3185 | int tmp, hidden_ssid; |
| 3186 | |
Michael Wu | 4822570 | 2007-10-19 17:14:36 -0400 | [diff] [blame] | 3187 | if (ssid_len == ifsta->ssid_len && |
| 3188 | !memcmp(ifsta->ssid, ssid, ssid_len)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3189 | return 1; |
| 3190 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3191 | if (ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3192 | return 0; |
| 3193 | |
| 3194 | hidden_ssid = 1; |
| 3195 | tmp = ssid_len; |
| 3196 | while (tmp--) { |
| 3197 | if (ssid[tmp] != '\0') { |
| 3198 | hidden_ssid = 0; |
| 3199 | break; |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | if (hidden_ssid && ifsta->ssid_len == ssid_len) |
| 3204 | return 1; |
| 3205 | |
| 3206 | if (ssid_len == 1 && ssid[0] == ' ') |
| 3207 | return 1; |
| 3208 | |
| 3209 | return 0; |
| 3210 | } |
| 3211 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3212 | static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3213 | struct ieee80211_if_sta *ifsta) |
| 3214 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3215 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3216 | struct ieee80211_sta_bss *bss; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3217 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3218 | u8 bssid[ETH_ALEN], *pos; |
| 3219 | int i; |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 3220 | int ret; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3221 | DECLARE_MAC_BUF(mac); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3222 | |
| 3223 | #if 0 |
| 3224 | /* Easier testing, use fixed BSSID. */ |
| 3225 | memset(bssid, 0xfe, ETH_ALEN); |
| 3226 | #else |
| 3227 | /* Generate random, not broadcast, locally administered BSSID. Mix in |
| 3228 | * own MAC address to make sure that devices that do not have proper |
| 3229 | * random number generator get different BSSID. */ |
| 3230 | get_random_bytes(bssid, ETH_ALEN); |
| 3231 | for (i = 0; i < ETH_ALEN; i++) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3232 | bssid[i] ^= sdata->dev->dev_addr[i]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3233 | bssid[0] &= ~0x01; |
| 3234 | bssid[0] |= 0x02; |
| 3235 | #endif |
| 3236 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3237 | printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3238 | sdata->dev->name, print_mac(mac, bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3239 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3240 | bss = ieee80211_rx_bss_add(sdata, bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3241 | local->hw.conf.channel->center_freq, |
John W. Linville | cffdd30 | 2007-10-05 14:23:27 -0400 | [diff] [blame] | 3242 | sdata->u.sta.ssid, sdata->u.sta.ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3243 | if (!bss) |
| 3244 | return -ENOMEM; |
| 3245 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3246 | bss->band = local->hw.conf.channel->band; |
| 3247 | sband = local->hw.wiphy->bands[bss->band]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3248 | |
| 3249 | if (local->hw.conf.beacon_int == 0) |
Tomas Winkler | dc0ae30 | 2008-06-12 22:38:37 +0300 | [diff] [blame] | 3250 | local->hw.conf.beacon_int = 100; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3251 | bss->beacon_int = local->hw.conf.beacon_int; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3252 | bss->last_update = jiffies; |
| 3253 | bss->capability = WLAN_CAPABILITY_IBSS; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 3254 | |
| 3255 | if (sdata->default_key) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3256 | bss->capability |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 3257 | else |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3258 | sdata->drop_unencrypted = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 3259 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3260 | bss->supp_rates_len = sband->n_bitrates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3261 | pos = bss->supp_rates; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3262 | for (i = 0; i < sband->n_bitrates; i++) { |
| 3263 | int rate = sband->bitrates[i].bitrate; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3264 | *pos++ = (u8) (rate / 5); |
| 3265 | } |
| 3266 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3267 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 3268 | ieee80211_rx_bss_put(local, bss); |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 3269 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3273 | static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3274 | struct ieee80211_if_sta *ifsta) |
| 3275 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3276 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3277 | struct ieee80211_sta_bss *bss; |
| 3278 | int found = 0; |
| 3279 | u8 bssid[ETH_ALEN]; |
| 3280 | int active_ibss; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3281 | DECLARE_MAC_BUF(mac); |
| 3282 | DECLARE_MAC_BUF(mac2); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3283 | |
| 3284 | if (ifsta->ssid_len == 0) |
| 3285 | return -EINVAL; |
| 3286 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3287 | active_ibss = ieee80211_sta_active_ibss(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3288 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 3289 | printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3290 | sdata->dev->name, active_ibss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3291 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 3292 | spin_lock_bh(&local->sta_bss_lock); |
| 3293 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 3294 | if (ifsta->ssid_len != bss->ssid_len || |
| 3295 | memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 |
| 3296 | || !(bss->capability & WLAN_CAPABILITY_IBSS)) |
| 3297 | continue; |
| 3298 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3299 | printk(KERN_DEBUG " bssid=%s found\n", |
| 3300 | print_mac(mac, bss->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3301 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 3302 | memcpy(bssid, bss->bssid, ETH_ALEN); |
| 3303 | found = 1; |
| 3304 | if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) |
| 3305 | break; |
| 3306 | } |
| 3307 | spin_unlock_bh(&local->sta_bss_lock); |
| 3308 | |
| 3309 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
Vladimir Koutny | 6e43829 | 2008-07-07 14:23:01 +0200 | [diff] [blame] | 3310 | if (found) |
| 3311 | printk(KERN_DEBUG " sta_find_ibss: selected %s current " |
| 3312 | "%s\n", print_mac(mac, bssid), |
| 3313 | print_mac(mac2, ifsta->bssid)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3314 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 3315 | |
| 3316 | if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 3317 | int ret; |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 3318 | int search_freq; |
| 3319 | |
| 3320 | if (ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) |
| 3321 | search_freq = bss->freq; |
| 3322 | else |
| 3323 | search_freq = local->hw.conf.channel->center_freq; |
| 3324 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3325 | bss = ieee80211_rx_bss_get(local, bssid, search_freq, |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 3326 | ifsta->ssid, ifsta->ssid_len); |
| 3327 | if (!bss) |
| 3328 | goto dont_join; |
| 3329 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3330 | printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3331 | " based on configured SSID\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3332 | sdata->dev->name, print_mac(mac, bssid)); |
| 3333 | ret = ieee80211_sta_join_ibss(sdata, ifsta, bss); |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 3334 | ieee80211_rx_bss_put(local, bss); |
Tomas Winkler | 167ad6f | 2008-05-21 18:17:05 +0300 | [diff] [blame] | 3335 | return ret; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3336 | } |
Daniel Drake | 80693ce | 2008-07-19 23:31:17 +0100 | [diff] [blame] | 3337 | |
| 3338 | dont_join: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3339 | #ifdef CONFIG_MAC80211_IBSS_DEBUG |
| 3340 | printk(KERN_DEBUG " did not try to join ibss\n"); |
| 3341 | #endif /* CONFIG_MAC80211_IBSS_DEBUG */ |
| 3342 | |
| 3343 | /* Selected IBSS not found in current scan results - try to scan */ |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3344 | if (ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3345 | !ieee80211_sta_active_ibss(sdata)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3346 | mod_timer(&ifsta->timer, jiffies + |
| 3347 | IEEE80211_IBSS_MERGE_INTERVAL); |
| 3348 | } else if (time_after(jiffies, local->last_scan_completed + |
| 3349 | IEEE80211_SCAN_INTERVAL)) { |
| 3350 | 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] | 3351 | "join\n", sdata->dev->name); |
| 3352 | return ieee80211_sta_req_scan(sdata, ifsta->ssid, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3353 | ifsta->ssid_len); |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3354 | } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3355 | int interval = IEEE80211_SCAN_INTERVAL; |
| 3356 | |
| 3357 | if (time_after(jiffies, ifsta->ibss_join_req + |
| 3358 | IEEE80211_IBSS_JOIN_TIMEOUT)) { |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3359 | if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3360 | (!(local->oper_channel->flags & |
| 3361 | IEEE80211_CHAN_NO_IBSS))) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3362 | return ieee80211_sta_create_ibss(sdata, ifsta); |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3363 | if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3364 | printk(KERN_DEBUG "%s: IBSS not allowed on" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3365 | " %d MHz\n", sdata->dev->name, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3366 | local->hw.conf.channel->center_freq); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | /* No IBSS found - decrease scan interval and continue |
| 3370 | * scanning. */ |
| 3371 | interval = IEEE80211_SCAN_INTERVAL_SLOW; |
| 3372 | } |
| 3373 | |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3374 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3375 | mod_timer(&ifsta->timer, jiffies + interval); |
| 3376 | return 0; |
| 3377 | } |
| 3378 | |
| 3379 | return 0; |
| 3380 | } |
| 3381 | |
| 3382 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3383 | 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] | 3384 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3385 | struct ieee80211_if_sta *ifsta; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3386 | int res; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3387 | |
| 3388 | if (len > IEEE80211_MAX_SSID_LEN) |
| 3389 | return -EINVAL; |
| 3390 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3391 | ifsta = &sdata->u.sta; |
| 3392 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3393 | if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) { |
| 3394 | memset(ifsta->ssid, 0, sizeof(ifsta->ssid)); |
| 3395 | memcpy(ifsta->ssid, ssid, len); |
| 3396 | ifsta->ssid_len = len; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3397 | ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3398 | |
| 3399 | res = 0; |
| 3400 | /* |
| 3401 | * Hack! MLME code needs to be cleaned up to have different |
| 3402 | * entry points for configuration and internal selection change |
| 3403 | */ |
| 3404 | if (netif_running(sdata->dev)) |
| 3405 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID); |
| 3406 | if (res) { |
| 3407 | printk(KERN_DEBUG "%s: Failed to config new SSID to " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3408 | "the low-level driver\n", sdata->dev->name); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3409 | return res; |
| 3410 | } |
| 3411 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3412 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3413 | if (len) |
| 3414 | ifsta->flags |= IEEE80211_STA_SSID_SET; |
| 3415 | else |
| 3416 | ifsta->flags &= ~IEEE80211_STA_SSID_SET; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3417 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3418 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3419 | !(ifsta->flags & IEEE80211_STA_BSSID_SET)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3420 | ifsta->ibss_join_req = jiffies; |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3421 | ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3422 | return ieee80211_sta_find_ibss(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3423 | } |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3424 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3425 | return 0; |
| 3426 | } |
| 3427 | |
| 3428 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3429 | 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] | 3430 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3431 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 3432 | memcpy(ssid, ifsta->ssid, ifsta->ssid_len); |
| 3433 | *len = ifsta->ssid_len; |
| 3434 | return 0; |
| 3435 | } |
| 3436 | |
| 3437 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3438 | 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] | 3439 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3440 | struct ieee80211_if_sta *ifsta; |
| 3441 | int res; |
| 3442 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3443 | ifsta = &sdata->u.sta; |
| 3444 | |
| 3445 | if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) { |
| 3446 | memcpy(ifsta->bssid, bssid, ETH_ALEN); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3447 | res = 0; |
| 3448 | /* |
| 3449 | * Hack! See also ieee80211_sta_set_ssid. |
| 3450 | */ |
| 3451 | if (netif_running(sdata->dev)) |
| 3452 | res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3453 | if (res) { |
| 3454 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3455 | "the low-level driver\n", sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3456 | return res; |
| 3457 | } |
| 3458 | } |
| 3459 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3460 | if (is_valid_ether_addr(bssid)) |
| 3461 | ifsta->flags |= IEEE80211_STA_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3462 | else |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3463 | ifsta->flags &= ~IEEE80211_STA_BSSID_SET; |
| 3464 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3465 | return 0; |
| 3466 | } |
| 3467 | |
| 3468 | |
| 3469 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 3470 | struct ieee80211_sub_if_data *sdata, |
| 3471 | int powersave) |
| 3472 | { |
| 3473 | struct sk_buff *skb; |
| 3474 | struct ieee80211_hdr *nullfunc; |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3475 | __le16 fc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3476 | |
| 3477 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); |
| 3478 | if (!skb) { |
| 3479 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " |
| 3480 | "frame\n", sdata->dev->name); |
| 3481 | return; |
| 3482 | } |
| 3483 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 3484 | |
| 3485 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 3486 | memset(nullfunc, 0, 24); |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3487 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 3488 | IEEE80211_FCTL_TODS); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3489 | if (powersave) |
Harvey Harrison | 4e3996f | 2008-06-22 16:45:32 -0700 | [diff] [blame] | 3490 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 3491 | nullfunc->frame_control = fc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3492 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); |
| 3493 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); |
| 3494 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); |
| 3495 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3496 | ieee80211_sta_tx(sdata, skb, 0); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | |
Johannes Berg | 69d3b6f | 2008-03-05 10:58:40 +0100 | [diff] [blame] | 3500 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 3501 | { |
| 3502 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || |
| 3503 | ieee80211_vif_is_mesh(&sdata->vif)) |
| 3504 | ieee80211_sta_timer((unsigned long)sdata); |
| 3505 | } |
| 3506 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3507 | void ieee80211_scan_completed(struct ieee80211_hw *hw) |
| 3508 | { |
| 3509 | struct ieee80211_local *local = hw_to_local(hw); |
| 3510 | struct net_device *dev = local->scan_dev; |
| 3511 | struct ieee80211_sub_if_data *sdata; |
| 3512 | union iwreq_data wrqu; |
| 3513 | |
| 3514 | local->last_scan_completed = jiffies; |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3515 | memset(&wrqu, 0, sizeof(wrqu)); |
| 3516 | wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3517 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3518 | if (local->sta_hw_scanning) { |
| 3519 | local->sta_hw_scanning = 0; |
Mohamed Abbas | 675ef58 | 2008-03-20 08:14:29 -0700 | [diff] [blame] | 3520 | if (ieee80211_hw_config(local)) |
| 3521 | printk(KERN_DEBUG "%s: failed to restore operational " |
| 3522 | "channel after scan\n", dev->name); |
Johannes Berg | 69d3b6f | 2008-03-05 10:58:40 +0100 | [diff] [blame] | 3523 | /* Restart STA timer for HW scan case */ |
| 3524 | rcu_read_lock(); |
| 3525 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 3526 | ieee80211_restart_sta_timer(sdata); |
| 3527 | rcu_read_unlock(); |
| 3528 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3529 | goto done; |
| 3530 | } |
| 3531 | |
| 3532 | local->sta_sw_scanning = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3533 | if (ieee80211_hw_config(local)) |
Bruno Randolf | 4b50e38 | 2007-11-16 17:04:01 +0900 | [diff] [blame] | 3534 | printk(KERN_DEBUG "%s: failed to restore operational " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3535 | "channel after scan\n", dev->name); |
| 3536 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3537 | |
| 3538 | netif_tx_lock_bh(local->mdev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3539 | netif_addr_lock(local->mdev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3540 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
| 3541 | local->ops->configure_filter(local_to_hw(local), |
| 3542 | FIF_BCN_PRBRESP_PROMISC, |
| 3543 | &local->filter_flags, |
| 3544 | local->mdev->mc_count, |
| 3545 | local->mdev->mc_list); |
| 3546 | |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3547 | netif_addr_unlock(local->mdev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3548 | netif_tx_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3549 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3550 | rcu_read_lock(); |
| 3551 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 69d3b6f | 2008-03-05 10:58:40 +0100 | [diff] [blame] | 3552 | /* Tell AP we're back */ |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 3553 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
| 3554 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { |
| 3555 | ieee80211_send_nullfunc(local, sdata, 0); |
| 3556 | netif_tx_wake_all_queues(sdata->dev); |
| 3557 | } |
| 3558 | } else |
| 3559 | netif_tx_wake_all_queues(sdata->dev); |
Mattias Nissler | 14042cbe | 2007-06-08 15:31:13 +0200 | [diff] [blame] | 3560 | |
Johannes Berg | 69d3b6f | 2008-03-05 10:58:40 +0100 | [diff] [blame] | 3561 | ieee80211_restart_sta_timer(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3562 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3563 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3564 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3565 | done: |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3566 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3567 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3568 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 3569 | if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || |
Tomas Winkler | 48c2fc5 | 2008-08-06 14:22:01 +0300 | [diff] [blame] | 3570 | (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3571 | !ieee80211_sta_active_ibss(sdata))) |
| 3572 | ieee80211_sta_find_ibss(sdata, ifsta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3573 | } |
| 3574 | } |
| 3575 | EXPORT_SYMBOL(ieee80211_scan_completed); |
| 3576 | |
| 3577 | void ieee80211_sta_scan_work(struct work_struct *work) |
| 3578 | { |
| 3579 | struct ieee80211_local *local = |
| 3580 | container_of(work, struct ieee80211_local, scan_work.work); |
| 3581 | struct net_device *dev = local->scan_dev; |
| 3582 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3583 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3584 | struct ieee80211_channel *chan; |
| 3585 | int skip; |
| 3586 | unsigned long next_delay = 0; |
| 3587 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3588 | if (!local->sta_sw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3589 | return; |
| 3590 | |
| 3591 | switch (local->scan_state) { |
| 3592 | case SCAN_SET_CHANNEL: |
Johannes Berg | 69d464d | 2008-01-28 17:08:56 +0100 | [diff] [blame] | 3593 | /* |
| 3594 | * Get current scan band. scan_band may be IEEE80211_NUM_BANDS |
| 3595 | * after we successfully scanned the last channel of the last |
| 3596 | * band (and the last band is supported by the hw) |
| 3597 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3598 | if (local->scan_band < IEEE80211_NUM_BANDS) |
| 3599 | sband = local->hw.wiphy->bands[local->scan_band]; |
| 3600 | else |
| 3601 | sband = NULL; |
| 3602 | |
Johannes Berg | 69d464d | 2008-01-28 17:08:56 +0100 | [diff] [blame] | 3603 | /* |
| 3604 | * If we are at an unsupported band and have more bands |
| 3605 | * left to scan, advance to the next supported one. |
| 3606 | */ |
| 3607 | while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3608 | local->scan_band++; |
| 3609 | sband = local->hw.wiphy->bands[local->scan_band]; |
| 3610 | local->scan_channel_idx = 0; |
| 3611 | } |
| 3612 | |
Johannes Berg | 69d464d | 2008-01-28 17:08:56 +0100 | [diff] [blame] | 3613 | /* if no more bands/channels left, complete scan */ |
| 3614 | if (!sband || local->scan_channel_idx >= sband->n_channels) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3615 | ieee80211_scan_completed(local_to_hw(local)); |
| 3616 | return; |
| 3617 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3618 | skip = 0; |
| 3619 | chan = &sband->channels[local->scan_channel_idx]; |
| 3620 | |
| 3621 | if (chan->flags & IEEE80211_CHAN_DISABLED || |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3622 | (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3623 | chan->flags & IEEE80211_CHAN_NO_IBSS)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3624 | skip = 1; |
| 3625 | |
| 3626 | if (!skip) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3627 | local->scan_channel = chan; |
| 3628 | if (ieee80211_hw_config(local)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3629 | printk(KERN_DEBUG "%s: failed to set freq to " |
| 3630 | "%d MHz for scan\n", dev->name, |
| 3631 | chan->center_freq); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3632 | skip = 1; |
| 3633 | } |
| 3634 | } |
| 3635 | |
Johannes Berg | 69d464d | 2008-01-28 17:08:56 +0100 | [diff] [blame] | 3636 | /* advance state machine to next channel/band */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3637 | local->scan_channel_idx++; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3638 | if (local->scan_channel_idx >= sband->n_channels) { |
Johannes Berg | 69d464d | 2008-01-28 17:08:56 +0100 | [diff] [blame] | 3639 | /* |
| 3640 | * scan_band may end up == IEEE80211_NUM_BANDS, but |
| 3641 | * we'll catch that case above and complete the scan |
| 3642 | * if that is the case. |
| 3643 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3644 | local->scan_band++; |
| 3645 | local->scan_channel_idx = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | if (skip) |
| 3649 | break; |
| 3650 | |
| 3651 | next_delay = IEEE80211_PROBE_DELAY + |
| 3652 | usecs_to_jiffies(local->hw.channel_change_time); |
| 3653 | local->scan_state = SCAN_SEND_PROBE; |
| 3654 | break; |
| 3655 | case SCAN_SEND_PROBE: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3656 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3657 | local->scan_state = SCAN_SET_CHANNEL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3658 | |
| 3659 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 3660 | break; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3661 | ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3662 | local->scan_ssid_len); |
| 3663 | next_delay = IEEE80211_CHANNEL_TIME; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3664 | break; |
| 3665 | } |
| 3666 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3667 | if (local->sta_sw_scanning) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3668 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 3669 | next_delay); |
| 3670 | } |
| 3671 | |
| 3672 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3673 | static int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3674 | u8 *ssid, size_t ssid_len) |
| 3675 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3676 | struct ieee80211_local *local = scan_sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3677 | struct ieee80211_sub_if_data *sdata; |
| 3678 | |
| 3679 | if (ssid_len > IEEE80211_MAX_SSID_LEN) |
| 3680 | return -EINVAL; |
| 3681 | |
| 3682 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
| 3683 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
| 3684 | * BSSID: MACAddress |
| 3685 | * SSID |
| 3686 | * ScanType: ACTIVE, PASSIVE |
| 3687 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting |
| 3688 | * a Probe frame during active scanning |
| 3689 | * ChannelList |
| 3690 | * MinChannelTime (>= ProbeDelay), in TU |
| 3691 | * MaxChannelTime: (>= MinChannelTime), in TU |
| 3692 | */ |
| 3693 | |
| 3694 | /* MLME-SCAN.confirm |
| 3695 | * BSSDescriptionSet |
| 3696 | * ResultCode: SUCCESS, INVALID_PARAMETERS |
| 3697 | */ |
| 3698 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3699 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3700 | if (local->scan_dev == scan_sdata->dev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3701 | return 0; |
| 3702 | return -EBUSY; |
| 3703 | } |
| 3704 | |
| 3705 | if (local->ops->hw_scan) { |
| 3706 | int rc = local->ops->hw_scan(local_to_hw(local), |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3707 | ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3708 | if (!rc) { |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3709 | local->sta_hw_scanning = 1; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3710 | local->scan_dev = scan_sdata->dev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3711 | } |
| 3712 | return rc; |
| 3713 | } |
| 3714 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3715 | local->sta_sw_scanning = 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3716 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3717 | rcu_read_lock(); |
| 3718 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 3719 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { |
| 3720 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { |
| 3721 | netif_tx_stop_all_queues(sdata->dev); |
| 3722 | ieee80211_send_nullfunc(local, sdata, 1); |
| 3723 | } |
| 3724 | } else |
| 3725 | netif_tx_stop_all_queues(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3726 | } |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 3727 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3728 | |
| 3729 | if (ssid) { |
| 3730 | local->scan_ssid_len = ssid_len; |
| 3731 | memcpy(local->scan_ssid, ssid, ssid_len); |
| 3732 | } else |
| 3733 | local->scan_ssid_len = 0; |
| 3734 | local->scan_state = SCAN_SET_CHANNEL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3735 | local->scan_channel_idx = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3736 | local->scan_band = IEEE80211_BAND_2GHZ; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3737 | local->scan_dev = scan_sdata->dev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3738 | |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 3739 | netif_addr_lock_bh(local->mdev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3740 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 3741 | local->ops->configure_filter(local_to_hw(local), |
| 3742 | FIF_BCN_PRBRESP_PROMISC, |
| 3743 | &local->filter_flags, |
| 3744 | local->mdev->mc_count, |
| 3745 | local->mdev->mc_list); |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 3746 | netif_addr_unlock_bh(local->mdev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3747 | |
| 3748 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ |
| 3749 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 3750 | IEEE80211_CHANNEL_TIME); |
| 3751 | |
| 3752 | return 0; |
| 3753 | } |
| 3754 | |
| 3755 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3756 | int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3757 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3758 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3759 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3760 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 3761 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3762 | return ieee80211_sta_start_scan(sdata, ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3763 | |
Zhu Yi | ece8edd | 2007-11-22 10:53:21 +0800 | [diff] [blame] | 3764 | if (local->sta_sw_scanning || local->sta_hw_scanning) { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3765 | if (local->scan_dev == sdata->dev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3766 | return 0; |
| 3767 | return -EBUSY; |
| 3768 | } |
| 3769 | |
Helmut Schaa | a0af5f1 | 2007-11-09 16:25:08 +0100 | [diff] [blame] | 3770 | ifsta->scan_ssid_len = ssid_len; |
| 3771 | if (ssid_len) |
| 3772 | memcpy(ifsta->scan_ssid, ssid, ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3773 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); |
| 3774 | queue_work(local->hw.workqueue, &ifsta->work); |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 3778 | |
| 3779 | static void ieee80211_sta_add_scan_ies(struct iw_request_info *info, |
| 3780 | struct ieee80211_sta_bss *bss, |
| 3781 | char **current_ev, char *end_buf) |
| 3782 | { |
| 3783 | u8 *pos, *end, *next; |
| 3784 | struct iw_event iwe; |
| 3785 | |
| 3786 | if (bss == NULL || bss->ies == NULL) |
| 3787 | return; |
| 3788 | |
| 3789 | /* |
| 3790 | * If needed, fragment the IEs buffer (at IE boundaries) into short |
| 3791 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. |
| 3792 | */ |
| 3793 | pos = bss->ies; |
| 3794 | end = pos + bss->ies_len; |
| 3795 | |
| 3796 | while (end - pos > IW_GENERIC_IE_MAX) { |
| 3797 | next = pos + 2 + pos[1]; |
| 3798 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) |
| 3799 | next = next + 2 + next[1]; |
| 3800 | |
| 3801 | memset(&iwe, 0, sizeof(iwe)); |
| 3802 | iwe.cmd = IWEVGENIE; |
| 3803 | iwe.u.data.length = next - pos; |
| 3804 | *current_ev = iwe_stream_add_point(info, *current_ev, |
| 3805 | end_buf, &iwe, pos); |
| 3806 | |
| 3807 | pos = next; |
| 3808 | } |
| 3809 | |
| 3810 | if (end > pos) { |
| 3811 | memset(&iwe, 0, sizeof(iwe)); |
| 3812 | iwe.cmd = IWEVGENIE; |
| 3813 | iwe.u.data.length = end - pos; |
| 3814 | *current_ev = iwe_stream_add_point(info, *current_ev, |
| 3815 | end_buf, &iwe, pos); |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3820 | static char * |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3821 | ieee80211_sta_scan_result(struct ieee80211_local *local, |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3822 | struct iw_request_info *info, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3823 | struct ieee80211_sta_bss *bss, |
| 3824 | char *current_ev, char *end_buf) |
| 3825 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3826 | struct iw_event iwe; |
| 3827 | |
| 3828 | if (time_after(jiffies, |
| 3829 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) |
| 3830 | return current_ev; |
| 3831 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3832 | memset(&iwe, 0, sizeof(iwe)); |
| 3833 | iwe.cmd = SIOCGIWAP; |
| 3834 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; |
| 3835 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3836 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3837 | IW_EV_ADDR_LEN); |
| 3838 | |
| 3839 | memset(&iwe, 0, sizeof(iwe)); |
| 3840 | iwe.cmd = SIOCGIWESSID; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 3841 | if (bss_mesh_cfg(bss)) { |
| 3842 | iwe.u.data.length = bss_mesh_id_len(bss); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3843 | iwe.u.data.flags = 1; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3844 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 3845 | &iwe, bss_mesh_id(bss)); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3846 | } else { |
| 3847 | iwe.u.data.length = bss->ssid_len; |
| 3848 | iwe.u.data.flags = 1; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3849 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 3850 | &iwe, bss->ssid); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3851 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3852 | |
Luis Carlos Cobo | 1d1b535 | 2008-02-29 12:15:28 -0800 | [diff] [blame] | 3853 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) |
| 3854 | || bss_mesh_cfg(bss)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3855 | memset(&iwe, 0, sizeof(iwe)); |
| 3856 | iwe.cmd = SIOCGIWMODE; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 3857 | if (bss_mesh_cfg(bss)) |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3858 | iwe.u.mode = IW_MODE_MESH; |
| 3859 | else if (bss->capability & WLAN_CAPABILITY_ESS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3860 | iwe.u.mode = IW_MODE_MASTER; |
| 3861 | else |
| 3862 | iwe.u.mode = IW_MODE_ADHOC; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3863 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
| 3864 | &iwe, IW_EV_UINT_LEN); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | memset(&iwe, 0, sizeof(iwe)); |
| 3868 | iwe.cmd = SIOCGIWFREQ; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3869 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); |
| 3870 | iwe.u.freq.e = 0; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3871 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3872 | IW_EV_FREQ_LEN); |
| 3873 | |
| 3874 | memset(&iwe, 0, sizeof(iwe)); |
Tomas Winkler | 9381be0 | 2008-05-23 01:36:36 +0300 | [diff] [blame] | 3875 | iwe.cmd = SIOCGIWFREQ; |
| 3876 | iwe.u.freq.m = bss->freq; |
| 3877 | iwe.u.freq.e = 6; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3878 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
Tomas Winkler | 9381be0 | 2008-05-23 01:36:36 +0300 | [diff] [blame] | 3879 | IW_EV_FREQ_LEN); |
| 3880 | memset(&iwe, 0, sizeof(iwe)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3881 | iwe.cmd = IWEVQUAL; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 3882 | iwe.u.qual.qual = bss->qual; |
| 3883 | iwe.u.qual.level = bss->signal; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3884 | iwe.u.qual.noise = bss->noise; |
| 3885 | iwe.u.qual.updated = local->wstats_flags; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3886 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3887 | IW_EV_QUAL_LEN); |
| 3888 | |
| 3889 | memset(&iwe, 0, sizeof(iwe)); |
| 3890 | iwe.cmd = SIOCGIWENCODE; |
| 3891 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) |
| 3892 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; |
| 3893 | else |
| 3894 | iwe.u.data.flags = IW_ENCODE_DISABLED; |
| 3895 | iwe.u.data.length = 0; |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3896 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
| 3897 | &iwe, ""); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3898 | |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 3899 | ieee80211_sta_add_scan_ies(info, bss, ¤t_ev, end_buf); |
Emmanuel Grumbach | e623157 | 2008-05-27 20:00:11 +0300 | [diff] [blame] | 3900 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3901 | if (bss && bss->supp_rates_len > 0) { |
| 3902 | /* display all supported rates in readable format */ |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3903 | char *p = current_ev + iwe_stream_lcp_len(info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3904 | int i; |
| 3905 | |
| 3906 | memset(&iwe, 0, sizeof(iwe)); |
| 3907 | iwe.cmd = SIOCGIWRATE; |
| 3908 | /* Those two flags are ignored... */ |
| 3909 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; |
| 3910 | |
| 3911 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 3912 | iwe.u.bitrate.value = ((bss->supp_rates[i] & |
| 3913 | 0x7f) * 500000); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3914 | p = iwe_stream_add_value(info, current_ev, p, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3915 | end_buf, &iwe, IW_EV_PARAM_LEN); |
| 3916 | } |
| 3917 | current_ev = p; |
| 3918 | } |
| 3919 | |
| 3920 | if (bss) { |
| 3921 | char *buf; |
| 3922 | buf = kmalloc(30, GFP_ATOMIC); |
| 3923 | if (buf) { |
| 3924 | memset(&iwe, 0, sizeof(iwe)); |
| 3925 | iwe.cmd = IWEVCUSTOM; |
| 3926 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); |
| 3927 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3928 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3929 | end_buf, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3930 | &iwe, buf); |
Emmanuel Grumbach | bf998f6 | 2008-06-24 13:38:00 +0300 | [diff] [blame] | 3931 | memset(&iwe, 0, sizeof(iwe)); |
| 3932 | iwe.cmd = IWEVCUSTOM; |
| 3933 | sprintf(buf, " Last beacon: %dms ago", |
| 3934 | jiffies_to_msecs(jiffies - bss->last_update)); |
| 3935 | iwe.u.data.length = strlen(buf); |
| 3936 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3937 | end_buf, &iwe, buf); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3938 | kfree(buf); |
| 3939 | } |
| 3940 | } |
| 3941 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 3942 | if (bss_mesh_cfg(bss)) { |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3943 | char *buf; |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3944 | u8 *cfg = bss_mesh_cfg(bss); |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3945 | buf = kmalloc(50, GFP_ATOMIC); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3946 | if (buf) { |
| 3947 | memset(&iwe, 0, sizeof(iwe)); |
| 3948 | iwe.cmd = IWEVCUSTOM; |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3949 | sprintf(buf, "Mesh network (version %d)", cfg[0]); |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3950 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3951 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3952 | end_buf, |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3953 | &iwe, buf); |
| 3954 | sprintf(buf, "Path Selection Protocol ID: " |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3955 | "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], |
| 3956 | cfg[4]); |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3957 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3958 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3959 | end_buf, |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3960 | &iwe, buf); |
| 3961 | sprintf(buf, "Path Selection Metric ID: " |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3962 | "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], |
| 3963 | cfg[8]); |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3964 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3965 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3966 | end_buf, |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3967 | &iwe, buf); |
| 3968 | sprintf(buf, "Congestion Control Mode ID: " |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3969 | "0x%02X%02X%02X%02X", cfg[9], cfg[10], |
| 3970 | cfg[11], cfg[12]); |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3971 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3972 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3973 | end_buf, |
Luis Carlos Cobo | 4f5d4c4 | 2008-02-29 12:32:46 -0800 | [diff] [blame] | 3974 | &iwe, buf); |
| 3975 | sprintf(buf, "Channel Precedence: " |
John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 3976 | "0x%02X%02X%02X%02X", cfg[13], cfg[14], |
| 3977 | cfg[15], cfg[16]); |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3978 | iwe.u.data.length = strlen(buf); |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3979 | current_ev = iwe_stream_add_point(info, current_ev, |
| 3980 | end_buf, |
Luis Carlos Cobo | f709fc6 | 2008-02-23 15:17:12 +0100 | [diff] [blame] | 3981 | &iwe, buf); |
| 3982 | kfree(buf); |
| 3983 | } |
| 3984 | } |
| 3985 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3986 | return current_ev; |
| 3987 | } |
| 3988 | |
| 3989 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 3990 | int ieee80211_sta_scan_results(struct ieee80211_local *local, |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 3991 | struct iw_request_info *info, |
| 3992 | char *buf, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3993 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3994 | char *current_ev = buf; |
| 3995 | char *end_buf = buf + len; |
| 3996 | struct ieee80211_sta_bss *bss; |
| 3997 | |
| 3998 | spin_lock_bh(&local->sta_bss_lock); |
| 3999 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 4000 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { |
| 4001 | spin_unlock_bh(&local->sta_bss_lock); |
| 4002 | return -E2BIG; |
| 4003 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4004 | current_ev = ieee80211_sta_scan_result(local, info, bss, |
David S. Miller | ccc5805 | 2008-06-16 18:50:49 -0700 | [diff] [blame] | 4005 | current_ev, end_buf); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4006 | } |
| 4007 | spin_unlock_bh(&local->sta_bss_lock); |
| 4008 | return current_ev - buf; |
| 4009 | } |
| 4010 | |
| 4011 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4012 | 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] | 4013 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4014 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 4015 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4016 | kfree(ifsta->extra_ie); |
| 4017 | if (len == 0) { |
| 4018 | ifsta->extra_ie = NULL; |
| 4019 | ifsta->extra_ie_len = 0; |
| 4020 | return 0; |
| 4021 | } |
| 4022 | ifsta->extra_ie = kmalloc(len, GFP_KERNEL); |
| 4023 | if (!ifsta->extra_ie) { |
| 4024 | ifsta->extra_ie_len = 0; |
| 4025 | return -ENOMEM; |
| 4026 | } |
| 4027 | memcpy(ifsta->extra_ie, ie, len); |
| 4028 | ifsta->extra_ie_len = len; |
| 4029 | return 0; |
| 4030 | } |
| 4031 | |
| 4032 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4033 | 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] | 4034 | struct sk_buff *skb, u8 *bssid, |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 4035 | u8 *addr, u64 supp_rates) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4036 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4037 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4038 | struct sta_info *sta; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4039 | DECLARE_MAC_BUF(mac); |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 4040 | int band = local->hw.conf.channel->band; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4041 | |
| 4042 | /* TODO: Could consider removing the least recently used entry and |
| 4043 | * allow new one to be added. */ |
| 4044 | if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { |
| 4045 | if (net_ratelimit()) { |
| 4046 | printk(KERN_DEBUG "%s: No room for a new IBSS STA " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4047 | "entry %s\n", sdata->dev->name, print_mac(mac, addr)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4048 | } |
| 4049 | return NULL; |
| 4050 | } |
| 4051 | |
Emmanuel Grumbach | 1e18863 | 2008-07-10 17:54:14 +0300 | [diff] [blame] | 4052 | if (compare_ether_addr(bssid, sdata->u.sta.bssid)) |
Vladimir Koutny | 87291c0 | 2008-06-13 16:50:44 +0200 | [diff] [blame] | 4053 | return NULL; |
| 4054 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 4055 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4056 | 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] | 4057 | wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 4058 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4059 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 4060 | sta = sta_info_alloc(sdata, addr, GFP_ATOMIC); |
| 4061 | if (!sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4062 | return NULL; |
| 4063 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 4064 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
Johannes Berg | 238814f | 2008-01-28 17:19:37 +0100 | [diff] [blame] | 4065 | |
Emmanuel Grumbach | 8e1535d | 2008-09-03 23:42:20 +0300 | [diff] [blame] | 4066 | /* make sure mandatory rates are always added */ |
| 4067 | sta->supp_rates[band] = supp_rates | |
| 4068 | ieee80211_sta_get_mandatory_rates(local, band); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4069 | |
| 4070 | rate_control_rate_init(sta, local); |
| 4071 | |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 4072 | if (sta_info_insert(sta)) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 4073 | return NULL; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 4074 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 4075 | return sta; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 4079 | static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata, |
| 4080 | struct ieee80211_if_sta *ifsta) |
| 4081 | { |
| 4082 | struct ieee80211_local *local = sdata->local; |
| 4083 | struct ieee80211_sta_bss *bss, *selected = NULL; |
| 4084 | int top_rssi = 0, freq; |
| 4085 | |
| 4086 | spin_lock_bh(&local->sta_bss_lock); |
| 4087 | freq = local->oper_channel->center_freq; |
| 4088 | list_for_each_entry(bss, &local->sta_bss_list, list) { |
| 4089 | if (!(bss->capability & WLAN_CAPABILITY_ESS)) |
| 4090 | continue; |
| 4091 | |
| 4092 | if ((ifsta->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
| 4093 | IEEE80211_STA_AUTO_BSSID_SEL | |
| 4094 | IEEE80211_STA_AUTO_CHANNEL_SEL)) && |
| 4095 | (!!(bss->capability & WLAN_CAPABILITY_PRIVACY) ^ |
| 4096 | !!sdata->default_key)) |
| 4097 | continue; |
| 4098 | |
| 4099 | if (!(ifsta->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) && |
| 4100 | bss->freq != freq) |
| 4101 | continue; |
| 4102 | |
| 4103 | if (!(ifsta->flags & IEEE80211_STA_AUTO_BSSID_SEL) && |
| 4104 | memcmp(bss->bssid, ifsta->bssid, ETH_ALEN)) |
| 4105 | continue; |
| 4106 | |
| 4107 | if (!(ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) && |
| 4108 | !ieee80211_sta_match_ssid(ifsta, bss->ssid, bss->ssid_len)) |
| 4109 | continue; |
| 4110 | |
| 4111 | if (!selected || top_rssi < bss->signal) { |
| 4112 | selected = bss; |
| 4113 | top_rssi = bss->signal; |
| 4114 | } |
| 4115 | } |
| 4116 | if (selected) |
| 4117 | atomic_inc(&selected->users); |
| 4118 | spin_unlock_bh(&local->sta_bss_lock); |
| 4119 | |
| 4120 | if (selected) { |
| 4121 | ieee80211_set_freq(sdata, selected->freq); |
| 4122 | if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) |
| 4123 | ieee80211_sta_set_ssid(sdata, selected->ssid, |
| 4124 | selected->ssid_len); |
| 4125 | ieee80211_sta_set_bssid(sdata, selected->bssid); |
| 4126 | ieee80211_sta_def_wmm_params(sdata, selected, 0); |
| 4127 | |
| 4128 | /* Send out direct probe if no probe resp was received or |
| 4129 | * the one we have is outdated |
| 4130 | */ |
| 4131 | if (!selected->last_probe_resp || |
| 4132 | time_after(jiffies, selected->last_probe_resp |
| 4133 | + IEEE80211_SCAN_RESULT_EXPIRE)) |
| 4134 | ifsta->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 4135 | else |
| 4136 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
| 4137 | |
| 4138 | ieee80211_rx_bss_put(local, selected); |
| 4139 | ieee80211_sta_reset_auth(sdata, ifsta); |
| 4140 | return 0; |
| 4141 | } else { |
| 4142 | if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { |
| 4143 | ifsta->assoc_scan_tries++; |
| 4144 | if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) |
| 4145 | ieee80211_sta_start_scan(sdata, NULL, 0); |
| 4146 | else |
| 4147 | ieee80211_sta_start_scan(sdata, ifsta->ssid, |
| 4148 | ifsta->ssid_len); |
| 4149 | ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; |
| 4150 | set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); |
| 4151 | } else |
| 4152 | ifsta->state = IEEE80211_STA_MLME_DISABLED; |
| 4153 | } |
| 4154 | return -1; |
| 4155 | } |
| 4156 | |
| 4157 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4158 | int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4159 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4160 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 4161 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 4162 | printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4163 | sdata->dev->name, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4164 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 4165 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 4166 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4167 | return -EINVAL; |
| 4168 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 4169 | ieee80211_set_disassoc(sdata, ifsta, true, true, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4170 | return 0; |
| 4171 | } |
| 4172 | |
| 4173 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4174 | int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4175 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4176 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 4177 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 4178 | printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4179 | sdata->dev->name, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4180 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 4181 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4182 | return -EINVAL; |
| 4183 | |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 4184 | if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4185 | return -1; |
| 4186 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 4187 | ieee80211_set_disassoc(sdata, ifsta, false, true, reason); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4188 | return 0; |
| 4189 | } |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4190 | |
| 4191 | void ieee80211_notify_mac(struct ieee80211_hw *hw, |
| 4192 | enum ieee80211_notification_types notif_type) |
| 4193 | { |
| 4194 | struct ieee80211_local *local = hw_to_local(hw); |
| 4195 | struct ieee80211_sub_if_data *sdata; |
| 4196 | |
| 4197 | switch (notif_type) { |
| 4198 | case IEEE80211_NOTIFY_RE_ASSOC: |
| 4199 | rcu_read_lock(); |
| 4200 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 4201 | if (sdata->vif.type != IEEE80211_IF_TYPE_STA) |
| 4202 | continue; |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4203 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 4204 | ieee80211_sta_req_auth(sdata, &sdata->u.sta); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4205 | } |
| 4206 | rcu_read_unlock(); |
| 4207 | break; |
| 4208 | } |
| 4209 | } |
| 4210 | EXPORT_SYMBOL(ieee80211_notify_mac); |
Johannes Berg | 60f8b39c | 2008-09-08 17:44:22 +0200 | [diff] [blame^] | 4211 | |
| 4212 | void ieee80211_sta_work(struct work_struct *work) |
| 4213 | { |
| 4214 | struct ieee80211_sub_if_data *sdata = |
| 4215 | container_of(work, struct ieee80211_sub_if_data, u.sta.work); |
| 4216 | struct ieee80211_local *local = sdata->local; |
| 4217 | struct ieee80211_if_sta *ifsta; |
| 4218 | struct sk_buff *skb; |
| 4219 | |
| 4220 | if (!netif_running(sdata->dev)) |
| 4221 | return; |
| 4222 | |
| 4223 | if (local->sta_sw_scanning || local->sta_hw_scanning) |
| 4224 | return; |
| 4225 | |
| 4226 | if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA && |
| 4227 | sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
| 4228 | sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) |
| 4229 | return; |
| 4230 | ifsta = &sdata->u.sta; |
| 4231 | |
| 4232 | while ((skb = skb_dequeue(&ifsta->skb_queue))) |
| 4233 | ieee80211_sta_rx_queued_mgmt(sdata, skb); |
| 4234 | |
| 4235 | #ifdef CONFIG_MAC80211_MESH |
| 4236 | if (ifsta->preq_queue_len && |
| 4237 | time_after(jiffies, |
| 4238 | ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval))) |
| 4239 | mesh_path_start_discovery(sdata); |
| 4240 | #endif |
| 4241 | |
| 4242 | if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE && |
| 4243 | ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && |
| 4244 | ifsta->state != IEEE80211_STA_MLME_ASSOCIATE && |
| 4245 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { |
| 4246 | if (ifsta->scan_ssid_len) |
| 4247 | ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len); |
| 4248 | else |
| 4249 | ieee80211_sta_start_scan(sdata, NULL, 0); |
| 4250 | return; |
| 4251 | } |
| 4252 | |
| 4253 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request)) { |
| 4254 | if (ieee80211_sta_config_auth(sdata, ifsta)) |
| 4255 | return; |
| 4256 | clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request); |
| 4257 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifsta->request)) |
| 4258 | return; |
| 4259 | |
| 4260 | switch (ifsta->state) { |
| 4261 | case IEEE80211_STA_MLME_DISABLED: |
| 4262 | break; |
| 4263 | case IEEE80211_STA_MLME_DIRECT_PROBE: |
| 4264 | ieee80211_direct_probe(sdata, ifsta); |
| 4265 | break; |
| 4266 | case IEEE80211_STA_MLME_AUTHENTICATE: |
| 4267 | ieee80211_authenticate(sdata, ifsta); |
| 4268 | break; |
| 4269 | case IEEE80211_STA_MLME_ASSOCIATE: |
| 4270 | ieee80211_associate(sdata, ifsta); |
| 4271 | break; |
| 4272 | case IEEE80211_STA_MLME_ASSOCIATED: |
| 4273 | ieee80211_associated(sdata, ifsta); |
| 4274 | break; |
| 4275 | case IEEE80211_STA_MLME_IBSS_SEARCH: |
| 4276 | ieee80211_sta_find_ibss(sdata, ifsta); |
| 4277 | break; |
| 4278 | case IEEE80211_STA_MLME_IBSS_JOINED: |
| 4279 | ieee80211_sta_merge_ibss(sdata, ifsta); |
| 4280 | break; |
| 4281 | #ifdef CONFIG_MAC80211_MESH |
| 4282 | case IEEE80211_STA_MLME_MESH_UP: |
| 4283 | ieee80211_mesh_housekeeping(sdata, ifsta); |
| 4284 | break; |
| 4285 | #endif |
| 4286 | default: |
| 4287 | WARN_ON(1); |
| 4288 | break; |
| 4289 | } |
| 4290 | |
| 4291 | if (ieee80211_privacy_mismatch(sdata, ifsta)) { |
| 4292 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " |
| 4293 | "mixed-cell disabled - disassociate\n", sdata->dev->name); |
| 4294 | |
| 4295 | ieee80211_set_disassoc(sdata, ifsta, false, true, |
| 4296 | WLAN_REASON_UNSPECIFIED); |
| 4297 | } |
| 4298 | } |