aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig16
-rw-r--r--net/mac80211/agg-rx.c19
-rw-r--r--net/mac80211/agg-tx.c13
-rw-r--r--net/mac80211/cfg.c144
-rw-r--r--net/mac80211/debugfs.c66
-rw-r--r--net/mac80211/driver-ops.h184
-rw-r--r--net/mac80211/event.c17
-rw-r--r--net/mac80211/ht.c84
-rw-r--r--net/mac80211/ibss.c484
-rw-r--r--net/mac80211/ieee80211_i.h108
-rw-r--r--net/mac80211/iface.c113
-rw-r--r--net/mac80211/key.c29
-rw-r--r--net/mac80211/key.h3
-rw-r--r--net/mac80211/main.c299
-rw-r--r--net/mac80211/mesh.c6
-rw-r--r--net/mac80211/mlme.c544
-rw-r--r--net/mac80211/pm.c130
-rw-r--r--net/mac80211/rc80211_minstrel.c8
-rw-r--r--net/mac80211/rc80211_pid_algo.c8
-rw-r--r--net/mac80211/rx.c198
-rw-r--r--net/mac80211/scan.c428
-rw-r--r--net/mac80211/spectmgmt.c2
-rw-r--r--net/mac80211/sta_info.c97
-rw-r--r--net/mac80211/sta_info.h5
-rw-r--r--net/mac80211/tkip.c6
-rw-r--r--net/mac80211/tx.c49
-rw-r--r--net/mac80211/util.c289
-rw-r--r--net/mac80211/wext.c552
-rw-r--r--net/mac80211/wme.c2
-rw-r--r--net/mac80211/wpa.c2
30 files changed, 2120 insertions, 1785 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index ecc3faf9f11a..9cbf545e95a2 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -11,6 +11,22 @@ config MAC80211
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
14config MAC80211_DEFAULT_PS
15 bool "enable powersave by default"
16 depends on MAC80211
17 default y
18 help
19 This option enables powersave mode by default.
20
21 If this causes your applications to misbehave you should fix your
22 applications instead -- they need to register their network
23 latency requirement, see Documentation/power/pm_qos_interface.txt.
24
25config MAC80211_DEFAULT_PS_VALUE
26 int
27 default 1 if MAC80211_DEFAULT_PS
28 default 0
29
14menu "Rate control algorithm selection" 30menu "Rate control algorithm selection"
15 depends on MAC80211 != n 31 depends on MAC80211 != n
16 32
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..43d00ffd3988 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/**
@@ -134,8 +135,8 @@ static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
134 *state = HT_AGG_STATE_REQ_STOP_BA_MSK | 135 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
135 (initiator << HT_AGG_STATE_INITIATOR_SHIFT); 136 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
136 137
137 ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP, 138 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_STOP,
138 &sta->sta, tid, NULL); 139 &sta->sta, tid, NULL);
139 140
140 /* HW shall not deny going back to legacy */ 141 /* HW shall not deny going back to legacy */
141 if (WARN_ON(ret)) { 142 if (WARN_ON(ret)) {
@@ -306,8 +307,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
306 307
307 start_seq_num = sta->tid_seq[tid]; 308 start_seq_num = sta->tid_seq[tid];
308 309
309 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, 310 ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_START,
310 &sta->sta, tid, &start_seq_num); 311 &sta->sta, tid, &start_seq_num);
311 312
312 if (ret) { 313 if (ret) {
313#ifdef CONFIG_MAC80211_HT_DEBUG 314#ifdef CONFIG_MAC80211_HT_DEBUG
@@ -418,8 +419,8 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
418 ieee80211_agg_splice_finish(local, sta, tid); 419 ieee80211_agg_splice_finish(local, sta, tid);
419 spin_unlock(&local->ampdu_lock); 420 spin_unlock(&local->ampdu_lock);
420 421
421 local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_OPERATIONAL, 422 drv_ampdu_action(local, IEEE80211_AMPDU_TX_OPERATIONAL,
422 &sta->sta, tid, NULL); 423 &sta->sta, tid, NULL);
423} 424}
424 425
425void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) 426void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index e677b751d468..77e9ff5ec4f3 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,38 @@ 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);
666 665
667 /* 666 /*
668 * FIXME: updating the following information is racy when this 667 * FIXME: updating the following information is racy when this
@@ -1120,7 +1119,7 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
1120 p.cw_max = params->cwmax; 1119 p.cw_max = params->cwmax;
1121 p.cw_min = params->cwmin; 1120 p.cw_min = params->cwmin;
1122 p.txop = params->txop; 1121 p.txop = params->txop;
1123 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) { 1122 if (drv_conf_tx(local, params->queue, &p)) {
1124 printk(KERN_DEBUG "%s: failed to set TX queue " 1123 printk(KERN_DEBUG "%s: failed to set TX queue "
1125 "parameters for queue %d\n", local->mdev->name, 1124 "parameters for queue %d\n", local->mdev->name,
1126 params->queue); 1125 params->queue);
@@ -1167,7 +1166,8 @@ static int ieee80211_scan(struct wiphy *wiphy,
1167 1166
1168 if (sdata->vif.type != NL80211_IFTYPE_STATION && 1167 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1169 sdata->vif.type != NL80211_IFTYPE_ADHOC && 1168 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT) 1169 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1170 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1171 return -EOPNOTSUPP; 1171 return -EOPNOTSUPP;
1172 1172
1173 return ieee80211_request_scan(sdata, req); 1173 return ieee80211_request_scan(sdata, req);
@@ -1258,6 +1258,19 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1258 if (ret) 1258 if (ret)
1259 return ret; 1259 return ret;
1260 1260
1261 if (req->use_mfp) {
1262 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
1263 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
1264 } else {
1265 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
1266 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
1267 }
1268
1269 if (req->control_port)
1270 sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
1271 else
1272 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
1273
1261 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME; 1274 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1262 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE; 1275 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1263 ieee80211_sta_req_auth(sdata); 1276 ieee80211_sta_req_auth(sdata);
@@ -1267,25 +1280,59 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1267static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 1280static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1268 struct cfg80211_deauth_request *req) 1281 struct cfg80211_deauth_request *req)
1269{ 1282{
1270 struct ieee80211_sub_if_data *sdata; 1283 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1271
1272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1273 1284
1274 /* TODO: req->ie */ 1285 /* TODO: req->ie, req->peer_addr */
1275 return ieee80211_sta_deauthenticate(sdata, req->reason_code); 1286 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1276} 1287}
1277 1288
1278static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 1289static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1279 struct cfg80211_disassoc_request *req) 1290 struct cfg80211_disassoc_request *req)
1280{ 1291{
1281 struct ieee80211_sub_if_data *sdata; 1292 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1282
1283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1284 1293
1285 /* TODO: req->ie */ 1294 /* TODO: req->ie, req->peer_addr */
1286 return ieee80211_sta_disassociate(sdata, req->reason_code); 1295 return ieee80211_sta_disassociate(sdata, req->reason_code);
1287} 1296}
1288 1297
1298static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1299 struct cfg80211_ibss_params *params)
1300{
1301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1302
1303 return ieee80211_ibss_join(sdata, params);
1304}
1305
1306static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1307{
1308 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1309
1310 return ieee80211_ibss_leave(sdata);
1311}
1312
1313static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1314{
1315 struct ieee80211_local *local = wiphy_priv(wiphy);
1316 int err;
1317
1318 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1319 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1320
1321 if (err)
1322 return err;
1323 }
1324
1325 if (changed & WIPHY_PARAM_RETRY_SHORT)
1326 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1327 if (changed & WIPHY_PARAM_RETRY_LONG)
1328 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1329 if (changed &
1330 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1331 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1332
1333 return 0;
1334}
1335
1289struct cfg80211_ops mac80211_config_ops = { 1336struct cfg80211_ops mac80211_config_ops = {
1290 .add_virtual_intf = ieee80211_add_iface, 1337 .add_virtual_intf = ieee80211_add_iface,
1291 .del_virtual_intf = ieee80211_del_iface, 1338 .del_virtual_intf = ieee80211_del_iface,
@@ -1322,4 +1369,7 @@ struct cfg80211_ops mac80211_config_ops = {
1322 .assoc = ieee80211_assoc, 1369 .assoc = ieee80211_assoc,
1323 .deauth = ieee80211_deauth, 1370 .deauth = ieee80211_deauth,
1324 .disassoc = ieee80211_disassoc, 1371 .disassoc = ieee80211_disassoc,
1372 .join_ibss = ieee80211_join_ibss,
1373 .leave_ibss = ieee80211_leave_ibss,
1374 .set_wiphy_params = ieee80211_set_wiphy_params,
1325}; 1375};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 210b9b6fecd2..e7682fe1c590 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
@@ -52,13 +53,13 @@ static const struct file_operations name## _ops = { \
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", 55DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
55 local->rts_threshold); 56 local->hw.wiphy->rts_threshold);
56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", 57DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
57 local->fragmentation_threshold); 58 local->hw.wiphy->frag_threshold);
58DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", 59DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
59 local->hw.conf.short_frame_max_tx_count); 60 local->hw.wiphy->retry_short);
60DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", 61DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
61 local->hw.conf.long_frame_max_tx_count); 62 local->hw.wiphy->retry_long);
62DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 63DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
63 local->total_ps_buffered); 64 local->total_ps_buffered);
64DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", 65DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
@@ -70,11 +71,10 @@ static ssize_t tsf_read(struct file *file, char __user *user_buf,
70 size_t count, loff_t *ppos) 71 size_t count, loff_t *ppos)
71{ 72{
72 struct ieee80211_local *local = file->private_data; 73 struct ieee80211_local *local = file->private_data;
73 u64 tsf = 0; 74 u64 tsf;
74 char buf[100]; 75 char buf[100];
75 76
76 if (local->ops->get_tsf) 77 tsf = drv_get_tsf(local);
77 tsf = local->ops->get_tsf(local_to_hw(local));
78 78
79 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf); 79 snprintf(buf, sizeof(buf), "0x%016llx\n", (unsigned long long) tsf);
80 80
@@ -97,13 +97,13 @@ static ssize_t tsf_write(struct file *file,
97 97
98 if (strncmp(buf, "reset", 5) == 0) { 98 if (strncmp(buf, "reset", 5) == 0) {
99 if (local->ops->reset_tsf) { 99 if (local->ops->reset_tsf) {
100 local->ops->reset_tsf(local_to_hw(local)); 100 drv_reset_tsf(local);
101 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy)); 101 printk(KERN_INFO "%s: debugfs reset TSF\n", wiphy_name(local->hw.wiphy));
102 } 102 }
103 } else { 103 } else {
104 tsf = simple_strtoul(buf, NULL, 0); 104 tsf = simple_strtoul(buf, NULL, 0);
105 if (local->ops->set_tsf) { 105 if (local->ops->set_tsf) {
106 local->ops->set_tsf(local_to_hw(local), tsf); 106 drv_set_tsf(local, tsf);
107 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf); 107 printk(KERN_INFO "%s: debugfs set TSF to %#018llx\n", wiphy_name(local->hw.wiphy), tsf);
108 } 108 }
109 } 109 }
@@ -135,6 +135,42 @@ static const struct file_operations reset_ops = {
135 .open = mac80211_open_file_generic, 135 .open = mac80211_open_file_generic,
136}; 136};
137 137
138static ssize_t noack_read(struct file *file, char __user *user_buf,
139 size_t count, loff_t *ppos)
140{
141 struct ieee80211_local *local = file->private_data;
142 int res;
143 char buf[10];
144
145 res = scnprintf(buf, sizeof(buf), "%d\n", local->wifi_wme_noack_test);
146
147 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
148}
149
150static ssize_t noack_write(struct file *file,
151 const char __user *user_buf,
152 size_t count, loff_t *ppos)
153{
154 struct ieee80211_local *local = file->private_data;
155 char buf[10];
156 size_t len;
157
158 len = min(count, sizeof(buf) - 1);
159 if (copy_from_user(buf, user_buf, len))
160 return -EFAULT;
161 buf[len] = '\0';
162
163 local->wifi_wme_noack_test = !!simple_strtoul(buf, NULL, 0);
164
165 return count;
166}
167
168static const struct file_operations noack_ops = {
169 .read = noack_read,
170 .write = noack_write,
171 .open = mac80211_open_file_generic
172};
173
138/* statistics stuff */ 174/* statistics stuff */
139 175
140#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \ 176#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
@@ -150,14 +186,12 @@ static ssize_t format_devstat_counter(struct ieee80211_local *local,
150 char buf[20]; 186 char buf[20];
151 int res; 187 int res;
152 188
153 if (!local->ops->get_stats)
154 return -EOPNOTSUPP;
155
156 rtnl_lock(); 189 rtnl_lock();
157 res = local->ops->get_stats(local_to_hw(local), &stats); 190 res = drv_get_stats(local, &stats);
158 rtnl_unlock(); 191 rtnl_unlock();
159 if (!res) 192 if (res)
160 res = printvalue(&stats, buf, sizeof(buf)); 193 return res;
194 res = printvalue(&stats, buf, sizeof(buf));
161 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 195 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
162} 196}
163 197
@@ -277,6 +311,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
277 DEBUGFS_ADD(wep_iv); 311 DEBUGFS_ADD(wep_iv);
278 DEBUGFS_ADD(tsf); 312 DEBUGFS_ADD(tsf);
279 DEBUGFS_ADD_MODE(reset, 0200); 313 DEBUGFS_ADD_MODE(reset, 0200);
314 DEBUGFS_ADD(noack);
280 315
281 statsd = debugfs_create_dir("statistics", phyd); 316 statsd = debugfs_create_dir("statistics", phyd);
282 local->debugfs.statistics = statsd; 317 local->debugfs.statistics = statsd;
@@ -332,6 +367,7 @@ void debugfs_hw_del(struct ieee80211_local *local)
332 DEBUGFS_DEL(wep_iv); 367 DEBUGFS_DEL(wep_iv);
333 DEBUGFS_DEL(tsf); 368 DEBUGFS_DEL(tsf);
334 DEBUGFS_DEL(reset); 369 DEBUGFS_DEL(reset);
370 DEBUGFS_DEL(noack);
335 371
336 DEBUGFS_STATS_DEL(transmitted_fragment_count); 372 DEBUGFS_STATS_DEL(transmitted_fragment_count);
337 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 373 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..3912b5334b9c
--- /dev/null
+++ b/net/mac80211/driver-ops.h
@@ -0,0 +1,184 @@
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#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..c236079ed38a 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
182 ieee80211_sta_def_wmm_params(sdata, supp_rates_len, supp_rates);
183 175
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,
178 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
187 179
188 memset(&wrqu, 0, sizeof(wrqu)); 180 cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
189 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); 181 mgmt, skb->len, 0, GFP_KERNEL);
190 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); 182 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
191
192 return res;
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;
525
526 capability = WLAN_CAPABILITY_IBSS;
527 if (sdata->default_key)
528 capability |= WLAN_CAPABILITY_PRIVACY;
529 529
530 if (ifibss->flags & IEEE80211_IBSS_BSSID_SET) 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 capability,
535 WLAN_CAPABILITY_IBSS); 539 WLAN_CAPABILITY_IBSS |
540 WLAN_CAPABILITY_PRIVACY);
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
@@ -794,89 +785,25 @@ void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
794 setup_timer(&ifibss->timer, ieee80211_ibss_timer, 785 setup_timer(&ifibss->timer, ieee80211_ibss_timer,
795 (unsigned long) sdata); 786 (unsigned long) sdata);
796 skb_queue_head_init(&ifibss->skb_queue); 787 skb_queue_head_init(&ifibss->skb_queue);
797
798 ifibss->flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
799 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
800}
801
802int ieee80211_ibss_commit(struct ieee80211_sub_if_data *sdata)
803{
804 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
805
806 ifibss->flags &= ~IEEE80211_IBSS_PREV_BSSID_SET;
807
808 if (ifibss->ssid_len)
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 }
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}
845
846int ieee80211_ibss_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
847{
848 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
849
850 if (is_valid_ether_addr(bssid)) {
851 memcpy(ifibss->bssid, bssid, ETH_ALEN);
852 ifibss->flags |= IEEE80211_IBSS_BSSID_SET;
853 } else {
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} 788}
867 789
868/* scan finished notification */ 790/* scan finished notification */
869void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) 791void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
870{ 792{
871 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 793 struct ieee80211_sub_if_data *sdata;
872 struct ieee80211_if_ibss *ifibss; 794
873 795 mutex_lock(&local->iflist_mtx);
874 if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) { 796 list_for_each_entry(sdata, &local->interfaces, list) {
875 ifibss = &sdata->u.ibss; 797 if (!netif_running(sdata->dev))
876 if ((!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET)) || 798 continue;
877 !ieee80211_sta_active_ibss(sdata)) 799 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
878 ieee80211_sta_find_ibss(sdata); 800 continue;
801 if (!sdata->u.ibss.ssid_len)
802 continue;
803 sdata->u.ibss.last_scan_completed = jiffies;
804 ieee80211_sta_find_ibss(sdata);
879 } 805 }
806 mutex_unlock(&local->iflist_mtx);
880} 807}
881 808
882ieee80211_rx_result 809ieee80211_rx_result
@@ -906,3 +833,86 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
906 833
907 return RX_DROP_MONITOR; 834 return RX_DROP_MONITOR;
908} 835}
836
837int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
838 struct cfg80211_ibss_params *params)
839{
840 struct sk_buff *skb;
841
842 if (params->bssid) {
843 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
844 sdata->u.ibss.fixed_bssid = true;
845 } else
846 sdata->u.ibss.fixed_bssid = false;
847
848 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
849
850 sdata->u.ibss.channel = params->channel;
851 sdata->u.ibss.fixed_channel = params->channel_fixed;
852
853 if (params->ie) {
854 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
855 GFP_KERNEL);
856 if (sdata->u.ibss.ie)
857 sdata->u.ibss.ie_len = params->ie_len;
858 }
859
860 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
861 36 /* bitrates */ +
862 34 /* SSID */ +
863 3 /* DS params */ +
864 4 /* IBSS params */ +
865 params->ie_len);
866 if (!skb)
867 return -ENOMEM;
868
869 sdata->u.ibss.skb = skb;
870 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
871 sdata->u.ibss.ibss_join_req = jiffies;
872
873 memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
874
875 /*
876 * The ssid_len setting below is used to see whether
877 * we are active, and we need all other settings
878 * before that may get visible.
879 */
880 mb();
881
882 sdata->u.ibss.ssid_len = params->ssid_len;
883
884 ieee80211_recalc_idle(sdata->local);
885
886 set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
887 queue_work(sdata->local->hw.workqueue, &sdata->u.ibss.work);
888
889 return 0;
890}
891
892int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
893{
894 struct sk_buff *skb;
895
896 del_timer_sync(&sdata->u.ibss.timer);
897 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
898 cancel_work_sync(&sdata->u.ibss.work);
899 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
900
901 sta_info_flush(sdata->local, sdata);
902
903 /* remove beacon */
904 kfree(sdata->u.ibss.ie);
905 skb = sdata->u.ibss.presp;
906 rcu_assign_pointer(sdata->u.ibss.presp, NULL);
907 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
908 synchronize_rcu();
909 kfree_skb(skb);
910
911 skb_queue_purge(&sdata->u.ibss.skb_queue);
912 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
913 sdata->u.ibss.ssid_len = 0;
914
915 ieee80211_recalc_idle(sdata->local);
916
917 return 0;
918}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index e6ed78cb16b3..9d1514727f6e 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,8 @@ 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 bool powersave; /* powersave requested for this iface */
297
298 unsigned long request; 298 unsigned long request;
299 299
300 unsigned long last_probe; 300 unsigned long last_probe;
@@ -306,6 +306,8 @@ struct ieee80211_if_managed {
306 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */ 306 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
307 int auth_transaction; 307 int auth_transaction;
308 308
309 u32 beacon_crc;
310
309 enum { 311 enum {
310 IEEE80211_MFP_DISABLED, 312 IEEE80211_MFP_DISABLED,
311 IEEE80211_MFP_OPTIONAL, 313 IEEE80211_MFP_OPTIONAL,
@@ -319,14 +321,6 @@ struct ieee80211_if_managed {
319 size_t sme_auth_ie_len; 321 size_t sme_auth_ie_len;
320}; 322};
321 323
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 { 324enum ieee80211_ibss_request {
331 IEEE80211_IBSS_REQ_RUN = 0, 325 IEEE80211_IBSS_REQ_RUN = 0,
332}; 326};
@@ -337,17 +331,20 @@ struct ieee80211_if_ibss {
337 331
338 struct sk_buff_head skb_queue; 332 struct sk_buff_head skb_queue;
339 333
340 u8 ssid[IEEE80211_MAX_SSID_LEN]; 334 unsigned long request;
341 u8 ssid_len; 335 unsigned long last_scan_completed;
342 336 bool fixed_bssid;
343 u32 flags; 337 bool fixed_channel;
344 338
345 u8 bssid[ETH_ALEN]; 339 u8 bssid[ETH_ALEN];
346 340 u8 ssid[IEEE80211_MAX_SSID_LEN];
347 unsigned long request; 341 u8 ssid_len, ie_len;
342 u8 *ie;
343 struct ieee80211_channel *channel;
348 344
349 unsigned long ibss_join_req; 345 unsigned long ibss_join_req;
350 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */ 346 /* probe response/beacon for IBSS */
347 struct sk_buff *presp, *skb;
351 348
352 enum { 349 enum {
353 IEEE80211_IBSS_MLME_SEARCH, 350 IEEE80211_IBSS_MLME_SEARCH,
@@ -430,6 +427,12 @@ struct ieee80211_sub_if_data {
430 427
431 int drop_unencrypted; 428 int drop_unencrypted;
432 429
430 /*
431 * keep track of whether the HT opmode (stored in
432 * vif.bss_info.ht_operation_mode) is valid.
433 */
434 bool ht_opmode_valid;
435
433 /* Fragment table for host-based reassembly */ 436 /* Fragment table for host-based reassembly */
434 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX]; 437 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
435 unsigned int fragment_next; 438 unsigned int fragment_next;
@@ -626,8 +629,6 @@ struct ieee80211_local {
626 spinlock_t sta_lock; 629 spinlock_t sta_lock;
627 unsigned long num_sta; 630 unsigned long num_sta;
628 struct list_head sta_list; 631 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]; 632 struct sta_info *sta_hash[STA_HASH_SIZE];
632 struct timer_list sta_cleanup; 633 struct timer_list sta_cleanup;
633 634
@@ -647,9 +648,6 @@ struct ieee80211_local {
647 648
648 struct rate_control_ref *rate_ctrl; 649 struct rate_control_ref *rate_ctrl;
649 650
650 int rts_threshold;
651 int fragmentation_threshold;
652
653 struct crypto_blkcipher *wep_tx_tfm; 651 struct crypto_blkcipher *wep_tx_tfm;
654 struct crypto_blkcipher *wep_rx_tfm; 652 struct crypto_blkcipher *wep_rx_tfm;
655 u32 wep_iv; 653 u32 wep_iv;
@@ -666,15 +664,18 @@ struct ieee80211_local {
666 664
667 665
668 /* Scanning and BSS list */ 666 /* Scanning and BSS list */
667 struct mutex scan_mtx;
669 bool sw_scanning, hw_scanning; 668 bool sw_scanning, hw_scanning;
670 struct cfg80211_ssid scan_ssid; 669 struct cfg80211_ssid scan_ssid;
671 struct cfg80211_scan_request int_scan_req; 670 struct cfg80211_scan_request int_scan_req;
672 struct cfg80211_scan_request *scan_req; 671 struct cfg80211_scan_request *scan_req;
673 struct ieee80211_channel *scan_channel; 672 struct ieee80211_channel *scan_channel;
673 const u8 *orig_ies;
674 int orig_ies_len;
674 int scan_channel_idx; 675 int scan_channel_idx;
676 int scan_ies_len;
675 677
676 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 678 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
677 unsigned long last_scan_completed;
678 struct delayed_work scan_work; 679 struct delayed_work scan_work;
679 struct ieee80211_sub_if_data *scan_sdata; 680 struct ieee80211_sub_if_data *scan_sdata;
680 enum nl80211_channel_type oper_channel_type; 681 enum nl80211_channel_type oper_channel_type;
@@ -736,15 +737,22 @@ struct ieee80211_local {
736 int wifi_wme_noack_test; 737 int wifi_wme_noack_test;
737 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 738 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
738 739
739 bool powersave;
740 bool pspolling; 740 bool pspolling;
741 /*
742 * PS can only be enabled when we have exactly one managed
743 * interface (and monitors) in PS, this then points there.
744 */
745 struct ieee80211_sub_if_data *ps_sdata;
741 struct work_struct dynamic_ps_enable_work; 746 struct work_struct dynamic_ps_enable_work;
742 struct work_struct dynamic_ps_disable_work; 747 struct work_struct dynamic_ps_disable_work;
743 struct timer_list dynamic_ps_timer; 748 struct timer_list dynamic_ps_timer;
749 struct notifier_block network_latency_notifier;
744 750
745 int user_power_level; /* in dBm */ 751 int user_power_level; /* in dBm */
746 int power_constr_level; /* in dBm */ 752 int power_constr_level; /* in dBm */
747 753
754 struct work_struct restart_work;
755
748#ifdef CONFIG_MAC80211_DEBUGFS 756#ifdef CONFIG_MAC80211_DEBUGFS
749 struct local_debugfsdentries { 757 struct local_debugfsdentries {
750 struct dentry *rcdir; 758 struct dentry *rcdir;
@@ -758,6 +766,7 @@ struct ieee80211_local {
758 struct dentry *wep_iv; 766 struct dentry *wep_iv;
759 struct dentry *tsf; 767 struct dentry *tsf;
760 struct dentry *reset; 768 struct dentry *reset;
769 struct dentry *noack;
761 struct dentry *statistics; 770 struct dentry *statistics;
762 struct local_debugfsdentries_statsdentries { 771 struct local_debugfsdentries_statsdentries {
763 struct dentry *transmitted_fragment_count; 772 struct dentry *transmitted_fragment_count;
@@ -830,7 +839,7 @@ struct ieee802_11_elems {
830 u8 *fh_params; 839 u8 *fh_params;
831 u8 *ds_params; 840 u8 *ds_params;
832 u8 *cf_params; 841 u8 *cf_params;
833 u8 *tim; 842 struct ieee80211_tim_ie *tim;
834 u8 *ibss_params; 843 u8 *ibss_params;
835 u8 *challenge; 844 u8 *challenge;
836 u8 *wpa; 845 u8 *wpa;
@@ -903,7 +912,6 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
903 912
904 913
905int ieee80211_hw_config(struct ieee80211_local *local, u32 changed); 914int 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); 915void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
908void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, 916void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
909 u32 changed); 917 u32 changed);
@@ -927,12 +935,11 @@ int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason
927int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason); 935int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
928void ieee80211_send_pspoll(struct ieee80211_local *local, 936void ieee80211_send_pspoll(struct ieee80211_local *local,
929 struct ieee80211_sub_if_data *sdata); 937 struct ieee80211_sub_if_data *sdata);
938void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency);
939int ieee80211_max_network_latency(struct notifier_block *nb,
940 unsigned long data, void *dummy);
930 941
931/* IBSS code */ 942/* 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); 943void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
937void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata); 944void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
938ieee80211_rx_result 945ieee80211_rx_result
@@ -940,9 +947,14 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
940 struct ieee80211_rx_status *rx_status); 947 struct ieee80211_rx_status *rx_status);
941struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 948struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
942 u8 *bssid, u8 *addr, u32 supp_rates); 949 u8 *bssid, u8 *addr, u32 supp_rates);
950int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
951 struct cfg80211_ibss_params *params);
952int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
943 953
944/* scan/BSS handling */ 954/* scan/BSS handling */
945void ieee80211_scan_work(struct work_struct *work); 955void ieee80211_scan_work(struct work_struct *work);
956int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
957 const u8 *ssid, u8 ssid_len);
946int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 958int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
947 struct cfg80211_scan_request *req); 959 struct cfg80211_scan_request *req);
948int ieee80211_scan_results(struct ieee80211_local *local, 960int ieee80211_scan_results(struct ieee80211_local *local,
@@ -956,9 +968,6 @@ int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
956 const char *ie, size_t len); 968 const char *ie, size_t len);
957 969
958void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); 970void 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 * 971struct ieee80211_bss *
963ieee80211_bss_info_update(struct ieee80211_local *local, 972ieee80211_bss_info_update(struct ieee80211_local *local,
964 struct ieee80211_rx_status *rx_status, 973 struct ieee80211_rx_status *rx_status,
@@ -983,6 +992,8 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
983 enum nl80211_iftype type); 992 enum nl80211_iftype type);
984void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata); 993void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata);
985void ieee80211_remove_interfaces(struct ieee80211_local *local); 994void ieee80211_remove_interfaces(struct ieee80211_local *local);
995u32 __ieee80211_recalc_idle(struct ieee80211_local *local);
996void ieee80211_recalc_idle(struct ieee80211_local *local);
986 997
987/* tx handling */ 998/* tx handling */
988void ieee80211_clear_tx_pending(struct ieee80211_local *local); 999void ieee80211_clear_tx_pending(struct ieee80211_local *local);
@@ -995,9 +1006,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, 1006void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
996 struct ieee80211_ht_cap *ht_cap_ie, 1007 struct ieee80211_ht_cap *ht_cap_ie,
997 struct ieee80211_sta_ht_cap *ht_cap); 1008 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); 1009void 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, 1010void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
1003 const u8 *da, u16 tid, 1011 const u8 *da, u16 tid,
@@ -1036,15 +1044,22 @@ void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1036 u16 capab_info, u8 *pwr_constr_elem, 1044 u16 capab_info, u8 *pwr_constr_elem,
1037 u8 pwr_constr_elem_len); 1045 u8 pwr_constr_elem_len);
1038 1046
1039/* Suspend/resume */ 1047/* Suspend/resume and hw reconfiguration */
1048int ieee80211_reconfig(struct ieee80211_local *local);
1049
1040#ifdef CONFIG_PM 1050#ifdef CONFIG_PM
1041int __ieee80211_suspend(struct ieee80211_hw *hw); 1051int __ieee80211_suspend(struct ieee80211_hw *hw);
1042int __ieee80211_resume(struct ieee80211_hw *hw); 1052
1053static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1054{
1055 return ieee80211_reconfig(hw_to_local(hw));
1056}
1043#else 1057#else
1044static inline int __ieee80211_suspend(struct ieee80211_hw *hw) 1058static inline int __ieee80211_suspend(struct ieee80211_hw *hw)
1045{ 1059{
1046 return 0; 1060 return 0;
1047} 1061}
1062
1048static inline int __ieee80211_resume(struct ieee80211_hw *hw) 1063static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1049{ 1064{
1050 return 0; 1065 return 0;
@@ -1060,12 +1075,15 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1060int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1075int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
1061 int rate, int erp, int short_preamble); 1076 int rate, int erp, int short_preamble);
1062void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1077void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1063 struct ieee80211_hdr *hdr); 1078 struct ieee80211_hdr *hdr, const u8 *tsc);
1064void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1079void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1065void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1080void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1066 int encrypt); 1081 int encrypt);
1067void ieee802_11_parse_elems(u8 *start, size_t len, 1082void ieee802_11_parse_elems(u8 *start, size_t len,
1068 struct ieee802_11_elems *elems); 1083 struct ieee802_11_elems *elems);
1084u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1085 struct ieee802_11_elems *elems,
1086 u64 filter, u32 crc);
1069int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq); 1087int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
1070u32 ieee80211_mandatory_rates(struct ieee80211_local *local, 1088u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1071 enum ieee80211_band band); 1089 enum ieee80211_band band);
@@ -1093,9 +1111,11 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1093 u16 transaction, u16 auth_alg, 1111 u16 transaction, u16 auth_alg,
1094 u8 *extra, size_t extra_len, 1112 u8 *extra, size_t extra_len,
1095 const u8 *bssid, int encrypt); 1113 const u8 *bssid, int encrypt);
1114int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1115 const u8 *ie, size_t ie_len);
1096void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 1116void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1097 u8 *ssid, size_t ssid_len, 1117 const u8 *ssid, size_t ssid_len,
1098 u8 *ie, size_t ie_len); 1118 const u8 *ie, size_t ie_len);
1099 1119
1100void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 1120void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1101 const size_t supp_rates_len, 1121 const size_t supp_rates_len,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 91e8e1bacaaa..8c9f1c722cdb 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,9 +165,7 @@ 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 */
@@ -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,17 +545,20 @@ 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, 0);
565 564
@@ -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..827ea8e6ee0a 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 && seq_len == 6) {
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 && seq_len == CCMP_PN_LEN) {
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 && seq_len == 6)
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..76df5eabf268 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
@@ -293,17 +220,77 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
293{ 220{
294 struct ieee80211_local *local = sdata->local; 221 struct ieee80211_local *local = sdata->local;
295 222
296 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) 223 if (!changed)
297 return; 224 return;
298 225
299 if (!changed) 226 if (sdata->vif.type == NL80211_IFTYPE_STATION)
227 sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid;
228 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
229 sdata->vif.bss_conf.bssid = sdata->u.ibss.bssid;
230 else if (sdata->vif.type == NL80211_IFTYPE_AP)
231 sdata->vif.bss_conf.bssid = sdata->dev->dev_addr;
232 else if (ieee80211_vif_is_mesh(&sdata->vif)) {
233 static const u8 zero[ETH_ALEN] = { 0 };
234 sdata->vif.bss_conf.bssid = zero;
235 } else {
236 WARN_ON(1);
300 return; 237 return;
238 }
239
240 switch (sdata->vif.type) {
241 case NL80211_IFTYPE_AP:
242 case NL80211_IFTYPE_ADHOC:
243 case NL80211_IFTYPE_MESH_POINT:
244 break;
245 default:
246 /* do not warn to simplify caller in scan.c */
247 changed &= ~BSS_CHANGED_BEACON_ENABLED;
248 if (WARN_ON(changed & BSS_CHANGED_BEACON))
249 return;
250 break;
251 }
301 252
302 if (local->ops->bss_info_changed) 253 if (changed & BSS_CHANGED_BEACON_ENABLED) {
303 local->ops->bss_info_changed(local_to_hw(local), 254 if (local->sw_scanning) {
304 &sdata->vif, 255 sdata->vif.bss_conf.enable_beacon = false;
305 &sdata->vif.bss_conf, 256 } else {
306 changed); 257 /*
258 * Beacon should be enabled, but AP mode must
259 * check whether there is a beacon configured.
260 */
261 switch (sdata->vif.type) {
262 case NL80211_IFTYPE_AP:
263 sdata->vif.bss_conf.enable_beacon =
264 !!rcu_dereference(sdata->u.ap.beacon);
265 break;
266 case NL80211_IFTYPE_ADHOC:
267 sdata->vif.bss_conf.enable_beacon =
268 !!rcu_dereference(sdata->u.ibss.presp);
269 break;
270 case NL80211_IFTYPE_MESH_POINT:
271 sdata->vif.bss_conf.enable_beacon = true;
272 break;
273 default:
274 /* not reached */
275 WARN_ON(1);
276 break;
277 }
278 }
279 }
280
281 drv_bss_info_changed(local, &sdata->vif,
282 &sdata->vif.bss_conf, changed);
283
284 /*
285 * DEPRECATED
286 *
287 * ~changed is just there to not do this at resume time
288 */
289 if (changed & BSS_CHANGED_BEACON_INT && ~changed) {
290 local->hw.conf.beacon_int = sdata->vif.bss_conf.beacon_int;
291 ieee80211_hw_config(local,
292 _IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
293 }
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)
@@ -696,6 +683,28 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
696} 683}
697EXPORT_SYMBOL(ieee80211_tx_status); 684EXPORT_SYMBOL(ieee80211_tx_status);
698 685
686static void ieee80211_restart_work(struct work_struct *work)
687{
688 struct ieee80211_local *local =
689 container_of(work, struct ieee80211_local, restart_work);
690
691 rtnl_lock();
692 ieee80211_reconfig(local);
693 rtnl_unlock();
694}
695
696void ieee80211_restart_hw(struct ieee80211_hw *hw)
697{
698 struct ieee80211_local *local = hw_to_local(hw);
699
700 /* use this reason, __ieee80211_resume will unblock it */
701 ieee80211_stop_queues_by_reason(hw,
702 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
703
704 schedule_work(&local->restart_work);
705}
706EXPORT_SYMBOL(ieee80211_restart_hw);
707
699struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 708struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
700 const struct ieee80211_ops *ops) 709 const struct ieee80211_ops *ops)
701{ 710{
@@ -728,12 +737,13 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
728 return NULL; 737 return NULL;
729 738
730 wiphy->privid = mac80211_wiphy_privid; 739 wiphy->privid = mac80211_wiphy_privid;
731 wiphy->max_scan_ssids = 4; 740
732 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ 741 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */
733 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) - 742 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) -
734 sizeof(struct cfg80211_bss); 743 sizeof(struct cfg80211_bss);
735 744
736 local = wiphy_priv(wiphy); 745 local = wiphy_priv(wiphy);
746
737 local->hw.wiphy = wiphy; 747 local->hw.wiphy = wiphy;
738 748
739 local->hw.priv = (char *)local + 749 local->hw.priv = (char *)local +
@@ -752,15 +762,14 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
752 /* set up some defaults */ 762 /* set up some defaults */
753 local->hw.queues = 1; 763 local->hw.queues = 1;
754 local->hw.max_rates = 1; 764 local->hw.max_rates = 1;
755 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 765 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
756 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 766 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; 767 local->hw.conf.radio_enabled = true;
760 local->user_power_level = -1; 768 local->user_power_level = -1;
761 769
762 INIT_LIST_HEAD(&local->interfaces); 770 INIT_LIST_HEAD(&local->interfaces);
763 mutex_init(&local->iflist_mtx); 771 mutex_init(&local->iflist_mtx);
772 mutex_init(&local->scan_mtx);
764 773
765 spin_lock_init(&local->key_lock); 774 spin_lock_init(&local->key_lock);
766 775
@@ -768,6 +777,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
768 777
769 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 778 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
770 779
780 INIT_WORK(&local->restart_work, ieee80211_restart_work);
781
771 INIT_WORK(&local->dynamic_ps_enable_work, 782 INIT_WORK(&local->dynamic_ps_enable_work,
772 ieee80211_dynamic_ps_enable_work); 783 ieee80211_dynamic_ps_enable_work);
773 INIT_WORK(&local->dynamic_ps_disable_work, 784 INIT_WORK(&local->dynamic_ps_disable_work,
@@ -821,7 +832,17 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
821 enum ieee80211_band band; 832 enum ieee80211_band band;
822 struct net_device *mdev; 833 struct net_device *mdev;
823 struct ieee80211_master_priv *mpriv; 834 struct ieee80211_master_priv *mpriv;
824 int channels, i, j; 835 int channels, i, j, max_bitrates;
836 bool supp_ht;
837 static const u32 cipher_suites[] = {
838 WLAN_CIPHER_SUITE_WEP40,
839 WLAN_CIPHER_SUITE_WEP104,
840 WLAN_CIPHER_SUITE_TKIP,
841 WLAN_CIPHER_SUITE_CCMP,
842
843 /* keep last -- depends on hw flags! */
844 WLAN_CIPHER_SUITE_AES_CMAC
845 };
825 846
826 /* 847 /*
827 * generic code guarantees at least one band, 848 * generic code guarantees at least one band,
@@ -829,18 +850,25 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
829 * that hw.conf.channel is assigned 850 * that hw.conf.channel is assigned
830 */ 851 */
831 channels = 0; 852 channels = 0;
853 max_bitrates = 0;
854 supp_ht = false;
832 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 855 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
833 struct ieee80211_supported_band *sband; 856 struct ieee80211_supported_band *sband;
834 857
835 sband = local->hw.wiphy->bands[band]; 858 sband = local->hw.wiphy->bands[band];
836 if (sband && !local->oper_channel) { 859 if (!sband)
860 continue;
861 if (!local->oper_channel) {
837 /* init channel we're on */ 862 /* init channel we're on */
838 local->hw.conf.channel = 863 local->hw.conf.channel =
839 local->oper_channel = 864 local->oper_channel = &sband->channels[0];
840 local->scan_channel = &sband->channels[0]; 865 local->hw.conf.channel_type = NL80211_CHAN_NO_HT;
841 } 866 }
842 if (sband) 867 channels += sband->n_channels;
843 channels += sband->n_channels; 868
869 if (max_bitrates < sband->n_bitrates)
870 max_bitrates = sband->n_bitrates;
871 supp_ht = supp_ht || sband->ht_cap.ht_supported;
844 } 872 }
845 873
846 local->int_scan_req.n_channels = channels; 874 local->int_scan_req.n_channels = channels;
@@ -860,6 +888,37 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
860 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 888 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
861 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; 889 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
862 890
891 /*
892 * Calculate scan IE length -- we need this to alloc
893 * memory and to subtract from the driver limit. It
894 * includes the (extended) supported rates and HT
895 * information -- SSID is the driver's responsibility.
896 */
897 local->scan_ies_len = 4 + max_bitrates; /* (ext) supp rates */
898 if (supp_ht)
899 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
900
901 if (!local->ops->hw_scan) {
902 /* For hw_scan, driver needs to set these up. */
903 local->hw.wiphy->max_scan_ssids = 4;
904 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
905 }
906
907 /*
908 * If the driver supports any scan IEs, then assume the
909 * limit includes the IEs mac80211 will add, otherwise
910 * leave it at zero and let the driver sort it out; we
911 * still pass our IEs to the driver but userspace will
912 * not be allowed to in that case.
913 */
914 if (local->hw.wiphy->max_scan_ie_len)
915 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
916
917 local->hw.wiphy->cipher_suites = cipher_suites;
918 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
919 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
920 local->hw.wiphy->n_cipher_suites--;
921
863 result = wiphy_register(local->hw.wiphy); 922 result = wiphy_register(local->hw.wiphy);
864 if (result < 0) 923 if (result < 0)
865 goto fail_wiphy_register; 924 goto fail_wiphy_register;
@@ -898,9 +957,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
898 957
899 debugfs_hw_add(local); 958 debugfs_hw_add(local);
900 959
901 if (local->hw.conf.beacon_int < 10)
902 local->hw.conf.beacon_int = 100;
903
904 if (local->hw.max_listen_interval == 0) 960 if (local->hw.max_listen_interval == 0)
905 local->hw.max_listen_interval = 1; 961 local->hw.max_listen_interval = 1;
906 962
@@ -965,25 +1021,38 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
965 } 1021 }
966 } 1022 }
967 1023
1024 local->network_latency_notifier.notifier_call =
1025 ieee80211_max_network_latency;
1026 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
1027 &local->network_latency_notifier);
1028
1029 if (result) {
1030 rtnl_lock();
1031 goto fail_pm_qos;
1032 }
1033
968 return 0; 1034 return 0;
969 1035
970fail_rate: 1036 fail_pm_qos:
1037 ieee80211_led_exit(local);
1038 ieee80211_remove_interfaces(local);
1039 fail_rate:
971 unregister_netdevice(local->mdev); 1040 unregister_netdevice(local->mdev);
972 local->mdev = NULL; 1041 local->mdev = NULL;
973fail_dev: 1042 fail_dev:
974 rtnl_unlock(); 1043 rtnl_unlock();
975 ieee80211_wep_free(local); 1044 ieee80211_wep_free(local);
976fail_wep: 1045 fail_wep:
977 sta_info_stop(local); 1046 sta_info_stop(local);
978fail_sta_info: 1047 fail_sta_info:
979 debugfs_hw_del(local); 1048 debugfs_hw_del(local);
980 destroy_workqueue(local->hw.workqueue); 1049 destroy_workqueue(local->hw.workqueue);
981fail_workqueue: 1050 fail_workqueue:
982 if (local->mdev) 1051 if (local->mdev)
983 free_netdev(local->mdev); 1052 free_netdev(local->mdev);
984fail_mdev_alloc: 1053 fail_mdev_alloc:
985 wiphy_unregister(local->hw.wiphy); 1054 wiphy_unregister(local->hw.wiphy);
986fail_wiphy_register: 1055 fail_wiphy_register:
987 kfree(local->int_scan_req.channels); 1056 kfree(local->int_scan_req.channels);
988 return result; 1057 return result;
989} 1058}
@@ -996,6 +1065,9 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
996 tasklet_kill(&local->tx_pending_tasklet); 1065 tasklet_kill(&local->tx_pending_tasklet);
997 tasklet_kill(&local->tasklet); 1066 tasklet_kill(&local->tasklet);
998 1067
1068 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1069 &local->network_latency_notifier);
1070
999 rtnl_lock(); 1071 rtnl_lock();
1000 1072
1001 /* 1073 /*
@@ -1038,6 +1110,7 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
1038 struct ieee80211_local *local = hw_to_local(hw); 1110 struct ieee80211_local *local = hw_to_local(hw);
1039 1111
1040 mutex_destroy(&local->iflist_mtx); 1112 mutex_destroy(&local->iflist_mtx);
1113 mutex_destroy(&local->scan_mtx);
1041 1114
1042 wiphy_free(local->hw.wiphy); 1115 wiphy_free(local->hw.wiphy);
1043} 1116}
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 9a3e5de0410a..9000b01a1671 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -417,7 +417,7 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
417 417
418 free_plinks = mesh_plink_availables(sdata); 418 free_plinks = mesh_plink_availables(sdata);
419 if (free_plinks != sdata->u.mesh.accepting_plinks) 419 if (free_plinks != sdata->u.mesh.accepting_plinks)
420 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); 420 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON);
421 421
422 ifmsh->housekeeping = false; 422 ifmsh->housekeeping = false;
423 mod_timer(&ifmsh->housekeeping_timer, 423 mod_timer(&ifmsh->housekeeping_timer,
@@ -432,8 +432,8 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
432 432
433 ifmsh->housekeeping = true; 433 ifmsh->housekeeping = true;
434 queue_work(local->hw.workqueue, &ifmsh->work); 434 queue_work(local->hw.workqueue, &ifmsh->work);
435 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON | 435 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
436 IEEE80211_IFCC_BEACON_ENABLED); 436 BSS_CHANGED_BEACON_ENABLED);
437} 437}
438 438
439void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) 439void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 132938b073dc..ae030688771f 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,6 +33,7 @@
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 / 20)
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
@@ -80,6 +84,88 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
80 return count; 84 return count;
81} 85}
82 86
87/*
88 * ieee80211_enable_ht should be called only after the operating band
89 * has been determined as ht configuration depends on the hw's
90 * HT abilities for a specific band.
91 */
92static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
93 struct ieee80211_ht_info *hti,
94 u16 ap_ht_cap_flags)
95{
96 struct ieee80211_local *local = sdata->local;
97 struct ieee80211_supported_band *sband;
98 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
99 struct sta_info *sta;
100 u32 changed = 0;
101 u16 ht_opmode;
102 bool enable_ht = true, ht_changed;
103 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
104
105 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
106
107 /* HT is not supported */
108 if (!sband->ht_cap.ht_supported)
109 enable_ht = false;
110
111 /* check that channel matches the right operating channel */
112 if (local->hw.conf.channel->center_freq !=
113 ieee80211_channel_to_frequency(hti->control_chan))
114 enable_ht = false;
115
116 if (enable_ht) {
117 channel_type = NL80211_CHAN_HT20;
118
119 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
120 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
121 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
122 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
123 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
124 channel_type = NL80211_CHAN_HT40PLUS;
125 break;
126 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
127 channel_type = NL80211_CHAN_HT40MINUS;
128 break;
129 }
130 }
131 }
132
133 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
134 channel_type != local->hw.conf.channel_type;
135
136 local->oper_channel_type = channel_type;
137
138 if (ht_changed) {
139 /* channel_type change automatically detected */
140 ieee80211_hw_config(local, 0);
141
142 rcu_read_lock();
143
144 sta = sta_info_get(local, ifmgd->bssid);
145 if (sta)
146 rate_control_rate_update(local, sband, sta,
147 IEEE80211_RC_HT_CHANGED);
148
149 rcu_read_unlock();
150 }
151
152 /* disable HT */
153 if (!enable_ht)
154 return 0;
155
156 ht_opmode = le16_to_cpu(hti->operation_mode);
157
158 /* if bss configuration changed store the new one */
159 if (!sdata->ht_opmode_valid ||
160 sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
161 changed |= BSS_CHANGED_HT;
162 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
163 sdata->ht_opmode_valid = true;
164 }
165
166 return changed;
167}
168
83/* frame sending functions */ 169/* frame sending functions */
84 170
85static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 171static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
@@ -325,6 +411,10 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
325 /* u.deauth.reason_code == u.disassoc.reason_code */ 411 /* u.deauth.reason_code == u.disassoc.reason_code */
326 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 412 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
327 413
414 if (stype == IEEE80211_STYPE_DEAUTH)
415 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
416 else
417 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
328 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 418 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
329} 419}
330 420
@@ -359,6 +449,173 @@ void ieee80211_send_pspoll(struct ieee80211_local *local,
359 ieee80211_tx_skb(sdata, skb, 0); 449 ieee80211_tx_skb(sdata, skb, 0);
360} 450}
361 451
452void ieee80211_send_nullfunc(struct ieee80211_local *local,
453 struct ieee80211_sub_if_data *sdata,
454 int powersave)
455{
456 struct sk_buff *skb;
457 struct ieee80211_hdr *nullfunc;
458 __le16 fc;
459
460 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
461 return;
462
463 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
464 if (!skb) {
465 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
466 "frame\n", sdata->dev->name);
467 return;
468 }
469 skb_reserve(skb, local->hw.extra_tx_headroom);
470
471 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
472 memset(nullfunc, 0, 24);
473 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
474 IEEE80211_FCTL_TODS);
475 if (powersave)
476 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
477 nullfunc->frame_control = fc;
478 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
479 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
480 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
481
482 ieee80211_tx_skb(sdata, skb, 0);
483}
484
485/* powersave */
486static void ieee80211_enable_ps(struct ieee80211_local *local,
487 struct ieee80211_sub_if_data *sdata)
488{
489 struct ieee80211_conf *conf = &local->hw.conf;
490
491 /*
492 * If we are scanning right now then the parameters will
493 * take effect when scan finishes.
494 */
495 if (local->hw_scanning || local->sw_scanning)
496 return;
497
498 if (conf->dynamic_ps_timeout > 0 &&
499 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
500 mod_timer(&local->dynamic_ps_timer, jiffies +
501 msecs_to_jiffies(conf->dynamic_ps_timeout));
502 } else {
503 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
504 ieee80211_send_nullfunc(local, sdata, 1);
505 conf->flags |= IEEE80211_CONF_PS;
506 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
507 }
508}
509
510static void ieee80211_change_ps(struct ieee80211_local *local)
511{
512 struct ieee80211_conf *conf = &local->hw.conf;
513
514 if (local->ps_sdata) {
515 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
516 return;
517
518 ieee80211_enable_ps(local, local->ps_sdata);
519 } else if (conf->flags & IEEE80211_CONF_PS) {
520 conf->flags &= ~IEEE80211_CONF_PS;
521 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
522 del_timer_sync(&local->dynamic_ps_timer);
523 cancel_work_sync(&local->dynamic_ps_enable_work);
524 }
525}
526
527/* need to hold RTNL or interface lock */
528void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
529{
530 struct ieee80211_sub_if_data *sdata, *found = NULL;
531 int count = 0;
532
533 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
534 local->ps_sdata = NULL;
535 return;
536 }
537
538 list_for_each_entry(sdata, &local->interfaces, list) {
539 if (!netif_running(sdata->dev))
540 continue;
541 if (sdata->vif.type != NL80211_IFTYPE_STATION)
542 continue;
543 found = sdata;
544 count++;
545 }
546
547 if (count == 1 && found->u.mgd.powersave) {
548 s32 beaconint_us;
549
550 if (latency < 0)
551 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
552
553 beaconint_us = ieee80211_tu_to_usec(
554 found->vif.bss_conf.beacon_int);
555
556 if (beaconint_us > latency) {
557 local->ps_sdata = NULL;
558 } else {
559 u8 dtimper = found->vif.bss_conf.dtim_period;
560 int maxslp = 1;
561
562 if (dtimper > 1)
563 maxslp = min_t(int, dtimper,
564 latency / beaconint_us);
565
566 local->hw.conf.max_sleep_period = maxslp;
567 local->ps_sdata = found;
568 }
569 } else {
570 local->ps_sdata = NULL;
571 }
572
573 ieee80211_change_ps(local);
574}
575
576void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
577{
578 struct ieee80211_local *local =
579 container_of(work, struct ieee80211_local,
580 dynamic_ps_disable_work);
581
582 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
583 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
585 }
586
587 ieee80211_wake_queues_by_reason(&local->hw,
588 IEEE80211_QUEUE_STOP_REASON_PS);
589}
590
591void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
592{
593 struct ieee80211_local *local =
594 container_of(work, struct ieee80211_local,
595 dynamic_ps_enable_work);
596 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
597
598 /* can only happen when PS was just disabled anyway */
599 if (!sdata)
600 return;
601
602 if (local->hw.conf.flags & IEEE80211_CONF_PS)
603 return;
604
605 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
606 ieee80211_send_nullfunc(local, sdata, 1);
607
608 local->hw.conf.flags |= IEEE80211_CONF_PS;
609 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
610}
611
612void ieee80211_dynamic_ps_timer(unsigned long data)
613{
614 struct ieee80211_local *local = (void *) data;
615
616 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
617}
618
362/* MLME */ 619/* MLME */
363static void ieee80211_sta_wmm_params(struct ieee80211_local *local, 620static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
364 struct ieee80211_if_managed *ifmgd, 621 struct ieee80211_if_managed *ifmgd,
@@ -427,38 +684,13 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
427 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min, 684 local->mdev->name, queue, aci, acm, params.aifs, params.cw_min,
428 params.cw_max, params.txop); 685 params.cw_max, params.txop);
429#endif 686#endif
430 if (local->ops->conf_tx && 687 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 " 688 printk(KERN_DEBUG "%s: failed to set TX queue "
433 "parameters for queue %d\n", local->mdev->name, queue); 689 "parameters for queue %d\n", local->mdev->name,
434 } 690 queue);
435 } 691 }
436} 692}
437 693
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, 694static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
463 u16 capab, bool erp_valid, u8 erp) 695 u16 capab, bool erp_valid, u8 erp)
464{ 696{
@@ -610,6 +842,7 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
610 sdata->vif.bss_conf.timestamp = bss->cbss.tsf; 842 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
611 sdata->vif.bss_conf.dtim_period = bss->dtim_period; 843 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
612 844
845 bss_info_changed |= BSS_CHANGED_BEACON_INT;
613 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 846 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
614 bss->cbss.capability, bss->has_erp_value, bss->erp_value); 847 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
615 848
@@ -634,18 +867,11 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
634 bss_info_changed |= BSS_CHANGED_BASIC_RATES; 867 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
635 ieee80211_bss_info_change_notify(sdata, bss_info_changed); 868 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
636 869
637 if (local->powersave) { 870 /* will be same as sdata */
638 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) && 871 if (local->ps_sdata) {
639 local->hw.conf.dynamic_ps_timeout > 0) { 872 mutex_lock(&local->iflist_mtx);
640 mod_timer(&local->dynamic_ps_timer, jiffies + 873 ieee80211_recalc_ps(local, -1);
641 msecs_to_jiffies( 874 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 } 875 }
650 876
651 netif_tx_start_all_queues(sdata->dev); 877 netif_tx_start_all_queues(sdata->dev);
@@ -664,7 +890,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", 890 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
665 sdata->dev->name, ifmgd->bssid); 891 sdata->dev->name, ifmgd->bssid);
666 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 892 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
667 ieee80211_sta_send_apinfo(sdata); 893 ieee80211_recalc_idle(local);
894 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
668 895
669 /* 896 /*
670 * Most likely AP is not in the range so remove the 897 * Most likely AP is not in the range so remove the
@@ -689,8 +916,6 @@ static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata)
689 916
690 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; 917 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
691 918
692 set_bit(IEEE80211_STA_REQ_DIRECT_PROBE, &ifmgd->request);
693
694 /* Direct probe is sent to broadcast address as some APs 919 /* Direct probe is sent to broadcast address as some APs
695 * will not answer to direct packet in unassociated state. 920 * will not answer to direct packet in unassociated state.
696 */ 921 */
@@ -714,7 +939,8 @@ static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
714 " timed out\n", 939 " timed out\n",
715 sdata->dev->name, ifmgd->bssid); 940 sdata->dev->name, ifmgd->bssid);
716 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 941 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
717 ieee80211_sta_send_apinfo(sdata); 942 ieee80211_recalc_idle(local);
943 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
718 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 944 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
719 sdata->local->hw.conf.channel->center_freq, 945 sdata->local->hw.conf.channel->center_freq,
720 ifmgd->ssid, ifmgd->ssid_len); 946 ifmgd->ssid, ifmgd->ssid_len);
@@ -817,9 +1043,16 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
817 1043
818 rcu_read_unlock(); 1044 rcu_read_unlock();
819 1045
1046 ieee80211_set_wmm_default(sdata);
1047
1048 ieee80211_recalc_idle(local);
1049
820 /* channel(_type) changes are handled by ieee80211_hw_config */ 1050 /* channel(_type) changes are handled by ieee80211_hw_config */
821 local->oper_channel_type = NL80211_CHAN_NO_HT; 1051 local->oper_channel_type = NL80211_CHAN_NO_HT;
822 1052
1053 /* on the next assoc, re-program HT parameters */
1054 sdata->ht_opmode_valid = false;
1055
823 local->power_constr_level = 0; 1056 local->power_constr_level = 0;
824 1057
825 del_timer_sync(&local->dynamic_ps_timer); 1058 del_timer_sync(&local->dynamic_ps_timer);
@@ -897,7 +1130,8 @@ static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
897 " timed out\n", 1130 " timed out\n",
898 sdata->dev->name, ifmgd->bssid); 1131 sdata->dev->name, ifmgd->bssid);
899 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1132 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
900 ieee80211_sta_send_apinfo(sdata); 1133 ieee80211_recalc_idle(local);
1134 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid);
901 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1135 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
902 sdata->local->hw.conf.channel->center_freq, 1136 sdata->local->hw.conf.channel->center_freq,
903 ifmgd->ssid, ifmgd->ssid_len); 1137 ifmgd->ssid, ifmgd->ssid_len);
@@ -917,6 +1151,7 @@ static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
917 printk(KERN_DEBUG "%s: mismatch in privacy configuration and " 1151 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
918 "mixed-cell disabled - abort association\n", sdata->dev->name); 1152 "mixed-cell disabled - abort association\n", sdata->dev->name);
919 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1153 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1154 ieee80211_recalc_idle(local);
920 return; 1155 return;
921 } 1156 }
922 1157
@@ -948,6 +1183,17 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
948 u.mgd.beacon_loss_work); 1183 u.mgd.beacon_loss_work);
949 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1184 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
950 1185
1186 /*
1187 * The driver has already reported this event and we have
1188 * already sent a probe request. Maybe the AP died and the
1189 * driver keeps reporting until we disassociate... We have
1190 * to ignore that because otherwise we would continually
1191 * reset the timer and never check whether we received a
1192 * probe response!
1193 */
1194 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1195 return;
1196
951#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1197#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
952 if (net_ratelimit()) { 1198 if (net_ratelimit()) {
953 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM " 1199 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
@@ -960,7 +1206,7 @@ void ieee80211_beacon_loss_work(struct work_struct *work)
960 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid, 1206 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
961 ifmgd->ssid_len, NULL, 0); 1207 ifmgd->ssid_len, NULL, 0);
962 1208
963 mod_timer(&ifmgd->timer, jiffies + IEEE80211_MONITORING_INTERVAL); 1209 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
964} 1210}
965 1211
966void ieee80211_beacon_loss(struct ieee80211_vif *vif) 1212void ieee80211_beacon_loss(struct ieee80211_vif *vif)
@@ -997,7 +1243,7 @@ static void ieee80211_associated(struct ieee80211_sub_if_data *sdata)
997 } 1243 }
998 1244
999 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) && 1245 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) &&
1000 time_after(jiffies, sta->last_rx + IEEE80211_MONITORING_INTERVAL)) { 1246 time_after(jiffies, sta->last_rx + IEEE80211_PROBE_WAIT)) {
1001 printk(KERN_DEBUG "%s: no probe response from AP %pM " 1247 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1002 "- disassociating\n", 1248 "- disassociating\n",
1003 sdata->dev->name, ifmgd->bssid); 1249 sdata->dev->name, ifmgd->bssid);
@@ -1055,6 +1301,7 @@ static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata)
1055 if (ifmgd->flags & IEEE80211_STA_EXT_SME) { 1301 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1056 /* Wait for SME to request association */ 1302 /* Wait for SME to request association */
1057 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1303 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1304 ieee80211_recalc_idle(sdata->local);
1058 } else 1305 } else
1059 ieee80211_associate(sdata); 1306 ieee80211_associate(sdata);
1060} 1307}
@@ -1187,7 +1434,7 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1187 1434
1188 ieee80211_set_disassoc(sdata, true, false, 0); 1435 ieee80211_set_disassoc(sdata, true, false, 0);
1189 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED; 1436 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1190 cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len); 1437 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1191} 1438}
1192 1439
1193 1440
@@ -1218,7 +1465,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1218 } 1465 }
1219 1466
1220 ieee80211_set_disassoc(sdata, false, false, reason_code); 1467 ieee80211_set_disassoc(sdata, false, false, reason_code);
1221 cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len); 1468 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
1222} 1469}
1223 1470
1224 1471
@@ -1287,6 +1534,12 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1287 * association next time. This works around some broken APs 1534 * association next time. This works around some broken APs
1288 * which do not correctly reject reassociation requests. */ 1535 * which do not correctly reject reassociation requests. */
1289 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET; 1536 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1537 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1538 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1539 /* Wait for SME to decide what to do next */
1540 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1541 ieee80211_recalc_idle(local);
1542 }
1290 return; 1543 return;
1291 } 1544 }
1292 1545
@@ -1340,8 +1593,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. 1593 * to between the sta_info_alloc() and sta_info_insert() above.
1341 */ 1594 */
1342 1595
1343 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP | 1596 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP);
1344 WLAN_STA_AUTHORIZED); 1597 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1598 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1345 1599
1346 rates = 0; 1600 rates = 0;
1347 basic_rates = 0; 1601 basic_rates = 0;
@@ -1421,6 +1675,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1421 if (elems.wmm_param) 1675 if (elems.wmm_param)
1422 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1676 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1423 elems.wmm_param_len); 1677 elems.wmm_param_len);
1678 else
1679 ieee80211_set_wmm_default(sdata);
1424 1680
1425 if (elems.ht_info_elem && elems.wmm_param && 1681 if (elems.ht_info_elem && elems.wmm_param &&
1426 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1682 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
@@ -1507,8 +1763,7 @@ 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); 1763 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1508 1764
1509 /* direct probe may be part of the association flow */ 1765 /* direct probe may be part of the association flow */
1510 if (test_and_clear_bit(IEEE80211_STA_REQ_DIRECT_PROBE, 1766 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) {
1511 &ifmgd->request)) {
1512 printk(KERN_DEBUG "%s direct probe responded\n", 1767 printk(KERN_DEBUG "%s direct probe responded\n",
1513 sdata->dev->name); 1768 sdata->dev->name);
1514 ieee80211_authenticate(sdata); 1769 ieee80211_authenticate(sdata);
@@ -1518,46 +1773,74 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1518 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1773 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1519} 1774}
1520 1775
1776/*
1777 * This is the canonical list of information elements we care about,
1778 * the filter code also gives us all changes to the Microsoft OUI
1779 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1780 *
1781 * We implement beacon filtering in software since that means we can
1782 * avoid processing the frame here and in cfg80211, and userspace
1783 * will not be able to tell whether the hardware supports it or not.
1784 *
1785 * XXX: This list needs to be dynamic -- userspace needs to be able to
1786 * add items it requires. It also needs to be able to tell us to
1787 * look out for other vendor IEs.
1788 */
1789static const u64 care_about_ies =
1790 (1ULL << WLAN_EID_COUNTRY) |
1791 (1ULL << WLAN_EID_ERP_INFO) |
1792 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1793 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1794 (1ULL << WLAN_EID_HT_CAPABILITY) |
1795 (1ULL << WLAN_EID_HT_INFORMATION);
1796
1521static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, 1797static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1522 struct ieee80211_mgmt *mgmt, 1798 struct ieee80211_mgmt *mgmt,
1523 size_t len, 1799 size_t len,
1524 struct ieee80211_rx_status *rx_status) 1800 struct ieee80211_rx_status *rx_status)
1525{ 1801{
1526 struct ieee80211_if_managed *ifmgd; 1802 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1527 size_t baselen; 1803 size_t baselen;
1528 struct ieee802_11_elems elems; 1804 struct ieee802_11_elems elems;
1529 struct ieee80211_local *local = sdata->local; 1805 struct ieee80211_local *local = sdata->local;
1530 u32 changed = 0; 1806 u32 changed = 0;
1531 bool erp_valid, directed_tim; 1807 bool erp_valid, directed_tim = false;
1532 u8 erp_value = 0; 1808 u8 erp_value = 0;
1809 u32 ncrc;
1533 1810
1534 /* Process beacon from the current BSS */ 1811 /* Process beacon from the current BSS */
1535 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1812 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1536 if (baselen > len) 1813 if (baselen > len)
1537 return; 1814 return;
1538 1815
1539 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); 1816 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; 1817 return;
1545 1818
1546 ifmgd = &sdata->u.mgd;
1547
1548 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || 1819 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1549 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1820 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
1550 return; 1821 return;
1551 1822
1552 if (rx_status->freq != local->hw.conf.channel->center_freq) 1823 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1824 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1825 len - baselen, &elems,
1826 care_about_ies, ncrc);
1827
1828 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1829 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1830 ifmgd->aid);
1831
1832 ncrc = crc32_be(ncrc, (void *)&directed_tim, sizeof(directed_tim));
1833
1834 if (ncrc == ifmgd->beacon_crc)
1553 return; 1835 return;
1836 ifmgd->beacon_crc = ncrc;
1837
1838 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1554 1839
1555 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1840 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1556 elems.wmm_param_len); 1841 elems.wmm_param_len);
1557 1842
1558 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { 1843 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1559 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
1560
1561 if (directed_tim) { 1844 if (directed_tim) {
1562 if (local->hw.conf.dynamic_ps_timeout > 0) { 1845 if (local->hw.conf.dynamic_ps_timeout > 0) {
1563 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 1846 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
@@ -1723,10 +2006,8 @@ static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata)
1723 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2006 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1724 struct ieee80211_local *local = sdata->local; 2007 struct ieee80211_local *local = sdata->local;
1725 2008
1726 if (local->ops->reset_tsf) { 2009 /* Reset own TSF to allow time synchronization work. */
1727 /* Reset own TSF to allow time synchronization work. */ 2010 drv_reset_tsf(local);
1728 local->ops->reset_tsf(local_to_hw(local));
1729 }
1730 2011
1731 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */ 2012 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */
1732 2013
@@ -1814,25 +2095,18 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata)
1814 return 0; 2095 return 0;
1815 } else { 2096 } else {
1816 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { 2097 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2098
1817 ifmgd->assoc_scan_tries++; 2099 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 2100
1828 if (ieee80211_start_scan(sdata, &local->int_scan_req)) 2101 ieee80211_request_internal_scan(sdata, ifmgd->ssid,
1829 ieee80211_scan_failed(local); 2102 ssid_len);
1830 2103
1831 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; 2104 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
1832 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); 2105 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request);
1833 } else { 2106 } else {
1834 ifmgd->assoc_scan_tries = 0; 2107 ifmgd->assoc_scan_tries = 0;
1835 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 2108 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
2109 ieee80211_recalc_idle(local);
1836 } 2110 }
1837 } 2111 }
1838 return -1; 2112 return -1;
@@ -1864,14 +2138,8 @@ static void ieee80211_sta_work(struct work_struct *work)
1864 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && 2138 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE &&
1865 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && 2139 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE &&
1866 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { 2140 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) {
1867 /* 2141 queue_delayed_work(local->hw.workqueue, &local->scan_work,
1868 * The call to ieee80211_start_scan can fail but ieee80211_request_scan 2142 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; 2143 return;
1876 } 2144 }
1877 2145
@@ -1882,6 +2150,8 @@ static void ieee80211_sta_work(struct work_struct *work)
1882 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request)) 2150 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
1883 return; 2151 return;
1884 2152
2153 ieee80211_recalc_idle(local);
2154
1885 switch (ifmgd->state) { 2155 switch (ifmgd->state) {
1886 case IEEE80211_STA_MLME_DISABLED: 2156 case IEEE80211_STA_MLME_DISABLED:
1887 break; 2157 break;
@@ -1930,6 +2200,7 @@ static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1930void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 2200void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1931{ 2201{
1932 struct ieee80211_if_managed *ifmgd; 2202 struct ieee80211_if_managed *ifmgd;
2203 u32 hw_flags;
1933 2204
1934 ifmgd = &sdata->u.mgd; 2205 ifmgd = &sdata->u.mgd;
1935 INIT_WORK(&ifmgd->work, ieee80211_sta_work); 2206 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
@@ -1949,6 +2220,13 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1949 IEEE80211_STA_AUTO_CHANNEL_SEL; 2220 IEEE80211_STA_AUTO_CHANNEL_SEL;
1950 if (sdata->local->hw.queues >= 4) 2221 if (sdata->local->hw.queues >= 4)
1951 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; 2222 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2223
2224 hw_flags = sdata->local->hw.flags;
2225
2226 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2227 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2228 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2229 }
1952} 2230}
1953 2231
1954/* configuration hooks */ 2232/* configuration hooks */
@@ -2032,12 +2310,8 @@ int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2032 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET; 2310 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET;
2033 } 2311 }
2034 2312
2035 if (netif_running(sdata->dev)) { 2313 if (netif_running(sdata->dev))
2036 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) { 2314 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
2037 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2038 "the low-level driver\n", sdata->dev->name);
2039 }
2040 }
2041 2315
2042 return ieee80211_sta_commit(sdata); 2316 return ieee80211_sta_commit(sdata);
2043} 2317}
@@ -2068,9 +2342,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", 2342 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2069 sdata->dev->name, reason); 2343 sdata->dev->name, reason);
2070 2344
2071 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2072 return -EINVAL;
2073
2074 ieee80211_set_disassoc(sdata, true, true, reason); 2345 ieee80211_set_disassoc(sdata, true, true, reason);
2075 return 0; 2346 return 0;
2076} 2347}
@@ -2082,9 +2353,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", 2353 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2083 sdata->dev->name, reason); 2354 sdata->dev->name, reason);
2084 2355
2085 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2086 return -EINVAL;
2087
2088 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) 2356 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2089 return -ENOLINK; 2357 return -ENOLINK;
2090 2358
@@ -2104,75 +2372,17 @@ void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2104 rcu_read_unlock(); 2372 rcu_read_unlock();
2105} 2373}
2106 2374
2107void ieee80211_dynamic_ps_disable_work(struct work_struct *work) 2375int ieee80211_max_network_latency(struct notifier_block *nb,
2108{ 2376 unsigned long data, void *dummy)
2109 struct ieee80211_local *local =
2110 container_of(work, struct ieee80211_local,
2111 dynamic_ps_disable_work);
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{ 2377{
2378 s32 latency_usec = (s32) data;
2124 struct ieee80211_local *local = 2379 struct ieee80211_local *local =
2125 container_of(work, struct ieee80211_local, 2380 container_of(nb, struct ieee80211_local,
2126 dynamic_ps_enable_work); 2381 network_latency_notifier);
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 2382
2144 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work); 2383 mutex_lock(&local->iflist_mtx);
2145} 2384 ieee80211_recalc_ps(local, latency_usec);
2146 2385 mutex_unlock(&local->iflist_mtx);
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
2155 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2156 return;
2157
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 2386
2166 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); 2387 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} 2388}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 81985d27cbda..9d3d89abbb57 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -2,6 +2,7 @@
2#include <net/rtnetlink.h> 2#include <net/rtnetlink.h>
3 3
4#include "ieee80211_i.h" 4#include "ieee80211_i.h"
5#include "driver-ops.h"
5#include "led.h" 6#include "led.h"
6 7
7int __ieee80211_suspend(struct ieee80211_hw *hw) 8int __ieee80211_suspend(struct ieee80211_hw *hw)
@@ -43,8 +44,8 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
43 struct ieee80211_sub_if_data, 44 struct ieee80211_sub_if_data,
44 u.ap); 45 u.ap);
45 46
46 local->ops->sta_notify(hw, &sdata->vif, 47 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
47 STA_NOTIFY_REMOVE, &sta->sta); 48 &sta->sta);
48 } 49 }
49 spin_unlock_irqrestore(&local->sta_lock, flags); 50 spin_unlock_irqrestore(&local->sta_lock, flags);
50 } 51 }
@@ -57,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
57 conf.vif = &sdata->vif; 58 conf.vif = &sdata->vif;
58 conf.type = sdata->vif.type; 59 conf.type = sdata->vif.type;
59 conf.mac_addr = sdata->dev->dev_addr; 60 conf.mac_addr = sdata->dev->dev_addr;
60 local->ops->remove_interface(hw, &conf); 61 drv_remove_interface(local, &conf);
61 } 62 }
62 } 63 }
63 64
@@ -67,124 +68,13 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
67 /* stop hardware */ 68 /* stop hardware */
68 if (local->open_count) { 69 if (local->open_count) {
69 ieee80211_led_radio(local, false); 70 ieee80211_led_radio(local, false);
70 local->ops->stop(hw); 71 drv_stop(local);
71 } 72 }
72 return 0; 73 return 0;
73} 74}
74 75
75int __ieee80211_resume(struct ieee80211_hw *hw) 76/*
76{ 77 * __ieee80211_resume() is a static inline which just calls
77 struct ieee80211_local *local = hw_to_local(hw); 78 * ieee80211_reconfig(), which is also needed for hardware
78 struct ieee80211_sub_if_data *sdata; 79 * hang/firmware failure/etc. recovery.
79 struct ieee80211_if_init_conf conf; 80 */
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 }
90
91 /* add interfaces */
92 list_for_each_entry(sdata, &local->interfaces, list) {
93 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
94 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
95 netif_running(sdata->dev)) {
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)
108 sdata = container_of(sdata->bss,
109 struct ieee80211_sub_if_data,
110 u.ap);
111
112 local->ops->sta_notify(hw, &sdata->vif,
113 STA_NOTIFY_ADD, &sta->sta);
114 }
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
122 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
123 list_for_each_entry_rcu(sta, &local->sta_list, list) {
124 clear_sta_flags(sta, WLAN_STA_SUSPEND);
125 }
126 }
127
128 rcu_read_unlock();
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) {
148 u32 changed = ~0;
149 if (!netif_running(sdata->dev))
150 continue;
151 switch (sdata->vif.type) {
152 case NL80211_IFTYPE_STATION:
153 /* disable beacon change bits */
154 changed &= ~IEEE80211_IFCC_BEACON;
155 /* fall through */
156 case NL80211_IFTYPE_ADHOC:
157 case NL80211_IFTYPE_AP:
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;
173 case NL80211_IFTYPE_WDS:
174 break;
175 case NL80211_IFTYPE_AP_VLAN:
176 case NL80211_IFTYPE_MONITOR:
177 /* ignore virtual */
178 break;
179 case NL80211_IFTYPE_UNSPECIFIED:
180 case __NL80211_IFTYPE_AFTER_LAST:
181 WARN_ON(1);
182 break;
183 }
184 }
185
186 ieee80211_wake_queues_by_reason(hw,
187 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
188
189 return 0;
190}
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index d9233ec50610..0a11515341ba 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
@@ -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..f962bd1b16e2 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);
@@ -792,9 +803,7 @@ static int ap_sta_ps_end(struct sta_info *sta)
792 atomic_dec(&sdata->bss->num_sta_ps); 803 atomic_dec(&sdata->bss->num_sta_ps);
793 804
794 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL); 805 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL);
795 if (local->ops->sta_notify) 806 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 807
799 if (!skb_queue_empty(&sta->ps_tx_buf)) 808 if (!skb_queue_empty(&sta->ps_tx_buf))
800 sta_info_clear_tim_bit(sta); 809 sta_info_clear_tim_bit(sta);
@@ -1212,17 +1221,27 @@ ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
1212 /* Drop unencrypted frames if key is set. */ 1221 /* Drop unencrypted frames if key is set. */
1213 if (unlikely(!ieee80211_has_protected(fc) && 1222 if (unlikely(!ieee80211_has_protected(fc) &&
1214 !ieee80211_is_nullfunc(fc) && 1223 !ieee80211_is_nullfunc(fc) &&
1215 (!ieee80211_is_mgmt(fc) || 1224 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))) 1225 (rx->key || rx->sdata->drop_unencrypted)))
1225 return -EACCES; 1226 return -EACCES;
1227 if (rx->sta && test_sta_flags(rx->sta, WLAN_STA_MFP)) {
1228 if (unlikely(ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
1229 rx->key))
1230 return -EACCES;
1231 /* BIP does not use Protected field, so need to check MMIE */
1232 if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb)
1233 && ieee80211_get_mmie_keyidx(rx->skb) < 0 &&
1234 rx->key))
1235 return -EACCES;
1236 /*
1237 * When using MFP, Action frames are not allowed prior to
1238 * having configured keys.
1239 */
1240 if (unlikely(ieee80211_is_action(fc) && !rx->key &&
1241 ieee80211_is_robust_mgmt_frame(
1242 (struct ieee80211_hdr *) rx->skb->data)))
1243 return -EACCES;
1244 }
1226 1245
1227 return 0; 1246 return 0;
1228} 1247}
@@ -1932,7 +1951,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1932 !ieee80211_is_auth(hdr->frame_control)) 1951 !ieee80211_is_auth(hdr->frame_control))
1933 goto ignore; 1952 goto ignore;
1934 1953
1935 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr); 1954 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL);
1936 ignore: 1955 ignore:
1937 dev_kfree_skb(rx->skb); 1956 dev_kfree_skb(rx->skb);
1938 rx->skb = NULL; 1957 rx->skb = NULL;
@@ -2287,6 +2306,43 @@ static inline u16 seq_sub(u16 sq1, u16 sq2)
2287} 2306}
2288 2307
2289 2308
2309static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
2310 struct tid_ampdu_rx *tid_agg_rx,
2311 int index)
2312{
2313 struct ieee80211_supported_band *sband;
2314 struct ieee80211_rate *rate;
2315 struct ieee80211_rx_status status;
2316
2317 if (!tid_agg_rx->reorder_buf[index])
2318 goto no_frame;
2319
2320 /* release the reordered frames to stack */
2321 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, sizeof(status));
2322 sband = hw->wiphy->bands[status.band];
2323 if (status.flag & RX_FLAG_HT)
2324 rate = sband->bitrates; /* TODO: HT rates */
2325 else
2326 rate = &sband->bitrates[status.rate_idx];
2327 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
2328 &status, rate);
2329 tid_agg_rx->stored_mpdu_num--;
2330 tid_agg_rx->reorder_buf[index] = NULL;
2331
2332no_frame:
2333 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
2334}
2335
2336
2337/*
2338 * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
2339 * the skb was added to the buffer longer than this time ago, the earlier
2340 * frames that have not yet been received are assumed to be lost and the skb
2341 * can be released for processing. This may also release other skb's from the
2342 * reorder buffer if there are no additional gaps between the frames.
2343 */
2344#define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
2345
2290/* 2346/*
2291 * As it function blongs to Rx path it must be called with 2347 * As it function blongs to Rx path it must be called with
2292 * the proper rcu_read_lock protection for its flow. 2348 * the proper rcu_read_lock protection for its flow.
@@ -2298,12 +2354,8 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2298 u16 mpdu_seq_num, 2354 u16 mpdu_seq_num,
2299 int bar_req) 2355 int bar_req)
2300{ 2356{
2301 struct ieee80211_local *local = hw_to_local(hw);
2302 struct ieee80211_rx_status status;
2303 u16 head_seq_num, buf_size; 2357 u16 head_seq_num, buf_size;
2304 int index; 2358 int index;
2305 struct ieee80211_supported_band *sband;
2306 struct ieee80211_rate *rate;
2307 2359
2308 buf_size = tid_agg_rx->buf_size; 2360 buf_size = tid_agg_rx->buf_size;
2309 head_seq_num = tid_agg_rx->head_seq_num; 2361 head_seq_num = tid_agg_rx->head_seq_num;
@@ -2328,28 +2380,8 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2328 index = seq_sub(tid_agg_rx->head_seq_num, 2380 index = seq_sub(tid_agg_rx->head_seq_num,
2329 tid_agg_rx->ssn) 2381 tid_agg_rx->ssn)
2330 % tid_agg_rx->buf_size; 2382 % tid_agg_rx->buf_size;
2331 2383 ieee80211_release_reorder_frame(hw, tid_agg_rx,
2332 if (tid_agg_rx->reorder_buf[index]) { 2384 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 } 2385 }
2354 if (bar_req) 2386 if (bar_req)
2355 return 1; 2387 return 1;
@@ -2376,26 +2408,50 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2376 2408
2377 /* put the frame in the reordering buffer */ 2409 /* put the frame in the reordering buffer */
2378 tid_agg_rx->reorder_buf[index] = skb; 2410 tid_agg_rx->reorder_buf[index] = skb;
2411 tid_agg_rx->reorder_time[index] = jiffies;
2379 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus, 2412 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus,
2380 sizeof(*rxstatus)); 2413 sizeof(*rxstatus));
2381 tid_agg_rx->stored_mpdu_num++; 2414 tid_agg_rx->stored_mpdu_num++;
2382 /* release the buffer until next missing frame */ 2415 /* release the buffer until next missing frame */
2383 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) 2416 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
2384 % tid_agg_rx->buf_size; 2417 % tid_agg_rx->buf_size;
2385 while (tid_agg_rx->reorder_buf[index]) { 2418 if (!tid_agg_rx->reorder_buf[index] &&
2386 /* release the reordered frame back to stack */ 2419 tid_agg_rx->stored_mpdu_num > 1) {
2387 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, 2420 /*
2388 sizeof(status)); 2421 * No buffers ready to be released, but check whether any
2389 sband = local->hw.wiphy->bands[status.band]; 2422 * frames in the reorder buffer have timed out.
2390 if (status.flag & RX_FLAG_HT) 2423 */
2391 rate = sband->bitrates; /* TODO: HT rates */ 2424 int j;
2392 else 2425 int skipped = 1;
2393 rate = &sband->bitrates[status.rate_idx]; 2426 for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
2394 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2427 j = (j + 1) % tid_agg_rx->buf_size) {
2395 &status, rate); 2428 if (tid_agg_rx->reorder_buf[j] == NULL) {
2396 tid_agg_rx->stored_mpdu_num--; 2429 skipped++;
2397 tid_agg_rx->reorder_buf[index] = NULL; 2430 continue;
2398 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 2431 }
2432 if (!time_after(jiffies, tid_agg_rx->reorder_time[j] +
2433 HZ / 10))
2434 break;
2435
2436#ifdef CONFIG_MAC80211_HT_DEBUG
2437 if (net_ratelimit())
2438 printk(KERN_DEBUG "%s: release an RX reorder "
2439 "frame due to timeout on earlier "
2440 "frames\n",
2441 wiphy_name(hw->wiphy));
2442#endif
2443 ieee80211_release_reorder_frame(hw, tid_agg_rx, j);
2444
2445 /*
2446 * Increment the head seq# also for the skipped slots.
2447 */
2448 tid_agg_rx->head_seq_num =
2449 (tid_agg_rx->head_seq_num + skipped) &
2450 SEQ_MASK;
2451 skipped = 0;
2452 }
2453 } else while (tid_agg_rx->reorder_buf[index]) {
2454 ieee80211_release_reorder_frame(hw, tid_agg_rx, index);
2399 index = seq_sub(tid_agg_rx->head_seq_num, 2455 index = seq_sub(tid_agg_rx->head_seq_num,
2400 tid_agg_rx->ssn) % tid_agg_rx->buf_size; 2456 tid_agg_rx->ssn) % tid_agg_rx->buf_size;
2401 } 2457 }
@@ -2517,6 +2573,18 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2517 return; 2573 return;
2518 } 2574 }
2519 2575
2576 /*
2577 * In theory, the block ack reordering should happen after duplicate
2578 * removal (ieee80211_rx_h_check(), which is an RX handler). As such,
2579 * the call to ieee80211_rx_reorder_ampdu() should really be moved to
2580 * happen as a new RX handler between ieee80211_rx_h_check and
2581 * ieee80211_rx_h_decrypt. This cleanup may eventually happen, but for
2582 * the time being, the call can be here since RX reorder buf processing
2583 * will implicitly skip duplicates. We could, in theory at least,
2584 * process frames that ieee80211_rx_h_passive_scan would drop (e.g.,
2585 * frames from other than operational channel), but that should not
2586 * happen in normal networks.
2587 */
2520 if (!ieee80211_rx_reorder_ampdu(local, skb, status)) 2588 if (!ieee80211_rx_reorder_ampdu(local, skb, status))
2521 __ieee80211_rx_handle_packet(hw, skb, status, rate); 2589 __ieee80211_rx_handle_packet(hw, skb, status, rate);
2522 2590
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 3bf9839f5916..e65d74ba404b 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,35 @@ 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 606
431 if (local->scan_req && local->scan_req != req) 607 mutex_lock(&sdata->local->scan_mtx);
432 return -EBUSY; 608 res = __ieee80211_start_scan(sdata, req);
433 609 mutex_unlock(&sdata->local->scan_mtx);
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 610
453 if (local->sw_scanning || local->hw_scanning) { 611 return res;
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
489 mutex_lock(&local->iflist_mtx);
490 list_for_each_entry(sdata, &local->interfaces, list) {
491 if (!netif_running(sdata->dev))
492 continue;
493
494 /* disable beaconing */
495 if (sdata->vif.type == NL80211_IFTYPE_AP ||
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
501 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
502 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) {
503 netif_tx_stop_all_queues(sdata->dev);
504 ieee80211_scan_ps_enable(sdata);
505 }
506 } else
507 netif_tx_stop_all_queues(sdata->dev);
508 }
509 mutex_unlock(&local->iflist_mtx);
510
511 local->scan_state = SCAN_SET_CHANNEL;
512 local->scan_channel_idx = 0;
513 local->scan_sdata = scan_sdata;
514 local->scan_req = req;
515
516 netif_addr_lock_bh(local->mdev);
517 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
518 local->ops->configure_filter(local_to_hw(local),
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
525 /* TODO: start scan as soon as all nullfunc frames are ACKed */
526 queue_delayed_work(local->hw.workqueue, &local->scan_work,
527 IEEE80211_CHANNEL_TIME);
528
529 return 0;
530} 612}
531 613
532 614int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
533int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 615 const u8 *ssid, u8 ssid_len)
534 struct cfg80211_scan_request *req)
535{ 616{
536 struct ieee80211_local *local = sdata->local; 617 struct ieee80211_local *local = sdata->local;
537 struct ieee80211_if_managed *ifmgd; 618 int ret = -EBUSY;
538 619
539 if (!req) 620 mutex_lock(&local->scan_mtx);
540 return -EINVAL;
541 621
542 if (local->scan_req && local->scan_req != req) 622 /* busy scanning */
543 return -EBUSY; 623 if (local->scan_req)
624 goto unlock;
544 625
545 local->scan_req = req; 626 memcpy(local->int_scan_req.ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
627 local->int_scan_req.ssids[0].ssid_len = ssid_len;
546 628
547 if (sdata->vif.type != NL80211_IFTYPE_STATION) 629 ret = __ieee80211_start_scan(sdata, &sdata->local->int_scan_req);
548 return ieee80211_start_scan(sdata, req); 630 unlock:
549 631 mutex_unlock(&local->scan_mtx);
550 /* 632 return ret;
551 * STA has a state machine that might need to defer scanning
552 * while it's trying to associate/authenticate, therefore we
553 * queue it up to the state machine in that case.
554 */
555
556 if (local->sw_scanning || local->hw_scanning) {
557 if (local->scan_sdata == sdata)
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} 633}
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index 5f7a2624ed74..48bf78e7fa7a 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"
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index c5f14e6bbde2..a98ea273a155 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"
@@ -346,8 +347,7 @@ int sta_info_insert(struct sta_info *sta)
346 struct ieee80211_sub_if_data, 347 struct ieee80211_sub_if_data,
347 u.ap); 348 u.ap);
348 349
349 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 350 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD, &sta->sta);
350 STA_NOTIFY_ADD, &sta->sta);
351 } 351 }
352 352
353#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 353#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -405,8 +405,7 @@ static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
405 405
406 if (sta->local->ops->set_tim) { 406 if (sta->local->ops->set_tim) {
407 sta->local->tim_in_locked_section = true; 407 sta->local->tim_in_locked_section = true;
408 sta->local->ops->set_tim(local_to_hw(sta->local), 408 drv_set_tim(sta->local, &sta->sta, true);
409 &sta->sta, true);
410 sta->local->tim_in_locked_section = false; 409 sta->local->tim_in_locked_section = false;
411 } 410 }
412} 411}
@@ -431,8 +430,7 @@ static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
431 430
432 if (sta->local->ops->set_tim) { 431 if (sta->local->ops->set_tim) {
433 sta->local->tim_in_locked_section = true; 432 sta->local->tim_in_locked_section = true;
434 sta->local->ops->set_tim(local_to_hw(sta->local), 433 drv_set_tim(sta->local, &sta->sta, false);
435 &sta->sta, false);
436 sta->local->tim_in_locked_section = false; 434 sta->local->tim_in_locked_section = false;
437 } 435 }
438} 436}
@@ -482,8 +480,8 @@ static void __sta_info_unlink(struct sta_info **sta)
482 struct ieee80211_sub_if_data, 480 struct ieee80211_sub_if_data,
483 u.ap); 481 u.ap);
484 482
485 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 483 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_REMOVE,
486 STA_NOTIFY_REMOVE, &(*sta)->sta); 484 &(*sta)->sta);
487 } 485 }
488 486
489 if (ieee80211_vif_is_mesh(&sdata->vif)) { 487 if (ieee80211_vif_is_mesh(&sdata->vif)) {
@@ -543,9 +541,8 @@ void sta_info_unlink(struct sta_info **sta)
543 spin_unlock_irqrestore(&local->sta_lock, flags); 541 spin_unlock_irqrestore(&local->sta_lock, flags);
544} 542}
545 543
546static inline int sta_info_buffer_expired(struct ieee80211_local *local, 544static int sta_info_buffer_expired(struct sta_info *sta,
547 struct sta_info *sta, 545 struct sk_buff *skb)
548 struct sk_buff *skb)
549{ 546{
550 struct ieee80211_tx_info *info; 547 struct ieee80211_tx_info *info;
551 int timeout; 548 int timeout;
@@ -556,8 +553,9 @@ static inline int sta_info_buffer_expired(struct ieee80211_local *local,
556 info = IEEE80211_SKB_CB(skb); 553 info = IEEE80211_SKB_CB(skb);
557 554
558 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */ 555 /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
559 timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 / 556 timeout = (sta->listen_interval *
560 15625) * HZ; 557 sta->sdata->vif.bss_conf.beacon_int *
558 32 / 15625) * HZ;
561 if (timeout < STA_TX_BUFFER_EXPIRE) 559 if (timeout < STA_TX_BUFFER_EXPIRE)
562 timeout = STA_TX_BUFFER_EXPIRE; 560 timeout = STA_TX_BUFFER_EXPIRE;
563 return time_after(jiffies, info->control.jiffies + timeout); 561 return time_after(jiffies, info->control.jiffies + timeout);
@@ -577,7 +575,7 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
577 for (;;) { 575 for (;;) {
578 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); 576 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
579 skb = skb_peek(&sta->ps_tx_buf); 577 skb = skb_peek(&sta->ps_tx_buf);
580 if (sta_info_buffer_expired(local, sta, skb)) 578 if (sta_info_buffer_expired(sta, skb))
581 skb = __skb_dequeue(&sta->ps_tx_buf); 579 skb = __skb_dequeue(&sta->ps_tx_buf);
582 else 580 else
583 skb = NULL; 581 skb = NULL;
@@ -686,41 +684,10 @@ static void sta_info_debugfs_add_work(struct work_struct *work)
686} 684}
687#endif 685#endif
688 686
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) 687void sta_info_init(struct ieee80211_local *local)
719{ 688{
720 spin_lock_init(&local->sta_lock); 689 spin_lock_init(&local->sta_lock);
721 INIT_LIST_HEAD(&local->sta_list); 690 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 691
725 setup_timer(&local->sta_cleanup, sta_info_cleanup, 692 setup_timer(&local->sta_cleanup, sta_info_cleanup,
726 (unsigned long)local); 693 (unsigned long)local);
@@ -741,7 +708,6 @@ int sta_info_start(struct ieee80211_local *local)
741void sta_info_stop(struct ieee80211_local *local) 708void sta_info_stop(struct ieee80211_local *local)
742{ 709{
743 del_timer(&local->sta_cleanup); 710 del_timer(&local->sta_cleanup);
744 cancel_work_sync(&local->sta_flush_work);
745#ifdef CONFIG_MAC80211_DEBUGFS 711#ifdef CONFIG_MAC80211_DEBUGFS
746 /* 712 /*
747 * Make sure the debugfs adding work isn't pending after this 713 * Make sure the debugfs adding work isn't pending after this
@@ -752,10 +718,7 @@ void sta_info_stop(struct ieee80211_local *local)
752 cancel_work_sync(&local->sta_debugfs_add); 718 cancel_work_sync(&local->sta_debugfs_add);
753#endif 719#endif
754 720
755 rtnl_lock();
756 sta_info_flush(local, NULL); 721 sta_info_flush(local, NULL);
757 __ieee80211_run_pending_flush(local);
758 rtnl_unlock();
759} 722}
760 723
761/** 724/**
@@ -767,7 +730,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 730 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
768 */ 731 */
769int sta_info_flush(struct ieee80211_local *local, 732int sta_info_flush(struct ieee80211_local *local,
770 struct ieee80211_sub_if_data *sdata) 733 struct ieee80211_sub_if_data *sdata)
771{ 734{
772 struct sta_info *sta, *tmp; 735 struct sta_info *sta, *tmp;
773 LIST_HEAD(tmp_list); 736 LIST_HEAD(tmp_list);
@@ -775,7 +738,6 @@ int sta_info_flush(struct ieee80211_local *local,
775 unsigned long flags; 738 unsigned long flags;
776 739
777 might_sleep(); 740 might_sleep();
778 ASSERT_RTNL();
779 741
780 spin_lock_irqsave(&local->sta_lock, flags); 742 spin_lock_irqsave(&local->sta_lock, flags);
781 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 743 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
@@ -795,39 +757,6 @@ int sta_info_flush(struct ieee80211_local *local,
795 return ret; 757 return ret;
796} 758}
797 759
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, 760void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
832 unsigned long exp_time) 761 unsigned long exp_time)
833{ 762{
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 5534d489f506..164b16cbe0a5 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;
@@ -442,8 +444,7 @@ void sta_info_init(struct ieee80211_local *local);
442int sta_info_start(struct ieee80211_local *local); 444int sta_info_start(struct ieee80211_local *local);
443void sta_info_stop(struct ieee80211_local *local); 445void sta_info_stop(struct ieee80211_local *local);
444int sta_info_flush(struct ieee80211_local *local, 446int sta_info_flush(struct ieee80211_local *local,
445 struct ieee80211_sub_if_data *sdata); 447 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, 448void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
448 unsigned long exp_time); 449 unsigned long exp_time);
449 450
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..8f68bf9746d0 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"
@@ -409,8 +410,24 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
409 sta->sta.addr); 410 sta->sta.addr);
410 } 411 }
411#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 412#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
412 clear_sta_flags(sta, WLAN_STA_PSPOLL); 413 if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
414 /*
415 * The sleeping station with pending data is now snoozing.
416 * It queried us for its buffered frames and will go back
417 * to deep sleep once it got everything.
418 *
419 * inform the driver, in case the hardware does powersave
420 * frame filtering and keeps a station blacklist on its own
421 * (e.g: p54), so that frames can be delivered unimpeded.
422 *
423 * Note: It should be save to disable the filter now.
424 * As, it is really unlikely that we still have any pending
425 * frame for this station in the hw's buffers/fifos left,
426 * that is not rejected with a unsuccessful tx_status yet.
427 */
413 428
429 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
430 }
414 return TX_CONTINUE; 431 return TX_CONTINUE;
415} 432}
416 433
@@ -429,7 +446,7 @@ ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
429static ieee80211_tx_result debug_noinline 446static ieee80211_tx_result debug_noinline
430ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) 447ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
431{ 448{
432 struct ieee80211_key *key; 449 struct ieee80211_key *key = NULL;
433 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 450 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 451 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
435 452
@@ -500,7 +517,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
500 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 517 sband = tx->local->hw.wiphy->bands[tx->channel->band];
501 518
502 len = min_t(int, tx->skb->len + FCS_LEN, 519 len = min_t(int, tx->skb->len + FCS_LEN,
503 tx->local->fragmentation_threshold); 520 tx->local->hw.wiphy->frag_threshold);
504 521
505 /* set up the tx rate control struct we give the RC algo */ 522 /* set up the tx rate control struct we give the RC algo */
506 txrc.hw = local_to_hw(tx->local); 523 txrc.hw = local_to_hw(tx->local);
@@ -511,8 +528,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
511 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx; 528 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
512 529
513 /* set up RTS protection if desired */ 530 /* set up RTS protection if desired */
514 if (tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD && 531 if (len > tx->local->hw.wiphy->rts_threshold) {
515 len > tx->local->rts_threshold) {
516 txrc.rts = rts = true; 532 txrc.rts = rts = true;
517 } 533 }
518 534
@@ -542,6 +558,10 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
542 if (unlikely(!info->control.rates[0].count)) 558 if (unlikely(!info->control.rates[0].count))
543 info->control.rates[0].count = 1; 559 info->control.rates[0].count = 1;
544 560
561 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
562 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
563 info->control.rates[0].count = 1;
564
545 if (is_multicast_ether_addr(hdr->addr1)) { 565 if (is_multicast_ether_addr(hdr->addr1)) {
546 /* 566 /*
547 * XXX: verify the rate is in the basic rateset 567 * XXX: verify the rate is in the basic rateset
@@ -754,7 +774,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
754 struct sk_buff *skb = tx->skb; 774 struct sk_buff *skb = tx->skb;
755 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 775 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
756 struct ieee80211_hdr *hdr = (void *)skb->data; 776 struct ieee80211_hdr *hdr = (void *)skb->data;
757 int frag_threshold = tx->local->fragmentation_threshold; 777 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
758 int hdrlen; 778 int hdrlen;
759 int fragnum; 779 int fragnum;
760 780
@@ -1067,12 +1087,15 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1067 info->flags |= IEEE80211_TX_CTL_NO_ACK; 1087 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1068 } else { 1088 } else {
1069 tx->flags |= IEEE80211_TX_UNICAST; 1089 tx->flags |= IEEE80211_TX_UNICAST;
1070 info->flags &= ~IEEE80211_TX_CTL_NO_ACK; 1090 if (unlikely(local->wifi_wme_noack_test))
1091 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1092 else
1093 info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
1071 } 1094 }
1072 1095
1073 if (tx->flags & IEEE80211_TX_FRAGMENTED) { 1096 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
1074 if ((tx->flags & IEEE80211_TX_UNICAST) && 1097 if ((tx->flags & IEEE80211_TX_UNICAST) &&
1075 skb->len + FCS_LEN > local->fragmentation_threshold && 1098 skb->len + FCS_LEN > local->hw.wiphy->frag_threshold &&
1076 !(info->flags & IEEE80211_TX_CTL_AMPDU)) 1099 !(info->flags & IEEE80211_TX_CTL_AMPDU))
1077 tx->flags |= IEEE80211_TX_FRAGMENTED; 1100 tx->flags |= IEEE80211_TX_FRAGMENTED;
1078 else 1101 else
@@ -1147,7 +1170,7 @@ static int __ieee80211_tx(struct ieee80211_local *local,
1147 1170
1148 next = skb->next; 1171 next = skb->next;
1149 len = skb->len; 1172 len = skb->len;
1150 ret = local->ops->tx(local_to_hw(local), skb); 1173 ret = drv_tx(local, skb);
1151 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) { 1174 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) {
1152 dev_kfree_skb(skb); 1175 dev_kfree_skb(skb);
1153 ret = NETDEV_TX_OK; 1176 ret = NETDEV_TX_OK;
@@ -2086,18 +2109,18 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2086 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 2109 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2087 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2110 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2088 struct ieee80211_hdr *hdr; 2111 struct ieee80211_hdr *hdr;
2112 struct sk_buff *presp = rcu_dereference(ifibss->presp);
2089 2113
2090 if (!ifibss->probe_resp) 2114 if (!presp)
2091 goto out; 2115 goto out;
2092 2116
2093 skb = skb_copy(ifibss->probe_resp, GFP_ATOMIC); 2117 skb = skb_copy(presp, GFP_ATOMIC);
2094 if (!skb) 2118 if (!skb)
2095 goto out; 2119 goto out;
2096 2120
2097 hdr = (struct ieee80211_hdr *) skb->data; 2121 hdr = (struct ieee80211_hdr *) skb->data;
2098 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2122 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2099 IEEE80211_STYPE_BEACON); 2123 IEEE80211_STYPE_BEACON);
2100
2101 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 2124 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2102 struct ieee80211_mgmt *mgmt; 2125 struct ieee80211_mgmt *mgmt;
2103 u8 *pos; 2126 u8 *pos;
@@ -2117,7 +2140,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2117 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 2140 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
2118 /* BSSID is left zeroed, wildcard value */ 2141 /* BSSID is left zeroed, wildcard value */
2119 mgmt->u.beacon.beacon_int = 2142 mgmt->u.beacon.beacon_int =
2120 cpu_to_le16(local->hw.conf.beacon_int); 2143 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
2121 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */ 2144 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
2122 2145
2123 pos = skb_put(skb, 2); 2146 pos = skb_put(skb, 2);
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index fdf432f14554..0689a8fbd1e6 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -20,14 +20,17 @@
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;
@@ -536,8 +539,16 @@ EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
536void ieee802_11_parse_elems(u8 *start, size_t len, 539void ieee802_11_parse_elems(u8 *start, size_t len,
537 struct ieee802_11_elems *elems) 540 struct ieee802_11_elems *elems)
538{ 541{
542 ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
543}
544
545u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
546 struct ieee802_11_elems *elems,
547 u64 filter, u32 crc)
548{
539 size_t left = len; 549 size_t left = len;
540 u8 *pos = start; 550 u8 *pos = start;
551 bool calc_crc = filter != 0;
541 552
542 memset(elems, 0, sizeof(*elems)); 553 memset(elems, 0, sizeof(*elems));
543 elems->ie_start = start; 554 elems->ie_start = start;
@@ -551,7 +562,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
551 left -= 2; 562 left -= 2;
552 563
553 if (elen > left) 564 if (elen > left)
554 return; 565 break;
566
567 if (calc_crc && id < 64 && (filter & BIT(id)))
568 crc = crc32_be(crc, pos - 2, elen + 2);
555 569
556 switch (id) { 570 switch (id) {
557 case WLAN_EID_SSID: 571 case WLAN_EID_SSID:
@@ -575,8 +589,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
575 elems->cf_params_len = elen; 589 elems->cf_params_len = elen;
576 break; 590 break;
577 case WLAN_EID_TIM: 591 case WLAN_EID_TIM:
578 elems->tim = pos; 592 if (elen >= sizeof(struct ieee80211_tim_ie)) {
579 elems->tim_len = elen; 593 elems->tim = (void *)pos;
594 elems->tim_len = elen;
595 }
580 break; 596 break;
581 case WLAN_EID_IBSS_PARAMS: 597 case WLAN_EID_IBSS_PARAMS:
582 elems->ibss_params = pos; 598 elems->ibss_params = pos;
@@ -586,15 +602,20 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
586 elems->challenge = pos; 602 elems->challenge = pos;
587 elems->challenge_len = elen; 603 elems->challenge_len = elen;
588 break; 604 break;
589 case WLAN_EID_WPA: 605 case WLAN_EID_VENDOR_SPECIFIC:
590 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && 606 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
591 pos[2] == 0xf2) { 607 pos[2] == 0xf2) {
592 /* Microsoft OUI (00:50:F2) */ 608 /* Microsoft OUI (00:50:F2) */
609
610 if (calc_crc)
611 crc = crc32_be(crc, pos - 2, elen + 2);
612
593 if (pos[3] == 1) { 613 if (pos[3] == 1) {
594 /* OUI Type 1 - WPA IE */ 614 /* OUI Type 1 - WPA IE */
595 elems->wpa = pos; 615 elems->wpa = pos;
596 elems->wpa_len = elen; 616 elems->wpa_len = elen;
597 } else if (elen >= 5 && pos[3] == 2) { 617 } else if (elen >= 5 && pos[3] == 2) {
618 /* OUI Type 2 - WMM IE */
598 if (pos[4] == 0) { 619 if (pos[4] == 0) {
599 elems->wmm_info = pos; 620 elems->wmm_info = pos;
600 elems->wmm_info_len = elen; 621 elems->wmm_info_len = elen;
@@ -679,32 +700,70 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
679 left -= elen; 700 left -= elen;
680 pos += elen; 701 pos += elen;
681 } 702 }
703
704 return crc;
682} 705}
683 706
684void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) 707void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
685{ 708{
686 struct ieee80211_local *local = sdata->local; 709 struct ieee80211_local *local = sdata->local;
687 struct ieee80211_tx_queue_params qparam; 710 struct ieee80211_tx_queue_params qparam;
688 int i; 711 int queue;
712 bool use_11b;
713 int aCWmin, aCWmax;
689 714
690 if (!local->ops->conf_tx) 715 if (!local->ops->conf_tx)
691 return; 716 return;
692 717
693 memset(&qparam, 0, sizeof(qparam)); 718 memset(&qparam, 0, sizeof(qparam));
694 719
695 qparam.aifs = 2; 720 use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
696 721 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
697 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
698 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
699 qparam.cw_min = 31;
700 else
701 qparam.cw_min = 15;
702 722
703 qparam.cw_max = 1023; 723 for (queue = 0; queue < local_to_hw(local)->queues; queue++) {
704 qparam.txop = 0; 724 /* Set defaults according to 802.11-2007 Table 7-37 */
725 aCWmax = 1023;
726 if (use_11b)
727 aCWmin = 31;
728 else
729 aCWmin = 15;
730
731 switch (queue) {
732 case 3: /* AC_BK */
733 qparam.cw_max = aCWmin;
734 qparam.cw_min = aCWmax;
735 qparam.txop = 0;
736 qparam.aifs = 7;
737 break;
738 default: /* never happens but let's not leave undefined */
739 case 2: /* AC_BE */
740 qparam.cw_max = aCWmin;
741 qparam.cw_min = aCWmax;
742 qparam.txop = 0;
743 qparam.aifs = 3;
744 break;
745 case 1: /* AC_VI */
746 qparam.cw_max = aCWmin;
747 qparam.cw_min = (aCWmin + 1) / 2 - 1;
748 if (use_11b)
749 qparam.txop = 6016/32;
750 else
751 qparam.txop = 3008/32;
752 qparam.aifs = 2;
753 break;
754 case 0: /* AC_VO */
755 qparam.cw_max = (aCWmin + 1) / 2 - 1;
756 qparam.cw_min = (aCWmin + 1) / 4 - 1;
757 if (use_11b)
758 qparam.txop = 3264/32;
759 else
760 qparam.txop = 1504/32;
761 qparam.aifs = 2;
762 break;
763 }
705 764
706 for (i = 0; i < local_to_hw(local)->queues; i++) 765 drv_conf_tx(local, queue, &qparam);
707 local->ops->conf_tx(local_to_hw(local), i, &qparam); 766 }
708} 767}
709 768
710void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 769void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
@@ -831,16 +890,73 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
831 ieee80211_tx_skb(sdata, skb, encrypt); 890 ieee80211_tx_skb(sdata, skb, encrypt);
832} 891}
833 892
893int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
894 const u8 *ie, size_t ie_len)
895{
896 struct ieee80211_supported_band *sband;
897 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL;
898 int i;
899
900 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
901
902 pos = buffer;
903
904 *pos++ = WLAN_EID_SUPP_RATES;
905 supp_rates_len = pos;
906 *pos++ = 0;
907
908 for (i = 0; i < sband->n_bitrates; i++) {
909 struct ieee80211_rate *rate = &sband->bitrates[i];
910
911 if (esupp_rates_len) {
912 *esupp_rates_len += 1;
913 } else if (*supp_rates_len == 8) {
914 *pos++ = WLAN_EID_EXT_SUPP_RATES;
915 esupp_rates_len = pos;
916 *pos++ = 1;
917 } else
918 *supp_rates_len += 1;
919
920 *pos++ = rate->bitrate / 5;
921 }
922
923 if (sband->ht_cap.ht_supported) {
924 __le16 tmp = cpu_to_le16(sband->ht_cap.cap);
925
926 *pos++ = WLAN_EID_HT_CAPABILITY;
927 *pos++ = sizeof(struct ieee80211_ht_cap);
928 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
929 memcpy(pos, &tmp, sizeof(u16));
930 pos += sizeof(u16);
931 /* TODO: needs a define here for << 2 */
932 *pos++ = sband->ht_cap.ampdu_factor |
933 (sband->ht_cap.ampdu_density << 2);
934 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
935 pos += sizeof(sband->ht_cap.mcs);
936 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
937 }
938
939 /*
940 * If adding more here, adjust code in main.c
941 * that calculates local->scan_ies_len.
942 */
943
944 if (ie) {
945 memcpy(pos, ie, ie_len);
946 pos += ie_len;
947 }
948
949 return pos - buffer;
950}
951
834void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 952void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
835 u8 *ssid, size_t ssid_len, 953 const u8 *ssid, size_t ssid_len,
836 u8 *ie, size_t ie_len) 954 const u8 *ie, size_t ie_len)
837{ 955{
838 struct ieee80211_local *local = sdata->local; 956 struct ieee80211_local *local = sdata->local;
839 struct ieee80211_supported_band *sband;
840 struct sk_buff *skb; 957 struct sk_buff *skb;
841 struct ieee80211_mgmt *mgmt; 958 struct ieee80211_mgmt *mgmt;
842 u8 *pos, *supp_rates, *esupp_rates = NULL; 959 u8 *pos;
843 int i;
844 960
845 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + 961 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
846 ie_len); 962 ie_len);
@@ -867,31 +983,9 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
867 *pos++ = WLAN_EID_SSID; 983 *pos++ = WLAN_EID_SSID;
868 *pos++ = ssid_len; 984 *pos++ = ssid_len;
869 memcpy(pos, ssid, ssid_len); 985 memcpy(pos, ssid, ssid_len);
986 pos += ssid_len;
870 987
871 supp_rates = skb_put(skb, 2); 988 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 989
896 ieee80211_tx_skb(sdata, skb, 0); 990 ieee80211_tx_skb(sdata, skb, 0);
897} 991}
@@ -931,3 +1025,108 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
931 } 1025 }
932 return supp_rates; 1026 return supp_rates;
933} 1027}
1028
1029int ieee80211_reconfig(struct ieee80211_local *local)
1030{
1031 struct ieee80211_hw *hw = &local->hw;
1032 struct ieee80211_sub_if_data *sdata;
1033 struct ieee80211_if_init_conf conf;
1034 struct sta_info *sta;
1035 unsigned long flags;
1036 int res;
1037
1038 /* restart hardware */
1039 if (local->open_count) {
1040 res = drv_start(local);
1041
1042 ieee80211_led_radio(local, hw->conf.radio_enabled);
1043 }
1044
1045 /* add interfaces */
1046 list_for_each_entry(sdata, &local->interfaces, list) {
1047 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1048 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1049 netif_running(sdata->dev)) {
1050 conf.vif = &sdata->vif;
1051 conf.type = sdata->vif.type;
1052 conf.mac_addr = sdata->dev->dev_addr;
1053 res = drv_add_interface(local, &conf);
1054 }
1055 }
1056
1057 /* add STAs back */
1058 if (local->ops->sta_notify) {
1059 spin_lock_irqsave(&local->sta_lock, flags);
1060 list_for_each_entry(sta, &local->sta_list, list) {
1061 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1062 sdata = container_of(sdata->bss,
1063 struct ieee80211_sub_if_data,
1064 u.ap);
1065
1066 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_ADD,
1067 &sta->sta);
1068 }
1069 spin_unlock_irqrestore(&local->sta_lock, flags);
1070 }
1071
1072 /* Clear Suspend state so that ADDBA requests can be processed */
1073
1074 rcu_read_lock();
1075
1076 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1077 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1078 clear_sta_flags(sta, WLAN_STA_SUSPEND);
1079 }
1080 }
1081
1082 rcu_read_unlock();
1083
1084 /* setup RTS threshold */
1085 drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
1086
1087 /* reconfigure hardware */
1088 ieee80211_hw_config(local, ~0);
1089
1090 netif_addr_lock_bh(local->mdev);
1091 ieee80211_configure_filter(local);
1092 netif_addr_unlock_bh(local->mdev);
1093
1094 /* Finally also reconfigure all the BSS information */
1095 list_for_each_entry(sdata, &local->interfaces, list) {
1096 u32 changed = ~0;
1097 if (!netif_running(sdata->dev))
1098 continue;
1099 switch (sdata->vif.type) {
1100 case NL80211_IFTYPE_STATION:
1101 /* disable beacon change bits */
1102 changed &= ~(BSS_CHANGED_BEACON |
1103 BSS_CHANGED_BEACON_ENABLED);
1104 /* fall through */
1105 case NL80211_IFTYPE_ADHOC:
1106 case NL80211_IFTYPE_AP:
1107 case NL80211_IFTYPE_MESH_POINT:
1108 ieee80211_bss_info_change_notify(sdata, changed);
1109 break;
1110 case NL80211_IFTYPE_WDS:
1111 break;
1112 case NL80211_IFTYPE_AP_VLAN:
1113 case NL80211_IFTYPE_MONITOR:
1114 /* ignore virtual */
1115 break;
1116 case NL80211_IFTYPE_UNSPECIFIED:
1117 case __NL80211_IFTYPE_AFTER_LAST:
1118 WARN_ON(1);
1119 break;
1120 }
1121 }
1122
1123 /* add back keys */
1124 list_for_each_entry(sdata, &local->interfaces, list)
1125 if (netif_running(sdata->dev))
1126 ieee80211_enable_keys(sdata);
1127
1128 ieee80211_wake_queues_by_reason(hw,
1129 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1130
1131 return 0;
1132}
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index 959aa8379ccf..c14394744a9c 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)
@@ -135,6 +41,7 @@ static int ieee80211_ioctl_siwgenie(struct net_device *dev,
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;
44 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
138 ieee80211_sta_req_auth(sdata); 45 ieee80211_sta_req_auth(sdata);
139 return 0; 46 return 0;
140 } 47 }
@@ -149,17 +56,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 56 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
150 57
151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 58 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
152 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL; 59 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
153 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 60 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; 61 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
155 62
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ 63 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
157 if (freq->e == 0) { 64 if (freq->e == 0) {
158 if (freq->m < 0) { 65 if (freq->m < 0) {
159 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 66 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 |= 67 sdata->u.mgd.flags |=
164 IEEE80211_STA_AUTO_CHANNEL_SEL; 68 IEEE80211_STA_AUTO_CHANNEL_SEL;
165 return 0; 69 return 0;
@@ -183,8 +87,12 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
183 struct iw_freq *freq, char *extra) 87 struct iw_freq *freq, char *extra)
184{ 88{
185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 89 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
90 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
91
92 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
93 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
186 94
187 freq->m = local->hw.conf.channel->center_freq; 95 freq->m = local->oper_channel->center_freq;
188 freq->e = 6; 96 freq->e = 6;
189 97
190 return 0; 98 return 0;
@@ -195,15 +103,17 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
195 struct iw_request_info *info, 103 struct iw_request_info *info,
196 struct iw_point *data, char *ssid) 104 struct iw_point *data, char *ssid)
197{ 105{
198 struct ieee80211_sub_if_data *sdata; 106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
199 size_t len = data->length; 107 size_t len = data->length;
200 int ret; 108 int ret;
201 109
110 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
111 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
112
202 /* iwconfig uses nul termination in SSID.. */ 113 /* iwconfig uses nul termination in SSID.. */
203 if (len > 0 && ssid[len - 1] == '\0') 114 if (len > 0 && ssid[len - 1] == '\0')
204 len--; 115 len--;
205 116
206 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
207 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 117 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
208 if (data->flags) 118 if (data->flags)
209 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; 119 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
@@ -215,10 +125,10 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
215 return ret; 125 return ret;
216 126
217 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 127 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
128 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
218 ieee80211_sta_req_auth(sdata); 129 ieee80211_sta_req_auth(sdata);
219 return 0; 130 return 0;
220 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 131 }
221 return ieee80211_ibss_set_ssid(sdata, ssid, len);
222 132
223 return -EOPNOTSUPP; 133 return -EOPNOTSUPP;
224} 134}
@@ -229,9 +139,13 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
229 struct iw_point *data, char *ssid) 139 struct iw_point *data, char *ssid)
230{ 140{
231 size_t len; 141 size_t len;
232
233 struct ieee80211_sub_if_data *sdata; 142 struct ieee80211_sub_if_data *sdata;
143
234 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 144 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
145
146 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
147 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
148
235 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 149 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
236 int res = ieee80211_sta_get_ssid(sdata, ssid, &len); 150 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
237 if (res == 0) { 151 if (res == 0) {
@@ -240,14 +154,6 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
240 } else 154 } else
241 data->flags = 0; 155 data->flags = 0;
242 return res; 156 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 } 157 }
252 158
253 return -EOPNOTSUPP; 159 return -EOPNOTSUPP;
@@ -258,9 +164,11 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
258 struct iw_request_info *info, 164 struct iw_request_info *info,
259 struct sockaddr *ap_addr, char *extra) 165 struct sockaddr *ap_addr, char *extra)
260{ 166{
261 struct ieee80211_sub_if_data *sdata; 167 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
168
169 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
170 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
262 171
263 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
264 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 172 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
265 int ret; 173 int ret;
266 174
@@ -275,18 +183,9 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
275 if (ret) 183 if (ret)
276 return ret; 184 return ret;
277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 185 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
186 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
278 ieee80211_sta_req_auth(sdata); 187 ieee80211_sta_req_auth(sdata);
279 return 0; 188 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) { 189 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
291 /* 190 /*
292 * If it is necessary to update the WDS peer address 191 * If it is necessary to update the WDS peer address
@@ -312,9 +211,11 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
312 struct iw_request_info *info, 211 struct iw_request_info *info,
313 struct sockaddr *ap_addr, char *extra) 212 struct sockaddr *ap_addr, char *extra)
314{ 213{
315 struct ieee80211_sub_if_data *sdata; 214 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
215
216 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
217 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
316 218
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
318 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 219 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
319 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) { 220 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
320 ap_addr->sa_family = ARPHRD_ETHER; 221 ap_addr->sa_family = ARPHRD_ETHER;
@@ -322,13 +223,6 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
322 } else 223 } else
323 memset(&ap_addr->sa_data, 0, ETH_ALEN); 224 memset(&ap_addr->sa_data, 0, ETH_ALEN);
324 return 0; 225 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) { 226 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
333 ap_addr->sa_family = ARPHRD_ETHER; 227 ap_addr->sa_family = ARPHRD_ETHER;
334 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); 228 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
@@ -487,258 +381,6 @@ static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
487 return 0; 381 return 0;
488} 382}
489 383
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, 384static int ieee80211_ioctl_siwpower(struct net_device *dev,
743 struct iw_request_info *info, 385 struct iw_request_info *info,
744 struct iw_param *wrq, 386 struct iw_param *wrq,
@@ -747,7 +389,7 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 389 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 390 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
749 struct ieee80211_conf *conf = &local->hw.conf; 391 struct ieee80211_conf *conf = &local->hw.conf;
750 int ret = 0, timeout = 0; 392 int timeout = 0;
751 bool ps; 393 bool ps;
752 394
753 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 395 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
@@ -779,42 +421,18 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
779 timeout = wrq->value / 1000; 421 timeout = wrq->value / 1000;
780 422
781 set: 423 set:
782 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout) 424 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
783 return ret; 425 return 0;
784 426
785 local->powersave = ps; 427 sdata->u.mgd.powersave = ps;
786 conf->dynamic_ps_timeout = timeout; 428 conf->dynamic_ps_timeout = timeout;
787 429
788 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) 430 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
789 ret = ieee80211_hw_config(local, 431 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
790 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
791 432
792 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)) 433 ieee80211_recalc_ps(local, -1);
793 return ret;
794
795 if (conf->dynamic_ps_timeout > 0 &&
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 434
817 return ret; 435 return 0;
818} 436}
819 437
820static int ieee80211_ioctl_giwpower(struct net_device *dev, 438static int ieee80211_ioctl_giwpower(struct net_device *dev,
@@ -822,9 +440,9 @@ static int ieee80211_ioctl_giwpower(struct net_device *dev,
822 union iwreq_data *wrqu, 440 union iwreq_data *wrqu,
823 char *extra) 441 char *extra)
824{ 442{
825 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 443 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
826 444
827 wrqu->power.disabled = !local->powersave; 445 wrqu->power.disabled = !sdata->u.mgd.powersave;
828 446
829 return 0; 447 return 0;
830} 448}
@@ -997,82 +615,6 @@ static int ieee80211_ioctl_giwauth(struct net_device *dev,
997} 615}
998 616
999 617
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 */ 618/* Structures to export the Wireless Handlers */
1077 619
1078static const iw_handler ieee80211_handler[] = 620static const iw_handler ieee80211_handler[] =
@@ -1099,7 +641,7 @@ static const iw_handler ieee80211_handler[] =
1099 (iw_handler) NULL, /* SIOCGIWTHRSPY */ 641 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1100 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ 642 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1101 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ 643 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1102 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ 644 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
1103 (iw_handler) NULL, /* SIOCGIWAPLIST */ 645 (iw_handler) NULL, /* SIOCGIWAPLIST */
1104 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ 646 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1105 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ 647 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
@@ -1111,16 +653,16 @@ static const iw_handler ieee80211_handler[] =
1111 (iw_handler) NULL, /* -- hole -- */ 653 (iw_handler) NULL, /* -- hole -- */
1112 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ 654 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1113 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ 655 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1114 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ 656 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
1115 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ 657 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
1116 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ 658 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
1117 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ 659 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
1118 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ 660 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1119 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ 661 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1120 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ 662 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
1121 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ 663 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
1122 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ 664 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
1123 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ 665 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
1124 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ 666 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
1125 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */ 667 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
1126 (iw_handler) NULL, /* -- hole -- */ 668 (iw_handler) NULL, /* -- hole -- */
@@ -1129,7 +671,7 @@ static const iw_handler ieee80211_handler[] =
1129 (iw_handler) NULL, /* SIOCGIWGENIE */ 671 (iw_handler) NULL, /* SIOCGIWGENIE */
1130 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */ 672 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1131 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */ 673 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1132 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ 674 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
1133 (iw_handler) NULL, /* SIOCGIWENCODEEXT */ 675 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1134 (iw_handler) NULL, /* SIOCSIWPMKSA */ 676 (iw_handler) NULL, /* SIOCSIWPMKSA */
1135 (iw_handler) NULL, /* -- hole -- */ 677 (iw_handler) NULL, /* -- hole -- */
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 0b8ad1f4ecdd..45b74f38b867 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -133,7 +133,7 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
133 u8 *p = ieee80211_get_qos_ctl(hdr); 133 u8 *p = ieee80211_get_qos_ctl(hdr);
134 u8 ack_policy = 0; 134 u8 ack_policy = 0;
135 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; 135 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
136 if (local->wifi_wme_noack_test) 136 if (unlikely(local->wifi_wme_noack_test))
137 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK << 137 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
138 QOS_CONTROL_ACK_POLICY_SHIFT; 138 QOS_CONTROL_ACK_POLICY_SHIFT;
139 /* qos header is 2 bytes, second reserved */ 139 /* 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