blob: a1f2332a6fedbe38b9188f674907f89a0dbb38fd [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>
Johannes Bergd91f36d2009-04-16 13:17:26 +020021#include <linux/crc32.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070022#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020023#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020024
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020026#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040027#include "rate.h"
28#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070029
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030030#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070031#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
32#define IEEE80211_AUTH_MAX_TRIES 3
33#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
34#define IEEE80211_ASSOC_MAX_TRIES 3
35#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Kalle Valo15b7b062009-03-22 21:57:14 +020036#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070037#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070038
Johannes Berg5484e232008-09-08 17:44:27 +020039/* utils */
40static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +020041{
Johannes Berg5484e232008-09-08 17:44:27 +020042 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +020043}
44
Johannes Bergc2b13452008-09-11 00:01:55 +020045static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030046{
47 u8 *end, *pos;
48
Johannes Berg00d3f142009-02-10 21:26:00 +010049 pos = bss->cbss.information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030050 if (pos == NULL)
51 return NULL;
Johannes Berg00d3f142009-02-10 21:26:00 +010052 end = pos + bss->cbss.len_information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030053
54 while (pos + 1 < end) {
55 if (pos + 2 + pos[1] > end)
56 break;
57 if (pos[0] == ie)
58 return pos;
59 pos += 2 + pos[1];
60 }
61
62 return NULL;
63}
64
Johannes Bergc2b13452008-09-11 00:01:55 +020065static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
Johannes Berg9ac19a92008-09-09 10:57:09 +020066 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010067 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +020068{
69 int i, j, count;
70 *rates = 0;
71 count = 0;
72 for (i = 0; i < bss->supp_rates_len; i++) {
73 int rate = (bss->supp_rates[i] & 0x7F) * 5;
74
75 for (j = 0; j < sband->n_bitrates; j++)
76 if (sband->bitrates[j].bitrate == rate) {
77 *rates |= BIT(j);
78 count++;
79 break;
80 }
81 }
82
83 return count;
84}
85
Johannes Bergd5522e02009-03-30 13:23:35 +020086/*
87 * ieee80211_enable_ht should be called only after the operating band
88 * has been determined as ht configuration depends on the hw's
89 * HT abilities for a specific band.
90 */
91static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
92 struct ieee80211_ht_info *hti,
93 u16 ap_ht_cap_flags)
94{
95 struct ieee80211_local *local = sdata->local;
96 struct ieee80211_supported_band *sband;
97 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergd5522e02009-03-30 13:23:35 +020098 struct sta_info *sta;
99 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200100 u16 ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200101 bool enable_ht = true, ht_changed;
102 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
103
104 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
105
Johannes Bergd5522e02009-03-30 13:23:35 +0200106 /* 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();
Johannes Bergd5522e02009-03-30 13:23:35 +0200149 }
150
151 /* disable HT */
152 if (!enable_ht)
153 return 0;
154
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200155 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200156
157 /* if bss configuration changed store the new one */
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200158 if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200159 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200160 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Bergd5522e02009-03-30 13:23:35 +0200161 }
162
163 return changed;
164}
165
Johannes Berg9c6bd792008-09-11 00:01:52 +0200166/* frame sending functions */
167
Johannes Berg46900292009-02-15 12:44:28 +0100168static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +0200169{
Johannes Berg46900292009-02-15 12:44:28 +0100170 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200171 struct ieee80211_local *local = sdata->local;
172 struct sk_buff *skb;
173 struct ieee80211_mgmt *mgmt;
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200174 u8 *pos, *ies, *ht_ie;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200175 int i, len, count, rates_len, supp_rates_len;
176 u16 capab;
Johannes Bergc2b13452008-09-11 00:01:55 +0200177 struct ieee80211_bss *bss;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200178 int wmm = 0;
179 struct ieee80211_supported_band *sband;
Johannes Berg881d9482009-01-21 15:13:48 +0100180 u32 rates = 0;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200181
182 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Johannes Berg46900292009-02-15 12:44:28 +0100183 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200184 ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200185 if (!skb) {
186 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
187 "frame\n", sdata->dev->name);
188 return;
189 }
190 skb_reserve(skb, local->hw.extra_tx_headroom);
191
192 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
193
Johannes Berg46900292009-02-15 12:44:28 +0100194 capab = ifmgd->capab;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200195
196 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
197 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
198 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
199 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
200 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
201 }
202
Johannes Berg46900292009-02-15 12:44:28 +0100203 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200204 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100205 ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200206 if (bss) {
Johannes Berg00d3f142009-02-10 21:26:00 +0100207 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200208 capab |= WLAN_CAPABILITY_PRIVACY;
209 if (bss->wmm_used)
210 wmm = 1;
211
212 /* get all rates supported by the device and the AP as
213 * some APs don't like getting a superset of their rates
214 * in the association request (e.g. D-Link DAP 1353 in
215 * b-only mode) */
216 rates_len = ieee80211_compatible_rates(bss, sband, &rates);
217
Johannes Berg00d3f142009-02-10 21:26:00 +0100218 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
Johannes Berg9ac19a92008-09-09 10:57:09 +0200219 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
220 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
221
222 ieee80211_rx_bss_put(local, bss);
223 } else {
224 rates = ~0;
225 rates_len = sband->n_bitrates;
226 }
227
228 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
229 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100230 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200231 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100232 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200233
Johannes Berg46900292009-02-15 12:44:28 +0100234 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200235 skb_put(skb, 10);
236 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
237 IEEE80211_STYPE_REASSOC_REQ);
238 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
239 mgmt->u.reassoc_req.listen_interval =
240 cpu_to_le16(local->hw.conf.listen_interval);
Johannes Berg46900292009-02-15 12:44:28 +0100241 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid,
Johannes Berg9ac19a92008-09-09 10:57:09 +0200242 ETH_ALEN);
243 } else {
244 skb_put(skb, 4);
245 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
246 IEEE80211_STYPE_ASSOC_REQ);
247 mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
Rami Rosen13554122008-12-16 22:38:29 +0200248 mgmt->u.assoc_req.listen_interval =
Johannes Berg9ac19a92008-09-09 10:57:09 +0200249 cpu_to_le16(local->hw.conf.listen_interval);
250 }
251
252 /* SSID */
Johannes Berg46900292009-02-15 12:44:28 +0100253 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200254 *pos++ = WLAN_EID_SSID;
Johannes Berg46900292009-02-15 12:44:28 +0100255 *pos++ = ifmgd->ssid_len;
256 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200257
258 /* add all rates which were marked to be used above */
259 supp_rates_len = rates_len;
260 if (supp_rates_len > 8)
261 supp_rates_len = 8;
262
263 len = sband->n_bitrates;
264 pos = skb_put(skb, supp_rates_len + 2);
265 *pos++ = WLAN_EID_SUPP_RATES;
266 *pos++ = supp_rates_len;
267
268 count = 0;
269 for (i = 0; i < sband->n_bitrates; i++) {
270 if (BIT(i) & rates) {
271 int rate = sband->bitrates[i].bitrate;
272 *pos++ = (u8) (rate / 5);
273 if (++count == 8)
274 break;
275 }
276 }
277
278 if (rates_len > count) {
279 pos = skb_put(skb, rates_len - count + 2);
280 *pos++ = WLAN_EID_EXT_SUPP_RATES;
281 *pos++ = rates_len - count;
282
283 for (i++; i < sband->n_bitrates; i++) {
284 if (BIT(i) & rates) {
285 int rate = sband->bitrates[i].bitrate;
286 *pos++ = (u8) (rate / 5);
287 }
288 }
289 }
290
291 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
292 /* 1. power capabilities */
293 pos = skb_put(skb, 4);
294 *pos++ = WLAN_EID_PWR_CAPABILITY;
295 *pos++ = 2;
296 *pos++ = 0; /* min tx power */
297 *pos++ = local->hw.conf.channel->max_power; /* max tx power */
298
299 /* 2. supported channels */
300 /* TODO: get this in reg domain format */
301 pos = skb_put(skb, 2 * sband->n_channels + 2);
302 *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
303 *pos++ = 2 * sband->n_channels;
304 for (i = 0; i < sband->n_channels; i++) {
305 *pos++ = ieee80211_frequency_to_channel(
306 sband->channels[i].center_freq);
307 *pos++ = 1; /* one channel in the subband*/
308 }
309 }
310
Johannes Berg46900292009-02-15 12:44:28 +0100311 if (ifmgd->extra_ie) {
312 pos = skb_put(skb, ifmgd->extra_ie_len);
313 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200314 }
315
Johannes Berg46900292009-02-15 12:44:28 +0100316 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
Johannes Berg9ac19a92008-09-09 10:57:09 +0200317 pos = skb_put(skb, 9);
318 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
319 *pos++ = 7; /* len */
320 *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
321 *pos++ = 0x50;
322 *pos++ = 0xf2;
323 *pos++ = 2; /* WME */
324 *pos++ = 0; /* WME info */
325 *pos++ = 1; /* WME ver */
326 *pos++ = 0;
327 }
328
329 /* wmm support is a must to HT */
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530330 /*
331 * IEEE802.11n does not allow TKIP/WEP as pairwise
332 * ciphers in HT mode. We still associate in non-ht
333 * mode (11a/b/g) if any one of these ciphers is
334 * configured as pairwise.
335 */
Johannes Berg46900292009-02-15 12:44:28 +0100336 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200337 sband->ht_cap.ht_supported &&
338 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) &&
Vasanthakumar Thiagarajaneb469362008-12-23 21:30:50 +0530339 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
Johannes Berg46900292009-02-15 12:44:28 +0100340 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200341 struct ieee80211_ht_info *ht_info =
342 (struct ieee80211_ht_info *)(ht_ie + 2);
343 u16 cap = sband->ht_cap.cap;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200344 __le16 tmp;
345 u32 flags = local->hw.conf.channel->flags;
346
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200347 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
348 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200349 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200350 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200351 cap &= ~IEEE80211_HT_CAP_SGI_40;
352 }
353 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200354 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Johannes Berg9ac19a92008-09-09 10:57:09 +0200355 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) {
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200356 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200357 cap &= ~IEEE80211_HT_CAP_SGI_40;
358 }
359 break;
360 }
361
362 tmp = cpu_to_le16(cap);
363 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
364 *pos++ = WLAN_EID_HT_CAPABILITY;
365 *pos++ = sizeof(struct ieee80211_ht_cap);
366 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
367 memcpy(pos, &tmp, sizeof(u16));
368 pos += sizeof(u16);
369 /* TODO: needs a define here for << 2 */
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200370 *pos++ = sband->ht_cap.ampdu_factor |
371 (sband->ht_cap.ampdu_density << 2);
372 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200373 }
374
Johannes Berg46900292009-02-15 12:44:28 +0100375 kfree(ifmgd->assocreq_ies);
376 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
377 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
378 if (ifmgd->assocreq_ies)
379 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200380
Johannes Berge50db652008-09-09 15:07:09 +0200381 ieee80211_tx_skb(sdata, skb, 0);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200382}
383
384
Johannes Bergef422bc2008-09-09 10:58:25 +0200385static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
386 u16 stype, u16 reason)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200387{
388 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100389 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200390 struct sk_buff *skb;
391 struct ieee80211_mgmt *mgmt;
392
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200393 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200394 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200395 printk(KERN_DEBUG "%s: failed to allocate buffer for "
396 "deauth/disassoc frame\n", sdata->dev->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200397 return;
398 }
399 skb_reserve(skb, local->hw.extra_tx_headroom);
400
401 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
402 memset(mgmt, 0, 24);
Johannes Berg46900292009-02-15 12:44:28 +0100403 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200404 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100405 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200406 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200407 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200408 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200409 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
410
Jouni Malinen53b46b82009-03-27 20:53:56 +0200411 if (stype == IEEE80211_STYPE_DEAUTH)
412 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
413 else
414 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
Johannes Berg46900292009-02-15 12:44:28 +0100415 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200416}
417
Kalle Valo572e0012009-02-10 17:09:31 +0200418void ieee80211_send_pspoll(struct ieee80211_local *local,
419 struct ieee80211_sub_if_data *sdata)
420{
Johannes Berg46900292009-02-15 12:44:28 +0100421 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Kalle Valo572e0012009-02-10 17:09:31 +0200422 struct ieee80211_pspoll *pspoll;
423 struct sk_buff *skb;
424 u16 fc;
425
426 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
427 if (!skb) {
428 printk(KERN_DEBUG "%s: failed to allocate buffer for "
429 "pspoll frame\n", sdata->dev->name);
430 return;
431 }
432 skb_reserve(skb, local->hw.extra_tx_headroom);
433
434 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
435 memset(pspoll, 0, sizeof(*pspoll));
436 fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL | IEEE80211_FCTL_PM;
437 pspoll->frame_control = cpu_to_le16(fc);
Johannes Berg46900292009-02-15 12:44:28 +0100438 pspoll->aid = cpu_to_le16(ifmgd->aid);
Kalle Valo572e0012009-02-10 17:09:31 +0200439
440 /* aid in PS-Poll has its two MSBs each set to 1 */
441 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
442
Johannes Berg46900292009-02-15 12:44:28 +0100443 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
Kalle Valo572e0012009-02-10 17:09:31 +0200444 memcpy(pspoll->ta, sdata->dev->dev_addr, ETH_ALEN);
445
446 ieee80211_tx_skb(sdata, skb, 0);
Kalle Valo572e0012009-02-10 17:09:31 +0200447}
448
Johannes Berg965beda2009-04-16 13:17:24 +0200449void ieee80211_send_nullfunc(struct ieee80211_local *local,
450 struct ieee80211_sub_if_data *sdata,
451 int powersave)
452{
453 struct sk_buff *skb;
454 struct ieee80211_hdr *nullfunc;
455 __le16 fc;
456
457 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
458 return;
459
460 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
461 if (!skb) {
462 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
463 "frame\n", sdata->dev->name);
464 return;
465 }
466 skb_reserve(skb, local->hw.extra_tx_headroom);
467
468 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
469 memset(nullfunc, 0, 24);
470 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
471 IEEE80211_FCTL_TODS);
472 if (powersave)
473 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
474 nullfunc->frame_control = fc;
475 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
476 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
477 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
478
479 ieee80211_tx_skb(sdata, skb, 0);
480}
481
482/* powersave */
483static void ieee80211_enable_ps(struct ieee80211_local *local,
484 struct ieee80211_sub_if_data *sdata)
485{
486 struct ieee80211_conf *conf = &local->hw.conf;
487
Johannes Bergd5edaed2009-04-22 23:02:51 +0200488 /*
489 * If we are scanning right now then the parameters will
490 * take effect when scan finishes.
491 */
492 if (local->hw_scanning || local->sw_scanning)
493 return;
494
Johannes Berg965beda2009-04-16 13:17:24 +0200495 if (conf->dynamic_ps_timeout > 0 &&
496 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
497 mod_timer(&local->dynamic_ps_timer, jiffies +
498 msecs_to_jiffies(conf->dynamic_ps_timeout));
499 } else {
500 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
501 ieee80211_send_nullfunc(local, sdata, 1);
502 conf->flags |= IEEE80211_CONF_PS;
503 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
504 }
505}
506
507static void ieee80211_change_ps(struct ieee80211_local *local)
508{
509 struct ieee80211_conf *conf = &local->hw.conf;
510
511 if (local->ps_sdata) {
512 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
513 return;
514
515 ieee80211_enable_ps(local, local->ps_sdata);
516 } else if (conf->flags & IEEE80211_CONF_PS) {
517 conf->flags &= ~IEEE80211_CONF_PS;
518 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
519 del_timer_sync(&local->dynamic_ps_timer);
520 cancel_work_sync(&local->dynamic_ps_enable_work);
521 }
522}
523
524/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200525void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200526{
527 struct ieee80211_sub_if_data *sdata, *found = NULL;
528 int count = 0;
529
530 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
531 local->ps_sdata = NULL;
532 return;
533 }
534
535 list_for_each_entry(sdata, &local->interfaces, list) {
536 if (!netif_running(sdata->dev))
537 continue;
538 if (sdata->vif.type != NL80211_IFTYPE_STATION)
539 continue;
540 found = sdata;
541 count++;
542 }
543
Johannes Berg10f644a2009-04-16 13:17:25 +0200544 if (count == 1 && found->u.mgd.powersave) {
545 s32 beaconint_us;
546
547 if (latency < 0)
548 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
549
550 beaconint_us = ieee80211_tu_to_usec(
551 found->vif.bss_conf.beacon_int);
552
Johannes Berg04fe2032009-04-22 18:44:37 +0200553 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200554 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200555 } else {
556 u8 dtimper = found->vif.bss_conf.dtim_period;
557 int maxslp = 1;
558
559 if (dtimper > 1)
560 maxslp = min_t(int, dtimper,
561 latency / beaconint_us);
562
Johannes Berg9ccebe62009-04-23 10:32:36 +0200563 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg10f644a2009-04-16 13:17:25 +0200564 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200565 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200566 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200567 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200568 }
Johannes Berg965beda2009-04-16 13:17:24 +0200569
570 ieee80211_change_ps(local);
571}
572
573void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
574{
575 struct ieee80211_local *local =
576 container_of(work, struct ieee80211_local,
577 dynamic_ps_disable_work);
578
579 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
580 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
581 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
582 }
583
584 ieee80211_wake_queues_by_reason(&local->hw,
585 IEEE80211_QUEUE_STOP_REASON_PS);
586}
587
588void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
589{
590 struct ieee80211_local *local =
591 container_of(work, struct ieee80211_local,
592 dynamic_ps_enable_work);
593 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
594
595 /* can only happen when PS was just disabled anyway */
596 if (!sdata)
597 return;
598
599 if (local->hw.conf.flags & IEEE80211_CONF_PS)
600 return;
601
602 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
603 ieee80211_send_nullfunc(local, sdata, 1);
604
605 local->hw.conf.flags |= IEEE80211_CONF_PS;
606 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
607}
608
609void ieee80211_dynamic_ps_timer(unsigned long data)
610{
611 struct ieee80211_local *local = (void *) data;
612
613 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
614}
615
Johannes Berg60f8b392008-09-08 17:44:22 +0200616/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200617static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100618 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700619 u8 *wmm_param, size_t wmm_param_len)
620{
Jiri Bencf0706e82007-05-05 11:45:53 -0700621 struct ieee80211_tx_queue_params params;
622 size_t left;
623 int count;
624 u8 *pos;
625
Johannes Berg46900292009-02-15 12:44:28 +0100626 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200627 return;
628
629 if (!wmm_param)
630 return;
631
Jiri Bencf0706e82007-05-05 11:45:53 -0700632 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
633 return;
634 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100635 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700636 return;
Johannes Berg46900292009-02-15 12:44:28 +0100637 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700638
639 pos = wmm_param + 8;
640 left = wmm_param_len - 8;
641
642 memset(&params, 0, sizeof(params));
643
Jiri Bencf0706e82007-05-05 11:45:53 -0700644 local->wmm_acm = 0;
645 for (; left >= 4; left -= 4, pos += 4) {
646 int aci = (pos[0] >> 5) & 0x03;
647 int acm = (pos[0] >> 4) & 0x01;
648 int queue;
649
650 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200651 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200652 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200653 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200654 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700655 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200656 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200657 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200658 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200659 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700660 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200661 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200662 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200663 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200664 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700665 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200666 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700667 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200668 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200669 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200670 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700671 break;
672 }
673
674 params.aifs = pos[0] & 0x0f;
675 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
676 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200677 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200678#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700679 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100680 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200681 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100682 params.cw_max, params.txop);
683#endif
Johannes Berg24487982009-04-23 18:52:52 +0200684 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
Jiri Bencf0706e82007-05-05 11:45:53 -0700685 printk(KERN_DEBUG "%s: failed to set TX queue "
Johannes Berg24487982009-04-23 18:52:52 +0200686 "parameters for queue %d\n", local->mdev->name,
687 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700688 }
689}
690
Johannes Berg7a5158e2008-10-08 10:59:33 +0200691static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
692 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200693{
Johannes Bergbda39332008-10-11 01:51:51 +0200694 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300695#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg46900292009-02-15 12:44:28 +0100696 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winklerebd74482008-07-01 10:44:50 +0300697#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100698 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200699 bool use_protection;
700 bool use_short_preamble;
701 bool use_short_slot;
702
703 if (erp_valid) {
704 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
705 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
706 } else {
707 use_protection = false;
708 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
709 }
710
711 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Daniel Drake56282212007-07-10 19:32:10 +0200712
Johannes Berg471b3ef2007-12-28 14:32:58 +0100713 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200714#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200715 if (net_ratelimit()) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700716 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100717 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200718 use_protection ? "enabled" : "disabled",
Johannes Berg46900292009-02-15 12:44:28 +0100719 ifmgd->bssid);
Daniel Drake56282212007-07-10 19:32:10 +0200720 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200721#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100722 bss_conf->use_cts_prot = use_protection;
723 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200724 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200725
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200726 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200727#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200728 if (net_ratelimit()) {
729 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Johannes Berg0c68ae262008-10-27 15:56:10 -0700730 " (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100731 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200732 use_short_preamble ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100733 ifmgd->bssid);
Daniel Drake7e9ed182007-07-27 15:43:24 +0200734 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200735#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200736 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100737 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200738 }
Daniel Draked9430a32007-07-27 15:43:24 +0200739
Johannes Berg7a5158e2008-10-08 10:59:33 +0200740 if (use_short_slot != bss_conf->use_short_slot) {
741#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
742 if (net_ratelimit()) {
Christian Lamparter391429c2009-01-18 02:24:15 +0100743 printk(KERN_DEBUG "%s: switched to %s slot time"
744 " (BSSID=%pM)\n",
Johannes Berg7a5158e2008-10-08 10:59:33 +0200745 sdata->dev->name,
746 use_short_slot ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100747 ifmgd->bssid);
Johannes Berg7a5158e2008-10-08 10:59:33 +0200748 }
749#endif
750 bss_conf->use_short_slot = use_short_slot;
751 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400752 }
753
754 return changed;
755}
756
Johannes Berg46900292009-02-15 12:44:28 +0100757static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200758{
759 union iwreq_data wrqu;
Johannes Berg46900292009-02-15 12:44:28 +0100760
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200761 memset(&wrqu, 0, sizeof(wrqu));
Johannes Berg46900292009-02-15 12:44:28 +0100762 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
763 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200764 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
765 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
766}
767
Johannes Berg46900292009-02-15 12:44:28 +0100768static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700769{
Johannes Berg46900292009-02-15 12:44:28 +0100770 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Linus Torvalds74af0252008-09-05 12:38:09 -0700771 char *buf;
772 size_t len;
773 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700774 union iwreq_data wrqu;
775
Johannes Berg46900292009-02-15 12:44:28 +0100776 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700777 return;
778
Johannes Berg46900292009-02-15 12:44:28 +0100779 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
780 ifmgd->assocresp_ies_len), GFP_KERNEL);
Linus Torvalds74af0252008-09-05 12:38:09 -0700781 if (!buf)
782 return;
783
784 len = sprintf(buf, "ASSOCINFO(");
Johannes Berg46900292009-02-15 12:44:28 +0100785 if (ifmgd->assocreq_ies) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700786 len += sprintf(buf + len, "ReqIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100787 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700788 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100789 ifmgd->assocreq_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700790 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700791 }
Johannes Berg46900292009-02-15 12:44:28 +0100792 if (ifmgd->assocresp_ies) {
793 if (ifmgd->assocreq_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700794 len += sprintf(buf + len, " ");
795 len += sprintf(buf + len, "RespIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100796 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700797 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100798 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700799 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700800 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700801 len += sprintf(buf + len, ")");
802
803 if (len > IW_CUSTOM_MAX) {
804 len = sprintf(buf, "ASSOCRESPIE=");
Johannes Berg46900292009-02-15 12:44:28 +0100805 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700806 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100807 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700808 }
809 }
810
John W. Linvillead788b52008-10-01 15:45:02 -0400811 if (len <= IW_CUSTOM_MAX) {
812 memset(&wrqu, 0, sizeof(wrqu));
813 wrqu.data.length = len;
814 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
815 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700816
817 kfree(buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700818}
819
820
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200821static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Bergae5eb022008-10-14 16:58:37 +0200822 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700823{
Johannes Berg46900292009-02-15 12:44:28 +0100824 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100825 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700826 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700827
Johannes Bergc2b13452008-09-11 00:01:55 +0200828 struct ieee80211_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400829
Johannes Bergae5eb022008-10-14 16:58:37 +0200830 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg46900292009-02-15 12:44:28 +0100831 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400832
Johannes Berg46900292009-02-15 12:44:28 +0100833 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200834 conf->channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100835 ifmgd->ssid, ifmgd->ssid_len);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200836 if (bss) {
837 /* set timing information */
Johannes Berg00d3f142009-02-10 21:26:00 +0100838 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
839 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
Johannes Bergbda39332008-10-11 01:51:51 +0200840 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700841
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200842 bss_info_changed |= BSS_CHANGED_BEACON_INT;
Johannes Bergae5eb022008-10-14 16:58:37 +0200843 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg00d3f142009-02-10 21:26:00 +0100844 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700845
Kalle Valo04de8382009-03-22 21:57:35 +0200846 cfg80211_hold_bss(&bss->cbss);
847
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200848 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700849 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100850
Johannes Berg46900292009-02-15 12:44:28 +0100851 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
852 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
853 ieee80211_sta_send_associnfo(sdata);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200854
Johannes Berg46900292009-02-15 12:44:28 +0100855 ifmgd->last_probe = jiffies;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200856 ieee80211_led_assoc(local, 1);
857
Johannes Bergbda39332008-10-11 01:51:51 +0200858 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200859 /*
860 * For now just always ask the driver to update the basic rateset
861 * when we have associated, we aren't checking whether it actually
862 * changed or not.
863 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200864 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
865 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300866
Johannes Berg965beda2009-04-16 13:17:24 +0200867 /* will be same as sdata */
Johannes Berg04fe2032009-04-22 18:44:37 +0200868 if (local->ps_sdata) {
869 mutex_lock(&local->iflist_mtx);
870 ieee80211_recalc_ps(local, -1);
871 mutex_unlock(&local->iflist_mtx);
872 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200873
Tomas Winkler24e64622008-09-08 17:33:40 +0200874 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200875 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300876
Johannes Berg46900292009-02-15 12:44:28 +0100877 ieee80211_sta_send_apinfo(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700878}
879
Johannes Berg46900292009-02-15 12:44:28 +0100880static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300881{
Johannes Berg46900292009-02-15 12:44:28 +0100882 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100883 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100884
885 ifmgd->direct_probe_tries++;
886 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700887 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100888 sdata->dev->name, ifmgd->bssid);
889 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +0200890 ieee80211_recalc_idle(local);
Jouni Malinene61f2342009-04-24 00:00:00 +0300891 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530892
893 /*
894 * Most likely AP is not in the range so remove the
895 * bss information associated to the AP
896 */
Johannes Berg46900292009-02-15 12:44:28 +0100897 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530898 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100899 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100900
901 /*
902 * We might have a pending scan which had no chance to run yet
903 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
904 * Hence, queue the STAs work again
905 */
906 queue_work(local->hw.workqueue, &ifmgd->work);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300907 return;
908 }
909
Johannes Berg0c68ae262008-10-27 15:56:10 -0700910 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
Johannes Berg46900292009-02-15 12:44:28 +0100911 sdata->dev->name, ifmgd->bssid,
912 ifmgd->direct_probe_tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300913
Johannes Berg46900292009-02-15 12:44:28 +0100914 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300915
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300916 /* Direct probe is sent to broadcast address as some APs
917 * will not answer to direct packet in unassociated state.
918 */
919 ieee80211_send_probe_req(sdata, NULL,
Jouni Malinen70692ad2009-02-16 19:39:13 +0200920 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300921
Johannes Berg46900292009-02-15 12:44:28 +0100922 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300923}
924
Jiri Bencf0706e82007-05-05 11:45:53 -0700925
Johannes Berg46900292009-02-15 12:44:28 +0100926static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700927{
Johannes Berg46900292009-02-15 12:44:28 +0100928 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100929 struct ieee80211_local *local = sdata->local;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200930 u8 *ies;
931 size_t ies_len;
Johannes Berg46900292009-02-15 12:44:28 +0100932
933 ifmgd->auth_tries++;
934 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700935 printk(KERN_DEBUG "%s: authentication with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700936 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100937 sdata->dev->name, ifmgd->bssid);
938 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +0200939 ieee80211_recalc_idle(local);
Jouni Malinen1965c852009-04-22 21:38:25 +0300940 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
Johannes Berg46900292009-02-15 12:44:28 +0100941 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530942 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100943 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100944
945 /*
946 * We might have a pending scan which had no chance to run yet
947 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
948 * Hence, queue the STAs work again
949 */
950 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700951 return;
952 }
953
Johannes Berg46900292009-02-15 12:44:28 +0100954 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700955 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100956 sdata->dev->name, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700957
Jouni Malinen636a5d32009-03-19 13:39:22 +0200958 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
959 ies = ifmgd->sme_auth_ie;
960 ies_len = ifmgd->sme_auth_ie_len;
961 } else {
962 ies = NULL;
963 ies_len = 0;
964 }
965 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
Johannes Berg46900292009-02-15 12:44:28 +0100966 ifmgd->bssid, 0);
967 ifmgd->auth_transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700968
Johannes Berg46900292009-02-15 12:44:28 +0100969 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700970}
971
Vivek Natarajan5925d972008-11-21 22:19:50 -0800972/*
973 * The disassoc 'reason' argument can be either our own reason
974 * if self disconnected or a reason code from the AP.
975 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300976static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg46900292009-02-15 12:44:28 +0100977 bool deauth, bool self_disconnected,
978 u16 reason)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300979{
Johannes Berg46900292009-02-15 12:44:28 +0100980 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300981 struct ieee80211_local *local = sdata->local;
Kalle Valo04de8382009-03-22 21:57:35 +0200982 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
983 struct ieee80211_bss *bss;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300984 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200985 u32 changed = 0, config_changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300986
987 rcu_read_lock();
988
Johannes Berg46900292009-02-15 12:44:28 +0100989 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300990 if (!sta) {
991 rcu_read_unlock();
992 return;
993 }
994
995 if (deauth) {
Johannes Berg46900292009-02-15 12:44:28 +0100996 ifmgd->direct_probe_tries = 0;
997 ifmgd->auth_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300998 }
Johannes Berg46900292009-02-15 12:44:28 +0100999 ifmgd->assoc_scan_tries = 0;
1000 ifmgd->assoc_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001001
Tomas Winkler24e64622008-09-08 17:33:40 +02001002 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001003 netif_carrier_off(sdata->dev);
1004
Johannes Berg2dace102009-02-10 21:25:52 +01001005 ieee80211_sta_tear_down_BA_sessions(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001006
Kalle Valo04de8382009-03-22 21:57:35 +02001007 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1008 conf->channel->center_freq,
1009 ifmgd->ssid, ifmgd->ssid_len);
1010
1011 if (bss) {
1012 cfg80211_unhold_bss(&bss->cbss);
1013 ieee80211_rx_bss_put(local, bss);
1014 }
1015
Tomas Winkleraa458d12008-09-09 00:32:12 +03001016 if (self_disconnected) {
1017 if (deauth)
Johannes Bergef422bc2008-09-09 10:58:25 +02001018 ieee80211_send_deauth_disassoc(sdata,
1019 IEEE80211_STYPE_DEAUTH, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001020 else
Johannes Bergef422bc2008-09-09 10:58:25 +02001021 ieee80211_send_deauth_disassoc(sdata,
1022 IEEE80211_STYPE_DISASSOC, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001023 }
1024
Johannes Berg46900292009-02-15 12:44:28 +01001025 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001026 changed |= ieee80211_reset_erp_info(sdata);
1027
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001028 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001029 changed |= BSS_CHANGED_ASSOC;
1030 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001031
Johannes Berg46900292009-02-15 12:44:28 +01001032 ieee80211_sta_send_apinfo(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001033
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301034 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
Johannes Berg46900292009-02-15 12:44:28 +01001035 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1036 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301037 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001038 ifmgd->ssid, ifmgd->ssid_len);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301039 }
Tomas Winkleraa458d12008-09-09 00:32:12 +03001040
Tomas Winkleraa458d12008-09-09 00:32:12 +03001041 rcu_read_unlock();
1042
Johannes Bergaa837e12009-05-07 16:16:24 +02001043 ieee80211_set_wmm_default(sdata);
1044
Johannes Berg5cff20e2009-04-29 12:26:17 +02001045 ieee80211_recalc_idle(local);
1046
Johannes Berg47979382009-01-07 10:13:27 +01001047 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +05301048 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001049
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301050 local->power_constr_level = 0;
1051
Kalle Valo520eb822008-12-18 23:35:27 +02001052 del_timer_sync(&local->dynamic_ps_timer);
1053 cancel_work_sync(&local->dynamic_ps_enable_work);
1054
Kalle Valoe0cb6862008-12-18 23:35:13 +02001055 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1056 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1057 config_changed |= IEEE80211_CONF_CHANGE_PS;
1058 }
1059
1060 ieee80211_hw_config(local, config_changed);
Johannes Bergae5eb022008-10-14 16:58:37 +02001061 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001062
1063 rcu_read_lock();
1064
Johannes Berg46900292009-02-15 12:44:28 +01001065 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001066 if (!sta) {
1067 rcu_read_unlock();
1068 return;
1069 }
1070
1071 sta_info_unlink(&sta);
1072
1073 rcu_read_unlock();
1074
1075 sta_info_destroy(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001076}
Jiri Bencf0706e82007-05-05 11:45:53 -07001077
Johannes Berg9ac19a92008-09-09 10:57:09 +02001078static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
1079{
1080 if (!sdata || !sdata->default_key ||
1081 sdata->default_key->conf.alg != ALG_WEP)
1082 return 0;
1083 return 1;
1084}
1085
Johannes Berg46900292009-02-15 12:44:28 +01001086static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001087{
Johannes Berg46900292009-02-15 12:44:28 +01001088 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001089 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001090 struct ieee80211_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001091 int bss_privacy;
1092 int wep_privacy;
1093 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -07001094
Johannes Berg7986cf92009-03-21 17:08:43 +01001095 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
Jiri Bencf0706e82007-05-05 11:45:53 -07001096 return 0;
1097
Johannes Berg46900292009-02-15 12:44:28 +01001098 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +01001099 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001100 ifmgd->ssid, ifmgd->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001101 if (!bss)
1102 return 0;
1103
Johannes Berg00d3f142009-02-10 21:26:00 +01001104 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001105 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001106 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001107
Johannes Berg3e122be2008-07-09 14:40:34 +02001108 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001109
Johannes Berg5b98b1f2007-11-03 13:11:10 +00001110 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1111 return 0;
1112
1113 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001114}
1115
Johannes Berg46900292009-02-15 12:44:28 +01001116static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001117{
Johannes Berg46900292009-02-15 12:44:28 +01001118 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +01001119 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001120
1121 ifmgd->assoc_tries++;
1122 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001123 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -07001124 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +01001125 sdata->dev->name, ifmgd->bssid);
1126 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001127 ieee80211_recalc_idle(local);
Jouni Malinen1965c852009-04-22 21:38:25 +03001128 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid);
Johannes Berg46900292009-02-15 12:44:28 +01001129 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301130 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +01001131 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +01001132 /*
1133 * We might have a pending scan which had no chance to run yet
1134 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
1135 * Hence, queue the STAs work again
1136 */
1137 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001138 return;
1139 }
1140
Johannes Berg46900292009-02-15 12:44:28 +01001141 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -07001142 printk(KERN_DEBUG "%s: associate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001143 sdata->dev->name, ifmgd->bssid);
1144 if (ieee80211_privacy_mismatch(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001145 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001146 "mixed-cell disabled - abort association\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001147 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001148 ieee80211_recalc_idle(local);
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;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001287 ieee80211_recalc_idle(sdata->local);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001288 } else
1289 ieee80211_associate(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001290}
1291
1292
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001293static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001294 struct ieee80211_mgmt *mgmt,
1295 size_t len)
1296{
1297 u8 *pos;
1298 struct ieee802_11_elems elems;
1299
Jiri Bencf0706e82007-05-05 11:45:53 -07001300 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001301 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001302 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001303 return;
Johannes Berg46900292009-02-15 12:44:28 +01001304 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1305 elems.challenge - 2, elems.challenge_len + 2,
1306 sdata->u.mgd.bssid, 1);
1307 sdata->u.mgd.auth_transaction = 4;
Johannes Bergfe3d2c32009-02-10 21:26:03 +01001308}
1309
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001310static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001311 struct ieee80211_mgmt *mgmt,
1312 size_t len)
1313{
Johannes Berg46900292009-02-15 12:44:28 +01001314 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001315 u16 auth_alg, auth_transaction, status_code;
1316
Johannes Berg46900292009-02-15 12:44:28 +01001317 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001318 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001319
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001320 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001321 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001322
Johannes Berg46900292009-02-15 12:44:28 +01001323 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001324 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001325
Johannes Berg46900292009-02-15 12:44:28 +01001326 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001327 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001328
1329 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1330 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1331 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1332
Johannes Berg46900292009-02-15 12:44:28 +01001333 if (auth_alg != ifmgd->auth_alg ||
1334 auth_transaction != ifmgd->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001335 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001336
1337 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001338 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1339 u8 algs[3];
1340 const int num_algs = ARRAY_SIZE(algs);
1341 int i, pos;
1342 algs[0] = algs[1] = algs[2] = 0xff;
Johannes Berg46900292009-02-15 12:44:28 +01001343 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001344 algs[0] = WLAN_AUTH_OPEN;
Johannes Berg46900292009-02-15 12:44:28 +01001345 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001346 algs[1] = WLAN_AUTH_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001347 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001348 algs[2] = WLAN_AUTH_LEAP;
Johannes Berg46900292009-02-15 12:44:28 +01001349 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001350 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001351 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001352 pos = 1;
1353 else
1354 pos = 2;
1355 for (i = 0; i < num_algs; i++) {
1356 pos++;
1357 if (pos >= num_algs)
1358 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001359 if (algs[pos] == ifmgd->auth_alg ||
Jiri Bencf0706e82007-05-05 11:45:53 -07001360 algs[pos] == 0xff)
1361 continue;
1362 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001363 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001364 continue;
Johannes Berg46900292009-02-15 12:44:28 +01001365 ifmgd->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001366 break;
1367 }
1368 }
1369 return;
1370 }
1371
Johannes Berg46900292009-02-15 12:44:28 +01001372 switch (ifmgd->auth_alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001373 case WLAN_AUTH_OPEN:
1374 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001375 case WLAN_AUTH_FT:
Johannes Berg46900292009-02-15 12:44:28 +01001376 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001377 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001378 break;
1379 case WLAN_AUTH_SHARED_KEY:
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001380 if (ifmgd->auth_transaction == 4) {
Johannes Berg46900292009-02-15 12:44:28 +01001381 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001382 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1383 } else
Johannes Berg46900292009-02-15 12:44:28 +01001384 ieee80211_auth_challenge(sdata, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001385 break;
1386 }
1387}
1388
1389
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001390static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001391 struct ieee80211_mgmt *mgmt,
1392 size_t len)
1393{
Johannes Berg46900292009-02-15 12:44:28 +01001394 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001395 u16 reason_code;
1396
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001397 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001398 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001399
Johannes Berg46900292009-02-15 12:44:28 +01001400 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001401 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001402
1403 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1404
Johannes Berg46900292009-02-15 12:44:28 +01001405 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001406 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1407 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001408
Jouni Malinen636a5d32009-03-19 13:39:22 +02001409 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1410 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1411 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1412 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
Johannes Berg46900292009-02-15 12:44:28 +01001413 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1414 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001415 IEEE80211_RETRY_AUTH_INTERVAL);
1416 }
1417
Johannes Berg46900292009-02-15 12:44:28 +01001418 ieee80211_set_disassoc(sdata, true, false, 0);
1419 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jouni Malinen53b46b82009-03-27 20:53:56 +02001420 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001421}
1422
1423
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001424static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001425 struct ieee80211_mgmt *mgmt,
1426 size_t len)
1427{
Johannes Berg46900292009-02-15 12:44:28 +01001428 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001429 u16 reason_code;
1430
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001431 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001432 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001433
Johannes Berg46900292009-02-15 12:44:28 +01001434 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001435 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001436
1437 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1438
Johannes Berg46900292009-02-15 12:44:28 +01001439 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001440 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1441 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001442
Jouni Malinen636a5d32009-03-19 13:39:22 +02001443 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1444 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
Johannes Berg46900292009-02-15 12:44:28 +01001445 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1446 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001447 IEEE80211_RETRY_AUTH_INTERVAL);
1448 }
1449
Johannes Berg46900292009-02-15 12:44:28 +01001450 ieee80211_set_disassoc(sdata, false, false, reason_code);
Jouni Malinen53b46b82009-03-27 20:53:56 +02001451 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001452}
1453
1454
Johannes Berg471b3ef2007-12-28 14:32:58 +01001455static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001456 struct ieee80211_mgmt *mgmt,
1457 size_t len,
1458 int reassoc)
1459{
Johannes Berg46900292009-02-15 12:44:28 +01001460 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001461 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001462 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001463 struct sta_info *sta;
Johannes Berg881d9482009-01-21 15:13:48 +01001464 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001465 u16 capab_info, status_code, aid;
1466 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001467 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001468 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001469 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001470 int i, j;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001471 bool have_higher_than_11mbit = false, newsta = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001472 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001473
1474 /* AssocResp and ReassocResp have identical structure, so process both
1475 * of them in this function. */
1476
Johannes Berg46900292009-02-15 12:44:28 +01001477 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001478 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001479
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001480 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001481 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001482
Johannes Berg46900292009-02-15 12:44:28 +01001483 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001484 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001485
1486 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1487 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1488 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001489
Johannes Berg0c68ae262008-10-27 15:56:10 -07001490 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001491 "status=%d aid=%d)\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001492 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001493 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001494
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001495 pos = mgmt->u.assoc_resp.variable;
1496 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1497
1498 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Jouni Malinenf797eb72009-01-19 18:48:46 +02001499 elems.timeout_int && elems.timeout_int_len == 5 &&
1500 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001501 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001502 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001503 ms = tu * 1024 / 1000;
1504 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1505 "comeback duration %u TU (%u ms)\n",
1506 sdata->dev->name, tu, ms);
1507 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg46900292009-02-15 12:44:28 +01001508 mod_timer(&ifmgd->timer,
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001509 jiffies + msecs_to_jiffies(ms));
1510 return;
1511 }
1512
Jiri Bencf0706e82007-05-05 11:45:53 -07001513 if (status_code != WLAN_STATUS_SUCCESS) {
1514 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001515 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001516 /* if this was a reassociation, ensure we try a "full"
1517 * association next time. This works around some broken APs
1518 * which do not correctly reject reassociation requests. */
Johannes Berg46900292009-02-15 12:44:28 +01001519 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jouni Malinen66174bb2009-04-01 17:23:54 +03001520 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1521 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1522 /* Wait for SME to decide what to do next */
1523 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02001524 ieee80211_recalc_idle(local);
Jouni Malinen66174bb2009-04-01 17:23:54 +03001525 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001526 return;
1527 }
1528
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001529 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1530 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001531 "set\n", sdata->dev->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001532 aid &= ~(BIT(15) | BIT(14));
1533
Jiri Bencf0706e82007-05-05 11:45:53 -07001534 if (!elems.supp_rates) {
1535 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001536 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001537 return;
1538 }
1539
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001540 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001541 ifmgd->aid = aid;
1542 ifmgd->ap_capab = capab_info;
Jiri Bencf0706e82007-05-05 11:45:53 -07001543
Johannes Berg46900292009-02-15 12:44:28 +01001544 kfree(ifmgd->assocresp_ies);
1545 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1546 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1547 if (ifmgd->assocresp_ies)
1548 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001549
Johannes Bergd0709a62008-02-25 16:27:46 +01001550 rcu_read_lock();
1551
Jiri Bencf0706e82007-05-05 11:45:53 -07001552 /* Add STA entry for the AP */
Johannes Berg46900292009-02-15 12:44:28 +01001553 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001554 if (!sta) {
Johannes Bergddf4ac52008-10-22 11:41:38 +02001555 newsta = true;
Johannes Bergd0709a62008-02-25 16:27:46 +01001556
Johannes Berg46900292009-02-15 12:44:28 +01001557 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
Johannes Berg73651ee2008-02-25 16:27:47 +01001558 if (!sta) {
1559 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001560 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001561 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001562 return;
1563 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001564
Ron Rindjunskya61dae12008-08-10 00:54:34 +03001565 /* update new sta with its last rx activity */
1566 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07001567 }
1568
Johannes Berg73651ee2008-02-25 16:27:47 +01001569 /*
1570 * FIXME: Do we really need to update the sta_info's information here?
1571 * We already know about the AP (we found it in our list) so it
1572 * should already be filled with the right info, no?
1573 * As is stands, all this is racy because typically we assume
1574 * the information that is filled in here (except flags) doesn't
1575 * change while a STA structure is alive. As such, it should move
1576 * to between the sta_info_alloc() and sta_info_insert() above.
1577 */
1578
Johannes Berg07346f812008-05-03 01:02:02 +02001579 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1580 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001581
1582 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001583 basic_rates = 0;
1584 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1585
Jiri Bencf0706e82007-05-05 11:45:53 -07001586 for (i = 0; i < elems.supp_rates_len; i++) {
1587 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001588 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001589
1590 if (rate > 110)
1591 have_higher_than_11mbit = true;
1592
1593 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001594 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001595 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001596 if (is_basic)
1597 basic_rates |= BIT(j);
1598 break;
1599 }
Johannes Berg8318d782008-01-24 19:38:38 +01001600 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001601 }
Johannes Berg8318d782008-01-24 19:38:38 +01001602
Jiri Bencf0706e82007-05-05 11:45:53 -07001603 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1604 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001605 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001606
1607 if (rate > 110)
1608 have_higher_than_11mbit = true;
1609
1610 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001611 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001612 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001613 if (is_basic)
1614 basic_rates |= BIT(j);
1615 break;
1616 }
Johannes Berg8318d782008-01-24 19:38:38 +01001617 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001618 }
Johannes Berg8318d782008-01-24 19:38:38 +01001619
Johannes Berg323ce792008-09-11 02:45:11 +02001620 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001621 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001622
1623 /* cf. IEEE 802.11 9.2.12 */
1624 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1625 have_higher_than_11mbit)
1626 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1627 else
1628 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001629
Sujithe65c2262009-03-02 13:28:31 +05301630 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1631 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001632 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001633 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001634
1635 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001636
Johannes Berg4b7679a2008-09-18 18:14:18 +02001637 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001638
Johannes Berg46900292009-02-15 12:44:28 +01001639 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001640 set_sta_flags(sta, WLAN_STA_MFP);
1641
Johannes Bergddf4ac52008-10-22 11:41:38 +02001642 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001643 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001644
1645 if (newsta) {
1646 int err = sta_info_insert(sta);
1647 if (err) {
1648 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1649 " the AP (error %d)\n", sdata->dev->name, err);
1650 rcu_read_unlock();
1651 return;
1652 }
1653 }
1654
1655 rcu_read_unlock();
1656
1657 if (elems.wmm_param)
Johannes Berg46900292009-02-15 12:44:28 +01001658 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001659 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001660 else
1661 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001662
Johannes Bergae5eb022008-10-14 16:58:37 +02001663 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001664 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1665 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001666 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1667 ap_ht_cap_flags);
1668
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001669 /* set AID and assoc capability,
1670 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001671 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001672 bss_conf->assoc_capability = capab_info;
Johannes Berg46900292009-02-15 12:44:28 +01001673 ieee80211_set_associated(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001674
Kalle Valo15b7b062009-03-22 21:57:14 +02001675 /*
1676 * initialise the time of last beacon to be the association time,
1677 * otherwise beacon loss check will trigger immediately
1678 */
1679 ifmgd->last_beacon = jiffies;
1680
Johannes Berg46900292009-02-15 12:44:28 +01001681 ieee80211_associated(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001682 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001683}
1684
1685
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001686static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001687 struct ieee80211_mgmt *mgmt,
1688 size_t len,
1689 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001690 struct ieee802_11_elems *elems,
1691 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001692{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001693 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001694 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001695 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001696 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001697
Johannes Berg5bda6172008-09-08 11:05:10 +02001698 if (elems->ds_params && elems->ds_params_len == 1)
1699 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1700 else
1701 freq = rx_status->freq;
1702
1703 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1704
1705 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1706 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001707
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001708 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001709 channel, beacon);
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001710 if (!bss)
1711 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001712
Sujithc481ec92009-01-06 09:28:37 +05301713 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg46900292009-02-15 12:44:28 +01001714 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301715 struct ieee80211_channel_sw_ie *sw_elem =
1716 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1717 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1718 }
1719
Johannes Berg3e122be2008-07-09 14:40:34 +02001720 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001721}
1722
1723
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001724static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001725 struct ieee80211_mgmt *mgmt,
1726 size_t len,
1727 struct ieee80211_rx_status *rx_status)
1728{
Kalle Valo15b7b062009-03-22 21:57:14 +02001729 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001730 size_t baselen;
1731 struct ieee802_11_elems elems;
1732
Kalle Valo15b7b062009-03-22 21:57:14 +02001733 ifmgd = &sdata->u.mgd;
1734
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001735 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1736 return; /* ignore ProbeResp to foreign address */
1737
Ester Kummerae6a44e2008-06-27 18:54:48 +03001738 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1739 if (baselen > len)
1740 return;
1741
1742 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1743 &elems);
1744
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001745 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001746
1747 /* direct probe may be part of the association flow */
Johannes Berg16cf4382009-04-24 15:15:25 +02001748 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) {
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001749 printk(KERN_DEBUG "%s direct probe responded\n",
1750 sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001751 ieee80211_authenticate(sdata);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001752 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001753
1754 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1755 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001756}
1757
Johannes Bergd91f36d2009-04-16 13:17:26 +02001758/*
1759 * This is the canonical list of information elements we care about,
1760 * the filter code also gives us all changes to the Microsoft OUI
1761 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1762 *
1763 * We implement beacon filtering in software since that means we can
1764 * avoid processing the frame here and in cfg80211, and userspace
1765 * will not be able to tell whether the hardware supports it or not.
1766 *
1767 * XXX: This list needs to be dynamic -- userspace needs to be able to
1768 * add items it requires. It also needs to be able to tell us to
1769 * look out for other vendor IEs.
1770 */
1771static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001772 (1ULL << WLAN_EID_COUNTRY) |
1773 (1ULL << WLAN_EID_ERP_INFO) |
1774 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1775 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1776 (1ULL << WLAN_EID_HT_CAPABILITY) |
1777 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001778
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001779static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001780 struct ieee80211_mgmt *mgmt,
1781 size_t len,
1782 struct ieee80211_rx_status *rx_status)
1783{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001784 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001785 size_t baselen;
1786 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001787 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001788 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001789 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001790 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001791 u32 ncrc;
Jiri Bencf0706e82007-05-05 11:45:53 -07001792
Ester Kummerae6a44e2008-06-27 18:54:48 +03001793 /* Process beacon from the current BSS */
1794 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1795 if (baselen > len)
1796 return;
1797
Johannes Bergd91f36d2009-04-16 13:17:26 +02001798 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001799 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001800
Johannes Berg46900292009-02-15 12:44:28 +01001801 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1802 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001803 return;
1804
Johannes Bergd91f36d2009-04-16 13:17:26 +02001805 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1806 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1807 len - baselen, &elems,
1808 care_about_ies, ncrc);
1809
1810 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001811 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1812 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001813
1814 ncrc = crc32_be(ncrc, (void *)&directed_tim, sizeof(directed_tim));
1815
1816 if (ncrc == ifmgd->beacon_crc)
Sujithc481ec92009-01-06 09:28:37 +05301817 return;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001818 ifmgd->beacon_crc = ncrc;
1819
1820 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
Sujithc481ec92009-01-06 09:28:37 +05301821
Johannes Berg46900292009-02-15 12:44:28 +01001822 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Johannes Bergfe3fa822008-09-08 11:05:09 +02001823 elems.wmm_param_len);
1824
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301825 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001826 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001827 if (local->hw.conf.dynamic_ps_timeout > 0) {
1828 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1829 ieee80211_hw_config(local,
1830 IEEE80211_CONF_CHANGE_PS);
1831 ieee80211_send_nullfunc(local, sdata, 0);
1832 } else {
1833 local->pspolling = true;
1834
1835 /*
1836 * Here is assumed that the driver will be
1837 * able to send ps-poll frame and receive a
1838 * response even though power save mode is
1839 * enabled, but some drivers might require
1840 * to disable power save here. This needs
1841 * to be investigated.
1842 */
1843 ieee80211_send_pspoll(local, sdata);
1844 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001845 }
1846 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001847
1848 if (elems.erp_info && elems.erp_info_len >= 1) {
1849 erp_valid = true;
1850 erp_value = elems.erp_info[0];
1851 } else {
1852 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001853 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001854 changed |= ieee80211_handle_bss_capability(sdata,
1855 le16_to_cpu(mgmt->u.beacon.capab_info),
1856 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001857
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001858
Vasanthakumar Thiagarajan53d6f81c2009-02-11 22:18:49 +05301859 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001860 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001861 struct sta_info *sta;
1862 struct ieee80211_supported_band *sband;
1863 u16 ap_ht_cap_flags;
1864
1865 rcu_read_lock();
1866
Johannes Berg46900292009-02-15 12:44:28 +01001867 sta = sta_info_get(local, ifmgd->bssid);
Johannes Bergae5eb022008-10-14 16:58:37 +02001868 if (!sta) {
1869 rcu_read_unlock();
1870 return;
1871 }
1872
1873 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1874
1875 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1876 elems.ht_cap_elem, &sta->sta.ht_cap);
1877
1878 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1879
1880 rcu_read_unlock();
1881
1882 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1883 ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001884 }
1885
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001886 if (elems.country_elem) {
1887 /* Note we are only reviewing this on beacons
1888 * for the BSSID we are associated to */
1889 regulatory_hint_11d(local->hw.wiphy,
1890 elems.country_elem, elems.country_elem_len);
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301891
1892 /* TODO: IBSS also needs this */
1893 if (elems.pwr_constr_elem)
1894 ieee80211_handle_pwr_constr(sdata,
1895 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1896 elems.pwr_constr_elem,
1897 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001898 }
1899
Johannes Berg471b3ef2007-12-28 14:32:58 +01001900 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001901}
1902
Johannes Berg46900292009-02-15 12:44:28 +01001903ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1904 struct sk_buff *skb,
1905 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07001906{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001907 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001908 struct ieee80211_mgmt *mgmt;
1909 u16 fc;
1910
1911 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001912 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001913
1914 mgmt = (struct ieee80211_mgmt *) skb->data;
1915 fc = le16_to_cpu(mgmt->frame_control);
1916
1917 switch (fc & IEEE80211_FCTL_STYPE) {
1918 case IEEE80211_STYPE_PROBE_REQ:
1919 case IEEE80211_STYPE_PROBE_RESP:
1920 case IEEE80211_STYPE_BEACON:
1921 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1922 case IEEE80211_STYPE_AUTH:
1923 case IEEE80211_STYPE_ASSOC_RESP:
1924 case IEEE80211_STYPE_REASSOC_RESP:
1925 case IEEE80211_STYPE_DEAUTH:
1926 case IEEE80211_STYPE_DISASSOC:
Johannes Berg46900292009-02-15 12:44:28 +01001927 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1928 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1929 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001930 }
1931
Johannes Berg46900292009-02-15 12:44:28 +01001932 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001933}
1934
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001935static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001936 struct sk_buff *skb)
1937{
1938 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001939 struct ieee80211_mgmt *mgmt;
1940 u16 fc;
1941
Jiri Bencf0706e82007-05-05 11:45:53 -07001942 rx_status = (struct ieee80211_rx_status *) skb->cb;
1943 mgmt = (struct ieee80211_mgmt *) skb->data;
1944 fc = le16_to_cpu(mgmt->frame_control);
1945
Johannes Berg46900292009-02-15 12:44:28 +01001946 switch (fc & IEEE80211_FCTL_STYPE) {
1947 case IEEE80211_STYPE_PROBE_RESP:
1948 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1949 rx_status);
1950 break;
1951 case IEEE80211_STYPE_BEACON:
1952 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1953 rx_status);
1954 break;
1955 case IEEE80211_STYPE_AUTH:
1956 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1957 break;
1958 case IEEE80211_STYPE_ASSOC_RESP:
1959 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1960 break;
1961 case IEEE80211_STYPE_REASSOC_RESP:
1962 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1963 break;
1964 case IEEE80211_STYPE_DEAUTH:
1965 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1966 break;
1967 case IEEE80211_STYPE_DISASSOC:
1968 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1969 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001970 }
1971
1972 kfree_skb(skb);
1973}
1974
Johannes Berg9c6bd792008-09-11 00:01:52 +02001975static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001976{
1977 struct ieee80211_sub_if_data *sdata =
1978 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001979 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001980 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001981
Johannes Berg46900292009-02-15 12:44:28 +01001982 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1983 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001984}
1985
Johannes Berg46900292009-02-15 12:44:28 +01001986static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001987{
Johannes Berg46900292009-02-15 12:44:28 +01001988 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001989 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001990
Johannes Berg24487982009-04-23 18:52:52 +02001991 /* Reset own TSF to allow time synchronization work. */
1992 drv_reset_tsf(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001993
Johannes Berg46900292009-02-15 12:44:28 +01001994 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
Jiri Bencf0706e82007-05-05 11:45:53 -07001995
1996
Johannes Berg46900292009-02-15 12:44:28 +01001997 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1998 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1999 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
2000 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
2001 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
2002 ifmgd->auth_alg = WLAN_AUTH_LEAP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02002003 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
2004 ifmgd->auth_alg = WLAN_AUTH_FT;
Jiri Bencf0706e82007-05-05 11:45:53 -07002005 else
Johannes Berg46900292009-02-15 12:44:28 +01002006 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2007 ifmgd->auth_transaction = -1;
2008 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
2009 ifmgd->assoc_scan_tries = 0;
2010 ifmgd->direct_probe_tries = 0;
2011 ifmgd->auth_tries = 0;
2012 ifmgd->assoc_tries = 0;
Tomas Winkler24e64622008-09-08 17:33:40 +02002013 netif_tx_stop_all_queues(sdata->dev);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002014 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07002015}
2016
Johannes Berg46900292009-02-15 12:44:28 +01002017static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07002018{
Johannes Berg46900292009-02-15 12:44:28 +01002019 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002020 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02002021 struct ieee80211_bss *bss;
Johannes Berg46900292009-02-15 12:44:28 +01002022 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
2023 u8 ssid_len = ifmgd->ssid_len;
Johannes Berg00d3f142009-02-10 21:26:00 +01002024 u16 capa_mask = WLAN_CAPABILITY_ESS;
2025 u16 capa_val = WLAN_CAPABILITY_ESS;
2026 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg60f8b392008-09-08 17:44:22 +02002027
Jouni Malinen636a5d32009-03-19 13:39:22 +02002028 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
2029 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
Johannes Berg00d3f142009-02-10 21:26:00 +01002030 IEEE80211_STA_AUTO_BSSID_SEL |
2031 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2032 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2033 if (sdata->default_key)
2034 capa_val |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg60f8b392008-09-08 17:44:22 +02002035 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002036
Johannes Berg46900292009-02-15 12:44:28 +01002037 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002038 chan = NULL;
2039
Johannes Berg46900292009-02-15 12:44:28 +01002040 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01002041 bssid = NULL;
2042
Johannes Berg46900292009-02-15 12:44:28 +01002043 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
Johannes Berg00d3f142009-02-10 21:26:00 +01002044 ssid = NULL;
2045 ssid_len = 0;
2046 }
2047
2048 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
2049 bssid, ssid, ssid_len,
2050 capa_mask, capa_val);
2051
2052 if (bss) {
2053 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
Johannes Berg46900292009-02-15 12:44:28 +01002054 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
Johannes Berg00d3f142009-02-10 21:26:00 +01002055 ieee80211_sta_set_ssid(sdata, bss->ssid,
2056 bss->ssid_len);
2057 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2058 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2059 bss->supp_rates);
Johannes Berg46900292009-02-15 12:44:28 +01002060 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2061 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
Jouni Malinenfdfacf02009-01-08 13:32:05 +02002062 else
Johannes Berg46900292009-02-15 12:44:28 +01002063 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
Johannes Berg60f8b392008-09-08 17:44:22 +02002064
2065 /* Send out direct probe if no probe resp was received or
2066 * the one we have is outdated
2067 */
Johannes Berg00d3f142009-02-10 21:26:00 +01002068 if (!bss->last_probe_resp ||
2069 time_after(jiffies, bss->last_probe_resp
Johannes Berg60f8b392008-09-08 17:44:22 +02002070 + IEEE80211_SCAN_RESULT_EXPIRE))
Johannes Berg46900292009-02-15 12:44:28 +01002071 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002072 else
Johannes Berg46900292009-02-15 12:44:28 +01002073 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg60f8b392008-09-08 17:44:22 +02002074
Johannes Berg00d3f142009-02-10 21:26:00 +01002075 ieee80211_rx_bss_put(local, bss);
Johannes Berg46900292009-02-15 12:44:28 +01002076 ieee80211_sta_reset_auth(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002077 return 0;
2078 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002079 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
Johannes Bergf3b85252009-04-23 16:01:47 +02002080
2081 ifmgd->assoc_scan_tries++;
2082
2083 ieee80211_request_internal_scan(sdata, ifmgd->ssid,
2084 ssid_len);
Helmut Schaaaf88b902009-03-09 15:47:08 +01002085
Johannes Berg46900292009-02-15 12:44:28 +01002086 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2087 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
Sujithe3740552009-01-29 09:34:22 +05302088 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002089 ifmgd->assoc_scan_tries = 0;
2090 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Johannes Berg5cff20e2009-04-29 12:26:17 +02002091 ieee80211_recalc_idle(local);
Sujithe3740552009-01-29 09:34:22 +05302092 }
Johannes Berg60f8b392008-09-08 17:44:22 +02002093 }
2094 return -1;
2095}
2096
2097
Johannes Berg9c6bd792008-09-11 00:01:52 +02002098static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02002099{
2100 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01002101 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02002102 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01002103 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002104 struct sk_buff *skb;
2105
2106 if (!netif_running(sdata->dev))
2107 return;
2108
Johannes Bergc2b13452008-09-11 00:01:55 +02002109 if (local->sw_scanning || local->hw_scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02002110 return;
2111
Johannes Berg46900292009-02-15 12:44:28 +01002112 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02002113 return;
Johannes Berg46900292009-02-15 12:44:28 +01002114 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002115
Johannes Berg46900292009-02-15 12:44:28 +01002116 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02002117 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2118
Johannes Berg46900292009-02-15 12:44:28 +01002119 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
2120 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
2121 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
2122 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
Johannes Bergf3b85252009-04-23 16:01:47 +02002123 queue_delayed_work(local->hw.workqueue, &local->scan_work,
2124 round_jiffies_relative(0));
Johannes Berg60f8b392008-09-08 17:44:22 +02002125 return;
2126 }
2127
Johannes Berg46900292009-02-15 12:44:28 +01002128 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
2129 if (ieee80211_sta_config_auth(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02002130 return;
Johannes Berg46900292009-02-15 12:44:28 +01002131 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2132 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
Johannes Berg60f8b392008-09-08 17:44:22 +02002133 return;
2134
Johannes Berg5cff20e2009-04-29 12:26:17 +02002135 ieee80211_recalc_idle(local);
2136
Johannes Berg46900292009-02-15 12:44:28 +01002137 switch (ifmgd->state) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002138 case IEEE80211_STA_MLME_DISABLED:
2139 break;
2140 case IEEE80211_STA_MLME_DIRECT_PROBE:
Johannes Berg46900292009-02-15 12:44:28 +01002141 ieee80211_direct_probe(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002142 break;
2143 case IEEE80211_STA_MLME_AUTHENTICATE:
Johannes Berg46900292009-02-15 12:44:28 +01002144 ieee80211_authenticate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002145 break;
2146 case IEEE80211_STA_MLME_ASSOCIATE:
Johannes Berg46900292009-02-15 12:44:28 +01002147 ieee80211_associate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002148 break;
2149 case IEEE80211_STA_MLME_ASSOCIATED:
Johannes Berg46900292009-02-15 12:44:28 +01002150 ieee80211_associated(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02002151 break;
Johannes Berg60f8b392008-09-08 17:44:22 +02002152 default:
2153 WARN_ON(1);
2154 break;
2155 }
2156
Johannes Berg46900292009-02-15 12:44:28 +01002157 if (ieee80211_privacy_mismatch(sdata)) {
Johannes Berg60f8b392008-09-08 17:44:22 +02002158 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
2159 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2160
Johannes Berg46900292009-02-15 12:44:28 +01002161 ieee80211_set_disassoc(sdata, false, true,
Johannes Berg60f8b392008-09-08 17:44:22 +02002162 WLAN_REASON_UNSPECIFIED);
2163 }
2164}
Johannes Berg0a51b272008-09-08 17:44:25 +02002165
Johannes Berga1678f82008-09-11 00:01:47 +02002166static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2167{
Kalle Vaload935682009-04-19 08:47:19 +03002168 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2169 /*
2170 * Need to update last_beacon to avoid beacon loss
2171 * test to trigger.
2172 */
2173 sdata->u.mgd.last_beacon = jiffies;
2174
2175
Johannes Berg7c950692008-09-11 00:01:48 +02002176 queue_work(sdata->local->hw.workqueue,
Johannes Berg46900292009-02-15 12:44:28 +01002177 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03002178 }
Johannes Berga1678f82008-09-11 00:01:47 +02002179}
2180
Johannes Berg9c6bd792008-09-11 00:01:52 +02002181/* interface setup */
2182void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2183{
Johannes Berg46900292009-02-15 12:44:28 +01002184 struct ieee80211_if_managed *ifmgd;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002185 u32 hw_flags;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002186
Johannes Berg46900292009-02-15 12:44:28 +01002187 ifmgd = &sdata->u.mgd;
2188 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2189 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002190 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01002191 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002192 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002193 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302194 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002195 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002196
Johannes Berg46900292009-02-15 12:44:28 +01002197 ifmgd->capab = WLAN_CAPABILITY_ESS;
2198 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002199 IEEE80211_AUTH_ALG_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01002200 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002201 IEEE80211_STA_AUTO_BSSID_SEL |
2202 IEEE80211_STA_AUTO_CHANNEL_SEL;
Johannes Berg176be722009-03-12 23:49:28 +01002203 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01002204 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002205
2206 hw_flags = sdata->local->hw.flags;
2207
2208 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2209 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2210 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2211 }
Johannes Berg9c6bd792008-09-11 00:01:52 +02002212}
2213
2214/* configuration hooks */
Johannes Berg46900292009-02-15 12:44:28 +01002215void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002216{
Johannes Berg46900292009-02-15 12:44:28 +01002217 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002218 struct ieee80211_local *local = sdata->local;
2219
Johannes Berg46900292009-02-15 12:44:28 +01002220 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg9c6bd792008-09-11 00:01:52 +02002221 return;
2222
Johannes Berg46900292009-02-15 12:44:28 +01002223 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002224 IEEE80211_STA_AUTO_BSSID_SEL)) &&
Johannes Berg46900292009-02-15 12:44:28 +01002225 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002226 IEEE80211_STA_AUTO_SSID_SEL))) {
2227
Johannes Berg46900292009-02-15 12:44:28 +01002228 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2229 ieee80211_set_disassoc(sdata, true, true,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002230 WLAN_REASON_DEAUTH_LEAVING);
2231
Jouni Malinen636a5d32009-03-19 13:39:22 +02002232 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
2233 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
2234 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2235 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
2236 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
Johannes Berg46900292009-02-15 12:44:28 +01002237 queue_work(local->hw.workqueue, &ifmgd->work);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002238 }
2239}
2240
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002241int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
2242{
2243 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2244
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002245 if (ifmgd->ssid_len)
2246 ifmgd->flags |= IEEE80211_STA_SSID_SET;
2247 else
2248 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2249
2250 return 0;
2251}
2252
Johannes Berg9c6bd792008-09-11 00:01:52 +02002253int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2254{
Johannes Berg46900292009-02-15 12:44:28 +01002255 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002256
2257 if (len > IEEE80211_MAX_SSID_LEN)
2258 return -EINVAL;
2259
Johannes Berg46900292009-02-15 12:44:28 +01002260 ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002261
Johannes Berg46900292009-02-15 12:44:28 +01002262 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
Jouni Malinena2995422009-03-19 13:39:20 +02002263 /*
2264 * Do not use reassociation if SSID is changed (different ESS).
2265 */
2266 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg46900292009-02-15 12:44:28 +01002267 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2268 memcpy(ifmgd->ssid, ssid, len);
2269 ifmgd->ssid_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002270 }
2271
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002272 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002273}
2274
2275int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2276{
Johannes Berg46900292009-02-15 12:44:28 +01002277 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2278 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2279 *len = ifmgd->ssid_len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002280 return 0;
2281}
2282
2283int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2284{
Johannes Berg46900292009-02-15 12:44:28 +01002285 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002286
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002287 if (is_valid_ether_addr(bssid)) {
Johannes Berg46900292009-02-15 12:44:28 +01002288 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2289 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002290 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002291 memset(ifmgd->bssid, 0, ETH_ALEN);
2292 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002293 }
2294
Johannes Berg2d0ddec2009-04-23 16:13:26 +02002295 if (netif_running(sdata->dev))
2296 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002297
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002298 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002299}
2300
Jouni Malinen636a5d32009-03-19 13:39:22 +02002301int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2302 const char *ie, size_t len)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002303{
Johannes Berg46900292009-02-15 12:44:28 +01002304 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002305
Johannes Berg46900292009-02-15 12:44:28 +01002306 kfree(ifmgd->extra_ie);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002307 if (len == 0) {
Johannes Berg46900292009-02-15 12:44:28 +01002308 ifmgd->extra_ie = NULL;
2309 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002310 return 0;
2311 }
Johannes Berg46900292009-02-15 12:44:28 +01002312 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2313 if (!ifmgd->extra_ie) {
2314 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002315 return -ENOMEM;
2316 }
Johannes Berg46900292009-02-15 12:44:28 +01002317 memcpy(ifmgd->extra_ie, ie, len);
2318 ifmgd->extra_ie_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002319 return 0;
2320}
2321
2322int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2323{
Johannes Berg9c6bd792008-09-11 00:01:52 +02002324 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2325 sdata->dev->name, reason);
2326
Johannes Berg46900292009-02-15 12:44:28 +01002327 ieee80211_set_disassoc(sdata, true, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002328 return 0;
2329}
2330
2331int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2332{
Johannes Berg46900292009-02-15 12:44:28 +01002333 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002334
2335 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2336 sdata->dev->name, reason);
2337
Johannes Berg46900292009-02-15 12:44:28 +01002338 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2339 return -ENOLINK;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002340
Johannes Berg46900292009-02-15 12:44:28 +01002341 ieee80211_set_disassoc(sdata, false, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002342 return 0;
2343}
2344
2345/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002346void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2347{
2348 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002349
2350 /* Restart STA timers */
2351 rcu_read_lock();
2352 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2353 ieee80211_restart_sta_timer(sdata);
2354 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002355}
Johannes Berg10f644a2009-04-16 13:17:25 +02002356
2357int ieee80211_max_network_latency(struct notifier_block *nb,
2358 unsigned long data, void *dummy)
2359{
2360 s32 latency_usec = (s32) data;
2361 struct ieee80211_local *local =
2362 container_of(nb, struct ieee80211_local,
2363 network_latency_notifier);
2364
2365 mutex_lock(&local->iflist_mtx);
2366 ieee80211_recalc_ps(local, latency_usec);
2367 mutex_unlock(&local->iflist_mtx);
2368
2369 return 0;
2370}