blob: c39a214e7ad0b344888c44864cfbda2898fc3014 [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>
Johannes Berg10f644a2009-04-16 13:17:25 +020020#include <linux/pm_qos_params.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070021#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020022#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020023
Jiri Bencf0706e82007-05-05 11:45:53 -070024#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040025#include "rate.h"
26#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070027
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030028#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070029#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
30#define IEEE80211_AUTH_MAX_TRIES 3
31#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
32#define IEEE80211_ASSOC_MAX_TRIES 3
33#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Kalle Valo15b7b062009-03-22 21:57:14 +020034#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070035#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070036
Johannes Berg5484e232008-09-08 17:44:27 +020037/* utils */
38static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +020039{
Johannes Berg5484e232008-09-08 17:44:27 +020040 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +020041}
42
Johannes Bergc2b13452008-09-11 00:01:55 +020043static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030044{
45 u8 *end, *pos;
46
Johannes Berg00d3f142009-02-10 21:26:00 +010047 pos = bss->cbss.information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030048 if (pos == NULL)
49 return NULL;
Johannes Berg00d3f142009-02-10 21:26:00 +010050 end = pos + bss->cbss.len_information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030051
52 while (pos + 1 < end) {
53 if (pos + 2 + pos[1] > end)
54 break;
55 if (pos[0] == ie)
56 return pos;
57 pos += 2 + pos[1];
58 }
59
60 return NULL;
61}
62
Johannes Bergc2b13452008-09-11 00:01:55 +020063static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
Johannes Berg9ac19a92008-09-09 10:57:09 +020064 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010065 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +020066{
67 int i, j, count;
68 *rates = 0;
69 count = 0;
70 for (i = 0; i < bss->supp_rates_len; i++) {
71 int rate = (bss->supp_rates[i] & 0x7F) * 5;
72
73 for (j = 0; j < sband->n_bitrates; j++)
74 if (sband->bitrates[j].bitrate == rate) {
75 *rates |= BIT(j);
76 count++;
77 break;
78 }
79 }
80
81 return count;
82}
83
Johannes Bergd5522e02009-03-30 13:23:35 +020084/*
85 * ieee80211_enable_ht should be called only after the operating band
86 * has been determined as ht configuration depends on the hw's
87 * HT abilities for a specific band.
88 */
89static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
90 struct ieee80211_ht_info *hti,
91 u16 ap_ht_cap_flags)
92{
93 struct ieee80211_local *local = sdata->local;
94 struct ieee80211_supported_band *sband;
95 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
96 struct ieee80211_bss_ht_conf ht;
97 struct sta_info *sta;
98 u32 changed = 0;
99 bool enable_ht = true, ht_changed;
100 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
101
102 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
103
104 memset(&ht, 0, sizeof(ht));
105
106 /* HT is not supported */
107 if (!sband->ht_cap.ht_supported)
108 enable_ht = false;
109
110 /* check that channel matches the right operating channel */
111 if (local->hw.conf.channel->center_freq !=
112 ieee80211_channel_to_frequency(hti->control_chan))
113 enable_ht = false;
114
115 if (enable_ht) {
116 channel_type = NL80211_CHAN_HT20;
117
118 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
119 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
120 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
121 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
122 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
123 channel_type = NL80211_CHAN_HT40PLUS;
124 break;
125 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
126 channel_type = NL80211_CHAN_HT40MINUS;
127 break;
128 }
129 }
130 }
131
132 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
133 channel_type != local->hw.conf.channel_type;
134
135 local->oper_channel_type = channel_type;
136
137 if (ht_changed) {
138 /* channel_type change automatically detected */
139 ieee80211_hw_config(local, 0);
140
141 rcu_read_lock();
142
143 sta = sta_info_get(local, ifmgd->bssid);
144 if (sta)
145 rate_control_rate_update(local, sband, sta,
146 IEEE80211_RC_HT_CHANGED);
147
148 rcu_read_unlock();
149
150 }
151
152 /* disable HT */
153 if (!enable_ht)
154 return 0;
155
156 ht.operation_mode = le16_to_cpu(hti->operation_mode);
157
158 /* if bss configuration changed store the new one */
159 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
160 changed |= BSS_CHANGED_HT;
161 sdata->vif.bss_conf.ht = ht;
162 }
163
164 return changed;
165}
166
Johannes Berg9c6bd792008-09-11 00:01:52 +0200167/* frame sending functions */
168
Johannes Berg46900292009-02-15 12:44:28 +0100169static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +0200170{
Johannes Berg46900292009-02-15 12:44:28 +0100171 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200172 struct ieee80211_local *local = sdata->local;
173 struct sk_buff *skb;
174 struct ieee80211_mgmt *mgmt;
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200175 u8 *pos, *ies, *ht_ie;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200176 int i, len, count, rates_len, supp_rates_len;
177 u16 capab;
Johannes Bergc2b13452008-09-11 00:01:55 +0200178 struct ieee80211_bss *bss;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200179 int wmm = 0;
180 struct ieee80211_supported_band *sband;
Johannes Berg881d9482009-01-21 15:13:48 +0100181 u32 rates = 0;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200182
183 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Johannes Berg46900292009-02-15 12:44:28 +0100184 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200185 ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200186 if (!skb) {
187 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
188 "frame\n", sdata->dev->name);
189 return;
190 }
191 skb_reserve(skb, local->hw.extra_tx_headroom);
192
193 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
194
Johannes Berg46900292009-02-15 12:44:28 +0100195 capab = ifmgd->capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200196
197 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
198 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
199 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
200 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
201 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
202 }
203
Johannes Berg46900292009-02-15 12:44:28 +0100204 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200205 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100206 ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200207 if (bss) {
Johannes Berg00d3f142009-02-10 21:26:00 +0100208 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200209 capab |= WLAN_CAPABILITY_PRIVACY;
210 if (bss->wmm_used)
211 wmm = 1;
212
213 /* get all rates supported by the device and the AP as
214 * some APs don't like getting a superset of their rates
215 * in the association request (e.g. D-Link DAP 1353 in
216 * b-only mode) */
217 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
218
Johannes Berg00d3f142009-02-10 21:26:00 +0100219 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg9ac19a92008-09-09 10:57:09 +0200220 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
221 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
222
223 ieee80211_rx_bss_put(local, bss);
224 } else {
225 rates = ~0;
226 rates_len = sband->n_bitrates;
227 }
228
229 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
230 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100231 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200232 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100233 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200234
Johannes Berg46900292009-02-15 12:44:28 +0100235 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200236 skb_put(skb, 10);
237 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
238 IEEE80211_STYPE_REASSOC_REQ);
239 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
240 mgmt->u.reassoc_req.listen_interval =
241 cpu_to_le16(local->hw.conf.listen_interval);
Johannes Berg46900292009-02-15 12:44:28 +0100242 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200243 ETH_ALEN);
244 } else {
245 skb_put(skb, 4);
246 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
247 IEEE80211_STYPE_ASSOC_REQ);
248 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
Rami Rosen13554122008-12-16 22:38:29 +0200249 mgmt->u.assoc_req.listen_interval =
Johannes Berg9ac19a92008-09-09 10:57:09 +0200250 cpu_to_le16(local->hw.conf.listen_interval);
251 }
252
253 /* SSID */
Johannes Berg46900292009-02-15 12:44:28 +0100254 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200255 *pos++ = WLAN_EID_SSID;
Johannes Berg46900292009-02-15 12:44:28 +0100256 *pos++ = ifmgd->ssid_len;
257 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200258
259 /* add all rates which were marked to be used above */
260 supp_rates_len = rates_len;
261 if (supp_rates_len > 8)
262 supp_rates_len = 8;
263
264 len = sband->n_bitrates;
265 pos = skb_put(skb, supp_rates_len + 2);
266 *pos++ = WLAN_EID_SUPP_RATES;
267 *pos++ = supp_rates_len;
268
269 count = 0;
270 for (i = 0; i < sband->n_bitrates; i++) {
271 if (BIT(i) & rates) {
272 int rate = sband->bitrates[i].bitrate;
273 *pos++ = (u8) (rate / 5);
274 if (++count == 8)
275 break;
276 }
277 }
278
279 if (rates_len > count) {
280 pos = skb_put(skb, rates_len - count + 2);
281 *pos++ = WLAN_EID_EXT_SUPP_RATES;
282 *pos++ = rates_len - count;
283
284 for (i++; i < sband->n_bitrates; i++) {
285 if (BIT(i) & rates) {
286 int rate = sband->bitrates[i].bitrate;
287 *pos++ = (u8) (rate / 5);
288 }
289 }
290 }
291
292 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
293 /* 1. power capabilities */
294 pos = skb_put(skb, 4);
295 *pos++ = WLAN_EID_PWR_CAPABILITY;
296 *pos++ = 2;
297 *pos++ = 0; /* min tx power */
298 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
299
300 /* 2. supported channels */
301 /* TODO: get this in reg domain format */
302 pos = skb_put(skb, 2 * sband->n_channels + 2);
303 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
304 *pos++ = 2 * sband->n_channels;
305 for (i = 0; i < sband->n_channels; i++) {
306 *pos++ = ieee80211_frequency_to_channel(
307 sband->channels[i].center_freq);
308 *pos++ = 1; /* one channel in the subband*/
309 }
310 }
311
Johannes Berg46900292009-02-15 12:44:28 +0100312 if (ifmgd->extra_ie) {
313 pos = skb_put(skb, ifmgd->extra_ie_len);
314 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200315 }
316
Johannes Berg46900292009-02-15 12:44:28 +0100317 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200318 pos = skb_put(skb, 9);
319 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
320 *pos++ = 7; /* len */
321 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
322 *pos++ = 0x50;
323 *pos++ = 0xf2;
324 *pos++ = 2; /* WME */
325 *pos++ = 0; /* WME info */
326 *pos++ = 1; /* WME ver */
327 *pos++ = 0;
328 }
329
330 /* wmm support is a must to HT */
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530331 /*
332 * IEEE802.11n does not allow TKIP/WEP as pairwise
333 * ciphers in HT mode. We still associate in non-ht
334 * mode (11a/b/g) if any one of these ciphers is
335 * configured as pairwise.
336 */
Johannes Berg46900292009-02-15 12:44:28 +0100337 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200338 sband->ht_cap.ht_supported &&
339 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530340 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
Johannes Berg46900292009-02-15 12:44:28 +0100341 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200342 struct ieee80211_ht_info *ht_info =
343 (struct ieee80211_ht_info *)(ht_ie + 2);
344 u16 cap = sband->ht_cap.cap;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200345 __le16 tmp;
346 u32 flags = local->hw.conf.channel->flags;
347
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200348 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
349 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200350 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200351 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200352 cap &= ~IEEE80211_HT_CAP_SGI_40;
353 }
354 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200355 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200356 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200357 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200358 cap &= ~IEEE80211_HT_CAP_SGI_40;
359 }
360 break;
361 }
362
363 tmp = cpu_to_le16(cap);
364 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
365 *pos++ = WLAN_EID_HT_CAPABILITY;
366 *pos++ = sizeof(struct ieee80211_ht_cap);
367 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
368 memcpy(pos, &tmp, sizeof(u16));
369 pos += sizeof(u16);
370 /* TODO: needs a define here for << 2 */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200371 *pos++ = sband->ht_cap.ampdu_factor |
372 (sband->ht_cap.ampdu_density << 2);
373 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200374 }
375
Johannes Berg46900292009-02-15 12:44:28 +0100376 kfree(ifmgd->assocreq_ies);
377 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
378 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
379 if (ifmgd->assocreq_ies)
380 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200381
Johannes Berge50db652008-09-09 15:07:09 +0200382 ieee80211_tx_skb(sdata, skb, 0);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200383}
384
385
Johannes Bergef422bc2008-09-09 10:58:25 +0200386static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
387 u16 stype, u16 reason)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200388{
389 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100390 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200391 struct sk_buff *skb;
392 struct ieee80211_mgmt *mgmt;
393
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200394 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200395 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200396 printk(KERN_DEBUG "%s: failed to allocate buffer for "
397 "deauth/disassoc frame\n", sdata->dev->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200398 return;
399 }
400 skb_reserve(skb, local->hw.extra_tx_headroom);
401
402 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
403 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100404 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200405 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100406 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200407 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200408 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200409 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200410 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
411
Jouni Malinen53b46b82009-03-27 20:53:56 +0200412 if (stype == IEEE80211_STYPE_DEAUTH)
413 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
414 else
415 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
Johannes Berg46900292009-02-15 12:44:28 +0100416 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200417}
418
Kalle Valo572e0012009-02-10 17:09:31 +0200419void ieee80211_send_pspoll(struct ieee80211_local *local,
420 struct ieee80211_sub_if_data *sdata)
421{
Johannes Berg46900292009-02-15 12:44:28 +0100422 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Kalle Valo572e0012009-02-10 17:09:31 +0200423 struct ieee80211_pspoll *pspoll;
424 struct sk_buff *skb;
425 u16 fc;
426
427 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
428 if (!skb) {
429 printk(KERN_DEBUG "%s: failed to allocate buffer for "
430 "pspoll frame\n", sdata->dev->name);
431 return;
432 }
433 skb_reserve(skb, local->hw.extra_tx_headroom);
434
435 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
436 memset(pspoll, 0, sizeof(*pspoll));
437 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
438 pspoll->frame_control = cpu_to_le16(fc);
Johannes Berg46900292009-02-15 12:44:28 +0100439 pspoll->aid = cpu_to_le16(ifmgd->aid);
Kalle Valo572e0012009-02-10 17:09:31 +0200440
441 /* aid in PS-Poll has its two MSBs each set to 1 */
442 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
443
Johannes Berg46900292009-02-15 12:44:28 +0100444 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
Kalle Valo572e0012009-02-10 17:09:31 +0200445 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
446
447 ieee80211_tx_skb(sdata, skb, 0);
Kalle Valo572e0012009-02-10 17:09:31 +0200448}
449
Johannes Berg965beda2009-04-16 13:17:24 +0200450void ieee80211_send_nullfunc(struct ieee80211_local *local,
451 struct ieee80211_sub_if_data *sdata,
452 int powersave)
453{
454 struct sk_buff *skb;
455 struct ieee80211_hdr *nullfunc;
456 __le16 fc;
457
458 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
459 return;
460
461 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
462 if (!skb) {
463 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
464 "frame\n", sdata->dev->name);
465 return;
466 }
467 skb_reserve(skb, local->hw.extra_tx_headroom);
468
469 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
470 memset(nullfunc, 0, 24);
471 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
472 IEEE80211_FCTL_TODS);
473 if (powersave)
474 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
475 nullfunc->frame_control = fc;
476 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
477 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
478 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
479
480 ieee80211_tx_skb(sdata, skb, 0);
481}
482
483/* powersave */
484static void ieee80211_enable_ps(struct ieee80211_local *local,
485 struct ieee80211_sub_if_data *sdata)
486{
487 struct ieee80211_conf *conf = &local->hw.conf;
488
489 if (conf->dynamic_ps_timeout > 0 &&
490 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
491 mod_timer(&local->dynamic_ps_timer, jiffies +
492 msecs_to_jiffies(conf->dynamic_ps_timeout));
493 } else {
494 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
495 ieee80211_send_nullfunc(local, sdata, 1);
496 conf->flags |= IEEE80211_CONF_PS;
497 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
498 }
499}
500
501static void ieee80211_change_ps(struct ieee80211_local *local)
502{
503 struct ieee80211_conf *conf = &local->hw.conf;
504
505 if (local->ps_sdata) {
506 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
507 return;
508
509 ieee80211_enable_ps(local, local->ps_sdata);
510 } else if (conf->flags & IEEE80211_CONF_PS) {
511 conf->flags &= ~IEEE80211_CONF_PS;
512 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
513 del_timer_sync(&local->dynamic_ps_timer);
514 cancel_work_sync(&local->dynamic_ps_enable_work);
515 }
516}
517
518/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200519void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200520{
521 struct ieee80211_sub_if_data *sdata, *found = NULL;
522 int count = 0;
523
524 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
525 local->ps_sdata = NULL;
526 return;
527 }
528
529 list_for_each_entry(sdata, &local->interfaces, list) {
530 if (!netif_running(sdata->dev))
531 continue;
532 if (sdata->vif.type != NL80211_IFTYPE_STATION)
533 continue;
534 found = sdata;
535 count++;
536 }
537
Johannes Berg10f644a2009-04-16 13:17:25 +0200538 if (count == 1 && found->u.mgd.powersave) {
539 s32 beaconint_us;
540
541 if (latency < 0)
542 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
543
544 beaconint_us = ieee80211_tu_to_usec(
545 found->vif.bss_conf.beacon_int);
546
547 if (beaconint_us > latency)
548 local->ps_sdata = NULL;
549 else
550 local->ps_sdata = found;
551 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200552 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200553 }
Johannes Berg965beda2009-04-16 13:17:24 +0200554
555 ieee80211_change_ps(local);
556}
557
558void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
559{
560 struct ieee80211_local *local =
561 container_of(work, struct ieee80211_local,
562 dynamic_ps_disable_work);
563
564 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
565 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
566 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
567 }
568
569 ieee80211_wake_queues_by_reason(&local->hw,
570 IEEE80211_QUEUE_STOP_REASON_PS);
571}
572
573void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
574{
575 struct ieee80211_local *local =
576 container_of(work, struct ieee80211_local,
577 dynamic_ps_enable_work);
578 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
579
580 /* can only happen when PS was just disabled anyway */
581 if (!sdata)
582 return;
583
584 if (local->hw.conf.flags & IEEE80211_CONF_PS)
585 return;
586
587 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
588 ieee80211_send_nullfunc(local, sdata, 1);
589
590 local->hw.conf.flags |= IEEE80211_CONF_PS;
591 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
592}
593
594void ieee80211_dynamic_ps_timer(unsigned long data)
595{
596 struct ieee80211_local *local = (void *) data;
597
598 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
599}
600
Johannes Berg60f8b392008-09-08 17:44:22 +0200601/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200602static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100603 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700604 u8 *wmm_param, size_t wmm_param_len)
605{
Jiri Bencf0706e82007-05-05 11:45:53 -0700606 struct ieee80211_tx_queue_params params;
607 size_t left;
608 int count;
609 u8 *pos;
610
Johannes Berg46900292009-02-15 12:44:28 +0100611 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200612 return;
613
614 if (!wmm_param)
615 return;
616
Jiri Bencf0706e82007-05-05 11:45:53 -0700617 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
618 return;
619 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100620 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700621 return;
Johannes Berg46900292009-02-15 12:44:28 +0100622 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700623
624 pos = wmm_param + 8;
625 left = wmm_param_len - 8;
626
627 memset(&params, 0, sizeof(params));
628
Jiri Bencf0706e82007-05-05 11:45:53 -0700629 local->wmm_acm = 0;
630 for (; left >= 4; left -= 4, pos += 4) {
631 int aci = (pos[0] >> 5) & 0x03;
632 int acm = (pos[0] >> 4) & 0x01;
633 int queue;
634
635 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200636 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200637 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200638 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200639 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700640 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200641 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200642 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200643 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200644 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700645 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200646 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200647 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200648 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200649 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700650 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200651 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700652 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200653 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200654 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200655 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700656 break;
657 }
658
659 params.aifs = pos[0] & 0x0f;
660 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
661 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200662 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200663#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700664 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100665 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200666 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100667 params.cw_max, params.txop);
668#endif
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200669 if (local->ops->conf_tx &&
670 local->ops->conf_tx(local_to_hw(local), queue, &params)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700671 printk(KERN_DEBUG "%s: failed to set TX queue "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200672 "parameters for queue %d\n", local->mdev->name, queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700673 }
674 }
675}
676
Kalle Valo1fb36062009-02-10 17:09:24 +0200677static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800678{
679 u8 mask;
680 u8 index, indexn1, indexn2;
681 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
682
Johannes Berg60375542009-04-17 00:54:23 +0200683 if (unlikely(!tim || elems->tim_len < 4))
684 return false;
685
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800686 aid &= 0x3fff;
687 index = aid / 8;
688 mask = 1 << (aid & 7);
689
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800690 indexn1 = tim->bitmap_ctrl & 0xfe;
691 indexn2 = elems->tim_len + indexn1 - 4;
692
693 if (index < indexn1 || index > indexn2)
694 return false;
695
696 index -= indexn1;
697
698 return !!(tim->virtual_map[index] & mask);
699}
700
Johannes Berg7a5158e2008-10-08 10:59:33 +0200701static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
702 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200703{
Johannes Bergbda39332008-10-11 01:51:51 +0200704 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300705#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg46900292009-02-15 12:44:28 +0100706 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winklerebd74482008-07-01 10:44:50 +0300707#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100708 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200709 bool use_protection;
710 bool use_short_preamble;
711 bool use_short_slot;
712
713 if (erp_valid) {
714 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
715 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
716 } else {
717 use_protection = false;
718 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
719 }
720
721 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Daniel Drake56282212007-07-10 19:32:10 +0200722
Johannes Berg471b3ef2007-12-28 14:32:58 +0100723 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200724#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200725 if (net_ratelimit()) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700726 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100727 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200728 use_protection ? "enabled" : "disabled",
Johannes Berg46900292009-02-15 12:44:28 +0100729 ifmgd->bssid);
Daniel Drake56282212007-07-10 19:32:10 +0200730 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200731#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100732 bss_conf->use_cts_prot = use_protection;
733 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200734 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200735
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200736 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200737#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200738 if (net_ratelimit()) {
739 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Johannes Berg0c68ae262008-10-27 15:56:10 -0700740 " (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100741 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200742 use_short_preamble ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100743 ifmgd->bssid);
Daniel Drake7e9ed182007-07-27 15:43:24 +0200744 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200745#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200746 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100747 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200748 }
Daniel Draked9430a32007-07-27 15:43:24 +0200749
Johannes Berg7a5158e2008-10-08 10:59:33 +0200750 if (use_short_slot != bss_conf->use_short_slot) {
751#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
752 if (net_ratelimit()) {
Christian Lamparter391429c2009-01-18 02:24:15 +0100753 printk(KERN_DEBUG "%s: switched to %s slot time"
754 " (BSSID=%pM)\n",
Johannes Berg7a5158e2008-10-08 10:59:33 +0200755 sdata->dev->name,
756 use_short_slot ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100757 ifmgd->bssid);
Johannes Berg7a5158e2008-10-08 10:59:33 +0200758 }
759#endif
760 bss_conf->use_short_slot = use_short_slot;
761 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400762 }
763
764 return changed;
765}
766
Johannes Berg46900292009-02-15 12:44:28 +0100767static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200768{
769 union iwreq_data wrqu;
Johannes Berg46900292009-02-15 12:44:28 +0100770
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200771 memset(&wrqu, 0, sizeof(wrqu));
Johannes Berg46900292009-02-15 12:44:28 +0100772 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
773 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200774 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
775 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
776}
777
Johannes Berg46900292009-02-15 12:44:28 +0100778static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700779{
Johannes Berg46900292009-02-15 12:44:28 +0100780 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Linus Torvalds74af0252008-09-05 12:38:09 -0700781 char *buf;
782 size_t len;
783 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700784 union iwreq_data wrqu;
785
Johannes Berg46900292009-02-15 12:44:28 +0100786 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700787 return;
788
Johannes Berg46900292009-02-15 12:44:28 +0100789 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
790 ifmgd->assocresp_ies_len), GFP_KERNEL);
Linus Torvalds74af0252008-09-05 12:38:09 -0700791 if (!buf)
792 return;
793
794 len = sprintf(buf, "ASSOCINFO(");
Johannes Berg46900292009-02-15 12:44:28 +0100795 if (ifmgd->assocreq_ies) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700796 len += sprintf(buf + len, "ReqIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100797 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700798 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100799 ifmgd->assocreq_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700800 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700801 }
Johannes Berg46900292009-02-15 12:44:28 +0100802 if (ifmgd->assocresp_ies) {
803 if (ifmgd->assocreq_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700804 len += sprintf(buf + len, " ");
805 len += sprintf(buf + len, "RespIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100806 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700807 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100808 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700809 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700810 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700811 len += sprintf(buf + len, ")");
812
813 if (len > IW_CUSTOM_MAX) {
814 len = sprintf(buf, "ASSOCRESPIE=");
Johannes Berg46900292009-02-15 12:44:28 +0100815 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700816 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100817 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700818 }
819 }
820
John W. Linvillead788b52008-10-01 15:45:02 -0400821 if (len <= IW_CUSTOM_MAX) {
822 memset(&wrqu, 0, sizeof(wrqu));
823 wrqu.data.length = len;
824 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
825 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700826
827 kfree(buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700828}
829
830
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200831static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Bergae5eb022008-10-14 16:58:37 +0200832 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700833{
Johannes Berg46900292009-02-15 12:44:28 +0100834 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100835 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700836 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700837
Johannes Bergc2b13452008-09-11 00:01:55 +0200838 struct ieee80211_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400839
Johannes Bergae5eb022008-10-14 16:58:37 +0200840 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg46900292009-02-15 12:44:28 +0100841 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400842
Johannes Berg46900292009-02-15 12:44:28 +0100843 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200844 conf->channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100845 ifmgd->ssid, ifmgd->ssid_len);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200846 if (bss) {
847 /* set timing information */
Johannes Berg00d3f142009-02-10 21:26:00 +0100848 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
849 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
Johannes Bergbda39332008-10-11 01:51:51 +0200850 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700851
Johannes Bergae5eb022008-10-14 16:58:37 +0200852 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg00d3f142009-02-10 21:26:00 +0100853 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700854
Kalle Valo04de8382009-03-22 21:57:35 +0200855 cfg80211_hold_bss(&bss->cbss);
856
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200857 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700858 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100859
Johannes Berg46900292009-02-15 12:44:28 +0100860 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
861 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
862 ieee80211_sta_send_associnfo(sdata);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200863
Johannes Berg46900292009-02-15 12:44:28 +0100864 ifmgd->last_probe = jiffies;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200865 ieee80211_led_assoc(local, 1);
866
Johannes Bergbda39332008-10-11 01:51:51 +0200867 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200868 /*
869 * For now just always ask the driver to update the basic rateset
870 * when we have associated, we aren't checking whether it actually
871 * changed or not.
872 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200873 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
874 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300875
Johannes Berg965beda2009-04-16 13:17:24 +0200876 /* will be same as sdata */
877 if (local->ps_sdata)
878 ieee80211_enable_ps(local, sdata);
Kalle Valoe0cb6862008-12-18 23:35:13 +0200879
Tomas Winkler24e64622008-09-08 17:33:40 +0200880 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200881 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300882
Johannes Berg46900292009-02-15 12:44:28 +0100883 ieee80211_sta_send_apinfo(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700884}
885
Johannes Berg46900292009-02-15 12:44:28 +0100886static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300887{
Johannes Berg46900292009-02-15 12:44:28 +0100888 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100889 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100890
891 ifmgd->direct_probe_tries++;
892 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700893 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100894 sdata->dev->name, ifmgd->bssid);
895 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
896 ieee80211_sta_send_apinfo(sdata);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530897
898 /*
899 * Most likely AP is not in the range so remove the
900 * bss information associated to the AP
901 */
Johannes Berg46900292009-02-15 12:44:28 +0100902 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530903 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100904 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100905
906 /*
907 * We might have a pending scan which had no chance to run yet
908 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
909 * Hence, queue the STAs work again
910 */
911 queue_work(local->hw.workqueue, &ifmgd->work);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300912 return;
913 }
914
Johannes Berg0c68ae262008-10-27 15:56:10 -0700915 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
Johannes Berg46900292009-02-15 12:44:28 +0100916 sdata->dev->name, ifmgd->bssid,
917 ifmgd->direct_probe_tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300918
Johannes Berg46900292009-02-15 12:44:28 +0100919 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300920
Johannes Berg46900292009-02-15 12:44:28 +0100921 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300922
923 /* Direct probe is sent to broadcast address as some APs
924 * will not answer to direct packet in unassociated state.
925 */
926 ieee80211_send_probe_req(sdata, NULL,
Jouni Malinen70692ad2009-02-16 19:39:13 +0200927 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300928
Johannes Berg46900292009-02-15 12:44:28 +0100929 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300930}
931
Jiri Bencf0706e82007-05-05 11:45:53 -0700932
Johannes Berg46900292009-02-15 12:44:28 +0100933static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700934{
Johannes Berg46900292009-02-15 12:44:28 +0100935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100936 struct ieee80211_local *local = sdata->local;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200937 u8 *ies;
938 size_t ies_len;
Johannes Berg46900292009-02-15 12:44:28 +0100939
940 ifmgd->auth_tries++;
941 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700942 printk(KERN_DEBUG "%s: authentication with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700943 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100944 sdata->dev->name, ifmgd->bssid);
945 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
946 ieee80211_sta_send_apinfo(sdata);
947 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530948 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100949 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100950
951 /*
952 * We might have a pending scan which had no chance to run yet
953 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
954 * Hence, queue the STAs work again
955 */
956 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700957 return;
958 }
959
Johannes Berg46900292009-02-15 12:44:28 +0100960 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700961 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100962 sdata->dev->name, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700963
Jouni Malinen636a5d32009-03-19 13:39:22 +0200964 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
965 ies = ifmgd->sme_auth_ie;
966 ies_len = ifmgd->sme_auth_ie_len;
967 } else {
968 ies = NULL;
969 ies_len = 0;
970 }
971 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
Johannes Berg46900292009-02-15 12:44:28 +0100972 ifmgd->bssid, 0);
973 ifmgd->auth_transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700974
Johannes Berg46900292009-02-15 12:44:28 +0100975 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700976}
977
Vivek Natarajan5925d972008-11-21 22:19:50 -0800978/*
979 * The disassoc 'reason' argument can be either our own reason
980 * if self disconnected or a reason code from the AP.
981 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300982static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg46900292009-02-15 12:44:28 +0100983 bool deauth, bool self_disconnected,
984 u16 reason)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300985{
Johannes Berg46900292009-02-15 12:44:28 +0100986 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300987 struct ieee80211_local *local = sdata->local;
Kalle Valo04de8382009-03-22 21:57:35 +0200988 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
989 struct ieee80211_bss *bss;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300990 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200991 u32 changed = 0, config_changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300992
993 rcu_read_lock();
994
Johannes Berg46900292009-02-15 12:44:28 +0100995 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300996 if (!sta) {
997 rcu_read_unlock();
998 return;
999 }
1000
1001 if (deauth) {
Johannes Berg46900292009-02-15 12:44:28 +01001002 ifmgd->direct_probe_tries = 0;
1003 ifmgd->auth_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001004 }
Johannes Berg46900292009-02-15 12:44:28 +01001005 ifmgd->assoc_scan_tries = 0;
1006 ifmgd->assoc_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001007
Tomas Winkler24e64622008-09-08 17:33:40 +02001008 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001009 netif_carrier_off(sdata->dev);
1010
Johannes Berg2dace102009-02-10 21:25:52 +01001011 ieee80211_sta_tear_down_BA_sessions(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001012
Kalle Valo04de8382009-03-22 21:57:35 +02001013 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1014 conf->channel->center_freq,
1015 ifmgd->ssid, ifmgd->ssid_len);
1016
1017 if (bss) {
1018 cfg80211_unhold_bss(&bss->cbss);
1019 ieee80211_rx_bss_put(local, bss);
1020 }
1021
Tomas Winkleraa458d12008-09-09 00:32:12 +03001022 if (self_disconnected) {
1023 if (deauth)
Johannes Bergef422bc2008-09-09 10:58:25 +02001024 ieee80211_send_deauth_disassoc(sdata,
1025 IEEE80211_STYPE_DEAUTH, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001026 else
Johannes Bergef422bc2008-09-09 10:58:25 +02001027 ieee80211_send_deauth_disassoc(sdata,
1028 IEEE80211_STYPE_DISASSOC, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001029 }
1030
Johannes Berg46900292009-02-15 12:44:28 +01001031 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001032 changed |= ieee80211_reset_erp_info(sdata);
1033
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001034 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001035 changed |= BSS_CHANGED_ASSOC;
1036 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001037
Johannes Berg46900292009-02-15 12:44:28 +01001038 ieee80211_sta_send_apinfo(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001039
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301040 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
Johannes Berg46900292009-02-15 12:44:28 +01001041 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1042 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301043 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001044 ifmgd->ssid, ifmgd->ssid_len);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301045 }
Tomas Winkleraa458d12008-09-09 00:32:12 +03001046
Tomas Winkleraa458d12008-09-09 00:32:12 +03001047 rcu_read_unlock();
1048
Johannes Berg47979382009-01-07 10:13:27 +01001049 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +05301050 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001051
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301052 local->power_constr_level = 0;
1053
Kalle Valo520eb822008-12-18 23:35:27 +02001054 del_timer_sync(&local->dynamic_ps_timer);
1055 cancel_work_sync(&local->dynamic_ps_enable_work);
1056
Kalle Valoe0cb6862008-12-18 23:35:13 +02001057 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1058 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1059 config_changed |= IEEE80211_CONF_CHANGE_PS;
1060 }
1061
1062 ieee80211_hw_config(local, config_changed);
Johannes Bergae5eb022008-10-14 16:58:37 +02001063 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001064
1065 rcu_read_lock();
1066
Johannes Berg46900292009-02-15 12:44:28 +01001067 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001068 if (!sta) {
1069 rcu_read_unlock();
1070 return;
1071 }
1072
1073 sta_info_unlink(&sta);
1074
1075 rcu_read_unlock();
1076
1077 sta_info_destroy(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001078}
Jiri Bencf0706e82007-05-05 11:45:53 -07001079
Johannes Berg9ac19a92008-09-09 10:57:09 +02001080static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
1081{
1082 if (!sdata || !sdata->default_key ||
1083 sdata->default_key->conf.alg != ALG_WEP)
1084 return 0;
1085 return 1;
1086}
1087
Johannes Berg46900292009-02-15 12:44:28 +01001088static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001089{
Johannes Berg46900292009-02-15 12:44:28 +01001090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001091 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001092 struct ieee80211_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001093 int bss_privacy;
1094 int wep_privacy;
1095 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -07001096
Johannes Berg7986cf92009-03-21 17:08:43 +01001097 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
Jiri Bencf0706e82007-05-05 11:45:53 -07001098 return 0;
1099
Johannes Berg46900292009-02-15 12:44:28 +01001100 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01001101 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001102 ifmgd->ssid, ifmgd->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001103 if (!bss)
1104 return 0;
1105
Johannes Berg00d3f142009-02-10 21:26:00 +01001106 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001107 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001108 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001109
Johannes Berg3e122be2008-07-09 14:40:34 +02001110 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001111
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001112 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1113 return 0;
1114
1115 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001116}
1117
Johannes Berg46900292009-02-15 12:44:28 +01001118static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001119{
Johannes Berg46900292009-02-15 12:44:28 +01001120 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001121 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001122
1123 ifmgd->assoc_tries++;
1124 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001125 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +01001127 sdata->dev->name, ifmgd->bssid);
1128 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1129 ieee80211_sta_send_apinfo(sdata);
1130 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301131 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001132 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +01001133 /*
1134 * We might have a pending scan which had no chance to run yet
1135 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
1136 * Hence, queue the STAs work again
1137 */
1138 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001139 return;
1140 }
1141
Johannes Berg46900292009-02-15 12:44:28 +01001142 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -07001143 printk(KERN_DEBUG "%s: associate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001144 sdata->dev->name, ifmgd->bssid);
1145 if (ieee80211_privacy_mismatch(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001146 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001147 "mixed-cell disabled - abort association\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001148 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001149 return;
1150 }
1151
Johannes Berg46900292009-02-15 12:44:28 +01001152 ieee80211_send_assoc(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001153
Johannes Berg46900292009-02-15 12:44:28 +01001154 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -07001155}
1156
Kalle Valo3cf335d2009-03-22 21:57:06 +02001157void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1158 struct ieee80211_hdr *hdr)
1159{
1160 /*
1161 * We can postpone the mgd.timer whenever receiving unicast frames
1162 * from AP because we know that the connection is working both ways
1163 * at that time. But multicast frames (and hence also beacons) must
1164 * be ignored here, because we need to trigger the timer during
1165 * data idle periods for sending the periodical probe request to
1166 * the AP.
1167 */
1168 if (!is_multicast_ether_addr(hdr->addr1))
1169 mod_timer(&sdata->u.mgd.timer,
1170 jiffies + IEEE80211_MONITORING_INTERVAL);
1171}
Jiri Bencf0706e82007-05-05 11:45:53 -07001172
Kalle Valo04de8382009-03-22 21:57:35 +02001173void ieee80211_beacon_loss_work(struct work_struct *work)
1174{
1175 struct ieee80211_sub_if_data *sdata =
1176 container_of(work, struct ieee80211_sub_if_data,
1177 u.mgd.beacon_loss_work);
1178 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1179
Michael Buescha8604022009-04-15 14:41:22 -04001180#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1181 if (net_ratelimit()) {
1182 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
1183 "- sending probe request\n", sdata->dev->name,
1184 sdata->u.mgd.bssid);
1185 }
1186#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001187
1188 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1189 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1190 ifmgd->ssid_len, NULL, 0);
1191
1192 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
1193}
1194
1195void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1196{
1197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1198
1199 queue_work(sdata->local->hw.workqueue,
1200 &sdata->u.mgd.beacon_loss_work);
1201}
1202EXPORT_SYMBOL(ieee80211_beacon_loss);
1203
Johannes Berg46900292009-02-15 12:44:28 +01001204static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001205{
Johannes Berg46900292009-02-15 12:44:28 +01001206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001207 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001208 struct sta_info *sta;
Kalle Valo15b7b062009-03-22 21:57:14 +02001209 bool disassoc = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001210
1211 /* TODO: start monitoring current AP signal quality and number of
1212 * missed beacons. Scan other channels every now and then and search
1213 * for better APs. */
1214 /* TODO: remove expired BSSes */
1215
Johannes Berg46900292009-02-15 12:44:28 +01001216 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001217
Johannes Bergd0709a62008-02-25 16:27:46 +01001218 rcu_read_lock();
1219
Johannes Berg46900292009-02-15 12:44:28 +01001220 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001221 if (!sta) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001222 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001223 sdata->dev->name, ifmgd->bssid);
Kalle Valo15b7b062009-03-22 21:57:14 +02001224 disassoc = true;
1225 goto unlock;
Jiri Bencf0706e82007-05-05 11:45:53 -07001226 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001227
Kalle Valo15b7b062009-03-22 21:57:14 +02001228 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1229 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
1230 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1231 "- disassociating\n",
1232 sdata->dev->name, ifmgd->bssid);
1233 disassoc = true;
1234 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1235 goto unlock;
1236 }
1237
Kalle Valo04de8382009-03-22 21:57:35 +02001238 /*
1239 * Beacon filtering is only enabled with power save and then the
1240 * stack should not check for beacon loss.
1241 */
1242 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1243 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1244 time_after(jiffies,
Kalle Valo15b7b062009-03-22 21:57:14 +02001245 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
Michael Buescha8604022009-04-15 14:41:22 -04001246#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1247 if (net_ratelimit()) {
1248 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1249 "- sending probe request\n",
1250 sdata->dev->name, ifmgd->bssid);
1251 }
1252#endif
Kalle Valo15b7b062009-03-22 21:57:14 +02001253 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1254 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1255 ifmgd->ssid_len, NULL, 0);
1256 goto unlock;
1257
1258 }
1259
1260 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1261 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1262 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1263 ifmgd->ssid_len, NULL, 0);
1264 }
1265
1266 unlock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001267 rcu_read_unlock();
1268
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301269 if (disassoc)
Johannes Berg46900292009-02-15 12:44:28 +01001270 ieee80211_set_disassoc(sdata, true, true,
Tomas Winkleraa458d12008-09-09 00:32:12 +03001271 WLAN_REASON_PREV_AUTH_NOT_VALID);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301272 else
Johannes Berg46900292009-02-15 12:44:28 +01001273 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001274 IEEE80211_MONITORING_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001275}
1276
1277
Johannes Berg46900292009-02-15 12:44:28 +01001278static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001279{
Johannes Berg46900292009-02-15 12:44:28 +01001280 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1281
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001282 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001283 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001284 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1285 /* Wait for SME to request association */
1286 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1287 } else
1288 ieee80211_associate(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001289}
1290
1291
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001292static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001293 struct ieee80211_mgmt *mgmt,
1294 size_t len)
1295{
1296 u8 *pos;
1297 struct ieee802_11_elems elems;
1298
Jiri Bencf0706e82007-05-05 11:45:53 -07001299 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001300 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001301 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001302 return;
Johannes Berg46900292009-02-15 12:44:28 +01001303 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1304 elems.challenge - 2, elems.challenge_len + 2,
1305 sdata->u.mgd.bssid, 1);
1306 sdata->u.mgd.auth_transaction = 4;
Johannes Bergfe3d2c32009-02-10 21:26:03 +01001307}
1308
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001309static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001310 struct ieee80211_mgmt *mgmt,
1311 size_t len)
1312{
Johannes Berg46900292009-02-15 12:44:28 +01001313 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001314 u16 auth_alg, auth_transaction, status_code;
1315
Johannes Berg46900292009-02-15 12:44:28 +01001316 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001317 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001318
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001319 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001320 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001321
Johannes Berg46900292009-02-15 12:44:28 +01001322 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001323 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001324
Johannes Berg46900292009-02-15 12:44:28 +01001325 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001326 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001327
1328 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1329 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1330 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1331
Johannes Berg46900292009-02-15 12:44:28 +01001332 if (auth_alg != ifmgd->auth_alg ||
1333 auth_transaction != ifmgd->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001334 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001335
1336 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001337 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1338 u8 algs[3];
1339 const int num_algs = ARRAY_SIZE(algs);
1340 int i, pos;
1341 algs[0] = algs[1] = algs[2] = 0xff;
Johannes Berg46900292009-02-15 12:44:28 +01001342 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001343 algs[0] = WLAN_AUTH_OPEN;
Johannes Berg46900292009-02-15 12:44:28 +01001344 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001345 algs[1] = WLAN_AUTH_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001346 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001347 algs[2] = WLAN_AUTH_LEAP;
Johannes Berg46900292009-02-15 12:44:28 +01001348 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001349 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001350 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001351 pos = 1;
1352 else
1353 pos = 2;
1354 for (i = 0; i < num_algs; i++) {
1355 pos++;
1356 if (pos >= num_algs)
1357 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001358 if (algs[pos] == ifmgd->auth_alg ||
Jiri Bencf0706e82007-05-05 11:45:53 -07001359 algs[pos] == 0xff)
1360 continue;
1361 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001362 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001363 continue;
Johannes Berg46900292009-02-15 12:44:28 +01001364 ifmgd->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001365 break;
1366 }
1367 }
1368 return;
1369 }
1370
Johannes Berg46900292009-02-15 12:44:28 +01001371 switch (ifmgd->auth_alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001372 case WLAN_AUTH_OPEN:
1373 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001374 case WLAN_AUTH_FT:
Johannes Berg46900292009-02-15 12:44:28 +01001375 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001376 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001377 break;
1378 case WLAN_AUTH_SHARED_KEY:
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001379 if (ifmgd->auth_transaction == 4) {
Johannes Berg46900292009-02-15 12:44:28 +01001380 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001381 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1382 } else
Johannes Berg46900292009-02-15 12:44:28 +01001383 ieee80211_auth_challenge(sdata, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001384 break;
1385 }
1386}
1387
1388
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001389static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001390 struct ieee80211_mgmt *mgmt,
1391 size_t len)
1392{
Johannes Berg46900292009-02-15 12:44:28 +01001393 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001394 u16 reason_code;
1395
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001396 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001397 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001398
Johannes Berg46900292009-02-15 12:44:28 +01001399 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001400 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001401
1402 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1403
Johannes Berg46900292009-02-15 12:44:28 +01001404 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001405 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1406 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001407
Jouni Malinen636a5d32009-03-19 13:39:22 +02001408 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1409 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1410 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1411 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
Johannes Berg46900292009-02-15 12:44:28 +01001412 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1413 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001414 IEEE80211_RETRY_AUTH_INTERVAL);
1415 }
1416
Johannes Berg46900292009-02-15 12:44:28 +01001417 ieee80211_set_disassoc(sdata, true, false, 0);
1418 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jouni Malinen53b46b82009-03-27 20:53:56 +02001419 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001420}
1421
1422
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001423static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001424 struct ieee80211_mgmt *mgmt,
1425 size_t len)
1426{
Johannes Berg46900292009-02-15 12:44:28 +01001427 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001428 u16 reason_code;
1429
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001430 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001431 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001432
Johannes Berg46900292009-02-15 12:44:28 +01001433 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001434 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001435
1436 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1437
Johannes Berg46900292009-02-15 12:44:28 +01001438 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001439 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1440 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001441
Jouni Malinen636a5d32009-03-19 13:39:22 +02001442 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1443 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
Johannes Berg46900292009-02-15 12:44:28 +01001444 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1445 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001446 IEEE80211_RETRY_AUTH_INTERVAL);
1447 }
1448
Johannes Berg46900292009-02-15 12:44:28 +01001449 ieee80211_set_disassoc(sdata, false, false, reason_code);
Jouni Malinen53b46b82009-03-27 20:53:56 +02001450 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001451}
1452
1453
Johannes Berg471b3ef2007-12-28 14:32:58 +01001454static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001455 struct ieee80211_mgmt *mgmt,
1456 size_t len,
1457 int reassoc)
1458{
Johannes Berg46900292009-02-15 12:44:28 +01001459 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001460 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001461 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001462 struct sta_info *sta;
Johannes Berg881d9482009-01-21 15:13:48 +01001463 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001464 u16 capab_info, status_code, aid;
1465 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001466 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001467 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001468 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001469 int i, j;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001470 bool have_higher_than_11mbit = false, newsta = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001471 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001472
1473 /* AssocResp and ReassocResp have identical structure, so process both
1474 * of them in this function. */
1475
Johannes Berg46900292009-02-15 12:44:28 +01001476 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001477 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001478
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001479 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001480 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001481
Johannes Berg46900292009-02-15 12:44:28 +01001482 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001483 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001484
1485 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1486 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1487 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001488
Johannes Berg0c68ae262008-10-27 15:56:10 -07001489 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001490 "status=%d aid=%d)\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001491 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001492 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001493
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001494 pos = mgmt->u.assoc_resp.variable;
1495 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1496
1497 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Jouni Malinenf797eb72009-01-19 18:48:46 +02001498 elems.timeout_int && elems.timeout_int_len == 5 &&
1499 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001500 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001501 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001502 ms = tu * 1024 / 1000;
1503 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1504 "comeback duration %u TU (%u ms)\n",
1505 sdata->dev->name, tu, ms);
1506 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg46900292009-02-15 12:44:28 +01001507 mod_timer(&ifmgd->timer,
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001508 jiffies + msecs_to_jiffies(ms));
1509 return;
1510 }
1511
Jiri Bencf0706e82007-05-05 11:45:53 -07001512 if (status_code != WLAN_STATUS_SUCCESS) {
1513 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001514 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001515 /* if this was a reassociation, ensure we try a "full"
1516 * association next time. This works around some broken APs
1517 * which do not correctly reject reassociation requests. */
Johannes Berg46900292009-02-15 12:44:28 +01001518 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jouni Malinen66174bb2009-04-01 17:23:54 +03001519 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1520 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1521 /* Wait for SME to decide what to do next */
1522 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1523 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001524 return;
1525 }
1526
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001527 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1528 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001529 "set\n", sdata->dev->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001530 aid &= ~(BIT(15) | BIT(14));
1531
Jiri Bencf0706e82007-05-05 11:45:53 -07001532 if (!elems.supp_rates) {
1533 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001534 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001535 return;
1536 }
1537
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001538 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001539 ifmgd->aid = aid;
1540 ifmgd->ap_capab = capab_info;
Jiri Bencf0706e82007-05-05 11:45:53 -07001541
Johannes Berg46900292009-02-15 12:44:28 +01001542 kfree(ifmgd->assocresp_ies);
1543 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1544 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1545 if (ifmgd->assocresp_ies)
1546 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001547
Johannes Bergd0709a62008-02-25 16:27:46 +01001548 rcu_read_lock();
1549
Jiri Bencf0706e82007-05-05 11:45:53 -07001550 /* Add STA entry for the AP */
Johannes Berg46900292009-02-15 12:44:28 +01001551 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001552 if (!sta) {
Johannes Bergddf4ac52008-10-22 11:41:38 +02001553 newsta = true;
Johannes Bergd0709a62008-02-25 16:27:46 +01001554
Johannes Berg46900292009-02-15 12:44:28 +01001555 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
Johannes Berg73651ee2008-02-25 16:27:47 +01001556 if (!sta) {
1557 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001558 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001559 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001560 return;
1561 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001562
Ron Rindjunskya61dae12008-08-10 00:54:34 +03001563 /* update new sta with its last rx activity */
1564 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07001565 }
1566
Johannes Berg73651ee2008-02-25 16:27:47 +01001567 /*
1568 * FIXME: Do we really need to update the sta_info's information here?
1569 * We already know about the AP (we found it in our list) so it
1570 * should already be filled with the right info, no?
1571 * As is stands, all this is racy because typically we assume
1572 * the information that is filled in here (except flags) doesn't
1573 * change while a STA structure is alive. As such, it should move
1574 * to between the sta_info_alloc() and sta_info_insert() above.
1575 */
1576
Johannes Berg07346f812008-05-03 01:02:02 +02001577 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1578 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001579
1580 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001581 basic_rates = 0;
1582 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1583
Jiri Bencf0706e82007-05-05 11:45:53 -07001584 for (i = 0; i < elems.supp_rates_len; i++) {
1585 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001586 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001587
1588 if (rate > 110)
1589 have_higher_than_11mbit = true;
1590
1591 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001592 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001593 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001594 if (is_basic)
1595 basic_rates |= BIT(j);
1596 break;
1597 }
Johannes Berg8318d782008-01-24 19:38:38 +01001598 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001599 }
Johannes Berg8318d782008-01-24 19:38:38 +01001600
Jiri Bencf0706e82007-05-05 11:45:53 -07001601 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1602 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001603 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001604
1605 if (rate > 110)
1606 have_higher_than_11mbit = true;
1607
1608 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001609 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001610 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001611 if (is_basic)
1612 basic_rates |= BIT(j);
1613 break;
1614 }
Johannes Berg8318d782008-01-24 19:38:38 +01001615 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001616 }
Johannes Berg8318d782008-01-24 19:38:38 +01001617
Johannes Berg323ce792008-09-11 02:45:11 +02001618 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001619 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001620
1621 /* cf. IEEE 802.11 9.2.12 */
1622 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1623 have_higher_than_11mbit)
1624 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1625 else
1626 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001627
Sujithe65c2262009-03-02 13:28:31 +05301628 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1629 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001630 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001631 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001632
1633 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001634
Johannes Berg4b7679a2008-09-18 18:14:18 +02001635 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001636
Johannes Berg46900292009-02-15 12:44:28 +01001637 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001638 set_sta_flags(sta, WLAN_STA_MFP);
1639
Johannes Bergddf4ac52008-10-22 11:41:38 +02001640 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001641 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001642
1643 if (newsta) {
1644 int err = sta_info_insert(sta);
1645 if (err) {
1646 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1647 " the AP (error %d)\n", sdata->dev->name, err);
1648 rcu_read_unlock();
1649 return;
1650 }
1651 }
1652
1653 rcu_read_unlock();
1654
1655 if (elems.wmm_param)
Johannes Berg46900292009-02-15 12:44:28 +01001656 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001657 elems.wmm_param_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001658
Johannes Bergae5eb022008-10-14 16:58:37 +02001659 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001660 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1661 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001662 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1663 ap_ht_cap_flags);
1664
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001665 /* set AID and assoc capability,
1666 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001667 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001668 bss_conf->assoc_capability = capab_info;
Johannes Berg46900292009-02-15 12:44:28 +01001669 ieee80211_set_associated(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001670
Kalle Valo15b7b062009-03-22 21:57:14 +02001671 /*
1672 * initialise the time of last beacon to be the association time,
1673 * otherwise beacon loss check will trigger immediately
1674 */
1675 ifmgd->last_beacon = jiffies;
1676
Johannes Berg46900292009-02-15 12:44:28 +01001677 ieee80211_associated(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001678 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001679}
1680
1681
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001682static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001683 struct ieee80211_mgmt *mgmt,
1684 size_t len,
1685 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001686 struct ieee802_11_elems *elems,
1687 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001688{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001689 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001690 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001691 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001692 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001693
Johannes Berg5bda6172008-09-08 11:05:10 +02001694 if (elems->ds_params && elems->ds_params_len == 1)
1695 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1696 else
1697 freq = rx_status->freq;
1698
1699 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1700
1701 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1702 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001703
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001704 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001705 channel, beacon);
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001706 if (!bss)
1707 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001708
Sujithc481ec92009-01-06 09:28:37 +05301709 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg46900292009-02-15 12:44:28 +01001710 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301711 struct ieee80211_channel_sw_ie *sw_elem =
1712 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1713 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1714 }
1715
Johannes Berg3e122be2008-07-09 14:40:34 +02001716 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001717}
1718
1719
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001720static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001721 struct ieee80211_mgmt *mgmt,
1722 size_t len,
1723 struct ieee80211_rx_status *rx_status)
1724{
Kalle Valo15b7b062009-03-22 21:57:14 +02001725 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001726 size_t baselen;
1727 struct ieee802_11_elems elems;
1728
Kalle Valo15b7b062009-03-22 21:57:14 +02001729 ifmgd = &sdata->u.mgd;
1730
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001731 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1732 return; /* ignore ProbeResp to foreign address */
1733
Ester Kummerae6a44e2008-06-27 18:54:48 +03001734 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1735 if (baselen > len)
1736 return;
1737
1738 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1739 &elems);
1740
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001741 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001742
1743 /* direct probe may be part of the association flow */
1744 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
Kalle Valo15b7b062009-03-22 21:57:14 +02001745 &ifmgd->request)) {
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001746 printk(KERN_DEBUG "%s direct probe responded\n",
1747 sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001748 ieee80211_authenticate(sdata);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001749 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001750
1751 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1752 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001753}
1754
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001755static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001756 struct ieee80211_mgmt *mgmt,
1757 size_t len,
1758 struct ieee80211_rx_status *rx_status)
1759{
Johannes Berg46900292009-02-15 12:44:28 +01001760 struct ieee80211_if_managed *ifmgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001761 size_t baselen;
1762 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001763 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001764 u32 changed = 0;
Kalle Valo1fb36062009-02-10 17:09:24 +02001765 bool erp_valid, directed_tim;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001766 u8 erp_value = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001767
Ester Kummerae6a44e2008-06-27 18:54:48 +03001768 /* Process beacon from the current BSS */
1769 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1770 if (baselen > len)
1771 return;
1772
1773 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1774
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001775 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07001776
Johannes Berg05c914f2008-09-11 00:01:58 +02001777 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -07001778 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001779
Johannes Berg46900292009-02-15 12:44:28 +01001780 ifmgd = &sdata->u.mgd;
1781
1782 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1783 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001784 return;
1785
Sujithc481ec92009-01-06 09:28:37 +05301786 if (rx_status->freq != local->hw.conf.channel->center_freq)
1787 return;
1788
Johannes Berg46900292009-02-15 12:44:28 +01001789 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Johannes Bergfe3fa822008-09-08 11:05:09 +02001790 elems.wmm_param_len);
1791
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301792 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Johannes Berg46900292009-02-15 12:44:28 +01001793 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001794
Kalle Valo1fb36062009-02-10 17:09:24 +02001795 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001796 if (local->hw.conf.dynamic_ps_timeout > 0) {
1797 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1798 ieee80211_hw_config(local,
1799 IEEE80211_CONF_CHANGE_PS);
1800 ieee80211_send_nullfunc(local, sdata, 0);
1801 } else {
1802 local->pspolling = true;
1803
1804 /*
1805 * Here is assumed that the driver will be
1806 * able to send ps-poll frame and receive a
1807 * response even though power save mode is
1808 * enabled, but some drivers might require
1809 * to disable power save here. This needs
1810 * to be investigated.
1811 */
1812 ieee80211_send_pspoll(local, sdata);
1813 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001814 }
1815 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001816
1817 if (elems.erp_info && elems.erp_info_len >= 1) {
1818 erp_valid = true;
1819 erp_value = elems.erp_info[0];
1820 } else {
1821 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001822 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001823 changed |= ieee80211_handle_bss_capability(sdata,
1824 le16_to_cpu(mgmt->u.beacon.capab_info),
1825 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001826
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001827
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301828 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001829 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001830 struct sta_info *sta;
1831 struct ieee80211_supported_band *sband;
1832 u16 ap_ht_cap_flags;
1833
1834 rcu_read_lock();
1835
Johannes Berg46900292009-02-15 12:44:28 +01001836 sta = sta_info_get(local, ifmgd->bssid);
Johannes Bergae5eb022008-10-14 16:58:37 +02001837 if (!sta) {
1838 rcu_read_unlock();
1839 return;
1840 }
1841
1842 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1843
1844 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1845 elems.ht_cap_elem, &sta->sta.ht_cap);
1846
1847 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1848
1849 rcu_read_unlock();
1850
1851 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1852 ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001853 }
1854
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001855 if (elems.country_elem) {
1856 /* Note we are only reviewing this on beacons
1857 * for the BSSID we are associated to */
1858 regulatory_hint_11d(local->hw.wiphy,
1859 elems.country_elem, elems.country_elem_len);
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301860
1861 /* TODO: IBSS also needs this */
1862 if (elems.pwr_constr_elem)
1863 ieee80211_handle_pwr_constr(sdata,
1864 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1865 elems.pwr_constr_elem,
1866 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001867 }
1868
Johannes Berg471b3ef2007-12-28 14:32:58 +01001869 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001870}
1871
Johannes Berg46900292009-02-15 12:44:28 +01001872ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1873 struct sk_buff *skb,
1874 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07001875{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001876 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001877 struct ieee80211_mgmt *mgmt;
1878 u16 fc;
1879
1880 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001881 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001882
1883 mgmt = (struct ieee80211_mgmt *) skb->data;
1884 fc = le16_to_cpu(mgmt->frame_control);
1885
1886 switch (fc & IEEE80211_FCTL_STYPE) {
1887 case IEEE80211_STYPE_PROBE_REQ:
1888 case IEEE80211_STYPE_PROBE_RESP:
1889 case IEEE80211_STYPE_BEACON:
1890 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1891 case IEEE80211_STYPE_AUTH:
1892 case IEEE80211_STYPE_ASSOC_RESP:
1893 case IEEE80211_STYPE_REASSOC_RESP:
1894 case IEEE80211_STYPE_DEAUTH:
1895 case IEEE80211_STYPE_DISASSOC:
Johannes Berg46900292009-02-15 12:44:28 +01001896 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1897 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1898 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001899 }
1900
Johannes Berg46900292009-02-15 12:44:28 +01001901 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001902}
1903
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001904static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001905 struct sk_buff *skb)
1906{
1907 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001908 struct ieee80211_mgmt *mgmt;
1909 u16 fc;
1910
Jiri Bencf0706e82007-05-05 11:45:53 -07001911 rx_status = (struct ieee80211_rx_status *) skb->cb;
1912 mgmt = (struct ieee80211_mgmt *) skb->data;
1913 fc = le16_to_cpu(mgmt->frame_control);
1914
Johannes Berg46900292009-02-15 12:44:28 +01001915 switch (fc & IEEE80211_FCTL_STYPE) {
1916 case IEEE80211_STYPE_PROBE_RESP:
1917 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1918 rx_status);
1919 break;
1920 case IEEE80211_STYPE_BEACON:
1921 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1922 rx_status);
1923 break;
1924 case IEEE80211_STYPE_AUTH:
1925 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1926 break;
1927 case IEEE80211_STYPE_ASSOC_RESP:
1928 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1929 break;
1930 case IEEE80211_STYPE_REASSOC_RESP:
1931 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1932 break;
1933 case IEEE80211_STYPE_DEAUTH:
1934 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1935 break;
1936 case IEEE80211_STYPE_DISASSOC:
1937 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1938 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001939 }
1940
1941 kfree_skb(skb);
1942}
1943
Johannes Berg9c6bd792008-09-11 00:01:52 +02001944static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001945{
1946 struct ieee80211_sub_if_data *sdata =
1947 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001948 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001949 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001950
Johannes Berg46900292009-02-15 12:44:28 +01001951 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1952 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001953}
1954
Johannes Berg46900292009-02-15 12:44:28 +01001955static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001956{
Johannes Berg46900292009-02-15 12:44:28 +01001957 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001958 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001959
1960 if (local->ops->reset_tsf) {
1961 /* Reset own TSF to allow time synchronization work. */
1962 local->ops->reset_tsf(local_to_hw(local));
1963 }
1964
Johannes Berg46900292009-02-15 12:44:28 +01001965 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
Jiri Bencf0706e82007-05-05 11:45:53 -07001966
1967
Johannes Berg46900292009-02-15 12:44:28 +01001968 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1969 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1970 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1971 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
1972 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1973 ifmgd->auth_alg = WLAN_AUTH_LEAP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001974 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
1975 ifmgd->auth_alg = WLAN_AUTH_FT;
Jiri Bencf0706e82007-05-05 11:45:53 -07001976 else
Johannes Berg46900292009-02-15 12:44:28 +01001977 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1978 ifmgd->auth_transaction = -1;
1979 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1980 ifmgd->assoc_scan_tries = 0;
1981 ifmgd->direct_probe_tries = 0;
1982 ifmgd->auth_tries = 0;
1983 ifmgd->assoc_tries = 0;
Tomas Winkler24e64622008-09-08 17:33:40 +02001984 netif_tx_stop_all_queues(sdata->dev);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001985 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001986}
1987
Johannes Berg46900292009-02-15 12:44:28 +01001988static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001989{
Johannes Berg46900292009-02-15 12:44:28 +01001990 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001991 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001992 struct ieee80211_bss *bss;
Johannes Berg46900292009-02-15 12:44:28 +01001993 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
1994 u8 ssid_len = ifmgd->ssid_len;
Johannes Berg00d3f142009-02-10 21:26:00 +01001995 u16 capa_mask = WLAN_CAPABILITY_ESS;
1996 u16 capa_val = WLAN_CAPABILITY_ESS;
1997 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg60f8b392008-09-08 17:44:22 +02001998
Jouni Malinen636a5d32009-03-19 13:39:22 +02001999 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
2000 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
Johannes Berg00d3f142009-02-10 21:26:00 +01002001 IEEE80211_STA_AUTO_BSSID_SEL |
2002 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2003 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2004 if (sdata->default_key)
2005 capa_val |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg60f8b392008-09-08 17:44:22 +02002006 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002007
Johannes Berg46900292009-02-15 12:44:28 +01002008 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002009 chan = NULL;
2010
Johannes Berg46900292009-02-15 12:44:28 +01002011 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002012 bssid = NULL;
2013
Johannes Berg46900292009-02-15 12:44:28 +01002014 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
Johannes Berg00d3f142009-02-10 21:26:00 +01002015 ssid = NULL;
2016 ssid_len = 0;
2017 }
2018
2019 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
2020 bssid, ssid, ssid_len,
2021 capa_mask, capa_val);
2022
2023 if (bss) {
2024 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
Johannes Berg46900292009-02-15 12:44:28 +01002025 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
Johannes Berg00d3f142009-02-10 21:26:00 +01002026 ieee80211_sta_set_ssid(sdata, bss->ssid,
2027 bss->ssid_len);
2028 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2029 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2030 bss->supp_rates);
Johannes Berg46900292009-02-15 12:44:28 +01002031 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2032 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
Jouni Malinenfdfacf02009-01-08 13:32:05 +02002033 else
Johannes Berg46900292009-02-15 12:44:28 +01002034 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
Johannes Berg60f8b392008-09-08 17:44:22 +02002035
2036 /* Send out direct probe if no probe resp was received or
2037 * the one we have is outdated
2038 */
Johannes Berg00d3f142009-02-10 21:26:00 +01002039 if (!bss->last_probe_resp ||
2040 time_after(jiffies, bss->last_probe_resp
Johannes Berg60f8b392008-09-08 17:44:22 +02002041 + IEEE80211_SCAN_RESULT_EXPIRE))
Johannes Berg46900292009-02-15 12:44:28 +01002042 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002043 else
Johannes Berg46900292009-02-15 12:44:28 +01002044 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002045
Johannes Berg00d3f142009-02-10 21:26:00 +01002046 ieee80211_rx_bss_put(local, bss);
Johannes Berg46900292009-02-15 12:44:28 +01002047 ieee80211_sta_reset_auth(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002048 return 0;
2049 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002050 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2051 ifmgd->assoc_scan_tries++;
Johannes Berg2a519312009-02-10 21:25:55 +01002052 /* XXX maybe racy? */
2053 if (local->scan_req)
2054 return -1;
2055 memcpy(local->int_scan_req.ssids[0].ssid,
Johannes Berg46900292009-02-15 12:44:28 +01002056 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
2057 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
Johannes Berg2a519312009-02-10 21:25:55 +01002058 local->int_scan_req.ssids[0].ssid_len = 0;
Johannes Berg60f8b392008-09-08 17:44:22 +02002059 else
Johannes Berg46900292009-02-15 12:44:28 +01002060 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
Helmut Schaaaf88b902009-03-09 15:47:08 +01002061
2062 if (ieee80211_start_scan(sdata, &local->int_scan_req))
2063 ieee80211_scan_failed(local);
2064
Johannes Berg46900292009-02-15 12:44:28 +01002065 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2066 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
Sujithe3740552009-01-29 09:34:22 +05302067 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002068 ifmgd->assoc_scan_tries = 0;
2069 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Sujithe3740552009-01-29 09:34:22 +05302070 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002071 }
2072 return -1;
2073}
2074
2075
Johannes Berg9c6bd792008-09-11 00:01:52 +02002076static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02002077{
2078 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01002079 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02002080 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01002081 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002082 struct sk_buff *skb;
2083
2084 if (!netif_running(sdata->dev))
2085 return;
2086
Johannes Bergc2b13452008-09-11 00:01:55 +02002087 if (local->sw_scanning || local->hw_scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02002088 return;
2089
Johannes Berg46900292009-02-15 12:44:28 +01002090 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02002091 return;
Johannes Berg46900292009-02-15 12:44:28 +01002092 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002093
Johannes Berg46900292009-02-15 12:44:28 +01002094 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02002095 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2096
Johannes Berg46900292009-02-15 12:44:28 +01002097 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
2098 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
2099 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
2100 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
Helmut Schaaaf88b902009-03-09 15:47:08 +01002101 /*
2102 * The call to ieee80211_start_scan can fail but ieee80211_request_scan
2103 * (which queued ieee80211_sta_work) did not return an error. Thus, call
2104 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
2105 * notify the scan requester.
2106 */
2107 if (ieee80211_start_scan(sdata, local->scan_req))
2108 ieee80211_scan_failed(local);
Johannes Berg60f8b392008-09-08 17:44:22 +02002109 return;
2110 }
2111
Johannes Berg46900292009-02-15 12:44:28 +01002112 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
2113 if (ieee80211_sta_config_auth(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02002114 return;
Johannes Berg46900292009-02-15 12:44:28 +01002115 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2116 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
Johannes Berg60f8b392008-09-08 17:44:22 +02002117 return;
2118
Johannes Berg46900292009-02-15 12:44:28 +01002119 switch (ifmgd->state) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002120 case IEEE80211_STA_MLME_DISABLED:
2121 break;
2122 case IEEE80211_STA_MLME_DIRECT_PROBE:
Johannes Berg46900292009-02-15 12:44:28 +01002123 ieee80211_direct_probe(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002124 break;
2125 case IEEE80211_STA_MLME_AUTHENTICATE:
Johannes Berg46900292009-02-15 12:44:28 +01002126 ieee80211_authenticate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002127 break;
2128 case IEEE80211_STA_MLME_ASSOCIATE:
Johannes Berg46900292009-02-15 12:44:28 +01002129 ieee80211_associate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002130 break;
2131 case IEEE80211_STA_MLME_ASSOCIATED:
Johannes Berg46900292009-02-15 12:44:28 +01002132 ieee80211_associated(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002133 break;
Johannes Berg60f8b392008-09-08 17:44:22 +02002134 default:
2135 WARN_ON(1);
2136 break;
2137 }
2138
Johannes Berg46900292009-02-15 12:44:28 +01002139 if (ieee80211_privacy_mismatch(sdata)) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002140 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2141 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2142
Johannes Berg46900292009-02-15 12:44:28 +01002143 ieee80211_set_disassoc(sdata, false, true,
Johannes Berg60f8b392008-09-08 17:44:22 +02002144 WLAN_REASON_UNSPECIFIED);
2145 }
2146}
Johannes Berg0a51b272008-09-08 17:44:25 +02002147
Johannes Berga1678f82008-09-11 00:01:47 +02002148static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2149{
Kalle Vaload935682009-04-19 08:47:19 +03002150 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2151 /*
2152 * Need to update last_beacon to avoid beacon loss
2153 * test to trigger.
2154 */
2155 sdata->u.mgd.last_beacon = jiffies;
2156
2157
Johannes Berg7c950692008-09-11 00:01:48 +02002158 queue_work(sdata->local->hw.workqueue,
Johannes Berg46900292009-02-15 12:44:28 +01002159 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03002160 }
Johannes Berga1678f82008-09-11 00:01:47 +02002161}
2162
Johannes Berg9c6bd792008-09-11 00:01:52 +02002163/* interface setup */
2164void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2165{
Johannes Berg46900292009-02-15 12:44:28 +01002166 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002167
Johannes Berg46900292009-02-15 12:44:28 +01002168 ifmgd = &sdata->u.mgd;
2169 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2170 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002171 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01002172 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002173 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002174 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302175 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002176 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002177
Johannes Berg46900292009-02-15 12:44:28 +01002178 ifmgd->capab = WLAN_CAPABILITY_ESS;
2179 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002180 IEEE80211_AUTH_ALG_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01002181 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002182 IEEE80211_STA_AUTO_BSSID_SEL |
2183 IEEE80211_STA_AUTO_CHANNEL_SEL;
Johannes Berg176be722009-03-12 23:49:28 +01002184 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01002185 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002186}
2187
2188/* configuration hooks */
Johannes Berg46900292009-02-15 12:44:28 +01002189void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002190{
Johannes Berg46900292009-02-15 12:44:28 +01002191 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002192 struct ieee80211_local *local = sdata->local;
2193
Johannes Berg46900292009-02-15 12:44:28 +01002194 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg9c6bd792008-09-11 00:01:52 +02002195 return;
2196
Johannes Berg46900292009-02-15 12:44:28 +01002197 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002198 IEEE80211_STA_AUTO_BSSID_SEL)) &&
Johannes Berg46900292009-02-15 12:44:28 +01002199 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002200 IEEE80211_STA_AUTO_SSID_SEL))) {
2201
Johannes Berg46900292009-02-15 12:44:28 +01002202 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2203 ieee80211_set_disassoc(sdata, true, true,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002204 WLAN_REASON_DEAUTH_LEAVING);
2205
Jouni Malinen636a5d32009-03-19 13:39:22 +02002206 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
2207 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
2208 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2209 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
2210 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
Johannes Berg46900292009-02-15 12:44:28 +01002211 queue_work(local->hw.workqueue, &ifmgd->work);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002212 }
2213}
2214
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002215int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
2216{
2217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2218
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002219 if (ifmgd->ssid_len)
2220 ifmgd->flags |= IEEE80211_STA_SSID_SET;
2221 else
2222 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2223
2224 return 0;
2225}
2226
Johannes Berg9c6bd792008-09-11 00:01:52 +02002227int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2228{
Johannes Berg46900292009-02-15 12:44:28 +01002229 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002230
2231 if (len > IEEE80211_MAX_SSID_LEN)
2232 return -EINVAL;
2233
Johannes Berg46900292009-02-15 12:44:28 +01002234 ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002235
Johannes Berg46900292009-02-15 12:44:28 +01002236 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
Jouni Malinena2995422009-03-19 13:39:20 +02002237 /*
2238 * Do not use reassociation if SSID is changed (different ESS).
2239 */
2240 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg46900292009-02-15 12:44:28 +01002241 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2242 memcpy(ifmgd->ssid, ssid, len);
2243 ifmgd->ssid_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002244 }
2245
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002246 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002247}
2248
2249int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2250{
Johannes Berg46900292009-02-15 12:44:28 +01002251 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2252 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2253 *len = ifmgd->ssid_len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002254 return 0;
2255}
2256
2257int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2258{
Johannes Berg46900292009-02-15 12:44:28 +01002259 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002260
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002261 if (is_valid_ether_addr(bssid)) {
Johannes Berg46900292009-02-15 12:44:28 +01002262 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2263 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002264 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002265 memset(ifmgd->bssid, 0, ETH_ALEN);
2266 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002267 }
2268
2269 if (netif_running(sdata->dev)) {
2270 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
Johannes Berg9c6bd792008-09-11 00:01:52 +02002271 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2272 "the low-level driver\n", sdata->dev->name);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002273 }
2274 }
2275
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002276 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002277}
2278
Jouni Malinen636a5d32009-03-19 13:39:22 +02002279int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2280 const char *ie, size_t len)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002281{
Johannes Berg46900292009-02-15 12:44:28 +01002282 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002283
Johannes Berg46900292009-02-15 12:44:28 +01002284 kfree(ifmgd->extra_ie);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002285 if (len == 0) {
Johannes Berg46900292009-02-15 12:44:28 +01002286 ifmgd->extra_ie = NULL;
2287 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002288 return 0;
2289 }
Johannes Berg46900292009-02-15 12:44:28 +01002290 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2291 if (!ifmgd->extra_ie) {
2292 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002293 return -ENOMEM;
2294 }
Johannes Berg46900292009-02-15 12:44:28 +01002295 memcpy(ifmgd->extra_ie, ie, len);
2296 ifmgd->extra_ie_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002297 return 0;
2298}
2299
2300int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2301{
Johannes Berg9c6bd792008-09-11 00:01:52 +02002302 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2303 sdata->dev->name, reason);
2304
Johannes Berg46900292009-02-15 12:44:28 +01002305 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002306 return -EINVAL;
2307
Johannes Berg46900292009-02-15 12:44:28 +01002308 ieee80211_set_disassoc(sdata, true, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002309 return 0;
2310}
2311
2312int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2313{
Johannes Berg46900292009-02-15 12:44:28 +01002314 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002315
2316 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2317 sdata->dev->name, reason);
2318
Johannes Berg05c914f2008-09-11 00:01:58 +02002319 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002320 return -EINVAL;
2321
Johannes Berg46900292009-02-15 12:44:28 +01002322 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2323 return -ENOLINK;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002324
Johannes Berg46900292009-02-15 12:44:28 +01002325 ieee80211_set_disassoc(sdata, false, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002326 return 0;
2327}
2328
2329/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002330void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2331{
2332 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002333
2334 /* Restart STA timers */
2335 rcu_read_lock();
2336 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2337 ieee80211_restart_sta_timer(sdata);
2338 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002339}
Johannes Berg10f644a2009-04-16 13:17:25 +02002340
2341int ieee80211_max_network_latency(struct notifier_block *nb,
2342 unsigned long data, void *dummy)
2343{
2344 s32 latency_usec = (s32) data;
2345 struct ieee80211_local *local =
2346 container_of(nb, struct ieee80211_local,
2347 network_latency_notifier);
2348
2349 mutex_lock(&local->iflist_mtx);
2350 ieee80211_recalc_ps(local, latency_usec);
2351 mutex_unlock(&local->iflist_mtx);
2352
2353 return 0;
2354}