blob: dfa752e5520b511db097d64b328fccd8ceb952ce [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;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200164 u16 ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200165 bool enable_ht = true;
166 enum nl80211_channel_type prev_chantype;
Johannes Bergd5522e02009-03-30 13:23:35 +0200167 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
168
169 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
170
Johannes Berg0aaffa92010-05-05 15:28:27 +0200171 prev_chantype = sdata->vif.bss_conf.channel_type;
172
Johannes Bergd5522e02009-03-30 13:23:35 +0200173 /* HT is not supported */
174 if (!sband->ht_cap.ht_supported)
175 enable_ht = false;
176
177 /* check that channel matches the right operating channel */
178 if (local->hw.conf.channel->center_freq !=
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900179 ieee80211_channel_to_frequency(hti->control_chan, sband->band))
Johannes Bergd5522e02009-03-30 13:23:35 +0200180 enable_ht = false;
181
182 if (enable_ht) {
183 channel_type = NL80211_CHAN_HT20;
184
185 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
186 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
187 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
188 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
189 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400190 if (!(local->hw.conf.channel->flags &
191 IEEE80211_CHAN_NO_HT40PLUS))
192 channel_type = NL80211_CHAN_HT40PLUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200193 break;
194 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
Luis R. Rodriguez768777e2009-05-02 00:37:19 -0400195 if (!(local->hw.conf.channel->flags &
196 IEEE80211_CHAN_NO_HT40MINUS))
197 channel_type = NL80211_CHAN_HT40MINUS;
Johannes Bergd5522e02009-03-30 13:23:35 +0200198 break;
199 }
200 }
201 }
202
Reinette Chatrefe6f2122010-04-19 10:46:31 -0700203 if (local->tmp_channel)
204 local->tmp_channel_type = channel_type;
Johannes Bergd5522e02009-03-30 13:23:35 +0200205
Johannes Berg0aaffa92010-05-05 15:28:27 +0200206 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
207 /* can only fail due to HT40+/- mismatch */
208 channel_type = NL80211_CHAN_HT20;
209 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
210 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200211
Johannes Berg0aaffa92010-05-05 15:28:27 +0200212 /* channel_type change automatically detected */
213 ieee80211_hw_config(local, 0);
214
215 if (prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200216 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100217 sta = sta_info_get(sdata, bssid);
Johannes Bergd5522e02009-03-30 13:23:35 +0200218 if (sta)
219 rate_control_rate_update(local, sband, sta,
Sujith4fa00432010-03-01 14:42:57 +0530220 IEEE80211_RC_HT_CHANGED,
Johannes Berg0aaffa92010-05-05 15:28:27 +0200221 channel_type);
Johannes Bergd5522e02009-03-30 13:23:35 +0200222 rcu_read_unlock();
Johannes Berg0aaffa92010-05-05 15:28:27 +0200223 }
Johannes Bergd5522e02009-03-30 13:23:35 +0200224
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200225 ht_opmode = le16_to_cpu(hti->operation_mode);
Johannes Bergd5522e02009-03-30 13:23:35 +0200226
227 /* if bss configuration changed store the new one */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200228 if (sdata->ht_opmode_valid != enable_ht ||
229 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
230 prev_chantype != channel_type) {
Johannes Bergd5522e02009-03-30 13:23:35 +0200231 changed |= BSS_CHANGED_HT;
Johannes Berg9ed6bcc2009-05-08 20:47:39 +0200232 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
Johannes Berg0aaffa92010-05-05 15:28:27 +0200233 sdata->ht_opmode_valid = enable_ht;
Johannes Bergd5522e02009-03-30 13:23:35 +0200234 }
235
236 return changed;
237}
238
Johannes Berg9c6bd792008-09-11 00:01:52 +0200239/* frame sending functions */
240
Johannes Bergef422bc2008-09-09 10:58:25 +0200241static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +0200242 const u8 *bssid, u16 stype, u16 reason,
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300243 void *cookie, bool send_frame)
Johannes Berg9ac19a92008-09-09 10:57:09 +0200244{
245 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100246 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg9ac19a92008-09-09 10:57:09 +0200247 struct sk_buff *skb;
248 struct ieee80211_mgmt *mgmt;
249
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200250 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
Johannes Berg9ac19a92008-09-09 10:57:09 +0200251 if (!skb) {
Johannes Bergef422bc2008-09-09 10:58:25 +0200252 printk(KERN_DEBUG "%s: failed to allocate buffer for "
Johannes Berg47846c92009-11-25 17:46:19 +0100253 "deauth/disassoc frame\n", sdata->name);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200254 return;
255 }
256 skb_reserve(skb, local->hw.extra_tx_headroom);
257
258 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
259 memset(mgmt, 0, 24);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200260 memcpy(mgmt->da, bssid, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100261 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200262 memcpy(mgmt->bssid, bssid, ETH_ALEN);
Johannes Bergef422bc2008-09-09 10:58:25 +0200263 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200264 skb_put(skb, 2);
Johannes Bergef422bc2008-09-09 10:58:25 +0200265 /* u.deauth.reason_code == u.disassoc.reason_code */
Johannes Berg9ac19a92008-09-09 10:57:09 +0200266 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
267
Jouni Malinen53b46b82009-03-27 20:53:56 +0200268 if (stype == IEEE80211_STYPE_DEAUTH)
Holger Schurigce470612009-10-13 13:28:13 +0200269 if (cookie)
270 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
271 else
272 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Jouni Malinen53b46b82009-03-27 20:53:56 +0200273 else
Holger Schurigce470612009-10-13 13:28:13 +0200274 if (cookie)
275 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
276 else
277 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg62ae67b2009-11-18 18:42:05 +0100278 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
279 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300280
281 if (send_frame)
282 ieee80211_tx_skb(sdata, skb);
283 else
284 kfree_skb(skb);
Johannes Berg9ac19a92008-09-09 10:57:09 +0200285}
286
Kalle Valo572e0012009-02-10 17:09:31 +0200287void ieee80211_send_pspoll(struct ieee80211_local *local,
288 struct ieee80211_sub_if_data *sdata)
289{
Kalle Valo572e0012009-02-10 17:09:31 +0200290 struct ieee80211_pspoll *pspoll;
291 struct sk_buff *skb;
Kalle Valo572e0012009-02-10 17:09:31 +0200292
Kalle Valod8cd1892010-01-05 20:16:26 +0200293 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
294 if (!skb)
Kalle Valo572e0012009-02-10 17:09:31 +0200295 return;
Kalle Valo572e0012009-02-10 17:09:31 +0200296
Kalle Valod8cd1892010-01-05 20:16:26 +0200297 pspoll = (struct ieee80211_pspoll *) skb->data;
298 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Kalle Valo572e0012009-02-10 17:09:31 +0200299
Johannes Berg62ae67b2009-11-18 18:42:05 +0100300 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
301 ieee80211_tx_skb(sdata, skb);
Kalle Valo572e0012009-02-10 17:09:31 +0200302}
303
Johannes Berg965beda2009-04-16 13:17:24 +0200304void ieee80211_send_nullfunc(struct ieee80211_local *local,
305 struct ieee80211_sub_if_data *sdata,
306 int powersave)
307{
308 struct sk_buff *skb;
Kalle Valod8cd1892010-01-05 20:16:26 +0200309 struct ieee80211_hdr_3addr *nullfunc;
Johannes Berg965beda2009-04-16 13:17:24 +0200310
Kalle Valod8cd1892010-01-05 20:16:26 +0200311 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
312 if (!skb)
Johannes Berg965beda2009-04-16 13:17:24 +0200313 return;
314
Kalle Valod8cd1892010-01-05 20:16:26 +0200315 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
Johannes Berg965beda2009-04-16 13:17:24 +0200316 if (powersave)
Kalle Valod8cd1892010-01-05 20:16:26 +0200317 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
Johannes Berg965beda2009-04-16 13:17:24 +0200318
Johannes Berg62ae67b2009-11-18 18:42:05 +0100319 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
320 ieee80211_tx_skb(sdata, skb);
Johannes Berg965beda2009-04-16 13:17:24 +0200321}
322
Felix Fietkaud5242152010-01-08 18:06:26 +0100323static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
324 struct ieee80211_sub_if_data *sdata)
325{
326 struct sk_buff *skb;
327 struct ieee80211_hdr *nullfunc;
328 __le16 fc;
329
330 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
331 return;
332
333 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
334 if (!skb) {
335 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
336 "nullfunc frame\n", sdata->name);
337 return;
338 }
339 skb_reserve(skb, local->hw.extra_tx_headroom);
340
341 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
342 memset(nullfunc, 0, 30);
343 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
344 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
345 nullfunc->frame_control = fc;
346 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
347 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
348 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
349 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
350
351 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
352 ieee80211_tx_skb(sdata, skb);
353}
354
Johannes Bergcc32abd2009-05-15 11:52:31 +0200355/* spectrum management related things */
356static void ieee80211_chswitch_work(struct work_struct *work)
357{
358 struct ieee80211_sub_if_data *sdata =
359 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200360 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
361
Johannes Berg9607e6b2009-12-23 13:15:31 +0100362 if (!ieee80211_sdata_running(sdata))
Johannes Bergcc32abd2009-05-15 11:52:31 +0200363 return;
364
Johannes Berg77fdaa12009-07-07 03:45:17 +0200365 mutex_lock(&ifmgd->mtx);
366 if (!ifmgd->associated)
367 goto out;
Johannes Bergcc32abd2009-05-15 11:52:31 +0200368
369 sdata->local->oper_channel = sdata->local->csa_channel;
Johannes Berg5ce6e432010-05-11 16:20:57 +0200370 if (!sdata->local->ops->channel_switch) {
371 /* call "hw_config" only if doing sw channel switch */
372 ieee80211_hw_config(sdata->local,
373 IEEE80211_CONF_CHANGE_CHANNEL);
374 }
Johannes Bergcc32abd2009-05-15 11:52:31 +0200375
Johannes Berg77fdaa12009-07-07 03:45:17 +0200376 /* XXX: shouldn't really modify cfg80211-owned data! */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100377 ifmgd->associated->channel = sdata->local->oper_channel;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200378
Johannes Bergcc32abd2009-05-15 11:52:31 +0200379 ieee80211_wake_queues_by_reason(&sdata->local->hw,
380 IEEE80211_QUEUE_STOP_REASON_CSA);
Johannes Berg77fdaa12009-07-07 03:45:17 +0200381 out:
382 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
383 mutex_unlock(&ifmgd->mtx);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200384}
385
Johannes Berg5ce6e432010-05-11 16:20:57 +0200386void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
387{
388 struct ieee80211_sub_if_data *sdata;
389 struct ieee80211_if_managed *ifmgd;
390
391 sdata = vif_to_sdata(vif);
392 ifmgd = &sdata->u.mgd;
393
394 trace_api_chswitch_done(sdata, success);
395 if (!success) {
396 /*
397 * If the channel switch was not successful, stay
398 * around on the old channel. We currently lack
399 * good handling of this situation, possibly we
400 * should just drop the association.
401 */
402 sdata->local->csa_channel = sdata->local->oper_channel;
403 }
404
405 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
406}
407EXPORT_SYMBOL(ieee80211_chswitch_done);
408
Johannes Bergcc32abd2009-05-15 11:52:31 +0200409static void ieee80211_chswitch_timer(unsigned long data)
410{
411 struct ieee80211_sub_if_data *sdata =
412 (struct ieee80211_sub_if_data *) data;
413 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
414
Johannes Berg5bb644a2009-05-17 11:40:42 +0200415 if (sdata->local->quiescing) {
416 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
417 return;
418 }
419
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400420 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200421}
422
423void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
424 struct ieee80211_channel_sw_ie *sw_elem,
Johannes Berg5ce6e432010-05-11 16:20:57 +0200425 struct ieee80211_bss *bss,
426 u64 timestamp)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200427{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100428 struct cfg80211_bss *cbss =
429 container_of((void *)bss, struct cfg80211_bss, priv);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200430 struct ieee80211_channel *new_ch;
431 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Bruno Randolf59eb21a2011-01-17 13:37:28 +0900432 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
433 cbss->channel->band);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200434
Johannes Berg77fdaa12009-07-07 03:45:17 +0200435 ASSERT_MGD_MTX(ifmgd);
436
437 if (!ifmgd->associated)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200438 return;
439
Helmut Schaafbe9c422009-07-23 12:14:04 +0200440 if (sdata->local->scanning)
Johannes Bergcc32abd2009-05-15 11:52:31 +0200441 return;
442
443 /* Disregard subsequent beacons if we are already running a timer
444 processing a CSA */
445
446 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
447 return;
448
449 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
450 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
451 return;
452
453 sdata->local->csa_channel = new_ch;
454
Johannes Berg5ce6e432010-05-11 16:20:57 +0200455 if (sdata->local->ops->channel_switch) {
456 /* use driver's channel switch callback */
457 struct ieee80211_channel_switch ch_switch;
458 memset(&ch_switch, 0, sizeof(ch_switch));
459 ch_switch.timestamp = timestamp;
460 if (sw_elem->mode) {
461 ch_switch.block_tx = true;
462 ieee80211_stop_queues_by_reason(&sdata->local->hw,
463 IEEE80211_QUEUE_STOP_REASON_CSA);
464 }
465 ch_switch.channel = new_ch;
466 ch_switch.count = sw_elem->count;
467 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
468 drv_channel_switch(sdata->local, &ch_switch);
469 return;
470 }
471
472 /* channel switch handled in software */
Johannes Bergcc32abd2009-05-15 11:52:31 +0200473 if (sw_elem->count <= 1) {
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400474 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
Johannes Bergcc32abd2009-05-15 11:52:31 +0200475 } else {
Wey-Yi Guy9feaddc2010-05-05 20:34:02 -0700476 if (sw_elem->mode)
477 ieee80211_stop_queues_by_reason(&sdata->local->hw,
Johannes Bergcc32abd2009-05-15 11:52:31 +0200478 IEEE80211_QUEUE_STOP_REASON_CSA);
479 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
480 mod_timer(&ifmgd->chswitch_timer,
481 jiffies +
482 msecs_to_jiffies(sw_elem->count *
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100483 cbss->beacon_interval));
Johannes Bergcc32abd2009-05-15 11:52:31 +0200484 }
485}
486
487static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
488 u16 capab_info, u8 *pwr_constr_elem,
489 u8 pwr_constr_elem_len)
490{
491 struct ieee80211_conf *conf = &sdata->local->hw.conf;
492
493 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
494 return;
495
496 /* Power constraint IE length should be 1 octet */
497 if (pwr_constr_elem_len != 1)
498 return;
499
500 if ((*pwr_constr_elem <= conf->channel->max_power) &&
501 (*pwr_constr_elem != sdata->local->power_constr_level)) {
502 sdata->local->power_constr_level = *pwr_constr_elem;
503 ieee80211_hw_config(sdata->local, 0);
504 }
505}
506
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300507void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
508{
509 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
510 struct ieee80211_local *local = sdata->local;
511 struct ieee80211_conf *conf = &local->hw.conf;
512
513 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
514 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
515 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
516
517 local->disable_dynamic_ps = false;
518 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
519}
520EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
521
522void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
523{
524 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
525 struct ieee80211_local *local = sdata->local;
526 struct ieee80211_conf *conf = &local->hw.conf;
527
528 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
529 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
530 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
531
532 local->disable_dynamic_ps = true;
533 conf->dynamic_ps_timeout = 0;
534 del_timer_sync(&local->dynamic_ps_timer);
535 ieee80211_queue_work(&local->hw,
536 &local->dynamic_ps_enable_work);
537}
538EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
539
Johannes Berg965beda2009-04-16 13:17:24 +0200540/* powersave */
541static void ieee80211_enable_ps(struct ieee80211_local *local,
542 struct ieee80211_sub_if_data *sdata)
543{
544 struct ieee80211_conf *conf = &local->hw.conf;
545
Johannes Bergd5edaed2009-04-22 23:02:51 +0200546 /*
547 * If we are scanning right now then the parameters will
548 * take effect when scan finishes.
549 */
Helmut Schaafbe9c422009-07-23 12:14:04 +0200550 if (local->scanning)
Johannes Bergd5edaed2009-04-22 23:02:51 +0200551 return;
552
Johannes Berg965beda2009-04-16 13:17:24 +0200553 if (conf->dynamic_ps_timeout > 0 &&
554 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
555 mod_timer(&local->dynamic_ps_timer, jiffies +
556 msecs_to_jiffies(conf->dynamic_ps_timeout));
557 } else {
558 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
559 ieee80211_send_nullfunc(local, sdata, 1);
Vivek Natarajan375177b2010-02-09 14:50:28 +0530560
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200561 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
562 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
563 return;
564
565 conf->flags |= IEEE80211_CONF_PS;
566 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Johannes Berg965beda2009-04-16 13:17:24 +0200567 }
568}
569
570static void ieee80211_change_ps(struct ieee80211_local *local)
571{
572 struct ieee80211_conf *conf = &local->hw.conf;
573
574 if (local->ps_sdata) {
Johannes Berg965beda2009-04-16 13:17:24 +0200575 ieee80211_enable_ps(local, local->ps_sdata);
576 } else if (conf->flags & IEEE80211_CONF_PS) {
577 conf->flags &= ~IEEE80211_CONF_PS;
578 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
579 del_timer_sync(&local->dynamic_ps_timer);
580 cancel_work_sync(&local->dynamic_ps_enable_work);
581 }
582}
583
584/* need to hold RTNL or interface lock */
Johannes Berg10f644a2009-04-16 13:17:25 +0200585void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
Johannes Berg965beda2009-04-16 13:17:24 +0200586{
587 struct ieee80211_sub_if_data *sdata, *found = NULL;
588 int count = 0;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300589 int timeout;
Johannes Berg965beda2009-04-16 13:17:24 +0200590
591 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
592 local->ps_sdata = NULL;
593 return;
594 }
595
Johannes Bergaf6b6372009-12-23 13:15:35 +0100596 if (!list_empty(&local->work_list)) {
597 local->ps_sdata = NULL;
598 goto change;
599 }
600
Johannes Berg965beda2009-04-16 13:17:24 +0200601 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg9607e6b2009-12-23 13:15:31 +0100602 if (!ieee80211_sdata_running(sdata))
Johannes Berg965beda2009-04-16 13:17:24 +0200603 continue;
Rajkumar Manoharan8c7914d2011-02-01 00:28:59 +0530604 if (sdata->vif.type == NL80211_IFTYPE_AP) {
605 /* If an AP vif is found, then disable PS
606 * by setting the count to zero thereby setting
607 * ps_sdata to NULL.
608 */
609 count = 0;
610 break;
611 }
Johannes Berg965beda2009-04-16 13:17:24 +0200612 if (sdata->vif.type != NL80211_IFTYPE_STATION)
613 continue;
614 found = sdata;
615 count++;
616 }
617
Luis R. Rodriguez43f78532009-06-10 15:16:15 +0200618 if (count == 1 && found->u.mgd.powersave &&
Johannes Bergaf6b6372009-12-23 13:15:35 +0100619 found->u.mgd.associated &&
Johannes Berg56007a02010-01-26 14:19:52 +0100620 found->u.mgd.associated->beacon_ies &&
Johannes Bergb291ba12009-07-10 15:29:03 +0200621 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
622 IEEE80211_STA_CONNECTION_POLL))) {
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300623 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg10f644a2009-04-16 13:17:25 +0200624 s32 beaconint_us;
625
626 if (latency < 0)
Mark Grossed771342010-05-06 01:59:26 +0200627 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
Johannes Berg10f644a2009-04-16 13:17:25 +0200628
629 beaconint_us = ieee80211_tu_to_usec(
630 found->vif.bss_conf.beacon_int);
631
Juuso Oikarinenff616382010-06-09 09:51:52 +0300632 timeout = local->dynamic_ps_forced_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300633 if (timeout < 0) {
634 /*
Juuso Oikarinenff616382010-06-09 09:51:52 +0300635 * Go to full PSM if the user configures a very low
636 * latency requirement.
Eliad Peller0ab82b02010-12-03 02:16:23 +0200637 * The 2000 second value is there for compatibility
638 * until the PM_QOS_NETWORK_LATENCY is configured
639 * with real values.
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300640 */
Eliad Peller0ab82b02010-12-03 02:16:23 +0200641 if (latency > (1900 * USEC_PER_MSEC) &&
642 latency != (2000 * USEC_PER_SEC))
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300643 timeout = 0;
Juuso Oikarinenff616382010-06-09 09:51:52 +0300644 else
645 timeout = 100;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300646 }
Juuso Oikarinenf90754c2010-06-21 08:59:39 +0300647 local->dynamic_ps_user_timeout = timeout;
648 if (!local->disable_dynamic_ps)
649 conf->dynamic_ps_timeout =
650 local->dynamic_ps_user_timeout;
Juuso Oikarinen195e2942010-04-27 12:47:40 +0300651
Johannes Berg04fe2032009-04-22 18:44:37 +0200652 if (beaconint_us > latency) {
Johannes Berg10f644a2009-04-16 13:17:25 +0200653 local->ps_sdata = NULL;
Johannes Berg04fe2032009-04-22 18:44:37 +0200654 } else {
Johannes Berg56007a02010-01-26 14:19:52 +0100655 struct ieee80211_bss *bss;
Johannes Berg04fe2032009-04-22 18:44:37 +0200656 int maxslp = 1;
Johannes Berg56007a02010-01-26 14:19:52 +0100657 u8 dtimper;
Johannes Berg04fe2032009-04-22 18:44:37 +0200658
Johannes Berg56007a02010-01-26 14:19:52 +0100659 bss = (void *)found->u.mgd.associated->priv;
660 dtimper = bss->dtim_period;
661
662 /* If the TIM IE is invalid, pretend the value is 1 */
663 if (!dtimper)
664 dtimper = 1;
665 else if (dtimper > 1)
Johannes Berg04fe2032009-04-22 18:44:37 +0200666 maxslp = min_t(int, dtimper,
667 latency / beaconint_us);
668
Johannes Berg9ccebe62009-04-23 10:32:36 +0200669 local->hw.conf.max_sleep_period = maxslp;
Johannes Berg56007a02010-01-26 14:19:52 +0100670 local->hw.conf.ps_dtim_period = dtimper;
Johannes Berg10f644a2009-04-16 13:17:25 +0200671 local->ps_sdata = found;
Johannes Berg04fe2032009-04-22 18:44:37 +0200672 }
Johannes Berg10f644a2009-04-16 13:17:25 +0200673 } else {
Johannes Berg965beda2009-04-16 13:17:24 +0200674 local->ps_sdata = NULL;
Johannes Berg10f644a2009-04-16 13:17:25 +0200675 }
Johannes Berg965beda2009-04-16 13:17:24 +0200676
Johannes Bergaf6b6372009-12-23 13:15:35 +0100677 change:
Johannes Berg965beda2009-04-16 13:17:24 +0200678 ieee80211_change_ps(local);
679}
680
681void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
682{
683 struct ieee80211_local *local =
684 container_of(work, struct ieee80211_local,
685 dynamic_ps_disable_work);
686
687 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
688 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
689 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
690 }
691
692 ieee80211_wake_queues_by_reason(&local->hw,
693 IEEE80211_QUEUE_STOP_REASON_PS);
694}
695
696void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
697{
698 struct ieee80211_local *local =
699 container_of(work, struct ieee80211_local,
700 dynamic_ps_enable_work);
701 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
Vivek Natarajan375177b2010-02-09 14:50:28 +0530702 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg965beda2009-04-16 13:17:24 +0200703
704 /* can only happen when PS was just disabled anyway */
705 if (!sdata)
706 return;
707
708 if (local->hw.conf.flags & IEEE80211_CONF_PS)
709 return;
710
Vivek Natarajan375177b2010-02-09 14:50:28 +0530711 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
712 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
Johannes Berg965beda2009-04-16 13:17:24 +0200713 ieee80211_send_nullfunc(local, sdata, 1);
714
Juuso Oikarinen2a130522010-03-09 14:25:02 +0200715 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
716 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
Vivek Natarajan375177b2010-02-09 14:50:28 +0530717 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
718 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
719 local->hw.conf.flags |= IEEE80211_CONF_PS;
720 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
721 }
Johannes Berg965beda2009-04-16 13:17:24 +0200722}
723
724void ieee80211_dynamic_ps_timer(unsigned long data)
725{
726 struct ieee80211_local *local = (void *) data;
727
Luis R. Rodriguez78f1a8b2009-07-27 08:38:25 -0700728 if (local->quiescing || local->suspended)
Johannes Berg5bb644a2009-05-17 11:40:42 +0200729 return;
730
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -0400731 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
Johannes Berg965beda2009-04-16 13:17:24 +0200732}
733
Johannes Berg60f8b392008-09-08 17:44:22 +0200734/* MLME */
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200735static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
Johannes Berg4ced3f72010-07-19 16:39:04 +0200736 struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -0700737 u8 *wmm_param, size_t wmm_param_len)
738{
Jiri Bencf0706e82007-05-05 11:45:53 -0700739 struct ieee80211_tx_queue_params params;
Johannes Berg4ced3f72010-07-19 16:39:04 +0200740 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -0700741 size_t left;
742 int count;
Kalle Valoab133152010-01-12 10:42:31 +0200743 u8 *pos, uapsd_queues = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700744
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200745 if (!local->ops->conf_tx)
746 return;
747
Johannes Bergaf6b6372009-12-23 13:15:35 +0100748 if (local->hw.queues < 4)
Johannes Berg3434fbd2008-05-03 00:59:37 +0200749 return;
750
751 if (!wmm_param)
752 return;
753
Jiri Bencf0706e82007-05-05 11:45:53 -0700754 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
755 return;
Kalle Valoab133152010-01-12 10:42:31 +0200756
757 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
Kalle Valo50ae0cf2010-01-12 10:42:39 +0200758 uapsd_queues = local->uapsd_queues;
Kalle Valoab133152010-01-12 10:42:31 +0200759
Jiri Bencf0706e82007-05-05 11:45:53 -0700760 count = wmm_param[6] & 0x0f;
Johannes Berg46900292009-02-15 12:44:28 +0100761 if (count == ifmgd->wmm_last_param_set)
Jiri Bencf0706e82007-05-05 11:45:53 -0700762 return;
Johannes Berg46900292009-02-15 12:44:28 +0100763 ifmgd->wmm_last_param_set = count;
Jiri Bencf0706e82007-05-05 11:45:53 -0700764
765 pos = wmm_param + 8;
766 left = wmm_param_len - 8;
767
768 memset(&params, 0, sizeof(params));
769
Jiri Bencf0706e82007-05-05 11:45:53 -0700770 local->wmm_acm = 0;
771 for (; left >= 4; left -= 4, pos += 4) {
772 int aci = (pos[0] >> 5) & 0x03;
773 int acm = (pos[0] >> 4) & 0x01;
Kalle Valoab133152010-01-12 10:42:31 +0200774 bool uapsd = false;
Jiri Bencf0706e82007-05-05 11:45:53 -0700775 int queue;
776
777 switch (aci) {
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200778 case 1: /* AC_BK */
Johannes Berge100bb62008-04-30 18:51:21 +0200779 queue = 3;
Johannes Berg988c0f72008-04-17 19:21:22 +0200780 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200781 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
Kalle Valoab133152010-01-12 10:42:31 +0200782 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
783 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700784 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200785 case 2: /* AC_VI */
Johannes Berge100bb62008-04-30 18:51:21 +0200786 queue = 1;
Johannes Berg988c0f72008-04-17 19:21:22 +0200787 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200788 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
Kalle Valoab133152010-01-12 10:42:31 +0200789 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
790 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700791 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200792 case 3: /* AC_VO */
Johannes Berge100bb62008-04-30 18:51:21 +0200793 queue = 0;
Johannes Berg988c0f72008-04-17 19:21:22 +0200794 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200795 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
Kalle Valoab133152010-01-12 10:42:31 +0200796 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
797 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700798 break;
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200799 case 0: /* AC_BE */
Jiri Bencf0706e82007-05-05 11:45:53 -0700800 default:
Johannes Berge100bb62008-04-30 18:51:21 +0200801 queue = 2;
Johannes Berg988c0f72008-04-17 19:21:22 +0200802 if (acm)
Jouni Malinen0eeb59f2009-03-05 17:23:46 +0200803 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
Kalle Valoab133152010-01-12 10:42:31 +0200804 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
805 uapsd = true;
Jiri Bencf0706e82007-05-05 11:45:53 -0700806 break;
807 }
808
809 params.aifs = pos[0] & 0x0f;
810 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
811 params.cw_min = ecw2cw(pos[1] & 0x0f);
Johannes Bergf434b2d2008-07-10 11:22:31 +0200812 params.txop = get_unaligned_le16(pos + 2);
Kalle Valoab133152010-01-12 10:42:31 +0200813 params.uapsd = uapsd;
814
Johannes Bergf4ea83d2008-06-30 15:10:46 +0200815#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700816 wiphy_debug(local->hw.wiphy,
817 "WMM queue=%d aci=%d acm=%d aifs=%d "
818 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
819 queue, aci, acm,
820 params.aifs, params.cw_min, params.cw_max,
821 params.txop, params.uapsd);
Johannes Berg3330d7b2008-02-10 16:49:38 +0100822#endif
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200823 if (drv_conf_tx(local, queue, &params))
Joe Perches0fb9a9e2010-08-20 16:25:38 -0700824 wiphy_debug(local->hw.wiphy,
825 "failed to set TX queue parameters for queue %d\n",
826 queue);
Jiri Bencf0706e82007-05-05 11:45:53 -0700827 }
Stanislaw Gruszkae1b3ec12010-03-29 12:18:34 +0200828
829 /* enable WMM or activate new settings */
Johannes Berg4ced3f72010-07-19 16:39:04 +0200830 sdata->vif.bss_conf.qos = true;
831 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
Jiri Bencf0706e82007-05-05 11:45:53 -0700832}
833
Johannes Berg7a5158e2008-10-08 10:59:33 +0200834static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
835 u16 capab, bool erp_valid, u8 erp)
Daniel Drake56282212007-07-10 19:32:10 +0200836{
Johannes Bergbda39332008-10-11 01:51:51 +0200837 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100838 u32 changed = 0;
Johannes Berg7a5158e2008-10-08 10:59:33 +0200839 bool use_protection;
840 bool use_short_preamble;
841 bool use_short_slot;
842
843 if (erp_valid) {
844 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
845 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
846 } else {
847 use_protection = false;
848 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
849 }
850
851 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
Felix Fietkau43d35342010-01-15 03:00:48 +0100852 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
853 use_short_slot = true;
Daniel Drake56282212007-07-10 19:32:10 +0200854
Johannes Berg471b3ef2007-12-28 14:32:58 +0100855 if (use_protection != bss_conf->use_cts_prot) {
Johannes Berg471b3ef2007-12-28 14:32:58 +0100856 bss_conf->use_cts_prot = use_protection;
857 changed |= BSS_CHANGED_ERP_CTS_PROT;
Daniel Drake56282212007-07-10 19:32:10 +0200858 }
Daniel Drake7e9ed182007-07-27 15:43:24 +0200859
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200860 if (use_short_preamble != bss_conf->use_short_preamble) {
Vladimir Koutnyd43c7b32008-03-31 17:05:03 +0200861 bss_conf->use_short_preamble = use_short_preamble;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100862 changed |= BSS_CHANGED_ERP_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200863 }
Daniel Draked9430a32007-07-27 15:43:24 +0200864
Johannes Berg7a5158e2008-10-08 10:59:33 +0200865 if (use_short_slot != bss_conf->use_short_slot) {
Johannes Berg7a5158e2008-10-08 10:59:33 +0200866 bss_conf->use_short_slot = use_short_slot;
867 changed |= BSS_CHANGED_ERP_SLOT;
John W. Linville50c4afb2008-04-15 14:09:27 -0400868 }
869
870 return changed;
871}
872
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200873static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100874 struct cfg80211_bss *cbss,
Johannes Bergae5eb022008-10-14 16:58:37 +0200875 u32 bss_info_changed)
Jiri Bencf0706e82007-05-05 11:45:53 -0700876{
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100877 struct ieee80211_bss *bss = (void *)cbss->priv;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100878 struct ieee80211_local *local = sdata->local;
Juuso Oikarinen68542962010-06-09 13:43:26 +0300879 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400880
Johannes Bergae5eb022008-10-14 16:58:37 +0200881 bss_info_changed |= BSS_CHANGED_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +0200882 /* set timing information */
Juuso Oikarinen68542962010-06-09 13:43:26 +0300883 bss_conf->beacon_int = cbss->beacon_interval;
884 bss_conf->timestamp = cbss->tsf;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400885
Johannes Berg77fdaa12009-07-07 03:45:17 +0200886 bss_info_changed |= BSS_CHANGED_BEACON_INT;
887 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100888 cbss->capability, bss->has_erp_value, bss->erp_value);
Tomas Winkler21c0cbe2008-03-28 16:33:34 -0700889
Felix Fietkau7ccc8bd2010-11-19 22:55:38 +0100890 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
891 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
892
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100893 sdata->u.mgd.associated = cbss;
894 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
Johannes Berg471b3ef2007-12-28 14:32:58 +0100895
Jouni Malinen17e4ec12010-03-29 23:28:30 -0700896 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
897
Johannes Bergb291ba12009-07-10 15:29:03 +0200898 /* just to be sure */
899 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
900 IEEE80211_STA_BEACON_POLL);
901
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200902 ieee80211_led_assoc(local, 1);
903
Johannes Berge5b900d2010-07-29 16:08:55 +0200904 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
905 bss_conf->dtim_period = bss->dtim_period;
906 else
907 bss_conf->dtim_period = 0;
908
Juuso Oikarinen68542962010-06-09 13:43:26 +0300909 bss_conf->assoc = 1;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200910 /*
911 * For now just always ask the driver to update the basic rateset
912 * when we have associated, we aren't checking whether it actually
913 * changed or not.
914 */
Johannes Bergae5eb022008-10-14 16:58:37 +0200915 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berg9cef8732009-05-14 13:10:14 +0200916
917 /* And the BSSID changed - we're associated now */
918 bss_info_changed |= BSS_CHANGED_BSSID;
919
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200920 /* Tell the driver to monitor connection quality (if supported) */
921 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
Juuso Oikarinen68542962010-06-09 13:43:26 +0300922 bss_conf->cqm_rssi_thold)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +0200923 bss_info_changed |= BSS_CHANGED_CQM;
924
Juuso Oikarinen68542962010-06-09 13:43:26 +0300925 /* Enable ARP filtering */
926 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
927 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
928 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
929 }
930
Johannes Bergae5eb022008-10-14 16:58:37 +0200931 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
Guy Cohen8db93692008-07-03 19:56:13 +0300932
Johannes Berg056508d2009-07-30 21:43:55 +0200933 mutex_lock(&local->iflist_mtx);
934 ieee80211_recalc_ps(local, -1);
Johannes Berg025e6be2010-10-05 10:41:47 +0200935 ieee80211_recalc_smps(local);
Johannes Berg056508d2009-07-30 21:43:55 +0200936 mutex_unlock(&local->iflist_mtx);
Kalle Valoe0cb6862008-12-18 23:35:13 +0200937
John W. Linville8a5b33f2010-01-06 15:39:39 -0500938 netif_tx_start_all_queues(sdata->dev);
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200939 netif_carrier_on(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700940}
941
Jouni Malinene69e95d2010-03-29 23:29:31 -0700942static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg53f73c02010-10-05 19:37:40 +0200943 bool remove_sta, bool tx)
Tomas Winkleraa458d12008-09-09 00:32:12 +0300944{
Johannes Berg46900292009-02-15 12:44:28 +0100945 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Tomas Winkleraa458d12008-09-09 00:32:12 +0300946 struct ieee80211_local *local = sdata->local;
947 struct sta_info *sta;
Kalle Valoe0cb6862008-12-18 23:35:13 +0200948 u32 changed = 0, config_changed = 0;
Johannes Bergb291ba12009-07-10 15:29:03 +0200949 u8 bssid[ETH_ALEN];
Tomas Winkleraa458d12008-09-09 00:32:12 +0300950
Johannes Berg77fdaa12009-07-07 03:45:17 +0200951 ASSERT_MGD_MTX(ifmgd);
952
Johannes Bergb291ba12009-07-10 15:29:03 +0200953 if (WARN_ON(!ifmgd->associated))
954 return;
955
Johannes Berg0c1ad2c2009-12-23 13:15:39 +0100956 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Johannes Bergb291ba12009-07-10 15:29:03 +0200957
Johannes Berg77fdaa12009-07-07 03:45:17 +0200958 ifmgd->associated = NULL;
959 memset(ifmgd->bssid, 0, ETH_ALEN);
960
961 /*
962 * we need to commit the associated = NULL change because the
963 * scan code uses that to determine whether this iface should
964 * go to/wake up from powersave or not -- and could otherwise
965 * wake the queues erroneously.
966 */
967 smp_mb();
968
969 /*
970 * Thus, we can only afterwards stop the queues -- to account
971 * for the case where another CPU is finishing a scan at this
972 * time -- we don't want the scan code to enable queues.
973 */
Tomas Winkleraa458d12008-09-09 00:32:12 +0300974
John W. Linville8a5b33f2010-01-06 15:39:39 -0500975 netif_tx_stop_all_queues(sdata->dev);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300976 netif_carrier_off(sdata->dev);
977
Johannes Berg2a419052010-06-10 10:21:29 +0200978 mutex_lock(&local->sta_mtx);
Johannes Bergabe60632009-11-25 17:46:18 +0100979 sta = sta_info_get(sdata, bssid);
Sujith4cad6c72010-02-10 14:52:21 +0530980 if (sta) {
Johannes Berg2a419052010-06-10 10:21:29 +0200981 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
Johannes Berg53f73c02010-10-05 19:37:40 +0200982 ieee80211_sta_tear_down_BA_sessions(sta, tx);
Sujith4cad6c72010-02-10 14:52:21 +0530983 }
Johannes Berg2a419052010-06-10 10:21:29 +0200984 mutex_unlock(&local->sta_mtx);
Tomas Winkleraa458d12008-09-09 00:32:12 +0300985
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200986 changed |= ieee80211_reset_erp_info(sdata);
987
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200988 ieee80211_led_assoc(local, 0);
Johannes Bergae5eb022008-10-14 16:58:37 +0200989 changed |= BSS_CHANGED_ASSOC;
990 sdata->vif.bss_conf.assoc = false;
Tomas Winklerf5e5bf22008-09-08 17:33:39 +0200991
Johannes Bergaa837e12009-05-07 16:16:24 +0200992 ieee80211_set_wmm_default(sdata);
993
Johannes Berg47979382009-01-07 10:13:27 +0100994 /* channel(_type) changes are handled by ieee80211_hw_config */
Johannes Berg0aaffa92010-05-05 15:28:27 +0200995 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
Johannes Bergae5eb022008-10-14 16:58:37 +0200996
Johannes Berg413ad502009-05-08 21:21:06 +0200997 /* on the next assoc, re-program HT parameters */
998 sdata->ht_opmode_valid = false;
999
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301000 local->power_constr_level = 0;
1001
Kalle Valo520eb822008-12-18 23:35:27 +02001002 del_timer_sync(&local->dynamic_ps_timer);
1003 cancel_work_sync(&local->dynamic_ps_enable_work);
1004
Kalle Valoe0cb6862008-12-18 23:35:13 +02001005 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1006 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1007 config_changed |= IEEE80211_CONF_CHANGE_PS;
1008 }
1009
1010 ieee80211_hw_config(local, config_changed);
Johannes Berg9cef8732009-05-14 13:10:14 +02001011
Juuso Oikarinen68542962010-06-09 13:43:26 +03001012 /* Disable ARP filtering */
1013 if (sdata->vif.bss_conf.arp_filter_enabled) {
1014 sdata->vif.bss_conf.arp_filter_enabled = false;
1015 changed |= BSS_CHANGED_ARP_FILTER;
1016 }
1017
Johannes Berg0aaffa92010-05-05 15:28:27 +02001018 /* The BSSID (not really interesting) and HT changed */
1019 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
Johannes Bergae5eb022008-10-14 16:58:37 +02001020 ieee80211_bss_info_change_notify(sdata, changed);
Tomas Winkler8e268e42008-11-25 13:05:44 +02001021
Jouni Malinene69e95d2010-03-29 23:29:31 -07001022 if (remove_sta)
1023 sta_info_destroy_addr(sdata, bssid);
Johannes Bergb9dcf712010-08-27 12:35:54 +02001024
1025 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
1026 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
1027 del_timer_sync(&sdata->u.mgd.timer);
1028 del_timer_sync(&sdata->u.mgd.chswitch_timer);
Tomas Winkleraa458d12008-09-09 00:32:12 +03001029}
Jiri Bencf0706e82007-05-05 11:45:53 -07001030
Kalle Valo3cf335d2009-03-22 21:57:06 +02001031void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1032 struct ieee80211_hdr *hdr)
1033{
1034 /*
1035 * We can postpone the mgd.timer whenever receiving unicast frames
1036 * from AP because we know that the connection is working both ways
1037 * at that time. But multicast frames (and hence also beacons) must
1038 * be ignored here, because we need to trigger the timer during
Johannes Bergb291ba12009-07-10 15:29:03 +02001039 * data idle periods for sending the periodic probe request to the
1040 * AP we're connected to.
Kalle Valo3cf335d2009-03-22 21:57:06 +02001041 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001042 if (is_multicast_ether_addr(hdr->addr1))
1043 return;
1044
Luis R. Rodriguezbe099e82010-09-16 15:12:29 -04001045 ieee80211_sta_reset_conn_monitor(sdata);
Kalle Valo3cf335d2009-03-22 21:57:06 +02001046}
Jiri Bencf0706e82007-05-05 11:45:53 -07001047
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001048static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
1049{
1050 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1051
1052 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1053 IEEE80211_STA_CONNECTION_POLL)))
1054 return;
1055
1056 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1057 IEEE80211_STA_BEACON_POLL);
1058 mutex_lock(&sdata->local->iflist_mtx);
1059 ieee80211_recalc_ps(sdata->local, -1);
1060 mutex_unlock(&sdata->local->iflist_mtx);
1061
1062 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1063 return;
1064
1065 /*
1066 * We've received a probe response, but are not sure whether
1067 * we have or will be receiving any beacons or data, so let's
1068 * schedule the timers again, just in case.
1069 */
1070 ieee80211_sta_reset_beacon_monitor(sdata);
1071
1072 mod_timer(&ifmgd->conn_mon_timer,
1073 round_jiffies_up(jiffies +
1074 IEEE80211_CONNECTION_IDLE_TIME));
1075}
1076
1077void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001078 struct ieee80211_hdr *hdr, bool ack)
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001079{
Felix Fietkau75706d02010-12-02 21:01:07 +01001080 if (!ieee80211_is_data(hdr->frame_control))
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001081 return;
1082
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001083 if (ack)
1084 ieee80211_sta_reset_conn_monitor(sdata);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001085
1086 if (ieee80211_is_nullfunc(hdr->frame_control) &&
1087 sdata->u.mgd.probe_send_count > 0) {
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001088 if (ack)
1089 sdata->u.mgd.probe_send_count = 0;
1090 else
1091 sdata->u.mgd.nullfunc_failed = true;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001092 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1093 }
1094}
1095
Maxim Levitskya43abf22009-07-31 18:54:12 +03001096static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1097{
1098 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1099 const u8 *ssid;
Luis R. Rodriguezf01a0672010-09-16 15:12:34 -04001100 u8 *dst = ifmgd->associated->bssid;
1101 u8 unicast_limit = max(1, IEEE80211_MAX_PROBE_TRIES - 3);
1102
1103 /*
1104 * Try sending broadcast probe requests for the last three
1105 * probe requests after the first ones failed since some
1106 * buggy APs only support broadcast probe requests.
1107 */
1108 if (ifmgd->probe_send_count >= unicast_limit)
1109 dst = NULL;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001110
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001111 /*
1112 * When the hardware reports an accurate Tx ACK status, it's
1113 * better to send a nullfunc frame instead of a probe request,
1114 * as it will kick us off the AP quickly if we aren't associated
1115 * anymore. The timeout will be reset if the frame is ACKed by
1116 * the AP.
1117 */
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001118 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
1119 ifmgd->nullfunc_failed = false;
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001120 ieee80211_send_nullfunc(sdata->local, sdata, 0);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001121 } else {
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001122 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1123 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0);
1124 }
Maxim Levitskya43abf22009-07-31 18:54:12 +03001125
1126 ifmgd->probe_send_count++;
1127 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1128 run_again(ifmgd, ifmgd->probe_timeout);
1129}
1130
Johannes Bergb291ba12009-07-10 15:29:03 +02001131static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1132 bool beacon)
Kalle Valo04de8382009-03-22 21:57:35 +02001133{
Kalle Valo04de8382009-03-22 21:57:35 +02001134 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02001135 bool already = false;
Johannes Berg34bfc412009-05-12 19:58:12 +02001136
Johannes Berg9607e6b2009-12-23 13:15:31 +01001137 if (!ieee80211_sdata_running(sdata))
Johannes Berg0e2b6282009-07-13 13:23:39 +02001138 return;
1139
Luis R. Rodriguez91a3bd72009-07-23 16:37:47 -07001140 if (sdata->local->scanning)
1141 return;
1142
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001143 if (sdata->local->tmp_channel)
1144 return;
1145
Johannes Berg77fdaa12009-07-07 03:45:17 +02001146 mutex_lock(&ifmgd->mtx);
1147
1148 if (!ifmgd->associated)
1149 goto out;
1150
Michael Buescha8604022009-04-15 14:41:22 -04001151#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Bergb291ba12009-07-10 15:29:03 +02001152 if (beacon && net_ratelimit())
1153 printk(KERN_DEBUG "%s: detected beacon loss from AP "
Johannes Berg47846c92009-11-25 17:46:19 +01001154 "- sending probe request\n", sdata->name);
Michael Buescha8604022009-04-15 14:41:22 -04001155#endif
Kalle Valo04de8382009-03-22 21:57:35 +02001156
Johannes Bergb291ba12009-07-10 15:29:03 +02001157 /*
1158 * The driver/our work has already reported this event or the
1159 * connection monitoring has kicked in and we have already sent
1160 * a probe request. Or maybe the AP died and the driver keeps
1161 * reporting until we disassociate...
1162 *
1163 * In either case we have to ignore the current call to this
1164 * function (except for setting the correct probe reason bit)
1165 * because otherwise we would reset the timer every time and
1166 * never check whether we received a probe response!
1167 */
1168 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1169 IEEE80211_STA_CONNECTION_POLL))
1170 already = true;
1171
1172 if (beacon)
1173 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1174 else
1175 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1176
1177 if (already)
1178 goto out;
1179
Johannes Berg4e751842009-06-10 15:16:52 +02001180 mutex_lock(&sdata->local->iflist_mtx);
1181 ieee80211_recalc_ps(sdata->local, -1);
1182 mutex_unlock(&sdata->local->iflist_mtx);
1183
Maxim Levitskya43abf22009-07-31 18:54:12 +03001184 ifmgd->probe_send_count = 0;
1185 ieee80211_mgd_probe_ap_send(sdata);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001186 out:
1187 mutex_unlock(&ifmgd->mtx);
Kalle Valo04de8382009-03-22 21:57:35 +02001188}
1189
Juuso Oikarinena619a4c2010-11-11 08:50:18 +02001190struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
1191 struct ieee80211_vif *vif)
1192{
1193 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1194 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1195 struct sk_buff *skb;
1196 const u8 *ssid;
1197
1198 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1199 return NULL;
1200
1201 ASSERT_MGD_MTX(ifmgd);
1202
1203 if (!ifmgd->associated)
1204 return NULL;
1205
1206 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1207 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
1208 ssid + 2, ssid[1], NULL, 0);
1209
1210 return skb;
1211}
1212EXPORT_SYMBOL(ieee80211_ap_probereq_get);
1213
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001214static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1215{
1216 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1217 struct ieee80211_local *local = sdata->local;
1218 u8 bssid[ETH_ALEN];
1219
1220 mutex_lock(&ifmgd->mtx);
1221 if (!ifmgd->associated) {
1222 mutex_unlock(&ifmgd->mtx);
1223 return;
1224 }
1225
1226 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1227
1228 printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid);
1229
Johannes Berg53f73c02010-10-05 19:37:40 +02001230 ieee80211_set_disassoc(sdata, true, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001231 mutex_unlock(&ifmgd->mtx);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001232
1233 mutex_lock(&local->mtx);
1234 ieee80211_recalc_idle(local);
1235 mutex_unlock(&local->mtx);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001236 /*
1237 * must be outside lock due to cfg80211,
1238 * but that's not a problem.
1239 */
1240 ieee80211_send_deauth_disassoc(sdata, bssid,
1241 IEEE80211_STYPE_DEAUTH,
1242 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03001243 NULL, true);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001244}
1245
1246void ieee80211_beacon_connection_loss_work(struct work_struct *work)
Johannes Bergb291ba12009-07-10 15:29:03 +02001247{
1248 struct ieee80211_sub_if_data *sdata =
1249 container_of(work, struct ieee80211_sub_if_data,
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001250 u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02001251
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001252 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1253 __ieee80211_connection_loss(sdata);
1254 else
1255 ieee80211_mgd_probe_ap(sdata, true);
Johannes Bergb291ba12009-07-10 15:29:03 +02001256}
1257
Kalle Valo04de8382009-03-22 21:57:35 +02001258void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1259{
1260 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001261 struct ieee80211_hw *hw = &sdata->local->hw;
Kalle Valo04de8382009-03-22 21:57:35 +02001262
Johannes Bergb5878a22010-04-07 16:48:40 +02001263 trace_api_beacon_loss(sdata);
1264
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001265 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1266 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
Kalle Valo04de8382009-03-22 21:57:35 +02001267}
1268EXPORT_SYMBOL(ieee80211_beacon_loss);
1269
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001270void ieee80211_connection_loss(struct ieee80211_vif *vif)
1271{
1272 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1273 struct ieee80211_hw *hw = &sdata->local->hw;
1274
Johannes Bergb5878a22010-04-07 16:48:40 +02001275 trace_api_connection_loss(sdata);
1276
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02001277 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1278 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1279}
1280EXPORT_SYMBOL(ieee80211_connection_loss);
1281
1282
Johannes Berg77fdaa12009-07-07 03:45:17 +02001283static enum rx_mgmt_action __must_check
1284ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001285 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001286{
Johannes Berg46900292009-02-15 12:44:28 +01001287 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001288 const u8 *bssid = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001289 u16 reason_code;
1290
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001291 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001292 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001293
Johannes Berg77fdaa12009-07-07 03:45:17 +02001294 ASSERT_MGD_MTX(ifmgd);
1295
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001296 bssid = ifmgd->associated->bssid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001297
1298 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1299
Johannes Berg77fdaa12009-07-07 03:45:17 +02001300 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001301 sdata->name, bssid, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001302
Johannes Berg53f73c02010-10-05 19:37:40 +02001303 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001304 mutex_lock(&sdata->local->mtx);
Johannes Berg63f170e2009-12-23 13:15:33 +01001305 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001306 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001307
1308 return RX_MGMT_CFG80211_DEAUTH;
Jiri Bencf0706e82007-05-05 11:45:53 -07001309}
1310
1311
Johannes Berg77fdaa12009-07-07 03:45:17 +02001312static enum rx_mgmt_action __must_check
1313ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1314 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001315{
Johannes Berg46900292009-02-15 12:44:28 +01001316 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001317 u16 reason_code;
1318
Johannes Bergf4ea83d2008-06-30 15:10:46 +02001319 if (len < 24 + 2)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001320 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001321
Johannes Berg77fdaa12009-07-07 03:45:17 +02001322 ASSERT_MGD_MTX(ifmgd);
1323
1324 if (WARN_ON(!ifmgd->associated))
1325 return RX_MGMT_NONE;
1326
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001327 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
Johannes Berg77fdaa12009-07-07 03:45:17 +02001328 return RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001329
1330 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1331
Johannes Berg0ff71612009-09-26 14:45:41 +02001332 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001333 sdata->name, mgmt->sa, reason_code);
Jiri Bencf0706e82007-05-05 11:45:53 -07001334
Johannes Berg53f73c02010-10-05 19:37:40 +02001335 ieee80211_set_disassoc(sdata, true, false);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001336 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01001337 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02001338 mutex_unlock(&sdata->local->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001339 return RX_MGMT_CFG80211_DISASSOC;
Jiri Bencf0706e82007-05-05 11:45:53 -07001340}
1341
1342
Johannes Bergaf6b6372009-12-23 13:15:35 +01001343static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1344 struct ieee80211_mgmt *mgmt, size_t len)
Jiri Bencf0706e82007-05-05 11:45:53 -07001345{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001346 struct ieee80211_sub_if_data *sdata = wk->sdata;
Johannes Berg46900292009-02-15 12:44:28 +01001347 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001348 struct ieee80211_local *local = sdata->local;
Johannes Berg8318d782008-01-24 19:38:38 +01001349 struct ieee80211_supported_band *sband;
Jiri Bencf0706e82007-05-05 11:45:53 -07001350 struct sta_info *sta;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001351 struct cfg80211_bss *cbss = wk->assoc.bss;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001352 u8 *pos;
Johannes Berg881d9482009-01-21 15:13:48 +01001353 u32 rates, basic_rates;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001354 u16 capab_info, aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001355 struct ieee802_11_elems elems;
Johannes Bergbda39332008-10-11 01:51:51 +02001356 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Johannes Bergae5eb022008-10-14 16:58:37 +02001357 u32 changed = 0;
Johannes Berg5d1ec852009-12-02 12:43:43 +01001358 int i, j, err;
1359 bool have_higher_than_11mbit = false;
Johannes Bergae5eb022008-10-14 16:58:37 +02001360 u16 ap_ht_cap_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001361
Johannes Bergaf6b6372009-12-23 13:15:35 +01001362 /* AssocResp and ReassocResp have identical structure */
Jiri Bencf0706e82007-05-05 11:45:53 -07001363
Jiri Bencf0706e82007-05-05 11:45:53 -07001364 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001365 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
Jiri Bencf0706e82007-05-05 11:45:53 -07001366
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001367 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1368 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
Johannes Berg47846c92009-11-25 17:46:19 +01001369 "set\n", sdata->name, aid);
Johannes Berg1dd84aa2007-10-10 12:03:41 +02001370 aid &= ~(BIT(15) | BIT(14));
1371
Johannes Bergaf6b6372009-12-23 13:15:35 +01001372 pos = mgmt->u.assoc_resp.variable;
1373 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1374
Jiri Bencf0706e82007-05-05 11:45:53 -07001375 if (!elems.supp_rates) {
1376 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
Johannes Berg47846c92009-11-25 17:46:19 +01001377 sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001378 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001379 }
1380
Johannes Berg46900292009-02-15 12:44:28 +01001381 ifmgd->aid = aid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001382
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001383 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
Jiri Bencf0706e82007-05-05 11:45:53 -07001384 if (!sta) {
Johannes Berg5d1ec852009-12-02 12:43:43 +01001385 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1386 " the AP\n", sdata->name);
Johannes Bergaf6b6372009-12-23 13:15:35 +01001387 return false;
Jiri Bencf0706e82007-05-05 11:45:53 -07001388 }
1389
Johannes Berg5d1ec852009-12-02 12:43:43 +01001390 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1391 WLAN_STA_ASSOC_AP);
1392 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1393 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1394
Jiri Bencf0706e82007-05-05 11:45:53 -07001395 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001396 basic_rates = 0;
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001397 sband = local->hw.wiphy->bands[wk->chan->band];
Johannes Berg8318d782008-01-24 19:38:38 +01001398
Jiri Bencf0706e82007-05-05 11:45:53 -07001399 for (i = 0; i < elems.supp_rates_len; i++) {
1400 int rate = (elems.supp_rates[i] & 0x7f) * 5;
Tomas Winklerd61272c2008-10-30 17:08:08 +02001401 bool is_basic = !!(elems.supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001402
1403 if (rate > 110)
1404 have_higher_than_11mbit = true;
1405
1406 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001407 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001408 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001409 if (is_basic)
1410 basic_rates |= BIT(j);
1411 break;
1412 }
Johannes Berg8318d782008-01-24 19:38:38 +01001413 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001414 }
Johannes Berg8318d782008-01-24 19:38:38 +01001415
Jiri Bencf0706e82007-05-05 11:45:53 -07001416 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1417 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
Johannes Berg7e0986c2009-04-19 13:22:11 +02001418 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
Johannes Berg8318d782008-01-24 19:38:38 +01001419
1420 if (rate > 110)
1421 have_higher_than_11mbit = true;
1422
1423 for (j = 0; j < sband->n_bitrates; j++) {
Tomas Winklerd61272c2008-10-30 17:08:08 +02001424 if (sband->bitrates[j].bitrate == rate) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001425 rates |= BIT(j);
Tomas Winklerd61272c2008-10-30 17:08:08 +02001426 if (is_basic)
1427 basic_rates |= BIT(j);
1428 break;
1429 }
Johannes Berg8318d782008-01-24 19:38:38 +01001430 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001431 }
Johannes Berg8318d782008-01-24 19:38:38 +01001432
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001433 sta->sta.supp_rates[wk->chan->band] = rates;
Johannes Bergbda39332008-10-11 01:51:51 +02001434 sdata->vif.bss_conf.basic_rates = basic_rates;
Johannes Berg8318d782008-01-24 19:38:38 +01001435
1436 /* cf. IEEE 802.11 9.2.12 */
Luis R. Rodrigueze7480bb2010-10-01 17:05:19 -04001437 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
Johannes Berg8318d782008-01-24 19:38:38 +01001438 have_higher_than_11mbit)
1439 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1440 else
1441 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001442
Johannes Bergab1faea2009-07-01 21:41:17 +02001443 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001444 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001445 elems.ht_cap_elem, &sta->sta.ht_cap);
Johannes Bergae5eb022008-10-14 16:58:37 +02001446
1447 ap_ht_cap_flags = sta->sta.ht_cap.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001448
Johannes Berg4b7679a2008-09-18 18:14:18 +02001449 rate_control_rate_init(sta);
Jiri Bencf0706e82007-05-05 11:45:53 -07001450
Johannes Berg46900292009-02-15 12:44:28 +01001451 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
Jouni Malinen5394af42009-01-08 13:31:59 +02001452 set_sta_flags(sta, WLAN_STA_MFP);
1453
Johannes Bergddf4ac52008-10-22 11:41:38 +02001454 if (elems.wmm_param)
Johannes Berg07346f812008-05-03 01:02:02 +02001455 set_sta_flags(sta, WLAN_STA_WME);
Johannes Bergddf4ac52008-10-22 11:41:38 +02001456
Johannes Berg5d1ec852009-12-02 12:43:43 +01001457 err = sta_info_insert(sta);
1458 sta = NULL;
1459 if (err) {
1460 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1461 " the AP (error %d)\n", sdata->name, err);
Johannes Berg90be5612010-01-08 19:01:07 +01001462 return false;
Johannes Bergddf4ac52008-10-22 11:41:38 +02001463 }
1464
Juuso Oikarinenf2176d72010-09-28 14:39:32 +03001465 /*
1466 * Always handle WMM once after association regardless
1467 * of the first value the AP uses. Setting -1 here has
1468 * that effect because the AP values is an unsigned
1469 * 4-bit value.
1470 */
1471 ifmgd->wmm_last_param_set = -1;
1472
Johannes Bergddf4ac52008-10-22 11:41:38 +02001473 if (elems.wmm_param)
Johannes Berg4ced3f72010-07-19 16:39:04 +02001474 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jiri Bencf0706e82007-05-05 11:45:53 -07001475 elems.wmm_param_len);
Johannes Bergaa837e12009-05-07 16:16:24 +02001476 else
1477 ieee80211_set_wmm_default(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001478
Johannes Berge4da8c32009-12-23 13:15:43 +01001479 local->oper_channel = wk->chan;
1480
Johannes Bergae5eb022008-10-14 16:58:37 +02001481 if (elems.ht_info_elem && elems.wmm_param &&
Johannes Bergaf6b6372009-12-23 13:15:35 +01001482 (sdata->local->hw.queues >= 4) &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001483 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
Johannes Bergae5eb022008-10-14 16:58:37 +02001484 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001485 cbss->bssid, ap_ht_cap_flags);
Johannes Bergae5eb022008-10-14 16:58:37 +02001486
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001487 /* set AID and assoc capability,
1488 * ieee80211_set_associated() will tell the driver */
Johannes Berg8318d782008-01-24 19:38:38 +01001489 bss_conf->aid = aid;
Tomas Winkler21c0cbe2008-03-28 16:33:34 -07001490 bss_conf->assoc_capability = capab_info;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001491 ieee80211_set_associated(sdata, cbss, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001492
Kalle Valo15b7b062009-03-22 21:57:14 +02001493 /*
Felix Fietkaud5242152010-01-08 18:06:26 +01001494 * If we're using 4-addr mode, let the AP know that we're
1495 * doing so, so that it can create the STA VLAN on its side
1496 */
1497 if (ifmgd->use_4addr)
1498 ieee80211_send_4addr_nullfunc(local, sdata);
1499
1500 /*
Johannes Bergb291ba12009-07-10 15:29:03 +02001501 * Start timer to probe the connection to the AP now.
1502 * Also start the timer that will detect beacon loss.
Kalle Valo15b7b062009-03-22 21:57:14 +02001503 */
Johannes Bergb291ba12009-07-10 15:29:03 +02001504 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001505 ieee80211_sta_reset_beacon_monitor(sdata);
Kalle Valo15b7b062009-03-22 21:57:14 +02001506
Johannes Bergaf6b6372009-12-23 13:15:35 +01001507 return true;
Jiri Bencf0706e82007-05-05 11:45:53 -07001508}
1509
1510
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001511static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001512 struct ieee80211_mgmt *mgmt,
1513 size_t len,
1514 struct ieee80211_rx_status *rx_status,
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001515 struct ieee802_11_elems *elems,
1516 bool beacon)
Jiri Bencf0706e82007-05-05 11:45:53 -07001517{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001518 struct ieee80211_local *local = sdata->local;
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001519 int freq;
Johannes Bergc2b13452008-09-11 00:01:55 +02001520 struct ieee80211_bss *bss;
Johannes Bergfab7d4a2008-03-16 18:42:44 +01001521 struct ieee80211_channel *channel;
Johannes Berg56007a02010-01-26 14:19:52 +01001522 bool need_ps = false;
1523
1524 if (sdata->u.mgd.associated) {
1525 bss = (void *)sdata->u.mgd.associated->priv;
1526 /* not previously set so we may need to recalc */
1527 need_ps = !bss->dtim_period;
1528 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001529
Johannes Berg5bda6172008-09-08 11:05:10 +02001530 if (elems->ds_params && elems->ds_params_len == 1)
Bruno Randolf59eb21a2011-01-17 13:37:28 +09001531 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
1532 rx_status->band);
Johannes Berg5bda6172008-09-08 11:05:10 +02001533 else
1534 freq = rx_status->freq;
1535
1536 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1537
1538 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1539 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001540
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001541 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
Johannes Berg2a519312009-02-10 21:25:55 +01001542 channel, beacon);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001543 if (bss)
1544 ieee80211_rx_bss_put(local, bss);
1545
1546 if (!sdata->u.mgd.associated)
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001547 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001548
Johannes Berg56007a02010-01-26 14:19:52 +01001549 if (need_ps) {
1550 mutex_lock(&local->iflist_mtx);
1551 ieee80211_recalc_ps(local, -1);
1552 mutex_unlock(&local->iflist_mtx);
1553 }
1554
Sujithc481ec92009-01-06 09:28:37 +05301555 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001556 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001557 ETH_ALEN) == 0)) {
Sujithc481ec92009-01-06 09:28:37 +05301558 struct ieee80211_channel_sw_ie *sw_elem =
1559 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
Johannes Berg5ce6e432010-05-11 16:20:57 +02001560 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1561 bss, rx_status->mactime);
Sujithc481ec92009-01-06 09:28:37 +05301562 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001563}
1564
1565
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001566static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Bergaf6b6372009-12-23 13:15:35 +01001567 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001568{
Johannes Bergaf6b6372009-12-23 13:15:35 +01001569 struct ieee80211_mgmt *mgmt = (void *)skb->data;
Kalle Valo15b7b062009-03-22 21:57:14 +02001570 struct ieee80211_if_managed *ifmgd;
Johannes Bergaf6b6372009-12-23 13:15:35 +01001571 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1572 size_t baselen, len = skb->len;
Ester Kummerae6a44e2008-06-27 18:54:48 +03001573 struct ieee802_11_elems elems;
1574
Kalle Valo15b7b062009-03-22 21:57:14 +02001575 ifmgd = &sdata->u.mgd;
1576
Johannes Berg77fdaa12009-07-07 03:45:17 +02001577 ASSERT_MGD_MTX(ifmgd);
1578
Johannes Berg47846c92009-11-25 17:46:19 +01001579 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
Tomas Winkler8e7cdbb2008-08-03 14:32:01 +03001580 return; /* ignore ProbeResp to foreign address */
1581
Ester Kummerae6a44e2008-06-27 18:54:48 +03001582 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1583 if (baselen > len)
1584 return;
1585
1586 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1587 &elems);
1588
Johannes Berg98c8fcc2008-09-08 17:44:26 +02001589 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
Ron Rindjunsky9859b812008-08-09 03:02:19 +03001590
Johannes Berg77fdaa12009-07-07 03:45:17 +02001591 if (ifmgd->associated &&
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001592 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
1593 ieee80211_reset_ap_probe(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -07001594}
1595
Johannes Bergd91f36d2009-04-16 13:17:26 +02001596/*
1597 * This is the canonical list of information elements we care about,
1598 * the filter code also gives us all changes to the Microsoft OUI
1599 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1600 *
1601 * We implement beacon filtering in software since that means we can
1602 * avoid processing the frame here and in cfg80211, and userspace
1603 * will not be able to tell whether the hardware supports it or not.
1604 *
1605 * XXX: This list needs to be dynamic -- userspace needs to be able to
1606 * add items it requires. It also needs to be able to tell us to
1607 * look out for other vendor IEs.
1608 */
1609static const u64 care_about_ies =
Johannes Berg1d4df3a2009-04-22 11:25:43 +02001610 (1ULL << WLAN_EID_COUNTRY) |
1611 (1ULL << WLAN_EID_ERP_INFO) |
1612 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1613 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1614 (1ULL << WLAN_EID_HT_CAPABILITY) |
1615 (1ULL << WLAN_EID_HT_INFORMATION);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001616
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001617static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
Jiri Bencf0706e82007-05-05 11:45:53 -07001618 struct ieee80211_mgmt *mgmt,
1619 size_t len,
1620 struct ieee80211_rx_status *rx_status)
1621{
Johannes Bergd91f36d2009-04-16 13:17:26 +02001622 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001623 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
Jiri Bencf0706e82007-05-05 11:45:53 -07001624 size_t baselen;
1625 struct ieee802_11_elems elems;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001626 struct ieee80211_local *local = sdata->local;
Johannes Berg471b3ef2007-12-28 14:32:58 +01001627 u32 changed = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001628 bool erp_valid, directed_tim = false;
Johannes Berg7a5158e2008-10-08 10:59:33 +02001629 u8 erp_value = 0;
Johannes Bergd91f36d2009-04-16 13:17:26 +02001630 u32 ncrc;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001631 u8 *bssid;
1632
1633 ASSERT_MGD_MTX(ifmgd);
Jiri Bencf0706e82007-05-05 11:45:53 -07001634
Ester Kummerae6a44e2008-06-27 18:54:48 +03001635 /* Process beacon from the current BSS */
1636 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1637 if (baselen > len)
1638 return;
1639
Johannes Bergd91f36d2009-04-16 13:17:26 +02001640 if (rx_status->freq != local->hw.conf.channel->center_freq)
Jiri Bencf0706e82007-05-05 11:45:53 -07001641 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001642
Johannes Bergb291ba12009-07-10 15:29:03 +02001643 /*
1644 * We might have received a number of frames, among them a
1645 * disassoc frame and a beacon...
1646 */
1647 if (!ifmgd->associated)
Johannes Berg77fdaa12009-07-07 03:45:17 +02001648 return;
1649
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001650 bssid = ifmgd->associated->bssid;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001651
Johannes Bergb291ba12009-07-10 15:29:03 +02001652 /*
1653 * And in theory even frames from a different AP we were just
1654 * associated to a split-second ago!
1655 */
1656 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
Jiri Bencf0706e82007-05-05 11:45:53 -07001657 return;
1658
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001659 /* Track average RSSI from the Beacon frames of the current AP */
1660 ifmgd->last_beacon_signal = rx_status->signal;
1661 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1662 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
Jouni Malinen3ba06c62010-08-27 22:21:13 +03001663 ifmgd->ave_beacon_signal = rx_status->signal * 16;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001664 ifmgd->last_cqm_event_signal = 0;
Jouni Malinen391a2002010-08-27 22:22:00 +03001665 ifmgd->count_beacon_signal = 1;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001666 } else {
1667 ifmgd->ave_beacon_signal =
1668 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1669 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1670 ifmgd->ave_beacon_signal) / 16;
Jouni Malinen391a2002010-08-27 22:22:00 +03001671 ifmgd->count_beacon_signal++;
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001672 }
1673 if (bss_conf->cqm_rssi_thold &&
Jouni Malinen391a2002010-08-27 22:22:00 +03001674 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001675 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1676 int sig = ifmgd->ave_beacon_signal / 16;
1677 int last_event = ifmgd->last_cqm_event_signal;
1678 int thold = bss_conf->cqm_rssi_thold;
1679 int hyst = bss_conf->cqm_rssi_hyst;
1680 if (sig < thold &&
1681 (last_event == 0 || sig < last_event - hyst)) {
1682 ifmgd->last_cqm_event_signal = sig;
1683 ieee80211_cqm_rssi_notify(
1684 &sdata->vif,
1685 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1686 GFP_KERNEL);
1687 } else if (sig > thold &&
1688 (last_event == 0 || sig > last_event + hyst)) {
1689 ifmgd->last_cqm_event_signal = sig;
1690 ieee80211_cqm_rssi_notify(
1691 &sdata->vif,
1692 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1693 GFP_KERNEL);
1694 }
1695 }
1696
Johannes Bergb291ba12009-07-10 15:29:03 +02001697 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
Jouni Malinen92778182009-05-14 21:15:36 +03001698#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1699 if (net_ratelimit()) {
1700 printk(KERN_DEBUG "%s: cancelling probereq poll due "
Johannes Berg47846c92009-11-25 17:46:19 +01001701 "to a received beacon\n", sdata->name);
Jouni Malinen92778182009-05-14 21:15:36 +03001702 }
1703#endif
Johannes Bergb291ba12009-07-10 15:29:03 +02001704 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
Johannes Berg4e751842009-06-10 15:16:52 +02001705 mutex_lock(&local->iflist_mtx);
1706 ieee80211_recalc_ps(local, -1);
1707 mutex_unlock(&local->iflist_mtx);
Jouni Malinen92778182009-05-14 21:15:36 +03001708 }
1709
Johannes Bergb291ba12009-07-10 15:29:03 +02001710 /*
1711 * Push the beacon loss detection into the future since
1712 * we are processing a beacon from the AP just now.
1713 */
Luis R. Rodriguezd3a910a2010-09-16 15:12:32 -04001714 ieee80211_sta_reset_beacon_monitor(sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02001715
Johannes Bergd91f36d2009-04-16 13:17:26 +02001716 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1717 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1718 len - baselen, &elems,
1719 care_about_ies, ncrc);
1720
1721 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
Johannes Berge7ec86f2009-04-18 17:33:24 +02001722 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1723 ifmgd->aid);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001724
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001725 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
Jouni Malinen30196672009-05-19 17:01:43 +03001726 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1727 true);
Johannes Bergd91f36d2009-04-16 13:17:26 +02001728
Johannes Berg4ced3f72010-07-19 16:39:04 +02001729 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
Jouni Malinen30196672009-05-19 17:01:43 +03001730 elems.wmm_param_len);
1731 }
Johannes Bergfe3fa822008-09-08 11:05:09 +02001732
Vivek Natarajan25c9c872009-03-02 20:20:30 +05301733 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
Kalle Valo1fb36062009-02-10 17:09:24 +02001734 if (directed_tim) {
Kalle Valo572e0012009-02-10 17:09:31 +02001735 if (local->hw.conf.dynamic_ps_timeout > 0) {
1736 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1737 ieee80211_hw_config(local,
1738 IEEE80211_CONF_CHANGE_PS);
1739 ieee80211_send_nullfunc(local, sdata, 0);
1740 } else {
1741 local->pspolling = true;
1742
1743 /*
1744 * Here is assumed that the driver will be
1745 * able to send ps-poll frame and receive a
1746 * response even though power save mode is
1747 * enabled, but some drivers might require
1748 * to disable power save here. This needs
1749 * to be investigated.
1750 */
1751 ieee80211_send_pspoll(local, sdata);
1752 }
Vivek Natarajana97b77b2008-12-23 18:39:02 -08001753 }
1754 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001755
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001756 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
Jouni Malinen30196672009-05-19 17:01:43 +03001757 return;
1758 ifmgd->beacon_crc = ncrc;
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03001759 ifmgd->beacon_crc_valid = true;
Jouni Malinen30196672009-05-19 17:01:43 +03001760
Johannes Berg7a5158e2008-10-08 10:59:33 +02001761 if (elems.erp_info && elems.erp_info_len >= 1) {
1762 erp_valid = true;
1763 erp_value = elems.erp_info[0];
1764 } else {
1765 erp_valid = false;
John W. Linville50c4afb2008-04-15 14:09:27 -04001766 }
Johannes Berg7a5158e2008-10-08 10:59:33 +02001767 changed |= ieee80211_handle_bss_capability(sdata,
1768 le16_to_cpu(mgmt->u.beacon.capab_info),
1769 erp_valid, erp_value);
Jiri Bencf0706e82007-05-05 11:45:53 -07001770
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001771
Vasanthakumar Thiagarajan53d6f812009-02-11 22:18:49 +05301772 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
Johannes Bergab1faea2009-07-01 21:41:17 +02001773 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001774 struct sta_info *sta;
1775 struct ieee80211_supported_band *sband;
1776 u16 ap_ht_cap_flags;
1777
1778 rcu_read_lock();
1779
Johannes Bergabe60632009-11-25 17:46:18 +01001780 sta = sta_info_get(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001781 if (WARN_ON(!sta)) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001782 rcu_read_unlock();
1783 return;
1784 }
1785
1786 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1787
1788 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1789 elems.ht_cap_elem, &sta->sta.ht_cap);
1790
1791 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1792
1793 rcu_read_unlock();
1794
1795 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
Johannes Berg77fdaa12009-07-07 03:45:17 +02001796 bssid, ap_ht_cap_flags);
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +02001797 }
1798
Luis R. Rodriguez8b19e6c2009-07-30 17:38:09 -07001799 /* Note: country IE parsing is done for us by cfg80211 */
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001800 if (elems.country_elem) {
Vasanthakumar Thiagarajana8302de2009-01-09 18:14:15 +05301801 /* TODO: IBSS also needs this */
1802 if (elems.pwr_constr_elem)
1803 ieee80211_handle_pwr_constr(sdata,
1804 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1805 elems.pwr_constr_elem,
1806 elems.pwr_constr_elem_len);
Luis R. Rodriguez3f2355c2008-11-12 14:22:02 -08001807 }
1808
Johannes Berg471b3ef2007-12-28 14:32:58 +01001809 ieee80211_bss_info_change_notify(sdata, changed);
Jiri Bencf0706e82007-05-05 11:45:53 -07001810}
1811
Johannes Berg1fa57d02010-06-10 10:21:32 +02001812void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1813 struct sk_buff *skb)
Jiri Bencf0706e82007-05-05 11:45:53 -07001814{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001815 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jiri Bencf0706e82007-05-05 11:45:53 -07001816 struct ieee80211_rx_status *rx_status;
Jiri Bencf0706e82007-05-05 11:45:53 -07001817 struct ieee80211_mgmt *mgmt;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001818 enum rx_mgmt_action rma = RX_MGMT_NONE;
Jiri Bencf0706e82007-05-05 11:45:53 -07001819 u16 fc;
1820
Jiri Bencf0706e82007-05-05 11:45:53 -07001821 rx_status = (struct ieee80211_rx_status *) skb->cb;
1822 mgmt = (struct ieee80211_mgmt *) skb->data;
1823 fc = le16_to_cpu(mgmt->frame_control);
1824
Johannes Berg77fdaa12009-07-07 03:45:17 +02001825 mutex_lock(&ifmgd->mtx);
1826
1827 if (ifmgd->associated &&
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001828 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02001829 switch (fc & IEEE80211_FCTL_STYPE) {
1830 case IEEE80211_STYPE_BEACON:
1831 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1832 rx_status);
1833 break;
1834 case IEEE80211_STYPE_PROBE_RESP:
Johannes Bergaf6b6372009-12-23 13:15:35 +01001835 ieee80211_rx_mgmt_probe_resp(sdata, skb);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001836 break;
1837 case IEEE80211_STYPE_DEAUTH:
Johannes Berg63f170e2009-12-23 13:15:33 +01001838 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001839 break;
1840 case IEEE80211_STYPE_DISASSOC:
1841 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1842 break;
1843 case IEEE80211_STYPE_ACTION:
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001844 switch (mgmt->u.action.category) {
Johannes Berg8b9a4e62010-05-28 15:22:58 +02001845 case WLAN_CATEGORY_SPECTRUM_MGMT:
1846 ieee80211_sta_process_chanswitch(sdata,
1847 &mgmt->u.action.u.chan_switch.sw_elem,
1848 (void *)ifmgd->associated->priv,
1849 rx_status->mactime);
1850 break;
1851 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02001852 }
1853 mutex_unlock(&ifmgd->mtx);
1854
1855 switch (rma) {
1856 case RX_MGMT_NONE:
1857 /* no action */
1858 break;
1859 case RX_MGMT_CFG80211_DEAUTH:
Holger Schurigce470612009-10-13 13:28:13 +02001860 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001861 break;
1862 case RX_MGMT_CFG80211_DISASSOC:
Holger Schurigce470612009-10-13 13:28:13 +02001863 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Berg77fdaa12009-07-07 03:45:17 +02001864 break;
1865 default:
1866 WARN(1, "unexpected: %d", rma);
1867 }
Johannes Berg36b3a622010-06-10 10:21:33 +02001868 return;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001869 }
1870
Johannes Berg77fdaa12009-07-07 03:45:17 +02001871 mutex_unlock(&ifmgd->mtx);
1872
Johannes Berg63f170e2009-12-23 13:15:33 +01001873 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
Johannes Bergb054b742010-06-07 21:50:07 +02001874 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
1875 struct ieee80211_local *local = sdata->local;
1876 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02001877
Johannes Berga1699b72010-07-30 16:46:07 +02001878 mutex_lock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001879 list_for_each_entry(wk, &local->work_list, list) {
1880 if (wk->sdata != sdata)
1881 continue;
1882
Johannes Berge5b900d2010-07-29 16:08:55 +02001883 if (wk->type != IEEE80211_WORK_ASSOC &&
1884 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Bergb054b742010-06-07 21:50:07 +02001885 continue;
1886
1887 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
1888 continue;
1889 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
1890 continue;
1891
1892 /*
1893 * Printing the message only here means we can't
1894 * spuriously print it, but it also means that it
1895 * won't be printed when the frame comes in before
1896 * we even tried to associate or in similar cases.
1897 *
1898 * Ultimately, I suspect cfg80211 should print the
1899 * messages instead.
1900 */
1901 printk(KERN_DEBUG
1902 "%s: deauthenticated from %pM (Reason: %u)\n",
1903 sdata->name, mgmt->bssid,
1904 le16_to_cpu(mgmt->u.deauth.reason_code));
1905
1906 list_del_rcu(&wk->list);
1907 free_work(wk);
1908 break;
1909 }
Johannes Berga1699b72010-07-30 16:46:07 +02001910 mutex_unlock(&local->mtx);
Johannes Bergb054b742010-06-07 21:50:07 +02001911
Johannes Berg77fdaa12009-07-07 03:45:17 +02001912 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
Johannes Bergb054b742010-06-07 21:50:07 +02001913 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001914}
1915
Johannes Berg9c6bd792008-09-11 00:01:52 +02001916static void ieee80211_sta_timer(unsigned long data)
Jiri Bencf0706e82007-05-05 11:45:53 -07001917{
1918 struct ieee80211_sub_if_data *sdata =
1919 (struct ieee80211_sub_if_data *) data;
Johannes Berg46900292009-02-15 12:44:28 +01001920 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001921 struct ieee80211_local *local = sdata->local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001922
Johannes Berg5bb644a2009-05-17 11:40:42 +02001923 if (local->quiescing) {
1924 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1925 return;
1926 }
1927
Johannes Berg64592c82010-06-10 10:21:31 +02001928 ieee80211_queue_work(&local->hw, &sdata->work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001929}
1930
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001931static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
1932 u8 *bssid)
1933{
1934 struct ieee80211_local *local = sdata->local;
1935 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1936
1937 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1938 IEEE80211_STA_BEACON_POLL);
1939
1940 ieee80211_set_disassoc(sdata, true, true);
1941 mutex_unlock(&ifmgd->mtx);
1942 mutex_lock(&local->mtx);
1943 ieee80211_recalc_idle(local);
1944 mutex_unlock(&local->mtx);
1945 /*
1946 * must be outside lock due to cfg80211,
1947 * but that's not a problem.
1948 */
1949 ieee80211_send_deauth_disassoc(sdata, bssid,
1950 IEEE80211_STYPE_DEAUTH,
1951 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
1952 NULL, true);
1953 mutex_lock(&ifmgd->mtx);
1954}
1955
Johannes Berg1fa57d02010-06-10 10:21:32 +02001956void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
Johannes Berg60f8b392008-09-08 17:44:22 +02001957{
Johannes Berg60f8b392008-09-08 17:44:22 +02001958 struct ieee80211_local *local = sdata->local;
Johannes Berg1fa57d02010-06-10 10:21:32 +02001959 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60f8b392008-09-08 17:44:22 +02001960
Johannes Berg77fdaa12009-07-07 03:45:17 +02001961 /* then process the rest of the work */
1962 mutex_lock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02001963
Johannes Bergb291ba12009-07-10 15:29:03 +02001964 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1965 IEEE80211_STA_CONNECTION_POLL) &&
1966 ifmgd->associated) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03001967 u8 bssid[ETH_ALEN];
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01001968 int max_tries;
Maxim Levitskya43abf22009-07-31 18:54:12 +03001969
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001970 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001971
Felix Fietkau72a8a3e2010-11-23 03:10:32 +01001972 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
1973 max_tries = IEEE80211_MAX_NULLFUNC_TRIES;
1974 else
1975 max_tries = IEEE80211_MAX_PROBE_TRIES;
1976
Felix Fietkau4e5ff372010-11-23 03:10:31 +01001977 /* ACK received for nullfunc probing frame */
1978 if (!ifmgd->probe_send_count)
1979 ieee80211_reset_ap_probe(sdata);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001980 else if (ifmgd->nullfunc_failed) {
1981 if (ifmgd->probe_send_count < max_tries) {
1982#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1983 wiphy_debug(local->hw.wiphy,
1984 "%s: No ack for nullfunc frame to"
Ben Greearbfc31df2011-01-14 09:32:18 -08001985 " AP %pM, try %d/%i\n",
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001986 sdata->name, bssid,
Ben Greearbfc31df2011-01-14 09:32:18 -08001987 ifmgd->probe_send_count, max_tries);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001988#endif
1989 ieee80211_mgd_probe_ap_send(sdata);
1990 } else {
1991#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1992 wiphy_debug(local->hw.wiphy,
1993 "%s: No ack for nullfunc frame to"
1994 " AP %pM, disconnecting.\n",
Felix Fietkauc658e5d2010-12-07 04:40:18 +01001995 sdata->name, bssid);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01001996#endif
1997 ieee80211_sta_connection_lost(sdata, bssid);
1998 }
1999 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
Johannes Bergb291ba12009-07-10 15:29:03 +02002000 run_again(ifmgd, ifmgd->probe_timeout);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002001 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
2002#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2003 wiphy_debug(local->hw.wiphy,
2004 "%s: Failed to send nullfunc to AP %pM"
2005 " after %dms, disconnecting.\n",
2006 sdata->name,
2007 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2008#endif
2009 ieee80211_sta_connection_lost(sdata, bssid);
2010 } else if (ifmgd->probe_send_count < max_tries) {
Maxim Levitskya43abf22009-07-31 18:54:12 +03002011#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Ben Greearb38afa82010-10-07 16:12:06 -07002012 wiphy_debug(local->hw.wiphy,
2013 "%s: No probe response from AP %pM"
Ben Greearbfc31df2011-01-14 09:32:18 -08002014 " after %dms, try %d/%i\n",
Ben Greearb38afa82010-10-07 16:12:06 -07002015 sdata->name,
2016 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ,
Ben Greearbfc31df2011-01-14 09:32:18 -08002017 ifmgd->probe_send_count, max_tries);
Maxim Levitskya43abf22009-07-31 18:54:12 +03002018#endif
2019 ieee80211_mgd_probe_ap_send(sdata);
2020 } else {
Johannes Bergb291ba12009-07-10 15:29:03 +02002021 /*
2022 * We actually lost the connection ... or did we?
2023 * Let's make sure!
2024 */
Ben Greearb38afa82010-10-07 16:12:06 -07002025 wiphy_debug(local->hw.wiphy,
2026 "%s: No probe response from AP %pM"
2027 " after %dms, disconnecting.\n",
2028 sdata->name,
2029 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
Felix Fietkau04ac3c02010-12-02 21:01:08 +01002030
2031 ieee80211_sta_connection_lost(sdata, bssid);
Johannes Bergb291ba12009-07-10 15:29:03 +02002032 }
2033 }
2034
Johannes Berg77fdaa12009-07-07 03:45:17 +02002035 mutex_unlock(&ifmgd->mtx);
Johannes Berg60f8b392008-09-08 17:44:22 +02002036}
Johannes Berg0a51b272008-09-08 17:44:25 +02002037
Johannes Bergb291ba12009-07-10 15:29:03 +02002038static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2039{
2040 struct ieee80211_sub_if_data *sdata =
2041 (struct ieee80211_sub_if_data *) data;
2042 struct ieee80211_local *local = sdata->local;
2043
2044 if (local->quiescing)
2045 return;
2046
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002047 ieee80211_queue_work(&sdata->local->hw,
2048 &sdata->u.mgd.beacon_connection_loss_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002049}
2050
2051static void ieee80211_sta_conn_mon_timer(unsigned long data)
2052{
2053 struct ieee80211_sub_if_data *sdata =
2054 (struct ieee80211_sub_if_data *) data;
2055 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2056 struct ieee80211_local *local = sdata->local;
2057
2058 if (local->quiescing)
2059 return;
2060
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002061 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
Johannes Bergb291ba12009-07-10 15:29:03 +02002062}
2063
2064static void ieee80211_sta_monitor_work(struct work_struct *work)
2065{
2066 struct ieee80211_sub_if_data *sdata =
2067 container_of(work, struct ieee80211_sub_if_data,
2068 u.mgd.monitor_work);
2069
2070 ieee80211_mgd_probe_ap(sdata, false);
2071}
2072
Johannes Berga1678f82008-09-11 00:01:47 +02002073static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2074{
Kalle Vaload935682009-04-19 08:47:19 +03002075 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
Johannes Bergb291ba12009-07-10 15:29:03 +02002076 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2077 IEEE80211_STA_CONNECTION_POLL);
Kalle Vaload935682009-04-19 08:47:19 +03002078
Johannes Bergb291ba12009-07-10 15:29:03 +02002079 /* let's probe the connection once */
Luis R. Rodriguez42935ec2009-07-29 20:08:07 -04002080 ieee80211_queue_work(&sdata->local->hw,
Johannes Bergb291ba12009-07-10 15:29:03 +02002081 &sdata->u.mgd.monitor_work);
2082 /* and do all the other regular work too */
Johannes Berg64592c82010-06-10 10:21:31 +02002083 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
Kalle Vaload935682009-04-19 08:47:19 +03002084 }
Johannes Berga1678f82008-09-11 00:01:47 +02002085}
2086
Johannes Berg5bb644a2009-05-17 11:40:42 +02002087#ifdef CONFIG_PM
2088void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2089{
2090 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2091
2092 /*
2093 * we need to use atomic bitops for the running bits
2094 * only because both timers might fire at the same
2095 * time -- the code here is properly synchronised.
2096 */
2097
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002098 cancel_work_sync(&ifmgd->request_smps_work);
2099
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002100 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002101 if (del_timer_sync(&ifmgd->timer))
2102 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2103
2104 cancel_work_sync(&ifmgd->chswitch_work);
2105 if (del_timer_sync(&ifmgd->chswitch_timer))
2106 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
Johannes Bergb291ba12009-07-10 15:29:03 +02002107
2108 cancel_work_sync(&ifmgd->monitor_work);
2109 /* these will just be re-established on connection */
2110 del_timer_sync(&ifmgd->conn_mon_timer);
2111 del_timer_sync(&ifmgd->bcn_mon_timer);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002112}
2113
2114void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2115{
2116 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2117
2118 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2119 add_timer(&ifmgd->timer);
2120 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2121 add_timer(&ifmgd->chswitch_timer);
Felix Fietkauc8a79722010-11-19 22:55:37 +01002122 ieee80211_sta_reset_beacon_monitor(sdata);
Felix Fietkau46090972010-11-23 20:28:03 +01002123 ieee80211_restart_sta_timer(sdata);
Johannes Berg5bb644a2009-05-17 11:40:42 +02002124}
2125#endif
2126
Johannes Berg9c6bd792008-09-11 00:01:52 +02002127/* interface setup */
2128void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2129{
Johannes Berg46900292009-02-15 12:44:28 +01002130 struct ieee80211_if_managed *ifmgd;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002131
Johannes Berg46900292009-02-15 12:44:28 +01002132 ifmgd = &sdata->u.mgd;
Johannes Bergb291ba12009-07-10 15:29:03 +02002133 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
Johannes Berg46900292009-02-15 12:44:28 +01002134 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
Juuso Oikarinen1e4dcd02010-03-19 07:14:53 +02002135 INIT_WORK(&ifmgd->beacon_connection_loss_work,
2136 ieee80211_beacon_connection_loss_work);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +02002137 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
Johannes Berg46900292009-02-15 12:44:28 +01002138 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
Johannes Berg9c6bd792008-09-11 00:01:52 +02002139 (unsigned long) sdata);
Johannes Bergb291ba12009-07-10 15:29:03 +02002140 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2141 (unsigned long) sdata);
2142 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2143 (unsigned long) sdata);
Johannes Berg46900292009-02-15 12:44:28 +01002144 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
Sujithc481ec92009-01-06 09:28:37 +05302145 (unsigned long) sdata);
Johannes Berg9c6bd792008-09-11 00:01:52 +02002146
Johannes Bergab1faea2009-07-01 21:41:17 +02002147 ifmgd->flags = 0;
Johannes Bergbbbdff92009-04-16 13:27:42 +02002148
Johannes Berg77fdaa12009-07-07 03:45:17 +02002149 mutex_init(&ifmgd->mtx);
Johannes Berg0f782312009-12-01 13:37:02 +01002150
2151 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
2152 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
2153 else
2154 ifmgd->req_smps = IEEE80211_SMPS_OFF;
Johannes Berg9c6bd792008-09-11 00:01:52 +02002155}
2156
2157/* scan finished notification */
Johannes Berg0a51b272008-09-08 17:44:25 +02002158void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2159{
2160 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
Johannes Berga1678f82008-09-11 00:01:47 +02002161
2162 /* Restart STA timers */
2163 rcu_read_lock();
2164 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2165 ieee80211_restart_sta_timer(sdata);
2166 rcu_read_unlock();
Johannes Berg0a51b272008-09-08 17:44:25 +02002167}
Johannes Berg10f644a2009-04-16 13:17:25 +02002168
2169int ieee80211_max_network_latency(struct notifier_block *nb,
2170 unsigned long data, void *dummy)
2171{
2172 s32 latency_usec = (s32) data;
2173 struct ieee80211_local *local =
2174 container_of(nb, struct ieee80211_local,
2175 network_latency_notifier);
2176
2177 mutex_lock(&local->iflist_mtx);
2178 ieee80211_recalc_ps(local, latency_usec);
2179 mutex_unlock(&local->iflist_mtx);
2180
2181 return 0;
2182}
Johannes Berg77fdaa12009-07-07 03:45:17 +02002183
2184/* config hooks */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002185static enum work_done_result
2186ieee80211_probe_auth_done(struct ieee80211_work *wk,
2187 struct sk_buff *skb)
2188{
2189 if (!skb) {
2190 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2191 return WORK_DONE_DESTROY;
2192 }
2193
2194 if (wk->type == IEEE80211_WORK_AUTH) {
2195 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2196 return WORK_DONE_DESTROY;
2197 }
2198
2199 mutex_lock(&wk->sdata->u.mgd.mtx);
2200 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2201 mutex_unlock(&wk->sdata->u.mgd.mtx);
2202
2203 wk->type = IEEE80211_WORK_AUTH;
2204 wk->probe_auth.tries = 0;
2205 return WORK_DONE_REQUEUE;
2206}
2207
Johannes Berg77fdaa12009-07-07 03:45:17 +02002208int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2209 struct cfg80211_auth_request *req)
2210{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002211 const u8 *ssid;
Johannes Bergf679f652009-12-23 13:15:34 +01002212 struct ieee80211_work *wk;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002213 u16 auth_alg;
2214
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002215 if (req->local_state_change)
2216 return 0; /* no need to update mac80211 state */
2217
Johannes Berg77fdaa12009-07-07 03:45:17 +02002218 switch (req->auth_type) {
2219 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2220 auth_alg = WLAN_AUTH_OPEN;
2221 break;
2222 case NL80211_AUTHTYPE_SHARED_KEY:
Johannes Berg9dca9c42010-07-21 10:09:25 +02002223 if (IS_ERR(sdata->local->wep_tx_tfm))
2224 return -EOPNOTSUPP;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002225 auth_alg = WLAN_AUTH_SHARED_KEY;
2226 break;
2227 case NL80211_AUTHTYPE_FT:
2228 auth_alg = WLAN_AUTH_FT;
2229 break;
2230 case NL80211_AUTHTYPE_NETWORK_EAP:
2231 auth_alg = WLAN_AUTH_LEAP;
2232 break;
2233 default:
2234 return -EOPNOTSUPP;
2235 }
2236
2237 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2238 if (!wk)
2239 return -ENOMEM;
2240
Joe Perches5e124bd2010-01-08 22:33:38 -08002241 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002242
2243 if (req->ie && req->ie_len) {
2244 memcpy(wk->ie, req->ie, req->ie_len);
2245 wk->ie_len = req->ie_len;
2246 }
2247
Johannes Bergfffd0932009-07-08 14:22:54 +02002248 if (req->key && req->key_len) {
Johannes Bergaf6b6372009-12-23 13:15:35 +01002249 wk->probe_auth.key_len = req->key_len;
2250 wk->probe_auth.key_idx = req->key_idx;
2251 memcpy(wk->probe_auth.key, req->key, req->key_len);
Johannes Bergfffd0932009-07-08 14:22:54 +02002252 }
2253
Johannes Berg77fdaa12009-07-07 03:45:17 +02002254 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002255 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2256 wk->probe_auth.ssid_len = ssid[1];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002257
Johannes Bergaf6b6372009-12-23 13:15:35 +01002258 wk->probe_auth.algorithm = auth_alg;
2259 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
Johannes Bergf679f652009-12-23 13:15:34 +01002260
Johannes Berg070bb542010-02-03 13:57:46 +01002261 /* if we already have a probe, don't probe again */
2262 if (req->bss->proberesp_ies)
2263 wk->type = IEEE80211_WORK_AUTH;
2264 else
2265 wk->type = IEEE80211_WORK_DIRECT_PROBE;
Johannes Bergf679f652009-12-23 13:15:34 +01002266 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002267 wk->sdata = sdata;
2268 wk->done = ieee80211_probe_auth_done;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002269
Johannes Bergaf6b6372009-12-23 13:15:35 +01002270 ieee80211_add_work(wk);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002271 return 0;
2272}
2273
Johannes Bergaf6b6372009-12-23 13:15:35 +01002274static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2275 struct sk_buff *skb)
2276{
2277 struct ieee80211_mgmt *mgmt;
Johannes Berge5b900d2010-07-29 16:08:55 +02002278 struct ieee80211_rx_status *rx_status;
2279 struct ieee802_11_elems elems;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002280 u16 status;
2281
2282 if (!skb) {
2283 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2284 return WORK_DONE_DESTROY;
2285 }
2286
Johannes Berge5b900d2010-07-29 16:08:55 +02002287 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2288 mutex_lock(&wk->sdata->u.mgd.mtx);
2289 rx_status = (void *) skb->cb;
2290 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2291 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2292 &elems, true);
2293 mutex_unlock(&wk->sdata->u.mgd.mtx);
2294
2295 wk->type = IEEE80211_WORK_ASSOC;
2296 /* not really done yet */
2297 return WORK_DONE_REQUEUE;
2298 }
2299
Johannes Bergaf6b6372009-12-23 13:15:35 +01002300 mgmt = (void *)skb->data;
2301 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2302
2303 if (status == WLAN_STATUS_SUCCESS) {
2304 mutex_lock(&wk->sdata->u.mgd.mtx);
2305 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2306 mutex_unlock(&wk->sdata->u.mgd.mtx);
2307 /* oops -- internal error -- send timeout for now */
2308 cfg80211_send_assoc_timeout(wk->sdata->dev,
2309 wk->filter_ta);
2310 return WORK_DONE_DESTROY;
2311 }
Juuso Oikarinen68542962010-06-09 13:43:26 +03002312
2313 mutex_unlock(&wk->sdata->u.mgd.mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002314 }
2315
2316 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2317 return WORK_DONE_DESTROY;
2318}
2319
Johannes Berg77fdaa12009-07-07 03:45:17 +02002320int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2321 struct cfg80211_assoc_request *req)
2322{
2323 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002324 struct ieee80211_bss *bss = (void *)req->bss->priv;
Johannes Bergf679f652009-12-23 13:15:34 +01002325 struct ieee80211_work *wk;
Johannes Berg63f170e2009-12-23 13:15:33 +01002326 const u8 *ssid;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002327 int i;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002328
2329 mutex_lock(&ifmgd->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002330 if (ifmgd->associated) {
Jouni Malinen9c87ba62010-02-28 12:13:46 +02002331 if (!req->prev_bssid ||
2332 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2333 ETH_ALEN)) {
2334 /*
2335 * We are already associated and the request was not a
2336 * reassociation request from the current BSS, so
2337 * reject it.
2338 */
2339 mutex_unlock(&ifmgd->mtx);
2340 return -EALREADY;
2341 }
2342
2343 /* Trying to reassociate - clear previous association state */
Johannes Berg53f73c02010-10-05 19:37:40 +02002344 ieee80211_set_disassoc(sdata, true, false);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002345 }
2346 mutex_unlock(&ifmgd->mtx);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002347
Johannes Berg63f170e2009-12-23 13:15:33 +01002348 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002349 if (!wk)
2350 return -ENOMEM;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002351
Johannes Berg77fdaa12009-07-07 03:45:17 +02002352 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
Vivek Natarajan375177b2010-02-09 14:50:28 +05302353 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002354
Juuso Oikarinend8ec4432010-10-01 16:02:31 +03002355 ifmgd->beacon_crc_valid = false;
2356
Johannes Berg77fdaa12009-07-07 03:45:17 +02002357 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2358 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2359 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2360 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2361 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2362
Johannes Berg77fdaa12009-07-07 03:45:17 +02002363
2364 if (req->ie && req->ie_len) {
2365 memcpy(wk->ie, req->ie, req->ie_len);
2366 wk->ie_len = req->ie_len;
2367 } else
2368 wk->ie_len = 0;
2369
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002370 wk->assoc.bss = req->bss;
Johannes Bergf679f652009-12-23 13:15:34 +01002371
Johannes Bergaf6b6372009-12-23 13:15:35 +01002372 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
Johannes Bergf679f652009-12-23 13:15:34 +01002373
Johannes Bergaf6b6372009-12-23 13:15:35 +01002374 /* new association always uses requested smps mode */
2375 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2376 if (ifmgd->powersave)
2377 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2378 else
2379 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2380 } else
2381 ifmgd->ap_smps = ifmgd->req_smps;
2382
2383 wk->assoc.smps = ifmgd->ap_smps;
Johannes Berg77c81442009-12-23 13:15:37 +01002384 /*
2385 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2386 * We still associate in non-HT mode (11a/b/g) if any one of these
2387 * ciphers is configured as pairwise.
2388 * We can set this to true for non-11n hardware, that'll be checked
2389 * separately along with the peer capabilities.
2390 */
Johannes Bergaf6b6372009-12-23 13:15:35 +01002391 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
Johannes Bergf679f652009-12-23 13:15:34 +01002392 wk->assoc.capability = req->bss->capability;
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002393 wk->assoc.wmm_used = bss->wmm_used;
2394 wk->assoc.supp_rates = bss->supp_rates;
2395 wk->assoc.supp_rates_len = bss->supp_rates_len;
Johannes Bergf679f652009-12-23 13:15:34 +01002396 wk->assoc.ht_information_ie =
2397 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
Johannes Berg63f170e2009-12-23 13:15:33 +01002398
Kalle Valoab133152010-01-12 10:42:31 +02002399 if (bss->wmm_used && bss->uapsd_supported &&
2400 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2401 wk->assoc.uapsd_used = true;
2402 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2403 } else {
2404 wk->assoc.uapsd_used = false;
2405 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2406 }
2407
Johannes Berg63f170e2009-12-23 13:15:33 +01002408 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
Johannes Bergf679f652009-12-23 13:15:34 +01002409 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2410 wk->assoc.ssid_len = ssid[1];
Johannes Berg63f170e2009-12-23 13:15:33 +01002411
Johannes Berg77fdaa12009-07-07 03:45:17 +02002412 if (req->prev_bssid)
Johannes Bergf679f652009-12-23 13:15:34 +01002413 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002414
Johannes Bergf679f652009-12-23 13:15:34 +01002415 wk->chan = req->bss->channel;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002416 wk->sdata = sdata;
2417 wk->done = ieee80211_assoc_done;
Johannes Berge5b900d2010-07-29 16:08:55 +02002418 if (!bss->dtim_period &&
2419 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2420 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2421 else
2422 wk->type = IEEE80211_WORK_ASSOC;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002423
2424 if (req->use_mfp) {
2425 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2426 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2427 } else {
2428 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2429 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2430 }
2431
2432 if (req->crypto.control_port)
2433 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2434 else
2435 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2436
Johannes Berga621fa42010-08-27 14:26:54 +03002437 sdata->control_port_protocol = req->crypto.control_port_ethertype;
2438 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
2439
Johannes Bergaf6b6372009-12-23 13:15:35 +01002440 ieee80211_add_work(wk);
2441 return 0;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002442}
2443
2444int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002445 struct cfg80211_deauth_request *req,
2446 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002447{
Johannes Bergaf6b6372009-12-23 13:15:35 +01002448 struct ieee80211_local *local = sdata->local;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002449 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Bergf679f652009-12-23 13:15:34 +01002450 struct ieee80211_work *wk;
Jouni Malinen05e48e82010-06-14 11:55:56 -07002451 u8 bssid[ETH_ALEN];
2452 bool assoc_bss = false;
Johannes Berg77fdaa12009-07-07 03:45:17 +02002453
Johannes Berg77fdaa12009-07-07 03:45:17 +02002454 mutex_lock(&ifmgd->mtx);
2455
Jouni Malinen05e48e82010-06-14 11:55:56 -07002456 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002457 if (ifmgd->associated == req->bss) {
Johannes Berg53f73c02010-10-05 19:37:40 +02002458 ieee80211_set_disassoc(sdata, false, true);
Johannes Berga58ce432009-11-19 12:45:42 +01002459 mutex_unlock(&ifmgd->mtx);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002460 assoc_bss = true;
Johannes Bergaf6b6372009-12-23 13:15:35 +01002461 } else {
2462 bool not_auth_yet = false;
Johannes Berga58ce432009-11-19 12:45:42 +01002463
Johannes Bergaf6b6372009-12-23 13:15:35 +01002464 mutex_unlock(&ifmgd->mtx);
2465
Johannes Berga1699b72010-07-30 16:46:07 +02002466 mutex_lock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002467 list_for_each_entry(wk, &local->work_list, list) {
Johannes Berg29165e42010-02-06 15:20:13 +01002468 if (wk->sdata != sdata)
Johannes Bergaf6b6372009-12-23 13:15:35 +01002469 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002470
2471 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
Reinette Chatre79733a82010-05-04 16:04:49 -07002472 wk->type != IEEE80211_WORK_AUTH &&
Johannes Berge5b900d2010-07-29 16:08:55 +02002473 wk->type != IEEE80211_WORK_ASSOC &&
2474 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
Johannes Berg29165e42010-02-06 15:20:13 +01002475 continue;
2476
Johannes Bergaf6b6372009-12-23 13:15:35 +01002477 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2478 continue;
Johannes Berg29165e42010-02-06 15:20:13 +01002479
2480 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2481 list_del_rcu(&wk->list);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002482 free_work(wk);
2483 break;
2484 }
Johannes Berga1699b72010-07-30 16:46:07 +02002485 mutex_unlock(&local->mtx);
Johannes Bergaf6b6372009-12-23 13:15:35 +01002486
2487 /*
2488 * If somebody requests authentication and we haven't
2489 * sent out an auth frame yet there's no need to send
2490 * out a deauth frame either. If the state was PROBE,
2491 * then this is the case. If it's AUTH we have sent a
2492 * frame, and if it's IDLE we have completed the auth
2493 * process already.
2494 */
2495 if (not_auth_yet) {
2496 __cfg80211_auth_canceled(sdata->dev, bssid);
2497 return 0;
2498 }
2499 }
Johannes Berg77fdaa12009-07-07 03:45:17 +02002500
Johannes Berg0ff71612009-09-26 14:45:41 +02002501 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002502 sdata->name, bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002503
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002504 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2505 req->reason_code, cookie,
2506 !req->local_state_change);
Jouni Malinen05e48e82010-06-14 11:55:56 -07002507 if (assoc_bss)
2508 sta_info_destroy_addr(sdata, bssid);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002509
Johannes Berg7da7cc12010-08-05 17:02:38 +02002510 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002511 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002512 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002513
Johannes Berg77fdaa12009-07-07 03:45:17 +02002514 return 0;
2515}
2516
2517int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
Johannes Berg667503d2009-07-07 03:56:11 +02002518 struct cfg80211_disassoc_request *req,
2519 void *cookie)
Johannes Berg77fdaa12009-07-07 03:45:17 +02002520{
2521 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Jouni Malinene69e95d2010-03-29 23:29:31 -07002522 u8 bssid[ETH_ALEN];
Johannes Berg77fdaa12009-07-07 03:45:17 +02002523
Johannes Berg77fdaa12009-07-07 03:45:17 +02002524 mutex_lock(&ifmgd->mtx);
2525
Johannes Berg8d8b2612009-07-25 11:58:36 +02002526 /*
2527 * cfg80211 should catch this ... but it's racy since
2528 * we can receive a disassoc frame, process it, hand it
2529 * to cfg80211 while that's in a locked section already
2530 * trying to tell us that the user wants to disconnect.
2531 */
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002532 if (ifmgd->associated != req->bss) {
Johannes Berg77fdaa12009-07-07 03:45:17 +02002533 mutex_unlock(&ifmgd->mtx);
2534 return -ENOLINK;
2535 }
2536
Johannes Berg0ff71612009-09-26 14:45:41 +02002537 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
Johannes Berg47846c92009-11-25 17:46:19 +01002538 sdata->name, req->bss->bssid, req->reason_code);
Johannes Berg0ff71612009-09-26 14:45:41 +02002539
Jouni Malinene69e95d2010-03-29 23:29:31 -07002540 memcpy(bssid, req->bss->bssid, ETH_ALEN);
Johannes Berg53f73c02010-10-05 19:37:40 +02002541 ieee80211_set_disassoc(sdata, false, true);
Johannes Berg77fdaa12009-07-07 03:45:17 +02002542
2543 mutex_unlock(&ifmgd->mtx);
2544
2545 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
Johannes Berg667503d2009-07-07 03:56:11 +02002546 IEEE80211_STYPE_DISASSOC, req->reason_code,
Jouni Malinend5cdfac2010-04-04 09:37:19 +03002547 cookie, !req->local_state_change);
Jouni Malinene69e95d2010-03-29 23:29:31 -07002548 sta_info_destroy_addr(sdata, bssid);
Johannes Bergbc83b682009-11-29 12:19:06 +01002549
Johannes Berg7da7cc12010-08-05 17:02:38 +02002550 mutex_lock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002551 ieee80211_recalc_idle(sdata->local);
Johannes Berg7da7cc12010-08-05 17:02:38 +02002552 mutex_unlock(&sdata->local->mtx);
Johannes Bergbc83b682009-11-29 12:19:06 +01002553
Johannes Berg77fdaa12009-07-07 03:45:17 +02002554 return 0;
2555}
Jouni Malinen026331c2010-02-15 12:53:10 +02002556
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002557void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2558 enum nl80211_cqm_rssi_threshold_event rssi_event,
2559 gfp_t gfp)
2560{
2561 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2562
Johannes Bergb5878a22010-04-07 16:48:40 +02002563 trace_api_cqm_rssi_notify(sdata, rssi_event);
2564
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002565 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2566}
2567EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);