]>
Commit | Line | Data |
---|---|---|
f0706e82 JB |
1 | /* |
2 | * BSS client mode implementation | |
5394af4d | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
f0706e82 JB |
4 | * 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 | ||
5b323edb | 14 | #include <linux/delay.h> |
f0706e82 JB |
15 | #include <linux/if_ether.h> |
16 | #include <linux/skbuff.h> | |
f0706e82 | 17 | #include <linux/if_arp.h> |
f0706e82 | 18 | #include <linux/etherdevice.h> |
d0709a65 | 19 | #include <linux/rtnetlink.h> |
10f644a4 | 20 | #include <linux/pm_qos_params.h> |
d91f36db | 21 | #include <linux/crc32.h> |
5a0e3ad6 | 22 | #include <linux/slab.h> |
f0706e82 | 23 | #include <net/mac80211.h> |
472dbc45 | 24 | #include <asm/unaligned.h> |
60f8b39c | 25 | |
f0706e82 | 26 | #include "ieee80211_i.h" |
24487981 | 27 | #include "driver-ops.h" |
2c8dccc7 JB |
28 | #include "rate.h" |
29 | #include "led.h" | |
f0706e82 | 30 | |
72a8a3ed | 31 | #define IEEE80211_MAX_NULLFUNC_TRIES 2 |
a43abf29 | 32 | #define IEEE80211_MAX_PROBE_TRIES 5 |
b291ba11 JB |
33 | |
34 | /* | |
7ccc8bd7 FF |
35 | * 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. | |
b291ba11 | 41 | */ |
7ccc8bd7 FF |
42 | #define IEEE80211_BEACON_LOSS_COUNT 7 |
43 | ||
b291ba11 JB |
44 | /* |
45 | * Time the connection can be idle before we probe | |
46 | * it to see if we can still talk to the AP. | |
47 | */ | |
d1c5091f | 48 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
b291ba11 JB |
49 | /* |
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 | */ | |
d1c5091f | 54 | #define IEEE80211_PROBE_WAIT (HZ / 2) |
f0706e82 | 55 | |
17e4ec14 JM |
56 | /* |
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 | ||
391a200a JM |
63 | /* |
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 | ||
5bb644a0 JB |
69 | #define TMR_RUNNING_TIMER 0 |
70 | #define TMR_RUNNING_CHANSW 1 | |
71 | ||
77fdaa12 JB |
72 | /* |
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 | */ | |
78 | enum 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 | ||
5d1ec85f JB |
94 | /* caller must tell cfg80211 about internal error */ |
95 | RX_MGMT_CFG80211_ASSOC_ERROR, | |
77fdaa12 JB |
96 | }; |
97 | ||
5484e237 | 98 | /* utils */ |
77fdaa12 JB |
99 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
100 | { | |
46a5ebaf | 101 | lockdep_assert_held(&ifmgd->mtx); |
77fdaa12 JB |
102 | } |
103 | ||
ca386f31 JB |
104 | /* |
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 | */ | |
114 | static 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 | ||
d3a910a8 | 124 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
b291ba11 JB |
125 | { |
126 | if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER) | |
127 | return; | |
128 | ||
129 | mod_timer(&sdata->u.mgd.bcn_mon_timer, | |
7ccc8bd7 | 130 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
b291ba11 JB |
131 | } |
132 | ||
be099e82 LR |
133 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
134 | { | |
0c699c3a LR |
135 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
136 | ||
be099e82 LR |
137 | 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)); | |
0c699c3a LR |
142 | |
143 | ifmgd->probe_send_count = 0; | |
be099e82 LR |
144 | } |
145 | ||
5484e237 | 146 | static int ecw2cw(int ecw) |
60f8b39c | 147 | { |
5484e237 | 148 | return (1 << ecw) - 1; |
60f8b39c JB |
149 | } |
150 | ||
d5522e03 JB |
151 | /* |
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 | */ | |
156 | static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata, | |
157 | struct ieee80211_ht_info *hti, | |
77fdaa12 | 158 | const u8 *bssid, u16 ap_ht_cap_flags) |
d5522e03 JB |
159 | { |
160 | struct ieee80211_local *local = sdata->local; | |
161 | struct ieee80211_supported_band *sband; | |
d5522e03 JB |
162 | struct sta_info *sta; |
163 | u32 changed = 0; | |
172710bf | 164 | int hti_cfreq; |
9ed6bcce | 165 | u16 ht_opmode; |
0aaffa9b JB |
166 | bool enable_ht = true; |
167 | enum nl80211_channel_type prev_chantype; | |
d5522e03 JB |
168 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
169 | ||
170 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
171 | ||
0aaffa9b JB |
172 | prev_chantype = sdata->vif.bss_conf.channel_type; |
173 | ||
d5522e03 JB |
174 | /* HT is not supported */ |
175 | if (!sband->ht_cap.ht_supported) | |
176 | enable_ht = false; | |
177 | ||
172710bf BG |
178 | if (enable_ht) { |
179 | hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan, | |
180 | sband->band); | |
181 | /* check that channel matches the right operating channel */ | |
182 | if (local->hw.conf.channel->center_freq != hti_cfreq) { | |
183 | /* Some APs mess this up, evidently. | |
184 | * Netgear WNDR3700 sometimes reports 4 higher than | |
185 | * the actual channel, for instance. | |
186 | */ | |
187 | printk(KERN_DEBUG | |
188 | "%s: Wrong control channel in association" | |
189 | " response: configured center-freq: %d" | |
190 | " hti-cfreq: %d hti->control_chan: %d" | |
191 | " band: %d. Disabling HT.\n", | |
192 | sdata->name, | |
193 | local->hw.conf.channel->center_freq, | |
194 | hti_cfreq, hti->control_chan, | |
195 | sband->band); | |
196 | enable_ht = false; | |
197 | } | |
198 | } | |
d5522e03 JB |
199 | |
200 | if (enable_ht) { | |
201 | channel_type = NL80211_CHAN_HT20; | |
202 | ||
203 | if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) && | |
204 | (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && | |
205 | (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) { | |
206 | switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { | |
207 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: | |
768777ea LR |
208 | if (!(local->hw.conf.channel->flags & |
209 | IEEE80211_CHAN_NO_HT40PLUS)) | |
210 | channel_type = NL80211_CHAN_HT40PLUS; | |
d5522e03 JB |
211 | break; |
212 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: | |
768777ea LR |
213 | if (!(local->hw.conf.channel->flags & |
214 | IEEE80211_CHAN_NO_HT40MINUS)) | |
215 | channel_type = NL80211_CHAN_HT40MINUS; | |
d5522e03 JB |
216 | break; |
217 | } | |
218 | } | |
219 | } | |
220 | ||
fe6f212c RC |
221 | if (local->tmp_channel) |
222 | local->tmp_channel_type = channel_type; | |
d5522e03 | 223 | |
0aaffa9b JB |
224 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) { |
225 | /* can only fail due to HT40+/- mismatch */ | |
226 | channel_type = NL80211_CHAN_HT20; | |
227 | WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type)); | |
228 | } | |
d5522e03 | 229 | |
0aaffa9b JB |
230 | /* channel_type change automatically detected */ |
231 | ieee80211_hw_config(local, 0); | |
d5522e03 | 232 | |
0aaffa9b | 233 | if (prev_chantype != channel_type) { |
d5522e03 | 234 | rcu_read_lock(); |
abe60632 | 235 | sta = sta_info_get(sdata, bssid); |
d5522e03 JB |
236 | if (sta) |
237 | rate_control_rate_update(local, sband, sta, | |
4fa00437 | 238 | IEEE80211_RC_HT_CHANGED, |
0aaffa9b | 239 | channel_type); |
d5522e03 | 240 | rcu_read_unlock(); |
0aaffa9b | 241 | } |
d5522e03 | 242 | |
9ed6bcce | 243 | ht_opmode = le16_to_cpu(hti->operation_mode); |
d5522e03 JB |
244 | |
245 | /* if bss configuration changed store the new one */ | |
0aaffa9b JB |
246 | if (sdata->ht_opmode_valid != enable_ht || |
247 | sdata->vif.bss_conf.ht_operation_mode != ht_opmode || | |
248 | prev_chantype != channel_type) { | |
d5522e03 | 249 | changed |= BSS_CHANGED_HT; |
9ed6bcce | 250 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
0aaffa9b | 251 | sdata->ht_opmode_valid = enable_ht; |
d5522e03 JB |
252 | } |
253 | ||
254 | return changed; | |
255 | } | |
256 | ||
9c6bd790 JB |
257 | /* frame sending functions */ |
258 | ||
ef422bc0 | 259 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
667503dd | 260 | const u8 *bssid, u16 stype, u16 reason, |
d5cdfacb | 261 | void *cookie, bool send_frame) |
9ac19a90 JB |
262 | { |
263 | struct ieee80211_local *local = sdata->local; | |
46900298 | 264 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9ac19a90 JB |
265 | struct sk_buff *skb; |
266 | struct ieee80211_mgmt *mgmt; | |
9aed3cc1 | 267 | |
65fc73ac | 268 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
9ac19a90 | 269 | if (!skb) { |
ef422bc0 | 270 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
47846c9b | 271 | "deauth/disassoc frame\n", sdata->name); |
9ac19a90 JB |
272 | return; |
273 | } | |
274 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
275 | ||
276 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
277 | memset(mgmt, 0, 24); | |
77fdaa12 | 278 | memcpy(mgmt->da, bssid, ETH_ALEN); |
47846c9b | 279 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
77fdaa12 | 280 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
ef422bc0 | 281 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
9ac19a90 | 282 | skb_put(skb, 2); |
ef422bc0 | 283 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
9ac19a90 JB |
284 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
285 | ||
53b46b84 | 286 | if (stype == IEEE80211_STYPE_DEAUTH) |
ce470613 HS |
287 | if (cookie) |
288 | __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); | |
289 | else | |
290 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); | |
53b46b84 | 291 | else |
ce470613 HS |
292 | if (cookie) |
293 | __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); | |
294 | else | |
295 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); | |
62ae67be JB |
296 | if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED)) |
297 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; | |
d5cdfacb JM |
298 | |
299 | if (send_frame) | |
300 | ieee80211_tx_skb(sdata, skb); | |
301 | else | |
302 | kfree_skb(skb); | |
9ac19a90 JB |
303 | } |
304 | ||
572e0012 KV |
305 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
306 | struct ieee80211_sub_if_data *sdata) | |
307 | { | |
572e0012 KV |
308 | struct ieee80211_pspoll *pspoll; |
309 | struct sk_buff *skb; | |
572e0012 | 310 | |
d8cd189e KV |
311 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
312 | if (!skb) | |
572e0012 | 313 | return; |
572e0012 | 314 | |
d8cd189e KV |
315 | pspoll = (struct ieee80211_pspoll *) skb->data; |
316 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
572e0012 | 317 | |
62ae67be JB |
318 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
319 | ieee80211_tx_skb(sdata, skb); | |
572e0012 KV |
320 | } |
321 | ||
965bedad JB |
322 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
323 | struct ieee80211_sub_if_data *sdata, | |
324 | int powersave) | |
325 | { | |
326 | struct sk_buff *skb; | |
d8cd189e | 327 | struct ieee80211_hdr_3addr *nullfunc; |
965bedad | 328 | |
d8cd189e KV |
329 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif); |
330 | if (!skb) | |
965bedad | 331 | return; |
965bedad | 332 | |
d8cd189e | 333 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
965bedad | 334 | if (powersave) |
d8cd189e | 335 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
965bedad | 336 | |
62ae67be JB |
337 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
338 | ieee80211_tx_skb(sdata, skb); | |
965bedad JB |
339 | } |
340 | ||
d524215f FF |
341 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
342 | struct ieee80211_sub_if_data *sdata) | |
343 | { | |
344 | struct sk_buff *skb; | |
345 | struct ieee80211_hdr *nullfunc; | |
346 | __le16 fc; | |
347 | ||
348 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
349 | return; | |
350 | ||
351 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); | |
352 | if (!skb) { | |
353 | printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr " | |
354 | "nullfunc frame\n", sdata->name); | |
355 | return; | |
356 | } | |
357 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
358 | ||
359 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30); | |
360 | memset(nullfunc, 0, 30); | |
361 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | |
362 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); | |
363 | nullfunc->frame_control = fc; | |
364 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); | |
365 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | |
366 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); | |
367 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); | |
368 | ||
369 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; | |
370 | ieee80211_tx_skb(sdata, skb); | |
371 | } | |
372 | ||
cc32abd4 JB |
373 | /* spectrum management related things */ |
374 | static void ieee80211_chswitch_work(struct work_struct *work) | |
375 | { | |
376 | struct ieee80211_sub_if_data *sdata = | |
377 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); | |
cc32abd4 JB |
378 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
379 | ||
9607e6b6 | 380 | if (!ieee80211_sdata_running(sdata)) |
cc32abd4 JB |
381 | return; |
382 | ||
77fdaa12 JB |
383 | mutex_lock(&ifmgd->mtx); |
384 | if (!ifmgd->associated) | |
385 | goto out; | |
cc32abd4 JB |
386 | |
387 | sdata->local->oper_channel = sdata->local->csa_channel; | |
5ce6e438 JB |
388 | if (!sdata->local->ops->channel_switch) { |
389 | /* call "hw_config" only if doing sw channel switch */ | |
390 | ieee80211_hw_config(sdata->local, | |
391 | IEEE80211_CONF_CHANGE_CHANNEL); | |
392 | } | |
77fdaa12 | 393 | |
cc32abd4 | 394 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
0c1ad2ca | 395 | ifmgd->associated->channel = sdata->local->oper_channel; |
cc32abd4 | 396 | |
cc32abd4 JB |
397 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
398 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
77fdaa12 JB |
399 | out: |
400 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; | |
401 | mutex_unlock(&ifmgd->mtx); | |
cc32abd4 JB |
402 | } |
403 | ||
5ce6e438 JB |
404 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
405 | { | |
406 | struct ieee80211_sub_if_data *sdata; | |
407 | struct ieee80211_if_managed *ifmgd; | |
408 | ||
409 | sdata = vif_to_sdata(vif); | |
410 | ifmgd = &sdata->u.mgd; | |
411 | ||
412 | trace_api_chswitch_done(sdata, success); | |
413 | if (!success) { | |
414 | /* | |
415 | * If the channel switch was not successful, stay | |
416 | * around on the old channel. We currently lack | |
417 | * good handling of this situation, possibly we | |
418 | * should just drop the association. | |
419 | */ | |
420 | sdata->local->csa_channel = sdata->local->oper_channel; | |
421 | } | |
422 | ||
423 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); | |
424 | } | |
425 | EXPORT_SYMBOL(ieee80211_chswitch_done); | |
426 | ||
cc32abd4 JB |
427 | static void ieee80211_chswitch_timer(unsigned long data) |
428 | { | |
429 | struct ieee80211_sub_if_data *sdata = | |
430 | (struct ieee80211_sub_if_data *) data; | |
431 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
432 | ||
5bb644a0 JB |
433 | if (sdata->local->quiescing) { |
434 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
435 | return; | |
436 | } | |
437 | ||
42935eca | 438 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
cc32abd4 JB |
439 | } |
440 | ||
441 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, | |
442 | struct ieee80211_channel_sw_ie *sw_elem, | |
5ce6e438 JB |
443 | struct ieee80211_bss *bss, |
444 | u64 timestamp) | |
cc32abd4 | 445 | { |
0c1ad2ca JB |
446 | struct cfg80211_bss *cbss = |
447 | container_of((void *)bss, struct cfg80211_bss, priv); | |
cc32abd4 JB |
448 | struct ieee80211_channel *new_ch; |
449 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
59eb21a6 BR |
450 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, |
451 | cbss->channel->band); | |
cc32abd4 | 452 | |
77fdaa12 JB |
453 | ASSERT_MGD_MTX(ifmgd); |
454 | ||
455 | if (!ifmgd->associated) | |
cc32abd4 JB |
456 | return; |
457 | ||
fbe9c429 | 458 | if (sdata->local->scanning) |
cc32abd4 JB |
459 | return; |
460 | ||
461 | /* Disregard subsequent beacons if we are already running a timer | |
462 | processing a CSA */ | |
463 | ||
464 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) | |
465 | return; | |
466 | ||
467 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); | |
468 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) | |
469 | return; | |
470 | ||
471 | sdata->local->csa_channel = new_ch; | |
472 | ||
5ce6e438 JB |
473 | if (sdata->local->ops->channel_switch) { |
474 | /* use driver's channel switch callback */ | |
475 | struct ieee80211_channel_switch ch_switch; | |
476 | memset(&ch_switch, 0, sizeof(ch_switch)); | |
477 | ch_switch.timestamp = timestamp; | |
478 | if (sw_elem->mode) { | |
479 | ch_switch.block_tx = true; | |
480 | ieee80211_stop_queues_by_reason(&sdata->local->hw, | |
481 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
482 | } | |
483 | ch_switch.channel = new_ch; | |
484 | ch_switch.count = sw_elem->count; | |
485 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; | |
486 | drv_channel_switch(sdata->local, &ch_switch); | |
487 | return; | |
488 | } | |
489 | ||
490 | /* channel switch handled in software */ | |
cc32abd4 | 491 | if (sw_elem->count <= 1) { |
42935eca | 492 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
cc32abd4 | 493 | } else { |
9feaddc7 WYG |
494 | if (sw_elem->mode) |
495 | ieee80211_stop_queues_by_reason(&sdata->local->hw, | |
cc32abd4 JB |
496 | IEEE80211_QUEUE_STOP_REASON_CSA); |
497 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; | |
498 | mod_timer(&ifmgd->chswitch_timer, | |
499 | jiffies + | |
500 | msecs_to_jiffies(sw_elem->count * | |
0c1ad2ca | 501 | cbss->beacon_interval)); |
cc32abd4 JB |
502 | } |
503 | } | |
504 | ||
505 | static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, | |
506 | u16 capab_info, u8 *pwr_constr_elem, | |
507 | u8 pwr_constr_elem_len) | |
508 | { | |
509 | struct ieee80211_conf *conf = &sdata->local->hw.conf; | |
510 | ||
511 | if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT)) | |
512 | return; | |
513 | ||
514 | /* Power constraint IE length should be 1 octet */ | |
515 | if (pwr_constr_elem_len != 1) | |
516 | return; | |
517 | ||
518 | if ((*pwr_constr_elem <= conf->channel->max_power) && | |
519 | (*pwr_constr_elem != sdata->local->power_constr_level)) { | |
520 | sdata->local->power_constr_level = *pwr_constr_elem; | |
521 | ieee80211_hw_config(sdata->local, 0); | |
522 | } | |
523 | } | |
524 | ||
f90754c1 JO |
525 | void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) |
526 | { | |
527 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
528 | struct ieee80211_local *local = sdata->local; | |
529 | struct ieee80211_conf *conf = &local->hw.conf; | |
530 | ||
531 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || | |
532 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || | |
533 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); | |
534 | ||
535 | local->disable_dynamic_ps = false; | |
536 | conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout; | |
537 | } | |
538 | EXPORT_SYMBOL(ieee80211_enable_dyn_ps); | |
539 | ||
540 | void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif) | |
541 | { | |
542 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
543 | struct ieee80211_local *local = sdata->local; | |
544 | struct ieee80211_conf *conf = &local->hw.conf; | |
545 | ||
546 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || | |
547 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || | |
548 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); | |
549 | ||
550 | local->disable_dynamic_ps = true; | |
551 | conf->dynamic_ps_timeout = 0; | |
552 | del_timer_sync(&local->dynamic_ps_timer); | |
553 | ieee80211_queue_work(&local->hw, | |
554 | &local->dynamic_ps_enable_work); | |
555 | } | |
556 | EXPORT_SYMBOL(ieee80211_disable_dyn_ps); | |
557 | ||
965bedad JB |
558 | /* powersave */ |
559 | static void ieee80211_enable_ps(struct ieee80211_local *local, | |
560 | struct ieee80211_sub_if_data *sdata) | |
561 | { | |
562 | struct ieee80211_conf *conf = &local->hw.conf; | |
563 | ||
d5edaedc JB |
564 | /* |
565 | * If we are scanning right now then the parameters will | |
566 | * take effect when scan finishes. | |
567 | */ | |
fbe9c429 | 568 | if (local->scanning) |
d5edaedc JB |
569 | return; |
570 | ||
965bedad JB |
571 | if (conf->dynamic_ps_timeout > 0 && |
572 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { | |
573 | mod_timer(&local->dynamic_ps_timer, jiffies + | |
574 | msecs_to_jiffies(conf->dynamic_ps_timeout)); | |
575 | } else { | |
576 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
577 | ieee80211_send_nullfunc(local, sdata, 1); | |
375177bf | 578 | |
2a13052f JO |
579 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
580 | (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) | |
581 | return; | |
582 | ||
583 | conf->flags |= IEEE80211_CONF_PS; | |
584 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
965bedad JB |
585 | } |
586 | } | |
587 | ||
588 | static void ieee80211_change_ps(struct ieee80211_local *local) | |
589 | { | |
590 | struct ieee80211_conf *conf = &local->hw.conf; | |
591 | ||
592 | if (local->ps_sdata) { | |
965bedad JB |
593 | ieee80211_enable_ps(local, local->ps_sdata); |
594 | } else if (conf->flags & IEEE80211_CONF_PS) { | |
595 | conf->flags &= ~IEEE80211_CONF_PS; | |
596 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
597 | del_timer_sync(&local->dynamic_ps_timer); | |
598 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
599 | } | |
600 | } | |
601 | ||
602 | /* need to hold RTNL or interface lock */ | |
10f644a4 | 603 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
965bedad JB |
604 | { |
605 | struct ieee80211_sub_if_data *sdata, *found = NULL; | |
606 | int count = 0; | |
195e294d | 607 | int timeout; |
965bedad JB |
608 | |
609 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { | |
610 | local->ps_sdata = NULL; | |
611 | return; | |
612 | } | |
613 | ||
af6b6374 JB |
614 | if (!list_empty(&local->work_list)) { |
615 | local->ps_sdata = NULL; | |
616 | goto change; | |
617 | } | |
618 | ||
965bedad | 619 | list_for_each_entry(sdata, &local->interfaces, list) { |
9607e6b6 | 620 | if (!ieee80211_sdata_running(sdata)) |
965bedad | 621 | continue; |
8c7914de RM |
622 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
623 | /* If an AP vif is found, then disable PS | |
624 | * by setting the count to zero thereby setting | |
625 | * ps_sdata to NULL. | |
626 | */ | |
627 | count = 0; | |
628 | break; | |
629 | } | |
965bedad JB |
630 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
631 | continue; | |
632 | found = sdata; | |
633 | count++; | |
634 | } | |
635 | ||
43f78531 | 636 | if (count == 1 && found->u.mgd.powersave && |
af6b6374 | 637 | found->u.mgd.associated && |
56007a02 | 638 | found->u.mgd.associated->beacon_ies && |
b291ba11 JB |
639 | !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | |
640 | IEEE80211_STA_CONNECTION_POLL))) { | |
f90754c1 | 641 | struct ieee80211_conf *conf = &local->hw.conf; |
10f644a4 JB |
642 | s32 beaconint_us; |
643 | ||
644 | if (latency < 0) | |
ed77134b | 645 | latency = pm_qos_request(PM_QOS_NETWORK_LATENCY); |
10f644a4 JB |
646 | |
647 | beaconint_us = ieee80211_tu_to_usec( | |
648 | found->vif.bss_conf.beacon_int); | |
649 | ||
ff616381 | 650 | timeout = local->dynamic_ps_forced_timeout; |
195e294d JO |
651 | if (timeout < 0) { |
652 | /* | |
ff616381 JO |
653 | * Go to full PSM if the user configures a very low |
654 | * latency requirement. | |
0ab82b04 EP |
655 | * The 2000 second value is there for compatibility |
656 | * until the PM_QOS_NETWORK_LATENCY is configured | |
657 | * with real values. | |
195e294d | 658 | */ |
0ab82b04 EP |
659 | if (latency > (1900 * USEC_PER_MSEC) && |
660 | latency != (2000 * USEC_PER_SEC)) | |
195e294d | 661 | timeout = 0; |
ff616381 JO |
662 | else |
663 | timeout = 100; | |
195e294d | 664 | } |
f90754c1 JO |
665 | local->dynamic_ps_user_timeout = timeout; |
666 | if (!local->disable_dynamic_ps) | |
667 | conf->dynamic_ps_timeout = | |
668 | local->dynamic_ps_user_timeout; | |
195e294d | 669 | |
04fe2037 | 670 | if (beaconint_us > latency) { |
10f644a4 | 671 | local->ps_sdata = NULL; |
04fe2037 | 672 | } else { |
56007a02 | 673 | struct ieee80211_bss *bss; |
04fe2037 | 674 | int maxslp = 1; |
56007a02 | 675 | u8 dtimper; |
04fe2037 | 676 | |
56007a02 JB |
677 | bss = (void *)found->u.mgd.associated->priv; |
678 | dtimper = bss->dtim_period; | |
679 | ||
680 | /* If the TIM IE is invalid, pretend the value is 1 */ | |
681 | if (!dtimper) | |
682 | dtimper = 1; | |
683 | else if (dtimper > 1) | |
04fe2037 JB |
684 | maxslp = min_t(int, dtimper, |
685 | latency / beaconint_us); | |
686 | ||
9ccebe61 | 687 | local->hw.conf.max_sleep_period = maxslp; |
56007a02 | 688 | local->hw.conf.ps_dtim_period = dtimper; |
10f644a4 | 689 | local->ps_sdata = found; |
04fe2037 | 690 | } |
10f644a4 | 691 | } else { |
965bedad | 692 | local->ps_sdata = NULL; |
10f644a4 | 693 | } |
965bedad | 694 | |
af6b6374 | 695 | change: |
965bedad JB |
696 | ieee80211_change_ps(local); |
697 | } | |
698 | ||
699 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) | |
700 | { | |
701 | struct ieee80211_local *local = | |
702 | container_of(work, struct ieee80211_local, | |
703 | dynamic_ps_disable_work); | |
704 | ||
705 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | |
706 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
707 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
708 | } | |
709 | ||
710 | ieee80211_wake_queues_by_reason(&local->hw, | |
711 | IEEE80211_QUEUE_STOP_REASON_PS); | |
712 | } | |
713 | ||
714 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) | |
715 | { | |
716 | struct ieee80211_local *local = | |
717 | container_of(work, struct ieee80211_local, | |
718 | dynamic_ps_enable_work); | |
719 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; | |
375177bf | 720 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
965bedad JB |
721 | |
722 | /* can only happen when PS was just disabled anyway */ | |
723 | if (!sdata) | |
724 | return; | |
725 | ||
726 | if (local->hw.conf.flags & IEEE80211_CONF_PS) | |
727 | return; | |
728 | ||
375177bf VN |
729 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
730 | (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) | |
965bedad JB |
731 | ieee80211_send_nullfunc(local, sdata, 1); |
732 | ||
2a13052f JO |
733 | if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) && |
734 | (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) || | |
375177bf VN |
735 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
736 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; | |
737 | local->hw.conf.flags |= IEEE80211_CONF_PS; | |
738 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
739 | } | |
965bedad JB |
740 | } |
741 | ||
742 | void ieee80211_dynamic_ps_timer(unsigned long data) | |
743 | { | |
744 | struct ieee80211_local *local = (void *) data; | |
745 | ||
78f1a8b7 | 746 | if (local->quiescing || local->suspended) |
5bb644a0 JB |
747 | return; |
748 | ||
42935eca | 749 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
965bedad JB |
750 | } |
751 | ||
60f8b39c | 752 | /* MLME */ |
f698d856 | 753 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
4ced3f74 | 754 | struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
755 | u8 *wmm_param, size_t wmm_param_len) |
756 | { | |
f0706e82 | 757 | struct ieee80211_tx_queue_params params; |
4ced3f74 | 758 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
759 | size_t left; |
760 | int count; | |
ab13315a | 761 | u8 *pos, uapsd_queues = 0; |
f0706e82 | 762 | |
e1b3ec1a SG |
763 | if (!local->ops->conf_tx) |
764 | return; | |
765 | ||
af6b6374 | 766 | if (local->hw.queues < 4) |
3434fbd3 JB |
767 | return; |
768 | ||
769 | if (!wmm_param) | |
770 | return; | |
771 | ||
f0706e82 JB |
772 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
773 | return; | |
ab13315a KV |
774 | |
775 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) | |
50ae0cf1 | 776 | uapsd_queues = local->uapsd_queues; |
ab13315a | 777 | |
f0706e82 | 778 | count = wmm_param[6] & 0x0f; |
46900298 | 779 | if (count == ifmgd->wmm_last_param_set) |
f0706e82 | 780 | return; |
46900298 | 781 | ifmgd->wmm_last_param_set = count; |
f0706e82 JB |
782 | |
783 | pos = wmm_param + 8; | |
784 | left = wmm_param_len - 8; | |
785 | ||
786 | memset(¶ms, 0, sizeof(params)); | |
787 | ||
f0706e82 JB |
788 | local->wmm_acm = 0; |
789 | for (; left >= 4; left -= 4, pos += 4) { | |
790 | int aci = (pos[0] >> 5) & 0x03; | |
791 | int acm = (pos[0] >> 4) & 0x01; | |
ab13315a | 792 | bool uapsd = false; |
f0706e82 JB |
793 | int queue; |
794 | ||
795 | switch (aci) { | |
0eeb59fe | 796 | case 1: /* AC_BK */ |
e100bb64 | 797 | queue = 3; |
988c0f72 | 798 | if (acm) |
0eeb59fe | 799 | local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
ab13315a KV |
800 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
801 | uapsd = true; | |
f0706e82 | 802 | break; |
0eeb59fe | 803 | case 2: /* AC_VI */ |
e100bb64 | 804 | queue = 1; |
988c0f72 | 805 | if (acm) |
0eeb59fe | 806 | local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
ab13315a KV |
807 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
808 | uapsd = true; | |
f0706e82 | 809 | break; |
0eeb59fe | 810 | case 3: /* AC_VO */ |
e100bb64 | 811 | queue = 0; |
988c0f72 | 812 | if (acm) |
0eeb59fe | 813 | local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
ab13315a KV |
814 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
815 | uapsd = true; | |
f0706e82 | 816 | break; |
0eeb59fe | 817 | case 0: /* AC_BE */ |
f0706e82 | 818 | default: |
e100bb64 | 819 | queue = 2; |
988c0f72 | 820 | if (acm) |
0eeb59fe | 821 | local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
ab13315a KV |
822 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
823 | uapsd = true; | |
f0706e82 JB |
824 | break; |
825 | } | |
826 | ||
827 | params.aifs = pos[0] & 0x0f; | |
828 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); | |
829 | params.cw_min = ecw2cw(pos[1] & 0x0f); | |
f434b2d1 | 830 | params.txop = get_unaligned_le16(pos + 2); |
ab13315a KV |
831 | params.uapsd = uapsd; |
832 | ||
f4ea83dd | 833 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
0fb9a9ec JP |
834 | wiphy_debug(local->hw.wiphy, |
835 | "WMM queue=%d aci=%d acm=%d aifs=%d " | |
836 | "cWmin=%d cWmax=%d txop=%d uapsd=%d\n", | |
837 | queue, aci, acm, | |
838 | params.aifs, params.cw_min, params.cw_max, | |
839 | params.txop, params.uapsd); | |
3330d7be | 840 | #endif |
e1b3ec1a | 841 | if (drv_conf_tx(local, queue, ¶ms)) |
0fb9a9ec JP |
842 | wiphy_debug(local->hw.wiphy, |
843 | "failed to set TX queue parameters for queue %d\n", | |
844 | queue); | |
f0706e82 | 845 | } |
e1b3ec1a SG |
846 | |
847 | /* enable WMM or activate new settings */ | |
4ced3f74 JB |
848 | sdata->vif.bss_conf.qos = true; |
849 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); | |
f0706e82 JB |
850 | } |
851 | ||
7a5158ef JB |
852 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
853 | u16 capab, bool erp_valid, u8 erp) | |
5628221c | 854 | { |
bda3933a | 855 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
471b3efd | 856 | u32 changed = 0; |
7a5158ef JB |
857 | bool use_protection; |
858 | bool use_short_preamble; | |
859 | bool use_short_slot; | |
860 | ||
861 | if (erp_valid) { | |
862 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; | |
863 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; | |
864 | } else { | |
865 | use_protection = false; | |
866 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); | |
867 | } | |
868 | ||
869 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); | |
43d35343 FF |
870 | if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) |
871 | use_short_slot = true; | |
5628221c | 872 | |
471b3efd | 873 | if (use_protection != bss_conf->use_cts_prot) { |
471b3efd JB |
874 | bss_conf->use_cts_prot = use_protection; |
875 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
5628221c | 876 | } |
7e9ed188 | 877 | |
d43c7b37 | 878 | if (use_short_preamble != bss_conf->use_short_preamble) { |
d43c7b37 | 879 | bss_conf->use_short_preamble = use_short_preamble; |
471b3efd | 880 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
7e9ed188 | 881 | } |
d9430a32 | 882 | |
7a5158ef | 883 | if (use_short_slot != bss_conf->use_short_slot) { |
7a5158ef JB |
884 | bss_conf->use_short_slot = use_short_slot; |
885 | changed |= BSS_CHANGED_ERP_SLOT; | |
50c4afb9 JL |
886 | } |
887 | ||
888 | return changed; | |
889 | } | |
890 | ||
f698d856 | 891 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
0c1ad2ca | 892 | struct cfg80211_bss *cbss, |
ae5eb026 | 893 | u32 bss_info_changed) |
f0706e82 | 894 | { |
0c1ad2ca | 895 | struct ieee80211_bss *bss = (void *)cbss->priv; |
471b3efd | 896 | struct ieee80211_local *local = sdata->local; |
68542962 | 897 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
d6f2da5b | 898 | |
ae5eb026 | 899 | bss_info_changed |= BSS_CHANGED_ASSOC; |
77fdaa12 | 900 | /* set timing information */ |
68542962 JO |
901 | bss_conf->beacon_int = cbss->beacon_interval; |
902 | bss_conf->timestamp = cbss->tsf; | |
5628221c | 903 | |
77fdaa12 JB |
904 | bss_info_changed |= BSS_CHANGED_BEACON_INT; |
905 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, | |
0c1ad2ca | 906 | cbss->capability, bss->has_erp_value, bss->erp_value); |
21c0cbe7 | 907 | |
7ccc8bd7 FF |
908 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
909 | IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); | |
910 | ||
0c1ad2ca JB |
911 | sdata->u.mgd.associated = cbss; |
912 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); | |
f0706e82 | 913 | |
17e4ec14 JM |
914 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
915 | ||
b291ba11 JB |
916 | /* just to be sure */ |
917 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
918 | IEEE80211_STA_BEACON_POLL); | |
919 | ||
9ac19a90 | 920 | ieee80211_led_assoc(local, 1); |
9306102e | 921 | |
e5b900d2 JB |
922 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
923 | bss_conf->dtim_period = bss->dtim_period; | |
924 | else | |
925 | bss_conf->dtim_period = 0; | |
926 | ||
68542962 | 927 | bss_conf->assoc = 1; |
96dd22ac JB |
928 | /* |
929 | * For now just always ask the driver to update the basic rateset | |
930 | * when we have associated, we aren't checking whether it actually | |
931 | * changed or not. | |
932 | */ | |
ae5eb026 | 933 | bss_info_changed |= BSS_CHANGED_BASIC_RATES; |
9cef8737 JB |
934 | |
935 | /* And the BSSID changed - we're associated now */ | |
936 | bss_info_changed |= BSS_CHANGED_BSSID; | |
937 | ||
a97c13c3 JO |
938 | /* Tell the driver to monitor connection quality (if supported) */ |
939 | if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) && | |
68542962 | 940 | bss_conf->cqm_rssi_thold) |
a97c13c3 JO |
941 | bss_info_changed |= BSS_CHANGED_CQM; |
942 | ||
68542962 JO |
943 | /* Enable ARP filtering */ |
944 | if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) { | |
945 | bss_conf->arp_filter_enabled = sdata->arp_filter_state; | |
946 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; | |
947 | } | |
948 | ||
ae5eb026 | 949 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
f0706e82 | 950 | |
056508dc JB |
951 | mutex_lock(&local->iflist_mtx); |
952 | ieee80211_recalc_ps(local, -1); | |
025e6be2 | 953 | ieee80211_recalc_smps(local); |
056508dc | 954 | mutex_unlock(&local->iflist_mtx); |
e0cb686f | 955 | |
8a5b33f5 | 956 | netif_tx_start_all_queues(sdata->dev); |
9ac19a90 | 957 | netif_carrier_on(sdata->dev); |
f0706e82 JB |
958 | } |
959 | ||
e69e95db | 960 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
53f73c09 | 961 | bool remove_sta, bool tx) |
aa458d17 | 962 | { |
46900298 | 963 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
aa458d17 TW |
964 | struct ieee80211_local *local = sdata->local; |
965 | struct sta_info *sta; | |
e0cb686f | 966 | u32 changed = 0, config_changed = 0; |
b291ba11 | 967 | u8 bssid[ETH_ALEN]; |
aa458d17 | 968 | |
77fdaa12 JB |
969 | ASSERT_MGD_MTX(ifmgd); |
970 | ||
b291ba11 JB |
971 | if (WARN_ON(!ifmgd->associated)) |
972 | return; | |
973 | ||
0c1ad2ca | 974 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
b291ba11 | 975 | |
77fdaa12 JB |
976 | ifmgd->associated = NULL; |
977 | memset(ifmgd->bssid, 0, ETH_ALEN); | |
978 | ||
979 | /* | |
980 | * we need to commit the associated = NULL change because the | |
981 | * scan code uses that to determine whether this iface should | |
982 | * go to/wake up from powersave or not -- and could otherwise | |
983 | * wake the queues erroneously. | |
984 | */ | |
985 | smp_mb(); | |
986 | ||
987 | /* | |
988 | * Thus, we can only afterwards stop the queues -- to account | |
989 | * for the case where another CPU is finishing a scan at this | |
990 | * time -- we don't want the scan code to enable queues. | |
991 | */ | |
aa458d17 | 992 | |
8a5b33f5 | 993 | netif_tx_stop_all_queues(sdata->dev); |
aa458d17 TW |
994 | netif_carrier_off(sdata->dev); |
995 | ||
2a419056 | 996 | mutex_lock(&local->sta_mtx); |
abe60632 | 997 | sta = sta_info_get(sdata, bssid); |
4cad6c7c | 998 | if (sta) { |
2a419056 | 999 | set_sta_flags(sta, WLAN_STA_BLOCK_BA); |
53f73c09 | 1000 | ieee80211_sta_tear_down_BA_sessions(sta, tx); |
4cad6c7c | 1001 | } |
2a419056 | 1002 | mutex_unlock(&local->sta_mtx); |
aa458d17 | 1003 | |
f5e5bf25 TW |
1004 | changed |= ieee80211_reset_erp_info(sdata); |
1005 | ||
f5e5bf25 | 1006 | ieee80211_led_assoc(local, 0); |
ae5eb026 JB |
1007 | changed |= BSS_CHANGED_ASSOC; |
1008 | sdata->vif.bss_conf.assoc = false; | |
f5e5bf25 | 1009 | |
aa837e1d JB |
1010 | ieee80211_set_wmm_default(sdata); |
1011 | ||
4797938c | 1012 | /* channel(_type) changes are handled by ieee80211_hw_config */ |
0aaffa9b | 1013 | WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT)); |
e0cb686f | 1014 | |
413ad50a JB |
1015 | /* on the next assoc, re-program HT parameters */ |
1016 | sdata->ht_opmode_valid = false; | |
1017 | ||
a8302de9 VT |
1018 | local->power_constr_level = 0; |
1019 | ||
520eb820 KV |
1020 | del_timer_sync(&local->dynamic_ps_timer); |
1021 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
1022 | ||
e0cb686f KV |
1023 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
1024 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1025 | config_changed |= IEEE80211_CONF_CHANGE_PS; | |
1026 | } | |
ae5eb026 | 1027 | |
e0cb686f | 1028 | ieee80211_hw_config(local, config_changed); |
9cef8737 | 1029 | |
68542962 JO |
1030 | /* Disable ARP filtering */ |
1031 | if (sdata->vif.bss_conf.arp_filter_enabled) { | |
1032 | sdata->vif.bss_conf.arp_filter_enabled = false; | |
1033 | changed |= BSS_CHANGED_ARP_FILTER; | |
1034 | } | |
1035 | ||
0aaffa9b JB |
1036 | /* The BSSID (not really interesting) and HT changed */ |
1037 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; | |
ae5eb026 | 1038 | ieee80211_bss_info_change_notify(sdata, changed); |
8e268e47 | 1039 | |
e69e95db JM |
1040 | if (remove_sta) |
1041 | sta_info_destroy_addr(sdata, bssid); | |
b9dcf712 JB |
1042 | |
1043 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); | |
1044 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); | |
1045 | del_timer_sync(&sdata->u.mgd.timer); | |
1046 | del_timer_sync(&sdata->u.mgd.chswitch_timer); | |
aa458d17 | 1047 | } |
f0706e82 | 1048 | |
3cf335d5 KV |
1049 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
1050 | struct ieee80211_hdr *hdr) | |
1051 | { | |
1052 | /* | |
1053 | * We can postpone the mgd.timer whenever receiving unicast frames | |
1054 | * from AP because we know that the connection is working both ways | |
1055 | * at that time. But multicast frames (and hence also beacons) must | |
1056 | * be ignored here, because we need to trigger the timer during | |
b291ba11 JB |
1057 | * data idle periods for sending the periodic probe request to the |
1058 | * AP we're connected to. | |
3cf335d5 | 1059 | */ |
b291ba11 JB |
1060 | if (is_multicast_ether_addr(hdr->addr1)) |
1061 | return; | |
1062 | ||
be099e82 | 1063 | ieee80211_sta_reset_conn_monitor(sdata); |
3cf335d5 | 1064 | } |
f0706e82 | 1065 | |
4e5ff376 FF |
1066 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
1067 | { | |
1068 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1069 | ||
1070 | if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL | | |
1071 | IEEE80211_STA_CONNECTION_POLL))) | |
1072 | return; | |
1073 | ||
1074 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
1075 | IEEE80211_STA_BEACON_POLL); | |
1076 | mutex_lock(&sdata->local->iflist_mtx); | |
1077 | ieee80211_recalc_ps(sdata->local, -1); | |
1078 | mutex_unlock(&sdata->local->iflist_mtx); | |
1079 | ||
1080 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) | |
1081 | return; | |
1082 | ||
1083 | /* | |
1084 | * We've received a probe response, but are not sure whether | |
1085 | * we have or will be receiving any beacons or data, so let's | |
1086 | * schedule the timers again, just in case. | |
1087 | */ | |
1088 | ieee80211_sta_reset_beacon_monitor(sdata); | |
1089 | ||
1090 | mod_timer(&ifmgd->conn_mon_timer, | |
1091 | round_jiffies_up(jiffies + | |
1092 | IEEE80211_CONNECTION_IDLE_TIME)); | |
1093 | } | |
1094 | ||
1095 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, | |
04ac3c0e | 1096 | struct ieee80211_hdr *hdr, bool ack) |
4e5ff376 | 1097 | { |
75706d0e | 1098 | if (!ieee80211_is_data(hdr->frame_control)) |
4e5ff376 FF |
1099 | return; |
1100 | ||
04ac3c0e FF |
1101 | if (ack) |
1102 | ieee80211_sta_reset_conn_monitor(sdata); | |
4e5ff376 FF |
1103 | |
1104 | if (ieee80211_is_nullfunc(hdr->frame_control) && | |
1105 | sdata->u.mgd.probe_send_count > 0) { | |
04ac3c0e FF |
1106 | if (ack) |
1107 | sdata->u.mgd.probe_send_count = 0; | |
1108 | else | |
1109 | sdata->u.mgd.nullfunc_failed = true; | |
4e5ff376 FF |
1110 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
1111 | } | |
1112 | } | |
1113 | ||
a43abf29 ML |
1114 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
1115 | { | |
1116 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1117 | const u8 *ssid; | |
f01a067d LR |
1118 | u8 *dst = ifmgd->associated->bssid; |
1119 | u8 unicast_limit = max(1, IEEE80211_MAX_PROBE_TRIES - 3); | |
1120 | ||
1121 | /* | |
1122 | * Try sending broadcast probe requests for the last three | |
1123 | * probe requests after the first ones failed since some | |
1124 | * buggy APs only support broadcast probe requests. | |
1125 | */ | |
1126 | if (ifmgd->probe_send_count >= unicast_limit) | |
1127 | dst = NULL; | |
a43abf29 | 1128 | |
4e5ff376 FF |
1129 | /* |
1130 | * When the hardware reports an accurate Tx ACK status, it's | |
1131 | * better to send a nullfunc frame instead of a probe request, | |
1132 | * as it will kick us off the AP quickly if we aren't associated | |
1133 | * anymore. The timeout will be reset if the frame is ACKed by | |
1134 | * the AP. | |
1135 | */ | |
04ac3c0e FF |
1136 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
1137 | ifmgd->nullfunc_failed = false; | |
4e5ff376 | 1138 | ieee80211_send_nullfunc(sdata->local, sdata, 0); |
04ac3c0e | 1139 | } else { |
4e5ff376 FF |
1140 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
1141 | ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0); | |
1142 | } | |
a43abf29 ML |
1143 | |
1144 | ifmgd->probe_send_count++; | |
1145 | ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT; | |
1146 | run_again(ifmgd, ifmgd->probe_timeout); | |
1147 | } | |
1148 | ||
b291ba11 JB |
1149 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
1150 | bool beacon) | |
04de8381 | 1151 | { |
04de8381 | 1152 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
b291ba11 | 1153 | bool already = false; |
34bfc411 | 1154 | |
9607e6b6 | 1155 | if (!ieee80211_sdata_running(sdata)) |
0e2b6286 JB |
1156 | return; |
1157 | ||
91a3bd76 LR |
1158 | if (sdata->local->scanning) |
1159 | return; | |
1160 | ||
b8bc4b0a JB |
1161 | if (sdata->local->tmp_channel) |
1162 | return; | |
1163 | ||
77fdaa12 JB |
1164 | mutex_lock(&ifmgd->mtx); |
1165 | ||
1166 | if (!ifmgd->associated) | |
1167 | goto out; | |
1168 | ||
a860402d | 1169 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
b291ba11 JB |
1170 | if (beacon && net_ratelimit()) |
1171 | printk(KERN_DEBUG "%s: detected beacon loss from AP " | |
47846c9b | 1172 | "- sending probe request\n", sdata->name); |
a860402d | 1173 | #endif |
04de8381 | 1174 | |
b291ba11 JB |
1175 | /* |
1176 | * The driver/our work has already reported this event or the | |
1177 | * connection monitoring has kicked in and we have already sent | |
1178 | * a probe request. Or maybe the AP died and the driver keeps | |
1179 | * reporting until we disassociate... | |
1180 | * | |
1181 | * In either case we have to ignore the current call to this | |
1182 | * function (except for setting the correct probe reason bit) | |
1183 | * because otherwise we would reset the timer every time and | |
1184 | * never check whether we received a probe response! | |
1185 | */ | |
1186 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | | |
1187 | IEEE80211_STA_CONNECTION_POLL)) | |
1188 | already = true; | |
1189 | ||
1190 | if (beacon) | |
1191 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; | |
1192 | else | |
1193 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; | |
1194 | ||
1195 | if (already) | |
1196 | goto out; | |
1197 | ||
4e751843 JB |
1198 | mutex_lock(&sdata->local->iflist_mtx); |
1199 | ieee80211_recalc_ps(sdata->local, -1); | |
1200 | mutex_unlock(&sdata->local->iflist_mtx); | |
1201 | ||
a43abf29 ML |
1202 | ifmgd->probe_send_count = 0; |
1203 | ieee80211_mgd_probe_ap_send(sdata); | |
77fdaa12 JB |
1204 | out: |
1205 | mutex_unlock(&ifmgd->mtx); | |
04de8381 KV |
1206 | } |
1207 | ||
a619a4c0 JO |
1208 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
1209 | struct ieee80211_vif *vif) | |
1210 | { | |
1211 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1212 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1213 | struct sk_buff *skb; | |
1214 | const u8 *ssid; | |
1215 | ||
1216 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) | |
1217 | return NULL; | |
1218 | ||
1219 | ASSERT_MGD_MTX(ifmgd); | |
1220 | ||
1221 | if (!ifmgd->associated) | |
1222 | return NULL; | |
1223 | ||
1224 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); | |
1225 | skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid, | |
1226 | ssid + 2, ssid[1], NULL, 0); | |
1227 | ||
1228 | return skb; | |
1229 | } | |
1230 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); | |
1231 | ||
1e4dcd01 JO |
1232 | static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata) |
1233 | { | |
1234 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1235 | struct ieee80211_local *local = sdata->local; | |
1236 | u8 bssid[ETH_ALEN]; | |
1237 | ||
1238 | mutex_lock(&ifmgd->mtx); | |
1239 | if (!ifmgd->associated) { | |
1240 | mutex_unlock(&ifmgd->mtx); | |
1241 | return; | |
1242 | } | |
1243 | ||
1244 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); | |
1245 | ||
1246 | printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid); | |
1247 | ||
53f73c09 | 1248 | ieee80211_set_disassoc(sdata, true, true); |
1e4dcd01 | 1249 | mutex_unlock(&ifmgd->mtx); |
7da7cc1d JB |
1250 | |
1251 | mutex_lock(&local->mtx); | |
1252 | ieee80211_recalc_idle(local); | |
1253 | mutex_unlock(&local->mtx); | |
1e4dcd01 JO |
1254 | /* |
1255 | * must be outside lock due to cfg80211, | |
1256 | * but that's not a problem. | |
1257 | */ | |
1258 | ieee80211_send_deauth_disassoc(sdata, bssid, | |
1259 | IEEE80211_STYPE_DEAUTH, | |
1260 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, | |
d5cdfacb | 1261 | NULL, true); |
1e4dcd01 JO |
1262 | } |
1263 | ||
1264 | void ieee80211_beacon_connection_loss_work(struct work_struct *work) | |
b291ba11 JB |
1265 | { |
1266 | struct ieee80211_sub_if_data *sdata = | |
1267 | container_of(work, struct ieee80211_sub_if_data, | |
1e4dcd01 | 1268 | u.mgd.beacon_connection_loss_work); |
b291ba11 | 1269 | |
1e4dcd01 JO |
1270 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
1271 | __ieee80211_connection_loss(sdata); | |
1272 | else | |
1273 | ieee80211_mgd_probe_ap(sdata, true); | |
b291ba11 JB |
1274 | } |
1275 | ||
04de8381 KV |
1276 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
1277 | { | |
1278 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1e4dcd01 | 1279 | struct ieee80211_hw *hw = &sdata->local->hw; |
04de8381 | 1280 | |
b5878a2d JB |
1281 | trace_api_beacon_loss(sdata); |
1282 | ||
1e4dcd01 JO |
1283 | WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR); |
1284 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); | |
04de8381 KV |
1285 | } |
1286 | EXPORT_SYMBOL(ieee80211_beacon_loss); | |
1287 | ||
1e4dcd01 JO |
1288 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
1289 | { | |
1290 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
1291 | struct ieee80211_hw *hw = &sdata->local->hw; | |
1292 | ||
b5878a2d JB |
1293 | trace_api_connection_loss(sdata); |
1294 | ||
1e4dcd01 JO |
1295 | WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR)); |
1296 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); | |
1297 | } | |
1298 | EXPORT_SYMBOL(ieee80211_connection_loss); | |
1299 | ||
1300 | ||
77fdaa12 JB |
1301 | static enum rx_mgmt_action __must_check |
1302 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, | |
77fdaa12 | 1303 | struct ieee80211_mgmt *mgmt, size_t len) |
f0706e82 | 1304 | { |
46900298 | 1305 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
77fdaa12 | 1306 | const u8 *bssid = NULL; |
f0706e82 JB |
1307 | u16 reason_code; |
1308 | ||
f4ea83dd | 1309 | if (len < 24 + 2) |
77fdaa12 | 1310 | return RX_MGMT_NONE; |
f0706e82 | 1311 | |
77fdaa12 JB |
1312 | ASSERT_MGD_MTX(ifmgd); |
1313 | ||
0c1ad2ca | 1314 | bssid = ifmgd->associated->bssid; |
f0706e82 JB |
1315 | |
1316 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); | |
1317 | ||
77fdaa12 | 1318 | printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", |
47846c9b | 1319 | sdata->name, bssid, reason_code); |
77fdaa12 | 1320 | |
53f73c09 | 1321 | ieee80211_set_disassoc(sdata, true, false); |
7da7cc1d | 1322 | mutex_lock(&sdata->local->mtx); |
63f170e0 | 1323 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 1324 | mutex_unlock(&sdata->local->mtx); |
f0706e82 | 1325 | |
77fdaa12 | 1326 | return RX_MGMT_CFG80211_DEAUTH; |
f0706e82 JB |
1327 | } |
1328 | ||
1329 | ||
77fdaa12 JB |
1330 | static enum rx_mgmt_action __must_check |
1331 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, | |
1332 | struct ieee80211_mgmt *mgmt, size_t len) | |
f0706e82 | 1333 | { |
46900298 | 1334 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 JB |
1335 | u16 reason_code; |
1336 | ||
f4ea83dd | 1337 | if (len < 24 + 2) |
77fdaa12 | 1338 | return RX_MGMT_NONE; |
f0706e82 | 1339 | |
77fdaa12 JB |
1340 | ASSERT_MGD_MTX(ifmgd); |
1341 | ||
1342 | if (WARN_ON(!ifmgd->associated)) | |
1343 | return RX_MGMT_NONE; | |
1344 | ||
0c1ad2ca | 1345 | if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN))) |
77fdaa12 | 1346 | return RX_MGMT_NONE; |
f0706e82 JB |
1347 | |
1348 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); | |
1349 | ||
0ff71613 | 1350 | printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", |
47846c9b | 1351 | sdata->name, mgmt->sa, reason_code); |
f0706e82 | 1352 | |
53f73c09 | 1353 | ieee80211_set_disassoc(sdata, true, false); |
7da7cc1d | 1354 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 1355 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 1356 | mutex_unlock(&sdata->local->mtx); |
77fdaa12 | 1357 | return RX_MGMT_CFG80211_DISASSOC; |
f0706e82 JB |
1358 | } |
1359 | ||
1360 | ||
af6b6374 JB |
1361 | static bool ieee80211_assoc_success(struct ieee80211_work *wk, |
1362 | struct ieee80211_mgmt *mgmt, size_t len) | |
f0706e82 | 1363 | { |
af6b6374 | 1364 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
46900298 | 1365 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
471b3efd | 1366 | struct ieee80211_local *local = sdata->local; |
8318d78a | 1367 | struct ieee80211_supported_band *sband; |
f0706e82 | 1368 | struct sta_info *sta; |
0c1ad2ca | 1369 | struct cfg80211_bss *cbss = wk->assoc.bss; |
af6b6374 | 1370 | u8 *pos; |
881d948c | 1371 | u32 rates, basic_rates; |
af6b6374 | 1372 | u16 capab_info, aid; |
f0706e82 | 1373 | struct ieee802_11_elems elems; |
bda3933a | 1374 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
ae5eb026 | 1375 | u32 changed = 0; |
5d1ec85f JB |
1376 | int i, j, err; |
1377 | bool have_higher_than_11mbit = false; | |
ae5eb026 | 1378 | u16 ap_ht_cap_flags; |
f0706e82 | 1379 | |
af6b6374 | 1380 | /* AssocResp and ReassocResp have identical structure */ |
f0706e82 | 1381 | |
f0706e82 | 1382 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
af6b6374 | 1383 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
f0706e82 | 1384 | |
1dd84aa2 JB |
1385 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
1386 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " | |
47846c9b | 1387 | "set\n", sdata->name, aid); |
1dd84aa2 JB |
1388 | aid &= ~(BIT(15) | BIT(14)); |
1389 | ||
af6b6374 JB |
1390 | pos = mgmt->u.assoc_resp.variable; |
1391 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); | |
1392 | ||
f0706e82 JB |
1393 | if (!elems.supp_rates) { |
1394 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", | |
47846c9b | 1395 | sdata->name); |
af6b6374 | 1396 | return false; |
f0706e82 JB |
1397 | } |
1398 | ||
46900298 | 1399 | ifmgd->aid = aid; |
f0706e82 | 1400 | |
0c1ad2ca | 1401 | sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
f0706e82 | 1402 | if (!sta) { |
5d1ec85f JB |
1403 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
1404 | " the AP\n", sdata->name); | |
af6b6374 | 1405 | return false; |
77fdaa12 | 1406 | } |
05e5e883 | 1407 | |
5d1ec85f JB |
1408 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | |
1409 | WLAN_STA_ASSOC_AP); | |
1410 | if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) | |
1411 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); | |
1412 | ||
60f8b39c JB |
1413 | rates = 0; |
1414 | basic_rates = 0; | |
e7480bbb | 1415 | sband = local->hw.wiphy->bands[wk->chan->band]; |
f709fc69 | 1416 | |
60f8b39c JB |
1417 | for (i = 0; i < elems.supp_rates_len; i++) { |
1418 | int rate = (elems.supp_rates[i] & 0x7f) * 5; | |
d61272cb | 1419 | bool is_basic = !!(elems.supp_rates[i] & 0x80); |
f709fc69 | 1420 | |
60f8b39c JB |
1421 | if (rate > 110) |
1422 | have_higher_than_11mbit = true; | |
1423 | ||
1424 | for (j = 0; j < sband->n_bitrates; j++) { | |
d61272cb | 1425 | if (sband->bitrates[j].bitrate == rate) { |
60f8b39c | 1426 | rates |= BIT(j); |
d61272cb TW |
1427 | if (is_basic) |
1428 | basic_rates |= BIT(j); | |
1429 | break; | |
1430 | } | |
f709fc69 | 1431 | } |
f709fc69 LCC |
1432 | } |
1433 | ||
60f8b39c JB |
1434 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
1435 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; | |
7e0986c1 | 1436 | bool is_basic = !!(elems.ext_supp_rates[i] & 0x80); |
f0706e82 | 1437 | |
60f8b39c JB |
1438 | if (rate > 110) |
1439 | have_higher_than_11mbit = true; | |
f0706e82 | 1440 | |
60f8b39c | 1441 | for (j = 0; j < sband->n_bitrates; j++) { |
d61272cb | 1442 | if (sband->bitrates[j].bitrate == rate) { |
60f8b39c | 1443 | rates |= BIT(j); |
d61272cb TW |
1444 | if (is_basic) |
1445 | basic_rates |= BIT(j); | |
1446 | break; | |
1447 | } | |
60f8b39c | 1448 | } |
1ebebea8 | 1449 | } |
f0706e82 | 1450 | |
e7480bbb | 1451 | sta->sta.supp_rates[wk->chan->band] = rates; |
bda3933a | 1452 | sdata->vif.bss_conf.basic_rates = basic_rates; |
60f8b39c JB |
1453 | |
1454 | /* cf. IEEE 802.11 9.2.12 */ | |
e7480bbb | 1455 | if (wk->chan->band == IEEE80211_BAND_2GHZ && |
60f8b39c JB |
1456 | have_higher_than_11mbit) |
1457 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; | |
1458 | else | |
1459 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; | |
f0706e82 | 1460 | |
ab1faead | 1461 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
ae5eb026 | 1462 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
d9fe60de | 1463 | elems.ht_cap_elem, &sta->sta.ht_cap); |
ae5eb026 JB |
1464 | |
1465 | ap_ht_cap_flags = sta->sta.ht_cap.cap; | |
f0706e82 | 1466 | |
4b7679a5 | 1467 | rate_control_rate_init(sta); |
f0706e82 | 1468 | |
46900298 | 1469 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
5394af4d JM |
1470 | set_sta_flags(sta, WLAN_STA_MFP); |
1471 | ||
ddf4ac53 | 1472 | if (elems.wmm_param) |
60f8b39c | 1473 | set_sta_flags(sta, WLAN_STA_WME); |
ddf4ac53 | 1474 | |
5d1ec85f JB |
1475 | err = sta_info_insert(sta); |
1476 | sta = NULL; | |
1477 | if (err) { | |
1478 | printk(KERN_DEBUG "%s: failed to insert STA entry for" | |
1479 | " the AP (error %d)\n", sdata->name, err); | |
90be561b | 1480 | return false; |
ddf4ac53 JB |
1481 | } |
1482 | ||
f2176d72 JO |
1483 | /* |
1484 | * Always handle WMM once after association regardless | |
1485 | * of the first value the AP uses. Setting -1 here has | |
1486 | * that effect because the AP values is an unsigned | |
1487 | * 4-bit value. | |
1488 | */ | |
1489 | ifmgd->wmm_last_param_set = -1; | |
1490 | ||
ddf4ac53 | 1491 | if (elems.wmm_param) |
4ced3f74 | 1492 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
60f8b39c | 1493 | elems.wmm_param_len); |
aa837e1d JB |
1494 | else |
1495 | ieee80211_set_wmm_default(sdata); | |
f0706e82 | 1496 | |
e4da8c37 JB |
1497 | local->oper_channel = wk->chan; |
1498 | ||
ae5eb026 | 1499 | if (elems.ht_info_elem && elems.wmm_param && |
af6b6374 | 1500 | (sdata->local->hw.queues >= 4) && |
ab1faead | 1501 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
ae5eb026 | 1502 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
0c1ad2ca | 1503 | cbss->bssid, ap_ht_cap_flags); |
ae5eb026 | 1504 | |
60f8b39c JB |
1505 | /* set AID and assoc capability, |
1506 | * ieee80211_set_associated() will tell the driver */ | |
1507 | bss_conf->aid = aid; | |
1508 | bss_conf->assoc_capability = capab_info; | |
0c1ad2ca | 1509 | ieee80211_set_associated(sdata, cbss, changed); |
f0706e82 | 1510 | |
d524215f FF |
1511 | /* |
1512 | * If we're using 4-addr mode, let the AP know that we're | |
1513 | * doing so, so that it can create the STA VLAN on its side | |
1514 | */ | |
1515 | if (ifmgd->use_4addr) | |
1516 | ieee80211_send_4addr_nullfunc(local, sdata); | |
1517 | ||
15b7b062 | 1518 | /* |
b291ba11 JB |
1519 | * Start timer to probe the connection to the AP now. |
1520 | * Also start the timer that will detect beacon loss. | |
15b7b062 | 1521 | */ |
b291ba11 | 1522 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
d3a910a8 | 1523 | ieee80211_sta_reset_beacon_monitor(sdata); |
15b7b062 | 1524 | |
af6b6374 | 1525 | return true; |
f0706e82 JB |
1526 | } |
1527 | ||
1528 | ||
98c8fccf JB |
1529 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
1530 | struct ieee80211_mgmt *mgmt, | |
1531 | size_t len, | |
1532 | struct ieee80211_rx_status *rx_status, | |
1533 | struct ieee802_11_elems *elems, | |
1534 | bool beacon) | |
1535 | { | |
1536 | struct ieee80211_local *local = sdata->local; | |
1537 | int freq; | |
c2b13452 | 1538 | struct ieee80211_bss *bss; |
98c8fccf | 1539 | struct ieee80211_channel *channel; |
56007a02 JB |
1540 | bool need_ps = false; |
1541 | ||
1542 | if (sdata->u.mgd.associated) { | |
1543 | bss = (void *)sdata->u.mgd.associated->priv; | |
1544 | /* not previously set so we may need to recalc */ | |
1545 | need_ps = !bss->dtim_period; | |
1546 | } | |
98c8fccf JB |
1547 | |
1548 | if (elems->ds_params && elems->ds_params_len == 1) | |
59eb21a6 BR |
1549 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
1550 | rx_status->band); | |
98c8fccf JB |
1551 | else |
1552 | freq = rx_status->freq; | |
1553 | ||
1554 | channel = ieee80211_get_channel(local->hw.wiphy, freq); | |
1555 | ||
1556 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
1557 | return; | |
1558 | ||
98c8fccf | 1559 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
2a519311 | 1560 | channel, beacon); |
77fdaa12 JB |
1561 | if (bss) |
1562 | ieee80211_rx_bss_put(local, bss); | |
1563 | ||
1564 | if (!sdata->u.mgd.associated) | |
98c8fccf JB |
1565 | return; |
1566 | ||
56007a02 JB |
1567 | if (need_ps) { |
1568 | mutex_lock(&local->iflist_mtx); | |
1569 | ieee80211_recalc_ps(local, -1); | |
1570 | mutex_unlock(&local->iflist_mtx); | |
1571 | } | |
1572 | ||
c481ec97 | 1573 | if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && |
0c1ad2ca | 1574 | (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, |
77fdaa12 | 1575 | ETH_ALEN) == 0)) { |
c481ec97 S |
1576 | struct ieee80211_channel_sw_ie *sw_elem = |
1577 | (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; | |
5ce6e438 JB |
1578 | ieee80211_sta_process_chanswitch(sdata, sw_elem, |
1579 | bss, rx_status->mactime); | |
c481ec97 | 1580 | } |
f0706e82 JB |
1581 | } |
1582 | ||
1583 | ||
f698d856 | 1584 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
af6b6374 | 1585 | struct sk_buff *skb) |
f0706e82 | 1586 | { |
af6b6374 | 1587 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
15b7b062 | 1588 | struct ieee80211_if_managed *ifmgd; |
af6b6374 JB |
1589 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
1590 | size_t baselen, len = skb->len; | |
ae6a44e3 EK |
1591 | struct ieee802_11_elems elems; |
1592 | ||
15b7b062 KV |
1593 | ifmgd = &sdata->u.mgd; |
1594 | ||
77fdaa12 JB |
1595 | ASSERT_MGD_MTX(ifmgd); |
1596 | ||
47846c9b | 1597 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
8e7cdbb6 TW |
1598 | return; /* ignore ProbeResp to foreign address */ |
1599 | ||
ae6a44e3 EK |
1600 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
1601 | if (baselen > len) | |
1602 | return; | |
1603 | ||
1604 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | |
1605 | &elems); | |
1606 | ||
98c8fccf | 1607 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
9859b81e | 1608 | |
77fdaa12 | 1609 | if (ifmgd->associated && |
4e5ff376 FF |
1610 | memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0) |
1611 | ieee80211_reset_ap_probe(sdata); | |
f0706e82 JB |
1612 | } |
1613 | ||
d91f36db JB |
1614 | /* |
1615 | * This is the canonical list of information elements we care about, | |
1616 | * the filter code also gives us all changes to the Microsoft OUI | |
1617 | * (00:50:F2) vendor IE which is used for WMM which we need to track. | |
1618 | * | |
1619 | * We implement beacon filtering in software since that means we can | |
1620 | * avoid processing the frame here and in cfg80211, and userspace | |
1621 | * will not be able to tell whether the hardware supports it or not. | |
1622 | * | |
1623 | * XXX: This list needs to be dynamic -- userspace needs to be able to | |
1624 | * add items it requires. It also needs to be able to tell us to | |
1625 | * look out for other vendor IEs. | |
1626 | */ | |
1627 | static const u64 care_about_ies = | |
1d4df3a5 JB |
1628 | (1ULL << WLAN_EID_COUNTRY) | |
1629 | (1ULL << WLAN_EID_ERP_INFO) | | |
1630 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | | |
1631 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | | |
1632 | (1ULL << WLAN_EID_HT_CAPABILITY) | | |
1633 | (1ULL << WLAN_EID_HT_INFORMATION); | |
d91f36db | 1634 | |
f698d856 | 1635 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
f0706e82 JB |
1636 | struct ieee80211_mgmt *mgmt, |
1637 | size_t len, | |
1638 | struct ieee80211_rx_status *rx_status) | |
1639 | { | |
d91f36db | 1640 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
17e4ec14 | 1641 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
f0706e82 JB |
1642 | size_t baselen; |
1643 | struct ieee802_11_elems elems; | |
f698d856 | 1644 | struct ieee80211_local *local = sdata->local; |
471b3efd | 1645 | u32 changed = 0; |
d91f36db | 1646 | bool erp_valid, directed_tim = false; |
7a5158ef | 1647 | u8 erp_value = 0; |
d91f36db | 1648 | u32 ncrc; |
77fdaa12 JB |
1649 | u8 *bssid; |
1650 | ||
1651 | ASSERT_MGD_MTX(ifmgd); | |
f0706e82 | 1652 | |
ae6a44e3 EK |
1653 | /* Process beacon from the current BSS */ |
1654 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; | |
1655 | if (baselen > len) | |
1656 | return; | |
1657 | ||
d91f36db | 1658 | if (rx_status->freq != local->hw.conf.channel->center_freq) |
f0706e82 | 1659 | return; |
f0706e82 | 1660 | |
b291ba11 JB |
1661 | /* |
1662 | * We might have received a number of frames, among them a | |
1663 | * disassoc frame and a beacon... | |
1664 | */ | |
1665 | if (!ifmgd->associated) | |
77fdaa12 JB |
1666 | return; |
1667 | ||
0c1ad2ca | 1668 | bssid = ifmgd->associated->bssid; |
77fdaa12 | 1669 | |
b291ba11 JB |
1670 | /* |
1671 | * And in theory even frames from a different AP we were just | |
1672 | * associated to a split-second ago! | |
1673 | */ | |
1674 | if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0) | |
f0706e82 JB |
1675 | return; |
1676 | ||
17e4ec14 JM |
1677 | /* Track average RSSI from the Beacon frames of the current AP */ |
1678 | ifmgd->last_beacon_signal = rx_status->signal; | |
1679 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { | |
1680 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; | |
3ba06c6f | 1681 | ifmgd->ave_beacon_signal = rx_status->signal * 16; |
17e4ec14 | 1682 | ifmgd->last_cqm_event_signal = 0; |
391a200a | 1683 | ifmgd->count_beacon_signal = 1; |
17e4ec14 JM |
1684 | } else { |
1685 | ifmgd->ave_beacon_signal = | |
1686 | (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 + | |
1687 | (16 - IEEE80211_SIGNAL_AVE_WEIGHT) * | |
1688 | ifmgd->ave_beacon_signal) / 16; | |
391a200a | 1689 | ifmgd->count_beacon_signal++; |
17e4ec14 JM |
1690 | } |
1691 | if (bss_conf->cqm_rssi_thold && | |
391a200a | 1692 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
17e4ec14 JM |
1693 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) { |
1694 | int sig = ifmgd->ave_beacon_signal / 16; | |
1695 | int last_event = ifmgd->last_cqm_event_signal; | |
1696 | int thold = bss_conf->cqm_rssi_thold; | |
1697 | int hyst = bss_conf->cqm_rssi_hyst; | |
1698 | if (sig < thold && | |
1699 | (last_event == 0 || sig < last_event - hyst)) { | |
1700 | ifmgd->last_cqm_event_signal = sig; | |
1701 | ieee80211_cqm_rssi_notify( | |
1702 | &sdata->vif, | |
1703 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, | |
1704 | GFP_KERNEL); | |
1705 | } else if (sig > thold && | |
1706 | (last_event == 0 || sig > last_event + hyst)) { | |
1707 | ifmgd->last_cqm_event_signal = sig; | |
1708 | ieee80211_cqm_rssi_notify( | |
1709 | &sdata->vif, | |
1710 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, | |
1711 | GFP_KERNEL); | |
1712 | } | |
1713 | } | |
1714 | ||
b291ba11 | 1715 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
92778180 JM |
1716 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
1717 | if (net_ratelimit()) { | |
1718 | printk(KERN_DEBUG "%s: cancelling probereq poll due " | |
47846c9b | 1719 | "to a received beacon\n", sdata->name); |
92778180 JM |
1720 | } |
1721 | #endif | |
b291ba11 | 1722 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
4e751843 JB |
1723 | mutex_lock(&local->iflist_mtx); |
1724 | ieee80211_recalc_ps(local, -1); | |
1725 | mutex_unlock(&local->iflist_mtx); | |
92778180 JM |
1726 | } |
1727 | ||
b291ba11 JB |
1728 | /* |
1729 | * Push the beacon loss detection into the future since | |
1730 | * we are processing a beacon from the AP just now. | |
1731 | */ | |
d3a910a8 | 1732 | ieee80211_sta_reset_beacon_monitor(sdata); |
b291ba11 | 1733 | |
d91f36db JB |
1734 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
1735 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, | |
1736 | len - baselen, &elems, | |
1737 | care_about_ies, ncrc); | |
1738 | ||
1739 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) | |
e7ec86f5 JB |
1740 | directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len, |
1741 | ifmgd->aid); | |
d91f36db | 1742 | |
d8ec4433 | 1743 | if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) { |
30196673 JM |
1744 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
1745 | true); | |
d91f36db | 1746 | |
4ced3f74 | 1747 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
30196673 JM |
1748 | elems.wmm_param_len); |
1749 | } | |
fe3fa827 | 1750 | |
25c9c875 | 1751 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
1fb3606b | 1752 | if (directed_tim) { |
572e0012 KV |
1753 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
1754 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
1755 | ieee80211_hw_config(local, | |
1756 | IEEE80211_CONF_CHANGE_PS); | |
1757 | ieee80211_send_nullfunc(local, sdata, 0); | |
1758 | } else { | |
1759 | local->pspolling = true; | |
1760 | ||
1761 | /* | |
1762 | * Here is assumed that the driver will be | |
1763 | * able to send ps-poll frame and receive a | |
1764 | * response even though power save mode is | |
1765 | * enabled, but some drivers might require | |
1766 | * to disable power save here. This needs | |
1767 | * to be investigated. | |
1768 | */ | |
1769 | ieee80211_send_pspoll(local, sdata); | |
1770 | } | |
a97b77b9 VN |
1771 | } |
1772 | } | |
7a5158ef | 1773 | |
d8ec4433 | 1774 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
30196673 JM |
1775 | return; |
1776 | ifmgd->beacon_crc = ncrc; | |
d8ec4433 | 1777 | ifmgd->beacon_crc_valid = true; |
30196673 | 1778 | |
7a5158ef JB |
1779 | if (elems.erp_info && elems.erp_info_len >= 1) { |
1780 | erp_valid = true; | |
1781 | erp_value = elems.erp_info[0]; | |
1782 | } else { | |
1783 | erp_valid = false; | |
50c4afb9 | 1784 | } |
7a5158ef JB |
1785 | changed |= ieee80211_handle_bss_capability(sdata, |
1786 | le16_to_cpu(mgmt->u.beacon.capab_info), | |
1787 | erp_valid, erp_value); | |
f0706e82 | 1788 | |
d3c990fb | 1789 | |
53d6f81c | 1790 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
ab1faead | 1791 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) { |
ae5eb026 JB |
1792 | struct sta_info *sta; |
1793 | struct ieee80211_supported_band *sband; | |
1794 | u16 ap_ht_cap_flags; | |
1795 | ||
1796 | rcu_read_lock(); | |
1797 | ||
abe60632 | 1798 | sta = sta_info_get(sdata, bssid); |
77fdaa12 | 1799 | if (WARN_ON(!sta)) { |
ae5eb026 JB |
1800 | rcu_read_unlock(); |
1801 | return; | |
1802 | } | |
1803 | ||
1804 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | |
1805 | ||
1806 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, | |
1807 | elems.ht_cap_elem, &sta->sta.ht_cap); | |
1808 | ||
1809 | ap_ht_cap_flags = sta->sta.ht_cap.cap; | |
1810 | ||
1811 | rcu_read_unlock(); | |
1812 | ||
1813 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, | |
77fdaa12 | 1814 | bssid, ap_ht_cap_flags); |
d3c990fb RR |
1815 | } |
1816 | ||
8b19e6ca | 1817 | /* Note: country IE parsing is done for us by cfg80211 */ |
3f2355cb | 1818 | if (elems.country_elem) { |
a8302de9 VT |
1819 | /* TODO: IBSS also needs this */ |
1820 | if (elems.pwr_constr_elem) | |
1821 | ieee80211_handle_pwr_constr(sdata, | |
1822 | le16_to_cpu(mgmt->u.probe_resp.capab_info), | |
1823 | elems.pwr_constr_elem, | |
1824 | elems.pwr_constr_elem_len); | |
3f2355cb LR |
1825 | } |
1826 | ||
471b3efd | 1827 | ieee80211_bss_info_change_notify(sdata, changed); |
f0706e82 JB |
1828 | } |
1829 | ||
1fa57d01 JB |
1830 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
1831 | struct sk_buff *skb) | |
f0706e82 | 1832 | { |
77fdaa12 | 1833 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f0706e82 | 1834 | struct ieee80211_rx_status *rx_status; |
f0706e82 | 1835 | struct ieee80211_mgmt *mgmt; |
77fdaa12 | 1836 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
f0706e82 JB |
1837 | u16 fc; |
1838 | ||
f0706e82 JB |
1839 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
1840 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1841 | fc = le16_to_cpu(mgmt->frame_control); | |
1842 | ||
77fdaa12 JB |
1843 | mutex_lock(&ifmgd->mtx); |
1844 | ||
1845 | if (ifmgd->associated && | |
0c1ad2ca | 1846 | memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) { |
77fdaa12 JB |
1847 | switch (fc & IEEE80211_FCTL_STYPE) { |
1848 | case IEEE80211_STYPE_BEACON: | |
1849 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, | |
1850 | rx_status); | |
1851 | break; | |
1852 | case IEEE80211_STYPE_PROBE_RESP: | |
af6b6374 | 1853 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
77fdaa12 JB |
1854 | break; |
1855 | case IEEE80211_STYPE_DEAUTH: | |
63f170e0 | 1856 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
77fdaa12 JB |
1857 | break; |
1858 | case IEEE80211_STYPE_DISASSOC: | |
1859 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); | |
1860 | break; | |
1861 | case IEEE80211_STYPE_ACTION: | |
8b9a4e6e | 1862 | switch (mgmt->u.action.category) { |
8b9a4e6e JB |
1863 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
1864 | ieee80211_sta_process_chanswitch(sdata, | |
1865 | &mgmt->u.action.u.chan_switch.sw_elem, | |
1866 | (void *)ifmgd->associated->priv, | |
1867 | rx_status->mactime); | |
1868 | break; | |
1869 | } | |
77fdaa12 JB |
1870 | } |
1871 | mutex_unlock(&ifmgd->mtx); | |
1872 | ||
1873 | switch (rma) { | |
1874 | case RX_MGMT_NONE: | |
1875 | /* no action */ | |
1876 | break; | |
1877 | case RX_MGMT_CFG80211_DEAUTH: | |
ce470613 | 1878 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
77fdaa12 JB |
1879 | break; |
1880 | case RX_MGMT_CFG80211_DISASSOC: | |
ce470613 | 1881 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
77fdaa12 JB |
1882 | break; |
1883 | default: | |
1884 | WARN(1, "unexpected: %d", rma); | |
1885 | } | |
36b3a628 | 1886 | return; |
77fdaa12 JB |
1887 | } |
1888 | ||
77fdaa12 JB |
1889 | mutex_unlock(&ifmgd->mtx); |
1890 | ||
63f170e0 | 1891 | if (skb->len >= 24 + 2 /* mgmt + deauth reason */ && |
b054b747 JB |
1892 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) { |
1893 | struct ieee80211_local *local = sdata->local; | |
1894 | struct ieee80211_work *wk; | |
1895 | ||
a1699b75 | 1896 | mutex_lock(&local->mtx); |
b054b747 JB |
1897 | list_for_each_entry(wk, &local->work_list, list) { |
1898 | if (wk->sdata != sdata) | |
1899 | continue; | |
1900 | ||
e5b900d2 JB |
1901 | if (wk->type != IEEE80211_WORK_ASSOC && |
1902 | wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT) | |
b054b747 JB |
1903 | continue; |
1904 | ||
1905 | if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN)) | |
1906 | continue; | |
1907 | if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN)) | |
1908 | continue; | |
1909 | ||
1910 | /* | |
1911 | * Printing the message only here means we can't | |
1912 | * spuriously print it, but it also means that it | |
1913 | * won't be printed when the frame comes in before | |
1914 | * we even tried to associate or in similar cases. | |
1915 | * | |
1916 | * Ultimately, I suspect cfg80211 should print the | |
1917 | * messages instead. | |
1918 | */ | |
1919 | printk(KERN_DEBUG | |
1920 | "%s: deauthenticated from %pM (Reason: %u)\n", | |
1921 | sdata->name, mgmt->bssid, | |
1922 | le16_to_cpu(mgmt->u.deauth.reason_code)); | |
1923 | ||
1924 | list_del_rcu(&wk->list); | |
1925 | free_work(wk); | |
1926 | break; | |
1927 | } | |
a1699b75 | 1928 | mutex_unlock(&local->mtx); |
f0706e82 | 1929 | |
ce470613 | 1930 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
b054b747 | 1931 | } |
f0706e82 JB |
1932 | } |
1933 | ||
9c6bd790 | 1934 | static void ieee80211_sta_timer(unsigned long data) |
f0706e82 | 1935 | { |
60f8b39c JB |
1936 | struct ieee80211_sub_if_data *sdata = |
1937 | (struct ieee80211_sub_if_data *) data; | |
46900298 | 1938 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
60f8b39c | 1939 | struct ieee80211_local *local = sdata->local; |
f0706e82 | 1940 | |
5bb644a0 JB |
1941 | if (local->quiescing) { |
1942 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
1943 | return; | |
1944 | } | |
1945 | ||
64592c8f | 1946 | ieee80211_queue_work(&local->hw, &sdata->work); |
f0706e82 JB |
1947 | } |
1948 | ||
04ac3c0e FF |
1949 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
1950 | u8 *bssid) | |
1951 | { | |
1952 | struct ieee80211_local *local = sdata->local; | |
1953 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
1954 | ||
1955 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | | |
1956 | IEEE80211_STA_BEACON_POLL); | |
1957 | ||
1958 | ieee80211_set_disassoc(sdata, true, true); | |
1959 | mutex_unlock(&ifmgd->mtx); | |
1960 | mutex_lock(&local->mtx); | |
1961 | ieee80211_recalc_idle(local); | |
1962 | mutex_unlock(&local->mtx); | |
1963 | /* | |
1964 | * must be outside lock due to cfg80211, | |
1965 | * but that's not a problem. | |
1966 | */ | |
1967 | ieee80211_send_deauth_disassoc(sdata, bssid, | |
1968 | IEEE80211_STYPE_DEAUTH, | |
1969 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, | |
1970 | NULL, true); | |
1971 | mutex_lock(&ifmgd->mtx); | |
1972 | } | |
1973 | ||
1fa57d01 | 1974 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
9c6bd790 | 1975 | { |
9c6bd790 | 1976 | struct ieee80211_local *local = sdata->local; |
1fa57d01 | 1977 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
9c6bd790 | 1978 | |
77fdaa12 JB |
1979 | /* then process the rest of the work */ |
1980 | mutex_lock(&ifmgd->mtx); | |
1981 | ||
b291ba11 JB |
1982 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
1983 | IEEE80211_STA_CONNECTION_POLL) && | |
1984 | ifmgd->associated) { | |
a43abf29 | 1985 | u8 bssid[ETH_ALEN]; |
72a8a3ed | 1986 | int max_tries; |
a43abf29 | 1987 | |
0c1ad2ca | 1988 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
4e5ff376 | 1989 | |
72a8a3ed FF |
1990 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
1991 | max_tries = IEEE80211_MAX_NULLFUNC_TRIES; | |
1992 | else | |
1993 | max_tries = IEEE80211_MAX_PROBE_TRIES; | |
1994 | ||
4e5ff376 FF |
1995 | /* ACK received for nullfunc probing frame */ |
1996 | if (!ifmgd->probe_send_count) | |
1997 | ieee80211_reset_ap_probe(sdata); | |
04ac3c0e FF |
1998 | else if (ifmgd->nullfunc_failed) { |
1999 | if (ifmgd->probe_send_count < max_tries) { | |
2000 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
2001 | wiphy_debug(local->hw.wiphy, | |
2002 | "%s: No ack for nullfunc frame to" | |
bfc31df3 | 2003 | " AP %pM, try %d/%i\n", |
04ac3c0e | 2004 | sdata->name, bssid, |
bfc31df3 | 2005 | ifmgd->probe_send_count, max_tries); |
04ac3c0e FF |
2006 | #endif |
2007 | ieee80211_mgd_probe_ap_send(sdata); | |
2008 | } else { | |
2009 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
2010 | wiphy_debug(local->hw.wiphy, | |
2011 | "%s: No ack for nullfunc frame to" | |
2012 | " AP %pM, disconnecting.\n", | |
c658e5db | 2013 | sdata->name, bssid); |
04ac3c0e FF |
2014 | #endif |
2015 | ieee80211_sta_connection_lost(sdata, bssid); | |
2016 | } | |
2017 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) | |
b291ba11 | 2018 | run_again(ifmgd, ifmgd->probe_timeout); |
04ac3c0e FF |
2019 | else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
2020 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
2021 | wiphy_debug(local->hw.wiphy, | |
2022 | "%s: Failed to send nullfunc to AP %pM" | |
2023 | " after %dms, disconnecting.\n", | |
2024 | sdata->name, | |
2025 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); | |
2026 | #endif | |
2027 | ieee80211_sta_connection_lost(sdata, bssid); | |
2028 | } else if (ifmgd->probe_send_count < max_tries) { | |
a43abf29 | 2029 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
b38afa87 BG |
2030 | wiphy_debug(local->hw.wiphy, |
2031 | "%s: No probe response from AP %pM" | |
bfc31df3 | 2032 | " after %dms, try %d/%i\n", |
b38afa87 BG |
2033 | sdata->name, |
2034 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ, | |
bfc31df3 | 2035 | ifmgd->probe_send_count, max_tries); |
a43abf29 ML |
2036 | #endif |
2037 | ieee80211_mgd_probe_ap_send(sdata); | |
2038 | } else { | |
b291ba11 JB |
2039 | /* |
2040 | * We actually lost the connection ... or did we? | |
2041 | * Let's make sure! | |
2042 | */ | |
b38afa87 BG |
2043 | wiphy_debug(local->hw.wiphy, |
2044 | "%s: No probe response from AP %pM" | |
2045 | " after %dms, disconnecting.\n", | |
2046 | sdata->name, | |
2047 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); | |
04ac3c0e FF |
2048 | |
2049 | ieee80211_sta_connection_lost(sdata, bssid); | |
b291ba11 JB |
2050 | } |
2051 | } | |
2052 | ||
77fdaa12 | 2053 | mutex_unlock(&ifmgd->mtx); |
f0706e82 JB |
2054 | } |
2055 | ||
b291ba11 JB |
2056 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
2057 | { | |
2058 | struct ieee80211_sub_if_data *sdata = | |
2059 | (struct ieee80211_sub_if_data *) data; | |
2060 | struct ieee80211_local *local = sdata->local; | |
2061 | ||
2062 | if (local->quiescing) | |
2063 | return; | |
2064 | ||
1e4dcd01 JO |
2065 | ieee80211_queue_work(&sdata->local->hw, |
2066 | &sdata->u.mgd.beacon_connection_loss_work); | |
b291ba11 JB |
2067 | } |
2068 | ||
2069 | static void ieee80211_sta_conn_mon_timer(unsigned long data) | |
2070 | { | |
2071 | struct ieee80211_sub_if_data *sdata = | |
2072 | (struct ieee80211_sub_if_data *) data; | |
2073 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2074 | struct ieee80211_local *local = sdata->local; | |
2075 | ||
2076 | if (local->quiescing) | |
2077 | return; | |
2078 | ||
42935eca | 2079 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
b291ba11 JB |
2080 | } |
2081 | ||
2082 | static void ieee80211_sta_monitor_work(struct work_struct *work) | |
2083 | { | |
2084 | struct ieee80211_sub_if_data *sdata = | |
2085 | container_of(work, struct ieee80211_sub_if_data, | |
2086 | u.mgd.monitor_work); | |
2087 | ||
2088 | ieee80211_mgd_probe_ap(sdata, false); | |
2089 | } | |
2090 | ||
9c6bd790 JB |
2091 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
2092 | { | |
ad935687 | 2093 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
b291ba11 JB |
2094 | sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL | |
2095 | IEEE80211_STA_CONNECTION_POLL); | |
ad935687 | 2096 | |
b291ba11 | 2097 | /* let's probe the connection once */ |
42935eca | 2098 | ieee80211_queue_work(&sdata->local->hw, |
b291ba11 JB |
2099 | &sdata->u.mgd.monitor_work); |
2100 | /* and do all the other regular work too */ | |
64592c8f | 2101 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
ad935687 | 2102 | } |
9c6bd790 | 2103 | } |
f0706e82 | 2104 | |
5bb644a0 JB |
2105 | #ifdef CONFIG_PM |
2106 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) | |
2107 | { | |
2108 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2109 | ||
2110 | /* | |
2111 | * we need to use atomic bitops for the running bits | |
2112 | * only because both timers might fire at the same | |
2113 | * time -- the code here is properly synchronised. | |
2114 | */ | |
2115 | ||
d1f5b7a3 JB |
2116 | cancel_work_sync(&ifmgd->request_smps_work); |
2117 | ||
1e4dcd01 | 2118 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
5bb644a0 JB |
2119 | if (del_timer_sync(&ifmgd->timer)) |
2120 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); | |
2121 | ||
2122 | cancel_work_sync(&ifmgd->chswitch_work); | |
2123 | if (del_timer_sync(&ifmgd->chswitch_timer)) | |
2124 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); | |
b291ba11 JB |
2125 | |
2126 | cancel_work_sync(&ifmgd->monitor_work); | |
2127 | /* these will just be re-established on connection */ | |
2128 | del_timer_sync(&ifmgd->conn_mon_timer); | |
2129 | del_timer_sync(&ifmgd->bcn_mon_timer); | |
5bb644a0 JB |
2130 | } |
2131 | ||
2132 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) | |
2133 | { | |
2134 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
2135 | ||
2136 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) | |
2137 | add_timer(&ifmgd->timer); | |
2138 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) | |
2139 | add_timer(&ifmgd->chswitch_timer); | |
c8a7972c | 2140 | ieee80211_sta_reset_beacon_monitor(sdata); |
46090979 | 2141 | ieee80211_restart_sta_timer(sdata); |
5bb644a0 JB |
2142 | } |
2143 | #endif | |
2144 | ||
9c6bd790 JB |
2145 | /* interface setup */ |
2146 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) | |
f0706e82 | 2147 | { |
46900298 | 2148 | struct ieee80211_if_managed *ifmgd; |
988c0f72 | 2149 | |
46900298 | 2150 | ifmgd = &sdata->u.mgd; |
b291ba11 | 2151 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
46900298 | 2152 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
1e4dcd01 JO |
2153 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
2154 | ieee80211_beacon_connection_loss_work); | |
d1f5b7a3 | 2155 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work); |
46900298 | 2156 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
c481ec97 | 2157 | (unsigned long) sdata); |
b291ba11 JB |
2158 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
2159 | (unsigned long) sdata); | |
2160 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, | |
2161 | (unsigned long) sdata); | |
46900298 | 2162 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
9c6bd790 | 2163 | (unsigned long) sdata); |
9c6bd790 | 2164 | |
ab1faead | 2165 | ifmgd->flags = 0; |
bbbdff9e | 2166 | |
77fdaa12 | 2167 | mutex_init(&ifmgd->mtx); |
0f78231b JB |
2168 | |
2169 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) | |
2170 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; | |
2171 | else | |
2172 | ifmgd->req_smps = IEEE80211_SMPS_OFF; | |
f0706e82 JB |
2173 | } |
2174 | ||
77fdaa12 JB |
2175 | /* scan finished notification */ |
2176 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) | |
60f8b39c | 2177 | { |
77fdaa12 | 2178 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
60f8b39c | 2179 | |
77fdaa12 JB |
2180 | /* Restart STA timers */ |
2181 | rcu_read_lock(); | |
2182 | list_for_each_entry_rcu(sdata, &local->interfaces, list) | |
2183 | ieee80211_restart_sta_timer(sdata); | |
2184 | rcu_read_unlock(); | |
2185 | } | |
60f8b39c | 2186 | |
77fdaa12 JB |
2187 | int ieee80211_max_network_latency(struct notifier_block *nb, |
2188 | unsigned long data, void *dummy) | |
2189 | { | |
2190 | s32 latency_usec = (s32) data; | |
2191 | struct ieee80211_local *local = | |
2192 | container_of(nb, struct ieee80211_local, | |
2193 | network_latency_notifier); | |
1fa6f4af | 2194 | |
77fdaa12 JB |
2195 | mutex_lock(&local->iflist_mtx); |
2196 | ieee80211_recalc_ps(local, latency_usec); | |
2197 | mutex_unlock(&local->iflist_mtx); | |
dfe67012 | 2198 | |
77fdaa12 | 2199 | return 0; |
9c6bd790 JB |
2200 | } |
2201 | ||
77fdaa12 | 2202 | /* config hooks */ |
af6b6374 JB |
2203 | static enum work_done_result |
2204 | ieee80211_probe_auth_done(struct ieee80211_work *wk, | |
2205 | struct sk_buff *skb) | |
2206 | { | |
2207 | if (!skb) { | |
2208 | cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta); | |
2209 | return WORK_DONE_DESTROY; | |
2210 | } | |
2211 | ||
2212 | if (wk->type == IEEE80211_WORK_AUTH) { | |
2213 | cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len); | |
2214 | return WORK_DONE_DESTROY; | |
2215 | } | |
2216 | ||
2217 | mutex_lock(&wk->sdata->u.mgd.mtx); | |
2218 | ieee80211_rx_mgmt_probe_resp(wk->sdata, skb); | |
2219 | mutex_unlock(&wk->sdata->u.mgd.mtx); | |
2220 | ||
2221 | wk->type = IEEE80211_WORK_AUTH; | |
2222 | wk->probe_auth.tries = 0; | |
2223 | return WORK_DONE_REQUEUE; | |
2224 | } | |
2225 | ||
77fdaa12 JB |
2226 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
2227 | struct cfg80211_auth_request *req) | |
9c6bd790 | 2228 | { |
77fdaa12 | 2229 | const u8 *ssid; |
f679f65d | 2230 | struct ieee80211_work *wk; |
77fdaa12 | 2231 | u16 auth_alg; |
9c6bd790 | 2232 | |
d5cdfacb JM |
2233 | if (req->local_state_change) |
2234 | return 0; /* no need to update mac80211 state */ | |
2235 | ||
77fdaa12 JB |
2236 | switch (req->auth_type) { |
2237 | case NL80211_AUTHTYPE_OPEN_SYSTEM: | |
2238 | auth_alg = WLAN_AUTH_OPEN; | |
2239 | break; | |
2240 | case NL80211_AUTHTYPE_SHARED_KEY: | |
9dca9c49 JB |
2241 | if (IS_ERR(sdata->local->wep_tx_tfm)) |
2242 | return -EOPNOTSUPP; | |
77fdaa12 JB |
2243 | auth_alg = WLAN_AUTH_SHARED_KEY; |
2244 | break; | |
2245 | case NL80211_AUTHTYPE_FT: | |
2246 | auth_alg = WLAN_AUTH_FT; | |
2247 | break; | |
2248 | case NL80211_AUTHTYPE_NETWORK_EAP: | |
2249 | auth_alg = WLAN_AUTH_LEAP; | |
2250 | break; | |
2251 | default: | |
2252 | return -EOPNOTSUPP; | |
60f8b39c | 2253 | } |
77fdaa12 JB |
2254 | |
2255 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); | |
2256 | if (!wk) | |
9c6bd790 | 2257 | return -ENOMEM; |
77fdaa12 | 2258 | |
5e124bd5 | 2259 | memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN); |
77fdaa12 JB |
2260 | |
2261 | if (req->ie && req->ie_len) { | |
2262 | memcpy(wk->ie, req->ie, req->ie_len); | |
2263 | wk->ie_len = req->ie_len; | |
9c6bd790 | 2264 | } |
77fdaa12 | 2265 | |
fffd0934 | 2266 | if (req->key && req->key_len) { |
af6b6374 JB |
2267 | wk->probe_auth.key_len = req->key_len; |
2268 | wk->probe_auth.key_idx = req->key_idx; | |
2269 | memcpy(wk->probe_auth.key, req->key, req->key_len); | |
fffd0934 JB |
2270 | } |
2271 | ||
77fdaa12 | 2272 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
af6b6374 JB |
2273 | memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]); |
2274 | wk->probe_auth.ssid_len = ssid[1]; | |
f679f65d | 2275 | |
af6b6374 JB |
2276 | wk->probe_auth.algorithm = auth_alg; |
2277 | wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY; | |
77fdaa12 | 2278 | |
070bb547 JB |
2279 | /* if we already have a probe, don't probe again */ |
2280 | if (req->bss->proberesp_ies) | |
2281 | wk->type = IEEE80211_WORK_AUTH; | |
2282 | else | |
2283 | wk->type = IEEE80211_WORK_DIRECT_PROBE; | |
f679f65d | 2284 | wk->chan = req->bss->channel; |
af6b6374 JB |
2285 | wk->sdata = sdata; |
2286 | wk->done = ieee80211_probe_auth_done; | |
77fdaa12 | 2287 | |
af6b6374 | 2288 | ieee80211_add_work(wk); |
9c6bd790 | 2289 | return 0; |
60f8b39c JB |
2290 | } |
2291 | ||
af6b6374 JB |
2292 | static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk, |
2293 | struct sk_buff *skb) | |
2294 | { | |
2295 | struct ieee80211_mgmt *mgmt; | |
e5b900d2 JB |
2296 | struct ieee80211_rx_status *rx_status; |
2297 | struct ieee802_11_elems elems; | |
af6b6374 JB |
2298 | u16 status; |
2299 | ||
2300 | if (!skb) { | |
2301 | cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta); | |
2302 | return WORK_DONE_DESTROY; | |
2303 | } | |
2304 | ||
e5b900d2 JB |
2305 | if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) { |
2306 | mutex_lock(&wk->sdata->u.mgd.mtx); | |
2307 | rx_status = (void *) skb->cb; | |
2308 | ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems); | |
2309 | ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status, | |
2310 | &elems, true); | |
2311 | mutex_unlock(&wk->sdata->u.mgd.mtx); | |
2312 | ||
2313 | wk->type = IEEE80211_WORK_ASSOC; | |
2314 | /* not really done yet */ | |
2315 | return WORK_DONE_REQUEUE; | |
2316 | } | |
2317 | ||
af6b6374 JB |
2318 | mgmt = (void *)skb->data; |
2319 | status = le16_to_cpu(mgmt->u.assoc_resp.status_code); | |
2320 | ||
2321 | if (status == WLAN_STATUS_SUCCESS) { | |
2322 | mutex_lock(&wk->sdata->u.mgd.mtx); | |
2323 | if (!ieee80211_assoc_success(wk, mgmt, skb->len)) { | |
2324 | mutex_unlock(&wk->sdata->u.mgd.mtx); | |
2325 | /* oops -- internal error -- send timeout for now */ | |
2326 | cfg80211_send_assoc_timeout(wk->sdata->dev, | |
2327 | wk->filter_ta); | |
2328 | return WORK_DONE_DESTROY; | |
2329 | } | |
68542962 JO |
2330 | |
2331 | mutex_unlock(&wk->sdata->u.mgd.mtx); | |
af6b6374 JB |
2332 | } |
2333 | ||
2334 | cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len); | |
2335 | return WORK_DONE_DESTROY; | |
2336 | } | |
2337 | ||
77fdaa12 JB |
2338 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
2339 | struct cfg80211_assoc_request *req) | |
f0706e82 | 2340 | { |
77fdaa12 | 2341 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
0c1ad2ca | 2342 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
f679f65d | 2343 | struct ieee80211_work *wk; |
63f170e0 | 2344 | const u8 *ssid; |
af6b6374 | 2345 | int i; |
f0706e82 | 2346 | |
77fdaa12 | 2347 | mutex_lock(&ifmgd->mtx); |
af6b6374 | 2348 | if (ifmgd->associated) { |
9c87ba67 JM |
2349 | if (!req->prev_bssid || |
2350 | memcmp(req->prev_bssid, ifmgd->associated->bssid, | |
2351 | ETH_ALEN)) { | |
2352 | /* | |
2353 | * We are already associated and the request was not a | |
2354 | * reassociation request from the current BSS, so | |
2355 | * reject it. | |
2356 | */ | |
2357 | mutex_unlock(&ifmgd->mtx); | |
2358 | return -EALREADY; | |
2359 | } | |
2360 | ||
2361 | /* Trying to reassociate - clear previous association state */ | |
53f73c09 | 2362 | ieee80211_set_disassoc(sdata, true, false); |
af6b6374 JB |
2363 | } |
2364 | mutex_unlock(&ifmgd->mtx); | |
77fdaa12 | 2365 | |
63f170e0 | 2366 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); |
af6b6374 JB |
2367 | if (!wk) |
2368 | return -ENOMEM; | |
77fdaa12 | 2369 | |
77fdaa12 | 2370 | ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; |
375177bf | 2371 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
77fdaa12 | 2372 | |
d8ec4433 JO |
2373 | ifmgd->beacon_crc_valid = false; |
2374 | ||
77fdaa12 JB |
2375 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) |
2376 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || | |
2377 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || | |
2378 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) | |
2379 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; | |
2380 | ||
77fdaa12 JB |
2381 | |
2382 | if (req->ie && req->ie_len) { | |
2383 | memcpy(wk->ie, req->ie, req->ie_len); | |
2384 | wk->ie_len = req->ie_len; | |
2385 | } else | |
2386 | wk->ie_len = 0; | |
2387 | ||
0c1ad2ca | 2388 | wk->assoc.bss = req->bss; |
f679f65d | 2389 | |
af6b6374 | 2390 | memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN); |
f679f65d | 2391 | |
af6b6374 JB |
2392 | /* new association always uses requested smps mode */ |
2393 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { | |
2394 | if (ifmgd->powersave) | |
2395 | ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC; | |
2396 | else | |
2397 | ifmgd->ap_smps = IEEE80211_SMPS_OFF; | |
2398 | } else | |
2399 | ifmgd->ap_smps = ifmgd->req_smps; | |
2400 | ||
2401 | wk->assoc.smps = ifmgd->ap_smps; | |
77c8144a JB |
2402 | /* |
2403 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. | |
2404 | * We still associate in non-HT mode (11a/b/g) if any one of these | |
2405 | * ciphers is configured as pairwise. | |
2406 | * We can set this to true for non-11n hardware, that'll be checked | |
2407 | * separately along with the peer capabilities. | |
2408 | */ | |
af6b6374 | 2409 | wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N); |
f679f65d | 2410 | wk->assoc.capability = req->bss->capability; |
0c1ad2ca JB |
2411 | wk->assoc.wmm_used = bss->wmm_used; |
2412 | wk->assoc.supp_rates = bss->supp_rates; | |
2413 | wk->assoc.supp_rates_len = bss->supp_rates_len; | |
f679f65d JB |
2414 | wk->assoc.ht_information_ie = |
2415 | ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION); | |
63f170e0 | 2416 | |
ab13315a KV |
2417 | if (bss->wmm_used && bss->uapsd_supported && |
2418 | (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { | |
2419 | wk->assoc.uapsd_used = true; | |
2420 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; | |
2421 | } else { | |
2422 | wk->assoc.uapsd_used = false; | |
2423 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; | |
2424 | } | |
2425 | ||
63f170e0 | 2426 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
f679f65d JB |
2427 | memcpy(wk->assoc.ssid, ssid + 2, ssid[1]); |
2428 | wk->assoc.ssid_len = ssid[1]; | |
63f170e0 | 2429 | |
77fdaa12 | 2430 | if (req->prev_bssid) |
f679f65d | 2431 | memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN); |
77fdaa12 | 2432 | |
f679f65d | 2433 | wk->chan = req->bss->channel; |
af6b6374 JB |
2434 | wk->sdata = sdata; |
2435 | wk->done = ieee80211_assoc_done; | |
e5b900d2 JB |
2436 | if (!bss->dtim_period && |
2437 | sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) | |
2438 | wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT; | |
2439 | else | |
2440 | wk->type = IEEE80211_WORK_ASSOC; | |
77fdaa12 JB |
2441 | |
2442 | if (req->use_mfp) { | |
2443 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; | |
2444 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; | |
2445 | } else { | |
2446 | ifmgd->mfp = IEEE80211_MFP_DISABLED; | |
2447 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; | |
2448 | } | |
2449 | ||
2450 | if (req->crypto.control_port) | |
2451 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; | |
2452 | else | |
2453 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; | |
2454 | ||
a621fa4d JB |
2455 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
2456 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; | |
2457 | ||
af6b6374 JB |
2458 | ieee80211_add_work(wk); |
2459 | return 0; | |
f0706e82 JB |
2460 | } |
2461 | ||
77fdaa12 | 2462 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
667503dd JB |
2463 | struct cfg80211_deauth_request *req, |
2464 | void *cookie) | |
f0706e82 | 2465 | { |
af6b6374 | 2466 | struct ieee80211_local *local = sdata->local; |
46900298 | 2467 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
f679f65d | 2468 | struct ieee80211_work *wk; |
05e48e8e JM |
2469 | u8 bssid[ETH_ALEN]; |
2470 | bool assoc_bss = false; | |
f0706e82 | 2471 | |
77fdaa12 JB |
2472 | mutex_lock(&ifmgd->mtx); |
2473 | ||
05e48e8e | 2474 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
0c1ad2ca | 2475 | if (ifmgd->associated == req->bss) { |
53f73c09 | 2476 | ieee80211_set_disassoc(sdata, false, true); |
af6b6374 | 2477 | mutex_unlock(&ifmgd->mtx); |
05e48e8e | 2478 | assoc_bss = true; |
af6b6374 JB |
2479 | } else { |
2480 | bool not_auth_yet = false; | |
f0706e82 | 2481 | |
a58ce43f | 2482 | mutex_unlock(&ifmgd->mtx); |
a58ce43f | 2483 | |
a1699b75 | 2484 | mutex_lock(&local->mtx); |
af6b6374 | 2485 | list_for_each_entry(wk, &local->work_list, list) { |
29165e4c | 2486 | if (wk->sdata != sdata) |
af6b6374 | 2487 | continue; |
29165e4c JB |
2488 | |
2489 | if (wk->type != IEEE80211_WORK_DIRECT_PROBE && | |
79733a86 | 2490 | wk->type != IEEE80211_WORK_AUTH && |
e5b900d2 JB |
2491 | wk->type != IEEE80211_WORK_ASSOC && |
2492 | wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT) | |
29165e4c JB |
2493 | continue; |
2494 | ||
af6b6374 JB |
2495 | if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN)) |
2496 | continue; | |
29165e4c JB |
2497 | |
2498 | not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE; | |
2499 | list_del_rcu(&wk->list); | |
af6b6374 JB |
2500 | free_work(wk); |
2501 | break; | |
2502 | } | |
a1699b75 | 2503 | mutex_unlock(&local->mtx); |
af6b6374 JB |
2504 | |
2505 | /* | |
2506 | * If somebody requests authentication and we haven't | |
2507 | * sent out an auth frame yet there's no need to send | |
2508 | * out a deauth frame either. If the state was PROBE, | |
2509 | * then this is the case. If it's AUTH we have sent a | |
2510 | * frame, and if it's IDLE we have completed the auth | |
2511 | * process already. | |
2512 | */ | |
2513 | if (not_auth_yet) { | |
2514 | __cfg80211_auth_canceled(sdata->dev, bssid); | |
2515 | return 0; | |
2516 | } | |
2517 | } | |
77fdaa12 | 2518 | |
0ff71613 | 2519 | printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", |
47846c9b | 2520 | sdata->name, bssid, req->reason_code); |
0ff71613 | 2521 | |
d5cdfacb JM |
2522 | ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH, |
2523 | req->reason_code, cookie, | |
2524 | !req->local_state_change); | |
05e48e8e JM |
2525 | if (assoc_bss) |
2526 | sta_info_destroy_addr(sdata, bssid); | |
f0706e82 | 2527 | |
7da7cc1d | 2528 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 2529 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 2530 | mutex_unlock(&sdata->local->mtx); |
bc83b681 | 2531 | |
f0706e82 JB |
2532 | return 0; |
2533 | } | |
84363e6e | 2534 | |
77fdaa12 | 2535 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
667503dd JB |
2536 | struct cfg80211_disassoc_request *req, |
2537 | void *cookie) | |
9c6bd790 | 2538 | { |
77fdaa12 | 2539 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
e69e95db | 2540 | u8 bssid[ETH_ALEN]; |
9c6bd790 | 2541 | |
77fdaa12 | 2542 | mutex_lock(&ifmgd->mtx); |
10f644a4 | 2543 | |
8d8b261a JB |
2544 | /* |
2545 | * cfg80211 should catch this ... but it's racy since | |
2546 | * we can receive a disassoc frame, process it, hand it | |
2547 | * to cfg80211 while that's in a locked section already | |
2548 | * trying to tell us that the user wants to disconnect. | |
2549 | */ | |
0c1ad2ca | 2550 | if (ifmgd->associated != req->bss) { |
77fdaa12 JB |
2551 | mutex_unlock(&ifmgd->mtx); |
2552 | return -ENOLINK; | |
2553 | } | |
2554 | ||
0ff71613 | 2555 | printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", |
47846c9b | 2556 | sdata->name, req->bss->bssid, req->reason_code); |
0ff71613 | 2557 | |
e69e95db | 2558 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
53f73c09 | 2559 | ieee80211_set_disassoc(sdata, false, true); |
77fdaa12 JB |
2560 | |
2561 | mutex_unlock(&ifmgd->mtx); | |
10f644a4 | 2562 | |
77fdaa12 | 2563 | ieee80211_send_deauth_disassoc(sdata, req->bss->bssid, |
667503dd | 2564 | IEEE80211_STYPE_DISASSOC, req->reason_code, |
d5cdfacb | 2565 | cookie, !req->local_state_change); |
e69e95db | 2566 | sta_info_destroy_addr(sdata, bssid); |
bc83b681 | 2567 | |
7da7cc1d | 2568 | mutex_lock(&sdata->local->mtx); |
bc83b681 | 2569 | ieee80211_recalc_idle(sdata->local); |
7da7cc1d | 2570 | mutex_unlock(&sdata->local->mtx); |
bc83b681 | 2571 | |
10f644a4 JB |
2572 | return 0; |
2573 | } | |
026331c4 | 2574 | |
a97c13c3 JO |
2575 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
2576 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
2577 | gfp_t gfp) | |
2578 | { | |
2579 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
2580 | ||
b5878a2d JB |
2581 | trace_api_cqm_rssi_notify(sdata, rssi_event); |
2582 | ||
a97c13c3 JO |
2583 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); |
2584 | } | |
2585 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |