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