blob: 90267afa8e69d2d198cfdf60588d3be2f2304e97 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010019#include <linux/rtnetlink.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070020#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020021#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020022
Jiri Bencf0706e82007-05-05 11:45:53 -070023#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "rate.h"
25#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026
Ron Rindjunsky6042a3e2008-08-08 01:50:46 +030027#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
Jiri Bencf0706e82007-05-05 11:45:53 -070028#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
29#define IEEE80211_AUTH_MAX_TRIES 3
30#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
31#define IEEE80211_ASSOC_MAX_TRIES 3
32#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
Kalle Valo15b7b062009-03-22 21:57:14 +020033#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070034#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg5484e232008-09-08 17:44:27 +020036/* utils */
37static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +020038{
Johannes Berg5484e232008-09-08 17:44:27 +020039 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +020040}
41
Johannes Bergc2b13452008-09-11 00:01:55 +020042static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030043{
44 u8 *end, *pos;
45
Johannes Berg00d3f142009-02-10 21:26:00 +010046 pos = bss->cbss.information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030047 if (pos == NULL)
48 return NULL;
Johannes Berg00d3f142009-02-10 21:26:00 +010049 end = pos + bss->cbss.len_information_elements;
Jouni Malinen43ac2ca2008-08-15 22:21:27 +030050
51 while (pos + 1 < end) {
52 if (pos + 2 + pos[1] > end)
53 break;
54 if (pos[0] == ie)
55 return pos;
56 pos += 2 + pos[1];
57 }
58
59 return NULL;
60}
61
Johannes Bergc2b13452008-09-11 00:01:55 +020062static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
Johannes Berg9ac19a92008-09-09 10:57:09 +020063 struct ieee80211_supported_band *sband,
Johannes Berg881d9482009-01-21 15:13:48 +010064 u32 *rates)
Johannes Berg9ac19a92008-09-09 10:57:09 +020065{
66 int i, j, count;
67 *rates = 0;
68 count = 0;
69 for (i = 0; i < bss->supp_rates_len; i++) {
70 int rate = (bss->supp_rates[i] & 0x7F) * 5;
71
72 for (j = 0; j < sband->n_bitrates; j++)
73 if (sband->bitrates[j].bitrate == rate) {
74 *rates |= BIT(j);
75 count++;
76 break;
77 }
78 }
79
80 return count;
81}
82
Johannes Bergd5522e02009-03-30 13:23:35 +020083/*
84 * ieee80211_enable_ht should be called only after the operating band
85 * has been determined as ht configuration depends on the hw's
86 * HT abilities for a specific band.
87 */
88static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
89 struct ieee80211_ht_info *hti,
90 u16 ap_ht_cap_flags)
91{
92 struct ieee80211_local *local = sdata->local;
93 struct ieee80211_supported_band *sband;
94 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
95 struct ieee80211_bss_ht_conf ht;
96 struct sta_info *sta;
97 u32 changed = 0;
98 bool enable_ht = true, ht_changed;
99 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
100
101 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
102
103 memset(&ht, 0, sizeof(ht));
104
105 /* HT is not supported */
106 if (!sband->ht_cap.ht_supported)
107 enable_ht = false;
108
109 /* check that channel matches the right operating channel */
110 if (local->hw.conf.channel->center_freq !=
111 ieee80211_channel_to_frequency(hti->control_chan))
112 enable_ht = false;
113
114 if (enable_ht) {
115 channel_type = NL80211_CHAN_HT20;
116
117 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
118 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
119 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
120 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
121 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
122 channel_type = NL80211_CHAN_HT40PLUS;
123 break;
124 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
125 channel_type = NL80211_CHAN_HT40MINUS;
126 break;
127 }
128 }
129 }
130
131 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
132 channel_type != local->hw.conf.channel_type;
133
134 local->oper_channel_type = channel_type;
135
136 if (ht_changed) {
137 /* channel_type change automatically detected */
138 ieee80211_hw_config(local, 0);
139
140 rcu_read_lock();
141
142 sta = sta_info_get(local, ifmgd->bssid);
143 if (sta)
144 rate_control_rate_update(local, sband, sta,
145 IEEE80211_RC_HT_CHANGED);
146
147 rcu_read_unlock();
148
149 }
150
151 /* disable HT */
152 if (!enable_ht)
153 return 0;
154
155 ht.operation_mode = le16_to_cpu(hti->operation_mode);
156
157 /* if bss configuration changed store the new one */
158 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
159 changed |= BSS_CHANGED_HT;
160 sdata->vif.bss_conf.ht = ht;
161 }
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 Berg60f8b392008-09-08 17:44:22 +0200449/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200450static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg46900292009-02-15 12:44:28 +0100451 struct ieee80211_if_managed *ifmgd,
Jiri Bencf0706e82007-05-05 11:45:53 -0700452 u8 *wmm_param, size_t wmm_param_len)
453{
Jiri Bencf0706e82007-05-05 11:45:53 -0700454 struct ieee80211_tx_queue_params params;
455 size_t left;
456 int count;
457 u8 *pos;
458
Johannes Berg46900292009-02-15 12:44:28 +0100459 if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED))
Johannes Berg3434fbd2008-05-03 00:59:37 +0200460 return;
461
462 if (!wmm_param)
463 return;
464
Jiri Bencf0706e82007-05-05 11:45:53 -0700465 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
466 return;
467 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100468 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700469 return;
Johannes Berg46900292009-02-15 12:44:28 +0100470 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700471
472 pos = wmm_param + 8;
473 left = wmm_param_len - 8;
474
475 memset(&params, 0, sizeof(params));
476
Jiri Bencf0706e82007-05-05 11:45:53 -0700477 local->wmm_acm = 0;
478 for (; left >= 4; left -= 4, pos += 4) {
479 int aci = (pos[0] >> 5) & 0x03;
480 int acm = (pos[0] >> 4) & 0x01;
481 int queue;
482
483 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200484 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200485 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200486 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200487 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Jiri Bencf0706e82007-05-05 11:45:53 -0700488 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200489 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200490 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200491 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200492 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Jiri Bencf0706e82007-05-05 11:45:53 -0700493 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200494 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200495 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200496 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200497 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Jiri Bencf0706e82007-05-05 11:45:53 -0700498 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200499 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700500 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200501 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200502 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200503 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700504 break;
505 }
506
507 params.aifs = pos[0] & 0x0f;
508 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
509 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200510 params.txop = get_unaligned_le16(pos + 2);
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200511#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Jiri Bencf0706e82007-05-05 11:45:53 -0700512 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
Johannes Berg3330d7b2008-02-10 16:49:38 +0100513 "cWmin=%d cWmax=%d txop=%d\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200514 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
Johannes Berg3330d7b2008-02-10 16:49:38 +0100515 params.cw_max, params.txop);
516#endif
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200517 if (local->ops->conf_tx &&
518 local->ops->conf_tx(local_to_hw(local), queue, &params)) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700519 printk(KERN_DEBUG "%s: failed to set TX queue "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200520 "parameters for queue %d\n", local->mdev->name, queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700521 }
522 }
523}
524
Kalle Valo1fb36062009-02-10 17:09:24 +0200525static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800526{
527 u8 mask;
528 u8 index, indexn1, indexn2;
529 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
530
Johannes Berg60375542009-04-17 00:54:23 +0200531 if (unlikely(!tim || elems->tim_len < 4))
532 return false;
533
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800534 aid &= 0x3fff;
535 index = aid / 8;
536 mask = 1 << (aid & 7);
537
Vivek Natarajana97b77b2008-12-23 18:39:02 -0800538 indexn1 = tim->bitmap_ctrl & 0xfe;
539 indexn2 = elems->tim_len + indexn1 - 4;
540
541 if (index < indexn1 || index > indexn2)
542 return false;
543
544 index -= indexn1;
545
546 return !!(tim->virtual_map[index] & mask);
547}
548
Johannes Berg7a5158e2008-10-08 10:59:33 +0200549static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
550 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200551{
Johannes Bergbda39332008-10-11 01:51:51 +0200552 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Tomas Winklerebd74482008-07-01 10:44:50 +0300553#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg46900292009-02-15 12:44:28 +0100554 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winklerebd74482008-07-01 10:44:50 +0300555#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100556 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200557 bool use_protection;
558 bool use_short_preamble;
559 bool use_short_slot;
560
561 if (erp_valid) {
562 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
563 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
564 } else {
565 use_protection = false;
566 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
567 }
568
569 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Daniel Drake56282212007-07-10 19:32:10 +0200570
Johannes Berg471b3ef2007-12-28 14:32:58 +0100571 if (use_protection != bss_conf->use_cts_prot) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200572#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake56282212007-07-10 19:32:10 +0200573 if (net_ratelimit()) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700574 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100575 sdata->dev->name,
Daniel Drake56282212007-07-10 19:32:10 +0200576 use_protection ? "enabled" : "disabled",
Johannes Berg46900292009-02-15 12:44:28 +0100577 ifmgd->bssid);
Daniel Drake56282212007-07-10 19:32:10 +0200578 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200579#endif
Johannes Berg471b3ef2007-12-28 14:32:58 +0100580 bss_conf->use_cts_prot = use_protection;
581 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200582 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200583
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200584 if (use_short_preamble != bss_conf->use_short_preamble) {
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200585#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Daniel Drake7e9ed182007-07-27 15:43:24 +0200586 if (net_ratelimit()) {
587 printk(KERN_DEBUG "%s: switched to %s barker preamble"
Johannes Berg0c68ae262008-10-27 15:56:10 -0700588 " (BSSID=%pM)\n",
Johannes Berg471b3ef2007-12-28 14:32:58 +0100589 sdata->dev->name,
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200590 use_short_preamble ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100591 ifmgd->bssid);
Daniel Drake7e9ed182007-07-27 15:43:24 +0200592 }
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200593#endif
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200594 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100595 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200596 }
Daniel Draked9430a32007-07-27 15:43:24 +0200597
Johannes Berg7a5158e2008-10-08 10:59:33 +0200598 if (use_short_slot != bss_conf->use_short_slot) {
599#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
600 if (net_ratelimit()) {
Christian Lamparter391429c2009-01-18 02:24:15 +0100601 printk(KERN_DEBUG "%s: switched to %s slot time"
602 " (BSSID=%pM)\n",
Johannes Berg7a5158e2008-10-08 10:59:33 +0200603 sdata->dev->name,
604 use_short_slot ? "short" : "long",
Johannes Berg46900292009-02-15 12:44:28 +0100605 ifmgd->bssid);
Johannes Berg7a5158e2008-10-08 10:59:33 +0200606 }
607#endif
608 bss_conf->use_short_slot = use_short_slot;
609 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400610 }
611
612 return changed;
613}
614
Johannes Berg46900292009-02-15 12:44:28 +0100615static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200616{
617 union iwreq_data wrqu;
Johannes Berg46900292009-02-15 12:44:28 +0100618
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200619 memset(&wrqu, 0, sizeof(wrqu));
Johannes Berg46900292009-02-15 12:44:28 +0100620 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
621 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200622 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
623 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
624}
625
Johannes Berg46900292009-02-15 12:44:28 +0100626static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700627{
Johannes Berg46900292009-02-15 12:44:28 +0100628 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Linus Torvalds74af0252008-09-05 12:38:09 -0700629 char *buf;
630 size_t len;
631 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700632 union iwreq_data wrqu;
633
Johannes Berg46900292009-02-15 12:44:28 +0100634 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700635 return;
636
Johannes Berg46900292009-02-15 12:44:28 +0100637 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
638 ifmgd->assocresp_ies_len), GFP_KERNEL);
Linus Torvalds74af0252008-09-05 12:38:09 -0700639 if (!buf)
640 return;
641
642 len = sprintf(buf, "ASSOCINFO(");
Johannes Berg46900292009-02-15 12:44:28 +0100643 if (ifmgd->assocreq_ies) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700644 len += sprintf(buf + len, "ReqIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100645 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700646 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100647 ifmgd->assocreq_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700648 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700649 }
Johannes Berg46900292009-02-15 12:44:28 +0100650 if (ifmgd->assocresp_ies) {
651 if (ifmgd->assocreq_ies)
Linus Torvalds74af0252008-09-05 12:38:09 -0700652 len += sprintf(buf + len, " ");
653 len += sprintf(buf + len, "RespIEs=");
Johannes Berg46900292009-02-15 12:44:28 +0100654 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700655 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100656 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700657 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700658 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700659 len += sprintf(buf + len, ")");
660
661 if (len > IW_CUSTOM_MAX) {
662 len = sprintf(buf, "ASSOCRESPIE=");
Johannes Berg46900292009-02-15 12:44:28 +0100663 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
Linus Torvalds74af0252008-09-05 12:38:09 -0700664 len += sprintf(buf + len, "%02x",
Johannes Berg46900292009-02-15 12:44:28 +0100665 ifmgd->assocresp_ies[i]);
Linus Torvalds74af0252008-09-05 12:38:09 -0700666 }
667 }
668
John W. Linvillead788b52008-10-01 15:45:02 -0400669 if (len <= IW_CUSTOM_MAX) {
670 memset(&wrqu, 0, sizeof(wrqu));
671 wrqu.data.length = len;
672 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
673 }
Linus Torvalds74af0252008-09-05 12:38:09 -0700674
675 kfree(buf);
Jiri Bencf0706e82007-05-05 11:45:53 -0700676}
677
678
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200679static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Bergae5eb022008-10-14 16:58:37 +0200680 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700681{
Johannes Berg46900292009-02-15 12:44:28 +0100682 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100683 struct ieee80211_local *local = sdata->local;
Tomas Winkler38668c02008-03-28 16:33:32 -0700684 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
Jiri Bencf0706e82007-05-05 11:45:53 -0700685
Johannes Bergc2b13452008-09-11 00:01:55 +0200686 struct ieee80211_bss *bss;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400687
Johannes Bergae5eb022008-10-14 16:58:37 +0200688 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg46900292009-02-15 12:44:28 +0100689 ifmgd->flags |= IEEE80211_STA_ASSOCIATED;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400690
Johannes Berg46900292009-02-15 12:44:28 +0100691 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200692 conf->channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100693 ifmgd->ssid, ifmgd->ssid_len);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200694 if (bss) {
695 /* set timing information */
Johannes Berg00d3f142009-02-10 21:26:00 +0100696 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
697 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
Johannes Bergbda39332008-10-11 01:51:51 +0200698 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700699
Johannes Bergae5eb022008-10-14 16:58:37 +0200700 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg00d3f142009-02-10 21:26:00 +0100701 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700702
Kalle Valo04de8382009-03-22 21:57:35 +0200703 cfg80211_hold_bss(&bss->cbss);
704
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200705 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700706 }
Johannes Berg471b3ef2007-12-28 14:32:58 +0100707
Johannes Berg46900292009-02-15 12:44:28 +0100708 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
709 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
710 ieee80211_sta_send_associnfo(sdata);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200711
Johannes Berg46900292009-02-15 12:44:28 +0100712 ifmgd->last_probe = jiffies;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200713 ieee80211_led_assoc(local, 1);
714
Johannes Bergbda39332008-10-11 01:51:51 +0200715 sdata->vif.bss_conf.assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200716 /*
717 * For now just always ask the driver to update the basic rateset
718 * when we have associated, we aren't checking whether it actually
719 * changed or not.
720 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200721 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
722 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300723
Johannes Berg4be8c382009-01-07 18:28:20 +0100724 if (local->powersave) {
725 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) &&
726 local->hw.conf.dynamic_ps_timeout > 0) {
Kalle Valo520eb822008-12-18 23:35:27 +0200727 mod_timer(&local->dynamic_ps_timer, jiffies +
Johannes Berg46f2c4b2009-01-06 18:13:18 +0100728 msecs_to_jiffies(
729 local->hw.conf.dynamic_ps_timeout));
Johannes Berg4be8c382009-01-07 18:28:20 +0100730 } else {
731 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
732 ieee80211_send_nullfunc(local, sdata, 1);
Kalle Valo520eb822008-12-18 23:35:27 +0200733 conf->flags |= IEEE80211_CONF_PS;
Johannes Berg4be8c382009-01-07 18:28:20 +0100734 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Kalle Valo520eb822008-12-18 23:35:27 +0200735 }
Kalle Valoe0cb6862008-12-18 23:35:13 +0200736 }
737
Tomas Winkler24e64622008-09-08 17:33:40 +0200738 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200739 netif_carrier_on(sdata->dev);
Guy Cohen8db93692008-07-03 19:56:13 +0300740
Johannes Berg46900292009-02-15 12:44:28 +0100741 ieee80211_sta_send_apinfo(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -0700742}
743
Johannes Berg46900292009-02-15 12:44:28 +0100744static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300745{
Johannes Berg46900292009-02-15 12:44:28 +0100746 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100747 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100748
749 ifmgd->direct_probe_tries++;
750 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700751 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100752 sdata->dev->name, ifmgd->bssid);
753 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
754 ieee80211_sta_send_apinfo(sdata);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530755
756 /*
757 * Most likely AP is not in the range so remove the
758 * bss information associated to the AP
759 */
Johannes Berg46900292009-02-15 12:44:28 +0100760 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530761 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100762 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100763
764 /*
765 * We might have a pending scan which had no chance to run yet
766 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE.
767 * Hence, queue the STAs work again
768 */
769 queue_work(local->hw.workqueue, &ifmgd->work);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300770 return;
771 }
772
Johannes Berg0c68ae262008-10-27 15:56:10 -0700773 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n",
Johannes Berg46900292009-02-15 12:44:28 +0100774 sdata->dev->name, ifmgd->bssid,
775 ifmgd->direct_probe_tries);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300776
Johannes Berg46900292009-02-15 12:44:28 +0100777 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300778
Johannes Berg46900292009-02-15 12:44:28 +0100779 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300780
781 /* Direct probe is sent to broadcast address as some APs
782 * will not answer to direct packet in unassociated state.
783 */
784 ieee80211_send_probe_req(sdata, NULL,
Jouni Malinen70692ad2009-02-16 19:39:13 +0200785 ifmgd->ssid, ifmgd->ssid_len, NULL, 0);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300786
Johannes Berg46900292009-02-15 12:44:28 +0100787 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Ron Rindjunsky9859b812008-08-09 03:02:19 +0300788}
789
Jiri Bencf0706e82007-05-05 11:45:53 -0700790
Johannes Berg46900292009-02-15 12:44:28 +0100791static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700792{
Johannes Berg46900292009-02-15 12:44:28 +0100793 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100794 struct ieee80211_local *local = sdata->local;
Jouni Malinen636a5d32009-03-19 13:39:22 +0200795 u8 *ies;
796 size_t ies_len;
Johannes Berg46900292009-02-15 12:44:28 +0100797
798 ifmgd->auth_tries++;
799 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700800 printk(KERN_DEBUG "%s: authentication with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700801 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100802 sdata->dev->name, ifmgd->bssid);
803 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
804 ieee80211_sta_send_apinfo(sdata);
805 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530806 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100807 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100808
809 /*
810 * We might have a pending scan which had no chance to run yet
811 * due to state == IEEE80211_STA_MLME_AUTHENTICATE.
812 * Hence, queue the STAs work again
813 */
814 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700815 return;
816 }
817
Johannes Berg46900292009-02-15 12:44:28 +0100818 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -0700819 printk(KERN_DEBUG "%s: authenticate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +0100820 sdata->dev->name, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -0700821
Jouni Malinen636a5d32009-03-19 13:39:22 +0200822 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
823 ies = ifmgd->sme_auth_ie;
824 ies_len = ifmgd->sme_auth_ie_len;
825 } else {
826 ies = NULL;
827 ies_len = 0;
828 }
829 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
Johannes Berg46900292009-02-15 12:44:28 +0100830 ifmgd->bssid, 0);
831 ifmgd->auth_transaction = 2;
Jiri Bencf0706e82007-05-05 11:45:53 -0700832
Johannes Berg46900292009-02-15 12:44:28 +0100833 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -0700834}
835
Vivek Natarajan5925d972008-11-21 22:19:50 -0800836/*
837 * The disassoc 'reason' argument can be either our own reason
838 * if self disconnected or a reason code from the AP.
839 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300840static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg46900292009-02-15 12:44:28 +0100841 bool deauth, bool self_disconnected,
842 u16 reason)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300843{
Johannes Berg46900292009-02-15 12:44:28 +0100844 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300845 struct ieee80211_local *local = sdata->local;
Kalle Valo04de8382009-03-22 21:57:35 +0200846 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
847 struct ieee80211_bss *bss;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300848 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200849 u32 changed = 0, config_changed = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300850
851 rcu_read_lock();
852
Johannes Berg46900292009-02-15 12:44:28 +0100853 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300854 if (!sta) {
855 rcu_read_unlock();
856 return;
857 }
858
859 if (deauth) {
Johannes Berg46900292009-02-15 12:44:28 +0100860 ifmgd->direct_probe_tries = 0;
861 ifmgd->auth_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300862 }
Johannes Berg46900292009-02-15 12:44:28 +0100863 ifmgd->assoc_scan_tries = 0;
864 ifmgd->assoc_tries = 0;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300865
Tomas Winkler24e64622008-09-08 17:33:40 +0200866 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300867 netif_carrier_off(sdata->dev);
868
Johannes Berg2dace102009-02-10 21:25:52 +0100869 ieee80211_sta_tear_down_BA_sessions(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300870
Kalle Valo04de8382009-03-22 21:57:35 +0200871 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
872 conf->channel->center_freq,
873 ifmgd->ssid, ifmgd->ssid_len);
874
875 if (bss) {
876 cfg80211_unhold_bss(&bss->cbss);
877 ieee80211_rx_bss_put(local, bss);
878 }
879
Tomas Winkleraa458d12008-09-09 00:32:12 +0300880 if (self_disconnected) {
881 if (deauth)
Johannes Bergef422bc2008-09-09 10:58:25 +0200882 ieee80211_send_deauth_disassoc(sdata,
883 IEEE80211_STYPE_DEAUTH, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300884 else
Johannes Bergef422bc2008-09-09 10:58:25 +0200885 ieee80211_send_deauth_disassoc(sdata,
886 IEEE80211_STYPE_DISASSOC, reason);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300887 }
888
Johannes Berg46900292009-02-15 12:44:28 +0100889 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200890 changed |= ieee80211_reset_erp_info(sdata);
891
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200892 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +0200893 changed |= BSS_CHANGED_ASSOC;
894 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200895
Johannes Berg46900292009-02-15 12:44:28 +0100896 ieee80211_sta_send_apinfo(sdata);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300897
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530898 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
Johannes Berg46900292009-02-15 12:44:28 +0100899 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
900 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530901 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100902 ifmgd->ssid, ifmgd->ssid_len);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530903 }
Tomas Winkleraa458d12008-09-09 00:32:12 +0300904
Tomas Winkleraa458d12008-09-09 00:32:12 +0300905 rcu_read_unlock();
906
Johannes Berg47979382009-01-07 10:13:27 +0100907 /* channel(_type) changes are handled by ieee80211_hw_config */
Sujith094d05d2008-12-12 11:57:43 +0530908 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +0200909
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +0530910 local->power_constr_level = 0;
911
Kalle Valo520eb822008-12-18 23:35:27 +0200912 del_timer_sync(&local->dynamic_ps_timer);
913 cancel_work_sync(&local->dynamic_ps_enable_work);
914
Kalle Valoe0cb6862008-12-18 23:35:13 +0200915 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
916 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
917 config_changed |= IEEE80211_CONF_CHANGE_PS;
918 }
919
920 ieee80211_hw_config(local, config_changed);
Johannes Bergae5eb022008-10-14 16:58:37 +0200921 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +0200922
923 rcu_read_lock();
924
Johannes Berg46900292009-02-15 12:44:28 +0100925 sta = sta_info_get(local, ifmgd->bssid);
Tomas Winkler8e268e42008-11-25 13:05:44 +0200926 if (!sta) {
927 rcu_read_unlock();
928 return;
929 }
930
931 sta_info_unlink(&sta);
932
933 rcu_read_unlock();
934
935 sta_info_destroy(sta);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300936}
Jiri Bencf0706e82007-05-05 11:45:53 -0700937
Johannes Berg9ac19a92008-09-09 10:57:09 +0200938static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata)
939{
940 if (!sdata || !sdata->default_key ||
941 sdata->default_key->conf.alg != ALG_WEP)
942 return 0;
943 return 1;
944}
945
Johannes Berg46900292009-02-15 12:44:28 +0100946static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700947{
Johannes Berg46900292009-02-15 12:44:28 +0100948 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200949 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +0200950 struct ieee80211_bss *bss;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000951 int bss_privacy;
952 int wep_privacy;
953 int privacy_invoked;
Jiri Bencf0706e82007-05-05 11:45:53 -0700954
Johannes Berg7986cf92009-03-21 17:08:43 +0100955 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
Jiri Bencf0706e82007-05-05 11:45:53 -0700956 return 0;
957
Johannes Berg46900292009-02-15 12:44:28 +0100958 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
Johannes Berg8318d782008-01-24 19:38:38 +0100959 local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100960 ifmgd->ssid, ifmgd->ssid_len);
Jiri Bencf0706e82007-05-05 11:45:53 -0700961 if (!bss)
962 return 0;
963
Johannes Berg00d3f142009-02-10 21:26:00 +0100964 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200965 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
Johannes Berg46900292009-02-15 12:44:28 +0100966 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
Jiri Bencf0706e82007-05-05 11:45:53 -0700967
Johannes Berg3e122be2008-07-09 14:40:34 +0200968 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -0700969
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000970 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
971 return 0;
972
973 return 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700974}
975
Johannes Berg46900292009-02-15 12:44:28 +0100976static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -0700977{
Johannes Berg46900292009-02-15 12:44:28 +0100978 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Helmut Schaa11432372009-03-12 14:04:34 +0100979 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100980
981 ifmgd->assoc_tries++;
982 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
Johannes Berg0c68ae262008-10-27 15:56:10 -0700983 printk(KERN_DEBUG "%s: association with AP %pM"
Jiri Bencf0706e82007-05-05 11:45:53 -0700984 " timed out\n",
Johannes Berg46900292009-02-15 12:44:28 +0100985 sdata->dev->name, ifmgd->bssid);
986 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
987 ieee80211_sta_send_apinfo(sdata);
988 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +0530989 sdata->local->hw.conf.channel->center_freq,
Johannes Berg46900292009-02-15 12:44:28 +0100990 ifmgd->ssid, ifmgd->ssid_len);
Helmut Schaa11432372009-03-12 14:04:34 +0100991 /*
992 * We might have a pending scan which had no chance to run yet
993 * due to state == IEEE80211_STA_MLME_ASSOCIATE.
994 * Hence, queue the STAs work again
995 */
996 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -0700997 return;
998 }
999
Johannes Berg46900292009-02-15 12:44:28 +01001000 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
Johannes Berg0c68ae262008-10-27 15:56:10 -07001001 printk(KERN_DEBUG "%s: associate with AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001002 sdata->dev->name, ifmgd->bssid);
1003 if (ieee80211_privacy_mismatch(sdata)) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001004 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001005 "mixed-cell disabled - abort association\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001006 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 return;
1008 }
1009
Johannes Berg46900292009-02-15 12:44:28 +01001010 ieee80211_send_assoc(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001011
Johannes Berg46900292009-02-15 12:44:28 +01001012 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
Jiri Bencf0706e82007-05-05 11:45:53 -07001013}
1014
Kalle Valo3cf335d2009-03-22 21:57:06 +02001015void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1016 struct ieee80211_hdr *hdr)
1017{
1018 /*
1019 * We can postpone the mgd.timer whenever receiving unicast frames
1020 * from AP because we know that the connection is working both ways
1021 * at that time. But multicast frames (and hence also beacons) must
1022 * be ignored here, because we need to trigger the timer during
1023 * data idle periods for sending the periodical probe request to
1024 * the AP.
1025 */
1026 if (!is_multicast_ether_addr(hdr->addr1))
1027 mod_timer(&sdata->u.mgd.timer,
1028 jiffies + IEEE80211_MONITORING_INTERVAL);
1029}
Jiri Bencf0706e82007-05-05 11:45:53 -07001030
Kalle Valo04de8382009-03-22 21:57:35 +02001031void ieee80211_beacon_loss_work(struct work_struct *work)
1032{
1033 struct ieee80211_sub_if_data *sdata =
1034 container_of(work, struct ieee80211_sub_if_data,
1035 u.mgd.beacon_loss_work);
1036 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1037
Michael Buescha8604022009-04-15 14:41:22 -04001038#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1039 if (net_ratelimit()) {
1040 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
1041 "- sending probe request\n", sdata->dev->name,
1042 sdata->u.mgd.bssid);
1043 }
1044#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001045
1046 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1047 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1048 ifmgd->ssid_len, NULL, 0);
1049
1050 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL);
1051}
1052
1053void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1054{
1055 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1056
1057 queue_work(sdata->local->hw.workqueue,
1058 &sdata->u.mgd.beacon_loss_work);
1059}
1060EXPORT_SYMBOL(ieee80211_beacon_loss);
1061
Johannes Berg46900292009-02-15 12:44:28 +01001062static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001063{
Johannes Berg46900292009-02-15 12:44:28 +01001064 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001065 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001066 struct sta_info *sta;
Kalle Valo15b7b062009-03-22 21:57:14 +02001067 bool disassoc = false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001068
1069 /* TODO: start monitoring current AP signal quality and number of
1070 * missed beacons. Scan other channels every now and then and search
1071 * for better APs. */
1072 /* TODO: remove expired BSSes */
1073
Johannes Berg46900292009-02-15 12:44:28 +01001074 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001075
Johannes Bergd0709a62008-02-25 16:27:46 +01001076 rcu_read_lock();
1077
Johannes Berg46900292009-02-15 12:44:28 +01001078 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001079 if (!sta) {
Johannes Berg0c68ae262008-10-27 15:56:10 -07001080 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
Johannes Berg46900292009-02-15 12:44:28 +01001081 sdata->dev->name, ifmgd->bssid);
Kalle Valo15b7b062009-03-22 21:57:14 +02001082 disassoc = true;
1083 goto unlock;
Jiri Bencf0706e82007-05-05 11:45:53 -07001084 }
Johannes Bergd0709a62008-02-25 16:27:46 +01001085
Kalle Valo15b7b062009-03-22 21:57:14 +02001086 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1087 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
1088 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1089 "- disassociating\n",
1090 sdata->dev->name, ifmgd->bssid);
1091 disassoc = true;
1092 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1093 goto unlock;
1094 }
1095
Kalle Valo04de8382009-03-22 21:57:35 +02001096 /*
1097 * Beacon filtering is only enabled with power save and then the
1098 * stack should not check for beacon loss.
1099 */
1100 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) &&
1101 (local->hw.conf.flags & IEEE80211_CONF_PS)) &&
1102 time_after(jiffies,
Kalle Valo15b7b062009-03-22 21:57:14 +02001103 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) {
Michael Buescha8604022009-04-15 14:41:22 -04001104#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1105 if (net_ratelimit()) {
1106 printk(KERN_DEBUG "%s: beacon loss from AP %pM "
1107 "- sending probe request\n",
1108 sdata->dev->name, ifmgd->bssid);
1109 }
1110#endif
Kalle Valo15b7b062009-03-22 21:57:14 +02001111 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1112 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1113 ifmgd->ssid_len, NULL, 0);
1114 goto unlock;
1115
1116 }
1117
1118 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1119 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1120 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1121 ifmgd->ssid_len, NULL, 0);
1122 }
1123
1124 unlock:
Johannes Bergd0709a62008-02-25 16:27:46 +01001125 rcu_read_unlock();
1126
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301127 if (disassoc)
Johannes Berg46900292009-02-15 12:44:28 +01001128 ieee80211_set_disassoc(sdata, true, true,
Tomas Winkleraa458d12008-09-09 00:32:12 +03001129 WLAN_REASON_PREV_AUTH_NOT_VALID);
Vasanthakumar Thiagarajan7a947082009-02-04 18:28:48 +05301130 else
Johannes Berg46900292009-02-15 12:44:28 +01001131 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001132 IEEE80211_MONITORING_INTERVAL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001133}
1134
1135
Johannes Berg46900292009-02-15 12:44:28 +01001136static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001137{
Johannes Berg46900292009-02-15 12:44:28 +01001138 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1139
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001140 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001141 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001142 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1143 /* Wait for SME to request association */
1144 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1145 } else
1146 ieee80211_associate(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001147}
1148
1149
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001150static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001151 struct ieee80211_mgmt *mgmt,
1152 size_t len)
1153{
1154 u8 *pos;
1155 struct ieee802_11_elems elems;
1156
Jiri Bencf0706e82007-05-05 11:45:53 -07001157 pos = mgmt->u.auth.variable;
John W. Linville67a4cce2007-10-12 16:40:37 -04001158 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001159 if (!elems.challenge)
Jiri Bencf0706e82007-05-05 11:45:53 -07001160 return;
Johannes Berg46900292009-02-15 12:44:28 +01001161 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg,
1162 elems.challenge - 2, elems.challenge_len + 2,
1163 sdata->u.mgd.bssid, 1);
1164 sdata->u.mgd.auth_transaction = 4;
Johannes Bergfe3d2c32009-02-10 21:26:03 +01001165}
1166
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001167static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001168 struct ieee80211_mgmt *mgmt,
1169 size_t len)
1170{
Johannes Berg46900292009-02-15 12:44:28 +01001171 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001172 u16 auth_alg, auth_transaction, status_code;
1173
Johannes Berg46900292009-02-15 12:44:28 +01001174 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001175 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001176
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001177 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001178 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001179
Johannes Berg46900292009-02-15 12:44:28 +01001180 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001181 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001182
Johannes Berg46900292009-02-15 12:44:28 +01001183 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001184 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001185
1186 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1187 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1188 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1189
Johannes Berg46900292009-02-15 12:44:28 +01001190 if (auth_alg != ifmgd->auth_alg ||
1191 auth_transaction != ifmgd->auth_transaction)
Jiri Bencf0706e82007-05-05 11:45:53 -07001192 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001193
1194 if (status_code != WLAN_STATUS_SUCCESS) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001195 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
1196 u8 algs[3];
1197 const int num_algs = ARRAY_SIZE(algs);
1198 int i, pos;
1199 algs[0] = algs[1] = algs[2] = 0xff;
Johannes Berg46900292009-02-15 12:44:28 +01001200 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001201 algs[0] = WLAN_AUTH_OPEN;
Johannes Berg46900292009-02-15 12:44:28 +01001202 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001203 algs[1] = WLAN_AUTH_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01001204 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
Jiri Bencf0706e82007-05-05 11:45:53 -07001205 algs[2] = WLAN_AUTH_LEAP;
Johannes Berg46900292009-02-15 12:44:28 +01001206 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
Jiri Bencf0706e82007-05-05 11:45:53 -07001207 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001208 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
Jiri Bencf0706e82007-05-05 11:45:53 -07001209 pos = 1;
1210 else
1211 pos = 2;
1212 for (i = 0; i < num_algs; i++) {
1213 pos++;
1214 if (pos >= num_algs)
1215 pos = 0;
Johannes Berg46900292009-02-15 12:44:28 +01001216 if (algs[pos] == ifmgd->auth_alg ||
Jiri Bencf0706e82007-05-05 11:45:53 -07001217 algs[pos] == 0xff)
1218 continue;
1219 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001220 !ieee80211_sta_wep_configured(sdata))
Jiri Bencf0706e82007-05-05 11:45:53 -07001221 continue;
Johannes Berg46900292009-02-15 12:44:28 +01001222 ifmgd->auth_alg = algs[pos];
Jiri Bencf0706e82007-05-05 11:45:53 -07001223 break;
1224 }
1225 }
1226 return;
1227 }
1228
Johannes Berg46900292009-02-15 12:44:28 +01001229 switch (ifmgd->auth_alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001230 case WLAN_AUTH_OPEN:
1231 case WLAN_AUTH_LEAP:
Jouni Malinen636a5d32009-03-19 13:39:22 +02001232 case WLAN_AUTH_FT:
Johannes Berg46900292009-02-15 12:44:28 +01001233 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001234 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001235 break;
1236 case WLAN_AUTH_SHARED_KEY:
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001237 if (ifmgd->auth_transaction == 4) {
Johannes Berg46900292009-02-15 12:44:28 +01001238 ieee80211_auth_completed(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001239 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1240 } else
Johannes Berg46900292009-02-15 12:44:28 +01001241 ieee80211_auth_challenge(sdata, mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001242 break;
1243 }
1244}
1245
1246
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001247static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001248 struct ieee80211_mgmt *mgmt,
1249 size_t len)
1250{
Johannes Berg46900292009-02-15 12:44:28 +01001251 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001252 u16 reason_code;
1253
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001254 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001255 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001256
Johannes Berg46900292009-02-15 12:44:28 +01001257 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001258 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001259
1260 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1261
Johannes Berg46900292009-02-15 12:44:28 +01001262 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001263 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n",
1264 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001265
Jouni Malinen636a5d32009-03-19 13:39:22 +02001266 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1267 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
1268 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE ||
1269 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) {
Johannes Berg46900292009-02-15 12:44:28 +01001270 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1271 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001272 IEEE80211_RETRY_AUTH_INTERVAL);
1273 }
1274
Johannes Berg46900292009-02-15 12:44:28 +01001275 ieee80211_set_disassoc(sdata, true, false, 0);
1276 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
Jouni Malinen53b46b82009-03-27 20:53:56 +02001277 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001278}
1279
1280
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001281static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001282 struct ieee80211_mgmt *mgmt,
1283 size_t len)
1284{
Johannes Berg46900292009-02-15 12:44:28 +01001285 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001286 u16 reason_code;
1287
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001288 if (len < 24 + 2)
Jiri Bencf0706e82007-05-05 11:45:53 -07001289 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001290
Johannes Berg46900292009-02-15 12:44:28 +01001291 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN))
Jiri Bencf0706e82007-05-05 11:45:53 -07001292 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001293
1294 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1295
Johannes Berg46900292009-02-15 12:44:28 +01001296 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED)
Zhu Yi97c8b012008-10-28 15:58:31 +08001297 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1298 sdata->dev->name, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001299
Jouni Malinen636a5d32009-03-19 13:39:22 +02001300 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1301 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) {
Johannes Berg46900292009-02-15 12:44:28 +01001302 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE;
1303 mod_timer(&ifmgd->timer, jiffies +
Jiri Bencf0706e82007-05-05 11:45:53 -07001304 IEEE80211_RETRY_AUTH_INTERVAL);
1305 }
1306
Johannes Berg46900292009-02-15 12:44:28 +01001307 ieee80211_set_disassoc(sdata, false, false, reason_code);
Jouni Malinen53b46b82009-03-27 20:53:56 +02001308 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001309}
1310
1311
Johannes Berg471b3ef2007-12-28 14:32:58 +01001312static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001313 struct ieee80211_mgmt *mgmt,
1314 size_t len,
1315 int reassoc)
1316{
Johannes Berg46900292009-02-15 12:44:28 +01001317 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001318 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001319 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001320 struct sta_info *sta;
Johannes Berg881d9482009-01-21 15:13:48 +01001321 u32 rates, basic_rates;
Jiri Bencf0706e82007-05-05 11:45:53 -07001322 u16 capab_info, status_code, aid;
1323 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001324 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001325 u8 *pos;
Johannes Bergae5eb022008-10-14 16:58:37 +02001326 u32 changed = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001327 int i, j;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001328 bool have_higher_than_11mbit = false, newsta = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001329 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001330
1331 /* AssocResp and ReassocResp have identical structure, so process both
1332 * of them in this function. */
1333
Johannes Berg46900292009-02-15 12:44:28 +01001334 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
Jiri Bencf0706e82007-05-05 11:45:53 -07001335 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001336
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001337 if (len < 24 + 6)
Jiri Bencf0706e82007-05-05 11:45:53 -07001338 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001339
Johannes Berg46900292009-02-15 12:44:28 +01001340 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001341 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001342
1343 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1344 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
1345 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001346
Johannes Berg0c68ae262008-10-27 15:56:10 -07001347 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x "
Jiri Bencf0706e82007-05-05 11:45:53 -07001348 "status=%d aid=%d)\n",
Johannes Berg0c68ae262008-10-27 15:56:10 -07001349 sdata->dev->name, reassoc ? "Rea" : "A", mgmt->sa,
Johannes Bergddd68582007-10-22 14:51:37 +02001350 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
Jiri Bencf0706e82007-05-05 11:45:53 -07001351
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001352 pos = mgmt->u.assoc_resp.variable;
1353 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1354
1355 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
Jouni Malinenf797eb72009-01-19 18:48:46 +02001356 elems.timeout_int && elems.timeout_int_len == 5 &&
1357 elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) {
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001358 u32 tu, ms;
Jouni Malinenf797eb72009-01-19 18:48:46 +02001359 tu = get_unaligned_le32(elems.timeout_int + 1);
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001360 ms = tu * 1024 / 1000;
1361 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1362 "comeback duration %u TU (%u ms)\n",
1363 sdata->dev->name, tu, ms);
1364 if (ms > IEEE80211_ASSOC_TIMEOUT)
Johannes Berg46900292009-02-15 12:44:28 +01001365 mod_timer(&ifmgd->timer,
Jouni Malinen63a5ab82009-01-08 13:32:09 +02001366 jiffies + msecs_to_jiffies(ms));
1367 return;
1368 }
1369
Jiri Bencf0706e82007-05-05 11:45:53 -07001370 if (status_code != WLAN_STATUS_SUCCESS) {
1371 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001372 sdata->dev->name, status_code);
Daniel Drake8a69aa92007-07-27 15:43:23 +02001373 /* if this was a reassociation, ensure we try a "full"
1374 * association next time. This works around some broken APs
1375 * which do not correctly reject reassociation requests. */
Johannes Berg46900292009-02-15 12:44:28 +01001376 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Jouni Malinen66174bb2009-04-01 17:23:54 +03001377 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1378 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1379 /* Wait for SME to decide what to do next */
1380 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1381 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001382 return;
1383 }
1384
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001385 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1386 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001387 "set\n", sdata->dev->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001388 aid &= ~(BIT(15) | BIT(14));
1389
Jiri Bencf0706e82007-05-05 11:45:53 -07001390 if (!elems.supp_rates) {
1391 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001392 sdata->dev->name);
Jiri Bencf0706e82007-05-05 11:45:53 -07001393 return;
1394 }
1395
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001396 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001397 ifmgd->aid = aid;
1398 ifmgd->ap_capab = capab_info;
Jiri Bencf0706e82007-05-05 11:45:53 -07001399
Johannes Berg46900292009-02-15 12:44:28 +01001400 kfree(ifmgd->assocresp_ies);
1401 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1402 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1403 if (ifmgd->assocresp_ies)
1404 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001405
Johannes Bergd0709a62008-02-25 16:27:46 +01001406 rcu_read_lock();
1407
Jiri Bencf0706e82007-05-05 11:45:53 -07001408 /* Add STA entry for the AP */
Johannes Berg46900292009-02-15 12:44:28 +01001409 sta = sta_info_get(local, ifmgd->bssid);
Jiri Bencf0706e82007-05-05 11:45:53 -07001410 if (!sta) {
Johannes Bergddf4ac52008-10-22 11:41:38 +02001411 newsta = true;
Johannes Bergd0709a62008-02-25 16:27:46 +01001412
Johannes Berg46900292009-02-15 12:44:28 +01001413 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC);
Johannes Berg73651ee2008-02-25 16:27:47 +01001414 if (!sta) {
1415 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001416 " the AP\n", sdata->dev->name);
Johannes Bergd0709a62008-02-25 16:27:46 +01001417 rcu_read_unlock();
Jiri Bencf0706e82007-05-05 11:45:53 -07001418 return;
1419 }
Johannes Berg73651ee2008-02-25 16:27:47 +01001420
Ron Rindjunskya61dae12008-08-10 00:54:34 +03001421 /* update new sta with its last rx activity */
1422 sta->last_rx = jiffies;
Jiri Bencf0706e82007-05-05 11:45:53 -07001423 }
1424
Johannes Berg73651ee2008-02-25 16:27:47 +01001425 /*
1426 * FIXME: Do we really need to update the sta_info's information here?
1427 * We already know about the AP (we found it in our list) so it
1428 * should already be filled with the right info, no?
1429 * As is stands, all this is racy because typically we assume
1430 * the information that is filled in here (except flags) doesn't
1431 * change while a STA structure is alive. As such, it should move
1432 * to between the sta_info_alloc() and sta_info_insert() above.
1433 */
1434
Johannes Berg07346f812008-05-03 01:02:02 +02001435 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1436 WLAN_STA_AUTHORIZED);
Jiri Bencf0706e82007-05-05 11:45:53 -07001437
1438 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001439 basic_rates = 0;
1440 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1441
Jiri Bencf0706e82007-05-05 11:45:53 -07001442 for (i = 0; i < elems.supp_rates_len; i++) {
1443 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001444 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001445
1446 if (rate > 110)
1447 have_higher_than_11mbit = true;
1448
1449 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001450 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001451 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001452 if (is_basic)
1453 basic_rates |= BIT(j);
1454 break;
1455 }
Johannes Berg8318d782008-01-24 19:38:38 +01001456 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001457 }
Johannes Berg8318d782008-01-24 19:38:38 +01001458
Jiri Bencf0706e82007-05-05 11:45:53 -07001459 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1460 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001461 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001462
1463 if (rate > 110)
1464 have_higher_than_11mbit = true;
1465
1466 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001467 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001468 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001469 if (is_basic)
1470 basic_rates |= BIT(j);
1471 break;
1472 }
Johannes Berg8318d782008-01-24 19:38:38 +01001473 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001474 }
Johannes Berg8318d782008-01-24 19:38:38 +01001475
Johannes Berg323ce792008-09-11 02:45:11 +02001476 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001477 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001478
1479 /* cf. IEEE 802.11 9.2.12 */
1480 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1481 have_higher_than_11mbit)
1482 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1483 else
1484 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001485
Sujithe65c2262009-03-02 13:28:31 +05301486 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */
1487 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001488 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001489 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001490
1491 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001492
Johannes Berg4b7679a2008-09-18 18:14:18 +02001493 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001494
Johannes Berg46900292009-02-15 12:44:28 +01001495 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001496 set_sta_flags(sta, WLAN_STA_MFP);
1497
Johannes Bergddf4ac52008-10-22 11:41:38 +02001498 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001499 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001500
1501 if (newsta) {
1502 int err = sta_info_insert(sta);
1503 if (err) {
1504 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1505 " the AP (error %d)\n", sdata->dev->name, err);
1506 rcu_read_unlock();
1507 return;
1508 }
1509 }
1510
1511 rcu_read_unlock();
1512
1513 if (elems.wmm_param)
Johannes Berg46900292009-02-15 12:44:28 +01001514 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001515 elems.wmm_param_len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001516
Johannes Bergae5eb022008-10-14 16:58:37 +02001517 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001518 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1519 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
Johannes Bergae5eb022008-10-14 16:58:37 +02001520 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1521 ap_ht_cap_flags);
1522
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001523 /* set AID and assoc capability,
1524 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001525 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001526 bss_conf->assoc_capability = capab_info;
Johannes Berg46900292009-02-15 12:44:28 +01001527 ieee80211_set_associated(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001528
Kalle Valo15b7b062009-03-22 21:57:14 +02001529 /*
1530 * initialise the time of last beacon to be the association time,
1531 * otherwise beacon loss check will trigger immediately
1532 */
1533 ifmgd->last_beacon = jiffies;
1534
Johannes Berg46900292009-02-15 12:44:28 +01001535 ieee80211_associated(sdata);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02001536 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
Jiri Bencf0706e82007-05-05 11:45:53 -07001537}
1538
1539
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001540static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001541 struct ieee80211_mgmt *mgmt,
1542 size_t len,
1543 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001544 struct ieee802_11_elems *elems,
1545 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001546{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001547 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001548 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001549 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001550 struct ieee80211_channel *channel;
Jiri Bencf0706e82007-05-05 11:45:53 -07001551
Johannes Berg5bda6172008-09-08 11:05:10 +02001552 if (elems->ds_params && elems->ds_params_len == 1)
1553 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1554 else
1555 freq = rx_status->freq;
1556
1557 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1558
1559 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1560 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001561
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001562 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001563 channel, beacon);
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001564 if (!bss)
1565 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001566
Sujithc481ec92009-01-06 09:28:37 +05301567 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg46900292009-02-15 12:44:28 +01001568 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301569 struct ieee80211_channel_sw_ie *sw_elem =
1570 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1571 ieee80211_process_chanswitch(sdata, sw_elem, bss);
1572 }
1573
Johannes Berg3e122be2008-07-09 14:40:34 +02001574 ieee80211_rx_bss_put(local, bss);
Jiri Bencf0706e82007-05-05 11:45:53 -07001575}
1576
1577
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001578static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001579 struct ieee80211_mgmt *mgmt,
1580 size_t len,
1581 struct ieee80211_rx_status *rx_status)
1582{
Kalle Valo15b7b062009-03-22 21:57:14 +02001583 struct ieee80211_if_managed *ifmgd;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001584 size_t baselen;
1585 struct ieee802_11_elems elems;
1586
Kalle Valo15b7b062009-03-22 21:57:14 +02001587 ifmgd = &sdata->u.mgd;
1588
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001589 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1590 return; /* ignore ProbeResp to foreign address */
1591
Ester Kummerae6a44e2008-06-27 18:54:48 +03001592 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1593 if (baselen > len)
1594 return;
1595
1596 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1597 &elems);
1598
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001599 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001600
1601 /* direct probe may be part of the association flow */
1602 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE,
Kalle Valo15b7b062009-03-22 21:57:14 +02001603 &ifmgd->request)) {
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001604 printk(KERN_DEBUG "%s direct probe responded\n",
1605 sdata->dev->name);
Johannes Berg46900292009-02-15 12:44:28 +01001606 ieee80211_authenticate(sdata);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001607 }
Kalle Valo15b7b062009-03-22 21:57:14 +02001608
1609 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1610 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001611}
1612
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001613static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001614 struct ieee80211_mgmt *mgmt,
1615 size_t len,
1616 struct ieee80211_rx_status *rx_status)
1617{
Johannes Berg46900292009-02-15 12:44:28 +01001618 struct ieee80211_if_managed *ifmgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001619 size_t baselen;
1620 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001621 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001622 u32 changed = 0;
Kalle Valo1fb36062009-02-10 17:09:24 +02001623 bool erp_valid, directed_tim;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001624 u8 erp_value = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001625
Ester Kummerae6a44e2008-06-27 18:54:48 +03001626 /* Process beacon from the current BSS */
1627 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1628 if (baselen > len)
1629 return;
1630
1631 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1632
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001633 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
Jiri Bencf0706e82007-05-05 11:45:53 -07001634
Johannes Berg05c914f2008-09-11 00:01:58 +02001635 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Jiri Bencf0706e82007-05-05 11:45:53 -07001636 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001637
Johannes Berg46900292009-02-15 12:44:28 +01001638 ifmgd = &sdata->u.mgd;
1639
1640 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1641 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001642 return;
1643
Sujithc481ec92009-01-06 09:28:37 +05301644 if (rx_status->freq != local->hw.conf.channel->center_freq)
1645 return;
1646
Johannes Berg46900292009-02-15 12:44:28 +01001647 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
Johannes Bergfe3fa822008-09-08 11:05:09 +02001648 elems.wmm_param_len);
1649
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301650 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Johannes Berg46900292009-02-15 12:44:28 +01001651 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001652
Kalle Valo1fb36062009-02-10 17:09:24 +02001653 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001654 if (local->hw.conf.dynamic_ps_timeout > 0) {
1655 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1656 ieee80211_hw_config(local,
1657 IEEE80211_CONF_CHANGE_PS);
1658 ieee80211_send_nullfunc(local, sdata, 0);
1659 } else {
1660 local->pspolling = true;
1661
1662 /*
1663 * Here is assumed that the driver will be
1664 * able to send ps-poll frame and receive a
1665 * response even though power save mode is
1666 * enabled, but some drivers might require
1667 * to disable power save here. This needs
1668 * to be investigated.
1669 */
1670 ieee80211_send_pspoll(local, sdata);
1671 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001672 }
1673 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001674
1675 if (elems.erp_info && elems.erp_info_len >= 1) {
1676 erp_valid = true;
1677 erp_value = elems.erp_info[0];
1678 } else {
1679 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001680 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001681 changed |= ieee80211_handle_bss_capability(sdata,
1682 le16_to_cpu(mgmt->u.beacon.capab_info),
1683 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001684
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001685
Vasanthakumar Thiagarajan53d6f81c2009-02-11 22:18:49 +05301686 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Berg46900292009-02-15 12:44:28 +01001687 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001688 struct sta_info *sta;
1689 struct ieee80211_supported_band *sband;
1690 u16 ap_ht_cap_flags;
1691
1692 rcu_read_lock();
1693
Johannes Berg46900292009-02-15 12:44:28 +01001694 sta = sta_info_get(local, ifmgd->bssid);
Johannes Bergae5eb022008-10-14 16:58:37 +02001695 if (!sta) {
1696 rcu_read_unlock();
1697 return;
1698 }
1699
1700 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1701
1702 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1703 elems.ht_cap_elem, &sta->sta.ht_cap);
1704
1705 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1706
1707 rcu_read_unlock();
1708
1709 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1710 ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001711 }
1712
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001713 if (elems.country_elem) {
1714 /* Note we are only reviewing this on beacons
1715 * for the BSSID we are associated to */
1716 regulatory_hint_11d(local->hw.wiphy,
1717 elems.country_elem, elems.country_elem_len);
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301718
1719 /* TODO: IBSS also needs this */
1720 if (elems.pwr_constr_elem)
1721 ieee80211_handle_pwr_constr(sdata,
1722 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1723 elems.pwr_constr_elem,
1724 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001725 }
1726
Johannes Berg471b3ef2007-12-28 14:32:58 +01001727 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001728}
1729
Johannes Berg46900292009-02-15 12:44:28 +01001730ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
1731 struct sk_buff *skb,
1732 struct ieee80211_rx_status *rx_status)
Jiri Bencf0706e82007-05-05 11:45:53 -07001733{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001734 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001735 struct ieee80211_mgmt *mgmt;
1736 u16 fc;
1737
1738 if (skb->len < 24)
Johannes Berg46900292009-02-15 12:44:28 +01001739 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001740
1741 mgmt = (struct ieee80211_mgmt *) skb->data;
1742 fc = le16_to_cpu(mgmt->frame_control);
1743
1744 switch (fc & IEEE80211_FCTL_STYPE) {
1745 case IEEE80211_STYPE_PROBE_REQ:
1746 case IEEE80211_STYPE_PROBE_RESP:
1747 case IEEE80211_STYPE_BEACON:
1748 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1749 case IEEE80211_STYPE_AUTH:
1750 case IEEE80211_STYPE_ASSOC_RESP:
1751 case IEEE80211_STYPE_REASSOC_RESP:
1752 case IEEE80211_STYPE_DEAUTH:
1753 case IEEE80211_STYPE_DISASSOC:
Johannes Berg46900292009-02-15 12:44:28 +01001754 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
1755 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
1756 return RX_QUEUED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001757 }
1758
Johannes Berg46900292009-02-15 12:44:28 +01001759 return RX_DROP_MONITOR;
Jiri Bencf0706e82007-05-05 11:45:53 -07001760}
1761
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001762static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001763 struct sk_buff *skb)
1764{
1765 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001766 struct ieee80211_mgmt *mgmt;
1767 u16 fc;
1768
Jiri Bencf0706e82007-05-05 11:45:53 -07001769 rx_status = (struct ieee80211_rx_status *) skb->cb;
1770 mgmt = (struct ieee80211_mgmt *) skb->data;
1771 fc = le16_to_cpu(mgmt->frame_control);
1772
Johannes Berg46900292009-02-15 12:44:28 +01001773 switch (fc & IEEE80211_FCTL_STYPE) {
1774 case IEEE80211_STYPE_PROBE_RESP:
1775 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len,
1776 rx_status);
1777 break;
1778 case IEEE80211_STYPE_BEACON:
1779 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1780 rx_status);
1781 break;
1782 case IEEE80211_STYPE_AUTH:
1783 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
1784 break;
1785 case IEEE80211_STYPE_ASSOC_RESP:
1786 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0);
1787 break;
1788 case IEEE80211_STYPE_REASSOC_RESP:
1789 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1);
1790 break;
1791 case IEEE80211_STYPE_DEAUTH:
1792 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1793 break;
1794 case IEEE80211_STYPE_DISASSOC:
1795 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1796 break;
Jiri Bencf0706e82007-05-05 11:45:53 -07001797 }
1798
1799 kfree_skb(skb);
1800}
1801
Johannes Berg9c6bd792008-09-11 00:01:52 +02001802static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001803{
1804 struct ieee80211_sub_if_data *sdata =
1805 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001806 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001807 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001808
Johannes Berg46900292009-02-15 12:44:28 +01001809 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1810 queue_work(local->hw.workqueue, &ifmgd->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001811}
1812
Johannes Berg46900292009-02-15 12:44:28 +01001813static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001814{
Johannes Berg46900292009-02-15 12:44:28 +01001815 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001816 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001817
1818 if (local->ops->reset_tsf) {
1819 /* Reset own TSF to allow time synchronization work. */
1820 local->ops->reset_tsf(local_to_hw(local));
1821 }
1822
Johannes Berg46900292009-02-15 12:44:28 +01001823 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
Jiri Bencf0706e82007-05-05 11:45:53 -07001824
1825
Johannes Berg46900292009-02-15 12:44:28 +01001826 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1827 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1828 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1829 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY;
1830 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1831 ifmgd->auth_alg = WLAN_AUTH_LEAP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02001832 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT)
1833 ifmgd->auth_alg = WLAN_AUTH_FT;
Jiri Bencf0706e82007-05-05 11:45:53 -07001834 else
Johannes Berg46900292009-02-15 12:44:28 +01001835 ifmgd->auth_alg = WLAN_AUTH_OPEN;
1836 ifmgd->auth_transaction = -1;
1837 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1838 ifmgd->assoc_scan_tries = 0;
1839 ifmgd->direct_probe_tries = 0;
1840 ifmgd->auth_tries = 0;
1841 ifmgd->assoc_tries = 0;
Tomas Winkler24e64622008-09-08 17:33:40 +02001842 netif_tx_stop_all_queues(sdata->dev);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001843 netif_carrier_off(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001844}
1845
Johannes Berg46900292009-02-15 12:44:28 +01001846static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
Jiri Bencf0706e82007-05-05 11:45:53 -07001847{
Johannes Berg46900292009-02-15 12:44:28 +01001848 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001849 struct ieee80211_local *local = sdata->local;
Johannes Bergc2b13452008-09-11 00:01:55 +02001850 struct ieee80211_bss *bss;
Johannes Berg46900292009-02-15 12:44:28 +01001851 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
1852 u8 ssid_len = ifmgd->ssid_len;
Johannes Berg00d3f142009-02-10 21:26:00 +01001853 u16 capa_mask = WLAN_CAPABILITY_ESS;
1854 u16 capa_val = WLAN_CAPABILITY_ESS;
1855 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg60f8b392008-09-08 17:44:22 +02001856
Jouni Malinen636a5d32009-03-19 13:39:22 +02001857 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) &&
1858 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL |
Johannes Berg00d3f142009-02-10 21:26:00 +01001859 IEEE80211_STA_AUTO_BSSID_SEL |
1860 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
1861 capa_mask |= WLAN_CAPABILITY_PRIVACY;
1862 if (sdata->default_key)
1863 capa_val |= WLAN_CAPABILITY_PRIVACY;
Johannes Berg60f8b392008-09-08 17:44:22 +02001864 }
Johannes Berg60f8b392008-09-08 17:44:22 +02001865
Johannes Berg46900292009-02-15 12:44:28 +01001866 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01001867 chan = NULL;
1868
Johannes Berg46900292009-02-15 12:44:28 +01001869 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL)
Johannes Berg00d3f142009-02-10 21:26:00 +01001870 bssid = NULL;
1871
Johannes Berg46900292009-02-15 12:44:28 +01001872 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) {
Johannes Berg00d3f142009-02-10 21:26:00 +01001873 ssid = NULL;
1874 ssid_len = 0;
1875 }
1876
1877 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan,
1878 bssid, ssid, ssid_len,
1879 capa_mask, capa_val);
1880
1881 if (bss) {
1882 ieee80211_set_freq(sdata, bss->cbss.channel->center_freq);
Johannes Berg46900292009-02-15 12:44:28 +01001883 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET))
Johannes Berg00d3f142009-02-10 21:26:00 +01001884 ieee80211_sta_set_ssid(sdata, bss->ssid,
1885 bss->ssid_len);
1886 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
1887 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
1888 bss->supp_rates);
Johannes Berg46900292009-02-15 12:44:28 +01001889 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
1890 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
Jouni Malinenfdfacf02009-01-08 13:32:05 +02001891 else
Johannes Berg46900292009-02-15 12:44:28 +01001892 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
Johannes Berg60f8b392008-09-08 17:44:22 +02001893
1894 /* Send out direct probe if no probe resp was received or
1895 * the one we have is outdated
1896 */
Johannes Berg00d3f142009-02-10 21:26:00 +01001897 if (!bss->last_probe_resp ||
1898 time_after(jiffies, bss->last_probe_resp
Johannes Berg60f8b392008-09-08 17:44:22 +02001899 + IEEE80211_SCAN_RESULT_EXPIRE))
Johannes Berg46900292009-02-15 12:44:28 +01001900 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
Johannes Berg60f8b392008-09-08 17:44:22 +02001901 else
Johannes Berg46900292009-02-15 12:44:28 +01001902 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
Johannes Berg60f8b392008-09-08 17:44:22 +02001903
Johannes Berg00d3f142009-02-10 21:26:00 +01001904 ieee80211_rx_bss_put(local, bss);
Johannes Berg46900292009-02-15 12:44:28 +01001905 ieee80211_sta_reset_auth(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001906 return 0;
1907 } else {
Johannes Berg46900292009-02-15 12:44:28 +01001908 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
1909 ifmgd->assoc_scan_tries++;
Johannes Berg2a519312009-02-10 21:25:55 +01001910 /* XXX maybe racy? */
1911 if (local->scan_req)
1912 return -1;
1913 memcpy(local->int_scan_req.ssids[0].ssid,
Johannes Berg46900292009-02-15 12:44:28 +01001914 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
1915 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
Johannes Berg2a519312009-02-10 21:25:55 +01001916 local->int_scan_req.ssids[0].ssid_len = 0;
Johannes Berg60f8b392008-09-08 17:44:22 +02001917 else
Johannes Berg46900292009-02-15 12:44:28 +01001918 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
Helmut Schaaaf88b902009-03-09 15:47:08 +01001919
1920 if (ieee80211_start_scan(sdata, &local->int_scan_req))
1921 ieee80211_scan_failed(local);
1922
Johannes Berg46900292009-02-15 12:44:28 +01001923 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
1924 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
Sujithe3740552009-01-29 09:34:22 +05301925 } else {
Johannes Berg46900292009-02-15 12:44:28 +01001926 ifmgd->assoc_scan_tries = 0;
1927 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
Sujithe3740552009-01-29 09:34:22 +05301928 }
Johannes Berg60f8b392008-09-08 17:44:22 +02001929 }
1930 return -1;
1931}
1932
1933
Johannes Berg9c6bd792008-09-11 00:01:52 +02001934static void ieee80211_sta_work(struct work_struct *work)
Johannes Berg60f8b392008-09-08 17:44:22 +02001935{
1936 struct ieee80211_sub_if_data *sdata =
Johannes Berg46900292009-02-15 12:44:28 +01001937 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
Johannes Berg60f8b392008-09-08 17:44:22 +02001938 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001939 struct ieee80211_if_managed *ifmgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001940 struct sk_buff *skb;
1941
1942 if (!netif_running(sdata->dev))
1943 return;
1944
Johannes Bergc2b13452008-09-11 00:01:55 +02001945 if (local->sw_scanning || local->hw_scanning)
Johannes Berg60f8b392008-09-08 17:44:22 +02001946 return;
1947
Johannes Berg46900292009-02-15 12:44:28 +01001948 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg60f8b392008-09-08 17:44:22 +02001949 return;
Johannes Berg46900292009-02-15 12:44:28 +01001950 ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001951
Johannes Berg46900292009-02-15 12:44:28 +01001952 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
Johannes Berg60f8b392008-09-08 17:44:22 +02001953 ieee80211_sta_rx_queued_mgmt(sdata, skb);
1954
Johannes Berg46900292009-02-15 12:44:28 +01001955 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
1956 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
1957 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
1958 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
Helmut Schaaaf88b902009-03-09 15:47:08 +01001959 /*
1960 * The call to ieee80211_start_scan can fail but ieee80211_request_scan
1961 * (which queued ieee80211_sta_work) did not return an error. Thus, call
1962 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
1963 * notify the scan requester.
1964 */
1965 if (ieee80211_start_scan(sdata, local->scan_req))
1966 ieee80211_scan_failed(local);
Johannes Berg60f8b392008-09-08 17:44:22 +02001967 return;
1968 }
1969
Johannes Berg46900292009-02-15 12:44:28 +01001970 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) {
1971 if (ieee80211_sta_config_auth(sdata))
Johannes Berg60f8b392008-09-08 17:44:22 +02001972 return;
Johannes Berg46900292009-02-15 12:44:28 +01001973 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1974 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
Johannes Berg60f8b392008-09-08 17:44:22 +02001975 return;
1976
Johannes Berg46900292009-02-15 12:44:28 +01001977 switch (ifmgd->state) {
Johannes Berg60f8b392008-09-08 17:44:22 +02001978 case IEEE80211_STA_MLME_DISABLED:
1979 break;
1980 case IEEE80211_STA_MLME_DIRECT_PROBE:
Johannes Berg46900292009-02-15 12:44:28 +01001981 ieee80211_direct_probe(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001982 break;
1983 case IEEE80211_STA_MLME_AUTHENTICATE:
Johannes Berg46900292009-02-15 12:44:28 +01001984 ieee80211_authenticate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001985 break;
1986 case IEEE80211_STA_MLME_ASSOCIATE:
Johannes Berg46900292009-02-15 12:44:28 +01001987 ieee80211_associate(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001988 break;
1989 case IEEE80211_STA_MLME_ASSOCIATED:
Johannes Berg46900292009-02-15 12:44:28 +01001990 ieee80211_associated(sdata);
Johannes Berg60f8b392008-09-08 17:44:22 +02001991 break;
Johannes Berg60f8b392008-09-08 17:44:22 +02001992 default:
1993 WARN_ON(1);
1994 break;
1995 }
1996
Johannes Berg46900292009-02-15 12:44:28 +01001997 if (ieee80211_privacy_mismatch(sdata)) {
Johannes Berg60f8b392008-09-08 17:44:22 +02001998 printk(KERN_DEBUG "%s: privacy configuration mismatch and "
1999 "mixed-cell disabled - disassociate\n", sdata->dev->name);
2000
Johannes Berg46900292009-02-15 12:44:28 +01002001 ieee80211_set_disassoc(sdata, false, true,
Johannes Berg60f8b392008-09-08 17:44:22 +02002002 WLAN_REASON_UNSPECIFIED);
2003 }
2004}
Johannes Berg0a51b272008-09-08 17:44:25 +02002005
Johannes Berga1678f82008-09-11 00:01:47 +02002006static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2007{
Kalle Vaload935682009-04-19 08:47:19 +03002008 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2009 /*
2010 * Need to update last_beacon to avoid beacon loss
2011 * test to trigger.
2012 */
2013 sdata->u.mgd.last_beacon = jiffies;
2014
2015
Johannes Berg7c950692008-09-11 00:01:48 +02002016 queue_work(sdata->local->hw.workqueue,
Johannes Berg46900292009-02-15 12:44:28 +01002017 &sdata->u.mgd.work);
Kalle Vaload935682009-04-19 08:47:19 +03002018 }
Johannes Berga1678f82008-09-11 00:01:47 +02002019}
2020
Johannes Berg9c6bd792008-09-11 00:01:52 +02002021/* interface setup */
2022void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2023{
Johannes Berg46900292009-02-15 12:44:28 +01002024 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002025
Johannes Berg46900292009-02-15 12:44:28 +01002026 ifmgd = &sdata->u.mgd;
2027 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2028 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Kalle Valo04de8382009-03-22 21:57:35 +02002029 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
Johannes Berg46900292009-02-15 12:44:28 +01002030 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002031 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002032 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302033 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002034 skb_queue_head_init(&ifmgd->skb_queue);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002035
Johannes Berg46900292009-02-15 12:44:28 +01002036 ifmgd->capab = WLAN_CAPABILITY_ESS;
2037 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002038 IEEE80211_AUTH_ALG_SHARED_KEY;
Johannes Berg46900292009-02-15 12:44:28 +01002039 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002040 IEEE80211_STA_AUTO_BSSID_SEL |
2041 IEEE80211_STA_AUTO_CHANNEL_SEL;
Johannes Berg176be722009-03-12 23:49:28 +01002042 if (sdata->local->hw.queues >= 4)
Johannes Berg46900292009-02-15 12:44:28 +01002043 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002044}
2045
2046/* configuration hooks */
Johannes Berg46900292009-02-15 12:44:28 +01002047void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002048{
Johannes Berg46900292009-02-15 12:44:28 +01002049 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002050 struct ieee80211_local *local = sdata->local;
2051
Johannes Berg46900292009-02-15 12:44:28 +01002052 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
Johannes Berg9c6bd792008-09-11 00:01:52 +02002053 return;
2054
Johannes Berg46900292009-02-15 12:44:28 +01002055 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002056 IEEE80211_STA_AUTO_BSSID_SEL)) &&
Johannes Berg46900292009-02-15 12:44:28 +01002057 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
Johannes Berg9c6bd792008-09-11 00:01:52 +02002058 IEEE80211_STA_AUTO_SSID_SEL))) {
2059
Johannes Berg46900292009-02-15 12:44:28 +01002060 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2061 ieee80211_set_disassoc(sdata, true, true,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002062 WLAN_REASON_DEAUTH_LEAVING);
2063
Jouni Malinen636a5d32009-03-19 13:39:22 +02002064 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) ||
2065 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE)
2066 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
2067 else if (ifmgd->flags & IEEE80211_STA_EXT_SME)
2068 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
Johannes Berg46900292009-02-15 12:44:28 +01002069 queue_work(local->hw.workqueue, &ifmgd->work);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002070 }
2071}
2072
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002073int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata)
2074{
2075 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2076
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002077 if (ifmgd->ssid_len)
2078 ifmgd->flags |= IEEE80211_STA_SSID_SET;
2079 else
2080 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2081
2082 return 0;
2083}
2084
Johannes Berg9c6bd792008-09-11 00:01:52 +02002085int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2086{
Johannes Berg46900292009-02-15 12:44:28 +01002087 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002088
2089 if (len > IEEE80211_MAX_SSID_LEN)
2090 return -EINVAL;
2091
Johannes Berg46900292009-02-15 12:44:28 +01002092 ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002093
Johannes Berg46900292009-02-15 12:44:28 +01002094 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) {
Jouni Malinena2995422009-03-19 13:39:20 +02002095 /*
2096 * Do not use reassociation if SSID is changed (different ESS).
2097 */
2098 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
Johannes Berg46900292009-02-15 12:44:28 +01002099 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2100 memcpy(ifmgd->ssid, ssid, len);
2101 ifmgd->ssid_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002102 }
2103
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002104 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002105}
2106
2107int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2108{
Johannes Berg46900292009-02-15 12:44:28 +01002109 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2110 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len);
2111 *len = ifmgd->ssid_len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002112 return 0;
2113}
2114
2115int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2116{
Johannes Berg46900292009-02-15 12:44:28 +01002117 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002118
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002119 if (is_valid_ether_addr(bssid)) {
Johannes Berg46900292009-02-15 12:44:28 +01002120 memcpy(ifmgd->bssid, bssid, ETH_ALEN);
2121 ifmgd->flags |= IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002122 } else {
Johannes Berg46900292009-02-15 12:44:28 +01002123 memset(ifmgd->bssid, 0, ETH_ALEN);
2124 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
Alina Friedrichsendfe67012009-01-24 01:19:04 +01002125 }
2126
2127 if (netif_running(sdata->dev)) {
2128 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
Johannes Berg9c6bd792008-09-11 00:01:52 +02002129 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2130 "the low-level driver\n", sdata->dev->name);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002131 }
2132 }
2133
Alina Friedrichsen79f64402009-02-21 01:27:29 +01002134 return ieee80211_sta_commit(sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002135}
2136
Jouni Malinen636a5d32009-03-19 13:39:22 +02002137int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2138 const char *ie, size_t len)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002139{
Johannes Berg46900292009-02-15 12:44:28 +01002140 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002141
Johannes Berg46900292009-02-15 12:44:28 +01002142 kfree(ifmgd->extra_ie);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002143 if (len == 0) {
Johannes Berg46900292009-02-15 12:44:28 +01002144 ifmgd->extra_ie = NULL;
2145 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002146 return 0;
2147 }
Johannes Berg46900292009-02-15 12:44:28 +01002148 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL);
2149 if (!ifmgd->extra_ie) {
2150 ifmgd->extra_ie_len = 0;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002151 return -ENOMEM;
2152 }
Johannes Berg46900292009-02-15 12:44:28 +01002153 memcpy(ifmgd->extra_ie, ie, len);
2154 ifmgd->extra_ie_len = len;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002155 return 0;
2156}
2157
2158int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2159{
Johannes Berg9c6bd792008-09-11 00:01:52 +02002160 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2161 sdata->dev->name, reason);
2162
Johannes Berg46900292009-02-15 12:44:28 +01002163 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002164 return -EINVAL;
2165
Johannes Berg46900292009-02-15 12:44:28 +01002166 ieee80211_set_disassoc(sdata, true, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002167 return 0;
2168}
2169
2170int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2171{
Johannes Berg46900292009-02-15 12:44:28 +01002172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002173
2174 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2175 sdata->dev->name, reason);
2176
Johannes Berg05c914f2008-09-11 00:01:58 +02002177 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Johannes Berg9c6bd792008-09-11 00:01:52 +02002178 return -EINVAL;
2179
Johannes Berg46900292009-02-15 12:44:28 +01002180 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2181 return -ENOLINK;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002182
Johannes Berg46900292009-02-15 12:44:28 +01002183 ieee80211_set_disassoc(sdata, false, true, reason);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002184 return 0;
2185}
2186
2187/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002188void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2189{
2190 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002191
2192 /* Restart STA timers */
2193 rcu_read_lock();
2194 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2195 ieee80211_restart_sta_timer(sdata);
2196 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002197}
Kalle Valo520eb822008-12-18 23:35:27 +02002198
2199void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
2200{
2201 struct ieee80211_local *local =
2202 container_of(work, struct ieee80211_local,
2203 dynamic_ps_disable_work);
2204
2205 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2206 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2207 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2208 }
2209
2210 ieee80211_wake_queues_by_reason(&local->hw,
2211 IEEE80211_QUEUE_STOP_REASON_PS);
2212}
2213
2214void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2215{
2216 struct ieee80211_local *local =
2217 container_of(work, struct ieee80211_local,
2218 dynamic_ps_enable_work);
Johannes Berg7181d462009-04-15 21:33:15 +02002219 /* XXX: using scan_sdata is completely broken! */
Vivek Natarajana97b77b2008-12-23 18:39:02 -08002220 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Kalle Valo520eb822008-12-18 23:35:27 +02002221
2222 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2223 return;
2224
Johannes Berg7181d462009-04-15 21:33:15 +02002225 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
Johannes Berg4be8c382009-01-07 18:28:20 +01002226 ieee80211_send_nullfunc(local, sdata, 1);
Kalle Valo520eb822008-12-18 23:35:27 +02002227
Johannes Berg4be8c382009-01-07 18:28:20 +01002228 local->hw.conf.flags |= IEEE80211_CONF_PS;
Kalle Valo520eb822008-12-18 23:35:27 +02002229 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2230}
2231
2232void ieee80211_dynamic_ps_timer(unsigned long data)
2233{
2234 struct ieee80211_local *local = (void *) data;
2235
2236 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
2237}
Johannes Berg46900292009-02-15 12:44:28 +01002238
2239void ieee80211_send_nullfunc(struct ieee80211_local *local,
2240 struct ieee80211_sub_if_data *sdata,
2241 int powersave)
2242{
2243 struct sk_buff *skb;
2244 struct ieee80211_hdr *nullfunc;
2245 __le16 fc;
2246
2247 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2248 return;
2249
2250 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
2251 if (!skb) {
2252 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2253 "frame\n", sdata->dev->name);
2254 return;
2255 }
2256 skb_reserve(skb, local->hw.extra_tx_headroom);
2257
2258 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
2259 memset(nullfunc, 0, 24);
2260 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2261 IEEE80211_FCTL_TODS);
2262 if (powersave)
2263 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
2264 nullfunc->frame_control = fc;
2265 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2266 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
2267 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
2268
2269 ieee80211_tx_skb(sdata, skb, 0);
2270}