blob: e059b3a6f285d401ea4649bb7ce653dcf1b196c3 [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
Felix Fietkau72a8a3e2010-11-23 03:10:32 +010031#define IEEE80211_MAX_NULLFUNC_TRIES 2
Maxim Levitskya43abf22009-07-31 18:54:12 +030032#define IEEE80211_MAX_PROBE_TRIES 5
Johannes Bergb291ba12009-07-10 15:29:03 +020033
34/*
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010035 * Beacon loss timeout is calculated as N frames times the
36 * advertised beacon interval. This may need to be somewhat
37 * higher than what hardware might detect to account for
38 * delays in the host processing frames. But since we also
39 * probe on beacon miss before declaring the connection lost
40 * default to what we want.
Johannes Bergb291ba12009-07-10 15:29:03 +020041 */
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +010042#define IEEE80211_BEACON_LOSS_COUNT 7
43
Johannes Bergb291ba12009-07-10 15:29:03 +020044/*
45 * Time the connection can be idle before we probe
46 * it to see if we can still talk to the AP.
47 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030048#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
Johannes Bergb291ba12009-07-10 15:29:03 +020049/*
50 * Time we wait for a probe response after sending
51 * a probe request because of beacon loss or for
52 * checking the connection still works.
53 */
Maxim Levitskyd1c50912009-07-31 18:54:23 +030054#define IEEE80211_PROBE_WAIT (HZ / 2)
Jiri Bencf0706e82007-05-05 11:45:53 -070055
Jouni Malinen17e4ec12010-03-29 23:28:30 -070056/*
57 * Weight given to the latest Beacon frame when calculating average signal
58 * strength for Beacon frames received in the current BSS. This must be
59 * between 1 and 15.
60 */
61#define IEEE80211_SIGNAL_AVE_WEIGHT 3
62
Jouni Malinen391a2002010-08-27 22:22:00 +030063/*
64 * How many Beacon frames need to have been used in average signal strength
65 * before starting to indicate signal change events.
66 */
67#define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
68
Johannes Berg5bb644a2009-05-17 11:40:42 +020069#define TMR_RUNNING_TIMER 0
70#define TMR_RUNNING_CHANSW 1
71
Johannes Berg77fdaa12009-07-07 03:45:17 +020072/*
73 * All cfg80211 functions have to be called outside a locked
74 * section so that they can acquire a lock themselves... This
75 * is much simpler than queuing up things in cfg80211, but we
76 * do need some indirection for that here.
77 */
78enum rx_mgmt_action {
79 /* no action required */
80 RX_MGMT_NONE,
81
82 /* caller must call cfg80211_send_rx_auth() */
83 RX_MGMT_CFG80211_AUTH,
84
85 /* caller must call cfg80211_send_rx_assoc() */
86 RX_MGMT_CFG80211_ASSOC,
87
88 /* caller must call cfg80211_send_deauth() */
89 RX_MGMT_CFG80211_DEAUTH,
90
91 /* caller must call cfg80211_send_disassoc() */
92 RX_MGMT_CFG80211_DISASSOC,
93
Johannes Berg5d1ec852009-12-02 12:43:43 +010094 /* caller must tell cfg80211 about internal error */
95 RX_MGMT_CFG80211_ASSOC_ERROR,
Johannes Berg77fdaa12009-07-07 03:45:17 +020096};
97
Johannes Berg5484e232008-09-08 17:44:27 +020098/* utils */
Johannes Berg77fdaa12009-07-07 03:45:17 +020099static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
100{
Johannes Berg46a5eba2010-09-15 13:28:15 +0200101 lockdep_assert_held(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200102}
103
Johannes Bergca386f32009-07-10 02:39:48 +0200104/*
105 * We can have multiple work items (and connection probing)
106 * scheduling this timer, but we need to take care to only
107 * reschedule it when it should fire _earlier_ than it was
108 * asked for before, or if it's not pending right now. This
109 * function ensures that. Note that it then is required to
110 * run this function for all timeouts after the first one
111 * has happened -- the work that runs from this timer will
112 * do that.
113 */
114static void run_again(struct ieee80211_if_managed *ifmgd,
115 unsigned long timeout)
116{
117 ASSERT_MGD_MTX(ifmgd);
118
119 if (!timer_pending(&ifmgd->timer) ||
120 time_before(timeout, ifmgd->timer.expires))
121 mod_timer(&ifmgd->timer, timeout);
122}
123
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -0400124void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
Johannes Bergb291ba12009-07-10 15:29:03 +0200125{
126 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
127 return;
128
129 mod_timer(&sdata->u.mgd.bcn_mon_timer,
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100130 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
Johannes Bergb291ba12009-07-10 15:29:03 +0200131}
132
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400133void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
134{
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400135 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
136
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400137 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
138 return;
139
140 mod_timer(&sdata->u.mgd.conn_mon_timer,
141 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
Luis R. Rodriguez0c699c32010-09-16 15:12:30 -0400142
143 ifmgd->probe_send_count = 0;
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -0400144}
145
Johannes Berg5484e232008-09-08 17:44:27 +0200146static int ecw2cw(int ecw)
Johannes Berg60f8b392008-09-08 17:44:22 +0200147{
Johannes Berg5484e232008-09-08 17:44:27 +0200148 return (1 << ecw) - 1;
Johannes Berg60f8b392008-09-08 17:44:22 +0200149}
150
Johannes Bergd5522e02009-03-30 13:23:35 +0200151/*
152 * ieee80211_enable_ht should be called only after the operating band
153 * has been determined as ht configuration depends on the hw's
154 * HT abilities for a specific band.
155 */
156static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
157 struct ieee80211_ht_info *hti,
Johannes Berg77fdaa12009-07-07 03:45:17 +0200158 const u8 *bssid, u16 ap_ht_cap_flags)
Johannes Bergd5522e02009-03-30 13:23:35 +0200159{
160 struct ieee80211_local *local = sdata->local;
161 struct ieee80211_supported_band *sband;
Johannes Bergd5522e02009-03-30 13:23:35 +0200162 struct sta_info *sta;
163 u32 changed = 0;
Ben Greear172710b2011-01-28 17:05:43 -0800164 int hti_cfreq;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200165 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200166 bool enable_ht = true;
167 enum nl80211_channel_type prev_chantype;
Johannes Bergd5522e02009-03-30 13:23:35 +0200168 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
169
170 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
171
Johannes Berg0aaffa92010-05-05 15:28:27 +0200172 prev_chantype = sdata->vif.bss_conf.channel_type;
173
Johannes Bergd5522e02009-03-30 13:23:35 +0200174 /* HT is not supported */
175 if (!sband->ht_cap.ht_supported)
176 enable_ht = false;
177
Ben Greear172710b2011-01-28 17:05:43 -0800178 if (enable_ht) {
179 hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
180 sband->band);
181 /* check that channel matches the right operating channel */
182 if (local->hw.conf.channel->center_freq != hti_cfreq) {
183 /* Some APs mess this up, evidently.
184 * Netgear WNDR3700 sometimes reports 4 higher than
185 * the actual channel, for instance.
186 */
187 printk(KERN_DEBUG
188 "%s: Wrong control channel in association"
189 " response: configured center-freq: %d"
190 " hti-cfreq: %d hti->control_chan: %d"
191 " band: %d. Disabling HT.\n",
192 sdata->name,
193 local->hw.conf.channel->center_freq,
194 hti_cfreq, hti->control_chan,
195 sband->band);
196 enable_ht = false;
197 }
198 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200199
200 if (enable_ht) {
201 channel_type = NL80211_CHAN_HT20;
202
203 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
204 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
205 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
206 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
207 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400208 if (!(local->hw.conf.channel->flags &
209 IEEE80211_CHAN_NO_HT40PLUS))
210 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200211 break;
212 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400213 if (!(local->hw.conf.channel->flags &
214 IEEE80211_CHAN_NO_HT40MINUS))
215 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200216 break;
217 }
218 }
219 }
220
Reinette Chatrefe6f2122010-04-19 10:46:31 -0700221 if (local->tmp_channel)
222 local->tmp_channel_type = channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200223
Johannes Berg0aaffa92010-05-05 15:28:27 +0200224 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
225 /* can only fail due to HT40+/- mismatch */
226 channel_type = NL80211_CHAN_HT20;
227 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
228 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200229
Johannes Berg0aaffa92010-05-05 15:28:27 +0200230 /* channel_type change automatically detected */
231 ieee80211_hw_config(local, 0);
232
233 if (prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200234 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100235 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200236 if (sta)
237 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530238 IEEE80211_RC_HT_CHANGED,
Johannes Berg0aaffa92010-05-05 15:28:27 +0200239 channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200240 rcu_read_unlock();
Johannes Berg0aaffa92010-05-05 15:28:27 +0200241 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200242
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200243 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200244
245 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200246 if (sdata->ht_opmode_valid != enable_ht ||
247 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
248 prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200249 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200250 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200251 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200252 }
253
254 return changed;
255}
256
Johannes Berg9c6bd792008-09-11 00:01:52 +0200257/* frame sending functions */
258
Johannes Bergef422bc2008-09-09 10:58:25 +0200259static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +0200260 const u8 *bssid, u16 stype, u16 reason,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300261 void *cookie, bool send_frame)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200262{
263 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100264 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200265 struct sk_buff *skb;
266 struct ieee80211_mgmt *mgmt;
267
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200268 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200269 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200270 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100271 "deauth/disassoc frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200272 return;
273 }
274 skb_reserve(skb, local->hw.extra_tx_headroom);
275
276 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
277 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200278 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100279 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200280 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200281 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200282 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200283 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200284 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
285
Jouni Malinen53b46b82009-03-27 20:53:56 +0200286 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470612009-10-13 13:28:13 +0200287 if (cookie)
288 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
289 else
290 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200291 else
Holger Schurigce470612009-10-13 13:28:13 +0200292 if (cookie)
293 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
294 else
295 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100296 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
297 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300298
299 if (send_frame)
300 ieee80211_tx_skb(sdata, skb);
301 else
302 kfree_skb(skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200303}
304
Kalle Valo572e0012009-02-10 17:09:31 +0200305void ieee80211_send_pspoll(struct ieee80211_local *local,
306 struct ieee80211_sub_if_data *sdata)
307{
Kalle Valo572e0012009-02-10 17:09:31 +0200308 struct ieee80211_pspoll *pspoll;
309 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200310
Kalle Valod8cd1892010-01-05 20:16:26 +0200311 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
312 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200313 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200314
Kalle Valod8cd1892010-01-05 20:16:26 +0200315 pspoll = (struct ieee80211_pspoll *) skb->data;
316 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200317
Johannes Berg62ae67b2009-11-18 18:42:05 +0100318 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
319 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200320}
321
Johannes Berg965beda2009-04-16 13:17:24 +0200322void ieee80211_send_nullfunc(struct ieee80211_local *local,
323 struct ieee80211_sub_if_data *sdata,
324 int powersave)
325{
326 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200327 struct ieee80211_hdr_3addr *nullfunc;
Johannes Berg965beda2009-04-16 13:17:24 +0200328
Kalle Valod8cd1892010-01-05 20:16:26 +0200329 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
330 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200331 return;
332
Kalle Valod8cd1892010-01-05 20:16:26 +0200333 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200334 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200335 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200336
Johannes Berg62ae67b2009-11-18 18:42:05 +0100337 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
338 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200339}
340
Felix Fietkaud5242152010-01-08 18:06:26 +0100341static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
342 struct ieee80211_sub_if_data *sdata)
343{
344 struct sk_buff *skb;
345 struct ieee80211_hdr *nullfunc;
346 __le16 fc;
347
348 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
349 return;
350
351 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
352 if (!skb) {
353 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
354 "nullfunc frame\n", sdata->name);
355 return;
356 }
357 skb_reserve(skb, local->hw.extra_tx_headroom);
358
359 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
360 memset(nullfunc, 0, 30);
361 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
362 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
363 nullfunc->frame_control = fc;
364 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
365 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
366 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
367 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
368
369 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
370 ieee80211_tx_skb(sdata, skb);
371}
372
Johannes Bergcc32abd2009-05-15 11:52:31 +0200373/* spectrum management related things */
374static void ieee80211_chswitch_work(struct work_struct *work)
375{
376 struct ieee80211_sub_if_data *sdata =
377 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200378 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
379
Johannes Berg9607e6b2009-12-23 13:15:31 +0100380 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200381 return;
382
Johannes Berg77fdaa12009-07-07 03:45:17 +0200383 mutex_lock(&ifmgd->mtx);
384 if (!ifmgd->associated)
385 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200386
387 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200388 if (!sdata->local->ops->channel_switch) {
389 /* call "hw_config" only if doing sw channel switch */
390 ieee80211_hw_config(sdata->local,
391 IEEE80211_CONF_CHANGE_CHANNEL);
392 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200393
Johannes Berg77fdaa12009-07-07 03:45:17 +0200394 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100395 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200396
Johannes Bergcc32abd2009-05-15 11:52:31 +0200397 ieee80211_wake_queues_by_reason(&sdata->local->hw,
398 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200399 out:
400 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
401 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200402}
403
Johannes Berg5ce6e432010-05-11 16:20:57 +0200404void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
405{
406 struct ieee80211_sub_if_data *sdata;
407 struct ieee80211_if_managed *ifmgd;
408
409 sdata = vif_to_sdata(vif);
410 ifmgd = &sdata->u.mgd;
411
412 trace_api_chswitch_done(sdata, success);
413 if (!success) {
414 /*
415 * If the channel switch was not successful, stay
416 * around on the old channel. We currently lack
417 * good handling of this situation, possibly we
418 * should just drop the association.
419 */
420 sdata->local->csa_channel = sdata->local->oper_channel;
421 }
422
423 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
424}
425EXPORT_SYMBOL(ieee80211_chswitch_done);
426
Johannes Bergcc32abd2009-05-15 11:52:31 +0200427static void ieee80211_chswitch_timer(unsigned long data)
428{
429 struct ieee80211_sub_if_data *sdata =
430 (struct ieee80211_sub_if_data *) data;
431 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
432
Johannes Berg5bb644a2009-05-17 11:40:42 +0200433 if (sdata->local->quiescing) {
434 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
435 return;
436 }
437
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400438 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200439}
440
441void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
442 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200443 struct ieee80211_bss *bss,
444 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200445{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100446 struct cfg80211_bss *cbss =
447 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200448 struct ieee80211_channel *new_ch;
449 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900450 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
451 cbss->channel->band);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200452
Johannes Berg77fdaa12009-07-07 03:45:17 +0200453 ASSERT_MGD_MTX(ifmgd);
454
455 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200456 return;
457
Helmut Schaafbe9c422009-07-23 12:14:04 +0200458 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200459 return;
460
461 /* Disregard subsequent beacons if we are already running a timer
462 processing a CSA */
463
464 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
465 return;
466
467 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
468 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
469 return;
470
471 sdata->local->csa_channel = new_ch;
472
Johannes Berg5ce6e432010-05-11 16:20:57 +0200473 if (sdata->local->ops->channel_switch) {
474 /* use driver's channel switch callback */
475 struct ieee80211_channel_switch ch_switch;
476 memset(&ch_switch, 0, sizeof(ch_switch));
477 ch_switch.timestamp = timestamp;
478 if (sw_elem->mode) {
479 ch_switch.block_tx = true;
480 ieee80211_stop_queues_by_reason(&sdata->local->hw,
481 IEEE80211_QUEUE_STOP_REASON_CSA);
482 }
483 ch_switch.channel = new_ch;
484 ch_switch.count = sw_elem->count;
485 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
486 drv_channel_switch(sdata->local, &ch_switch);
487 return;
488 }
489
490 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200491 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400492 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200493 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700494 if (sw_elem->mode)
495 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200496 IEEE80211_QUEUE_STOP_REASON_CSA);
497 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
498 mod_timer(&ifmgd->chswitch_timer,
499 jiffies +
500 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100501 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200502 }
503}
504
505static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
506 u16 capab_info, u8 *pwr_constr_elem,
507 u8 pwr_constr_elem_len)
508{
509 struct ieee80211_conf *conf = &sdata->local->hw.conf;
510
511 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
512 return;
513
514 /* Power constraint IE length should be 1 octet */
515 if (pwr_constr_elem_len != 1)
516 return;
517
518 if ((*pwr_constr_elem <= conf->channel->max_power) &&
519 (*pwr_constr_elem != sdata->local->power_constr_level)) {
520 sdata->local->power_constr_level = *pwr_constr_elem;
521 ieee80211_hw_config(sdata->local, 0);
522 }
523}
524
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300525void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
526{
527 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
528 struct ieee80211_local *local = sdata->local;
529 struct ieee80211_conf *conf = &local->hw.conf;
530
531 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
532 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
533 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
534
535 local->disable_dynamic_ps = false;
536 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
537}
538EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
539
540void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
541{
542 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
543 struct ieee80211_local *local = sdata->local;
544 struct ieee80211_conf *conf = &local->hw.conf;
545
546 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
547 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
548 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
549
550 local->disable_dynamic_ps = true;
551 conf->dynamic_ps_timeout = 0;
552 del_timer_sync(&local->dynamic_ps_timer);
553 ieee80211_queue_work(&local->hw,
554 &local->dynamic_ps_enable_work);
555}
556EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
557
Johannes Berg965beda2009-04-16 13:17:24 +0200558/* powersave */
559static void ieee80211_enable_ps(struct ieee80211_local *local,
560 struct ieee80211_sub_if_data *sdata)
561{
562 struct ieee80211_conf *conf = &local->hw.conf;
563
Johannes Bergd5edaed2009-04-22 23:02:51 +0200564 /*
565 * If we are scanning right now then the parameters will
566 * take effect when scan finishes.
567 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200568 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200569 return;
570
Johannes Berg965beda2009-04-16 13:17:24 +0200571 if (conf->dynamic_ps_timeout > 0 &&
572 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
573 mod_timer(&local->dynamic_ps_timer, jiffies +
574 msecs_to_jiffies(conf->dynamic_ps_timeout));
575 } else {
576 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
577 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530578
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200579 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
580 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
581 return;
582
583 conf->flags |= IEEE80211_CONF_PS;
584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200585 }
586}
587
588static void ieee80211_change_ps(struct ieee80211_local *local)
589{
590 struct ieee80211_conf *conf = &local->hw.conf;
591
592 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200593 ieee80211_enable_ps(local, local->ps_sdata);
594 } else if (conf->flags & IEEE80211_CONF_PS) {
595 conf->flags &= ~IEEE80211_CONF_PS;
596 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
597 del_timer_sync(&local->dynamic_ps_timer);
598 cancel_work_sync(&local->dynamic_ps_enable_work);
599 }
600}
601
602/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200603void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200604{
605 struct ieee80211_sub_if_data *sdata, *found = NULL;
606 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300607 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +0200608
609 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
610 local->ps_sdata = NULL;
611 return;
612 }
613
Johannes Bergaf6b6372009-12-23 13:15:35 +0100614 if (!list_empty(&local->work_list)) {
615 local->ps_sdata = NULL;
616 goto change;
617 }
618
Johannes Berg965beda2009-04-16 13:17:24 +0200619 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100620 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200621 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +0530622 if (sdata->vif.type == NL80211_IFTYPE_AP) {
623 /* If an AP vif is found, then disable PS
624 * by setting the count to zero thereby setting
625 * ps_sdata to NULL.
626 */
627 count = 0;
628 break;
629 }
Johannes Berg965beda2009-04-16 13:17:24 +0200630 if (sdata->vif.type != NL80211_IFTYPE_STATION)
631 continue;
632 found = sdata;
633 count++;
634 }
635
Luis R. Rodriguez43f78532009-06-10 15:16:15 +0200636 if (count == 1 && found->u.mgd.powersave &&
Johannes Bergaf6b6372009-12-23 13:15:35 +0100637 found->u.mgd.associated &&
Johannes Berg56007a02010-01-26 14:19:52 +0100638 found->u.mgd.associated->beacon_ies &&
Johannes Bergb291ba12009-07-10 15:29:03 +0200639 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
640 IEEE80211_STA_CONNECTION_POLL))) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300641 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +0200642 s32 beaconint_us;
643
644 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +0200645 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +0200646
647 beaconint_us = ieee80211_tu_to_usec(
648 found->vif.bss_conf.beacon_int);
649
Juuso Oikarinenff616382010-06-09 09:51:52 +0300650 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300651 if (timeout < 0) {
652 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +0300653 * Go to full PSM if the user configures a very low
654 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +0200655 * The 2000 second value is there for compatibility
656 * until the PM_QOS_NETWORK_LATENCY is configured
657 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300658 */
Eliad Peller0ab82b02010-12-03 02:16:23 +0200659 if (latency > (1900 * USEC_PER_MSEC) &&
660 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300661 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +0300662 else
663 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300664 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300665 local->dynamic_ps_user_timeout = timeout;
666 if (!local->disable_dynamic_ps)
667 conf->dynamic_ps_timeout =
668 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300669
Johannes Berg04fe2032009-04-22 18:44:37 +0200670 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200671 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200672 } else {
Johannes Berg56007a02010-01-26 14:19:52 +0100673 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +0200674 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +0100675 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +0200676
Johannes Berg56007a02010-01-26 14:19:52 +0100677 bss = (void *)found->u.mgd.associated->priv;
678 dtimper = bss->dtim_period;
679
680 /* If the TIM IE is invalid, pretend the value is 1 */
681 if (!dtimper)
682 dtimper = 1;
683 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +0200684 maxslp = min_t(int, dtimper,
685 latency / beaconint_us);
686
Johannes Berg9ccebe62009-04-23 10:32:36 +0200687 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +0100688 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +0200689 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200690 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200691 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200692 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200693 }
Johannes Berg965beda2009-04-16 13:17:24 +0200694
Johannes Bergaf6b6372009-12-23 13:15:35 +0100695 change:
Johannes Berg965beda2009-04-16 13:17:24 +0200696 ieee80211_change_ps(local);
697}
698
699void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
700{
701 struct ieee80211_local *local =
702 container_of(work, struct ieee80211_local,
703 dynamic_ps_disable_work);
704
705 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
706 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
707 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
708 }
709
710 ieee80211_wake_queues_by_reason(&local->hw,
711 IEEE80211_QUEUE_STOP_REASON_PS);
712}
713
714void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
715{
716 struct ieee80211_local *local =
717 container_of(work, struct ieee80211_local,
718 dynamic_ps_enable_work);
719 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Vivek Natarajan375177b2010-02-09 14:50:28 +0530720 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200721
722 /* can only happen when PS was just disabled anyway */
723 if (!sdata)
724 return;
725
726 if (local->hw.conf.flags & IEEE80211_CONF_PS)
727 return;
728
Vivek Natarajan375177b2010-02-09 14:50:28 +0530729 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
730 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
Johannes Berg965beda2009-04-16 13:17:24 +0200731 ieee80211_send_nullfunc(local, sdata, 1);
732
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200733 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
734 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +0530735 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
736 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
737 local->hw.conf.flags |= IEEE80211_CONF_PS;
738 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
739 }
Johannes Berg965beda2009-04-16 13:17:24 +0200740}
741
742void ieee80211_dynamic_ps_timer(unsigned long data)
743{
744 struct ieee80211_local *local = (void *) data;
745
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700746 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200747 return;
748
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400749 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200750}
751
Johannes Berg60f8b392008-09-08 17:44:22 +0200752/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200753static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +0200754 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700755 u8 *wmm_param, size_t wmm_param_len)
756{
Jiri Bencf0706e82007-05-05 11:45:53 -0700757 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +0200758 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -0700759 size_t left;
760 int count;
Kalle Valoab133152010-01-12 10:42:31 +0200761 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700762
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200763 if (!local->ops->conf_tx)
764 return;
765
Johannes Bergaf6b6372009-12-23 13:15:35 +0100766 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +0200767 return;
768
769 if (!wmm_param)
770 return;
771
Jiri Bencf0706e82007-05-05 11:45:53 -0700772 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
773 return;
Kalle Valoab133152010-01-12 10:42:31 +0200774
775 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200776 uapsd_queues = local->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +0200777
Jiri Bencf0706e82007-05-05 11:45:53 -0700778 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100779 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700780 return;
Johannes Berg46900292009-02-15 12:44:28 +0100781 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700782
783 pos = wmm_param + 8;
784 left = wmm_param_len - 8;
785
786 memset(&params, 0, sizeof(params));
787
Jiri Bencf0706e82007-05-05 11:45:53 -0700788 local->wmm_acm = 0;
789 for (; left >= 4; left -= 4, pos += 4) {
790 int aci = (pos[0] >> 5) & 0x03;
791 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +0200792 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700793 int queue;
794
795 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200796 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200797 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200798 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200799 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +0200800 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
801 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700802 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200803 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200804 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200805 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200806 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +0200807 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
808 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700809 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200810 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200811 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200812 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200813 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +0200814 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
815 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700816 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200817 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700818 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200819 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200820 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200821 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +0200822 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
823 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700824 break;
825 }
826
827 params.aifs = pos[0] & 0x0f;
828 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
829 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200830 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +0200831 params.uapsd = uapsd;
832
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200833#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700834 wiphy_debug(local->hw.wiphy,
835 "WMM queue=%d aci=%d acm=%d aifs=%d "
836 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
837 queue, aci, acm,
838 params.aifs, params.cw_min, params.cw_max,
839 params.txop, params.uapsd);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100840#endif
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200841 if (drv_conf_tx(local, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700842 wiphy_debug(local->hw.wiphy,
843 "failed to set TX queue parameters for queue %d\n",
844 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700845 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200846
847 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +0200848 sdata->vif.bss_conf.qos = true;
849 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700850}
851
Johannes Berg7a5158e2008-10-08 10:59:33 +0200852static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
853 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200854{
Johannes Bergbda39332008-10-11 01:51:51 +0200855 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100856 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200857 bool use_protection;
858 bool use_short_preamble;
859 bool use_short_slot;
860
861 if (erp_valid) {
862 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
863 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
864 } else {
865 use_protection = false;
866 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
867 }
868
869 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +0100870 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
871 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +0200872
Johannes Berg471b3ef2007-12-28 14:32:58 +0100873 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100874 bss_conf->use_cts_prot = use_protection;
875 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200876 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200877
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200878 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200879 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100880 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200881 }
Daniel Draked9430a32007-07-27 15:43:24 +0200882
Johannes Berg7a5158e2008-10-08 10:59:33 +0200883 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200884 bss_conf->use_short_slot = use_short_slot;
885 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400886 }
887
888 return changed;
889}
890
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200891static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100892 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200893 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700894{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100895 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100896 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +0300897 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400898
Johannes Bergae5eb022008-10-14 16:58:37 +0200899 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200900 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +0300901 bss_conf->beacon_int = cbss->beacon_interval;
902 bss_conf->timestamp = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400903
Johannes Berg77fdaa12009-07-07 03:45:17 +0200904 bss_info_changed |= BSS_CHANGED_BEACON_INT;
905 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100906 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700907
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100908 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
909 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
910
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100911 sdata->u.mgd.associated = cbss;
912 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100913
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700914 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
915
Johannes Bergb291ba12009-07-10 15:29:03 +0200916 /* just to be sure */
917 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
918 IEEE80211_STA_BEACON_POLL);
919
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200920 ieee80211_led_assoc(local, 1);
921
Johannes Berge5b900d2010-07-29 16:08:55 +0200922 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
923 bss_conf->dtim_period = bss->dtim_period;
924 else
925 bss_conf->dtim_period = 0;
926
Juuso Oikarinen68542962010-06-09 13:43:26 +0300927 bss_conf->assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200928 /*
929 * For now just always ask the driver to update the basic rateset
930 * when we have associated, we aren't checking whether it actually
931 * changed or not.
932 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200933 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +0200934
935 /* And the BSSID changed - we're associated now */
936 bss_info_changed |= BSS_CHANGED_BSSID;
937
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200938 /* Tell the driver to monitor connection quality (if supported) */
939 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
Juuso Oikarinen68542962010-06-09 13:43:26 +0300940 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200941 bss_info_changed |= BSS_CHANGED_CQM;
942
Juuso Oikarinen68542962010-06-09 13:43:26 +0300943 /* Enable ARP filtering */
944 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
945 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
946 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
947 }
948
Johannes Bergae5eb022008-10-14 16:58:37 +0200949 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300950
Johannes Berg056508d2009-07-30 21:43:55 +0200951 mutex_lock(&local->iflist_mtx);
952 ieee80211_recalc_ps(local, -1);
Johannes Berg025e6be2010-10-05 10:41:47 +0200953 ieee80211_recalc_smps(local);
Johannes Berg056508d2009-07-30 21:43:55 +0200954 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +0200955
John W. Linville8a5b33f2010-01-06 15:39:39 -0500956 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200957 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700958}
959
Jouni Malinene69e95d2010-03-29 23:29:31 -0700960static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg53f73c02010-10-05 19:37:40 +0200961 bool remove_sta, bool tx)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300962{
Johannes Berg46900292009-02-15 12:44:28 +0100963 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300964 struct ieee80211_local *local = sdata->local;
965 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200966 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +0200967 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +0300968
Johannes Berg77fdaa12009-07-07 03:45:17 +0200969 ASSERT_MGD_MTX(ifmgd);
970
Johannes Bergb291ba12009-07-10 15:29:03 +0200971 if (WARN_ON(!ifmgd->associated))
972 return;
973
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100974 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +0200975
Johannes Berg77fdaa12009-07-07 03:45:17 +0200976 ifmgd->associated = NULL;
977 memset(ifmgd->bssid, 0, ETH_ALEN);
978
979 /*
980 * we need to commit the associated = NULL change because the
981 * scan code uses that to determine whether this iface should
982 * go to/wake up from powersave or not -- and could otherwise
983 * wake the queues erroneously.
984 */
985 smp_mb();
986
987 /*
988 * Thus, we can only afterwards stop the queues -- to account
989 * for the case where another CPU is finishing a scan at this
990 * time -- we don't want the scan code to enable queues.
991 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300992
John W. Linville8a5b33f2010-01-06 15:39:39 -0500993 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300994 netif_carrier_off(sdata->dev);
995
Johannes Berg2a419052010-06-10 10:21:29 +0200996 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +0100997 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +0530998 if (sta) {
Johannes Berg2a419052010-06-10 10:21:29 +0200999 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
Johannes Berg53f73c02010-10-05 19:37:40 +02001000 ieee80211_sta_tear_down_BA_sessions(sta, tx);
Sujith4cad6c72010-02-10 14:52:21 +05301001 }
Johannes Berg2a419052010-06-10 10:21:29 +02001002 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001003
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001004 changed |= ieee80211_reset_erp_info(sdata);
1005
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001006 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +02001007 changed |= BSS_CHANGED_ASSOC;
1008 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +02001009
Johannes Bergaa837e12009-05-07 16:16:24 +02001010 ieee80211_set_wmm_default(sdata);
1011
Johannes Berg47979382009-01-07 10:13:27 +01001012 /* channel(_type) changes are handled by ieee80211_hw_config */
Johannes Berg0aaffa92010-05-05 15:28:27 +02001013 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
Johannes Bergae5eb022008-10-14 16:58:37 +02001014
Johannes Berg413ad502009-05-08 21:21:06 +02001015 /* on the next assoc, re-program HT parameters */
1016 sdata->ht_opmode_valid = false;
1017
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301018 local->power_constr_level = 0;
1019
Kalle Valo520eb822008-12-18 23:35:27 +02001020 del_timer_sync(&local->dynamic_ps_timer);
1021 cancel_work_sync(&local->dynamic_ps_enable_work);
1022
Kalle Valoe0cb6862008-12-18 23:35:13 +02001023 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1024 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1025 config_changed |= IEEE80211_CONF_CHANGE_PS;
1026 }
1027
1028 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +02001029
Juuso Oikarinen68542962010-06-09 13:43:26 +03001030 /* Disable ARP filtering */
1031 if (sdata->vif.bss_conf.arp_filter_enabled) {
1032 sdata->vif.bss_conf.arp_filter_enabled = false;
1033 changed |= BSS_CHANGED_ARP_FILTER;
1034 }
1035
Johannes Berg0aaffa92010-05-05 15:28:27 +02001036 /* The BSSID (not really interesting) and HT changed */
1037 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001038 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001039
Jouni Malinene69e95d2010-03-29 23:29:31 -07001040 if (remove_sta)
1041 sta_info_destroy_addr(sdata, bssid);
Johannes Bergb9dcf712010-08-27 12:35:54 +02001042
1043 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1044 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1045 del_timer_sync(&sdata->u.mgd.timer);
1046 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001047}
Jiri Bencf0706e82007-05-05 11:45:53 -07001048
Kalle Valo3cf335d2009-03-22 21:57:06 +02001049void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1050 struct ieee80211_hdr *hdr)
1051{
1052 /*
1053 * We can postpone the mgd.timer whenever receiving unicast frames
1054 * from AP because we know that the connection is working both ways
1055 * at that time. But multicast frames (and hence also beacons) must
1056 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001057 * data idle periods for sending the periodic probe request to the
1058 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001059 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001060 if (is_multicast_ether_addr(hdr->addr1))
1061 return;
1062
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001063 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001064}
Jiri Bencf0706e82007-05-05 11:45:53 -07001065
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001066static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1067{
1068 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1069
1070 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1071 IEEE80211_STA_CONNECTION_POLL)))
1072 return;
1073
1074 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1075 IEEE80211_STA_BEACON_POLL);
1076 mutex_lock(&sdata->local->iflist_mtx);
1077 ieee80211_recalc_ps(sdata->local, -1);
1078 mutex_unlock(&sdata->local->iflist_mtx);
1079
1080 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1081 return;
1082
1083 /*
1084 * We've received a probe response, but are not sure whether
1085 * we have or will be receiving any beacons or data, so let's
1086 * schedule the timers again, just in case.
1087 */
1088 ieee80211_sta_reset_beacon_monitor(sdata);
1089
1090 mod_timer(&ifmgd->conn_mon_timer,
1091 round_jiffies_up(jiffies +
1092 IEEE80211_CONNECTION_IDLE_TIME));
1093}
1094
1095void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001096 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001097{
Felix Fietkau75706d02010-12-02 21:01:07 +01001098 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001099 return;
1100
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001101 if (ack)
1102 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001103
1104 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1105 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001106 if (ack)
1107 sdata->u.mgd.probe_send_count = 0;
1108 else
1109 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001110 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1111 }
1112}
1113
Maxim Levitskya43abf22009-07-31 18:54:12 +03001114static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1115{
1116 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1117 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001118 u8 *dst = ifmgd->associated->bssid;
1119 u8 unicast_limit = max(1, IEEE80211_MAX_PROBE_TRIES - 3);
1120
1121 /*
1122 * Try sending broadcast probe requests for the last three
1123 * probe requests after the first ones failed since some
1124 * buggy APs only support broadcast probe requests.
1125 */
1126 if (ifmgd->probe_send_count >= unicast_limit)
1127 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001128
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001129 /*
1130 * When the hardware reports an accurate Tx ACK status, it's
1131 * better to send a nullfunc frame instead of a probe request,
1132 * as it will kick us off the AP quickly if we aren't associated
1133 * anymore. The timeout will be reset if the frame is ACKed by
1134 * the AP.
1135 */
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001136 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1137 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001138 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001139 } else {
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001140 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1141 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0);
1142 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001143
1144 ifmgd->probe_send_count++;
1145 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1146 run_again(ifmgd, ifmgd->probe_timeout);
1147}
1148
Johannes Bergb291ba12009-07-10 15:29:03 +02001149static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1150 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001151{
Kalle Valo04de8382009-03-22 21:57:35 +02001152 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001153 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001154
Johannes Berg9607e6b2009-12-23 13:15:31 +01001155 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001156 return;
1157
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001158 if (sdata->local->scanning)
1159 return;
1160
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001161 if (sdata->local->tmp_channel)
1162 return;
1163
Johannes Berg77fdaa12009-07-07 03:45:17 +02001164 mutex_lock(&ifmgd->mtx);
1165
1166 if (!ifmgd->associated)
1167 goto out;
1168
Michael Buescha8604022009-04-15 14:41:22 -04001169#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001170 if (beacon && net_ratelimit())
1171 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001172 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001173#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001174
Johannes Bergb291ba12009-07-10 15:29:03 +02001175 /*
1176 * The driver/our work has already reported this event or the
1177 * connection monitoring has kicked in and we have already sent
1178 * a probe request. Or maybe the AP died and the driver keeps
1179 * reporting until we disassociate...
1180 *
1181 * In either case we have to ignore the current call to this
1182 * function (except for setting the correct probe reason bit)
1183 * because otherwise we would reset the timer every time and
1184 * never check whether we received a probe response!
1185 */
1186 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1187 IEEE80211_STA_CONNECTION_POLL))
1188 already = true;
1189
1190 if (beacon)
1191 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1192 else
1193 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1194
1195 if (already)
1196 goto out;
1197
Johannes Berg4e751842009-06-10 15:16:52 +02001198 mutex_lock(&sdata->local->iflist_mtx);
1199 ieee80211_recalc_ps(sdata->local, -1);
1200 mutex_unlock(&sdata->local->iflist_mtx);
1201
Maxim Levitskya43abf22009-07-31 18:54:12 +03001202 ifmgd->probe_send_count = 0;
1203 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001204 out:
1205 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001206}
1207
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001208struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1209 struct ieee80211_vif *vif)
1210{
1211 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1212 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1213 struct sk_buff *skb;
1214 const u8 *ssid;
1215
1216 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1217 return NULL;
1218
1219 ASSERT_MGD_MTX(ifmgd);
1220
1221 if (!ifmgd->associated)
1222 return NULL;
1223
1224 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1225 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
1226 ssid + 2, ssid[1], NULL, 0);
1227
1228 return skb;
1229}
1230EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1231
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001232static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1233{
1234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1235 struct ieee80211_local *local = sdata->local;
1236 u8 bssid[ETH_ALEN];
1237
1238 mutex_lock(&ifmgd->mtx);
1239 if (!ifmgd->associated) {
1240 mutex_unlock(&ifmgd->mtx);
1241 return;
1242 }
1243
1244 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1245
1246 printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid);
1247
Johannes Berg53f73c02010-10-05 19:37:40 +02001248 ieee80211_set_disassoc(sdata, true, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001249 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001250
1251 mutex_lock(&local->mtx);
1252 ieee80211_recalc_idle(local);
1253 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001254 /*
1255 * must be outside lock due to cfg80211,
1256 * but that's not a problem.
1257 */
1258 ieee80211_send_deauth_disassoc(sdata, bssid,
1259 IEEE80211_STYPE_DEAUTH,
1260 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001261 NULL, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001262}
1263
1264void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001265{
1266 struct ieee80211_sub_if_data *sdata =
1267 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001268 u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001269
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001270 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1271 __ieee80211_connection_loss(sdata);
1272 else
1273 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001274}
1275
Kalle Valo04de8382009-03-22 21:57:35 +02001276void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1277{
1278 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001279 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001280
Johannes Bergb5878a22010-04-07 16:48:40 +02001281 trace_api_beacon_loss(sdata);
1282
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001283 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1284 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001285}
1286EXPORT_SYMBOL(ieee80211_beacon_loss);
1287
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001288void ieee80211_connection_loss(struct ieee80211_vif *vif)
1289{
1290 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1291 struct ieee80211_hw *hw = &sdata->local->hw;
1292
Johannes Bergb5878a22010-04-07 16:48:40 +02001293 trace_api_connection_loss(sdata);
1294
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001295 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1296 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1297}
1298EXPORT_SYMBOL(ieee80211_connection_loss);
1299
1300
Johannes Berg77fdaa12009-07-07 03:45:17 +02001301static enum rx_mgmt_action __must_check
1302ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001303 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001304{
Johannes Berg46900292009-02-15 12:44:28 +01001305 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001306 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001307 u16 reason_code;
1308
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001309 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001310 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001311
Johannes Berg77fdaa12009-07-07 03:45:17 +02001312 ASSERT_MGD_MTX(ifmgd);
1313
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001314 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001315
1316 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1317
Johannes Berg77fdaa12009-07-07 03:45:17 +02001318 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001319 sdata->name, bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001320
Johannes Berg53f73c02010-10-05 19:37:40 +02001321 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001322 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001323 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001324 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001325
1326 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001327}
1328
1329
Johannes Berg77fdaa12009-07-07 03:45:17 +02001330static enum rx_mgmt_action __must_check
1331ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1332 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001333{
Johannes Berg46900292009-02-15 12:44:28 +01001334 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001335 u16 reason_code;
1336
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001337 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001338 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001339
Johannes Berg77fdaa12009-07-07 03:45:17 +02001340 ASSERT_MGD_MTX(ifmgd);
1341
1342 if (WARN_ON(!ifmgd->associated))
1343 return RX_MGMT_NONE;
1344
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001345 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001346 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001347
1348 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1349
Johannes Berg0ff71612009-09-26 14:45:41 +02001350 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001351 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001352
Johannes Berg53f73c02010-10-05 19:37:40 +02001353 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001354 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001355 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001356 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001357 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001358}
1359
1360
Johannes Bergaf6b6372009-12-23 13:15:35 +01001361static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1362 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001363{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001364 struct ieee80211_sub_if_data *sdata = wk->sdata;
Johannes Berg46900292009-02-15 12:44:28 +01001365 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001366 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001367 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001368 struct sta_info *sta;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001369 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001370 u8 *pos;
Johannes Berg881d9482009-01-21 15:13:48 +01001371 u32 rates, basic_rates;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001372 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001373 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001374 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02001375 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001376 int i, j, err;
1377 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001378 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001379
Johannes Bergaf6b6372009-12-23 13:15:35 +01001380 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07001381
Jiri Bencf0706e82007-05-05 11:45:53 -07001382 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001383 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07001384
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001385 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1386 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001387 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001388 aid &= ~(BIT(15) | BIT(14));
1389
Johannes Bergaf6b6372009-12-23 13:15:35 +01001390 pos = mgmt->u.assoc_resp.variable;
1391 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1392
Jiri Bencf0706e82007-05-05 11:45:53 -07001393 if (!elems.supp_rates) {
1394 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001395 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001396 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001397 }
1398
Johannes Berg46900292009-02-15 12:44:28 +01001399 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001400
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001401 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001402 if (!sta) {
Johannes Berg5d1ec852009-12-02 12:43:43 +01001403 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1404 " the AP\n", sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001405 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001406 }
1407
Johannes Berg5d1ec852009-12-02 12:43:43 +01001408 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1409 WLAN_STA_ASSOC_AP);
1410 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1411 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1412
Jiri Bencf0706e82007-05-05 11:45:53 -07001413 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001414 basic_rates = 0;
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001415 sband = local->hw.wiphy->bands[wk->chan->band];
Johannes Berg8318d782008-01-24 19:38:38 +01001416
Jiri Bencf0706e82007-05-05 11:45:53 -07001417 for (i = 0; i < elems.supp_rates_len; i++) {
1418 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001419 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001420
1421 if (rate > 110)
1422 have_higher_than_11mbit = true;
1423
1424 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001425 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001426 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001427 if (is_basic)
1428 basic_rates |= BIT(j);
1429 break;
1430 }
Johannes Berg8318d782008-01-24 19:38:38 +01001431 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001432 }
Johannes Berg8318d782008-01-24 19:38:38 +01001433
Jiri Bencf0706e82007-05-05 11:45:53 -07001434 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1435 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001436 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001437
1438 if (rate > 110)
1439 have_higher_than_11mbit = true;
1440
1441 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001442 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001443 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001444 if (is_basic)
1445 basic_rates |= BIT(j);
1446 break;
1447 }
Johannes Berg8318d782008-01-24 19:38:38 +01001448 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001449 }
Johannes Berg8318d782008-01-24 19:38:38 +01001450
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001451 sta->sta.supp_rates[wk->chan->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001452 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001453
1454 /* cf. IEEE 802.11 9.2.12 */
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001455 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
Johannes Berg8318d782008-01-24 19:38:38 +01001456 have_higher_than_11mbit)
1457 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1458 else
1459 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001460
Johannes Bergab1faea2009-07-01 21:41:17 +02001461 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001462 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001463 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001464
1465 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001466
Johannes Berg4b7679a2008-09-18 18:14:18 +02001467 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001468
Johannes Berg46900292009-02-15 12:44:28 +01001469 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001470 set_sta_flags(sta, WLAN_STA_MFP);
1471
Johannes Bergddf4ac52008-10-22 11:41:38 +02001472 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001473 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001474
Johannes Berg5d1ec852009-12-02 12:43:43 +01001475 err = sta_info_insert(sta);
1476 sta = NULL;
1477 if (err) {
1478 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1479 " the AP (error %d)\n", sdata->name, err);
Johannes Berg90be5612010-01-08 19:01:07 +01001480 return false;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001481 }
1482
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03001483 /*
1484 * Always handle WMM once after association regardless
1485 * of the first value the AP uses. Setting -1 here has
1486 * that effect because the AP values is an unsigned
1487 * 4-bit value.
1488 */
1489 ifmgd->wmm_last_param_set = -1;
1490
Johannes Bergddf4ac52008-10-22 11:41:38 +02001491 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02001492 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001493 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001494 else
1495 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001496
Johannes Berge4da8c32009-12-23 13:15:43 +01001497 local->oper_channel = wk->chan;
1498
Johannes Bergae5eb022008-10-14 16:58:37 +02001499 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergaf6b6372009-12-23 13:15:35 +01001500 (sdata->local->hw.queues >= 4) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001501 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001502 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001503 cbss->bssid, ap_ht_cap_flags);
Johannes Bergae5eb022008-10-14 16:58:37 +02001504
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001505 /* set AID and assoc capability,
1506 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001507 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001508 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001509 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001510
Kalle Valo15b7b062009-03-22 21:57:14 +02001511 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01001512 * If we're using 4-addr mode, let the AP know that we're
1513 * doing so, so that it can create the STA VLAN on its side
1514 */
1515 if (ifmgd->use_4addr)
1516 ieee80211_send_4addr_nullfunc(local, sdata);
1517
1518 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001519 * Start timer to probe the connection to the AP now.
1520 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001521 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001522 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001523 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001524
Johannes Bergaf6b6372009-12-23 13:15:35 +01001525 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001526}
1527
1528
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001529static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001530 struct ieee80211_mgmt *mgmt,
1531 size_t len,
1532 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001533 struct ieee802_11_elems *elems,
1534 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001535{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001536 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001537 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001538 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001539 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01001540 bool need_ps = false;
1541
1542 if (sdata->u.mgd.associated) {
1543 bss = (void *)sdata->u.mgd.associated->priv;
1544 /* not previously set so we may need to recalc */
1545 need_ps = !bss->dtim_period;
1546 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001547
Johannes Berg5bda6172008-09-08 11:05:10 +02001548 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001549 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
1550 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02001551 else
1552 freq = rx_status->freq;
1553
1554 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1555
1556 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1557 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001558
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001559 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001560 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001561 if (bss)
1562 ieee80211_rx_bss_put(local, bss);
1563
1564 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001565 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001566
Johannes Berg56007a02010-01-26 14:19:52 +01001567 if (need_ps) {
1568 mutex_lock(&local->iflist_mtx);
1569 ieee80211_recalc_ps(local, -1);
1570 mutex_unlock(&local->iflist_mtx);
1571 }
1572
Sujithc481ec92009-01-06 09:28:37 +05301573 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001574 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001575 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301576 struct ieee80211_channel_sw_ie *sw_elem =
1577 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001578 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1579 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05301580 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001581}
1582
1583
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001584static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01001585 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001586{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001587 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02001588 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001589 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1590 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001591 struct ieee802_11_elems elems;
1592
Kalle Valo15b7b062009-03-22 21:57:14 +02001593 ifmgd = &sdata->u.mgd;
1594
Johannes Berg77fdaa12009-07-07 03:45:17 +02001595 ASSERT_MGD_MTX(ifmgd);
1596
Johannes Berg47846c92009-11-25 17:46:19 +01001597 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001598 return; /* ignore ProbeResp to foreign address */
1599
Ester Kummerae6a44e2008-06-27 18:54:48 +03001600 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1601 if (baselen > len)
1602 return;
1603
1604 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1605 &elems);
1606
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001607 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001608
Johannes Berg77fdaa12009-07-07 03:45:17 +02001609 if (ifmgd->associated &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001610 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
1611 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001612}
1613
Johannes Bergd91f36d2009-04-16 13:17:26 +02001614/*
1615 * This is the canonical list of information elements we care about,
1616 * the filter code also gives us all changes to the Microsoft OUI
1617 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1618 *
1619 * We implement beacon filtering in software since that means we can
1620 * avoid processing the frame here and in cfg80211, and userspace
1621 * will not be able to tell whether the hardware supports it or not.
1622 *
1623 * XXX: This list needs to be dynamic -- userspace needs to be able to
1624 * add items it requires. It also needs to be able to tell us to
1625 * look out for other vendor IEs.
1626 */
1627static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001628 (1ULL << WLAN_EID_COUNTRY) |
1629 (1ULL << WLAN_EID_ERP_INFO) |
1630 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1631 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1632 (1ULL << WLAN_EID_HT_CAPABILITY) |
1633 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001634
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001635static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001636 struct ieee80211_mgmt *mgmt,
1637 size_t len,
1638 struct ieee80211_rx_status *rx_status)
1639{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001640 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001641 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001642 size_t baselen;
1643 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001644 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001645 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001646 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001647 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001648 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001649 u8 *bssid;
1650
1651 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e82007-05-05 11:45:53 -07001652
Ester Kummerae6a44e2008-06-27 18:54:48 +03001653 /* Process beacon from the current BSS */
1654 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1655 if (baselen > len)
1656 return;
1657
Johannes Bergd91f36d2009-04-16 13:17:26 +02001658 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001659 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001660
Johannes Bergb291ba12009-07-10 15:29:03 +02001661 /*
1662 * We might have received a number of frames, among them a
1663 * disassoc frame and a beacon...
1664 */
1665 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001666 return;
1667
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001668 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001669
Johannes Bergb291ba12009-07-10 15:29:03 +02001670 /*
1671 * And in theory even frames from a different AP we were just
1672 * associated to a split-second ago!
1673 */
1674 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001675 return;
1676
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001677 /* Track average RSSI from the Beacon frames of the current AP */
1678 ifmgd->last_beacon_signal = rx_status->signal;
1679 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1680 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03001681 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001682 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03001683 ifmgd->count_beacon_signal = 1;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001684 } else {
1685 ifmgd->ave_beacon_signal =
1686 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1687 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1688 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03001689 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001690 }
1691 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03001692 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001693 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1694 int sig = ifmgd->ave_beacon_signal / 16;
1695 int last_event = ifmgd->last_cqm_event_signal;
1696 int thold = bss_conf->cqm_rssi_thold;
1697 int hyst = bss_conf->cqm_rssi_hyst;
1698 if (sig < thold &&
1699 (last_event == 0 || sig < last_event - hyst)) {
1700 ifmgd->last_cqm_event_signal = sig;
1701 ieee80211_cqm_rssi_notify(
1702 &sdata->vif,
1703 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1704 GFP_KERNEL);
1705 } else if (sig > thold &&
1706 (last_event == 0 || sig > last_event + hyst)) {
1707 ifmgd->last_cqm_event_signal = sig;
1708 ieee80211_cqm_rssi_notify(
1709 &sdata->vif,
1710 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1711 GFP_KERNEL);
1712 }
1713 }
1714
Johannes Bergb291ba12009-07-10 15:29:03 +02001715 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001716#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1717 if (net_ratelimit()) {
1718 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001719 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001720 }
1721#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001722 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001723 mutex_lock(&local->iflist_mtx);
1724 ieee80211_recalc_ps(local, -1);
1725 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001726 }
1727
Johannes Bergb291ba12009-07-10 15:29:03 +02001728 /*
1729 * Push the beacon loss detection into the future since
1730 * we are processing a beacon from the AP just now.
1731 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001732 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001733
Johannes Bergd91f36d2009-04-16 13:17:26 +02001734 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1735 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1736 len - baselen, &elems,
1737 care_about_ies, ncrc);
1738
1739 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001740 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1741 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001742
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001743 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
Jouni Malinen30196672009-05-19 17:01:43 +03001744 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1745 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001746
Johannes Berg4ced3f72010-07-19 16:39:04 +02001747 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03001748 elems.wmm_param_len);
1749 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001750
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301751 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001752 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001753 if (local->hw.conf.dynamic_ps_timeout > 0) {
1754 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1755 ieee80211_hw_config(local,
1756 IEEE80211_CONF_CHANGE_PS);
1757 ieee80211_send_nullfunc(local, sdata, 0);
1758 } else {
1759 local->pspolling = true;
1760
1761 /*
1762 * Here is assumed that the driver will be
1763 * able to send ps-poll frame and receive a
1764 * response even though power save mode is
1765 * enabled, but some drivers might require
1766 * to disable power save here. This needs
1767 * to be investigated.
1768 */
1769 ieee80211_send_pspoll(local, sdata);
1770 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001771 }
1772 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001773
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001774 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03001775 return;
1776 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001777 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03001778
Johannes Berg7a5158e2008-10-08 10:59:33 +02001779 if (elems.erp_info && elems.erp_info_len >= 1) {
1780 erp_valid = true;
1781 erp_value = elems.erp_info[0];
1782 } else {
1783 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001784 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001785 changed |= ieee80211_handle_bss_capability(sdata,
1786 le16_to_cpu(mgmt->u.beacon.capab_info),
1787 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001788
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001789
Vasanthakumar Thiagarajan53d6f81c2009-02-11 22:18:49 +05301790 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001791 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001792 struct sta_info *sta;
1793 struct ieee80211_supported_band *sband;
1794 u16 ap_ht_cap_flags;
1795
1796 rcu_read_lock();
1797
Johannes Bergabe60632009-11-25 17:46:18 +01001798 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001799 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001800 rcu_read_unlock();
1801 return;
1802 }
1803
1804 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1805
1806 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1807 elems.ht_cap_elem, &sta->sta.ht_cap);
1808
1809 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1810
1811 rcu_read_unlock();
1812
1813 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001814 bssid, ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001815 }
1816
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001817 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001818 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301819 /* TODO: IBSS also needs this */
1820 if (elems.pwr_constr_elem)
1821 ieee80211_handle_pwr_constr(sdata,
1822 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1823 elems.pwr_constr_elem,
1824 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001825 }
1826
Johannes Berg471b3ef2007-12-28 14:32:58 +01001827 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001828}
1829
Johannes Berg1fa57d02010-06-10 10:21:32 +02001830void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1831 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001832{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001833 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001834 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001835 struct ieee80211_mgmt *mgmt;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001836 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001837 u16 fc;
1838
Jiri Bencf0706e82007-05-05 11:45:53 -07001839 rx_status = (struct ieee80211_rx_status *) skb->cb;
1840 mgmt = (struct ieee80211_mgmt *) skb->data;
1841 fc = le16_to_cpu(mgmt->frame_control);
1842
Johannes Berg77fdaa12009-07-07 03:45:17 +02001843 mutex_lock(&ifmgd->mtx);
1844
1845 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001846 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001847 switch (fc & IEEE80211_FCTL_STYPE) {
1848 case IEEE80211_STYPE_BEACON:
1849 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1850 rx_status);
1851 break;
1852 case IEEE80211_STYPE_PROBE_RESP:
Johannes Bergaf6b6372009-12-23 13:15:35 +01001853 ieee80211_rx_mgmt_probe_resp(sdata, skb);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001854 break;
1855 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01001856 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001857 break;
1858 case IEEE80211_STYPE_DISASSOC:
1859 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1860 break;
1861 case IEEE80211_STYPE_ACTION:
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001862 switch (mgmt->u.action.category) {
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001863 case WLAN_CATEGORY_SPECTRUM_MGMT:
1864 ieee80211_sta_process_chanswitch(sdata,
1865 &mgmt->u.action.u.chan_switch.sw_elem,
1866 (void *)ifmgd->associated->priv,
1867 rx_status->mactime);
1868 break;
1869 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02001870 }
1871 mutex_unlock(&ifmgd->mtx);
1872
1873 switch (rma) {
1874 case RX_MGMT_NONE:
1875 /* no action */
1876 break;
1877 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02001878 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001879 break;
1880 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470612009-10-13 13:28:13 +02001881 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001882 break;
1883 default:
1884 WARN(1, "unexpected: %d", rma);
1885 }
Johannes Berg36b3a622010-06-10 10:21:33 +02001886 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001887 }
1888
Johannes Berg77fdaa12009-07-07 03:45:17 +02001889 mutex_unlock(&ifmgd->mtx);
1890
Johannes Berg63f170e2009-12-23 13:15:33 +01001891 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
Johannes Bergb054b742010-06-07 21:50:07 +02001892 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
1893 struct ieee80211_local *local = sdata->local;
1894 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001895
Johannes Berga1699b72010-07-30 16:46:07 +02001896 mutex_lock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001897 list_for_each_entry(wk, &local->work_list, list) {
1898 if (wk->sdata != sdata)
1899 continue;
1900
Johannes Berge5b900d2010-07-29 16:08:55 +02001901 if (wk->type != IEEE80211_WORK_ASSOC &&
1902 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Bergb054b742010-06-07 21:50:07 +02001903 continue;
1904
1905 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
1906 continue;
1907 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
1908 continue;
1909
1910 /*
1911 * Printing the message only here means we can't
1912 * spuriously print it, but it also means that it
1913 * won't be printed when the frame comes in before
1914 * we even tried to associate or in similar cases.
1915 *
1916 * Ultimately, I suspect cfg80211 should print the
1917 * messages instead.
1918 */
1919 printk(KERN_DEBUG
1920 "%s: deauthenticated from %pM (Reason: %u)\n",
1921 sdata->name, mgmt->bssid,
1922 le16_to_cpu(mgmt->u.deauth.reason_code));
1923
1924 list_del_rcu(&wk->list);
1925 free_work(wk);
1926 break;
1927 }
Johannes Berga1699b72010-07-30 16:46:07 +02001928 mutex_unlock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001929
Johannes Berg77fdaa12009-07-07 03:45:17 +02001930 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Bergb054b742010-06-07 21:50:07 +02001931 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001932}
1933
Johannes Berg9c6bd792008-09-11 00:01:52 +02001934static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001935{
1936 struct ieee80211_sub_if_data *sdata =
1937 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001938 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001939 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001940
Johannes Berg5bb644a2009-05-17 11:40:42 +02001941 if (local->quiescing) {
1942 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1943 return;
1944 }
1945
Johannes Berg64592c82010-06-10 10:21:31 +02001946 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001947}
1948
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001949static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
1950 u8 *bssid)
1951{
1952 struct ieee80211_local *local = sdata->local;
1953 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1954
1955 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1956 IEEE80211_STA_BEACON_POLL);
1957
1958 ieee80211_set_disassoc(sdata, true, true);
1959 mutex_unlock(&ifmgd->mtx);
1960 mutex_lock(&local->mtx);
1961 ieee80211_recalc_idle(local);
1962 mutex_unlock(&local->mtx);
1963 /*
1964 * must be outside lock due to cfg80211,
1965 * but that's not a problem.
1966 */
1967 ieee80211_send_deauth_disassoc(sdata, bssid,
1968 IEEE80211_STYPE_DEAUTH,
1969 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
1970 NULL, true);
1971 mutex_lock(&ifmgd->mtx);
1972}
1973
Johannes Berg1fa57d02010-06-10 10:21:32 +02001974void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02001975{
Johannes Berg60f8b392008-09-08 17:44:22 +02001976 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02001977 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001978
Johannes Berg77fdaa12009-07-07 03:45:17 +02001979 /* then process the rest of the work */
1980 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02001981
Johannes Bergb291ba12009-07-10 15:29:03 +02001982 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1983 IEEE80211_STA_CONNECTION_POLL) &&
1984 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03001985 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01001986 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001987
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001988 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001989
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01001990 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1991 max_tries = IEEE80211_MAX_NULLFUNC_TRIES;
1992 else
1993 max_tries = IEEE80211_MAX_PROBE_TRIES;
1994
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001995 /* ACK received for nullfunc probing frame */
1996 if (!ifmgd->probe_send_count)
1997 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001998 else if (ifmgd->nullfunc_failed) {
1999 if (ifmgd->probe_send_count < max_tries) {
2000#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2001 wiphy_debug(local->hw.wiphy,
2002 "%s: No ack for nullfunc frame to"
Ben Greearbfc31df2011-01-14 09:32:18 -08002003 " AP %pM, try %d/%i\n",
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002004 sdata->name, bssid,
Ben Greearbfc31df2011-01-14 09:32:18 -08002005 ifmgd->probe_send_count, max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002006#endif
2007 ieee80211_mgd_probe_ap_send(sdata);
2008 } else {
2009#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2010 wiphy_debug(local->hw.wiphy,
2011 "%s: No ack for nullfunc frame to"
2012 " AP %pM, disconnecting.\n",
Felix Fietkauc658e5d2010-12-07 04:40:18 +01002013 sdata->name, bssid);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002014#endif
2015 ieee80211_sta_connection_lost(sdata, bssid);
2016 }
2017 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002018 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002019 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2020#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2021 wiphy_debug(local->hw.wiphy,
2022 "%s: Failed to send nullfunc to AP %pM"
2023 " after %dms, disconnecting.\n",
2024 sdata->name,
2025 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2026#endif
2027 ieee80211_sta_connection_lost(sdata, bssid);
2028 } else if (ifmgd->probe_send_count < max_tries) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002029#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Ben Greearb38afa82010-10-07 16:12:06 -07002030 wiphy_debug(local->hw.wiphy,
2031 "%s: No probe response from AP %pM"
Ben Greearbfc31df2011-01-14 09:32:18 -08002032 " after %dms, try %d/%i\n",
Ben Greearb38afa82010-10-07 16:12:06 -07002033 sdata->name,
2034 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ,
Ben Greearbfc31df2011-01-14 09:32:18 -08002035 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002036#endif
2037 ieee80211_mgd_probe_ap_send(sdata);
2038 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002039 /*
2040 * We actually lost the connection ... or did we?
2041 * Let's make sure!
2042 */
Ben Greearb38afa82010-10-07 16:12:06 -07002043 wiphy_debug(local->hw.wiphy,
2044 "%s: No probe response from AP %pM"
2045 " after %dms, disconnecting.\n",
2046 sdata->name,
2047 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002048
2049 ieee80211_sta_connection_lost(sdata, bssid);
Johannes Bergb291ba12009-07-10 15:29:03 +02002050 }
2051 }
2052
Johannes Berg77fdaa12009-07-07 03:45:17 +02002053 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002054}
Johannes Berg0a51b272008-09-08 17:44:25 +02002055
Johannes Bergb291ba12009-07-10 15:29:03 +02002056static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2057{
2058 struct ieee80211_sub_if_data *sdata =
2059 (struct ieee80211_sub_if_data *) data;
2060 struct ieee80211_local *local = sdata->local;
2061
2062 if (local->quiescing)
2063 return;
2064
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002065 ieee80211_queue_work(&sdata->local->hw,
2066 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002067}
2068
2069static void ieee80211_sta_conn_mon_timer(unsigned long data)
2070{
2071 struct ieee80211_sub_if_data *sdata =
2072 (struct ieee80211_sub_if_data *) data;
2073 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2074 struct ieee80211_local *local = sdata->local;
2075
2076 if (local->quiescing)
2077 return;
2078
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002079 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002080}
2081
2082static void ieee80211_sta_monitor_work(struct work_struct *work)
2083{
2084 struct ieee80211_sub_if_data *sdata =
2085 container_of(work, struct ieee80211_sub_if_data,
2086 u.mgd.monitor_work);
2087
2088 ieee80211_mgd_probe_ap(sdata, false);
2089}
2090
Johannes Berga1678f82008-09-11 00:01:47 +02002091static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2092{
Kalle Vaload935682009-04-19 08:47:19 +03002093 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002094 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2095 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002096
Johannes Bergb291ba12009-07-10 15:29:03 +02002097 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002098 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02002099 &sdata->u.mgd.monitor_work);
2100 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02002101 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03002102 }
Johannes Berga1678f82008-09-11 00:01:47 +02002103}
2104
Johannes Berg5bb644a2009-05-17 11:40:42 +02002105#ifdef CONFIG_PM
2106void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2107{
2108 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2109
2110 /*
2111 * we need to use atomic bitops for the running bits
2112 * only because both timers might fire at the same
2113 * time -- the code here is properly synchronised.
2114 */
2115
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002116 cancel_work_sync(&ifmgd->request_smps_work);
2117
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002118 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002119 if (del_timer_sync(&ifmgd->timer))
2120 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2121
2122 cancel_work_sync(&ifmgd->chswitch_work);
2123 if (del_timer_sync(&ifmgd->chswitch_timer))
2124 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002125
2126 cancel_work_sync(&ifmgd->monitor_work);
2127 /* these will just be re-established on connection */
2128 del_timer_sync(&ifmgd->conn_mon_timer);
2129 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002130}
2131
2132void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2133{
2134 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2135
2136 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2137 add_timer(&ifmgd->timer);
2138 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2139 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01002140 ieee80211_sta_reset_beacon_monitor(sdata);
Felix Fietkau46090972010-11-23 20:28:03 +01002141 ieee80211_restart_sta_timer(sdata);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002142}
2143#endif
2144
Johannes Berg9c6bd792008-09-11 00:01:52 +02002145/* interface setup */
2146void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2147{
Johannes Berg46900292009-02-15 12:44:28 +01002148 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002149
Johannes Berg46900292009-02-15 12:44:28 +01002150 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002151 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01002152 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002153 INIT_WORK(&ifmgd->beacon_connection_loss_work,
2154 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002155 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01002156 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002157 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002158 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2159 (unsigned long) sdata);
2160 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2161 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002162 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302163 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002164
Johannes Bergab1faea2009-07-01 21:41:17 +02002165 ifmgd->flags = 0;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002166
Johannes Berg77fdaa12009-07-07 03:45:17 +02002167 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01002168
2169 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2170 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2171 else
2172 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002173}
2174
2175/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002176void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2177{
2178 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002179
2180 /* Restart STA timers */
2181 rcu_read_lock();
2182 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2183 ieee80211_restart_sta_timer(sdata);
2184 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002185}
Johannes Berg10f644a2009-04-16 13:17:25 +02002186
2187int ieee80211_max_network_latency(struct notifier_block *nb,
2188 unsigned long data, void *dummy)
2189{
2190 s32 latency_usec = (s32) data;
2191 struct ieee80211_local *local =
2192 container_of(nb, struct ieee80211_local,
2193 network_latency_notifier);
2194
2195 mutex_lock(&local->iflist_mtx);
2196 ieee80211_recalc_ps(local, latency_usec);
2197 mutex_unlock(&local->iflist_mtx);
2198
2199 return 0;
2200}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002201
2202/* config hooks */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002203static enum work_done_result
2204ieee80211_probe_auth_done(struct ieee80211_work *wk,
2205 struct sk_buff *skb)
2206{
2207 if (!skb) {
2208 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2209 return WORK_DONE_DESTROY;
2210 }
2211
2212 if (wk->type == IEEE80211_WORK_AUTH) {
2213 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2214 return WORK_DONE_DESTROY;
2215 }
2216
2217 mutex_lock(&wk->sdata->u.mgd.mtx);
2218 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2219 mutex_unlock(&wk->sdata->u.mgd.mtx);
2220
2221 wk->type = IEEE80211_WORK_AUTH;
2222 wk->probe_auth.tries = 0;
2223 return WORK_DONE_REQUEUE;
2224}
2225
Johannes Berg77fdaa12009-07-07 03:45:17 +02002226int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2227 struct cfg80211_auth_request *req)
2228{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002229 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002230 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002231 u16 auth_alg;
2232
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002233 if (req->local_state_change)
2234 return 0; /* no need to update mac80211 state */
2235
Johannes Berg77fdaa12009-07-07 03:45:17 +02002236 switch (req->auth_type) {
2237 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2238 auth_alg = WLAN_AUTH_OPEN;
2239 break;
2240 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg9dca9c42010-07-21 10:09:25 +02002241 if (IS_ERR(sdata->local->wep_tx_tfm))
2242 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002243 auth_alg = WLAN_AUTH_SHARED_KEY;
2244 break;
2245 case NL80211_AUTHTYPE_FT:
2246 auth_alg = WLAN_AUTH_FT;
2247 break;
2248 case NL80211_AUTHTYPE_NETWORK_EAP:
2249 auth_alg = WLAN_AUTH_LEAP;
2250 break;
2251 default:
2252 return -EOPNOTSUPP;
2253 }
2254
2255 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2256 if (!wk)
2257 return -ENOMEM;
2258
Joe Perches5e124bd2010-01-08 22:33:38 -08002259 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002260
2261 if (req->ie && req->ie_len) {
2262 memcpy(wk->ie, req->ie, req->ie_len);
2263 wk->ie_len = req->ie_len;
2264 }
2265
Johannes Bergfffd0932009-07-08 14:22:54 +02002266 if (req->key && req->key_len) {
Johannes Bergaf6b6372009-12-23 13:15:35 +01002267 wk->probe_auth.key_len = req->key_len;
2268 wk->probe_auth.key_idx = req->key_idx;
2269 memcpy(wk->probe_auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002270 }
2271
Johannes Berg77fdaa12009-07-07 03:45:17 +02002272 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002273 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2274 wk->probe_auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002275
Johannes Bergaf6b6372009-12-23 13:15:35 +01002276 wk->probe_auth.algorithm = auth_alg;
2277 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +01002278
Johannes Berg070bb542010-02-03 13:57:46 +01002279 /* if we already have a probe, don't probe again */
2280 if (req->bss->proberesp_ies)
2281 wk->type = IEEE80211_WORK_AUTH;
2282 else
2283 wk->type = IEEE80211_WORK_DIRECT_PROBE;
Johannes Bergf679f652009-12-23 13:15:34 +01002284 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002285 wk->sdata = sdata;
2286 wk->done = ieee80211_probe_auth_done;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002287
Johannes Bergaf6b6372009-12-23 13:15:35 +01002288 ieee80211_add_work(wk);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002289 return 0;
2290}
2291
Johannes Bergaf6b6372009-12-23 13:15:35 +01002292static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2293 struct sk_buff *skb)
2294{
2295 struct ieee80211_mgmt *mgmt;
Johannes Berge5b900d2010-07-29 16:08:55 +02002296 struct ieee80211_rx_status *rx_status;
2297 struct ieee802_11_elems elems;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002298 u16 status;
2299
2300 if (!skb) {
2301 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2302 return WORK_DONE_DESTROY;
2303 }
2304
Johannes Berge5b900d2010-07-29 16:08:55 +02002305 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2306 mutex_lock(&wk->sdata->u.mgd.mtx);
2307 rx_status = (void *) skb->cb;
2308 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2309 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2310 &elems, true);
2311 mutex_unlock(&wk->sdata->u.mgd.mtx);
2312
2313 wk->type = IEEE80211_WORK_ASSOC;
2314 /* not really done yet */
2315 return WORK_DONE_REQUEUE;
2316 }
2317
Johannes Bergaf6b6372009-12-23 13:15:35 +01002318 mgmt = (void *)skb->data;
2319 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2320
2321 if (status == WLAN_STATUS_SUCCESS) {
2322 mutex_lock(&wk->sdata->u.mgd.mtx);
2323 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2324 mutex_unlock(&wk->sdata->u.mgd.mtx);
2325 /* oops -- internal error -- send timeout for now */
2326 cfg80211_send_assoc_timeout(wk->sdata->dev,
2327 wk->filter_ta);
2328 return WORK_DONE_DESTROY;
2329 }
Juuso Oikarinen68542962010-06-09 13:43:26 +03002330
2331 mutex_unlock(&wk->sdata->u.mgd.mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002332 }
2333
2334 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2335 return WORK_DONE_DESTROY;
2336}
2337
Johannes Berg77fdaa12009-07-07 03:45:17 +02002338int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2339 struct cfg80211_assoc_request *req)
2340{
2341 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002342 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Bergf679f652009-12-23 13:15:34 +01002343 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002344 const u8 *ssid;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002345 int i;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002346
2347 mutex_lock(&ifmgd->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002348 if (ifmgd->associated) {
Jouni Malinen9c87ba62010-02-28 12:13:46 +02002349 if (!req->prev_bssid ||
2350 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2351 ETH_ALEN)) {
2352 /*
2353 * We are already associated and the request was not a
2354 * reassociation request from the current BSS, so
2355 * reject it.
2356 */
2357 mutex_unlock(&ifmgd->mtx);
2358 return -EALREADY;
2359 }
2360
2361 /* Trying to reassociate - clear previous association state */
Johannes Berg53f73c02010-10-05 19:37:40 +02002362 ieee80211_set_disassoc(sdata, true, false);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002363 }
2364 mutex_unlock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002365
Johannes Berg63f170e2009-12-23 13:15:33 +01002366 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002367 if (!wk)
2368 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002369
Johannes Berg77fdaa12009-07-07 03:45:17 +02002370 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05302371 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002372
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002373 ifmgd->beacon_crc_valid = false;
2374
Johannes Berg77fdaa12009-07-07 03:45:17 +02002375 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2376 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2377 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2378 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2379 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2380
Johannes Berg77fdaa12009-07-07 03:45:17 +02002381
2382 if (req->ie && req->ie_len) {
2383 memcpy(wk->ie, req->ie, req->ie_len);
2384 wk->ie_len = req->ie_len;
2385 } else
2386 wk->ie_len = 0;
2387
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002388 wk->assoc.bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01002389
Johannes Bergaf6b6372009-12-23 13:15:35 +01002390 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +01002391
Johannes Bergaf6b6372009-12-23 13:15:35 +01002392 /* new association always uses requested smps mode */
2393 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2394 if (ifmgd->powersave)
2395 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2396 else
2397 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2398 } else
2399 ifmgd->ap_smps = ifmgd->req_smps;
2400
2401 wk->assoc.smps = ifmgd->ap_smps;
Johannes Berg77c81442009-12-23 13:15:37 +01002402 /*
2403 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2404 * We still associate in non-HT mode (11a/b/g) if any one of these
2405 * ciphers is configured as pairwise.
2406 * We can set this to true for non-11n hardware, that'll be checked
2407 * separately along with the peer capabilities.
2408 */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002409 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
Johannes Bergf679f652009-12-23 13:15:34 +01002410 wk->assoc.capability = req->bss->capability;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002411 wk->assoc.wmm_used = bss->wmm_used;
2412 wk->assoc.supp_rates = bss->supp_rates;
2413 wk->assoc.supp_rates_len = bss->supp_rates_len;
Johannes Bergf679f652009-12-23 13:15:34 +01002414 wk->assoc.ht_information_ie =
2415 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002416
Kalle Valoab133152010-01-12 10:42:31 +02002417 if (bss->wmm_used && bss->uapsd_supported &&
2418 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2419 wk->assoc.uapsd_used = true;
2420 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2421 } else {
2422 wk->assoc.uapsd_used = false;
2423 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2424 }
2425
Johannes Berg63f170e2009-12-23 13:15:33 +01002426 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002427 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2428 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002429
Johannes Berg77fdaa12009-07-07 03:45:17 +02002430 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002431 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002432
Johannes Bergf679f652009-12-23 13:15:34 +01002433 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002434 wk->sdata = sdata;
2435 wk->done = ieee80211_assoc_done;
Johannes Berge5b900d2010-07-29 16:08:55 +02002436 if (!bss->dtim_period &&
2437 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2438 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2439 else
2440 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002441
2442 if (req->use_mfp) {
2443 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2444 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2445 } else {
2446 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2447 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2448 }
2449
2450 if (req->crypto.control_port)
2451 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2452 else
2453 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2454
Johannes Berga621fa42010-08-27 14:26:54 +03002455 sdata->control_port_protocol = req->crypto.control_port_ethertype;
2456 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2457
Johannes Bergaf6b6372009-12-23 13:15:35 +01002458 ieee80211_add_work(wk);
2459 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002460}
2461
2462int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +02002463 struct cfg80211_deauth_request *req,
2464 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002465{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002466 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002467 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002468 struct ieee80211_work *wk;
Jouni Malinen05e48e82010-06-14 11:55:56 -07002469 u8 bssid[ETH_ALEN];
2470 bool assoc_bss = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002471
Johannes Berg77fdaa12009-07-07 03:45:17 +02002472 mutex_lock(&ifmgd->mtx);
2473
Jouni Malinen05e48e82010-06-14 11:55:56 -07002474 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002475 if (ifmgd->associated == req->bss) {
Johannes Berg53f73c02010-10-05 19:37:40 +02002476 ieee80211_set_disassoc(sdata, false, true);
Johannes Berga58ce432009-11-19 12:45:42 +01002477 mutex_unlock(&ifmgd->mtx);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002478 assoc_bss = true;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002479 } else {
2480 bool not_auth_yet = false;
Johannes Berga58ce432009-11-19 12:45:42 +01002481
Johannes Bergaf6b6372009-12-23 13:15:35 +01002482 mutex_unlock(&ifmgd->mtx);
2483
Johannes Berga1699b72010-07-30 16:46:07 +02002484 mutex_lock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002485 list_for_each_entry(wk, &local->work_list, list) {
Johannes Berg29165e42010-02-06 15:20:13 +01002486 if (wk->sdata != sdata)
Johannes Bergaf6b6372009-12-23 13:15:35 +01002487 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002488
2489 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
Reinette Chatre79733a82010-05-04 16:04:49 -07002490 wk->type != IEEE80211_WORK_AUTH &&
Johannes Berge5b900d2010-07-29 16:08:55 +02002491 wk->type != IEEE80211_WORK_ASSOC &&
2492 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Berg29165e42010-02-06 15:20:13 +01002493 continue;
2494
Johannes Bergaf6b6372009-12-23 13:15:35 +01002495 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2496 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002497
2498 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2499 list_del_rcu(&wk->list);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002500 free_work(wk);
2501 break;
2502 }
Johannes Berga1699b72010-07-30 16:46:07 +02002503 mutex_unlock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002504
2505 /*
2506 * If somebody requests authentication and we haven't
2507 * sent out an auth frame yet there's no need to send
2508 * out a deauth frame either. If the state was PROBE,
2509 * then this is the case. If it's AUTH we have sent a
2510 * frame, and if it's IDLE we have completed the auth
2511 * process already.
2512 */
2513 if (not_auth_yet) {
2514 __cfg80211_auth_canceled(sdata->dev, bssid);
2515 return 0;
2516 }
2517 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002518
Johannes Berg0ff71612009-09-26 14:45:41 +02002519 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002520 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002521
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002522 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2523 req->reason_code, cookie,
2524 !req->local_state_change);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002525 if (assoc_bss)
2526 sta_info_destroy_addr(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002527
Johannes Berg7da7cc12010-08-05 17:02:38 +02002528 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002529 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002530 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002531
Johannes Berg77fdaa12009-07-07 03:45:17 +02002532 return 0;
2533}
2534
2535int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503dd2009-07-07 03:56:11 +02002536 struct cfg80211_disassoc_request *req,
2537 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002538{
2539 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07002540 u8 bssid[ETH_ALEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002541
Johannes Berg77fdaa12009-07-07 03:45:17 +02002542 mutex_lock(&ifmgd->mtx);
2543
Johannes Berg8d8b2612009-07-25 11:58:36 +02002544 /*
2545 * cfg80211 should catch this ... but it's racy since
2546 * we can receive a disassoc frame, process it, hand it
2547 * to cfg80211 while that's in a locked section already
2548 * trying to tell us that the user wants to disconnect.
2549 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002550 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002551 mutex_unlock(&ifmgd->mtx);
2552 return -ENOLINK;
2553 }
2554
Johannes Berg0ff71612009-09-26 14:45:41 +02002555 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002556 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002557
Jouni Malinene69e95d2010-03-29 23:29:31 -07002558 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg53f73c02010-10-05 19:37:40 +02002559 ieee80211_set_disassoc(sdata, false, true);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002560
2561 mutex_unlock(&ifmgd->mtx);
2562
2563 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503dd2009-07-07 03:56:11 +02002564 IEEE80211_STYPE_DISASSOC, req->reason_code,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002565 cookie, !req->local_state_change);
Jouni Malinene69e95d2010-03-29 23:29:31 -07002566 sta_info_destroy_addr(sdata, bssid);
Johannes Bergbc83b682009-11-29 12:19:06 +01002567
Johannes Berg7da7cc12010-08-05 17:02:38 +02002568 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002569 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002570 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002571
Johannes Berg77fdaa12009-07-07 03:45:17 +02002572 return 0;
2573}
Jouni Malinen026331c2010-02-15 12:53:10 +02002574
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002575void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2576 enum nl80211_cqm_rssi_threshold_event rssi_event,
2577 gfp_t gfp)
2578{
2579 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2580
Johannes Bergb5878a22010-04-07 16:48:40 +02002581 trace_api_cqm_rssi_notify(sdata, rssi_event);
2582
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002583 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2584}
2585EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);