blob: 2d86a4d5e912bd506814d1e18a5058a5764f25ff [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * BSS client mode implementation
Jouni Malinen5394af42009-01-08 13:31:59 +02003 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
Jiri Bencf0706e82007-05-05 11:45:53 -07004 * Copyright 2004, Instant802 Networks, Inc.
5 * Copyright 2005, Devicescape Software, Inc.
6 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
7 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Geert Uytterhoeven5b323ed2007-05-08 18:40:27 -070014#include <linux/delay.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <linux/if_ether.h>
16#include <linux/skbuff.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <linux/if_arp.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070018#include <linux/etherdevice.h>
Johannes Bergd0709a62008-02-25 16:27:46 +010019#include <linux/rtnetlink.h>
Johannes Berg10f644a2009-04-16 13:17:25 +020020#include <linux/pm_qos_params.h>
Johannes Bergd91f36d2009-04-16 13:17:26 +020021#include <linux/crc32.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070023#include <net/mac80211.h>
Johannes Berg472dbc42008-09-11 00:01:49 +020024#include <asm/unaligned.h>
Johannes Berg60f8b392008-09-08 17:44:22 +020025
Jiri Bencf0706e82007-05-05 11:45:53 -070026#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020027#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040028#include "rate.h"
29#include "led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070030
Maxim Levitskya43abf22009-07-31 18:54:12 +030031#define IEEE80211_MAX_PROBE_TRIES 5
Johannes Bergb291ba12009-07-10 15:29:03 +020032
33/*
34 * beacon loss detection timeout
35 * XXX: should depend on beacon interval
36 */
37#define IEEE80211_BEACON_LOSS_TIME (2 * HZ)
38/*
39 * Time the connection can be idle before we probe
40 * it to see if we can still talk to the AP.
41 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030042#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020043/*
44 * Time we wait for a probe response after sending
45 * a probe request because of beacon loss or for
46 * checking the connection still works.
47 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030048#define IEEE80211_PROBE_WAIT (HZ / 2)
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Jouni Malinen17e4ec12010-03-29 23:28:30 -070050/*
51 * Weight given to the latest Beacon frame when calculating average signal
52 * strength for Beacon frames received in the current BSS. This must be
53 * between 1 and 15.
54 */
55#define IEEE80211_SIGNAL_AVE_WEIGHT 3
56
Jouni Malinen391a2002010-08-27 22:22:00 +030057/*
58 * How many Beacon frames need to have been used in average signal strength
59 * before starting to indicate signal change events.
60 */
61#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
62
Johannes Berg5bb644a2009-05-17 11:40:42 +020063#define TMR_RUNNING_TIMER 0
64#define TMR_RUNNING_CHANSW 1
65
Johannes Berg77fdaa12009-07-07 03:45:17 +020066/*
67 * All cfg80211 functions have to be called outside a locked
68 * section so that they can acquire a lock themselves... This
69 * is much simpler than queuing up things in cfg80211, but we
70 * do need some indirection for that here.
71 */
72enum rx_mgmt_action {
73 /* no action required */
74 RX_MGMT_NONE,
75
76 /* caller must call cfg80211_send_rx_auth() */
77 RX_MGMT_CFG80211_AUTH,
78
79 /* caller must call cfg80211_send_rx_assoc() */
80 RX_MGMT_CFG80211_ASSOC,
81
82 /* caller must call cfg80211_send_deauth() */
83 RX_MGMT_CFG80211_DEAUTH,
84
85 /* caller must call cfg80211_send_disassoc() */
86 RX_MGMT_CFG80211_DISASSOC,
87
Johannes Berg5d1ec852009-12-02 12:43:43 +010088 /* caller must tell cfg80211 about internal error */
89 RX_MGMT_CFG80211_ASSOC_ERROR,
Johannes Berg77fdaa12009-07-07 03:45:17 +020090};
91
Johannes Berg5484e232008-09-08 17:44:27 +020092/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +020093static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
94{
Johannes Berg46a5eba2010-09-15 13:28:15 +020095 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +020096}
97
Johannes Bergca386f32009-07-10 02:39:48 +020098/*
99 * We can have multiple work items (and connection probing)
100 * scheduling this timer, but we need to take care to only
101 * reschedule it when it should fire _earlier_ than it was
102 * asked for before, or if it's not pending right now. This
103 * function ensures that. Note that it then is required to
104 * run this function for all timeouts after the first one
105 * has happened -- the work that runs from this timer will
106 * do that.
107 */
108static void run_again(struct ieee80211_if_managed *ifmgd,
109 unsigned long timeout)
110{
111 ASSERT_MGD_MTX(ifmgd);
112
113 if (!timer_pending(&ifmgd->timer) ||
114 time_before(timeout, ifmgd->timer.expires))
115 mod_timer(&ifmgd->timer, timeout);
116}
117
Johannes Bergb291ba12009-07-10 15:29:03 +0200118static void mod_beacon_timer(struct ieee80211_sub_if_data *sdata)
119{
120 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
121 return;
122
123 mod_timer(&sdata->u.mgd.bcn_mon_timer,
124 round_jiffies_up(jiffies + IEEE80211_BEACON_LOSS_TIME));
125}
126
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400127void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
128{
129 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
130 return;
131
132 mod_timer(&sdata->u.mgd.conn_mon_timer,
133 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
134}
135
Johannes Berg5484e232008-09-08 17:44:27 +0200136static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200137{
Johannes Berg5484e232008-09-08 17:44:27 +0200138 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200139}
140
Johannes Bergd5522e02009-03-30 13:23:35 +0200141/*
142 * ieee80211_enable_ht should be called only after the operating band
143 * has been determined as ht configuration depends on the hw's
144 * HT abilities for a specific band.
145 */
146static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
147 struct ieee80211_ht_info *hti,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200148 const u8 *bssid, u16 ap_ht_cap_flags)
Johannes Bergd5522e02009-03-30 13:23:35 +0200149{
150 struct ieee80211_local *local = sdata->local;
151 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200152 struct sta_info *sta;
153 u32 changed = 0;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200154 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200155 bool enable_ht = true;
156 enum nl80211_channel_type prev_chantype;
Johannes Bergd5522e02009-03-30 13:23:35 +0200157 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
158
159 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
160
Johannes Berg0aaffa92010-05-05 15:28:27 +0200161 prev_chantype = sdata->vif.bss_conf.channel_type;
162
Johannes Bergd5522e02009-03-30 13:23:35 +0200163 /* HT is not supported */
164 if (!sband->ht_cap.ht_supported)
165 enable_ht = false;
166
167 /* check that channel matches the right operating channel */
168 if (local->hw.conf.channel->center_freq !=
169 ieee80211_channel_to_frequency(hti->control_chan))
170 enable_ht = false;
171
172 if (enable_ht) {
173 channel_type = NL80211_CHAN_HT20;
174
175 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
176 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
177 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
178 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
179 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400180 if (!(local->hw.conf.channel->flags &
181 IEEE80211_CHAN_NO_HT40PLUS))
182 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200183 break;
184 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400185 if (!(local->hw.conf.channel->flags &
186 IEEE80211_CHAN_NO_HT40MINUS))
187 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200188 break;
189 }
190 }
191 }
192
Reinette Chatrefe6f2122010-04-19 10:46:31 -0700193 if (local->tmp_channel)
194 local->tmp_channel_type = channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200195
Johannes Berg0aaffa92010-05-05 15:28:27 +0200196 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
197 /* can only fail due to HT40+/- mismatch */
198 channel_type = NL80211_CHAN_HT20;
199 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
200 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200201
Johannes Berg0aaffa92010-05-05 15:28:27 +0200202 /* channel_type change automatically detected */
203 ieee80211_hw_config(local, 0);
204
205 if (prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200206 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100207 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200208 if (sta)
209 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530210 IEEE80211_RC_HT_CHANGED,
Johannes Berg0aaffa92010-05-05 15:28:27 +0200211 channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200212 rcu_read_unlock();
Johannes Berg0aaffa92010-05-05 15:28:27 +0200213 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200214
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200215 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200216
217 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200218 if (sdata->ht_opmode_valid != enable_ht ||
219 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
220 prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200221 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200222 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200223 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200224 }
225
226 return changed;
227}
228
Johannes Berg9c6bd792008-09-11 00:01:52 +0200229/* frame sending functions */
230
Johannes Bergef422bc2008-09-09 10:58:25 +0200231static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +0200232 const u8 *bssid, u16 stype, u16 reason,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300233 void *cookie, bool send_frame)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200234{
235 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100236 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200237 struct sk_buff *skb;
238 struct ieee80211_mgmt *mgmt;
239
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200240 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200241 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200242 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100243 "deauth/disassoc frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200244 return;
245 }
246 skb_reserve(skb, local->hw.extra_tx_headroom);
247
248 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
249 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200250 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100251 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200252 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200253 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200254 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200255 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200256 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
257
Jouni Malinen53b46b82009-03-27 20:53:56 +0200258 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470612009-10-13 13:28:13 +0200259 if (cookie)
260 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
261 else
262 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200263 else
Holger Schurigce470612009-10-13 13:28:13 +0200264 if (cookie)
265 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
266 else
267 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100268 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
269 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300270
271 if (send_frame)
272 ieee80211_tx_skb(sdata, skb);
273 else
274 kfree_skb(skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200275}
276
Kalle Valo572e0012009-02-10 17:09:31 +0200277void ieee80211_send_pspoll(struct ieee80211_local *local,
278 struct ieee80211_sub_if_data *sdata)
279{
Kalle Valo572e0012009-02-10 17:09:31 +0200280 struct ieee80211_pspoll *pspoll;
281 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200282
Kalle Valod8cd1892010-01-05 20:16:26 +0200283 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
284 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200285 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200286
Kalle Valod8cd1892010-01-05 20:16:26 +0200287 pspoll = (struct ieee80211_pspoll *) skb->data;
288 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200289
Johannes Berg62ae67b2009-11-18 18:42:05 +0100290 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
291 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200292}
293
Johannes Berg965beda2009-04-16 13:17:24 +0200294void ieee80211_send_nullfunc(struct ieee80211_local *local,
295 struct ieee80211_sub_if_data *sdata,
296 int powersave)
297{
298 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200299 struct ieee80211_hdr_3addr *nullfunc;
Johannes Berg965beda2009-04-16 13:17:24 +0200300
Kalle Valod8cd1892010-01-05 20:16:26 +0200301 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
302 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200303 return;
304
Kalle Valod8cd1892010-01-05 20:16:26 +0200305 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200306 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200307 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200308
Johannes Berg62ae67b2009-11-18 18:42:05 +0100309 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
310 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200311}
312
Felix Fietkaud5242152010-01-08 18:06:26 +0100313static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
314 struct ieee80211_sub_if_data *sdata)
315{
316 struct sk_buff *skb;
317 struct ieee80211_hdr *nullfunc;
318 __le16 fc;
319
320 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
321 return;
322
323 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
324 if (!skb) {
325 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
326 "nullfunc frame\n", sdata->name);
327 return;
328 }
329 skb_reserve(skb, local->hw.extra_tx_headroom);
330
331 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
332 memset(nullfunc, 0, 30);
333 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
334 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
335 nullfunc->frame_control = fc;
336 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
337 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
338 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
339 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
340
341 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
342 ieee80211_tx_skb(sdata, skb);
343}
344
Johannes Bergcc32abd2009-05-15 11:52:31 +0200345/* spectrum management related things */
346static void ieee80211_chswitch_work(struct work_struct *work)
347{
348 struct ieee80211_sub_if_data *sdata =
349 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200350 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
351
Johannes Berg9607e6b2009-12-23 13:15:31 +0100352 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200353 return;
354
Johannes Berg77fdaa12009-07-07 03:45:17 +0200355 mutex_lock(&ifmgd->mtx);
356 if (!ifmgd->associated)
357 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200358
359 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200360 if (!sdata->local->ops->channel_switch) {
361 /* call "hw_config" only if doing sw channel switch */
362 ieee80211_hw_config(sdata->local,
363 IEEE80211_CONF_CHANGE_CHANNEL);
364 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200365
Johannes Berg77fdaa12009-07-07 03:45:17 +0200366 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100367 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200368
Johannes Bergcc32abd2009-05-15 11:52:31 +0200369 ieee80211_wake_queues_by_reason(&sdata->local->hw,
370 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200371 out:
372 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
373 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200374}
375
Johannes Berg5ce6e432010-05-11 16:20:57 +0200376void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
377{
378 struct ieee80211_sub_if_data *sdata;
379 struct ieee80211_if_managed *ifmgd;
380
381 sdata = vif_to_sdata(vif);
382 ifmgd = &sdata->u.mgd;
383
384 trace_api_chswitch_done(sdata, success);
385 if (!success) {
386 /*
387 * If the channel switch was not successful, stay
388 * around on the old channel. We currently lack
389 * good handling of this situation, possibly we
390 * should just drop the association.
391 */
392 sdata->local->csa_channel = sdata->local->oper_channel;
393 }
394
395 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
396}
397EXPORT_SYMBOL(ieee80211_chswitch_done);
398
Johannes Bergcc32abd2009-05-15 11:52:31 +0200399static void ieee80211_chswitch_timer(unsigned long data)
400{
401 struct ieee80211_sub_if_data *sdata =
402 (struct ieee80211_sub_if_data *) data;
403 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
404
Johannes Berg5bb644a2009-05-17 11:40:42 +0200405 if (sdata->local->quiescing) {
406 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
407 return;
408 }
409
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400410 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200411}
412
413void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
414 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200415 struct ieee80211_bss *bss,
416 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200417{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100418 struct cfg80211_bss *cbss =
419 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200420 struct ieee80211_channel *new_ch;
421 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
422 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
423
Johannes Berg77fdaa12009-07-07 03:45:17 +0200424 ASSERT_MGD_MTX(ifmgd);
425
426 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200427 return;
428
Helmut Schaafbe9c422009-07-23 12:14:04 +0200429 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200430 return;
431
432 /* Disregard subsequent beacons if we are already running a timer
433 processing a CSA */
434
435 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
436 return;
437
438 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
439 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
440 return;
441
442 sdata->local->csa_channel = new_ch;
443
Johannes Berg5ce6e432010-05-11 16:20:57 +0200444 if (sdata->local->ops->channel_switch) {
445 /* use driver's channel switch callback */
446 struct ieee80211_channel_switch ch_switch;
447 memset(&ch_switch, 0, sizeof(ch_switch));
448 ch_switch.timestamp = timestamp;
449 if (sw_elem->mode) {
450 ch_switch.block_tx = true;
451 ieee80211_stop_queues_by_reason(&sdata->local->hw,
452 IEEE80211_QUEUE_STOP_REASON_CSA);
453 }
454 ch_switch.channel = new_ch;
455 ch_switch.count = sw_elem->count;
456 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
457 drv_channel_switch(sdata->local, &ch_switch);
458 return;
459 }
460
461 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200462 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400463 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200464 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700465 if (sw_elem->mode)
466 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200467 IEEE80211_QUEUE_STOP_REASON_CSA);
468 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
469 mod_timer(&ifmgd->chswitch_timer,
470 jiffies +
471 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100472 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200473 }
474}
475
476static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
477 u16 capab_info, u8 *pwr_constr_elem,
478 u8 pwr_constr_elem_len)
479{
480 struct ieee80211_conf *conf = &sdata->local->hw.conf;
481
482 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
483 return;
484
485 /* Power constraint IE length should be 1 octet */
486 if (pwr_constr_elem_len != 1)
487 return;
488
489 if ((*pwr_constr_elem <= conf->channel->max_power) &&
490 (*pwr_constr_elem != sdata->local->power_constr_level)) {
491 sdata->local->power_constr_level = *pwr_constr_elem;
492 ieee80211_hw_config(sdata->local, 0);
493 }
494}
495
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300496void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
497{
498 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
499 struct ieee80211_local *local = sdata->local;
500 struct ieee80211_conf *conf = &local->hw.conf;
501
502 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
503 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
504 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
505
506 local->disable_dynamic_ps = false;
507 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
508}
509EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
510
511void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
512{
513 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
514 struct ieee80211_local *local = sdata->local;
515 struct ieee80211_conf *conf = &local->hw.conf;
516
517 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
518 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
519 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
520
521 local->disable_dynamic_ps = true;
522 conf->dynamic_ps_timeout = 0;
523 del_timer_sync(&local->dynamic_ps_timer);
524 ieee80211_queue_work(&local->hw,
525 &local->dynamic_ps_enable_work);
526}
527EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
528
Johannes Berg965beda2009-04-16 13:17:24 +0200529/* powersave */
530static void ieee80211_enable_ps(struct ieee80211_local *local,
531 struct ieee80211_sub_if_data *sdata)
532{
533 struct ieee80211_conf *conf = &local->hw.conf;
534
Johannes Bergd5edaed2009-04-22 23:02:51 +0200535 /*
536 * If we are scanning right now then the parameters will
537 * take effect when scan finishes.
538 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200539 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200540 return;
541
Johannes Berg965beda2009-04-16 13:17:24 +0200542 if (conf->dynamic_ps_timeout > 0 &&
543 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
544 mod_timer(&local->dynamic_ps_timer, jiffies +
545 msecs_to_jiffies(conf->dynamic_ps_timeout));
546 } else {
547 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
548 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530549
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200550 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
551 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
552 return;
553
554 conf->flags |= IEEE80211_CONF_PS;
555 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200556 }
557}
558
559static void ieee80211_change_ps(struct ieee80211_local *local)
560{
561 struct ieee80211_conf *conf = &local->hw.conf;
562
563 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200564 ieee80211_enable_ps(local, local->ps_sdata);
565 } else if (conf->flags & IEEE80211_CONF_PS) {
566 conf->flags &= ~IEEE80211_CONF_PS;
567 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
568 del_timer_sync(&local->dynamic_ps_timer);
569 cancel_work_sync(&local->dynamic_ps_enable_work);
570 }
571}
572
573/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200574void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200575{
576 struct ieee80211_sub_if_data *sdata, *found = NULL;
577 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300578 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +0200579
580 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
581 local->ps_sdata = NULL;
582 return;
583 }
584
Johannes Bergaf6b6372009-12-23 13:15:35 +0100585 if (!list_empty(&local->work_list)) {
586 local->ps_sdata = NULL;
587 goto change;
588 }
589
Johannes Berg965beda2009-04-16 13:17:24 +0200590 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100591 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200592 continue;
593 if (sdata->vif.type != NL80211_IFTYPE_STATION)
594 continue;
595 found = sdata;
596 count++;
597 }
598
Luis R. Rodriguez43f78532009-06-10 15:16:15 +0200599 if (count == 1 && found->u.mgd.powersave &&
Johannes Bergaf6b6372009-12-23 13:15:35 +0100600 found->u.mgd.associated &&
Johannes Berg56007a02010-01-26 14:19:52 +0100601 found->u.mgd.associated->beacon_ies &&
Johannes Bergb291ba12009-07-10 15:29:03 +0200602 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
603 IEEE80211_STA_CONNECTION_POLL))) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300604 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +0200605 s32 beaconint_us;
606
607 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +0200608 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +0200609
610 beaconint_us = ieee80211_tu_to_usec(
611 found->vif.bss_conf.beacon_int);
612
Juuso Oikarinenff616382010-06-09 09:51:52 +0300613 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300614 if (timeout < 0) {
615 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +0300616 * Go to full PSM if the user configures a very low
617 * latency requirement.
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300618 * The 2 second value is there for compatibility until
619 * the PM_QOS_NETWORK_LATENCY is configured with real
620 * values.
621 */
Juuso Oikarinenff616382010-06-09 09:51:52 +0300622 if (latency > 1900000000 && latency != 2000000000)
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300623 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +0300624 else
625 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300626 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300627 local->dynamic_ps_user_timeout = timeout;
628 if (!local->disable_dynamic_ps)
629 conf->dynamic_ps_timeout =
630 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300631
Johannes Berg04fe2032009-04-22 18:44:37 +0200632 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200633 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200634 } else {
Johannes Berg56007a02010-01-26 14:19:52 +0100635 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +0200636 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +0100637 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +0200638
Johannes Berg56007a02010-01-26 14:19:52 +0100639 bss = (void *)found->u.mgd.associated->priv;
640 dtimper = bss->dtim_period;
641
642 /* If the TIM IE is invalid, pretend the value is 1 */
643 if (!dtimper)
644 dtimper = 1;
645 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +0200646 maxslp = min_t(int, dtimper,
647 latency / beaconint_us);
648
Johannes Berg9ccebe62009-04-23 10:32:36 +0200649 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +0100650 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +0200651 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200652 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200653 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200654 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200655 }
Johannes Berg965beda2009-04-16 13:17:24 +0200656
Johannes Bergaf6b6372009-12-23 13:15:35 +0100657 change:
Johannes Berg965beda2009-04-16 13:17:24 +0200658 ieee80211_change_ps(local);
659}
660
661void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
662{
663 struct ieee80211_local *local =
664 container_of(work, struct ieee80211_local,
665 dynamic_ps_disable_work);
666
667 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
668 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
669 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
670 }
671
672 ieee80211_wake_queues_by_reason(&local->hw,
673 IEEE80211_QUEUE_STOP_REASON_PS);
674}
675
676void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
677{
678 struct ieee80211_local *local =
679 container_of(work, struct ieee80211_local,
680 dynamic_ps_enable_work);
681 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Vivek Natarajan375177b2010-02-09 14:50:28 +0530682 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200683
684 /* can only happen when PS was just disabled anyway */
685 if (!sdata)
686 return;
687
688 if (local->hw.conf.flags & IEEE80211_CONF_PS)
689 return;
690
Vivek Natarajan375177b2010-02-09 14:50:28 +0530691 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
692 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
Johannes Berg965beda2009-04-16 13:17:24 +0200693 ieee80211_send_nullfunc(local, sdata, 1);
694
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200695 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
696 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +0530697 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
698 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
699 local->hw.conf.flags |= IEEE80211_CONF_PS;
700 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
701 }
Johannes Berg965beda2009-04-16 13:17:24 +0200702}
703
704void ieee80211_dynamic_ps_timer(unsigned long data)
705{
706 struct ieee80211_local *local = (void *) data;
707
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700708 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200709 return;
710
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400711 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200712}
713
Johannes Berg60f8b392008-09-08 17:44:22 +0200714/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200715static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +0200716 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700717 u8 *wmm_param, size_t wmm_param_len)
718{
Jiri Bencf0706e82007-05-05 11:45:53 -0700719 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +0200720 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -0700721 size_t left;
722 int count;
Kalle Valoab133152010-01-12 10:42:31 +0200723 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700724
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200725 if (!local->ops->conf_tx)
726 return;
727
Johannes Bergaf6b6372009-12-23 13:15:35 +0100728 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +0200729 return;
730
731 if (!wmm_param)
732 return;
733
Jiri Bencf0706e82007-05-05 11:45:53 -0700734 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
735 return;
Kalle Valoab133152010-01-12 10:42:31 +0200736
737 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200738 uapsd_queues = local->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +0200739
Jiri Bencf0706e82007-05-05 11:45:53 -0700740 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100741 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700742 return;
Johannes Berg46900292009-02-15 12:44:28 +0100743 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700744
745 pos = wmm_param + 8;
746 left = wmm_param_len - 8;
747
748 memset(&params, 0, sizeof(params));
749
Jiri Bencf0706e82007-05-05 11:45:53 -0700750 local->wmm_acm = 0;
751 for (; left >= 4; left -= 4, pos += 4) {
752 int aci = (pos[0] >> 5) & 0x03;
753 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +0200754 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700755 int queue;
756
757 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200758 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200759 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200760 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200761 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +0200762 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
763 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700764 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200765 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200766 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200767 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200768 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +0200769 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
770 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700771 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200772 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200773 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200774 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200775 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +0200776 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
777 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700778 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200779 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700780 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200781 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200782 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200783 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +0200784 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
785 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700786 break;
787 }
788
789 params.aifs = pos[0] & 0x0f;
790 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
791 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200792 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +0200793 params.uapsd = uapsd;
794
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200795#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700796 wiphy_debug(local->hw.wiphy,
797 "WMM queue=%d aci=%d acm=%d aifs=%d "
798 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
799 queue, aci, acm,
800 params.aifs, params.cw_min, params.cw_max,
801 params.txop, params.uapsd);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100802#endif
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200803 if (drv_conf_tx(local, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700804 wiphy_debug(local->hw.wiphy,
805 "failed to set TX queue parameters for queue %d\n",
806 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700807 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200808
809 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +0200810 sdata->vif.bss_conf.qos = true;
811 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700812}
813
Johannes Berg7a5158e2008-10-08 10:59:33 +0200814static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
815 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200816{
Johannes Bergbda39332008-10-11 01:51:51 +0200817 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100818 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200819 bool use_protection;
820 bool use_short_preamble;
821 bool use_short_slot;
822
823 if (erp_valid) {
824 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
825 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
826 } else {
827 use_protection = false;
828 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
829 }
830
831 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +0100832 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
833 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +0200834
Johannes Berg471b3ef2007-12-28 14:32:58 +0100835 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100836 bss_conf->use_cts_prot = use_protection;
837 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200838 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200839
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200840 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200841 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100842 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200843 }
Daniel Draked9430a32007-07-27 15:43:24 +0200844
Johannes Berg7a5158e2008-10-08 10:59:33 +0200845 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200846 bss_conf->use_short_slot = use_short_slot;
847 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400848 }
849
850 return changed;
851}
852
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200853static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100854 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200855 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700856{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100857 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100858 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +0300859 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400860
Johannes Bergae5eb022008-10-14 16:58:37 +0200861 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200862 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +0300863 bss_conf->beacon_int = cbss->beacon_interval;
864 bss_conf->timestamp = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400865
Johannes Berg77fdaa12009-07-07 03:45:17 +0200866 bss_info_changed |= BSS_CHANGED_BEACON_INT;
867 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100868 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700869
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100870 sdata->u.mgd.associated = cbss;
871 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100872
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700873 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
874
Johannes Bergb291ba12009-07-10 15:29:03 +0200875 /* just to be sure */
876 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
877 IEEE80211_STA_BEACON_POLL);
878
Johannes Berg01838262009-12-17 16:16:53 +0100879 /*
880 * Always handle WMM once after association regardless
881 * of the first value the AP uses. Setting -1 here has
882 * that effect because the AP values is an unsigned
883 * 4-bit value.
884 */
885 sdata->u.mgd.wmm_last_param_set = -1;
886
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200887 ieee80211_led_assoc(local, 1);
888
Johannes Berge5b900d2010-07-29 16:08:55 +0200889 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
890 bss_conf->dtim_period = bss->dtim_period;
891 else
892 bss_conf->dtim_period = 0;
893
Juuso Oikarinen68542962010-06-09 13:43:26 +0300894 bss_conf->assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200895 /*
896 * For now just always ask the driver to update the basic rateset
897 * when we have associated, we aren't checking whether it actually
898 * changed or not.
899 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200900 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +0200901
902 /* And the BSSID changed - we're associated now */
903 bss_info_changed |= BSS_CHANGED_BSSID;
904
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200905 /* Tell the driver to monitor connection quality (if supported) */
906 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
Juuso Oikarinen68542962010-06-09 13:43:26 +0300907 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200908 bss_info_changed |= BSS_CHANGED_CQM;
909
Juuso Oikarinen68542962010-06-09 13:43:26 +0300910 /* Enable ARP filtering */
911 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
912 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
913 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
914 }
915
Johannes Bergae5eb022008-10-14 16:58:37 +0200916 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300917
Johannes Berg056508d2009-07-30 21:43:55 +0200918 mutex_lock(&local->iflist_mtx);
919 ieee80211_recalc_ps(local, -1);
Johannes Berg0f782312009-12-01 13:37:02 +0100920 ieee80211_recalc_smps(local, sdata);
Johannes Berg056508d2009-07-30 21:43:55 +0200921 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +0200922
John W. Linville8a5b33f2010-01-06 15:39:39 -0500923 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200924 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700925}
926
Jouni Malinene69e95d2010-03-29 23:29:31 -0700927static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
928 bool remove_sta)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300929{
Johannes Berg46900292009-02-15 12:44:28 +0100930 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300931 struct ieee80211_local *local = sdata->local;
932 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200933 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +0200934 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +0300935
Johannes Berg77fdaa12009-07-07 03:45:17 +0200936 ASSERT_MGD_MTX(ifmgd);
937
Johannes Bergb291ba12009-07-10 15:29:03 +0200938 if (WARN_ON(!ifmgd->associated))
939 return;
940
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100941 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +0200942
Johannes Berg77fdaa12009-07-07 03:45:17 +0200943 ifmgd->associated = NULL;
944 memset(ifmgd->bssid, 0, ETH_ALEN);
945
946 /*
947 * we need to commit the associated = NULL change because the
948 * scan code uses that to determine whether this iface should
949 * go to/wake up from powersave or not -- and could otherwise
950 * wake the queues erroneously.
951 */
952 smp_mb();
953
954 /*
955 * Thus, we can only afterwards stop the queues -- to account
956 * for the case where another CPU is finishing a scan at this
957 * time -- we don't want the scan code to enable queues.
958 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300959
John W. Linville8a5b33f2010-01-06 15:39:39 -0500960 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300961 netif_carrier_off(sdata->dev);
962
Johannes Berg2a419052010-06-10 10:21:29 +0200963 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +0100964 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +0530965 if (sta) {
Johannes Berg2a419052010-06-10 10:21:29 +0200966 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
Johannes Berg1fa6f4a2009-06-15 18:13:58 +0200967 ieee80211_sta_tear_down_BA_sessions(sta);
Sujith4cad6c72010-02-10 14:52:21 +0530968 }
Johannes Berg2a419052010-06-10 10:21:29 +0200969 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300970
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200971 changed |= ieee80211_reset_erp_info(sdata);
972
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200973 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +0200974 changed |= BSS_CHANGED_ASSOC;
975 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200976
Johannes Bergaa837e12009-05-07 16:16:24 +0200977 ieee80211_set_wmm_default(sdata);
978
Johannes Berg47979382009-01-07 10:13:27 +0100979 /* channel(_type) changes are handled by ieee80211_hw_config */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200980 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
Johannes Bergae5eb022008-10-14 16:58:37 +0200981
Johannes Berg413ad502009-05-08 21:21:06 +0200982 /* on the next assoc, re-program HT parameters */
983 sdata->ht_opmode_valid = false;
984
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +0530985 local->power_constr_level = 0;
986
Kalle Valo520eb822008-12-18 23:35:27 +0200987 del_timer_sync(&local->dynamic_ps_timer);
988 cancel_work_sync(&local->dynamic_ps_enable_work);
989
Kalle Valoe0cb6862008-12-18 23:35:13 +0200990 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
991 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
992 config_changed |= IEEE80211_CONF_CHANGE_PS;
993 }
994
995 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +0200996
Juuso Oikarinen68542962010-06-09 13:43:26 +0300997 /* Disable ARP filtering */
998 if (sdata->vif.bss_conf.arp_filter_enabled) {
999 sdata->vif.bss_conf.arp_filter_enabled = false;
1000 changed |= BSS_CHANGED_ARP_FILTER;
1001 }
1002
Johannes Berg0aaffa92010-05-05 15:28:27 +02001003 /* The BSSID (not really interesting) and HT changed */
1004 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001005 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001006
Jouni Malinene69e95d2010-03-29 23:29:31 -07001007 if (remove_sta)
1008 sta_info_destroy_addr(sdata, bssid);
Johannes Bergb9dcf712010-08-27 12:35:54 +02001009
1010 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1011 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1012 del_timer_sync(&sdata->u.mgd.timer);
1013 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001014}
Jiri Bencf0706e82007-05-05 11:45:53 -07001015
Kalle Valo3cf335d2009-03-22 21:57:06 +02001016void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1017 struct ieee80211_hdr *hdr)
1018{
1019 /*
1020 * We can postpone the mgd.timer whenever receiving unicast frames
1021 * from AP because we know that the connection is working both ways
1022 * at that time. But multicast frames (and hence also beacons) must
1023 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001024 * data idle periods for sending the periodic probe request to the
1025 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001026 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001027 if (is_multicast_ether_addr(hdr->addr1))
1028 return;
1029
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001030 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001031}
Jiri Bencf0706e82007-05-05 11:45:53 -07001032
Maxim Levitskya43abf22009-07-31 18:54:12 +03001033static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1034{
1035 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1036 const u8 *ssid;
1037
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001038 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1039 ieee80211_send_probe_req(sdata, ifmgd->associated->bssid,
Maxim Levitskya43abf22009-07-31 18:54:12 +03001040 ssid + 2, ssid[1], NULL, 0);
1041
1042 ifmgd->probe_send_count++;
1043 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1044 run_again(ifmgd, ifmgd->probe_timeout);
1045}
1046
Johannes Bergb291ba12009-07-10 15:29:03 +02001047static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1048 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001049{
Kalle Valo04de8382009-03-22 21:57:35 +02001050 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001051 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001052
Johannes Berg9607e6b2009-12-23 13:15:31 +01001053 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001054 return;
1055
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001056 if (sdata->local->scanning)
1057 return;
1058
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001059 if (sdata->local->tmp_channel)
1060 return;
1061
Johannes Berg77fdaa12009-07-07 03:45:17 +02001062 mutex_lock(&ifmgd->mtx);
1063
1064 if (!ifmgd->associated)
1065 goto out;
1066
Michael Buescha8604022009-04-15 14:41:22 -04001067#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001068 if (beacon && net_ratelimit())
1069 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001070 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001071#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001072
Johannes Bergb291ba12009-07-10 15:29:03 +02001073 /*
1074 * The driver/our work has already reported this event or the
1075 * connection monitoring has kicked in and we have already sent
1076 * a probe request. Or maybe the AP died and the driver keeps
1077 * reporting until we disassociate...
1078 *
1079 * In either case we have to ignore the current call to this
1080 * function (except for setting the correct probe reason bit)
1081 * because otherwise we would reset the timer every time and
1082 * never check whether we received a probe response!
1083 */
1084 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1085 IEEE80211_STA_CONNECTION_POLL))
1086 already = true;
1087
1088 if (beacon)
1089 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1090 else
1091 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1092
1093 if (already)
1094 goto out;
1095
Johannes Berg4e751842009-06-10 15:16:52 +02001096 mutex_lock(&sdata->local->iflist_mtx);
1097 ieee80211_recalc_ps(sdata->local, -1);
1098 mutex_unlock(&sdata->local->iflist_mtx);
1099
Maxim Levitskya43abf22009-07-31 18:54:12 +03001100 ifmgd->probe_send_count = 0;
1101 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001102 out:
1103 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001104}
1105
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001106static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1107{
1108 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1109 struct ieee80211_local *local = sdata->local;
1110 u8 bssid[ETH_ALEN];
1111
1112 mutex_lock(&ifmgd->mtx);
1113 if (!ifmgd->associated) {
1114 mutex_unlock(&ifmgd->mtx);
1115 return;
1116 }
1117
1118 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1119
1120 printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid);
1121
Jouni Malinene69e95d2010-03-29 23:29:31 -07001122 ieee80211_set_disassoc(sdata, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001123 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001124
1125 mutex_lock(&local->mtx);
1126 ieee80211_recalc_idle(local);
1127 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001128 /*
1129 * must be outside lock due to cfg80211,
1130 * but that's not a problem.
1131 */
1132 ieee80211_send_deauth_disassoc(sdata, bssid,
1133 IEEE80211_STYPE_DEAUTH,
1134 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001135 NULL, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001136}
1137
1138void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001139{
1140 struct ieee80211_sub_if_data *sdata =
1141 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001142 u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001143
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001144 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1145 __ieee80211_connection_loss(sdata);
1146 else
1147 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001148}
1149
Kalle Valo04de8382009-03-22 21:57:35 +02001150void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1151{
1152 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001153 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001154
Johannes Bergb5878a22010-04-07 16:48:40 +02001155 trace_api_beacon_loss(sdata);
1156
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001157 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1158 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001159}
1160EXPORT_SYMBOL(ieee80211_beacon_loss);
1161
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001162void ieee80211_connection_loss(struct ieee80211_vif *vif)
1163{
1164 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1165 struct ieee80211_hw *hw = &sdata->local->hw;
1166
Johannes Bergb5878a22010-04-07 16:48:40 +02001167 trace_api_connection_loss(sdata);
1168
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001169 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1170 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1171}
1172EXPORT_SYMBOL(ieee80211_connection_loss);
1173
1174
Johannes Berg77fdaa12009-07-07 03:45:17 +02001175static enum rx_mgmt_action __must_check
1176ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001177 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001178{
Johannes Berg46900292009-02-15 12:44:28 +01001179 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001180 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001181 u16 reason_code;
1182
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001183 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001184 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001185
Johannes Berg77fdaa12009-07-07 03:45:17 +02001186 ASSERT_MGD_MTX(ifmgd);
1187
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001188 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001189
1190 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1191
Johannes Berg77fdaa12009-07-07 03:45:17 +02001192 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001193 sdata->name, bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001194
Jouni Malinene69e95d2010-03-29 23:29:31 -07001195 ieee80211_set_disassoc(sdata, true);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001196 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001197 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001198 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001199
1200 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001201}
1202
1203
Johannes Berg77fdaa12009-07-07 03:45:17 +02001204static enum rx_mgmt_action __must_check
1205ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1206 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001207{
Johannes Berg46900292009-02-15 12:44:28 +01001208 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001209 u16 reason_code;
1210
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001211 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001212 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001213
Johannes Berg77fdaa12009-07-07 03:45:17 +02001214 ASSERT_MGD_MTX(ifmgd);
1215
1216 if (WARN_ON(!ifmgd->associated))
1217 return RX_MGMT_NONE;
1218
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001219 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001220 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001221
1222 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1223
Johannes Berg0ff71612009-09-26 14:45:41 +02001224 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001225 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001226
Jouni Malinene69e95d2010-03-29 23:29:31 -07001227 ieee80211_set_disassoc(sdata, true);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001228 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001229 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001230 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001231 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001232}
1233
1234
Johannes Bergaf6b6372009-12-23 13:15:35 +01001235static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1236 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001237{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001238 struct ieee80211_sub_if_data *sdata = wk->sdata;
Johannes Berg46900292009-02-15 12:44:28 +01001239 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001240 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001241 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001242 struct sta_info *sta;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001243 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001244 u8 *pos;
Johannes Berg881d9482009-01-21 15:13:48 +01001245 u32 rates, basic_rates;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001246 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001247 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001248 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02001249 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001250 int i, j, err;
1251 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001252 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001253
Johannes Bergaf6b6372009-12-23 13:15:35 +01001254 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07001255
Jiri Bencf0706e82007-05-05 11:45:53 -07001256 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001257 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07001258
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001259 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1260 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001261 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001262 aid &= ~(BIT(15) | BIT(14));
1263
Johannes Bergaf6b6372009-12-23 13:15:35 +01001264 pos = mgmt->u.assoc_resp.variable;
1265 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1266
Jiri Bencf0706e82007-05-05 11:45:53 -07001267 if (!elems.supp_rates) {
1268 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001269 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001270 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001271 }
1272
Johannes Berg46900292009-02-15 12:44:28 +01001273 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001274
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001275 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001276 if (!sta) {
Johannes Berg5d1ec852009-12-02 12:43:43 +01001277 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1278 " the AP\n", sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001279 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001280 }
1281
Johannes Berg5d1ec852009-12-02 12:43:43 +01001282 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1283 WLAN_STA_ASSOC_AP);
1284 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1285 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1286
Jiri Bencf0706e82007-05-05 11:45:53 -07001287 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001288 basic_rates = 0;
1289 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1290
Jiri Bencf0706e82007-05-05 11:45:53 -07001291 for (i = 0; i < elems.supp_rates_len; i++) {
1292 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001293 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001294
1295 if (rate > 110)
1296 have_higher_than_11mbit = true;
1297
1298 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001299 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001300 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001301 if (is_basic)
1302 basic_rates |= BIT(j);
1303 break;
1304 }
Johannes Berg8318d782008-01-24 19:38:38 +01001305 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001306 }
Johannes Berg8318d782008-01-24 19:38:38 +01001307
Jiri Bencf0706e82007-05-05 11:45:53 -07001308 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1309 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001310 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001311
1312 if (rate > 110)
1313 have_higher_than_11mbit = true;
1314
1315 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001316 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001317 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001318 if (is_basic)
1319 basic_rates |= BIT(j);
1320 break;
1321 }
Johannes Berg8318d782008-01-24 19:38:38 +01001322 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001323 }
Johannes Berg8318d782008-01-24 19:38:38 +01001324
Johannes Berg323ce792008-09-11 02:45:11 +02001325 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001326 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001327
1328 /* cf. IEEE 802.11 9.2.12 */
1329 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1330 have_higher_than_11mbit)
1331 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1332 else
1333 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001334
Johannes Bergab1faea2009-07-01 21:41:17 +02001335 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001336 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001337 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001338
1339 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001340
Johannes Berg4b7679a2008-09-18 18:14:18 +02001341 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001342
Johannes Berg46900292009-02-15 12:44:28 +01001343 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001344 set_sta_flags(sta, WLAN_STA_MFP);
1345
Johannes Bergddf4ac52008-10-22 11:41:38 +02001346 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001347 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001348
Johannes Berg5d1ec852009-12-02 12:43:43 +01001349 err = sta_info_insert(sta);
1350 sta = NULL;
1351 if (err) {
1352 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1353 " the AP (error %d)\n", sdata->name, err);
Johannes Berg90be5612010-01-08 19:01:07 +01001354 return false;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001355 }
1356
Johannes Bergddf4ac52008-10-22 11:41:38 +02001357 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02001358 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001359 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001360 else
1361 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001362
Johannes Berge4da8c32009-12-23 13:15:43 +01001363 local->oper_channel = wk->chan;
1364
Johannes Bergae5eb022008-10-14 16:58:37 +02001365 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergaf6b6372009-12-23 13:15:35 +01001366 (sdata->local->hw.queues >= 4) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001367 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001368 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001369 cbss->bssid, ap_ht_cap_flags);
Johannes Bergae5eb022008-10-14 16:58:37 +02001370
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001371 /* set AID and assoc capability,
1372 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001373 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001374 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001375 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001376
Kalle Valo15b7b062009-03-22 21:57:14 +02001377 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01001378 * If we're using 4-addr mode, let the AP know that we're
1379 * doing so, so that it can create the STA VLAN on its side
1380 */
1381 if (ifmgd->use_4addr)
1382 ieee80211_send_4addr_nullfunc(local, sdata);
1383
1384 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001385 * Start timer to probe the connection to the AP now.
1386 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001387 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001388 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1389 mod_beacon_timer(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001390
Johannes Bergaf6b6372009-12-23 13:15:35 +01001391 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001392}
1393
1394
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001395static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001396 struct ieee80211_mgmt *mgmt,
1397 size_t len,
1398 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001399 struct ieee802_11_elems *elems,
1400 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001401{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001402 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001403 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001404 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001405 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01001406 bool need_ps = false;
1407
1408 if (sdata->u.mgd.associated) {
1409 bss = (void *)sdata->u.mgd.associated->priv;
1410 /* not previously set so we may need to recalc */
1411 need_ps = !bss->dtim_period;
1412 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001413
Johannes Berg5bda6172008-09-08 11:05:10 +02001414 if (elems->ds_params && elems->ds_params_len == 1)
1415 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1416 else
1417 freq = rx_status->freq;
1418
1419 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1420
1421 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1422 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001423
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001424 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001425 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001426 if (bss)
1427 ieee80211_rx_bss_put(local, bss);
1428
1429 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001430 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001431
Johannes Berg56007a02010-01-26 14:19:52 +01001432 if (need_ps) {
1433 mutex_lock(&local->iflist_mtx);
1434 ieee80211_recalc_ps(local, -1);
1435 mutex_unlock(&local->iflist_mtx);
1436 }
1437
Sujithc481ec92009-01-06 09:28:37 +05301438 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001439 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001440 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301441 struct ieee80211_channel_sw_ie *sw_elem =
1442 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001443 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1444 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05301445 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001446}
1447
1448
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001449static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01001450 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001451{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001452 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02001453 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001454 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1455 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001456 struct ieee802_11_elems elems;
1457
Kalle Valo15b7b062009-03-22 21:57:14 +02001458 ifmgd = &sdata->u.mgd;
1459
Johannes Berg77fdaa12009-07-07 03:45:17 +02001460 ASSERT_MGD_MTX(ifmgd);
1461
Johannes Berg47846c92009-11-25 17:46:19 +01001462 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001463 return; /* ignore ProbeResp to foreign address */
1464
Ester Kummerae6a44e2008-06-27 18:54:48 +03001465 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1466 if (baselen > len)
1467 return;
1468
1469 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1470 &elems);
1471
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001472 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001473
Johannes Berg77fdaa12009-07-07 03:45:17 +02001474 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001475 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0 &&
Johannes Bergb291ba12009-07-10 15:29:03 +02001476 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1477 IEEE80211_STA_CONNECTION_POLL)) {
1478 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1479 IEEE80211_STA_BEACON_POLL);
Johannes Berg4e751842009-06-10 15:16:52 +02001480 mutex_lock(&sdata->local->iflist_mtx);
1481 ieee80211_recalc_ps(sdata->local, -1);
1482 mutex_unlock(&sdata->local->iflist_mtx);
Juuso Oikarinen7bdfcaa2010-04-20 13:15:56 +03001483
1484 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1485 return;
1486
Johannes Bergb291ba12009-07-10 15:29:03 +02001487 /*
1488 * We've received a probe response, but are not sure whether
1489 * we have or will be receiving any beacons or data, so let's
1490 * schedule the timers again, just in case.
1491 */
1492 mod_beacon_timer(sdata);
Juuso Oikarinen7bdfcaa2010-04-20 13:15:56 +03001493
Johannes Bergb291ba12009-07-10 15:29:03 +02001494 mod_timer(&ifmgd->conn_mon_timer,
1495 round_jiffies_up(jiffies +
1496 IEEE80211_CONNECTION_IDLE_TIME));
Johannes Berg4e751842009-06-10 15:16:52 +02001497 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001498}
1499
Johannes Bergd91f36d2009-04-16 13:17:26 +02001500/*
1501 * This is the canonical list of information elements we care about,
1502 * the filter code also gives us all changes to the Microsoft OUI
1503 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1504 *
1505 * We implement beacon filtering in software since that means we can
1506 * avoid processing the frame here and in cfg80211, and userspace
1507 * will not be able to tell whether the hardware supports it or not.
1508 *
1509 * XXX: This list needs to be dynamic -- userspace needs to be able to
1510 * add items it requires. It also needs to be able to tell us to
1511 * look out for other vendor IEs.
1512 */
1513static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001514 (1ULL << WLAN_EID_COUNTRY) |
1515 (1ULL << WLAN_EID_ERP_INFO) |
1516 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1517 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1518 (1ULL << WLAN_EID_HT_CAPABILITY) |
1519 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001520
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001521static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001522 struct ieee80211_mgmt *mgmt,
1523 size_t len,
1524 struct ieee80211_rx_status *rx_status)
1525{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001526 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001527 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001528 size_t baselen;
1529 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001530 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001531 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001532 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001533 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001534 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001535 u8 *bssid;
1536
1537 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e82007-05-05 11:45:53 -07001538
Ester Kummerae6a44e2008-06-27 18:54:48 +03001539 /* Process beacon from the current BSS */
1540 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1541 if (baselen > len)
1542 return;
1543
Johannes Bergd91f36d2009-04-16 13:17:26 +02001544 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001545 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001546
Johannes Bergb291ba12009-07-10 15:29:03 +02001547 /*
1548 * We might have received a number of frames, among them a
1549 * disassoc frame and a beacon...
1550 */
1551 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001552 return;
1553
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001554 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001555
Johannes Bergb291ba12009-07-10 15:29:03 +02001556 /*
1557 * And in theory even frames from a different AP we were just
1558 * associated to a split-second ago!
1559 */
1560 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001561 return;
1562
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001563 /* Track average RSSI from the Beacon frames of the current AP */
1564 ifmgd->last_beacon_signal = rx_status->signal;
1565 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1566 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03001567 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001568 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03001569 ifmgd->count_beacon_signal = 1;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001570 } else {
1571 ifmgd->ave_beacon_signal =
1572 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1573 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1574 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03001575 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001576 }
1577 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03001578 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001579 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1580 int sig = ifmgd->ave_beacon_signal / 16;
1581 int last_event = ifmgd->last_cqm_event_signal;
1582 int thold = bss_conf->cqm_rssi_thold;
1583 int hyst = bss_conf->cqm_rssi_hyst;
1584 if (sig < thold &&
1585 (last_event == 0 || sig < last_event - hyst)) {
1586 ifmgd->last_cqm_event_signal = sig;
1587 ieee80211_cqm_rssi_notify(
1588 &sdata->vif,
1589 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1590 GFP_KERNEL);
1591 } else if (sig > thold &&
1592 (last_event == 0 || sig > last_event + hyst)) {
1593 ifmgd->last_cqm_event_signal = sig;
1594 ieee80211_cqm_rssi_notify(
1595 &sdata->vif,
1596 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1597 GFP_KERNEL);
1598 }
1599 }
1600
Johannes Bergb291ba12009-07-10 15:29:03 +02001601 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001602#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1603 if (net_ratelimit()) {
1604 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001605 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001606 }
1607#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001608 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001609 mutex_lock(&local->iflist_mtx);
1610 ieee80211_recalc_ps(local, -1);
1611 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001612 }
1613
Johannes Bergb291ba12009-07-10 15:29:03 +02001614 /*
1615 * Push the beacon loss detection into the future since
1616 * we are processing a beacon from the AP just now.
1617 */
1618 mod_beacon_timer(sdata);
1619
Johannes Bergd91f36d2009-04-16 13:17:26 +02001620 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1621 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1622 len - baselen, &elems,
1623 care_about_ies, ncrc);
1624
1625 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001626 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1627 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001628
Jouni Malinen30196672009-05-19 17:01:43 +03001629 if (ncrc != ifmgd->beacon_crc) {
1630 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1631 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001632
Johannes Berg4ced3f72010-07-19 16:39:04 +02001633 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03001634 elems.wmm_param_len);
1635 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001636
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301637 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001638 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001639 if (local->hw.conf.dynamic_ps_timeout > 0) {
1640 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1641 ieee80211_hw_config(local,
1642 IEEE80211_CONF_CHANGE_PS);
1643 ieee80211_send_nullfunc(local, sdata, 0);
1644 } else {
1645 local->pspolling = true;
1646
1647 /*
1648 * Here is assumed that the driver will be
1649 * able to send ps-poll frame and receive a
1650 * response even though power save mode is
1651 * enabled, but some drivers might require
1652 * to disable power save here. This needs
1653 * to be investigated.
1654 */
1655 ieee80211_send_pspoll(local, sdata);
1656 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001657 }
1658 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001659
Jouni Malinen30196672009-05-19 17:01:43 +03001660 if (ncrc == ifmgd->beacon_crc)
1661 return;
1662 ifmgd->beacon_crc = ncrc;
1663
Johannes Berg7a5158e2008-10-08 10:59:33 +02001664 if (elems.erp_info && elems.erp_info_len >= 1) {
1665 erp_valid = true;
1666 erp_value = elems.erp_info[0];
1667 } else {
1668 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001669 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001670 changed |= ieee80211_handle_bss_capability(sdata,
1671 le16_to_cpu(mgmt->u.beacon.capab_info),
1672 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001673
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001674
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301675 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001676 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001677 struct sta_info *sta;
1678 struct ieee80211_supported_band *sband;
1679 u16 ap_ht_cap_flags;
1680
1681 rcu_read_lock();
1682
Johannes Bergabe60632009-11-25 17:46:18 +01001683 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001684 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001685 rcu_read_unlock();
1686 return;
1687 }
1688
1689 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1690
1691 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1692 elems.ht_cap_elem, &sta->sta.ht_cap);
1693
1694 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1695
1696 rcu_read_unlock();
1697
1698 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001699 bssid, ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001700 }
1701
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001702 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001703 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301704 /* TODO: IBSS also needs this */
1705 if (elems.pwr_constr_elem)
1706 ieee80211_handle_pwr_constr(sdata,
1707 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1708 elems.pwr_constr_elem,
1709 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001710 }
1711
Johannes Berg471b3ef2007-12-28 14:32:58 +01001712 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001713}
1714
Johannes Berg1fa57d02010-06-10 10:21:32 +02001715void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1716 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001717{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001718 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001719 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001720 struct ieee80211_mgmt *mgmt;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001721 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001722 u16 fc;
1723
Jiri Bencf0706e82007-05-05 11:45:53 -07001724 rx_status = (struct ieee80211_rx_status *) skb->cb;
1725 mgmt = (struct ieee80211_mgmt *) skb->data;
1726 fc = le16_to_cpu(mgmt->frame_control);
1727
Johannes Berg77fdaa12009-07-07 03:45:17 +02001728 mutex_lock(&ifmgd->mtx);
1729
1730 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001731 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001732 switch (fc & IEEE80211_FCTL_STYPE) {
1733 case IEEE80211_STYPE_BEACON:
1734 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1735 rx_status);
1736 break;
1737 case IEEE80211_STYPE_PROBE_RESP:
Johannes Bergaf6b6372009-12-23 13:15:35 +01001738 ieee80211_rx_mgmt_probe_resp(sdata, skb);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001739 break;
1740 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01001741 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001742 break;
1743 case IEEE80211_STYPE_DISASSOC:
1744 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1745 break;
1746 case IEEE80211_STYPE_ACTION:
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001747 switch (mgmt->u.action.category) {
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001748 case WLAN_CATEGORY_SPECTRUM_MGMT:
1749 ieee80211_sta_process_chanswitch(sdata,
1750 &mgmt->u.action.u.chan_switch.sw_elem,
1751 (void *)ifmgd->associated->priv,
1752 rx_status->mactime);
1753 break;
1754 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02001755 }
1756 mutex_unlock(&ifmgd->mtx);
1757
1758 switch (rma) {
1759 case RX_MGMT_NONE:
1760 /* no action */
1761 break;
1762 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02001763 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001764 break;
1765 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470612009-10-13 13:28:13 +02001766 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001767 break;
1768 default:
1769 WARN(1, "unexpected: %d", rma);
1770 }
Johannes Berg36b3a622010-06-10 10:21:33 +02001771 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001772 }
1773
Johannes Berg77fdaa12009-07-07 03:45:17 +02001774 mutex_unlock(&ifmgd->mtx);
1775
Johannes Berg63f170e2009-12-23 13:15:33 +01001776 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
Johannes Bergb054b742010-06-07 21:50:07 +02001777 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
1778 struct ieee80211_local *local = sdata->local;
1779 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001780
Johannes Berga1699b72010-07-30 16:46:07 +02001781 mutex_lock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001782 list_for_each_entry(wk, &local->work_list, list) {
1783 if (wk->sdata != sdata)
1784 continue;
1785
Johannes Berge5b900d2010-07-29 16:08:55 +02001786 if (wk->type != IEEE80211_WORK_ASSOC &&
1787 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Bergb054b742010-06-07 21:50:07 +02001788 continue;
1789
1790 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
1791 continue;
1792 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
1793 continue;
1794
1795 /*
1796 * Printing the message only here means we can't
1797 * spuriously print it, but it also means that it
1798 * won't be printed when the frame comes in before
1799 * we even tried to associate or in similar cases.
1800 *
1801 * Ultimately, I suspect cfg80211 should print the
1802 * messages instead.
1803 */
1804 printk(KERN_DEBUG
1805 "%s: deauthenticated from %pM (Reason: %u)\n",
1806 sdata->name, mgmt->bssid,
1807 le16_to_cpu(mgmt->u.deauth.reason_code));
1808
1809 list_del_rcu(&wk->list);
1810 free_work(wk);
1811 break;
1812 }
Johannes Berga1699b72010-07-30 16:46:07 +02001813 mutex_unlock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001814
Johannes Berg77fdaa12009-07-07 03:45:17 +02001815 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Bergb054b742010-06-07 21:50:07 +02001816 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001817}
1818
Johannes Berg9c6bd792008-09-11 00:01:52 +02001819static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001820{
1821 struct ieee80211_sub_if_data *sdata =
1822 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001823 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001824 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001825
Johannes Berg5bb644a2009-05-17 11:40:42 +02001826 if (local->quiescing) {
1827 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1828 return;
1829 }
1830
Johannes Berg64592c82010-06-10 10:21:31 +02001831 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001832}
1833
Johannes Berg1fa57d02010-06-10 10:21:32 +02001834void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02001835{
Johannes Berg60f8b392008-09-08 17:44:22 +02001836 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02001837 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001838
Johannes Berg77fdaa12009-07-07 03:45:17 +02001839 /* then process the rest of the work */
1840 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02001841
Johannes Bergb291ba12009-07-10 15:29:03 +02001842 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1843 IEEE80211_STA_CONNECTION_POLL) &&
1844 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03001845 u8 bssid[ETH_ALEN];
1846
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001847 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +02001848 if (time_is_after_jiffies(ifmgd->probe_timeout))
1849 run_again(ifmgd, ifmgd->probe_timeout);
Maxim Levitskya43abf22009-07-31 18:54:12 +03001850
1851 else if (ifmgd->probe_send_count < IEEE80211_MAX_PROBE_TRIES) {
1852#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1853 printk(KERN_DEBUG "No probe response from AP %pM"
1854 " after %dms, try %d\n", bssid,
1855 (1000 * IEEE80211_PROBE_WAIT)/HZ,
1856 ifmgd->probe_send_count);
1857#endif
1858 ieee80211_mgd_probe_ap_send(sdata);
1859 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02001860 /*
1861 * We actually lost the connection ... or did we?
1862 * Let's make sure!
1863 */
1864 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1865 IEEE80211_STA_BEACON_POLL);
Johannes Bergb291ba12009-07-10 15:29:03 +02001866 printk(KERN_DEBUG "No probe response from AP %pM"
1867 " after %dms, disconnecting.\n",
1868 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
Jouni Malinene69e95d2010-03-29 23:29:31 -07001869 ieee80211_set_disassoc(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001870 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001871 mutex_lock(&local->mtx);
1872 ieee80211_recalc_idle(local);
1873 mutex_unlock(&local->mtx);
Johannes Bergb291ba12009-07-10 15:29:03 +02001874 /*
1875 * must be outside lock due to cfg80211,
1876 * but that's not a problem.
1877 */
1878 ieee80211_send_deauth_disassoc(sdata, bssid,
1879 IEEE80211_STYPE_DEAUTH,
1880 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001881 NULL, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001882 mutex_lock(&ifmgd->mtx);
1883 }
1884 }
1885
Johannes Berg77fdaa12009-07-07 03:45:17 +02001886 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02001887}
Johannes Berg0a51b272008-09-08 17:44:25 +02001888
Johannes Bergb291ba12009-07-10 15:29:03 +02001889static void ieee80211_sta_bcn_mon_timer(unsigned long data)
1890{
1891 struct ieee80211_sub_if_data *sdata =
1892 (struct ieee80211_sub_if_data *) data;
1893 struct ieee80211_local *local = sdata->local;
1894
1895 if (local->quiescing)
1896 return;
1897
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001898 ieee80211_queue_work(&sdata->local->hw,
1899 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001900}
1901
1902static void ieee80211_sta_conn_mon_timer(unsigned long data)
1903{
1904 struct ieee80211_sub_if_data *sdata =
1905 (struct ieee80211_sub_if_data *) data;
1906 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1907 struct ieee80211_local *local = sdata->local;
1908
1909 if (local->quiescing)
1910 return;
1911
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001912 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001913}
1914
1915static void ieee80211_sta_monitor_work(struct work_struct *work)
1916{
1917 struct ieee80211_sub_if_data *sdata =
1918 container_of(work, struct ieee80211_sub_if_data,
1919 u.mgd.monitor_work);
1920
1921 ieee80211_mgd_probe_ap(sdata, false);
1922}
1923
Johannes Berga1678f82008-09-11 00:01:47 +02001924static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1925{
Kalle Vaload935682009-04-19 08:47:19 +03001926 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02001927 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
1928 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03001929
Johannes Bergb291ba12009-07-10 15:29:03 +02001930 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04001931 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02001932 &sdata->u.mgd.monitor_work);
1933 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02001934 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03001935 }
Johannes Berga1678f82008-09-11 00:01:47 +02001936}
1937
Johannes Berg5bb644a2009-05-17 11:40:42 +02001938#ifdef CONFIG_PM
1939void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
1940{
1941 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1942
1943 /*
1944 * we need to use atomic bitops for the running bits
1945 * only because both timers might fire at the same
1946 * time -- the code here is properly synchronised.
1947 */
1948
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02001949 cancel_work_sync(&ifmgd->request_smps_work);
1950
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001951 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02001952 if (del_timer_sync(&ifmgd->timer))
1953 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1954
1955 cancel_work_sync(&ifmgd->chswitch_work);
1956 if (del_timer_sync(&ifmgd->chswitch_timer))
1957 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02001958
1959 cancel_work_sync(&ifmgd->monitor_work);
1960 /* these will just be re-established on connection */
1961 del_timer_sync(&ifmgd->conn_mon_timer);
1962 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02001963}
1964
1965void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
1966{
1967 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1968
1969 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
1970 add_timer(&ifmgd->timer);
1971 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
1972 add_timer(&ifmgd->chswitch_timer);
1973}
1974#endif
1975
Johannes Berg9c6bd792008-09-11 00:01:52 +02001976/* interface setup */
1977void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1978{
Johannes Berg46900292009-02-15 12:44:28 +01001979 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02001980
Johannes Berg46900292009-02-15 12:44:28 +01001981 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001982 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01001983 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001984 INIT_WORK(&ifmgd->beacon_connection_loss_work,
1985 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02001986 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01001987 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02001988 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001989 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
1990 (unsigned long) sdata);
1991 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
1992 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01001993 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05301994 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02001995
Johannes Bergab1faea2009-07-01 21:41:17 +02001996 ifmgd->flags = 0;
Johannes Bergbbbdff92009-04-16 13:27:42 +02001997
Johannes Berg77fdaa12009-07-07 03:45:17 +02001998 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01001999
2000 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2001 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2002 else
2003 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002004}
2005
2006/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002007void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2008{
2009 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002010
2011 /* Restart STA timers */
2012 rcu_read_lock();
2013 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2014 ieee80211_restart_sta_timer(sdata);
2015 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002016}
Johannes Berg10f644a2009-04-16 13:17:25 +02002017
2018int ieee80211_max_network_latency(struct notifier_block *nb,
2019 unsigned long data, void *dummy)
2020{
2021 s32 latency_usec = (s32) data;
2022 struct ieee80211_local *local =
2023 container_of(nb, struct ieee80211_local,
2024 network_latency_notifier);
2025
2026 mutex_lock(&local->iflist_mtx);
2027 ieee80211_recalc_ps(local, latency_usec);
2028 mutex_unlock(&local->iflist_mtx);
2029
2030 return 0;
2031}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002032
2033/* config hooks */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002034static enum work_done_result
2035ieee80211_probe_auth_done(struct ieee80211_work *wk,
2036 struct sk_buff *skb)
2037{
2038 if (!skb) {
2039 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2040 return WORK_DONE_DESTROY;
2041 }
2042
2043 if (wk->type == IEEE80211_WORK_AUTH) {
2044 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2045 return WORK_DONE_DESTROY;
2046 }
2047
2048 mutex_lock(&wk->sdata->u.mgd.mtx);
2049 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2050 mutex_unlock(&wk->sdata->u.mgd.mtx);
2051
2052 wk->type = IEEE80211_WORK_AUTH;
2053 wk->probe_auth.tries = 0;
2054 return WORK_DONE_REQUEUE;
2055}
2056
Johannes Berg77fdaa12009-07-07 03:45:17 +02002057int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2058 struct cfg80211_auth_request *req)
2059{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002060 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002061 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002062 u16 auth_alg;
2063
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002064 if (req->local_state_change)
2065 return 0; /* no need to update mac80211 state */
2066
Johannes Berg77fdaa12009-07-07 03:45:17 +02002067 switch (req->auth_type) {
2068 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2069 auth_alg = WLAN_AUTH_OPEN;
2070 break;
2071 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg9dca9c42010-07-21 10:09:25 +02002072 if (IS_ERR(sdata->local->wep_tx_tfm))
2073 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002074 auth_alg = WLAN_AUTH_SHARED_KEY;
2075 break;
2076 case NL80211_AUTHTYPE_FT:
2077 auth_alg = WLAN_AUTH_FT;
2078 break;
2079 case NL80211_AUTHTYPE_NETWORK_EAP:
2080 auth_alg = WLAN_AUTH_LEAP;
2081 break;
2082 default:
2083 return -EOPNOTSUPP;
2084 }
2085
2086 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2087 if (!wk)
2088 return -ENOMEM;
2089
Joe Perches5e124bd2010-01-08 22:33:38 -08002090 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002091
2092 if (req->ie && req->ie_len) {
2093 memcpy(wk->ie, req->ie, req->ie_len);
2094 wk->ie_len = req->ie_len;
2095 }
2096
Johannes Bergfffd0932009-07-08 14:22:54 +02002097 if (req->key && req->key_len) {
Johannes Bergaf6b6372009-12-23 13:15:35 +01002098 wk->probe_auth.key_len = req->key_len;
2099 wk->probe_auth.key_idx = req->key_idx;
2100 memcpy(wk->probe_auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002101 }
2102
Johannes Berg77fdaa12009-07-07 03:45:17 +02002103 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002104 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2105 wk->probe_auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002106
Johannes Bergaf6b6372009-12-23 13:15:35 +01002107 wk->probe_auth.algorithm = auth_alg;
2108 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +01002109
Johannes Berg070bb542010-02-03 13:57:46 +01002110 /* if we already have a probe, don't probe again */
2111 if (req->bss->proberesp_ies)
2112 wk->type = IEEE80211_WORK_AUTH;
2113 else
2114 wk->type = IEEE80211_WORK_DIRECT_PROBE;
Johannes Bergf679f652009-12-23 13:15:34 +01002115 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002116 wk->sdata = sdata;
2117 wk->done = ieee80211_probe_auth_done;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002118
Johannes Bergaf6b6372009-12-23 13:15:35 +01002119 ieee80211_add_work(wk);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002120 return 0;
2121}
2122
Johannes Bergaf6b6372009-12-23 13:15:35 +01002123static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2124 struct sk_buff *skb)
2125{
2126 struct ieee80211_mgmt *mgmt;
Johannes Berge5b900d2010-07-29 16:08:55 +02002127 struct ieee80211_rx_status *rx_status;
2128 struct ieee802_11_elems elems;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002129 u16 status;
2130
2131 if (!skb) {
2132 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2133 return WORK_DONE_DESTROY;
2134 }
2135
Johannes Berge5b900d2010-07-29 16:08:55 +02002136 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2137 mutex_lock(&wk->sdata->u.mgd.mtx);
2138 rx_status = (void *) skb->cb;
2139 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2140 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2141 &elems, true);
2142 mutex_unlock(&wk->sdata->u.mgd.mtx);
2143
2144 wk->type = IEEE80211_WORK_ASSOC;
2145 /* not really done yet */
2146 return WORK_DONE_REQUEUE;
2147 }
2148
Johannes Bergaf6b6372009-12-23 13:15:35 +01002149 mgmt = (void *)skb->data;
2150 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2151
2152 if (status == WLAN_STATUS_SUCCESS) {
2153 mutex_lock(&wk->sdata->u.mgd.mtx);
2154 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2155 mutex_unlock(&wk->sdata->u.mgd.mtx);
2156 /* oops -- internal error -- send timeout for now */
2157 cfg80211_send_assoc_timeout(wk->sdata->dev,
2158 wk->filter_ta);
2159 return WORK_DONE_DESTROY;
2160 }
Juuso Oikarinen68542962010-06-09 13:43:26 +03002161
2162 mutex_unlock(&wk->sdata->u.mgd.mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002163 }
2164
2165 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2166 return WORK_DONE_DESTROY;
2167}
2168
Johannes Berg77fdaa12009-07-07 03:45:17 +02002169int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2170 struct cfg80211_assoc_request *req)
2171{
2172 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002173 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Bergf679f652009-12-23 13:15:34 +01002174 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002175 const u8 *ssid;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002176 int i;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002177
2178 mutex_lock(&ifmgd->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002179 if (ifmgd->associated) {
Jouni Malinen9c87ba62010-02-28 12:13:46 +02002180 if (!req->prev_bssid ||
2181 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2182 ETH_ALEN)) {
2183 /*
2184 * We are already associated and the request was not a
2185 * reassociation request from the current BSS, so
2186 * reject it.
2187 */
2188 mutex_unlock(&ifmgd->mtx);
2189 return -EALREADY;
2190 }
2191
2192 /* Trying to reassociate - clear previous association state */
Jouni Malinene69e95d2010-03-29 23:29:31 -07002193 ieee80211_set_disassoc(sdata, true);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002194 }
2195 mutex_unlock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002196
Johannes Berg63f170e2009-12-23 13:15:33 +01002197 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002198 if (!wk)
2199 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002200
Johannes Berg77fdaa12009-07-07 03:45:17 +02002201 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05302202 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002203
2204 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2205 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2206 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2207 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2208 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2209
Johannes Berg77fdaa12009-07-07 03:45:17 +02002210
2211 if (req->ie && req->ie_len) {
2212 memcpy(wk->ie, req->ie, req->ie_len);
2213 wk->ie_len = req->ie_len;
2214 } else
2215 wk->ie_len = 0;
2216
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002217 wk->assoc.bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01002218
Johannes Bergaf6b6372009-12-23 13:15:35 +01002219 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +01002220
Johannes Bergaf6b6372009-12-23 13:15:35 +01002221 /* new association always uses requested smps mode */
2222 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2223 if (ifmgd->powersave)
2224 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2225 else
2226 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2227 } else
2228 ifmgd->ap_smps = ifmgd->req_smps;
2229
2230 wk->assoc.smps = ifmgd->ap_smps;
Johannes Berg77c81442009-12-23 13:15:37 +01002231 /*
2232 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2233 * We still associate in non-HT mode (11a/b/g) if any one of these
2234 * ciphers is configured as pairwise.
2235 * We can set this to true for non-11n hardware, that'll be checked
2236 * separately along with the peer capabilities.
2237 */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002238 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
Johannes Bergf679f652009-12-23 13:15:34 +01002239 wk->assoc.capability = req->bss->capability;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002240 wk->assoc.wmm_used = bss->wmm_used;
2241 wk->assoc.supp_rates = bss->supp_rates;
2242 wk->assoc.supp_rates_len = bss->supp_rates_len;
Johannes Bergf679f652009-12-23 13:15:34 +01002243 wk->assoc.ht_information_ie =
2244 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002245
Kalle Valoab133152010-01-12 10:42:31 +02002246 if (bss->wmm_used && bss->uapsd_supported &&
2247 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2248 wk->assoc.uapsd_used = true;
2249 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2250 } else {
2251 wk->assoc.uapsd_used = false;
2252 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2253 }
2254
Johannes Berg63f170e2009-12-23 13:15:33 +01002255 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002256 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2257 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002258
Johannes Berg77fdaa12009-07-07 03:45:17 +02002259 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002260 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002261
Johannes Bergf679f652009-12-23 13:15:34 +01002262 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002263 wk->sdata = sdata;
2264 wk->done = ieee80211_assoc_done;
Johannes Berge5b900d2010-07-29 16:08:55 +02002265 if (!bss->dtim_period &&
2266 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2267 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2268 else
2269 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002270
2271 if (req->use_mfp) {
2272 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2273 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2274 } else {
2275 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2276 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2277 }
2278
2279 if (req->crypto.control_port)
2280 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2281 else
2282 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2283
Johannes Berga621fa42010-08-27 14:26:54 +03002284 sdata->control_port_protocol = req->crypto.control_port_ethertype;
2285 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2286
Johannes Bergaf6b6372009-12-23 13:15:35 +01002287 ieee80211_add_work(wk);
2288 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002289}
2290
2291int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002292 struct cfg80211_deauth_request *req,
2293 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002294{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002295 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002296 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002297 struct ieee80211_work *wk;
Jouni Malinen05e48e82010-06-14 11:55:56 -07002298 u8 bssid[ETH_ALEN];
2299 bool assoc_bss = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002300
Johannes Berg77fdaa12009-07-07 03:45:17 +02002301 mutex_lock(&ifmgd->mtx);
2302
Jouni Malinen05e48e82010-06-14 11:55:56 -07002303 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002304 if (ifmgd->associated == req->bss) {
Jouni Malinen05e48e82010-06-14 11:55:56 -07002305 ieee80211_set_disassoc(sdata, false);
Johannes Berga58ce432009-11-19 12:45:42 +01002306 mutex_unlock(&ifmgd->mtx);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002307 assoc_bss = true;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002308 } else {
2309 bool not_auth_yet = false;
Johannes Berga58ce432009-11-19 12:45:42 +01002310
Johannes Bergaf6b6372009-12-23 13:15:35 +01002311 mutex_unlock(&ifmgd->mtx);
2312
Johannes Berga1699b72010-07-30 16:46:07 +02002313 mutex_lock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002314 list_for_each_entry(wk, &local->work_list, list) {
Johannes Berg29165e42010-02-06 15:20:13 +01002315 if (wk->sdata != sdata)
Johannes Bergaf6b6372009-12-23 13:15:35 +01002316 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002317
2318 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
Reinette Chatre79733a82010-05-04 16:04:49 -07002319 wk->type != IEEE80211_WORK_AUTH &&
Johannes Berge5b900d2010-07-29 16:08:55 +02002320 wk->type != IEEE80211_WORK_ASSOC &&
2321 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Berg29165e42010-02-06 15:20:13 +01002322 continue;
2323
Johannes Bergaf6b6372009-12-23 13:15:35 +01002324 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2325 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002326
2327 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2328 list_del_rcu(&wk->list);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002329 free_work(wk);
2330 break;
2331 }
Johannes Berga1699b72010-07-30 16:46:07 +02002332 mutex_unlock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002333
2334 /*
2335 * If somebody requests authentication and we haven't
2336 * sent out an auth frame yet there's no need to send
2337 * out a deauth frame either. If the state was PROBE,
2338 * then this is the case. If it's AUTH we have sent a
2339 * frame, and if it's IDLE we have completed the auth
2340 * process already.
2341 */
2342 if (not_auth_yet) {
2343 __cfg80211_auth_canceled(sdata->dev, bssid);
2344 return 0;
2345 }
2346 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002347
Johannes Berg0ff71612009-09-26 14:45:41 +02002348 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002349 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002350
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002351 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2352 req->reason_code, cookie,
2353 !req->local_state_change);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002354 if (assoc_bss)
2355 sta_info_destroy_addr(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002356
Johannes Berg7da7cc12010-08-05 17:02:38 +02002357 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002358 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002359 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002360
Johannes Berg77fdaa12009-07-07 03:45:17 +02002361 return 0;
2362}
2363
2364int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002365 struct cfg80211_disassoc_request *req,
2366 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002367{
2368 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07002369 u8 bssid[ETH_ALEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002370
Johannes Berg77fdaa12009-07-07 03:45:17 +02002371 mutex_lock(&ifmgd->mtx);
2372
Johannes Berg8d8b2612009-07-25 11:58:36 +02002373 /*
2374 * cfg80211 should catch this ... but it's racy since
2375 * we can receive a disassoc frame, process it, hand it
2376 * to cfg80211 while that's in a locked section already
2377 * trying to tell us that the user wants to disconnect.
2378 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002379 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002380 mutex_unlock(&ifmgd->mtx);
2381 return -ENOLINK;
2382 }
2383
Johannes Berg0ff71612009-09-26 14:45:41 +02002384 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002385 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002386
Jouni Malinene69e95d2010-03-29 23:29:31 -07002387 memcpy(bssid, req->bss->bssid, ETH_ALEN);
2388 ieee80211_set_disassoc(sdata, false);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002389
2390 mutex_unlock(&ifmgd->mtx);
2391
2392 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +02002393 IEEE80211_STYPE_DISASSOC, req->reason_code,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002394 cookie, !req->local_state_change);
Jouni Malinene69e95d2010-03-29 23:29:31 -07002395 sta_info_destroy_addr(sdata, bssid);
Johannes Bergbc83b682009-11-29 12:19:06 +01002396
Johannes Berg7da7cc12010-08-05 17:02:38 +02002397 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002398 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002399 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002400
Johannes Berg77fdaa12009-07-07 03:45:17 +02002401 return 0;
2402}
Jouni Malinen026331c2010-02-15 12:53:10 +02002403
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002404void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2405 enum nl80211_cqm_rssi_threshold_event rssi_event,
2406 gfp_t gfp)
2407{
2408 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2409
Johannes Bergb5878a22010-04-07 16:48:40 +02002410 trace_api_cqm_rssi_notify(sdata, rssi_event);
2411
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002412 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2413}
2414EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);