blob: 64d92d5a7f40e93c001dabf3bc9680d0adfab4e5 [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010019#include <linux/rtnetlink.h>
Johannes Berg10f644a2009-04-16 13:17:25 +020020#include <linux/pm_qos_params.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020021#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070023#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020024#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020025
Jiri Bencf0706e822007-05-05 11:45:53 -070026#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020027#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040028#include "rate.h"
29#include "led.h"
Jiri Bencf0706e822007-05-05 11:45:53 -070030
Ben Greear180205b2011-02-04 15:30:24 -080031static int max_nullfunc_tries = 2;
32module_param(max_nullfunc_tries, int, 0644);
33MODULE_PARM_DESC(max_nullfunc_tries,
34 "Maximum nullfunc tx tries before disconnecting (reason 4).");
35
36static int max_probe_tries = 5;
37module_param(max_probe_tries, int, 0644);
38MODULE_PARM_DESC(max_probe_tries,
39 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020040
41/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010042 * Beacon loss timeout is calculated as N frames times the
43 * advertised beacon interval. This may need to be somewhat
44 * higher than what hardware might detect to account for
45 * delays in the host processing frames. But since we also
46 * probe on beacon miss before declaring the connection lost
47 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020048 */
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010049#define IEEE80211_BEACON_LOSS_COUNT 7
50
Johannes Bergb291ba12009-07-10 15:29:03 +020051/*
52 * Time the connection can be idle before we probe
53 * it to see if we can still talk to the AP.
54 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030055#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020056/*
57 * Time we wait for a probe response after sending
58 * a probe request because of beacon loss or for
59 * checking the connection still works.
60 */
Ben Greear180205b2011-02-04 15:30:24 -080061static int probe_wait_ms = 500;
62module_param(probe_wait_ms, int, 0644);
63MODULE_PARM_DESC(probe_wait_ms,
64 "Maximum time(ms) to wait for probe response"
65 " before disconnecting (reason 4).");
Jiri Bencf0706e822007-05-05 11:45:53 -070066
Jouni Malinen17e4ec12010-03-29 23:28:30 -070067/*
68 * Weight given to the latest Beacon frame when calculating average signal
69 * strength for Beacon frames received in the current BSS. This must be
70 * between 1 and 15.
71 */
72#define IEEE80211_SIGNAL_AVE_WEIGHT 3
73
Jouni Malinen391a2002010-08-27 22:22:00 +030074/*
75 * How many Beacon frames need to have been used in average signal strength
76 * before starting to indicate signal change events.
77 */
78#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
79
Johannes Berg5bb644a2009-05-17 11:40:42 +020080#define TMR_RUNNING_TIMER 0
81#define TMR_RUNNING_CHANSW 1
82
Johannes Berg77fdaa12009-07-07 03:45:17 +020083/*
84 * All cfg80211 functions have to be called outside a locked
85 * section so that they can acquire a lock themselves... This
86 * is much simpler than queuing up things in cfg80211, but we
87 * do need some indirection for that here.
88 */
89enum rx_mgmt_action {
90 /* no action required */
91 RX_MGMT_NONE,
92
93 /* caller must call cfg80211_send_rx_auth() */
94 RX_MGMT_CFG80211_AUTH,
95
96 /* caller must call cfg80211_send_rx_assoc() */
97 RX_MGMT_CFG80211_ASSOC,
98
99 /* caller must call cfg80211_send_deauth() */
100 RX_MGMT_CFG80211_DEAUTH,
101
102 /* caller must call cfg80211_send_disassoc() */
103 RX_MGMT_CFG80211_DISASSOC,
104
Johannes Berg5d1ec852009-12-02 12:43:43 +0100105 /* caller must tell cfg80211 about internal error */
106 RX_MGMT_CFG80211_ASSOC_ERROR,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200107};
108
Johannes Berg5484e232008-09-08 17:44:27 +0200109/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200110static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
111{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200112 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200113}
114
Johannes Bergca386f32009-07-10 02:39:48 +0200115/*
116 * We can have multiple work items (and connection probing)
117 * scheduling this timer, but we need to take care to only
118 * reschedule it when it should fire _earlier_ than it was
119 * asked for before, or if it's not pending right now. This
120 * function ensures that. Note that it then is required to
121 * run this function for all timeouts after the first one
122 * has happened -- the work that runs from this timer will
123 * do that.
124 */
125static void run_again(struct ieee80211_if_managed *ifmgd,
126 unsigned long timeout)
127{
128 ASSERT_MGD_MTX(ifmgd);
129
130 if (!timer_pending(&ifmgd->timer) ||
131 time_before(timeout, ifmgd->timer.expires))
132 mod_timer(&ifmgd->timer, timeout);
133}
134
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400135void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200136{
137 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
138 return;
139
140 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100141 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200142}
143
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400144void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
145{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400146 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
147
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100148 if (unlikely(!sdata->u.mgd.associated))
149 return;
150
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400151 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
152 return;
153
154 mod_timer(&sdata->u.mgd.conn_mon_timer,
155 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400156
157 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400158}
159
Johannes Berg5484e232008-09-08 17:44:27 +0200160static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200161{
Johannes Berg5484e232008-09-08 17:44:27 +0200162 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200163}
164
Johannes Bergd5522e02009-03-30 13:23:35 +0200165/*
166 * ieee80211_enable_ht should be called only after the operating band
167 * has been determined as ht configuration depends on the hw's
168 * HT abilities for a specific band.
169 */
170static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
171 struct ieee80211_ht_info *hti,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200172 const u8 *bssid, u16 ap_ht_cap_flags)
Johannes Bergd5522e02009-03-30 13:23:35 +0200173{
174 struct ieee80211_local *local = sdata->local;
175 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200176 struct sta_info *sta;
177 u32 changed = 0;
Ben Greear172710b2011-01-28 17:05:43 -0800178 int hti_cfreq;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200179 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200180 bool enable_ht = true;
181 enum nl80211_channel_type prev_chantype;
Johannes Bergd5522e02009-03-30 13:23:35 +0200182 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
183
184 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
185
Johannes Berg0aaffa92010-05-05 15:28:27 +0200186 prev_chantype = sdata->vif.bss_conf.channel_type;
187
Johannes Bergd5522e02009-03-30 13:23:35 +0200188 /* HT is not supported */
189 if (!sband->ht_cap.ht_supported)
190 enable_ht = false;
191
Ben Greear172710b2011-01-28 17:05:43 -0800192 if (enable_ht) {
193 hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
194 sband->band);
195 /* check that channel matches the right operating channel */
196 if (local->hw.conf.channel->center_freq != hti_cfreq) {
197 /* Some APs mess this up, evidently.
198 * Netgear WNDR3700 sometimes reports 4 higher than
199 * the actual channel, for instance.
200 */
201 printk(KERN_DEBUG
202 "%s: Wrong control channel in association"
203 " response: configured center-freq: %d"
204 " hti-cfreq: %d hti->control_chan: %d"
205 " band: %d. Disabling HT.\n",
206 sdata->name,
207 local->hw.conf.channel->center_freq,
208 hti_cfreq, hti->control_chan,
209 sband->band);
210 enable_ht = false;
211 }
212 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200213
214 if (enable_ht) {
215 channel_type = NL80211_CHAN_HT20;
216
217 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
218 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
219 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
220 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
221 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400222 if (!(local->hw.conf.channel->flags &
223 IEEE80211_CHAN_NO_HT40PLUS))
224 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200225 break;
226 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400227 if (!(local->hw.conf.channel->flags &
228 IEEE80211_CHAN_NO_HT40MINUS))
229 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200230 break;
231 }
232 }
233 }
234
Reinette Chatrefe6f2122010-04-19 10:46:31 -0700235 if (local->tmp_channel)
236 local->tmp_channel_type = channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200237
Johannes Berg0aaffa92010-05-05 15:28:27 +0200238 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
239 /* can only fail due to HT40+/- mismatch */
240 channel_type = NL80211_CHAN_HT20;
241 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
242 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200243
Johannes Berg0aaffa92010-05-05 15:28:27 +0200244 /* channel_type change automatically detected */
245 ieee80211_hw_config(local, 0);
246
247 if (prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200248 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100249 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200250 if (sta)
251 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530252 IEEE80211_RC_HT_CHANGED,
Johannes Berg0aaffa92010-05-05 15:28:27 +0200253 channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200254 rcu_read_unlock();
Johannes Berg0aaffa92010-05-05 15:28:27 +0200255 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200256
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200257 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200258
259 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200260 if (sdata->ht_opmode_valid != enable_ht ||
261 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
262 prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200263 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200264 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200265 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200266 }
267
268 return changed;
269}
270
Johannes Berg9c6bd792008-09-11 00:01:52 +0200271/* frame sending functions */
272
Johannes Bergef422bc2008-09-09 10:58:25 +0200273static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +0200274 const u8 *bssid, u16 stype, u16 reason,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300275 void *cookie, bool send_frame)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200276{
277 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100278 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200279 struct sk_buff *skb;
280 struct ieee80211_mgmt *mgmt;
281
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200282 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200283 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200284 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100285 "deauth/disassoc frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200286 return;
287 }
288 skb_reserve(skb, local->hw.extra_tx_headroom);
289
290 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
291 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200292 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100293 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200294 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200295 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200296 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200297 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200298 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
299
Jouni Malinen53b46b82009-03-27 20:53:56 +0200300 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470613c2009-10-13 13:28:13 +0200301 if (cookie)
302 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
303 else
304 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200305 else
Holger Schurigce470613c2009-10-13 13:28:13 +0200306 if (cookie)
307 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
308 else
309 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100310 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
311 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300312
313 if (send_frame)
314 ieee80211_tx_skb(sdata, skb);
315 else
316 kfree_skb(skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200317}
318
Kalle Valo572e0012009-02-10 17:09:31 +0200319void ieee80211_send_pspoll(struct ieee80211_local *local,
320 struct ieee80211_sub_if_data *sdata)
321{
Kalle Valo572e0012009-02-10 17:09:31 +0200322 struct ieee80211_pspoll *pspoll;
323 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200324
Kalle Valod8cd1892010-01-05 20:16:26 +0200325 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
326 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200327 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200328
Kalle Valod8cd1892010-01-05 20:16:26 +0200329 pspoll = (struct ieee80211_pspoll *) skb->data;
330 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200331
Johannes Berg62ae67b2009-11-18 18:42:05 +0100332 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
333 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200334}
335
Johannes Berg965beda2009-04-16 13:17:24 +0200336void ieee80211_send_nullfunc(struct ieee80211_local *local,
337 struct ieee80211_sub_if_data *sdata,
338 int powersave)
339{
340 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200341 struct ieee80211_hdr_3addr *nullfunc;
Johannes Berg965beda2009-04-16 13:17:24 +0200342
Kalle Valod8cd1892010-01-05 20:16:26 +0200343 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
344 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200345 return;
346
Kalle Valod8cd1892010-01-05 20:16:26 +0200347 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200348 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200349 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200350
Johannes Berg62ae67b2009-11-18 18:42:05 +0100351 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
352 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200353}
354
Felix Fietkaud5242152010-01-08 18:06:26 +0100355static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
356 struct ieee80211_sub_if_data *sdata)
357{
358 struct sk_buff *skb;
359 struct ieee80211_hdr *nullfunc;
360 __le16 fc;
361
362 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
363 return;
364
365 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
366 if (!skb) {
367 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
368 "nullfunc frame\n", sdata->name);
369 return;
370 }
371 skb_reserve(skb, local->hw.extra_tx_headroom);
372
373 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
374 memset(nullfunc, 0, 30);
375 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
376 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
377 nullfunc->frame_control = fc;
378 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
379 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
380 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
381 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
382
383 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
384 ieee80211_tx_skb(sdata, skb);
385}
386
Johannes Bergcc32abd2009-05-15 11:52:31 +0200387/* spectrum management related things */
388static void ieee80211_chswitch_work(struct work_struct *work)
389{
390 struct ieee80211_sub_if_data *sdata =
391 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200392 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
393
Johannes Berg9607e6b2009-12-23 13:15:31 +0100394 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200395 return;
396
Johannes Berg77fdaa12009-07-07 03:45:17 +0200397 mutex_lock(&ifmgd->mtx);
398 if (!ifmgd->associated)
399 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200400
401 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200402 if (!sdata->local->ops->channel_switch) {
403 /* call "hw_config" only if doing sw channel switch */
404 ieee80211_hw_config(sdata->local,
405 IEEE80211_CONF_CHANGE_CHANNEL);
406 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200407
Johannes Berg77fdaa12009-07-07 03:45:17 +0200408 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100409 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200410
Johannes Bergcc32abd2009-05-15 11:52:31 +0200411 ieee80211_wake_queues_by_reason(&sdata->local->hw,
412 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200413 out:
414 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
415 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200416}
417
Johannes Berg5ce6e432010-05-11 16:20:57 +0200418void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
419{
420 struct ieee80211_sub_if_data *sdata;
421 struct ieee80211_if_managed *ifmgd;
422
423 sdata = vif_to_sdata(vif);
424 ifmgd = &sdata->u.mgd;
425
426 trace_api_chswitch_done(sdata, success);
427 if (!success) {
428 /*
429 * If the channel switch was not successful, stay
430 * around on the old channel. We currently lack
431 * good handling of this situation, possibly we
432 * should just drop the association.
433 */
434 sdata->local->csa_channel = sdata->local->oper_channel;
435 }
436
437 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
438}
439EXPORT_SYMBOL(ieee80211_chswitch_done);
440
Johannes Bergcc32abd2009-05-15 11:52:31 +0200441static void ieee80211_chswitch_timer(unsigned long data)
442{
443 struct ieee80211_sub_if_data *sdata =
444 (struct ieee80211_sub_if_data *) data;
445 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
446
Johannes Berg5bb644a2009-05-17 11:40:42 +0200447 if (sdata->local->quiescing) {
448 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
449 return;
450 }
451
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400452 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200453}
454
455void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
456 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200457 struct ieee80211_bss *bss,
458 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200459{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100460 struct cfg80211_bss *cbss =
461 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200462 struct ieee80211_channel *new_ch;
463 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900464 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
465 cbss->channel->band);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200466
Johannes Berg77fdaa12009-07-07 03:45:17 +0200467 ASSERT_MGD_MTX(ifmgd);
468
469 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200470 return;
471
Helmut Schaafbe9c422009-07-23 12:14:04 +0200472 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200473 return;
474
475 /* Disregard subsequent beacons if we are already running a timer
476 processing a CSA */
477
478 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
479 return;
480
481 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
482 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
483 return;
484
485 sdata->local->csa_channel = new_ch;
486
Johannes Berg5ce6e432010-05-11 16:20:57 +0200487 if (sdata->local->ops->channel_switch) {
488 /* use driver's channel switch callback */
489 struct ieee80211_channel_switch ch_switch;
490 memset(&ch_switch, 0, sizeof(ch_switch));
491 ch_switch.timestamp = timestamp;
492 if (sw_elem->mode) {
493 ch_switch.block_tx = true;
494 ieee80211_stop_queues_by_reason(&sdata->local->hw,
495 IEEE80211_QUEUE_STOP_REASON_CSA);
496 }
497 ch_switch.channel = new_ch;
498 ch_switch.count = sw_elem->count;
499 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
500 drv_channel_switch(sdata->local, &ch_switch);
501 return;
502 }
503
504 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200505 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400506 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200507 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700508 if (sw_elem->mode)
509 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200510 IEEE80211_QUEUE_STOP_REASON_CSA);
511 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
512 mod_timer(&ifmgd->chswitch_timer,
513 jiffies +
514 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100515 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200516 }
517}
518
519static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
520 u16 capab_info, u8 *pwr_constr_elem,
521 u8 pwr_constr_elem_len)
522{
523 struct ieee80211_conf *conf = &sdata->local->hw.conf;
524
525 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
526 return;
527
528 /* Power constraint IE length should be 1 octet */
529 if (pwr_constr_elem_len != 1)
530 return;
531
532 if ((*pwr_constr_elem <= conf->channel->max_power) &&
533 (*pwr_constr_elem != sdata->local->power_constr_level)) {
534 sdata->local->power_constr_level = *pwr_constr_elem;
535 ieee80211_hw_config(sdata->local, 0);
536 }
537}
538
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300539void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
540{
541 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
542 struct ieee80211_local *local = sdata->local;
543 struct ieee80211_conf *conf = &local->hw.conf;
544
545 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
546 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
547 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
548
549 local->disable_dynamic_ps = false;
550 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
551}
552EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
553
554void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
555{
556 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
557 struct ieee80211_local *local = sdata->local;
558 struct ieee80211_conf *conf = &local->hw.conf;
559
560 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
561 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
562 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
563
564 local->disable_dynamic_ps = true;
565 conf->dynamic_ps_timeout = 0;
566 del_timer_sync(&local->dynamic_ps_timer);
567 ieee80211_queue_work(&local->hw,
568 &local->dynamic_ps_enable_work);
569}
570EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
571
Johannes Berg965beda2009-04-16 13:17:24 +0200572/* powersave */
573static void ieee80211_enable_ps(struct ieee80211_local *local,
574 struct ieee80211_sub_if_data *sdata)
575{
576 struct ieee80211_conf *conf = &local->hw.conf;
577
Johannes Bergd5edaed2009-04-22 23:02:51 +0200578 /*
579 * If we are scanning right now then the parameters will
580 * take effect when scan finishes.
581 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200582 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200583 return;
584
Johannes Berg965beda2009-04-16 13:17:24 +0200585 if (conf->dynamic_ps_timeout > 0 &&
586 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
587 mod_timer(&local->dynamic_ps_timer, jiffies +
588 msecs_to_jiffies(conf->dynamic_ps_timeout));
589 } else {
590 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
591 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530592
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200593 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
594 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
595 return;
596
597 conf->flags |= IEEE80211_CONF_PS;
598 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200599 }
600}
601
602static void ieee80211_change_ps(struct ieee80211_local *local)
603{
604 struct ieee80211_conf *conf = &local->hw.conf;
605
606 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200607 ieee80211_enable_ps(local, local->ps_sdata);
608 } else if (conf->flags & IEEE80211_CONF_PS) {
609 conf->flags &= ~IEEE80211_CONF_PS;
610 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
611 del_timer_sync(&local->dynamic_ps_timer);
612 cancel_work_sync(&local->dynamic_ps_enable_work);
613 }
614}
615
Jason Young808118c2011-03-10 16:43:19 -0800616static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
617{
618 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
619 struct sta_info *sta = NULL;
620 u32 sta_flags = 0;
621
622 if (!mgd->powersave)
623 return false;
624
625 if (!mgd->associated)
626 return false;
627
628 if (!mgd->associated->beacon_ies)
629 return false;
630
631 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
632 IEEE80211_STA_CONNECTION_POLL))
633 return false;
634
635 rcu_read_lock();
636 sta = sta_info_get(sdata, mgd->bssid);
637 if (sta)
638 sta_flags = get_sta_flags(sta);
639 rcu_read_unlock();
640
641 if (!(sta_flags & WLAN_STA_AUTHORIZED))
642 return false;
643
644 return true;
645}
646
Johannes Berg965beda2009-04-16 13:17:24 +0200647/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200648void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200649{
650 struct ieee80211_sub_if_data *sdata, *found = NULL;
651 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300652 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +0200653
654 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
655 local->ps_sdata = NULL;
656 return;
657 }
658
Johannes Bergaf6b6372009-12-23 13:15:35 +0100659 if (!list_empty(&local->work_list)) {
660 local->ps_sdata = NULL;
661 goto change;
662 }
663
Johannes Berg965beda2009-04-16 13:17:24 +0200664 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100665 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200666 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +0530667 if (sdata->vif.type == NL80211_IFTYPE_AP) {
668 /* If an AP vif is found, then disable PS
669 * by setting the count to zero thereby setting
670 * ps_sdata to NULL.
671 */
672 count = 0;
673 break;
674 }
Johannes Berg965beda2009-04-16 13:17:24 +0200675 if (sdata->vif.type != NL80211_IFTYPE_STATION)
676 continue;
677 found = sdata;
678 count++;
679 }
680
Jason Young808118c2011-03-10 16:43:19 -0800681 if (count == 1 && ieee80211_powersave_allowed(found)) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300682 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +0200683 s32 beaconint_us;
684
685 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +0200686 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +0200687
688 beaconint_us = ieee80211_tu_to_usec(
689 found->vif.bss_conf.beacon_int);
690
Juuso Oikarinenff616382010-06-09 09:51:52 +0300691 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300692 if (timeout < 0) {
693 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +0300694 * Go to full PSM if the user configures a very low
695 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +0200696 * The 2000 second value is there for compatibility
697 * until the PM_QOS_NETWORK_LATENCY is configured
698 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300699 */
Eliad Peller0ab82b02010-12-03 02:16:23 +0200700 if (latency > (1900 * USEC_PER_MSEC) &&
701 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300702 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +0300703 else
704 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300705 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300706 local->dynamic_ps_user_timeout = timeout;
707 if (!local->disable_dynamic_ps)
708 conf->dynamic_ps_timeout =
709 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300710
Johannes Berg04fe2032009-04-22 18:44:37 +0200711 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200712 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200713 } else {
Johannes Berg56007a02010-01-26 14:19:52 +0100714 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +0200715 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +0100716 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +0200717
Johannes Berg56007a02010-01-26 14:19:52 +0100718 bss = (void *)found->u.mgd.associated->priv;
719 dtimper = bss->dtim_period;
720
721 /* If the TIM IE is invalid, pretend the value is 1 */
722 if (!dtimper)
723 dtimper = 1;
724 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +0200725 maxslp = min_t(int, dtimper,
726 latency / beaconint_us);
727
Johannes Berg9ccebe62009-04-23 10:32:36 +0200728 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +0100729 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +0200730 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200731 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200732 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200733 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200734 }
Johannes Berg965beda2009-04-16 13:17:24 +0200735
Johannes Bergaf6b6372009-12-23 13:15:35 +0100736 change:
Johannes Berg965beda2009-04-16 13:17:24 +0200737 ieee80211_change_ps(local);
738}
739
740void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
741{
742 struct ieee80211_local *local =
743 container_of(work, struct ieee80211_local,
744 dynamic_ps_disable_work);
745
746 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
747 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
748 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
749 }
750
751 ieee80211_wake_queues_by_reason(&local->hw,
752 IEEE80211_QUEUE_STOP_REASON_PS);
753}
754
755void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
756{
757 struct ieee80211_local *local =
758 container_of(work, struct ieee80211_local,
759 dynamic_ps_enable_work);
760 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Vivek Natarajan375177b2010-02-09 14:50:28 +0530761 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200762
763 /* can only happen when PS was just disabled anyway */
764 if (!sdata)
765 return;
766
767 if (local->hw.conf.flags & IEEE80211_CONF_PS)
768 return;
769
Vivek Natarajan375177b2010-02-09 14:50:28 +0530770 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530771 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
772 netif_tx_stop_all_queues(sdata->dev);
773 /*
774 * Flush all the frames queued in the driver before
775 * going to power save
776 */
777 drv_flush(local, false);
Johannes Berg965beda2009-04-16 13:17:24 +0200778 ieee80211_send_nullfunc(local, sdata, 1);
779
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530780 /* Flush once again to get the tx status of nullfunc frame */
781 drv_flush(local, false);
782 }
783
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200784 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
785 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +0530786 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
787 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
788 local->hw.conf.flags |= IEEE80211_CONF_PS;
789 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
790 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530791
792 netif_tx_start_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +0200793}
794
795void ieee80211_dynamic_ps_timer(unsigned long data)
796{
797 struct ieee80211_local *local = (void *) data;
798
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700799 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200800 return;
801
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400802 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200803}
804
Johannes Berg60f8b392008-09-08 17:44:22 +0200805/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200806static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +0200807 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -0700808 u8 *wmm_param, size_t wmm_param_len)
809{
Jiri Bencf0706e822007-05-05 11:45:53 -0700810 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +0200811 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -0700812 size_t left;
813 int count;
Kalle Valoab133152010-01-12 10:42:31 +0200814 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e822007-05-05 11:45:53 -0700815
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200816 if (!local->ops->conf_tx)
817 return;
818
Johannes Bergaf6b6372009-12-23 13:15:35 +0100819 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +0200820 return;
821
822 if (!wmm_param)
823 return;
824
Jiri Bencf0706e822007-05-05 11:45:53 -0700825 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
826 return;
Kalle Valoab133152010-01-12 10:42:31 +0200827
828 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200829 uapsd_queues = local->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +0200830
Jiri Bencf0706e822007-05-05 11:45:53 -0700831 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100832 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e822007-05-05 11:45:53 -0700833 return;
Johannes Berg46900292009-02-15 12:44:28 +0100834 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e822007-05-05 11:45:53 -0700835
836 pos = wmm_param + 8;
837 left = wmm_param_len - 8;
838
839 memset(&params, 0, sizeof(params));
840
Jiri Bencf0706e822007-05-05 11:45:53 -0700841 local->wmm_acm = 0;
842 for (; left >= 4; left -= 4, pos += 4) {
843 int aci = (pos[0] >> 5) & 0x03;
844 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +0200845 bool uapsd = false;
Jiri Bencf0706e822007-05-05 11:45:53 -0700846 int queue;
847
848 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200849 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200850 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200851 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200852 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +0200853 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
854 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -0700855 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200856 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200857 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200858 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200859 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +0200860 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
861 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -0700862 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200863 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200864 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200865 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200866 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +0200867 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
868 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -0700869 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200870 case 0: /* AC_BE */
Jiri Bencf0706e822007-05-05 11:45:53 -0700871 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200872 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200873 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200874 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +0200875 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
876 uapsd = true;
Jiri Bencf0706e822007-05-05 11:45:53 -0700877 break;
878 }
879
880 params.aifs = pos[0] & 0x0f;
881 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
882 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200883 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +0200884 params.uapsd = uapsd;
885
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200886#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700887 wiphy_debug(local->hw.wiphy,
888 "WMM queue=%d aci=%d acm=%d aifs=%d "
889 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
890 queue, aci, acm,
891 params.aifs, params.cw_min, params.cw_max,
892 params.txop, params.uapsd);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100893#endif
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200894 if (drv_conf_tx(local, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700895 wiphy_debug(local->hw.wiphy,
896 "failed to set TX queue parameters for queue %d\n",
897 queue);
Jiri Bencf0706e822007-05-05 11:45:53 -0700898 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200899
900 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +0200901 sdata->vif.bss_conf.qos = true;
902 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
Jiri Bencf0706e822007-05-05 11:45:53 -0700903}
904
Johannes Berg7a5158e2008-10-08 10:59:33 +0200905static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
906 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200907{
Johannes Bergbda39332008-10-11 01:51:51 +0200908 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100909 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200910 bool use_protection;
911 bool use_short_preamble;
912 bool use_short_slot;
913
914 if (erp_valid) {
915 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
916 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
917 } else {
918 use_protection = false;
919 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
920 }
921
922 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +0100923 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
924 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +0200925
Johannes Berg471b3ef2007-12-28 14:32:58 +0100926 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100927 bss_conf->use_cts_prot = use_protection;
928 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200929 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200930
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200931 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200932 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100933 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200934 }
Daniel Draked9430a32007-07-27 15:43:24 +0200935
Johannes Berg7a5158e2008-10-08 10:59:33 +0200936 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200937 bss_conf->use_short_slot = use_short_slot;
938 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400939 }
940
941 return changed;
942}
943
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200944static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100945 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200946 u32 bss_info_changed)
Jiri Bencf0706e822007-05-05 11:45:53 -0700947{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100948 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100949 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +0300950 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400951
Johannes Bergae5eb022008-10-14 16:58:37 +0200952 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200953 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +0300954 bss_conf->beacon_int = cbss->beacon_interval;
955 bss_conf->timestamp = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400956
Johannes Berg77fdaa12009-07-07 03:45:17 +0200957 bss_info_changed |= BSS_CHANGED_BEACON_INT;
958 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100959 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700960
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100961 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
962 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
963
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100964 sdata->u.mgd.associated = cbss;
965 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100966
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700967 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
968
Johannes Bergb291ba12009-07-10 15:29:03 +0200969 /* just to be sure */
970 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
971 IEEE80211_STA_BEACON_POLL);
972
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200973 ieee80211_led_assoc(local, 1);
974
Johannes Berge5b900d2010-07-29 16:08:55 +0200975 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
976 bss_conf->dtim_period = bss->dtim_period;
977 else
978 bss_conf->dtim_period = 0;
979
Juuso Oikarinen68542962010-06-09 13:43:26 +0300980 bss_conf->assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200981 /*
982 * For now just always ask the driver to update the basic rateset
983 * when we have associated, we aren't checking whether it actually
984 * changed or not.
985 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200986 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +0200987
988 /* And the BSSID changed - we're associated now */
989 bss_info_changed |= BSS_CHANGED_BSSID;
990
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200991 /* Tell the driver to monitor connection quality (if supported) */
992 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
Juuso Oikarinen68542962010-06-09 13:43:26 +0300993 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200994 bss_info_changed |= BSS_CHANGED_CQM;
995
Juuso Oikarinen68542962010-06-09 13:43:26 +0300996 /* Enable ARP filtering */
997 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
998 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
999 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
1000 }
1001
Johannes Bergae5eb022008-10-14 16:58:37 +02001002 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001003
Johannes Berg056508d2009-07-30 21:43:55 +02001004 mutex_lock(&local->iflist_mtx);
1005 ieee80211_recalc_ps(local, -1);
Johannes Berg025e6be2010-10-05 10:41:47 +02001006 ieee80211_recalc_smps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02001007 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001008
John W. Linville8a5b33f2010-01-06 15:39:39 -05001009 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001010 netif_carrier_on(sdata->dev);
Jiri Bencf0706e822007-05-05 11:45:53 -07001011}
1012
Jouni Malinene69e95d2010-03-29 23:29:31 -07001013static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg53f73c02010-10-05 19:37:40 +02001014 bool remove_sta, bool tx)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001015{
Johannes Berg46900292009-02-15 12:44:28 +01001016 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001017 struct ieee80211_local *local = sdata->local;
1018 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +02001019 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +02001020 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +03001021
Johannes Berg77fdaa12009-07-07 03:45:17 +02001022 ASSERT_MGD_MTX(ifmgd);
1023
Johannes Bergb291ba12009-07-10 15:29:03 +02001024 if (WARN_ON(!ifmgd->associated))
1025 return;
1026
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001027 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +02001028
Johannes Berg77fdaa12009-07-07 03:45:17 +02001029 ifmgd->associated = NULL;
1030 memset(ifmgd->bssid, 0, ETH_ALEN);
1031
1032 /*
1033 * we need to commit the associated = NULL change because the
1034 * scan code uses that to determine whether this iface should
1035 * go to/wake up from powersave or not -- and could otherwise
1036 * wake the queues erroneously.
1037 */
1038 smp_mb();
1039
1040 /*
1041 * Thus, we can only afterwards stop the queues -- to account
1042 * for the case where another CPU is finishing a scan at this
1043 * time -- we don't want the scan code to enable queues.
1044 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001045
John W. Linville8a5b33f2010-01-06 15:39:39 -05001046 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001047 netif_carrier_off(sdata->dev);
1048
Johannes Berg2a419052010-06-10 10:21:29 +02001049 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +01001050 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +05301051 if (sta) {
Johannes Berg2a419052010-06-10 10:21:29 +02001052 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
Johannes Berg53f73c02010-10-05 19:37:40 +02001053 ieee80211_sta_tear_down_BA_sessions(sta, tx);
Sujith4cad6c72010-02-10 14:52:21 +05301054 }
Johannes Berg2a419052010-06-10 10:21:29 +02001055 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001056
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001057 changed |= ieee80211_reset_erp_info(sdata);
1058
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001059 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001060 changed |= BSS_CHANGED_ASSOC;
1061 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001062
Johannes Bergaa837e12009-05-07 16:16:24 +02001063 ieee80211_set_wmm_default(sdata);
1064
Johannes Berg47979382009-01-07 10:13:27 +01001065 /* channel(_type) changes are handled by ieee80211_hw_config */
Johannes Berg0aaffa92010-05-05 15:28:27 +02001066 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
Johannes Bergae5eb022008-10-14 16:58:37 +02001067
Johannes Berg413ad502009-05-08 21:21:06 +02001068 /* on the next assoc, re-program HT parameters */
1069 sdata->ht_opmode_valid = false;
1070
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301071 local->power_constr_level = 0;
1072
Kalle Valo520eb822008-12-18 23:35:27 +02001073 del_timer_sync(&local->dynamic_ps_timer);
1074 cancel_work_sync(&local->dynamic_ps_enable_work);
1075
Kalle Valoe0cb6862008-12-18 23:35:13 +02001076 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1077 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1078 config_changed |= IEEE80211_CONF_CHANGE_PS;
1079 }
1080
1081 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +02001082
Juuso Oikarinen68542962010-06-09 13:43:26 +03001083 /* Disable ARP filtering */
1084 if (sdata->vif.bss_conf.arp_filter_enabled) {
1085 sdata->vif.bss_conf.arp_filter_enabled = false;
1086 changed |= BSS_CHANGED_ARP_FILTER;
1087 }
1088
Johannes Berg0aaffa92010-05-05 15:28:27 +02001089 /* The BSSID (not really interesting) and HT changed */
1090 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001091 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001092
Jouni Malinene69e95d2010-03-29 23:29:31 -07001093 if (remove_sta)
1094 sta_info_destroy_addr(sdata, bssid);
Johannes Bergb9dcf712010-08-27 12:35:54 +02001095
1096 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1097 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1098 del_timer_sync(&sdata->u.mgd.timer);
1099 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001100}
Jiri Bencf0706e822007-05-05 11:45:53 -07001101
Kalle Valo3cf335d2009-03-22 21:57:06 +02001102void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1103 struct ieee80211_hdr *hdr)
1104{
1105 /*
1106 * We can postpone the mgd.timer whenever receiving unicast frames
1107 * from AP because we know that the connection is working both ways
1108 * at that time. But multicast frames (and hence also beacons) must
1109 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001110 * data idle periods for sending the periodic probe request to the
1111 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001112 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001113 if (is_multicast_ether_addr(hdr->addr1))
1114 return;
1115
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001116 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001117}
Jiri Bencf0706e822007-05-05 11:45:53 -07001118
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001119static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1120{
1121 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1122
1123 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1124 IEEE80211_STA_CONNECTION_POLL)))
1125 return;
1126
1127 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1128 IEEE80211_STA_BEACON_POLL);
1129 mutex_lock(&sdata->local->iflist_mtx);
1130 ieee80211_recalc_ps(sdata->local, -1);
1131 mutex_unlock(&sdata->local->iflist_mtx);
1132
1133 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1134 return;
1135
1136 /*
1137 * We've received a probe response, but are not sure whether
1138 * we have or will be receiving any beacons or data, so let's
1139 * schedule the timers again, just in case.
1140 */
1141 ieee80211_sta_reset_beacon_monitor(sdata);
1142
1143 mod_timer(&ifmgd->conn_mon_timer,
1144 round_jiffies_up(jiffies +
1145 IEEE80211_CONNECTION_IDLE_TIME));
1146}
1147
1148void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001149 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001150{
Felix Fietkau75706d02010-12-02 21:01:07 +01001151 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001152 return;
1153
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001154 if (ack)
1155 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001156
1157 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1158 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001159 if (ack)
1160 sdata->u.mgd.probe_send_count = 0;
1161 else
1162 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001163 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1164 }
1165}
1166
Maxim Levitskya43abf22009-07-31 18:54:12 +03001167static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1168{
1169 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1170 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001171 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001172 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001173
1174 /*
1175 * Try sending broadcast probe requests for the last three
1176 * probe requests after the first ones failed since some
1177 * buggy APs only support broadcast probe requests.
1178 */
1179 if (ifmgd->probe_send_count >= unicast_limit)
1180 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001181
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001182 /*
1183 * When the hardware reports an accurate Tx ACK status, it's
1184 * better to send a nullfunc frame instead of a probe request,
1185 * as it will kick us off the AP quickly if we aren't associated
1186 * anymore. The timeout will be reset if the frame is ACKed by
1187 * the AP.
1188 */
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001189 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1190 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001191 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001192 } else {
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001193 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1194 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0);
1195 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001196
1197 ifmgd->probe_send_count++;
Ben Greear180205b2011-02-04 15:30:24 -08001198 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001199 run_again(ifmgd, ifmgd->probe_timeout);
1200}
1201
Johannes Bergb291ba12009-07-10 15:29:03 +02001202static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1203 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001204{
Kalle Valo04de8382009-03-22 21:57:35 +02001205 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001206 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001207
Johannes Berg9607e6b2009-12-23 13:15:31 +01001208 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001209 return;
1210
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001211 if (sdata->local->scanning)
1212 return;
1213
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001214 if (sdata->local->tmp_channel)
1215 return;
1216
Johannes Berg77fdaa12009-07-07 03:45:17 +02001217 mutex_lock(&ifmgd->mtx);
1218
1219 if (!ifmgd->associated)
1220 goto out;
1221
Michael Buescha8604022009-04-15 14:41:22 -04001222#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001223 if (beacon && net_ratelimit())
1224 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001225 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001226#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001227
Johannes Bergb291ba12009-07-10 15:29:03 +02001228 /*
1229 * The driver/our work has already reported this event or the
1230 * connection monitoring has kicked in and we have already sent
1231 * a probe request. Or maybe the AP died and the driver keeps
1232 * reporting until we disassociate...
1233 *
1234 * In either case we have to ignore the current call to this
1235 * function (except for setting the correct probe reason bit)
1236 * because otherwise we would reset the timer every time and
1237 * never check whether we received a probe response!
1238 */
1239 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1240 IEEE80211_STA_CONNECTION_POLL))
1241 already = true;
1242
1243 if (beacon)
1244 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1245 else
1246 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1247
1248 if (already)
1249 goto out;
1250
Johannes Berg4e751842009-06-10 15:16:52 +02001251 mutex_lock(&sdata->local->iflist_mtx);
1252 ieee80211_recalc_ps(sdata->local, -1);
1253 mutex_unlock(&sdata->local->iflist_mtx);
1254
Maxim Levitskya43abf22009-07-31 18:54:12 +03001255 ifmgd->probe_send_count = 0;
1256 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001257 out:
1258 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001259}
1260
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001261struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1262 struct ieee80211_vif *vif)
1263{
1264 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1265 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1266 struct sk_buff *skb;
1267 const u8 *ssid;
1268
1269 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1270 return NULL;
1271
1272 ASSERT_MGD_MTX(ifmgd);
1273
1274 if (!ifmgd->associated)
1275 return NULL;
1276
1277 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1278 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
1279 ssid + 2, ssid[1], NULL, 0);
1280
1281 return skb;
1282}
1283EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1284
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001285static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1286{
1287 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1288 struct ieee80211_local *local = sdata->local;
1289 u8 bssid[ETH_ALEN];
1290
1291 mutex_lock(&ifmgd->mtx);
1292 if (!ifmgd->associated) {
1293 mutex_unlock(&ifmgd->mtx);
1294 return;
1295 }
1296
1297 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1298
Ben Greear180205b2011-02-04 15:30:24 -08001299 printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
1300 sdata->name, bssid);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001301
Johannes Berg53f73c02010-10-05 19:37:40 +02001302 ieee80211_set_disassoc(sdata, true, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001303 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001304
1305 mutex_lock(&local->mtx);
1306 ieee80211_recalc_idle(local);
1307 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001308 /*
1309 * must be outside lock due to cfg80211,
1310 * but that's not a problem.
1311 */
1312 ieee80211_send_deauth_disassoc(sdata, bssid,
1313 IEEE80211_STYPE_DEAUTH,
1314 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001315 NULL, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001316}
1317
1318void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001319{
1320 struct ieee80211_sub_if_data *sdata =
1321 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001322 u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001323
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001324 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1325 __ieee80211_connection_loss(sdata);
1326 else
1327 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001328}
1329
Kalle Valo04de8382009-03-22 21:57:35 +02001330void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1331{
1332 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001333 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001334
Johannes Bergb5878a22010-04-07 16:48:40 +02001335 trace_api_beacon_loss(sdata);
1336
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001337 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1338 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001339}
1340EXPORT_SYMBOL(ieee80211_beacon_loss);
1341
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001342void ieee80211_connection_loss(struct ieee80211_vif *vif)
1343{
1344 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1345 struct ieee80211_hw *hw = &sdata->local->hw;
1346
Johannes Bergb5878a22010-04-07 16:48:40 +02001347 trace_api_connection_loss(sdata);
1348
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001349 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1350 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1351}
1352EXPORT_SYMBOL(ieee80211_connection_loss);
1353
1354
Johannes Berg77fdaa12009-07-07 03:45:17 +02001355static enum rx_mgmt_action __must_check
1356ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001357 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07001358{
Johannes Berg46900292009-02-15 12:44:28 +01001359 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001360 const u8 *bssid = NULL;
Jiri Bencf0706e822007-05-05 11:45:53 -07001361 u16 reason_code;
1362
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001363 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001364 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001365
Johannes Berg77fdaa12009-07-07 03:45:17 +02001366 ASSERT_MGD_MTX(ifmgd);
1367
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001368 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e822007-05-05 11:45:53 -07001369
1370 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1371
Johannes Berg77fdaa12009-07-07 03:45:17 +02001372 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001373 sdata->name, bssid, reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001374
Johannes Berg53f73c02010-10-05 19:37:40 +02001375 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001376 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001377 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001378 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001379
1380 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e822007-05-05 11:45:53 -07001381}
1382
1383
Johannes Berg77fdaa12009-07-07 03:45:17 +02001384static enum rx_mgmt_action __must_check
1385ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1386 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07001387{
Johannes Berg46900292009-02-15 12:44:28 +01001388 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -07001389 u16 reason_code;
1390
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001391 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001392 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001393
Johannes Berg77fdaa12009-07-07 03:45:17 +02001394 ASSERT_MGD_MTX(ifmgd);
1395
1396 if (WARN_ON(!ifmgd->associated))
1397 return RX_MGMT_NONE;
1398
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001399 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001400 return RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001401
1402 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1403
Johannes Berg0ff71612009-09-26 14:45:41 +02001404 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001405 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e822007-05-05 11:45:53 -07001406
Johannes Berg53f73c02010-10-05 19:37:40 +02001407 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001408 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001409 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001410 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001411 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e822007-05-05 11:45:53 -07001412}
1413
1414
Johannes Bergaf6b6372009-12-23 13:15:35 +01001415static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1416 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e822007-05-05 11:45:53 -07001417{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001418 struct ieee80211_sub_if_data *sdata = wk->sdata;
Johannes Berg46900292009-02-15 12:44:28 +01001419 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001420 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001421 struct ieee80211_supported_band *sband;
Jiri Bencf0706e822007-05-05 11:45:53 -07001422 struct sta_info *sta;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001423 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001424 u8 *pos;
Johannes Berg881d9482009-01-21 15:13:48 +01001425 u32 rates, basic_rates;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001426 u16 capab_info, aid;
Jiri Bencf0706e822007-05-05 11:45:53 -07001427 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001428 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02001429 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001430 int i, j, err;
1431 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001432 u16 ap_ht_cap_flags;
Jiri Bencf0706e822007-05-05 11:45:53 -07001433
Johannes Bergaf6b6372009-12-23 13:15:35 +01001434 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e822007-05-05 11:45:53 -07001435
Jiri Bencf0706e822007-05-05 11:45:53 -07001436 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001437 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e822007-05-05 11:45:53 -07001438
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001439 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1440 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001441 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001442 aid &= ~(BIT(15) | BIT(14));
1443
Johannes Bergaf6b6372009-12-23 13:15:35 +01001444 pos = mgmt->u.assoc_resp.variable;
1445 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1446
Jiri Bencf0706e822007-05-05 11:45:53 -07001447 if (!elems.supp_rates) {
1448 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001449 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001450 return false;
Jiri Bencf0706e822007-05-05 11:45:53 -07001451 }
1452
Johannes Berg46900292009-02-15 12:44:28 +01001453 ifmgd->aid = aid;
Jiri Bencf0706e822007-05-05 11:45:53 -07001454
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001455 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
Jiri Bencf0706e822007-05-05 11:45:53 -07001456 if (!sta) {
Johannes Berg5d1ec852009-12-02 12:43:43 +01001457 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1458 " the AP\n", sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001459 return false;
Jiri Bencf0706e822007-05-05 11:45:53 -07001460 }
1461
Johannes Berg5d1ec852009-12-02 12:43:43 +01001462 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1463 WLAN_STA_ASSOC_AP);
1464 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1465 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1466
Jiri Bencf0706e822007-05-05 11:45:53 -07001467 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001468 basic_rates = 0;
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001469 sband = local->hw.wiphy->bands[wk->chan->band];
Johannes Berg8318d782008-01-24 19:38:38 +01001470
Jiri Bencf0706e822007-05-05 11:45:53 -07001471 for (i = 0; i < elems.supp_rates_len; i++) {
1472 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001473 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001474
1475 if (rate > 110)
1476 have_higher_than_11mbit = true;
1477
1478 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001479 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001480 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001481 if (is_basic)
1482 basic_rates |= BIT(j);
1483 break;
1484 }
Johannes Berg8318d782008-01-24 19:38:38 +01001485 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001486 }
Johannes Berg8318d782008-01-24 19:38:38 +01001487
Jiri Bencf0706e822007-05-05 11:45:53 -07001488 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1489 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001490 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001491
1492 if (rate > 110)
1493 have_higher_than_11mbit = true;
1494
1495 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001496 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e822007-05-05 11:45:53 -07001497 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001498 if (is_basic)
1499 basic_rates |= BIT(j);
1500 break;
1501 }
Johannes Berg8318d782008-01-24 19:38:38 +01001502 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001503 }
Johannes Berg8318d782008-01-24 19:38:38 +01001504
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001505 sta->sta.supp_rates[wk->chan->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001506 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001507
1508 /* cf. IEEE 802.11 9.2.12 */
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001509 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
Johannes Berg8318d782008-01-24 19:38:38 +01001510 have_higher_than_11mbit)
1511 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1512 else
1513 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001514
Johannes Bergab1faea2009-07-01 21:41:17 +02001515 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001516 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001517 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001518
1519 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001520
Johannes Berg4b7679a2008-09-18 18:14:18 +02001521 rate_control_rate_init(sta);
Jiri Bencf0706e822007-05-05 11:45:53 -07001522
Johannes Berg46900292009-02-15 12:44:28 +01001523 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001524 set_sta_flags(sta, WLAN_STA_MFP);
1525
Johannes Bergddf4ac52008-10-22 11:41:38 +02001526 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001527 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001528
Johannes Berg5d1ec852009-12-02 12:43:43 +01001529 err = sta_info_insert(sta);
1530 sta = NULL;
1531 if (err) {
1532 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1533 " the AP (error %d)\n", sdata->name, err);
Johannes Berg90be5612010-01-08 19:01:07 +01001534 return false;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001535 }
1536
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03001537 /*
1538 * Always handle WMM once after association regardless
1539 * of the first value the AP uses. Setting -1 here has
1540 * that effect because the AP values is an unsigned
1541 * 4-bit value.
1542 */
1543 ifmgd->wmm_last_param_set = -1;
1544
Johannes Bergddf4ac52008-10-22 11:41:38 +02001545 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02001546 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e822007-05-05 11:45:53 -07001547 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001548 else
1549 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -07001550
Johannes Berge4da8c32009-12-23 13:15:43 +01001551 local->oper_channel = wk->chan;
1552
Johannes Bergae5eb022008-10-14 16:58:37 +02001553 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergaf6b6372009-12-23 13:15:35 +01001554 (sdata->local->hw.queues >= 4) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001555 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001556 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001557 cbss->bssid, ap_ht_cap_flags);
Johannes Bergae5eb022008-10-14 16:58:37 +02001558
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001559 /* set AID and assoc capability,
1560 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001561 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001562 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001563 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07001564
Kalle Valo15b7b062009-03-22 21:57:14 +02001565 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01001566 * If we're using 4-addr mode, let the AP know that we're
1567 * doing so, so that it can create the STA VLAN on its side
1568 */
1569 if (ifmgd->use_4addr)
1570 ieee80211_send_4addr_nullfunc(local, sdata);
1571
1572 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001573 * Start timer to probe the connection to the AP now.
1574 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001575 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001576 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001577 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001578
Johannes Bergaf6b6372009-12-23 13:15:35 +01001579 return true;
Jiri Bencf0706e822007-05-05 11:45:53 -07001580}
1581
1582
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001583static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07001584 struct ieee80211_mgmt *mgmt,
1585 size_t len,
1586 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001587 struct ieee802_11_elems *elems,
1588 bool beacon)
Jiri Bencf0706e822007-05-05 11:45:53 -07001589{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001590 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001591 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001592 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001593 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01001594 bool need_ps = false;
1595
1596 if (sdata->u.mgd.associated) {
1597 bss = (void *)sdata->u.mgd.associated->priv;
1598 /* not previously set so we may need to recalc */
1599 need_ps = !bss->dtim_period;
1600 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001601
Johannes Berg5bda6172008-09-08 11:05:10 +02001602 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001603 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
1604 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02001605 else
1606 freq = rx_status->freq;
1607
1608 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1609
1610 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1611 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07001612
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001613 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001614 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001615 if (bss)
1616 ieee80211_rx_bss_put(local, bss);
1617
1618 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001619 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07001620
Johannes Berg56007a02010-01-26 14:19:52 +01001621 if (need_ps) {
1622 mutex_lock(&local->iflist_mtx);
1623 ieee80211_recalc_ps(local, -1);
1624 mutex_unlock(&local->iflist_mtx);
1625 }
1626
Sujithc481ec92009-01-06 09:28:37 +05301627 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001628 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001629 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301630 struct ieee80211_channel_sw_ie *sw_elem =
1631 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001632 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1633 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05301634 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001635}
1636
1637
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001638static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01001639 struct sk_buff *skb)
Jiri Bencf0706e822007-05-05 11:45:53 -07001640{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001641 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02001642 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001643 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1644 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001645 struct ieee802_11_elems elems;
1646
Kalle Valo15b7b062009-03-22 21:57:14 +02001647 ifmgd = &sdata->u.mgd;
1648
Johannes Berg77fdaa12009-07-07 03:45:17 +02001649 ASSERT_MGD_MTX(ifmgd);
1650
Johannes Berg47846c92009-11-25 17:46:19 +01001651 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001652 return; /* ignore ProbeResp to foreign address */
1653
Ester Kummerae6a44e2008-06-27 18:54:48 +03001654 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1655 if (baselen > len)
1656 return;
1657
1658 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1659 &elems);
1660
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001661 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001662
Johannes Berg77fdaa12009-07-07 03:45:17 +02001663 if (ifmgd->associated &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001664 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
1665 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -07001666}
1667
Johannes Bergd91f36d2009-04-16 13:17:26 +02001668/*
1669 * This is the canonical list of information elements we care about,
1670 * the filter code also gives us all changes to the Microsoft OUI
1671 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1672 *
1673 * We implement beacon filtering in software since that means we can
1674 * avoid processing the frame here and in cfg80211, and userspace
1675 * will not be able to tell whether the hardware supports it or not.
1676 *
1677 * XXX: This list needs to be dynamic -- userspace needs to be able to
1678 * add items it requires. It also needs to be able to tell us to
1679 * look out for other vendor IEs.
1680 */
1681static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001682 (1ULL << WLAN_EID_COUNTRY) |
1683 (1ULL << WLAN_EID_ERP_INFO) |
1684 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1685 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1686 (1ULL << WLAN_EID_HT_CAPABILITY) |
1687 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001688
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001689static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e822007-05-05 11:45:53 -07001690 struct ieee80211_mgmt *mgmt,
1691 size_t len,
1692 struct ieee80211_rx_status *rx_status)
1693{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001694 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001695 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e822007-05-05 11:45:53 -07001696 size_t baselen;
1697 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001698 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001699 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001700 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001701 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001702 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001703 u8 *bssid;
1704
1705 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e822007-05-05 11:45:53 -07001706
Ester Kummerae6a44e2008-06-27 18:54:48 +03001707 /* Process beacon from the current BSS */
1708 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1709 if (baselen > len)
1710 return;
1711
Johannes Bergd91f36d2009-04-16 13:17:26 +02001712 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e822007-05-05 11:45:53 -07001713 return;
Jiri Bencf0706e822007-05-05 11:45:53 -07001714
Johannes Bergb291ba12009-07-10 15:29:03 +02001715 /*
1716 * We might have received a number of frames, among them a
1717 * disassoc frame and a beacon...
1718 */
1719 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001720 return;
1721
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001722 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001723
Johannes Bergb291ba12009-07-10 15:29:03 +02001724 /*
1725 * And in theory even frames from a different AP we were just
1726 * associated to a split-second ago!
1727 */
1728 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e822007-05-05 11:45:53 -07001729 return;
1730
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001731 /* Track average RSSI from the Beacon frames of the current AP */
1732 ifmgd->last_beacon_signal = rx_status->signal;
1733 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1734 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03001735 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001736 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03001737 ifmgd->count_beacon_signal = 1;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001738 } else {
1739 ifmgd->ave_beacon_signal =
1740 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1741 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1742 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03001743 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001744 }
1745 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03001746 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001747 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1748 int sig = ifmgd->ave_beacon_signal / 16;
1749 int last_event = ifmgd->last_cqm_event_signal;
1750 int thold = bss_conf->cqm_rssi_thold;
1751 int hyst = bss_conf->cqm_rssi_hyst;
1752 if (sig < thold &&
1753 (last_event == 0 || sig < last_event - hyst)) {
1754 ifmgd->last_cqm_event_signal = sig;
1755 ieee80211_cqm_rssi_notify(
1756 &sdata->vif,
1757 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1758 GFP_KERNEL);
1759 } else if (sig > thold &&
1760 (last_event == 0 || sig > last_event + hyst)) {
1761 ifmgd->last_cqm_event_signal = sig;
1762 ieee80211_cqm_rssi_notify(
1763 &sdata->vif,
1764 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1765 GFP_KERNEL);
1766 }
1767 }
1768
Johannes Bergb291ba12009-07-10 15:29:03 +02001769 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001770#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1771 if (net_ratelimit()) {
1772 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001773 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001774 }
1775#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001776 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001777 mutex_lock(&local->iflist_mtx);
1778 ieee80211_recalc_ps(local, -1);
1779 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001780 }
1781
Johannes Bergb291ba12009-07-10 15:29:03 +02001782 /*
1783 * Push the beacon loss detection into the future since
1784 * we are processing a beacon from the AP just now.
1785 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001786 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001787
Johannes Bergd91f36d2009-04-16 13:17:26 +02001788 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1789 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1790 len - baselen, &elems,
1791 care_about_ies, ncrc);
1792
1793 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001794 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1795 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001796
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001797 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
Jouni Malinen30196672009-05-19 17:01:43 +03001798 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1799 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001800
Johannes Berg4ced3f72010-07-19 16:39:04 +02001801 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03001802 elems.wmm_param_len);
1803 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001804
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301805 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001806 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001807 if (local->hw.conf.dynamic_ps_timeout > 0) {
1808 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1809 ieee80211_hw_config(local,
1810 IEEE80211_CONF_CHANGE_PS);
1811 ieee80211_send_nullfunc(local, sdata, 0);
1812 } else {
1813 local->pspolling = true;
1814
1815 /*
1816 * Here is assumed that the driver will be
1817 * able to send ps-poll frame and receive a
1818 * response even though power save mode is
1819 * enabled, but some drivers might require
1820 * to disable power save here. This needs
1821 * to be investigated.
1822 */
1823 ieee80211_send_pspoll(local, sdata);
1824 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001825 }
1826 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001827
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001828 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03001829 return;
1830 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001831 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03001832
Johannes Berg7a5158e2008-10-08 10:59:33 +02001833 if (elems.erp_info && elems.erp_info_len >= 1) {
1834 erp_valid = true;
1835 erp_value = elems.erp_info[0];
1836 } else {
1837 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001838 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001839 changed |= ieee80211_handle_bss_capability(sdata,
1840 le16_to_cpu(mgmt->u.beacon.capab_info),
1841 erp_valid, erp_value);
Jiri Bencf0706e822007-05-05 11:45:53 -07001842
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001843
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301844 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001845 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001846 struct sta_info *sta;
1847 struct ieee80211_supported_band *sband;
1848 u16 ap_ht_cap_flags;
1849
1850 rcu_read_lock();
1851
Johannes Bergabe60632009-11-25 17:46:18 +01001852 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001853 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001854 rcu_read_unlock();
1855 return;
1856 }
1857
1858 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1859
1860 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1861 elems.ht_cap_elem, &sta->sta.ht_cap);
1862
1863 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1864
1865 rcu_read_unlock();
1866
1867 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001868 bssid, ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001869 }
1870
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001871 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001872 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301873 /* TODO: IBSS also needs this */
1874 if (elems.pwr_constr_elem)
1875 ieee80211_handle_pwr_constr(sdata,
1876 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1877 elems.pwr_constr_elem,
1878 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001879 }
1880
Johannes Berg471b3ef2007-12-28 14:32:58 +01001881 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e822007-05-05 11:45:53 -07001882}
1883
Johannes Berg1fa57d02010-06-10 10:21:32 +02001884void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1885 struct sk_buff *skb)
Jiri Bencf0706e822007-05-05 11:45:53 -07001886{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001887 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e822007-05-05 11:45:53 -07001888 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e822007-05-05 11:45:53 -07001889 struct ieee80211_mgmt *mgmt;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001890 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e822007-05-05 11:45:53 -07001891 u16 fc;
1892
Jiri Bencf0706e822007-05-05 11:45:53 -07001893 rx_status = (struct ieee80211_rx_status *) skb->cb;
1894 mgmt = (struct ieee80211_mgmt *) skb->data;
1895 fc = le16_to_cpu(mgmt->frame_control);
1896
Johannes Berg77fdaa12009-07-07 03:45:17 +02001897 mutex_lock(&ifmgd->mtx);
1898
1899 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001900 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001901 switch (fc & IEEE80211_FCTL_STYPE) {
1902 case IEEE80211_STYPE_BEACON:
1903 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1904 rx_status);
1905 break;
1906 case IEEE80211_STYPE_PROBE_RESP:
Johannes Bergaf6b6372009-12-23 13:15:35 +01001907 ieee80211_rx_mgmt_probe_resp(sdata, skb);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001908 break;
1909 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01001910 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001911 break;
1912 case IEEE80211_STYPE_DISASSOC:
1913 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1914 break;
1915 case IEEE80211_STYPE_ACTION:
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001916 switch (mgmt->u.action.category) {
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001917 case WLAN_CATEGORY_SPECTRUM_MGMT:
1918 ieee80211_sta_process_chanswitch(sdata,
1919 &mgmt->u.action.u.chan_switch.sw_elem,
1920 (void *)ifmgd->associated->priv,
1921 rx_status->mactime);
1922 break;
1923 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02001924 }
1925 mutex_unlock(&ifmgd->mtx);
1926
1927 switch (rma) {
1928 case RX_MGMT_NONE:
1929 /* no action */
1930 break;
1931 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470613c2009-10-13 13:28:13 +02001932 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001933 break;
1934 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470613c2009-10-13 13:28:13 +02001935 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001936 break;
1937 default:
1938 WARN(1, "unexpected: %d", rma);
1939 }
Johannes Berg36b3a622010-06-10 10:21:33 +02001940 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001941 }
1942
Johannes Berg77fdaa12009-07-07 03:45:17 +02001943 mutex_unlock(&ifmgd->mtx);
1944
Johannes Berg63f170e2009-12-23 13:15:33 +01001945 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
Johannes Bergb054b742010-06-07 21:50:07 +02001946 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
1947 struct ieee80211_local *local = sdata->local;
1948 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001949
Johannes Berga1699b72010-07-30 16:46:07 +02001950 mutex_lock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001951 list_for_each_entry(wk, &local->work_list, list) {
1952 if (wk->sdata != sdata)
1953 continue;
1954
Johannes Berge5b900d2010-07-29 16:08:55 +02001955 if (wk->type != IEEE80211_WORK_ASSOC &&
1956 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Bergb054b742010-06-07 21:50:07 +02001957 continue;
1958
1959 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
1960 continue;
1961 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
1962 continue;
1963
1964 /*
1965 * Printing the message only here means we can't
1966 * spuriously print it, but it also means that it
1967 * won't be printed when the frame comes in before
1968 * we even tried to associate or in similar cases.
1969 *
1970 * Ultimately, I suspect cfg80211 should print the
1971 * messages instead.
1972 */
1973 printk(KERN_DEBUG
1974 "%s: deauthenticated from %pM (Reason: %u)\n",
1975 sdata->name, mgmt->bssid,
1976 le16_to_cpu(mgmt->u.deauth.reason_code));
1977
1978 list_del_rcu(&wk->list);
1979 free_work(wk);
1980 break;
1981 }
Johannes Berga1699b72010-07-30 16:46:07 +02001982 mutex_unlock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001983
Johannes Berg77fdaa12009-07-07 03:45:17 +02001984 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Bergb054b742010-06-07 21:50:07 +02001985 }
Jiri Bencf0706e822007-05-05 11:45:53 -07001986}
1987
Johannes Berg9c6bd792008-09-11 00:01:52 +02001988static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e822007-05-05 11:45:53 -07001989{
1990 struct ieee80211_sub_if_data *sdata =
1991 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001992 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001993 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e822007-05-05 11:45:53 -07001994
Johannes Berg5bb644a2009-05-17 11:40:42 +02001995 if (local->quiescing) {
1996 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1997 return;
1998 }
1999
Johannes Berg64592c82010-06-10 10:21:31 +02002000 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e822007-05-05 11:45:53 -07002001}
2002
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002003static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
2004 u8 *bssid)
2005{
2006 struct ieee80211_local *local = sdata->local;
2007 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2008
2009 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
2010 IEEE80211_STA_BEACON_POLL);
2011
2012 ieee80211_set_disassoc(sdata, true, true);
2013 mutex_unlock(&ifmgd->mtx);
2014 mutex_lock(&local->mtx);
2015 ieee80211_recalc_idle(local);
2016 mutex_unlock(&local->mtx);
2017 /*
2018 * must be outside lock due to cfg80211,
2019 * but that's not a problem.
2020 */
2021 ieee80211_send_deauth_disassoc(sdata, bssid,
2022 IEEE80211_STYPE_DEAUTH,
2023 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2024 NULL, true);
2025 mutex_lock(&ifmgd->mtx);
2026}
2027
Johannes Berg1fa57d02010-06-10 10:21:32 +02002028void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02002029{
Johannes Berg60f8b392008-09-08 17:44:22 +02002030 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02002031 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002032
Johannes Berg77fdaa12009-07-07 03:45:17 +02002033 /* then process the rest of the work */
2034 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002035
Johannes Bergb291ba12009-07-10 15:29:03 +02002036 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2037 IEEE80211_STA_CONNECTION_POLL) &&
2038 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002039 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002040 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002041
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002042 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002043
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002044 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08002045 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002046 else
Ben Greear180205b2011-02-04 15:30:24 -08002047 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002048
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002049 /* ACK received for nullfunc probing frame */
2050 if (!ifmgd->probe_send_count)
2051 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002052 else if (ifmgd->nullfunc_failed) {
2053 if (ifmgd->probe_send_count < max_tries) {
2054#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2055 wiphy_debug(local->hw.wiphy,
2056 "%s: No ack for nullfunc frame to"
Ben Greearbfc31df2011-01-14 09:32:18 -08002057 " AP %pM, try %d/%i\n",
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002058 sdata->name, bssid,
Ben Greearbfc31df2011-01-14 09:32:18 -08002059 ifmgd->probe_send_count, max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002060#endif
2061 ieee80211_mgd_probe_ap_send(sdata);
2062 } else {
2063#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2064 wiphy_debug(local->hw.wiphy,
2065 "%s: No ack for nullfunc frame to"
2066 " AP %pM, disconnecting.\n",
Felix Fietkauc658e5d2010-12-07 04:40:18 +01002067 sdata->name, bssid);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002068#endif
2069 ieee80211_sta_connection_lost(sdata, bssid);
2070 }
2071 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002072 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002073 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2074#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2075 wiphy_debug(local->hw.wiphy,
2076 "%s: Failed to send nullfunc to AP %pM"
2077 " after %dms, disconnecting.\n",
2078 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002079 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002080#endif
2081 ieee80211_sta_connection_lost(sdata, bssid);
2082 } else if (ifmgd->probe_send_count < max_tries) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002083#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Ben Greearb38afa82010-10-07 16:12:06 -07002084 wiphy_debug(local->hw.wiphy,
2085 "%s: No probe response from AP %pM"
Ben Greearbfc31df2011-01-14 09:32:18 -08002086 " after %dms, try %d/%i\n",
Ben Greearb38afa82010-10-07 16:12:06 -07002087 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002088 bssid, probe_wait_ms,
Ben Greearbfc31df2011-01-14 09:32:18 -08002089 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002090#endif
2091 ieee80211_mgd_probe_ap_send(sdata);
2092 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002093 /*
2094 * We actually lost the connection ... or did we?
2095 * Let's make sure!
2096 */
Ben Greearb38afa82010-10-07 16:12:06 -07002097 wiphy_debug(local->hw.wiphy,
2098 "%s: No probe response from AP %pM"
2099 " after %dms, disconnecting.\n",
2100 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002101 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002102
2103 ieee80211_sta_connection_lost(sdata, bssid);
Johannes Bergb291ba12009-07-10 15:29:03 +02002104 }
2105 }
2106
Johannes Berg77fdaa12009-07-07 03:45:17 +02002107 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002108}
Johannes Berg0a51b272008-09-08 17:44:25 +02002109
Johannes Bergb291ba12009-07-10 15:29:03 +02002110static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2111{
2112 struct ieee80211_sub_if_data *sdata =
2113 (struct ieee80211_sub_if_data *) data;
2114 struct ieee80211_local *local = sdata->local;
2115
2116 if (local->quiescing)
2117 return;
2118
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002119 ieee80211_queue_work(&sdata->local->hw,
2120 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002121}
2122
2123static void ieee80211_sta_conn_mon_timer(unsigned long data)
2124{
2125 struct ieee80211_sub_if_data *sdata =
2126 (struct ieee80211_sub_if_data *) data;
2127 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2128 struct ieee80211_local *local = sdata->local;
2129
2130 if (local->quiescing)
2131 return;
2132
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002133 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002134}
2135
2136static void ieee80211_sta_monitor_work(struct work_struct *work)
2137{
2138 struct ieee80211_sub_if_data *sdata =
2139 container_of(work, struct ieee80211_sub_if_data,
2140 u.mgd.monitor_work);
2141
2142 ieee80211_mgd_probe_ap(sdata, false);
2143}
2144
Johannes Berga1678f82008-09-11 00:01:47 +02002145static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2146{
Kalle Vaload935682009-04-19 08:47:19 +03002147 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002148 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2149 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002150
Johannes Bergb291ba12009-07-10 15:29:03 +02002151 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002152 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02002153 &sdata->u.mgd.monitor_work);
2154 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02002155 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03002156 }
Johannes Berga1678f82008-09-11 00:01:47 +02002157}
2158
Johannes Berg5bb644a2009-05-17 11:40:42 +02002159#ifdef CONFIG_PM
2160void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2161{
2162 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2163
2164 /*
2165 * we need to use atomic bitops for the running bits
2166 * only because both timers might fire at the same
2167 * time -- the code here is properly synchronised.
2168 */
2169
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002170 cancel_work_sync(&ifmgd->request_smps_work);
2171
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002172 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002173 if (del_timer_sync(&ifmgd->timer))
2174 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2175
2176 cancel_work_sync(&ifmgd->chswitch_work);
2177 if (del_timer_sync(&ifmgd->chswitch_timer))
2178 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002179
2180 cancel_work_sync(&ifmgd->monitor_work);
2181 /* these will just be re-established on connection */
2182 del_timer_sync(&ifmgd->conn_mon_timer);
2183 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002184}
2185
2186void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2187{
2188 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2189
2190 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2191 add_timer(&ifmgd->timer);
2192 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2193 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01002194 ieee80211_sta_reset_beacon_monitor(sdata);
Felix Fietkau46090972010-11-23 20:28:03 +01002195 ieee80211_restart_sta_timer(sdata);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002196}
2197#endif
2198
Johannes Berg9c6bd792008-09-11 00:01:52 +02002199/* interface setup */
2200void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2201{
Johannes Berg46900292009-02-15 12:44:28 +01002202 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002203
Johannes Berg46900292009-02-15 12:44:28 +01002204 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002205 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01002206 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002207 INIT_WORK(&ifmgd->beacon_connection_loss_work,
2208 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002209 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01002210 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002211 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002212 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2213 (unsigned long) sdata);
2214 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2215 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002216 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302217 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002218
Johannes Bergab1faea2009-07-01 21:41:17 +02002219 ifmgd->flags = 0;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002220
Johannes Berg77fdaa12009-07-07 03:45:17 +02002221 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01002222
2223 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2224 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2225 else
2226 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002227}
2228
2229/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002230void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2231{
2232 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002233
2234 /* Restart STA timers */
2235 rcu_read_lock();
2236 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2237 ieee80211_restart_sta_timer(sdata);
2238 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002239}
Johannes Berg10f644a2009-04-16 13:17:25 +02002240
2241int ieee80211_max_network_latency(struct notifier_block *nb,
2242 unsigned long data, void *dummy)
2243{
2244 s32 latency_usec = (s32) data;
2245 struct ieee80211_local *local =
2246 container_of(nb, struct ieee80211_local,
2247 network_latency_notifier);
2248
2249 mutex_lock(&local->iflist_mtx);
2250 ieee80211_recalc_ps(local, latency_usec);
2251 mutex_unlock(&local->iflist_mtx);
2252
2253 return 0;
2254}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002255
2256/* config hooks */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002257static enum work_done_result
2258ieee80211_probe_auth_done(struct ieee80211_work *wk,
2259 struct sk_buff *skb)
2260{
2261 if (!skb) {
2262 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2263 return WORK_DONE_DESTROY;
2264 }
2265
2266 if (wk->type == IEEE80211_WORK_AUTH) {
2267 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2268 return WORK_DONE_DESTROY;
2269 }
2270
2271 mutex_lock(&wk->sdata->u.mgd.mtx);
2272 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2273 mutex_unlock(&wk->sdata->u.mgd.mtx);
2274
2275 wk->type = IEEE80211_WORK_AUTH;
2276 wk->probe_auth.tries = 0;
2277 return WORK_DONE_REQUEUE;
2278}
2279
Johannes Berg77fdaa12009-07-07 03:45:17 +02002280int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2281 struct cfg80211_auth_request *req)
2282{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002283 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002284 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002285 u16 auth_alg;
2286
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002287 if (req->local_state_change)
2288 return 0; /* no need to update mac80211 state */
2289
Johannes Berg77fdaa12009-07-07 03:45:17 +02002290 switch (req->auth_type) {
2291 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2292 auth_alg = WLAN_AUTH_OPEN;
2293 break;
2294 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg9dca9c42010-07-21 10:09:25 +02002295 if (IS_ERR(sdata->local->wep_tx_tfm))
2296 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002297 auth_alg = WLAN_AUTH_SHARED_KEY;
2298 break;
2299 case NL80211_AUTHTYPE_FT:
2300 auth_alg = WLAN_AUTH_FT;
2301 break;
2302 case NL80211_AUTHTYPE_NETWORK_EAP:
2303 auth_alg = WLAN_AUTH_LEAP;
2304 break;
2305 default:
2306 return -EOPNOTSUPP;
2307 }
2308
2309 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2310 if (!wk)
2311 return -ENOMEM;
2312
Joe Perches5e124bd2010-01-08 22:33:38 -08002313 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002314
2315 if (req->ie && req->ie_len) {
2316 memcpy(wk->ie, req->ie, req->ie_len);
2317 wk->ie_len = req->ie_len;
2318 }
2319
Johannes Bergfffd0932009-07-08 14:22:54 +02002320 if (req->key && req->key_len) {
Johannes Bergaf6b6372009-12-23 13:15:35 +01002321 wk->probe_auth.key_len = req->key_len;
2322 wk->probe_auth.key_idx = req->key_idx;
2323 memcpy(wk->probe_auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002324 }
2325
Johannes Berg77fdaa12009-07-07 03:45:17 +02002326 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002327 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2328 wk->probe_auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002329
Johannes Bergaf6b6372009-12-23 13:15:35 +01002330 wk->probe_auth.algorithm = auth_alg;
2331 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +01002332
Johannes Berg070bb542010-02-03 13:57:46 +01002333 /* if we already have a probe, don't probe again */
2334 if (req->bss->proberesp_ies)
2335 wk->type = IEEE80211_WORK_AUTH;
2336 else
2337 wk->type = IEEE80211_WORK_DIRECT_PROBE;
Johannes Bergf679f652009-12-23 13:15:34 +01002338 wk->chan = req->bss->channel;
Ben Greear4d51e142011-02-07 13:44:34 -08002339 wk->chan_type = NL80211_CHAN_NO_HT;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002340 wk->sdata = sdata;
2341 wk->done = ieee80211_probe_auth_done;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002342
Johannes Bergaf6b6372009-12-23 13:15:35 +01002343 ieee80211_add_work(wk);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002344 return 0;
2345}
2346
Johannes Bergaf6b6372009-12-23 13:15:35 +01002347static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2348 struct sk_buff *skb)
2349{
2350 struct ieee80211_mgmt *mgmt;
Johannes Berge5b900d2010-07-29 16:08:55 +02002351 struct ieee80211_rx_status *rx_status;
2352 struct ieee802_11_elems elems;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002353 u16 status;
2354
2355 if (!skb) {
2356 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2357 return WORK_DONE_DESTROY;
2358 }
2359
Johannes Berge5b900d2010-07-29 16:08:55 +02002360 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2361 mutex_lock(&wk->sdata->u.mgd.mtx);
2362 rx_status = (void *) skb->cb;
2363 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2364 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2365 &elems, true);
2366 mutex_unlock(&wk->sdata->u.mgd.mtx);
2367
2368 wk->type = IEEE80211_WORK_ASSOC;
2369 /* not really done yet */
2370 return WORK_DONE_REQUEUE;
2371 }
2372
Johannes Bergaf6b6372009-12-23 13:15:35 +01002373 mgmt = (void *)skb->data;
2374 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2375
2376 if (status == WLAN_STATUS_SUCCESS) {
2377 mutex_lock(&wk->sdata->u.mgd.mtx);
2378 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2379 mutex_unlock(&wk->sdata->u.mgd.mtx);
2380 /* oops -- internal error -- send timeout for now */
2381 cfg80211_send_assoc_timeout(wk->sdata->dev,
2382 wk->filter_ta);
2383 return WORK_DONE_DESTROY;
2384 }
Juuso Oikarinen68542962010-06-09 13:43:26 +03002385
2386 mutex_unlock(&wk->sdata->u.mgd.mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002387 }
2388
2389 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2390 return WORK_DONE_DESTROY;
2391}
2392
Johannes Berg77fdaa12009-07-07 03:45:17 +02002393int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2394 struct cfg80211_assoc_request *req)
2395{
2396 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002397 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Bergf679f652009-12-23 13:15:34 +01002398 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002399 const u8 *ssid;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002400 int i;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002401
2402 mutex_lock(&ifmgd->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002403 if (ifmgd->associated) {
Jouni Malinen9c87ba62010-02-28 12:13:46 +02002404 if (!req->prev_bssid ||
2405 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2406 ETH_ALEN)) {
2407 /*
2408 * We are already associated and the request was not a
2409 * reassociation request from the current BSS, so
2410 * reject it.
2411 */
2412 mutex_unlock(&ifmgd->mtx);
2413 return -EALREADY;
2414 }
2415
2416 /* Trying to reassociate - clear previous association state */
Johannes Berg53f73c02010-10-05 19:37:40 +02002417 ieee80211_set_disassoc(sdata, true, false);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002418 }
2419 mutex_unlock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002420
Johannes Berg63f170e2009-12-23 13:15:33 +01002421 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002422 if (!wk)
2423 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002424
Johannes Berg77fdaa12009-07-07 03:45:17 +02002425 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05302426 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002427
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002428 ifmgd->beacon_crc_valid = false;
2429
Johannes Berg77fdaa12009-07-07 03:45:17 +02002430 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2431 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2432 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2433 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2434 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2435
Johannes Berg77fdaa12009-07-07 03:45:17 +02002436
2437 if (req->ie && req->ie_len) {
2438 memcpy(wk->ie, req->ie, req->ie_len);
2439 wk->ie_len = req->ie_len;
2440 } else
2441 wk->ie_len = 0;
2442
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002443 wk->assoc.bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01002444
Johannes Bergaf6b6372009-12-23 13:15:35 +01002445 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +01002446
Johannes Bergaf6b6372009-12-23 13:15:35 +01002447 /* new association always uses requested smps mode */
2448 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2449 if (ifmgd->powersave)
2450 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2451 else
2452 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2453 } else
2454 ifmgd->ap_smps = ifmgd->req_smps;
2455
2456 wk->assoc.smps = ifmgd->ap_smps;
Johannes Berg77c81442009-12-23 13:15:37 +01002457 /*
2458 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2459 * We still associate in non-HT mode (11a/b/g) if any one of these
2460 * ciphers is configured as pairwise.
2461 * We can set this to true for non-11n hardware, that'll be checked
2462 * separately along with the peer capabilities.
2463 */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002464 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
Johannes Bergf679f652009-12-23 13:15:34 +01002465 wk->assoc.capability = req->bss->capability;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002466 wk->assoc.wmm_used = bss->wmm_used;
2467 wk->assoc.supp_rates = bss->supp_rates;
2468 wk->assoc.supp_rates_len = bss->supp_rates_len;
Johannes Bergf679f652009-12-23 13:15:34 +01002469 wk->assoc.ht_information_ie =
2470 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002471
Kalle Valoab133152010-01-12 10:42:31 +02002472 if (bss->wmm_used && bss->uapsd_supported &&
2473 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2474 wk->assoc.uapsd_used = true;
2475 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2476 } else {
2477 wk->assoc.uapsd_used = false;
2478 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2479 }
2480
Johannes Berg63f170e2009-12-23 13:15:33 +01002481 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002482 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2483 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002484
Johannes Berg77fdaa12009-07-07 03:45:17 +02002485 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002486 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002487
Johannes Bergf679f652009-12-23 13:15:34 +01002488 wk->chan = req->bss->channel;
Ben Greear4d51e142011-02-07 13:44:34 -08002489 wk->chan_type = NL80211_CHAN_NO_HT;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002490 wk->sdata = sdata;
2491 wk->done = ieee80211_assoc_done;
Johannes Berge5b900d2010-07-29 16:08:55 +02002492 if (!bss->dtim_period &&
2493 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2494 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2495 else
2496 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002497
2498 if (req->use_mfp) {
2499 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2500 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2501 } else {
2502 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2503 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2504 }
2505
2506 if (req->crypto.control_port)
2507 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2508 else
2509 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2510
Johannes Berga621fa42010-08-27 14:26:54 +03002511 sdata->control_port_protocol = req->crypto.control_port_ethertype;
2512 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2513
Johannes Bergaf6b6372009-12-23 13:15:35 +01002514 ieee80211_add_work(wk);
2515 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002516}
2517
2518int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002519 struct cfg80211_deauth_request *req,
2520 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002521{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002522 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002523 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002524 struct ieee80211_work *wk;
Jouni Malinen05e48e82010-06-14 11:55:56 -07002525 u8 bssid[ETH_ALEN];
2526 bool assoc_bss = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002527
Johannes Berg77fdaa12009-07-07 03:45:17 +02002528 mutex_lock(&ifmgd->mtx);
2529
Jouni Malinen05e48e82010-06-14 11:55:56 -07002530 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002531 if (ifmgd->associated == req->bss) {
Johannes Berg53f73c02010-10-05 19:37:40 +02002532 ieee80211_set_disassoc(sdata, false, true);
Johannes Berga58ce432009-11-19 12:45:42 +01002533 mutex_unlock(&ifmgd->mtx);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002534 assoc_bss = true;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002535 } else {
2536 bool not_auth_yet = false;
Johannes Berga58ce432009-11-19 12:45:42 +01002537
Johannes Bergaf6b6372009-12-23 13:15:35 +01002538 mutex_unlock(&ifmgd->mtx);
2539
Johannes Berga1699b72010-07-30 16:46:07 +02002540 mutex_lock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002541 list_for_each_entry(wk, &local->work_list, list) {
Johannes Berg29165e42010-02-06 15:20:13 +01002542 if (wk->sdata != sdata)
Johannes Bergaf6b6372009-12-23 13:15:35 +01002543 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002544
2545 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
Reinette Chatre79733a82010-05-04 16:04:49 -07002546 wk->type != IEEE80211_WORK_AUTH &&
Johannes Berge5b900d2010-07-29 16:08:55 +02002547 wk->type != IEEE80211_WORK_ASSOC &&
2548 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Berg29165e42010-02-06 15:20:13 +01002549 continue;
2550
Johannes Bergaf6b6372009-12-23 13:15:35 +01002551 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2552 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002553
2554 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2555 list_del_rcu(&wk->list);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002556 free_work(wk);
2557 break;
2558 }
Johannes Berga1699b72010-07-30 16:46:07 +02002559 mutex_unlock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002560
2561 /*
2562 * If somebody requests authentication and we haven't
2563 * sent out an auth frame yet there's no need to send
2564 * out a deauth frame either. If the state was PROBE,
2565 * then this is the case. If it's AUTH we have sent a
2566 * frame, and if it's IDLE we have completed the auth
2567 * process already.
2568 */
2569 if (not_auth_yet) {
2570 __cfg80211_auth_canceled(sdata->dev, bssid);
2571 return 0;
2572 }
2573 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002574
Johannes Berg0ff71612009-09-26 14:45:41 +02002575 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002576 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002577
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002578 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2579 req->reason_code, cookie,
2580 !req->local_state_change);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002581 if (assoc_bss)
2582 sta_info_destroy_addr(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002583
Johannes Berg7da7cc12010-08-05 17:02:38 +02002584 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002585 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002586 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002587
Johannes Berg77fdaa12009-07-07 03:45:17 +02002588 return 0;
2589}
2590
2591int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002592 struct cfg80211_disassoc_request *req,
2593 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002594{
2595 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07002596 u8 bssid[ETH_ALEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002597
Johannes Berg77fdaa12009-07-07 03:45:17 +02002598 mutex_lock(&ifmgd->mtx);
2599
Johannes Berg8d8b2612009-07-25 11:58:36 +02002600 /*
2601 * cfg80211 should catch this ... but it's racy since
2602 * we can receive a disassoc frame, process it, hand it
2603 * to cfg80211 while that's in a locked section already
2604 * trying to tell us that the user wants to disconnect.
2605 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002606 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002607 mutex_unlock(&ifmgd->mtx);
2608 return -ENOLINK;
2609 }
2610
Johannes Berg0ff71612009-09-26 14:45:41 +02002611 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002612 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002613
Jouni Malinene69e95d2010-03-29 23:29:31 -07002614 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg53f73c02010-10-05 19:37:40 +02002615 ieee80211_set_disassoc(sdata, false, true);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002616
2617 mutex_unlock(&ifmgd->mtx);
2618
2619 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +02002620 IEEE80211_STYPE_DISASSOC, req->reason_code,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002621 cookie, !req->local_state_change);
Jouni Malinene69e95d2010-03-29 23:29:31 -07002622 sta_info_destroy_addr(sdata, bssid);
Johannes Bergbc83b682009-11-29 12:19:06 +01002623
Johannes Berg7da7cc12010-08-05 17:02:38 +02002624 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002625 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002626 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002627
Johannes Berg77fdaa12009-07-07 03:45:17 +02002628 return 0;
2629}
Jouni Malinen026331c2010-02-15 12:53:10 +02002630
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002631void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2632 enum nl80211_cqm_rssi_threshold_event rssi_event,
2633 gfp_t gfp)
2634{
2635 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2636
Johannes Bergb5878a22010-04-07 16:48:40 +02002637 trace_api_cqm_rssi_notify(sdata, rssi_event);
2638
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002639 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2640}
2641EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);