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