aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig21
-rw-r--r--net/mac80211/agg-rx.c19
-rw-r--r--net/mac80211/agg-tx.c19
-rw-r--r--net/mac80211/cfg.c213
-rw-r--r--net/mac80211/debugfs.c74
-rw-r--r--net/mac80211/driver-ops.h191
-rw-r--r--net/mac80211/event.c17
-rw-r--r--net/mac80211/ht.c84
-rw-r--r--net/mac80211/ibss.c501
-rw-r--r--net/mac80211/ieee80211_i.h156
-rw-r--r--net/mac80211/iface.c117
-rw-r--r--net/mac80211/key.c29
-rw-r--r--net/mac80211/key.h3
-rw-r--r--net/mac80211/main.c368
-rw-r--r--net/mac80211/mesh.c46
-rw-r--r--net/mac80211/mesh.h16
-rw-r--r--net/mac80211/mesh_hwmp.c8
-rw-r--r--net/mac80211/mesh_plink.c21
-rw-r--r--net/mac80211/mlme.c790
-rw-r--r--net/mac80211/pm.c182
-rw-r--r--net/mac80211/rc80211_minstrel.c10
-rw-r--r--net/mac80211/rc80211_pid_algo.c8
-rw-r--r--net/mac80211/rx.c319
-rw-r--r--net/mac80211/scan.c436
-rw-r--r--net/mac80211/spectmgmt.c103
-rw-r--r--net/mac80211/sta_info.c112
-rw-r--r--net/mac80211/sta_info.h7
-rw-r--r--net/mac80211/tkip.c6
-rw-r--r--net/mac80211/tx.c72
-rw-r--r--net/mac80211/util.c451
-rw-r--r--net/mac80211/wext.c637
-rw-r--r--net/mac80211/wme.c34
-rw-r--r--net/mac80211/wpa.c2
33 files changed, 2767 insertions, 2305 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index ecc3faf9f11a..ba2643a43c73 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -1,16 +1,35 @@
1config MAC80211 1config MAC80211
2 tristate "Generic IEEE 802.11 Networking Stack (mac80211)" 2 tristate "Generic IEEE 802.11 Networking Stack (mac80211)"
3 depends on CFG80211
3 select CRYPTO 4 select CRYPTO
4 select CRYPTO_ECB 5 select CRYPTO_ECB
5 select CRYPTO_ARC4 6 select CRYPTO_ARC4
6 select CRYPTO_AES 7 select CRYPTO_AES
7 select CRC32 8 select CRC32
8 select WIRELESS_EXT 9 select WIRELESS_EXT
9 select CFG80211
10 ---help--- 10 ---help---
11 This option enables the hardware independent IEEE 802.11 11 This option enables the hardware independent IEEE 802.11
12 networking stack. 12 networking stack.
13 13
14comment "CFG80211 needs to be enabled for MAC80211"
15 depends on CFG80211=n
16
17config MAC80211_DEFAULT_PS
18 bool "enable powersave by default"
19 depends on MAC80211
20 default y
21 help
22 This option enables powersave mode by default.
23
24 If this causes your applications to misbehave you should fix your
25 applications instead -- they need to register their network
26 latency requirement, see Documentation/power/pm_qos_interface.txt.
27
28config MAC80211_DEFAULT_PS_VALUE
29 int
30 default 1 if MAC80211_DEFAULT_PS
31 default 0
32
14menu "Rate control algorithm selection" 33menu "Rate control algorithm selection"
15 depends on MAC80211 != n 34 depends on MAC80211 != n
16 35
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index 07656d830bc4..bc064d7933ff 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -16,12 +16,12 @@
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <net/mac80211.h> 17#include <net/mac80211.h>
18#include "ieee80211_i.h" 18#include "ieee80211_i.h"
19#include "driver-ops.h"
19 20
20void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid, 21void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
21 u16 initiator, u16 reason) 22 u16 initiator, u16 reason)
22{ 23{
23 struct ieee80211_local *local = sta->local; 24 struct ieee80211_local *local = sta->local;
24 struct ieee80211_hw *hw = &local->hw;
25 int i; 25 int i;
26 26
27 /* check if TID is in operational state */ 27 /* check if TID is in operational state */
@@ -41,8 +41,8 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
41 sta->sta.addr, tid); 41 sta->sta.addr, tid);
42#endif /* CONFIG_MAC80211_HT_DEBUG */ 42#endif /* CONFIG_MAC80211_HT_DEBUG */
43 43
44 if (local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, 44 if (drv_ampdu_action(local, IEEE80211_AMPDU_RX_STOP,
45 &sta->sta, tid, NULL)) 45 &sta->sta, tid, NULL))
46 printk(KERN_DEBUG "HW problem - can not stop rx " 46 printk(KERN_DEBUG "HW problem - can not stop rx "
47 "aggregation for tid %d\n", tid); 47 "aggregation for tid %d\n", tid);
48 48
@@ -68,6 +68,7 @@ void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
68 spin_lock_bh(&sta->lock); 68 spin_lock_bh(&sta->lock);
69 /* free resources */ 69 /* free resources */
70 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf); 70 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
71 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_time);
71 72
72 if (!sta->ampdu_mlme.tid_rx[tid]->shutdown) { 73 if (!sta->ampdu_mlme.tid_rx[tid]->shutdown) {
73 kfree(sta->ampdu_mlme.tid_rx[tid]); 74 kfree(sta->ampdu_mlme.tid_rx[tid]);
@@ -268,19 +269,23 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
268 /* prepare reordering buffer */ 269 /* prepare reordering buffer */
269 tid_agg_rx->reorder_buf = 270 tid_agg_rx->reorder_buf =
270 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC); 271 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC);
271 if (!tid_agg_rx->reorder_buf) { 272 tid_agg_rx->reorder_time =
273 kcalloc(buf_size, sizeof(unsigned long), GFP_ATOMIC);
274 if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) {
272#ifdef CONFIG_MAC80211_HT_DEBUG 275#ifdef CONFIG_MAC80211_HT_DEBUG
273 if (net_ratelimit()) 276 if (net_ratelimit())
274 printk(KERN_ERR "can not allocate reordering buffer " 277 printk(KERN_ERR "can not allocate reordering buffer "
275 "to tid %d\n", tid); 278 "to tid %d\n", tid);
276#endif 279#endif
280 kfree(tid_agg_rx->reorder_buf);
281 kfree(tid_agg_rx->reorder_time);
277 kfree(sta->ampdu_mlme.tid_rx[tid]); 282 kfree(sta->ampdu_mlme.tid_rx[tid]);
283 sta->ampdu_mlme.tid_rx[tid] = NULL;
278 goto end; 284 goto end;
279 } 285 }
280 286
281 if (local->ops->ampdu_action) 287 ret = drv_ampdu_action(local, IEEE80211_AMPDU_RX_START,
282 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, 288 &sta->sta, tid, &start_seq_num);
283 &sta->sta, tid, &start_seq_num);
284#ifdef CONFIG_MAC80211_HT_DEBUG 289#ifdef CONFIG_MAC80211_HT_DEBUG
285 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret); 290 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
286#endif /* CONFIG_MAC80211_HT_DEBUG */ 291#endif /* CONFIG_MAC80211_HT_DEBUG */
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index 947aaaad35d2..9e5762ad307d 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -16,6 +16,7 @@
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <net/mac80211.h> 17#include <net/mac80211.h>
18#include "ieee80211_i.h" 18#include "ieee80211_i.h"
19#include "driver-ops.h"
19#include "wme.h" 20#include "wme.h"
20 21
21/** 22/**
@@ -131,11 +132,14 @@ static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
131 132
132 state = &sta->ampdu_mlme.tid_state_tx[tid]; 133 state = &sta->ampdu_mlme.tid_state_tx[tid];
133 134
135 if (*state == HT_AGG_STATE_OPERATIONAL)
136 sta->ampdu_mlme.addba_req_num[tid] = 0;
137
134 *state = HT_AGG_STATE_REQ_STOP_BA_MSK | 138 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
135 (initiator << HT_AGG_STATE_INITIATOR_SHIFT); 139 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
136 140
137 ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP, 141 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_STOP,
138 &sta->sta, tid, NULL); 142 &sta->sta, tid, NULL);
139 143
140 /* HW shall not deny going back to legacy */ 144 /* HW shall not deny going back to legacy */
141 if (WARN_ON(ret)) { 145 if (WARN_ON(ret)) {
@@ -306,8 +310,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
306 310
307 start_seq_num = sta->tid_seq[tid]; 311 start_seq_num = sta->tid_seq[tid];
308 312
309 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, 313 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_START,
310 &sta->sta, tid, &start_seq_num); 314 &sta->sta, tid, &start_seq_num);
311 315
312 if (ret) { 316 if (ret) {
313#ifdef CONFIG_MAC80211_HT_DEBUG 317#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -336,6 +340,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
336 sta->ampdu_mlme.tid_tx[tid]->dialog_token, 340 sta->ampdu_mlme.tid_tx[tid]->dialog_token,
337 sta->ampdu_mlme.tid_tx[tid]->ssn, 341 sta->ampdu_mlme.tid_tx[tid]->ssn,
338 0x40, 5000); 342 0x40, 5000);
343 sta->ampdu_mlme.addba_req_num[tid]++;
339 /* activate the timer for the recipient's addBA response */ 344 /* activate the timer for the recipient's addBA response */
340 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires = 345 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
341 jiffies + ADDBA_RESP_INTERVAL; 346 jiffies + ADDBA_RESP_INTERVAL;
@@ -418,8 +423,8 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
418 ieee80211_agg_splice_finish(local, sta, tid); 423 ieee80211_agg_splice_finish(local, sta, tid);
419 spin_unlock(&local->ampdu_lock); 424 spin_unlock(&local->ampdu_lock);
420 425
421 local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_OPERATIONAL, 426 drv_ampdu_action(local, IEEE80211_AMPDU_TX_OPERATIONAL,
422 &sta->sta, tid, NULL); 427 &sta->sta, tid, NULL);
423} 428}
424 429
425void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) 430void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
@@ -605,7 +610,6 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
605 610
606 *state = HT_AGG_STATE_IDLE; 611 *state = HT_AGG_STATE_IDLE;
607 /* from now on packets are no longer put onto sta->pending */ 612 /* from now on packets are no longer put onto sta->pending */
608 sta->ampdu_mlme.addba_req_num[tid] = 0;
609 kfree(sta->ampdu_mlme.tid_tx[tid]); 613 kfree(sta->ampdu_mlme.tid_tx[tid]);
610 sta->ampdu_mlme.tid_tx[tid] = NULL; 614 sta->ampdu_mlme.tid_tx[tid] = NULL;
611 615
@@ -688,7 +692,6 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
688 692
689 sta->ampdu_mlme.addba_req_num[tid] = 0; 693 sta->ampdu_mlme.addba_req_num[tid] = 0;
690 } else { 694 } else {
691 sta->ampdu_mlme.addba_req_num[tid]++;
692 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR); 695 ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
693 } 696 }
694 spin_unlock_bh(&sta->lock); 697 spin_unlock_bh(&sta->lock);
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index e677b751d468..3f47276caeb8 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -13,6 +13,7 @@
13#include <linux/rcupdate.h> 13#include <linux/rcupdate.h>
14#include <net/cfg80211.h> 14#include <net/cfg80211.h>
15#include "ieee80211_i.h" 15#include "ieee80211_i.h"
16#include "driver-ops.h"
16#include "cfg.h" 17#include "cfg.h"
17#include "rate.h" 18#include "rate.h"
18#include "mesh.h" 19#include "mesh.h"
@@ -111,7 +112,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
111} 112}
112 113
113static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, 114static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
114 u8 key_idx, u8 *mac_addr, 115 u8 key_idx, const u8 *mac_addr,
115 struct key_params *params) 116 struct key_params *params)
116{ 117{
117 struct ieee80211_sub_if_data *sdata; 118 struct ieee80211_sub_if_data *sdata;
@@ -140,7 +141,8 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
140 return -EINVAL; 141 return -EINVAL;
141 } 142 }
142 143
143 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key); 144 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
145 params->seq_len, params->seq);
144 if (!key) 146 if (!key)
145 return -ENOMEM; 147 return -ENOMEM;
146 148
@@ -165,7 +167,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
165} 167}
166 168
167static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, 169static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
168 u8 key_idx, u8 *mac_addr) 170 u8 key_idx, const u8 *mac_addr)
169{ 171{
170 struct ieee80211_sub_if_data *sdata; 172 struct ieee80211_sub_if_data *sdata;
171 struct sta_info *sta; 173 struct sta_info *sta;
@@ -207,7 +209,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
207} 209}
208 210
209static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, 211static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
210 u8 key_idx, u8 *mac_addr, void *cookie, 212 u8 key_idx, const u8 *mac_addr, void *cookie,
211 void (*callback)(void *cookie, 213 void (*callback)(void *cookie,
212 struct key_params *params)) 214 struct key_params *params))
213{ 215{
@@ -245,12 +247,10 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
245 iv32 = key->u.tkip.tx.iv32; 247 iv32 = key->u.tkip.tx.iv32;
246 iv16 = key->u.tkip.tx.iv16; 248 iv16 = key->u.tkip.tx.iv16;
247 249
248 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && 250 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
249 sdata->local->ops->get_tkip_seq) 251 drv_get_tkip_seq(sdata->local,
250 sdata->local->ops->get_tkip_seq( 252 key->conf.hw_key_idx,
251 local_to_hw(sdata->local), 253 &iv32, &iv16);
252 key->conf.hw_key_idx,
253 &iv32, &iv16);
254 254
255 seq[0] = iv16 & 0xff; 255 seq[0] = iv16 & 0xff;
256 seq[1] = (iv16 >> 8) & 0xff; 256 seq[1] = (iv16 >> 8) & 0xff;
@@ -451,18 +451,11 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
451 * This is a kludge. beacon interval should really be part 451 * This is a kludge. beacon interval should really be part
452 * of the beacon information. 452 * of the beacon information.
453 */ 453 */
454 if (params->interval && (sdata->local->hw.conf.beacon_int != 454 if (params->interval &&
455 params->interval)) { 455 (sdata->vif.bss_conf.beacon_int != params->interval)) {
456 sdata->local->hw.conf.beacon_int = params->interval; 456 sdata->vif.bss_conf.beacon_int = params->interval;
457 err = ieee80211_hw_config(sdata->local, 457 ieee80211_bss_info_change_notify(sdata,
458 IEEE80211_CONF_CHANGE_BEACON_INTERVAL); 458 BSS_CHANGED_BEACON_INT);
459 if (err < 0)
460 return err;
461 /*
462 * We updated some parameter so if below bails out
463 * it's not an error.
464 */
465 err = 0;
466 } 459 }
467 460
468 /* Need to have a beacon head if we don't have one yet */ 461 /* Need to have a beacon head if we don't have one yet */
@@ -528,8 +521,9 @@ static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
528 521
529 kfree(old); 522 kfree(old);
530 523
531 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON | 524 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
532 IEEE80211_IFCC_BEACON_ENABLED); 525 BSS_CHANGED_BEACON);
526 return 0;
533} 527}
534 528
535static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, 529static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
@@ -580,7 +574,8 @@ static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
580 synchronize_rcu(); 574 synchronize_rcu();
581 kfree(old); 575 kfree(old);
582 576
583 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED); 577 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
578 return 0;
584} 579}
585 580
586/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ 581/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
@@ -635,34 +630,45 @@ static void sta_apply_parameters(struct ieee80211_local *local,
635 int i, j; 630 int i, j;
636 struct ieee80211_supported_band *sband; 631 struct ieee80211_supported_band *sband;
637 struct ieee80211_sub_if_data *sdata = sta->sdata; 632 struct ieee80211_sub_if_data *sdata = sta->sdata;
633 u32 mask, set;
638 634
639 sband = local->hw.wiphy->bands[local->oper_channel->band]; 635 sband = local->hw.wiphy->bands[local->oper_channel->band];
640 636
641 /* 637 spin_lock_bh(&sta->lock);
642 * FIXME: updating the flags is racy when this function is 638 mask = params->sta_flags_mask;
643 * called from ieee80211_change_station(), this will 639 set = params->sta_flags_set;
644 * be resolved in a future patch.
645 */
646 640
647 if (params->station_flags & STATION_FLAG_CHANGED) { 641 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
648 spin_lock_bh(&sta->lock);
649 sta->flags &= ~WLAN_STA_AUTHORIZED; 642 sta->flags &= ~WLAN_STA_AUTHORIZED;
650 if (params->station_flags & STATION_FLAG_AUTHORIZED) 643 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
651 sta->flags |= WLAN_STA_AUTHORIZED; 644 sta->flags |= WLAN_STA_AUTHORIZED;
645 }
652 646
647 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
653 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; 648 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
654 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE) 649 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
655 sta->flags |= WLAN_STA_SHORT_PREAMBLE; 650 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
651 }
656 652
653 if (mask & BIT(NL80211_STA_FLAG_WME)) {
657 sta->flags &= ~WLAN_STA_WME; 654 sta->flags &= ~WLAN_STA_WME;
658 if (params->station_flags & STATION_FLAG_WME) 655 if (set & BIT(NL80211_STA_FLAG_WME))
659 sta->flags |= WLAN_STA_WME; 656 sta->flags |= WLAN_STA_WME;
657 }
660 658
659 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
661 sta->flags &= ~WLAN_STA_MFP; 660 sta->flags &= ~WLAN_STA_MFP;
662 if (params->station_flags & STATION_FLAG_MFP) 661 if (set & BIT(NL80211_STA_FLAG_MFP))
663 sta->flags |= WLAN_STA_MFP; 662 sta->flags |= WLAN_STA_MFP;
664 spin_unlock_bh(&sta->lock);
665 } 663 }
664 spin_unlock_bh(&sta->lock);
665
666 /*
667 * cfg80211 validates this (1-2007) and allows setting the AID
668 * only when creating a new station entry
669 */
670 if (params->aid)
671 sta->sta.aid = params->aid;
666 672
667 /* 673 /*
668 * FIXME: updating the following information is racy when this 674 * FIXME: updating the following information is racy when this
@@ -671,12 +677,6 @@ static void sta_apply_parameters(struct ieee80211_local *local,
671 * maybe we should just reject attemps to change it. 677 * maybe we should just reject attemps to change it.
672 */ 678 */
673 679
674 if (params->aid) {
675 sta->sta.aid = params->aid;
676 if (sta->sta.aid > IEEE80211_MAX_AID)
677 sta->sta.aid = 0; /* XXX: should this be an error? */
678 }
679
680 if (params->listen_interval >= 0) 680 if (params->listen_interval >= 0)
681 sta->listen_interval = params->listen_interval; 681 sta->listen_interval = params->listen_interval;
682 682
@@ -1120,10 +1120,10 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
1120 p.cw_max = params->cwmax; 1120 p.cw_max = params->cwmax;
1121 p.cw_min = params->cwmin; 1121 p.cw_min = params->cwmin;
1122 p.txop = params->txop; 1122 p.txop = params->txop;
1123 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) { 1123 if (drv_conf_tx(local, params->queue, &p)) {
1124 printk(KERN_DEBUG "%s: failed to set TX queue " 1124 printk(KERN_DEBUG "%s: failed to set TX queue "
1125 "parameters for queue %d\n", local->mdev->name, 1125 "parameters for queue %d\n",
1126 params->queue); 1126 wiphy_name(local->hw.wiphy), params->queue);
1127 return -EINVAL; 1127 return -EINVAL;
1128 } 1128 }
1129 1129
@@ -1167,7 +1167,8 @@ static int ieee80211_scan(struct wiphy *wiphy,
1167 1167
1168 if (sdata->vif.type != NL80211_IFTYPE_STATION && 1168 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1169 sdata->vif.type != NL80211_IFTYPE_ADHOC && 1169 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT) 1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1171 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1171 return -EOPNOTSUPP; 1172 return -EOPNOTSUPP;
1172 1173
1173 return ieee80211_request_scan(sdata, req); 1174 return ieee80211_request_scan(sdata, req);
@@ -1255,9 +1256,22 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1255 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL; 1256 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1256 1257
1257 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len); 1258 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1258 if (ret) 1259 if (ret && ret != -EALREADY)
1259 return ret; 1260 return ret;
1260 1261
1262 if (req->use_mfp) {
1263 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
1264 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
1265 } else {
1266 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
1267 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
1268 }
1269
1270 if (req->control_port)
1271 sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
1272 else
1273 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
1274
1261 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME; 1275 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1262 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE; 1276 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1263 ieee80211_sta_req_auth(sdata); 1277 ieee80211_sta_req_auth(sdata);
@@ -1267,25 +1281,106 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1267static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 1281static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1268 struct cfg80211_deauth_request *req) 1282 struct cfg80211_deauth_request *req)
1269{ 1283{
1270 struct ieee80211_sub_if_data *sdata; 1284 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1271
1272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1273 1285
1274 /* TODO: req->ie */ 1286 /* TODO: req->ie, req->peer_addr */
1275 return ieee80211_sta_deauthenticate(sdata, req->reason_code); 1287 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1276} 1288}
1277 1289
1278static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 1290static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1279 struct cfg80211_disassoc_request *req) 1291 struct cfg80211_disassoc_request *req)
1280{ 1292{
1281 struct ieee80211_sub_if_data *sdata; 1293 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1282
1283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1284 1294
1285 /* TODO: req->ie */ 1295 /* TODO: req->ie, req->peer_addr */
1286 return ieee80211_sta_disassociate(sdata, req->reason_code); 1296 return ieee80211_sta_disassociate(sdata, req->reason_code);
1287} 1297}
1288 1298
1299static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1300 struct cfg80211_ibss_params *params)
1301{
1302 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1303
1304 return ieee80211_ibss_join(sdata, params);
1305}
1306
1307static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1308{
1309 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1310
1311 return ieee80211_ibss_leave(sdata);
1312}
1313
1314static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1315{
1316 struct ieee80211_local *local = wiphy_priv(wiphy);
1317 int err;
1318
1319 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1320 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1321
1322 if (err)
1323 return err;
1324 }
1325
1326 if (changed & WIPHY_PARAM_RETRY_SHORT)
1327 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1328 if (changed & WIPHY_PARAM_RETRY_LONG)
1329 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1330 if (changed &
1331 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1332 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1333
1334 return 0;
1335}
1336
1337static int ieee80211_set_tx_power(struct wiphy *wiphy,
1338 enum tx_power_setting type, int dbm)
1339{
1340 struct ieee80211_local *local = wiphy_priv(wiphy);
1341 struct ieee80211_channel *chan = local->hw.conf.channel;
1342 u32 changes = 0;
1343
1344 switch (type) {
1345 case TX_POWER_AUTOMATIC:
1346 local->user_power_level = -1;
1347 break;
1348 case TX_POWER_LIMITED:
1349 if (dbm < 0)
1350 return -EINVAL;
1351 local->user_power_level = dbm;
1352 break;
1353 case TX_POWER_FIXED:
1354 if (dbm < 0)
1355 return -EINVAL;
1356 /* TODO: move to cfg80211 when it knows the channel */
1357 if (dbm > chan->max_power)
1358 return -EINVAL;
1359 local->user_power_level = dbm;
1360 break;
1361 }
1362
1363 ieee80211_hw_config(local, changes);
1364
1365 return 0;
1366}
1367
1368static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1369{
1370 struct ieee80211_local *local = wiphy_priv(wiphy);
1371
1372 *dbm = local->hw.conf.power_level;
1373
1374 return 0;
1375}
1376
1377static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1378{
1379 struct ieee80211_local *local = wiphy_priv(wiphy);
1380
1381 drv_rfkill_poll(local);
1382}
1383
1289struct cfg80211_ops mac80211_config_ops = { 1384struct cfg80211_ops mac80211_config_ops = {
1290 .add_virtual_intf = ieee80211_add_iface, 1385 .add_virtual_intf = ieee80211_add_iface,
1291 .del_virtual_intf = ieee80211_del_iface, 1386 .del_virtual_intf = ieee80211_del_iface,
@@ -1322,4 +1417,10 @@ struct cfg80211_ops mac80211_config_ops = {
1322 .assoc = ieee80211_assoc, 1417 .assoc = ieee80211_assoc,
1323 .deauth = ieee80211_deauth, 1418 .deauth = ieee80211_deauth,
1324 .disassoc = ieee80211_disassoc, 1419 .disassoc = ieee80211_disassoc,
1420 .join_ibss = ieee80211_join_ibss,
1421 .leave_ibss = ieee80211_leave_ibss,
1422 .set_wiphy_params = ieee80211_set_wiphy_params,
1423 .set_tx_power = ieee80211_set_tx_power,
1424 .get_tx_power = ieee80211_get_tx_power,
1425 .rfkill_poll = ieee80211_rfkill_poll,
1325}; 1426};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 210b9b6fecd2..11c72311f35b 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -10,6 +10,7 @@
10#include <linux/debugfs.h> 10#include <linux/debugfs.h>
11#include <linux/rtnetlink.h> 11#include <linux/rtnetlink.h>
12#include "ieee80211_i.h" 12#include "ieee80211_i.h"
13#include "driver-ops.h"
13#include "rate.h" 14#include "rate.h"
14#include "debugfs.h" 15#include "debugfs.h"
15 16
@@ -51,14 +52,6 @@ static const struct file_operations name## _ops = { \
51 52
52DEBUGFS_READONLY_FILE(frequency, 20, "%d", 53DEBUGFS_READONLY_FILE(frequency, 20, "%d",
53 local->hw.conf.channel->center_freq); 54 local->hw.conf.channel->center_freq);
54DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
55 local->rts_threshold);
56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
57 local->fragmentation_threshold);
58DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
59 local->hw.conf.short_frame_max_tx_count);
60DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
61 local->hw.conf.long_frame_max_tx_count);
62DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 55DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
63 local->total_ps_buffered); 56 local->total_ps_buffered);
64DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", 57DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
@@ -70,11 +63,10 @@ static ssize_t tsf_read(struct file *file, char __user *user_buf,
70 size_t count, loff_t *ppos) 63 size_t count, loff_t *ppos)
71{ 64{
72 struct ieee80211_local *local = file->private_data; 65 struct ieee80211_local *local = file->private_data;
73 u64 tsf = 0; 66 u64 tsf;
74 char buf[100]; 67 char buf[100];
75 68
76 if (local->ops->get_tsf) 69 tsf = drv_get_tsf(local);
77 tsf = local->ops->get_tsf(local_to_hw(local));
78 70
79 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf); 71 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
80 72
@@ -97,13 +89,13 @@ static ssize_t tsf_write(struct file *file,
97 89
98 if (strncmp(buf, "reset", 5) == 0) { 90 if (strncmp(buf, "reset", 5) == 0) {
99 if (local->ops->reset_tsf) { 91 if (local->ops->reset_tsf) {
100 local->ops->reset_tsf(local_to_hw(local)); 92 drv_reset_tsf(local);
101 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy)); 93 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
102 } 94 }
103 } else { 95 } else {
104 tsf = simple_strtoul(buf, NULL, 0); 96 tsf = simple_strtoul(buf, NULL, 0);
105 if (local->ops->set_tsf) { 97 if (local->ops->set_tsf) {
106 local->ops->set_tsf(local_to_hw(local), tsf); 98 drv_set_tsf(local, tsf);
107 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf); 99 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
108 } 100 }
109 } 101 }
@@ -135,6 +127,42 @@ static const struct file_operations reset_ops = {
135 .open = mac80211_open_file_generic, 127 .open = mac80211_open_file_generic,
136}; 128};
137 129
130static ssize_t noack_read(struct file *file, char __user *user_buf,
131 size_t count, loff_t *ppos)
132{
133 struct ieee80211_local *local = file->private_data;
134 int res;
135 char buf[10];
136
137 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
138
139 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
140}
141
142static ssize_t noack_write(struct file *file,
143 const char __user *user_buf,
144 size_t count, loff_t *ppos)
145{
146 struct ieee80211_local *local = file->private_data;
147 char buf[10];
148 size_t len;
149
150 len = min(count, sizeof(buf) - 1);
151 if (copy_from_user(buf, user_buf, len))
152 return -EFAULT;
153 buf[len] = '\0';
154
155 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
156
157 return count;
158}
159
160static const struct file_operations noack_ops = {
161 .read = noack_read,
162 .write = noack_write,
163 .open = mac80211_open_file_generic
164};
165
138/* statistics stuff */ 166/* statistics stuff */
139 167
140#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ 168#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
@@ -150,14 +178,12 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
150 char buf[20]; 178 char buf[20];
151 int res; 179 int res;
152 180
153 if (!local->ops->get_stats)
154 return -EOPNOTSUPP;
155
156 rtnl_lock(); 181 rtnl_lock();
157 res = local->ops->get_stats(local_to_hw(local), &stats); 182 res = drv_get_stats(local, &stats);
158 rtnl_unlock(); 183 rtnl_unlock();
159 if (!res) 184 if (res)
160 res = printvalue(&stats, buf, sizeof(buf)); 185 return res;
186 res = printvalue(&stats, buf, sizeof(buf));
161 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 187 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
162} 188}
163 189
@@ -269,14 +295,11 @@ void debugfs_hw_add(struct ieee80211_local *local)
269 local->debugfs.keys = debugfs_create_dir("keys", phyd); 295 local->debugfs.keys = debugfs_create_dir("keys", phyd);
270 296
271 DEBUGFS_ADD(frequency); 297 DEBUGFS_ADD(frequency);
272 DEBUGFS_ADD(rts_threshold);
273 DEBUGFS_ADD(fragmentation_threshold);
274 DEBUGFS_ADD(short_retry_limit);
275 DEBUGFS_ADD(long_retry_limit);
276 DEBUGFS_ADD(total_ps_buffered); 298 DEBUGFS_ADD(total_ps_buffered);
277 DEBUGFS_ADD(wep_iv); 299 DEBUGFS_ADD(wep_iv);
278 DEBUGFS_ADD(tsf); 300 DEBUGFS_ADD(tsf);
279 DEBUGFS_ADD_MODE(reset, 0200); 301 DEBUGFS_ADD_MODE(reset, 0200);
302 DEBUGFS_ADD(noack);
280 303
281 statsd = debugfs_create_dir("statistics", phyd); 304 statsd = debugfs_create_dir("statistics", phyd);
282 local->debugfs.statistics = statsd; 305 local->debugfs.statistics = statsd;
@@ -324,14 +347,11 @@ void debugfs_hw_add(struct ieee80211_local *local)
324void debugfs_hw_del(struct ieee80211_local *local) 347void debugfs_hw_del(struct ieee80211_local *local)
325{ 348{
326 DEBUGFS_DEL(frequency); 349 DEBUGFS_DEL(frequency);
327 DEBUGFS_DEL(rts_threshold);
328 DEBUGFS_DEL(fragmentation_threshold);
329 DEBUGFS_DEL(short_retry_limit);
330 DEBUGFS_DEL(long_retry_limit);
331 DEBUGFS_DEL(total_ps_buffered); 350 DEBUGFS_DEL(total_ps_buffered);
332 DEBUGFS_DEL(wep_iv); 351 DEBUGFS_DEL(wep_iv);
333 DEBUGFS_DEL(tsf); 352 DEBUGFS_DEL(tsf);
334 DEBUGFS_DEL(reset); 353 DEBUGFS_DEL(reset);
354 DEBUGFS_DEL(noack);
335 355
336 DEBUGFS_STATS_DEL(transmitted_fragment_count); 356 DEBUGFS_STATS_DEL(transmitted_fragment_count);
337 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 357 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
new file mode 100644
index 000000000000..b13446afd48f
--- /dev/null
+++ b/net/mac80211/driver-ops.h
@@ -0,0 +1,191 @@
1#ifndef __MAC80211_DRIVER_OPS
2#define __MAC80211_DRIVER_OPS
3
4#include <net/mac80211.h>
5#include "ieee80211_i.h"
6
7static inline int drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
8{
9 return local->ops->tx(&local->hw, skb);
10}
11
12static inline int drv_start(struct ieee80211_local *local)
13{
14 return local->ops->start(&local->hw);
15}
16
17static inline void drv_stop(struct ieee80211_local *local)
18{
19 local->ops->stop(&local->hw);
20}
21
22static inline int drv_add_interface(struct ieee80211_local *local,
23 struct ieee80211_if_init_conf *conf)
24{
25 return local->ops->add_interface(&local->hw, conf);
26}
27
28static inline void drv_remove_interface(struct ieee80211_local *local,
29 struct ieee80211_if_init_conf *conf)
30{
31 local->ops->remove_interface(&local->hw, conf);
32}
33
34static inline int drv_config(struct ieee80211_local *local, u32 changed)
35{
36 return local->ops->config(&local->hw, changed);
37}
38
39static inline void drv_bss_info_changed(struct ieee80211_local *local,
40 struct ieee80211_vif *vif,
41 struct ieee80211_bss_conf *info,
42 u32 changed)
43{
44 if (local->ops->bss_info_changed)
45 local->ops->bss_info_changed(&local->hw, vif, info, changed);
46}
47
48static inline void drv_configure_filter(struct ieee80211_local *local,
49 unsigned int changed_flags,
50 unsigned int *total_flags,
51 int mc_count,
52 struct dev_addr_list *mc_list)
53{
54 local->ops->configure_filter(&local->hw, changed_flags, total_flags,
55 mc_count, mc_list);
56}
57
58static inline int drv_set_tim(struct ieee80211_local *local,
59 struct ieee80211_sta *sta, bool set)
60{
61 if (local->ops->set_tim)
62 return local->ops->set_tim(&local->hw, sta, set);
63 return 0;
64}
65
66static inline int drv_set_key(struct ieee80211_local *local,
67 enum set_key_cmd cmd, struct ieee80211_vif *vif,
68 struct ieee80211_sta *sta,
69 struct ieee80211_key_conf *key)
70{
71 return local->ops->set_key(&local->hw, cmd, vif, sta, key);
72}
73
74static inline void drv_update_tkip_key(struct ieee80211_local *local,
75 struct ieee80211_key_conf *conf,
76 const u8 *address, u32 iv32,
77 u16 *phase1key)
78{
79 if (local->ops->update_tkip_key)
80 local->ops->update_tkip_key(&local->hw, conf, address,
81 iv32, phase1key);
82}
83
84static inline int drv_hw_scan(struct ieee80211_local *local,
85 struct cfg80211_scan_request *req)
86{
87 return local->ops->hw_scan(&local->hw, req);
88}
89
90static inline void drv_sw_scan_start(struct ieee80211_local *local)
91{
92 if (local->ops->sw_scan_start)
93 local->ops->sw_scan_start(&local->hw);
94}
95
96static inline void drv_sw_scan_complete(struct ieee80211_local *local)
97{
98 if (local->ops->sw_scan_complete)
99 local->ops->sw_scan_complete(&local->hw);
100}
101
102static inline int drv_get_stats(struct ieee80211_local *local,
103 struct ieee80211_low_level_stats *stats)
104{
105 if (!local->ops->get_stats)
106 return -EOPNOTSUPP;
107 return local->ops->get_stats(&local->hw, stats);
108}
109
110static inline void drv_get_tkip_seq(struct ieee80211_local *local,
111 u8 hw_key_idx, u32 *iv32, u16 *iv16)
112{
113 if (local->ops->get_tkip_seq)
114 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
115}
116
117static inline int drv_set_rts_threshold(struct ieee80211_local *local,
118 u32 value)
119{
120 if (local->ops->set_rts_threshold)
121 return local->ops->set_rts_threshold(&local->hw, value);
122 return 0;
123}
124
125static inline void drv_sta_notify(struct ieee80211_local *local,
126 struct ieee80211_vif *vif,
127 enum sta_notify_cmd cmd,
128 struct ieee80211_sta *sta)
129{
130 if (local->ops->sta_notify)
131 local->ops->sta_notify(&local->hw, vif, cmd, sta);
132}
133
134static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue,
135 const struct ieee80211_tx_queue_params *params)
136{
137 if (local->ops->conf_tx)
138 return local->ops->conf_tx(&local->hw, queue, params);
139 return -EOPNOTSUPP;
140}
141
142static inline int drv_get_tx_stats(struct ieee80211_local *local,
143 struct ieee80211_tx_queue_stats *stats)
144{
145 return local->ops->get_tx_stats(&local->hw, stats);
146}
147
148static inline u64 drv_get_tsf(struct ieee80211_local *local)
149{
150 if (local->ops->get_tsf)
151 return local->ops->get_tsf(&local->hw);
152 return -1ULL;
153}
154
155static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
156{
157 if (local->ops->set_tsf)
158 local->ops->set_tsf(&local->hw, tsf);
159}
160
161static inline void drv_reset_tsf(struct ieee80211_local *local)
162{
163 if (local->ops->reset_tsf)
164 local->ops->reset_tsf(&local->hw);
165}
166
167static inline int drv_tx_last_beacon(struct ieee80211_local *local)
168{
169 if (local->ops->tx_last_beacon)
170 return local->ops->tx_last_beacon(&local->hw);
171 return 1;
172}
173
174static inline int drv_ampdu_action(struct ieee80211_local *local,
175 enum ieee80211_ampdu_mlme_action action,
176 struct ieee80211_sta *sta, u16 tid,
177 u16 *ssn)
178{
179 if (local->ops->ampdu_action)
180 return local->ops->ampdu_action(&local->hw, action,
181 sta, tid, ssn);
182 return -EOPNOTSUPP;
183}
184
185
186static inline void drv_rfkill_poll(struct ieee80211_local *local)
187{
188 if (local->ops->rfkill_poll)
189 local->ops->rfkill_poll(&local->hw);
190}
191#endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/event.c b/net/mac80211/event.c
index 0d95561c0ee0..f288d01a6344 100644
--- a/net/mac80211/event.c
+++ b/net/mac80211/event.c
@@ -12,12 +12,12 @@
12#include "ieee80211_i.h" 12#include "ieee80211_i.h"
13 13
14/* 14/*
15 * indicate a failed Michael MIC to userspace; the passed packet 15 * Indicate a failed Michael MIC to userspace. If the caller knows the TSC of
16 * (in the variable hdr) must be long enough to extract the TKIP 16 * the frame that generated the MIC failure (i.e., if it was provided by the
17 * fields like TSC 17 * driver or is still in the frame), it should provide that information.
18 */ 18 */
19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
20 struct ieee80211_hdr *hdr) 20 struct ieee80211_hdr *hdr, const u8 *tsc)
21{ 21{
22 union iwreq_data wrqu; 22 union iwreq_data wrqu;
23 char *buf = kmalloc(128, GFP_ATOMIC); 23 char *buf = kmalloc(128, GFP_ATOMIC);
@@ -34,8 +34,9 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
34 kfree(buf); 34 kfree(buf);
35 } 35 }
36 36
37 /* 37 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2,
38 * TODO: re-add support for sending MIC failure indication 38 (hdr->addr1[0] & 0x01) ?
39 * with all info via nl80211 39 NL80211_KEYTYPE_GROUP :
40 */ 40 NL80211_KEYTYPE_PAIRWISE,
41 keyidx, tsc);
41} 42}
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index 4e3c72f20de7..0891bfb06996 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -14,7 +14,6 @@
14 */ 14 */
15 15
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <net/wireless.h>
18#include <net/mac80211.h> 17#include <net/mac80211.h>
19#include "ieee80211_i.h" 18#include "ieee80211_i.h"
20#include "rate.h" 19#include "rate.h"
@@ -83,89 +82,6 @@ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
83 ht_cap->mcs.rx_mask[32/8] |= 1; 82 ht_cap->mcs.rx_mask[32/8] |= 1;
84} 83}
85 84
86/*
87 * ieee80211_enable_ht should be called only after the operating band
88 * has been determined as ht configuration depends on the hw's
89 * HT abilities for a specific band.
90 */
91u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
92 struct ieee80211_ht_info *hti,
93 u16 ap_ht_cap_flags)
94{
95 struct ieee80211_local *local = sdata->local;
96 struct ieee80211_supported_band *sband;
97 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
98 struct ieee80211_bss_ht_conf ht;
99 struct sta_info *sta;
100 u32 changed = 0;
101 bool enable_ht = true, ht_changed;
102 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
103
104 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
105
106 memset(&ht, 0, sizeof(ht));
107
108 /* HT is not supported */
109 if (!sband->ht_cap.ht_supported)
110 enable_ht = false;
111
112 /* check that channel matches the right operating channel */
113 if (local->hw.conf.channel->center_freq !=
114 ieee80211_channel_to_frequency(hti->control_chan))
115 enable_ht = false;
116
117 if (enable_ht) {
118 channel_type = NL80211_CHAN_HT20;
119
120 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
121 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
122 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
123 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
124 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
125 channel_type = NL80211_CHAN_HT40PLUS;
126 break;
127 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
128 channel_type = NL80211_CHAN_HT40MINUS;
129 break;
130 }
131 }
132 }
133
134 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
135 channel_type != local->hw.conf.channel_type;
136
137 local->oper_channel_type = channel_type;
138
139 if (ht_changed) {
140 /* channel_type change automatically detected */
141 ieee80211_hw_config(local, 0);
142
143 rcu_read_lock();
144
145 sta = sta_info_get(local, ifmgd->bssid);
146 if (sta)
147 rate_control_rate_update(local, sband, sta,
148 IEEE80211_RC_HT_CHANGED);
149
150 rcu_read_unlock();
151
152 }
153
154 /* disable HT */
155 if (!enable_ht)
156 return 0;
157
158 ht.operation_mode = le16_to_cpu(hti->operation_mode);
159
160 /* if bss configuration changed store the new one */
161 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
162 changed |= BSS_CHANGED_HT;
163 sdata->vif.bss_conf.ht = ht;
164 }
165
166 return changed;
167}
168
169void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta) 85void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta)
170{ 86{
171 int i; 87 int i;
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 3201e1f96365..0b30277eb366 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -22,6 +22,7 @@
22#include <asm/unaligned.h> 22#include <asm/unaligned.h>
23 23
24#include "ieee80211_i.h" 24#include "ieee80211_i.h"
25#include "driver-ops.h"
25#include "rate.h" 26#include "rate.h"
26 27
27#define IEEE80211_SCAN_INTERVAL (2 * HZ) 28#define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -59,74 +60,65 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
59 sdata->u.ibss.bssid, 0); 60 sdata->u.ibss.bssid, 0);
60} 61}
61 62
62static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 63static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
63 const u8 *bssid, const int beacon_int, 64 const u8 *bssid, const int beacon_int,
64 const int freq, 65 struct ieee80211_channel *chan,
65 const size_t supp_rates_len, 66 const u32 basic_rates,
66 const u8 *supp_rates, 67 const u16 capability, u64 tsf)
67 const u16 capability, u64 tsf)
68{ 68{
69 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 69 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
70 struct ieee80211_local *local = sdata->local; 70 struct ieee80211_local *local = sdata->local;
71 int res = 0, rates, i, j; 71 int rates, i;
72 struct sk_buff *skb; 72 struct sk_buff *skb;
73 struct ieee80211_mgmt *mgmt; 73 struct ieee80211_mgmt *mgmt;
74 u8 *pos; 74 u8 *pos;
75 struct ieee80211_supported_band *sband; 75 struct ieee80211_supported_band *sband;
76 union iwreq_data wrqu; 76 u32 bss_change;
77 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
77 78
78 if (local->ops->reset_tsf) { 79 /* Reset own TSF to allow time synchronization work. */
79 /* Reset own TSF to allow time synchronization work. */ 80 drv_reset_tsf(local);
80 local->ops->reset_tsf(local_to_hw(local));
81 }
82 81
83 if ((ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET) && 82 skb = ifibss->skb;
84 memcmp(ifibss->bssid, bssid, ETH_ALEN) == 0) 83 rcu_assign_pointer(ifibss->presp, NULL);
85 return res; 84 synchronize_rcu();
85 skb->data = skb->head;
86 skb->len = 0;
87 skb_reset_tail_pointer(skb);
88 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
86 89
87 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); 90 if (memcmp(ifibss->bssid, bssid, ETH_ALEN))
88 if (!skb) { 91 sta_info_flush(sdata->local, sdata);
89 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
90 "response\n", sdata->dev->name);
91 return -ENOMEM;
92 }
93
94 if (!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET)) {
95 /* Remove possible STA entries from other IBSS networks. */
96 sta_info_flush_delayed(sdata);
97 }
98 92
99 memcpy(ifibss->bssid, bssid, ETH_ALEN); 93 memcpy(ifibss->bssid, bssid, ETH_ALEN);
100 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
101 if (res)
102 return res;
103
104 local->hw.conf.beacon_int = beacon_int >= 10 ? beacon_int : 10;
105 94
106 sdata->drop_unencrypted = capability & 95 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
107 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
108 96
109 res = ieee80211_set_freq(sdata, freq); 97 local->oper_channel = chan;
98 local->oper_channel_type = NL80211_CHAN_NO_HT;
99 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
110 100
111 if (res) 101 sband = local->hw.wiphy->bands[chan->band];
112 return res;
113 102
114 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 103 /* build supported rates array */
104 pos = supp_rates;
105 for (i = 0; i < sband->n_bitrates; i++) {
106 int rate = sband->bitrates[i].bitrate;
107 u8 basic = 0;
108 if (basic_rates & BIT(i))
109 basic = 0x80;
110 *pos++ = basic | (u8) (rate / 5);
111 }
115 112
116 /* Build IBSS probe response */ 113 /* Build IBSS probe response */
117 114 mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon));
118 skb_reserve(skb, local->hw.extra_tx_headroom);
119
120 mgmt = (struct ieee80211_mgmt *)
121 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
122 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); 115 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
123 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 116 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
124 IEEE80211_STYPE_PROBE_RESP); 117 IEEE80211_STYPE_PROBE_RESP);
125 memset(mgmt->da, 0xff, ETH_ALEN); 118 memset(mgmt->da, 0xff, ETH_ALEN);
126 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 119 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
127 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); 120 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
128 mgmt->u.beacon.beacon_int = 121 mgmt->u.beacon.beacon_int = cpu_to_le16(beacon_int);
129 cpu_to_le16(local->hw.conf.beacon_int);
130 mgmt->u.beacon.timestamp = cpu_to_le64(tsf); 122 mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
131 mgmt->u.beacon.capab_info = cpu_to_le16(capability); 123 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
132 124
@@ -135,7 +127,7 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
135 *pos++ = ifibss->ssid_len; 127 *pos++ = ifibss->ssid_len;
136 memcpy(pos, ifibss->ssid, ifibss->ssid_len); 128 memcpy(pos, ifibss->ssid, ifibss->ssid_len);
137 129
138 rates = supp_rates_len; 130 rates = sband->n_bitrates;
139 if (rates > 8) 131 if (rates > 8)
140 rates = 8; 132 rates = 8;
141 pos = skb_put(skb, 2 + rates); 133 pos = skb_put(skb, 2 + rates);
@@ -147,7 +139,7 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
147 pos = skb_put(skb, 2 + 1); 139 pos = skb_put(skb, 2 + 1);
148 *pos++ = WLAN_EID_DS_PARAMS; 140 *pos++ = WLAN_EID_DS_PARAMS;
149 *pos++ = 1; 141 *pos++ = 1;
150 *pos++ = ieee80211_frequency_to_channel(freq); 142 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
151 } 143 }
152 144
153 pos = skb_put(skb, 2 + 2); 145 pos = skb_put(skb, 2 + 2);
@@ -157,51 +149,73 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
157 *pos++ = 0; 149 *pos++ = 0;
158 *pos++ = 0; 150 *pos++ = 0;
159 151
160 if (supp_rates_len > 8) { 152 if (sband->n_bitrates > 8) {
161 rates = supp_rates_len - 8; 153 rates = sband->n_bitrates - 8;
162 pos = skb_put(skb, 2 + rates); 154 pos = skb_put(skb, 2 + rates);
163 *pos++ = WLAN_EID_EXT_SUPP_RATES; 155 *pos++ = WLAN_EID_EXT_SUPP_RATES;
164 *pos++ = rates; 156 *pos++ = rates;
165 memcpy(pos, &supp_rates[8], rates); 157 memcpy(pos, &supp_rates[8], rates);
166 } 158 }
167 159
168 ifibss->probe_resp = skb; 160 if (ifibss->ie_len)
161 memcpy(skb_put(skb, ifibss->ie_len),
162 ifibss->ie, ifibss->ie_len);
169 163
170 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON | 164 rcu_assign_pointer(ifibss->presp, skb);
171 IEEE80211_IFCC_BEACON_ENABLED);
172 165
166 sdata->vif.bss_conf.beacon_int = beacon_int;
167 bss_change = BSS_CHANGED_BEACON_INT;
168 bss_change |= ieee80211_reset_erp_info(sdata);
169 bss_change |= BSS_CHANGED_BSSID;
170 bss_change |= BSS_CHANGED_BEACON;
171 bss_change |= BSS_CHANGED_BEACON_ENABLED;
172 ieee80211_bss_info_change_notify(sdata, bss_change);
173 173
174 rates = 0; 174 ieee80211_sta_def_wmm_params(sdata, sband->n_bitrates, supp_rates);
175 for (i = 0; i < supp_rates_len; i++) {
176 int bitrate = (supp_rates[i] & 0x7f) * 5;
177 for (j = 0; j < sband->n_bitrates; j++)
178 if (sband->bitrates[j].bitrate == bitrate)
179 rates |= BIT(j);
180 }
181 175
182 ieee80211_sta_def_wmm_params(sdata, supp_rates_len, supp_rates);
183
184 ifibss->flags |= IEEE80211_IBSS_PREV_BSSID_SET;
185 ifibss->state = IEEE80211_IBSS_MLME_JOINED; 176 ifibss->state = IEEE80211_IBSS_MLME_JOINED;
186 mod_timer(&ifibss->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); 177 mod_timer(&ifibss->timer,
187 178 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
188 memset(&wrqu, 0, sizeof(wrqu));
189 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
190 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
191 179
192 return res; 180 cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
181 mgmt, skb->len, 0, GFP_KERNEL);
182 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
193} 183}
194 184
195static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 185static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
196 struct ieee80211_bss *bss) 186 struct ieee80211_bss *bss)
197{ 187{
198 return __ieee80211_sta_join_ibss(sdata, 188 struct ieee80211_supported_band *sband;
199 bss->cbss.bssid, 189 u32 basic_rates;
200 bss->cbss.beacon_interval, 190 int i, j;
201 bss->cbss.channel->center_freq, 191 u16 beacon_int = bss->cbss.beacon_interval;
202 bss->supp_rates_len, bss->supp_rates, 192
203 bss->cbss.capability, 193 if (beacon_int < 10)
204 bss->cbss.tsf); 194 beacon_int = 10;
195
196 sband = sdata->local->hw.wiphy->bands[bss->cbss.channel->band];
197
198 basic_rates = 0;
199
200 for (i = 0; i < bss->supp_rates_len; i++) {
201 int rate = (bss->supp_rates[i] & 0x7f) * 5;
202 bool is_basic = !!(bss->supp_rates[i] & 0x80);
203
204 for (j = 0; j < sband->n_bitrates; j++) {
205 if (sband->bitrates[j].bitrate == rate) {
206 if (is_basic)
207 basic_rates |= BIT(j);
208 break;
209 }
210 }
211 }
212
213 __ieee80211_sta_join_ibss(sdata, bss->cbss.bssid,
214 beacon_int,
215 bss->cbss.channel,
216 basic_rates,
217 bss->cbss.capability,
218 bss->cbss.tsf);
205} 219}
206 220
207static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 221static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
@@ -277,7 +291,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
277 goto put_bss; 291 goto put_bss;
278 292
279 /* we use a fixed BSSID */ 293 /* we use a fixed BSSID */
280 if (sdata->u.ibss.flags & IEEE80211_IBSS_BSSID_SET) 294 if (sdata->u.ibss.bssid)
281 goto put_bss; 295 goto put_bss;
282 296
283 /* not an IBSS */ 297 /* not an IBSS */
@@ -322,12 +336,13 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
322 bitrates[rx_status->rate_idx].bitrate; 336 bitrates[rx_status->rate_idx].bitrate;
323 337
324 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate); 338 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
325 } else if (local && local->ops && local->ops->get_tsf) 339 } else {
326 /* second best option: get current TSF */ 340 /*
327 rx_timestamp = local->ops->get_tsf(local_to_hw(local)); 341 * second best option: get current TSF
328 else 342 * (will return -1 if not supported)
329 /* can't merge without knowing the TSF */ 343 */
330 rx_timestamp = -1LLU; 344 rx_timestamp = drv_get_tsf(local);
345 }
331 346
332#ifdef CONFIG_MAC80211_IBSS_DEBUG 347#ifdef CONFIG_MAC80211_IBSS_DEBUG
333 printk(KERN_DEBUG "RX beacon SA=%pM BSSID=" 348 printk(KERN_DEBUG "RX beacon SA=%pM BSSID="
@@ -369,13 +384,14 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
369 struct sta_info *sta; 384 struct sta_info *sta;
370 int band = local->hw.conf.channel->band; 385 int band = local->hw.conf.channel->band;
371 386
372 /* TODO: Could consider removing the least recently used entry and 387 /*
373 * allow new one to be added. */ 388 * XXX: Consider removing the least recently used entry and
389 * allow new one to be added.
390 */
374 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 391 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
375 if (net_ratelimit()) { 392 if (net_ratelimit())
376 printk(KERN_DEBUG "%s: No room for a new IBSS STA " 393 printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
377 "entry %pM\n", sdata->dev->name, addr); 394 sdata->dev->name, addr);
378 }
379 return NULL; 395 return NULL;
380 } 396 }
381 397
@@ -432,41 +448,33 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
432{ 448{
433 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 449 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
434 450
435 mod_timer(&ifibss->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); 451 mod_timer(&ifibss->timer,
452 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
436 453
437 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); 454 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
455
438 if (ieee80211_sta_active_ibss(sdata)) 456 if (ieee80211_sta_active_ibss(sdata))
439 return; 457 return;
440 458
441 if ((ifibss->flags & IEEE80211_IBSS_BSSID_SET) && 459 if (ifibss->fixed_channel)
442 (!(ifibss->flags & IEEE80211_IBSS_AUTO_CHANNEL_SEL)))
443 return; 460 return;
444 461
445 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " 462 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
446 "IBSS networks with same SSID (merge)\n", sdata->dev->name); 463 "IBSS networks with same SSID (merge)\n", sdata->dev->name);
447 464
448 /* XXX maybe racy? */ 465 ieee80211_request_internal_scan(sdata, ifibss->ssid, ifibss->ssid_len);
449 if (sdata->local->scan_req)
450 return;
451
452 memcpy(sdata->local->int_scan_req.ssids[0].ssid,
453 ifibss->ssid, IEEE80211_MAX_SSID_LEN);
454 sdata->local->int_scan_req.ssids[0].ssid_len = ifibss->ssid_len;
455 ieee80211_request_scan(sdata, &sdata->local->int_scan_req);
456} 466}
457 467
458static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) 468static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
459{ 469{
460 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 470 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
461 struct ieee80211_local *local = sdata->local; 471 struct ieee80211_local *local = sdata->local;
462 struct ieee80211_supported_band *sband; 472 struct ieee80211_supported_band *sband;
463 u8 *pos;
464 u8 bssid[ETH_ALEN]; 473 u8 bssid[ETH_ALEN];
465 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
466 u16 capability; 474 u16 capability;
467 int i; 475 int i;
468 476
469 if (ifibss->flags & IEEE80211_IBSS_BSSID_SET) { 477 if (ifibss->fixed_bssid) {
470 memcpy(bssid, ifibss->bssid, ETH_ALEN); 478 memcpy(bssid, ifibss->bssid, ETH_ALEN);
471 } else { 479 } else {
472 /* Generate random, not broadcast, locally administered BSSID. Mix in 480 /* Generate random, not broadcast, locally administered BSSID. Mix in
@@ -482,10 +490,7 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
482 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", 490 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
483 sdata->dev->name, bssid); 491 sdata->dev->name, bssid);
484 492
485 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 493 sband = local->hw.wiphy->bands[ifibss->channel->band];
486
487 if (local->hw.conf.beacon_int == 0)
488 local->hw.conf.beacon_int = 100;
489 494
490 capability = WLAN_CAPABILITY_IBSS; 495 capability = WLAN_CAPABILITY_IBSS;
491 496
@@ -494,29 +499,20 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
494 else 499 else
495 sdata->drop_unencrypted = 0; 500 sdata->drop_unencrypted = 0;
496 501
497 pos = supp_rates; 502 __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
498 for (i = 0; i < sband->n_bitrates; i++) { 503 ifibss->channel, 3, /* first two are basic */
499 int rate = sband->bitrates[i].bitrate; 504 capability, 0);
500 *pos++ = (u8) (rate / 5);
501 }
502
503 return __ieee80211_sta_join_ibss(sdata,
504 bssid, local->hw.conf.beacon_int,
505 local->hw.conf.channel->center_freq,
506 sband->n_bitrates, supp_rates,
507 capability, 0);
508} 505}
509 506
510static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) 507static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
511{ 508{
512 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 509 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
513 struct ieee80211_local *local = sdata->local; 510 struct ieee80211_local *local = sdata->local;
514 struct ieee80211_bss *bss; 511 struct ieee80211_bss *bss;
512 struct ieee80211_channel *chan = NULL;
515 const u8 *bssid = NULL; 513 const u8 *bssid = NULL;
516 int active_ibss; 514 int active_ibss;
517 515 u16 capability;
518 if (ifibss->ssid_len == 0)
519 return -EINVAL;
520 516
521 active_ibss = ieee80211_sta_active_ibss(sdata); 517 active_ibss = ieee80211_sta_active_ibss(sdata);
522#ifdef CONFIG_MAC80211_IBSS_DEBUG 518#ifdef CONFIG_MAC80211_IBSS_DEBUG
@@ -525,14 +521,23 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
525#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 521#endif /* CONFIG_MAC80211_IBSS_DEBUG */
526 522
527 if (active_ibss) 523 if (active_ibss)
528 return 0; 524 return;
529 525
530 if (ifibss->flags & IEEE80211_IBSS_BSSID_SET) 526 capability = WLAN_CAPABILITY_IBSS;
527 if (sdata->default_key)
528 capability |= WLAN_CAPABILITY_PRIVACY;
529
530 if (ifibss->fixed_bssid)
531 bssid = ifibss->bssid; 531 bssid = ifibss->bssid;
532 bss = (void *)cfg80211_get_bss(local->hw.wiphy, NULL, bssid, 532 if (ifibss->fixed_channel)
533 chan = ifibss->channel;
534 if (!is_zero_ether_addr(ifibss->bssid))
535 bssid = ifibss->bssid;
536 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, bssid,
533 ifibss->ssid, ifibss->ssid_len, 537 ifibss->ssid, ifibss->ssid_len,
534 WLAN_CAPABILITY_IBSS, 538 WLAN_CAPABILITY_IBSS |
535 WLAN_CAPABILITY_IBSS); 539 WLAN_CAPABILITY_PRIVACY,
540 capability);
536 541
537#ifdef CONFIG_MAC80211_IBSS_DEBUG 542#ifdef CONFIG_MAC80211_IBSS_DEBUG
538 if (bss) 543 if (bss)
@@ -540,18 +545,14 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
540 "%pM\n", bss->cbss.bssid, ifibss->bssid); 545 "%pM\n", bss->cbss.bssid, ifibss->bssid);
541#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 546#endif /* CONFIG_MAC80211_IBSS_DEBUG */
542 547
543 if (bss && 548 if (bss && memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN)) {
544 (!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET) ||
545 memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN))) {
546 int ret;
547
548 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" 549 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
549 " based on configured SSID\n", 550 " based on configured SSID\n",
550 sdata->dev->name, bss->cbss.bssid); 551 sdata->dev->name, bss->cbss.bssid);
551 552
552 ret = ieee80211_sta_join_ibss(sdata, bss); 553 ieee80211_sta_join_ibss(sdata, bss);
553 ieee80211_rx_bss_put(local, bss); 554 ieee80211_rx_bss_put(local, bss);
554 return ret; 555 return;
555 } else if (bss) 556 } else if (bss)
556 ieee80211_rx_bss_put(local, bss); 557 ieee80211_rx_bss_put(local, bss);
557 558
@@ -562,29 +563,24 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
562 /* Selected IBSS not found in current scan results - try to scan */ 563 /* Selected IBSS not found in current scan results - try to scan */
563 if (ifibss->state == IEEE80211_IBSS_MLME_JOINED && 564 if (ifibss->state == IEEE80211_IBSS_MLME_JOINED &&
564 !ieee80211_sta_active_ibss(sdata)) { 565 !ieee80211_sta_active_ibss(sdata)) {
565 mod_timer(&ifibss->timer, jiffies + 566 mod_timer(&ifibss->timer,
566 IEEE80211_IBSS_MERGE_INTERVAL); 567 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
567 } else if (time_after(jiffies, local->last_scan_completed + 568 } else if (time_after(jiffies, ifibss->last_scan_completed +
568 IEEE80211_SCAN_INTERVAL)) { 569 IEEE80211_SCAN_INTERVAL)) {
569 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " 570 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
570 "join\n", sdata->dev->name); 571 "join\n", sdata->dev->name);
571 572
572 /* XXX maybe racy? */ 573 ieee80211_request_internal_scan(sdata, ifibss->ssid,
573 if (local->scan_req) 574 ifibss->ssid_len);
574 return -EBUSY;
575
576 memcpy(local->int_scan_req.ssids[0].ssid,
577 ifibss->ssid, IEEE80211_MAX_SSID_LEN);
578 local->int_scan_req.ssids[0].ssid_len = ifibss->ssid_len;
579 return ieee80211_request_scan(sdata, &local->int_scan_req);
580 } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) { 575 } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) {
581 int interval = IEEE80211_SCAN_INTERVAL; 576 int interval = IEEE80211_SCAN_INTERVAL;
582 577
583 if (time_after(jiffies, ifibss->ibss_join_req + 578 if (time_after(jiffies, ifibss->ibss_join_req +
584 IEEE80211_IBSS_JOIN_TIMEOUT)) { 579 IEEE80211_IBSS_JOIN_TIMEOUT)) {
585 if (!(local->oper_channel->flags & 580 if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) {
586 IEEE80211_CHAN_NO_IBSS)) 581 ieee80211_sta_create_ibss(sdata);
587 return ieee80211_sta_create_ibss(sdata); 582 return;
583 }
588 printk(KERN_DEBUG "%s: IBSS not allowed on" 584 printk(KERN_DEBUG "%s: IBSS not allowed on"
589 " %d MHz\n", sdata->dev->name, 585 " %d MHz\n", sdata->dev->name,
590 local->hw.conf.channel->center_freq); 586 local->hw.conf.channel->center_freq);
@@ -595,11 +591,9 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
595 } 591 }
596 592
597 ifibss->state = IEEE80211_IBSS_MLME_SEARCH; 593 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
598 mod_timer(&ifibss->timer, jiffies + interval); 594 mod_timer(&ifibss->timer,
599 return 0; 595 round_jiffies(jiffies + interval));
600 } 596 }
601
602 return 0;
603} 597}
604 598
605static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, 599static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
@@ -614,13 +608,10 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
614 u8 *pos, *end; 608 u8 *pos, *end;
615 609
616 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || 610 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED ||
617 len < 24 + 2 || !ifibss->probe_resp) 611 len < 24 + 2 || !ifibss->presp)
618 return; 612 return;
619 613
620 if (local->ops->tx_last_beacon) 614 tx_last_beacon = drv_tx_last_beacon(local);
621 tx_last_beacon = local->ops->tx_last_beacon(local_to_hw(local));
622 else
623 tx_last_beacon = 1;
624 615
625#ifdef CONFIG_MAC80211_IBSS_DEBUG 616#ifdef CONFIG_MAC80211_IBSS_DEBUG
626 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" 617 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM"
@@ -649,13 +640,13 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
649 } 640 }
650 if (pos[1] != 0 && 641 if (pos[1] != 0 &&
651 (pos[1] != ifibss->ssid_len || 642 (pos[1] != ifibss->ssid_len ||
652 memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len) != 0)) { 643 !memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) {
653 /* Ignore ProbeReq for foreign SSID */ 644 /* Ignore ProbeReq for foreign SSID */
654 return; 645 return;
655 } 646 }
656 647
657 /* Reply with ProbeResp */ 648 /* Reply with ProbeResp */
658 skb = skb_copy(ifibss->probe_resp, GFP_KERNEL); 649 skb = skb_copy(ifibss->presp, GFP_KERNEL);
659 if (!skb) 650 if (!skb)
660 return; 651 return;
661 652
@@ -746,6 +737,9 @@ static void ieee80211_ibss_work(struct work_struct *work)
746 struct ieee80211_if_ibss *ifibss; 737 struct ieee80211_if_ibss *ifibss;
747 struct sk_buff *skb; 738 struct sk_buff *skb;
748 739
740 if (WARN_ON(local->suspended))
741 return;
742
749 if (!netif_running(sdata->dev)) 743 if (!netif_running(sdata->dev))
750 return; 744 return;
751 745
@@ -782,101 +776,63 @@ static void ieee80211_ibss_timer(unsigned long data)
782 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 776 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
783 struct ieee80211_local *local = sdata->local; 777 struct ieee80211_local *local = sdata->local;
784 778
779 if (local->quiescing) {
780 ifibss->timer_running = true;
781 return;
782 }
783
785 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request); 784 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request);
786 queue_work(local->hw.workqueue, &ifibss->work); 785 queue_work(local->hw.workqueue, &ifibss->work);
787} 786}
788 787
789void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata) 788#ifdef CONFIG_PM
789void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata)
790{ 790{
791 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 791 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
792 792
793 INIT_WORK(&ifibss->work, ieee80211_ibss_work); 793 cancel_work_sync(&ifibss->work);
794 setup_timer(&ifibss->timer, ieee80211_ibss_timer, 794 if (del_timer_sync(&ifibss->timer))
795 (unsigned long) sdata); 795 ifibss->timer_running = true;
796 skb_queue_head_init(&ifibss->skb_queue);
797
798 ifibss->flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
799 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
800} 796}
801 797
802int ieee80211_ibss_commit(struct ieee80211_sub_if_data *sdata) 798void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata)
803{ 799{
804 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 800 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
805 801
806 ifibss->flags &= ~IEEE80211_IBSS_PREV_BSSID_SET; 802 if (ifibss->timer_running) {
807 803 add_timer(&ifibss->timer);
808 if (ifibss->ssid_len) 804 ifibss->timer_running = false;
809 ifibss->flags |= IEEE80211_IBSS_SSID_SET;
810 else
811 ifibss->flags &= ~IEEE80211_IBSS_SSID_SET;
812
813 ifibss->ibss_join_req = jiffies;
814 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
815 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request);
816
817 return 0;
818}
819
820int ieee80211_ibss_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
821{
822 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
823
824 if (len > IEEE80211_MAX_SSID_LEN)
825 return -EINVAL;
826
827 if (ifibss->ssid_len != len || memcmp(ifibss->ssid, ssid, len) != 0) {
828 memset(ifibss->ssid, 0, sizeof(ifibss->ssid));
829 memcpy(ifibss->ssid, ssid, len);
830 ifibss->ssid_len = len;
831 } 805 }
832
833 return ieee80211_ibss_commit(sdata);
834}
835
836int ieee80211_ibss_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
837{
838 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
839
840 memcpy(ssid, ifibss->ssid, ifibss->ssid_len);
841 *len = ifibss->ssid_len;
842
843 return 0;
844} 806}
807#endif
845 808
846int ieee80211_ibss_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) 809void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
847{ 810{
848 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 811 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
849 812
850 if (is_valid_ether_addr(bssid)) { 813 INIT_WORK(&ifibss->work, ieee80211_ibss_work);
851 memcpy(ifibss->bssid, bssid, ETH_ALEN); 814 setup_timer(&ifibss->timer, ieee80211_ibss_timer,
852 ifibss->flags |= IEEE80211_IBSS_BSSID_SET; 815 (unsigned long) sdata);
853 } else { 816 skb_queue_head_init(&ifibss->skb_queue);
854 memset(ifibss->bssid, 0, ETH_ALEN);
855 ifibss->flags &= ~IEEE80211_IBSS_BSSID_SET;
856 }
857
858 if (netif_running(sdata->dev)) {
859 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
860 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
861 "the low-level driver\n", sdata->dev->name);
862 }
863 }
864
865 return ieee80211_ibss_commit(sdata);
866} 817}
867 818
868/* scan finished notification */ 819/* scan finished notification */
869void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) 820void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
870{ 821{
871 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 822 struct ieee80211_sub_if_data *sdata;
872 struct ieee80211_if_ibss *ifibss; 823
873 824 mutex_lock(&local->iflist_mtx);
874 if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) { 825 list_for_each_entry(sdata, &local->interfaces, list) {
875 ifibss = &sdata->u.ibss; 826 if (!netif_running(sdata->dev))
876 if ((!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET)) || 827 continue;
877 !ieee80211_sta_active_ibss(sdata)) 828 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
878 ieee80211_sta_find_ibss(sdata); 829 continue;
830 if (!sdata->u.ibss.ssid_len)
831 continue;
832 sdata->u.ibss.last_scan_completed = jiffies;
833 ieee80211_sta_find_ibss(sdata);
879 } 834 }
835 mutex_unlock(&local->iflist_mtx);
880} 836}
881 837
882ieee80211_rx_result 838ieee80211_rx_result
@@ -906,3 +862,86 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
906 862
907 return RX_DROP_MONITOR; 863 return RX_DROP_MONITOR;
908} 864}
865
866int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
867 struct cfg80211_ibss_params *params)
868{
869 struct sk_buff *skb;
870
871 if (params->bssid) {
872 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
873 sdata->u.ibss.fixed_bssid = true;
874 } else
875 sdata->u.ibss.fixed_bssid = false;
876
877 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
878
879 sdata->u.ibss.channel = params->channel;
880 sdata->u.ibss.fixed_channel = params->channel_fixed;
881
882 if (params->ie) {
883 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
884 GFP_KERNEL);
885 if (sdata->u.ibss.ie)
886 sdata->u.ibss.ie_len = params->ie_len;
887 }
888
889 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
890 36 /* bitrates */ +
891 34 /* SSID */ +
892 3 /* DS params */ +
893 4 /* IBSS params */ +
894 params->ie_len);
895 if (!skb)
896 return -ENOMEM;
897
898 sdata->u.ibss.skb = skb;
899 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
900 sdata->u.ibss.ibss_join_req = jiffies;
901
902 memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
903
904 /*
905 * The ssid_len setting below is used to see whether
906 * we are active, and we need all other settings
907 * before that may get visible.
908 */
909 mb();
910
911 sdata->u.ibss.ssid_len = params->ssid_len;
912
913 ieee80211_recalc_idle(sdata->local);
914
915 set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
916 queue_work(sdata->local->hw.workqueue, &sdata->u.ibss.work);
917
918 return 0;
919}
920
921int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
922{
923 struct sk_buff *skb;
924
925 del_timer_sync(&sdata->u.ibss.timer);
926 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
927 cancel_work_sync(&sdata->u.ibss.work);
928 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
929
930 sta_info_flush(sdata->local, sdata);
931
932 /* remove beacon */
933 kfree(sdata->u.ibss.ie);
934 skb = sdata->u.ibss.presp;
935 rcu_assign_pointer(sdata->u.ibss.presp, NULL);
936 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
937 synchronize_rcu();
938 kfree_skb(skb);
939
940 skb_queue_purge(&sdata->u.ibss.skb_queue);
941 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
942 sdata->u.ibss.ssid_len = 0;
943
944 ieee80211_recalc_idle(sdata->local);
945
946 return 0;
947}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index e6ed78cb16b3..4dbc28964196 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -24,7 +24,6 @@
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <net/cfg80211.h> 26#include <net/cfg80211.h>
27#include <net/wireless.h>
28#include <net/iw_handler.h> 27#include <net/iw_handler.h>
29#include <net/mac80211.h> 28#include <net/mac80211.h>
30#include "key.h" 29#include "key.h"
@@ -236,7 +235,7 @@ struct mesh_preq_queue {
236#define IEEE80211_STA_ASSOCIATED BIT(4) 235#define IEEE80211_STA_ASSOCIATED BIT(4)
237#define IEEE80211_STA_PROBEREQ_POLL BIT(5) 236#define IEEE80211_STA_PROBEREQ_POLL BIT(5)
238#define IEEE80211_STA_CREATE_IBSS BIT(6) 237#define IEEE80211_STA_CREATE_IBSS BIT(6)
239/* hole at 7, please re-use */ 238#define IEEE80211_STA_CONTROL_PORT BIT(7)
240#define IEEE80211_STA_WMM_ENABLED BIT(8) 239#define IEEE80211_STA_WMM_ENABLED BIT(8)
241/* hole at 9, please re-use */ 240/* hole at 9, please re-use */
242#define IEEE80211_STA_AUTO_SSID_SEL BIT(10) 241#define IEEE80211_STA_AUTO_SSID_SEL BIT(10)
@@ -249,9 +248,8 @@ struct mesh_preq_queue {
249#define IEEE80211_STA_EXT_SME BIT(17) 248#define IEEE80211_STA_EXT_SME BIT(17)
250/* flags for MLME request */ 249/* flags for MLME request */
251#define IEEE80211_STA_REQ_SCAN 0 250#define IEEE80211_STA_REQ_SCAN 0
252#define IEEE80211_STA_REQ_DIRECT_PROBE 1 251#define IEEE80211_STA_REQ_AUTH 1
253#define IEEE80211_STA_REQ_AUTH 2 252#define IEEE80211_STA_REQ_RUN 2
254#define IEEE80211_STA_REQ_RUN 3
255 253
256/* bitfield of allowed auth algs */ 254/* bitfield of allowed auth algs */
257#define IEEE80211_AUTH_ALG_OPEN BIT(0) 255#define IEEE80211_AUTH_ALG_OPEN BIT(0)
@@ -295,6 +293,9 @@ struct ieee80211_if_managed {
295 int auth_tries; /* retries for auth req */ 293 int auth_tries; /* retries for auth req */
296 int assoc_tries; /* retries for assoc req */ 294 int assoc_tries; /* retries for assoc req */
297 295
296 unsigned long timers_running; /* used for quiesce/restart */
297 bool powersave; /* powersave requested for this iface */
298
298 unsigned long request; 299 unsigned long request;
299 300
300 unsigned long last_probe; 301 unsigned long last_probe;
@@ -306,6 +307,8 @@ struct ieee80211_if_managed {
306 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */ 307 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
307 int auth_transaction; 308 int auth_transaction;
308 309
310 u32 beacon_crc;
311
309 enum { 312 enum {
310 IEEE80211_MFP_DISABLED, 313 IEEE80211_MFP_DISABLED,
311 IEEE80211_MFP_OPTIONAL, 314 IEEE80211_MFP_OPTIONAL,
@@ -319,14 +322,6 @@ struct ieee80211_if_managed {
319 size_t sme_auth_ie_len; 322 size_t sme_auth_ie_len;
320}; 323};
321 324
322enum ieee80211_ibss_flags {
323 IEEE80211_IBSS_AUTO_CHANNEL_SEL = BIT(0),
324 IEEE80211_IBSS_AUTO_BSSID_SEL = BIT(1),
325 IEEE80211_IBSS_BSSID_SET = BIT(2),
326 IEEE80211_IBSS_PREV_BSSID_SET = BIT(3),
327 IEEE80211_IBSS_SSID_SET = BIT(4),
328};
329
330enum ieee80211_ibss_request { 325enum ieee80211_ibss_request {
331 IEEE80211_IBSS_REQ_RUN = 0, 326 IEEE80211_IBSS_REQ_RUN = 0,
332}; 327};
@@ -337,17 +332,23 @@ struct ieee80211_if_ibss {
337 332
338 struct sk_buff_head skb_queue; 333 struct sk_buff_head skb_queue;
339 334
340 u8 ssid[IEEE80211_MAX_SSID_LEN]; 335 unsigned long request;
341 u8 ssid_len; 336 unsigned long last_scan_completed;
342 337
343 u32 flags; 338 bool timer_running;
344 339
345 u8 bssid[ETH_ALEN]; 340 bool fixed_bssid;
341 bool fixed_channel;
346 342
347 unsigned long request; 343 u8 bssid[ETH_ALEN];
344 u8 ssid[IEEE80211_MAX_SSID_LEN];
345 u8 ssid_len, ie_len;
346 u8 *ie;
347 struct ieee80211_channel *channel;
348 348
349 unsigned long ibss_join_req; 349 unsigned long ibss_join_req;
350 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */ 350 /* probe response/beacon for IBSS */
351 struct sk_buff *presp, *skb;
351 352
352 enum { 353 enum {
353 IEEE80211_IBSS_MLME_SEARCH, 354 IEEE80211_IBSS_MLME_SEARCH,
@@ -361,6 +362,8 @@ struct ieee80211_if_mesh {
361 struct timer_list mesh_path_timer; 362 struct timer_list mesh_path_timer;
362 struct sk_buff_head skb_queue; 363 struct sk_buff_head skb_queue;
363 364
365 unsigned long timers_running;
366
364 bool housekeeping; 367 bool housekeeping;
365 368
366 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN]; 369 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
@@ -430,6 +433,12 @@ struct ieee80211_sub_if_data {
430 433
431 int drop_unencrypted; 434 int drop_unencrypted;
432 435
436 /*
437 * keep track of whether the HT opmode (stored in
438 * vif.bss_info.ht_operation_mode) is valid.
439 */
440 bool ht_opmode_valid;
441
433 /* Fragment table for host-based reassembly */ 442 /* Fragment table for host-based reassembly */
434 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX]; 443 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
435 unsigned int fragment_next; 444 unsigned int fragment_next;
@@ -580,6 +589,7 @@ enum queue_stop_reason {
580 IEEE80211_QUEUE_STOP_REASON_AGGREGATION, 589 IEEE80211_QUEUE_STOP_REASON_AGGREGATION,
581 IEEE80211_QUEUE_STOP_REASON_SUSPEND, 590 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
582 IEEE80211_QUEUE_STOP_REASON_PENDING, 591 IEEE80211_QUEUE_STOP_REASON_PENDING,
592 IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
583}; 593};
584 594
585struct ieee80211_master_priv { 595struct ieee80211_master_priv {
@@ -606,6 +616,21 @@ struct ieee80211_local {
606 unsigned int filter_flags; /* FIF_* */ 616 unsigned int filter_flags; /* FIF_* */
607 struct iw_statistics wstats; 617 struct iw_statistics wstats;
608 bool tim_in_locked_section; /* see ieee80211_beacon_get() */ 618 bool tim_in_locked_section; /* see ieee80211_beacon_get() */
619
620 /*
621 * suspended is true if we finished all the suspend _and_ we have
622 * not yet come up from resume. This is to be used by mac80211
623 * to ensure driver sanity during suspend and mac80211's own
624 * sanity. It can eventually be used for WoW as well.
625 */
626 bool suspended;
627
628 /*
629 * quiescing is true during the suspend process _only_ to
630 * ease timer cancelling etc.
631 */
632 bool quiescing;
633
609 int tx_headroom; /* required headroom for hardware/radiotap */ 634 int tx_headroom; /* required headroom for hardware/radiotap */
610 635
611 /* Tasklet and skb queue to process calls from IRQ mode. All frames 636 /* Tasklet and skb queue to process calls from IRQ mode. All frames
@@ -626,8 +651,6 @@ struct ieee80211_local {
626 spinlock_t sta_lock; 651 spinlock_t sta_lock;
627 unsigned long num_sta; 652 unsigned long num_sta;
628 struct list_head sta_list; 653 struct list_head sta_list;
629 struct list_head sta_flush_list;
630 struct work_struct sta_flush_work;
631 struct sta_info *sta_hash[STA_HASH_SIZE]; 654 struct sta_info *sta_hash[STA_HASH_SIZE];
632 struct timer_list sta_cleanup; 655 struct timer_list sta_cleanup;
633 656
@@ -647,9 +670,6 @@ struct ieee80211_local {
647 670
648 struct rate_control_ref *rate_ctrl; 671 struct rate_control_ref *rate_ctrl;
649 672
650 int rts_threshold;
651 int fragmentation_threshold;
652
653 struct crypto_blkcipher *wep_tx_tfm; 673 struct crypto_blkcipher *wep_tx_tfm;
654 struct crypto_blkcipher *wep_rx_tfm; 674 struct crypto_blkcipher *wep_rx_tfm;
655 u32 wep_iv; 675 u32 wep_iv;
@@ -666,15 +686,18 @@ struct ieee80211_local {
666 686
667 687
668 /* Scanning and BSS list */ 688 /* Scanning and BSS list */
689 struct mutex scan_mtx;
669 bool sw_scanning, hw_scanning; 690 bool sw_scanning, hw_scanning;
670 struct cfg80211_ssid scan_ssid; 691 struct cfg80211_ssid scan_ssid;
671 struct cfg80211_scan_request int_scan_req; 692 struct cfg80211_scan_request int_scan_req;
672 struct cfg80211_scan_request *scan_req; 693 struct cfg80211_scan_request *scan_req;
673 struct ieee80211_channel *scan_channel; 694 struct ieee80211_channel *scan_channel;
695 const u8 *orig_ies;
696 int orig_ies_len;
674 int scan_channel_idx; 697 int scan_channel_idx;
698 int scan_ies_len;
675 699
676 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 700 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
677 unsigned long last_scan_completed;
678 struct delayed_work scan_work; 701 struct delayed_work scan_work;
679 struct ieee80211_sub_if_data *scan_sdata; 702 struct ieee80211_sub_if_data *scan_sdata;
680 enum nl80211_channel_type oper_channel_type; 703 enum nl80211_channel_type oper_channel_type;
@@ -736,28 +759,32 @@ struct ieee80211_local {
736 int wifi_wme_noack_test; 759 int wifi_wme_noack_test;
737 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 760 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
738 761
739 bool powersave;
740 bool pspolling; 762 bool pspolling;
763 /*
764 * PS can only be enabled when we have exactly one managed
765 * interface (and monitors) in PS, this then points there.
766 */
767 struct ieee80211_sub_if_data *ps_sdata;
741 struct work_struct dynamic_ps_enable_work; 768 struct work_struct dynamic_ps_enable_work;
742 struct work_struct dynamic_ps_disable_work; 769 struct work_struct dynamic_ps_disable_work;
743 struct timer_list dynamic_ps_timer; 770 struct timer_list dynamic_ps_timer;
771 struct notifier_block network_latency_notifier;
744 772
745 int user_power_level; /* in dBm */ 773 int user_power_level; /* in dBm */
746 int power_constr_level; /* in dBm */ 774 int power_constr_level; /* in dBm */
747 775
776 struct work_struct restart_work;
777
748#ifdef CONFIG_MAC80211_DEBUGFS 778#ifdef CONFIG_MAC80211_DEBUGFS
749 struct local_debugfsdentries { 779 struct local_debugfsdentries {
750 struct dentry *rcdir; 780 struct dentry *rcdir;
751 struct dentry *rcname; 781 struct dentry *rcname;
752 struct dentry *frequency; 782 struct dentry *frequency;
753 struct dentry *rts_threshold;
754 struct dentry *fragmentation_threshold;
755 struct dentry *short_retry_limit;
756 struct dentry *long_retry_limit;
757 struct dentry *total_ps_buffered; 783 struct dentry *total_ps_buffered;
758 struct dentry *wep_iv; 784 struct dentry *wep_iv;
759 struct dentry *tsf; 785 struct dentry *tsf;
760 struct dentry *reset; 786 struct dentry *reset;
787 struct dentry *noack;
761 struct dentry *statistics; 788 struct dentry *statistics;
762 struct local_debugfsdentries_statsdentries { 789 struct local_debugfsdentries_statsdentries {
763 struct dentry *transmitted_fragment_count; 790 struct dentry *transmitted_fragment_count;
@@ -830,7 +857,7 @@ struct ieee802_11_elems {
830 u8 *fh_params; 857 u8 *fh_params;
831 u8 *ds_params; 858 u8 *ds_params;
832 u8 *cf_params; 859 u8 *cf_params;
833 u8 *tim; 860 struct ieee80211_tim_ie *tim;
834 u8 *ibss_params; 861 u8 *ibss_params;
835 u8 *challenge; 862 u8 *challenge;
836 u8 *wpa; 863 u8 *wpa;
@@ -903,7 +930,6 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
903 930
904 931
905int ieee80211_hw_config(struct ieee80211_local *local, u32 changed); 932int ieee80211_hw_config(struct ieee80211_local *local, u32 changed);
906int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed);
907void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx); 933void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
908void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, 934void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
909 u32 changed); 935 u32 changed);
@@ -927,12 +953,16 @@ int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason
927int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason); 953int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
928void ieee80211_send_pspoll(struct ieee80211_local *local, 954void ieee80211_send_pspoll(struct ieee80211_local *local,
929 struct ieee80211_sub_if_data *sdata); 955 struct ieee80211_sub_if_data *sdata);
956void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency);
957int ieee80211_max_network_latency(struct notifier_block *nb,
958 unsigned long data, void *dummy);
959void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
960 struct ieee80211_channel_sw_ie *sw_elem,
961 struct ieee80211_bss *bss);
962void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata);
963void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
930 964
931/* IBSS code */ 965/* IBSS code */
932int ieee80211_ibss_commit(struct ieee80211_sub_if_data *sdata);
933int ieee80211_ibss_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len);
934int ieee80211_ibss_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len);
935int ieee80211_ibss_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
936void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 966void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
937void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata); 967void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
938ieee80211_rx_result 968ieee80211_rx_result
@@ -940,14 +970,22 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
940 struct ieee80211_rx_status *rx_status); 970 struct ieee80211_rx_status *rx_status);
941struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 971struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
942 u8 *bssid, u8 *addr, u32 supp_rates); 972 u8 *bssid, u8 *addr, u32 supp_rates);
973int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
974 struct cfg80211_ibss_params *params);
975int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
976void ieee80211_ibss_quiesce(struct ieee80211_sub_if_data *sdata);
977void ieee80211_ibss_restart(struct ieee80211_sub_if_data *sdata);
943 978
944/* scan/BSS handling */ 979/* scan/BSS handling */
945void ieee80211_scan_work(struct work_struct *work); 980void ieee80211_scan_work(struct work_struct *work);
981int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
982 const u8 *ssid, u8 ssid_len);
946int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 983int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
947 struct cfg80211_scan_request *req); 984 struct cfg80211_scan_request *req);
948int ieee80211_scan_results(struct ieee80211_local *local, 985int ieee80211_scan_results(struct ieee80211_local *local,
949 struct iw_request_info *info, 986 struct iw_request_info *info,
950 char *buf, size_t len); 987 char *buf, size_t len);
988void ieee80211_scan_cancel(struct ieee80211_local *local);
951ieee80211_rx_result 989ieee80211_rx_result
952ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, 990ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata,
953 struct sk_buff *skb, 991 struct sk_buff *skb,
@@ -956,9 +994,6 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
956 const char *ie, size_t len); 994 const char *ie, size_t len);
957 995
958void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); 996void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
959void ieee80211_scan_failed(struct ieee80211_local *local);
960int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
961 struct cfg80211_scan_request *req);
962struct ieee80211_bss * 997struct ieee80211_bss *
963ieee80211_bss_info_update(struct ieee80211_local *local, 998ieee80211_bss_info_update(struct ieee80211_local *local,
964 struct ieee80211_rx_status *rx_status, 999 struct ieee80211_rx_status *rx_status,
@@ -983,6 +1018,8 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
983 enum nl80211_iftype type); 1018 enum nl80211_iftype type);
984void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata); 1019void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata);
985void ieee80211_remove_interfaces(struct ieee80211_local *local); 1020void ieee80211_remove_interfaces(struct ieee80211_local *local);
1021u32 __ieee80211_recalc_idle(struct ieee80211_local *local);
1022void ieee80211_recalc_idle(struct ieee80211_local *local);
986 1023
987/* tx handling */ 1024/* tx handling */
988void ieee80211_clear_tx_pending(struct ieee80211_local *local); 1025void ieee80211_clear_tx_pending(struct ieee80211_local *local);
@@ -995,9 +1032,6 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
995void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband, 1032void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
996 struct ieee80211_ht_cap *ht_cap_ie, 1033 struct ieee80211_ht_cap *ht_cap_ie,
997 struct ieee80211_sta_ht_cap *ht_cap); 1034 struct ieee80211_sta_ht_cap *ht_cap);
998u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
999 struct ieee80211_ht_info *hti,
1000 u16 ap_ht_cap_flags);
1001void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn); 1035void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn);
1002void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, 1036void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
1003 const u8 *da, u16 tid, 1037 const u8 *da, u16 tid,
@@ -1027,24 +1061,23 @@ int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
1027void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata, 1061void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
1028 struct ieee80211_mgmt *mgmt, 1062 struct ieee80211_mgmt *mgmt,
1029 size_t len); 1063 size_t len);
1030void ieee80211_chswitch_timer(unsigned long data); 1064
1031void ieee80211_chswitch_work(struct work_struct *work); 1065/* Suspend/resume and hw reconfiguration */
1032void ieee80211_process_chanswitch(struct ieee80211_sub_if_data *sdata, 1066int ieee80211_reconfig(struct ieee80211_local *local);
1033 struct ieee80211_channel_sw_ie *sw_elem, 1067
1034 struct ieee80211_bss *bss);
1035void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1036 u16 capab_info, u8 *pwr_constr_elem,
1037 u8 pwr_constr_elem_len);
1038
1039/* Suspend/resume */
1040#ifdef CONFIG_PM 1068#ifdef CONFIG_PM
1041int __ieee80211_suspend(struct ieee80211_hw *hw); 1069int __ieee80211_suspend(struct ieee80211_hw *hw);
1042int __ieee80211_resume(struct ieee80211_hw *hw); 1070
1071static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1072{
1073 return ieee80211_reconfig(hw_to_local(hw));
1074}
1043#else 1075#else
1044static inline int __ieee80211_suspend(struct ieee80211_hw *hw) 1076static inline int __ieee80211_suspend(struct ieee80211_hw *hw)
1045{ 1077{
1046 return 0; 1078 return 0;
1047} 1079}
1080
1048static inline int __ieee80211_resume(struct ieee80211_hw *hw) 1081static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1049{ 1082{
1050 return 0; 1083 return 0;
@@ -1053,19 +1086,20 @@ static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1053 1086
1054/* utility functions/constants */ 1087/* utility functions/constants */
1055extern void *mac80211_wiphy_privid; /* for wiphy privid */ 1088extern void *mac80211_wiphy_privid; /* for wiphy privid */
1056extern const unsigned char rfc1042_header[6];
1057extern const unsigned char bridge_tunnel_header[6];
1058u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 1089u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1059 enum nl80211_iftype type); 1090 enum nl80211_iftype type);
1060int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1091int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
1061 int rate, int erp, int short_preamble); 1092 int rate, int erp, int short_preamble);
1062void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1093void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1063 struct ieee80211_hdr *hdr); 1094 struct ieee80211_hdr *hdr, const u8 *tsc);
1064void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1095void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1065void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1096void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1066 int encrypt); 1097 int encrypt);
1067void ieee802_11_parse_elems(u8 *start, size_t len, 1098void ieee802_11_parse_elems(u8 *start, size_t len,
1068 struct ieee802_11_elems *elems); 1099 struct ieee802_11_elems *elems);
1100u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1101 struct ieee802_11_elems *elems,
1102 u64 filter, u32 crc);
1069int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq); 1103int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
1070u32 ieee80211_mandatory_rates(struct ieee80211_local *local, 1104u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1071 enum ieee80211_band band); 1105 enum ieee80211_band band);
@@ -1088,14 +1122,20 @@ void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
1088 enum queue_stop_reason reason); 1122 enum queue_stop_reason reason);
1089void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, 1123void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
1090 enum queue_stop_reason reason); 1124 enum queue_stop_reason reason);
1125void ieee80211_add_pending_skb(struct ieee80211_local *local,
1126 struct sk_buff *skb);
1127int ieee80211_add_pending_skbs(struct ieee80211_local *local,
1128 struct sk_buff_head *skbs);
1091 1129
1092void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1130void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1093 u16 transaction, u16 auth_alg, 1131 u16 transaction, u16 auth_alg,
1094 u8 *extra, size_t extra_len, 1132 u8 *extra, size_t extra_len,
1095 const u8 *bssid, int encrypt); 1133 const u8 *bssid, int encrypt);
1134int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1135 const u8 *ie, size_t ie_len);
1096void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 1136void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1097 u8 *ssid, size_t ssid_len, 1137 const u8 *ssid, size_t ssid_len,
1098 u8 *ie, size_t ie_len); 1138 const u8 *ie, size_t ie_len);
1099 1139
1100void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 1140void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1101 const size_t supp_rates_len, 1141 const size_t supp_rates_len,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 91e8e1bacaaa..b7c8a4484298 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -20,6 +20,7 @@
20#include "debugfs_netdev.h" 20#include "debugfs_netdev.h"
21#include "mesh.h" 21#include "mesh.h"
22#include "led.h" 22#include "led.h"
23#include "driver-ops.h"
23 24
24/** 25/**
25 * DOC: Interface list locking 26 * DOC: Interface list locking
@@ -164,14 +165,12 @@ static int ieee80211_open(struct net_device *dev)
164 } 165 }
165 166
166 if (local->open_count == 0) { 167 if (local->open_count == 0) {
167 res = 0; 168 res = drv_start(local);
168 if (local->ops->start)
169 res = local->ops->start(local_to_hw(local));
170 if (res) 169 if (res)
171 goto err_del_bss; 170 goto err_del_bss;
172 /* we're brought up, everything changes */ 171 /* we're brought up, everything changes */
173 hw_reconf_flags = ~0; 172 hw_reconf_flags = ~0;
174 ieee80211_led_radio(local, local->hw.conf.radio_enabled); 173 ieee80211_led_radio(local, true);
175 } 174 }
176 175
177 /* 176 /*
@@ -199,8 +198,8 @@ static int ieee80211_open(struct net_device *dev)
199 * Validate the MAC address for this device. 198 * Validate the MAC address for this device.
200 */ 199 */
201 if (!is_valid_ether_addr(dev->dev_addr)) { 200 if (!is_valid_ether_addr(dev->dev_addr)) {
202 if (!local->open_count && local->ops->stop) 201 if (!local->open_count)
203 local->ops->stop(local_to_hw(local)); 202 drv_stop(local);
204 return -EADDRNOTAVAIL; 203 return -EADDRNOTAVAIL;
205 } 204 }
206 205
@@ -235,17 +234,13 @@ static int ieee80211_open(struct net_device *dev)
235 netif_addr_unlock_bh(local->mdev); 234 netif_addr_unlock_bh(local->mdev);
236 break; 235 break;
237 case NL80211_IFTYPE_STATION: 236 case NL80211_IFTYPE_STATION:
238 case NL80211_IFTYPE_ADHOC: 237 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
239 if (sdata->vif.type == NL80211_IFTYPE_STATION)
240 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
241 else
242 sdata->u.ibss.flags &= ~IEEE80211_IBSS_PREV_BSSID_SET;
243 /* fall through */ 238 /* fall through */
244 default: 239 default:
245 conf.vif = &sdata->vif; 240 conf.vif = &sdata->vif;
246 conf.type = sdata->vif.type; 241 conf.type = sdata->vif.type;
247 conf.mac_addr = dev->dev_addr; 242 conf.mac_addr = dev->dev_addr;
248 res = local->ops->add_interface(local_to_hw(local), &conf); 243 res = drv_add_interface(local, &conf);
249 if (res) 244 if (res)
250 goto err_stop; 245 goto err_stop;
251 246
@@ -306,6 +301,8 @@ static int ieee80211_open(struct net_device *dev)
306 if (sdata->flags & IEEE80211_SDATA_PROMISC) 301 if (sdata->flags & IEEE80211_SDATA_PROMISC)
307 atomic_inc(&local->iff_promiscs); 302 atomic_inc(&local->iff_promiscs);
308 303
304 hw_reconf_flags |= __ieee80211_recalc_idle(local);
305
309 local->open_count++; 306 local->open_count++;
310 if (hw_reconf_flags) { 307 if (hw_reconf_flags) {
311 ieee80211_hw_config(local, hw_reconf_flags); 308 ieee80211_hw_config(local, hw_reconf_flags);
@@ -317,6 +314,8 @@ static int ieee80211_open(struct net_device *dev)
317 ieee80211_set_wmm_default(sdata); 314 ieee80211_set_wmm_default(sdata);
318 } 315 }
319 316
317 ieee80211_recalc_ps(local, -1);
318
320 /* 319 /*
321 * ieee80211_sta_work is disabled while network interface 320 * ieee80211_sta_work is disabled while network interface
322 * is down. Therefore, some configuration changes may not 321 * is down. Therefore, some configuration changes may not
@@ -325,17 +324,15 @@ static int ieee80211_open(struct net_device *dev)
325 */ 324 */
326 if (sdata->vif.type == NL80211_IFTYPE_STATION) 325 if (sdata->vif.type == NL80211_IFTYPE_STATION)
327 queue_work(local->hw.workqueue, &sdata->u.mgd.work); 326 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
328 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
329 queue_work(local->hw.workqueue, &sdata->u.ibss.work);
330 327
331 netif_tx_start_all_queues(dev); 328 netif_tx_start_all_queues(dev);
332 329
333 return 0; 330 return 0;
334 err_del_interface: 331 err_del_interface:
335 local->ops->remove_interface(local_to_hw(local), &conf); 332 drv_remove_interface(local, &conf);
336 err_stop: 333 err_stop:
337 if (!local->open_count && local->ops->stop) 334 if (!local->open_count)
338 local->ops->stop(local_to_hw(local)); 335 drv_stop(local);
339 err_del_bss: 336 err_del_bss:
340 sdata->bss = NULL; 337 sdata->bss = NULL;
341 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 338 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
@@ -497,7 +494,6 @@ static int ieee80211_stop(struct net_device *dev)
497 /* fall through */ 494 /* fall through */
498 case NL80211_IFTYPE_ADHOC: 495 case NL80211_IFTYPE_ADHOC:
499 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 496 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
500 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
501 del_timer_sync(&sdata->u.ibss.timer); 497 del_timer_sync(&sdata->u.ibss.timer);
502 cancel_work_sync(&sdata->u.ibss.work); 498 cancel_work_sync(&sdata->u.ibss.work);
503 synchronize_rcu(); 499 synchronize_rcu();
@@ -549,19 +545,22 @@ static int ieee80211_stop(struct net_device *dev)
549 conf.mac_addr = dev->dev_addr; 545 conf.mac_addr = dev->dev_addr;
550 /* disable all keys for as long as this netdev is down */ 546 /* disable all keys for as long as this netdev is down */
551 ieee80211_disable_keys(sdata); 547 ieee80211_disable_keys(sdata);
552 local->ops->remove_interface(local_to_hw(local), &conf); 548 drv_remove_interface(local, &conf);
553 } 549 }
554 550
555 sdata->bss = NULL; 551 sdata->bss = NULL;
556 552
553 hw_reconf_flags |= __ieee80211_recalc_idle(local);
554
555 ieee80211_recalc_ps(local, -1);
556
557 if (local->open_count == 0) { 557 if (local->open_count == 0) {
558 if (netif_running(local->mdev)) 558 if (netif_running(local->mdev))
559 dev_close(local->mdev); 559 dev_close(local->mdev);
560 560
561 if (local->ops->stop) 561 drv_stop(local);
562 local->ops->stop(local_to_hw(local));
563 562
564 ieee80211_led_radio(local, 0); 563 ieee80211_led_radio(local, false);
565 564
566 flush_workqueue(local->hw.workqueue); 565 flush_workqueue(local->hw.workqueue);
567 566
@@ -649,7 +648,8 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
649 mesh_rmc_free(sdata); 648 mesh_rmc_free(sdata);
650 break; 649 break;
651 case NL80211_IFTYPE_ADHOC: 650 case NL80211_IFTYPE_ADHOC:
652 kfree_skb(sdata->u.ibss.probe_resp); 651 if (WARN_ON(sdata->u.ibss.presp))
652 kfree_skb(sdata->u.ibss.presp);
653 break; 653 break;
654 case NL80211_IFTYPE_STATION: 654 case NL80211_IFTYPE_STATION:
655 kfree(sdata->u.mgd.extra_ie); 655 kfree(sdata->u.mgd.extra_ie);
@@ -896,3 +896,74 @@ void ieee80211_remove_interfaces(struct ieee80211_local *local)
896 unregister_netdevice(sdata->dev); 896 unregister_netdevice(sdata->dev);
897 } 897 }
898} 898}
899
900static u32 ieee80211_idle_off(struct ieee80211_local *local,
901 const char *reason)
902{
903 if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE))
904 return 0;
905
906#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
907 printk(KERN_DEBUG "%s: device no longer idle - %s\n",
908 wiphy_name(local->hw.wiphy), reason);
909#endif
910
911 local->hw.conf.flags &= ~IEEE80211_CONF_IDLE;
912 return IEEE80211_CONF_CHANGE_IDLE;
913}
914
915static u32 ieee80211_idle_on(struct ieee80211_local *local)
916{
917 if (local->hw.conf.flags & IEEE80211_CONF_IDLE)
918 return 0;
919
920#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
921 printk(KERN_DEBUG "%s: device now idle\n",
922 wiphy_name(local->hw.wiphy));
923#endif
924
925 local->hw.conf.flags |= IEEE80211_CONF_IDLE;
926 return IEEE80211_CONF_CHANGE_IDLE;
927}
928
929u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
930{
931 struct ieee80211_sub_if_data *sdata;
932 int count = 0;
933
934 if (local->hw_scanning || local->sw_scanning)
935 return ieee80211_idle_off(local, "scanning");
936
937 list_for_each_entry(sdata, &local->interfaces, list) {
938 if (!netif_running(sdata->dev))
939 continue;
940 /* do not count disabled managed interfaces */
941 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
942 sdata->u.mgd.state == IEEE80211_STA_MLME_DISABLED)
943 continue;
944 /* do not count unused IBSS interfaces */
945 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
946 !sdata->u.ibss.ssid_len)
947 continue;
948 /* count everything else */
949 count++;
950 }
951
952 if (!count)
953 return ieee80211_idle_on(local);
954 else
955 return ieee80211_idle_off(local, "in use");
956
957 return 0;
958}
959
960void ieee80211_recalc_idle(struct ieee80211_local *local)
961{
962 u32 chg;
963
964 mutex_lock(&local->iflist_mtx);
965 chg = __ieee80211_recalc_idle(local);
966 mutex_unlock(&local->iflist_mtx);
967 if (chg)
968 ieee80211_hw_config(local, chg);
969}
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 687acf23054d..ce267565e180 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -16,6 +16,7 @@
16#include <linux/rtnetlink.h> 16#include <linux/rtnetlink.h>
17#include <net/mac80211.h> 17#include <net/mac80211.h>
18#include "ieee80211_i.h" 18#include "ieee80211_i.h"
19#include "driver-ops.h"
19#include "debugfs_key.h" 20#include "debugfs_key.h"
20#include "aes_ccm.h" 21#include "aes_ccm.h"
21#include "aes_cmac.h" 22#include "aes_cmac.h"
@@ -136,8 +137,7 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
136 struct ieee80211_sub_if_data, 137 struct ieee80211_sub_if_data,
137 u.ap); 138 u.ap);
138 139
139 ret = key->local->ops->set_key(local_to_hw(key->local), SET_KEY, 140 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);
140 &sdata->vif, sta, &key->conf);
141 141
142 if (!ret) { 142 if (!ret) {
143 spin_lock(&todo_lock); 143 spin_lock(&todo_lock);
@@ -179,8 +179,8 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
179 struct ieee80211_sub_if_data, 179 struct ieee80211_sub_if_data,
180 u.ap); 180 u.ap);
181 181
182 ret = key->local->ops->set_key(local_to_hw(key->local), DISABLE_KEY, 182 ret = drv_set_key(key->local, DISABLE_KEY, &sdata->vif,
183 &sdata->vif, sta, &key->conf); 183 sta, &key->conf);
184 184
185 if (ret) 185 if (ret)
186 printk(KERN_ERR "mac80211-%s: failed to remove key " 186 printk(KERN_ERR "mac80211-%s: failed to remove key "
@@ -290,9 +290,11 @@ static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
290struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg, 290struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
291 int idx, 291 int idx,
292 size_t key_len, 292 size_t key_len,
293 const u8 *key_data) 293 const u8 *key_data,
294 size_t seq_len, const u8 *seq)
294{ 295{
295 struct ieee80211_key *key; 296 struct ieee80211_key *key;
297 int i, j;
296 298
297 BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS); 299 BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS);
298 300
@@ -318,14 +320,31 @@ struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
318 case ALG_TKIP: 320 case ALG_TKIP:
319 key->conf.iv_len = TKIP_IV_LEN; 321 key->conf.iv_len = TKIP_IV_LEN;
320 key->conf.icv_len = TKIP_ICV_LEN; 322 key->conf.icv_len = TKIP_ICV_LEN;
323 if (seq) {
324 for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
325 key->u.tkip.rx[i].iv32 =
326 get_unaligned_le32(&seq[2]);
327 key->u.tkip.rx[i].iv16 =
328 get_unaligned_le16(seq);
329 }
330 }
321 break; 331 break;
322 case ALG_CCMP: 332 case ALG_CCMP:
323 key->conf.iv_len = CCMP_HDR_LEN; 333 key->conf.iv_len = CCMP_HDR_LEN;
324 key->conf.icv_len = CCMP_MIC_LEN; 334 key->conf.icv_len = CCMP_MIC_LEN;
335 if (seq) {
336 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
337 for (j = 0; j < CCMP_PN_LEN; j++)
338 key->u.ccmp.rx_pn[i][j] =
339 seq[CCMP_PN_LEN - j - 1];
340 }
325 break; 341 break;
326 case ALG_AES_CMAC: 342 case ALG_AES_CMAC:
327 key->conf.iv_len = 0; 343 key->conf.iv_len = 0;
328 key->conf.icv_len = sizeof(struct ieee80211_mmie); 344 key->conf.icv_len = sizeof(struct ieee80211_mmie);
345 if (seq)
346 for (j = 0; j < 6; j++)
347 key->u.aes_cmac.rx_pn[j] = seq[6 - j - 1];
329 break; 348 break;
330 } 349 }
331 memcpy(key->conf.key, key_data, key_len); 350 memcpy(key->conf.key, key_data, key_len);
diff --git a/net/mac80211/key.h b/net/mac80211/key.h
index 215d3ef42a4f..9572e00f532c 100644
--- a/net/mac80211/key.h
+++ b/net/mac80211/key.h
@@ -144,7 +144,8 @@ struct ieee80211_key {
144struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg, 144struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
145 int idx, 145 int idx,
146 size_t key_len, 146 size_t key_len,
147 const u8 *key_data); 147 const u8 *key_data,
148 size_t seq_len, const u8 *seq);
148/* 149/*
149 * Insert a key into data structures (sdata, sta if necessary) 150 * Insert a key into data structures (sdata, sta if necessary)
150 * to make it used, free old key. 151 * to make it used, free old key.
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 14134193cd17..092a017b237e 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -21,10 +21,12 @@
21#include <linux/wireless.h> 21#include <linux/wireless.h>
22#include <linux/rtnetlink.h> 22#include <linux/rtnetlink.h>
23#include <linux/bitmap.h> 23#include <linux/bitmap.h>
24#include <linux/pm_qos_params.h>
24#include <net/net_namespace.h> 25#include <net/net_namespace.h>
25#include <net/cfg80211.h> 26#include <net/cfg80211.h>
26 27
27#include "ieee80211_i.h" 28#include "ieee80211_i.h"
29#include "driver-ops.h"
28#include "rate.h" 30#include "rate.h"
29#include "mesh.h" 31#include "mesh.h"
30#include "wep.h" 32#include "wep.h"
@@ -80,10 +82,9 @@ void ieee80211_configure_filter(struct ieee80211_local *local)
80 /* be a bit nasty */ 82 /* be a bit nasty */
81 new_flags |= (1<<31); 83 new_flags |= (1<<31);
82 84
83 local->ops->configure_filter(local_to_hw(local), 85 drv_configure_filter(local, changed_flags, &new_flags,
84 changed_flags, &new_flags, 86 local->mdev->mc_count,
85 local->mdev->mc_count, 87 local->mdev->mc_list);
86 local->mdev->mc_list);
87 88
88 WARN_ON(new_flags & (1<<31)); 89 WARN_ON(new_flags & (1<<31));
89 90
@@ -151,93 +152,19 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev)
151 ieee80211_configure_filter(local); 152 ieee80211_configure_filter(local);
152} 153}
153 154
154/* everything else */
155
156int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
157{
158 struct ieee80211_local *local = sdata->local;
159 struct ieee80211_if_conf conf;
160
161 if (WARN_ON(!netif_running(sdata->dev)))
162 return 0;
163
164 memset(&conf, 0, sizeof(conf));
165
166 if (sdata->vif.type == NL80211_IFTYPE_STATION)
167 conf.bssid = sdata->u.mgd.bssid;
168 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
169 conf.bssid = sdata->u.ibss.bssid;
170 else if (sdata->vif.type == NL80211_IFTYPE_AP)
171 conf.bssid = sdata->dev->dev_addr;
172 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
173 static const u8 zero[ETH_ALEN] = { 0 };
174 conf.bssid = zero;
175 } else {
176 WARN_ON(1);
177 return -EINVAL;
178 }
179
180 if (!local->ops->config_interface)
181 return 0;
182
183 switch (sdata->vif.type) {
184 case NL80211_IFTYPE_AP:
185 case NL80211_IFTYPE_ADHOC:
186 case NL80211_IFTYPE_MESH_POINT:
187 break;
188 default:
189 /* do not warn to simplify caller in scan.c */
190 changed &= ~IEEE80211_IFCC_BEACON_ENABLED;
191 if (WARN_ON(changed & IEEE80211_IFCC_BEACON))
192 return -EINVAL;
193 changed &= ~IEEE80211_IFCC_BEACON;
194 break;
195 }
196
197 if (changed & IEEE80211_IFCC_BEACON_ENABLED) {
198 if (local->sw_scanning) {
199 conf.enable_beacon = false;
200 } else {
201 /*
202 * Beacon should be enabled, but AP mode must
203 * check whether there is a beacon configured.
204 */
205 switch (sdata->vif.type) {
206 case NL80211_IFTYPE_AP:
207 conf.enable_beacon =
208 !!rcu_dereference(sdata->u.ap.beacon);
209 break;
210 case NL80211_IFTYPE_ADHOC:
211 conf.enable_beacon = !!sdata->u.ibss.probe_resp;
212 break;
213 case NL80211_IFTYPE_MESH_POINT:
214 conf.enable_beacon = true;
215 break;
216 default:
217 /* not reached */
218 WARN_ON(1);
219 break;
220 }
221 }
222 }
223
224 conf.changed = changed;
225
226 return local->ops->config_interface(local_to_hw(local),
227 &sdata->vif, &conf);
228}
229
230int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) 155int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
231{ 156{
232 struct ieee80211_channel *chan; 157 struct ieee80211_channel *chan, *scan_chan;
233 int ret = 0; 158 int ret = 0;
234 int power; 159 int power;
235 enum nl80211_channel_type channel_type; 160 enum nl80211_channel_type channel_type;
236 161
237 might_sleep(); 162 might_sleep();
238 163
239 if (local->sw_scanning) { 164 scan_chan = local->scan_channel;
240 chan = local->scan_channel; 165
166 if (scan_chan) {
167 chan = scan_chan;
241 channel_type = NL80211_CHAN_NO_HT; 168 channel_type = NL80211_CHAN_NO_HT;
242 } else { 169 } else {
243 chan = local->oper_channel; 170 chan = local->oper_channel;
@@ -251,7 +178,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
251 changed |= IEEE80211_CONF_CHANGE_CHANNEL; 178 changed |= IEEE80211_CONF_CHANGE_CHANNEL;
252 } 179 }
253 180
254 if (local->sw_scanning) 181 if (scan_chan)
255 power = chan->max_power; 182 power = chan->max_power;
256 else 183 else
257 power = local->power_constr_level ? 184 power = local->power_constr_level ?
@@ -267,7 +194,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
267 } 194 }
268 195
269 if (changed && local->open_count) { 196 if (changed && local->open_count) {
270 ret = local->ops->config(local_to_hw(local), changed); 197 ret = drv_config(local, changed);
271 /* 198 /*
272 * Goal: 199 * Goal:
273 * HW reconfiguration should never fail, the driver has told 200 * HW reconfiguration should never fail, the driver has told
@@ -292,18 +219,78 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
292 u32 changed) 219 u32 changed)
293{ 220{
294 struct ieee80211_local *local = sdata->local; 221 struct ieee80211_local *local = sdata->local;
222 static const u8 zero[ETH_ALEN] = { 0 };
295 223
296 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) 224 if (!changed)
297 return; 225 return;
298 226
299 if (!changed) 227 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
228 /*
229 * While not associated, claim a BSSID of all-zeroes
230 * so that drivers don't do any weird things with the
231 * BSSID at that time.
232 */
233 if (sdata->vif.bss_conf.assoc)
234 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
235 else
236 sdata->vif.bss_conf.bssid = zero;
237 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
238 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
239 else if (sdata->vif.type == NL80211_IFTYPE_AP)
240 sdata->vif.bss_conf.bssid = sdata->dev->dev_addr;
241 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
242 sdata->vif.bss_conf.bssid = zero;
243 } else {
244 WARN_ON(1);
300 return; 245 return;
246 }
247
248 switch (sdata->vif.type) {
249 case NL80211_IFTYPE_AP:
250 case NL80211_IFTYPE_ADHOC:
251 case NL80211_IFTYPE_MESH_POINT:
252 break;
253 default:
254 /* do not warn to simplify caller in scan.c */
255 changed &= ~BSS_CHANGED_BEACON_ENABLED;
256 if (WARN_ON(changed & BSS_CHANGED_BEACON))
257 return;
258 break;
259 }
260
261 if (changed & BSS_CHANGED_BEACON_ENABLED) {
262 if (local->sw_scanning) {
263 sdata->vif.bss_conf.enable_beacon = false;
264 } else {
265 /*
266 * Beacon should be enabled, but AP mode must
267 * check whether there is a beacon configured.
268 */
269 switch (sdata->vif.type) {
270 case NL80211_IFTYPE_AP:
271 sdata->vif.bss_conf.enable_beacon =
272 !!rcu_dereference(sdata->u.ap.beacon);
273 break;
274 case NL80211_IFTYPE_ADHOC:
275 sdata->vif.bss_conf.enable_beacon =
276 !!rcu_dereference(sdata->u.ibss.presp);
277 break;
278 case NL80211_IFTYPE_MESH_POINT:
279 sdata->vif.bss_conf.enable_beacon = true;
280 break;
281 default:
282 /* not reached */
283 WARN_ON(1);
284 break;
285 }
286 }
287 }
288
289 drv_bss_info_changed(local, &sdata->vif,
290 &sdata->vif.bss_conf, changed);
301 291
302 if (local->ops->bss_info_changed) 292 /* DEPRECATED */
303 local->ops->bss_info_changed(local_to_hw(local), 293 local->hw.conf.beacon_int = sdata->vif.bss_conf.beacon_int;
304 &sdata->vif,
305 &sdata->vif.bss_conf,
306 changed);
307} 294}
308 295
309u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata) 296u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
@@ -382,60 +369,12 @@ static void ieee80211_tasklet_handler(unsigned long data)
382 } 369 }
383} 370}
384 371
385/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
386 * make a prepared TX frame (one that has been given to hw) to look like brand
387 * new IEEE 802.11 frame that is ready to go through TX processing again.
388 */
389static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
390 struct ieee80211_key *key,
391 struct sk_buff *skb)
392{
393 unsigned int hdrlen, iv_len, mic_len;
394 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
395
396 hdrlen = ieee80211_hdrlen(hdr->frame_control);
397
398 if (!key)
399 goto no_key;
400
401 switch (key->conf.alg) {
402 case ALG_WEP:
403 iv_len = WEP_IV_LEN;
404 mic_len = WEP_ICV_LEN;
405 break;
406 case ALG_TKIP:
407 iv_len = TKIP_IV_LEN;
408 mic_len = TKIP_ICV_LEN;
409 break;
410 case ALG_CCMP:
411 iv_len = CCMP_HDR_LEN;
412 mic_len = CCMP_MIC_LEN;
413 break;
414 default:
415 goto no_key;
416 }
417
418 if (skb->len >= hdrlen + mic_len &&
419 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
420 skb_trim(skb, skb->len - mic_len);
421 if (skb->len >= hdrlen + iv_len) {
422 memmove(skb->data + iv_len, skb->data, hdrlen);
423 hdr = (struct ieee80211_hdr *)skb_pull(skb, iv_len);
424 }
425
426no_key:
427 if (ieee80211_is_data_qos(hdr->frame_control)) {
428 hdr->frame_control &= ~cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
429 memmove(skb->data + IEEE80211_QOS_CTL_LEN, skb->data,
430 hdrlen - IEEE80211_QOS_CTL_LEN);
431 skb_pull(skb, IEEE80211_QOS_CTL_LEN);
432 }
433}
434
435static void ieee80211_handle_filtered_frame(struct ieee80211_local *local, 372static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
436 struct sta_info *sta, 373 struct sta_info *sta,
437 struct sk_buff *skb) 374 struct sk_buff *skb)
438{ 375{
376 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
377
439 sta->tx_filtered_count++; 378 sta->tx_filtered_count++;
440 379
441 /* 380 /*
@@ -477,16 +416,15 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
477 */ 416 */
478 if (test_sta_flags(sta, WLAN_STA_PS) && 417 if (test_sta_flags(sta, WLAN_STA_PS) &&
479 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) { 418 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
480 ieee80211_remove_tx_extra(local, sta->key, skb);
481 skb_queue_tail(&sta->tx_filtered, skb); 419 skb_queue_tail(&sta->tx_filtered, skb);
482 return; 420 return;
483 } 421 }
484 422
485 if (!test_sta_flags(sta, WLAN_STA_PS) && !skb->requeue) { 423 if (!test_sta_flags(sta, WLAN_STA_PS) &&
424 !(info->flags & IEEE80211_TX_INTFL_RETRIED)) {
486 /* Software retry the packet once */ 425 /* Software retry the packet once */
487 skb->requeue = 1; 426 info->flags |= IEEE80211_TX_INTFL_RETRIED;
488 ieee80211_remove_tx_extra(local, sta->key, skb); 427 ieee80211_add_pending_skb(local, skb);
489 dev_queue_xmit(skb);
490 return; 428 return;
491 } 429 }
492 430
@@ -696,6 +634,28 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
696} 634}
697EXPORT_SYMBOL(ieee80211_tx_status); 635EXPORT_SYMBOL(ieee80211_tx_status);
698 636
637static void ieee80211_restart_work(struct work_struct *work)
638{
639 struct ieee80211_local *local =
640 container_of(work, struct ieee80211_local, restart_work);
641
642 rtnl_lock();
643 ieee80211_reconfig(local);
644 rtnl_unlock();
645}
646
647void ieee80211_restart_hw(struct ieee80211_hw *hw)
648{
649 struct ieee80211_local *local = hw_to_local(hw);
650
651 /* use this reason, __ieee80211_resume will unblock it */
652 ieee80211_stop_queues_by_reason(hw,
653 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
654
655 schedule_work(&local->restart_work);
656}
657EXPORT_SYMBOL(ieee80211_restart_hw);
658
699struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 659struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
700 const struct ieee80211_ops *ops) 660 const struct ieee80211_ops *ops)
701{ 661{
@@ -718,9 +678,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
718 * +-------------------------+ 678 * +-------------------------+
719 * 679 *
720 */ 680 */
721 priv_size = ((sizeof(struct ieee80211_local) + 681 priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
722 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
723 priv_data_len;
724 682
725 wiphy = wiphy_new(&mac80211_config_ops, priv_size); 683 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
726 684
@@ -728,17 +686,16 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
728 return NULL; 686 return NULL;
729 687
730 wiphy->privid = mac80211_wiphy_privid; 688 wiphy->privid = mac80211_wiphy_privid;
731 wiphy->max_scan_ssids = 4; 689
732 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ 690 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */
733 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) - 691 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) -
734 sizeof(struct cfg80211_bss); 692 sizeof(struct cfg80211_bss);
735 693
736 local = wiphy_priv(wiphy); 694 local = wiphy_priv(wiphy);
695
737 local->hw.wiphy = wiphy; 696 local->hw.wiphy = wiphy;
738 697
739 local->hw.priv = (char *)local + 698 local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
740 ((sizeof(struct ieee80211_local) +
741 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
742 699
743 BUG_ON(!ops->tx); 700 BUG_ON(!ops->tx);
744 BUG_ON(!ops->start); 701 BUG_ON(!ops->start);
@@ -752,15 +709,14 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
752 /* set up some defaults */ 709 /* set up some defaults */
753 local->hw.queues = 1; 710 local->hw.queues = 1;
754 local->hw.max_rates = 1; 711 local->hw.max_rates = 1;
755 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 712 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
756 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 713 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
757 local->hw.conf.long_frame_max_tx_count = 4;
758 local->hw.conf.short_frame_max_tx_count = 7;
759 local->hw.conf.radio_enabled = true; 714 local->hw.conf.radio_enabled = true;
760 local->user_power_level = -1; 715 local->user_power_level = -1;
761 716
762 INIT_LIST_HEAD(&local->interfaces); 717 INIT_LIST_HEAD(&local->interfaces);
763 mutex_init(&local->iflist_mtx); 718 mutex_init(&local->iflist_mtx);
719 mutex_init(&local->scan_mtx);
764 720
765 spin_lock_init(&local->key_lock); 721 spin_lock_init(&local->key_lock);
766 722
@@ -768,6 +724,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
768 724
769 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 725 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
770 726
727 INIT_WORK(&local->restart_work, ieee80211_restart_work);
728
771 INIT_WORK(&local->dynamic_ps_enable_work, 729 INIT_WORK(&local->dynamic_ps_enable_work,
772 ieee80211_dynamic_ps_enable_work); 730 ieee80211_dynamic_ps_enable_work);
773 INIT_WORK(&local->dynamic_ps_disable_work, 731 INIT_WORK(&local->dynamic_ps_disable_work,
@@ -821,7 +779,17 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
821 enum ieee80211_band band; 779 enum ieee80211_band band;
822 struct net_device *mdev; 780 struct net_device *mdev;
823 struct ieee80211_master_priv *mpriv; 781 struct ieee80211_master_priv *mpriv;
824 int channels, i, j; 782 int channels, i, j, max_bitrates;
783 bool supp_ht;
784 static const u32 cipher_suites[] = {
785 WLAN_CIPHER_SUITE_WEP40,
786 WLAN_CIPHER_SUITE_WEP104,
787 WLAN_CIPHER_SUITE_TKIP,
788 WLAN_CIPHER_SUITE_CCMP,
789
790 /* keep last -- depends on hw flags! */
791 WLAN_CIPHER_SUITE_AES_CMAC
792 };
825 793
826 /* 794 /*
827 * generic code guarantees at least one band, 795 * generic code guarantees at least one band,
@@ -829,18 +797,25 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
829 * that hw.conf.channel is assigned 797 * that hw.conf.channel is assigned
830 */ 798 */
831 channels = 0; 799 channels = 0;
800 max_bitrates = 0;
801 supp_ht = false;
832 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 802 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
833 struct ieee80211_supported_band *sband; 803 struct ieee80211_supported_band *sband;
834 804
835 sband = local->hw.wiphy->bands[band]; 805 sband = local->hw.wiphy->bands[band];
836 if (sband && !local->oper_channel) { 806 if (!sband)
807 continue;
808 if (!local->oper_channel) {
837 /* init channel we're on */ 809 /* init channel we're on */
838 local->hw.conf.channel = 810 local->hw.conf.channel =
839 local->oper_channel = 811 local->oper_channel = &sband->channels[0];
840 local->scan_channel = &sband->channels[0]; 812 local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
841 } 813 }
842 if (sband) 814 channels += sband->n_channels;
843 channels += sband->n_channels; 815
816 if (max_bitrates < sband->n_bitrates)
817 max_bitrates = sband->n_bitrates;
818 supp_ht = supp_ht || sband->ht_cap.ht_supported;
844 } 819 }
845 820
846 local->int_scan_req.n_channels = channels; 821 local->int_scan_req.n_channels = channels;
@@ -860,6 +835,37 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
860 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 835 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
861 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; 836 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
862 837
838 /*
839 * Calculate scan IE length -- we need this to alloc
840 * memory and to subtract from the driver limit. It
841 * includes the (extended) supported rates and HT
842 * information -- SSID is the driver's responsibility.
843 */
844 local->scan_ies_len = 4 + max_bitrates; /* (ext) supp rates */
845 if (supp_ht)
846 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
847
848 if (!local->ops->hw_scan) {
849 /* For hw_scan, driver needs to set these up. */
850 local->hw.wiphy->max_scan_ssids = 4;
851 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
852 }
853
854 /*
855 * If the driver supports any scan IEs, then assume the
856 * limit includes the IEs mac80211 will add, otherwise
857 * leave it at zero and let the driver sort it out; we
858 * still pass our IEs to the driver but userspace will
859 * not be allowed to in that case.
860 */
861 if (local->hw.wiphy->max_scan_ie_len)
862 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
863
864 local->hw.wiphy->cipher_suites = cipher_suites;
865 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
866 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
867 local->hw.wiphy->n_cipher_suites--;
868
863 result = wiphy_register(local->hw.wiphy); 869 result = wiphy_register(local->hw.wiphy);
864 if (result < 0) 870 if (result < 0)
865 goto fail_wiphy_register; 871 goto fail_wiphy_register;
@@ -898,9 +904,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
898 904
899 debugfs_hw_add(local); 905 debugfs_hw_add(local);
900 906
901 if (local->hw.conf.beacon_int < 10)
902 local->hw.conf.beacon_int = 100;
903
904 if (local->hw.max_listen_interval == 0) 907 if (local->hw.max_listen_interval == 0)
905 local->hw.max_listen_interval = 1; 908 local->hw.max_listen_interval = 1;
906 909
@@ -965,25 +968,38 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
965 } 968 }
966 } 969 }
967 970
971 local->network_latency_notifier.notifier_call =
972 ieee80211_max_network_latency;
973 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
974 &local->network_latency_notifier);
975
976 if (result) {
977 rtnl_lock();
978 goto fail_pm_qos;
979 }
980
968 return 0; 981 return 0;
969 982
970fail_rate: 983 fail_pm_qos:
984 ieee80211_led_exit(local);
985 ieee80211_remove_interfaces(local);
986 fail_rate:
971 unregister_netdevice(local->mdev); 987 unregister_netdevice(local->mdev);
972 local->mdev = NULL; 988 local->mdev = NULL;
973fail_dev: 989 fail_dev:
974 rtnl_unlock(); 990 rtnl_unlock();
975 ieee80211_wep_free(local); 991 ieee80211_wep_free(local);
976fail_wep: 992 fail_wep:
977 sta_info_stop(local); 993 sta_info_stop(local);
978fail_sta_info: 994 fail_sta_info:
979 debugfs_hw_del(local); 995 debugfs_hw_del(local);
980 destroy_workqueue(local->hw.workqueue); 996 destroy_workqueue(local->hw.workqueue);
981fail_workqueue: 997 fail_workqueue:
982 if (local->mdev) 998 if (local->mdev)
983 free_netdev(local->mdev); 999 free_netdev(local->mdev);
984fail_mdev_alloc: 1000 fail_mdev_alloc:
985 wiphy_unregister(local->hw.wiphy); 1001 wiphy_unregister(local->hw.wiphy);
986fail_wiphy_register: 1002 fail_wiphy_register:
987 kfree(local->int_scan_req.channels); 1003 kfree(local->int_scan_req.channels);
988 return result; 1004 return result;
989} 1005}
@@ -996,6 +1012,9 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
996 tasklet_kill(&local->tx_pending_tasklet); 1012 tasklet_kill(&local->tx_pending_tasklet);
997 tasklet_kill(&local->tasklet); 1013 tasklet_kill(&local->tasklet);
998 1014
1015 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1016 &local->network_latency_notifier);
1017
999 rtnl_lock(); 1018 rtnl_lock();
1000 1019
1001 /* 1020 /*
@@ -1038,6 +1057,7 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
1038 struct ieee80211_local *local = hw_to_local(hw); 1057 struct ieee80211_local *local = hw_to_local(hw);
1039 1058
1040 mutex_destroy(&local->iflist_mtx); 1059 mutex_destroy(&local->iflist_mtx);
1060 mutex_destroy(&local->scan_mtx);
1041 1061
1042 wiphy_free(local->hw.wiphy); 1062 wiphy_free(local->hw.wiphy);
1043} 1063}
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 9a3e5de0410a..fc712e60705d 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -21,6 +21,9 @@
21#define CAPAB_OFFSET 17 21#define CAPAB_OFFSET 17
22#define ACCEPT_PLINKS 0x80 22#define ACCEPT_PLINKS 0x80
23 23
24#define TMR_RUNNING_HK 0
25#define TMR_RUNNING_MP 1
26
24int mesh_allocated; 27int mesh_allocated;
25static struct kmem_cache *rm_cache; 28static struct kmem_cache *rm_cache;
26 29
@@ -45,6 +48,12 @@ static void ieee80211_mesh_housekeeping_timer(unsigned long data)
45 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 48 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
46 49
47 ifmsh->housekeeping = true; 50 ifmsh->housekeeping = true;
51
52 if (local->quiescing) {
53 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
54 return;
55 }
56
48 queue_work(local->hw.workqueue, &ifmsh->work); 57 queue_work(local->hw.workqueue, &ifmsh->work);
49} 58}
50 59
@@ -343,6 +352,11 @@ static void ieee80211_mesh_path_timer(unsigned long data)
343 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 352 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
344 struct ieee80211_local *local = sdata->local; 353 struct ieee80211_local *local = sdata->local;
345 354
355 if (local->quiescing) {
356 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
357 return;
358 }
359
346 queue_work(local->hw.workqueue, &ifmsh->work); 360 queue_work(local->hw.workqueue, &ifmsh->work);
347} 361}
348 362
@@ -417,13 +431,39 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
417 431
418 free_plinks = mesh_plink_availables(sdata); 432 free_plinks = mesh_plink_availables(sdata);
419 if (free_plinks != sdata->u.mesh.accepting_plinks) 433 if (free_plinks != sdata->u.mesh.accepting_plinks)
420 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); 434 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
421 435
422 ifmsh->housekeeping = false; 436 ifmsh->housekeeping = false;
423 mod_timer(&ifmsh->housekeeping_timer, 437 mod_timer(&ifmsh->housekeeping_timer,
424 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); 438 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
425} 439}
426 440
441#ifdef CONFIG_PM
442void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
443{
444 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
445
446 /* might restart the timer but that doesn't matter */
447 cancel_work_sync(&ifmsh->work);
448
449 /* use atomic bitops in case both timers fire at the same time */
450
451 if (del_timer_sync(&ifmsh->housekeeping_timer))
452 set_bit(TMR_RUNNING_HK, &ifmsh->timers_running);
453 if (del_timer_sync(&ifmsh->mesh_path_timer))
454 set_bit(TMR_RUNNING_MP, &ifmsh->timers_running);
455}
456
457void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
458{
459 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
460
461 if (test_and_clear_bit(TMR_RUNNING_HK, &ifmsh->timers_running))
462 add_timer(&ifmsh->housekeeping_timer);
463 if (test_and_clear_bit(TMR_RUNNING_MP, &ifmsh->timers_running))
464 add_timer(&ifmsh->mesh_path_timer);
465}
466#endif
427 467
428void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) 468void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
429{ 469{
@@ -432,8 +472,8 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
432 472
433 ifmsh->housekeeping = true; 473 ifmsh->housekeeping = true;
434 queue_work(local->hw.workqueue, &ifmsh->work); 474 queue_work(local->hw.workqueue, &ifmsh->work);
435 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON | 475 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
436 IEEE80211_IFCC_BEACON_ENABLED); 476 BSS_CHANGED_BEACON_ENABLED);
437} 477}
438 478
439void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) 479void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index d891d7ddccd7..c7d72819cdd2 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -191,12 +191,8 @@ struct mesh_rmc {
191#define PLINK_CATEGORY 30 191#define PLINK_CATEGORY 30
192#define MESH_PATH_SEL_CATEGORY 32 192#define MESH_PATH_SEL_CATEGORY 32
193 193
194/* Mesh Header Flags */
195#define IEEE80211S_FLAGS_AE 0x3
196
197/* Public interfaces */ 194/* Public interfaces */
198/* Various */ 195/* Various */
199int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
200int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, 196int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
201 struct ieee80211_sub_if_data *sdata); 197 struct ieee80211_sub_if_data *sdata);
202int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr, 198int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr,
@@ -267,6 +263,8 @@ void mesh_path_timer(unsigned long data);
267void mesh_path_flush_by_nexthop(struct sta_info *sta); 263void mesh_path_flush_by_nexthop(struct sta_info *sta);
268void mesh_path_discard_frame(struct sk_buff *skb, 264void mesh_path_discard_frame(struct sk_buff *skb,
269 struct ieee80211_sub_if_data *sdata); 265 struct ieee80211_sub_if_data *sdata);
266void mesh_path_quiesce(struct ieee80211_sub_if_data *sdata);
267void mesh_path_restart(struct ieee80211_sub_if_data *sdata);
270 268
271#ifdef CONFIG_MAC80211_MESH 269#ifdef CONFIG_MAC80211_MESH
272extern int mesh_allocated; 270extern int mesh_allocated;
@@ -294,10 +292,20 @@ static inline void mesh_path_activate(struct mesh_path *mpath)
294 292
295void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local); 293void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local);
296 294
295void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata);
296void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata);
297void mesh_plink_quiesce(struct sta_info *sta);
298void mesh_plink_restart(struct sta_info *sta);
297#else 299#else
298#define mesh_allocated 0 300#define mesh_allocated 0
299static inline void 301static inline void
300ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {} 302ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {}
303static inline void ieee80211_mesh_quiesce(struct ieee80211_sub_if_data *sdata)
304{}
305static inline void ieee80211_mesh_restart(struct ieee80211_sub_if_data *sdata)
306{}
307static inline void mesh_plink_quiesce(struct sta_info *sta) {}
308static inline void mesh_plink_restart(struct sta_info *sta) {}
301#endif 309#endif
302 310
303#endif /* IEEE80211S_H */ 311#endif /* IEEE80211S_H */
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 60b35accda91..003cb470ac84 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -836,8 +836,14 @@ void mesh_path_timer(unsigned long data)
836 mpath = rcu_dereference(mpath); 836 mpath = rcu_dereference(mpath);
837 if (!mpath) 837 if (!mpath)
838 goto endmpathtimer; 838 goto endmpathtimer;
839 spin_lock_bh(&mpath->state_lock);
840 sdata = mpath->sdata; 839 sdata = mpath->sdata;
840
841 if (sdata->local->quiescing) {
842 rcu_read_unlock();
843 return;
844 }
845
846 spin_lock_bh(&mpath->state_lock);
841 if (mpath->flags & MESH_PATH_RESOLVED || 847 if (mpath->flags & MESH_PATH_RESOLVED ||
842 (!(mpath->flags & MESH_PATH_RESOLVING))) 848 (!(mpath->flags & MESH_PATH_RESOLVING)))
843 mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED); 849 mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index a8bbdeca013a..cb14253587f1 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -266,6 +266,11 @@ static void mesh_plink_timer(unsigned long data)
266 */ 266 */
267 sta = (struct sta_info *) data; 267 sta = (struct sta_info *) data;
268 268
269 if (sta->sdata->local->quiescing) {
270 sta->plink_timer_was_running = true;
271 return;
272 }
273
269 spin_lock_bh(&sta->lock); 274 spin_lock_bh(&sta->lock);
270 if (sta->ignore_plink_timer) { 275 if (sta->ignore_plink_timer) {
271 sta->ignore_plink_timer = false; 276 sta->ignore_plink_timer = false;
@@ -322,6 +327,22 @@ static void mesh_plink_timer(unsigned long data)
322 } 327 }
323} 328}
324 329
330#ifdef CONFIG_PM
331void mesh_plink_quiesce(struct sta_info *sta)
332{
333 if (del_timer_sync(&sta->plink_timer))
334 sta->plink_timer_was_running = true;
335}
336
337void mesh_plink_restart(struct sta_info *sta)
338{
339 if (sta->plink_timer_was_running) {
340 add_timer(&sta->plink_timer);
341 sta->plink_timer_was_running = false;
342 }
343}
344#endif
345
325static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) 346static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
326{ 347{
327 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000); 348 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 132938b073dc..d779c57a8220 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -17,10 +17,13 @@
17#include <linux/if_arp.h> 17#include <linux/if_arp.h>
18#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/pm_qos_params.h>
21#include <linux/crc32.h>
20#include <net/mac80211.h> 22#include <net/mac80211.h>
21#include <asm/unaligned.h> 23#include <asm/unaligned.h>
22 24
23#include "ieee80211_i.h" 25#include "ieee80211_i.h"
26#include "driver-ops.h"
24#include "rate.h" 27#include "rate.h"
25#include "led.h" 28#include "led.h"
26 29
@@ -30,9 +33,13 @@
30#define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 33#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
31#define IEEE80211_ASSOC_MAX_TRIES 3 34#define IEEE80211_ASSOC_MAX_TRIES 3
32#define IEEE80211_MONITORING_INTERVAL (2 * HZ) 35#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
36#define IEEE80211_PROBE_WAIT (HZ / 5)
33#define IEEE80211_PROBE_IDLE_TIME (60 * HZ) 37#define IEEE80211_PROBE_IDLE_TIME (60 * HZ)
34#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) 38#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
35 39
40#define TMR_RUNNING_TIMER 0
41#define TMR_RUNNING_CHANSW 1
42
36/* utils */ 43/* utils */
37static int ecw2cw(int ecw) 44static int ecw2cw(int ecw)
38{ 45{
@@ -80,6 +87,92 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
80 return count; 87 return count;
81} 88}
82 89
90/*
91 * ieee80211_enable_ht should be called only after the operating band
92 * has been determined as ht configuration depends on the hw's
93 * HT abilities for a specific band.
94 */
95static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
96 struct ieee80211_ht_info *hti,
97 u16 ap_ht_cap_flags)
98{
99 struct ieee80211_local *local = sdata->local;
100 struct ieee80211_supported_band *sband;
101 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
102 struct sta_info *sta;
103 u32 changed = 0;
104 u16 ht_opmode;
105 bool enable_ht = true, ht_changed;
106 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
107
108 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
109
110 /* HT is not supported */
111 if (!sband->ht_cap.ht_supported)
112 enable_ht = false;
113
114 /* check that channel matches the right operating channel */
115 if (local->hw.conf.channel->center_freq !=
116 ieee80211_channel_to_frequency(hti->control_chan))
117 enable_ht = false;
118
119 if (enable_ht) {
120 channel_type = NL80211_CHAN_HT20;
121
122 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
123 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
124 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
125 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
126 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
127 if (!(local->hw.conf.channel->flags &
128 IEEE80211_CHAN_NO_HT40PLUS))
129 channel_type = NL80211_CHAN_HT40PLUS;
130 break;
131 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
132 if (!(local->hw.conf.channel->flags &
133 IEEE80211_CHAN_NO_HT40MINUS))
134 channel_type = NL80211_CHAN_HT40MINUS;
135 break;
136 }
137 }
138 }
139
140 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
141 channel_type != local->hw.conf.channel_type;
142
143 local->oper_channel_type = channel_type;
144
145 if (ht_changed) {
146 /* channel_type change automatically detected */
147 ieee80211_hw_config(local, 0);
148
149 rcu_read_lock();
150
151 sta = sta_info_get(local, ifmgd->bssid);
152 if (sta)
153 rate_control_rate_update(local, sband, sta,
154 IEEE80211_RC_HT_CHANGED);
155
156 rcu_read_unlock();
157 }
158
159 /* disable HT */
160 if (!enable_ht)
161 return 0;
162
163 ht_opmode = le16_to_cpu(hti->operation_mode);
164
165 /* if bss configuration changed store the new one */
166 if (!sdata->ht_opmode_valid ||
167 sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
168 changed |= BSS_CHANGED_HT;
169 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
170 sdata->ht_opmode_valid = true;
171 }
172
173 return changed;
174}
175
83/* frame sending functions */ 176/* frame sending functions */
84 177
85static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 178static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
@@ -263,13 +356,13 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
263 356
264 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 357 switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
265 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 358 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
266 if (flags & IEEE80211_CHAN_NO_FAT_ABOVE) { 359 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
267 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 360 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
268 cap &= ~IEEE80211_HT_CAP_SGI_40; 361 cap &= ~IEEE80211_HT_CAP_SGI_40;
269 } 362 }
270 break; 363 break;
271 case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 364 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
272 if (flags & IEEE80211_CHAN_NO_FAT_BELOW) { 365 if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
273 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 366 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
274 cap &= ~IEEE80211_HT_CAP_SGI_40; 367 cap &= ~IEEE80211_HT_CAP_SGI_40;
275 } 368 }
@@ -325,6 +418,10 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
325 /* u.deauth.reason_code == u.disassoc.reason_code */ 418 /* u.deauth.reason_code == u.disassoc.reason_code */
326 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 419 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
327 420
421 if (stype == IEEE80211_STYPE_DEAUTH)
422 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
423 else
424 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
328 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 425 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
329} 426}
330 427
@@ -359,6 +456,277 @@ void ieee80211_send_pspoll(struct ieee80211_local *local,
359 ieee80211_tx_skb(sdata, skb, 0); 456 ieee80211_tx_skb(sdata, skb, 0);
360} 457}
361 458
459void ieee80211_send_nullfunc(struct ieee80211_local *local,
460 struct ieee80211_sub_if_data *sdata,
461 int powersave)
462{
463 struct sk_buff *skb;
464 struct ieee80211_hdr *nullfunc;
465 __le16 fc;
466
467 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
468 return;
469
470 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
471 if (!skb) {
472 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
473 "frame\n", sdata->dev->name);
474 return;
475 }
476 skb_reserve(skb, local->hw.extra_tx_headroom);
477
478 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
479 memset(nullfunc, 0, 24);
480 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
481 IEEE80211_FCTL_TODS);
482 if (powersave)
483 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
484 nullfunc->frame_control = fc;
485 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
486 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
487 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
488
489 ieee80211_tx_skb(sdata, skb, 0);
490}
491
492/* spectrum management related things */
493static void ieee80211_chswitch_work(struct work_struct *work)
494{
495 struct ieee80211_sub_if_data *sdata =
496 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
497 struct ieee80211_bss *bss;
498 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
499
500 if (!netif_running(sdata->dev))
501 return;
502
503 bss = ieee80211_rx_bss_get(sdata->local, ifmgd->bssid,
504 sdata->local->hw.conf.channel->center_freq,
505 ifmgd->ssid, ifmgd->ssid_len);
506 if (!bss)
507 goto exit;
508
509 sdata->local->oper_channel = sdata->local->csa_channel;
510 /* XXX: shouldn't really modify cfg80211-owned data! */
511 if (!ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL))
512 bss->cbss.channel = sdata->local->oper_channel;
513
514 ieee80211_rx_bss_put(sdata->local, bss);
515exit:
516 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
517 ieee80211_wake_queues_by_reason(&sdata->local->hw,
518 IEEE80211_QUEUE_STOP_REASON_CSA);
519}
520
521static void ieee80211_chswitch_timer(unsigned long data)
522{
523 struct ieee80211_sub_if_data *sdata =
524 (struct ieee80211_sub_if_data *) data;
525 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
526
527 if (sdata->local->quiescing) {
528 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
529 return;
530 }
531
532 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work);
533}
534
535void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
536 struct ieee80211_channel_sw_ie *sw_elem,
537 struct ieee80211_bss *bss)
538{
539 struct ieee80211_channel *new_ch;
540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
541 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
542
543 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATED)
544 return;
545
546 if (sdata->local->sw_scanning || sdata->local->hw_scanning)
547 return;
548
549 /* Disregard subsequent beacons if we are already running a timer
550 processing a CSA */
551
552 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
553 return;
554
555 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
556 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
557 return;
558
559 sdata->local->csa_channel = new_ch;
560
561 if (sw_elem->count <= 1) {
562 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work);
563 } else {
564 ieee80211_stop_queues_by_reason(&sdata->local->hw,
565 IEEE80211_QUEUE_STOP_REASON_CSA);
566 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
567 mod_timer(&ifmgd->chswitch_timer,
568 jiffies +
569 msecs_to_jiffies(sw_elem->count *
570 bss->cbss.beacon_interval));
571 }
572}
573
574static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
575 u16 capab_info, u8 *pwr_constr_elem,
576 u8 pwr_constr_elem_len)
577{
578 struct ieee80211_conf *conf = &sdata->local->hw.conf;
579
580 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
581 return;
582
583 /* Power constraint IE length should be 1 octet */
584 if (pwr_constr_elem_len != 1)
585 return;
586
587 if ((*pwr_constr_elem <= conf->channel->max_power) &&
588 (*pwr_constr_elem != sdata->local->power_constr_level)) {
589 sdata->local->power_constr_level = *pwr_constr_elem;
590 ieee80211_hw_config(sdata->local, 0);
591 }
592}
593
594/* powersave */
595static void ieee80211_enable_ps(struct ieee80211_local *local,
596 struct ieee80211_sub_if_data *sdata)
597{
598 struct ieee80211_conf *conf = &local->hw.conf;
599
600 /*
601 * If we are scanning right now then the parameters will
602 * take effect when scan finishes.
603 */
604 if (local->hw_scanning || local->sw_scanning)
605 return;
606
607 if (conf->dynamic_ps_timeout > 0 &&
608 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
609 mod_timer(&local->dynamic_ps_timer, jiffies +
610 msecs_to_jiffies(conf->dynamic_ps_timeout));
611 } else {
612 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
613 ieee80211_send_nullfunc(local, sdata, 1);
614 conf->flags |= IEEE80211_CONF_PS;
615 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
616 }
617}
618
619static void ieee80211_change_ps(struct ieee80211_local *local)
620{
621 struct ieee80211_conf *conf = &local->hw.conf;
622
623 if (local->ps_sdata) {
624 ieee80211_enable_ps(local, local->ps_sdata);
625 } else if (conf->flags & IEEE80211_CONF_PS) {
626 conf->flags &= ~IEEE80211_CONF_PS;
627 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
628 del_timer_sync(&local->dynamic_ps_timer);
629 cancel_work_sync(&local->dynamic_ps_enable_work);
630 }
631}
632
633/* need to hold RTNL or interface lock */
634void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
635{
636 struct ieee80211_sub_if_data *sdata, *found = NULL;
637 int count = 0;
638
639 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
640 local->ps_sdata = NULL;
641 return;
642 }
643
644 list_for_each_entry(sdata, &local->interfaces, list) {
645 if (!netif_running(sdata->dev))
646 continue;
647 if (sdata->vif.type != NL80211_IFTYPE_STATION)
648 continue;
649 found = sdata;
650 count++;
651 }
652
653 if (count == 1 && found->u.mgd.powersave &&
654 (found->u.mgd.flags & IEEE80211_STA_ASSOCIATED) &&
655 !(found->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL)) {
656 s32 beaconint_us;
657
658 if (latency < 0)
659 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
660
661 beaconint_us = ieee80211_tu_to_usec(
662 found->vif.bss_conf.beacon_int);
663
664 if (beaconint_us > latency) {
665 local->ps_sdata = NULL;
666 } else {
667 u8 dtimper = found->vif.bss_conf.dtim_period;
668 int maxslp = 1;
669
670 if (dtimper > 1)
671 maxslp = min_t(int, dtimper,
672 latency / beaconint_us);
673
674 local->hw.conf.max_sleep_period = maxslp;
675 local->ps_sdata = found;
676 }
677 } else {
678 local->ps_sdata = NULL;
679 }
680
681 ieee80211_change_ps(local);
682}
683
684void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
685{
686 struct ieee80211_local *local =
687 container_of(work, struct ieee80211_local,
688 dynamic_ps_disable_work);
689
690 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
691 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
692 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
693 }
694
695 ieee80211_wake_queues_by_reason(&local->hw,
696 IEEE80211_QUEUE_STOP_REASON_PS);
697}
698
699void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
700{
701 struct ieee80211_local *local =
702 container_of(work, struct ieee80211_local,
703 dynamic_ps_enable_work);
704 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
705
706 /* can only happen when PS was just disabled anyway */
707 if (!sdata)
708 return;
709
710 if (local->hw.conf.flags & IEEE80211_CONF_PS)
711 return;
712
713 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
714 ieee80211_send_nullfunc(local, sdata, 1);
715
716 local->hw.conf.flags |= IEEE80211_CONF_PS;
717 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
718}
719
720void ieee80211_dynamic_ps_timer(unsigned long data)
721{
722 struct ieee80211_local *local = (void *) data;
723
724 if (local->quiescing)
725 return;
726
727 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
728}
729
362/* MLME */ 730/* MLME */
363static void ieee80211_sta_wmm_params(struct ieee80211_local *local, 731static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
364 struct ieee80211_if_managed *ifmgd, 732 struct ieee80211_if_managed *ifmgd,
@@ -424,41 +792,16 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
424#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 792#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
425 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " 793 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
426 "cWmin=%d cWmax=%d txop=%d\n", 794 "cWmin=%d cWmax=%d txop=%d\n",
427 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, 795 wiphy_name(local->hw.wiphy), queue, aci, acm,
428 params.cw_max, params.txop); 796 params.aifs, params.cw_min, params.cw_max, params.txop);
429#endif 797#endif
430 if (local->ops->conf_tx && 798 if (drv_conf_tx(local, queue, &params) && local->ops->conf_tx)
431 local->ops->conf_tx(local_to_hw(local), queue, &params)) {
432 printk(KERN_DEBUG "%s: failed to set TX queue " 799 printk(KERN_DEBUG "%s: failed to set TX queue "
433 "parameters for queue %d\n", local->mdev->name, queue); 800 "parameters for queue %d\n",
434 } 801 wiphy_name(local->hw.wiphy), queue);
435 } 802 }
436} 803}
437 804
438static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
439{
440 u8 mask;
441 u8 index, indexn1, indexn2;
442 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
443
444 if (unlikely(!tim || elems->tim_len < 4))
445 return false;
446
447 aid &= 0x3fff;
448 index = aid / 8;
449 mask = 1 << (aid & 7);
450
451 indexn1 = tim->bitmap_ctrl & 0xfe;
452 indexn2 = elems->tim_len + indexn1 - 4;
453
454 if (index < indexn1 || index > indexn2)
455 return false;
456
457 index -= indexn1;
458
459 return !!(tim->virtual_map[index] & mask);
460}
461
462static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, 805static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
463 u16 capab, bool erp_valid, u8 erp) 806 u16 capab, bool erp_valid, u8 erp)
464{ 807{
@@ -610,6 +953,7 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
610 sdata->vif.bss_conf.timestamp = bss->cbss.tsf; 953 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
611 sdata->vif.bss_conf.dtim_period = bss->dtim_period; 954 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
612 955
956 bss_info_changed |= BSS_CHANGED_BEACON_INT;
613 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 957 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
614 bss->cbss.capability, bss->has_erp_value, bss->erp_value); 958 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
615 959
@@ -632,20 +976,17 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
632 * changed or not. 976 * changed or not.
633 */ 977 */
634 bss_info_changed |= BSS_CHANGED_BASIC_RATES; 978 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
979
980 /* And the BSSID changed - we're associated now */
981 bss_info_changed |= BSS_CHANGED_BSSID;
982
635 ieee80211_bss_info_change_notify(sdata, bss_info_changed); 983 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
636 984
637 if (local->powersave) { 985 /* will be same as sdata */
638 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) && 986 if (local->ps_sdata) {
639 local->hw.conf.dynamic_ps_timeout > 0) { 987 mutex_lock(&local->iflist_mtx);
640 mod_timer(&local->dynamic_ps_timer, jiffies + 988 ieee80211_recalc_ps(local, -1);
641 msecs_to_jiffies( 989 mutex_unlock(&local->iflist_mtx);
642 local->hw.conf.dynamic_ps_timeout));
643 } else {
644 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
645 ieee80211_send_nullfunc(local, sdata, 1);
646 conf->flags |= IEEE80211_CONF_PS;
647 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
648 }
649 } 990 }
650 991
651 netif_tx_start_all_queues(sdata->dev); 992 netif_tx_start_all_queues(sdata->dev);
@@ -664,7 +1005,8 @@ static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
664 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n", 1005 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
665 sdata->dev->name, ifmgd->bssid); 1006 sdata->dev->name, ifmgd->bssid);
666 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1007 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
667 ieee80211_sta_send_apinfo(sdata); 1008 ieee80211_recalc_idle(local);
1009 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
668 1010
669 /* 1011 /*
670 * Most likely AP is not in the range so remove the 1012 * Most likely AP is not in the range so remove the
@@ -689,8 +1031,6 @@ static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
689 1031
690 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; 1032 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
691 1033
692 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
693
694 /* Direct probe is sent to broadcast address as some APs 1034 /* Direct probe is sent to broadcast address as some APs
695 * will not answer to direct packet in unassociated state. 1035 * will not answer to direct packet in unassociated state.
696 */ 1036 */
@@ -714,7 +1054,8 @@ static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
714 " timed out\n", 1054 " timed out\n",
715 sdata->dev->name, ifmgd->bssid); 1055 sdata->dev->name, ifmgd->bssid);
716 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1056 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
717 ieee80211_sta_send_apinfo(sdata); 1057 ieee80211_recalc_idle(local);
1058 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
718 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1059 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
719 sdata->local->hw.conf.channel->center_freq, 1060 sdata->local->hw.conf.channel->center_freq,
720 ifmgd->ssid, ifmgd->ssid_len); 1061 ifmgd->ssid, ifmgd->ssid_len);
@@ -817,9 +1158,16 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
817 1158
818 rcu_read_unlock(); 1159 rcu_read_unlock();
819 1160
1161 ieee80211_set_wmm_default(sdata);
1162
1163 ieee80211_recalc_idle(local);
1164
820 /* channel(_type) changes are handled by ieee80211_hw_config */ 1165 /* channel(_type) changes are handled by ieee80211_hw_config */
821 local->oper_channel_type = NL80211_CHAN_NO_HT; 1166 local->oper_channel_type = NL80211_CHAN_NO_HT;
822 1167
1168 /* on the next assoc, re-program HT parameters */
1169 sdata->ht_opmode_valid = false;
1170
823 local->power_constr_level = 0; 1171 local->power_constr_level = 0;
824 1172
825 del_timer_sync(&local->dynamic_ps_timer); 1173 del_timer_sync(&local->dynamic_ps_timer);
@@ -831,6 +1179,9 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
831 } 1179 }
832 1180
833 ieee80211_hw_config(local, config_changed); 1181 ieee80211_hw_config(local, config_changed);
1182
1183 /* And the BSSID changed -- not very interesting here */
1184 changed |= BSS_CHANGED_BSSID;
834 ieee80211_bss_info_change_notify(sdata, changed); 1185 ieee80211_bss_info_change_notify(sdata, changed);
835 1186
836 rcu_read_lock(); 1187 rcu_read_lock();
@@ -897,7 +1248,8 @@ static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
897 " timed out\n", 1248 " timed out\n",
898 sdata->dev->name, ifmgd->bssid); 1249 sdata->dev->name, ifmgd->bssid);
899 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1250 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
900 ieee80211_sta_send_apinfo(sdata); 1251 ieee80211_recalc_idle(local);
1252 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid);
901 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1253 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
902 sdata->local->hw.conf.channel->center_freq, 1254 sdata->local->hw.conf.channel->center_freq,
903 ifmgd->ssid, ifmgd->ssid_len); 1255 ifmgd->ssid, ifmgd->ssid_len);
@@ -917,6 +1269,7 @@ static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
917 printk(KERN_DEBUG "%s: mismatch in privacy configuration and " 1269 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
918 "mixed-cell disabled - abort association\n", sdata->dev->name); 1270 "mixed-cell disabled - abort association\n", sdata->dev->name);
919 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1271 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1272 ieee80211_recalc_idle(local);
920 return; 1273 return;
921 } 1274 }
922 1275
@@ -948,6 +1301,17 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
948 u.mgd.beacon_loss_work); 1301 u.mgd.beacon_loss_work);
949 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1302 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
950 1303
1304 /*
1305 * The driver has already reported this event and we have
1306 * already sent a probe request. Maybe the AP died and the
1307 * driver keeps reporting until we disassociate... We have
1308 * to ignore that because otherwise we would continually
1309 * reset the timer and never check whether we received a
1310 * probe response!
1311 */
1312 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1313 return;
1314
951#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1315#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
952 if (net_ratelimit()) { 1316 if (net_ratelimit()) {
953 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM " 1317 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
@@ -957,10 +1321,15 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
957#endif 1321#endif
958 1322
959 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; 1323 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1324
1325 mutex_lock(&sdata->local->iflist_mtx);
1326 ieee80211_recalc_ps(sdata->local, -1);
1327 mutex_unlock(&sdata->local->iflist_mtx);
1328
960 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, 1329 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
961 ifmgd->ssid_len, NULL, 0); 1330 ifmgd->ssid_len, NULL, 0);
962 1331
963 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL); 1332 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
964} 1333}
965 1334
966void ieee80211_beacon_loss(struct ieee80211_vif *vif) 1335void ieee80211_beacon_loss(struct ieee80211_vif *vif)
@@ -977,6 +1346,7 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
977 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1346 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
978 struct ieee80211_local *local = sdata->local; 1347 struct ieee80211_local *local = sdata->local;
979 struct sta_info *sta; 1348 struct sta_info *sta;
1349 unsigned long last_rx;
980 bool disassoc = false; 1350 bool disassoc = false;
981 1351
982 /* TODO: start monitoring current AP signal quality and number of 1352 /* TODO: start monitoring current AP signal quality and number of
@@ -993,17 +1363,21 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
993 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n", 1363 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
994 sdata->dev->name, ifmgd->bssid); 1364 sdata->dev->name, ifmgd->bssid);
995 disassoc = true; 1365 disassoc = true;
996 goto unlock; 1366 rcu_read_unlock();
1367 goto out;
997 } 1368 }
998 1369
1370 last_rx = sta->last_rx;
1371 rcu_read_unlock();
1372
999 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) && 1373 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1000 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { 1374 time_after(jiffies, last_rx + IEEE80211_PROBE_WAIT)) {
1001 printk(KERN_DEBUG "%s: no probe response from AP %pM " 1375 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1002 "- disassociating\n", 1376 "- disassociating\n",
1003 sdata->dev->name, ifmgd->bssid); 1377 sdata->dev->name, ifmgd->bssid);
1004 disassoc = true; 1378 disassoc = true;
1005 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1379 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1006 goto unlock; 1380 goto out;
1007 } 1381 }
1008 1382
1009 /* 1383 /*
@@ -1022,27 +1396,31 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
1022 } 1396 }
1023#endif 1397#endif
1024 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; 1398 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1399 mutex_lock(&local->iflist_mtx);
1400 ieee80211_recalc_ps(local, -1);
1401 mutex_unlock(&local->iflist_mtx);
1025 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, 1402 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1026 ifmgd->ssid_len, NULL, 0); 1403 ifmgd->ssid_len, NULL, 0);
1027 goto unlock; 1404 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
1028 1405 goto out;
1029 } 1406 }
1030 1407
1031 if (time_after(jiffies, sta->last_rx + IEEE80211_PROBE_IDLE_TIME)) { 1408 if (time_after(jiffies, last_rx + IEEE80211_PROBE_IDLE_TIME)) {
1032 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; 1409 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1410 mutex_lock(&local->iflist_mtx);
1411 ieee80211_recalc_ps(local, -1);
1412 mutex_unlock(&local->iflist_mtx);
1033 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, 1413 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1034 ifmgd->ssid_len, NULL, 0); 1414 ifmgd->ssid_len, NULL, 0);
1035 } 1415 }
1036 1416
1037 unlock: 1417 out:
1038 rcu_read_unlock(); 1418 if (!disassoc)
1039 1419 mod_timer(&ifmgd->timer,
1040 if (disassoc) 1420 jiffies + IEEE80211_MONITORING_INTERVAL);
1421 else
1041 ieee80211_set_disassoc(sdata, true, true, 1422 ieee80211_set_disassoc(sdata, true, true,
1042 WLAN_REASON_PREV_AUTH_NOT_VALID); 1423 WLAN_REASON_PREV_AUTH_NOT_VALID);
1043 else
1044 mod_timer(&ifmgd->timer, jiffies +
1045 IEEE80211_MONITORING_INTERVAL);
1046} 1424}
1047 1425
1048 1426
@@ -1055,6 +1433,7 @@ static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
1055 if (ifmgd->flags & IEEE80211_STA_EXT_SME) { 1433 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1056 /* Wait for SME to request association */ 1434 /* Wait for SME to request association */
1057 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1435 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1436 ieee80211_recalc_idle(sdata->local);
1058 } else 1437 } else
1059 ieee80211_associate(sdata); 1438 ieee80211_associate(sdata);
1060} 1439}
@@ -1187,7 +1566,7 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1187 1566
1188 ieee80211_set_disassoc(sdata, true, false, 0); 1567 ieee80211_set_disassoc(sdata, true, false, 0);
1189 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED; 1568 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1190 cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len); 1569 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1191} 1570}
1192 1571
1193 1572
@@ -1218,7 +1597,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1218 } 1597 }
1219 1598
1220 ieee80211_set_disassoc(sdata, false, false, reason_code); 1599 ieee80211_set_disassoc(sdata, false, false, reason_code);
1221 cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len); 1600 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
1222} 1601}
1223 1602
1224 1603
@@ -1287,6 +1666,12 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1287 * association next time. This works around some broken APs 1666 * association next time. This works around some broken APs
1288 * which do not correctly reject reassociation requests. */ 1667 * which do not correctly reject reassociation requests. */
1289 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET; 1668 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1669 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1670 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1671 /* Wait for SME to decide what to do next */
1672 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1673 ieee80211_recalc_idle(local);
1674 }
1290 return; 1675 return;
1291 } 1676 }
1292 1677
@@ -1340,8 +1725,9 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1340 * to between the sta_info_alloc() and sta_info_insert() above. 1725 * to between the sta_info_alloc() and sta_info_insert() above.
1341 */ 1726 */
1342 1727
1343 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | 1728 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP);
1344 WLAN_STA_AUTHORIZED); 1729 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1730 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1345 1731
1346 rates = 0; 1732 rates = 0;
1347 basic_rates = 0; 1733 basic_rates = 0;
@@ -1421,6 +1807,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1421 if (elems.wmm_param) 1807 if (elems.wmm_param)
1422 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1808 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1423 elems.wmm_param_len); 1809 elems.wmm_param_len);
1810 else
1811 ieee80211_set_wmm_default(sdata);
1424 1812
1425 if (elems.ht_info_elem && elems.wmm_param && 1813 if (elems.ht_info_elem && elems.wmm_param &&
1426 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1814 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
@@ -1476,7 +1864,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1476 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) { 1864 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) {
1477 struct ieee80211_channel_sw_ie *sw_elem = 1865 struct ieee80211_channel_sw_ie *sw_elem =
1478 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1866 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1479 ieee80211_process_chanswitch(sdata, sw_elem, bss); 1867 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss);
1480 } 1868 }
1481 1869
1482 ieee80211_rx_bss_put(local, bss); 1870 ieee80211_rx_bss_put(local, bss);
@@ -1507,57 +1895,98 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1507 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1895 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1508 1896
1509 /* direct probe may be part of the association flow */ 1897 /* direct probe may be part of the association flow */
1510 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, 1898 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) {
1511 &ifmgd->request)) {
1512 printk(KERN_DEBUG "%s direct probe responded\n", 1899 printk(KERN_DEBUG "%s direct probe responded\n",
1513 sdata->dev->name); 1900 sdata->dev->name);
1514 ieee80211_authenticate(sdata); 1901 ieee80211_authenticate(sdata);
1515 } 1902 }
1516 1903
1517 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) 1904 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) {
1518 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1905 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1906 mutex_lock(&sdata->local->iflist_mtx);
1907 ieee80211_recalc_ps(sdata->local, -1);
1908 mutex_unlock(&sdata->local->iflist_mtx);
1909 }
1519} 1910}
1520 1911
1912/*
1913 * This is the canonical list of information elements we care about,
1914 * the filter code also gives us all changes to the Microsoft OUI
1915 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1916 *
1917 * We implement beacon filtering in software since that means we can
1918 * avoid processing the frame here and in cfg80211, and userspace
1919 * will not be able to tell whether the hardware supports it or not.
1920 *
1921 * XXX: This list needs to be dynamic -- userspace needs to be able to
1922 * add items it requires. It also needs to be able to tell us to
1923 * look out for other vendor IEs.
1924 */
1925static const u64 care_about_ies =
1926 (1ULL << WLAN_EID_COUNTRY) |
1927 (1ULL << WLAN_EID_ERP_INFO) |
1928 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1929 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1930 (1ULL << WLAN_EID_HT_CAPABILITY) |
1931 (1ULL << WLAN_EID_HT_INFORMATION);
1932
1521static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, 1933static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1522 struct ieee80211_mgmt *mgmt, 1934 struct ieee80211_mgmt *mgmt,
1523 size_t len, 1935 size_t len,
1524 struct ieee80211_rx_status *rx_status) 1936 struct ieee80211_rx_status *rx_status)
1525{ 1937{
1526 struct ieee80211_if_managed *ifmgd; 1938 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1527 size_t baselen; 1939 size_t baselen;
1528 struct ieee802_11_elems elems; 1940 struct ieee802_11_elems elems;
1529 struct ieee80211_local *local = sdata->local; 1941 struct ieee80211_local *local = sdata->local;
1530 u32 changed = 0; 1942 u32 changed = 0;
1531 bool erp_valid, directed_tim; 1943 bool erp_valid, directed_tim = false;
1532 u8 erp_value = 0; 1944 u8 erp_value = 0;
1945 u32 ncrc;
1533 1946
1534 /* Process beacon from the current BSS */ 1947 /* Process beacon from the current BSS */
1535 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1948 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1536 if (baselen > len) 1949 if (baselen > len)
1537 return; 1950 return;
1538 1951
1539 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); 1952 if (rx_status->freq != local->hw.conf.channel->center_freq)
1540
1541 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1542
1543 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1544 return; 1953 return;
1545 1954
1546 ifmgd = &sdata->u.mgd;
1547
1548 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || 1955 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1549 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1956 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
1550 return; 1957 return;
1551 1958
1552 if (rx_status->freq != local->hw.conf.channel->center_freq) 1959 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) {
1553 return; 1960#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1961 if (net_ratelimit()) {
1962 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1963 "to a received beacon\n", sdata->dev->name);
1964 }
1965#endif
1966 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1967 mutex_lock(&local->iflist_mtx);
1968 ieee80211_recalc_ps(local, -1);
1969 mutex_unlock(&local->iflist_mtx);
1970 }
1554 1971
1555 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1972 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1556 elems.wmm_param_len); 1973 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1974 len - baselen, &elems,
1975 care_about_ies, ncrc);
1557 1976
1558 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { 1977 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1559 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid); 1978 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1979 ifmgd->aid);
1560 1980
1981 if (ncrc != ifmgd->beacon_crc) {
1982 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
1983 true);
1984
1985 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1986 elems.wmm_param_len);
1987 }
1988
1989 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1561 if (directed_tim) { 1990 if (directed_tim) {
1562 if (local->hw.conf.dynamic_ps_timeout > 0) { 1991 if (local->hw.conf.dynamic_ps_timeout > 0) {
1563 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 1992 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
@@ -1580,6 +2009,10 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1580 } 2009 }
1581 } 2010 }
1582 2011
2012 if (ncrc == ifmgd->beacon_crc)
2013 return;
2014 ifmgd->beacon_crc = ncrc;
2015
1583 if (elems.erp_info && elems.erp_info_len >= 1) { 2016 if (elems.erp_info && elems.erp_info_len >= 1) {
1584 erp_valid = true; 2017 erp_valid = true;
1585 erp_value = elems.erp_info[0]; 2018 erp_value = elems.erp_info[0];
@@ -1714,6 +2147,11 @@ static void ieee80211_sta_timer(unsigned long data)
1714 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2147 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1715 struct ieee80211_local *local = sdata->local; 2148 struct ieee80211_local *local = sdata->local;
1716 2149
2150 if (local->quiescing) {
2151 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2152 return;
2153 }
2154
1717 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); 2155 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
1718 queue_work(local->hw.workqueue, &ifmgd->work); 2156 queue_work(local->hw.workqueue, &ifmgd->work);
1719} 2157}
@@ -1723,10 +2161,8 @@ static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
1723 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2161 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1724 struct ieee80211_local *local = sdata->local; 2162 struct ieee80211_local *local = sdata->local;
1725 2163
1726 if (local->ops->reset_tsf) { 2164 /* Reset own TSF to allow time synchronization work. */
1727 /* Reset own TSF to allow time synchronization work. */ 2165 drv_reset_tsf(local);
1728 local->ops->reset_tsf(local_to_hw(local));
1729 }
1730 2166
1731 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */ 2167 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
1732 2168
@@ -1814,25 +2250,18 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
1814 return 0; 2250 return 0;
1815 } else { 2251 } else {
1816 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { 2252 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2253
1817 ifmgd->assoc_scan_tries++; 2254 ifmgd->assoc_scan_tries++;
1818 /* XXX maybe racy? */
1819 if (local->scan_req)
1820 return -1;
1821 memcpy(local->int_scan_req.ssids[0].ssid,
1822 ifmgd->ssid, IEEE80211_MAX_SSID_LEN);
1823 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL)
1824 local->int_scan_req.ssids[0].ssid_len = 0;
1825 else
1826 local->int_scan_req.ssids[0].ssid_len = ifmgd->ssid_len;
1827 2255
1828 if (ieee80211_start_scan(sdata, &local->int_scan_req)) 2256 ieee80211_request_internal_scan(sdata, ifmgd->ssid,
1829 ieee80211_scan_failed(local); 2257 ssid_len);
1830 2258
1831 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; 2259 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
1832 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); 2260 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
1833 } else { 2261 } else {
1834 ifmgd->assoc_scan_tries = 0; 2262 ifmgd->assoc_scan_tries = 0;
1835 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 2263 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
2264 ieee80211_recalc_idle(local);
1836 } 2265 }
1837 } 2266 }
1838 return -1; 2267 return -1;
@@ -1855,6 +2284,17 @@ static void ieee80211_sta_work(struct work_struct *work)
1855 2284
1856 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 2285 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
1857 return; 2286 return;
2287
2288 /*
2289 * Nothing should have been stuffed into the workqueue during
2290 * the suspend->resume cycle. If this WARN is seen then there
2291 * is a bug with either the driver suspend or something in
2292 * mac80211 stuffing into the workqueue which we haven't yet
2293 * cleared during mac80211's suspend cycle.
2294 */
2295 if (WARN_ON(local->suspended))
2296 return;
2297
1858 ifmgd = &sdata->u.mgd; 2298 ifmgd = &sdata->u.mgd;
1859 2299
1860 while ((skb = skb_dequeue(&ifmgd->skb_queue))) 2300 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
@@ -1864,14 +2304,8 @@ static void ieee80211_sta_work(struct work_struct *work)
1864 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && 2304 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
1865 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && 2305 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
1866 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { 2306 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
1867 /* 2307 queue_delayed_work(local->hw.workqueue, &local->scan_work,
1868 * The call to ieee80211_start_scan can fail but ieee80211_request_scan 2308 round_jiffies_relative(0));
1869 * (which queued ieee80211_sta_work) did not return an error. Thus, call
1870 * ieee80211_scan_failed here if ieee80211_start_scan fails in order to
1871 * notify the scan requester.
1872 */
1873 if (ieee80211_start_scan(sdata, local->scan_req))
1874 ieee80211_scan_failed(local);
1875 return; 2309 return;
1876 } 2310 }
1877 2311
@@ -1882,6 +2316,8 @@ static void ieee80211_sta_work(struct work_struct *work)
1882 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request)) 2316 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
1883 return; 2317 return;
1884 2318
2319 ieee80211_recalc_idle(local);
2320
1885 switch (ifmgd->state) { 2321 switch (ifmgd->state) {
1886 case IEEE80211_STA_MLME_DISABLED: 2322 case IEEE80211_STA_MLME_DISABLED:
1887 break; 2323 break;
@@ -1926,10 +2362,43 @@ static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1926 } 2362 }
1927} 2363}
1928 2364
2365#ifdef CONFIG_PM
2366void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2367{
2368 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2369
2370 /*
2371 * we need to use atomic bitops for the running bits
2372 * only because both timers might fire at the same
2373 * time -- the code here is properly synchronised.
2374 */
2375
2376 cancel_work_sync(&ifmgd->work);
2377 cancel_work_sync(&ifmgd->beacon_loss_work);
2378 if (del_timer_sync(&ifmgd->timer))
2379 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
2380
2381 cancel_work_sync(&ifmgd->chswitch_work);
2382 if (del_timer_sync(&ifmgd->chswitch_timer))
2383 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
2384}
2385
2386void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2387{
2388 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2389
2390 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
2391 add_timer(&ifmgd->timer);
2392 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
2393 add_timer(&ifmgd->chswitch_timer);
2394}
2395#endif
2396
1929/* interface setup */ 2397/* interface setup */
1930void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 2398void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1931{ 2399{
1932 struct ieee80211_if_managed *ifmgd; 2400 struct ieee80211_if_managed *ifmgd;
2401 u32 hw_flags;
1933 2402
1934 ifmgd = &sdata->u.mgd; 2403 ifmgd = &sdata->u.mgd;
1935 INIT_WORK(&ifmgd->work, ieee80211_sta_work); 2404 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
@@ -1949,6 +2418,13 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1949 IEEE80211_STA_AUTO_CHANNEL_SEL; 2418 IEEE80211_STA_AUTO_CHANNEL_SEL;
1950 if (sdata->local->hw.queues >= 4) 2419 if (sdata->local->hw.queues >= 4)
1951 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; 2420 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2421
2422 hw_flags = sdata->local->hw.flags;
2423
2424 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2425 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2426 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2427 }
1952} 2428}
1953 2429
1954/* configuration hooks */ 2430/* configuration hooks */
@@ -2032,13 +2508,6 @@ int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2032 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET; 2508 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
2033 } 2509 }
2034 2510
2035 if (netif_running(sdata->dev)) {
2036 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
2037 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2038 "the low-level driver\n", sdata->dev->name);
2039 }
2040 }
2041
2042 return ieee80211_sta_commit(sdata); 2511 return ieee80211_sta_commit(sdata);
2043} 2512}
2044 2513
@@ -2047,6 +2516,13 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
2047{ 2516{
2048 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2517 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2049 2518
2519 if (len == 0 && ifmgd->extra_ie_len == 0)
2520 return -EALREADY;
2521
2522 if (len == ifmgd->extra_ie_len && ifmgd->extra_ie &&
2523 memcmp(ifmgd->extra_ie, ie, len) == 0)
2524 return -EALREADY;
2525
2050 kfree(ifmgd->extra_ie); 2526 kfree(ifmgd->extra_ie);
2051 if (len == 0) { 2527 if (len == 0) {
2052 ifmgd->extra_ie = NULL; 2528 ifmgd->extra_ie = NULL;
@@ -2068,9 +2544,6 @@ int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason
2068 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", 2544 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2069 sdata->dev->name, reason); 2545 sdata->dev->name, reason);
2070 2546
2071 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2072 return -EINVAL;
2073
2074 ieee80211_set_disassoc(sdata, true, true, reason); 2547 ieee80211_set_disassoc(sdata, true, true, reason);
2075 return 0; 2548 return 0;
2076} 2549}
@@ -2082,9 +2555,6 @@ int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2082 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", 2555 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2083 sdata->dev->name, reason); 2556 sdata->dev->name, reason);
2084 2557
2085 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2086 return -EINVAL;
2087
2088 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) 2558 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2089 return -ENOLINK; 2559 return -ENOLINK;
2090 2560
@@ -2104,75 +2574,17 @@ void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2104 rcu_read_unlock(); 2574 rcu_read_unlock();
2105} 2575}
2106 2576
2107void ieee80211_dynamic_ps_disable_work(struct work_struct *work) 2577int ieee80211_max_network_latency(struct notifier_block *nb,
2578 unsigned long data, void *dummy)
2108{ 2579{
2580 s32 latency_usec = (s32) data;
2109 struct ieee80211_local *local = 2581 struct ieee80211_local *local =
2110 container_of(work, struct ieee80211_local, 2582 container_of(nb, struct ieee80211_local,
2111 dynamic_ps_disable_work); 2583 network_latency_notifier);
2112
2113 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
2114 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
2115 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2116 }
2117
2118 ieee80211_wake_queues_by_reason(&local->hw,
2119 IEEE80211_QUEUE_STOP_REASON_PS);
2120}
2121
2122void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2123{
2124 struct ieee80211_local *local =
2125 container_of(work, struct ieee80211_local,
2126 dynamic_ps_enable_work);
2127 /* XXX: using scan_sdata is completely broken! */
2128 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2129
2130 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2131 return;
2132
2133 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
2134 ieee80211_send_nullfunc(local, sdata, 1);
2135
2136 local->hw.conf.flags |= IEEE80211_CONF_PS;
2137 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2138}
2139
2140void ieee80211_dynamic_ps_timer(unsigned long data)
2141{
2142 struct ieee80211_local *local = (void *) data;
2143
2144 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
2145}
2146
2147void ieee80211_send_nullfunc(struct ieee80211_local *local,
2148 struct ieee80211_sub_if_data *sdata,
2149 int powersave)
2150{
2151 struct sk_buff *skb;
2152 struct ieee80211_hdr *nullfunc;
2153 __le16 fc;
2154 2584
2155 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 2585 mutex_lock(&local->iflist_mtx);
2156 return; 2586 ieee80211_recalc_ps(local, latency_usec);
2157 2587 mutex_unlock(&local->iflist_mtx);
2158 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
2159 if (!skb) {
2160 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2161 "frame\n", sdata->dev->name);
2162 return;
2163 }
2164 skb_reserve(skb, local->hw.extra_tx_headroom);
2165 2588
2166 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 2589 return 0;
2167 memset(nullfunc, 0, 24);
2168 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2169 IEEE80211_FCTL_TODS);
2170 if (powersave)
2171 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
2172 nullfunc->frame_control = fc;
2173 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2174 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
2175 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
2176
2177 ieee80211_tx_skb(sdata, skb, 0);
2178} 2590}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 81985d27cbda..7a549f9deb96 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -2,6 +2,8 @@
2#include <net/rtnetlink.h> 2#include <net/rtnetlink.h>
3 3
4#include "ieee80211_i.h" 4#include "ieee80211_i.h"
5#include "mesh.h"
6#include "driver-ops.h"
5#include "led.h" 7#include "led.h"
6 8
7int __ieee80211_suspend(struct ieee80211_hw *hw) 9int __ieee80211_suspend(struct ieee80211_hw *hw)
@@ -12,11 +14,30 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
12 struct sta_info *sta; 14 struct sta_info *sta;
13 unsigned long flags; 15 unsigned long flags;
14 16
17 ieee80211_scan_cancel(local);
18
15 ieee80211_stop_queues_by_reason(hw, 19 ieee80211_stop_queues_by_reason(hw,
16 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 20 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
17 21
22 /* flush out all packets */
23 synchronize_net();
24
25 local->quiescing = true;
26 /* make quiescing visible to timers everywhere */
27 mb();
28
18 flush_workqueue(local->hw.workqueue); 29 flush_workqueue(local->hw.workqueue);
19 30
31 /* Don't try to run timers while suspended. */
32 del_timer_sync(&local->sta_cleanup);
33
34 /*
35 * Note that this particular timer doesn't need to be
36 * restarted at resume.
37 */
38 cancel_work_sync(&local->dynamic_ps_enable_work);
39 del_timer_sync(&local->dynamic_ps_timer);
40
20 /* disable keys */ 41 /* disable keys */
21 list_for_each_entry(sdata, &local->interfaces, list) 42 list_for_each_entry(sdata, &local->interfaces, list)
22 ieee80211_disable_keys(sdata); 43 ieee80211_disable_keys(sdata);
@@ -34,157 +55,70 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
34 55
35 rcu_read_unlock(); 56 rcu_read_unlock();
36 57
37 /* remove STAs */
38 if (local->ops->sta_notify) {
39 spin_lock_irqsave(&local->sta_lock, flags);
40 list_for_each_entry(sta, &local->sta_list, list) {
41 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
42 sdata = container_of(sdata->bss,
43 struct ieee80211_sub_if_data,
44 u.ap);
45
46 local->ops->sta_notify(hw, &sdata->vif,
47 STA_NOTIFY_REMOVE, &sta->sta);
48 }
49 spin_unlock_irqrestore(&local->sta_lock, flags);
50 }
51
52 /* remove all interfaces */
53 list_for_each_entry(sdata, &local->interfaces, list) {
54 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
55 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
56 netif_running(sdata->dev)) {
57 conf.vif = &sdata->vif;
58 conf.type = sdata->vif.type;
59 conf.mac_addr = sdata->dev->dev_addr;
60 local->ops->remove_interface(hw, &conf);
61 }
62 }
63
64 /* flush again, in case driver queued work */ 58 /* flush again, in case driver queued work */
65 flush_workqueue(local->hw.workqueue); 59 flush_workqueue(local->hw.workqueue);
66 60
67 /* stop hardware */ 61 /* stop hardware - this must stop RX */
68 if (local->open_count) { 62 if (local->open_count) {
69 ieee80211_led_radio(local, false); 63 ieee80211_led_radio(local, false);
70 local->ops->stop(hw); 64 drv_stop(local);
71 }
72 return 0;
73}
74
75int __ieee80211_resume(struct ieee80211_hw *hw)
76{
77 struct ieee80211_local *local = hw_to_local(hw);
78 struct ieee80211_sub_if_data *sdata;
79 struct ieee80211_if_init_conf conf;
80 struct sta_info *sta;
81 unsigned long flags;
82 int res;
83
84 /* restart hardware */
85 if (local->open_count) {
86 res = local->ops->start(hw);
87
88 ieee80211_led_radio(local, hw->conf.radio_enabled);
89 } 65 }
90 66
91 /* add interfaces */ 67 /* remove STAs */
92 list_for_each_entry(sdata, &local->interfaces, list) { 68 spin_lock_irqsave(&local->sta_lock, flags);
93 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 69 list_for_each_entry(sta, &local->sta_list, list) {
94 sdata->vif.type != NL80211_IFTYPE_MONITOR && 70 if (local->ops->sta_notify) {
95 netif_running(sdata->dev)) { 71 sdata = sta->sdata;
96 conf.vif = &sdata->vif;
97 conf.type = sdata->vif.type;
98 conf.mac_addr = sdata->dev->dev_addr;
99 res = local->ops->add_interface(hw, &conf);
100 }
101 }
102
103 /* add STAs back */
104 if (local->ops->sta_notify) {
105 spin_lock_irqsave(&local->sta_lock, flags);
106 list_for_each_entry(sta, &local->sta_list, list) {
107 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 72 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
108 sdata = container_of(sdata->bss, 73 sdata = container_of(sdata->bss,
109 struct ieee80211_sub_if_data, 74 struct ieee80211_sub_if_data,
110 u.ap); 75 u.ap);
111 76
112 local->ops->sta_notify(hw, &sdata->vif, 77 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
113 STA_NOTIFY_ADD, &sta->sta); 78 &sta->sta);
114 } 79 }
115 spin_unlock_irqrestore(&local->sta_lock, flags);
116 }
117
118 /* Clear Suspend state so that ADDBA requests can be processed */
119
120 rcu_read_lock();
121 80
122 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { 81 mesh_plink_quiesce(sta);
123 list_for_each_entry_rcu(sta, &local->sta_list, list) {
124 clear_sta_flags(sta, WLAN_STA_SUSPEND);
125 }
126 } 82 }
83 spin_unlock_irqrestore(&local->sta_lock, flags);
127 84
128 rcu_read_unlock(); 85 /* remove all interfaces */
129
130 /* add back keys */
131 list_for_each_entry(sdata, &local->interfaces, list)
132 if (netif_running(sdata->dev))
133 ieee80211_enable_keys(sdata);
134
135 /* setup RTS threshold */
136 if (local->ops->set_rts_threshold)
137 local->ops->set_rts_threshold(hw, local->rts_threshold);
138
139 /* reconfigure hardware */
140 ieee80211_hw_config(local, ~0);
141
142 netif_addr_lock_bh(local->mdev);
143 ieee80211_configure_filter(local);
144 netif_addr_unlock_bh(local->mdev);
145
146 /* Finally also reconfigure all the BSS information */
147 list_for_each_entry(sdata, &local->interfaces, list) { 86 list_for_each_entry(sdata, &local->interfaces, list) {
148 u32 changed = ~0; 87 switch(sdata->vif.type) {
149 if (!netif_running(sdata->dev))
150 continue;
151 switch (sdata->vif.type) {
152 case NL80211_IFTYPE_STATION: 88 case NL80211_IFTYPE_STATION:
153 /* disable beacon change bits */ 89 ieee80211_sta_quiesce(sdata);
154 changed &= ~IEEE80211_IFCC_BEACON; 90 break;
155 /* fall through */
156 case NL80211_IFTYPE_ADHOC: 91 case NL80211_IFTYPE_ADHOC:
157 case NL80211_IFTYPE_AP: 92 ieee80211_ibss_quiesce(sdata);
158 case NL80211_IFTYPE_MESH_POINT:
159 /*
160 * Driver's config_interface can fail if rfkill is
161 * enabled. Accommodate this return code.
162 * FIXME: When mac80211 has knowledge of rfkill
163 * state the code below can change back to:
164 * WARN(ieee80211_if_config(sdata, changed));
165 * ieee80211_bss_info_change_notify(sdata, ~0);
166 */
167 if (ieee80211_if_config(sdata, changed))
168 printk(KERN_DEBUG "%s: failed to configure interface during resume\n",
169 sdata->dev->name);
170 else
171 ieee80211_bss_info_change_notify(sdata, ~0);
172 break; 93 break;
173 case NL80211_IFTYPE_WDS: 94 case NL80211_IFTYPE_MESH_POINT:
95 ieee80211_mesh_quiesce(sdata);
174 break; 96 break;
175 case NL80211_IFTYPE_AP_VLAN: 97 case NL80211_IFTYPE_AP_VLAN:
176 case NL80211_IFTYPE_MONITOR: 98 case NL80211_IFTYPE_MONITOR:
177 /* ignore virtual */ 99 /* don't tell driver about this */
178 break; 100 continue;
179 case NL80211_IFTYPE_UNSPECIFIED: 101 default:
180 case __NL80211_IFTYPE_AFTER_LAST:
181 WARN_ON(1);
182 break; 102 break;
183 } 103 }
104
105 if (!netif_running(sdata->dev))
106 continue;
107
108 conf.vif = &sdata->vif;
109 conf.type = sdata->vif.type;
110 conf.mac_addr = sdata->dev->dev_addr;
111 drv_remove_interface(local, &conf);
184 } 112 }
185 113
186 ieee80211_wake_queues_by_reason(hw, 114 local->suspended = true;
187 IEEE80211_QUEUE_STOP_REASON_SUSPEND); 115 local->quiescing = false;
188 116
189 return 0; 117 return 0;
190} 118}
119
120/*
121 * __ieee80211_resume() is a static inline which just calls
122 * ieee80211_reconfig(), which is also needed for hardware
123 * hang/firmware failure/etc. recovery.
124 */
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index d9233ec50610..b218b98fba7f 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -80,8 +80,7 @@ use_low_rate(struct sk_buff *skb)
80 fc = le16_to_cpu(hdr->frame_control); 80 fc = le16_to_cpu(hdr->frame_control);
81 81
82 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) || 82 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) ||
83 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 83 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA);
84 is_multicast_ether_addr(hdr->addr1));
85} 84}
86 85
87 86
@@ -216,7 +215,7 @@ minstrel_get_next_sample(struct minstrel_sta_info *mi)
216 unsigned int sample_ndx; 215 unsigned int sample_ndx;
217 sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column); 216 sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column);
218 mi->sample_idx++; 217 mi->sample_idx++;
219 if (mi->sample_idx > (mi->n_rates - 2)) { 218 if ((int) mi->sample_idx > (mi->n_rates - 2)) {
220 mi->sample_idx = 0; 219 mi->sample_idx = 0;
221 mi->sample_column++; 220 mi->sample_column++;
222 if (mi->sample_column >= SAMPLE_COLUMNS) 221 if (mi->sample_column >= SAMPLE_COLUMNS)
@@ -245,7 +244,10 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
245 244
246 if (!sta || !mi || use_low_rate(skb)) { 245 if (!sta || !mi || use_low_rate(skb)) {
247 ar[0].idx = rate_lowest_index(sband, sta); 246 ar[0].idx = rate_lowest_index(sband, sta);
248 ar[0].count = mp->max_retry; 247 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
248 ar[0].count = 1;
249 else
250 ar[0].count = mp->max_retry;
249 return; 251 return;
250 } 252 }
251 253
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 8bef9a1262ff..a0bef767ceb5 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -289,13 +289,15 @@ rate_control_pid_get_rate(void *priv, struct ieee80211_sta *sta,
289 info->control.rates[0].count = 289 info->control.rates[0].count =
290 txrc->hw->conf.short_frame_max_tx_count; 290 txrc->hw->conf.short_frame_max_tx_count;
291 291
292 /* Send management frames and broadcast/multicast data using lowest 292 /* Send management frames and NO_ACK data using lowest rate. */
293 * rate. */
294 fc = le16_to_cpu(hdr->frame_control); 293 fc = le16_to_cpu(hdr->frame_control);
295 if (!sta || !spinfo || 294 if (!sta || !spinfo ||
296 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 295 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
297 is_multicast_ether_addr(hdr->addr1)) { 296 info->flags & IEEE80211_TX_CTL_NO_ACK) {
298 info->control.rates[0].idx = rate_lowest_index(sband, sta); 297 info->control.rates[0].idx = rate_lowest_index(sband, sta);
298 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
299 info->control.rates[0].count = 1;
300
299 return; 301 return;
300 } 302 }
301 303
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 9776f73c51ad..de5bba7f910a 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -19,6 +19,7 @@
19#include <net/ieee80211_radiotap.h> 19#include <net/ieee80211_radiotap.h>
20 20
21#include "ieee80211_i.h" 21#include "ieee80211_i.h"
22#include "driver-ops.h"
22#include "led.h" 23#include "led.h"
23#include "mesh.h" 24#include "mesh.h"
24#include "wep.h" 25#include "wep.h"
@@ -629,15 +630,6 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
629 * possible. 630 * possible.
630 */ 631 */
631 632
632 if (!ieee80211_has_protected(hdr->frame_control)) {
633 if (!ieee80211_is_mgmt(hdr->frame_control) ||
634 rx->sta == NULL || !test_sta_flags(rx->sta, WLAN_STA_MFP))
635 return RX_CONTINUE;
636 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
637 if (mmie_keyidx < 0)
638 return RX_CONTINUE;
639 }
640
641 /* 633 /*
642 * No point in finding a key and decrypting if the frame is neither 634 * No point in finding a key and decrypting if the frame is neither
643 * addressed to us nor a multicast frame. 635 * addressed to us nor a multicast frame.
@@ -648,8 +640,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
648 if (rx->sta) 640 if (rx->sta)
649 stakey = rcu_dereference(rx->sta->key); 641 stakey = rcu_dereference(rx->sta->key);
650 642
643 if (!ieee80211_has_protected(hdr->frame_control))
644 mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
645
651 if (!is_multicast_ether_addr(hdr->addr1) && stakey) { 646 if (!is_multicast_ether_addr(hdr->addr1) && stakey) {
652 rx->key = stakey; 647 rx->key = stakey;
648 /* Skip decryption if the frame is not protected. */
649 if (!ieee80211_has_protected(hdr->frame_control))
650 return RX_CONTINUE;
653 } else if (mmie_keyidx >= 0) { 651 } else if (mmie_keyidx >= 0) {
654 /* Broadcast/multicast robust management frame / BIP */ 652 /* Broadcast/multicast robust management frame / BIP */
655 if ((rx->status->flag & RX_FLAG_DECRYPTED) && 653 if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
@@ -660,6 +658,21 @@ ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
660 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) 658 mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
661 return RX_DROP_MONITOR; /* unexpected BIP keyidx */ 659 return RX_DROP_MONITOR; /* unexpected BIP keyidx */
662 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]); 660 rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
661 } else if (!ieee80211_has_protected(hdr->frame_control)) {
662 /*
663 * The frame was not protected, so skip decryption. However, we
664 * need to set rx->key if there is a key that could have been
665 * used so that the frame may be dropped if encryption would
666 * have been expected.
667 */
668 struct ieee80211_key *key = NULL;
669 if (ieee80211_is_mgmt(hdr->frame_control) &&
670 is_multicast_ether_addr(hdr->addr1) &&
671 (key = rcu_dereference(rx->sdata->default_mgmt_key)))
672 rx->key = key;
673 else if ((key = rcu_dereference(rx->sdata->default_key)))
674 rx->key = key;
675 return RX_CONTINUE;
663 } else { 676 } else {
664 /* 677 /*
665 * The device doesn't give us the IV so we won't be 678 * The device doesn't give us the IV so we won't be
@@ -773,9 +786,7 @@ static void ap_sta_ps_start(struct sta_info *sta)
773 786
774 atomic_inc(&sdata->bss->num_sta_ps); 787 atomic_inc(&sdata->bss->num_sta_ps);
775 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL); 788 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
776 if (local->ops->sta_notify) 789 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_SLEEP, &sta->sta);
777 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
778 STA_NOTIFY_SLEEP, &sta->sta);
779#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 790#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
780 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", 791 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
781 sdata->dev->name, sta->sta.addr, sta->sta.aid); 792 sdata->dev->name, sta->sta.addr, sta->sta.aid);
@@ -786,15 +797,12 @@ static int ap_sta_ps_end(struct sta_info *sta)
786{ 797{
787 struct ieee80211_sub_if_data *sdata = sta->sdata; 798 struct ieee80211_sub_if_data *sdata = sta->sdata;
788 struct ieee80211_local *local = sdata->local; 799 struct ieee80211_local *local = sdata->local;
789 struct sk_buff *skb; 800 int sent, buffered;
790 int sent = 0;
791 801
792 atomic_dec(&sdata->bss->num_sta_ps); 802 atomic_dec(&sdata->bss->num_sta_ps);
793 803
794 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL); 804 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
795 if (local->ops->sta_notify) 805 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_AWAKE, &sta->sta);
796 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
797 STA_NOTIFY_AWAKE, &sta->sta);
798 806
799 if (!skb_queue_empty(&sta->ps_tx_buf)) 807 if (!skb_queue_empty(&sta->ps_tx_buf))
800 sta_info_clear_tim_bit(sta); 808 sta_info_clear_tim_bit(sta);
@@ -805,22 +813,16 @@ static int ap_sta_ps_end(struct sta_info *sta)
805#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 813#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
806 814
807 /* Send all buffered frames to the station */ 815 /* Send all buffered frames to the station */
808 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { 816 sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered);
809 sent++; 817 buffered = ieee80211_add_pending_skbs(local, &sta->ps_tx_buf);
810 skb->requeue = 1; 818 sent += buffered;
811 dev_queue_xmit(skb); 819 local->total_ps_buffered -= buffered;
812 } 820
813 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
814 local->total_ps_buffered--;
815 sent++;
816#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 821#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
817 printk(KERN_DEBUG "%s: STA %pM aid %d send PS frame " 822 printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames "
818 "since STA not sleeping anymore\n", sdata->dev->name, 823 "since STA not sleeping anymore\n", sdata->dev->name,
819 sta->sta.addr, sta->sta.aid); 824 sta->sta.addr, sta->sta.aid, sent - buffered, buffered);
820#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 825#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
821 skb->requeue = 1;
822 dev_queue_xmit(skb);
823 }
824 826
825 return sent; 827 return sent;
826} 828}
@@ -1212,109 +1214,38 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1212 /* Drop unencrypted frames if key is set. */ 1214 /* Drop unencrypted frames if key is set. */
1213 if (unlikely(!ieee80211_has_protected(fc) && 1215 if (unlikely(!ieee80211_has_protected(fc) &&
1214 !ieee80211_is_nullfunc(fc) && 1216 !ieee80211_is_nullfunc(fc) &&
1215 (!ieee80211_is_mgmt(fc) || 1217 ieee80211_is_data(fc) &&
1216 (ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1217 rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP))) &&
1218 (rx->key || rx->sdata->drop_unencrypted)))
1219 return -EACCES;
1220 /* BIP does not use Protected field, so need to check MMIE */
1221 if (unlikely(rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP) &&
1222 ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
1223 ieee80211_get_mmie_keyidx(rx->skb) < 0 &&
1224 (rx->key || rx->sdata->drop_unencrypted))) 1218 (rx->key || rx->sdata->drop_unencrypted)))
1225 return -EACCES; 1219 return -EACCES;
1220 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
1221 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1222 rx->key))
1223 return -EACCES;
1224 /* BIP does not use Protected field, so need to check MMIE */
1225 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb)
1226 && ieee80211_get_mmie_keyidx(rx->skb) < 0 &&
1227 rx->key))
1228 return -EACCES;
1229 /*
1230 * When using MFP, Action frames are not allowed prior to
1231 * having configured keys.
1232 */
1233 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1234 ieee80211_is_robust_mgmt_frame(
1235 (struct ieee80211_hdr *) rx->skb->data)))
1236 return -EACCES;
1237 }
1226 1238
1227 return 0; 1239 return 0;
1228} 1240}
1229 1241
1230static int 1242static int
1231ieee80211_data_to_8023(struct ieee80211_rx_data *rx) 1243__ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1232{ 1244{
1233 struct net_device *dev = rx->dev; 1245 struct net_device *dev = rx->dev;
1234 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
1235 u16 hdrlen, ethertype;
1236 u8 *payload;
1237 u8 dst[ETH_ALEN];
1238 u8 src[ETH_ALEN] __aligned(2);
1239 struct sk_buff *skb = rx->skb;
1240 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1246 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1241 1247
1242 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 1248 return ieee80211_data_to_8023(rx->skb, dev->dev_addr, sdata->vif.type);
1243 return -1;
1244
1245 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1246
1247 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1248 * header
1249 * IEEE 802.11 address fields:
1250 * ToDS FromDS Addr1 Addr2 Addr3 Addr4
1251 * 0 0 DA SA BSSID n/a
1252 * 0 1 DA BSSID SA n/a
1253 * 1 0 BSSID SA DA n/a
1254 * 1 1 RA TA DA SA
1255 */
1256 memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
1257 memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
1258
1259 switch (hdr->frame_control &
1260 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1261 case cpu_to_le16(IEEE80211_FCTL_TODS):
1262 if (unlikely(sdata->vif.type != NL80211_IFTYPE_AP &&
1263 sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1264 return -1;
1265 break;
1266 case cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1267 if (unlikely(sdata->vif.type != NL80211_IFTYPE_WDS &&
1268 sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
1269 return -1;
1270 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1271 struct ieee80211s_hdr *meshdr = (struct ieee80211s_hdr *)
1272 (skb->data + hdrlen);
1273 hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
1274 if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
1275 memcpy(dst, meshdr->eaddr1, ETH_ALEN);
1276 memcpy(src, meshdr->eaddr2, ETH_ALEN);
1277 }
1278 }
1279 break;
1280 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
1281 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
1282 (is_multicast_ether_addr(dst) &&
1283 !compare_ether_addr(src, dev->dev_addr)))
1284 return -1;
1285 break;
1286 case cpu_to_le16(0):
1287 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
1288 return -1;
1289 break;
1290 }
1291
1292 if (unlikely(skb->len - hdrlen < 8))
1293 return -1;
1294
1295 payload = skb->data + hdrlen;
1296 ethertype = (payload[6] << 8) | payload[7];
1297
1298 if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
1299 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1300 compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
1301 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1302 * replace EtherType */
1303 skb_pull(skb, hdrlen + 6);
1304 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1305 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1306 } else {
1307 struct ethhdr *ehdr;
1308 __be16 len;
1309
1310 skb_pull(skb, hdrlen);
1311 len = htons(skb->len);
1312 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
1313 memcpy(ehdr->h_dest, dst, ETH_ALEN);
1314 memcpy(ehdr->h_source, src, ETH_ALEN);
1315 ehdr->h_proto = len;
1316 }
1317 return 0;
1318} 1249}
1319 1250
1320/* 1251/*
@@ -1397,7 +1328,7 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1397 * mac80211. That also explains the __skb_push() 1328 * mac80211. That also explains the __skb_push()
1398 * below. 1329 * below.
1399 */ 1330 */
1400 align = (unsigned long)skb->data & 3; 1331 align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
1401 if (align) { 1332 if (align) {
1402 if (WARN_ON(skb_headroom(skb) < 3)) { 1333 if (WARN_ON(skb_headroom(skb) < 3)) {
1403 dev_kfree_skb(skb); 1334 dev_kfree_skb(skb);
@@ -1453,7 +1384,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1453 if (!(rx->flags & IEEE80211_RX_AMSDU)) 1384 if (!(rx->flags & IEEE80211_RX_AMSDU))
1454 return RX_CONTINUE; 1385 return RX_CONTINUE;
1455 1386
1456 err = ieee80211_data_to_8023(rx); 1387 err = __ieee80211_data_to_8023(rx);
1457 if (unlikely(err)) 1388 if (unlikely(err))
1458 return RX_DROP_UNUSABLE; 1389 return RX_DROP_UNUSABLE;
1459 1390
@@ -1639,7 +1570,7 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1639 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 1570 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1640 return RX_DROP_MONITOR; 1571 return RX_DROP_MONITOR;
1641 1572
1642 err = ieee80211_data_to_8023(rx); 1573 err = __ieee80211_data_to_8023(rx);
1643 if (unlikely(err)) 1574 if (unlikely(err))
1644 return RX_DROP_UNUSABLE; 1575 return RX_DROP_UNUSABLE;
1645 1576
@@ -1827,6 +1758,9 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1827 sizeof(mgmt->u.action.u.chan_switch))) 1758 sizeof(mgmt->u.action.u.chan_switch)))
1828 return RX_DROP_MONITOR; 1759 return RX_DROP_MONITOR;
1829 1760
1761 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1762 return RX_DROP_MONITOR;
1763
1830 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN)) 1764 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
1831 return RX_DROP_MONITOR; 1765 return RX_DROP_MONITOR;
1832 1766
@@ -1837,7 +1771,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1837 if (!bss) 1771 if (!bss)
1838 return RX_DROP_MONITOR; 1772 return RX_DROP_MONITOR;
1839 1773
1840 ieee80211_process_chanswitch(sdata, 1774 ieee80211_sta_process_chanswitch(sdata,
1841 &mgmt->u.action.u.chan_switch.sw_elem, bss); 1775 &mgmt->u.action.u.chan_switch.sw_elem, bss);
1842 ieee80211_rx_bss_put(local, bss); 1776 ieee80211_rx_bss_put(local, bss);
1843 break; 1777 break;
@@ -1932,7 +1866,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1932 !ieee80211_is_auth(hdr->frame_control)) 1866 !ieee80211_is_auth(hdr->frame_control))
1933 goto ignore; 1867 goto ignore;
1934 1868
1935 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr); 1869 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL);
1936 ignore: 1870 ignore:
1937 dev_kfree_skb(rx->skb); 1871 dev_kfree_skb(rx->skb);
1938 rx->skb = NULL; 1872 rx->skb = NULL;
@@ -2287,6 +2221,43 @@ static inline u16 seq_sub(u16 sq1, u16 sq2)
2287} 2221}
2288 2222
2289 2223
2224static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
2225 struct tid_ampdu_rx *tid_agg_rx,
2226 int index)
2227{
2228 struct ieee80211_supported_band *sband;
2229 struct ieee80211_rate *rate;
2230 struct ieee80211_rx_status status;
2231
2232 if (!tid_agg_rx->reorder_buf[index])
2233 goto no_frame;
2234
2235 /* release the reordered frames to stack */
2236 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, sizeof(status));
2237 sband = hw->wiphy->bands[status.band];
2238 if (status.flag & RX_FLAG_HT)
2239 rate = sband->bitrates; /* TODO: HT rates */
2240 else
2241 rate = &sband->bitrates[status.rate_idx];
2242 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
2243 &status, rate);
2244 tid_agg_rx->stored_mpdu_num--;
2245 tid_agg_rx->reorder_buf[index] = NULL;
2246
2247no_frame:
2248 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
2249}
2250
2251
2252/*
2253 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
2254 * the skb was added to the buffer longer than this time ago, the earlier
2255 * frames that have not yet been received are assumed to be lost and the skb
2256 * can be released for processing. This may also release other skb's from the
2257 * reorder buffer if there are no additional gaps between the frames.
2258 */
2259#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
2260
2290/* 2261/*
2291 * As it function blongs to Rx path it must be called with 2262 * As it function blongs to Rx path it must be called with
2292 * the proper rcu_read_lock protection for its flow. 2263 * the proper rcu_read_lock protection for its flow.
@@ -2298,12 +2269,8 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2298 u16 mpdu_seq_num, 2269 u16 mpdu_seq_num,
2299 int bar_req) 2270 int bar_req)
2300{ 2271{
2301 struct ieee80211_local *local = hw_to_local(hw);
2302 struct ieee80211_rx_status status;
2303 u16 head_seq_num, buf_size; 2272 u16 head_seq_num, buf_size;
2304 int index; 2273 int index;
2305 struct ieee80211_supported_band *sband;
2306 struct ieee80211_rate *rate;
2307 2274
2308 buf_size = tid_agg_rx->buf_size; 2275 buf_size = tid_agg_rx->buf_size;
2309 head_seq_num = tid_agg_rx->head_seq_num; 2276 head_seq_num = tid_agg_rx->head_seq_num;
@@ -2328,28 +2295,8 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2328 index = seq_sub(tid_agg_rx->head_seq_num, 2295 index = seq_sub(tid_agg_rx->head_seq_num,
2329 tid_agg_rx->ssn) 2296 tid_agg_rx->ssn)
2330 % tid_agg_rx->buf_size; 2297 % tid_agg_rx->buf_size;
2331 2298 ieee80211_release_reorder_frame(hw, tid_agg_rx,
2332 if (tid_agg_rx->reorder_buf[index]) { 2299 index);
2333 /* release the reordered frames to stack */
2334 memcpy(&status,
2335 tid_agg_rx->reorder_buf[index]->cb,
2336 sizeof(status));
2337 sband = local->hw.wiphy->bands[status.band];
2338 if (status.flag & RX_FLAG_HT) {
2339 /* TODO: HT rates */
2340 rate = sband->bitrates;
2341 } else {
2342 rate = &sband->bitrates
2343 [status.rate_idx];
2344 }
2345 __ieee80211_rx_handle_packet(hw,
2346 tid_agg_rx->reorder_buf[index],
2347 &status, rate);
2348 tid_agg_rx->stored_mpdu_num--;
2349 tid_agg_rx->reorder_buf[index] = NULL;
2350 }
2351 tid_agg_rx->head_seq_num =
2352 seq_inc(tid_agg_rx->head_seq_num);
2353 } 2300 }
2354 if (bar_req) 2301 if (bar_req)
2355 return 1; 2302 return 1;
@@ -2376,26 +2323,50 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2376 2323
2377 /* put the frame in the reordering buffer */ 2324 /* put the frame in the reordering buffer */
2378 tid_agg_rx->reorder_buf[index] = skb; 2325 tid_agg_rx->reorder_buf[index] = skb;
2326 tid_agg_rx->reorder_time[index] = jiffies;
2379 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus, 2327 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus,
2380 sizeof(*rxstatus)); 2328 sizeof(*rxstatus));
2381 tid_agg_rx->stored_mpdu_num++; 2329 tid_agg_rx->stored_mpdu_num++;
2382 /* release the buffer until next missing frame */ 2330 /* release the buffer until next missing frame */
2383 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) 2331 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
2384 % tid_agg_rx->buf_size; 2332 % tid_agg_rx->buf_size;
2385 while (tid_agg_rx->reorder_buf[index]) { 2333 if (!tid_agg_rx->reorder_buf[index] &&
2386 /* release the reordered frame back to stack */ 2334 tid_agg_rx->stored_mpdu_num > 1) {
2387 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, 2335 /*
2388 sizeof(status)); 2336 * No buffers ready to be released, but check whether any
2389 sband = local->hw.wiphy->bands[status.band]; 2337 * frames in the reorder buffer have timed out.
2390 if (status.flag & RX_FLAG_HT) 2338 */
2391 rate = sband->bitrates; /* TODO: HT rates */ 2339 int j;
2392 else 2340 int skipped = 1;
2393 rate = &sband->bitrates[status.rate_idx]; 2341 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
2394 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2342 j = (j + 1) % tid_agg_rx->buf_size) {
2395 &status, rate); 2343 if (tid_agg_rx->reorder_buf[j] == NULL) {
2396 tid_agg_rx->stored_mpdu_num--; 2344 skipped++;
2397 tid_agg_rx->reorder_buf[index] = NULL; 2345 continue;
2398 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 2346 }
2347 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
2348 HZ / 10))
2349 break;
2350
2351#ifdef CONFIG_MAC80211_HT_DEBUG
2352 if (net_ratelimit())
2353 printk(KERN_DEBUG "%s: release an RX reorder "
2354 "frame due to timeout on earlier "
2355 "frames\n",
2356 wiphy_name(hw->wiphy));
2357#endif
2358 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
2359
2360 /*
2361 * Increment the head seq# also for the skipped slots.
2362 */
2363 tid_agg_rx->head_seq_num =
2364 (tid_agg_rx->head_seq_num + skipped) &
2365 SEQ_MASK;
2366 skipped = 0;
2367 }
2368 } else while (tid_agg_rx->reorder_buf[index]) {
2369 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
2399 index = seq_sub(tid_agg_rx->head_seq_num, 2370 index = seq_sub(tid_agg_rx->head_seq_num,
2400 tid_agg_rx->ssn) % tid_agg_rx->buf_size; 2371 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
2401 } 2372 }
@@ -2517,6 +2488,18 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2517 return; 2488 return;
2518 } 2489 }
2519 2490
2491 /*
2492 * In theory, the block ack reordering should happen after duplicate
2493 * removal (ieee80211_rx_h_check(), which is an RX handler). As such,
2494 * the call to ieee80211_rx_reorder_ampdu() should really be moved to
2495 * happen as a new RX handler between ieee80211_rx_h_check and
2496 * ieee80211_rx_h_decrypt. This cleanup may eventually happen, but for
2497 * the time being, the call can be here since RX reorder buf processing
2498 * will implicitly skip duplicates. We could, in theory at least,
2499 * process frames that ieee80211_rx_h_passive_scan would drop (e.g.,
2500 * frames from other than operational channel), but that should not
2501 * happen in normal networks.
2502 */
2520 if (!ieee80211_rx_reorder_ampdu(local, skb, status)) 2503 if (!ieee80211_rx_reorder_ampdu(local, skb, status))
2521 __ieee80211_rx_handle_packet(hw, skb, status, rate); 2504 __ieee80211_rx_handle_packet(hw, skb, status, rate);
2522 2505
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 3bf9839f5916..2a8d09ad17ff 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -21,6 +21,7 @@
21#include <net/iw_handler.h> 21#include <net/iw_handler.h>
22 22
23#include "ieee80211_i.h" 23#include "ieee80211_i.h"
24#include "driver-ops.h"
24#include "mesh.h" 25#include "mesh.h"
25 26
26#define IEEE80211_PROBE_DELAY (HZ / 33) 27#define IEEE80211_PROBE_DELAY (HZ / 33)
@@ -202,18 +203,6 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
202 return RX_QUEUED; 203 return RX_QUEUED;
203} 204}
204 205
205void ieee80211_scan_failed(struct ieee80211_local *local)
206{
207 if (WARN_ON(!local->scan_req))
208 return;
209
210 /* notify cfg80211 about the failed scan */
211 if (local->scan_req != &local->int_scan_req)
212 cfg80211_scan_done(local->scan_req, true);
213
214 local->scan_req = NULL;
215}
216
217/* 206/*
218 * inform AP that we will go to sleep so that it will buffer the frames 207 * inform AP that we will go to sleep so that it will buffer the frames
219 * while we scan 208 * while we scan
@@ -253,7 +242,7 @@ static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
253{ 242{
254 struct ieee80211_local *local = sdata->local; 243 struct ieee80211_local *local = sdata->local;
255 244
256 if (!local->powersave) 245 if (!local->ps_sdata)
257 ieee80211_send_nullfunc(local, sdata, 0); 246 ieee80211_send_nullfunc(local, sdata, 0);
258 else { 247 else {
259 /* 248 /*
@@ -274,51 +263,62 @@ static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
274 } 263 }
275} 264}
276 265
266static void ieee80211_restore_scan_ies(struct ieee80211_local *local)
267{
268 kfree(local->scan_req->ie);
269 local->scan_req->ie = local->orig_ies;
270 local->scan_req->ie_len = local->orig_ies_len;
271}
272
277void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) 273void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
278{ 274{
279 struct ieee80211_local *local = hw_to_local(hw); 275 struct ieee80211_local *local = hw_to_local(hw);
280 struct ieee80211_sub_if_data *sdata; 276 struct ieee80211_sub_if_data *sdata;
277 bool was_hw_scan;
281 278
282 if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) 279 mutex_lock(&local->scan_mtx);
280
281 if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) {
282 mutex_unlock(&local->scan_mtx);
283 return; 283 return;
284 }
284 285
285 if (WARN_ON(!local->scan_req)) 286 if (WARN_ON(!local->scan_req)) {
287 mutex_unlock(&local->scan_mtx);
286 return; 288 return;
289 }
290
291 if (local->hw_scanning)
292 ieee80211_restore_scan_ies(local);
287 293
288 if (local->scan_req != &local->int_scan_req) 294 if (local->scan_req != &local->int_scan_req)
289 cfg80211_scan_done(local->scan_req, aborted); 295 cfg80211_scan_done(local->scan_req, aborted);
290 local->scan_req = NULL; 296 local->scan_req = NULL;
291 297
292 local->last_scan_completed = jiffies; 298 was_hw_scan = local->hw_scanning;
299 local->hw_scanning = false;
300 local->sw_scanning = false;
301 local->scan_channel = NULL;
293 302
294 if (local->hw_scanning) { 303 /* we only have to protect scan_req and hw/sw scan */
295 local->hw_scanning = false; 304 mutex_unlock(&local->scan_mtx);
296 /*
297 * Somebody might have requested channel change during scan
298 * that we won't have acted upon, try now. ieee80211_hw_config
299 * will set the flag based on actual changes.
300 */
301 ieee80211_hw_config(local, 0);
302 goto done;
303 }
304 305
305 local->sw_scanning = false;
306 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); 306 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
307 if (was_hw_scan)
308 goto done;
307 309
308 netif_tx_lock_bh(local->mdev); 310 netif_tx_lock_bh(local->mdev);
309 netif_addr_lock(local->mdev); 311 netif_addr_lock(local->mdev);
310 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; 312 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
311 local->ops->configure_filter(local_to_hw(local), 313 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
312 FIF_BCN_PRBRESP_PROMISC, 314 &local->filter_flags,
313 &local->filter_flags, 315 local->mdev->mc_count,
314 local->mdev->mc_count, 316 local->mdev->mc_list);
315 local->mdev->mc_list);
316 317
317 netif_addr_unlock(local->mdev); 318 netif_addr_unlock(local->mdev);
318 netif_tx_unlock_bh(local->mdev); 319 netif_tx_unlock_bh(local->mdev);
319 320
320 if (local->ops->sw_scan_complete) 321 drv_sw_scan_complete(local);
321 local->ops->sw_scan_complete(local_to_hw(local));
322 322
323 mutex_lock(&local->iflist_mtx); 323 mutex_lock(&local->iflist_mtx);
324 list_for_each_entry(sdata, &local->interfaces, list) { 324 list_for_each_entry(sdata, &local->interfaces, list) {
@@ -338,18 +338,160 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
338 if (sdata->vif.type == NL80211_IFTYPE_AP || 338 if (sdata->vif.type == NL80211_IFTYPE_AP ||
339 sdata->vif.type == NL80211_IFTYPE_ADHOC || 339 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
340 sdata->vif.type == NL80211_IFTYPE_MESH_POINT) 340 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
341 ieee80211_if_config(sdata, 341 ieee80211_bss_info_change_notify(
342 IEEE80211_IFCC_BEACON_ENABLED); 342 sdata, BSS_CHANGED_BEACON_ENABLED);
343 } 343 }
344 mutex_unlock(&local->iflist_mtx); 344 mutex_unlock(&local->iflist_mtx);
345 345
346 done: 346 done:
347 ieee80211_recalc_idle(local);
347 ieee80211_mlme_notify_scan_completed(local); 348 ieee80211_mlme_notify_scan_completed(local);
348 ieee80211_ibss_notify_scan_completed(local); 349 ieee80211_ibss_notify_scan_completed(local);
349 ieee80211_mesh_notify_scan_completed(local); 350 ieee80211_mesh_notify_scan_completed(local);
350} 351}
351EXPORT_SYMBOL(ieee80211_scan_completed); 352EXPORT_SYMBOL(ieee80211_scan_completed);
352 353
354static int ieee80211_start_sw_scan(struct ieee80211_local *local)
355{
356 struct ieee80211_sub_if_data *sdata;
357
358 /*
359 * Hardware/driver doesn't support hw_scan, so use software
360 * scanning instead. First send a nullfunc frame with power save
361 * bit on so that AP will buffer the frames for us while we are not
362 * listening, then send probe requests to each channel and wait for
363 * the responses. After all channels are scanned, tune back to the
364 * original channel and send a nullfunc frame with power save bit
365 * off to trigger the AP to send us all the buffered frames.
366 *
367 * Note that while local->sw_scanning is true everything else but
368 * nullfunc frames and probe requests will be dropped in
369 * ieee80211_tx_h_check_assoc().
370 */
371 drv_sw_scan_start(local);
372
373 mutex_lock(&local->iflist_mtx);
374 list_for_each_entry(sdata, &local->interfaces, list) {
375 if (!netif_running(sdata->dev))
376 continue;
377
378 /* disable beaconing */
379 if (sdata->vif.type == NL80211_IFTYPE_AP ||
380 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
381 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
382 ieee80211_bss_info_change_notify(
383 sdata, BSS_CHANGED_BEACON_ENABLED);
384
385 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
386 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) {
387 netif_tx_stop_all_queues(sdata->dev);
388 ieee80211_scan_ps_enable(sdata);
389 }
390 } else
391 netif_tx_stop_all_queues(sdata->dev);
392 }
393 mutex_unlock(&local->iflist_mtx);
394
395 local->scan_state = SCAN_SET_CHANNEL;
396 local->scan_channel_idx = 0;
397
398 netif_addr_lock_bh(local->mdev);
399 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
400 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
401 &local->filter_flags,
402 local->mdev->mc_count,
403 local->mdev->mc_list);
404 netif_addr_unlock_bh(local->mdev);
405
406 /* TODO: start scan as soon as all nullfunc frames are ACKed */
407 queue_delayed_work(local->hw.workqueue, &local->scan_work,
408 IEEE80211_CHANNEL_TIME);
409
410 return 0;
411}
412
413
414static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
415 struct cfg80211_scan_request *req)
416{
417 struct ieee80211_local *local = sdata->local;
418 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
419 int rc;
420
421 if (local->scan_req)
422 return -EBUSY;
423
424 if (local->ops->hw_scan) {
425 u8 *ies;
426 int ielen;
427
428 ies = kmalloc(2 + IEEE80211_MAX_SSID_LEN +
429 local->scan_ies_len + req->ie_len, GFP_KERNEL);
430 if (!ies)
431 return -ENOMEM;
432
433 ielen = ieee80211_build_preq_ies(local, ies,
434 req->ie, req->ie_len);
435 local->orig_ies = req->ie;
436 local->orig_ies_len = req->ie_len;
437 req->ie = ies;
438 req->ie_len = ielen;
439 }
440
441 local->scan_req = req;
442 local->scan_sdata = sdata;
443
444 if (req != &local->int_scan_req &&
445 sdata->vif.type == NL80211_IFTYPE_STATION &&
446 (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE ||
447 ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
448 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE)) {
449 /* actually wait for the assoc to finish/time out */
450 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
451 return 0;
452 }
453
454 if (local->ops->hw_scan)
455 local->hw_scanning = true;
456 else
457 local->sw_scanning = true;
458 /*
459 * Kicking off the scan need not be protected,
460 * only the scan variable stuff, since now
461 * local->scan_req is assigned and other callers
462 * will abort their scan attempts.
463 *
464 * This avoids getting a scan_mtx -> iflist_mtx
465 * dependency, so that the scan completed calls
466 * have more locking freedom.
467 */
468
469 ieee80211_recalc_idle(local);
470 mutex_unlock(&local->scan_mtx);
471
472 if (local->ops->hw_scan)
473 rc = drv_hw_scan(local, local->scan_req);
474 else
475 rc = ieee80211_start_sw_scan(local);
476
477 mutex_lock(&local->scan_mtx);
478
479 if (rc) {
480 if (local->ops->hw_scan) {
481 local->hw_scanning = false;
482 ieee80211_restore_scan_ies(local);
483 } else
484 local->sw_scanning = false;
485
486 ieee80211_recalc_idle(local);
487
488 local->scan_req = NULL;
489 local->scan_sdata = NULL;
490 }
491
492 return rc;
493}
494
353void ieee80211_scan_work(struct work_struct *work) 495void ieee80211_scan_work(struct work_struct *work)
354{ 496{
355 struct ieee80211_local *local = 497 struct ieee80211_local *local =
@@ -359,17 +501,41 @@ void ieee80211_scan_work(struct work_struct *work)
359 int skip, i; 501 int skip, i;
360 unsigned long next_delay = 0; 502 unsigned long next_delay = 0;
361 503
504 mutex_lock(&local->scan_mtx);
505 if (!sdata || !local->scan_req) {
506 mutex_unlock(&local->scan_mtx);
507 return;
508 }
509
510 if (local->scan_req && !(local->sw_scanning || local->hw_scanning)) {
511 struct cfg80211_scan_request *req = local->scan_req;
512 int rc;
513
514 local->scan_req = NULL;
515
516 rc = __ieee80211_start_scan(sdata, req);
517 mutex_unlock(&local->scan_mtx);
518
519 if (rc)
520 ieee80211_scan_completed(&local->hw, true);
521 return;
522 }
523
524 mutex_unlock(&local->scan_mtx);
525
362 /* 526 /*
363 * Avoid re-scheduling when the sdata is going away. 527 * Avoid re-scheduling when the sdata is going away.
364 */ 528 */
365 if (!netif_running(sdata->dev)) 529 if (!netif_running(sdata->dev)) {
530 ieee80211_scan_completed(&local->hw, true);
366 return; 531 return;
532 }
367 533
368 switch (local->scan_state) { 534 switch (local->scan_state) {
369 case SCAN_SET_CHANNEL: 535 case SCAN_SET_CHANNEL:
370 /* if no more bands/channels left, complete scan */ 536 /* if no more bands/channels left, complete scan */
371 if (local->scan_channel_idx >= local->scan_req->n_channels) { 537 if (local->scan_channel_idx >= local->scan_req->n_channels) {
372 ieee80211_scan_completed(local_to_hw(local), false); 538 ieee80211_scan_completed(&local->hw, false);
373 return; 539 return;
374 } 540 }
375 skip = 0; 541 skip = 0;
@@ -393,24 +559,39 @@ void ieee80211_scan_work(struct work_struct *work)
393 if (skip) 559 if (skip)
394 break; 560 break;
395 561
396 next_delay = IEEE80211_PROBE_DELAY + 562 /*
397 usecs_to_jiffies(local->hw.channel_change_time); 563 * Probe delay is used to update the NAV, cf. 11.1.3.2.2
564 * (which unfortunately doesn't say _why_ step a) is done,
565 * but it waits for the probe delay or until a frame is
566 * received - and the received frame would update the NAV).
567 * For now, we do not support waiting until a frame is
568 * received.
569 *
570 * In any case, it is not necessary for a passive scan.
571 */
572 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
573 !local->scan_req->n_ssids) {
574 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
575 break;
576 }
577
578 next_delay = IEEE80211_PROBE_DELAY;
398 local->scan_state = SCAN_SEND_PROBE; 579 local->scan_state = SCAN_SEND_PROBE;
399 break; 580 break;
400 case SCAN_SEND_PROBE: 581 case SCAN_SEND_PROBE:
401 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
402 local->scan_state = SCAN_SET_CHANNEL;
403
404 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
405 !local->scan_req->n_ssids)
406 break;
407 for (i = 0; i < local->scan_req->n_ssids; i++) 582 for (i = 0; i < local->scan_req->n_ssids; i++)
408 ieee80211_send_probe_req( 583 ieee80211_send_probe_req(
409 sdata, NULL, 584 sdata, NULL,
410 local->scan_req->ssids[i].ssid, 585 local->scan_req->ssids[i].ssid,
411 local->scan_req->ssids[i].ssid_len, 586 local->scan_req->ssids[i].ssid_len,
412 local->scan_req->ie, local->scan_req->ie_len); 587 local->scan_req->ie, local->scan_req->ie_len);
588
589 /*
590 * After sending probe requests, wait for probe responses
591 * on the channel.
592 */
413 next_delay = IEEE80211_CHANNEL_TIME; 593 next_delay = IEEE80211_CHANNEL_TIME;
594 local->scan_state = SCAN_SET_CHANNEL;
414 break; 595 break;
415 } 596 }
416 597
@@ -418,150 +599,53 @@ void ieee80211_scan_work(struct work_struct *work)
418 next_delay); 599 next_delay);
419} 600}
420 601
421 602int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
422int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, 603 struct cfg80211_scan_request *req)
423 struct cfg80211_scan_request *req)
424{ 604{
425 struct ieee80211_local *local = scan_sdata->local; 605 int res;
426 struct ieee80211_sub_if_data *sdata;
427
428 if (!req)
429 return -EINVAL;
430
431 if (local->scan_req && local->scan_req != req)
432 return -EBUSY;
433
434 local->scan_req = req;
435
436 /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
437 * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
438 * BSSID: MACAddress
439 * SSID
440 * ScanType: ACTIVE, PASSIVE
441 * ProbeDelay: delay (in microseconds) to be used prior to transmitting
442 * a Probe frame during active scanning
443 * ChannelList
444 * MinChannelTime (>= ProbeDelay), in TU
445 * MaxChannelTime: (>= MinChannelTime), in TU
446 */
447
448 /* MLME-SCAN.confirm
449 * BSSDescriptionSet
450 * ResultCode: SUCCESS, INVALID_PARAMETERS
451 */
452
453 if (local->sw_scanning || local->hw_scanning) {
454 if (local->scan_sdata == scan_sdata)
455 return 0;
456 return -EBUSY;
457 }
458
459 if (local->ops->hw_scan) {
460 int rc;
461
462 local->hw_scanning = true;
463 rc = local->ops->hw_scan(local_to_hw(local), req);
464 if (rc) {
465 local->hw_scanning = false;
466 return rc;
467 }
468 local->scan_sdata = scan_sdata;
469 return 0;
470 }
471
472 /*
473 * Hardware/driver doesn't support hw_scan, so use software
474 * scanning instead. First send a nullfunc frame with power save
475 * bit on so that AP will buffer the frames for us while we are not
476 * listening, then send probe requests to each channel and wait for
477 * the responses. After all channels are scanned, tune back to the
478 * original channel and send a nullfunc frame with power save bit
479 * off to trigger the AP to send us all the buffered frames.
480 *
481 * Note that while local->sw_scanning is true everything else but
482 * nullfunc frames and probe requests will be dropped in
483 * ieee80211_tx_h_check_assoc().
484 */
485 local->sw_scanning = true;
486 if (local->ops->sw_scan_start)
487 local->ops->sw_scan_start(local_to_hw(local));
488 606
489 mutex_lock(&local->iflist_mtx); 607 mutex_lock(&sdata->local->scan_mtx);
490 list_for_each_entry(sdata, &local->interfaces, list) { 608 res = __ieee80211_start_scan(sdata, req);
491 if (!netif_running(sdata->dev)) 609 mutex_unlock(&sdata->local->scan_mtx);
492 continue;
493 610
494 /* disable beaconing */ 611 return res;
495 if (sdata->vif.type == NL80211_IFTYPE_AP || 612}
496 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
497 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
498 ieee80211_if_config(sdata,
499 IEEE80211_IFCC_BEACON_ENABLED);
500 613
501 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 614int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
502 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { 615 const u8 *ssid, u8 ssid_len)
503 netif_tx_stop_all_queues(sdata->dev); 616{
504 ieee80211_scan_ps_enable(sdata); 617 struct ieee80211_local *local = sdata->local;
505 } 618 int ret = -EBUSY;
506 } else
507 netif_tx_stop_all_queues(sdata->dev);
508 }
509 mutex_unlock(&local->iflist_mtx);
510 619
511 local->scan_state = SCAN_SET_CHANNEL; 620 mutex_lock(&local->scan_mtx);
512 local->scan_channel_idx = 0;
513 local->scan_sdata = scan_sdata;
514 local->scan_req = req;
515 621
516 netif_addr_lock_bh(local->mdev); 622 /* busy scanning */
517 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; 623 if (local->scan_req)
518 local->ops->configure_filter(local_to_hw(local), 624 goto unlock;
519 FIF_BCN_PRBRESP_PROMISC,
520 &local->filter_flags,
521 local->mdev->mc_count,
522 local->mdev->mc_list);
523 netif_addr_unlock_bh(local->mdev);
524 625
525 /* TODO: start scan as soon as all nullfunc frames are ACKed */ 626 memcpy(local->int_scan_req.ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
526 queue_delayed_work(local->hw.workqueue, &local->scan_work, 627 local->int_scan_req.ssids[0].ssid_len = ssid_len;
527 IEEE80211_CHANNEL_TIME);
528 628
529 return 0; 629 ret = __ieee80211_start_scan(sdata, &sdata->local->int_scan_req);
630 unlock:
631 mutex_unlock(&local->scan_mtx);
632 return ret;
530} 633}
531 634
532 635void ieee80211_scan_cancel(struct ieee80211_local *local)
533int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
534 struct cfg80211_scan_request *req)
535{ 636{
536 struct ieee80211_local *local = sdata->local; 637 bool swscan;
537 struct ieee80211_if_managed *ifmgd;
538
539 if (!req)
540 return -EINVAL;
541 638
542 if (local->scan_req && local->scan_req != req) 639 cancel_delayed_work_sync(&local->scan_work);
543 return -EBUSY;
544
545 local->scan_req = req;
546
547 if (sdata->vif.type != NL80211_IFTYPE_STATION)
548 return ieee80211_start_scan(sdata, req);
549 640
550 /* 641 /*
551 * STA has a state machine that might need to defer scanning 642 * Only call this function when a scan can't be
552 * while it's trying to associate/authenticate, therefore we 643 * queued -- mostly at suspend under RTNL.
553 * queue it up to the state machine in that case.
554 */ 644 */
645 mutex_lock(&local->scan_mtx);
646 swscan = local->sw_scanning;
647 mutex_unlock(&local->scan_mtx);
555 648
556 if (local->sw_scanning || local->hw_scanning) { 649 if (swscan)
557 if (local->scan_sdata == sdata) 650 ieee80211_scan_completed(&local->hw, true);
558 return 0;
559 return -EBUSY;
560 }
561
562 ifmgd = &sdata->u.mgd;
563 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
564 queue_work(local->hw.workqueue, &ifmgd->work);
565
566 return 0;
567} 651}
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index 5f7a2624ed74..68953033403d 100644
--- a/net/mac80211/spectmgmt.c
+++ b/net/mac80211/spectmgmt.c
@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17#include <linux/ieee80211.h> 17#include <linux/ieee80211.h>
18#include <net/wireless.h> 18#include <net/cfg80211.h>
19#include <net/mac80211.h> 19#include <net/mac80211.h>
20#include "ieee80211_i.h" 20#include "ieee80211_i.h"
21#include "sta_info.h" 21#include "sta_info.h"
@@ -84,104 +84,3 @@ void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
84 mgmt->sa, mgmt->bssid, 84 mgmt->sa, mgmt->bssid,
85 mgmt->u.action.u.measurement.dialog_token); 85 mgmt->u.action.u.measurement.dialog_token);
86} 86}
87
88void ieee80211_chswitch_work(struct work_struct *work)
89{
90 struct ieee80211_sub_if_data *sdata =
91 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
92 struct ieee80211_bss *bss;
93 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
94
95 if (!netif_running(sdata->dev))
96 return;
97
98 bss = ieee80211_rx_bss_get(sdata->local, ifmgd->bssid,
99 sdata->local->hw.conf.channel->center_freq,
100 ifmgd->ssid, ifmgd->ssid_len);
101 if (!bss)
102 goto exit;
103
104 sdata->local->oper_channel = sdata->local->csa_channel;
105 /* XXX: shouldn't really modify cfg80211-owned data! */
106 if (!ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL))
107 bss->cbss.channel = sdata->local->oper_channel;
108
109 ieee80211_rx_bss_put(sdata->local, bss);
110exit:
111 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
112 ieee80211_wake_queues_by_reason(&sdata->local->hw,
113 IEEE80211_QUEUE_STOP_REASON_CSA);
114}
115
116void ieee80211_chswitch_timer(unsigned long data)
117{
118 struct ieee80211_sub_if_data *sdata =
119 (struct ieee80211_sub_if_data *) data;
120 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
121
122 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work);
123}
124
125void ieee80211_process_chanswitch(struct ieee80211_sub_if_data *sdata,
126 struct ieee80211_channel_sw_ie *sw_elem,
127 struct ieee80211_bss *bss)
128{
129 struct ieee80211_channel *new_ch;
130 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
131 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
132
133 /* FIXME: Handle ADHOC later */
134 if (sdata->vif.type != NL80211_IFTYPE_STATION)
135 return;
136
137 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATED)
138 return;
139
140 if (sdata->local->sw_scanning || sdata->local->hw_scanning)
141 return;
142
143 /* Disregard subsequent beacons if we are already running a timer
144 processing a CSA */
145
146 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
147 return;
148
149 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
150 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
151 return;
152
153 sdata->local->csa_channel = new_ch;
154
155 if (sw_elem->count <= 1) {
156 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work);
157 } else {
158 ieee80211_stop_queues_by_reason(&sdata->local->hw,
159 IEEE80211_QUEUE_STOP_REASON_CSA);
160 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
161 mod_timer(&ifmgd->chswitch_timer,
162 jiffies +
163 msecs_to_jiffies(sw_elem->count *
164 bss->cbss.beacon_interval));
165 }
166}
167
168void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
169 u16 capab_info, u8 *pwr_constr_elem,
170 u8 pwr_constr_elem_len)
171{
172 struct ieee80211_conf *conf = &sdata->local->hw.conf;
173
174 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
175 return;
176
177 /* Power constraint IE length should be 1 octet */
178 if (pwr_constr_elem_len != 1)
179 return;
180
181 if ((*pwr_constr_elem <= conf->channel->max_power) &&
182 (*pwr_constr_elem != sdata->local->power_constr_level)) {
183 sdata->local->power_constr_level = *pwr_constr_elem;
184 ieee80211_hw_config(sdata->local, 0);
185 }
186}
187
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index c5f14e6bbde2..a360bceeba59 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -19,6 +19,7 @@
19 19
20#include <net/mac80211.h> 20#include <net/mac80211.h>
21#include "ieee80211_i.h" 21#include "ieee80211_i.h"
22#include "driver-ops.h"
22#include "rate.h" 23#include "rate.h"
23#include "sta_info.h" 24#include "sta_info.h"
24#include "debugfs_sta.h" 25#include "debugfs_sta.h"
@@ -43,6 +44,15 @@
43 * When the insertion fails (sta_info_insert()) returns non-zero), the 44 * When the insertion fails (sta_info_insert()) returns non-zero), the
44 * structure will have been freed by sta_info_insert()! 45 * structure will have been freed by sta_info_insert()!
45 * 46 *
47 * sta entries are added by mac80211 when you establish a link with a
48 * peer. This means different things for the different type of interfaces
49 * we support. For a regular station this mean we add the AP sta when we
50 * receive an assocation response from the AP. For IBSS this occurs when
51 * we receive a probe response or a beacon from target IBSS network. For
52 * WDS we add the sta for the peer imediately upon device open. When using
53 * AP mode we add stations for each respective station upon request from
54 * userspace through nl80211.
55 *
46 * Because there are debugfs entries for each station, and adding those 56 * Because there are debugfs entries for each station, and adding those
47 * must be able to sleep, it is also possible to "pin" a station entry, 57 * must be able to sleep, it is also possible to "pin" a station entry,
48 * that means it can be removed from the hash table but not be freed. 58 * that means it can be removed from the hash table but not be freed.
@@ -292,6 +302,9 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
292 skb_queue_head_init(&sta->ps_tx_buf); 302 skb_queue_head_init(&sta->ps_tx_buf);
293 skb_queue_head_init(&sta->tx_filtered); 303 skb_queue_head_init(&sta->tx_filtered);
294 304
305 for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
306 sta->last_seq_ctrl[i] = cpu_to_le16(USHORT_MAX);
307
295#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 308#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
296 printk(KERN_DEBUG "%s: Allocated STA %pM\n", 309 printk(KERN_DEBUG "%s: Allocated STA %pM\n",
297 wiphy_name(local->hw.wiphy), sta->sta.addr); 310 wiphy_name(local->hw.wiphy), sta->sta.addr);
@@ -346,8 +359,7 @@ int sta_info_insert(struct sta_info *sta)
346 struct ieee80211_sub_if_data, 359 struct ieee80211_sub_if_data,
347 u.ap); 360 u.ap);
348 361
349 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 362 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta);
350 STA_NOTIFY_ADD, &sta->sta);
351 } 363 }
352 364
353#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 365#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -405,8 +417,7 @@ static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
405 417
406 if (sta->local->ops->set_tim) { 418 if (sta->local->ops->set_tim) {
407 sta->local->tim_in_locked_section = true; 419 sta->local->tim_in_locked_section = true;
408 sta->local->ops->set_tim(local_to_hw(sta->local), 420 drv_set_tim(sta->local, &sta->sta, true);
409 &sta->sta, true);
410 sta->local->tim_in_locked_section = false; 421 sta->local->tim_in_locked_section = false;
411 } 422 }
412} 423}
@@ -431,8 +442,7 @@ static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
431 442
432 if (sta->local->ops->set_tim) { 443 if (sta->local->ops->set_tim) {
433 sta->local->tim_in_locked_section = true; 444 sta->local->tim_in_locked_section = true;
434 sta->local->ops->set_tim(local_to_hw(sta->local), 445 drv_set_tim(sta->local, &sta->sta, false);
435 &sta->sta, false);
436 sta->local->tim_in_locked_section = false; 446 sta->local->tim_in_locked_section = false;
437 } 447 }
438} 448}
@@ -482,8 +492,8 @@ static void __sta_info_unlink(struct sta_info **sta)
482 struct ieee80211_sub_if_data, 492 struct ieee80211_sub_if_data,
483 u.ap); 493 u.ap);
484 494
485 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 495 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
486 STA_NOTIFY_REMOVE, &(*sta)->sta); 496 &(*sta)->sta);
487 } 497 }
488 498
489 if (ieee80211_vif_is_mesh(&sdata->vif)) { 499 if (ieee80211_vif_is_mesh(&sdata->vif)) {
@@ -543,9 +553,8 @@ void sta_info_unlink(struct sta_info **sta)
543 spin_unlock_irqrestore(&local->sta_lock, flags); 553 spin_unlock_irqrestore(&local->sta_lock, flags);
544} 554}
545 555
546static inline int sta_info_buffer_expired(struct ieee80211_local *local, 556static int sta_info_buffer_expired(struct sta_info *sta,
547 struct sta_info *sta, 557 struct sk_buff *skb)
548 struct sk_buff *skb)
549{ 558{
550 struct ieee80211_tx_info *info; 559 struct ieee80211_tx_info *info;
551 int timeout; 560 int timeout;
@@ -556,8 +565,9 @@ static inline int sta_info_buffer_expired(struct ieee80211_local *local,
556 info = IEEE80211_SKB_CB(skb); 565 info = IEEE80211_SKB_CB(skb);
557 566
558 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ 567 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
559 timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 / 568 timeout = (sta->listen_interval *
560 15625) * HZ; 569 sta->sdata->vif.bss_conf.beacon_int *
570 32 / 15625) * HZ;
561 if (timeout < STA_TX_BUFFER_EXPIRE) 571 if (timeout < STA_TX_BUFFER_EXPIRE)
562 timeout = STA_TX_BUFFER_EXPIRE; 572 timeout = STA_TX_BUFFER_EXPIRE;
563 return time_after(jiffies, info->control.jiffies + timeout); 573 return time_after(jiffies, info->control.jiffies + timeout);
@@ -577,7 +587,7 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
577 for (;;) { 587 for (;;) {
578 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); 588 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
579 skb = skb_peek(&sta->ps_tx_buf); 589 skb = skb_peek(&sta->ps_tx_buf);
580 if (sta_info_buffer_expired(local, sta, skb)) 590 if (sta_info_buffer_expired(sta, skb))
581 skb = __skb_dequeue(&sta->ps_tx_buf); 591 skb = __skb_dequeue(&sta->ps_tx_buf);
582 else 592 else
583 skb = NULL; 593 skb = NULL;
@@ -610,6 +620,9 @@ static void sta_info_cleanup(unsigned long data)
610 sta_info_cleanup_expire_buffered(local, sta); 620 sta_info_cleanup_expire_buffered(local, sta);
611 rcu_read_unlock(); 621 rcu_read_unlock();
612 622
623 if (local->quiescing)
624 return;
625
613 local->sta_cleanup.expires = 626 local->sta_cleanup.expires =
614 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 627 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
615 add_timer(&local->sta_cleanup); 628 add_timer(&local->sta_cleanup);
@@ -686,41 +699,10 @@ static void sta_info_debugfs_add_work(struct work_struct *work)
686} 699}
687#endif 700#endif
688 701
689static void __ieee80211_run_pending_flush(struct ieee80211_local *local)
690{
691 struct sta_info *sta;
692 unsigned long flags;
693
694 ASSERT_RTNL();
695
696 spin_lock_irqsave(&local->sta_lock, flags);
697 while (!list_empty(&local->sta_flush_list)) {
698 sta = list_first_entry(&local->sta_flush_list,
699 struct sta_info, list);
700 list_del(&sta->list);
701 spin_unlock_irqrestore(&local->sta_lock, flags);
702 sta_info_destroy(sta);
703 spin_lock_irqsave(&local->sta_lock, flags);
704 }
705 spin_unlock_irqrestore(&local->sta_lock, flags);
706}
707
708static void ieee80211_sta_flush_work(struct work_struct *work)
709{
710 struct ieee80211_local *local =
711 container_of(work, struct ieee80211_local, sta_flush_work);
712
713 rtnl_lock();
714 __ieee80211_run_pending_flush(local);
715 rtnl_unlock();
716}
717
718void sta_info_init(struct ieee80211_local *local) 702void sta_info_init(struct ieee80211_local *local)
719{ 703{
720 spin_lock_init(&local->sta_lock); 704 spin_lock_init(&local->sta_lock);
721 INIT_LIST_HEAD(&local->sta_list); 705 INIT_LIST_HEAD(&local->sta_list);
722 INIT_LIST_HEAD(&local->sta_flush_list);
723 INIT_WORK(&local->sta_flush_work, ieee80211_sta_flush_work);
724 706
725 setup_timer(&local->sta_cleanup, sta_info_cleanup, 707 setup_timer(&local->sta_cleanup, sta_info_cleanup,
726 (unsigned long)local); 708 (unsigned long)local);
@@ -741,7 +723,6 @@ int sta_info_start(struct ieee80211_local *local)
741void sta_info_stop(struct ieee80211_local *local) 723void sta_info_stop(struct ieee80211_local *local)
742{ 724{
743 del_timer(&local->sta_cleanup); 725 del_timer(&local->sta_cleanup);
744 cancel_work_sync(&local->sta_flush_work);
745#ifdef CONFIG_MAC80211_DEBUGFS 726#ifdef CONFIG_MAC80211_DEBUGFS
746 /* 727 /*
747 * Make sure the debugfs adding work isn't pending after this 728 * Make sure the debugfs adding work isn't pending after this
@@ -752,10 +733,7 @@ void sta_info_stop(struct ieee80211_local *local)
752 cancel_work_sync(&local->sta_debugfs_add); 733 cancel_work_sync(&local->sta_debugfs_add);
753#endif 734#endif
754 735
755 rtnl_lock();
756 sta_info_flush(local, NULL); 736 sta_info_flush(local, NULL);
757 __ieee80211_run_pending_flush(local);
758 rtnl_unlock();
759} 737}
760 738
761/** 739/**
@@ -767,7 +745,7 @@ void sta_info_stop(struct ieee80211_local *local)
767 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs 745 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
768 */ 746 */
769int sta_info_flush(struct ieee80211_local *local, 747int sta_info_flush(struct ieee80211_local *local,
770 struct ieee80211_sub_if_data *sdata) 748 struct ieee80211_sub_if_data *sdata)
771{ 749{
772 struct sta_info *sta, *tmp; 750 struct sta_info *sta, *tmp;
773 LIST_HEAD(tmp_list); 751 LIST_HEAD(tmp_list);
@@ -775,7 +753,6 @@ int sta_info_flush(struct ieee80211_local *local,
775 unsigned long flags; 753 unsigned long flags;
776 754
777 might_sleep(); 755 might_sleep();
778 ASSERT_RTNL();
779 756
780 spin_lock_irqsave(&local->sta_lock, flags); 757 spin_lock_irqsave(&local->sta_lock, flags);
781 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 758 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
@@ -795,39 +772,6 @@ int sta_info_flush(struct ieee80211_local *local,
795 return ret; 772 return ret;
796} 773}
797 774
798/**
799 * sta_info_flush_delayed - flush matching STA entries from the STA table
800 *
801 * This function unlinks all stations for a given interface and queues
802 * them for freeing. Note that the workqueue function scheduled here has
803 * to run before any new keys can be added to the system to avoid set_key()
804 * callback ordering issues.
805 *
806 * @sdata: the interface
807 */
808void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata)
809{
810 struct ieee80211_local *local = sdata->local;
811 struct sta_info *sta, *tmp;
812 unsigned long flags;
813 bool work = false;
814
815 spin_lock_irqsave(&local->sta_lock, flags);
816 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
817 if (sdata == sta->sdata) {
818 __sta_info_unlink(&sta);
819 if (sta) {
820 list_add_tail(&sta->list,
821 &local->sta_flush_list);
822 work = true;
823 }
824 }
825 }
826 if (work)
827 schedule_work(&local->sta_flush_work);
828 spin_unlock_irqrestore(&local->sta_lock, flags);
829}
830
831void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 775void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
832 unsigned long exp_time) 776 unsigned long exp_time)
833{ 777{
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 5534d489f506..49a1a1f76511 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -88,6 +88,7 @@ struct tid_ampdu_tx {
88 * struct tid_ampdu_rx - TID aggregation information (Rx). 88 * struct tid_ampdu_rx - TID aggregation information (Rx).
89 * 89 *
90 * @reorder_buf: buffer to reorder incoming aggregated MPDUs 90 * @reorder_buf: buffer to reorder incoming aggregated MPDUs
91 * @reorder_time: jiffies when skb was added
91 * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value) 92 * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
92 * @head_seq_num: head sequence number in reordering buffer. 93 * @head_seq_num: head sequence number in reordering buffer.
93 * @stored_mpdu_num: number of MPDUs in reordering buffer 94 * @stored_mpdu_num: number of MPDUs in reordering buffer
@@ -99,6 +100,7 @@ struct tid_ampdu_tx {
99 */ 100 */
100struct tid_ampdu_rx { 101struct tid_ampdu_rx {
101 struct sk_buff **reorder_buf; 102 struct sk_buff **reorder_buf;
103 unsigned long *reorder_time;
102 struct timer_list session_timer; 104 struct timer_list session_timer;
103 u16 head_seq_num; 105 u16 head_seq_num;
104 u16 stored_mpdu_num; 106 u16 stored_mpdu_num;
@@ -214,6 +216,7 @@ struct sta_ampdu_mlme {
214 * @plink_state: peer link state 216 * @plink_state: peer link state
215 * @plink_timeout: timeout of peer link 217 * @plink_timeout: timeout of peer link
216 * @plink_timer: peer link watch timer 218 * @plink_timer: peer link watch timer
219 * @plink_timer_was_running: used by suspend/resume to restore timers
217 * @debugfs: debug filesystem info 220 * @debugfs: debug filesystem info
218 * @sta: station information we share with the driver 221 * @sta: station information we share with the driver
219 */ 222 */
@@ -291,6 +294,7 @@ struct sta_info {
291 __le16 reason; 294 __le16 reason;
292 u8 plink_retries; 295 u8 plink_retries;
293 bool ignore_plink_timer; 296 bool ignore_plink_timer;
297 bool plink_timer_was_running;
294 enum plink_state plink_state; 298 enum plink_state plink_state;
295 u32 plink_timeout; 299 u32 plink_timeout;
296 struct timer_list plink_timer; 300 struct timer_list plink_timer;
@@ -442,8 +446,7 @@ void sta_info_init(struct ieee80211_local *local);
442int sta_info_start(struct ieee80211_local *local); 446int sta_info_start(struct ieee80211_local *local);
443void sta_info_stop(struct ieee80211_local *local); 447void sta_info_stop(struct ieee80211_local *local);
444int sta_info_flush(struct ieee80211_local *local, 448int sta_info_flush(struct ieee80211_local *local,
445 struct ieee80211_sub_if_data *sdata); 449 struct ieee80211_sub_if_data *sdata);
446void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata);
447void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 450void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
448 unsigned long exp_time); 451 unsigned long exp_time);
449 452
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 38fa111d2dc6..964b7faa7f17 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -13,6 +13,7 @@
13#include <asm/unaligned.h> 13#include <asm/unaligned.h>
14 14
15#include <net/mac80211.h> 15#include <net/mac80211.h>
16#include "driver-ops.h"
16#include "key.h" 17#include "key.h"
17#include "tkip.h" 18#include "tkip.h"
18#include "wep.h" 19#include "wep.h"
@@ -307,9 +308,8 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
307 if (is_multicast_ether_addr(ra)) 308 if (is_multicast_ether_addr(ra))
308 sta_addr = bcast; 309 sta_addr = bcast;
309 310
310 key->local->ops->update_tkip_key( 311 drv_update_tkip_key(key->local, &key->conf, sta_addr,
311 local_to_hw(key->local), &key->conf, 312 iv32, key->u.tkip.rx[queue].p1k);
312 sta_addr, iv32, key->u.tkip.rx[queue].p1k);
313 } 313 }
314 } 314 }
315 315
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 63656266d567..d238a8939a09 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -25,6 +25,7 @@
25#include <asm/unaligned.h> 25#include <asm/unaligned.h>
26 26
27#include "ieee80211_i.h" 27#include "ieee80211_i.h"
28#include "driver-ops.h"
28#include "led.h" 29#include "led.h"
29#include "mesh.h" 30#include "mesh.h"
30#include "wep.h" 31#include "wep.h"
@@ -399,6 +400,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
399 sta_info_set_tim_bit(sta); 400 sta_info_set_tim_bit(sta);
400 401
401 info->control.jiffies = jiffies; 402 info->control.jiffies = jiffies;
403 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
402 skb_queue_tail(&sta->ps_tx_buf, tx->skb); 404 skb_queue_tail(&sta->ps_tx_buf, tx->skb);
403 return TX_QUEUED; 405 return TX_QUEUED;
404 } 406 }
@@ -409,8 +411,24 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
409 sta->sta.addr); 411 sta->sta.addr);
410 } 412 }
411#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 413#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
412 clear_sta_flags(sta, WLAN_STA_PSPOLL); 414 if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
415 /*
416 * The sleeping station with pending data is now snoozing.
417 * It queried us for its buffered frames and will go back
418 * to deep sleep once it got everything.
419 *
420 * inform the driver, in case the hardware does powersave
421 * frame filtering and keeps a station blacklist on its own
422 * (e.g: p54), so that frames can be delivered unimpeded.
423 *
424 * Note: It should be safe to disable the filter now.
425 * As, it is really unlikely that we still have any pending
426 * frame for this station in the hw's buffers/fifos left,
427 * that is not rejected with a unsuccessful tx_status yet.
428 */
413 429
430 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
431 }
414 return TX_CONTINUE; 432 return TX_CONTINUE;
415} 433}
416 434
@@ -429,7 +447,7 @@ ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
429static ieee80211_tx_result debug_noinline 447static ieee80211_tx_result debug_noinline
430ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) 448ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
431{ 449{
432 struct ieee80211_key *key; 450 struct ieee80211_key *key = NULL;
433 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 451 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 452 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
435 453
@@ -500,7 +518,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
500 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 518 sband = tx->local->hw.wiphy->bands[tx->channel->band];
501 519
502 len = min_t(int, tx->skb->len + FCS_LEN, 520 len = min_t(int, tx->skb->len + FCS_LEN,
503 tx->local->fragmentation_threshold); 521 tx->local->hw.wiphy->frag_threshold);
504 522
505 /* set up the tx rate control struct we give the RC algo */ 523 /* set up the tx rate control struct we give the RC algo */
506 txrc.hw = local_to_hw(tx->local); 524 txrc.hw = local_to_hw(tx->local);
@@ -511,8 +529,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
511 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx; 529 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
512 530
513 /* set up RTS protection if desired */ 531 /* set up RTS protection if desired */
514 if (tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD && 532 if (len > tx->local->hw.wiphy->rts_threshold) {
515 len > tx->local->rts_threshold) {
516 txrc.rts = rts = true; 533 txrc.rts = rts = true;
517 } 534 }
518 535
@@ -542,6 +559,10 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
542 if (unlikely(!info->control.rates[0].count)) 559 if (unlikely(!info->control.rates[0].count))
543 info->control.rates[0].count = 1; 560 info->control.rates[0].count = 1;
544 561
562 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
563 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
564 info->control.rates[0].count = 1;
565
545 if (is_multicast_ether_addr(hdr->addr1)) { 566 if (is_multicast_ether_addr(hdr->addr1)) {
546 /* 567 /*
547 * XXX: verify the rate is in the basic rateset 568 * XXX: verify the rate is in the basic rateset
@@ -754,7 +775,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
754 struct sk_buff *skb = tx->skb; 775 struct sk_buff *skb = tx->skb;
755 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 776 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
756 struct ieee80211_hdr *hdr = (void *)skb->data; 777 struct ieee80211_hdr *hdr = (void *)skb->data;
757 int frag_threshold = tx->local->fragmentation_threshold; 778 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
758 int hdrlen; 779 int hdrlen;
759 int fragnum; 780 int fragnum;
760 781
@@ -852,6 +873,8 @@ ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
852 873
853 do { 874 do {
854 hdr = (void *) skb->data; 875 hdr = (void *) skb->data;
876 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
877 break; /* must not overwrite AID */
855 next_len = skb->next ? skb->next->len : 0; 878 next_len = skb->next ? skb->next->len : 0;
856 group_addr = is_multicast_ether_addr(hdr->addr1); 879 group_addr = is_multicast_ether_addr(hdr->addr1);
857 880
@@ -885,9 +908,8 @@ ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
885 * deal with packet injection down monitor interface 908 * deal with packet injection down monitor interface
886 * with Radiotap Header -- only called for monitor mode interface 909 * with Radiotap Header -- only called for monitor mode interface
887 */ 910 */
888static ieee80211_tx_result 911static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
889__ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, 912 struct sk_buff *skb)
890 struct sk_buff *skb)
891{ 913{
892 /* 914 /*
893 * this is the moment to interpret and discard the radiotap header that 915 * this is the moment to interpret and discard the radiotap header that
@@ -938,7 +960,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
938 * on transmission 960 * on transmission
939 */ 961 */
940 if (skb->len < (iterator.max_length + FCS_LEN)) 962 if (skb->len < (iterator.max_length + FCS_LEN))
941 return TX_DROP; 963 return false;
942 964
943 skb_trim(skb, skb->len - FCS_LEN); 965 skb_trim(skb, skb->len - FCS_LEN);
944 } 966 }
@@ -960,7 +982,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
960 } 982 }
961 983
962 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ 984 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
963 return TX_DROP; 985 return false;
964 986
965 /* 987 /*
966 * remove the radiotap header 988 * remove the radiotap header
@@ -969,7 +991,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
969 */ 991 */
970 skb_pull(skb, iterator.max_length); 992 skb_pull(skb, iterator.max_length);
971 993
972 return TX_CONTINUE; 994 return true;
973} 995}
974 996
975/* 997/*
@@ -1003,7 +1025,7 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1003 /* process and remove the injection radiotap header */ 1025 /* process and remove the injection radiotap header */
1004 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1026 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1005 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) { 1027 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
1006 if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP) 1028 if (!__ieee80211_parse_tx_radiotap(tx, skb))
1007 return TX_DROP; 1029 return TX_DROP;
1008 1030
1009 /* 1031 /*
@@ -1067,12 +1089,15 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1067 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1089 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1068 } else { 1090 } else {
1069 tx->flags |= IEEE80211_TX_UNICAST; 1091 tx->flags |= IEEE80211_TX_UNICAST;
1070 info->flags &= ~IEEE80211_TX_CTL_NO_ACK; 1092 if (unlikely(local->wifi_wme_noack_test))
1093 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1094 else
1095 info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
1071 } 1096 }
1072 1097
1073 if (tx->flags & IEEE80211_TX_FRAGMENTED) { 1098 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
1074 if ((tx->flags & IEEE80211_TX_UNICAST) && 1099 if ((tx->flags & IEEE80211_TX_UNICAST) &&
1075 skb->len + FCS_LEN > local->fragmentation_threshold && 1100 skb->len + FCS_LEN > local->hw.wiphy->frag_threshold &&
1076 !(info->flags & IEEE80211_TX_CTL_AMPDU)) 1101 !(info->flags & IEEE80211_TX_CTL_AMPDU))
1077 tx->flags |= IEEE80211_TX_FRAGMENTED; 1102 tx->flags |= IEEE80211_TX_FRAGMENTED;
1078 else 1103 else
@@ -1147,7 +1172,7 @@ static int __ieee80211_tx(struct ieee80211_local *local,
1147 1172
1148 next = skb->next; 1173 next = skb->next;
1149 len = skb->len; 1174 len = skb->len;
1150 ret = local->ops->tx(local_to_hw(local), skb); 1175 ret = drv_tx(local, skb);
1151 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) { 1176 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) {
1152 dev_kfree_skb(skb); 1177 dev_kfree_skb(skb);
1153 ret = NETDEV_TX_OK; 1178 ret = NETDEV_TX_OK;
@@ -1213,7 +1238,6 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1213 bool txpending) 1238 bool txpending)
1214{ 1239{
1215 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1240 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1216 struct sta_info *sta;
1217 struct ieee80211_tx_data tx; 1241 struct ieee80211_tx_data tx;
1218 ieee80211_tx_result res_prepare; 1242 ieee80211_tx_result res_prepare;
1219 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1243 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
@@ -1245,7 +1269,6 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1245 return; 1269 return;
1246 } 1270 }
1247 1271
1248 sta = tx.sta;
1249 tx.channel = local->hw.conf.channel; 1272 tx.channel = local->hw.conf.channel;
1250 info->band = tx.channel->band; 1273 info->band = tx.channel->band;
1251 1274
@@ -1392,7 +1415,8 @@ int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
1392 } 1415 }
1393 1416
1394 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && 1417 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1395 local->hw.conf.dynamic_ps_timeout > 0) { 1418 local->hw.conf.dynamic_ps_timeout > 0 &&
1419 !local->sw_scanning && !local->hw_scanning && local->ps_sdata) {
1396 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 1420 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1397 ieee80211_stop_queues_by_reason(&local->hw, 1421 ieee80211_stop_queues_by_reason(&local->hw,
1398 IEEE80211_QUEUE_STOP_REASON_PS); 1422 IEEE80211_QUEUE_STOP_REASON_PS);
@@ -1591,7 +1615,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1591{ 1615{
1592 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1616 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593 struct ieee80211_local *local = sdata->local; 1617 struct ieee80211_local *local = sdata->local;
1594 int ret = 1, head_need; 1618 int ret = NETDEV_TX_BUSY, head_need;
1595 u16 ethertype, hdrlen, meshhdrlen = 0; 1619 u16 ethertype, hdrlen, meshhdrlen = 0;
1596 __le16 fc; 1620 __le16 fc;
1597 struct ieee80211_hdr hdr; 1621 struct ieee80211_hdr hdr;
@@ -2086,18 +2110,18 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2086 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 2110 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2087 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2111 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2088 struct ieee80211_hdr *hdr; 2112 struct ieee80211_hdr *hdr;
2113 struct sk_buff *presp = rcu_dereference(ifibss->presp);
2089 2114
2090 if (!ifibss->probe_resp) 2115 if (!presp)
2091 goto out; 2116 goto out;
2092 2117
2093 skb = skb_copy(ifibss->probe_resp, GFP_ATOMIC); 2118 skb = skb_copy(presp, GFP_ATOMIC);
2094 if (!skb) 2119 if (!skb)
2095 goto out; 2120 goto out;
2096 2121
2097 hdr = (struct ieee80211_hdr *) skb->data; 2122 hdr = (struct ieee80211_hdr *) skb->data;
2098 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2123 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2099 IEEE80211_STYPE_BEACON); 2124 IEEE80211_STYPE_BEACON);
2100
2101 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 2125 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2102 struct ieee80211_mgmt *mgmt; 2126 struct ieee80211_mgmt *mgmt;
2103 u8 *pos; 2127 u8 *pos;
@@ -2117,7 +2141,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2117 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 2141 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
2118 /* BSSID is left zeroed, wildcard value */ 2142 /* BSSID is left zeroed, wildcard value */
2119 mgmt->u.beacon.beacon_int = 2143 mgmt->u.beacon.beacon_int =
2120 cpu_to_le16(local->hw.conf.beacon_int); 2144 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
2121 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */ 2145 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
2122 2146
2123 pos = skb_put(skb, 2); 2147 pos = skb_put(skb, 2);
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index fdf432f14554..66ce96a69f31 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -20,27 +20,21 @@
20#include <linux/if_arp.h> 20#include <linux/if_arp.h>
21#include <linux/wireless.h> 21#include <linux/wireless.h>
22#include <linux/bitmap.h> 22#include <linux/bitmap.h>
23#include <linux/crc32.h>
23#include <net/net_namespace.h> 24#include <net/net_namespace.h>
24#include <net/cfg80211.h> 25#include <net/cfg80211.h>
25#include <net/rtnetlink.h> 26#include <net/rtnetlink.h>
26 27
27#include "ieee80211_i.h" 28#include "ieee80211_i.h"
29#include "driver-ops.h"
28#include "rate.h" 30#include "rate.h"
29#include "mesh.h" 31#include "mesh.h"
30#include "wme.h" 32#include "wme.h"
33#include "led.h"
31 34
32/* privid for wiphys to determine whether they belong to us or not */ 35/* privid for wiphys to determine whether they belong to us or not */
33void *mac80211_wiphy_privid = &mac80211_wiphy_privid; 36void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
34 37
35/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
36/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
37const unsigned char rfc1042_header[] __aligned(2) =
38 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
39
40/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
41const unsigned char bridge_tunnel_header[] __aligned(2) =
42 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
43
44struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) 38struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
45{ 39{
46 struct ieee80211_local *local; 40 struct ieee80211_local *local;
@@ -100,70 +94,6 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
100 return NULL; 94 return NULL;
101} 95}
102 96
103unsigned int ieee80211_hdrlen(__le16 fc)
104{
105 unsigned int hdrlen = 24;
106
107 if (ieee80211_is_data(fc)) {
108 if (ieee80211_has_a4(fc))
109 hdrlen = 30;
110 if (ieee80211_is_data_qos(fc))
111 hdrlen += IEEE80211_QOS_CTL_LEN;
112 goto out;
113 }
114
115 if (ieee80211_is_ctl(fc)) {
116 /*
117 * ACK and CTS are 10 bytes, all others 16. To see how
118 * to get this condition consider
119 * subtype mask: 0b0000000011110000 (0x00F0)
120 * ACK subtype: 0b0000000011010000 (0x00D0)
121 * CTS subtype: 0b0000000011000000 (0x00C0)
122 * bits that matter: ^^^ (0x00E0)
123 * value of those: 0b0000000011000000 (0x00C0)
124 */
125 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
126 hdrlen = 10;
127 else
128 hdrlen = 16;
129 }
130out:
131 return hdrlen;
132}
133EXPORT_SYMBOL(ieee80211_hdrlen);
134
135unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
136{
137 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
138 unsigned int hdrlen;
139
140 if (unlikely(skb->len < 10))
141 return 0;
142 hdrlen = ieee80211_hdrlen(hdr->frame_control);
143 if (unlikely(hdrlen > skb->len))
144 return 0;
145 return hdrlen;
146}
147EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
148
149int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
150{
151 int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
152 /* 7.1.3.5a.2 */
153 switch (ae) {
154 case 0:
155 return 6;
156 case 1:
157 return 12;
158 case 2:
159 return 18;
160 case 3:
161 return 24;
162 default:
163 return 6;
164 }
165}
166
167void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) 97void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
168{ 98{
169 struct sk_buff *skb = tx->skb; 99 struct sk_buff *skb = tx->skb;
@@ -411,6 +341,52 @@ void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
411} 341}
412EXPORT_SYMBOL(ieee80211_stop_queue); 342EXPORT_SYMBOL(ieee80211_stop_queue);
413 343
344void ieee80211_add_pending_skb(struct ieee80211_local *local,
345 struct sk_buff *skb)
346{
347 struct ieee80211_hw *hw = &local->hw;
348 unsigned long flags;
349 int queue = skb_get_queue_mapping(skb);
350
351 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
352 __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
353 __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_PENDING);
354 skb_queue_tail(&local->pending[queue], skb);
355 __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
356 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
357}
358
359int ieee80211_add_pending_skbs(struct ieee80211_local *local,
360 struct sk_buff_head *skbs)
361{
362 struct ieee80211_hw *hw = &local->hw;
363 struct sk_buff *skb;
364 unsigned long flags;
365 int queue, ret = 0, i;
366
367 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
368 for (i = 0; i < hw->queues; i++)
369 __ieee80211_stop_queue(hw, i,
370 IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
371
372 while ((skb = skb_dequeue(skbs))) {
373 ret++;
374 queue = skb_get_queue_mapping(skb);
375 skb_queue_tail(&local->pending[queue], skb);
376 }
377
378 for (i = 0; i < hw->queues; i++) {
379 if (ret)
380 __ieee80211_stop_queue(hw, i,
381 IEEE80211_QUEUE_STOP_REASON_PENDING);
382 __ieee80211_wake_queue(hw, i,
383 IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
384 }
385 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
386
387 return ret;
388}
389
414void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, 390void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
415 enum queue_stop_reason reason) 391 enum queue_stop_reason reason)
416{ 392{
@@ -536,8 +512,16 @@ EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
536void ieee802_11_parse_elems(u8 *start, size_t len, 512void ieee802_11_parse_elems(u8 *start, size_t len,
537 struct ieee802_11_elems *elems) 513 struct ieee802_11_elems *elems)
538{ 514{
515 ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
516}
517
518u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
519 struct ieee802_11_elems *elems,
520 u64 filter, u32 crc)
521{
539 size_t left = len; 522 size_t left = len;
540 u8 *pos = start; 523 u8 *pos = start;
524 bool calc_crc = filter != 0;
541 525
542 memset(elems, 0, sizeof(*elems)); 526 memset(elems, 0, sizeof(*elems));
543 elems->ie_start = start; 527 elems->ie_start = start;
@@ -551,7 +535,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
551 left -= 2; 535 left -= 2;
552 536
553 if (elen > left) 537 if (elen > left)
554 return; 538 break;
539
540 if (calc_crc && id < 64 && (filter & BIT(id)))
541 crc = crc32_be(crc, pos - 2, elen + 2);
555 542
556 switch (id) { 543 switch (id) {
557 case WLAN_EID_SSID: 544 case WLAN_EID_SSID:
@@ -575,8 +562,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
575 elems->cf_params_len = elen; 562 elems->cf_params_len = elen;
576 break; 563 break;
577 case WLAN_EID_TIM: 564 case WLAN_EID_TIM:
578 elems->tim = pos; 565 if (elen >= sizeof(struct ieee80211_tim_ie)) {
579 elems->tim_len = elen; 566 elems->tim = (void *)pos;
567 elems->tim_len = elen;
568 }
580 break; 569 break;
581 case WLAN_EID_IBSS_PARAMS: 570 case WLAN_EID_IBSS_PARAMS:
582 elems->ibss_params = pos; 571 elems->ibss_params = pos;
@@ -586,15 +575,20 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
586 elems->challenge = pos; 575 elems->challenge = pos;
587 elems->challenge_len = elen; 576 elems->challenge_len = elen;
588 break; 577 break;
589 case WLAN_EID_WPA: 578 case WLAN_EID_VENDOR_SPECIFIC:
590 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && 579 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
591 pos[2] == 0xf2) { 580 pos[2] == 0xf2) {
592 /* Microsoft OUI (00:50:F2) */ 581 /* Microsoft OUI (00:50:F2) */
582
583 if (calc_crc)
584 crc = crc32_be(crc, pos - 2, elen + 2);
585
593 if (pos[3] == 1) { 586 if (pos[3] == 1) {
594 /* OUI Type 1 - WPA IE */ 587 /* OUI Type 1 - WPA IE */
595 elems->wpa = pos; 588 elems->wpa = pos;
596 elems->wpa_len = elen; 589 elems->wpa_len = elen;
597 } else if (elen >= 5 && pos[3] == 2) { 590 } else if (elen >= 5 && pos[3] == 2) {
591 /* OUI Type 2 - WMM IE */
598 if (pos[4] == 0) { 592 if (pos[4] == 0) {
599 elems->wmm_info = pos; 593 elems->wmm_info = pos;
600 elems->wmm_info_len = elen; 594 elems->wmm_info_len = elen;
@@ -679,32 +673,70 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
679 left -= elen; 673 left -= elen;
680 pos += elen; 674 pos += elen;
681 } 675 }
676
677 return crc;
682} 678}
683 679
684void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) 680void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
685{ 681{
686 struct ieee80211_local *local = sdata->local; 682 struct ieee80211_local *local = sdata->local;
687 struct ieee80211_tx_queue_params qparam; 683 struct ieee80211_tx_queue_params qparam;
688 int i; 684 int queue;
685 bool use_11b;
686 int aCWmin, aCWmax;
689 687
690 if (!local->ops->conf_tx) 688 if (!local->ops->conf_tx)
691 return; 689 return;
692 690
693 memset(&qparam, 0, sizeof(qparam)); 691 memset(&qparam, 0, sizeof(qparam));
694 692
695 qparam.aifs = 2; 693 use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
694 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
696 695
697 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && 696 for (queue = 0; queue < local_to_hw(local)->queues; queue++) {
698 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) 697 /* Set defaults according to 802.11-2007 Table 7-37 */
699 qparam.cw_min = 31; 698 aCWmax = 1023;
700 else 699 if (use_11b)
701 qparam.cw_min = 15; 700 aCWmin = 31;
702 701 else
703 qparam.cw_max = 1023; 702 aCWmin = 15;
704 qparam.txop = 0; 703
704 switch (queue) {
705 case 3: /* AC_BK */
706 qparam.cw_max = aCWmax;
707 qparam.cw_min = aCWmin;
708 qparam.txop = 0;
709 qparam.aifs = 7;
710 break;
711 default: /* never happens but let's not leave undefined */
712 case 2: /* AC_BE */
713 qparam.cw_max = aCWmax;
714 qparam.cw_min = aCWmin;
715 qparam.txop = 0;
716 qparam.aifs = 3;
717 break;
718 case 1: /* AC_VI */
719 qparam.cw_max = aCWmin;
720 qparam.cw_min = (aCWmin + 1) / 2 - 1;
721 if (use_11b)
722 qparam.txop = 6016/32;
723 else
724 qparam.txop = 3008/32;
725 qparam.aifs = 2;
726 break;
727 case 0: /* AC_VO */
728 qparam.cw_max = (aCWmin + 1) / 2 - 1;
729 qparam.cw_min = (aCWmin + 1) / 4 - 1;
730 if (use_11b)
731 qparam.txop = 3264/32;
732 else
733 qparam.txop = 1504/32;
734 qparam.aifs = 2;
735 break;
736 }
705 737
706 for (i = 0; i < local_to_hw(local)->queues; i++) 738 drv_conf_tx(local, queue, &qparam);
707 local->ops->conf_tx(local_to_hw(local), i, &qparam); 739 }
708} 740}
709 741
710void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 742void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
@@ -831,16 +863,73 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
831 ieee80211_tx_skb(sdata, skb, encrypt); 863 ieee80211_tx_skb(sdata, skb, encrypt);
832} 864}
833 865
866int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
867 const u8 *ie, size_t ie_len)
868{
869 struct ieee80211_supported_band *sband;
870 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL;
871 int i;
872
873 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
874
875 pos = buffer;
876
877 *pos++ = WLAN_EID_SUPP_RATES;
878 supp_rates_len = pos;
879 *pos++ = 0;
880
881 for (i = 0; i < sband->n_bitrates; i++) {
882 struct ieee80211_rate *rate = &sband->bitrates[i];
883
884 if (esupp_rates_len) {
885 *esupp_rates_len += 1;
886 } else if (*supp_rates_len == 8) {
887 *pos++ = WLAN_EID_EXT_SUPP_RATES;
888 esupp_rates_len = pos;
889 *pos++ = 1;
890 } else
891 *supp_rates_len += 1;
892
893 *pos++ = rate->bitrate / 5;
894 }
895
896 if (sband->ht_cap.ht_supported) {
897 __le16 tmp = cpu_to_le16(sband->ht_cap.cap);
898
899 *pos++ = WLAN_EID_HT_CAPABILITY;
900 *pos++ = sizeof(struct ieee80211_ht_cap);
901 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
902 memcpy(pos, &tmp, sizeof(u16));
903 pos += sizeof(u16);
904 /* TODO: needs a define here for << 2 */
905 *pos++ = sband->ht_cap.ampdu_factor |
906 (sband->ht_cap.ampdu_density << 2);
907 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
908 pos += sizeof(sband->ht_cap.mcs);
909 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
910 }
911
912 /*
913 * If adding more here, adjust code in main.c
914 * that calculates local->scan_ies_len.
915 */
916
917 if (ie) {
918 memcpy(pos, ie, ie_len);
919 pos += ie_len;
920 }
921
922 return pos - buffer;
923}
924
834void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 925void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
835 u8 *ssid, size_t ssid_len, 926 const u8 *ssid, size_t ssid_len,
836 u8 *ie, size_t ie_len) 927 const u8 *ie, size_t ie_len)
837{ 928{
838 struct ieee80211_local *local = sdata->local; 929 struct ieee80211_local *local = sdata->local;
839 struct ieee80211_supported_band *sband;
840 struct sk_buff *skb; 930 struct sk_buff *skb;
841 struct ieee80211_mgmt *mgmt; 931 struct ieee80211_mgmt *mgmt;
842 u8 *pos, *supp_rates, *esupp_rates = NULL; 932 u8 *pos;
843 int i;
844 933
845 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + 934 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
846 ie_len); 935 ie_len);
@@ -867,31 +956,9 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
867 *pos++ = WLAN_EID_SSID; 956 *pos++ = WLAN_EID_SSID;
868 *pos++ = ssid_len; 957 *pos++ = ssid_len;
869 memcpy(pos, ssid, ssid_len); 958 memcpy(pos, ssid, ssid_len);
959 pos += ssid_len;
870 960
871 supp_rates = skb_put(skb, 2); 961 skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len));
872 supp_rates[0] = WLAN_EID_SUPP_RATES;
873 supp_rates[1] = 0;
874 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
875
876 for (i = 0; i < sband->n_bitrates; i++) {
877 struct ieee80211_rate *rate = &sband->bitrates[i];
878 if (esupp_rates) {
879 pos = skb_put(skb, 1);
880 esupp_rates[1]++;
881 } else if (supp_rates[1] == 8) {
882 esupp_rates = skb_put(skb, 3);
883 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
884 esupp_rates[1] = 1;
885 pos = &esupp_rates[2];
886 } else {
887 pos = skb_put(skb, 1);
888 supp_rates[1]++;
889 }
890 *pos = rate->bitrate / 5;
891 }
892
893 if (ie)
894 memcpy(skb_put(skb, ie_len), ie, ie_len);
895 962
896 ieee80211_tx_skb(sdata, skb, 0); 963 ieee80211_tx_skb(sdata, skb, 0);
897} 964}
@@ -931,3 +998,151 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
931 } 998 }
932 return supp_rates; 999 return supp_rates;
933} 1000}
1001
1002int ieee80211_reconfig(struct ieee80211_local *local)
1003{
1004 struct ieee80211_hw *hw = &local->hw;
1005 struct ieee80211_sub_if_data *sdata;
1006 struct ieee80211_if_init_conf conf;
1007 struct sta_info *sta;
1008 unsigned long flags;
1009 int res;
1010 bool from_suspend = local->suspended;
1011
1012 /*
1013 * We're going to start the hardware, at that point
1014 * we are no longer suspended and can RX frames.
1015 */
1016 local->suspended = false;
1017
1018 /* restart hardware */
1019 if (local->open_count) {
1020 res = drv_start(local);
1021
1022 ieee80211_led_radio(local, true);
1023 }
1024
1025 /* add interfaces */
1026 list_for_each_entry(sdata, &local->interfaces, list) {
1027 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1028 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1029 netif_running(sdata->dev)) {
1030 conf.vif = &sdata->vif;
1031 conf.type = sdata->vif.type;
1032 conf.mac_addr = sdata->dev->dev_addr;
1033 res = drv_add_interface(local, &conf);
1034 }
1035 }
1036
1037 /* add STAs back */
1038 if (local->ops->sta_notify) {
1039 spin_lock_irqsave(&local->sta_lock, flags);
1040 list_for_each_entry(sta, &local->sta_list, list) {
1041 sdata = sta->sdata;
1042 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1043 sdata = container_of(sdata->bss,
1044 struct ieee80211_sub_if_data,
1045 u.ap);
1046
1047 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD,
1048 &sta->sta);
1049 }
1050 spin_unlock_irqrestore(&local->sta_lock, flags);
1051 }
1052
1053 /* Clear Suspend state so that ADDBA requests can be processed */
1054
1055 rcu_read_lock();
1056
1057 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1058 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1059 clear_sta_flags(sta, WLAN_STA_SUSPEND);
1060 }
1061 }
1062
1063 rcu_read_unlock();
1064
1065 /* setup RTS threshold */
1066 drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
1067
1068 /* reconfigure hardware */
1069 ieee80211_hw_config(local, ~0);
1070
1071 netif_addr_lock_bh(local->mdev);
1072 ieee80211_configure_filter(local);
1073 netif_addr_unlock_bh(local->mdev);
1074
1075 /* Finally also reconfigure all the BSS information */
1076 list_for_each_entry(sdata, &local->interfaces, list) {
1077 u32 changed = ~0;
1078 if (!netif_running(sdata->dev))
1079 continue;
1080 switch (sdata->vif.type) {
1081 case NL80211_IFTYPE_STATION:
1082 /* disable beacon change bits */
1083 changed &= ~(BSS_CHANGED_BEACON |
1084 BSS_CHANGED_BEACON_ENABLED);
1085 /* fall through */
1086 case NL80211_IFTYPE_ADHOC:
1087 case NL80211_IFTYPE_AP:
1088 case NL80211_IFTYPE_MESH_POINT:
1089 ieee80211_bss_info_change_notify(sdata, changed);
1090 break;
1091 case NL80211_IFTYPE_WDS:
1092 break;
1093 case NL80211_IFTYPE_AP_VLAN:
1094 case NL80211_IFTYPE_MONITOR:
1095 /* ignore virtual */
1096 break;
1097 case NL80211_IFTYPE_UNSPECIFIED:
1098 case __NL80211_IFTYPE_AFTER_LAST:
1099 WARN_ON(1);
1100 break;
1101 }
1102 }
1103
1104 /* add back keys */
1105 list_for_each_entry(sdata, &local->interfaces, list)
1106 if (netif_running(sdata->dev))
1107 ieee80211_enable_keys(sdata);
1108
1109 ieee80211_wake_queues_by_reason(hw,
1110 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1111
1112 /*
1113 * If this is for hw restart things are still running.
1114 * We may want to change that later, however.
1115 */
1116 if (!from_suspend)
1117 return 0;
1118
1119#ifdef CONFIG_PM
1120 local->suspended = false;
1121
1122 list_for_each_entry(sdata, &local->interfaces, list) {
1123 switch(sdata->vif.type) {
1124 case NL80211_IFTYPE_STATION:
1125 ieee80211_sta_restart(sdata);
1126 break;
1127 case NL80211_IFTYPE_ADHOC:
1128 ieee80211_ibss_restart(sdata);
1129 break;
1130 case NL80211_IFTYPE_MESH_POINT:
1131 ieee80211_mesh_restart(sdata);
1132 break;
1133 default:
1134 break;
1135 }
1136 }
1137
1138 add_timer(&local->sta_cleanup);
1139
1140 spin_lock_irqsave(&local->sta_lock, flags);
1141 list_for_each_entry(sta, &local->sta_list, list)
1142 mesh_plink_restart(sta);
1143 spin_unlock_irqrestore(&local->sta_lock, flags);
1144#else
1145 WARN_ON(1);
1146#endif
1147 return 0;
1148}
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index 959aa8379ccf..d2d81b103341 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -27,100 +27,6 @@
27#include "aes_ccm.h" 27#include "aes_ccm.h"
28 28
29 29
30static int ieee80211_set_encryption(struct ieee80211_sub_if_data *sdata, u8 *sta_addr,
31 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
33 size_t key_len)
34{
35 struct ieee80211_local *local = sdata->local;
36 struct sta_info *sta;
37 struct ieee80211_key *key;
38 int err;
39
40 if (alg == ALG_AES_CMAC) {
41 if (idx < NUM_DEFAULT_KEYS ||
42 idx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d "
44 "(BIP)\n", sdata->dev->name, idx);
45 return -EINVAL;
46 }
47 } else if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
48 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
49 sdata->dev->name, idx);
50 return -EINVAL;
51 }
52
53 if (remove) {
54 rcu_read_lock();
55
56 err = 0;
57
58 if (is_broadcast_ether_addr(sta_addr)) {
59 key = sdata->keys[idx];
60 } else {
61 sta = sta_info_get(local, sta_addr);
62 if (!sta) {
63 err = -ENOENT;
64 goto out_unlock;
65 }
66 key = sta->key;
67 }
68
69 ieee80211_key_free(key);
70 } else {
71 key = ieee80211_key_alloc(alg, idx, key_len, _key);
72 if (!key)
73 return -ENOMEM;
74
75 sta = NULL;
76 err = 0;
77
78 rcu_read_lock();
79
80 if (!is_broadcast_ether_addr(sta_addr)) {
81 set_tx_key = 0;
82 /*
83 * According to the standard, the key index of a
84 * pairwise key must be zero. However, some AP are
85 * broken when it comes to WEP key indices, so we
86 * work around this.
87 */
88 if (idx != 0 && alg != ALG_WEP) {
89 ieee80211_key_free(key);
90 err = -EINVAL;
91 goto out_unlock;
92 }
93
94 sta = sta_info_get(local, sta_addr);
95 if (!sta) {
96 ieee80211_key_free(key);
97 err = -ENOENT;
98 goto out_unlock;
99 }
100 }
101
102 if (alg == ALG_WEP &&
103 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
104 ieee80211_key_free(key);
105 err = -EINVAL;
106 goto out_unlock;
107 }
108
109 ieee80211_key_link(key, sdata, sta);
110
111 if (set_tx_key || (!sta && !sdata->default_key && key))
112 ieee80211_set_default_key(sdata, idx);
113 if (alg == ALG_AES_CMAC &&
114 (set_tx_key || (!sta && !sdata->default_mgmt_key && key)))
115 ieee80211_set_default_mgmt_key(sdata, idx);
116 }
117
118 out_unlock:
119 rcu_read_unlock();
120
121 return err;
122}
123
124static int ieee80211_ioctl_siwgenie(struct net_device *dev, 30static int ieee80211_ioctl_siwgenie(struct net_device *dev,
125 struct iw_request_info *info, 31 struct iw_request_info *info,
126 struct iw_point *data, char *extra) 32 struct iw_point *data, char *extra)
@@ -131,11 +37,13 @@ static int ieee80211_ioctl_siwgenie(struct net_device *dev,
131 37
132 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 38 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
133 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); 39 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
134 if (ret) 40 if (ret && ret != -EALREADY)
135 return ret; 41 return ret;
136 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; 42 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
137 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 43 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
138 ieee80211_sta_req_auth(sdata); 44 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
45 if (ret != -EALREADY)
46 ieee80211_sta_req_auth(sdata);
139 return 0; 47 return 0;
140 } 48 }
141 49
@@ -149,17 +57,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
150 58
151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 59 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
152 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL; 60 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
153 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 61 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; 62 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
155 63
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ 64 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
157 if (freq->e == 0) { 65 if (freq->e == 0) {
158 if (freq->m < 0) { 66 if (freq->m < 0) {
159 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 67 if (sdata->vif.type == NL80211_IFTYPE_STATION)
160 sdata->u.ibss.flags |=
161 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
162 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
163 sdata->u.mgd.flags |= 68 sdata->u.mgd.flags |=
164 IEEE80211_STA_AUTO_CHANNEL_SEL; 69 IEEE80211_STA_AUTO_CHANNEL_SEL;
165 return 0; 70 return 0;
@@ -183,8 +88,12 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
183 struct iw_freq *freq, char *extra) 88 struct iw_freq *freq, char *extra)
184{ 89{
185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 90 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
91 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
186 92
187 freq->m = local->hw.conf.channel->center_freq; 93 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
94 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
95
96 freq->m = local->oper_channel->center_freq;
188 freq->e = 6; 97 freq->e = 6;
189 98
190 return 0; 99 return 0;
@@ -195,15 +104,17 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
195 struct iw_request_info *info, 104 struct iw_request_info *info,
196 struct iw_point *data, char *ssid) 105 struct iw_point *data, char *ssid)
197{ 106{
198 struct ieee80211_sub_if_data *sdata; 107 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
199 size_t len = data->length; 108 size_t len = data->length;
200 int ret; 109 int ret;
201 110
111 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
112 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
113
202 /* iwconfig uses nul termination in SSID.. */ 114 /* iwconfig uses nul termination in SSID.. */
203 if (len > 0 && ssid[len - 1] == '\0') 115 if (len > 0 && ssid[len - 1] == '\0')
204 len--; 116 len--;
205 117
206 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
207 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 118 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
208 if (data->flags) 119 if (data->flags)
209 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; 120 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
@@ -215,10 +126,10 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
215 return ret; 126 return ret;
216 127
217 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 128 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
129 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
218 ieee80211_sta_req_auth(sdata); 130 ieee80211_sta_req_auth(sdata);
219 return 0; 131 return 0;
220 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 132 }
221 return ieee80211_ibss_set_ssid(sdata, ssid, len);
222 133
223 return -EOPNOTSUPP; 134 return -EOPNOTSUPP;
224} 135}
@@ -229,9 +140,13 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
229 struct iw_point *data, char *ssid) 140 struct iw_point *data, char *ssid)
230{ 141{
231 size_t len; 142 size_t len;
232
233 struct ieee80211_sub_if_data *sdata; 143 struct ieee80211_sub_if_data *sdata;
144
234 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 145 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
146
147 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
148 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
149
235 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 150 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
236 int res = ieee80211_sta_get_ssid(sdata, ssid, &len); 151 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
237 if (res == 0) { 152 if (res == 0) {
@@ -240,14 +155,6 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
240 } else 155 } else
241 data->flags = 0; 156 data->flags = 0;
242 return res; 157 return res;
243 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
244 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
245 if (res == 0) {
246 data->length = len;
247 data->flags = 1;
248 } else
249 data->flags = 0;
250 return res;
251 } 158 }
252 159
253 return -EOPNOTSUPP; 160 return -EOPNOTSUPP;
@@ -258,9 +165,11 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
258 struct iw_request_info *info, 165 struct iw_request_info *info,
259 struct sockaddr *ap_addr, char *extra) 166 struct sockaddr *ap_addr, char *extra)
260{ 167{
261 struct ieee80211_sub_if_data *sdata; 168 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
169
170 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
171 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
262 172
263 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
264 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 173 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
265 int ret; 174 int ret;
266 175
@@ -275,18 +184,9 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
275 if (ret) 184 if (ret)
276 return ret; 185 return ret;
277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 186 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
187 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
278 ieee80211_sta_req_auth(sdata); 188 ieee80211_sta_req_auth(sdata);
279 return 0; 189 return 0;
280 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
281 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
282 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
283 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
284 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
285 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
286 else
287 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
288
289 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
290 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { 190 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
291 /* 191 /*
292 * If it is necessary to update the WDS peer address 192 * If it is necessary to update the WDS peer address
@@ -312,9 +212,11 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
312 struct iw_request_info *info, 212 struct iw_request_info *info,
313 struct sockaddr *ap_addr, char *extra) 213 struct sockaddr *ap_addr, char *extra)
314{ 214{
315 struct ieee80211_sub_if_data *sdata; 215 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
216
217 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
218 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
316 219
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
318 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 220 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
319 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) { 221 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
320 ap_addr->sa_family = ARPHRD_ETHER; 222 ap_addr->sa_family = ARPHRD_ETHER;
@@ -322,13 +224,6 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
322 } else 224 } else
323 memset(&ap_addr->sa_data, 0, ETH_ALEN); 225 memset(&ap_addr->sa_data, 0, ETH_ALEN);
324 return 0; 226 return 0;
325 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
326 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
327 ap_addr->sa_family = ARPHRD_ETHER;
328 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
329 } else
330 memset(&ap_addr->sa_data, 0, ETH_ALEN);
331 return 0;
332 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { 227 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
333 ap_addr->sa_family = ARPHRD_ETHER; 228 ap_addr->sa_family = ARPHRD_ETHER;
334 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); 229 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
@@ -411,334 +306,6 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
411 return 0; 306 return 0;
412} 307}
413 308
414static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
415 struct iw_request_info *info,
416 union iwreq_data *data, char *extra)
417{
418 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
419 struct ieee80211_channel* chan = local->hw.conf.channel;
420 bool reconf = false;
421 u32 reconf_flags = 0;
422 int new_power_level;
423
424 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
425 return -EINVAL;
426 if (data->txpower.flags & IW_TXPOW_RANGE)
427 return -EINVAL;
428 if (!chan)
429 return -EINVAL;
430
431 /* only change when not disabling */
432 if (!data->txpower.disabled) {
433 if (data->txpower.fixed) {
434 if (data->txpower.value < 0)
435 return -EINVAL;
436 new_power_level = data->txpower.value;
437 /*
438 * Debatable, but we cannot do a fixed power
439 * level above the regulatory constraint.
440 * Use "iwconfig wlan0 txpower 15dBm" instead.
441 */
442 if (new_power_level > chan->max_power)
443 return -EINVAL;
444 } else {
445 /*
446 * Automatic power level setting, max being the value
447 * passed in from userland.
448 */
449 if (data->txpower.value < 0)
450 new_power_level = -1;
451 else
452 new_power_level = data->txpower.value;
453 }
454
455 reconf = true;
456
457 /*
458 * ieee80211_hw_config() will limit to the channel's
459 * max power and possibly power constraint from AP.
460 */
461 local->user_power_level = new_power_level;
462 }
463
464 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
465 local->hw.conf.radio_enabled = !(data->txpower.disabled);
466 reconf_flags |= IEEE80211_CONF_CHANGE_RADIO_ENABLED;
467 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
468 }
469
470 if (reconf || reconf_flags)
471 ieee80211_hw_config(local, reconf_flags);
472
473 return 0;
474}
475
476static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
477 struct iw_request_info *info,
478 union iwreq_data *data, char *extra)
479{
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
481
482 data->txpower.fixed = 1;
483 data->txpower.disabled = !(local->hw.conf.radio_enabled);
484 data->txpower.value = local->hw.conf.power_level;
485 data->txpower.flags = IW_TXPOW_DBM;
486
487 return 0;
488}
489
490static int ieee80211_ioctl_siwrts(struct net_device *dev,
491 struct iw_request_info *info,
492 struct iw_param *rts, char *extra)
493{
494 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
495
496 if (rts->disabled)
497 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
498 else if (!rts->fixed)
499 /* if the rts value is not fixed, then take default */
500 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
501 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
502 return -EINVAL;
503 else
504 local->rts_threshold = rts->value;
505
506 /* If the wlan card performs RTS/CTS in hardware/firmware,
507 * configure it here */
508
509 if (local->ops->set_rts_threshold)
510 local->ops->set_rts_threshold(local_to_hw(local),
511 local->rts_threshold);
512
513 return 0;
514}
515
516static int ieee80211_ioctl_giwrts(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_param *rts, char *extra)
519{
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
521
522 rts->value = local->rts_threshold;
523 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
524 rts->fixed = 1;
525
526 return 0;
527}
528
529
530static int ieee80211_ioctl_siwfrag(struct net_device *dev,
531 struct iw_request_info *info,
532 struct iw_param *frag, char *extra)
533{
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
535
536 if (frag->disabled)
537 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
538 else if (!frag->fixed)
539 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
540 else if (frag->value < 256 ||
541 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
542 return -EINVAL;
543 else {
544 /* Fragment length must be even, so strip LSB. */
545 local->fragmentation_threshold = frag->value & ~0x1;
546 }
547
548 return 0;
549}
550
551static int ieee80211_ioctl_giwfrag(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_param *frag, char *extra)
554{
555 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
556
557 frag->value = local->fragmentation_threshold;
558 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
559 frag->fixed = 1;
560
561 return 0;
562}
563
564
565static int ieee80211_ioctl_siwretry(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_param *retry, char *extra)
568{
569 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
570
571 if (retry->disabled ||
572 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
573 return -EINVAL;
574
575 if (retry->flags & IW_RETRY_MAX) {
576 local->hw.conf.long_frame_max_tx_count = retry->value;
577 } else if (retry->flags & IW_RETRY_MIN) {
578 local->hw.conf.short_frame_max_tx_count = retry->value;
579 } else {
580 local->hw.conf.long_frame_max_tx_count = retry->value;
581 local->hw.conf.short_frame_max_tx_count = retry->value;
582 }
583
584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
585
586 return 0;
587}
588
589
590static int ieee80211_ioctl_giwretry(struct net_device *dev,
591 struct iw_request_info *info,
592 struct iw_param *retry, char *extra)
593{
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
595
596 retry->disabled = 0;
597 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
598 /* first return min value, iwconfig will ask max value
599 * later if needed */
600 retry->flags |= IW_RETRY_LIMIT;
601 retry->value = local->hw.conf.short_frame_max_tx_count;
602 if (local->hw.conf.long_frame_max_tx_count !=
603 local->hw.conf.short_frame_max_tx_count)
604 retry->flags |= IW_RETRY_MIN;
605 return 0;
606 }
607 if (retry->flags & IW_RETRY_MAX) {
608 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
609 retry->value = local->hw.conf.long_frame_max_tx_count;
610 }
611
612 return 0;
613}
614
615static int ieee80211_ioctl_siwmlme(struct net_device *dev,
616 struct iw_request_info *info,
617 struct iw_point *data, char *extra)
618{
619 struct ieee80211_sub_if_data *sdata;
620 struct iw_mlme *mlme = (struct iw_mlme *) extra;
621
622 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
623 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
624 return -EINVAL;
625
626 switch (mlme->cmd) {
627 case IW_MLME_DEAUTH:
628 /* TODO: mlme->addr.sa_data */
629 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
630 case IW_MLME_DISASSOC:
631 /* TODO: mlme->addr.sa_data */
632 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
633 default:
634 return -EOPNOTSUPP;
635 }
636}
637
638
639static int ieee80211_ioctl_siwencode(struct net_device *dev,
640 struct iw_request_info *info,
641 struct iw_point *erq, char *keybuf)
642{
643 struct ieee80211_sub_if_data *sdata;
644 int idx, i, alg = ALG_WEP;
645 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
646 int remove = 0, ret;
647
648 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
649
650 idx = erq->flags & IW_ENCODE_INDEX;
651 if (idx == 0) {
652 if (sdata->default_key)
653 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
654 if (sdata->default_key == sdata->keys[i]) {
655 idx = i;
656 break;
657 }
658 }
659 } else if (idx < 1 || idx > 4)
660 return -EINVAL;
661 else
662 idx--;
663
664 if (erq->flags & IW_ENCODE_DISABLED)
665 remove = 1;
666 else if (erq->length == 0) {
667 /* No key data - just set the default TX key index */
668 ieee80211_set_default_key(sdata, idx);
669 return 0;
670 }
671
672 ret = ieee80211_set_encryption(
673 sdata, bcaddr,
674 idx, alg, remove,
675 !sdata->default_key,
676 keybuf, erq->length);
677
678 if (!ret) {
679 if (remove)
680 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
681 else
682 sdata->u.mgd.flags |= IEEE80211_STA_TKIP_WEP_USED;
683 }
684
685 return ret;
686}
687
688
689static int ieee80211_ioctl_giwencode(struct net_device *dev,
690 struct iw_request_info *info,
691 struct iw_point *erq, char *key)
692{
693 struct ieee80211_sub_if_data *sdata;
694 int idx, i;
695
696 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
697
698 idx = erq->flags & IW_ENCODE_INDEX;
699 if (idx < 1 || idx > 4) {
700 idx = -1;
701 if (!sdata->default_key)
702 idx = 0;
703 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
704 if (sdata->default_key == sdata->keys[i]) {
705 idx = i;
706 break;
707 }
708 }
709 if (idx < 0)
710 return -EINVAL;
711 } else
712 idx--;
713
714 erq->flags = idx + 1;
715
716 if (!sdata->keys[idx]) {
717 erq->length = 0;
718 erq->flags |= IW_ENCODE_DISABLED;
719 return 0;
720 }
721
722 memcpy(key, sdata->keys[idx]->conf.key,
723 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
724 erq->length = sdata->keys[idx]->conf.keylen;
725 erq->flags |= IW_ENCODE_ENABLED;
726
727 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
728 switch (sdata->u.mgd.auth_alg) {
729 case WLAN_AUTH_OPEN:
730 case WLAN_AUTH_LEAP:
731 erq->flags |= IW_ENCODE_OPEN;
732 break;
733 case WLAN_AUTH_SHARED_KEY:
734 erq->flags |= IW_ENCODE_RESTRICTED;
735 break;
736 }
737 }
738
739 return 0;
740}
741
742static int ieee80211_ioctl_siwpower(struct net_device *dev, 309static int ieee80211_ioctl_siwpower(struct net_device *dev,
743 struct iw_request_info *info, 310 struct iw_request_info *info,
744 struct iw_param *wrq, 311 struct iw_param *wrq,
@@ -747,7 +314,7 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 314 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 315 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
749 struct ieee80211_conf *conf = &local->hw.conf; 316 struct ieee80211_conf *conf = &local->hw.conf;
750 int ret = 0, timeout = 0; 317 int timeout = 0;
751 bool ps; 318 bool ps;
752 319
753 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 320 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
@@ -779,42 +346,18 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
779 timeout = wrq->value / 1000; 346 timeout = wrq->value / 1000;
780 347
781 set: 348 set:
782 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout) 349 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
783 return ret; 350 return 0;
784 351
785 local->powersave = ps; 352 sdata->u.mgd.powersave = ps;
786 conf->dynamic_ps_timeout = timeout; 353 conf->dynamic_ps_timeout = timeout;
787 354
788 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) 355 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
789 ret = ieee80211_hw_config(local, 356 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
790 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
791
792 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
793 return ret;
794 357
795 if (conf->dynamic_ps_timeout > 0 && 358 ieee80211_recalc_ps(local, -1);
796 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
797 mod_timer(&local->dynamic_ps_timer, jiffies +
798 msecs_to_jiffies(conf->dynamic_ps_timeout));
799 } else {
800 if (local->powersave) {
801 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
802 ieee80211_send_nullfunc(local, sdata, 1);
803 conf->flags |= IEEE80211_CONF_PS;
804 ret = ieee80211_hw_config(local,
805 IEEE80211_CONF_CHANGE_PS);
806 } else {
807 conf->flags &= ~IEEE80211_CONF_PS;
808 ret = ieee80211_hw_config(local,
809 IEEE80211_CONF_CHANGE_PS);
810 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
811 ieee80211_send_nullfunc(local, sdata, 0);
812 del_timer_sync(&local->dynamic_ps_timer);
813 cancel_work_sync(&local->dynamic_ps_enable_work);
814 }
815 }
816 359
817 return ret; 360 return 0;
818} 361}
819 362
820static int ieee80211_ioctl_giwpower(struct net_device *dev, 363static int ieee80211_ioctl_giwpower(struct net_device *dev,
@@ -822,9 +365,9 @@ static int ieee80211_ioctl_giwpower(struct net_device *dev,
822 union iwreq_data *wrqu, 365 union iwreq_data *wrqu,
823 char *extra) 366 char *extra)
824{ 367{
825 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 368 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
826 369
827 wrqu->power.disabled = !local->powersave; 370 wrqu->power.disabled = !sdata->u.mgd.powersave;
828 371
829 return 0; 372 return 0;
830} 373}
@@ -997,82 +540,6 @@ static int ieee80211_ioctl_giwauth(struct net_device *dev,
997} 540}
998 541
999 542
1000static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1001 struct iw_request_info *info,
1002 struct iw_point *erq, char *extra)
1003{
1004 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1005 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1006 int uninitialized_var(alg), idx, i, remove = 0;
1007
1008 switch (ext->alg) {
1009 case IW_ENCODE_ALG_NONE:
1010 remove = 1;
1011 break;
1012 case IW_ENCODE_ALG_WEP:
1013 alg = ALG_WEP;
1014 break;
1015 case IW_ENCODE_ALG_TKIP:
1016 alg = ALG_TKIP;
1017 break;
1018 case IW_ENCODE_ALG_CCMP:
1019 alg = ALG_CCMP;
1020 break;
1021 case IW_ENCODE_ALG_AES_CMAC:
1022 alg = ALG_AES_CMAC;
1023 break;
1024 default:
1025 return -EOPNOTSUPP;
1026 }
1027
1028 if (erq->flags & IW_ENCODE_DISABLED)
1029 remove = 1;
1030
1031 idx = erq->flags & IW_ENCODE_INDEX;
1032 if (alg == ALG_AES_CMAC) {
1033 if (idx < NUM_DEFAULT_KEYS + 1 ||
1034 idx > NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) {
1035 idx = -1;
1036 if (!sdata->default_mgmt_key)
1037 idx = 0;
1038 else for (i = NUM_DEFAULT_KEYS;
1039 i < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
1040 i++) {
1041 if (sdata->default_mgmt_key == sdata->keys[i])
1042 {
1043 idx = i;
1044 break;
1045 }
1046 }
1047 if (idx < 0)
1048 return -EINVAL;
1049 } else
1050 idx--;
1051 } else {
1052 if (idx < 1 || idx > 4) {
1053 idx = -1;
1054 if (!sdata->default_key)
1055 idx = 0;
1056 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1057 if (sdata->default_key == sdata->keys[i]) {
1058 idx = i;
1059 break;
1060 }
1061 }
1062 if (idx < 0)
1063 return -EINVAL;
1064 } else
1065 idx--;
1066 }
1067
1068 return ieee80211_set_encryption(sdata, ext->addr.sa_data, idx, alg,
1069 remove,
1070 ext->ext_flags &
1071 IW_ENCODE_EXT_SET_TX_KEY,
1072 ext->key, ext->key_len);
1073}
1074
1075
1076/* Structures to export the Wireless Handlers */ 543/* Structures to export the Wireless Handlers */
1077 544
1078static const iw_handler ieee80211_handler[] = 545static const iw_handler ieee80211_handler[] =
@@ -1099,7 +566,7 @@ static const iw_handler ieee80211_handler[] =
1099 (iw_handler) NULL, /* SIOCGIWTHRSPY */ 566 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1100 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ 567 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1101 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ 568 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1102 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ 569 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
1103 (iw_handler) NULL, /* SIOCGIWAPLIST */ 570 (iw_handler) NULL, /* SIOCGIWAPLIST */
1104 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ 571 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1105 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ 572 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
@@ -1111,16 +578,16 @@ static const iw_handler ieee80211_handler[] =
1111 (iw_handler) NULL, /* -- hole -- */ 578 (iw_handler) NULL, /* -- hole -- */
1112 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ 579 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1113 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ 580 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1114 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ 581 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
1115 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ 582 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
1116 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ 583 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
1117 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ 584 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
1118 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ 585 (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */
1119 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ 586 (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */
1120 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ 587 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
1121 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ 588 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
1122 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ 589 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
1123 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ 590 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
1124 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ 591 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1125 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ 592 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1126 (iw_handler) NULL, /* -- hole -- */ 593 (iw_handler) NULL, /* -- hole -- */
@@ -1129,7 +596,7 @@ static const iw_handler ieee80211_handler[] =
1129 (iw_handler) NULL, /* SIOCGIWGENIE */ 596 (iw_handler) NULL, /* SIOCGIWGENIE */
1130 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ 597 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1131 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ 598 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1132 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ 599 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
1133 (iw_handler) NULL, /* SIOCGIWENCODEEXT */ 600 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1134 (iw_handler) NULL, /* SIOCSIWPMKSA */ 601 (iw_handler) NULL, /* SIOCSIWPMKSA */
1135 (iw_handler) NULL, /* -- hole -- */ 602 (iw_handler) NULL, /* -- hole -- */
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 0b8ad1f4ecdd..116a923b14d6 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -23,34 +23,6 @@
23 */ 23 */
24const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 }; 24const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
25 25
26static const char llc_ip_hdr[8] = {0xAA, 0xAA, 0x3, 0, 0, 0, 0x08, 0};
27
28/* Given a data frame determine the 802.1p/1d tag to use. */
29static unsigned int classify_1d(struct sk_buff *skb)
30{
31 unsigned int dscp;
32
33 /* skb->priority values from 256->263 are magic values to
34 * directly indicate a specific 802.1d priority. This is used
35 * to allow 802.1d priority to be passed directly in from VLAN
36 * tags, etc.
37 */
38 if (skb->priority >= 256 && skb->priority <= 263)
39 return skb->priority - 256;
40
41 switch (skb->protocol) {
42 case htons(ETH_P_IP):
43 dscp = ip_hdr(skb)->tos & 0xfc;
44 break;
45
46 default:
47 return 0;
48 }
49
50 return dscp >> 5;
51}
52
53
54static int wme_downgrade_ac(struct sk_buff *skb) 26static int wme_downgrade_ac(struct sk_buff *skb)
55{ 27{
56 switch (skb->priority) { 28 switch (skb->priority) {
@@ -94,7 +66,7 @@ static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
94 66
95 /* use the data classifier to determine what 802.1d tag the 67 /* use the data classifier to determine what 802.1d tag the
96 * data frame has */ 68 * data frame has */
97 skb->priority = classify_1d(skb); 69 skb->priority = cfg80211_classify8021d(skb);
98 70
99 /* in case we are a client verify acm is not set for this ac */ 71 /* in case we are a client verify acm is not set for this ac */
100 while (unlikely(local->wmm_acm & BIT(skb->priority))) { 72 while (unlikely(local->wmm_acm & BIT(skb->priority))) {
@@ -129,11 +101,11 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
129 * Now we know the 1d priority, fill in the QoS header if 101 * Now we know the 1d priority, fill in the QoS header if
130 * there is one (and we haven't done this before). 102 * there is one (and we haven't done this before).
131 */ 103 */
132 if (!skb->requeue && ieee80211_is_data_qos(hdr->frame_control)) { 104 if (ieee80211_is_data_qos(hdr->frame_control)) {
133 u8 *p = ieee80211_get_qos_ctl(hdr); 105 u8 *p = ieee80211_get_qos_ctl(hdr);
134 u8 ack_policy = 0; 106 u8 ack_policy = 0;
135 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 107 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
136 if (local->wifi_wme_noack_test) 108 if (unlikely(local->wifi_wme_noack_test))
137 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK << 109 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
138 QOS_CONTROL_ACK_POLICY_SHIFT; 110 QOS_CONTROL_ACK_POLICY_SHIFT;
139 /* qos header is 2 bytes, second reserved */ 111 /* qos header is 2 bytes, second reserved */
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 4f8bfea278f2..dcfae8884b86 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -122,7 +122,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
122 return RX_DROP_UNUSABLE; 122 return RX_DROP_UNUSABLE;
123 123
124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx, 124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx,
125 (void *) skb->data); 125 (void *) skb->data, NULL);
126 return RX_DROP_UNUSABLE; 126 return RX_DROP_UNUSABLE;
127 } 127 }
128 128