blob: 72f1e806a8cab22a82de5f240a914af984c79a22 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Paul Gortmakerd9b93842011-09-18 13:21:27 -040019#include <linux/moduleparam.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010020#include <linux/rtnetlink.h>
Jean Pihete8db0be2011-08-25 15:35:03 +020021#include <linux/pm_qos.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020022#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070024#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020025#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020026
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020028#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040029#include "rate.h"
30#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070031
Ben Greear180205b2011-02-04 15:30:24 -080032static int max_nullfunc_tries = 2;
33module_param(max_nullfunc_tries, int, 0644);
34MODULE_PARM_DESC(max_nullfunc_tries,
35 "Maximum nullfunc tx tries before disconnecting (reason 4).");
36
37static int max_probe_tries = 5;
38module_param(max_probe_tries, int, 0644);
39MODULE_PARM_DESC(max_probe_tries,
40 "Maximum probe tries before disconnecting (reason 4).");
Johannes Bergb291ba12009-07-10 15:29:03 +020041
42/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010043 * Beacon loss timeout is calculated as N frames times the
44 * advertised beacon interval. This may need to be somewhat
45 * higher than what hardware might detect to account for
46 * delays in the host processing frames. But since we also
47 * probe on beacon miss before declaring the connection lost
48 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020049 */
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010050#define IEEE80211_BEACON_LOSS_COUNT 7
51
Johannes Bergb291ba12009-07-10 15:29:03 +020052/*
53 * Time the connection can be idle before we probe
54 * it to see if we can still talk to the AP.
55 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030056#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020057/*
58 * Time we wait for a probe response after sending
59 * a probe request because of beacon loss or for
60 * checking the connection still works.
61 */
Ben Greear180205b2011-02-04 15:30:24 -080062static int probe_wait_ms = 500;
63module_param(probe_wait_ms, int, 0644);
64MODULE_PARM_DESC(probe_wait_ms,
65 "Maximum time(ms) to wait for probe response"
66 " before disconnecting (reason 4).");
Jiri Bencf0706e82007-05-05 11:45:53 -070067
Jouni Malinen17e4ec12010-03-29 23:28:30 -070068/*
69 * Weight given to the latest Beacon frame when calculating average signal
70 * strength for Beacon frames received in the current BSS. This must be
71 * between 1 and 15.
72 */
73#define IEEE80211_SIGNAL_AVE_WEIGHT 3
74
Jouni Malinen391a2002010-08-27 22:22:00 +030075/*
76 * How many Beacon frames need to have been used in average signal strength
77 * before starting to indicate signal change events.
78 */
79#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
80
Johannes Berg5bb644a2009-05-17 11:40:42 +020081#define TMR_RUNNING_TIMER 0
82#define TMR_RUNNING_CHANSW 1
83
Johannes Berg77fdaa12009-07-07 03:45:17 +020084/*
85 * All cfg80211 functions have to be called outside a locked
86 * section so that they can acquire a lock themselves... This
87 * is much simpler than queuing up things in cfg80211, but we
88 * do need some indirection for that here.
89 */
90enum rx_mgmt_action {
91 /* no action required */
92 RX_MGMT_NONE,
93
Johannes Berg77fdaa12009-07-07 03:45:17 +020094 /* caller must call cfg80211_send_deauth() */
95 RX_MGMT_CFG80211_DEAUTH,
96
97 /* caller must call cfg80211_send_disassoc() */
98 RX_MGMT_CFG80211_DISASSOC,
Johannes Berg77fdaa12009-07-07 03:45:17 +020099};
100
Johannes Berg5484e232008-09-08 17:44:27 +0200101/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +0200102static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
103{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200104 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200105}
106
Johannes Bergca386f32009-07-10 02:39:48 +0200107/*
108 * We can have multiple work items (and connection probing)
109 * scheduling this timer, but we need to take care to only
110 * reschedule it when it should fire _earlier_ than it was
111 * asked for before, or if it's not pending right now. This
112 * function ensures that. Note that it then is required to
113 * run this function for all timeouts after the first one
114 * has happened -- the work that runs from this timer will
115 * do that.
116 */
117static void run_again(struct ieee80211_if_managed *ifmgd,
118 unsigned long timeout)
119{
120 ASSERT_MGD_MTX(ifmgd);
121
122 if (!timer_pending(&ifmgd->timer) ||
123 time_before(timeout, ifmgd->timer.expires))
124 mod_timer(&ifmgd->timer, timeout);
125}
126
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400127void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200128{
129 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
130 return;
131
132 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100133 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200134}
135
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400136void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
137{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400138 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
139
Stanislaw Gruszka86281722011-02-25 14:46:02 +0100140 if (unlikely(!sdata->u.mgd.associated))
141 return;
142
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400143 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
144 return;
145
146 mod_timer(&sdata->u.mgd.conn_mon_timer,
147 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400148
149 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400150}
151
Johannes Berg5484e232008-09-08 17:44:27 +0200152static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200153{
Johannes Berg5484e232008-09-08 17:44:27 +0200154 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200155}
156
Johannes Bergd5522e02009-03-30 13:23:35 +0200157/*
158 * ieee80211_enable_ht should be called only after the operating band
159 * has been determined as ht configuration depends on the hw's
160 * HT abilities for a specific band.
161 */
162static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
163 struct ieee80211_ht_info *hti,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530164 const u8 *bssid, u16 ap_ht_cap_flags,
165 bool beacon_htcap_ie)
Johannes Bergd5522e02009-03-30 13:23:35 +0200166{
167 struct ieee80211_local *local = sdata->local;
168 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200169 struct sta_info *sta;
170 u32 changed = 0;
Ben Greear172710b2011-01-28 17:05:43 -0800171 int hti_cfreq;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200172 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200173 bool enable_ht = true;
174 enum nl80211_channel_type prev_chantype;
Johannes Bergd5522e02009-03-30 13:23:35 +0200175 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
176
177 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
178
Johannes Berg0aaffa92010-05-05 15:28:27 +0200179 prev_chantype = sdata->vif.bss_conf.channel_type;
180
Johannes Bergd5522e02009-03-30 13:23:35 +0200181 /* HT is not supported */
182 if (!sband->ht_cap.ht_supported)
183 enable_ht = false;
184
Ben Greear172710b2011-01-28 17:05:43 -0800185 if (enable_ht) {
186 hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
187 sband->band);
188 /* check that channel matches the right operating channel */
189 if (local->hw.conf.channel->center_freq != hti_cfreq) {
190 /* Some APs mess this up, evidently.
191 * Netgear WNDR3700 sometimes reports 4 higher than
192 * the actual channel, for instance.
193 */
194 printk(KERN_DEBUG
195 "%s: Wrong control channel in association"
196 " response: configured center-freq: %d"
197 " hti-cfreq: %d hti->control_chan: %d"
198 " band: %d. Disabling HT.\n",
199 sdata->name,
200 local->hw.conf.channel->center_freq,
201 hti_cfreq, hti->control_chan,
202 sband->band);
203 enable_ht = false;
204 }
205 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200206
207 if (enable_ht) {
208 channel_type = NL80211_CHAN_HT20;
209
210 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
211 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
212 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
213 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
214 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400215 if (!(local->hw.conf.channel->flags &
216 IEEE80211_CHAN_NO_HT40PLUS))
217 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200218 break;
219 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400220 if (!(local->hw.conf.channel->flags &
221 IEEE80211_CHAN_NO_HT40MINUS))
222 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200223 break;
224 }
225 }
226 }
227
Reinette Chatrefe6f2122010-04-19 10:46:31 -0700228 if (local->tmp_channel)
229 local->tmp_channel_type = channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200230
Johannes Berg0aaffa92010-05-05 15:28:27 +0200231 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
232 /* can only fail due to HT40+/- mismatch */
233 channel_type = NL80211_CHAN_HT20;
234 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
235 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200236
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530237 if (beacon_htcap_ie && (prev_chantype != channel_type)) {
238 /*
239 * Whenever the AP announces the HT mode change that can be
240 * 40MHz intolerant or etc., it would be safer to stop tx
241 * queues before doing hw config to avoid buffer overflow.
242 */
243 ieee80211_stop_queues_by_reason(&sdata->local->hw,
244 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
245
246 /* flush out all packets */
247 synchronize_net();
248
249 drv_flush(local, false);
250 }
251
Johannes Berg0aaffa92010-05-05 15:28:27 +0200252 /* channel_type change automatically detected */
253 ieee80211_hw_config(local, 0);
254
255 if (prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200256 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100257 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200258 if (sta)
259 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530260 IEEE80211_RC_HT_CHANGED,
Johannes Berg0aaffa92010-05-05 15:28:27 +0200261 channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200262 rcu_read_unlock();
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +0530263
264 if (beacon_htcap_ie)
265 ieee80211_wake_queues_by_reason(&sdata->local->hw,
266 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
Johannes Berg0aaffa92010-05-05 15:28:27 +0200267 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200268
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200269 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200270
271 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200272 if (sdata->ht_opmode_valid != enable_ht ||
273 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
274 prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200275 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200276 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200277 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200278 }
279
280 return changed;
281}
282
Johannes Berg9c6bd792008-09-11 00:01:52 +0200283/* frame sending functions */
284
Johannes Bergef422bc2008-09-09 10:58:25 +0200285static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +0200286 const u8 *bssid, u16 stype, u16 reason,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300287 void *cookie, bool send_frame)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200288{
289 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100290 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200291 struct sk_buff *skb;
292 struct ieee80211_mgmt *mgmt;
293
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200294 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Joe Perchesd15b8452011-08-29 14:17:31 -0700295 if (!skb)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200296 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700297
Johannes Berg9ac19a92008-09-09 10:57:09 +0200298 skb_reserve(skb, local->hw.extra_tx_headroom);
299
300 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
301 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200302 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100303 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200304 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200305 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200306 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200307 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200308 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
309
Jouni Malinen53b46b82009-03-27 20:53:56 +0200310 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470612009-10-13 13:28:13 +0200311 if (cookie)
312 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
313 else
314 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200315 else
Holger Schurigce470612009-10-13 13:28:13 +0200316 if (cookie)
317 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
318 else
319 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100320 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
321 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300322
323 if (send_frame)
324 ieee80211_tx_skb(sdata, skb);
325 else
326 kfree_skb(skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200327}
328
Kalle Valo572e0012009-02-10 17:09:31 +0200329void ieee80211_send_pspoll(struct ieee80211_local *local,
330 struct ieee80211_sub_if_data *sdata)
331{
Kalle Valo572e0012009-02-10 17:09:31 +0200332 struct ieee80211_pspoll *pspoll;
333 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200334
Kalle Valod8cd1892010-01-05 20:16:26 +0200335 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
336 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200337 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200338
Kalle Valod8cd1892010-01-05 20:16:26 +0200339 pspoll = (struct ieee80211_pspoll *) skb->data;
340 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200341
Johannes Berg62ae67b2009-11-18 18:42:05 +0100342 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
343 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200344}
345
Johannes Berg965beda2009-04-16 13:17:24 +0200346void ieee80211_send_nullfunc(struct ieee80211_local *local,
347 struct ieee80211_sub_if_data *sdata,
348 int powersave)
349{
350 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200351 struct ieee80211_hdr_3addr *nullfunc;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530352 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200353
Kalle Valod8cd1892010-01-05 20:16:26 +0200354 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
355 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200356 return;
357
Kalle Valod8cd1892010-01-05 20:16:26 +0200358 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200359 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200360 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200361
Johannes Berg62ae67b2009-11-18 18:42:05 +0100362 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Rajkumar Manoharanb6f35302011-09-29 20:34:04 +0530363 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
364 IEEE80211_STA_CONNECTION_POLL))
365 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
366
Johannes Berg62ae67b2009-11-18 18:42:05 +0100367 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200368}
369
Felix Fietkaud5242152010-01-08 18:06:26 +0100370static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
371 struct ieee80211_sub_if_data *sdata)
372{
373 struct sk_buff *skb;
374 struct ieee80211_hdr *nullfunc;
375 __le16 fc;
376
377 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
378 return;
379
380 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
Joe Perchesd15b8452011-08-29 14:17:31 -0700381 if (!skb)
Felix Fietkaud5242152010-01-08 18:06:26 +0100382 return;
Joe Perchesd15b8452011-08-29 14:17:31 -0700383
Felix Fietkaud5242152010-01-08 18:06:26 +0100384 skb_reserve(skb, local->hw.extra_tx_headroom);
385
386 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
387 memset(nullfunc, 0, 30);
388 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
389 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
390 nullfunc->frame_control = fc;
391 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
392 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
393 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
394 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
395
396 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
397 ieee80211_tx_skb(sdata, skb);
398}
399
Johannes Bergcc32abd2009-05-15 11:52:31 +0200400/* spectrum management related things */
401static void ieee80211_chswitch_work(struct work_struct *work)
402{
403 struct ieee80211_sub_if_data *sdata =
404 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200405 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
406
Johannes Berg9607e6b2009-12-23 13:15:31 +0100407 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200408 return;
409
Johannes Berg77fdaa12009-07-07 03:45:17 +0200410 mutex_lock(&ifmgd->mtx);
411 if (!ifmgd->associated)
412 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200413
414 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200415 if (!sdata->local->ops->channel_switch) {
416 /* call "hw_config" only if doing sw channel switch */
417 ieee80211_hw_config(sdata->local,
418 IEEE80211_CONF_CHANGE_CHANNEL);
Shahar Levi1ea57b12011-09-08 08:44:05 +0300419 } else {
420 /* update the device channel directly */
421 sdata->local->hw.conf.channel = sdata->local->oper_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200422 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200423
Johannes Berg77fdaa12009-07-07 03:45:17 +0200424 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100425 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200426
Johannes Bergcc32abd2009-05-15 11:52:31 +0200427 ieee80211_wake_queues_by_reason(&sdata->local->hw,
428 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200429 out:
430 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
431 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200432}
433
Johannes Berg5ce6e432010-05-11 16:20:57 +0200434void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
435{
436 struct ieee80211_sub_if_data *sdata;
437 struct ieee80211_if_managed *ifmgd;
438
439 sdata = vif_to_sdata(vif);
440 ifmgd = &sdata->u.mgd;
441
442 trace_api_chswitch_done(sdata, success);
443 if (!success) {
444 /*
445 * If the channel switch was not successful, stay
446 * around on the old channel. We currently lack
447 * good handling of this situation, possibly we
448 * should just drop the association.
449 */
450 sdata->local->csa_channel = sdata->local->oper_channel;
451 }
452
453 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
454}
455EXPORT_SYMBOL(ieee80211_chswitch_done);
456
Johannes Bergcc32abd2009-05-15 11:52:31 +0200457static void ieee80211_chswitch_timer(unsigned long data)
458{
459 struct ieee80211_sub_if_data *sdata =
460 (struct ieee80211_sub_if_data *) data;
461 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
462
Johannes Berg5bb644a2009-05-17 11:40:42 +0200463 if (sdata->local->quiescing) {
464 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
465 return;
466 }
467
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400468 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200469}
470
471void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
472 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200473 struct ieee80211_bss *bss,
474 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200475{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100476 struct cfg80211_bss *cbss =
477 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200478 struct ieee80211_channel *new_ch;
479 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900480 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
481 cbss->channel->band);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200482
Johannes Berg77fdaa12009-07-07 03:45:17 +0200483 ASSERT_MGD_MTX(ifmgd);
484
485 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200486 return;
487
Helmut Schaafbe9c422009-07-23 12:14:04 +0200488 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200489 return;
490
491 /* Disregard subsequent beacons if we are already running a timer
492 processing a CSA */
493
494 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
495 return;
496
497 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
498 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
499 return;
500
501 sdata->local->csa_channel = new_ch;
502
Johannes Berg5ce6e432010-05-11 16:20:57 +0200503 if (sdata->local->ops->channel_switch) {
504 /* use driver's channel switch callback */
505 struct ieee80211_channel_switch ch_switch;
506 memset(&ch_switch, 0, sizeof(ch_switch));
507 ch_switch.timestamp = timestamp;
508 if (sw_elem->mode) {
509 ch_switch.block_tx = true;
510 ieee80211_stop_queues_by_reason(&sdata->local->hw,
511 IEEE80211_QUEUE_STOP_REASON_CSA);
512 }
513 ch_switch.channel = new_ch;
514 ch_switch.count = sw_elem->count;
515 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
516 drv_channel_switch(sdata->local, &ch_switch);
517 return;
518 }
519
520 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200521 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400522 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200523 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700524 if (sw_elem->mode)
525 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200526 IEEE80211_QUEUE_STOP_REASON_CSA);
527 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
528 mod_timer(&ifmgd->chswitch_timer,
529 jiffies +
530 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100531 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200532 }
533}
534
535static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
536 u16 capab_info, u8 *pwr_constr_elem,
537 u8 pwr_constr_elem_len)
538{
539 struct ieee80211_conf *conf = &sdata->local->hw.conf;
540
541 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
542 return;
543
544 /* Power constraint IE length should be 1 octet */
545 if (pwr_constr_elem_len != 1)
546 return;
547
548 if ((*pwr_constr_elem <= conf->channel->max_power) &&
549 (*pwr_constr_elem != sdata->local->power_constr_level)) {
550 sdata->local->power_constr_level = *pwr_constr_elem;
551 ieee80211_hw_config(sdata->local, 0);
552 }
553}
554
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300555void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
556{
557 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
558 struct ieee80211_local *local = sdata->local;
559 struct ieee80211_conf *conf = &local->hw.conf;
560
561 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
562 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
563 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
564
565 local->disable_dynamic_ps = false;
566 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
567}
568EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
569
570void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
571{
572 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
573 struct ieee80211_local *local = sdata->local;
574 struct ieee80211_conf *conf = &local->hw.conf;
575
576 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
577 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
578 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
579
580 local->disable_dynamic_ps = true;
581 conf->dynamic_ps_timeout = 0;
582 del_timer_sync(&local->dynamic_ps_timer);
583 ieee80211_queue_work(&local->hw,
584 &local->dynamic_ps_enable_work);
585}
586EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
587
Johannes Berg965beda2009-04-16 13:17:24 +0200588/* powersave */
589static void ieee80211_enable_ps(struct ieee80211_local *local,
590 struct ieee80211_sub_if_data *sdata)
591{
592 struct ieee80211_conf *conf = &local->hw.conf;
593
Johannes Bergd5edaed2009-04-22 23:02:51 +0200594 /*
595 * If we are scanning right now then the parameters will
596 * take effect when scan finishes.
597 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200598 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200599 return;
600
Johannes Berg965beda2009-04-16 13:17:24 +0200601 if (conf->dynamic_ps_timeout > 0 &&
602 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
603 mod_timer(&local->dynamic_ps_timer, jiffies +
604 msecs_to_jiffies(conf->dynamic_ps_timeout));
605 } else {
606 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
607 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530608
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200609 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
610 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
611 return;
612
613 conf->flags |= IEEE80211_CONF_PS;
614 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200615 }
616}
617
618static void ieee80211_change_ps(struct ieee80211_local *local)
619{
620 struct ieee80211_conf *conf = &local->hw.conf;
621
622 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200623 ieee80211_enable_ps(local, local->ps_sdata);
624 } else if (conf->flags & IEEE80211_CONF_PS) {
625 conf->flags &= ~IEEE80211_CONF_PS;
626 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
627 del_timer_sync(&local->dynamic_ps_timer);
628 cancel_work_sync(&local->dynamic_ps_enable_work);
629 }
630}
631
Jason Young808118c2011-03-10 16:43:19 -0800632static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
633{
634 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
635 struct sta_info *sta = NULL;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200636 bool authorized = false;
Jason Young808118c2011-03-10 16:43:19 -0800637
638 if (!mgd->powersave)
639 return false;
640
641 if (!mgd->associated)
642 return false;
643
644 if (!mgd->associated->beacon_ies)
645 return false;
646
647 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
648 IEEE80211_STA_CONNECTION_POLL))
649 return false;
650
651 rcu_read_lock();
652 sta = sta_info_get(sdata, mgd->bssid);
653 if (sta)
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200654 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
Jason Young808118c2011-03-10 16:43:19 -0800655 rcu_read_unlock();
656
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200657 return authorized;
Jason Young808118c2011-03-10 16:43:19 -0800658}
659
Johannes Berg965beda2009-04-16 13:17:24 +0200660/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200661void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200662{
663 struct ieee80211_sub_if_data *sdata, *found = NULL;
664 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300665 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +0200666
667 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
668 local->ps_sdata = NULL;
669 return;
670 }
671
Johannes Bergaf6b6372009-12-23 13:15:35 +0100672 if (!list_empty(&local->work_list)) {
673 local->ps_sdata = NULL;
674 goto change;
675 }
676
Johannes Berg965beda2009-04-16 13:17:24 +0200677 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100678 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200679 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +0530680 if (sdata->vif.type == NL80211_IFTYPE_AP) {
681 /* If an AP vif is found, then disable PS
682 * by setting the count to zero thereby setting
683 * ps_sdata to NULL.
684 */
685 count = 0;
686 break;
687 }
Johannes Berg965beda2009-04-16 13:17:24 +0200688 if (sdata->vif.type != NL80211_IFTYPE_STATION)
689 continue;
690 found = sdata;
691 count++;
692 }
693
Jason Young808118c2011-03-10 16:43:19 -0800694 if (count == 1 && ieee80211_powersave_allowed(found)) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300695 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +0200696 s32 beaconint_us;
697
698 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +0200699 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +0200700
701 beaconint_us = ieee80211_tu_to_usec(
702 found->vif.bss_conf.beacon_int);
703
Juuso Oikarinenff616382010-06-09 09:51:52 +0300704 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300705 if (timeout < 0) {
706 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +0300707 * Go to full PSM if the user configures a very low
708 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +0200709 * The 2000 second value is there for compatibility
710 * until the PM_QOS_NETWORK_LATENCY is configured
711 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300712 */
Eliad Peller0ab82b02010-12-03 02:16:23 +0200713 if (latency > (1900 * USEC_PER_MSEC) &&
714 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300715 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +0300716 else
717 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300718 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300719 local->dynamic_ps_user_timeout = timeout;
720 if (!local->disable_dynamic_ps)
721 conf->dynamic_ps_timeout =
722 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300723
Johannes Berg04fe2032009-04-22 18:44:37 +0200724 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200725 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200726 } else {
Johannes Berg56007a02010-01-26 14:19:52 +0100727 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +0200728 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +0100729 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +0200730
Johannes Berg56007a02010-01-26 14:19:52 +0100731 bss = (void *)found->u.mgd.associated->priv;
732 dtimper = bss->dtim_period;
733
734 /* If the TIM IE is invalid, pretend the value is 1 */
735 if (!dtimper)
736 dtimper = 1;
737 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +0200738 maxslp = min_t(int, dtimper,
739 latency / beaconint_us);
740
Johannes Berg9ccebe62009-04-23 10:32:36 +0200741 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +0100742 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +0200743 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200744 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200745 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200746 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200747 }
Johannes Berg965beda2009-04-16 13:17:24 +0200748
Johannes Bergaf6b6372009-12-23 13:15:35 +0100749 change:
Johannes Berg965beda2009-04-16 13:17:24 +0200750 ieee80211_change_ps(local);
751}
752
753void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
754{
755 struct ieee80211_local *local =
756 container_of(work, struct ieee80211_local,
757 dynamic_ps_disable_work);
758
759 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
760 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
761 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
762 }
763
764 ieee80211_wake_queues_by_reason(&local->hw,
765 IEEE80211_QUEUE_STOP_REASON_PS);
766}
767
768void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
769{
770 struct ieee80211_local *local =
771 container_of(work, struct ieee80211_local,
772 dynamic_ps_enable_work);
773 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Christian Lamparter5e340692011-06-30 21:08:43 +0200774 struct ieee80211_if_managed *ifmgd;
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +0530775 unsigned long flags;
776 int q;
Johannes Berg965beda2009-04-16 13:17:24 +0200777
778 /* can only happen when PS was just disabled anyway */
779 if (!sdata)
780 return;
781
Christian Lamparter5e340692011-06-30 21:08:43 +0200782 ifmgd = &sdata->u.mgd;
783
Johannes Berg965beda2009-04-16 13:17:24 +0200784 if (local->hw.conf.flags & IEEE80211_CONF_PS)
785 return;
786
Arik Nemtsov77b70232011-06-26 12:06:54 +0300787 if (!local->disable_dynamic_ps &&
788 local->hw.conf.dynamic_ps_timeout > 0) {
789 /* don't enter PS if TX frames are pending */
790 if (drv_tx_frames_pending(local)) {
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +0530791 mod_timer(&local->dynamic_ps_timer, jiffies +
792 msecs_to_jiffies(
793 local->hw.conf.dynamic_ps_timeout));
794 return;
795 }
Arik Nemtsov77b70232011-06-26 12:06:54 +0300796
797 /*
798 * transmission can be stopped by others which leads to
799 * dynamic_ps_timer expiry. Postpone the ps timer if it
800 * is not the actual idle state.
801 */
802 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
803 for (q = 0; q < local->hw.queues; q++) {
804 if (local->queue_stop_reasons[q]) {
805 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
806 flags);
807 mod_timer(&local->dynamic_ps_timer, jiffies +
808 msecs_to_jiffies(
809 local->hw.conf.dynamic_ps_timeout));
810 return;
811 }
812 }
813 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +0530814 }
Rajkumar Manoharan1ddc2862011-05-03 17:03:59 +0530815
Vivek Natarajan375177b2010-02-09 14:50:28 +0530816 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530817 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
818 netif_tx_stop_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +0200819
Vivek Natarajane8306f92011-04-06 11:41:10 +0530820 if (drv_tx_frames_pending(local))
821 mod_timer(&local->dynamic_ps_timer, jiffies +
822 msecs_to_jiffies(
823 local->hw.conf.dynamic_ps_timeout));
824 else {
825 ieee80211_send_nullfunc(local, sdata, 1);
826 /* Flush to get the tx status of nullfunc frame */
827 drv_flush(local, false);
828 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530829 }
830
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200831 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
832 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +0530833 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
834 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
835 local->hw.conf.flags |= IEEE80211_CONF_PS;
836 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
837 }
Vivek Natarajanf3e85b92011-02-23 13:04:32 +0530838
Arik Nemtsov77b70232011-06-26 12:06:54 +0300839 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
840 netif_tx_wake_all_queues(sdata->dev);
Johannes Berg965beda2009-04-16 13:17:24 +0200841}
842
843void ieee80211_dynamic_ps_timer(unsigned long data)
844{
845 struct ieee80211_local *local = (void *) data;
846
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700847 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200848 return;
849
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400850 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200851}
852
Johannes Berg60f8b392008-09-08 17:44:22 +0200853/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200854static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +0200855 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700856 u8 *wmm_param, size_t wmm_param_len)
857{
Jiri Bencf0706e82007-05-05 11:45:53 -0700858 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +0200859 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -0700860 size_t left;
861 int count;
Kalle Valoab133152010-01-12 10:42:31 +0200862 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700863
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200864 if (!local->ops->conf_tx)
865 return;
866
Johannes Bergaf6b6372009-12-23 13:15:35 +0100867 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +0200868 return;
869
870 if (!wmm_param)
871 return;
872
Jiri Bencf0706e82007-05-05 11:45:53 -0700873 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
874 return;
Kalle Valoab133152010-01-12 10:42:31 +0200875
876 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200877 uapsd_queues = local->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +0200878
Jiri Bencf0706e82007-05-05 11:45:53 -0700879 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100880 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700881 return;
Johannes Berg46900292009-02-15 12:44:28 +0100882 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700883
884 pos = wmm_param + 8;
885 left = wmm_param_len - 8;
886
887 memset(&params, 0, sizeof(params));
888
Jiri Bencf0706e82007-05-05 11:45:53 -0700889 local->wmm_acm = 0;
890 for (; left >= 4; left -= 4, pos += 4) {
891 int aci = (pos[0] >> 5) & 0x03;
892 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +0200893 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700894 int queue;
895
896 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200897 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200898 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200899 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200900 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +0200901 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
902 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700903 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200904 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200905 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200906 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200907 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +0200908 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
909 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700910 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200911 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200912 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200913 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200914 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +0200915 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
916 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700917 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200918 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700919 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200920 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200921 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200922 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +0200923 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
924 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700925 break;
926 }
927
928 params.aifs = pos[0] & 0x0f;
929 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
930 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200931 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +0200932 params.uapsd = uapsd;
933
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200934#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700935 wiphy_debug(local->hw.wiphy,
936 "WMM queue=%d aci=%d acm=%d aifs=%d "
937 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
938 queue, aci, acm,
939 params.aifs, params.cw_min, params.cw_max,
940 params.txop, params.uapsd);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100941#endif
Eliad Pellerf6f3def2011-09-25 20:06:54 +0300942 sdata->tx_conf[queue] = params;
943 if (drv_conf_tx(local, sdata, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700944 wiphy_debug(local->hw.wiphy,
945 "failed to set TX queue parameters for queue %d\n",
946 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700947 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200948
949 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +0200950 sdata->vif.bss_conf.qos = true;
951 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700952}
953
Johannes Berg7a5158e2008-10-08 10:59:33 +0200954static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
955 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200956{
Johannes Bergbda39332008-10-11 01:51:51 +0200957 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100958 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200959 bool use_protection;
960 bool use_short_preamble;
961 bool use_short_slot;
962
963 if (erp_valid) {
964 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
965 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
966 } else {
967 use_protection = false;
968 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
969 }
970
971 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +0100972 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
973 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +0200974
Johannes Berg471b3ef2007-12-28 14:32:58 +0100975 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100976 bss_conf->use_cts_prot = use_protection;
977 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200978 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200979
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200980 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200981 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100982 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200983 }
Daniel Draked9430a32007-07-27 15:43:24 +0200984
Johannes Berg7a5158e2008-10-08 10:59:33 +0200985 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200986 bss_conf->use_short_slot = use_short_slot;
987 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400988 }
989
990 return changed;
991}
992
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200993static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100994 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200995 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700996{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100997 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100998 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +0300999 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001000
Johannes Bergae5eb022008-10-14 16:58:37 +02001001 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001002 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +03001003 bss_conf->beacon_int = cbss->beacon_interval;
1004 bss_conf->timestamp = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -04001005
Johannes Berg77fdaa12009-07-07 03:45:17 +02001006 bss_info_changed |= BSS_CHANGED_BEACON_INT;
1007 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001008 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001009
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +01001010 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
1011 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
1012
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001013 sdata->u.mgd.associated = cbss;
1014 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +01001015
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001016 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
1017
Johannes Bergb291ba12009-07-10 15:29:03 +02001018 /* just to be sure */
1019 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1020 IEEE80211_STA_BEACON_POLL);
1021
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001022 ieee80211_led_assoc(local, 1);
1023
Johannes Berge5b900d2010-07-29 16:08:55 +02001024 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
1025 bss_conf->dtim_period = bss->dtim_period;
1026 else
1027 bss_conf->dtim_period = 0;
1028
Juuso Oikarinen68542962010-06-09 13:43:26 +03001029 bss_conf->assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +02001030 /*
1031 * For now just always ask the driver to update the basic rateset
1032 * when we have associated, we aren't checking whether it actually
1033 * changed or not.
1034 */
Johannes Bergae5eb022008-10-14 16:58:37 +02001035 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +02001036
1037 /* And the BSSID changed - we're associated now */
1038 bss_info_changed |= BSS_CHANGED_BSSID;
1039
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001040 /* Tell the driver to monitor connection quality (if supported) */
1041 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
Juuso Oikarinen68542962010-06-09 13:43:26 +03001042 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001043 bss_info_changed |= BSS_CHANGED_CQM;
1044
Juuso Oikarinen68542962010-06-09 13:43:26 +03001045 /* Enable ARP filtering */
1046 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
1047 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
1048 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
1049 }
1050
Johannes Bergae5eb022008-10-14 16:58:37 +02001051 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +03001052
Johannes Berg056508d2009-07-30 21:43:55 +02001053 mutex_lock(&local->iflist_mtx);
1054 ieee80211_recalc_ps(local, -1);
Johannes Berg025e6be2010-10-05 10:41:47 +02001055 ieee80211_recalc_smps(local);
Johannes Berg056508d2009-07-30 21:43:55 +02001056 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +02001057
John W. Linville8a5b33f2010-01-06 15:39:39 -05001058 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001059 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -07001060}
1061
Jouni Malinene69e95d2010-03-29 23:29:31 -07001062static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg53f73c02010-10-05 19:37:40 +02001063 bool remove_sta, bool tx)
Tomas Winkleraa458d12008-09-09 00:32:12 +03001064{
Johannes Berg46900292009-02-15 12:44:28 +01001065 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +03001066 struct ieee80211_local *local = sdata->local;
1067 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +02001068 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +02001069 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +03001070
Johannes Berg77fdaa12009-07-07 03:45:17 +02001071 ASSERT_MGD_MTX(ifmgd);
1072
Johannes Bergb291ba12009-07-10 15:29:03 +02001073 if (WARN_ON(!ifmgd->associated))
1074 return;
1075
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001076 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +02001077
Johannes Berg77fdaa12009-07-07 03:45:17 +02001078 ifmgd->associated = NULL;
1079 memset(ifmgd->bssid, 0, ETH_ALEN);
1080
1081 /*
1082 * we need to commit the associated = NULL change because the
1083 * scan code uses that to determine whether this iface should
1084 * go to/wake up from powersave or not -- and could otherwise
1085 * wake the queues erroneously.
1086 */
1087 smp_mb();
1088
1089 /*
1090 * Thus, we can only afterwards stop the queues -- to account
1091 * for the case where another CPU is finishing a scan at this
1092 * time -- we don't want the scan code to enable queues.
1093 */
Tomas Winkleraa458d12008-09-09 00:32:12 +03001094
John W. Linville8a5b33f2010-01-06 15:39:39 -05001095 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001096 netif_carrier_off(sdata->dev);
1097
Johannes Berg2a419052010-06-10 10:21:29 +02001098 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +01001099 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +05301100 if (sta) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001101 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
Johannes Berg53f73c02010-10-05 19:37:40 +02001102 ieee80211_sta_tear_down_BA_sessions(sta, tx);
Sujith4cad6c72010-02-10 14:52:21 +05301103 }
Johannes Berg2a419052010-06-10 10:21:29 +02001104 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001105
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001106 changed |= ieee80211_reset_erp_info(sdata);
1107
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001108 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001109 changed |= BSS_CHANGED_ASSOC;
1110 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001111
Johannes Bergaa837e12009-05-07 16:16:24 +02001112 ieee80211_set_wmm_default(sdata);
1113
Johannes Berg47979382009-01-07 10:13:27 +01001114 /* channel(_type) changes are handled by ieee80211_hw_config */
Johannes Berg0aaffa92010-05-05 15:28:27 +02001115 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
Johannes Bergae5eb022008-10-14 16:58:37 +02001116
Johannes Berg413ad502009-05-08 21:21:06 +02001117 /* on the next assoc, re-program HT parameters */
1118 sdata->ht_opmode_valid = false;
1119
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301120 local->power_constr_level = 0;
1121
Kalle Valo520eb822008-12-18 23:35:27 +02001122 del_timer_sync(&local->dynamic_ps_timer);
1123 cancel_work_sync(&local->dynamic_ps_enable_work);
1124
Kalle Valoe0cb6862008-12-18 23:35:13 +02001125 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1126 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1127 config_changed |= IEEE80211_CONF_CHANGE_PS;
1128 }
Eliad Pellera3314002011-05-26 11:46:37 +03001129 local->ps_sdata = NULL;
Kalle Valoe0cb6862008-12-18 23:35:13 +02001130
1131 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +02001132
Juuso Oikarinen68542962010-06-09 13:43:26 +03001133 /* Disable ARP filtering */
1134 if (sdata->vif.bss_conf.arp_filter_enabled) {
1135 sdata->vif.bss_conf.arp_filter_enabled = false;
1136 changed |= BSS_CHANGED_ARP_FILTER;
1137 }
1138
Johannes Berg0aaffa92010-05-05 15:28:27 +02001139 /* The BSSID (not really interesting) and HT changed */
1140 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001141 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001142
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001143 /* remove AP and TDLS peers */
Jouni Malinene69e95d2010-03-29 23:29:31 -07001144 if (remove_sta)
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001145 sta_info_flush(local, sdata);
Johannes Bergb9dcf712010-08-27 12:35:54 +02001146
1147 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1148 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1149 del_timer_sync(&sdata->u.mgd.timer);
1150 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001151}
Jiri Bencf0706e82007-05-05 11:45:53 -07001152
Kalle Valo3cf335d2009-03-22 21:57:06 +02001153void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1154 struct ieee80211_hdr *hdr)
1155{
1156 /*
1157 * We can postpone the mgd.timer whenever receiving unicast frames
1158 * from AP because we know that the connection is working both ways
1159 * at that time. But multicast frames (and hence also beacons) must
1160 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001161 * data idle periods for sending the periodic probe request to the
1162 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001163 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001164 if (is_multicast_ether_addr(hdr->addr1))
1165 return;
1166
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001167 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001168}
Jiri Bencf0706e82007-05-05 11:45:53 -07001169
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001170static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1171{
1172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1173
1174 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1175 IEEE80211_STA_CONNECTION_POLL)))
1176 return;
1177
1178 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1179 IEEE80211_STA_BEACON_POLL);
1180 mutex_lock(&sdata->local->iflist_mtx);
1181 ieee80211_recalc_ps(sdata->local, -1);
1182 mutex_unlock(&sdata->local->iflist_mtx);
1183
1184 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1185 return;
1186
1187 /*
1188 * We've received a probe response, but are not sure whether
1189 * we have or will be receiving any beacons or data, so let's
1190 * schedule the timers again, just in case.
1191 */
1192 ieee80211_sta_reset_beacon_monitor(sdata);
1193
1194 mod_timer(&ifmgd->conn_mon_timer,
1195 round_jiffies_up(jiffies +
1196 IEEE80211_CONNECTION_IDLE_TIME));
1197}
1198
1199void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001200 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001201{
Felix Fietkau75706d02010-12-02 21:01:07 +01001202 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001203 return;
1204
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001205 if (ack)
1206 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001207
1208 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1209 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001210 if (ack)
1211 sdata->u.mgd.probe_send_count = 0;
1212 else
1213 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001214 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1215 }
1216}
1217
Maxim Levitskya43abf22009-07-31 18:54:12 +03001218static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1219{
1220 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1221 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001222 u8 *dst = ifmgd->associated->bssid;
Ben Greear180205b2011-02-04 15:30:24 -08001223 u8 unicast_limit = max(1, max_probe_tries - 3);
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001224
1225 /*
1226 * Try sending broadcast probe requests for the last three
1227 * probe requests after the first ones failed since some
1228 * buggy APs only support broadcast probe requests.
1229 */
1230 if (ifmgd->probe_send_count >= unicast_limit)
1231 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001232
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001233 /*
1234 * When the hardware reports an accurate Tx ACK status, it's
1235 * better to send a nullfunc frame instead of a probe request,
1236 * as it will kick us off the AP quickly if we aren't associated
1237 * anymore. The timeout will be reset if the frame is ACKed by
1238 * the AP.
1239 */
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001240 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1241 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001242 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001243 } else {
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001244 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
Paul Stewarta806c552011-06-23 09:00:11 -08001245 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05301246 (u32) -1, true, false);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001247 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001248
1249 ifmgd->probe_send_count++;
Ben Greear180205b2011-02-04 15:30:24 -08001250 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001251 run_again(ifmgd, ifmgd->probe_timeout);
1252}
1253
Johannes Bergb291ba12009-07-10 15:29:03 +02001254static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1255 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001256{
Kalle Valo04de8382009-03-22 21:57:35 +02001257 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001258 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001259
Johannes Berg9607e6b2009-12-23 13:15:31 +01001260 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001261 return;
1262
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001263 if (sdata->local->scanning)
1264 return;
1265
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001266 if (sdata->local->tmp_channel)
1267 return;
1268
Johannes Berg77fdaa12009-07-07 03:45:17 +02001269 mutex_lock(&ifmgd->mtx);
1270
1271 if (!ifmgd->associated)
1272 goto out;
1273
Michael Buescha8604022009-04-15 14:41:22 -04001274#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001275 if (beacon && net_ratelimit())
1276 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001277 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001278#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001279
Johannes Bergb291ba12009-07-10 15:29:03 +02001280 /*
1281 * The driver/our work has already reported this event or the
1282 * connection monitoring has kicked in and we have already sent
1283 * a probe request. Or maybe the AP died and the driver keeps
1284 * reporting until we disassociate...
1285 *
1286 * In either case we have to ignore the current call to this
1287 * function (except for setting the correct probe reason bit)
1288 * because otherwise we would reset the timer every time and
1289 * never check whether we received a probe response!
1290 */
1291 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1292 IEEE80211_STA_CONNECTION_POLL))
1293 already = true;
1294
1295 if (beacon)
1296 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1297 else
1298 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1299
1300 if (already)
1301 goto out;
1302
Johannes Berg4e751842009-06-10 15:16:52 +02001303 mutex_lock(&sdata->local->iflist_mtx);
1304 ieee80211_recalc_ps(sdata->local, -1);
1305 mutex_unlock(&sdata->local->iflist_mtx);
1306
Maxim Levitskya43abf22009-07-31 18:54:12 +03001307 ifmgd->probe_send_count = 0;
1308 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001309 out:
1310 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001311}
1312
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001313struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1314 struct ieee80211_vif *vif)
1315{
1316 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1317 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1318 struct sk_buff *skb;
1319 const u8 *ssid;
1320
1321 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1322 return NULL;
1323
1324 ASSERT_MGD_MTX(ifmgd);
1325
1326 if (!ifmgd->associated)
1327 return NULL;
1328
1329 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1330 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
Johannes Berg85a237f2011-07-18 18:08:36 +02001331 (u32) -1, ssid + 2, ssid[1],
1332 NULL, 0, true);
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001333
1334 return skb;
1335}
1336EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1337
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001338static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1339{
1340 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1341 struct ieee80211_local *local = sdata->local;
1342 u8 bssid[ETH_ALEN];
1343
1344 mutex_lock(&ifmgd->mtx);
1345 if (!ifmgd->associated) {
1346 mutex_unlock(&ifmgd->mtx);
1347 return;
1348 }
1349
1350 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1351
Ben Greear180205b2011-02-04 15:30:24 -08001352 printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
1353 sdata->name, bssid);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001354
Johannes Berg53f73c02010-10-05 19:37:40 +02001355 ieee80211_set_disassoc(sdata, true, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001356 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001357
1358 mutex_lock(&local->mtx);
1359 ieee80211_recalc_idle(local);
1360 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001361 /*
1362 * must be outside lock due to cfg80211,
1363 * but that's not a problem.
1364 */
1365 ieee80211_send_deauth_disassoc(sdata, bssid,
1366 IEEE80211_STYPE_DEAUTH,
1367 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001368 NULL, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001369}
1370
1371void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001372{
1373 struct ieee80211_sub_if_data *sdata =
1374 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001375 u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001376
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001377 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1378 __ieee80211_connection_loss(sdata);
1379 else
1380 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001381}
1382
Kalle Valo04de8382009-03-22 21:57:35 +02001383void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1384{
1385 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001386 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001387
Johannes Bergb5878a22010-04-07 16:48:40 +02001388 trace_api_beacon_loss(sdata);
1389
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001390 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1391 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001392}
1393EXPORT_SYMBOL(ieee80211_beacon_loss);
1394
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001395void ieee80211_connection_loss(struct ieee80211_vif *vif)
1396{
1397 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1398 struct ieee80211_hw *hw = &sdata->local->hw;
1399
Johannes Bergb5878a22010-04-07 16:48:40 +02001400 trace_api_connection_loss(sdata);
1401
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001402 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1403 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1404}
1405EXPORT_SYMBOL(ieee80211_connection_loss);
1406
1407
Johannes Berg77fdaa12009-07-07 03:45:17 +02001408static enum rx_mgmt_action __must_check
1409ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001410 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001411{
Johannes Berg46900292009-02-15 12:44:28 +01001412 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001413 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001414 u16 reason_code;
1415
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001416 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001417 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001418
Johannes Berg77fdaa12009-07-07 03:45:17 +02001419 ASSERT_MGD_MTX(ifmgd);
1420
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001421 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001422
1423 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1424
Johannes Berg77fdaa12009-07-07 03:45:17 +02001425 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001426 sdata->name, bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001427
Johannes Berg53f73c02010-10-05 19:37:40 +02001428 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001429 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001430 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001431 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001432
1433 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001434}
1435
1436
Johannes Berg77fdaa12009-07-07 03:45:17 +02001437static enum rx_mgmt_action __must_check
1438ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1439 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001440{
Johannes Berg46900292009-02-15 12:44:28 +01001441 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001442 u16 reason_code;
1443
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001444 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001445 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001446
Johannes Berg77fdaa12009-07-07 03:45:17 +02001447 ASSERT_MGD_MTX(ifmgd);
1448
1449 if (WARN_ON(!ifmgd->associated))
1450 return RX_MGMT_NONE;
1451
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001452 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001453 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001454
1455 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1456
Johannes Berg0ff71612009-09-26 14:45:41 +02001457 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001458 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001459
Johannes Berg53f73c02010-10-05 19:37:40 +02001460 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001461 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001462 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001463 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001464 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001465}
1466
1467
Johannes Bergaf6b6372009-12-23 13:15:35 +01001468static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1469 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001470{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001471 struct ieee80211_sub_if_data *sdata = wk->sdata;
Johannes Berg46900292009-02-15 12:44:28 +01001472 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001473 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001474 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001475 struct sta_info *sta;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001476 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001477 u8 *pos;
Johannes Berg881d9482009-01-21 15:13:48 +01001478 u32 rates, basic_rates;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001479 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001480 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001481 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02001482 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001483 int i, j, err;
1484 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001485 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001486
Johannes Bergaf6b6372009-12-23 13:15:35 +01001487 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07001488
Jiri Bencf0706e82007-05-05 11:45:53 -07001489 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001490 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07001491
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001492 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1493 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001494 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001495 aid &= ~(BIT(15) | BIT(14));
1496
Johannes Bergaf6b6372009-12-23 13:15:35 +01001497 pos = mgmt->u.assoc_resp.variable;
1498 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1499
Jiri Bencf0706e82007-05-05 11:45:53 -07001500 if (!elems.supp_rates) {
1501 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001502 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001503 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001504 }
1505
Johannes Berg46900292009-02-15 12:44:28 +01001506 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001507
Guy Eilam2a33bee2011-08-17 15:18:15 +03001508 mutex_lock(&sdata->local->sta_mtx);
1509 /*
1510 * station info was already allocated and inserted before
1511 * the association and should be available to us
1512 */
1513 sta = sta_info_get_rx(sdata, cbss->bssid);
1514 if (WARN_ON(!sta)) {
1515 mutex_unlock(&sdata->local->sta_mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001516 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001517 }
1518
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001519 set_sta_flag(sta, WLAN_STA_AUTH);
1520 set_sta_flag(sta, WLAN_STA_ASSOC);
1521 set_sta_flag(sta, WLAN_STA_ASSOC_AP);
Johannes Berg5d1ec852009-12-02 12:43:43 +01001522 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001523 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
Johannes Berg5d1ec852009-12-02 12:43:43 +01001524
Jiri Bencf0706e82007-05-05 11:45:53 -07001525 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001526 basic_rates = 0;
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001527 sband = local->hw.wiphy->bands[wk->chan->band];
Johannes Berg8318d782008-01-24 19:38:38 +01001528
Jiri Bencf0706e82007-05-05 11:45:53 -07001529 for (i = 0; i < elems.supp_rates_len; i++) {
1530 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001531 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001532
1533 if (rate > 110)
1534 have_higher_than_11mbit = true;
1535
1536 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001537 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001538 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001539 if (is_basic)
1540 basic_rates |= BIT(j);
1541 break;
1542 }
Johannes Berg8318d782008-01-24 19:38:38 +01001543 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001544 }
Johannes Berg8318d782008-01-24 19:38:38 +01001545
Jiri Bencf0706e82007-05-05 11:45:53 -07001546 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1547 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001548 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001549
1550 if (rate > 110)
1551 have_higher_than_11mbit = true;
1552
1553 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001554 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001555 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001556 if (is_basic)
1557 basic_rates |= BIT(j);
1558 break;
1559 }
Johannes Berg8318d782008-01-24 19:38:38 +01001560 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001561 }
Johannes Berg8318d782008-01-24 19:38:38 +01001562
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001563 sta->sta.supp_rates[wk->chan->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001564 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001565
1566 /* cf. IEEE 802.11 9.2.12 */
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001567 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
Johannes Berg8318d782008-01-24 19:38:38 +01001568 have_higher_than_11mbit)
1569 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1570 else
1571 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001572
Johannes Bergab1faea2009-07-01 21:41:17 +02001573 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001574 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001575 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001576
1577 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001578
Johannes Berg4b7679a2008-09-18 18:14:18 +02001579 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001580
Johannes Berg46900292009-02-15 12:44:28 +01001581 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001582 set_sta_flag(sta, WLAN_STA_MFP);
Jouni Malinen5394af42009-01-08 13:31:59 +02001583
Johannes Bergddf4ac52008-10-22 11:41:38 +02001584 if (elems.wmm_param)
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001585 set_sta_flag(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001586
Guy Eilam2a33bee2011-08-17 15:18:15 +03001587 /* sta_info_reinsert will also unlock the mutex lock */
1588 err = sta_info_reinsert(sta);
Johannes Berg5d1ec852009-12-02 12:43:43 +01001589 sta = NULL;
1590 if (err) {
1591 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1592 " the AP (error %d)\n", sdata->name, err);
Johannes Berg90be5612010-01-08 19:01:07 +01001593 return false;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001594 }
1595
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03001596 /*
1597 * Always handle WMM once after association regardless
1598 * of the first value the AP uses. Setting -1 here has
1599 * that effect because the AP values is an unsigned
1600 * 4-bit value.
1601 */
1602 ifmgd->wmm_last_param_set = -1;
1603
Johannes Bergddf4ac52008-10-22 11:41:38 +02001604 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02001605 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001606 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001607 else
1608 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001609
Johannes Berge4da8c32009-12-23 13:15:43 +01001610 local->oper_channel = wk->chan;
1611
Johannes Bergae5eb022008-10-14 16:58:37 +02001612 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergaf6b6372009-12-23 13:15:35 +01001613 (sdata->local->hw.queues >= 4) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001614 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001615 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +05301616 cbss->bssid, ap_ht_cap_flags,
1617 false);
Johannes Bergae5eb022008-10-14 16:58:37 +02001618
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001619 /* set AID and assoc capability,
1620 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001621 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001622 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001623 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001624
Kalle Valo15b7b062009-03-22 21:57:14 +02001625 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01001626 * If we're using 4-addr mode, let the AP know that we're
1627 * doing so, so that it can create the STA VLAN on its side
1628 */
1629 if (ifmgd->use_4addr)
1630 ieee80211_send_4addr_nullfunc(local, sdata);
1631
1632 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001633 * Start timer to probe the connection to the AP now.
1634 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001635 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001636 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001637 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001638
Johannes Bergaf6b6372009-12-23 13:15:35 +01001639 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001640}
1641
1642
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001643static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001644 struct ieee80211_mgmt *mgmt,
1645 size_t len,
1646 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001647 struct ieee802_11_elems *elems,
1648 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001649{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001650 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001651 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001652 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001653 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01001654 bool need_ps = false;
1655
1656 if (sdata->u.mgd.associated) {
1657 bss = (void *)sdata->u.mgd.associated->priv;
1658 /* not previously set so we may need to recalc */
1659 need_ps = !bss->dtim_period;
1660 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001661
Johannes Berg5bda6172008-09-08 11:05:10 +02001662 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001663 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
1664 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02001665 else
1666 freq = rx_status->freq;
1667
1668 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1669
1670 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1671 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001672
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001673 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001674 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001675 if (bss)
1676 ieee80211_rx_bss_put(local, bss);
1677
1678 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001679 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001680
Johannes Berg56007a02010-01-26 14:19:52 +01001681 if (need_ps) {
1682 mutex_lock(&local->iflist_mtx);
1683 ieee80211_recalc_ps(local, -1);
1684 mutex_unlock(&local->iflist_mtx);
1685 }
1686
Sujithc481ec92009-01-06 09:28:37 +05301687 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001688 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001689 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301690 struct ieee80211_channel_sw_ie *sw_elem =
1691 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001692 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1693 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05301694 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001695}
1696
1697
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001698static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01001699 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001700{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001701 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02001702 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001703 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1704 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001705 struct ieee802_11_elems elems;
1706
Kalle Valo15b7b062009-03-22 21:57:14 +02001707 ifmgd = &sdata->u.mgd;
1708
Johannes Berg77fdaa12009-07-07 03:45:17 +02001709 ASSERT_MGD_MTX(ifmgd);
1710
Johannes Berg47846c92009-11-25 17:46:19 +01001711 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001712 return; /* ignore ProbeResp to foreign address */
1713
Ester Kummerae6a44e2008-06-27 18:54:48 +03001714 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1715 if (baselen > len)
1716 return;
1717
1718 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1719 &elems);
1720
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001721 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001722
Johannes Berg77fdaa12009-07-07 03:45:17 +02001723 if (ifmgd->associated &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001724 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
1725 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001726}
1727
Johannes Bergd91f36d2009-04-16 13:17:26 +02001728/*
1729 * This is the canonical list of information elements we care about,
1730 * the filter code also gives us all changes to the Microsoft OUI
1731 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1732 *
1733 * We implement beacon filtering in software since that means we can
1734 * avoid processing the frame here and in cfg80211, and userspace
1735 * will not be able to tell whether the hardware supports it or not.
1736 *
1737 * XXX: This list needs to be dynamic -- userspace needs to be able to
1738 * add items it requires. It also needs to be able to tell us to
1739 * look out for other vendor IEs.
1740 */
1741static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001742 (1ULL << WLAN_EID_COUNTRY) |
1743 (1ULL << WLAN_EID_ERP_INFO) |
1744 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1745 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1746 (1ULL << WLAN_EID_HT_CAPABILITY) |
1747 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001748
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001749static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001750 struct ieee80211_mgmt *mgmt,
1751 size_t len,
1752 struct ieee80211_rx_status *rx_status)
1753{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001754 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001755 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001756 size_t baselen;
1757 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001758 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001759 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001760 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001761 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001762 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001763 u8 *bssid;
1764
1765 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e82007-05-05 11:45:53 -07001766
Ester Kummerae6a44e2008-06-27 18:54:48 +03001767 /* Process beacon from the current BSS */
1768 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1769 if (baselen > len)
1770 return;
1771
Johannes Bergd91f36d2009-04-16 13:17:26 +02001772 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001773 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001774
Johannes Bergb291ba12009-07-10 15:29:03 +02001775 /*
1776 * We might have received a number of frames, among them a
1777 * disassoc frame and a beacon...
1778 */
1779 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001780 return;
1781
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001782 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001783
Johannes Bergb291ba12009-07-10 15:29:03 +02001784 /*
1785 * And in theory even frames from a different AP we were just
1786 * associated to a split-second ago!
1787 */
1788 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001789 return;
1790
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001791 /* Track average RSSI from the Beacon frames of the current AP */
1792 ifmgd->last_beacon_signal = rx_status->signal;
1793 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1794 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03001795 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001796 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03001797 ifmgd->count_beacon_signal = 1;
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07001798 ifmgd->last_ave_beacon_signal = 0;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001799 } else {
1800 ifmgd->ave_beacon_signal =
1801 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1802 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1803 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03001804 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001805 }
Meenakshi Venkataraman615f7b92011-07-08 08:46:22 -07001806
1807 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
1808 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
1809 int sig = ifmgd->ave_beacon_signal;
1810 int last_sig = ifmgd->last_ave_beacon_signal;
1811
1812 /*
1813 * if signal crosses either of the boundaries, invoke callback
1814 * with appropriate parameters
1815 */
1816 if (sig > ifmgd->rssi_max_thold &&
1817 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
1818 ifmgd->last_ave_beacon_signal = sig;
1819 drv_rssi_callback(local, RSSI_EVENT_HIGH);
1820 } else if (sig < ifmgd->rssi_min_thold &&
1821 (last_sig >= ifmgd->rssi_max_thold ||
1822 last_sig == 0)) {
1823 ifmgd->last_ave_beacon_signal = sig;
1824 drv_rssi_callback(local, RSSI_EVENT_LOW);
1825 }
1826 }
1827
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001828 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03001829 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001830 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1831 int sig = ifmgd->ave_beacon_signal / 16;
1832 int last_event = ifmgd->last_cqm_event_signal;
1833 int thold = bss_conf->cqm_rssi_thold;
1834 int hyst = bss_conf->cqm_rssi_hyst;
1835 if (sig < thold &&
1836 (last_event == 0 || sig < last_event - hyst)) {
1837 ifmgd->last_cqm_event_signal = sig;
1838 ieee80211_cqm_rssi_notify(
1839 &sdata->vif,
1840 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1841 GFP_KERNEL);
1842 } else if (sig > thold &&
1843 (last_event == 0 || sig > last_event + hyst)) {
1844 ifmgd->last_cqm_event_signal = sig;
1845 ieee80211_cqm_rssi_notify(
1846 &sdata->vif,
1847 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1848 GFP_KERNEL);
1849 }
1850 }
1851
Johannes Bergb291ba12009-07-10 15:29:03 +02001852 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001853#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1854 if (net_ratelimit()) {
1855 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001856 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001857 }
1858#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001859 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001860 mutex_lock(&local->iflist_mtx);
1861 ieee80211_recalc_ps(local, -1);
1862 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001863 }
1864
Johannes Bergb291ba12009-07-10 15:29:03 +02001865 /*
1866 * Push the beacon loss detection into the future since
1867 * we are processing a beacon from the AP just now.
1868 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001869 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001870
Johannes Bergd91f36d2009-04-16 13:17:26 +02001871 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1872 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1873 len - baselen, &elems,
1874 care_about_ies, ncrc);
1875
1876 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001877 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1878 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001879
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001880 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
Jouni Malinen30196672009-05-19 17:01:43 +03001881 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1882 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001883
Johannes Berg4ced3f72010-07-19 16:39:04 +02001884 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03001885 elems.wmm_param_len);
1886 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001887
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301888 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001889 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001890 if (local->hw.conf.dynamic_ps_timeout > 0) {
1891 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1892 ieee80211_hw_config(local,
1893 IEEE80211_CONF_CHANGE_PS);
1894 ieee80211_send_nullfunc(local, sdata, 0);
1895 } else {
1896 local->pspolling = true;
1897
1898 /*
1899 * Here is assumed that the driver will be
1900 * able to send ps-poll frame and receive a
1901 * response even though power save mode is
1902 * enabled, but some drivers might require
1903 * to disable power save here. This needs
1904 * to be investigated.
1905 */
1906 ieee80211_send_pspoll(local, sdata);
1907 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001908 }
1909 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001910
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001911 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03001912 return;
1913 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001914 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03001915
Johannes Berg7a5158e2008-10-08 10:59:33 +02001916 if (elems.erp_info && elems.erp_info_len >= 1) {
1917 erp_valid = true;
1918 erp_value = elems.erp_info[0];
1919 } else {
1920 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001921 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001922 changed |= ieee80211_handle_bss_capability(sdata,
1923 le16_to_cpu(mgmt->u.beacon.capab_info),
1924 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001925
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001926
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301927 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001928 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001929 struct sta_info *sta;
1930 struct ieee80211_supported_band *sband;
1931 u16 ap_ht_cap_flags;
1932
1933 rcu_read_lock();
1934
Johannes Bergabe60632009-11-25 17:46:18 +01001935 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001936 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001937 rcu_read_unlock();
1938 return;
1939 }
1940
1941 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1942
1943 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1944 elems.ht_cap_elem, &sta->sta.ht_cap);
1945
1946 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1947
1948 rcu_read_unlock();
1949
1950 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Rajkumar Manoharan7cc44ed2011-09-16 15:32:34 +05301951 bssid, ap_ht_cap_flags, true);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001952 }
1953
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001954 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001955 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301956 /* TODO: IBSS also needs this */
1957 if (elems.pwr_constr_elem)
1958 ieee80211_handle_pwr_constr(sdata,
1959 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1960 elems.pwr_constr_elem,
1961 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001962 }
1963
Johannes Berg471b3ef2007-12-28 14:32:58 +01001964 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001965}
1966
Johannes Berg1fa57d02010-06-10 10:21:32 +02001967void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1968 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001969{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001970 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001971 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001972 struct ieee80211_mgmt *mgmt;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001973 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001974 u16 fc;
1975
Jiri Bencf0706e82007-05-05 11:45:53 -07001976 rx_status = (struct ieee80211_rx_status *) skb->cb;
1977 mgmt = (struct ieee80211_mgmt *) skb->data;
1978 fc = le16_to_cpu(mgmt->frame_control);
1979
Johannes Berg77fdaa12009-07-07 03:45:17 +02001980 mutex_lock(&ifmgd->mtx);
1981
1982 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001983 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001984 switch (fc & IEEE80211_FCTL_STYPE) {
1985 case IEEE80211_STYPE_BEACON:
1986 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1987 rx_status);
1988 break;
1989 case IEEE80211_STYPE_PROBE_RESP:
Johannes Bergaf6b6372009-12-23 13:15:35 +01001990 ieee80211_rx_mgmt_probe_resp(sdata, skb);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001991 break;
1992 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01001993 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001994 break;
1995 case IEEE80211_STYPE_DISASSOC:
1996 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1997 break;
1998 case IEEE80211_STYPE_ACTION:
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001999 switch (mgmt->u.action.category) {
Johannes Berg8b9a4e62010-05-28 15:22:58 +02002000 case WLAN_CATEGORY_SPECTRUM_MGMT:
2001 ieee80211_sta_process_chanswitch(sdata,
2002 &mgmt->u.action.u.chan_switch.sw_elem,
2003 (void *)ifmgd->associated->priv,
2004 rx_status->mactime);
2005 break;
2006 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002007 }
2008 mutex_unlock(&ifmgd->mtx);
2009
2010 switch (rma) {
2011 case RX_MGMT_NONE:
2012 /* no action */
2013 break;
2014 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02002015 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002016 break;
2017 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470612009-10-13 13:28:13 +02002018 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002019 break;
2020 default:
2021 WARN(1, "unexpected: %d", rma);
2022 }
Johannes Berg36b3a622010-06-10 10:21:33 +02002023 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002024 }
2025
Johannes Berg77fdaa12009-07-07 03:45:17 +02002026 mutex_unlock(&ifmgd->mtx);
2027
Johannes Berg63f170e2009-12-23 13:15:33 +01002028 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
Johannes Bergb054b742010-06-07 21:50:07 +02002029 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
2030 struct ieee80211_local *local = sdata->local;
2031 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002032
Johannes Berga1699b72010-07-30 16:46:07 +02002033 mutex_lock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02002034 list_for_each_entry(wk, &local->work_list, list) {
2035 if (wk->sdata != sdata)
2036 continue;
2037
Johannes Berge5b900d2010-07-29 16:08:55 +02002038 if (wk->type != IEEE80211_WORK_ASSOC &&
2039 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Bergb054b742010-06-07 21:50:07 +02002040 continue;
2041
2042 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
2043 continue;
2044 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
2045 continue;
2046
2047 /*
2048 * Printing the message only here means we can't
2049 * spuriously print it, but it also means that it
2050 * won't be printed when the frame comes in before
2051 * we even tried to associate or in similar cases.
2052 *
2053 * Ultimately, I suspect cfg80211 should print the
2054 * messages instead.
2055 */
2056 printk(KERN_DEBUG
2057 "%s: deauthenticated from %pM (Reason: %u)\n",
2058 sdata->name, mgmt->bssid,
2059 le16_to_cpu(mgmt->u.deauth.reason_code));
2060
2061 list_del_rcu(&wk->list);
2062 free_work(wk);
2063 break;
2064 }
Johannes Berga1699b72010-07-30 16:46:07 +02002065 mutex_unlock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02002066
Johannes Berg77fdaa12009-07-07 03:45:17 +02002067 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Bergb054b742010-06-07 21:50:07 +02002068 }
Jiri Bencf0706e82007-05-05 11:45:53 -07002069}
2070
Johannes Berg9c6bd792008-09-11 00:01:52 +02002071static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07002072{
2073 struct ieee80211_sub_if_data *sdata =
2074 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01002075 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12002076 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07002077
Johannes Berg5bb644a2009-05-17 11:40:42 +02002078 if (local->quiescing) {
2079 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2080 return;
2081 }
2082
Johannes Berg64592c82010-06-10 10:21:31 +02002083 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07002084}
2085
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002086static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
Johannes Berg95acac62011-07-12 12:30:59 +02002087 u8 *bssid, u8 reason)
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002088{
2089 struct ieee80211_local *local = sdata->local;
2090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2091
2092 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
2093 IEEE80211_STA_BEACON_POLL);
2094
2095 ieee80211_set_disassoc(sdata, true, true);
2096 mutex_unlock(&ifmgd->mtx);
2097 mutex_lock(&local->mtx);
2098 ieee80211_recalc_idle(local);
2099 mutex_unlock(&local->mtx);
2100 /*
2101 * must be outside lock due to cfg80211,
2102 * but that's not a problem.
2103 */
2104 ieee80211_send_deauth_disassoc(sdata, bssid,
Johannes Berg95acac62011-07-12 12:30:59 +02002105 IEEE80211_STYPE_DEAUTH, reason,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002106 NULL, true);
2107 mutex_lock(&ifmgd->mtx);
2108}
2109
Johannes Berg1fa57d02010-06-10 10:21:32 +02002110void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02002111{
Johannes Berg60f8b392008-09-08 17:44:22 +02002112 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02002113 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02002114
Johannes Berg77fdaa12009-07-07 03:45:17 +02002115 /* then process the rest of the work */
2116 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002117
Johannes Bergb291ba12009-07-10 15:29:03 +02002118 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2119 IEEE80211_STA_CONNECTION_POLL) &&
2120 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002121 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002122 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03002123
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002124 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002125
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002126 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
Ben Greear180205b2011-02-04 15:30:24 -08002127 max_tries = max_nullfunc_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002128 else
Ben Greear180205b2011-02-04 15:30:24 -08002129 max_tries = max_probe_tries;
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01002130
Felix Fietkau4e5ff372010-11-23 03:10:31 +01002131 /* ACK received for nullfunc probing frame */
2132 if (!ifmgd->probe_send_count)
2133 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002134 else if (ifmgd->nullfunc_failed) {
2135 if (ifmgd->probe_send_count < max_tries) {
2136#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2137 wiphy_debug(local->hw.wiphy,
2138 "%s: No ack for nullfunc frame to"
Ben Greearbfc31df2011-01-14 09:32:18 -08002139 " AP %pM, try %d/%i\n",
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002140 sdata->name, bssid,
Ben Greearbfc31df2011-01-14 09:32:18 -08002141 ifmgd->probe_send_count, max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002142#endif
2143 ieee80211_mgd_probe_ap_send(sdata);
2144 } else {
2145#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2146 wiphy_debug(local->hw.wiphy,
2147 "%s: No ack for nullfunc frame to"
2148 " AP %pM, disconnecting.\n",
Felix Fietkauc658e5d2010-12-07 04:40:18 +01002149 sdata->name, bssid);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002150#endif
Johannes Berg95acac62011-07-12 12:30:59 +02002151 ieee80211_sta_connection_lost(sdata, bssid,
2152 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002153 }
2154 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002155 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002156 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2157#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2158 wiphy_debug(local->hw.wiphy,
2159 "%s: Failed to send nullfunc to AP %pM"
2160 " after %dms, disconnecting.\n",
2161 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002162 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002163#endif
Johannes Berg95acac62011-07-12 12:30:59 +02002164 ieee80211_sta_connection_lost(sdata, bssid,
2165 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002166 } else if (ifmgd->probe_send_count < max_tries) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002167#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Ben Greearb38afa82010-10-07 16:12:06 -07002168 wiphy_debug(local->hw.wiphy,
2169 "%s: No probe response from AP %pM"
Ben Greearbfc31df2011-01-14 09:32:18 -08002170 " after %dms, try %d/%i\n",
Ben Greearb38afa82010-10-07 16:12:06 -07002171 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002172 bssid, probe_wait_ms,
Ben Greearbfc31df2011-01-14 09:32:18 -08002173 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002174#endif
2175 ieee80211_mgd_probe_ap_send(sdata);
2176 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002177 /*
2178 * We actually lost the connection ... or did we?
2179 * Let's make sure!
2180 */
Ben Greearb38afa82010-10-07 16:12:06 -07002181 wiphy_debug(local->hw.wiphy,
2182 "%s: No probe response from AP %pM"
2183 " after %dms, disconnecting.\n",
2184 sdata->name,
Ben Greear180205b2011-02-04 15:30:24 -08002185 bssid, probe_wait_ms);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002186
Johannes Berg95acac62011-07-12 12:30:59 +02002187 ieee80211_sta_connection_lost(sdata, bssid,
2188 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
Johannes Bergb291ba12009-07-10 15:29:03 +02002189 }
2190 }
2191
Johannes Berg77fdaa12009-07-07 03:45:17 +02002192 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002193}
Johannes Berg0a51b272008-09-08 17:44:25 +02002194
Johannes Bergb291ba12009-07-10 15:29:03 +02002195static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2196{
2197 struct ieee80211_sub_if_data *sdata =
2198 (struct ieee80211_sub_if_data *) data;
2199 struct ieee80211_local *local = sdata->local;
2200
2201 if (local->quiescing)
2202 return;
2203
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002204 ieee80211_queue_work(&sdata->local->hw,
2205 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002206}
2207
2208static void ieee80211_sta_conn_mon_timer(unsigned long data)
2209{
2210 struct ieee80211_sub_if_data *sdata =
2211 (struct ieee80211_sub_if_data *) data;
2212 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2213 struct ieee80211_local *local = sdata->local;
2214
2215 if (local->quiescing)
2216 return;
2217
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002218 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002219}
2220
2221static void ieee80211_sta_monitor_work(struct work_struct *work)
2222{
2223 struct ieee80211_sub_if_data *sdata =
2224 container_of(work, struct ieee80211_sub_if_data,
2225 u.mgd.monitor_work);
2226
2227 ieee80211_mgd_probe_ap(sdata, false);
2228}
2229
Johannes Berga1678f82008-09-11 00:01:47 +02002230static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2231{
Kalle Vaload935682009-04-19 08:47:19 +03002232 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002233 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2234 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002235
Johannes Bergb291ba12009-07-10 15:29:03 +02002236 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002237 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02002238 &sdata->u.mgd.monitor_work);
2239 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02002240 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03002241 }
Johannes Berga1678f82008-09-11 00:01:47 +02002242}
2243
Johannes Berg5bb644a2009-05-17 11:40:42 +02002244#ifdef CONFIG_PM
2245void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2246{
2247 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2248
2249 /*
2250 * we need to use atomic bitops for the running bits
2251 * only because both timers might fire at the same
2252 * time -- the code here is properly synchronised.
2253 */
2254
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002255 cancel_work_sync(&ifmgd->request_smps_work);
2256
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002257 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002258 if (del_timer_sync(&ifmgd->timer))
2259 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2260
2261 cancel_work_sync(&ifmgd->chswitch_work);
2262 if (del_timer_sync(&ifmgd->chswitch_timer))
2263 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002264
2265 cancel_work_sync(&ifmgd->monitor_work);
2266 /* these will just be re-established on connection */
2267 del_timer_sync(&ifmgd->conn_mon_timer);
2268 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002269}
2270
2271void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2272{
2273 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2274
Rajkumar Manoharan676b58c2011-07-07 23:33:39 +05302275 if (!ifmgd->associated)
2276 return;
2277
Johannes Berg95acac62011-07-12 12:30:59 +02002278 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
2279 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
2280 mutex_lock(&ifmgd->mtx);
2281 if (ifmgd->associated) {
2282#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2283 wiphy_debug(sdata->local->hw.wiphy,
2284 "%s: driver requested disconnect after resume.\n",
2285 sdata->name);
2286#endif
2287 ieee80211_sta_connection_lost(sdata,
2288 ifmgd->associated->bssid,
2289 WLAN_REASON_UNSPECIFIED);
2290 mutex_unlock(&ifmgd->mtx);
2291 return;
2292 }
2293 mutex_unlock(&ifmgd->mtx);
2294 }
2295
Johannes Berg5bb644a2009-05-17 11:40:42 +02002296 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2297 add_timer(&ifmgd->timer);
2298 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2299 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01002300 ieee80211_sta_reset_beacon_monitor(sdata);
Felix Fietkau46090972010-11-23 20:28:03 +01002301 ieee80211_restart_sta_timer(sdata);
Paul Stewarta6af1d82011-06-10 07:00:19 -08002302 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.monitor_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002303}
2304#endif
2305
Johannes Berg9c6bd792008-09-11 00:01:52 +02002306/* interface setup */
2307void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2308{
Johannes Berg46900292009-02-15 12:44:28 +01002309 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002310
Johannes Berg46900292009-02-15 12:44:28 +01002311 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002312 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01002313 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002314 INIT_WORK(&ifmgd->beacon_connection_loss_work,
2315 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002316 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01002317 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002318 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002319 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2320 (unsigned long) sdata);
2321 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2322 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002323 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302324 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002325
Johannes Bergab1faea2009-07-01 21:41:17 +02002326 ifmgd->flags = 0;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002327
Johannes Berg77fdaa12009-07-07 03:45:17 +02002328 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01002329
2330 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2331 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2332 else
2333 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002334}
2335
2336/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002337void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2338{
2339 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002340
2341 /* Restart STA timers */
2342 rcu_read_lock();
2343 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2344 ieee80211_restart_sta_timer(sdata);
2345 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002346}
Johannes Berg10f644a2009-04-16 13:17:25 +02002347
2348int ieee80211_max_network_latency(struct notifier_block *nb,
2349 unsigned long data, void *dummy)
2350{
2351 s32 latency_usec = (s32) data;
2352 struct ieee80211_local *local =
2353 container_of(nb, struct ieee80211_local,
2354 network_latency_notifier);
2355
2356 mutex_lock(&local->iflist_mtx);
2357 ieee80211_recalc_ps(local, latency_usec);
2358 mutex_unlock(&local->iflist_mtx);
2359
2360 return 0;
2361}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002362
2363/* config hooks */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002364static enum work_done_result
2365ieee80211_probe_auth_done(struct ieee80211_work *wk,
2366 struct sk_buff *skb)
2367{
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002368 struct ieee80211_local *local = wk->sdata->local;
2369
Johannes Bergaf6b6372009-12-23 13:15:35 +01002370 if (!skb) {
2371 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002372 goto destroy;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002373 }
2374
2375 if (wk->type == IEEE80211_WORK_AUTH) {
2376 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002377 goto destroy;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002378 }
2379
2380 mutex_lock(&wk->sdata->u.mgd.mtx);
2381 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2382 mutex_unlock(&wk->sdata->u.mgd.mtx);
2383
2384 wk->type = IEEE80211_WORK_AUTH;
2385 wk->probe_auth.tries = 0;
2386 return WORK_DONE_REQUEUE;
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002387 destroy:
2388 if (wk->probe_auth.synced)
2389 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2390 IEEE80211_TX_SYNC_AUTH);
2391
2392 return WORK_DONE_DESTROY;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002393}
2394
Johannes Berg77fdaa12009-07-07 03:45:17 +02002395int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2396 struct cfg80211_auth_request *req)
2397{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002398 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002399 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002400 u16 auth_alg;
2401
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002402 if (req->local_state_change)
2403 return 0; /* no need to update mac80211 state */
2404
Johannes Berg77fdaa12009-07-07 03:45:17 +02002405 switch (req->auth_type) {
2406 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2407 auth_alg = WLAN_AUTH_OPEN;
2408 break;
2409 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg9dca9c42010-07-21 10:09:25 +02002410 if (IS_ERR(sdata->local->wep_tx_tfm))
2411 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002412 auth_alg = WLAN_AUTH_SHARED_KEY;
2413 break;
2414 case NL80211_AUTHTYPE_FT:
2415 auth_alg = WLAN_AUTH_FT;
2416 break;
2417 case NL80211_AUTHTYPE_NETWORK_EAP:
2418 auth_alg = WLAN_AUTH_LEAP;
2419 break;
2420 default:
2421 return -EOPNOTSUPP;
2422 }
2423
2424 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2425 if (!wk)
2426 return -ENOMEM;
2427
Joe Perches5e124bd2010-01-08 22:33:38 -08002428 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002429
2430 if (req->ie && req->ie_len) {
2431 memcpy(wk->ie, req->ie, req->ie_len);
2432 wk->ie_len = req->ie_len;
2433 }
2434
Johannes Bergfffd0932009-07-08 14:22:54 +02002435 if (req->key && req->key_len) {
Johannes Bergaf6b6372009-12-23 13:15:35 +01002436 wk->probe_auth.key_len = req->key_len;
2437 wk->probe_auth.key_idx = req->key_idx;
2438 memcpy(wk->probe_auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002439 }
2440
Johannes Berg77fdaa12009-07-07 03:45:17 +02002441 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002442 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2443 wk->probe_auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002444
Johannes Bergaf6b6372009-12-23 13:15:35 +01002445 wk->probe_auth.algorithm = auth_alg;
2446 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +01002447
Johannes Berg070bb542010-02-03 13:57:46 +01002448 /* if we already have a probe, don't probe again */
2449 if (req->bss->proberesp_ies)
2450 wk->type = IEEE80211_WORK_AUTH;
2451 else
2452 wk->type = IEEE80211_WORK_DIRECT_PROBE;
Johannes Bergf679f652009-12-23 13:15:34 +01002453 wk->chan = req->bss->channel;
Ben Greear4d51e142011-02-07 13:44:34 -08002454 wk->chan_type = NL80211_CHAN_NO_HT;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002455 wk->sdata = sdata;
2456 wk->done = ieee80211_probe_auth_done;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002457
Johannes Bergaf6b6372009-12-23 13:15:35 +01002458 ieee80211_add_work(wk);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002459 return 0;
2460}
2461
Guy Eilam2a33bee2011-08-17 15:18:15 +03002462/* create and insert a dummy station entry */
2463static int ieee80211_pre_assoc(struct ieee80211_sub_if_data *sdata,
2464 u8 *bssid) {
2465 struct sta_info *sta;
2466 int err;
2467
2468 sta = sta_info_alloc(sdata, bssid, GFP_KERNEL);
Joe Perchesd15b8452011-08-29 14:17:31 -07002469 if (!sta)
Guy Eilam2a33bee2011-08-17 15:18:15 +03002470 return -ENOMEM;
Guy Eilam2a33bee2011-08-17 15:18:15 +03002471
2472 sta->dummy = true;
2473
2474 err = sta_info_insert(sta);
2475 sta = NULL;
2476 if (err) {
2477 printk(KERN_DEBUG "%s: failed to insert Dummy STA entry for"
2478 " the AP (error %d)\n", sdata->name, err);
2479 return err;
2480 }
2481
2482 return 0;
2483}
2484
Johannes Bergaf6b6372009-12-23 13:15:35 +01002485static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2486 struct sk_buff *skb)
2487{
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002488 struct ieee80211_local *local = wk->sdata->local;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002489 struct ieee80211_mgmt *mgmt;
Johannes Berge5b900d2010-07-29 16:08:55 +02002490 struct ieee80211_rx_status *rx_status;
2491 struct ieee802_11_elems elems;
Guy Eilam2a33bee2011-08-17 15:18:15 +03002492 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002493 u16 status;
2494
2495 if (!skb) {
Guy Eilam2a33bee2011-08-17 15:18:15 +03002496 sta_info_destroy_addr(wk->sdata, cbss->bssid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002497 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002498 goto destroy;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002499 }
2500
Johannes Berge5b900d2010-07-29 16:08:55 +02002501 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2502 mutex_lock(&wk->sdata->u.mgd.mtx);
2503 rx_status = (void *) skb->cb;
2504 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2505 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2506 &elems, true);
2507 mutex_unlock(&wk->sdata->u.mgd.mtx);
2508
2509 wk->type = IEEE80211_WORK_ASSOC;
2510 /* not really done yet */
2511 return WORK_DONE_REQUEUE;
2512 }
2513
Johannes Bergaf6b6372009-12-23 13:15:35 +01002514 mgmt = (void *)skb->data;
2515 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2516
2517 if (status == WLAN_STATUS_SUCCESS) {
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002518 if (wk->assoc.synced)
2519 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2520 IEEE80211_TX_SYNC_ASSOC);
2521
Johannes Bergaf6b6372009-12-23 13:15:35 +01002522 mutex_lock(&wk->sdata->u.mgd.mtx);
2523 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2524 mutex_unlock(&wk->sdata->u.mgd.mtx);
2525 /* oops -- internal error -- send timeout for now */
Guy Eilam2a33bee2011-08-17 15:18:15 +03002526 sta_info_destroy_addr(wk->sdata, cbss->bssid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002527 cfg80211_send_assoc_timeout(wk->sdata->dev,
2528 wk->filter_ta);
2529 return WORK_DONE_DESTROY;
2530 }
Juuso Oikarinen68542962010-06-09 13:43:26 +03002531
2532 mutex_unlock(&wk->sdata->u.mgd.mtx);
Guy Eilam2a33bee2011-08-17 15:18:15 +03002533 } else {
2534 /* assoc failed - destroy the dummy station entry */
2535 sta_info_destroy_addr(wk->sdata, cbss->bssid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002536 }
2537
2538 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
Johannes Bergb2abb6e2011-07-19 10:39:53 +02002539 destroy:
2540 if (wk->assoc.synced)
2541 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
2542 IEEE80211_TX_SYNC_ASSOC);
2543
Johannes Bergaf6b6372009-12-23 13:15:35 +01002544 return WORK_DONE_DESTROY;
2545}
2546
Johannes Berg77fdaa12009-07-07 03:45:17 +02002547int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2548 struct cfg80211_assoc_request *req)
2549{
2550 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002551 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Bergf679f652009-12-23 13:15:34 +01002552 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002553 const u8 *ssid;
Guy Eilam2a33bee2011-08-17 15:18:15 +03002554 int i, err;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002555
2556 mutex_lock(&ifmgd->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002557 if (ifmgd->associated) {
Jouni Malinen9c87ba62010-02-28 12:13:46 +02002558 if (!req->prev_bssid ||
2559 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2560 ETH_ALEN)) {
2561 /*
2562 * We are already associated and the request was not a
2563 * reassociation request from the current BSS, so
2564 * reject it.
2565 */
2566 mutex_unlock(&ifmgd->mtx);
2567 return -EALREADY;
2568 }
2569
2570 /* Trying to reassociate - clear previous association state */
Johannes Berg53f73c02010-10-05 19:37:40 +02002571 ieee80211_set_disassoc(sdata, true, false);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002572 }
2573 mutex_unlock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002574
Johannes Berg63f170e2009-12-23 13:15:33 +01002575 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002576 if (!wk)
2577 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002578
Guy Eilam2a33bee2011-08-17 15:18:15 +03002579 /*
2580 * create a dummy station info entry in order
2581 * to start accepting incoming EAPOL packets from the station
2582 */
2583 err = ieee80211_pre_assoc(sdata, req->bss->bssid);
2584 if (err) {
2585 kfree(wk);
2586 return err;
2587 }
2588
Johannes Berg77fdaa12009-07-07 03:45:17 +02002589 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05302590 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002591
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002592 ifmgd->beacon_crc_valid = false;
2593
Johannes Berg77fdaa12009-07-07 03:45:17 +02002594 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2595 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2596 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2597 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2598 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2599
Johannes Berg77fdaa12009-07-07 03:45:17 +02002600
2601 if (req->ie && req->ie_len) {
2602 memcpy(wk->ie, req->ie, req->ie_len);
2603 wk->ie_len = req->ie_len;
2604 } else
2605 wk->ie_len = 0;
2606
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002607 wk->assoc.bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01002608
Johannes Bergaf6b6372009-12-23 13:15:35 +01002609 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +01002610
Johannes Bergaf6b6372009-12-23 13:15:35 +01002611 /* new association always uses requested smps mode */
2612 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2613 if (ifmgd->powersave)
2614 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2615 else
2616 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2617 } else
2618 ifmgd->ap_smps = ifmgd->req_smps;
2619
2620 wk->assoc.smps = ifmgd->ap_smps;
Johannes Berg77c81442009-12-23 13:15:37 +01002621 /*
2622 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2623 * We still associate in non-HT mode (11a/b/g) if any one of these
2624 * ciphers is configured as pairwise.
2625 * We can set this to true for non-11n hardware, that'll be checked
2626 * separately along with the peer capabilities.
2627 */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002628 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
Johannes Bergf679f652009-12-23 13:15:34 +01002629 wk->assoc.capability = req->bss->capability;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002630 wk->assoc.wmm_used = bss->wmm_used;
2631 wk->assoc.supp_rates = bss->supp_rates;
2632 wk->assoc.supp_rates_len = bss->supp_rates_len;
Johannes Bergf679f652009-12-23 13:15:34 +01002633 wk->assoc.ht_information_ie =
2634 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002635
Kalle Valoab133152010-01-12 10:42:31 +02002636 if (bss->wmm_used && bss->uapsd_supported &&
2637 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2638 wk->assoc.uapsd_used = true;
2639 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2640 } else {
2641 wk->assoc.uapsd_used = false;
2642 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2643 }
2644
Johannes Berg63f170e2009-12-23 13:15:33 +01002645 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002646 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2647 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002648
Johannes Berg77fdaa12009-07-07 03:45:17 +02002649 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002650 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002651
Johannes Bergf679f652009-12-23 13:15:34 +01002652 wk->chan = req->bss->channel;
Ben Greear4d51e142011-02-07 13:44:34 -08002653 wk->chan_type = NL80211_CHAN_NO_HT;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002654 wk->sdata = sdata;
2655 wk->done = ieee80211_assoc_done;
Johannes Berge5b900d2010-07-29 16:08:55 +02002656 if (!bss->dtim_period &&
2657 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2658 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2659 else
2660 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002661
2662 if (req->use_mfp) {
2663 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2664 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2665 } else {
2666 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2667 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2668 }
2669
2670 if (req->crypto.control_port)
2671 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2672 else
2673 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2674
Johannes Berga621fa42010-08-27 14:26:54 +03002675 sdata->control_port_protocol = req->crypto.control_port_ethertype;
2676 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2677
Johannes Bergaf6b6372009-12-23 13:15:35 +01002678 ieee80211_add_work(wk);
2679 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002680}
2681
2682int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002683 struct cfg80211_deauth_request *req,
2684 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002685{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002686 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002687 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002688 struct ieee80211_work *wk;
Jouni Malinen05e48e82010-06-14 11:55:56 -07002689 u8 bssid[ETH_ALEN];
2690 bool assoc_bss = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002691
Johannes Berg77fdaa12009-07-07 03:45:17 +02002692 mutex_lock(&ifmgd->mtx);
2693
Jouni Malinen05e48e82010-06-14 11:55:56 -07002694 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002695 if (ifmgd->associated == req->bss) {
Johannes Berg53f73c02010-10-05 19:37:40 +02002696 ieee80211_set_disassoc(sdata, false, true);
Johannes Berga58ce432009-11-19 12:45:42 +01002697 mutex_unlock(&ifmgd->mtx);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002698 assoc_bss = true;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002699 } else {
2700 bool not_auth_yet = false;
Johannes Berga58ce432009-11-19 12:45:42 +01002701
Johannes Bergaf6b6372009-12-23 13:15:35 +01002702 mutex_unlock(&ifmgd->mtx);
2703
Johannes Berga1699b72010-07-30 16:46:07 +02002704 mutex_lock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002705 list_for_each_entry(wk, &local->work_list, list) {
Johannes Berg29165e42010-02-06 15:20:13 +01002706 if (wk->sdata != sdata)
Johannes Bergaf6b6372009-12-23 13:15:35 +01002707 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002708
2709 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
Reinette Chatre79733a82010-05-04 16:04:49 -07002710 wk->type != IEEE80211_WORK_AUTH &&
Johannes Berge5b900d2010-07-29 16:08:55 +02002711 wk->type != IEEE80211_WORK_ASSOC &&
2712 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Berg29165e42010-02-06 15:20:13 +01002713 continue;
2714
Johannes Bergaf6b6372009-12-23 13:15:35 +01002715 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2716 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002717
2718 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2719 list_del_rcu(&wk->list);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002720 free_work(wk);
2721 break;
2722 }
Johannes Berga1699b72010-07-30 16:46:07 +02002723 mutex_unlock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002724
2725 /*
2726 * If somebody requests authentication and we haven't
2727 * sent out an auth frame yet there's no need to send
2728 * out a deauth frame either. If the state was PROBE,
2729 * then this is the case. If it's AUTH we have sent a
2730 * frame, and if it's IDLE we have completed the auth
2731 * process already.
2732 */
2733 if (not_auth_yet) {
2734 __cfg80211_auth_canceled(sdata->dev, bssid);
2735 return 0;
2736 }
2737 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002738
Johannes Berg0ff71612009-09-26 14:45:41 +02002739 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002740 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002741
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002742 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2743 req->reason_code, cookie,
2744 !req->local_state_change);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002745 if (assoc_bss)
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002746 sta_info_flush(sdata->local, sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002747
Johannes Berg7da7cc12010-08-05 17:02:38 +02002748 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002749 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002750 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002751
Johannes Berg77fdaa12009-07-07 03:45:17 +02002752 return 0;
2753}
2754
2755int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002756 struct cfg80211_disassoc_request *req,
2757 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002758{
2759 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07002760 u8 bssid[ETH_ALEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002761
Johannes Berg77fdaa12009-07-07 03:45:17 +02002762 mutex_lock(&ifmgd->mtx);
2763
Johannes Berg8d8b2612009-07-25 11:58:36 +02002764 /*
2765 * cfg80211 should catch this ... but it's racy since
2766 * we can receive a disassoc frame, process it, hand it
2767 * to cfg80211 while that's in a locked section already
2768 * trying to tell us that the user wants to disconnect.
2769 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002770 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002771 mutex_unlock(&ifmgd->mtx);
2772 return -ENOLINK;
2773 }
2774
Johannes Berg0ff71612009-09-26 14:45:41 +02002775 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002776 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002777
Jouni Malinene69e95d2010-03-29 23:29:31 -07002778 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg53f73c02010-10-05 19:37:40 +02002779 ieee80211_set_disassoc(sdata, false, true);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002780
2781 mutex_unlock(&ifmgd->mtx);
2782
2783 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +02002784 IEEE80211_STYPE_DISASSOC, req->reason_code,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002785 cookie, !req->local_state_change);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03002786 sta_info_flush(sdata->local, sdata);
Johannes Bergbc83b682009-11-29 12:19:06 +01002787
Johannes Berg7da7cc12010-08-05 17:02:38 +02002788 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002789 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002790 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002791
Johannes Berg77fdaa12009-07-07 03:45:17 +02002792 return 0;
2793}
Jouni Malinen026331c2010-02-15 12:53:10 +02002794
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002795void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2796 enum nl80211_cqm_rssi_threshold_event rssi_event,
2797 gfp_t gfp)
2798{
2799 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2800
Johannes Bergb5878a22010-04-07 16:48:40 +02002801 trace_api_cqm_rssi_notify(sdata, rssi_event);
2802
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002803 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2804}
2805EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
Eliad Peller1d34d102011-06-06 12:59:29 +03002806
2807unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
2808{
2809 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2810 return sdata->dev->operstate;
2811}
2812EXPORT_SYMBOL(ieee80211_get_operstate);