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