2 * BSS client mode implementation
3 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
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>
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.
14 #include <linux/delay.h>
15 #include <linux/if_ether.h>
16 #include <linux/skbuff.h>
17 #include <linux/if_arp.h>
18 #include <linux/etherdevice.h>
19 #include <linux/rtnetlink.h>
20 #include <linux/pm_qos_params.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"
27 #include "driver-ops.h"
31 static int max_nullfunc_tries
= 2;
32 module_param(max_nullfunc_tries
, int, 0644);
33 MODULE_PARM_DESC(max_nullfunc_tries
,
34 "Maximum nullfunc tx tries before disconnecting (reason 4).");
36 static int max_probe_tries
= 5;
37 module_param(max_probe_tries
, int, 0644);
38 MODULE_PARM_DESC(max_probe_tries
,
39 "Maximum probe tries before disconnecting (reason 4).");
42 * Beacon loss timeout is calculated as N frames times the
43 * advertised beacon interval. This may need to be somewhat
44 * higher than what hardware might detect to account for
45 * delays in the host processing frames. But since we also
46 * probe on beacon miss before declaring the connection lost
47 * default to what we want.
49 #define IEEE80211_BEACON_LOSS_COUNT 7
52 * Time the connection can be idle before we probe
53 * it to see if we can still talk to the AP.
55 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
57 * Time we wait for a probe response after sending
58 * a probe request because of beacon loss or for
59 * checking the connection still works.
61 static int probe_wait_ms
= 500;
62 module_param(probe_wait_ms
, int, 0644);
63 MODULE_PARM_DESC(probe_wait_ms
,
64 "Maximum time(ms) to wait for probe response"
65 " before disconnecting (reason 4).");
68 * Weight given to the latest Beacon frame when calculating average signal
69 * strength for Beacon frames received in the current BSS. This must be
72 #define IEEE80211_SIGNAL_AVE_WEIGHT 3
75 * How many Beacon frames need to have been used in average signal strength
76 * before starting to indicate signal change events.
78 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
80 #define TMR_RUNNING_TIMER 0
81 #define TMR_RUNNING_CHANSW 1
84 * All cfg80211 functions have to be called outside a locked
85 * section so that they can acquire a lock themselves... This
86 * is much simpler than queuing up things in cfg80211, but we
87 * do need some indirection for that here.
90 /* no action required */
93 /* caller must call cfg80211_send_rx_auth() */
94 RX_MGMT_CFG80211_AUTH
,
96 /* caller must call cfg80211_send_rx_assoc() */
97 RX_MGMT_CFG80211_ASSOC
,
99 /* caller must call cfg80211_send_deauth() */
100 RX_MGMT_CFG80211_DEAUTH
,
102 /* caller must call cfg80211_send_disassoc() */
103 RX_MGMT_CFG80211_DISASSOC
,
105 /* caller must tell cfg80211 about internal error */
106 RX_MGMT_CFG80211_ASSOC_ERROR
,
110 static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed
*ifmgd
)
112 lockdep_assert_held(&ifmgd
->mtx
);
116 * We can have multiple work items (and connection probing)
117 * scheduling this timer, but we need to take care to only
118 * reschedule it when it should fire _earlier_ than it was
119 * asked for before, or if it's not pending right now. This
120 * function ensures that. Note that it then is required to
121 * run this function for all timeouts after the first one
122 * has happened -- the work that runs from this timer will
125 static void run_again(struct ieee80211_if_managed
*ifmgd
,
126 unsigned long timeout
)
128 ASSERT_MGD_MTX(ifmgd
);
130 if (!timer_pending(&ifmgd
->timer
) ||
131 time_before(timeout
, ifmgd
->timer
.expires
))
132 mod_timer(&ifmgd
->timer
, timeout
);
135 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data
*sdata
)
137 if (sdata
->local
->hw
.flags
& IEEE80211_HW_BEACON_FILTER
)
140 mod_timer(&sdata
->u
.mgd
.bcn_mon_timer
,
141 round_jiffies_up(jiffies
+ sdata
->u
.mgd
.beacon_timeout
));
144 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data
*sdata
)
146 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
148 if (unlikely(!sdata
->u
.mgd
.associated
))
151 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
154 mod_timer(&sdata
->u
.mgd
.conn_mon_timer
,
155 round_jiffies_up(jiffies
+ IEEE80211_CONNECTION_IDLE_TIME
));
157 ifmgd
->probe_send_count
= 0;
160 static int ecw2cw(int ecw
)
162 return (1 << ecw
) - 1;
166 * ieee80211_enable_ht should be called only after the operating band
167 * has been determined as ht configuration depends on the hw's
168 * HT abilities for a specific band.
170 static u32
ieee80211_enable_ht(struct ieee80211_sub_if_data
*sdata
,
171 struct ieee80211_ht_info
*hti
,
172 const u8
*bssid
, u16 ap_ht_cap_flags
)
174 struct ieee80211_local
*local
= sdata
->local
;
175 struct ieee80211_supported_band
*sband
;
176 struct sta_info
*sta
;
180 bool enable_ht
= true;
181 enum nl80211_channel_type prev_chantype
;
182 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
184 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
186 prev_chantype
= sdata
->vif
.bss_conf
.channel_type
;
188 /* HT is not supported */
189 if (!sband
->ht_cap
.ht_supported
)
193 hti_cfreq
= ieee80211_channel_to_frequency(hti
->control_chan
,
195 /* check that channel matches the right operating channel */
196 if (local
->hw
.conf
.channel
->center_freq
!= hti_cfreq
) {
197 /* Some APs mess this up, evidently.
198 * Netgear WNDR3700 sometimes reports 4 higher than
199 * the actual channel, for instance.
202 "%s: Wrong control channel in association"
203 " response: configured center-freq: %d"
204 " hti-cfreq: %d hti->control_chan: %d"
205 " band: %d. Disabling HT.\n",
207 local
->hw
.conf
.channel
->center_freq
,
208 hti_cfreq
, hti
->control_chan
,
215 channel_type
= NL80211_CHAN_HT20
;
217 if (!(ap_ht_cap_flags
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
) &&
218 (sband
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
219 (hti
->ht_param
& IEEE80211_HT_PARAM_CHAN_WIDTH_ANY
)) {
220 switch(hti
->ht_param
& IEEE80211_HT_PARAM_CHA_SEC_OFFSET
) {
221 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
222 if (!(local
->hw
.conf
.channel
->flags
&
223 IEEE80211_CHAN_NO_HT40PLUS
))
224 channel_type
= NL80211_CHAN_HT40PLUS
;
226 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
227 if (!(local
->hw
.conf
.channel
->flags
&
228 IEEE80211_CHAN_NO_HT40MINUS
))
229 channel_type
= NL80211_CHAN_HT40MINUS
;
235 if (local
->tmp_channel
)
236 local
->tmp_channel_type
= channel_type
;
238 if (!ieee80211_set_channel_type(local
, sdata
, channel_type
)) {
239 /* can only fail due to HT40+/- mismatch */
240 channel_type
= NL80211_CHAN_HT20
;
241 WARN_ON(!ieee80211_set_channel_type(local
, sdata
, channel_type
));
244 /* channel_type change automatically detected */
245 ieee80211_hw_config(local
, 0);
247 if (prev_chantype
!= channel_type
) {
249 sta
= sta_info_get(sdata
, bssid
);
251 rate_control_rate_update(local
, sband
, sta
,
252 IEEE80211_RC_HT_CHANGED
,
257 ht_opmode
= le16_to_cpu(hti
->operation_mode
);
259 /* if bss configuration changed store the new one */
260 if (sdata
->ht_opmode_valid
!= enable_ht
||
261 sdata
->vif
.bss_conf
.ht_operation_mode
!= ht_opmode
||
262 prev_chantype
!= channel_type
) {
263 changed
|= BSS_CHANGED_HT
;
264 sdata
->vif
.bss_conf
.ht_operation_mode
= ht_opmode
;
265 sdata
->ht_opmode_valid
= enable_ht
;
271 /* frame sending functions */
273 static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data
*sdata
,
274 const u8
*bssid
, u16 stype
, u16 reason
,
275 void *cookie
, bool send_frame
)
277 struct ieee80211_local
*local
= sdata
->local
;
278 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
280 struct ieee80211_mgmt
*mgmt
;
282 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ sizeof(*mgmt
));
284 printk(KERN_DEBUG
"%s: failed to allocate buffer for "
285 "deauth/disassoc frame\n", sdata
->name
);
288 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
290 mgmt
= (struct ieee80211_mgmt
*) skb_put(skb
, 24);
292 memcpy(mgmt
->da
, bssid
, ETH_ALEN
);
293 memcpy(mgmt
->sa
, sdata
->vif
.addr
, ETH_ALEN
);
294 memcpy(mgmt
->bssid
, bssid
, ETH_ALEN
);
295 mgmt
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
| stype
);
297 /* u.deauth.reason_code == u.disassoc.reason_code */
298 mgmt
->u
.deauth
.reason_code
= cpu_to_le16(reason
);
300 if (stype
== IEEE80211_STYPE_DEAUTH
)
302 __cfg80211_send_deauth(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
304 cfg80211_send_deauth(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
307 __cfg80211_send_disassoc(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
309 cfg80211_send_disassoc(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
310 if (!(ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
))
311 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
314 ieee80211_tx_skb(sdata
, skb
);
319 void ieee80211_send_pspoll(struct ieee80211_local
*local
,
320 struct ieee80211_sub_if_data
*sdata
)
322 struct ieee80211_pspoll
*pspoll
;
325 skb
= ieee80211_pspoll_get(&local
->hw
, &sdata
->vif
);
329 pspoll
= (struct ieee80211_pspoll
*) skb
->data
;
330 pspoll
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
332 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
333 ieee80211_tx_skb(sdata
, skb
);
336 void ieee80211_send_nullfunc(struct ieee80211_local
*local
,
337 struct ieee80211_sub_if_data
*sdata
,
341 struct ieee80211_hdr_3addr
*nullfunc
;
343 skb
= ieee80211_nullfunc_get(&local
->hw
, &sdata
->vif
);
347 nullfunc
= (struct ieee80211_hdr_3addr
*) skb
->data
;
349 nullfunc
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
351 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
352 ieee80211_tx_skb(sdata
, skb
);
355 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local
*local
,
356 struct ieee80211_sub_if_data
*sdata
)
359 struct ieee80211_hdr
*nullfunc
;
362 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
365 skb
= dev_alloc_skb(local
->hw
.extra_tx_headroom
+ 30);
367 printk(KERN_DEBUG
"%s: failed to allocate buffer for 4addr "
368 "nullfunc frame\n", sdata
->name
);
371 skb_reserve(skb
, local
->hw
.extra_tx_headroom
);
373 nullfunc
= (struct ieee80211_hdr
*) skb_put(skb
, 30);
374 memset(nullfunc
, 0, 30);
375 fc
= cpu_to_le16(IEEE80211_FTYPE_DATA
| IEEE80211_STYPE_NULLFUNC
|
376 IEEE80211_FCTL_FROMDS
| IEEE80211_FCTL_TODS
);
377 nullfunc
->frame_control
= fc
;
378 memcpy(nullfunc
->addr1
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
379 memcpy(nullfunc
->addr2
, sdata
->vif
.addr
, ETH_ALEN
);
380 memcpy(nullfunc
->addr3
, sdata
->u
.mgd
.bssid
, ETH_ALEN
);
381 memcpy(nullfunc
->addr4
, sdata
->vif
.addr
, ETH_ALEN
);
383 IEEE80211_SKB_CB(skb
)->flags
|= IEEE80211_TX_INTFL_DONT_ENCRYPT
;
384 ieee80211_tx_skb(sdata
, skb
);
387 /* spectrum management related things */
388 static void ieee80211_chswitch_work(struct work_struct
*work
)
390 struct ieee80211_sub_if_data
*sdata
=
391 container_of(work
, struct ieee80211_sub_if_data
, u
.mgd
.chswitch_work
);
392 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
394 if (!ieee80211_sdata_running(sdata
))
397 mutex_lock(&ifmgd
->mtx
);
398 if (!ifmgd
->associated
)
401 sdata
->local
->oper_channel
= sdata
->local
->csa_channel
;
402 if (!sdata
->local
->ops
->channel_switch
) {
403 /* call "hw_config" only if doing sw channel switch */
404 ieee80211_hw_config(sdata
->local
,
405 IEEE80211_CONF_CHANGE_CHANNEL
);
408 /* XXX: shouldn't really modify cfg80211-owned data! */
409 ifmgd
->associated
->channel
= sdata
->local
->oper_channel
;
411 ieee80211_wake_queues_by_reason(&sdata
->local
->hw
,
412 IEEE80211_QUEUE_STOP_REASON_CSA
);
414 ifmgd
->flags
&= ~IEEE80211_STA_CSA_RECEIVED
;
415 mutex_unlock(&ifmgd
->mtx
);
418 void ieee80211_chswitch_done(struct ieee80211_vif
*vif
, bool success
)
420 struct ieee80211_sub_if_data
*sdata
;
421 struct ieee80211_if_managed
*ifmgd
;
423 sdata
= vif_to_sdata(vif
);
424 ifmgd
= &sdata
->u
.mgd
;
426 trace_api_chswitch_done(sdata
, success
);
429 * If the channel switch was not successful, stay
430 * around on the old channel. We currently lack
431 * good handling of this situation, possibly we
432 * should just drop the association.
434 sdata
->local
->csa_channel
= sdata
->local
->oper_channel
;
437 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
439 EXPORT_SYMBOL(ieee80211_chswitch_done
);
441 static void ieee80211_chswitch_timer(unsigned long data
)
443 struct ieee80211_sub_if_data
*sdata
=
444 (struct ieee80211_sub_if_data
*) data
;
445 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
447 if (sdata
->local
->quiescing
) {
448 set_bit(TMR_RUNNING_CHANSW
, &ifmgd
->timers_running
);
452 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
455 void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data
*sdata
,
456 struct ieee80211_channel_sw_ie
*sw_elem
,
457 struct ieee80211_bss
*bss
,
460 struct cfg80211_bss
*cbss
=
461 container_of((void *)bss
, struct cfg80211_bss
, priv
);
462 struct ieee80211_channel
*new_ch
;
463 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
464 int new_freq
= ieee80211_channel_to_frequency(sw_elem
->new_ch_num
,
465 cbss
->channel
->band
);
467 ASSERT_MGD_MTX(ifmgd
);
469 if (!ifmgd
->associated
)
472 if (sdata
->local
->scanning
)
475 /* Disregard subsequent beacons if we are already running a timer
478 if (ifmgd
->flags
& IEEE80211_STA_CSA_RECEIVED
)
481 new_ch
= ieee80211_get_channel(sdata
->local
->hw
.wiphy
, new_freq
);
482 if (!new_ch
|| new_ch
->flags
& IEEE80211_CHAN_DISABLED
)
485 sdata
->local
->csa_channel
= new_ch
;
487 if (sdata
->local
->ops
->channel_switch
) {
488 /* use driver's channel switch callback */
489 struct ieee80211_channel_switch ch_switch
;
490 memset(&ch_switch
, 0, sizeof(ch_switch
));
491 ch_switch
.timestamp
= timestamp
;
493 ch_switch
.block_tx
= true;
494 ieee80211_stop_queues_by_reason(&sdata
->local
->hw
,
495 IEEE80211_QUEUE_STOP_REASON_CSA
);
497 ch_switch
.channel
= new_ch
;
498 ch_switch
.count
= sw_elem
->count
;
499 ifmgd
->flags
|= IEEE80211_STA_CSA_RECEIVED
;
500 drv_channel_switch(sdata
->local
, &ch_switch
);
504 /* channel switch handled in software */
505 if (sw_elem
->count
<= 1) {
506 ieee80211_queue_work(&sdata
->local
->hw
, &ifmgd
->chswitch_work
);
509 ieee80211_stop_queues_by_reason(&sdata
->local
->hw
,
510 IEEE80211_QUEUE_STOP_REASON_CSA
);
511 ifmgd
->flags
|= IEEE80211_STA_CSA_RECEIVED
;
512 mod_timer(&ifmgd
->chswitch_timer
,
514 msecs_to_jiffies(sw_elem
->count
*
515 cbss
->beacon_interval
));
519 static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data
*sdata
,
520 u16 capab_info
, u8
*pwr_constr_elem
,
521 u8 pwr_constr_elem_len
)
523 struct ieee80211_conf
*conf
= &sdata
->local
->hw
.conf
;
525 if (!(capab_info
& WLAN_CAPABILITY_SPECTRUM_MGMT
))
528 /* Power constraint IE length should be 1 octet */
529 if (pwr_constr_elem_len
!= 1)
532 if ((*pwr_constr_elem
<= conf
->channel
->max_power
) &&
533 (*pwr_constr_elem
!= sdata
->local
->power_constr_level
)) {
534 sdata
->local
->power_constr_level
= *pwr_constr_elem
;
535 ieee80211_hw_config(sdata
->local
, 0);
539 void ieee80211_enable_dyn_ps(struct ieee80211_vif
*vif
)
541 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
542 struct ieee80211_local
*local
= sdata
->local
;
543 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
545 WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
546 !(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
) ||
547 (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
));
549 local
->disable_dynamic_ps
= false;
550 conf
->dynamic_ps_timeout
= local
->dynamic_ps_user_timeout
;
552 EXPORT_SYMBOL(ieee80211_enable_dyn_ps
);
554 void ieee80211_disable_dyn_ps(struct ieee80211_vif
*vif
)
556 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
557 struct ieee80211_local
*local
= sdata
->local
;
558 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
560 WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
||
561 !(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
) ||
562 (local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
));
564 local
->disable_dynamic_ps
= true;
565 conf
->dynamic_ps_timeout
= 0;
566 del_timer_sync(&local
->dynamic_ps_timer
);
567 ieee80211_queue_work(&local
->hw
,
568 &local
->dynamic_ps_enable_work
);
570 EXPORT_SYMBOL(ieee80211_disable_dyn_ps
);
573 static void ieee80211_enable_ps(struct ieee80211_local
*local
,
574 struct ieee80211_sub_if_data
*sdata
)
576 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
579 * If we are scanning right now then the parameters will
580 * take effect when scan finishes.
585 if (conf
->dynamic_ps_timeout
> 0 &&
586 !(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_PS
)) {
587 mod_timer(&local
->dynamic_ps_timer
, jiffies
+
588 msecs_to_jiffies(conf
->dynamic_ps_timeout
));
590 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)
591 ieee80211_send_nullfunc(local
, sdata
, 1);
593 if ((local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) &&
594 (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
))
597 conf
->flags
|= IEEE80211_CONF_PS
;
598 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
602 static void ieee80211_change_ps(struct ieee80211_local
*local
)
604 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
606 if (local
->ps_sdata
) {
607 ieee80211_enable_ps(local
, local
->ps_sdata
);
608 } else if (conf
->flags
& IEEE80211_CONF_PS
) {
609 conf
->flags
&= ~IEEE80211_CONF_PS
;
610 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
611 del_timer_sync(&local
->dynamic_ps_timer
);
612 cancel_work_sync(&local
->dynamic_ps_enable_work
);
616 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data
*sdata
)
618 struct ieee80211_if_managed
*mgd
= &sdata
->u
.mgd
;
619 struct sta_info
*sta
= NULL
;
625 if (!mgd
->associated
)
628 if (!mgd
->associated
->beacon_ies
)
631 if (mgd
->flags
& (IEEE80211_STA_BEACON_POLL
|
632 IEEE80211_STA_CONNECTION_POLL
))
636 sta
= sta_info_get(sdata
, mgd
->bssid
);
638 sta_flags
= get_sta_flags(sta
);
641 if (!(sta_flags
& WLAN_STA_AUTHORIZED
))
647 /* need to hold RTNL or interface lock */
648 void ieee80211_recalc_ps(struct ieee80211_local
*local
, s32 latency
)
650 struct ieee80211_sub_if_data
*sdata
, *found
= NULL
;
654 if (!(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_PS
)) {
655 local
->ps_sdata
= NULL
;
659 if (!list_empty(&local
->work_list
)) {
660 local
->ps_sdata
= NULL
;
664 list_for_each_entry(sdata
, &local
->interfaces
, list
) {
665 if (!ieee80211_sdata_running(sdata
))
667 if (sdata
->vif
.type
== NL80211_IFTYPE_AP
) {
668 /* If an AP vif is found, then disable PS
669 * by setting the count to zero thereby setting
675 if (sdata
->vif
.type
!= NL80211_IFTYPE_STATION
)
681 if (count
== 1 && ieee80211_powersave_allowed(found
)) {
682 struct ieee80211_conf
*conf
= &local
->hw
.conf
;
686 latency
= pm_qos_request(PM_QOS_NETWORK_LATENCY
);
688 beaconint_us
= ieee80211_tu_to_usec(
689 found
->vif
.bss_conf
.beacon_int
);
691 timeout
= local
->dynamic_ps_forced_timeout
;
694 * Go to full PSM if the user configures a very low
695 * latency requirement.
696 * The 2000 second value is there for compatibility
697 * until the PM_QOS_NETWORK_LATENCY is configured
700 if (latency
> (1900 * USEC_PER_MSEC
) &&
701 latency
!= (2000 * USEC_PER_SEC
))
706 local
->dynamic_ps_user_timeout
= timeout
;
707 if (!local
->disable_dynamic_ps
)
708 conf
->dynamic_ps_timeout
=
709 local
->dynamic_ps_user_timeout
;
711 if (beaconint_us
> latency
) {
712 local
->ps_sdata
= NULL
;
714 struct ieee80211_bss
*bss
;
718 bss
= (void *)found
->u
.mgd
.associated
->priv
;
719 dtimper
= bss
->dtim_period
;
721 /* If the TIM IE is invalid, pretend the value is 1 */
724 else if (dtimper
> 1)
725 maxslp
= min_t(int, dtimper
,
726 latency
/ beaconint_us
);
728 local
->hw
.conf
.max_sleep_period
= maxslp
;
729 local
->hw
.conf
.ps_dtim_period
= dtimper
;
730 local
->ps_sdata
= found
;
733 local
->ps_sdata
= NULL
;
737 ieee80211_change_ps(local
);
740 void ieee80211_dynamic_ps_disable_work(struct work_struct
*work
)
742 struct ieee80211_local
*local
=
743 container_of(work
, struct ieee80211_local
,
744 dynamic_ps_disable_work
);
746 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
747 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
748 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
751 ieee80211_wake_queues_by_reason(&local
->hw
,
752 IEEE80211_QUEUE_STOP_REASON_PS
);
755 void ieee80211_dynamic_ps_enable_work(struct work_struct
*work
)
757 struct ieee80211_local
*local
=
758 container_of(work
, struct ieee80211_local
,
759 dynamic_ps_enable_work
);
760 struct ieee80211_sub_if_data
*sdata
= local
->ps_sdata
;
761 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
763 /* can only happen when PS was just disabled anyway */
767 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
)
770 if ((local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) &&
771 (!(ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
))) {
772 netif_tx_stop_all_queues(sdata
->dev
);
774 * Flush all the frames queued in the driver before
775 * going to power save
777 drv_flush(local
, false);
778 ieee80211_send_nullfunc(local
, sdata
, 1);
780 /* Flush once again to get the tx status of nullfunc frame */
781 drv_flush(local
, false);
784 if (!((local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) &&
785 (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)) ||
786 (ifmgd
->flags
& IEEE80211_STA_NULLFUNC_ACKED
)) {
787 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
788 local
->hw
.conf
.flags
|= IEEE80211_CONF_PS
;
789 ieee80211_hw_config(local
, IEEE80211_CONF_CHANGE_PS
);
792 netif_tx_start_all_queues(sdata
->dev
);
795 void ieee80211_dynamic_ps_timer(unsigned long data
)
797 struct ieee80211_local
*local
= (void *) data
;
799 if (local
->quiescing
|| local
->suspended
)
802 ieee80211_queue_work(&local
->hw
, &local
->dynamic_ps_enable_work
);
806 static void ieee80211_sta_wmm_params(struct ieee80211_local
*local
,
807 struct ieee80211_sub_if_data
*sdata
,
808 u8
*wmm_param
, size_t wmm_param_len
)
810 struct ieee80211_tx_queue_params params
;
811 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
814 u8
*pos
, uapsd_queues
= 0;
816 if (!local
->ops
->conf_tx
)
819 if (local
->hw
.queues
< 4)
825 if (wmm_param_len
< 8 || wmm_param
[5] /* version */ != 1)
828 if (ifmgd
->flags
& IEEE80211_STA_UAPSD_ENABLED
)
829 uapsd_queues
= local
->uapsd_queues
;
831 count
= wmm_param
[6] & 0x0f;
832 if (count
== ifmgd
->wmm_last_param_set
)
834 ifmgd
->wmm_last_param_set
= count
;
837 left
= wmm_param_len
- 8;
839 memset(¶ms
, 0, sizeof(params
));
842 for (; left
>= 4; left
-= 4, pos
+= 4) {
843 int aci
= (pos
[0] >> 5) & 0x03;
844 int acm
= (pos
[0] >> 4) & 0x01;
852 local
->wmm_acm
|= BIT(1) | BIT(2); /* BK/- */
853 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
859 local
->wmm_acm
|= BIT(4) | BIT(5); /* CL/VI */
860 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
866 local
->wmm_acm
|= BIT(6) | BIT(7); /* VO/NC */
867 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
874 local
->wmm_acm
|= BIT(0) | BIT(3); /* BE/EE */
875 if (uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
880 params
.aifs
= pos
[0] & 0x0f;
881 params
.cw_max
= ecw2cw((pos
[1] & 0xf0) >> 4);
882 params
.cw_min
= ecw2cw(pos
[1] & 0x0f);
883 params
.txop
= get_unaligned_le16(pos
+ 2);
884 params
.uapsd
= uapsd
;
886 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
887 wiphy_debug(local
->hw
.wiphy
,
888 "WMM queue=%d aci=%d acm=%d aifs=%d "
889 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
891 params
.aifs
, params
.cw_min
, params
.cw_max
,
892 params
.txop
, params
.uapsd
);
894 if (drv_conf_tx(local
, queue
, ¶ms
))
895 wiphy_debug(local
->hw
.wiphy
,
896 "failed to set TX queue parameters for queue %d\n",
900 /* enable WMM or activate new settings */
901 sdata
->vif
.bss_conf
.qos
= true;
902 ieee80211_bss_info_change_notify(sdata
, BSS_CHANGED_QOS
);
905 static u32
ieee80211_handle_bss_capability(struct ieee80211_sub_if_data
*sdata
,
906 u16 capab
, bool erp_valid
, u8 erp
)
908 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
911 bool use_short_preamble
;
915 use_protection
= (erp
& WLAN_ERP_USE_PROTECTION
) != 0;
916 use_short_preamble
= (erp
& WLAN_ERP_BARKER_PREAMBLE
) == 0;
918 use_protection
= false;
919 use_short_preamble
= !!(capab
& WLAN_CAPABILITY_SHORT_PREAMBLE
);
922 use_short_slot
= !!(capab
& WLAN_CAPABILITY_SHORT_SLOT_TIME
);
923 if (sdata
->local
->hw
.conf
.channel
->band
== IEEE80211_BAND_5GHZ
)
924 use_short_slot
= true;
926 if (use_protection
!= bss_conf
->use_cts_prot
) {
927 bss_conf
->use_cts_prot
= use_protection
;
928 changed
|= BSS_CHANGED_ERP_CTS_PROT
;
931 if (use_short_preamble
!= bss_conf
->use_short_preamble
) {
932 bss_conf
->use_short_preamble
= use_short_preamble
;
933 changed
|= BSS_CHANGED_ERP_PREAMBLE
;
936 if (use_short_slot
!= bss_conf
->use_short_slot
) {
937 bss_conf
->use_short_slot
= use_short_slot
;
938 changed
|= BSS_CHANGED_ERP_SLOT
;
944 static void ieee80211_set_associated(struct ieee80211_sub_if_data
*sdata
,
945 struct cfg80211_bss
*cbss
,
946 u32 bss_info_changed
)
948 struct ieee80211_bss
*bss
= (void *)cbss
->priv
;
949 struct ieee80211_local
*local
= sdata
->local
;
950 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
952 bss_info_changed
|= BSS_CHANGED_ASSOC
;
953 /* set timing information */
954 bss_conf
->beacon_int
= cbss
->beacon_interval
;
955 bss_conf
->timestamp
= cbss
->tsf
;
957 bss_info_changed
|= BSS_CHANGED_BEACON_INT
;
958 bss_info_changed
|= ieee80211_handle_bss_capability(sdata
,
959 cbss
->capability
, bss
->has_erp_value
, bss
->erp_value
);
961 sdata
->u
.mgd
.beacon_timeout
= usecs_to_jiffies(ieee80211_tu_to_usec(
962 IEEE80211_BEACON_LOSS_COUNT
* bss_conf
->beacon_int
));
964 sdata
->u
.mgd
.associated
= cbss
;
965 memcpy(sdata
->u
.mgd
.bssid
, cbss
->bssid
, ETH_ALEN
);
967 sdata
->u
.mgd
.flags
|= IEEE80211_STA_RESET_SIGNAL_AVE
;
969 /* just to be sure */
970 sdata
->u
.mgd
.flags
&= ~(IEEE80211_STA_CONNECTION_POLL
|
971 IEEE80211_STA_BEACON_POLL
);
973 ieee80211_led_assoc(local
, 1);
975 if (local
->hw
.flags
& IEEE80211_HW_NEED_DTIM_PERIOD
)
976 bss_conf
->dtim_period
= bss
->dtim_period
;
978 bss_conf
->dtim_period
= 0;
982 * For now just always ask the driver to update the basic rateset
983 * when we have associated, we aren't checking whether it actually
986 bss_info_changed
|= BSS_CHANGED_BASIC_RATES
;
988 /* And the BSSID changed - we're associated now */
989 bss_info_changed
|= BSS_CHANGED_BSSID
;
991 /* Tell the driver to monitor connection quality (if supported) */
992 if ((local
->hw
.flags
& IEEE80211_HW_SUPPORTS_CQM_RSSI
) &&
993 bss_conf
->cqm_rssi_thold
)
994 bss_info_changed
|= BSS_CHANGED_CQM
;
996 /* Enable ARP filtering */
997 if (bss_conf
->arp_filter_enabled
!= sdata
->arp_filter_state
) {
998 bss_conf
->arp_filter_enabled
= sdata
->arp_filter_state
;
999 bss_info_changed
|= BSS_CHANGED_ARP_FILTER
;
1002 ieee80211_bss_info_change_notify(sdata
, bss_info_changed
);
1004 mutex_lock(&local
->iflist_mtx
);
1005 ieee80211_recalc_ps(local
, -1);
1006 ieee80211_recalc_smps(local
);
1007 mutex_unlock(&local
->iflist_mtx
);
1009 netif_tx_start_all_queues(sdata
->dev
);
1010 netif_carrier_on(sdata
->dev
);
1013 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data
*sdata
,
1014 bool remove_sta
, bool tx
)
1016 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1017 struct ieee80211_local
*local
= sdata
->local
;
1018 struct sta_info
*sta
;
1019 u32 changed
= 0, config_changed
= 0;
1022 ASSERT_MGD_MTX(ifmgd
);
1024 if (WARN_ON(!ifmgd
->associated
))
1027 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
1029 ifmgd
->associated
= NULL
;
1030 memset(ifmgd
->bssid
, 0, ETH_ALEN
);
1033 * we need to commit the associated = NULL change because the
1034 * scan code uses that to determine whether this iface should
1035 * go to/wake up from powersave or not -- and could otherwise
1036 * wake the queues erroneously.
1041 * Thus, we can only afterwards stop the queues -- to account
1042 * for the case where another CPU is finishing a scan at this
1043 * time -- we don't want the scan code to enable queues.
1046 netif_tx_stop_all_queues(sdata
->dev
);
1047 netif_carrier_off(sdata
->dev
);
1049 mutex_lock(&local
->sta_mtx
);
1050 sta
= sta_info_get(sdata
, bssid
);
1052 set_sta_flags(sta
, WLAN_STA_BLOCK_BA
);
1053 ieee80211_sta_tear_down_BA_sessions(sta
, tx
);
1055 mutex_unlock(&local
->sta_mtx
);
1057 changed
|= ieee80211_reset_erp_info(sdata
);
1059 ieee80211_led_assoc(local
, 0);
1060 changed
|= BSS_CHANGED_ASSOC
;
1061 sdata
->vif
.bss_conf
.assoc
= false;
1063 ieee80211_set_wmm_default(sdata
);
1065 /* channel(_type) changes are handled by ieee80211_hw_config */
1066 WARN_ON(!ieee80211_set_channel_type(local
, sdata
, NL80211_CHAN_NO_HT
));
1068 /* on the next assoc, re-program HT parameters */
1069 sdata
->ht_opmode_valid
= false;
1071 local
->power_constr_level
= 0;
1073 del_timer_sync(&local
->dynamic_ps_timer
);
1074 cancel_work_sync(&local
->dynamic_ps_enable_work
);
1076 if (local
->hw
.conf
.flags
& IEEE80211_CONF_PS
) {
1077 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1078 config_changed
|= IEEE80211_CONF_CHANGE_PS
;
1081 ieee80211_hw_config(local
, config_changed
);
1083 /* Disable ARP filtering */
1084 if (sdata
->vif
.bss_conf
.arp_filter_enabled
) {
1085 sdata
->vif
.bss_conf
.arp_filter_enabled
= false;
1086 changed
|= BSS_CHANGED_ARP_FILTER
;
1089 /* The BSSID (not really interesting) and HT changed */
1090 changed
|= BSS_CHANGED_BSSID
| BSS_CHANGED_HT
;
1091 ieee80211_bss_info_change_notify(sdata
, changed
);
1094 sta_info_destroy_addr(sdata
, bssid
);
1096 del_timer_sync(&sdata
->u
.mgd
.conn_mon_timer
);
1097 del_timer_sync(&sdata
->u
.mgd
.bcn_mon_timer
);
1098 del_timer_sync(&sdata
->u
.mgd
.timer
);
1099 del_timer_sync(&sdata
->u
.mgd
.chswitch_timer
);
1102 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data
*sdata
,
1103 struct ieee80211_hdr
*hdr
)
1106 * We can postpone the mgd.timer whenever receiving unicast frames
1107 * from AP because we know that the connection is working both ways
1108 * at that time. But multicast frames (and hence also beacons) must
1109 * be ignored here, because we need to trigger the timer during
1110 * data idle periods for sending the periodic probe request to the
1111 * AP we're connected to.
1113 if (is_multicast_ether_addr(hdr
->addr1
))
1116 ieee80211_sta_reset_conn_monitor(sdata
);
1119 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data
*sdata
)
1121 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1123 if (!(ifmgd
->flags
& (IEEE80211_STA_BEACON_POLL
|
1124 IEEE80211_STA_CONNECTION_POLL
)))
1127 ifmgd
->flags
&= ~(IEEE80211_STA_CONNECTION_POLL
|
1128 IEEE80211_STA_BEACON_POLL
);
1129 mutex_lock(&sdata
->local
->iflist_mtx
);
1130 ieee80211_recalc_ps(sdata
->local
, -1);
1131 mutex_unlock(&sdata
->local
->iflist_mtx
);
1133 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
1137 * We've received a probe response, but are not sure whether
1138 * we have or will be receiving any beacons or data, so let's
1139 * schedule the timers again, just in case.
1141 ieee80211_sta_reset_beacon_monitor(sdata
);
1143 mod_timer(&ifmgd
->conn_mon_timer
,
1144 round_jiffies_up(jiffies
+
1145 IEEE80211_CONNECTION_IDLE_TIME
));
1148 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data
*sdata
,
1149 struct ieee80211_hdr
*hdr
, bool ack
)
1151 if (!ieee80211_is_data(hdr
->frame_control
))
1155 ieee80211_sta_reset_conn_monitor(sdata
);
1157 if (ieee80211_is_nullfunc(hdr
->frame_control
) &&
1158 sdata
->u
.mgd
.probe_send_count
> 0) {
1160 sdata
->u
.mgd
.probe_send_count
= 0;
1162 sdata
->u
.mgd
.nullfunc_failed
= true;
1163 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
1167 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data
*sdata
)
1169 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1171 u8
*dst
= ifmgd
->associated
->bssid
;
1172 u8 unicast_limit
= max(1, max_probe_tries
- 3);
1175 * Try sending broadcast probe requests for the last three
1176 * probe requests after the first ones failed since some
1177 * buggy APs only support broadcast probe requests.
1179 if (ifmgd
->probe_send_count
>= unicast_limit
)
1183 * When the hardware reports an accurate Tx ACK status, it's
1184 * better to send a nullfunc frame instead of a probe request,
1185 * as it will kick us off the AP quickly if we aren't associated
1186 * anymore. The timeout will be reset if the frame is ACKed by
1189 if (sdata
->local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) {
1190 ifmgd
->nullfunc_failed
= false;
1191 ieee80211_send_nullfunc(sdata
->local
, sdata
, 0);
1193 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
1194 ieee80211_send_probe_req(sdata
, dst
, ssid
+ 2, ssid
[1], NULL
, 0);
1197 ifmgd
->probe_send_count
++;
1198 ifmgd
->probe_timeout
= jiffies
+ msecs_to_jiffies(probe_wait_ms
);
1199 run_again(ifmgd
, ifmgd
->probe_timeout
);
1202 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data
*sdata
,
1205 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1206 bool already
= false;
1208 if (!ieee80211_sdata_running(sdata
))
1211 if (sdata
->local
->scanning
)
1214 if (sdata
->local
->tmp_channel
)
1217 mutex_lock(&ifmgd
->mtx
);
1219 if (!ifmgd
->associated
)
1222 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1223 if (beacon
&& net_ratelimit())
1224 printk(KERN_DEBUG
"%s: detected beacon loss from AP "
1225 "- sending probe request\n", sdata
->name
);
1229 * The driver/our work has already reported this event or the
1230 * connection monitoring has kicked in and we have already sent
1231 * a probe request. Or maybe the AP died and the driver keeps
1232 * reporting until we disassociate...
1234 * In either case we have to ignore the current call to this
1235 * function (except for setting the correct probe reason bit)
1236 * because otherwise we would reset the timer every time and
1237 * never check whether we received a probe response!
1239 if (ifmgd
->flags
& (IEEE80211_STA_BEACON_POLL
|
1240 IEEE80211_STA_CONNECTION_POLL
))
1244 ifmgd
->flags
|= IEEE80211_STA_BEACON_POLL
;
1246 ifmgd
->flags
|= IEEE80211_STA_CONNECTION_POLL
;
1251 mutex_lock(&sdata
->local
->iflist_mtx
);
1252 ieee80211_recalc_ps(sdata
->local
, -1);
1253 mutex_unlock(&sdata
->local
->iflist_mtx
);
1255 ifmgd
->probe_send_count
= 0;
1256 ieee80211_mgd_probe_ap_send(sdata
);
1258 mutex_unlock(&ifmgd
->mtx
);
1261 struct sk_buff
*ieee80211_ap_probereq_get(struct ieee80211_hw
*hw
,
1262 struct ieee80211_vif
*vif
)
1264 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1265 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1266 struct sk_buff
*skb
;
1269 if (WARN_ON(sdata
->vif
.type
!= NL80211_IFTYPE_STATION
))
1272 ASSERT_MGD_MTX(ifmgd
);
1274 if (!ifmgd
->associated
)
1277 ssid
= ieee80211_bss_get_ie(ifmgd
->associated
, WLAN_EID_SSID
);
1278 skb
= ieee80211_build_probe_req(sdata
, ifmgd
->associated
->bssid
,
1279 ssid
+ 2, ssid
[1], NULL
, 0);
1283 EXPORT_SYMBOL(ieee80211_ap_probereq_get
);
1285 static void __ieee80211_connection_loss(struct ieee80211_sub_if_data
*sdata
)
1287 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1288 struct ieee80211_local
*local
= sdata
->local
;
1291 mutex_lock(&ifmgd
->mtx
);
1292 if (!ifmgd
->associated
) {
1293 mutex_unlock(&ifmgd
->mtx
);
1297 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
1299 printk(KERN_DEBUG
"%s: Connection to AP %pM lost.\n",
1300 sdata
->name
, bssid
);
1302 ieee80211_set_disassoc(sdata
, true, true);
1303 mutex_unlock(&ifmgd
->mtx
);
1305 mutex_lock(&local
->mtx
);
1306 ieee80211_recalc_idle(local
);
1307 mutex_unlock(&local
->mtx
);
1309 * must be outside lock due to cfg80211,
1310 * but that's not a problem.
1312 ieee80211_send_deauth_disassoc(sdata
, bssid
,
1313 IEEE80211_STYPE_DEAUTH
,
1314 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
1318 void ieee80211_beacon_connection_loss_work(struct work_struct
*work
)
1320 struct ieee80211_sub_if_data
*sdata
=
1321 container_of(work
, struct ieee80211_sub_if_data
,
1322 u
.mgd
.beacon_connection_loss_work
);
1324 if (sdata
->local
->hw
.flags
& IEEE80211_HW_CONNECTION_MONITOR
)
1325 __ieee80211_connection_loss(sdata
);
1327 ieee80211_mgd_probe_ap(sdata
, true);
1330 void ieee80211_beacon_loss(struct ieee80211_vif
*vif
)
1332 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1333 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
1335 trace_api_beacon_loss(sdata
);
1337 WARN_ON(hw
->flags
& IEEE80211_HW_CONNECTION_MONITOR
);
1338 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
1340 EXPORT_SYMBOL(ieee80211_beacon_loss
);
1342 void ieee80211_connection_loss(struct ieee80211_vif
*vif
)
1344 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
1345 struct ieee80211_hw
*hw
= &sdata
->local
->hw
;
1347 trace_api_connection_loss(sdata
);
1349 WARN_ON(!(hw
->flags
& IEEE80211_HW_CONNECTION_MONITOR
));
1350 ieee80211_queue_work(hw
, &sdata
->u
.mgd
.beacon_connection_loss_work
);
1352 EXPORT_SYMBOL(ieee80211_connection_loss
);
1355 static enum rx_mgmt_action __must_check
1356 ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data
*sdata
,
1357 struct ieee80211_mgmt
*mgmt
, size_t len
)
1359 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1360 const u8
*bssid
= NULL
;
1364 return RX_MGMT_NONE
;
1366 ASSERT_MGD_MTX(ifmgd
);
1368 bssid
= ifmgd
->associated
->bssid
;
1370 reason_code
= le16_to_cpu(mgmt
->u
.deauth
.reason_code
);
1372 printk(KERN_DEBUG
"%s: deauthenticated from %pM (Reason: %u)\n",
1373 sdata
->name
, bssid
, reason_code
);
1375 ieee80211_set_disassoc(sdata
, true, false);
1376 mutex_lock(&sdata
->local
->mtx
);
1377 ieee80211_recalc_idle(sdata
->local
);
1378 mutex_unlock(&sdata
->local
->mtx
);
1380 return RX_MGMT_CFG80211_DEAUTH
;
1384 static enum rx_mgmt_action __must_check
1385 ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data
*sdata
,
1386 struct ieee80211_mgmt
*mgmt
, size_t len
)
1388 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1392 return RX_MGMT_NONE
;
1394 ASSERT_MGD_MTX(ifmgd
);
1396 if (WARN_ON(!ifmgd
->associated
))
1397 return RX_MGMT_NONE
;
1399 if (WARN_ON(memcmp(ifmgd
->associated
->bssid
, mgmt
->sa
, ETH_ALEN
)))
1400 return RX_MGMT_NONE
;
1402 reason_code
= le16_to_cpu(mgmt
->u
.disassoc
.reason_code
);
1404 printk(KERN_DEBUG
"%s: disassociated from %pM (Reason: %u)\n",
1405 sdata
->name
, mgmt
->sa
, reason_code
);
1407 ieee80211_set_disassoc(sdata
, true, false);
1408 mutex_lock(&sdata
->local
->mtx
);
1409 ieee80211_recalc_idle(sdata
->local
);
1410 mutex_unlock(&sdata
->local
->mtx
);
1411 return RX_MGMT_CFG80211_DISASSOC
;
1415 static bool ieee80211_assoc_success(struct ieee80211_work
*wk
,
1416 struct ieee80211_mgmt
*mgmt
, size_t len
)
1418 struct ieee80211_sub_if_data
*sdata
= wk
->sdata
;
1419 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1420 struct ieee80211_local
*local
= sdata
->local
;
1421 struct ieee80211_supported_band
*sband
;
1422 struct sta_info
*sta
;
1423 struct cfg80211_bss
*cbss
= wk
->assoc
.bss
;
1425 u32 rates
, basic_rates
;
1426 u16 capab_info
, aid
;
1427 struct ieee802_11_elems elems
;
1428 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1431 bool have_higher_than_11mbit
= false;
1432 u16 ap_ht_cap_flags
;
1434 /* AssocResp and ReassocResp have identical structure */
1436 aid
= le16_to_cpu(mgmt
->u
.assoc_resp
.aid
);
1437 capab_info
= le16_to_cpu(mgmt
->u
.assoc_resp
.capab_info
);
1439 if ((aid
& (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1440 printk(KERN_DEBUG
"%s: invalid aid value %d; bits 15:14 not "
1441 "set\n", sdata
->name
, aid
);
1442 aid
&= ~(BIT(15) | BIT(14));
1444 pos
= mgmt
->u
.assoc_resp
.variable
;
1445 ieee802_11_parse_elems(pos
, len
- (pos
- (u8
*) mgmt
), &elems
);
1447 if (!elems
.supp_rates
) {
1448 printk(KERN_DEBUG
"%s: no SuppRates element in AssocResp\n",
1455 sta
= sta_info_alloc(sdata
, cbss
->bssid
, GFP_KERNEL
);
1457 printk(KERN_DEBUG
"%s: failed to alloc STA entry for"
1458 " the AP\n", sdata
->name
);
1462 set_sta_flags(sta
, WLAN_STA_AUTH
| WLAN_STA_ASSOC
|
1464 if (!(ifmgd
->flags
& IEEE80211_STA_CONTROL_PORT
))
1465 set_sta_flags(sta
, WLAN_STA_AUTHORIZED
);
1469 sband
= local
->hw
.wiphy
->bands
[wk
->chan
->band
];
1471 for (i
= 0; i
< elems
.supp_rates_len
; i
++) {
1472 int rate
= (elems
.supp_rates
[i
] & 0x7f) * 5;
1473 bool is_basic
= !!(elems
.supp_rates
[i
] & 0x80);
1476 have_higher_than_11mbit
= true;
1478 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1479 if (sband
->bitrates
[j
].bitrate
== rate
) {
1482 basic_rates
|= BIT(j
);
1488 for (i
= 0; i
< elems
.ext_supp_rates_len
; i
++) {
1489 int rate
= (elems
.ext_supp_rates
[i
] & 0x7f) * 5;
1490 bool is_basic
= !!(elems
.ext_supp_rates
[i
] & 0x80);
1493 have_higher_than_11mbit
= true;
1495 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
1496 if (sband
->bitrates
[j
].bitrate
== rate
) {
1499 basic_rates
|= BIT(j
);
1505 sta
->sta
.supp_rates
[wk
->chan
->band
] = rates
;
1506 sdata
->vif
.bss_conf
.basic_rates
= basic_rates
;
1508 /* cf. IEEE 802.11 9.2.12 */
1509 if (wk
->chan
->band
== IEEE80211_BAND_2GHZ
&&
1510 have_higher_than_11mbit
)
1511 sdata
->flags
|= IEEE80211_SDATA_OPERATING_GMODE
;
1513 sdata
->flags
&= ~IEEE80211_SDATA_OPERATING_GMODE
;
1515 if (elems
.ht_cap_elem
&& !(ifmgd
->flags
& IEEE80211_STA_DISABLE_11N
))
1516 ieee80211_ht_cap_ie_to_sta_ht_cap(sband
,
1517 elems
.ht_cap_elem
, &sta
->sta
.ht_cap
);
1519 ap_ht_cap_flags
= sta
->sta
.ht_cap
.cap
;
1521 rate_control_rate_init(sta
);
1523 if (ifmgd
->flags
& IEEE80211_STA_MFP_ENABLED
)
1524 set_sta_flags(sta
, WLAN_STA_MFP
);
1526 if (elems
.wmm_param
)
1527 set_sta_flags(sta
, WLAN_STA_WME
);
1529 err
= sta_info_insert(sta
);
1532 printk(KERN_DEBUG
"%s: failed to insert STA entry for"
1533 " the AP (error %d)\n", sdata
->name
, err
);
1538 * Always handle WMM once after association regardless
1539 * of the first value the AP uses. Setting -1 here has
1540 * that effect because the AP values is an unsigned
1543 ifmgd
->wmm_last_param_set
= -1;
1545 if (elems
.wmm_param
)
1546 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
1547 elems
.wmm_param_len
);
1549 ieee80211_set_wmm_default(sdata
);
1551 local
->oper_channel
= wk
->chan
;
1553 if (elems
.ht_info_elem
&& elems
.wmm_param
&&
1554 (sdata
->local
->hw
.queues
>= 4) &&
1555 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_11N
))
1556 changed
|= ieee80211_enable_ht(sdata
, elems
.ht_info_elem
,
1557 cbss
->bssid
, ap_ht_cap_flags
);
1559 /* set AID and assoc capability,
1560 * ieee80211_set_associated() will tell the driver */
1561 bss_conf
->aid
= aid
;
1562 bss_conf
->assoc_capability
= capab_info
;
1563 ieee80211_set_associated(sdata
, cbss
, changed
);
1566 * If we're using 4-addr mode, let the AP know that we're
1567 * doing so, so that it can create the STA VLAN on its side
1569 if (ifmgd
->use_4addr
)
1570 ieee80211_send_4addr_nullfunc(local
, sdata
);
1573 * Start timer to probe the connection to the AP now.
1574 * Also start the timer that will detect beacon loss.
1576 ieee80211_sta_rx_notify(sdata
, (struct ieee80211_hdr
*)mgmt
);
1577 ieee80211_sta_reset_beacon_monitor(sdata
);
1583 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data
*sdata
,
1584 struct ieee80211_mgmt
*mgmt
,
1586 struct ieee80211_rx_status
*rx_status
,
1587 struct ieee802_11_elems
*elems
,
1590 struct ieee80211_local
*local
= sdata
->local
;
1592 struct ieee80211_bss
*bss
;
1593 struct ieee80211_channel
*channel
;
1594 bool need_ps
= false;
1596 if (sdata
->u
.mgd
.associated
) {
1597 bss
= (void *)sdata
->u
.mgd
.associated
->priv
;
1598 /* not previously set so we may need to recalc */
1599 need_ps
= !bss
->dtim_period
;
1602 if (elems
->ds_params
&& elems
->ds_params_len
== 1)
1603 freq
= ieee80211_channel_to_frequency(elems
->ds_params
[0],
1606 freq
= rx_status
->freq
;
1608 channel
= ieee80211_get_channel(local
->hw
.wiphy
, freq
);
1610 if (!channel
|| channel
->flags
& IEEE80211_CHAN_DISABLED
)
1613 bss
= ieee80211_bss_info_update(local
, rx_status
, mgmt
, len
, elems
,
1616 ieee80211_rx_bss_put(local
, bss
);
1618 if (!sdata
->u
.mgd
.associated
)
1622 mutex_lock(&local
->iflist_mtx
);
1623 ieee80211_recalc_ps(local
, -1);
1624 mutex_unlock(&local
->iflist_mtx
);
1627 if (elems
->ch_switch_elem
&& (elems
->ch_switch_elem_len
== 3) &&
1628 (memcmp(mgmt
->bssid
, sdata
->u
.mgd
.associated
->bssid
,
1630 struct ieee80211_channel_sw_ie
*sw_elem
=
1631 (struct ieee80211_channel_sw_ie
*)elems
->ch_switch_elem
;
1632 ieee80211_sta_process_chanswitch(sdata
, sw_elem
,
1633 bss
, rx_status
->mactime
);
1638 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data
*sdata
,
1639 struct sk_buff
*skb
)
1641 struct ieee80211_mgmt
*mgmt
= (void *)skb
->data
;
1642 struct ieee80211_if_managed
*ifmgd
;
1643 struct ieee80211_rx_status
*rx_status
= (void *) skb
->cb
;
1644 size_t baselen
, len
= skb
->len
;
1645 struct ieee802_11_elems elems
;
1647 ifmgd
= &sdata
->u
.mgd
;
1649 ASSERT_MGD_MTX(ifmgd
);
1651 if (memcmp(mgmt
->da
, sdata
->vif
.addr
, ETH_ALEN
))
1652 return; /* ignore ProbeResp to foreign address */
1654 baselen
= (u8
*) mgmt
->u
.probe_resp
.variable
- (u8
*) mgmt
;
1658 ieee802_11_parse_elems(mgmt
->u
.probe_resp
.variable
, len
- baselen
,
1661 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
, false);
1663 if (ifmgd
->associated
&&
1664 memcmp(mgmt
->bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
) == 0)
1665 ieee80211_reset_ap_probe(sdata
);
1669 * This is the canonical list of information elements we care about,
1670 * the filter code also gives us all changes to the Microsoft OUI
1671 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1673 * We implement beacon filtering in software since that means we can
1674 * avoid processing the frame here and in cfg80211, and userspace
1675 * will not be able to tell whether the hardware supports it or not.
1677 * XXX: This list needs to be dynamic -- userspace needs to be able to
1678 * add items it requires. It also needs to be able to tell us to
1679 * look out for other vendor IEs.
1681 static const u64 care_about_ies
=
1682 (1ULL << WLAN_EID_COUNTRY
) |
1683 (1ULL << WLAN_EID_ERP_INFO
) |
1684 (1ULL << WLAN_EID_CHANNEL_SWITCH
) |
1685 (1ULL << WLAN_EID_PWR_CONSTRAINT
) |
1686 (1ULL << WLAN_EID_HT_CAPABILITY
) |
1687 (1ULL << WLAN_EID_HT_INFORMATION
);
1689 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data
*sdata
,
1690 struct ieee80211_mgmt
*mgmt
,
1692 struct ieee80211_rx_status
*rx_status
)
1694 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1695 struct ieee80211_bss_conf
*bss_conf
= &sdata
->vif
.bss_conf
;
1697 struct ieee802_11_elems elems
;
1698 struct ieee80211_local
*local
= sdata
->local
;
1700 bool erp_valid
, directed_tim
= false;
1705 ASSERT_MGD_MTX(ifmgd
);
1707 /* Process beacon from the current BSS */
1708 baselen
= (u8
*) mgmt
->u
.beacon
.variable
- (u8
*) mgmt
;
1712 if (rx_status
->freq
!= local
->hw
.conf
.channel
->center_freq
)
1716 * We might have received a number of frames, among them a
1717 * disassoc frame and a beacon...
1719 if (!ifmgd
->associated
)
1722 bssid
= ifmgd
->associated
->bssid
;
1725 * And in theory even frames from a different AP we were just
1726 * associated to a split-second ago!
1728 if (memcmp(bssid
, mgmt
->bssid
, ETH_ALEN
) != 0)
1731 /* Track average RSSI from the Beacon frames of the current AP */
1732 ifmgd
->last_beacon_signal
= rx_status
->signal
;
1733 if (ifmgd
->flags
& IEEE80211_STA_RESET_SIGNAL_AVE
) {
1734 ifmgd
->flags
&= ~IEEE80211_STA_RESET_SIGNAL_AVE
;
1735 ifmgd
->ave_beacon_signal
= rx_status
->signal
* 16;
1736 ifmgd
->last_cqm_event_signal
= 0;
1737 ifmgd
->count_beacon_signal
= 1;
1739 ifmgd
->ave_beacon_signal
=
1740 (IEEE80211_SIGNAL_AVE_WEIGHT
* rx_status
->signal
* 16 +
1741 (16 - IEEE80211_SIGNAL_AVE_WEIGHT
) *
1742 ifmgd
->ave_beacon_signal
) / 16;
1743 ifmgd
->count_beacon_signal
++;
1745 if (bss_conf
->cqm_rssi_thold
&&
1746 ifmgd
->count_beacon_signal
>= IEEE80211_SIGNAL_AVE_MIN_COUNT
&&
1747 !(local
->hw
.flags
& IEEE80211_HW_SUPPORTS_CQM_RSSI
)) {
1748 int sig
= ifmgd
->ave_beacon_signal
/ 16;
1749 int last_event
= ifmgd
->last_cqm_event_signal
;
1750 int thold
= bss_conf
->cqm_rssi_thold
;
1751 int hyst
= bss_conf
->cqm_rssi_hyst
;
1753 (last_event
== 0 || sig
< last_event
- hyst
)) {
1754 ifmgd
->last_cqm_event_signal
= sig
;
1755 ieee80211_cqm_rssi_notify(
1757 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
,
1759 } else if (sig
> thold
&&
1760 (last_event
== 0 || sig
> last_event
+ hyst
)) {
1761 ifmgd
->last_cqm_event_signal
= sig
;
1762 ieee80211_cqm_rssi_notify(
1764 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
,
1769 if (ifmgd
->flags
& IEEE80211_STA_BEACON_POLL
) {
1770 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1771 if (net_ratelimit()) {
1772 printk(KERN_DEBUG
"%s: cancelling probereq poll due "
1773 "to a received beacon\n", sdata
->name
);
1776 ifmgd
->flags
&= ~IEEE80211_STA_BEACON_POLL
;
1777 mutex_lock(&local
->iflist_mtx
);
1778 ieee80211_recalc_ps(local
, -1);
1779 mutex_unlock(&local
->iflist_mtx
);
1783 * Push the beacon loss detection into the future since
1784 * we are processing a beacon from the AP just now.
1786 ieee80211_sta_reset_beacon_monitor(sdata
);
1788 ncrc
= crc32_be(0, (void *)&mgmt
->u
.beacon
.beacon_int
, 4);
1789 ncrc
= ieee802_11_parse_elems_crc(mgmt
->u
.beacon
.variable
,
1790 len
- baselen
, &elems
,
1791 care_about_ies
, ncrc
);
1793 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
)
1794 directed_tim
= ieee80211_check_tim(elems
.tim
, elems
.tim_len
,
1797 if (ncrc
!= ifmgd
->beacon_crc
|| !ifmgd
->beacon_crc_valid
) {
1798 ieee80211_rx_bss_info(sdata
, mgmt
, len
, rx_status
, &elems
,
1801 ieee80211_sta_wmm_params(local
, sdata
, elems
.wmm_param
,
1802 elems
.wmm_param_len
);
1805 if (local
->hw
.flags
& IEEE80211_HW_PS_NULLFUNC_STACK
) {
1807 if (local
->hw
.conf
.dynamic_ps_timeout
> 0) {
1808 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_PS
;
1809 ieee80211_hw_config(local
,
1810 IEEE80211_CONF_CHANGE_PS
);
1811 ieee80211_send_nullfunc(local
, sdata
, 0);
1813 local
->pspolling
= true;
1816 * Here is assumed that the driver will be
1817 * able to send ps-poll frame and receive a
1818 * response even though power save mode is
1819 * enabled, but some drivers might require
1820 * to disable power save here. This needs
1821 * to be investigated.
1823 ieee80211_send_pspoll(local
, sdata
);
1828 if (ncrc
== ifmgd
->beacon_crc
&& ifmgd
->beacon_crc_valid
)
1830 ifmgd
->beacon_crc
= ncrc
;
1831 ifmgd
->beacon_crc_valid
= true;
1833 if (elems
.erp_info
&& elems
.erp_info_len
>= 1) {
1835 erp_value
= elems
.erp_info
[0];
1839 changed
|= ieee80211_handle_bss_capability(sdata
,
1840 le16_to_cpu(mgmt
->u
.beacon
.capab_info
),
1841 erp_valid
, erp_value
);
1844 if (elems
.ht_cap_elem
&& elems
.ht_info_elem
&& elems
.wmm_param
&&
1845 !(ifmgd
->flags
& IEEE80211_STA_DISABLE_11N
)) {
1846 struct sta_info
*sta
;
1847 struct ieee80211_supported_band
*sband
;
1848 u16 ap_ht_cap_flags
;
1852 sta
= sta_info_get(sdata
, bssid
);
1853 if (WARN_ON(!sta
)) {
1858 sband
= local
->hw
.wiphy
->bands
[local
->hw
.conf
.channel
->band
];
1860 ieee80211_ht_cap_ie_to_sta_ht_cap(sband
,
1861 elems
.ht_cap_elem
, &sta
->sta
.ht_cap
);
1863 ap_ht_cap_flags
= sta
->sta
.ht_cap
.cap
;
1867 changed
|= ieee80211_enable_ht(sdata
, elems
.ht_info_elem
,
1868 bssid
, ap_ht_cap_flags
);
1871 /* Note: country IE parsing is done for us by cfg80211 */
1872 if (elems
.country_elem
) {
1873 /* TODO: IBSS also needs this */
1874 if (elems
.pwr_constr_elem
)
1875 ieee80211_handle_pwr_constr(sdata
,
1876 le16_to_cpu(mgmt
->u
.probe_resp
.capab_info
),
1877 elems
.pwr_constr_elem
,
1878 elems
.pwr_constr_elem_len
);
1881 ieee80211_bss_info_change_notify(sdata
, changed
);
1884 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data
*sdata
,
1885 struct sk_buff
*skb
)
1887 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1888 struct ieee80211_rx_status
*rx_status
;
1889 struct ieee80211_mgmt
*mgmt
;
1890 enum rx_mgmt_action rma
= RX_MGMT_NONE
;
1893 rx_status
= (struct ieee80211_rx_status
*) skb
->cb
;
1894 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1895 fc
= le16_to_cpu(mgmt
->frame_control
);
1897 mutex_lock(&ifmgd
->mtx
);
1899 if (ifmgd
->associated
&&
1900 memcmp(ifmgd
->associated
->bssid
, mgmt
->bssid
, ETH_ALEN
) == 0) {
1901 switch (fc
& IEEE80211_FCTL_STYPE
) {
1902 case IEEE80211_STYPE_BEACON
:
1903 ieee80211_rx_mgmt_beacon(sdata
, mgmt
, skb
->len
,
1906 case IEEE80211_STYPE_PROBE_RESP
:
1907 ieee80211_rx_mgmt_probe_resp(sdata
, skb
);
1909 case IEEE80211_STYPE_DEAUTH
:
1910 rma
= ieee80211_rx_mgmt_deauth(sdata
, mgmt
, skb
->len
);
1912 case IEEE80211_STYPE_DISASSOC
:
1913 rma
= ieee80211_rx_mgmt_disassoc(sdata
, mgmt
, skb
->len
);
1915 case IEEE80211_STYPE_ACTION
:
1916 switch (mgmt
->u
.action
.category
) {
1917 case WLAN_CATEGORY_SPECTRUM_MGMT
:
1918 ieee80211_sta_process_chanswitch(sdata
,
1919 &mgmt
->u
.action
.u
.chan_switch
.sw_elem
,
1920 (void *)ifmgd
->associated
->priv
,
1921 rx_status
->mactime
);
1925 mutex_unlock(&ifmgd
->mtx
);
1931 case RX_MGMT_CFG80211_DEAUTH
:
1932 cfg80211_send_deauth(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
1934 case RX_MGMT_CFG80211_DISASSOC
:
1935 cfg80211_send_disassoc(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
1938 WARN(1, "unexpected: %d", rma
);
1943 mutex_unlock(&ifmgd
->mtx
);
1945 if (skb
->len
>= 24 + 2 /* mgmt + deauth reason */ &&
1946 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_DEAUTH
) {
1947 struct ieee80211_local
*local
= sdata
->local
;
1948 struct ieee80211_work
*wk
;
1950 mutex_lock(&local
->mtx
);
1951 list_for_each_entry(wk
, &local
->work_list
, list
) {
1952 if (wk
->sdata
!= sdata
)
1955 if (wk
->type
!= IEEE80211_WORK_ASSOC
&&
1956 wk
->type
!= IEEE80211_WORK_ASSOC_BEACON_WAIT
)
1959 if (memcmp(mgmt
->bssid
, wk
->filter_ta
, ETH_ALEN
))
1961 if (memcmp(mgmt
->sa
, wk
->filter_ta
, ETH_ALEN
))
1965 * Printing the message only here means we can't
1966 * spuriously print it, but it also means that it
1967 * won't be printed when the frame comes in before
1968 * we even tried to associate or in similar cases.
1970 * Ultimately, I suspect cfg80211 should print the
1974 "%s: deauthenticated from %pM (Reason: %u)\n",
1975 sdata
->name
, mgmt
->bssid
,
1976 le16_to_cpu(mgmt
->u
.deauth
.reason_code
));
1978 list_del_rcu(&wk
->list
);
1982 mutex_unlock(&local
->mtx
);
1984 cfg80211_send_deauth(sdata
->dev
, (u8
*)mgmt
, skb
->len
);
1988 static void ieee80211_sta_timer(unsigned long data
)
1990 struct ieee80211_sub_if_data
*sdata
=
1991 (struct ieee80211_sub_if_data
*) data
;
1992 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
1993 struct ieee80211_local
*local
= sdata
->local
;
1995 if (local
->quiescing
) {
1996 set_bit(TMR_RUNNING_TIMER
, &ifmgd
->timers_running
);
2000 ieee80211_queue_work(&local
->hw
, &sdata
->work
);
2003 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data
*sdata
,
2006 struct ieee80211_local
*local
= sdata
->local
;
2007 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2009 ifmgd
->flags
&= ~(IEEE80211_STA_CONNECTION_POLL
|
2010 IEEE80211_STA_BEACON_POLL
);
2012 ieee80211_set_disassoc(sdata
, true, true);
2013 mutex_unlock(&ifmgd
->mtx
);
2014 mutex_lock(&local
->mtx
);
2015 ieee80211_recalc_idle(local
);
2016 mutex_unlock(&local
->mtx
);
2018 * must be outside lock due to cfg80211,
2019 * but that's not a problem.
2021 ieee80211_send_deauth_disassoc(sdata
, bssid
,
2022 IEEE80211_STYPE_DEAUTH
,
2023 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
,
2025 mutex_lock(&ifmgd
->mtx
);
2028 void ieee80211_sta_work(struct ieee80211_sub_if_data
*sdata
)
2030 struct ieee80211_local
*local
= sdata
->local
;
2031 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2033 /* then process the rest of the work */
2034 mutex_lock(&ifmgd
->mtx
);
2036 if (ifmgd
->flags
& (IEEE80211_STA_BEACON_POLL
|
2037 IEEE80211_STA_CONNECTION_POLL
) &&
2038 ifmgd
->associated
) {
2042 memcpy(bssid
, ifmgd
->associated
->bssid
, ETH_ALEN
);
2044 if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
)
2045 max_tries
= max_nullfunc_tries
;
2047 max_tries
= max_probe_tries
;
2049 /* ACK received for nullfunc probing frame */
2050 if (!ifmgd
->probe_send_count
)
2051 ieee80211_reset_ap_probe(sdata
);
2052 else if (ifmgd
->nullfunc_failed
) {
2053 if (ifmgd
->probe_send_count
< max_tries
) {
2054 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2055 wiphy_debug(local
->hw
.wiphy
,
2056 "%s: No ack for nullfunc frame to"
2057 " AP %pM, try %d/%i\n",
2059 ifmgd
->probe_send_count
, max_tries
);
2061 ieee80211_mgd_probe_ap_send(sdata
);
2063 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2064 wiphy_debug(local
->hw
.wiphy
,
2065 "%s: No ack for nullfunc frame to"
2066 " AP %pM, disconnecting.\n",
2067 sdata
->name
, bssid
);
2069 ieee80211_sta_connection_lost(sdata
, bssid
);
2071 } else if (time_is_after_jiffies(ifmgd
->probe_timeout
))
2072 run_again(ifmgd
, ifmgd
->probe_timeout
);
2073 else if (local
->hw
.flags
& IEEE80211_HW_REPORTS_TX_ACK_STATUS
) {
2074 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2075 wiphy_debug(local
->hw
.wiphy
,
2076 "%s: Failed to send nullfunc to AP %pM"
2077 " after %dms, disconnecting.\n",
2079 bssid
, probe_wait_ms
);
2081 ieee80211_sta_connection_lost(sdata
, bssid
);
2082 } else if (ifmgd
->probe_send_count
< max_tries
) {
2083 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2084 wiphy_debug(local
->hw
.wiphy
,
2085 "%s: No probe response from AP %pM"
2086 " after %dms, try %d/%i\n",
2088 bssid
, probe_wait_ms
,
2089 ifmgd
->probe_send_count
, max_tries
);
2091 ieee80211_mgd_probe_ap_send(sdata
);
2094 * We actually lost the connection ... or did we?
2097 wiphy_debug(local
->hw
.wiphy
,
2098 "%s: No probe response from AP %pM"
2099 " after %dms, disconnecting.\n",
2101 bssid
, probe_wait_ms
);
2103 ieee80211_sta_connection_lost(sdata
, bssid
);
2107 mutex_unlock(&ifmgd
->mtx
);
2110 static void ieee80211_sta_bcn_mon_timer(unsigned long data
)
2112 struct ieee80211_sub_if_data
*sdata
=
2113 (struct ieee80211_sub_if_data
*) data
;
2114 struct ieee80211_local
*local
= sdata
->local
;
2116 if (local
->quiescing
)
2119 ieee80211_queue_work(&sdata
->local
->hw
,
2120 &sdata
->u
.mgd
.beacon_connection_loss_work
);
2123 static void ieee80211_sta_conn_mon_timer(unsigned long data
)
2125 struct ieee80211_sub_if_data
*sdata
=
2126 (struct ieee80211_sub_if_data
*) data
;
2127 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2128 struct ieee80211_local
*local
= sdata
->local
;
2130 if (local
->quiescing
)
2133 ieee80211_queue_work(&local
->hw
, &ifmgd
->monitor_work
);
2136 static void ieee80211_sta_monitor_work(struct work_struct
*work
)
2138 struct ieee80211_sub_if_data
*sdata
=
2139 container_of(work
, struct ieee80211_sub_if_data
,
2140 u
.mgd
.monitor_work
);
2142 ieee80211_mgd_probe_ap(sdata
, false);
2145 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data
*sdata
)
2147 if (sdata
->vif
.type
== NL80211_IFTYPE_STATION
) {
2148 sdata
->u
.mgd
.flags
&= ~(IEEE80211_STA_BEACON_POLL
|
2149 IEEE80211_STA_CONNECTION_POLL
);
2151 /* let's probe the connection once */
2152 ieee80211_queue_work(&sdata
->local
->hw
,
2153 &sdata
->u
.mgd
.monitor_work
);
2154 /* and do all the other regular work too */
2155 ieee80211_queue_work(&sdata
->local
->hw
, &sdata
->work
);
2160 void ieee80211_sta_quiesce(struct ieee80211_sub_if_data
*sdata
)
2162 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2165 * we need to use atomic bitops for the running bits
2166 * only because both timers might fire at the same
2167 * time -- the code here is properly synchronised.
2170 cancel_work_sync(&ifmgd
->request_smps_work
);
2172 cancel_work_sync(&ifmgd
->beacon_connection_loss_work
);
2173 if (del_timer_sync(&ifmgd
->timer
))
2174 set_bit(TMR_RUNNING_TIMER
, &ifmgd
->timers_running
);
2176 cancel_work_sync(&ifmgd
->chswitch_work
);
2177 if (del_timer_sync(&ifmgd
->chswitch_timer
))
2178 set_bit(TMR_RUNNING_CHANSW
, &ifmgd
->timers_running
);
2180 cancel_work_sync(&ifmgd
->monitor_work
);
2181 /* these will just be re-established on connection */
2182 del_timer_sync(&ifmgd
->conn_mon_timer
);
2183 del_timer_sync(&ifmgd
->bcn_mon_timer
);
2186 void ieee80211_sta_restart(struct ieee80211_sub_if_data
*sdata
)
2188 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2190 if (test_and_clear_bit(TMR_RUNNING_TIMER
, &ifmgd
->timers_running
))
2191 add_timer(&ifmgd
->timer
);
2192 if (test_and_clear_bit(TMR_RUNNING_CHANSW
, &ifmgd
->timers_running
))
2193 add_timer(&ifmgd
->chswitch_timer
);
2194 ieee80211_sta_reset_beacon_monitor(sdata
);
2195 ieee80211_restart_sta_timer(sdata
);
2199 /* interface setup */
2200 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data
*sdata
)
2202 struct ieee80211_if_managed
*ifmgd
;
2204 ifmgd
= &sdata
->u
.mgd
;
2205 INIT_WORK(&ifmgd
->monitor_work
, ieee80211_sta_monitor_work
);
2206 INIT_WORK(&ifmgd
->chswitch_work
, ieee80211_chswitch_work
);
2207 INIT_WORK(&ifmgd
->beacon_connection_loss_work
,
2208 ieee80211_beacon_connection_loss_work
);
2209 INIT_WORK(&ifmgd
->request_smps_work
, ieee80211_request_smps_work
);
2210 setup_timer(&ifmgd
->timer
, ieee80211_sta_timer
,
2211 (unsigned long) sdata
);
2212 setup_timer(&ifmgd
->bcn_mon_timer
, ieee80211_sta_bcn_mon_timer
,
2213 (unsigned long) sdata
);
2214 setup_timer(&ifmgd
->conn_mon_timer
, ieee80211_sta_conn_mon_timer
,
2215 (unsigned long) sdata
);
2216 setup_timer(&ifmgd
->chswitch_timer
, ieee80211_chswitch_timer
,
2217 (unsigned long) sdata
);
2221 mutex_init(&ifmgd
->mtx
);
2223 if (sdata
->local
->hw
.flags
& IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
)
2224 ifmgd
->req_smps
= IEEE80211_SMPS_AUTOMATIC
;
2226 ifmgd
->req_smps
= IEEE80211_SMPS_OFF
;
2229 /* scan finished notification */
2230 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local
*local
)
2232 struct ieee80211_sub_if_data
*sdata
= local
->scan_sdata
;
2234 /* Restart STA timers */
2236 list_for_each_entry_rcu(sdata
, &local
->interfaces
, list
)
2237 ieee80211_restart_sta_timer(sdata
);
2241 int ieee80211_max_network_latency(struct notifier_block
*nb
,
2242 unsigned long data
, void *dummy
)
2244 s32 latency_usec
= (s32
) data
;
2245 struct ieee80211_local
*local
=
2246 container_of(nb
, struct ieee80211_local
,
2247 network_latency_notifier
);
2249 mutex_lock(&local
->iflist_mtx
);
2250 ieee80211_recalc_ps(local
, latency_usec
);
2251 mutex_unlock(&local
->iflist_mtx
);
2257 static enum work_done_result
2258 ieee80211_probe_auth_done(struct ieee80211_work
*wk
,
2259 struct sk_buff
*skb
)
2262 cfg80211_send_auth_timeout(wk
->sdata
->dev
, wk
->filter_ta
);
2263 return WORK_DONE_DESTROY
;
2266 if (wk
->type
== IEEE80211_WORK_AUTH
) {
2267 cfg80211_send_rx_auth(wk
->sdata
->dev
, skb
->data
, skb
->len
);
2268 return WORK_DONE_DESTROY
;
2271 mutex_lock(&wk
->sdata
->u
.mgd
.mtx
);
2272 ieee80211_rx_mgmt_probe_resp(wk
->sdata
, skb
);
2273 mutex_unlock(&wk
->sdata
->u
.mgd
.mtx
);
2275 wk
->type
= IEEE80211_WORK_AUTH
;
2276 wk
->probe_auth
.tries
= 0;
2277 return WORK_DONE_REQUEUE
;
2280 int ieee80211_mgd_auth(struct ieee80211_sub_if_data
*sdata
,
2281 struct cfg80211_auth_request
*req
)
2284 struct ieee80211_work
*wk
;
2287 if (req
->local_state_change
)
2288 return 0; /* no need to update mac80211 state */
2290 switch (req
->auth_type
) {
2291 case NL80211_AUTHTYPE_OPEN_SYSTEM
:
2292 auth_alg
= WLAN_AUTH_OPEN
;
2294 case NL80211_AUTHTYPE_SHARED_KEY
:
2295 if (IS_ERR(sdata
->local
->wep_tx_tfm
))
2297 auth_alg
= WLAN_AUTH_SHARED_KEY
;
2299 case NL80211_AUTHTYPE_FT
:
2300 auth_alg
= WLAN_AUTH_FT
;
2302 case NL80211_AUTHTYPE_NETWORK_EAP
:
2303 auth_alg
= WLAN_AUTH_LEAP
;
2309 wk
= kzalloc(sizeof(*wk
) + req
->ie_len
, GFP_KERNEL
);
2313 memcpy(wk
->filter_ta
, req
->bss
->bssid
, ETH_ALEN
);
2315 if (req
->ie
&& req
->ie_len
) {
2316 memcpy(wk
->ie
, req
->ie
, req
->ie_len
);
2317 wk
->ie_len
= req
->ie_len
;
2320 if (req
->key
&& req
->key_len
) {
2321 wk
->probe_auth
.key_len
= req
->key_len
;
2322 wk
->probe_auth
.key_idx
= req
->key_idx
;
2323 memcpy(wk
->probe_auth
.key
, req
->key
, req
->key_len
);
2326 ssid
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
2327 memcpy(wk
->probe_auth
.ssid
, ssid
+ 2, ssid
[1]);
2328 wk
->probe_auth
.ssid_len
= ssid
[1];
2330 wk
->probe_auth
.algorithm
= auth_alg
;
2331 wk
->probe_auth
.privacy
= req
->bss
->capability
& WLAN_CAPABILITY_PRIVACY
;
2333 /* if we already have a probe, don't probe again */
2334 if (req
->bss
->proberesp_ies
)
2335 wk
->type
= IEEE80211_WORK_AUTH
;
2337 wk
->type
= IEEE80211_WORK_DIRECT_PROBE
;
2338 wk
->chan
= req
->bss
->channel
;
2339 wk
->chan_type
= NL80211_CHAN_NO_HT
;
2341 wk
->done
= ieee80211_probe_auth_done
;
2343 ieee80211_add_work(wk
);
2347 static enum work_done_result
ieee80211_assoc_done(struct ieee80211_work
*wk
,
2348 struct sk_buff
*skb
)
2350 struct ieee80211_mgmt
*mgmt
;
2351 struct ieee80211_rx_status
*rx_status
;
2352 struct ieee802_11_elems elems
;
2356 cfg80211_send_assoc_timeout(wk
->sdata
->dev
, wk
->filter_ta
);
2357 return WORK_DONE_DESTROY
;
2360 if (wk
->type
== IEEE80211_WORK_ASSOC_BEACON_WAIT
) {
2361 mutex_lock(&wk
->sdata
->u
.mgd
.mtx
);
2362 rx_status
= (void *) skb
->cb
;
2363 ieee802_11_parse_elems(skb
->data
+ 24 + 12, skb
->len
- 24 - 12, &elems
);
2364 ieee80211_rx_bss_info(wk
->sdata
, (void *)skb
->data
, skb
->len
, rx_status
,
2366 mutex_unlock(&wk
->sdata
->u
.mgd
.mtx
);
2368 wk
->type
= IEEE80211_WORK_ASSOC
;
2369 /* not really done yet */
2370 return WORK_DONE_REQUEUE
;
2373 mgmt
= (void *)skb
->data
;
2374 status
= le16_to_cpu(mgmt
->u
.assoc_resp
.status_code
);
2376 if (status
== WLAN_STATUS_SUCCESS
) {
2377 mutex_lock(&wk
->sdata
->u
.mgd
.mtx
);
2378 if (!ieee80211_assoc_success(wk
, mgmt
, skb
->len
)) {
2379 mutex_unlock(&wk
->sdata
->u
.mgd
.mtx
);
2380 /* oops -- internal error -- send timeout for now */
2381 cfg80211_send_assoc_timeout(wk
->sdata
->dev
,
2383 return WORK_DONE_DESTROY
;
2386 mutex_unlock(&wk
->sdata
->u
.mgd
.mtx
);
2389 cfg80211_send_rx_assoc(wk
->sdata
->dev
, skb
->data
, skb
->len
);
2390 return WORK_DONE_DESTROY
;
2393 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data
*sdata
,
2394 struct cfg80211_assoc_request
*req
)
2396 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2397 struct ieee80211_bss
*bss
= (void *)req
->bss
->priv
;
2398 struct ieee80211_work
*wk
;
2402 mutex_lock(&ifmgd
->mtx
);
2403 if (ifmgd
->associated
) {
2404 if (!req
->prev_bssid
||
2405 memcmp(req
->prev_bssid
, ifmgd
->associated
->bssid
,
2408 * We are already associated and the request was not a
2409 * reassociation request from the current BSS, so
2412 mutex_unlock(&ifmgd
->mtx
);
2416 /* Trying to reassociate - clear previous association state */
2417 ieee80211_set_disassoc(sdata
, true, false);
2419 mutex_unlock(&ifmgd
->mtx
);
2421 wk
= kzalloc(sizeof(*wk
) + req
->ie_len
, GFP_KERNEL
);
2425 ifmgd
->flags
&= ~IEEE80211_STA_DISABLE_11N
;
2426 ifmgd
->flags
&= ~IEEE80211_STA_NULLFUNC_ACKED
;
2428 ifmgd
->beacon_crc_valid
= false;
2430 for (i
= 0; i
< req
->crypto
.n_ciphers_pairwise
; i
++)
2431 if (req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP40
||
2432 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_TKIP
||
2433 req
->crypto
.ciphers_pairwise
[i
] == WLAN_CIPHER_SUITE_WEP104
)
2434 ifmgd
->flags
|= IEEE80211_STA_DISABLE_11N
;
2437 if (req
->ie
&& req
->ie_len
) {
2438 memcpy(wk
->ie
, req
->ie
, req
->ie_len
);
2439 wk
->ie_len
= req
->ie_len
;
2443 wk
->assoc
.bss
= req
->bss
;
2445 memcpy(wk
->filter_ta
, req
->bss
->bssid
, ETH_ALEN
);
2447 /* new association always uses requested smps mode */
2448 if (ifmgd
->req_smps
== IEEE80211_SMPS_AUTOMATIC
) {
2449 if (ifmgd
->powersave
)
2450 ifmgd
->ap_smps
= IEEE80211_SMPS_DYNAMIC
;
2452 ifmgd
->ap_smps
= IEEE80211_SMPS_OFF
;
2454 ifmgd
->ap_smps
= ifmgd
->req_smps
;
2456 wk
->assoc
.smps
= ifmgd
->ap_smps
;
2458 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2459 * We still associate in non-HT mode (11a/b/g) if any one of these
2460 * ciphers is configured as pairwise.
2461 * We can set this to true for non-11n hardware, that'll be checked
2462 * separately along with the peer capabilities.
2464 wk
->assoc
.use_11n
= !(ifmgd
->flags
& IEEE80211_STA_DISABLE_11N
);
2465 wk
->assoc
.capability
= req
->bss
->capability
;
2466 wk
->assoc
.wmm_used
= bss
->wmm_used
;
2467 wk
->assoc
.supp_rates
= bss
->supp_rates
;
2468 wk
->assoc
.supp_rates_len
= bss
->supp_rates_len
;
2469 wk
->assoc
.ht_information_ie
=
2470 ieee80211_bss_get_ie(req
->bss
, WLAN_EID_HT_INFORMATION
);
2472 if (bss
->wmm_used
&& bss
->uapsd_supported
&&
2473 (sdata
->local
->hw
.flags
& IEEE80211_HW_SUPPORTS_UAPSD
)) {
2474 wk
->assoc
.uapsd_used
= true;
2475 ifmgd
->flags
|= IEEE80211_STA_UAPSD_ENABLED
;
2477 wk
->assoc
.uapsd_used
= false;
2478 ifmgd
->flags
&= ~IEEE80211_STA_UAPSD_ENABLED
;
2481 ssid
= ieee80211_bss_get_ie(req
->bss
, WLAN_EID_SSID
);
2482 memcpy(wk
->assoc
.ssid
, ssid
+ 2, ssid
[1]);
2483 wk
->assoc
.ssid_len
= ssid
[1];
2485 if (req
->prev_bssid
)
2486 memcpy(wk
->assoc
.prev_bssid
, req
->prev_bssid
, ETH_ALEN
);
2488 wk
->chan
= req
->bss
->channel
;
2489 wk
->chan_type
= NL80211_CHAN_NO_HT
;
2491 wk
->done
= ieee80211_assoc_done
;
2492 if (!bss
->dtim_period
&&
2493 sdata
->local
->hw
.flags
& IEEE80211_HW_NEED_DTIM_PERIOD
)
2494 wk
->type
= IEEE80211_WORK_ASSOC_BEACON_WAIT
;
2496 wk
->type
= IEEE80211_WORK_ASSOC
;
2499 ifmgd
->mfp
= IEEE80211_MFP_REQUIRED
;
2500 ifmgd
->flags
|= IEEE80211_STA_MFP_ENABLED
;
2502 ifmgd
->mfp
= IEEE80211_MFP_DISABLED
;
2503 ifmgd
->flags
&= ~IEEE80211_STA_MFP_ENABLED
;
2506 if (req
->crypto
.control_port
)
2507 ifmgd
->flags
|= IEEE80211_STA_CONTROL_PORT
;
2509 ifmgd
->flags
&= ~IEEE80211_STA_CONTROL_PORT
;
2511 sdata
->control_port_protocol
= req
->crypto
.control_port_ethertype
;
2512 sdata
->control_port_no_encrypt
= req
->crypto
.control_port_no_encrypt
;
2514 ieee80211_add_work(wk
);
2518 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data
*sdata
,
2519 struct cfg80211_deauth_request
*req
,
2522 struct ieee80211_local
*local
= sdata
->local
;
2523 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2524 struct ieee80211_work
*wk
;
2526 bool assoc_bss
= false;
2528 mutex_lock(&ifmgd
->mtx
);
2530 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
2531 if (ifmgd
->associated
== req
->bss
) {
2532 ieee80211_set_disassoc(sdata
, false, true);
2533 mutex_unlock(&ifmgd
->mtx
);
2536 bool not_auth_yet
= false;
2538 mutex_unlock(&ifmgd
->mtx
);
2540 mutex_lock(&local
->mtx
);
2541 list_for_each_entry(wk
, &local
->work_list
, list
) {
2542 if (wk
->sdata
!= sdata
)
2545 if (wk
->type
!= IEEE80211_WORK_DIRECT_PROBE
&&
2546 wk
->type
!= IEEE80211_WORK_AUTH
&&
2547 wk
->type
!= IEEE80211_WORK_ASSOC
&&
2548 wk
->type
!= IEEE80211_WORK_ASSOC_BEACON_WAIT
)
2551 if (memcmp(req
->bss
->bssid
, wk
->filter_ta
, ETH_ALEN
))
2554 not_auth_yet
= wk
->type
== IEEE80211_WORK_DIRECT_PROBE
;
2555 list_del_rcu(&wk
->list
);
2559 mutex_unlock(&local
->mtx
);
2562 * If somebody requests authentication and we haven't
2563 * sent out an auth frame yet there's no need to send
2564 * out a deauth frame either. If the state was PROBE,
2565 * then this is the case. If it's AUTH we have sent a
2566 * frame, and if it's IDLE we have completed the auth
2570 __cfg80211_auth_canceled(sdata
->dev
, bssid
);
2575 printk(KERN_DEBUG
"%s: deauthenticating from %pM by local choice (reason=%d)\n",
2576 sdata
->name
, bssid
, req
->reason_code
);
2578 ieee80211_send_deauth_disassoc(sdata
, bssid
, IEEE80211_STYPE_DEAUTH
,
2579 req
->reason_code
, cookie
,
2580 !req
->local_state_change
);
2582 sta_info_destroy_addr(sdata
, bssid
);
2584 mutex_lock(&sdata
->local
->mtx
);
2585 ieee80211_recalc_idle(sdata
->local
);
2586 mutex_unlock(&sdata
->local
->mtx
);
2591 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data
*sdata
,
2592 struct cfg80211_disassoc_request
*req
,
2595 struct ieee80211_if_managed
*ifmgd
= &sdata
->u
.mgd
;
2598 mutex_lock(&ifmgd
->mtx
);
2601 * cfg80211 should catch this ... but it's racy since
2602 * we can receive a disassoc frame, process it, hand it
2603 * to cfg80211 while that's in a locked section already
2604 * trying to tell us that the user wants to disconnect.
2606 if (ifmgd
->associated
!= req
->bss
) {
2607 mutex_unlock(&ifmgd
->mtx
);
2611 printk(KERN_DEBUG
"%s: disassociating from %pM by local choice (reason=%d)\n",
2612 sdata
->name
, req
->bss
->bssid
, req
->reason_code
);
2614 memcpy(bssid
, req
->bss
->bssid
, ETH_ALEN
);
2615 ieee80211_set_disassoc(sdata
, false, true);
2617 mutex_unlock(&ifmgd
->mtx
);
2619 ieee80211_send_deauth_disassoc(sdata
, req
->bss
->bssid
,
2620 IEEE80211_STYPE_DISASSOC
, req
->reason_code
,
2621 cookie
, !req
->local_state_change
);
2622 sta_info_destroy_addr(sdata
, bssid
);
2624 mutex_lock(&sdata
->local
->mtx
);
2625 ieee80211_recalc_idle(sdata
->local
);
2626 mutex_unlock(&sdata
->local
->mtx
);
2631 void ieee80211_cqm_rssi_notify(struct ieee80211_vif
*vif
,
2632 enum nl80211_cqm_rssi_threshold_event rssi_event
,
2635 struct ieee80211_sub_if_data
*sdata
= vif_to_sdata(vif
);
2637 trace_api_cqm_rssi_notify(sdata
, rssi_event
);
2639 cfg80211_cqm_rssi_notify(sdata
->dev
, rssi_event
, gfp
);
2641 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify
);