blob: 08db02c237c9045af0ea24116a00fd5e72e86040 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * 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 Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010019#include <linux/rtnetlink.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020021#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020022
Jiri Bencf0706e82007-05-05 11:45:53 -070023#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "rate.h"
25#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030027#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070028#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 Valo15b7b062009-03-22 21:57:14 +020033#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070034#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg5484e232008-09-08 17:44:27 +020036/* utils */
37static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +020038{
Johannes Berg5484e232008-09-08 17:44:27 +020039 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +020040}
41
Johannes Bergc2b13452008-09-11 00:01:55 +020042static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030043{
44 u8 *end, *pos;
45
Johannes Berg00d3f142009-02-10 21:26:00 +010046 pos = bss->cbss.information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030047 if (pos == NULL)
48 return NULL;
Johannes Berg00d3f142009-02-10 21:26:00 +010049 end = pos + bss->cbss.len_information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030050
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 Bergc2b13452008-09-11 00:01:55 +020062static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
Johannes Berg9ac19a92008-09-09 10:57:09 +020063 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010064 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +020065{
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 Berg9c6bd792008-09-11 00:01:52 +020083/* frame sending functions */
84
Johannes Berg46900292009-02-15 12:44:28 +010085static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +020086{
Johannes Berg46900292009-02-15 12:44:28 +010087 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +020088 struct ieee80211_local *local = sdata->local;
89 struct sk_buff *skb;
90 struct ieee80211_mgmt *mgmt;
Jouni Malinen65fc73a2009-03-20 21:21:16 +020091 u8 *pos, *ies, *ht_ie;
Johannes Berg9ac19a92008-09-09 10:57:09 +020092 int i, len, count, rates_len, supp_rates_len;
93 u16 capab;
Johannes Bergc2b13452008-09-11 00:01:55 +020094 struct ieee80211_bss *bss;
Johannes Berg9ac19a92008-09-09 10:57:09 +020095 int wmm = 0;
96 struct ieee80211_supported_band *sband;
Johannes Berg881d9482009-01-21 15:13:48 +010097 u32 rates = 0;
Johannes Berg9ac19a92008-09-09 10:57:09 +020098
99 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Johannes Berg46900292009-02-15 12:44:28 +0100100 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200101 ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200102 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 Berg46900292009-02-15 12:44:28 +0100111 capab = ifmgd->capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200112
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 Berg46900292009-02-15 12:44:28 +0100120 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200121 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100122 ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200123 if (bss) {
Johannes Berg00d3f142009-02-10 21:26:00 +0100124 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200125 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 Berg00d3f142009-02-10 21:26:00 +0100135 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg9ac19a92008-09-09 10:57:09 +0200136 (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 Berg46900292009-02-15 12:44:28 +0100147 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200148 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100149 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200150
Johannes Berg46900292009-02-15 12:44:28 +0100151 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200152 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 Berg46900292009-02-15 12:44:28 +0100158 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200159 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 Rosen13554122008-12-16 22:38:29 +0200165 mgmt->u.assoc_req.listen_interval =
Johannes Berg9ac19a92008-09-09 10:57:09 +0200166 cpu_to_le16(local->hw.conf.listen_interval);
167 }
168
169 /* SSID */
Johannes Berg46900292009-02-15 12:44:28 +0100170 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200171 *pos++ = WLAN_EID_SSID;
Johannes Berg46900292009-02-15 12:44:28 +0100172 *pos++ = ifmgd->ssid_len;
173 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200174
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 Berg46900292009-02-15 12:44:28 +0100228 if (ifmgd->extra_ie) {
229 pos = skb_put(skb, ifmgd->extra_ie_len);
230 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200231 }
232
Johannes Berg46900292009-02-15 12:44:28 +0100233 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200234 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 Thiagarajaneb469362008-12-23 21:30:50 +0530247 /*
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 Berg46900292009-02-15 12:44:28 +0100253 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200254 sband->ht_cap.ht_supported &&
255 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530256 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
Johannes Berg46900292009-02-15 12:44:28 +0100257 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200258 struct ieee80211_ht_info *ht_info =
259 (struct ieee80211_ht_info *)(ht_ie + 2);
260 u16 cap = sband->ht_cap.cap;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200261 __le16 tmp;
262 u32 flags = local->hw.conf.channel->flags;
263
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200264 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
265 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200266 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200267 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200268 cap &= ~IEEE80211_HT_CAP_SGI_40;
269 }
270 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200271 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200272 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200273 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200274 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 Bergd9fe60d2008-10-09 12:13:49 +0200287 *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 Berg9ac19a92008-09-09 10:57:09 +0200290 }
291
Johannes Berg46900292009-02-15 12:44:28 +0100292 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 Berg9ac19a92008-09-09 10:57:09 +0200297
Johannes Berge50db652008-09-09 15:07:09 +0200298 ieee80211_tx_skb(sdata, skb, 0);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200299}
300
301
Johannes Bergef422bc2008-09-09 10:58:25 +0200302static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
303 u16 stype, u16 reason)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200304{
305 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100306 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200307 struct sk_buff *skb;
308 struct ieee80211_mgmt *mgmt;
309
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200310 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200311 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200312 printk(KERN_DEBUG "%s: failed to allocate buffer for "
313 "deauth/disassoc frame\n", sdata->dev->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200314 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 Berg46900292009-02-15 12:44:28 +0100320 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200321 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100322 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200323 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200324 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200325 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200326 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
327
Jouni Malinen53b46b82009-03-27 20:53:56 +0200328 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 Berg46900292009-02-15 12:44:28 +0100332 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200333}
334
Kalle Valo572e0012009-02-10 17:09:31 +0200335void ieee80211_send_pspoll(struct ieee80211_local *local,
336 struct ieee80211_sub_if_data *sdata)
337{
Johannes Berg46900292009-02-15 12:44:28 +0100338 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Kalle Valo572e0012009-02-10 17:09:31 +0200339 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 Berg46900292009-02-15 12:44:28 +0100355 pspoll->aid = cpu_to_le16(ifmgd->aid);
Kalle Valo572e0012009-02-10 17:09:31 +0200356
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 Berg46900292009-02-15 12:44:28 +0100360 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
Kalle Valo572e0012009-02-10 17:09:31 +0200361 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
362
363 ieee80211_tx_skb(sdata, skb, 0);
Kalle Valo572e0012009-02-10 17:09:31 +0200364}
365
Johannes Berg60f8b392008-09-08 17:44:22 +0200366/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200367static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100368 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700369 u8 *wmm_param, size_t wmm_param_len)
370{
Jiri Bencf0706e82007-05-05 11:45:53 -0700371 struct ieee80211_tx_queue_params params;
372 size_t left;
373 int count;
374 u8 *pos;
375
Johannes Berg46900292009-02-15 12:44:28 +0100376 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200377 return;
378
379 if (!wmm_param)
380 return;
381
Jiri Bencf0706e82007-05-05 11:45:53 -0700382 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
383 return;
384 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100385 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700386 return;
Johannes Berg46900292009-02-15 12:44:28 +0100387 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700388
389 pos = wmm_param + 8;
390 left = wmm_param_len - 8;
391
392 memset(&params, 0, sizeof(params));
393
Jiri Bencf0706e82007-05-05 11:45:53 -0700394 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 Malinen0eeb59f2009-03-05 17:23:46 +0200401 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200402 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200403 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200404 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700405 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200406 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200407 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200408 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200409 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700410 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200411 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200412 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200413 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200414 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700415 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200416 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700417 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200418 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200419 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200420 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700421 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 Bergf434b2d2008-07-10 11:22:31 +0200427 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200428#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700429 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100430 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200431 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100432 params.cw_max, params.txop);
433#endif
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200434 if (local->ops->conf_tx &&
435 local->ops->conf_tx(local_to_hw(local), queue, &params)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700436 printk(KERN_DEBUG "%s: failed to set TX queue "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200437 "parameters for queue %d\n", local->mdev->name, queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700438 }
439 }
440}
441
Kalle Valo1fb36062009-02-10 17:09:24 +0200442static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800443{
444 u8 mask;
445 u8 index, indexn1, indexn2;
446 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
447
Johannes Berg60375542009-04-17 00:54:23 +0200448 if (unlikely(!tim || elems->tim_len < 4))
449 return false;
450
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800451 aid &= 0x3fff;
452 index = aid / 8;
453 mask = 1 << (aid & 7);
454
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800455 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 Berg7a5158e2008-10-08 10:59:33 +0200466static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
467 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200468{
Johannes Bergbda39332008-10-11 01:51:51 +0200469 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300470#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg46900292009-02-15 12:44:28 +0100471 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winklerebd74482008-07-01 10:44:50 +0300472#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100473 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200474 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 Drake56282212007-07-10 19:32:10 +0200487
Johannes Berg471b3ef2007-12-28 14:32:58 +0100488 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200489#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200490 if (net_ratelimit()) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700491 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100492 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200493 use_protection ? "enabled" : "disabled",
Johannes Berg46900292009-02-15 12:44:28 +0100494 ifmgd->bssid);
Daniel Drake56282212007-07-10 19:32:10 +0200495 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200496#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100497 bss_conf->use_cts_prot = use_protection;
498 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200499 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200500
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200501 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200502#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200503 if (net_ratelimit()) {
504 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Johannes Berg0c68ae262008-10-27 15:56:10 -0700505 " (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100506 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200507 use_short_preamble ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100508 ifmgd->bssid);
Daniel Drake7e9ed182007-07-27 15:43:24 +0200509 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200510#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200511 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100512 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200513 }
Daniel Draked9430a32007-07-27 15:43:24 +0200514
Johannes Berg7a5158e2008-10-08 10:59:33 +0200515 if (use_short_slot != bss_conf->use_short_slot) {
516#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
517 if (net_ratelimit()) {
Christian Lamparter391429c2009-01-18 02:24:15 +0100518 printk(KERN_DEBUG "%s: switched to %s slot time"
519 " (BSSID=%pM)\n",
Johannes Berg7a5158e2008-10-08 10:59:33 +0200520 sdata->dev->name,
521 use_short_slot ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100522 ifmgd->bssid);
Johannes Berg7a5158e2008-10-08 10:59:33 +0200523 }
524#endif
525 bss_conf->use_short_slot = use_short_slot;
526 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400527 }
528
529 return changed;
530}
531
Johannes Berg46900292009-02-15 12:44:28 +0100532static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200533{
534 union iwreq_data wrqu;
Johannes Berg46900292009-02-15 12:44:28 +0100535
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200536 memset(&wrqu, 0, sizeof(wrqu));
Johannes Berg46900292009-02-15 12:44:28 +0100537 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
538 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200539 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
540 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
541}
542
Johannes Berg46900292009-02-15 12:44:28 +0100543static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700544{
Johannes Berg46900292009-02-15 12:44:28 +0100545 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Linus Torvalds74af0252008-09-05 12:38:09 -0700546 char *buf;
547 size_t len;
548 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700549 union iwreq_data wrqu;
550
Johannes Berg46900292009-02-15 12:44:28 +0100551 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700552 return;
553
Johannes Berg46900292009-02-15 12:44:28 +0100554 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
555 ifmgd->assocresp_ies_len), GFP_KERNEL);
Linus Torvalds74af0252008-09-05 12:38:09 -0700556 if (!buf)
557 return;
558
559 len = sprintf(buf, "ASSOCINFO(");
Johannes Berg46900292009-02-15 12:44:28 +0100560 if (ifmgd->assocreq_ies) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700561 len += sprintf(buf + len, "ReqIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100562 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700563 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100564 ifmgd->assocreq_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700565 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700566 }
Johannes Berg46900292009-02-15 12:44:28 +0100567 if (ifmgd->assocresp_ies) {
568 if (ifmgd->assocreq_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700569 len += sprintf(buf + len, " ");
570 len += sprintf(buf + len, "RespIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100571 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700572 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100573 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700574 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700575 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700576 len += sprintf(buf + len, ")");
577
578 if (len > IW_CUSTOM_MAX) {
579 len = sprintf(buf, "ASSOCRESPIE=");
Johannes Berg46900292009-02-15 12:44:28 +0100580 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700581 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100582 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700583 }
584 }
585
John W. Linvillead788b52008-10-01 15:45:02 -0400586 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 Torvalds74af0252008-09-05 12:38:09 -0700591
592 kfree(buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700593}
594
595
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200596static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Bergae5eb022008-10-14 16:58:37 +0200597 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700598{
Johannes Berg46900292009-02-15 12:44:28 +0100599 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100600 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700601 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700602
Johannes Bergc2b13452008-09-11 00:01:55 +0200603 struct ieee80211_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400604
Johannes Bergae5eb022008-10-14 16:58:37 +0200605 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg46900292009-02-15 12:44:28 +0100606 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400607
Johannes Berg46900292009-02-15 12:44:28 +0100608 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200609 conf->channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100610 ifmgd->ssid, ifmgd->ssid_len);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200611 if (bss) {
612 /* set timing information */
Johannes Berg00d3f142009-02-10 21:26:00 +0100613 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
614 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
Johannes Bergbda39332008-10-11 01:51:51 +0200615 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700616
Johannes Bergae5eb022008-10-14 16:58:37 +0200617 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg00d3f142009-02-10 21:26:00 +0100618 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700619
Kalle Valo04de8382009-03-22 21:57:35 +0200620 cfg80211_hold_bss(&bss->cbss);
621
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200622 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700623 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100624
Johannes Berg46900292009-02-15 12:44:28 +0100625 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 Winklerf5e5bf22008-09-08 17:33:39 +0200628
Johannes Berg46900292009-02-15 12:44:28 +0100629 ifmgd->last_probe = jiffies;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200630 ieee80211_led_assoc(local, 1);
631
Johannes Bergbda39332008-10-11 01:51:51 +0200632 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200633 /*
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 Bergae5eb022008-10-14 16:58:37 +0200638 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
639 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300640
Johannes Berg4be8c382009-01-07 18:28:20 +0100641 if (local->powersave) {
642 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
643 local->hw.conf.dynamic_ps_timeout > 0) {
Kalle Valo520eb822008-12-18 23:35:27 +0200644 mod_timer(&local->dynamic_ps_timer, jiffies +
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100645 msecs_to_jiffies(
646 local->hw.conf.dynamic_ps_timeout));
Johannes Berg4be8c382009-01-07 18:28:20 +0100647 } else {
648 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
649 ieee80211_send_nullfunc(local, sdata, 1);
Kalle Valo520eb822008-12-18 23:35:27 +0200650 conf->flags |= IEEE80211_CONF_PS;
Johannes Berg4be8c382009-01-07 18:28:20 +0100651 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Kalle Valo520eb822008-12-18 23:35:27 +0200652 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200653 }
654
Tomas Winkler24e64622008-09-08 17:33:40 +0200655 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200656 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300657
Johannes Berg46900292009-02-15 12:44:28 +0100658 ieee80211_sta_send_apinfo(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700659}
660
Johannes Berg46900292009-02-15 12:44:28 +0100661static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300662{
Johannes Berg46900292009-02-15 12:44:28 +0100663 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100664 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100665
666 ifmgd->direct_probe_tries++;
667 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700668 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100669 sdata->dev->name, ifmgd->bssid);
670 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
671 ieee80211_sta_send_apinfo(sdata);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530672
673 /*
674 * Most likely AP is not in the range so remove the
675 * bss information associated to the AP
676 */
Johannes Berg46900292009-02-15 12:44:28 +0100677 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530678 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100679 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100680
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 Rindjunsky9859b812008-08-09 03:02:19 +0300687 return;
688 }
689
Johannes Berg0c68ae262008-10-27 15:56:10 -0700690 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
Johannes Berg46900292009-02-15 12:44:28 +0100691 sdata->dev->name, ifmgd->bssid,
692 ifmgd->direct_probe_tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300693
Johannes Berg46900292009-02-15 12:44:28 +0100694 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300695
Johannes Berg46900292009-02-15 12:44:28 +0100696 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300697
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 Malinen70692ad2009-02-16 19:39:13 +0200702 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300703
Johannes Berg46900292009-02-15 12:44:28 +0100704 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300705}
706
Jiri Bencf0706e82007-05-05 11:45:53 -0700707
Johannes Berg46900292009-02-15 12:44:28 +0100708static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700709{
Johannes Berg46900292009-02-15 12:44:28 +0100710 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100711 struct ieee80211_local *local = sdata->local;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200712 u8 *ies;
713 size_t ies_len;
Johannes Berg46900292009-02-15 12:44:28 +0100714
715 ifmgd->auth_tries++;
716 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700717 printk(KERN_DEBUG "%s: authentication with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700718 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100719 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 Thiagarajan7a947082009-02-04 18:28:48 +0530723 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100724 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100725
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 Bencf0706e82007-05-05 11:45:53 -0700732 return;
733 }
734
Johannes Berg46900292009-02-15 12:44:28 +0100735 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700736 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100737 sdata->dev->name, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700738
Jouni Malinen636a5d32009-03-19 13:39:22 +0200739 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 Berg46900292009-02-15 12:44:28 +0100747 ifmgd->bssid, 0);
748 ifmgd->auth_transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700749
Johannes Berg46900292009-02-15 12:44:28 +0100750 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700751}
752
Vivek Natarajan5925d972008-11-21 22:19:50 -0800753/*
754 * The disassoc 'reason' argument can be either our own reason
755 * if self disconnected or a reason code from the AP.
756 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300757static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg46900292009-02-15 12:44:28 +0100758 bool deauth, bool self_disconnected,
759 u16 reason)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300760{
Johannes Berg46900292009-02-15 12:44:28 +0100761 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300762 struct ieee80211_local *local = sdata->local;
Kalle Valo04de8382009-03-22 21:57:35 +0200763 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
764 struct ieee80211_bss *bss;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300765 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200766 u32 changed = 0, config_changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300767
768 rcu_read_lock();
769
Johannes Berg46900292009-02-15 12:44:28 +0100770 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300771 if (!sta) {
772 rcu_read_unlock();
773 return;
774 }
775
776 if (deauth) {
Johannes Berg46900292009-02-15 12:44:28 +0100777 ifmgd->direct_probe_tries = 0;
778 ifmgd->auth_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300779 }
Johannes Berg46900292009-02-15 12:44:28 +0100780 ifmgd->assoc_scan_tries = 0;
781 ifmgd->assoc_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300782
Tomas Winkler24e64622008-09-08 17:33:40 +0200783 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300784 netif_carrier_off(sdata->dev);
785
Johannes Berg2dace102009-02-10 21:25:52 +0100786 ieee80211_sta_tear_down_BA_sessions(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300787
Kalle Valo04de8382009-03-22 21:57:35 +0200788 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 Winkleraa458d12008-09-09 00:32:12 +0300797 if (self_disconnected) {
798 if (deauth)
Johannes Bergef422bc2008-09-09 10:58:25 +0200799 ieee80211_send_deauth_disassoc(sdata,
800 IEEE80211_STYPE_DEAUTH, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300801 else
Johannes Bergef422bc2008-09-09 10:58:25 +0200802 ieee80211_send_deauth_disassoc(sdata,
803 IEEE80211_STYPE_DISASSOC, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300804 }
805
Johannes Berg46900292009-02-15 12:44:28 +0100806 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200807 changed |= ieee80211_reset_erp_info(sdata);
808
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200809 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +0200810 changed |= BSS_CHANGED_ASSOC;
811 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200812
Johannes Berg46900292009-02-15 12:44:28 +0100813 ieee80211_sta_send_apinfo(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300814
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530815 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
Johannes Berg46900292009-02-15 12:44:28 +0100816 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
817 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530818 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100819 ifmgd->ssid, ifmgd->ssid_len);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530820 }
Tomas Winkleraa458d12008-09-09 00:32:12 +0300821
Tomas Winkleraa458d12008-09-09 00:32:12 +0300822 rcu_read_unlock();
823
Johannes Berg47979382009-01-07 10:13:27 +0100824 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +0530825 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +0200826
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +0530827 local->power_constr_level = 0;
828
Kalle Valo520eb822008-12-18 23:35:27 +0200829 del_timer_sync(&local->dynamic_ps_timer);
830 cancel_work_sync(&local->dynamic_ps_enable_work);
831
Kalle Valoe0cb6862008-12-18 23:35:13 +0200832 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 Bergae5eb022008-10-14 16:58:37 +0200838 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +0200839
840 rcu_read_lock();
841
Johannes Berg46900292009-02-15 12:44:28 +0100842 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +0200843 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 Winkleraa458d12008-09-09 00:32:12 +0300853}
Jiri Bencf0706e82007-05-05 11:45:53 -0700854
Johannes Berg9ac19a92008-09-09 10:57:09 +0200855static 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 Berg46900292009-02-15 12:44:28 +0100863static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700864{
Johannes Berg46900292009-02-15 12:44:28 +0100865 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200866 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +0200867 struct ieee80211_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000868 int bss_privacy;
869 int wep_privacy;
870 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -0700871
Johannes Berg7986cf92009-03-21 17:08:43 +0100872 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
Jiri Bencf0706e82007-05-05 11:45:53 -0700873 return 0;
874
Johannes Berg46900292009-02-15 12:44:28 +0100875 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +0100876 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100877 ifmgd->ssid, ifmgd->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700878 if (!bss)
879 return 0;
880
Johannes Berg00d3f142009-02-10 21:26:00 +0100881 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200882 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg46900292009-02-15 12:44:28 +0100883 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -0700884
Johannes Berg3e122be2008-07-09 14:40:34 +0200885 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700886
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000887 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
888 return 0;
889
890 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700891}
892
Johannes Berg46900292009-02-15 12:44:28 +0100893static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700894{
Johannes Berg46900292009-02-15 12:44:28 +0100895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100896 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100897
898 ifmgd->assoc_tries++;
899 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700900 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700901 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100902 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 Thiagarajan7a947082009-02-04 18:28:48 +0530906 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100907 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100908 /*
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 Bencf0706e82007-05-05 11:45:53 -0700914 return;
915 }
916
Johannes Berg46900292009-02-15 12:44:28 +0100917 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700918 printk(KERN_DEBUG "%s: associate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100919 sdata->dev->name, ifmgd->bssid);
920 if (ieee80211_privacy_mismatch(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700921 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200922 "mixed-cell disabled - abort association\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +0100923 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700924 return;
925 }
926
Johannes Berg46900292009-02-15 12:44:28 +0100927 ieee80211_send_assoc(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700928
Johannes Berg46900292009-02-15 12:44:28 +0100929 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700930}
931
Kalle Valo3cf335d2009-03-22 21:57:06 +0200932void 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 Bencf0706e82007-05-05 11:45:53 -0700947
Kalle Valo04de8382009-03-22 21:57:35 +0200948void 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 Buescha8604022009-04-15 14:41:22 -0400955#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 Valo04de8382009-03-22 21:57:35 +0200962
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
970void 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}
977EXPORT_SYMBOL(ieee80211_beacon_loss);
978
Johannes Berg46900292009-02-15 12:44:28 +0100979static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700980{
Johannes Berg46900292009-02-15 12:44:28 +0100981 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200982 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -0700983 struct sta_info *sta;
Kalle Valo15b7b062009-03-22 21:57:14 +0200984 bool disassoc = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700985
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 Berg46900292009-02-15 12:44:28 +0100991 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700992
Johannes Bergd0709a62008-02-25 16:27:46 +0100993 rcu_read_lock();
994
Johannes Berg46900292009-02-15 12:44:28 +0100995 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700996 if (!sta) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700997 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100998 sdata->dev->name, ifmgd->bssid);
Kalle Valo15b7b062009-03-22 21:57:14 +0200999 disassoc = true;
1000 goto unlock;
Jiri Bencf0706e82007-05-05 11:45:53 -07001001 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001002
Kalle Valo15b7b062009-03-22 21:57:14 +02001003 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 Valo04de8382009-03-22 21:57:35 +02001013 /*
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 Valo15b7b062009-03-22 21:57:14 +02001020 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
Michael Buescha8604022009-04-15 14:41:22 -04001021#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 Valo15b7b062009-03-22 21:57:14 +02001028 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 Bergd0709a62008-02-25 16:27:46 +01001042 rcu_read_unlock();
1043
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301044 if (disassoc)
Johannes Berg46900292009-02-15 12:44:28 +01001045 ieee80211_set_disassoc(sdata, true, true,
Tomas Winkleraa458d12008-09-09 00:32:12 +03001046 WLAN_REASON_PREV_AUTH_NOT_VALID);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301047 else
Johannes Berg46900292009-02-15 12:44:28 +01001048 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001049 IEEE80211_MONITORING_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001050}
1051
1052
Johannes Berg46900292009-02-15 12:44:28 +01001053static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001054{
Johannes Berg46900292009-02-15 12:44:28 +01001055 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1056
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001057 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001058 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001059 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 Bencf0706e82007-05-05 11:45:53 -07001064}
1065
1066
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001067static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001068 struct ieee80211_mgmt *mgmt,
1069 size_t len)
1070{
1071 u8 *pos;
1072 struct ieee802_11_elems elems;
1073
Jiri Bencf0706e82007-05-05 11:45:53 -07001074 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001075 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001076 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001077 return;
Johannes Berg46900292009-02-15 12:44:28 +01001078 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 Bergfe3d2c32009-02-10 21:26:03 +01001082}
1083
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001084static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001085 struct ieee80211_mgmt *mgmt,
1086 size_t len)
1087{
Johannes Berg46900292009-02-15 12:44:28 +01001088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001089 u16 auth_alg, auth_transaction, status_code;
1090
Johannes Berg46900292009-02-15 12:44:28 +01001091 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001092 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001093
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001094 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001095 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001096
Johannes Berg46900292009-02-15 12:44:28 +01001097 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001098 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001099
Johannes Berg46900292009-02-15 12:44:28 +01001100 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001101 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001102
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 Berg46900292009-02-15 12:44:28 +01001107 if (auth_alg != ifmgd->auth_alg ||
1108 auth_transaction != ifmgd->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001109 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001110
1111 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001112 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 Berg46900292009-02-15 12:44:28 +01001117 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001118 algs[0] = WLAN_AUTH_OPEN;
Johannes Berg46900292009-02-15 12:44:28 +01001119 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001120 algs[1] = WLAN_AUTH_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001121 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001122 algs[2] = WLAN_AUTH_LEAP;
Johannes Berg46900292009-02-15 12:44:28 +01001123 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001124 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001125 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 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 Berg46900292009-02-15 12:44:28 +01001133 if (algs[pos] == ifmgd->auth_alg ||
Jiri Bencf0706e82007-05-05 11:45:53 -07001134 algs[pos] == 0xff)
1135 continue;
1136 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001137 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001138 continue;
Johannes Berg46900292009-02-15 12:44:28 +01001139 ifmgd->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001140 break;
1141 }
1142 }
1143 return;
1144 }
1145
Johannes Berg46900292009-02-15 12:44:28 +01001146 switch (ifmgd->auth_alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001147 case WLAN_AUTH_OPEN:
1148 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001149 case WLAN_AUTH_FT:
Johannes Berg46900292009-02-15 12:44:28 +01001150 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001151 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001152 break;
1153 case WLAN_AUTH_SHARED_KEY:
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001154 if (ifmgd->auth_transaction == 4) {
Johannes Berg46900292009-02-15 12:44:28 +01001155 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001156 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1157 } else
Johannes Berg46900292009-02-15 12:44:28 +01001158 ieee80211_auth_challenge(sdata, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001159 break;
1160 }
1161}
1162
1163
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001164static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001165 struct ieee80211_mgmt *mgmt,
1166 size_t len)
1167{
Johannes Berg46900292009-02-15 12:44:28 +01001168 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001169 u16 reason_code;
1170
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001171 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001172 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001173
Johannes Berg46900292009-02-15 12:44:28 +01001174 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001175 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001176
1177 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1178
Johannes Berg46900292009-02-15 12:44:28 +01001179 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001180 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1181 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001182
Jouni Malinen636a5d32009-03-19 13:39:22 +02001183 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 Berg46900292009-02-15 12:44:28 +01001187 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1188 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001189 IEEE80211_RETRY_AUTH_INTERVAL);
1190 }
1191
Johannes Berg46900292009-02-15 12:44:28 +01001192 ieee80211_set_disassoc(sdata, true, false, 0);
1193 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jouni Malinen53b46b82009-03-27 20:53:56 +02001194 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001195}
1196
1197
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001198static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001199 struct ieee80211_mgmt *mgmt,
1200 size_t len)
1201{
Johannes Berg46900292009-02-15 12:44:28 +01001202 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001203 u16 reason_code;
1204
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001205 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001206 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001207
Johannes Berg46900292009-02-15 12:44:28 +01001208 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001209 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001210
1211 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1212
Johannes Berg46900292009-02-15 12:44:28 +01001213 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001214 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1215 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001216
Jouni Malinen636a5d32009-03-19 13:39:22 +02001217 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1218 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
Johannes Berg46900292009-02-15 12:44:28 +01001219 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1220 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001221 IEEE80211_RETRY_AUTH_INTERVAL);
1222 }
1223
Johannes Berg46900292009-02-15 12:44:28 +01001224 ieee80211_set_disassoc(sdata, false, false, reason_code);
Jouni Malinen53b46b82009-03-27 20:53:56 +02001225 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001226}
1227
1228
Johannes Berg471b3ef2007-12-28 14:32:58 +01001229static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001230 struct ieee80211_mgmt *mgmt,
1231 size_t len,
1232 int reassoc)
1233{
Johannes Berg46900292009-02-15 12:44:28 +01001234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001235 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001236 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001237 struct sta_info *sta;
Johannes Berg881d9482009-01-21 15:13:48 +01001238 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001239 u16 capab_info, status_code, aid;
1240 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001241 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001242 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001243 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001244 int i, j;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001245 bool have_higher_than_11mbit = false, newsta = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001246 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001247
1248 /* AssocResp and ReassocResp have identical structure, so process both
1249 * of them in this function. */
1250
Johannes Berg46900292009-02-15 12:44:28 +01001251 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001252 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001253
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001254 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001255 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001256
Johannes Berg46900292009-02-15 12:44:28 +01001257 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001258 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001259
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 Bencf0706e82007-05-05 11:45:53 -07001263
Johannes Berg0c68ae262008-10-27 15:56:10 -07001264 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001265 "status=%d aid=%d)\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001266 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001267 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001268
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001269 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 Malinenf797eb72009-01-19 18:48:46 +02001273 elems.timeout_int && elems.timeout_int_len == 5 &&
1274 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001275 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001276 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001277 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 Berg46900292009-02-15 12:44:28 +01001282 mod_timer(&ifmgd->timer,
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001283 jiffies + msecs_to_jiffies(ms));
1284 return;
1285 }
1286
Jiri Bencf0706e82007-05-05 11:45:53 -07001287 if (status_code != WLAN_STATUS_SUCCESS) {
1288 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001289 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001290 /* 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 Berg46900292009-02-15 12:44:28 +01001293 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jiri Bencf0706e82007-05-05 11:45:53 -07001294 return;
1295 }
1296
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001297 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-Greenef698d852008-08-03 12:04:37 +12001299 "set\n", sdata->dev->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001300 aid &= ~(BIT(15) | BIT(14));
1301
Jiri Bencf0706e82007-05-05 11:45:53 -07001302 if (!elems.supp_rates) {
1303 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001304 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001305 return;
1306 }
1307
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001308 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001309 ifmgd->aid = aid;
1310 ifmgd->ap_capab = capab_info;
Jiri Bencf0706e82007-05-05 11:45:53 -07001311
Johannes Berg46900292009-02-15 12:44:28 +01001312 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 Bencf0706e82007-05-05 11:45:53 -07001317
Johannes Bergd0709a62008-02-25 16:27:46 +01001318 rcu_read_lock();
1319
Jiri Bencf0706e82007-05-05 11:45:53 -07001320 /* Add STA entry for the AP */
Johannes Berg46900292009-02-15 12:44:28 +01001321 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001322 if (!sta) {
Johannes Bergddf4ac52008-10-22 11:41:38 +02001323 newsta = true;
Johannes Bergd0709a62008-02-25 16:27:46 +01001324
Johannes Berg46900292009-02-15 12:44:28 +01001325 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
Johannes Berg73651ee2008-02-25 16:27:47 +01001326 if (!sta) {
1327 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001328 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001329 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001330 return;
1331 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001332
Ron Rindjunskya61dae12008-08-10 00:54:34 +03001333 /* update new sta with its last rx activity */
1334 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07001335 }
1336
Johannes Berg73651ee2008-02-25 16:27:47 +01001337 /*
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 Berg07346f812008-05-03 01:02:02 +02001347 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1348 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001349
1350 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001351 basic_rates = 0;
1352 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1353
Jiri Bencf0706e82007-05-05 11:45:53 -07001354 for (i = 0; i < elems.supp_rates_len; i++) {
1355 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001356 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001357
1358 if (rate > 110)
1359 have_higher_than_11mbit = true;
1360
1361 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001362 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001363 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001364 if (is_basic)
1365 basic_rates |= BIT(j);
1366 break;
1367 }
Johannes Berg8318d782008-01-24 19:38:38 +01001368 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001369 }
Johannes Berg8318d782008-01-24 19:38:38 +01001370
Jiri Bencf0706e82007-05-05 11:45:53 -07001371 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1372 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001373 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001374
1375 if (rate > 110)
1376 have_higher_than_11mbit = true;
1377
1378 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001379 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001380 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001381 if (is_basic)
1382 basic_rates |= BIT(j);
1383 break;
1384 }
Johannes Berg8318d782008-01-24 19:38:38 +01001385 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001386 }
Johannes Berg8318d782008-01-24 19:38:38 +01001387
Johannes Berg323ce792008-09-11 02:45:11 +02001388 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001389 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001390
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 Bencf0706e82007-05-05 11:45:53 -07001397
Sujithe65c2262009-03-02 13:28:31 +05301398 /* 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 Bergae5eb022008-10-14 16:58:37 +02001400 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001401 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001402
1403 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001404
Johannes Berg4b7679a2008-09-18 18:14:18 +02001405 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001406
Johannes Berg46900292009-02-15 12:44:28 +01001407 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001408 set_sta_flags(sta, WLAN_STA_MFP);
1409
Johannes Bergddf4ac52008-10-22 11:41:38 +02001410 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001411 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001412
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 Berg46900292009-02-15 12:44:28 +01001426 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001427 elems.wmm_param_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001428
Johannes Bergae5eb022008-10-14 16:58:37 +02001429 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001430 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1431 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001432 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1433 ap_ht_cap_flags);
1434
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001435 /* set AID and assoc capability,
1436 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001437 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001438 bss_conf->assoc_capability = capab_info;
Johannes Berg46900292009-02-15 12:44:28 +01001439 ieee80211_set_associated(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001440
Kalle Valo15b7b062009-03-22 21:57:14 +02001441 /*
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 Berg46900292009-02-15 12:44:28 +01001447 ieee80211_associated(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001448 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001449}
1450
1451
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001452static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001453 struct ieee80211_mgmt *mgmt,
1454 size_t len,
1455 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001456 struct ieee802_11_elems *elems,
1457 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001458{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001459 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001460 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001461 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001462 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001463
Johannes Berg5bda6172008-09-08 11:05:10 +02001464 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 Bencf0706e82007-05-05 11:45:53 -07001473
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001474 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001475 channel, beacon);
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001476 if (!bss)
1477 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001478
Sujithc481ec92009-01-06 09:28:37 +05301479 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg46900292009-02-15 12:44:28 +01001480 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301481 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 Berg3e122be2008-07-09 14:40:34 +02001486 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001487}
1488
1489
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001490static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001491 struct ieee80211_mgmt *mgmt,
1492 size_t len,
1493 struct ieee80211_rx_status *rx_status)
1494{
Kalle Valo15b7b062009-03-22 21:57:14 +02001495 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001496 size_t baselen;
1497 struct ieee802_11_elems elems;
1498
Kalle Valo15b7b062009-03-22 21:57:14 +02001499 ifmgd = &sdata->u.mgd;
1500
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001501 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1502 return; /* ignore ProbeResp to foreign address */
1503
Ester Kummerae6a44e2008-06-27 18:54:48 +03001504 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 Berg98c8fcc2008-09-08 17:44:26 +02001511 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001512
1513 /* direct probe may be part of the association flow */
1514 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
Kalle Valo15b7b062009-03-22 21:57:14 +02001515 &ifmgd->request)) {
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001516 printk(KERN_DEBUG "%s direct probe responded\n",
1517 sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001518 ieee80211_authenticate(sdata);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001519 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001520
1521 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1522 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001523}
1524
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001525static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001526 struct ieee80211_mgmt *mgmt,
1527 size_t len,
1528 struct ieee80211_rx_status *rx_status)
1529{
Johannes Berg46900292009-02-15 12:44:28 +01001530 struct ieee80211_if_managed *ifmgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001531 size_t baselen;
1532 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001533 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001534 u32 changed = 0;
Kalle Valo1fb36062009-02-10 17:09:24 +02001535 bool erp_valid, directed_tim;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001536 u8 erp_value = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001537
Ester Kummerae6a44e2008-06-27 18:54:48 +03001538 /* 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 Berg98c8fcc2008-09-08 17:44:26 +02001545 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07001546
Johannes Berg05c914f2008-09-11 00:01:58 +02001547 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -07001548 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001549
Johannes Berg46900292009-02-15 12:44:28 +01001550 ifmgd = &sdata->u.mgd;
1551
1552 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1553 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001554 return;
1555
Sujithc481ec92009-01-06 09:28:37 +05301556 if (rx_status->freq != local->hw.conf.channel->center_freq)
1557 return;
1558
Johannes Berg46900292009-02-15 12:44:28 +01001559 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Johannes Bergfe3fa822008-09-08 11:05:09 +02001560 elems.wmm_param_len);
1561
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301562 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Johannes Berg46900292009-02-15 12:44:28 +01001563 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001564
Kalle Valo1fb36062009-02-10 17:09:24 +02001565 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001566 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 Natarajana97b77b2008-12-23 18:39:02 -08001584 }
1585 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001586
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. Linville50c4afb2008-04-15 14:09:27 -04001592 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001593 changed |= ieee80211_handle_bss_capability(sdata,
1594 le16_to_cpu(mgmt->u.beacon.capab_info),
1595 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001596
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001597
Vasanthakumar Thiagarajan53d6f81c2009-02-11 22:18:49 +05301598 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001599 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001600 struct sta_info *sta;
1601 struct ieee80211_supported_band *sband;
1602 u16 ap_ht_cap_flags;
1603
1604 rcu_read_lock();
1605
Johannes Berg46900292009-02-15 12:44:28 +01001606 sta = sta_info_get(local, ifmgd->bssid);
Johannes Bergae5eb022008-10-14 16:58:37 +02001607 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 Rindjunskyd3c990f2007-11-26 16:14:34 +02001623 }
1624
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001625 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 Thiagarajana8302de2009-01-09 18:14:15 +05301630
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. Rodriguez3f2355c2008-11-12 14:22:02 -08001637 }
1638
Johannes Berg471b3ef2007-12-28 14:32:58 +01001639 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001640}
1641
Johannes Berg46900292009-02-15 12:44:28 +01001642ieee80211_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 Bencf0706e82007-05-05 11:45:53 -07001645{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001646 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001647 struct ieee80211_mgmt *mgmt;
1648 u16 fc;
1649
1650 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001651 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001652
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 Berg46900292009-02-15 12:44:28 +01001666 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1667 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1668 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001669 }
1670
Johannes Berg46900292009-02-15 12:44:28 +01001671 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001672}
1673
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001674static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001675 struct sk_buff *skb)
1676{
1677 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001678 struct ieee80211_mgmt *mgmt;
1679 u16 fc;
1680
Jiri Bencf0706e82007-05-05 11:45:53 -07001681 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 Berg46900292009-02-15 12:44:28 +01001685 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 Bencf0706e82007-05-05 11:45:53 -07001709 }
1710
1711 kfree_skb(skb);
1712}
1713
Johannes Berg9c6bd792008-09-11 00:01:52 +02001714static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001715{
1716 struct ieee80211_sub_if_data *sdata =
1717 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001718 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001719 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001720
Johannes Berg46900292009-02-15 12:44:28 +01001721 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1722 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001723}
1724
Johannes Berg46900292009-02-15 12:44:28 +01001725static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001726{
Johannes Berg46900292009-02-15 12:44:28 +01001727 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001728 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001729
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 Berg46900292009-02-15 12:44:28 +01001735 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
Jiri Bencf0706e82007-05-05 11:45:53 -07001736
1737
Johannes Berg46900292009-02-15 12:44:28 +01001738 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 Malinen636a5d32009-03-19 13:39:22 +02001744 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
1745 ifmgd->auth_alg = WLAN_AUTH_FT;
Jiri Bencf0706e82007-05-05 11:45:53 -07001746 else
Johannes Berg46900292009-02-15 12:44:28 +01001747 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 Winkler24e64622008-09-08 17:33:40 +02001754 netif_tx_stop_all_queues(sdata->dev);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001755 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001756}
1757
Johannes Berg46900292009-02-15 12:44:28 +01001758static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001759{
Johannes Berg46900292009-02-15 12:44:28 +01001760 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001761 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001762 struct ieee80211_bss *bss;
Johannes Berg46900292009-02-15 12:44:28 +01001763 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
1764 u8 ssid_len = ifmgd->ssid_len;
Johannes Berg00d3f142009-02-10 21:26:00 +01001765 u16 capa_mask = WLAN_CAPABILITY_ESS;
1766 u16 capa_val = WLAN_CAPABILITY_ESS;
1767 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg60f8b392008-09-08 17:44:22 +02001768
Jouni Malinen636a5d32009-03-19 13:39:22 +02001769 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1770 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
Johannes Berg00d3f142009-02-10 21:26:00 +01001771 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 Berg60f8b392008-09-08 17:44:22 +02001776 }
Johannes Berg60f8b392008-09-08 17:44:22 +02001777
Johannes Berg46900292009-02-15 12:44:28 +01001778 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01001779 chan = NULL;
1780
Johannes Berg46900292009-02-15 12:44:28 +01001781 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01001782 bssid = NULL;
1783
Johannes Berg46900292009-02-15 12:44:28 +01001784 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
Johannes Berg00d3f142009-02-10 21:26:00 +01001785 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 Berg46900292009-02-15 12:44:28 +01001795 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
Johannes Berg00d3f142009-02-10 21:26:00 +01001796 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 Berg46900292009-02-15 12:44:28 +01001801 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
1802 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
Jouni Malinenfdfacf02009-01-08 13:32:05 +02001803 else
Johannes Berg46900292009-02-15 12:44:28 +01001804 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
Johannes Berg60f8b392008-09-08 17:44:22 +02001805
1806 /* Send out direct probe if no probe resp was received or
1807 * the one we have is outdated
1808 */
Johannes Berg00d3f142009-02-10 21:26:00 +01001809 if (!bss->last_probe_resp ||
1810 time_after(jiffies, bss->last_probe_resp
Johannes Berg60f8b392008-09-08 17:44:22 +02001811 + IEEE80211_SCAN_RESULT_EXPIRE))
Johannes Berg46900292009-02-15 12:44:28 +01001812 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Johannes Berg60f8b392008-09-08 17:44:22 +02001813 else
Johannes Berg46900292009-02-15 12:44:28 +01001814 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg60f8b392008-09-08 17:44:22 +02001815
Johannes Berg00d3f142009-02-10 21:26:00 +01001816 ieee80211_rx_bss_put(local, bss);
Johannes Berg46900292009-02-15 12:44:28 +01001817 ieee80211_sta_reset_auth(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001818 return 0;
1819 } else {
Johannes Berg46900292009-02-15 12:44:28 +01001820 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
1821 ifmgd->assoc_scan_tries++;
Johannes Berg2a519312009-02-10 21:25:55 +01001822 /* XXX maybe racy? */
1823 if (local->scan_req)
1824 return -1;
1825 memcpy(local->int_scan_req.ssids[0].ssid,
Johannes Berg46900292009-02-15 12:44:28 +01001826 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
1827 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
Johannes Berg2a519312009-02-10 21:25:55 +01001828 local->int_scan_req.ssids[0].ssid_len = 0;
Johannes Berg60f8b392008-09-08 17:44:22 +02001829 else
Johannes Berg46900292009-02-15 12:44:28 +01001830 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
Helmut Schaaaf88b902009-03-09 15:47:08 +01001831
1832 if (ieee80211_start_scan(sdata, &local->int_scan_req))
1833 ieee80211_scan_failed(local);
1834
Johannes Berg46900292009-02-15 12:44:28 +01001835 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
1836 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
Sujithe3740552009-01-29 09:34:22 +05301837 } else {
Johannes Berg46900292009-02-15 12:44:28 +01001838 ifmgd->assoc_scan_tries = 0;
1839 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Sujithe3740552009-01-29 09:34:22 +05301840 }
Johannes Berg60f8b392008-09-08 17:44:22 +02001841 }
1842 return -1;
1843}
1844
1845
Johannes Berg9c6bd792008-09-11 00:01:52 +02001846static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02001847{
1848 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01001849 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02001850 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001851 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001852 struct sk_buff *skb;
1853
1854 if (!netif_running(sdata->dev))
1855 return;
1856
Johannes Bergc2b13452008-09-11 00:01:55 +02001857 if (local->sw_scanning || local->hw_scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02001858 return;
1859
Johannes Berg46900292009-02-15 12:44:28 +01001860 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02001861 return;
Johannes Berg46900292009-02-15 12:44:28 +01001862 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001863
Johannes Berg46900292009-02-15 12:44:28 +01001864 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02001865 ieee80211_sta_rx_queued_mgmt(sdata, skb);
1866
Johannes Berg46900292009-02-15 12:44:28 +01001867 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 Schaaaf88b902009-03-09 15:47:08 +01001871 /*
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 Berg60f8b392008-09-08 17:44:22 +02001879 return;
1880 }
1881
Johannes Berg46900292009-02-15 12:44:28 +01001882 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
1883 if (ieee80211_sta_config_auth(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02001884 return;
Johannes Berg46900292009-02-15 12:44:28 +01001885 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1886 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
Johannes Berg60f8b392008-09-08 17:44:22 +02001887 return;
1888
Johannes Berg46900292009-02-15 12:44:28 +01001889 switch (ifmgd->state) {
Johannes Berg60f8b392008-09-08 17:44:22 +02001890 case IEEE80211_STA_MLME_DISABLED:
1891 break;
1892 case IEEE80211_STA_MLME_DIRECT_PROBE:
Johannes Berg46900292009-02-15 12:44:28 +01001893 ieee80211_direct_probe(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001894 break;
1895 case IEEE80211_STA_MLME_AUTHENTICATE:
Johannes Berg46900292009-02-15 12:44:28 +01001896 ieee80211_authenticate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001897 break;
1898 case IEEE80211_STA_MLME_ASSOCIATE:
Johannes Berg46900292009-02-15 12:44:28 +01001899 ieee80211_associate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001900 break;
1901 case IEEE80211_STA_MLME_ASSOCIATED:
Johannes Berg46900292009-02-15 12:44:28 +01001902 ieee80211_associated(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001903 break;
Johannes Berg60f8b392008-09-08 17:44:22 +02001904 default:
1905 WARN_ON(1);
1906 break;
1907 }
1908
Johannes Berg46900292009-02-15 12:44:28 +01001909 if (ieee80211_privacy_mismatch(sdata)) {
Johannes Berg60f8b392008-09-08 17:44:22 +02001910 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
1911 "mixed-cell disabled - disassociate\n", sdata->dev->name);
1912
Johannes Berg46900292009-02-15 12:44:28 +01001913 ieee80211_set_disassoc(sdata, false, true,
Johannes Berg60f8b392008-09-08 17:44:22 +02001914 WLAN_REASON_UNSPECIFIED);
1915 }
1916}
Johannes Berg0a51b272008-09-08 17:44:25 +02001917
Johannes Berga1678f82008-09-11 00:01:47 +02001918static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1919{
Kalle Vaload935682009-04-19 08:47:19 +03001920 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 Berg7c950692008-09-11 00:01:48 +02001928 queue_work(sdata->local->hw.workqueue,
Johannes Berg46900292009-02-15 12:44:28 +01001929 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03001930 }
Johannes Berga1678f82008-09-11 00:01:47 +02001931}
1932
Johannes Berg9c6bd792008-09-11 00:01:52 +02001933/* interface setup */
1934void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1935{
Johannes Berg46900292009-02-15 12:44:28 +01001936 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02001937
Johannes Berg46900292009-02-15 12:44:28 +01001938 ifmgd = &sdata->u.mgd;
1939 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
1940 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001941 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01001942 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02001943 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001944 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05301945 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001946 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02001947
Johannes Berg46900292009-02-15 12:44:28 +01001948 ifmgd->capab = WLAN_CAPABILITY_ESS;
1949 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
Johannes Berg9c6bd792008-09-11 00:01:52 +02001950 IEEE80211_AUTH_ALG_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001951 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
Johannes Berg9c6bd792008-09-11 00:01:52 +02001952 IEEE80211_STA_AUTO_BSSID_SEL |
1953 IEEE80211_STA_AUTO_CHANNEL_SEL;
Johannes Berg176be722009-03-12 23:49:28 +01001954 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01001955 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Berg9c6bd792008-09-11 00:01:52 +02001956}
1957
1958/* configuration hooks */
Johannes Berg46900292009-02-15 12:44:28 +01001959void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg9c6bd792008-09-11 00:01:52 +02001960{
Johannes Berg46900292009-02-15 12:44:28 +01001961 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02001962 struct ieee80211_local *local = sdata->local;
1963
Johannes Berg46900292009-02-15 12:44:28 +01001964 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg9c6bd792008-09-11 00:01:52 +02001965 return;
1966
Johannes Berg46900292009-02-15 12:44:28 +01001967 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02001968 IEEE80211_STA_AUTO_BSSID_SEL)) &&
Johannes Berg46900292009-02-15 12:44:28 +01001969 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02001970 IEEE80211_STA_AUTO_SSID_SEL))) {
1971
Johannes Berg46900292009-02-15 12:44:28 +01001972 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
1973 ieee80211_set_disassoc(sdata, true, true,
Johannes Berg9c6bd792008-09-11 00:01:52 +02001974 WLAN_REASON_DEAUTH_LEAVING);
1975
Jouni Malinen636a5d32009-03-19 13:39:22 +02001976 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 Berg46900292009-02-15 12:44:28 +01001981 queue_work(local->hw.workqueue, &ifmgd->work);
Johannes Berg9c6bd792008-09-11 00:01:52 +02001982 }
1983}
1984
Alina Friedrichsen79f64402009-02-21 01:27:29 +01001985int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
1986{
1987 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1988
Alina Friedrichsen79f64402009-02-21 01:27:29 +01001989 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 Berg9c6bd792008-09-11 00:01:52 +02001997int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
1998{
Johannes Berg46900292009-02-15 12:44:28 +01001999 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002000
2001 if (len > IEEE80211_MAX_SSID_LEN)
2002 return -EINVAL;
2003
Johannes Berg46900292009-02-15 12:44:28 +01002004 ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002005
Johannes Berg46900292009-02-15 12:44:28 +01002006 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
Jouni Malinena2995422009-03-19 13:39:20 +02002007 /*
2008 * Do not use reassociation if SSID is changed (different ESS).
2009 */
2010 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg46900292009-02-15 12:44:28 +01002011 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2012 memcpy(ifmgd->ssid, ssid, len);
2013 ifmgd->ssid_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002014 }
2015
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002016 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002017}
2018
2019int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2020{
Johannes Berg46900292009-02-15 12:44:28 +01002021 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2022 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2023 *len = ifmgd->ssid_len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002024 return 0;
2025}
2026
2027int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2028{
Johannes Berg46900292009-02-15 12:44:28 +01002029 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002030
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002031 if (is_valid_ether_addr(bssid)) {
Johannes Berg46900292009-02-15 12:44:28 +01002032 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2033 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002034 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002035 memset(ifmgd->bssid, 0, ETH_ALEN);
2036 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002037 }
2038
2039 if (netif_running(sdata->dev)) {
2040 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
Johannes Berg9c6bd792008-09-11 00:01:52 +02002041 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2042 "the low-level driver\n", sdata->dev->name);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002043 }
2044 }
2045
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002046 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002047}
2048
Jouni Malinen636a5d32009-03-19 13:39:22 +02002049int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2050 const char *ie, size_t len)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002051{
Johannes Berg46900292009-02-15 12:44:28 +01002052 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002053
Johannes Berg46900292009-02-15 12:44:28 +01002054 kfree(ifmgd->extra_ie);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002055 if (len == 0) {
Johannes Berg46900292009-02-15 12:44:28 +01002056 ifmgd->extra_ie = NULL;
2057 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002058 return 0;
2059 }
Johannes Berg46900292009-02-15 12:44:28 +01002060 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2061 if (!ifmgd->extra_ie) {
2062 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002063 return -ENOMEM;
2064 }
Johannes Berg46900292009-02-15 12:44:28 +01002065 memcpy(ifmgd->extra_ie, ie, len);
2066 ifmgd->extra_ie_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002067 return 0;
2068}
2069
2070int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2071{
Johannes Berg9c6bd792008-09-11 00:01:52 +02002072 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2073 sdata->dev->name, reason);
2074
Johannes Berg46900292009-02-15 12:44:28 +01002075 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002076 return -EINVAL;
2077
Johannes Berg46900292009-02-15 12:44:28 +01002078 ieee80211_set_disassoc(sdata, true, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002079 return 0;
2080}
2081
2082int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2083{
Johannes Berg46900292009-02-15 12:44:28 +01002084 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002085
2086 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2087 sdata->dev->name, reason);
2088
Johannes Berg05c914f2008-09-11 00:01:58 +02002089 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002090 return -EINVAL;
2091
Johannes Berg46900292009-02-15 12:44:28 +01002092 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2093 return -ENOLINK;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002094
Johannes Berg46900292009-02-15 12:44:28 +01002095 ieee80211_set_disassoc(sdata, false, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002096 return 0;
2097}
2098
2099/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002100void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2101{
2102 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002103
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 Berg0a51b272008-09-08 17:44:25 +02002109}
Kalle Valo520eb822008-12-18 23:35:27 +02002110
2111void 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
2126void 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 Berg7181d462009-04-15 21:33:15 +02002131 /* XXX: using scan_sdata is completely broken! */
Vivek Natarajana97b77b2008-12-23 18:39:02 -08002132 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Kalle Valo520eb822008-12-18 23:35:27 +02002133
2134 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2135 return;
2136
Johannes Berg7181d462009-04-15 21:33:15 +02002137 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
Johannes Berg4be8c382009-01-07 18:28:20 +01002138 ieee80211_send_nullfunc(local, sdata, 1);
Kalle Valo520eb822008-12-18 23:35:27 +02002139
Johannes Berg4be8c382009-01-07 18:28:20 +01002140 local->hw.conf.flags |= IEEE80211_CONF_PS;
Kalle Valo520eb822008-12-18 23:35:27 +02002141 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2142}
2143
2144void 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 Berg46900292009-02-15 12:44:28 +01002150
2151void 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}