Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 17 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 20 | #include <net/mac80211.h> |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 21 | #include <asm/unaligned.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 22 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 23 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 24 | #include "rate.h" |
| 25 | #include "led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | |
Ron Rindjunsky | 6042a3e | 2008-08-08 01:50:46 +0300 | [diff] [blame] | 27 | #define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 29 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 30 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 31 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 32 | #define IEEE80211_MONITORING_INTERVAL (2 * HZ) |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 33 | #define IEEE80211_PROBE_IDLE_TIME (60 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 34 | #define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 35 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 36 | /* utils */ |
| 37 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 38 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 39 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 42 | static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie) |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 43 | { |
| 44 | u8 *end, *pos; |
| 45 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 46 | pos = bss->cbss.information_elements; |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 47 | if (pos == NULL) |
| 48 | return NULL; |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 49 | end = pos + bss->cbss.len_information_elements; |
Jouni Malinen | 43ac2ca | 2008-08-15 22:21:27 +0300 | [diff] [blame] | 50 | |
| 51 | while (pos + 1 < end) { |
| 52 | if (pos + 2 + pos[1] > end) |
| 53 | break; |
| 54 | if (pos[0] == ie) |
| 55 | return pos; |
| 56 | pos += 2 + pos[1]; |
| 57 | } |
| 58 | |
| 59 | return NULL; |
| 60 | } |
| 61 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 62 | static int ieee80211_compatible_rates(struct ieee80211_bss *bss, |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 63 | struct ieee80211_supported_band *sband, |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 64 | u32 *rates) |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 65 | { |
| 66 | int i, j, count; |
| 67 | *rates = 0; |
| 68 | count = 0; |
| 69 | for (i = 0; i < bss->supp_rates_len; i++) { |
| 70 | int rate = (bss->supp_rates[i] & 0x7F) * 5; |
| 71 | |
| 72 | for (j = 0; j < sband->n_bitrates; j++) |
| 73 | if (sband->bitrates[j].bitrate == rate) { |
| 74 | *rates |= BIT(j); |
| 75 | count++; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return count; |
| 81 | } |
| 82 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 83 | /* frame sending functions */ |
| 84 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 85 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 86 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 87 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 88 | struct ieee80211_local *local = sdata->local; |
| 89 | struct sk_buff *skb; |
| 90 | struct ieee80211_mgmt *mgmt; |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 91 | u8 *pos, *ies, *ht_ie; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 92 | int i, len, count, rates_len, supp_rates_len; |
| 93 | u16 capab; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 94 | struct ieee80211_bss *bss; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 95 | int wmm = 0; |
| 96 | struct ieee80211_supported_band *sband; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 97 | u32 rates = 0; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 98 | |
| 99 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 100 | sizeof(*mgmt) + 200 + ifmgd->extra_ie_len + |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 101 | ifmgd->ssid_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 102 | if (!skb) { |
| 103 | printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " |
| 104 | "frame\n", sdata->dev->name); |
| 105 | return; |
| 106 | } |
| 107 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 108 | |
| 109 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 110 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 111 | capab = ifmgd->capab; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 112 | |
| 113 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) { |
| 114 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 115 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 116 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 117 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 118 | } |
| 119 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 120 | bss = ieee80211_rx_bss_get(local, ifmgd->bssid, |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 121 | local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 122 | ifmgd->ssid, ifmgd->ssid_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 123 | if (bss) { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 124 | if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY) |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 125 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 126 | if (bss->wmm_used) |
| 127 | wmm = 1; |
| 128 | |
| 129 | /* get all rates supported by the device and the AP as |
| 130 | * some APs don't like getting a superset of their rates |
| 131 | * in the association request (e.g. D-Link DAP 1353 in |
| 132 | * b-only mode) */ |
| 133 | rates_len = ieee80211_compatible_rates(bss, sband, &rates); |
| 134 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 135 | if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 136 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 137 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 138 | |
| 139 | ieee80211_rx_bss_put(local, bss); |
| 140 | } else { |
| 141 | rates = ~0; |
| 142 | rates_len = sband->n_bitrates; |
| 143 | } |
| 144 | |
| 145 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 146 | memset(mgmt, 0, 24); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 147 | memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 148 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 149 | memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 150 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 151 | if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) { |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 152 | skb_put(skb, 10); |
| 153 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 154 | IEEE80211_STYPE_REASSOC_REQ); |
| 155 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 156 | mgmt->u.reassoc_req.listen_interval = |
| 157 | cpu_to_le16(local->hw.conf.listen_interval); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 158 | memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid, |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 159 | ETH_ALEN); |
| 160 | } else { |
| 161 | skb_put(skb, 4); |
| 162 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 163 | IEEE80211_STYPE_ASSOC_REQ); |
| 164 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
Rami Rosen | 1355412 | 2008-12-16 22:38:29 +0200 | [diff] [blame] | 165 | mgmt->u.assoc_req.listen_interval = |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 166 | cpu_to_le16(local->hw.conf.listen_interval); |
| 167 | } |
| 168 | |
| 169 | /* SSID */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 170 | ies = pos = skb_put(skb, 2 + ifmgd->ssid_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 171 | *pos++ = WLAN_EID_SSID; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 172 | *pos++ = ifmgd->ssid_len; |
| 173 | memcpy(pos, ifmgd->ssid, ifmgd->ssid_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 174 | |
| 175 | /* add all rates which were marked to be used above */ |
| 176 | supp_rates_len = rates_len; |
| 177 | if (supp_rates_len > 8) |
| 178 | supp_rates_len = 8; |
| 179 | |
| 180 | len = sband->n_bitrates; |
| 181 | pos = skb_put(skb, supp_rates_len + 2); |
| 182 | *pos++ = WLAN_EID_SUPP_RATES; |
| 183 | *pos++ = supp_rates_len; |
| 184 | |
| 185 | count = 0; |
| 186 | for (i = 0; i < sband->n_bitrates; i++) { |
| 187 | if (BIT(i) & rates) { |
| 188 | int rate = sband->bitrates[i].bitrate; |
| 189 | *pos++ = (u8) (rate / 5); |
| 190 | if (++count == 8) |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | if (rates_len > count) { |
| 196 | pos = skb_put(skb, rates_len - count + 2); |
| 197 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 198 | *pos++ = rates_len - count; |
| 199 | |
| 200 | for (i++; i < sband->n_bitrates; i++) { |
| 201 | if (BIT(i) & rates) { |
| 202 | int rate = sband->bitrates[i].bitrate; |
| 203 | *pos++ = (u8) (rate / 5); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 209 | /* 1. power capabilities */ |
| 210 | pos = skb_put(skb, 4); |
| 211 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 212 | *pos++ = 2; |
| 213 | *pos++ = 0; /* min tx power */ |
| 214 | *pos++ = local->hw.conf.channel->max_power; /* max tx power */ |
| 215 | |
| 216 | /* 2. supported channels */ |
| 217 | /* TODO: get this in reg domain format */ |
| 218 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 219 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 220 | *pos++ = 2 * sband->n_channels; |
| 221 | for (i = 0; i < sband->n_channels; i++) { |
| 222 | *pos++ = ieee80211_frequency_to_channel( |
| 223 | sband->channels[i].center_freq); |
| 224 | *pos++ = 1; /* one channel in the subband*/ |
| 225 | } |
| 226 | } |
| 227 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 228 | if (ifmgd->extra_ie) { |
| 229 | pos = skb_put(skb, ifmgd->extra_ie_len); |
| 230 | memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 233 | if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) { |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 234 | pos = skb_put(skb, 9); |
| 235 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 236 | *pos++ = 7; /* len */ |
| 237 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 238 | *pos++ = 0x50; |
| 239 | *pos++ = 0xf2; |
| 240 | *pos++ = 2; /* WME */ |
| 241 | *pos++ = 0; /* WME info */ |
| 242 | *pos++ = 1; /* WME ver */ |
| 243 | *pos++ = 0; |
| 244 | } |
| 245 | |
| 246 | /* wmm support is a must to HT */ |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 247 | /* |
| 248 | * IEEE802.11n does not allow TKIP/WEP as pairwise |
| 249 | * ciphers in HT mode. We still associate in non-ht |
| 250 | * mode (11a/b/g) if any one of these ciphers is |
| 251 | * configured as pairwise. |
| 252 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 253 | if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 254 | sband->ht_cap.ht_supported && |
| 255 | (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) && |
Vasanthakumar Thiagarajan | eb46936 | 2008-12-23 21:30:50 +0530 | [diff] [blame] | 256 | ht_ie[1] >= sizeof(struct ieee80211_ht_info) && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 257 | (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 258 | struct ieee80211_ht_info *ht_info = |
| 259 | (struct ieee80211_ht_info *)(ht_ie + 2); |
| 260 | u16 cap = sband->ht_cap.cap; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 261 | __le16 tmp; |
| 262 | u32 flags = local->hw.conf.channel->flags; |
| 263 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 264 | switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
| 265 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 266 | if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 267 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 268 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 269 | } |
| 270 | break; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 271 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 272 | if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 273 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 274 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 275 | } |
| 276 | break; |
| 277 | } |
| 278 | |
| 279 | tmp = cpu_to_le16(cap); |
| 280 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); |
| 281 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 282 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 283 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); |
| 284 | memcpy(pos, &tmp, sizeof(u16)); |
| 285 | pos += sizeof(u16); |
| 286 | /* TODO: needs a define here for << 2 */ |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 287 | *pos++ = sband->ht_cap.ampdu_factor | |
| 288 | (sband->ht_cap.ampdu_density << 2); |
| 289 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 292 | kfree(ifmgd->assocreq_ies); |
| 293 | ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies; |
| 294 | ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL); |
| 295 | if (ifmgd->assocreq_ies) |
| 296 | memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 297 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 298 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 302 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
| 303 | u16 stype, u16 reason) |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 304 | { |
| 305 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 306 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 307 | struct sk_buff *skb; |
| 308 | struct ieee80211_mgmt *mgmt; |
| 309 | |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 310 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 311 | if (!skb) { |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 312 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
| 313 | "deauth/disassoc frame\n", sdata->dev->name); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 314 | return; |
| 315 | } |
| 316 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 317 | |
| 318 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 319 | memset(mgmt, 0, 24); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 320 | memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 321 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 322 | memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 323 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 324 | skb_put(skb, 2); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 325 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 326 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
| 327 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame^] | 328 | if (stype == IEEE80211_STYPE_DEAUTH) |
| 329 | cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len); |
| 330 | else |
| 331 | cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 332 | ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 335 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 336 | struct ieee80211_sub_if_data *sdata) |
| 337 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 338 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 339 | struct ieee80211_pspoll *pspoll; |
| 340 | struct sk_buff *skb; |
| 341 | u16 fc; |
| 342 | |
| 343 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); |
| 344 | if (!skb) { |
| 345 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
| 346 | "pspoll frame\n", sdata->dev->name); |
| 347 | return; |
| 348 | } |
| 349 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 350 | |
| 351 | pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll)); |
| 352 | memset(pspoll, 0, sizeof(*pspoll)); |
| 353 | fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM; |
| 354 | pspoll->frame_control = cpu_to_le16(fc); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 355 | pspoll->aid = cpu_to_le16(ifmgd->aid); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 356 | |
| 357 | /* aid in PS-Poll has its two MSBs each set to 1 */ |
| 358 | pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); |
| 359 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 360 | memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 361 | memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN); |
| 362 | |
| 363 | ieee80211_tx_skb(sdata, skb, 0); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 366 | /* MLME */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 367 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 368 | struct ieee80211_if_managed *ifmgd, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 369 | u8 *wmm_param, size_t wmm_param_len) |
| 370 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 371 | struct ieee80211_tx_queue_params params; |
| 372 | size_t left; |
| 373 | int count; |
| 374 | u8 *pos; |
| 375 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 376 | if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 377 | return; |
| 378 | |
| 379 | if (!wmm_param) |
| 380 | return; |
| 381 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 382 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
| 383 | return; |
| 384 | count = wmm_param[6] & 0x0f; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 385 | if (count == ifmgd->wmm_last_param_set) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 386 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 387 | ifmgd->wmm_last_param_set = count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 388 | |
| 389 | pos = wmm_param + 8; |
| 390 | left = wmm_param_len - 8; |
| 391 | |
| 392 | memset(¶ms, 0, sizeof(params)); |
| 393 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 394 | local->wmm_acm = 0; |
| 395 | for (; left >= 4; left -= 4, pos += 4) { |
| 396 | int aci = (pos[0] >> 5) & 0x03; |
| 397 | int acm = (pos[0] >> 4) & 0x01; |
| 398 | int queue; |
| 399 | |
| 400 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 401 | case 1: /* AC_BK */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 402 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 403 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 404 | local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 405 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 406 | case 2: /* AC_VI */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 407 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 408 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 409 | local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 410 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 411 | case 3: /* AC_VO */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 412 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 413 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 414 | local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 415 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 416 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 417 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 418 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 419 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 420 | local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 421 | break; |
| 422 | } |
| 423 | |
| 424 | params.aifs = pos[0] & 0x0f; |
| 425 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 426 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 427 | params.txop = get_unaligned_le16(pos + 2); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 428 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 429 | 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] | 430 | "cWmin=%d cWmax=%d txop=%d\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 431 | local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 432 | params.cw_max, params.txop); |
| 433 | #endif |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 434 | if (local->ops->conf_tx && |
| 435 | local->ops->conf_tx(local_to_hw(local), queue, ¶ms)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 436 | printk(KERN_DEBUG "%s: failed to set TX queue " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 437 | "parameters for queue %d\n", local->mdev->name, queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 442 | static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid) |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 443 | { |
| 444 | u8 mask; |
| 445 | u8 index, indexn1, indexn2; |
| 446 | struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim; |
| 447 | |
Johannes Berg | 6037554 | 2009-04-17 00:54:23 +0200 | [diff] [blame] | 448 | if (unlikely(!tim || elems->tim_len < 4)) |
| 449 | return false; |
| 450 | |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 451 | aid &= 0x3fff; |
| 452 | index = aid / 8; |
| 453 | mask = 1 << (aid & 7); |
| 454 | |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 455 | indexn1 = tim->bitmap_ctrl & 0xfe; |
| 456 | indexn2 = elems->tim_len + indexn1 - 4; |
| 457 | |
| 458 | if (index < indexn1 || index > indexn2) |
| 459 | return false; |
| 460 | |
| 461 | index -= indexn1; |
| 462 | |
| 463 | return !!(tim->virtual_map[index] & mask); |
| 464 | } |
| 465 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 466 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 467 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 468 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 469 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 470 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 471 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | ebd7448 | 2008-07-01 10:44:50 +0300 | [diff] [blame] | 472 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 473 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 474 | bool use_protection; |
| 475 | bool use_short_preamble; |
| 476 | bool use_short_slot; |
| 477 | |
| 478 | if (erp_valid) { |
| 479 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 480 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 481 | } else { |
| 482 | use_protection = false; |
| 483 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 484 | } |
| 485 | |
| 486 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 487 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 488 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 489 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 490 | if (net_ratelimit()) { |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 491 | printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 492 | sdata->dev->name, |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 493 | use_protection ? "enabled" : "disabled", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 494 | ifmgd->bssid); |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 495 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 496 | #endif |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 497 | bss_conf->use_cts_prot = use_protection; |
| 498 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 499 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 500 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 501 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 502 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 503 | if (net_ratelimit()) { |
| 504 | printk(KERN_DEBUG "%s: switched to %s barker preamble" |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 505 | " (BSSID=%pM)\n", |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 506 | sdata->dev->name, |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 507 | use_short_preamble ? "short" : "long", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 508 | ifmgd->bssid); |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 509 | } |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 510 | #endif |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 511 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 512 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 513 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 514 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 515 | if (use_short_slot != bss_conf->use_short_slot) { |
| 516 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 517 | if (net_ratelimit()) { |
Christian Lamparter | 391429c | 2009-01-18 02:24:15 +0100 | [diff] [blame] | 518 | printk(KERN_DEBUG "%s: switched to %s slot time" |
| 519 | " (BSSID=%pM)\n", |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 520 | sdata->dev->name, |
| 521 | use_short_slot ? "short" : "long", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 522 | ifmgd->bssid); |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 523 | } |
| 524 | #endif |
| 525 | bss_conf->use_short_slot = use_short_slot; |
| 526 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | return changed; |
| 530 | } |
| 531 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 532 | static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata) |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 533 | { |
| 534 | union iwreq_data wrqu; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 535 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 536 | memset(&wrqu, 0, sizeof(wrqu)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 537 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) |
| 538 | memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 539 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 540 | wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); |
| 541 | } |
| 542 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 543 | static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 544 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 545 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 546 | char *buf; |
| 547 | size_t len; |
| 548 | int i; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 549 | union iwreq_data wrqu; |
| 550 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 551 | if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies) |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 552 | return; |
| 553 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 554 | buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len + |
| 555 | ifmgd->assocresp_ies_len), GFP_KERNEL); |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 556 | if (!buf) |
| 557 | return; |
| 558 | |
| 559 | len = sprintf(buf, "ASSOCINFO("); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 560 | if (ifmgd->assocreq_ies) { |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 561 | len += sprintf(buf + len, "ReqIEs="); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 562 | for (i = 0; i < ifmgd->assocreq_ies_len; i++) { |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 563 | len += sprintf(buf + len, "%02x", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 564 | ifmgd->assocreq_ies[i]); |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 565 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 566 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 567 | if (ifmgd->assocresp_ies) { |
| 568 | if (ifmgd->assocreq_ies) |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 569 | len += sprintf(buf + len, " "); |
| 570 | len += sprintf(buf + len, "RespIEs="); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 571 | for (i = 0; i < ifmgd->assocresp_ies_len; i++) { |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 572 | len += sprintf(buf + len, "%02x", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 573 | ifmgd->assocresp_ies[i]); |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 574 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 575 | } |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 576 | len += sprintf(buf + len, ")"); |
| 577 | |
| 578 | if (len > IW_CUSTOM_MAX) { |
| 579 | len = sprintf(buf, "ASSOCRESPIE="); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 580 | for (i = 0; i < ifmgd->assocresp_ies_len; i++) { |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 581 | len += sprintf(buf + len, "%02x", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 582 | ifmgd->assocresp_ies[i]); |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | |
John W. Linville | ad788b5 | 2008-10-01 15:45:02 -0400 | [diff] [blame] | 586 | if (len <= IW_CUSTOM_MAX) { |
| 587 | memset(&wrqu, 0, sizeof(wrqu)); |
| 588 | wrqu.data.length = len; |
| 589 | wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf); |
| 590 | } |
Linus Torvalds | 74af025 | 2008-09-05 12:38:09 -0700 | [diff] [blame] | 591 | |
| 592 | kfree(buf); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 596 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 597 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 598 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 599 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 600 | struct ieee80211_local *local = sdata->local; |
Tomas Winkler | 38668c0 | 2008-03-28 16:33:32 -0700 | [diff] [blame] | 601 | struct ieee80211_conf *conf = &local_to_hw(local)->conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 602 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 603 | struct ieee80211_bss *bss; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 604 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 605 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 606 | ifmgd->flags |= IEEE80211_STA_ASSOCIATED; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 607 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 608 | bss = ieee80211_rx_bss_get(local, ifmgd->bssid, |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 609 | conf->channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 610 | ifmgd->ssid, ifmgd->ssid_len); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 611 | if (bss) { |
| 612 | /* set timing information */ |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 613 | sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval; |
| 614 | sdata->vif.bss_conf.timestamp = bss->cbss.tsf; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 615 | sdata->vif.bss_conf.dtim_period = bss->dtim_period; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 616 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 617 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 618 | bss->cbss.capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 619 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 620 | cfg80211_hold_bss(&bss->cbss); |
| 621 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 622 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 623 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 624 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 625 | ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET; |
| 626 | memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN); |
| 627 | ieee80211_sta_send_associnfo(sdata); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 628 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 629 | ifmgd->last_probe = jiffies; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 630 | ieee80211_led_assoc(local, 1); |
| 631 | |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 632 | sdata->vif.bss_conf.assoc = 1; |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 633 | /* |
| 634 | * For now just always ask the driver to update the basic rateset |
| 635 | * when we have associated, we aren't checking whether it actually |
| 636 | * changed or not. |
| 637 | */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 638 | bss_info_changed |= BSS_CHANGED_BASIC_RATES; |
| 639 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 640 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 641 | if (local->powersave) { |
| 642 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) && |
| 643 | local->hw.conf.dynamic_ps_timeout > 0) { |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 644 | mod_timer(&local->dynamic_ps_timer, jiffies + |
Johannes Berg | 46f2c4b | 2009-01-06 18:13:18 +0100 | [diff] [blame] | 645 | msecs_to_jiffies( |
| 646 | local->hw.conf.dynamic_ps_timeout)); |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 647 | } else { |
| 648 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 649 | ieee80211_send_nullfunc(local, sdata, 1); |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 650 | conf->flags |= IEEE80211_CONF_PS; |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 651 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 652 | } |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 653 | } |
| 654 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 655 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 656 | netif_carrier_on(sdata->dev); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 657 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 658 | ieee80211_sta_send_apinfo(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 661 | static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata) |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 662 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 663 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 664 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 665 | |
| 666 | ifmgd->direct_probe_tries++; |
| 667 | if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 668 | printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 669 | sdata->dev->name, ifmgd->bssid); |
| 670 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
| 671 | ieee80211_sta_send_apinfo(sdata); |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 672 | |
| 673 | /* |
| 674 | * Most likely AP is not in the range so remove the |
| 675 | * bss information associated to the AP |
| 676 | */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 677 | ieee80211_rx_bss_remove(sdata, ifmgd->bssid, |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 678 | sdata->local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 679 | ifmgd->ssid, ifmgd->ssid_len); |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 680 | |
| 681 | /* |
| 682 | * We might have a pending scan which had no chance to run yet |
| 683 | * due to state == IEEE80211_STA_MLME_DIRECT_PROBE. |
| 684 | * Hence, queue the STAs work again |
| 685 | */ |
| 686 | queue_work(local->hw.workqueue, &ifmgd->work); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 690 | printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 691 | sdata->dev->name, ifmgd->bssid, |
| 692 | ifmgd->direct_probe_tries); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 693 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 694 | ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 695 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 696 | set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 697 | |
| 698 | /* Direct probe is sent to broadcast address as some APs |
| 699 | * will not answer to direct packet in unassociated state. |
| 700 | */ |
| 701 | ieee80211_send_probe_req(sdata, NULL, |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 702 | ifmgd->ssid, ifmgd->ssid_len, NULL, 0); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 703 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 704 | mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 705 | } |
| 706 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 707 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 708 | static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 709 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 710 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 711 | struct ieee80211_local *local = sdata->local; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 712 | u8 *ies; |
| 713 | size_t ies_len; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 714 | |
| 715 | ifmgd->auth_tries++; |
| 716 | if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 717 | printk(KERN_DEBUG "%s: authentication with AP %pM" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 718 | " timed out\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 719 | sdata->dev->name, ifmgd->bssid); |
| 720 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
| 721 | ieee80211_sta_send_apinfo(sdata); |
| 722 | ieee80211_rx_bss_remove(sdata, ifmgd->bssid, |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 723 | sdata->local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 724 | ifmgd->ssid, ifmgd->ssid_len); |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * We might have a pending scan which had no chance to run yet |
| 728 | * due to state == IEEE80211_STA_MLME_AUTHENTICATE. |
| 729 | * Hence, queue the STAs work again |
| 730 | */ |
| 731 | queue_work(local->hw.workqueue, &ifmgd->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 735 | ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 736 | printk(KERN_DEBUG "%s: authenticate with AP %pM\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 737 | sdata->dev->name, ifmgd->bssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 738 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 739 | if (ifmgd->flags & IEEE80211_STA_EXT_SME) { |
| 740 | ies = ifmgd->sme_auth_ie; |
| 741 | ies_len = ifmgd->sme_auth_ie_len; |
| 742 | } else { |
| 743 | ies = NULL; |
| 744 | ies_len = 0; |
| 745 | } |
| 746 | ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 747 | ifmgd->bssid, 0); |
| 748 | ifmgd->auth_transaction = 2; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 749 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 750 | mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Vivek Natarajan | 5925d97 | 2008-11-21 22:19:50 -0800 | [diff] [blame] | 753 | /* |
| 754 | * The disassoc 'reason' argument can be either our own reason |
| 755 | * if self disconnected or a reason code from the AP. |
| 756 | */ |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 757 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 758 | bool deauth, bool self_disconnected, |
| 759 | u16 reason) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 760 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 761 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 762 | struct ieee80211_local *local = sdata->local; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 763 | struct ieee80211_conf *conf = &local_to_hw(local)->conf; |
| 764 | struct ieee80211_bss *bss; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 765 | struct sta_info *sta; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 766 | u32 changed = 0, config_changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 767 | |
| 768 | rcu_read_lock(); |
| 769 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 770 | sta = sta_info_get(local, ifmgd->bssid); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 771 | if (!sta) { |
| 772 | rcu_read_unlock(); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | if (deauth) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 777 | ifmgd->direct_probe_tries = 0; |
| 778 | ifmgd->auth_tries = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 779 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 780 | ifmgd->assoc_scan_tries = 0; |
| 781 | ifmgd->assoc_tries = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 782 | |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 783 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 784 | netif_carrier_off(sdata->dev); |
| 785 | |
Johannes Berg | 2dace10 | 2009-02-10 21:25:52 +0100 | [diff] [blame] | 786 | ieee80211_sta_tear_down_BA_sessions(sta); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 787 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 788 | bss = ieee80211_rx_bss_get(local, ifmgd->bssid, |
| 789 | conf->channel->center_freq, |
| 790 | ifmgd->ssid, ifmgd->ssid_len); |
| 791 | |
| 792 | if (bss) { |
| 793 | cfg80211_unhold_bss(&bss->cbss); |
| 794 | ieee80211_rx_bss_put(local, bss); |
| 795 | } |
| 796 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 797 | if (self_disconnected) { |
| 798 | if (deauth) |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 799 | ieee80211_send_deauth_disassoc(sdata, |
| 800 | IEEE80211_STYPE_DEAUTH, reason); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 801 | else |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 802 | ieee80211_send_deauth_disassoc(sdata, |
| 803 | IEEE80211_STYPE_DISASSOC, reason); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 804 | } |
| 805 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 806 | ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 807 | changed |= ieee80211_reset_erp_info(sdata); |
| 808 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 809 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 810 | changed |= BSS_CHANGED_ASSOC; |
| 811 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 812 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 813 | ieee80211_sta_send_apinfo(sdata); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 814 | |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 815 | if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 816 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
| 817 | ieee80211_rx_bss_remove(sdata, ifmgd->bssid, |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 818 | sdata->local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 819 | ifmgd->ssid, ifmgd->ssid_len); |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 820 | } |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 821 | |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 822 | rcu_read_unlock(); |
| 823 | |
Johannes Berg | 4797938 | 2009-01-07 10:13:27 +0100 | [diff] [blame] | 824 | /* channel(_type) changes are handled by ieee80211_hw_config */ |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 825 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 826 | |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 827 | local->power_constr_level = 0; |
| 828 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 829 | del_timer_sync(&local->dynamic_ps_timer); |
| 830 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 831 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 832 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 833 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 834 | config_changed |= IEEE80211_CONF_CHANGE_PS; |
| 835 | } |
| 836 | |
| 837 | ieee80211_hw_config(local, config_changed); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 838 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 839 | |
| 840 | rcu_read_lock(); |
| 841 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 842 | sta = sta_info_get(local, ifmgd->bssid); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 843 | if (!sta) { |
| 844 | rcu_read_unlock(); |
| 845 | return; |
| 846 | } |
| 847 | |
| 848 | sta_info_unlink(&sta); |
| 849 | |
| 850 | rcu_read_unlock(); |
| 851 | |
| 852 | sta_info_destroy(sta); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 853 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 854 | |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 855 | static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) |
| 856 | { |
| 857 | if (!sdata || !sdata->default_key || |
| 858 | sdata->default_key->conf.alg != ALG_WEP) |
| 859 | return 0; |
| 860 | return 1; |
| 861 | } |
| 862 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 863 | static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 864 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 865 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 866 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 867 | struct ieee80211_bss *bss; |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 868 | int bss_privacy; |
| 869 | int wep_privacy; |
| 870 | int privacy_invoked; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 871 | |
Johannes Berg | 7986cf9 | 2009-03-21 17:08:43 +0100 | [diff] [blame] | 872 | if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 873 | return 0; |
| 874 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 875 | bss = ieee80211_rx_bss_get(local, ifmgd->bssid, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 876 | local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 877 | ifmgd->ssid, ifmgd->ssid_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 878 | if (!bss) |
| 879 | return 0; |
| 880 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 881 | bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 882 | wep_privacy = !!ieee80211_sta_wep_configured(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 883 | privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 884 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 885 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 886 | |
Johannes Berg | 5b98b1f | 2007-11-03 13:11:10 +0000 | [diff] [blame] | 887 | if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked)) |
| 888 | return 0; |
| 889 | |
| 890 | return 1; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 893 | static void ieee80211_associate(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 894 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 895 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 896 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 897 | |
| 898 | ifmgd->assoc_tries++; |
| 899 | if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 900 | printk(KERN_DEBUG "%s: association with AP %pM" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 901 | " timed out\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 902 | sdata->dev->name, ifmgd->bssid); |
| 903 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
| 904 | ieee80211_sta_send_apinfo(sdata); |
| 905 | ieee80211_rx_bss_remove(sdata, ifmgd->bssid, |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 906 | sdata->local->hw.conf.channel->center_freq, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 907 | ifmgd->ssid, ifmgd->ssid_len); |
Helmut Schaa | 1143237 | 2009-03-12 14:04:34 +0100 | [diff] [blame] | 908 | /* |
| 909 | * We might have a pending scan which had no chance to run yet |
| 910 | * due to state == IEEE80211_STA_MLME_ASSOCIATE. |
| 911 | * Hence, queue the STAs work again |
| 912 | */ |
| 913 | queue_work(local->hw.workqueue, &ifmgd->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 914 | return; |
| 915 | } |
| 916 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 917 | ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 918 | printk(KERN_DEBUG "%s: associate with AP %pM\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 919 | sdata->dev->name, ifmgd->bssid); |
| 920 | if (ieee80211_privacy_mismatch(sdata)) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 921 | printk(KERN_DEBUG "%s: mismatch in privacy configuration and " |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 922 | "mixed-cell disabled - abort association\n", sdata->dev->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 923 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 927 | ieee80211_send_assoc(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 928 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 929 | mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 930 | } |
| 931 | |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 932 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 933 | struct ieee80211_hdr *hdr) |
| 934 | { |
| 935 | /* |
| 936 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 937 | * from AP because we know that the connection is working both ways |
| 938 | * at that time. But multicast frames (and hence also beacons) must |
| 939 | * be ignored here, because we need to trigger the timer during |
| 940 | * data idle periods for sending the periodical probe request to |
| 941 | * the AP. |
| 942 | */ |
| 943 | if (!is_multicast_ether_addr(hdr->addr1)) |
| 944 | mod_timer(&sdata->u.mgd.timer, |
| 945 | jiffies + IEEE80211_MONITORING_INTERVAL); |
| 946 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 947 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 948 | void ieee80211_beacon_loss_work(struct work_struct *work) |
| 949 | { |
| 950 | struct ieee80211_sub_if_data *sdata = |
| 951 | container_of(work, struct ieee80211_sub_if_data, |
| 952 | u.mgd.beacon_loss_work); |
| 953 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 954 | |
Michael Buesch | a860402 | 2009-04-15 14:41:22 -0400 | [diff] [blame] | 955 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 956 | if (net_ratelimit()) { |
| 957 | printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM " |
| 958 | "- sending probe request\n", sdata->dev->name, |
| 959 | sdata->u.mgd.bssid); |
| 960 | } |
| 961 | #endif |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 962 | |
| 963 | ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; |
| 964 | ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, |
| 965 | ifmgd->ssid_len, NULL, 0); |
| 966 | |
| 967 | mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL); |
| 968 | } |
| 969 | |
| 970 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 971 | { |
| 972 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 973 | |
| 974 | queue_work(sdata->local->hw.workqueue, |
| 975 | &sdata->u.mgd.beacon_loss_work); |
| 976 | } |
| 977 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 978 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 979 | static void ieee80211_associated(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 980 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 981 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 982 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 983 | struct sta_info *sta; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 984 | bool disassoc = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 985 | |
| 986 | /* TODO: start monitoring current AP signal quality and number of |
| 987 | * missed beacons. Scan other channels every now and then and search |
| 988 | * for better APs. */ |
| 989 | /* TODO: remove expired BSSes */ |
| 990 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 991 | ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 992 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 993 | rcu_read_lock(); |
| 994 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 995 | sta = sta_info_get(local, ifmgd->bssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 996 | if (!sta) { |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 997 | printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n", |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 998 | sdata->dev->name, ifmgd->bssid); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 999 | disassoc = true; |
| 1000 | goto unlock; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1001 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1002 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1003 | if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) && |
| 1004 | time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { |
| 1005 | printk(KERN_DEBUG "%s: no probe response from AP %pM " |
| 1006 | "- disassociating\n", |
| 1007 | sdata->dev->name, ifmgd->bssid); |
| 1008 | disassoc = true; |
| 1009 | ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
| 1010 | goto unlock; |
| 1011 | } |
| 1012 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1013 | /* |
| 1014 | * Beacon filtering is only enabled with power save and then the |
| 1015 | * stack should not check for beacon loss. |
| 1016 | */ |
| 1017 | if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) && |
| 1018 | (local->hw.conf.flags & IEEE80211_CONF_PS)) && |
| 1019 | time_after(jiffies, |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1020 | ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) { |
Michael Buesch | a860402 | 2009-04-15 14:41:22 -0400 | [diff] [blame] | 1021 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 1022 | if (net_ratelimit()) { |
| 1023 | printk(KERN_DEBUG "%s: beacon loss from AP %pM " |
| 1024 | "- sending probe request\n", |
| 1025 | sdata->dev->name, ifmgd->bssid); |
| 1026 | } |
| 1027 | #endif |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1028 | ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; |
| 1029 | ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, |
| 1030 | ifmgd->ssid_len, NULL, 0); |
| 1031 | goto unlock; |
| 1032 | |
| 1033 | } |
| 1034 | |
| 1035 | if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) { |
| 1036 | ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; |
| 1037 | ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, |
| 1038 | ifmgd->ssid_len, NULL, 0); |
| 1039 | } |
| 1040 | |
| 1041 | unlock: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1042 | rcu_read_unlock(); |
| 1043 | |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 1044 | if (disassoc) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1045 | ieee80211_set_disassoc(sdata, true, true, |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1046 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 1047 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1048 | mod_timer(&ifmgd->timer, jiffies + |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1049 | IEEE80211_MONITORING_INTERVAL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1053 | static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1054 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1055 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1056 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1057 | printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1058 | ifmgd->flags |= IEEE80211_STA_AUTHENTICATED; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1059 | if (ifmgd->flags & IEEE80211_STA_EXT_SME) { |
| 1060 | /* Wait for SME to request association */ |
| 1061 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
| 1062 | } else |
| 1063 | ieee80211_associate(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1067 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1068 | struct ieee80211_mgmt *mgmt, |
| 1069 | size_t len) |
| 1070 | { |
| 1071 | u8 *pos; |
| 1072 | struct ieee802_11_elems elems; |
| 1073 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1074 | pos = mgmt->u.auth.variable; |
John W. Linville | 67a4cce | 2007-10-12 16:40:37 -0400 | [diff] [blame] | 1075 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1076 | if (!elems.challenge) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1077 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1078 | ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg, |
| 1079 | elems.challenge - 2, elems.challenge_len + 2, |
| 1080 | sdata->u.mgd.bssid, 1); |
| 1081 | sdata->u.mgd.auth_transaction = 4; |
Johannes Berg | fe3d2c3 | 2009-02-10 21:26:03 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1084 | static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1085 | struct ieee80211_mgmt *mgmt, |
| 1086 | size_t len) |
| 1087 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1088 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1089 | u16 auth_alg, auth_transaction, status_code; |
| 1090 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1091 | if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1092 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1093 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1094 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1095 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1096 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1097 | if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1098 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1099 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1100 | if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) |
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 | |
| 1103 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 1104 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 1105 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 1106 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1107 | if (auth_alg != ifmgd->auth_alg || |
| 1108 | auth_transaction != ifmgd->auth_transaction) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1109 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1110 | |
| 1111 | if (status_code != WLAN_STATUS_SUCCESS) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1112 | if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { |
| 1113 | u8 algs[3]; |
| 1114 | const int num_algs = ARRAY_SIZE(algs); |
| 1115 | int i, pos; |
| 1116 | algs[0] = algs[1] = algs[2] = 0xff; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1117 | if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1118 | algs[0] = WLAN_AUTH_OPEN; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1119 | if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1120 | algs[1] = WLAN_AUTH_SHARED_KEY; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1121 | if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1122 | algs[2] = WLAN_AUTH_LEAP; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1123 | if (ifmgd->auth_alg == WLAN_AUTH_OPEN) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1124 | pos = 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1125 | else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1126 | pos = 1; |
| 1127 | else |
| 1128 | pos = 2; |
| 1129 | for (i = 0; i < num_algs; i++) { |
| 1130 | pos++; |
| 1131 | if (pos >= num_algs) |
| 1132 | pos = 0; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1133 | if (algs[pos] == ifmgd->auth_alg || |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1134 | algs[pos] == 0xff) |
| 1135 | continue; |
| 1136 | if (algs[pos] == WLAN_AUTH_SHARED_KEY && |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1137 | !ieee80211_sta_wep_configured(sdata)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1138 | continue; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1139 | ifmgd->auth_alg = algs[pos]; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1140 | break; |
| 1141 | } |
| 1142 | } |
| 1143 | return; |
| 1144 | } |
| 1145 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1146 | switch (ifmgd->auth_alg) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1147 | case WLAN_AUTH_OPEN: |
| 1148 | case WLAN_AUTH_LEAP: |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1149 | case WLAN_AUTH_FT: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1150 | ieee80211_auth_completed(sdata); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1151 | cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1152 | break; |
| 1153 | case WLAN_AUTH_SHARED_KEY: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1154 | if (ifmgd->auth_transaction == 4) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1155 | ieee80211_auth_completed(sdata); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1156 | cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); |
| 1157 | } else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1158 | ieee80211_auth_challenge(sdata, mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1164 | static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1165 | struct ieee80211_mgmt *mgmt, |
| 1166 | size_t len) |
| 1167 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1168 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1169 | u16 reason_code; |
| 1170 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1171 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1172 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1173 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1174 | if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1175 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1176 | |
| 1177 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1178 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1179 | if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED) |
Zhu Yi | 97c8b01 | 2008-10-28 15:58:31 +0800 | [diff] [blame] | 1180 | printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n", |
| 1181 | sdata->dev->name, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1182 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1183 | if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && |
| 1184 | (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE || |
| 1185 | ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE || |
| 1186 | ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1187 | ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 1188 | mod_timer(&ifmgd->timer, jiffies + |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1189 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1190 | } |
| 1191 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1192 | ieee80211_set_disassoc(sdata, true, false, 0); |
| 1193 | ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED; |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame^] | 1194 | cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1198 | static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1199 | struct ieee80211_mgmt *mgmt, |
| 1200 | size_t len) |
| 1201 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1202 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1203 | u16 reason_code; |
| 1204 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1205 | if (len < 24 + 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1206 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1207 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1208 | if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1209 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1210 | |
| 1211 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 1212 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1213 | if (ifmgd->flags & IEEE80211_STA_ASSOCIATED) |
Zhu Yi | 97c8b01 | 2008-10-28 15:58:31 +0800 | [diff] [blame] | 1214 | printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n", |
| 1215 | sdata->dev->name, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1216 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1217 | if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && |
| 1218 | ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1219 | ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; |
| 1220 | mod_timer(&ifmgd->timer, jiffies + |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1221 | IEEE80211_RETRY_AUTH_INTERVAL); |
| 1222 | } |
| 1223 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1224 | ieee80211_set_disassoc(sdata, false, false, reason_code); |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame^] | 1225 | cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1229 | 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] | 1230 | struct ieee80211_mgmt *mgmt, |
| 1231 | size_t len, |
| 1232 | int reassoc) |
| 1233 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1234 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1235 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1236 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1237 | struct sta_info *sta; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 1238 | u32 rates, basic_rates; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1239 | u16 capab_info, status_code, aid; |
| 1240 | struct ieee802_11_elems elems; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1241 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1242 | u8 *pos; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1243 | u32 changed = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1244 | int i, j; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1245 | bool have_higher_than_11mbit = false, newsta = false; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1246 | u16 ap_ht_cap_flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* AssocResp and ReassocResp have identical structure, so process both |
| 1249 | * of them in this function. */ |
| 1250 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1251 | if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1252 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1253 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1254 | if (len < 24 + 6) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1255 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1256 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1257 | if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1258 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1259 | |
| 1260 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 1261 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 1262 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1263 | |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1264 | printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x " |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1265 | "status=%d aid=%d)\n", |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1266 | sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa, |
Johannes Berg | ddd6858 | 2007-10-22 14:51:37 +0200 | [diff] [blame] | 1267 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1268 | |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 1269 | pos = mgmt->u.assoc_resp.variable; |
| 1270 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 1271 | |
| 1272 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
Jouni Malinen | f797eb7 | 2009-01-19 18:48:46 +0200 | [diff] [blame] | 1273 | elems.timeout_int && elems.timeout_int_len == 5 && |
| 1274 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 1275 | u32 tu, ms; |
Jouni Malinen | f797eb7 | 2009-01-19 18:48:46 +0200 | [diff] [blame] | 1276 | tu = get_unaligned_le32(elems.timeout_int + 1); |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 1277 | ms = tu * 1024 / 1000; |
| 1278 | printk(KERN_DEBUG "%s: AP rejected association temporarily; " |
| 1279 | "comeback duration %u TU (%u ms)\n", |
| 1280 | sdata->dev->name, tu, ms); |
| 1281 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1282 | mod_timer(&ifmgd->timer, |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 1283 | jiffies + msecs_to_jiffies(ms)); |
| 1284 | return; |
| 1285 | } |
| 1286 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1287 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 1288 | printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1289 | sdata->dev->name, status_code); |
Daniel Drake | 8a69aa9 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1290 | /* if this was a reassociation, ensure we try a "full" |
| 1291 | * association next time. This works around some broken APs |
| 1292 | * which do not correctly reject reassociation requests. */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1293 | ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1297 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 1298 | 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] | 1299 | "set\n", sdata->dev->name, aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1300 | aid &= ~(BIT(15) | BIT(14)); |
| 1301 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1302 | if (!elems.supp_rates) { |
| 1303 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1304 | sdata->dev->name); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1305 | return; |
| 1306 | } |
| 1307 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1308 | printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1309 | ifmgd->aid = aid; |
| 1310 | ifmgd->ap_capab = capab_info; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1311 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1312 | kfree(ifmgd->assocresp_ies); |
| 1313 | ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt); |
| 1314 | ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL); |
| 1315 | if (ifmgd->assocresp_ies) |
| 1316 | memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1317 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1318 | rcu_read_lock(); |
| 1319 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1320 | /* Add STA entry for the AP */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1321 | sta = sta_info_get(local, ifmgd->bssid); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1322 | if (!sta) { |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1323 | newsta = true; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1324 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1325 | sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1326 | if (!sta) { |
| 1327 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1328 | " the AP\n", sdata->dev->name); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1329 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1330 | return; |
| 1331 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1332 | |
Ron Rindjunsky | a61dae1 | 2008-08-10 00:54:34 +0300 | [diff] [blame] | 1333 | /* update new sta with its last rx activity */ |
| 1334 | sta->last_rx = jiffies; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1337 | /* |
| 1338 | * FIXME: Do we really need to update the sta_info's information here? |
| 1339 | * We already know about the AP (we found it in our list) so it |
| 1340 | * should already be filled with the right info, no? |
| 1341 | * As is stands, all this is racy because typically we assume |
| 1342 | * the information that is filled in here (except flags) doesn't |
| 1343 | * change while a STA structure is alive. As such, it should move |
| 1344 | * to between the sta_info_alloc() and sta_info_insert() above. |
| 1345 | */ |
| 1346 | |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1347 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | |
| 1348 | WLAN_STA_AUTHORIZED); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1349 | |
| 1350 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1351 | basic_rates = 0; |
| 1352 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1353 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1354 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 1355 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1356 | bool is_basic = !!(elems.supp_rates[i] & 0x80); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1357 | |
| 1358 | if (rate > 110) |
| 1359 | have_higher_than_11mbit = true; |
| 1360 | |
| 1361 | for (j = 0; j < sband->n_bitrates; j++) { |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1362 | if (sband->bitrates[j].bitrate == rate) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1363 | rates |= BIT(j); |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1364 | if (is_basic) |
| 1365 | basic_rates |= BIT(j); |
| 1366 | break; |
| 1367 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1368 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1369 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1370 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1371 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 1372 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 7e0986c | 2009-04-19 13:22:11 +0200 | [diff] [blame] | 1373 | bool is_basic = !!(elems.ext_supp_rates[i] & 0x80); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1374 | |
| 1375 | if (rate > 110) |
| 1376 | have_higher_than_11mbit = true; |
| 1377 | |
| 1378 | for (j = 0; j < sband->n_bitrates; j++) { |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1379 | if (sband->bitrates[j].bitrate == rate) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1380 | rates |= BIT(j); |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1381 | if (is_basic) |
| 1382 | basic_rates |= BIT(j); |
| 1383 | break; |
| 1384 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1385 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1386 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1387 | |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 1388 | sta->sta.supp_rates[local->hw.conf.channel->band] = rates; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1389 | sdata->vif.bss_conf.basic_rates = basic_rates; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1390 | |
| 1391 | /* cf. IEEE 802.11 9.2.12 */ |
| 1392 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 1393 | have_higher_than_11mbit) |
| 1394 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 1395 | else |
| 1396 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1397 | |
Sujith | e65c226 | 2009-03-02 13:28:31 +0530 | [diff] [blame] | 1398 | /* If TKIP/WEP is used, no need to parse AP's HT capabilities */ |
| 1399 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1400 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 1401 | elems.ht_cap_elem, &sta->sta.ht_cap); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1402 | |
| 1403 | ap_ht_cap_flags = sta->sta.ht_cap.cap; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1404 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1405 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1406 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1407 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 1408 | set_sta_flags(sta, WLAN_STA_MFP); |
| 1409 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1410 | if (elems.wmm_param) |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1411 | set_sta_flags(sta, WLAN_STA_WME); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1412 | |
| 1413 | if (newsta) { |
| 1414 | int err = sta_info_insert(sta); |
| 1415 | if (err) { |
| 1416 | printk(KERN_DEBUG "%s: failed to insert STA entry for" |
| 1417 | " the AP (error %d)\n", sdata->dev->name, err); |
| 1418 | rcu_read_unlock(); |
| 1419 | return; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | rcu_read_unlock(); |
| 1424 | |
| 1425 | if (elems.wmm_param) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1426 | ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1427 | elems.wmm_param_len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1428 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1429 | if (elems.ht_info_elem && elems.wmm_param && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1430 | (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && |
| 1431 | !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1432 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
| 1433 | ap_ht_cap_flags); |
| 1434 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1435 | /* set AID and assoc capability, |
| 1436 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1437 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1438 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1439 | ieee80211_set_associated(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1440 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1441 | /* |
| 1442 | * initialise the time of last beacon to be the association time, |
| 1443 | * otherwise beacon loss check will trigger immediately |
| 1444 | */ |
| 1445 | ifmgd->last_beacon = jiffies; |
| 1446 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1447 | ieee80211_associated(sdata); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 1448 | cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1452 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1453 | struct ieee80211_mgmt *mgmt, |
| 1454 | size_t len, |
| 1455 | struct ieee80211_rx_status *rx_status, |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1456 | struct ieee802_11_elems *elems, |
| 1457 | bool beacon) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1458 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1459 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1460 | int freq; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 1461 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 1462 | struct ieee80211_channel *channel; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1463 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 1464 | if (elems->ds_params && elems->ds_params_len == 1) |
| 1465 | freq = ieee80211_channel_to_frequency(elems->ds_params[0]); |
| 1466 | else |
| 1467 | freq = rx_status->freq; |
| 1468 | |
| 1469 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 1470 | |
| 1471 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 1472 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1473 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1474 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1475 | channel, beacon); |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1476 | if (!bss) |
| 1477 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1478 | |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1479 | if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1480 | (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) { |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1481 | struct ieee80211_channel_sw_ie *sw_elem = |
| 1482 | (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; |
| 1483 | ieee80211_process_chanswitch(sdata, sw_elem, bss); |
| 1484 | } |
| 1485 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 1486 | ieee80211_rx_bss_put(local, bss); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1490 | 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] | 1491 | struct ieee80211_mgmt *mgmt, |
| 1492 | size_t len, |
| 1493 | struct ieee80211_rx_status *rx_status) |
| 1494 | { |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1495 | struct ieee80211_if_managed *ifmgd; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1496 | size_t baselen; |
| 1497 | struct ieee802_11_elems elems; |
| 1498 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1499 | ifmgd = &sdata->u.mgd; |
| 1500 | |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 1501 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
| 1502 | return; /* ignore ProbeResp to foreign address */ |
| 1503 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1504 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 1505 | if (baselen > len) |
| 1506 | return; |
| 1507 | |
| 1508 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 1509 | &elems); |
| 1510 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1511 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1512 | |
| 1513 | /* direct probe may be part of the association flow */ |
| 1514 | if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1515 | &ifmgd->request)) { |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1516 | printk(KERN_DEBUG "%s direct probe responded\n", |
| 1517 | sdata->dev->name); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1518 | ieee80211_authenticate(sdata); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1519 | } |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1520 | |
| 1521 | if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) |
| 1522 | ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1525 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1526 | struct ieee80211_mgmt *mgmt, |
| 1527 | size_t len, |
| 1528 | struct ieee80211_rx_status *rx_status) |
| 1529 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1530 | struct ieee80211_if_managed *ifmgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1531 | size_t baselen; |
| 1532 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1533 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1534 | u32 changed = 0; |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 1535 | bool erp_valid, directed_tim; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1536 | u8 erp_value = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1537 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1538 | /* Process beacon from the current BSS */ |
| 1539 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1540 | if (baselen > len) |
| 1541 | return; |
| 1542 | |
| 1543 | ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); |
| 1544 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1545 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1546 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1547 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1548 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1549 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1550 | ifmgd = &sdata->u.mgd; |
| 1551 | |
| 1552 | if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || |
| 1553 | memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1554 | return; |
| 1555 | |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1556 | if (rx_status->freq != local->hw.conf.channel->center_freq) |
| 1557 | return; |
| 1558 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1559 | ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, |
Johannes Berg | fe3fa82 | 2008-09-08 11:05:09 +0200 | [diff] [blame] | 1560 | elems.wmm_param_len); |
| 1561 | |
Vivek Natarajan | 25c9c87 | 2009-03-02 20:20:30 +0530 | [diff] [blame] | 1562 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1563 | directed_tim = ieee80211_check_tim(&elems, ifmgd->aid); |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 1564 | |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 1565 | if (directed_tim) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1566 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 1567 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1568 | ieee80211_hw_config(local, |
| 1569 | IEEE80211_CONF_CHANGE_PS); |
| 1570 | ieee80211_send_nullfunc(local, sdata, 0); |
| 1571 | } else { |
| 1572 | local->pspolling = true; |
| 1573 | |
| 1574 | /* |
| 1575 | * Here is assumed that the driver will be |
| 1576 | * able to send ps-poll frame and receive a |
| 1577 | * response even though power save mode is |
| 1578 | * enabled, but some drivers might require |
| 1579 | * to disable power save here. This needs |
| 1580 | * to be investigated. |
| 1581 | */ |
| 1582 | ieee80211_send_pspoll(local, sdata); |
| 1583 | } |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 1584 | } |
| 1585 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1586 | |
| 1587 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 1588 | erp_valid = true; |
| 1589 | erp_value = elems.erp_info[0]; |
| 1590 | } else { |
| 1591 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 1592 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1593 | changed |= ieee80211_handle_bss_capability(sdata, |
| 1594 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 1595 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1596 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1597 | |
Vasanthakumar Thiagarajan | 53d6f81c | 2009-02-11 22:18:49 +0530 | [diff] [blame] | 1598 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1599 | !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1600 | struct sta_info *sta; |
| 1601 | struct ieee80211_supported_band *sband; |
| 1602 | u16 ap_ht_cap_flags; |
| 1603 | |
| 1604 | rcu_read_lock(); |
| 1605 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1606 | sta = sta_info_get(local, ifmgd->bssid); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1607 | if (!sta) { |
| 1608 | rcu_read_unlock(); |
| 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1613 | |
| 1614 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
| 1615 | elems.ht_cap_elem, &sta->sta.ht_cap); |
| 1616 | |
| 1617 | ap_ht_cap_flags = sta->sta.ht_cap.cap; |
| 1618 | |
| 1619 | rcu_read_unlock(); |
| 1620 | |
| 1621 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
| 1622 | ap_ht_cap_flags); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1623 | } |
| 1624 | |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1625 | if (elems.country_elem) { |
| 1626 | /* Note we are only reviewing this on beacons |
| 1627 | * for the BSSID we are associated to */ |
| 1628 | regulatory_hint_11d(local->hw.wiphy, |
| 1629 | elems.country_elem, elems.country_elem_len); |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 1630 | |
| 1631 | /* TODO: IBSS also needs this */ |
| 1632 | if (elems.pwr_constr_elem) |
| 1633 | ieee80211_handle_pwr_constr(sdata, |
| 1634 | le16_to_cpu(mgmt->u.probe_resp.capab_info), |
| 1635 | elems.pwr_constr_elem, |
| 1636 | elems.pwr_constr_elem_len); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1639 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1642 | ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, |
| 1643 | struct sk_buff *skb, |
| 1644 | struct ieee80211_rx_status *rx_status) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1645 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1646 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1647 | struct ieee80211_mgmt *mgmt; |
| 1648 | u16 fc; |
| 1649 | |
| 1650 | if (skb->len < 24) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1651 | return RX_DROP_MONITOR; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1652 | |
| 1653 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1654 | fc = le16_to_cpu(mgmt->frame_control); |
| 1655 | |
| 1656 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1657 | case IEEE80211_STYPE_PROBE_REQ: |
| 1658 | case IEEE80211_STYPE_PROBE_RESP: |
| 1659 | case IEEE80211_STYPE_BEACON: |
| 1660 | memcpy(skb->cb, rx_status, sizeof(*rx_status)); |
| 1661 | case IEEE80211_STYPE_AUTH: |
| 1662 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1663 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1664 | case IEEE80211_STYPE_DEAUTH: |
| 1665 | case IEEE80211_STYPE_DISASSOC: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1666 | skb_queue_tail(&sdata->u.mgd.skb_queue, skb); |
| 1667 | queue_work(local->hw.workqueue, &sdata->u.mgd.work); |
| 1668 | return RX_QUEUED; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1671 | return RX_DROP_MONITOR; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1674 | 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] | 1675 | struct sk_buff *skb) |
| 1676 | { |
| 1677 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1678 | struct ieee80211_mgmt *mgmt; |
| 1679 | u16 fc; |
| 1680 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1681 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 1682 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1683 | fc = le16_to_cpu(mgmt->frame_control); |
| 1684 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1685 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1686 | case IEEE80211_STYPE_PROBE_RESP: |
| 1687 | ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, |
| 1688 | rx_status); |
| 1689 | break; |
| 1690 | case IEEE80211_STYPE_BEACON: |
| 1691 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, |
| 1692 | rx_status); |
| 1693 | break; |
| 1694 | case IEEE80211_STYPE_AUTH: |
| 1695 | ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
| 1696 | break; |
| 1697 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1698 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0); |
| 1699 | break; |
| 1700 | case IEEE80211_STYPE_REASSOC_RESP: |
| 1701 | ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1); |
| 1702 | break; |
| 1703 | case IEEE80211_STYPE_DEAUTH: |
| 1704 | ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
| 1705 | break; |
| 1706 | case IEEE80211_STYPE_DISASSOC: |
| 1707 | ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
| 1708 | break; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | kfree_skb(skb); |
| 1712 | } |
| 1713 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1714 | static void ieee80211_sta_timer(unsigned long data) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1715 | { |
| 1716 | struct ieee80211_sub_if_data *sdata = |
| 1717 | (struct ieee80211_sub_if_data *) data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1718 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1719 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1720 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1721 | set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); |
| 1722 | queue_work(local->hw.workqueue, &ifmgd->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1725 | static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1726 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1727 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1728 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1729 | |
| 1730 | if (local->ops->reset_tsf) { |
| 1731 | /* Reset own TSF to allow time synchronization work. */ |
| 1732 | local->ops->reset_tsf(local_to_hw(local)); |
| 1733 | } |
| 1734 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1735 | ifmgd->wmm_last_param_set = -1; /* allow any WMM update */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1736 | |
| 1737 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1738 | if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN) |
| 1739 | ifmgd->auth_alg = WLAN_AUTH_OPEN; |
| 1740 | else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) |
| 1741 | ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 1742 | else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP) |
| 1743 | ifmgd->auth_alg = WLAN_AUTH_LEAP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1744 | else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT) |
| 1745 | ifmgd->auth_alg = WLAN_AUTH_FT; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1746 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1747 | ifmgd->auth_alg = WLAN_AUTH_OPEN; |
| 1748 | ifmgd->auth_transaction = -1; |
| 1749 | ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED; |
| 1750 | ifmgd->assoc_scan_tries = 0; |
| 1751 | ifmgd->direct_probe_tries = 0; |
| 1752 | ifmgd->auth_tries = 0; |
| 1753 | ifmgd->assoc_tries = 0; |
Tomas Winkler | 24e6462 | 2008-09-08 17:33:40 +0200 | [diff] [blame] | 1754 | netif_tx_stop_all_queues(sdata->dev); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1755 | netif_carrier_off(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1758 | static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1759 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1760 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1761 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 1762 | struct ieee80211_bss *bss; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1763 | u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid; |
| 1764 | u8 ssid_len = ifmgd->ssid_len; |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1765 | u16 capa_mask = WLAN_CAPABILITY_ESS; |
| 1766 | u16 capa_val = WLAN_CAPABILITY_ESS; |
| 1767 | struct ieee80211_channel *chan = local->oper_channel; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1768 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1769 | if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && |
| 1770 | ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1771 | IEEE80211_STA_AUTO_BSSID_SEL | |
| 1772 | IEEE80211_STA_AUTO_CHANNEL_SEL)) { |
| 1773 | capa_mask |= WLAN_CAPABILITY_PRIVACY; |
| 1774 | if (sdata->default_key) |
| 1775 | capa_val |= WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1776 | } |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1777 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1778 | if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1779 | chan = NULL; |
| 1780 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1781 | if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL) |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1782 | bssid = NULL; |
| 1783 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1784 | if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1785 | ssid = NULL; |
| 1786 | ssid_len = 0; |
| 1787 | } |
| 1788 | |
| 1789 | bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, |
| 1790 | bssid, ssid, ssid_len, |
| 1791 | capa_mask, capa_val); |
| 1792 | |
| 1793 | if (bss) { |
| 1794 | ieee80211_set_freq(sdata, bss->cbss.channel->center_freq); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1795 | if (!(ifmgd->flags & IEEE80211_STA_SSID_SET)) |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1796 | ieee80211_sta_set_ssid(sdata, bss->ssid, |
| 1797 | bss->ssid_len); |
| 1798 | ieee80211_sta_set_bssid(sdata, bss->cbss.bssid); |
| 1799 | ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len, |
| 1800 | bss->supp_rates); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1801 | if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED) |
| 1802 | sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED; |
Jouni Malinen | fdfacf0 | 2009-01-08 13:32:05 +0200 | [diff] [blame] | 1803 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1804 | sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1805 | |
| 1806 | /* Send out direct probe if no probe resp was received or |
| 1807 | * the one we have is outdated |
| 1808 | */ |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1809 | if (!bss->last_probe_resp || |
| 1810 | time_after(jiffies, bss->last_probe_resp |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1811 | + IEEE80211_SCAN_RESULT_EXPIRE)) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1812 | ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1813 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1814 | ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1815 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 1816 | ieee80211_rx_bss_put(local, bss); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1817 | ieee80211_sta_reset_auth(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1818 | return 0; |
| 1819 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1820 | if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { |
| 1821 | ifmgd->assoc_scan_tries++; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1822 | /* XXX maybe racy? */ |
| 1823 | if (local->scan_req) |
| 1824 | return -1; |
| 1825 | memcpy(local->int_scan_req.ssids[0].ssid, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1826 | ifmgd->ssid, IEEE80211_MAX_SSID_LEN); |
| 1827 | if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1828 | local->int_scan_req.ssids[0].ssid_len = 0; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1829 | else |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1830 | local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len; |
Helmut Schaa | af88b90 | 2009-03-09 15:47:08 +0100 | [diff] [blame] | 1831 | |
| 1832 | if (ieee80211_start_scan(sdata, &local->int_scan_req)) |
| 1833 | ieee80211_scan_failed(local); |
| 1834 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1835 | ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; |
| 1836 | set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); |
Sujith | e374055 | 2009-01-29 09:34:22 +0530 | [diff] [blame] | 1837 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1838 | ifmgd->assoc_scan_tries = 0; |
| 1839 | ifmgd->state = IEEE80211_STA_MLME_DISABLED; |
Sujith | e374055 | 2009-01-29 09:34:22 +0530 | [diff] [blame] | 1840 | } |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1841 | } |
| 1842 | return -1; |
| 1843 | } |
| 1844 | |
| 1845 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1846 | static void ieee80211_sta_work(struct work_struct *work) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1847 | { |
| 1848 | struct ieee80211_sub_if_data *sdata = |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1849 | container_of(work, struct ieee80211_sub_if_data, u.mgd.work); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1850 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1851 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1852 | struct sk_buff *skb; |
| 1853 | |
| 1854 | if (!netif_running(sdata->dev)) |
| 1855 | return; |
| 1856 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 1857 | if (local->sw_scanning || local->hw_scanning) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1858 | return; |
| 1859 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1860 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1861 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1862 | ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1863 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1864 | while ((skb = skb_dequeue(&ifmgd->skb_queue))) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1865 | ieee80211_sta_rx_queued_mgmt(sdata, skb); |
| 1866 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1867 | if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE && |
| 1868 | ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && |
| 1869 | ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && |
| 1870 | test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { |
Helmut Schaa | af88b90 | 2009-03-09 15:47:08 +0100 | [diff] [blame] | 1871 | /* |
| 1872 | * The call to ieee80211_start_scan can fail but ieee80211_request_scan |
| 1873 | * (which queued ieee80211_sta_work) did not return an error. Thus, call |
| 1874 | * ieee80211_scan_failed here if ieee80211_start_scan fails in order to |
| 1875 | * notify the scan requester. |
| 1876 | */ |
| 1877 | if (ieee80211_start_scan(sdata, local->scan_req)) |
| 1878 | ieee80211_scan_failed(local); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1879 | return; |
| 1880 | } |
| 1881 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1882 | if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) { |
| 1883 | if (ieee80211_sta_config_auth(sdata)) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1884 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1885 | clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); |
| 1886 | } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request)) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1887 | return; |
| 1888 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1889 | switch (ifmgd->state) { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1890 | case IEEE80211_STA_MLME_DISABLED: |
| 1891 | break; |
| 1892 | case IEEE80211_STA_MLME_DIRECT_PROBE: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1893 | ieee80211_direct_probe(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1894 | break; |
| 1895 | case IEEE80211_STA_MLME_AUTHENTICATE: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1896 | ieee80211_authenticate(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1897 | break; |
| 1898 | case IEEE80211_STA_MLME_ASSOCIATE: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1899 | ieee80211_associate(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1900 | break; |
| 1901 | case IEEE80211_STA_MLME_ASSOCIATED: |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1902 | ieee80211_associated(sdata); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1903 | break; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1904 | default: |
| 1905 | WARN_ON(1); |
| 1906 | break; |
| 1907 | } |
| 1908 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1909 | if (ieee80211_privacy_mismatch(sdata)) { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1910 | printk(KERN_DEBUG "%s: privacy configuration mismatch and " |
| 1911 | "mixed-cell disabled - disassociate\n", sdata->dev->name); |
| 1912 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1913 | ieee80211_set_disassoc(sdata, false, true, |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1914 | WLAN_REASON_UNSPECIFIED); |
| 1915 | } |
| 1916 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 1917 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 1918 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 1919 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 1920 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 1921 | /* |
| 1922 | * Need to update last_beacon to avoid beacon loss |
| 1923 | * test to trigger. |
| 1924 | */ |
| 1925 | sdata->u.mgd.last_beacon = jiffies; |
| 1926 | |
| 1927 | |
Johannes Berg | 7c95069 | 2008-09-11 00:01:48 +0200 | [diff] [blame] | 1928 | queue_work(sdata->local->hw.workqueue, |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1929 | &sdata->u.mgd.work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 1930 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 1931 | } |
| 1932 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1933 | /* interface setup */ |
| 1934 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 1935 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1936 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1937 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1938 | ifmgd = &sdata->u.mgd; |
| 1939 | INIT_WORK(&ifmgd->work, ieee80211_sta_work); |
| 1940 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1941 | INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1942 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1943 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1944 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1945 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1946 | skb_queue_head_init(&ifmgd->skb_queue); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1947 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1948 | ifmgd->capab = WLAN_CAPABILITY_ESS; |
| 1949 | ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1950 | IEEE80211_AUTH_ALG_SHARED_KEY; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1951 | ifmgd->flags |= IEEE80211_STA_CREATE_IBSS | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1952 | IEEE80211_STA_AUTO_BSSID_SEL | |
| 1953 | IEEE80211_STA_AUTO_CHANNEL_SEL; |
Johannes Berg | 176be72 | 2009-03-12 23:49:28 +0100 | [diff] [blame] | 1954 | if (sdata->local->hw.queues >= 4) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1955 | ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* configuration hooks */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1959 | void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1960 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1961 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1962 | struct ieee80211_local *local = sdata->local; |
| 1963 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1964 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1965 | return; |
| 1966 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1967 | if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1968 | IEEE80211_STA_AUTO_BSSID_SEL)) && |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1969 | (ifmgd->flags & (IEEE80211_STA_SSID_SET | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1970 | IEEE80211_STA_AUTO_SSID_SEL))) { |
| 1971 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1972 | if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) |
| 1973 | ieee80211_set_disassoc(sdata, true, true, |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1974 | WLAN_REASON_DEAUTH_LEAVING); |
| 1975 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1976 | if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) || |
| 1977 | ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) |
| 1978 | set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); |
| 1979 | else if (ifmgd->flags & IEEE80211_STA_EXT_SME) |
| 1980 | set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1981 | queue_work(local->hw.workqueue, &ifmgd->work); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | |
Alina Friedrichsen | 79f6440 | 2009-02-21 01:27:29 +0100 | [diff] [blame] | 1985 | int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata) |
| 1986 | { |
| 1987 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1988 | |
Alina Friedrichsen | 79f6440 | 2009-02-21 01:27:29 +0100 | [diff] [blame] | 1989 | if (ifmgd->ssid_len) |
| 1990 | ifmgd->flags |= IEEE80211_STA_SSID_SET; |
| 1991 | else |
| 1992 | ifmgd->flags &= ~IEEE80211_STA_SSID_SET; |
| 1993 | |
| 1994 | return 0; |
| 1995 | } |
| 1996 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1997 | int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) |
| 1998 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1999 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2000 | |
| 2001 | if (len > IEEE80211_MAX_SSID_LEN) |
| 2002 | return -EINVAL; |
| 2003 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2004 | ifmgd = &sdata->u.mgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2005 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2006 | if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) { |
Jouni Malinen | a299542 | 2009-03-19 13:39:20 +0200 | [diff] [blame] | 2007 | /* |
| 2008 | * Do not use reassociation if SSID is changed (different ESS). |
| 2009 | */ |
| 2010 | ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2011 | memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid)); |
| 2012 | memcpy(ifmgd->ssid, ssid, len); |
| 2013 | ifmgd->ssid_len = len; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2014 | } |
| 2015 | |
Alina Friedrichsen | 79f6440 | 2009-02-21 01:27:29 +0100 | [diff] [blame] | 2016 | return ieee80211_sta_commit(sdata); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) |
| 2020 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2021 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2022 | memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len); |
| 2023 | *len = ifmgd->ssid_len; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2024 | return 0; |
| 2025 | } |
| 2026 | |
| 2027 | int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) |
| 2028 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2029 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2030 | |
Alina Friedrichsen | dfe6701 | 2009-01-24 01:19:04 +0100 | [diff] [blame] | 2031 | if (is_valid_ether_addr(bssid)) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2032 | memcpy(ifmgd->bssid, bssid, ETH_ALEN); |
| 2033 | ifmgd->flags |= IEEE80211_STA_BSSID_SET; |
Alina Friedrichsen | dfe6701 | 2009-01-24 01:19:04 +0100 | [diff] [blame] | 2034 | } else { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2035 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 2036 | ifmgd->flags &= ~IEEE80211_STA_BSSID_SET; |
Alina Friedrichsen | dfe6701 | 2009-01-24 01:19:04 +0100 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | if (netif_running(sdata->dev)) { |
| 2040 | if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) { |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2041 | printk(KERN_DEBUG "%s: Failed to config new BSSID to " |
| 2042 | "the low-level driver\n", sdata->dev->name); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2043 | } |
| 2044 | } |
| 2045 | |
Alina Friedrichsen | 79f6440 | 2009-02-21 01:27:29 +0100 | [diff] [blame] | 2046 | return ieee80211_sta_commit(sdata); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2047 | } |
| 2048 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2049 | int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, |
| 2050 | const char *ie, size_t len) |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2051 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2052 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2053 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2054 | kfree(ifmgd->extra_ie); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2055 | if (len == 0) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2056 | ifmgd->extra_ie = NULL; |
| 2057 | ifmgd->extra_ie_len = 0; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2058 | return 0; |
| 2059 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2060 | ifmgd->extra_ie = kmalloc(len, GFP_KERNEL); |
| 2061 | if (!ifmgd->extra_ie) { |
| 2062 | ifmgd->extra_ie_len = 0; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2063 | return -ENOMEM; |
| 2064 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2065 | memcpy(ifmgd->extra_ie, ie, len); |
| 2066 | ifmgd->extra_ie_len = len; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) |
| 2071 | { |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2072 | printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", |
| 2073 | sdata->dev->name, reason); |
| 2074 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2075 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2076 | return -EINVAL; |
| 2077 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2078 | ieee80211_set_disassoc(sdata, true, true, reason); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2079 | return 0; |
| 2080 | } |
| 2081 | |
| 2082 | int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) |
| 2083 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2084 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2085 | |
| 2086 | printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", |
| 2087 | sdata->dev->name, reason); |
| 2088 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2089 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2090 | return -EINVAL; |
| 2091 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2092 | if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) |
| 2093 | return -ENOLINK; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2094 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2095 | ieee80211_set_disassoc(sdata, false, true, reason); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2100 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 2101 | { |
| 2102 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 2103 | |
| 2104 | /* Restart STA timers */ |
| 2105 | rcu_read_lock(); |
| 2106 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 2107 | ieee80211_restart_sta_timer(sdata); |
| 2108 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2109 | } |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2110 | |
| 2111 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 2112 | { |
| 2113 | struct ieee80211_local *local = |
| 2114 | container_of(work, struct ieee80211_local, |
| 2115 | dynamic_ps_disable_work); |
| 2116 | |
| 2117 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2118 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2119 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2120 | } |
| 2121 | |
| 2122 | ieee80211_wake_queues_by_reason(&local->hw, |
| 2123 | IEEE80211_QUEUE_STOP_REASON_PS); |
| 2124 | } |
| 2125 | |
| 2126 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 2127 | { |
| 2128 | struct ieee80211_local *local = |
| 2129 | container_of(work, struct ieee80211_local, |
| 2130 | dynamic_ps_enable_work); |
Johannes Berg | 7181d46 | 2009-04-15 21:33:15 +0200 | [diff] [blame] | 2131 | /* XXX: using scan_sdata is completely broken! */ |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 2132 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2133 | |
| 2134 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 2135 | return; |
| 2136 | |
Johannes Berg | 7181d46 | 2009-04-15 21:33:15 +0200 | [diff] [blame] | 2137 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata) |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 2138 | ieee80211_send_nullfunc(local, sdata, 1); |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2139 | |
Johannes Berg | 4be8c38 | 2009-01-07 18:28:20 +0100 | [diff] [blame] | 2140 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 2141 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2142 | } |
| 2143 | |
| 2144 | void ieee80211_dynamic_ps_timer(unsigned long data) |
| 2145 | { |
| 2146 | struct ieee80211_local *local = (void *) data; |
| 2147 | |
| 2148 | queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work); |
| 2149 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2150 | |
| 2151 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 2152 | struct ieee80211_sub_if_data *sdata, |
| 2153 | int powersave) |
| 2154 | { |
| 2155 | struct sk_buff *skb; |
| 2156 | struct ieee80211_hdr *nullfunc; |
| 2157 | __le16 fc; |
| 2158 | |
| 2159 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2160 | return; |
| 2161 | |
| 2162 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); |
| 2163 | if (!skb) { |
| 2164 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " |
| 2165 | "frame\n", sdata->dev->name); |
| 2166 | return; |
| 2167 | } |
| 2168 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 2169 | |
| 2170 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 2171 | memset(nullfunc, 0, 24); |
| 2172 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 2173 | IEEE80211_FCTL_TODS); |
| 2174 | if (powersave) |
| 2175 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 2176 | nullfunc->frame_control = fc; |
| 2177 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 2178 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); |
| 2179 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 2180 | |
| 2181 | ieee80211_tx_skb(sdata, skb, 0); |
| 2182 | } |