2 * mac80211 work implementation
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #include <linux/delay.h>
17 #include <linux/if_ether.h>
18 #include <linux/skbuff.h>
19 #include <linux/if_arp.h>
20 #include <linux/etherdevice.h>
21 #include <linux/crc32.h>
22 #include <linux/slab.h>
23 #include <net/mac80211.h>
24 #include <asm/unaligned.h>
26 #include "ieee80211_i.h"
29 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
30 #define IEEE80211_AUTH_MAX_TRIES 3
31 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
32 #define IEEE80211_ASSOC_MAX_TRIES 3
33 #define IEEE80211_MAX_PROBE_TRIES 5
43 static inline void ASSERT_WORK_MTX(struct ieee80211_local
*local
)
45 WARN_ON(!mutex_is_locked(&local
->work_mtx
));
49 * We can have multiple work items (and connection probing)
50 * scheduling this timer, but we need to take care to only
51 * reschedule it when it should fire _earlier_ than it was
52 * asked for before, or if it's not pending right now. This
53 * function ensures that. Note that it then is required to
54 * run this function for all timeouts after the first one
55 * has happened -- the work that runs from this timer will
58 static void run_again(struct ieee80211_local
*local
,
59 unsigned long timeout
)
61 ASSERT_WORK_MTX(local
);
63 if (!timer_pending(&local
->work_timer
) ||
64 time_before(timeout
, local
->work_timer
.expires
))
65 mod_timer(&local
->work_timer
, timeout
);
68 static void work_free_rcu(struct rcu_head
*head
)
70 struct ieee80211_work
*wk
=
71 container_of(head
, struct ieee80211_work
, rcu_head
);
76 void free_work(struct ieee80211_work
*wk
)
78 call_rcu(&wk
->rcu_head
, work_free_rcu
);
81 static int ieee80211_compatible_rates(const u8
*supp_rates
, int supp_rates_len
,
82 struct ieee80211_supported_band
*sband
,
88 for (i
= 0; i
< supp_rates_len
; i
++) {
89 int rate
= (supp_rates
[i
] & 0x7F) * 5;
91 for (j
= 0; j
< sband
->n_bitrates
; j
++)
92 if (sband
->bitrates
[j
].bitrate
== rate
) {
102 /* frame sending functions */
104 static void ieee80211_add_ht_ie(struct sk_buff
*skb
, const u8
*ht_info_ie
,
105 struct ieee80211_supported_band
*sband
,
106 struct ieee80211_channel
*channel
,
107 enum ieee80211_smps_mode smps
)
109 struct ieee80211_ht_info
*ht_info
;
111 u32 flags
= channel
->flags
;
112 u16 cap
= sband
->ht_cap
.cap
;
115 if (!sband
->ht_cap
.ht_supported
)
121 if (ht_info_ie
[1] < sizeof(struct ieee80211_ht_info
))
124 ht_info
= (struct ieee80211_ht_info
*)(ht_info_ie
+ 2);
126 /* determine capability flags */
128 if (ieee80211_disable_40mhz_24ghz
&&
129 sband
->band
== IEEE80211_BAND_2GHZ
) {
130 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
131 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
134 switch (ht_info
->ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
135 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
136 if (flags
& IEEE80211_CHAN_NO_HT40PLUS
) {
137 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
138 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
141 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
142 if (flags
& IEEE80211_CHAN_NO_HT40MINUS
) {
143 cap
&= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
144 cap
&= ~IEEE80211_HT_CAP_SGI_40
;
149 /* set SM PS mode properly */
150 cap
&= ~IEEE80211_HT_CAP_SM_PS
;
152 case IEEE80211_SMPS_AUTOMATIC
:
153 case IEEE80211_SMPS_NUM_MODES
:
155 case IEEE80211_SMPS_OFF
:
156 cap
|= WLAN_HT_CAP_SM_PS_DISABLED
<<
157 IEEE80211_HT_CAP_SM_PS_SHIFT
;
159 case IEEE80211_SMPS_STATIC
:
160 cap
|= WLAN_HT_CAP_SM_PS_STATIC
<<
161 IEEE80211_HT_CAP_SM_PS_SHIFT
;
163 case IEEE80211_SMPS_DYNAMIC
:
164 cap
|= WLAN_HT_CAP_SM_PS_DYNAMIC
<<
165 IEEE80211_HT_CAP_SM_PS_SHIFT
;
169 /* reserve and fill IE */
171 pos
= skb_put(skb
, sizeof(struct ieee80211_ht_cap
) + 2);
172 *pos
++ = WLAN_EID_HT_CAPABILITY
;
173 *pos
++ = sizeof(struct ieee80211_ht_cap
);
174 memset(pos
, 0, sizeof(struct ieee80211_ht_cap
));
176 /* capability flags */
177 tmp
= cpu_to_le16(cap
);
178 memcpy(pos
, &tmp
, sizeof(u16
));
181 /* AMPDU parameters */
182 *pos
++ = sband
->ht_cap
.ampdu_factor
|
183 (sband
->ht_cap
.ampdu_density
<<
184 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT
);
187 memcpy(pos
, &sband
->ht_cap
.mcs
, sizeof(sband
->ht_cap
.mcs
));
188 pos
+= sizeof(sband
->ht_cap
.mcs
);
190 /* extended capabilities */
191 pos
+= sizeof(__le16
);
193 /* BF capabilities */
194 pos
+= sizeof(__le32
);
196 /* antenna selection */
200 static void ieee80211_send_assoc(struct ieee80211_sub_if_data
*sdata
,
201 struct ieee80211_work
*wk
)
203 struct ieee80211_local
*local
= sdata
->local
;
205 struct ieee80211_mgmt
*mgmt
;
208 size_t offset
= 0, noffset
;
209 int i
, len
, count
, rates_len
, supp_rates_len
;
211 struct ieee80211_supported_band
*sband
;
214 sband
= local
->hw
.wiphy
->bands
[wk
->chan
->band
];
216 if (wk
->assoc
.supp_rates_len
) {
218 * Get all rates supported by the device and the AP as
219 * some APs don't like getting a superset of their rates
220 * in the association request (e.g. D-Link DAP 1353 in
223 rates_len
= ieee80211_compatible_rates(wk
->assoc
.supp_rates
,
224 wk
->assoc
.supp_rates_len
,
228 * In case AP not provide any supported rates information
229 * before association, we send information element(s) with
230 * all rates that we support.
233 rates_len
= sband
->n_bitrates
;
236 skb
= alloc_skb(local
->hw
.extra_tx_headroom
+
237 sizeof(*mgmt
) + /* bit too much but doesn't matter */
238 2 + wk
->assoc
.ssid_len
+ /* SSID */
239 4 + rates_len
+ /* (extended) rates */
240 4 + /* power capability */
241 2 + 2 * sband
->n_channels
+ /* supported channels */
242 2 + sizeof(struct ieee80211_ht_cap
) + /* HT */
243 wk
->ie_len
+ /* extra IEs */
247 printk(KERN_DEBUG
"%s: failed to allocate buffer for assoc "
248 "frame\n", sdata
->name
);
251 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
253 capab
= WLAN_CAPABILITY_ESS
;
255 if (sband
->band
== IEEE80211_BAND_2GHZ
) {
256 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE
))
257 capab
|= WLAN_CAPABILITY_SHORT_SLOT_TIME
;
258 if (!(local
->hw
.flags
& IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE
))
259 capab
|= WLAN_CAPABILITY_SHORT_PREAMBLE
;
262 if (wk
->assoc
.capability
& WLAN_CAPABILITY_PRIVACY
)
263 capab
|= WLAN_CAPABILITY_PRIVACY
;
265 if ((wk
->assoc
.capability
& WLAN_CAPABILITY_SPECTRUM_MGMT
) &&
266 (local
->hw
.flags
& IEEE80211_HW_SPECTRUM_MGMT
))
267 capab
|= WLAN_CAPABILITY_SPECTRUM_MGMT
;
269 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
271 memcpy(mgmt
->da
, wk
->filter_ta
, ETH_ALEN
);
272 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
273 memcpy(mgmt
->bssid
, wk
->filter_ta
, ETH_ALEN
);
275 if (!is_zero_ether_addr(wk
->assoc
.prev_bssid
)) {
277 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
278 IEEE80211_STYPE_REASSOC_REQ
);
279 mgmt
->u
.reassoc_req
.capab_info
= cpu_to_le16(capab
);
280 mgmt
->u
.reassoc_req
.listen_interval
=
281 cpu_to_le16(local
->hw
.conf
.listen_interval
);
282 memcpy(mgmt
->u
.reassoc_req
.current_ap
, wk
->assoc
.prev_bssid
,
286 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
287 IEEE80211_STYPE_ASSOC_REQ
);
288 mgmt
->u
.assoc_req
.capab_info
= cpu_to_le16(capab
);
289 mgmt
->u
.assoc_req
.listen_interval
=
290 cpu_to_le16(local
->hw
.conf
.listen_interval
);
294 ies
= pos
= skb_put(skb
, 2 + wk
->assoc
.ssid_len
);
295 *pos
++ = WLAN_EID_SSID
;
296 *pos
++ = wk
->assoc
.ssid_len
;
297 memcpy(pos
, wk
->assoc
.ssid
, wk
->assoc
.ssid_len
);
299 /* add all rates which were marked to be used above */
300 supp_rates_len
= rates_len
;
301 if (supp_rates_len
> 8)
304 len
= sband
->n_bitrates
;
305 pos
= skb_put(skb
, supp_rates_len
+ 2);
306 *pos
++ = WLAN_EID_SUPP_RATES
;
307 *pos
++ = supp_rates_len
;
310 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
311 if (BIT(i
) & rates
) {
312 int rate
= sband
->bitrates
[i
].bitrate
;
313 *pos
++ = (u8
) (rate
/ 5);
319 if (rates_len
> count
) {
320 pos
= skb_put(skb
, rates_len
- count
+ 2);
321 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
322 *pos
++ = rates_len
- count
;
324 for (i
++; i
< sband
->n_bitrates
; i
++) {
325 if (BIT(i
) & rates
) {
326 int rate
= sband
->bitrates
[i
].bitrate
;
327 *pos
++ = (u8
) (rate
/ 5);
332 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
) {
333 /* 1. power capabilities */
334 pos
= skb_put(skb
, 4);
335 *pos
++ = WLAN_EID_PWR_CAPABILITY
;
337 *pos
++ = 0; /* min tx power */
338 *pos
++ = wk
->chan
->max_power
; /* max tx power */
340 /* 2. supported channels */
341 /* TODO: get this in reg domain format */
342 pos
= skb_put(skb
, 2 * sband
->n_channels
+ 2);
343 *pos
++ = WLAN_EID_SUPPORTED_CHANNELS
;
344 *pos
++ = 2 * sband
->n_channels
;
345 for (i
= 0; i
< sband
->n_channels
; i
++) {
346 *pos
++ = ieee80211_frequency_to_channel(
347 sband
->channels
[i
].center_freq
);
348 *pos
++ = 1; /* one channel in the subband*/
352 /* if present, add any custom IEs that go before HT */
353 if (wk
->ie_len
&& wk
->ie
) {
354 static const u8 before_ht
[] = {
357 WLAN_EID_EXT_SUPP_RATES
,
358 WLAN_EID_PWR_CAPABILITY
,
359 WLAN_EID_SUPPORTED_CHANNELS
,
362 WLAN_EID_RRM_ENABLED_CAPABILITIES
,
363 WLAN_EID_MOBILITY_DOMAIN
,
364 WLAN_EID_SUPPORTED_REGULATORY_CLASSES
,
366 noffset
= ieee80211_ie_split(wk
->ie
, wk
->ie_len
,
367 before_ht
, ARRAY_SIZE(before_ht
),
369 pos
= skb_put(skb
, noffset
- offset
);
370 memcpy(pos
, wk
->ie
+ offset
, noffset
- offset
);
374 if (wk
->assoc
.use_11n
&& wk
->assoc
.wmm_used
&&
375 local
->hw
.queues
>= 4)
376 ieee80211_add_ht_ie(skb
, wk
->assoc
.ht_information_ie
,
377 sband
, wk
->chan
, wk
->assoc
.smps
);
379 /* if present, add any custom non-vendor IEs that go after HT */
380 if (wk
->ie_len
&& wk
->ie
) {
381 noffset
= ieee80211_ie_split_vendor(wk
->ie
, wk
->ie_len
,
383 pos
= skb_put(skb
, noffset
- offset
);
384 memcpy(pos
, wk
->ie
+ offset
, noffset
- offset
);
388 if (wk
->assoc
.wmm_used
&& local
->hw
.queues
>= 4) {
389 if (wk
->assoc
.uapsd_used
) {
390 qos_info
= local
->uapsd_queues
;
391 qos_info
|= (local
->uapsd_max_sp_len
<<
392 IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT
);
397 pos
= skb_put(skb
, 9);
398 *pos
++ = WLAN_EID_VENDOR_SPECIFIC
;
399 *pos
++ = 7; /* len */
400 *pos
++ = 0x00; /* Microsoft OUI 00:50:F2 */
403 *pos
++ = 2; /* WME */
404 *pos
++ = 0; /* WME info */
405 *pos
++ = 1; /* WME ver */
409 /* add any remaining custom (i.e. vendor specific here) IEs */
410 if (wk
->ie_len
&& wk
->ie
) {
411 noffset
= wk
->ie_len
;
412 pos
= skb_put(skb
, noffset
- offset
);
413 memcpy(pos
, wk
->ie
+ offset
, noffset
- offset
);
416 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
417 ieee80211_tx_skb(sdata
, skb
);
420 static void ieee80211_remove_auth_bss(struct ieee80211_local
*local
,
421 struct ieee80211_work
*wk
)
423 struct cfg80211_bss
*cbss
;
424 u16 capa_val
= WLAN_CAPABILITY_ESS
;
426 if (wk
->probe_auth
.privacy
)
427 capa_val
|= WLAN_CAPABILITY_PRIVACY
;
429 cbss
= cfg80211_get_bss(local
->hw
.wiphy
, wk
->chan
, wk
->filter_ta
,
430 wk
->probe_auth
.ssid
, wk
->probe_auth
.ssid_len
,
431 WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_PRIVACY
,
436 cfg80211_unlink_bss(local
->hw
.wiphy
, cbss
);
437 cfg80211_put_bss(cbss
);
440 static enum work_action __must_check
441 ieee80211_direct_probe(struct ieee80211_work
*wk
)
443 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
444 struct ieee80211_local
*local
= sdata
->local
;
446 wk
->probe_auth
.tries
++;
447 if (wk
->probe_auth
.tries
> IEEE80211_AUTH_MAX_TRIES
) {
448 printk(KERN_DEBUG
"%s: direct probe to %pM timed out\n",
449 sdata
->name
, wk
->filter_ta
);
452 * Most likely AP is not in the range so remove the
453 * bss struct for that AP.
455 ieee80211_remove_auth_bss(local
, wk
);
457 return WORK_ACT_TIMEOUT
;
460 printk(KERN_DEBUG
"%s: direct probe to %pM (try %d)\n",
461 sdata
->name
, wk
->filter_ta
, wk
->probe_auth
.tries
);
464 * Direct probe is sent to broadcast address as some APs
465 * will not answer to direct packet in unassociated state.
467 ieee80211_send_probe_req(sdata
, NULL
, wk
->probe_auth
.ssid
,
468 wk
->probe_auth
.ssid_len
, NULL
, 0);
470 wk
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
471 run_again(local
, wk
->timeout
);
473 return WORK_ACT_NONE
;
477 static enum work_action __must_check
478 ieee80211_authenticate(struct ieee80211_work
*wk
)
480 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
481 struct ieee80211_local
*local
= sdata
->local
;
483 wk
->probe_auth
.tries
++;
484 if (wk
->probe_auth
.tries
> IEEE80211_AUTH_MAX_TRIES
) {
485 printk(KERN_DEBUG
"%s: authentication with %pM"
486 " timed out\n", sdata
->name
, wk
->filter_ta
);
489 * Most likely AP is not in the range so remove the
490 * bss struct for that AP.
492 ieee80211_remove_auth_bss(local
, wk
);
494 return WORK_ACT_TIMEOUT
;
497 printk(KERN_DEBUG
"%s: authenticate with %pM (try %d)\n",
498 sdata
->name
, wk
->filter_ta
, wk
->probe_auth
.tries
);
500 ieee80211_send_auth(sdata
, 1, wk
->probe_auth
.algorithm
, wk
->ie
,
501 wk
->ie_len
, wk
->filter_ta
, NULL
, 0, 0);
502 wk
->probe_auth
.transaction
= 2;
504 wk
->timeout
= jiffies
+ IEEE80211_AUTH_TIMEOUT
;
505 run_again(local
, wk
->timeout
);
507 return WORK_ACT_NONE
;
510 static enum work_action __must_check
511 ieee80211_associate(struct ieee80211_work
*wk
)
513 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
514 struct ieee80211_local
*local
= sdata
->local
;
517 if (wk
->assoc
.tries
> IEEE80211_ASSOC_MAX_TRIES
) {
518 printk(KERN_DEBUG
"%s: association with %pM"
520 sdata
->name
, wk
->filter_ta
);
523 * Most likely AP is not in the range so remove the
524 * bss struct for that AP.
527 cfg80211_unlink_bss(local
->hw
.wiphy
, wk
->assoc
.bss
);
529 return WORK_ACT_TIMEOUT
;
532 printk(KERN_DEBUG
"%s: associate with %pM (try %d)\n",
533 sdata
->name
, wk
->filter_ta
, wk
->assoc
.tries
);
534 ieee80211_send_assoc(sdata
, wk
);
536 wk
->timeout
= jiffies
+ IEEE80211_ASSOC_TIMEOUT
;
537 run_again(local
, wk
->timeout
);
539 return WORK_ACT_NONE
;
542 static enum work_action __must_check
543 ieee80211_remain_on_channel_timeout(struct ieee80211_work
*wk
)
546 * First time we run, do nothing -- the generic code will
547 * have switched to the right channel etc.
550 wk
->timeout
= jiffies
+ msecs_to_jiffies(wk
->remain
.duration
);
552 cfg80211_ready_on_channel(wk
->sdata
->dev
, (unsigned long) wk
,
553 wk
->chan
, wk
->chan_type
,
554 wk
->remain
.duration
, GFP_KERNEL
);
556 return WORK_ACT_NONE
;
559 return WORK_ACT_TIMEOUT
;
562 static void ieee80211_auth_challenge(struct ieee80211_work
*wk
,
563 struct ieee80211_mgmt
*mgmt
,
566 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
568 struct ieee802_11_elems elems
;
570 pos
= mgmt
->u
.auth
.variable
;
571 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
572 if (!elems
.challenge
)
574 ieee80211_send_auth(sdata
, 3, wk
->probe_auth
.algorithm
,
575 elems
.challenge
- 2, elems
.challenge_len
+ 2,
576 wk
->filter_ta
, wk
->probe_auth
.key
,
577 wk
->probe_auth
.key_len
, wk
->probe_auth
.key_idx
);
578 wk
->probe_auth
.transaction
= 4;
581 static enum work_action __must_check
582 ieee80211_rx_mgmt_auth(struct ieee80211_work
*wk
,
583 struct ieee80211_mgmt
*mgmt
, size_t len
)
585 u16 auth_alg
, auth_transaction
, status_code
;
587 if (wk
->type
!= IEEE80211_WORK_AUTH
)
588 return WORK_ACT_NONE
;
591 return WORK_ACT_NONE
;
593 auth_alg
= le16_to_cpu(mgmt
->u
.auth
.auth_alg
);
594 auth_transaction
= le16_to_cpu(mgmt
->u
.auth
.auth_transaction
);
595 status_code
= le16_to_cpu(mgmt
->u
.auth
.status_code
);
597 if (auth_alg
!= wk
->probe_auth
.algorithm
||
598 auth_transaction
!= wk
->probe_auth
.transaction
)
599 return WORK_ACT_NONE
;
601 if (status_code
!= WLAN_STATUS_SUCCESS
) {
602 printk(KERN_DEBUG
"%s: %pM denied authentication (status %d)\n",
603 wk
->sdata
->name
, mgmt
->sa
, status_code
);
604 return WORK_ACT_DONE
;
607 switch (wk
->probe_auth
.algorithm
) {
612 case WLAN_AUTH_SHARED_KEY
:
613 if (wk
->probe_auth
.transaction
!= 4) {
614 ieee80211_auth_challenge(wk
, mgmt
, len
);
615 /* need another frame */
616 return WORK_ACT_NONE
;
621 return WORK_ACT_NONE
;
624 printk(KERN_DEBUG
"%s: authenticated\n", wk
->sdata
->name
);
625 return WORK_ACT_DONE
;
628 static enum work_action __must_check
629 ieee80211_rx_mgmt_assoc_resp(struct ieee80211_work
*wk
,
630 struct ieee80211_mgmt
*mgmt
, size_t len
,
633 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
634 struct ieee80211_local
*local
= sdata
->local
;
635 u16 capab_info
, status_code
, aid
;
636 struct ieee802_11_elems elems
;
640 * AssocResp and ReassocResp have identical structure, so process both
641 * of them in this function.
645 return WORK_ACT_NONE
;
647 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
648 status_code
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
649 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
651 printk(KERN_DEBUG
"%s: RX %sssocResp from %pM (capab=0x%x "
652 "status=%d aid=%d)\n",
653 sdata
->name
, reassoc
? "Rea" : "A", mgmt
->sa
,
654 capab_info
, status_code
, (u16
)(aid
& ~(BIT(15) | BIT(14))));
656 pos
= mgmt
->u
.assoc_resp
.variable
;
657 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
659 if (status_code
== WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY
&&
660 elems
.timeout_int
&& elems
.timeout_int_len
== 5 &&
661 elems
.timeout_int
[0] == WLAN_TIMEOUT_ASSOC_COMEBACK
) {
663 tu
= get_unaligned_le32(elems
.timeout_int
+ 1);
664 ms
= tu
* 1024 / 1000;
665 printk(KERN_DEBUG
"%s: %pM rejected association temporarily; "
666 "comeback duration %u TU (%u ms)\n",
667 sdata
->name
, mgmt
->sa
, tu
, ms
);
668 wk
->timeout
= jiffies
+ msecs_to_jiffies(ms
);
669 if (ms
> IEEE80211_ASSOC_TIMEOUT
)
670 run_again(local
, wk
->timeout
);
671 return WORK_ACT_NONE
;
674 if (status_code
!= WLAN_STATUS_SUCCESS
)
675 printk(KERN_DEBUG
"%s: %pM denied association (code=%d)\n",
676 sdata
->name
, mgmt
->sa
, status_code
);
678 printk(KERN_DEBUG
"%s: associated\n", sdata
->name
);
680 return WORK_ACT_DONE
;
683 static enum work_action __must_check
684 ieee80211_rx_mgmt_probe_resp(struct ieee80211_work
*wk
,
685 struct ieee80211_mgmt
*mgmt
, size_t len
,
686 struct ieee80211_rx_status
*rx_status
)
688 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
689 struct ieee80211_local
*local
= sdata
->local
;
692 ASSERT_WORK_MTX(local
);
694 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
696 return WORK_ACT_NONE
;
698 printk(KERN_DEBUG
"%s: direct probe responded\n", sdata
->name
);
699 return WORK_ACT_DONE
;
702 static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local
*local
,
705 struct ieee80211_rx_status
*rx_status
;
706 struct ieee80211_mgmt
*mgmt
;
707 struct ieee80211_work
*wk
;
708 enum work_action rma
= WORK_ACT_NONE
;
711 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
712 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
713 fc
= le16_to_cpu(mgmt
->frame_control
);
715 mutex_lock(&local
->work_mtx
);
717 list_for_each_entry(wk
, &local
->work_list
, list
) {
718 const u8
*bssid
= NULL
;
721 case IEEE80211_WORK_DIRECT_PROBE
:
722 case IEEE80211_WORK_AUTH
:
723 case IEEE80211_WORK_ASSOC
:
724 bssid
= wk
->filter_ta
;
731 * Before queuing, we already verified mgmt->sa,
732 * so this is needed just for matching.
734 if (compare_ether_addr(bssid
, mgmt
->bssid
))
737 switch (fc
& IEEE80211_FCTL_STYPE
) {
738 case IEEE80211_STYPE_PROBE_RESP
:
739 rma
= ieee80211_rx_mgmt_probe_resp(wk
, mgmt
, skb
->len
,
742 case IEEE80211_STYPE_AUTH
:
743 rma
= ieee80211_rx_mgmt_auth(wk
, mgmt
, skb
->len
);
745 case IEEE80211_STYPE_ASSOC_RESP
:
746 rma
= ieee80211_rx_mgmt_assoc_resp(wk
, mgmt
,
749 case IEEE80211_STYPE_REASSOC_RESP
:
750 rma
= ieee80211_rx_mgmt_assoc_resp(wk
, mgmt
,
757 * We've processed this frame for that work, so it can't
758 * belong to another work struct.
759 * NB: this is also required for correctness for 'rma'!
768 list_del_rcu(&wk
->list
);
771 WARN(1, "unexpected: %d", rma
);
774 mutex_unlock(&local
->work_mtx
);
776 if (rma
!= WORK_ACT_DONE
)
779 switch (wk
->done(wk
, skb
)) {
780 case WORK_DONE_DESTROY
:
783 case WORK_DONE_REQUEUE
:
785 wk
->started
= false; /* restart */
786 mutex_lock(&local
->work_mtx
);
787 list_add_tail(&wk
->list
, &local
->work_list
);
788 mutex_unlock(&local
->work_mtx
);
795 static void ieee80211_work_timer(unsigned long data
)
797 struct ieee80211_local
*local
= (void *) data
;
799 if (local
->quiescing
)
802 ieee80211_queue_work(&local
->hw
, &local
->work_work
);
805 static void ieee80211_work_work(struct work_struct
*work
)
807 struct ieee80211_local
*local
=
808 container_of(work
, struct ieee80211_local
, work_work
);
810 struct ieee80211_work
*wk
, *tmp
;
811 LIST_HEAD(free_work
);
812 enum work_action rma
;
813 bool remain_off_channel
= false;
819 * ieee80211_queue_work() should have picked up most cases,
820 * here we'll pick the the rest.
822 if (WARN(local
->suspended
, "work scheduled while going to suspend\n"))
825 /* first process frames to avoid timing out while a frame is pending */
826 while ((skb
= skb_dequeue(&local
->work_skb_queue
)))
827 ieee80211_work_rx_queued_mgmt(local
, skb
);
829 ieee80211_recalc_idle(local
);
831 mutex_lock(&local
->work_mtx
);
833 list_for_each_entry_safe(wk
, tmp
, &local
->work_list
, list
) {
834 bool started
= wk
->started
;
836 /* mark work as started if it's on the current off-channel */
837 if (!started
&& local
->tmp_channel
&&
838 wk
->chan
== local
->tmp_channel
&&
839 wk
->chan_type
== local
->tmp_channel_type
) {
841 wk
->timeout
= jiffies
;
844 if (!started
&& !local
->tmp_channel
) {
846 * TODO: could optimize this by leaving the
847 * station vifs in awake mode if they
848 * happen to be on the same channel as
849 * the requested channel
851 ieee80211_offchannel_stop_beaconing(local
);
852 ieee80211_offchannel_stop_station(local
);
854 local
->tmp_channel
= wk
->chan
;
855 local
->tmp_channel_type
= wk
->chan_type
;
856 ieee80211_hw_config(local
, 0);
858 wk
->timeout
= jiffies
;
861 /* don't try to work with items that aren't started */
865 if (time_is_after_jiffies(wk
->timeout
)) {
867 * This work item isn't supposed to be worked on
868 * right now, but take care to adjust the timer
871 run_again(local
, wk
->timeout
);
881 case IEEE80211_WORK_ABORT
:
882 rma
= WORK_ACT_TIMEOUT
;
884 case IEEE80211_WORK_DIRECT_PROBE
:
885 rma
= ieee80211_direct_probe(wk
);
887 case IEEE80211_WORK_AUTH
:
888 rma
= ieee80211_authenticate(wk
);
890 case IEEE80211_WORK_ASSOC
:
891 rma
= ieee80211_associate(wk
);
893 case IEEE80211_WORK_REMAIN_ON_CHANNEL
:
894 rma
= ieee80211_remain_on_channel_timeout(wk
);
898 wk
->started
= started
;
902 /* might have changed the timeout */
903 run_again(local
, wk
->timeout
);
905 case WORK_ACT_TIMEOUT
:
906 list_del_rcu(&wk
->list
);
908 list_add(&wk
->list
, &free_work
);
911 WARN(1, "unexpected: %d", rma
);
915 list_for_each_entry(wk
, &local
->work_list
, list
) {
918 if (wk
->chan
!= local
->tmp_channel
)
920 if (wk
->chan_type
!= local
->tmp_channel_type
)
922 remain_off_channel
= true;
925 if (!remain_off_channel
&& local
->tmp_channel
) {
926 local
->tmp_channel
= NULL
;
927 ieee80211_hw_config(local
, 0);
928 ieee80211_offchannel_return(local
, true);
929 /* give connection some time to breathe */
930 run_again(local
, jiffies
+ HZ
/2);
933 if (list_empty(&local
->work_list
) && local
->scan_req
)
934 ieee80211_queue_delayed_work(&local
->hw
,
936 round_jiffies_relative(0));
938 mutex_unlock(&local
->work_mtx
);
940 ieee80211_recalc_idle(local
);
942 list_for_each_entry_safe(wk
, tmp
, &free_work
, list
) {
949 void ieee80211_add_work(struct ieee80211_work
*wk
)
951 struct ieee80211_local
*local
;
953 if (WARN_ON(!wk
->chan
))
956 if (WARN_ON(!wk
->sdata
))
959 if (WARN_ON(!wk
->done
))
962 if (WARN_ON(!ieee80211_sdata_running(wk
->sdata
)))
967 local
= wk
->sdata
->local
;
968 mutex_lock(&local
->work_mtx
);
969 list_add_tail(&wk
->list
, &local
->work_list
);
970 mutex_unlock(&local
->work_mtx
);
972 ieee80211_queue_work(&local
->hw
, &local
->work_work
);
975 void ieee80211_work_init(struct ieee80211_local
*local
)
977 mutex_init(&local
->work_mtx
);
978 INIT_LIST_HEAD(&local
->work_list
);
979 setup_timer(&local
->work_timer
, ieee80211_work_timer
,
980 (unsigned long)local
);
981 INIT_WORK(&local
->work_work
, ieee80211_work_work
);
982 skb_queue_head_init(&local
->work_skb_queue
);
985 void ieee80211_work_purge(struct ieee80211_sub_if_data
*sdata
)
987 struct ieee80211_local
*local
= sdata
->local
;
988 struct ieee80211_work
*wk
;
990 mutex_lock(&local
->work_mtx
);
991 list_for_each_entry(wk
, &local
->work_list
, list
) {
992 if (wk
->sdata
!= sdata
)
994 wk
->type
= IEEE80211_WORK_ABORT
;
996 wk
->timeout
= jiffies
;
998 mutex_unlock(&local
->work_mtx
);
1000 /* run cleanups etc. */
1001 ieee80211_work_work(&local
->work_work
);
1003 mutex_lock(&local
->work_mtx
);
1004 list_for_each_entry(wk
, &local
->work_list
, list
) {
1005 if (wk
->sdata
!= sdata
)
1010 mutex_unlock(&local
->work_mtx
);
1013 ieee80211_rx_result
ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data
*sdata
,
1014 struct sk_buff
*skb
)
1016 struct ieee80211_local
*local
= sdata
->local
;
1017 struct ieee80211_mgmt
*mgmt
;
1018 struct ieee80211_work
*wk
;
1022 return RX_DROP_MONITOR
;
1024 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1025 fc
= le16_to_cpu(mgmt
->frame_control
);
1027 list_for_each_entry_rcu(wk
, &local
->work_list
, list
) {
1028 if (sdata
!= wk
->sdata
)
1030 if (compare_ether_addr(wk
->filter_ta
, mgmt
->sa
))
1032 if (compare_ether_addr(wk
->filter_ta
, mgmt
->bssid
))
1035 switch (fc
& IEEE80211_FCTL_STYPE
) {
1036 case IEEE80211_STYPE_AUTH
:
1037 case IEEE80211_STYPE_PROBE_RESP
:
1038 case IEEE80211_STYPE_ASSOC_RESP
:
1039 case IEEE80211_STYPE_REASSOC_RESP
:
1040 skb_queue_tail(&local
->work_skb_queue
, skb
);
1041 ieee80211_queue_work(&local
->hw
, &local
->work_work
);
1049 static enum work_done_result
ieee80211_remain_done(struct ieee80211_work
*wk
,
1050 struct sk_buff
*skb
)
1053 * We are done serving the remain-on-channel command.
1055 cfg80211_remain_on_channel_expired(wk
->sdata
->dev
, (unsigned long) wk
,
1056 wk
->chan
, wk
->chan_type
,
1059 return WORK_DONE_DESTROY
;
1062 int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data
*sdata
,
1063 struct ieee80211_channel
*chan
,
1064 enum nl80211_channel_type channel_type
,
1065 unsigned int duration
, u64
*cookie
)
1067 struct ieee80211_work
*wk
;
1069 wk
= kzalloc(sizeof(*wk
), GFP_KERNEL
);
1073 wk
->type
= IEEE80211_WORK_REMAIN_ON_CHANNEL
;
1075 wk
->chan_type
= channel_type
;
1077 wk
->done
= ieee80211_remain_done
;
1079 wk
->remain
.duration
= duration
;
1081 *cookie
= (unsigned long) wk
;
1083 ieee80211_add_work(wk
);
1088 int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data
*sdata
,
1091 struct ieee80211_local
*local
= sdata
->local
;
1092 struct ieee80211_work
*wk
, *tmp
;
1095 mutex_lock(&local
->work_mtx
);
1096 list_for_each_entry_safe(wk
, tmp
, &local
->work_list
, list
) {
1097 if ((unsigned long) wk
== cookie
) {
1098 wk
->timeout
= jiffies
;
1103 mutex_unlock(&local
->work_mtx
);
1108 ieee80211_queue_work(&local
->hw
, &local
->work_work
);