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