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 #define IEEE80211_MAX_PROBE_TRIES 5
34 * beacon loss detection timeout
35 * XXX: should depend on beacon interval
37 #define IEEE80211_BEACON_LOSS_TIME (2 * HZ)
39 * Time the connection can be idle before we probe
40 * it to see if we can still talk to the AP.
42 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
44 * Time we wait for a probe response after sending
45 * a probe request because of beacon loss or for
46 * checking the connection still works.
48 #define IEEE80211_PROBE_WAIT (HZ / 2)
51 * Weight given to the latest Beacon frame when calculating average signal
52 * strength for Beacon frames received in the current BSS. This must be
55 #define IEEE80211_SIGNAL_AVE_WEIGHT 3
57 #define TMR_RUNNING_TIMER 0
58 #define TMR_RUNNING_CHANSW 1
61 * All cfg80211 functions have to be called outside a locked
62 * section so that they can acquire a lock themselves... This
63 * is much simpler than queuing up things in cfg80211, but we
64 * do need some indirection for that here.
67 /* no action required */
70 /* caller must call cfg80211_send_rx_auth() */
71 RX_MGMT_CFG80211_AUTH,
73 /* caller must call cfg80211_send_rx_assoc() */
74 RX_MGMT_CFG80211_ASSOC,
76 /* caller must call cfg80211_send_deauth() */
77 RX_MGMT_CFG80211_DEAUTH,
79 /* caller must call cfg80211_send_disassoc() */
80 RX_MGMT_CFG80211_DISASSOC,
82 /* caller must tell cfg80211 about internal error */
83 RX_MGMT_CFG80211_ASSOC_ERROR,
87 static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
89 WARN_ON(!mutex_is_locked(&ifmgd->mtx));
93 * We can have multiple work items (and connection probing)
94 * scheduling this timer, but we need to take care to only
95 * reschedule it when it should fire _earlier_ than it was
96 * asked for before, or if it's not pending right now. This
97 * function ensures that. Note that it then is required to
98 * run this function for all timeouts after the first one
99 * has happened -- the work that runs from this timer will
102 static void run_again(struct ieee80211_if_managed *ifmgd,
103 unsigned long timeout)
105 ASSERT_MGD_MTX(ifmgd);
107 if (!timer_pending(&ifmgd->timer) ||
108 time_before(timeout, ifmgd->timer.expires))
109 mod_timer(&ifmgd->timer, timeout);
112 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
114 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
117 mod_timer(&sdata->u.mgd.bcn_mon_timer,
118 round_jiffies_up(jiffies + IEEE80211_BEACON_LOSS_TIME));
121 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
123 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
125 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
128 mod_timer(&sdata->u.mgd.conn_mon_timer,
129 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
131 ifmgd->probe_send_count = 0;
134 static int ecw2cw(int ecw)
136 return (1 << ecw) - 1;
140 * ieee80211_enable_ht should be called only after the operating band
141 * has been determined as ht configuration depends on the hw's
142 * HT abilities for a specific band.
144 static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
145 struct ieee80211_ht_info *hti,
146 const u8 *bssid, u16 ap_ht_cap_flags)
148 struct ieee80211_local *local = sdata->local;
149 struct ieee80211_supported_band *sband;
150 struct sta_info *sta;
153 bool enable_ht = true;
154 enum nl80211_channel_type prev_chantype;
155 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
157 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
159 prev_chantype = sdata->vif.bss_conf.channel_type;
161 /* HT is not supported */
162 if (!sband->ht_cap.ht_supported)
165 /* check that channel matches the right operating channel */
166 if (local->hw.conf.channel->center_freq !=
167 ieee80211_channel_to_frequency(hti->control_chan))
171 channel_type = NL80211_CHAN_HT20;
173 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
174 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
175 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
176 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
177 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
178 if (!(local->hw.conf.channel->flags &
179 IEEE80211_CHAN_NO_HT40PLUS))
180 channel_type = NL80211_CHAN_HT40PLUS;
182 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
183 if (!(local->hw.conf.channel->flags &
184 IEEE80211_CHAN_NO_HT40MINUS))
185 channel_type = NL80211_CHAN_HT40MINUS;
191 if (local->tmp_channel)
192 local->tmp_channel_type = channel_type;
194 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
195 /* can only fail due to HT40+/- mismatch */
196 channel_type = NL80211_CHAN_HT20;
197 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
200 /* channel_type change automatically detected */
201 ieee80211_hw_config(local, 0);
203 if (prev_chantype != channel_type) {
205 sta = sta_info_get(sdata, bssid);
207 rate_control_rate_update(local, sband, sta,
208 IEEE80211_RC_HT_CHANGED,
213 ht_opmode = le16_to_cpu(hti->operation_mode);
215 /* if bss configuration changed store the new one */
216 if (sdata->ht_opmode_valid != enable_ht ||
217 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
218 prev_chantype != channel_type) {
219 changed |= BSS_CHANGED_HT;
220 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
221 sdata->ht_opmode_valid = enable_ht;
227 /* frame sending functions */
229 static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
230 const u8 *bssid, u16 stype, u16 reason,
231 void *cookie, bool send_frame)
233 struct ieee80211_local *local = sdata->local;
234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
236 struct ieee80211_mgmt *mgmt;
238 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
240 printk(KERN_DEBUG "%s: failed to allocate buffer for "
241 "deauth/disassoc frame\n", sdata->name);
244 skb_reserve(skb, local->hw.extra_tx_headroom);
246 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
248 memcpy(mgmt->da, bssid, ETH_ALEN);
249 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
250 memcpy(mgmt->bssid, bssid, ETH_ALEN);
251 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
253 /* u.deauth.reason_code == u.disassoc.reason_code */
254 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
256 if (stype == IEEE80211_STYPE_DEAUTH)
258 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
260 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
263 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
265 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
266 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
267 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
270 ieee80211_tx_skb(sdata, skb);
275 void ieee80211_send_pspoll(struct ieee80211_local *local,
276 struct ieee80211_sub_if_data *sdata)
278 struct ieee80211_pspoll *pspoll;
281 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
285 pspoll = (struct ieee80211_pspoll *) skb->data;
286 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
288 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
289 ieee80211_tx_skb(sdata, skb);
292 void ieee80211_send_nullfunc(struct ieee80211_local *local,
293 struct ieee80211_sub_if_data *sdata,
297 struct ieee80211_hdr_3addr *nullfunc;
299 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
303 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
305 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
307 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
308 ieee80211_tx_skb(sdata, skb);
311 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
312 struct ieee80211_sub_if_data *sdata)
315 struct ieee80211_hdr *nullfunc;
318 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
321 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
323 printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr "
324 "nullfunc frame\n", sdata->name);
327 skb_reserve(skb, local->hw.extra_tx_headroom);
329 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
330 memset(nullfunc, 0, 30);
331 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
332 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
333 nullfunc->frame_control = fc;
334 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
335 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
336 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
337 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
339 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
340 ieee80211_tx_skb(sdata, skb);
343 /* spectrum management related things */
344 static void ieee80211_chswitch_work(struct work_struct *work)
346 struct ieee80211_sub_if_data *sdata =
347 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
348 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
350 if (!ieee80211_sdata_running(sdata))
353 mutex_lock(&ifmgd->mtx);
354 if (!ifmgd->associated)
357 sdata->local->oper_channel = sdata->local->csa_channel;
358 if (!sdata->local->ops->channel_switch) {
359 /* call "hw_config" only if doing sw channel switch */
360 ieee80211_hw_config(sdata->local,
361 IEEE80211_CONF_CHANGE_CHANNEL);
364 /* XXX: shouldn't really modify cfg80211-owned data! */
365 ifmgd->associated->channel = sdata->local->oper_channel;
367 ieee80211_wake_queues_by_reason(&sdata->local->hw,
368 IEEE80211_QUEUE_STOP_REASON_CSA);
370 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
371 mutex_unlock(&ifmgd->mtx);
374 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
376 struct ieee80211_sub_if_data *sdata;
377 struct ieee80211_if_managed *ifmgd;
379 sdata = vif_to_sdata(vif);
380 ifmgd = &sdata->u.mgd;
382 trace_api_chswitch_done(sdata, success);
385 * If the channel switch was not successful, stay
386 * around on the old channel. We currently lack
387 * good handling of this situation, possibly we
388 * should just drop the association.
390 sdata->local->csa_channel = sdata->local->oper_channel;
393 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
395 EXPORT_SYMBOL(ieee80211_chswitch_done);
397 static void ieee80211_chswitch_timer(unsigned long data)
399 struct ieee80211_sub_if_data *sdata =
400 (struct ieee80211_sub_if_data *) data;
401 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
403 if (sdata->local->quiescing) {
404 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
408 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
411 void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
412 struct ieee80211_channel_sw_ie *sw_elem,
413 struct ieee80211_bss *bss,
416 struct cfg80211_bss *cbss =
417 container_of((void *)bss, struct cfg80211_bss, priv);
418 struct ieee80211_channel *new_ch;
419 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
420 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
422 ASSERT_MGD_MTX(ifmgd);
424 if (!ifmgd->associated)
427 if (sdata->local->scanning)
430 /* Disregard subsequent beacons if we are already running a timer
433 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
436 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
437 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
440 sdata->local->csa_channel = new_ch;
442 if (sdata->local->ops->channel_switch) {
443 /* use driver's channel switch callback */
444 struct ieee80211_channel_switch ch_switch;
445 memset(&ch_switch, 0, sizeof(ch_switch));
446 ch_switch.timestamp = timestamp;
448 ch_switch.block_tx = true;
449 ieee80211_stop_queues_by_reason(&sdata->local->hw,
450 IEEE80211_QUEUE_STOP_REASON_CSA);
452 ch_switch.channel = new_ch;
453 ch_switch.count = sw_elem->count;
454 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
455 drv_channel_switch(sdata->local, &ch_switch);
459 /* channel switch handled in software */
460 if (sw_elem->count <= 1) {
461 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
464 ieee80211_stop_queues_by_reason(&sdata->local->hw,
465 IEEE80211_QUEUE_STOP_REASON_CSA);
466 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
467 mod_timer(&ifmgd->chswitch_timer,
469 msecs_to_jiffies(sw_elem->count *
470 cbss->beacon_interval));
474 static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
475 u16 capab_info, u8 *pwr_constr_elem,
476 u8 pwr_constr_elem_len)
478 struct ieee80211_conf *conf = &sdata->local->hw.conf;
480 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
483 /* Power constraint IE length should be 1 octet */
484 if (pwr_constr_elem_len != 1)
487 if ((*pwr_constr_elem <= conf->channel->max_power) &&
488 (*pwr_constr_elem != sdata->local->power_constr_level)) {
489 sdata->local->power_constr_level = *pwr_constr_elem;
490 ieee80211_hw_config(sdata->local, 0);
494 void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
496 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
497 struct ieee80211_local *local = sdata->local;
498 struct ieee80211_conf *conf = &local->hw.conf;
500 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
501 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
502 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
504 local->disable_dynamic_ps = false;
505 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
507 EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
509 void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
511 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
512 struct ieee80211_local *local = sdata->local;
513 struct ieee80211_conf *conf = &local->hw.conf;
515 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
516 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
517 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
519 local->disable_dynamic_ps = true;
520 conf->dynamic_ps_timeout = 0;
521 del_timer_sync(&local->dynamic_ps_timer);
522 ieee80211_queue_work(&local->hw,
523 &local->dynamic_ps_enable_work);
525 EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
528 static void ieee80211_enable_ps(struct ieee80211_local *local,
529 struct ieee80211_sub_if_data *sdata)
531 struct ieee80211_conf *conf = &local->hw.conf;
534 * If we are scanning right now then the parameters will
535 * take effect when scan finishes.
540 if (conf->dynamic_ps_timeout > 0 &&
541 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
542 mod_timer(&local->dynamic_ps_timer, jiffies +
543 msecs_to_jiffies(conf->dynamic_ps_timeout));
545 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
546 ieee80211_send_nullfunc(local, sdata, 1);
548 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
549 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
552 conf->flags |= IEEE80211_CONF_PS;
553 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
557 static void ieee80211_change_ps(struct ieee80211_local *local)
559 struct ieee80211_conf *conf = &local->hw.conf;
561 if (local->ps_sdata) {
562 ieee80211_enable_ps(local, local->ps_sdata);
563 } else if (conf->flags & IEEE80211_CONF_PS) {
564 conf->flags &= ~IEEE80211_CONF_PS;
565 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
566 del_timer_sync(&local->dynamic_ps_timer);
567 cancel_work_sync(&local->dynamic_ps_enable_work);
571 /* need to hold RTNL or interface lock */
572 void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
574 struct ieee80211_sub_if_data *sdata, *found = NULL;
578 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
579 local->ps_sdata = NULL;
583 if (!list_empty(&local->work_list)) {
584 local->ps_sdata = NULL;
588 list_for_each_entry(sdata, &local->interfaces, list) {
589 if (!ieee80211_sdata_running(sdata))
591 if (sdata->vif.type != NL80211_IFTYPE_STATION)
597 if (count == 1 && found->u.mgd.powersave &&
598 found->u.mgd.associated &&
599 found->u.mgd.associated->beacon_ies &&
600 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
601 IEEE80211_STA_CONNECTION_POLL))) {
602 struct ieee80211_conf *conf = &local->hw.conf;
606 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
608 beaconint_us = ieee80211_tu_to_usec(
609 found->vif.bss_conf.beacon_int);
611 timeout = local->dynamic_ps_forced_timeout;
614 * Go to full PSM if the user configures a very low
615 * latency requirement.
616 * The 2 second value is there for compatibility until
617 * the PM_QOS_NETWORK_LATENCY is configured with real
620 if (latency > 1900000000 && latency != 2000000000)
625 local->dynamic_ps_user_timeout = timeout;
626 if (!local->disable_dynamic_ps)
627 conf->dynamic_ps_timeout =
628 local->dynamic_ps_user_timeout;
630 if (beaconint_us > latency) {
631 local->ps_sdata = NULL;
633 struct ieee80211_bss *bss;
637 bss = (void *)found->u.mgd.associated->priv;
638 dtimper = bss->dtim_period;
640 /* If the TIM IE is invalid, pretend the value is 1 */
643 else if (dtimper > 1)
644 maxslp = min_t(int, dtimper,
645 latency / beaconint_us);
647 local->hw.conf.max_sleep_period = maxslp;
648 local->hw.conf.ps_dtim_period = dtimper;
649 local->ps_sdata = found;
652 local->ps_sdata = NULL;
656 ieee80211_change_ps(local);
659 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
661 struct ieee80211_local *local =
662 container_of(work, struct ieee80211_local,
663 dynamic_ps_disable_work);
665 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
666 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
667 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
670 ieee80211_wake_queues_by_reason(&local->hw,
671 IEEE80211_QUEUE_STOP_REASON_PS);
674 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
676 struct ieee80211_local *local =
677 container_of(work, struct ieee80211_local,
678 dynamic_ps_enable_work);
679 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
680 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
682 /* can only happen when PS was just disabled anyway */
686 if (local->hw.conf.flags & IEEE80211_CONF_PS)
689 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
690 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)))
691 ieee80211_send_nullfunc(local, sdata, 1);
693 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
694 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
695 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
696 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
697 local->hw.conf.flags |= IEEE80211_CONF_PS;
698 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
702 void ieee80211_dynamic_ps_timer(unsigned long data)
704 struct ieee80211_local *local = (void *) data;
706 if (local->quiescing || local->suspended)
709 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
713 static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
714 struct ieee80211_sub_if_data *sdata,
715 u8 *wmm_param, size_t wmm_param_len)
717 struct ieee80211_tx_queue_params params;
718 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
721 u8 *pos, uapsd_queues = 0;
723 if (!local->ops->conf_tx)
726 if (local->hw.queues < 4)
732 if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
735 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
736 uapsd_queues = local->uapsd_queues;
738 count = wmm_param[6] & 0x0f;
739 if (count == ifmgd->wmm_last_param_set)
741 ifmgd->wmm_last_param_set = count;
744 left = wmm_param_len - 8;
746 memset(¶ms, 0, sizeof(params));
749 for (; left >= 4; left -= 4, pos += 4) {
750 int aci = (pos[0] >> 5) & 0x03;
751 int acm = (pos[0] >> 4) & 0x01;
759 local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
760 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
766 local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
767 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
773 local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
774 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
781 local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
782 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
787 params.aifs = pos[0] & 0x0f;
788 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
789 params.cw_min = ecw2cw(pos[1] & 0x0f);
790 params.txop = get_unaligned_le16(pos + 2);
791 params.uapsd = uapsd;
793 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
794 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
795 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
796 wiphy_name(local->hw.wiphy), queue, aci, acm,
797 params.aifs, params.cw_min, params.cw_max, params.txop,
800 if (drv_conf_tx(local, queue, ¶ms))
801 printk(KERN_DEBUG "%s: failed to set TX queue "
802 "parameters for queue %d\n",
803 wiphy_name(local->hw.wiphy), queue);
806 /* enable WMM or activate new settings */
807 sdata->vif.bss_conf.qos = true;
808 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
811 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
812 u16 capab, bool erp_valid, u8 erp)
814 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
817 bool use_short_preamble;
821 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
822 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
824 use_protection = false;
825 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
828 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
829 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
830 use_short_slot = true;
832 if (use_protection != bss_conf->use_cts_prot) {
833 bss_conf->use_cts_prot = use_protection;
834 changed |= BSS_CHANGED_ERP_CTS_PROT;
837 if (use_short_preamble != bss_conf->use_short_preamble) {
838 bss_conf->use_short_preamble = use_short_preamble;
839 changed |= BSS_CHANGED_ERP_PREAMBLE;
842 if (use_short_slot != bss_conf->use_short_slot) {
843 bss_conf->use_short_slot = use_short_slot;
844 changed |= BSS_CHANGED_ERP_SLOT;
850 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
851 struct cfg80211_bss *cbss,
852 u32 bss_info_changed)
854 struct ieee80211_bss *bss = (void *)cbss->priv;
855 struct ieee80211_local *local = sdata->local;
856 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
858 bss_info_changed |= BSS_CHANGED_ASSOC;
859 /* set timing information */
860 bss_conf->beacon_int = cbss->beacon_interval;
861 bss_conf->timestamp = cbss->tsf;
863 bss_info_changed |= BSS_CHANGED_BEACON_INT;
864 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
865 cbss->capability, bss->has_erp_value, bss->erp_value);
867 sdata->u.mgd.associated = cbss;
868 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
870 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
872 /* just to be sure */
873 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
874 IEEE80211_STA_BEACON_POLL);
877 * Always handle WMM once after association regardless
878 * of the first value the AP uses. Setting -1 here has
879 * that effect because the AP values is an unsigned
882 sdata->u.mgd.wmm_last_param_set = -1;
884 ieee80211_led_assoc(local, 1);
886 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
887 bss_conf->dtim_period = bss->dtim_period;
889 bss_conf->dtim_period = 0;
893 * For now just always ask the driver to update the basic rateset
894 * when we have associated, we aren't checking whether it actually
897 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
899 /* And the BSSID changed - we're associated now */
900 bss_info_changed |= BSS_CHANGED_BSSID;
902 /* Tell the driver to monitor connection quality (if supported) */
903 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
904 bss_conf->cqm_rssi_thold)
905 bss_info_changed |= BSS_CHANGED_CQM;
907 /* Enable ARP filtering */
908 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
909 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
910 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
913 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
915 mutex_lock(&local->iflist_mtx);
916 ieee80211_recalc_ps(local, -1);
917 ieee80211_recalc_smps(local, sdata);
918 mutex_unlock(&local->iflist_mtx);
920 netif_tx_start_all_queues(sdata->dev);
921 netif_carrier_on(sdata->dev);
924 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
927 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
928 struct ieee80211_local *local = sdata->local;
929 struct sta_info *sta;
930 u32 changed = 0, config_changed = 0;
933 ASSERT_MGD_MTX(ifmgd);
935 if (WARN_ON(!ifmgd->associated))
938 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
940 ifmgd->associated = NULL;
941 memset(ifmgd->bssid, 0, ETH_ALEN);
944 * we need to commit the associated = NULL change because the
945 * scan code uses that to determine whether this iface should
946 * go to/wake up from powersave or not -- and could otherwise
947 * wake the queues erroneously.
952 * Thus, we can only afterwards stop the queues -- to account
953 * for the case where another CPU is finishing a scan at this
954 * time -- we don't want the scan code to enable queues.
957 netif_tx_stop_all_queues(sdata->dev);
958 netif_carrier_off(sdata->dev);
960 mutex_lock(&local->sta_mtx);
961 sta = sta_info_get(sdata, bssid);
963 set_sta_flags(sta, WLAN_STA_BLOCK_BA);
964 ieee80211_sta_tear_down_BA_sessions(sta);
966 mutex_unlock(&local->sta_mtx);
968 changed |= ieee80211_reset_erp_info(sdata);
970 ieee80211_led_assoc(local, 0);
971 changed |= BSS_CHANGED_ASSOC;
972 sdata->vif.bss_conf.assoc = false;
974 ieee80211_set_wmm_default(sdata);
976 /* channel(_type) changes are handled by ieee80211_hw_config */
977 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
979 /* on the next assoc, re-program HT parameters */
980 sdata->ht_opmode_valid = false;
982 local->power_constr_level = 0;
984 del_timer_sync(&local->dynamic_ps_timer);
985 cancel_work_sync(&local->dynamic_ps_enable_work);
987 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
988 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
989 config_changed |= IEEE80211_CONF_CHANGE_PS;
992 ieee80211_hw_config(local, config_changed);
994 /* Disable ARP filtering */
995 if (sdata->vif.bss_conf.arp_filter_enabled) {
996 sdata->vif.bss_conf.arp_filter_enabled = false;
997 changed |= BSS_CHANGED_ARP_FILTER;
1000 /* The BSSID (not really interesting) and HT changed */
1001 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
1002 ieee80211_bss_info_change_notify(sdata, changed);
1005 sta_info_destroy_addr(sdata, bssid);
1008 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1009 struct ieee80211_hdr *hdr)
1012 * We can postpone the mgd.timer whenever receiving unicast frames
1013 * from AP because we know that the connection is working both ways
1014 * at that time. But multicast frames (and hence also beacons) must
1015 * be ignored here, because we need to trigger the timer during
1016 * data idle periods for sending the periodic probe request to the
1017 * AP we're connected to.
1019 if (is_multicast_ether_addr(hdr->addr1))
1022 ieee80211_sta_reset_conn_monitor(sdata);
1025 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1027 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1029 u8 *dst = ifmgd->associated->bssid;
1030 u8 unicast_limit = max(1, IEEE80211_MAX_PROBE_TRIES - 3);
1033 * Try sending broadcast probe requests for the last three
1034 * probe requests after the first ones failed since some
1035 * buggy APs only support broadcast probe requests.
1037 if (ifmgd->probe_send_count >= unicast_limit)
1040 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
1041 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0);
1043 ifmgd->probe_send_count++;
1044 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1045 run_again(ifmgd, ifmgd->probe_timeout);
1048 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1051 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1052 bool already = false;
1054 if (!ieee80211_sdata_running(sdata))
1057 if (sdata->local->scanning)
1060 if (sdata->local->tmp_channel)
1063 mutex_lock(&ifmgd->mtx);
1065 if (!ifmgd->associated)
1068 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1069 if (beacon && net_ratelimit())
1070 printk(KERN_DEBUG "%s: detected beacon loss from AP "
1071 "- sending probe request\n", sdata->name);
1075 * The driver/our work has already reported this event or the
1076 * connection monitoring has kicked in and we have already sent
1077 * a probe request. Or maybe the AP died and the driver keeps
1078 * reporting until we disassociate...
1080 * In either case we have to ignore the current call to this
1081 * function (except for setting the correct probe reason bit)
1082 * because otherwise we would reset the timer every time and
1083 * never check whether we received a probe response!
1085 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1086 IEEE80211_STA_CONNECTION_POLL))
1090 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1092 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1097 mutex_lock(&sdata->local->iflist_mtx);
1098 ieee80211_recalc_ps(sdata->local, -1);
1099 mutex_unlock(&sdata->local->iflist_mtx);
1101 ifmgd->probe_send_count = 0;
1102 ieee80211_mgd_probe_ap_send(sdata);
1104 mutex_unlock(&ifmgd->mtx);
1107 static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1109 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1110 struct ieee80211_local *local = sdata->local;
1113 mutex_lock(&ifmgd->mtx);
1114 if (!ifmgd->associated) {
1115 mutex_unlock(&ifmgd->mtx);
1119 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1121 printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid);
1123 ieee80211_set_disassoc(sdata, true);
1124 ieee80211_recalc_idle(local);
1125 mutex_unlock(&ifmgd->mtx);
1127 * must be outside lock due to cfg80211,
1128 * but that's not a problem.
1130 ieee80211_send_deauth_disassoc(sdata, bssid,
1131 IEEE80211_STYPE_DEAUTH,
1132 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
1136 void ieee80211_beacon_connection_loss_work(struct work_struct *work)
1138 struct ieee80211_sub_if_data *sdata =
1139 container_of(work, struct ieee80211_sub_if_data,
1140 u.mgd.beacon_connection_loss_work);
1142 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1143 __ieee80211_connection_loss(sdata);
1145 ieee80211_mgd_probe_ap(sdata, true);
1148 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1150 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1151 struct ieee80211_hw *hw = &sdata->local->hw;
1153 trace_api_beacon_loss(sdata);
1155 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
1156 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1158 EXPORT_SYMBOL(ieee80211_beacon_loss);
1160 void ieee80211_connection_loss(struct ieee80211_vif *vif)
1162 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1163 struct ieee80211_hw *hw = &sdata->local->hw;
1165 trace_api_connection_loss(sdata);
1167 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
1168 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
1170 EXPORT_SYMBOL(ieee80211_connection_loss);
1173 static enum rx_mgmt_action __must_check
1174 ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1175 struct ieee80211_mgmt *mgmt, size_t len)
1177 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1178 const u8 *bssid = NULL;
1182 return RX_MGMT_NONE;
1184 ASSERT_MGD_MTX(ifmgd);
1186 bssid = ifmgd->associated->bssid;
1188 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1190 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1191 sdata->name, bssid, reason_code);
1193 ieee80211_set_disassoc(sdata, true);
1194 ieee80211_recalc_idle(sdata->local);
1196 return RX_MGMT_CFG80211_DEAUTH;
1200 static enum rx_mgmt_action __must_check
1201 ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1202 struct ieee80211_mgmt *mgmt, size_t len)
1204 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1208 return RX_MGMT_NONE;
1210 ASSERT_MGD_MTX(ifmgd);
1212 if (WARN_ON(!ifmgd->associated))
1213 return RX_MGMT_NONE;
1215 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
1216 return RX_MGMT_NONE;
1218 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1220 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
1221 sdata->name, mgmt->sa, reason_code);
1223 ieee80211_set_disassoc(sdata, true);
1224 ieee80211_recalc_idle(sdata->local);
1225 return RX_MGMT_CFG80211_DISASSOC;
1229 static bool ieee80211_assoc_success(struct ieee80211_work *wk,
1230 struct ieee80211_mgmt *mgmt, size_t len)
1232 struct ieee80211_sub_if_data *sdata = wk->sdata;
1233 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1234 struct ieee80211_local *local = sdata->local;
1235 struct ieee80211_supported_band *sband;
1236 struct sta_info *sta;
1237 struct cfg80211_bss *cbss = wk->assoc.bss;
1239 u32 rates, basic_rates;
1240 u16 capab_info, aid;
1241 struct ieee802_11_elems elems;
1242 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1245 bool have_higher_than_11mbit = false;
1246 u16 ap_ht_cap_flags;
1248 /* AssocResp and ReassocResp have identical structure */
1250 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
1251 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1253 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
1254 printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
1255 "set\n", sdata->name, aid);
1256 aid &= ~(BIT(15) | BIT(14));
1258 pos = mgmt->u.assoc_resp.variable;
1259 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1261 if (!elems.supp_rates) {
1262 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1269 sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
1271 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1272 " the AP\n", sdata->name);
1276 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1278 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1279 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1283 sband = local->hw.wiphy->bands[wk->chan->band];
1285 for (i = 0; i < elems.supp_rates_len; i++) {
1286 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1287 bool is_basic = !!(elems.supp_rates[i] & 0x80);
1290 have_higher_than_11mbit = true;
1292 for (j = 0; j < sband->n_bitrates; j++) {
1293 if (sband->bitrates[j].bitrate == rate) {
1296 basic_rates |= BIT(j);
1302 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1303 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1304 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
1307 have_higher_than_11mbit = true;
1309 for (j = 0; j < sband->n_bitrates; j++) {
1310 if (sband->bitrates[j].bitrate == rate) {
1313 basic_rates |= BIT(j);
1319 sta->sta.supp_rates[wk->chan->band] = rates;
1320 sdata->vif.bss_conf.basic_rates = basic_rates;
1322 /* cf. IEEE 802.11 9.2.12 */
1323 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
1324 have_higher_than_11mbit)
1325 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1327 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1329 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1330 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1331 elems.ht_cap_elem, &sta->sta.ht_cap);
1333 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1335 rate_control_rate_init(sta);
1337 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
1338 set_sta_flags(sta, WLAN_STA_MFP);
1340 if (elems.wmm_param)
1341 set_sta_flags(sta, WLAN_STA_WME);
1343 err = sta_info_insert(sta);
1346 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1347 " the AP (error %d)\n", sdata->name, err);
1351 if (elems.wmm_param)
1352 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
1353 elems.wmm_param_len);
1355 ieee80211_set_wmm_default(sdata);
1357 local->oper_channel = wk->chan;
1359 if (elems.ht_info_elem && elems.wmm_param &&
1360 (sdata->local->hw.queues >= 4) &&
1361 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1362 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1363 cbss->bssid, ap_ht_cap_flags);
1365 /* set AID and assoc capability,
1366 * ieee80211_set_associated() will tell the driver */
1367 bss_conf->aid = aid;
1368 bss_conf->assoc_capability = capab_info;
1369 ieee80211_set_associated(sdata, cbss, changed);
1372 * If we're using 4-addr mode, let the AP know that we're
1373 * doing so, so that it can create the STA VLAN on its side
1375 if (ifmgd->use_4addr)
1376 ieee80211_send_4addr_nullfunc(local, sdata);
1379 * Start timer to probe the connection to the AP now.
1380 * Also start the timer that will detect beacon loss.
1382 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1383 ieee80211_sta_reset_beacon_monitor(sdata);
1389 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1390 struct ieee80211_mgmt *mgmt,
1392 struct ieee80211_rx_status *rx_status,
1393 struct ieee802_11_elems *elems,
1396 struct ieee80211_local *local = sdata->local;
1398 struct ieee80211_bss *bss;
1399 struct ieee80211_channel *channel;
1400 bool need_ps = false;
1402 if (sdata->u.mgd.associated) {
1403 bss = (void *)sdata->u.mgd.associated->priv;
1404 /* not previously set so we may need to recalc */
1405 need_ps = !bss->dtim_period;
1408 if (elems->ds_params && elems->ds_params_len == 1)
1409 freq = ieee80211_channel_to_frequency(elems->ds_params[0]);
1411 freq = rx_status->freq;
1413 channel = ieee80211_get_channel(local->hw.wiphy, freq);
1415 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1418 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
1421 ieee80211_rx_bss_put(local, bss);
1423 if (!sdata->u.mgd.associated)
1427 mutex_lock(&local->iflist_mtx);
1428 ieee80211_recalc_ps(local, -1);
1429 mutex_unlock(&local->iflist_mtx);
1432 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1433 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
1435 struct ieee80211_channel_sw_ie *sw_elem =
1436 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1437 ieee80211_sta_process_chanswitch(sdata, sw_elem,
1438 bss, rx_status->mactime);
1443 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1444 struct sk_buff *skb)
1446 struct ieee80211_mgmt *mgmt = (void *)skb->data;
1447 struct ieee80211_if_managed *ifmgd;
1448 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
1449 size_t baselen, len = skb->len;
1450 struct ieee802_11_elems elems;
1452 ifmgd = &sdata->u.mgd;
1454 ASSERT_MGD_MTX(ifmgd);
1456 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
1457 return; /* ignore ProbeResp to foreign address */
1459 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
1463 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
1466 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1468 if (ifmgd->associated &&
1469 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0 &&
1470 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1471 IEEE80211_STA_CONNECTION_POLL)) {
1472 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1473 IEEE80211_STA_BEACON_POLL);
1474 mutex_lock(&sdata->local->iflist_mtx);
1475 ieee80211_recalc_ps(sdata->local, -1);
1476 mutex_unlock(&sdata->local->iflist_mtx);
1478 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
1482 * We've received a probe response, but are not sure whether
1483 * we have or will be receiving any beacons or data, so let's
1484 * schedule the timers again, just in case.
1486 ieee80211_sta_reset_beacon_monitor(sdata);
1488 mod_timer(&ifmgd->conn_mon_timer,
1489 round_jiffies_up(jiffies +
1490 IEEE80211_CONNECTION_IDLE_TIME));
1495 * This is the canonical list of information elements we care about,
1496 * the filter code also gives us all changes to the Microsoft OUI
1497 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1499 * We implement beacon filtering in software since that means we can
1500 * avoid processing the frame here and in cfg80211, and userspace
1501 * will not be able to tell whether the hardware supports it or not.
1503 * XXX: This list needs to be dynamic -- userspace needs to be able to
1504 * add items it requires. It also needs to be able to tell us to
1505 * look out for other vendor IEs.
1507 static const u64 care_about_ies =
1508 (1ULL << WLAN_EID_COUNTRY) |
1509 (1ULL << WLAN_EID_ERP_INFO) |
1510 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1511 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1512 (1ULL << WLAN_EID_HT_CAPABILITY) |
1513 (1ULL << WLAN_EID_HT_INFORMATION);
1515 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1516 struct ieee80211_mgmt *mgmt,
1518 struct ieee80211_rx_status *rx_status)
1520 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1521 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
1523 struct ieee802_11_elems elems;
1524 struct ieee80211_local *local = sdata->local;
1526 bool erp_valid, directed_tim = false;
1531 ASSERT_MGD_MTX(ifmgd);
1533 /* Process beacon from the current BSS */
1534 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1538 if (rx_status->freq != local->hw.conf.channel->center_freq)
1542 * We might have received a number of frames, among them a
1543 * disassoc frame and a beacon...
1545 if (!ifmgd->associated)
1548 bssid = ifmgd->associated->bssid;
1551 * And in theory even frames from a different AP we were just
1552 * associated to a split-second ago!
1554 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
1557 /* Track average RSSI from the Beacon frames of the current AP */
1558 ifmgd->last_beacon_signal = rx_status->signal;
1559 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
1560 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
1561 ifmgd->ave_beacon_signal = rx_status->signal * 16;
1562 ifmgd->last_cqm_event_signal = 0;
1564 ifmgd->ave_beacon_signal =
1565 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
1566 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
1567 ifmgd->ave_beacon_signal) / 16;
1569 if (bss_conf->cqm_rssi_thold &&
1570 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1571 int sig = ifmgd->ave_beacon_signal / 16;
1572 int last_event = ifmgd->last_cqm_event_signal;
1573 int thold = bss_conf->cqm_rssi_thold;
1574 int hyst = bss_conf->cqm_rssi_hyst;
1576 (last_event == 0 || sig < last_event - hyst)) {
1577 ifmgd->last_cqm_event_signal = sig;
1578 ieee80211_cqm_rssi_notify(
1580 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
1582 } else if (sig > thold &&
1583 (last_event == 0 || sig > last_event + hyst)) {
1584 ifmgd->last_cqm_event_signal = sig;
1585 ieee80211_cqm_rssi_notify(
1587 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
1592 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
1593 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1594 if (net_ratelimit()) {
1595 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1596 "to a received beacon\n", sdata->name);
1599 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
1600 mutex_lock(&local->iflist_mtx);
1601 ieee80211_recalc_ps(local, -1);
1602 mutex_unlock(&local->iflist_mtx);
1606 * Push the beacon loss detection into the future since
1607 * we are processing a beacon from the AP just now.
1609 ieee80211_sta_reset_beacon_monitor(sdata);
1611 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1612 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1613 len - baselen, &elems,
1614 care_about_ies, ncrc);
1616 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1617 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1620 if (ncrc != ifmgd->beacon_crc) {
1621 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1624 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
1625 elems.wmm_param_len);
1628 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1630 if (local->hw.conf.dynamic_ps_timeout > 0) {
1631 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
1632 ieee80211_hw_config(local,
1633 IEEE80211_CONF_CHANGE_PS);
1634 ieee80211_send_nullfunc(local, sdata, 0);
1636 local->pspolling = true;
1639 * Here is assumed that the driver will be
1640 * able to send ps-poll frame and receive a
1641 * response even though power save mode is
1642 * enabled, but some drivers might require
1643 * to disable power save here. This needs
1644 * to be investigated.
1646 ieee80211_send_pspoll(local, sdata);
1651 if (ncrc == ifmgd->beacon_crc)
1653 ifmgd->beacon_crc = ncrc;
1655 if (elems.erp_info && elems.erp_info_len >= 1) {
1657 erp_value = elems.erp_info[0];
1661 changed |= ieee80211_handle_bss_capability(sdata,
1662 le16_to_cpu(mgmt->u.beacon.capab_info),
1663 erp_valid, erp_value);
1666 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1667 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
1668 struct sta_info *sta;
1669 struct ieee80211_supported_band *sband;
1670 u16 ap_ht_cap_flags;
1674 sta = sta_info_get(sdata, bssid);
1675 if (WARN_ON(!sta)) {
1680 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1682 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1683 elems.ht_cap_elem, &sta->sta.ht_cap);
1685 ap_ht_cap_flags = sta->sta.ht_cap.cap;
1689 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1690 bssid, ap_ht_cap_flags);
1693 /* Note: country IE parsing is done for us by cfg80211 */
1694 if (elems.country_elem) {
1695 /* TODO: IBSS also needs this */
1696 if (elems.pwr_constr_elem)
1697 ieee80211_handle_pwr_constr(sdata,
1698 le16_to_cpu(mgmt->u.probe_resp.capab_info),
1699 elems.pwr_constr_elem,
1700 elems.pwr_constr_elem_len);
1703 ieee80211_bss_info_change_notify(sdata, changed);
1706 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1707 struct sk_buff *skb)
1709 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1710 struct ieee80211_rx_status *rx_status;
1711 struct ieee80211_mgmt *mgmt;
1712 enum rx_mgmt_action rma = RX_MGMT_NONE;
1715 rx_status = (struct ieee80211_rx_status *) skb->cb;
1716 mgmt = (struct ieee80211_mgmt *) skb->data;
1717 fc = le16_to_cpu(mgmt->frame_control);
1719 mutex_lock(&ifmgd->mtx);
1721 if (ifmgd->associated &&
1722 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
1723 switch (fc & IEEE80211_FCTL_STYPE) {
1724 case IEEE80211_STYPE_BEACON:
1725 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
1728 case IEEE80211_STYPE_PROBE_RESP:
1729 ieee80211_rx_mgmt_probe_resp(sdata, skb);
1731 case IEEE80211_STYPE_DEAUTH:
1732 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
1734 case IEEE80211_STYPE_DISASSOC:
1735 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1737 case IEEE80211_STYPE_ACTION:
1738 switch (mgmt->u.action.category) {
1739 case WLAN_CATEGORY_SPECTRUM_MGMT:
1740 ieee80211_sta_process_chanswitch(sdata,
1741 &mgmt->u.action.u.chan_switch.sw_elem,
1742 (void *)ifmgd->associated->priv,
1743 rx_status->mactime);
1747 mutex_unlock(&ifmgd->mtx);
1753 case RX_MGMT_CFG80211_DEAUTH:
1754 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
1756 case RX_MGMT_CFG80211_DISASSOC:
1757 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
1760 WARN(1, "unexpected: %d", rma);
1765 mutex_unlock(&ifmgd->mtx);
1767 if (skb->len >= 24 + 2 /* mgmt + deauth reason */ &&
1768 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
1769 struct ieee80211_local *local = sdata->local;
1770 struct ieee80211_work *wk;
1772 mutex_lock(&local->work_mtx);
1773 list_for_each_entry(wk, &local->work_list, list) {
1774 if (wk->sdata != sdata)
1777 if (wk->type != IEEE80211_WORK_ASSOC &&
1778 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
1781 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
1783 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
1787 * Printing the message only here means we can't
1788 * spuriously print it, but it also means that it
1789 * won't be printed when the frame comes in before
1790 * we even tried to associate or in similar cases.
1792 * Ultimately, I suspect cfg80211 should print the
1796 "%s: deauthenticated from %pM (Reason: %u)\n",
1797 sdata->name, mgmt->bssid,
1798 le16_to_cpu(mgmt->u.deauth.reason_code));
1800 list_del_rcu(&wk->list);
1804 mutex_unlock(&local->work_mtx);
1806 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
1810 static void ieee80211_sta_timer(unsigned long data)
1812 struct ieee80211_sub_if_data *sdata =
1813 (struct ieee80211_sub_if_data *) data;
1814 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1815 struct ieee80211_local *local = sdata->local;
1817 if (local->quiescing) {
1818 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1822 ieee80211_queue_work(&local->hw, &sdata->work);
1825 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
1827 struct ieee80211_local *local = sdata->local;
1828 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1830 /* then process the rest of the work */
1831 mutex_lock(&ifmgd->mtx);
1833 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1834 IEEE80211_STA_CONNECTION_POLL) &&
1835 ifmgd->associated) {
1838 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1839 if (time_is_after_jiffies(ifmgd->probe_timeout))
1840 run_again(ifmgd, ifmgd->probe_timeout);
1842 else if (ifmgd->probe_send_count < IEEE80211_MAX_PROBE_TRIES) {
1843 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1844 printk(KERN_DEBUG "No probe response from AP %pM"
1845 " after %dms, try %d\n", bssid,
1846 (1000 * IEEE80211_PROBE_WAIT)/HZ,
1847 ifmgd->probe_send_count);
1849 ieee80211_mgd_probe_ap_send(sdata);
1852 * We actually lost the connection ... or did we?
1855 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1856 IEEE80211_STA_BEACON_POLL);
1857 printk(KERN_DEBUG "No probe response from AP %pM"
1858 " after %dms, disconnecting.\n",
1859 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
1860 ieee80211_set_disassoc(sdata, true);
1861 ieee80211_recalc_idle(local);
1862 mutex_unlock(&ifmgd->mtx);
1864 * must be outside lock due to cfg80211,
1865 * but that's not a problem.
1867 ieee80211_send_deauth_disassoc(sdata, bssid,
1868 IEEE80211_STYPE_DEAUTH,
1869 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
1871 mutex_lock(&ifmgd->mtx);
1875 mutex_unlock(&ifmgd->mtx);
1878 static void ieee80211_sta_bcn_mon_timer(unsigned long data)
1880 struct ieee80211_sub_if_data *sdata =
1881 (struct ieee80211_sub_if_data *) data;
1882 struct ieee80211_local *local = sdata->local;
1884 if (local->quiescing)
1887 ieee80211_queue_work(&sdata->local->hw,
1888 &sdata->u.mgd.beacon_connection_loss_work);
1891 static void ieee80211_sta_conn_mon_timer(unsigned long data)
1893 struct ieee80211_sub_if_data *sdata =
1894 (struct ieee80211_sub_if_data *) data;
1895 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1896 struct ieee80211_local *local = sdata->local;
1898 if (local->quiescing)
1901 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
1904 static void ieee80211_sta_monitor_work(struct work_struct *work)
1906 struct ieee80211_sub_if_data *sdata =
1907 container_of(work, struct ieee80211_sub_if_data,
1908 u.mgd.monitor_work);
1910 ieee80211_mgd_probe_ap(sdata, false);
1913 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1915 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
1916 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
1917 IEEE80211_STA_CONNECTION_POLL);
1919 /* let's probe the connection once */
1920 ieee80211_queue_work(&sdata->local->hw,
1921 &sdata->u.mgd.monitor_work);
1922 /* and do all the other regular work too */
1923 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
1928 void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
1930 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1933 * we need to use atomic bitops for the running bits
1934 * only because both timers might fire at the same
1935 * time -- the code here is properly synchronised.
1938 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
1939 if (del_timer_sync(&ifmgd->timer))
1940 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
1942 cancel_work_sync(&ifmgd->chswitch_work);
1943 if (del_timer_sync(&ifmgd->chswitch_timer))
1944 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
1946 cancel_work_sync(&ifmgd->monitor_work);
1947 /* these will just be re-established on connection */
1948 del_timer_sync(&ifmgd->conn_mon_timer);
1949 del_timer_sync(&ifmgd->bcn_mon_timer);
1952 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
1954 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1956 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
1957 add_timer(&ifmgd->timer);
1958 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
1959 add_timer(&ifmgd->chswitch_timer);
1963 /* interface setup */
1964 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1966 struct ieee80211_if_managed *ifmgd;
1968 ifmgd = &sdata->u.mgd;
1969 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
1970 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
1971 INIT_WORK(&ifmgd->beacon_connection_loss_work,
1972 ieee80211_beacon_connection_loss_work);
1973 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
1974 (unsigned long) sdata);
1975 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
1976 (unsigned long) sdata);
1977 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
1978 (unsigned long) sdata);
1979 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
1980 (unsigned long) sdata);
1984 mutex_init(&ifmgd->mtx);
1986 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
1987 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
1989 ifmgd->req_smps = IEEE80211_SMPS_OFF;
1992 /* scan finished notification */
1993 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
1995 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
1997 /* Restart STA timers */
1999 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2000 ieee80211_restart_sta_timer(sdata);
2004 int ieee80211_max_network_latency(struct notifier_block *nb,
2005 unsigned long data, void *dummy)
2007 s32 latency_usec = (s32) data;
2008 struct ieee80211_local *local =
2009 container_of(nb, struct ieee80211_local,
2010 network_latency_notifier);
2012 mutex_lock(&local->iflist_mtx);
2013 ieee80211_recalc_ps(local, latency_usec);
2014 mutex_unlock(&local->iflist_mtx);
2020 static enum work_done_result
2021 ieee80211_probe_auth_done(struct ieee80211_work *wk,
2022 struct sk_buff *skb)
2025 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
2026 return WORK_DONE_DESTROY;
2029 if (wk->type == IEEE80211_WORK_AUTH) {
2030 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
2031 return WORK_DONE_DESTROY;
2034 mutex_lock(&wk->sdata->u.mgd.mtx);
2035 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
2036 mutex_unlock(&wk->sdata->u.mgd.mtx);
2038 wk->type = IEEE80211_WORK_AUTH;
2039 wk->probe_auth.tries = 0;
2040 return WORK_DONE_REQUEUE;
2043 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2044 struct cfg80211_auth_request *req)
2047 struct ieee80211_work *wk;
2050 if (req->local_state_change)
2051 return 0; /* no need to update mac80211 state */
2053 switch (req->auth_type) {
2054 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2055 auth_alg = WLAN_AUTH_OPEN;
2057 case NL80211_AUTHTYPE_SHARED_KEY:
2058 if (IS_ERR(sdata->local->wep_tx_tfm))
2060 auth_alg = WLAN_AUTH_SHARED_KEY;
2062 case NL80211_AUTHTYPE_FT:
2063 auth_alg = WLAN_AUTH_FT;
2065 case NL80211_AUTHTYPE_NETWORK_EAP:
2066 auth_alg = WLAN_AUTH_LEAP;
2072 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2076 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
2078 if (req->ie && req->ie_len) {
2079 memcpy(wk->ie, req->ie, req->ie_len);
2080 wk->ie_len = req->ie_len;
2083 if (req->key && req->key_len) {
2084 wk->probe_auth.key_len = req->key_len;
2085 wk->probe_auth.key_idx = req->key_idx;
2086 memcpy(wk->probe_auth.key, req->key, req->key_len);
2089 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2090 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
2091 wk->probe_auth.ssid_len = ssid[1];
2093 wk->probe_auth.algorithm = auth_alg;
2094 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
2096 /* if we already have a probe, don't probe again */
2097 if (req->bss->proberesp_ies)
2098 wk->type = IEEE80211_WORK_AUTH;
2100 wk->type = IEEE80211_WORK_DIRECT_PROBE;
2101 wk->chan = req->bss->channel;
2103 wk->done = ieee80211_probe_auth_done;
2105 ieee80211_add_work(wk);
2109 static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
2110 struct sk_buff *skb)
2112 struct ieee80211_mgmt *mgmt;
2113 struct ieee80211_rx_status *rx_status;
2114 struct ieee802_11_elems elems;
2118 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
2119 return WORK_DONE_DESTROY;
2122 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
2123 mutex_lock(&wk->sdata->u.mgd.mtx);
2124 rx_status = (void *) skb->cb;
2125 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
2126 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
2128 mutex_unlock(&wk->sdata->u.mgd.mtx);
2130 wk->type = IEEE80211_WORK_ASSOC;
2131 /* not really done yet */
2132 return WORK_DONE_REQUEUE;
2135 mgmt = (void *)skb->data;
2136 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2138 if (status == WLAN_STATUS_SUCCESS) {
2139 mutex_lock(&wk->sdata->u.mgd.mtx);
2140 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
2141 mutex_unlock(&wk->sdata->u.mgd.mtx);
2142 /* oops -- internal error -- send timeout for now */
2143 cfg80211_send_assoc_timeout(wk->sdata->dev,
2145 return WORK_DONE_DESTROY;
2148 mutex_unlock(&wk->sdata->u.mgd.mtx);
2151 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
2152 return WORK_DONE_DESTROY;
2155 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2156 struct cfg80211_assoc_request *req)
2158 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2159 struct ieee80211_bss *bss = (void *)req->bss->priv;
2160 struct ieee80211_work *wk;
2164 mutex_lock(&ifmgd->mtx);
2165 if (ifmgd->associated) {
2166 if (!req->prev_bssid ||
2167 memcmp(req->prev_bssid, ifmgd->associated->bssid,
2170 * We are already associated and the request was not a
2171 * reassociation request from the current BSS, so
2174 mutex_unlock(&ifmgd->mtx);
2178 /* Trying to reassociate - clear previous association state */
2179 ieee80211_set_disassoc(sdata, true);
2181 mutex_unlock(&ifmgd->mtx);
2183 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2187 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
2188 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
2190 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2191 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2192 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2193 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2194 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2197 if (req->ie && req->ie_len) {
2198 memcpy(wk->ie, req->ie, req->ie_len);
2199 wk->ie_len = req->ie_len;
2203 wk->assoc.bss = req->bss;
2205 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
2207 /* new association always uses requested smps mode */
2208 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
2209 if (ifmgd->powersave)
2210 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
2212 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
2214 ifmgd->ap_smps = ifmgd->req_smps;
2216 wk->assoc.smps = ifmgd->ap_smps;
2218 * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
2219 * We still associate in non-HT mode (11a/b/g) if any one of these
2220 * ciphers is configured as pairwise.
2221 * We can set this to true for non-11n hardware, that'll be checked
2222 * separately along with the peer capabilities.
2224 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
2225 wk->assoc.capability = req->bss->capability;
2226 wk->assoc.wmm_used = bss->wmm_used;
2227 wk->assoc.supp_rates = bss->supp_rates;
2228 wk->assoc.supp_rates_len = bss->supp_rates_len;
2229 wk->assoc.ht_information_ie =
2230 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
2232 if (bss->wmm_used && bss->uapsd_supported &&
2233 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
2234 wk->assoc.uapsd_used = true;
2235 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
2237 wk->assoc.uapsd_used = false;
2238 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
2241 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2242 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
2243 wk->assoc.ssid_len = ssid[1];
2245 if (req->prev_bssid)
2246 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
2248 wk->chan = req->bss->channel;
2250 wk->done = ieee80211_assoc_done;
2251 if (!bss->dtim_period &&
2252 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
2253 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
2255 wk->type = IEEE80211_WORK_ASSOC;
2258 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2259 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2261 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2262 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2265 if (req->crypto.control_port)
2266 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2268 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2270 ieee80211_add_work(wk);
2274 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2275 struct cfg80211_deauth_request *req,
2278 struct ieee80211_local *local = sdata->local;
2279 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2280 struct ieee80211_work *wk;
2282 bool assoc_bss = false;
2284 mutex_lock(&ifmgd->mtx);
2286 memcpy(bssid, req->bss->bssid, ETH_ALEN);
2287 if (ifmgd->associated == req->bss) {
2288 ieee80211_set_disassoc(sdata, false);
2289 mutex_unlock(&ifmgd->mtx);
2292 bool not_auth_yet = false;
2294 mutex_unlock(&ifmgd->mtx);
2296 mutex_lock(&local->work_mtx);
2297 list_for_each_entry(wk, &local->work_list, list) {
2298 if (wk->sdata != sdata)
2301 if (wk->type != IEEE80211_WORK_DIRECT_PROBE &&
2302 wk->type != IEEE80211_WORK_AUTH &&
2303 wk->type != IEEE80211_WORK_ASSOC &&
2304 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
2307 if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN))
2310 not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE;
2311 list_del_rcu(&wk->list);
2315 mutex_unlock(&local->work_mtx);
2318 * If somebody requests authentication and we haven't
2319 * sent out an auth frame yet there's no need to send
2320 * out a deauth frame either. If the state was PROBE,
2321 * then this is the case. If it's AUTH we have sent a
2322 * frame, and if it's IDLE we have completed the auth
2326 __cfg80211_auth_canceled(sdata->dev, bssid);
2331 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
2332 sdata->name, bssid, req->reason_code);
2334 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
2335 req->reason_code, cookie,
2336 !req->local_state_change);
2338 sta_info_destroy_addr(sdata, bssid);
2340 ieee80211_recalc_idle(sdata->local);
2345 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2346 struct cfg80211_disassoc_request *req,
2349 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2352 mutex_lock(&ifmgd->mtx);
2355 * cfg80211 should catch this ... but it's racy since
2356 * we can receive a disassoc frame, process it, hand it
2357 * to cfg80211 while that's in a locked section already
2358 * trying to tell us that the user wants to disconnect.
2360 if (ifmgd->associated != req->bss) {
2361 mutex_unlock(&ifmgd->mtx);
2365 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
2366 sdata->name, req->bss->bssid, req->reason_code);
2368 memcpy(bssid, req->bss->bssid, ETH_ALEN);
2369 ieee80211_set_disassoc(sdata, false);
2371 mutex_unlock(&ifmgd->mtx);
2373 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
2374 IEEE80211_STYPE_DISASSOC, req->reason_code,
2375 cookie, !req->local_state_change);
2376 sta_info_destroy_addr(sdata, bssid);
2378 ieee80211_recalc_idle(sdata->local);
2383 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
2384 enum nl80211_cqm_rssi_threshold_event rssi_event,
2387 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2389 trace_api_cqm_rssi_notify(sdata, rssi_event);
2391 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
2393 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);