aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/mac80211/Kconfig13
-rw-r--r--net/mac80211/cfg.c86
-rw-r--r--net/mac80211/debugfs.c4
-rw-r--r--net/mac80211/debugfs_key.c3
-rw-r--r--net/mac80211/debugfs_netdev.c72
-rw-r--r--net/mac80211/debugfs_sta.c6
-rw-r--r--net/mac80211/ht.c28
-rw-r--r--net/mac80211/ieee80211_i.h233
-rw-r--r--net/mac80211/iface.c608
-rw-r--r--net/mac80211/key.c8
-rw-r--r--net/mac80211/main.c608
-rw-r--r--net/mac80211/mesh.c337
-rw-r--r--net/mac80211/mesh.h15
-rw-r--r--net/mac80211/mesh_hwmp.c108
-rw-r--r--net/mac80211/mesh_pathtbl.c8
-rw-r--r--net/mac80211/mesh_plink.c66
-rw-r--r--net/mac80211/mlme.c875
-rw-r--r--net/mac80211/rate.h2
-rw-r--r--net/mac80211/rc80211_pid.h2
-rw-r--r--net/mac80211/rc80211_pid_algo.c53
-rw-r--r--net/mac80211/rx.c98
-rw-r--r--net/mac80211/scan.c208
-rw-r--r--net/mac80211/sta_info.c89
-rw-r--r--net/mac80211/sta_info.h27
-rw-r--r--net/mac80211/tkip.c2
-rw-r--r--net/mac80211/tx.c187
-rw-r--r--net/mac80211/util.c135
-rw-r--r--net/mac80211/wext.c122
-rw-r--r--net/mac80211/wme.c2
-rw-r--r--net/mac80211/wme.h1
-rw-r--r--net/mac80211/wpa.c2
-rw-r--r--net/rfkill/rfkill.c16
-rw-r--r--net/wireless/Kconfig32
-rw-r--r--net/wireless/core.c162
-rw-r--r--net/wireless/core.h2
-rw-r--r--net/wireless/nl80211.c151
-rw-r--r--net/wireless/reg.c805
-rw-r--r--net/wireless/reg.h44
38 files changed, 3200 insertions, 2020 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 80d693392b0f..8427518e4f20 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -179,19 +179,6 @@ config MAC80211_VERBOSE_MPL_DEBUG
179 179
180 Do not select this option. 180 Do not select this option.
181 181
182config MAC80211_LOWTX_FRAME_DUMP
183 bool "Debug frame dumping"
184 depends on MAC80211_DEBUG_MENU
185 ---help---
186 Selecting this option will cause the stack to
187 print a message for each frame that is handed
188 to the lowlevel driver for transmission. This
189 message includes all MAC addresses and the
190 frame control field.
191
192 If unsure, say N and insert the debugging code
193 you require into the driver you are debugging.
194
195config MAC80211_DEBUG_COUNTERS 182config MAC80211_DEBUG_COUNTERS
196 bool "Extra statistics for TX/RX debugging" 183 bool "Extra statistics for TX/RX debugging"
197 depends on MAC80211_DEBUG_MENU 184 depends on MAC80211_DEBUG_MENU
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 928813ce08e2..e2574885db4a 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -17,26 +17,26 @@
17#include "rate.h" 17#include "rate.h"
18#include "mesh.h" 18#include "mesh.h"
19 19
20static enum ieee80211_if_types 20struct ieee80211_hw *wiphy_to_hw(struct wiphy *wiphy)
21nl80211_type_to_mac80211_type(enum nl80211_iftype type) 21{
22 struct ieee80211_local *local = wiphy_priv(wiphy);
23 return &local->hw;
24}
25EXPORT_SYMBOL(wiphy_to_hw);
26
27static bool nl80211_type_check(enum nl80211_iftype type)
22{ 28{
23 switch (type) { 29 switch (type) {
24 case NL80211_IFTYPE_UNSPECIFIED:
25 return IEEE80211_IF_TYPE_STA;
26 case NL80211_IFTYPE_ADHOC: 30 case NL80211_IFTYPE_ADHOC:
27 return IEEE80211_IF_TYPE_IBSS;
28 case NL80211_IFTYPE_STATION: 31 case NL80211_IFTYPE_STATION:
29 return IEEE80211_IF_TYPE_STA;
30 case NL80211_IFTYPE_MONITOR: 32 case NL80211_IFTYPE_MONITOR:
31 return IEEE80211_IF_TYPE_MNTR;
32#ifdef CONFIG_MAC80211_MESH 33#ifdef CONFIG_MAC80211_MESH
33 case NL80211_IFTYPE_MESH_POINT: 34 case NL80211_IFTYPE_MESH_POINT:
34 return IEEE80211_IF_TYPE_MESH_POINT;
35#endif 35#endif
36 case NL80211_IFTYPE_WDS: 36 case NL80211_IFTYPE_WDS:
37 return IEEE80211_IF_TYPE_WDS; 37 return true;
38 default: 38 default:
39 return IEEE80211_IF_TYPE_INVALID; 39 return false;
40 } 40 }
41} 41}
42 42
@@ -45,17 +45,15 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
45 struct vif_params *params) 45 struct vif_params *params)
46{ 46{
47 struct ieee80211_local *local = wiphy_priv(wiphy); 47 struct ieee80211_local *local = wiphy_priv(wiphy);
48 enum ieee80211_if_types itype;
49 struct net_device *dev; 48 struct net_device *dev;
50 struct ieee80211_sub_if_data *sdata; 49 struct ieee80211_sub_if_data *sdata;
51 int err; 50 int err;
52 51
53 itype = nl80211_type_to_mac80211_type(type); 52 if (!nl80211_type_check(type))
54 if (itype == IEEE80211_IF_TYPE_INVALID)
55 return -EINVAL; 53 return -EINVAL;
56 54
57 err = ieee80211_if_add(local, name, &dev, itype, params); 55 err = ieee80211_if_add(local, name, &dev, type, params);
58 if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags) 56 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
59 return err; 57 return err;
60 58
61 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 59 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -86,7 +84,6 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
86{ 84{
87 struct ieee80211_local *local = wiphy_priv(wiphy); 85 struct ieee80211_local *local = wiphy_priv(wiphy);
88 struct net_device *dev; 86 struct net_device *dev;
89 enum ieee80211_if_types itype;
90 struct ieee80211_sub_if_data *sdata; 87 struct ieee80211_sub_if_data *sdata;
91 int ret; 88 int ret;
92 89
@@ -95,8 +92,7 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
95 if (!dev) 92 if (!dev)
96 return -ENODEV; 93 return -ENODEV;
97 94
98 itype = nl80211_type_to_mac80211_type(type); 95 if (!nl80211_type_check(type))
99 if (itype == IEEE80211_IF_TYPE_INVALID)
100 return -EINVAL; 96 return -EINVAL;
101 97
102 if (dev == local->mdev) 98 if (dev == local->mdev)
@@ -104,16 +100,16 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
104 100
105 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 101 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
106 102
107 ret = ieee80211_if_change_type(sdata, itype); 103 ret = ieee80211_if_change_type(sdata, type);
108 if (ret) 104 if (ret)
109 return ret; 105 return ret;
110 106
111 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) 107 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
112 ieee80211_if_sta_set_mesh_id(&sdata->u.sta, 108 ieee80211_sdata_set_mesh_id(sdata,
113 params->mesh_id_len, 109 params->mesh_id_len,
114 params->mesh_id); 110 params->mesh_id);
115 111
116 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags) 112 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
117 return 0; 113 return 0;
118 114
119 sdata->u.mntr_flags = *flags; 115 sdata->u.mntr_flags = *flags;
@@ -368,7 +364,7 @@ static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
368 sta = sta_info_get_by_idx(local, idx, dev); 364 sta = sta_info_get_by_idx(local, idx, dev);
369 if (sta) { 365 if (sta) {
370 ret = 0; 366 ret = 0;
371 memcpy(mac, sta->addr, ETH_ALEN); 367 memcpy(mac, sta->sta.addr, ETH_ALEN);
372 sta_set_sinfo(sta, sinfo); 368 sta_set_sinfo(sta, sinfo);
373 } 369 }
374 370
@@ -509,7 +505,7 @@ static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
509 505
510 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 506 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
511 507
512 if (sdata->vif.type != IEEE80211_IF_TYPE_AP) 508 if (sdata->vif.type != NL80211_IFTYPE_AP)
513 return -EINVAL; 509 return -EINVAL;
514 510
515 old = sdata->u.ap.beacon; 511 old = sdata->u.ap.beacon;
@@ -532,7 +528,7 @@ static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
532 528
533 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 529 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
534 530
535 if (sdata->vif.type != IEEE80211_IF_TYPE_AP) 531 if (sdata->vif.type != NL80211_IFTYPE_AP)
536 return -EINVAL; 532 return -EINVAL;
537 533
538 old = sdata->u.ap.beacon; 534 old = sdata->u.ap.beacon;
@@ -554,7 +550,7 @@ static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
554 550
555 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 551 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
556 552
557 if (sdata->vif.type != IEEE80211_IF_TYPE_AP) 553 if (sdata->vif.type != NL80211_IFTYPE_AP)
558 return -EINVAL; 554 return -EINVAL;
559 555
560 old = sdata->u.ap.beacon; 556 old = sdata->u.ap.beacon;
@@ -597,7 +593,7 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
597 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ 593 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
598 594
599 memset(msg->da, 0xff, ETH_ALEN); 595 memset(msg->da, 0xff, ETH_ALEN);
600 memcpy(msg->sa, sta->addr, ETH_ALEN); 596 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
601 msg->len = htons(6); 597 msg->len = htons(6);
602 msg->dsap = 0; 598 msg->dsap = 0;
603 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ 599 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
@@ -652,9 +648,9 @@ static void sta_apply_parameters(struct ieee80211_local *local,
652 */ 648 */
653 649
654 if (params->aid) { 650 if (params->aid) {
655 sta->aid = params->aid; 651 sta->sta.aid = params->aid;
656 if (sta->aid > IEEE80211_MAX_AID) 652 if (sta->sta.aid > IEEE80211_MAX_AID)
657 sta->aid = 0; /* XXX: should this be an error? */ 653 sta->sta.aid = 0; /* XXX: should this be an error? */
658 } 654 }
659 655
660 if (params->listen_interval >= 0) 656 if (params->listen_interval >= 0)
@@ -671,12 +667,12 @@ static void sta_apply_parameters(struct ieee80211_local *local,
671 rates |= BIT(j); 667 rates |= BIT(j);
672 } 668 }
673 } 669 }
674 sta->supp_rates[local->oper_channel->band] = rates; 670 sta->sta.supp_rates[local->oper_channel->band] = rates;
675 } 671 }
676 672
677 if (params->ht_capa) { 673 if (params->ht_capa) {
678 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa, 674 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa,
679 &sta->ht_info); 675 &sta->sta.ht_info);
680 } 676 }
681 677
682 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { 678 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
@@ -709,8 +705,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
709 if (params->vlan) { 705 if (params->vlan) {
710 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 706 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
711 707
712 if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN && 708 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
713 sdata->vif.type != IEEE80211_IF_TYPE_AP) 709 sdata->vif.type != NL80211_IFTYPE_AP)
714 return -EINVAL; 710 return -EINVAL;
715 } else 711 } else
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 712 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -740,8 +736,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
740 return err; 736 return err;
741 } 737 }
742 738
743 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN || 739 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
744 sdata->vif.type == IEEE80211_IF_TYPE_AP) 740 sdata->vif.type == NL80211_IFTYPE_AP)
745 ieee80211_send_layer2_update(sta); 741 ieee80211_send_layer2_update(sta);
746 742
747 rcu_read_unlock(); 743 rcu_read_unlock();
@@ -805,8 +801,8 @@ static int ieee80211_change_station(struct wiphy *wiphy,
805 if (params->vlan && params->vlan != sta->sdata->dev) { 801 if (params->vlan && params->vlan != sta->sdata->dev) {
806 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 802 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
807 803
808 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN && 804 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
809 vlansdata->vif.type != IEEE80211_IF_TYPE_AP) { 805 vlansdata->vif.type != NL80211_IFTYPE_AP) {
810 rcu_read_unlock(); 806 rcu_read_unlock();
811 return -EINVAL; 807 return -EINVAL;
812 } 808 }
@@ -840,7 +836,7 @@ static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
840 836
841 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
842 838
843 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) 839 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
844 return -ENOTSUPP; 840 return -ENOTSUPP;
845 841
846 rcu_read_lock(); 842 rcu_read_lock();
@@ -896,7 +892,7 @@ static int ieee80211_change_mpath(struct wiphy *wiphy,
896 892
897 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 893 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
898 894
899 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) 895 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
900 return -ENOTSUPP; 896 return -ENOTSUPP;
901 897
902 rcu_read_lock(); 898 rcu_read_lock();
@@ -923,7 +919,7 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
923 struct mpath_info *pinfo) 919 struct mpath_info *pinfo)
924{ 920{
925 if (mpath->next_hop) 921 if (mpath->next_hop)
926 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN); 922 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
927 else 923 else
928 memset(next_hop, 0, ETH_ALEN); 924 memset(next_hop, 0, ETH_ALEN);
929 925
@@ -971,7 +967,7 @@ static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
971 967
972 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 968 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
973 969
974 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) 970 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
975 return -ENOTSUPP; 971 return -ENOTSUPP;
976 972
977 rcu_read_lock(); 973 rcu_read_lock();
@@ -999,7 +995,7 @@ static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
999 995
1000 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 996 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001 997
1002 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) 998 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1003 return -ENOTSUPP; 999 return -ENOTSUPP;
1004 1000
1005 rcu_read_lock(); 1001 rcu_read_lock();
@@ -1028,7 +1024,7 @@ static int ieee80211_change_bss(struct wiphy *wiphy,
1028 1024
1029 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1025 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1030 1026
1031 if (sdata->vif.type != IEEE80211_IF_TYPE_AP) 1027 if (sdata->vif.type != NL80211_IFTYPE_AP)
1032 return -EINVAL; 1028 return -EINVAL;
1033 1029
1034 if (params->use_cts_prot >= 0) { 1030 if (params->use_cts_prot >= 0) {
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index ee509f1109e2..24ce54463310 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -51,8 +51,6 @@ DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
51 local->hw.conf.antenna_sel_tx); 51 local->hw.conf.antenna_sel_tx);
52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d", 52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
53 local->hw.conf.antenna_sel_rx); 53 local->hw.conf.antenna_sel_rx);
54DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
55 local->bridge_packets);
56DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", 54DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
57 local->rts_threshold); 55 local->rts_threshold);
58DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", 56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
@@ -206,7 +204,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
206 DEBUGFS_ADD(frequency); 204 DEBUGFS_ADD(frequency);
207 DEBUGFS_ADD(antenna_sel_tx); 205 DEBUGFS_ADD(antenna_sel_tx);
208 DEBUGFS_ADD(antenna_sel_rx); 206 DEBUGFS_ADD(antenna_sel_rx);
209 DEBUGFS_ADD(bridge_packets);
210 DEBUGFS_ADD(rts_threshold); 207 DEBUGFS_ADD(rts_threshold);
211 DEBUGFS_ADD(fragmentation_threshold); 208 DEBUGFS_ADD(fragmentation_threshold);
212 DEBUGFS_ADD(short_retry_limit); 209 DEBUGFS_ADD(short_retry_limit);
@@ -263,7 +260,6 @@ void debugfs_hw_del(struct ieee80211_local *local)
263 DEBUGFS_DEL(frequency); 260 DEBUGFS_DEL(frequency);
264 DEBUGFS_DEL(antenna_sel_tx); 261 DEBUGFS_DEL(antenna_sel_tx);
265 DEBUGFS_DEL(antenna_sel_rx); 262 DEBUGFS_DEL(antenna_sel_rx);
266 DEBUGFS_DEL(bridge_packets);
267 DEBUGFS_DEL(rts_threshold); 263 DEBUGFS_DEL(rts_threshold);
268 DEBUGFS_DEL(fragmentation_threshold); 264 DEBUGFS_DEL(fragmentation_threshold);
269 DEBUGFS_DEL(short_retry_limit); 265 DEBUGFS_DEL(short_retry_limit);
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index cf82acec913a..a3294d109322 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -206,7 +206,8 @@ void ieee80211_debugfs_key_add(struct ieee80211_key *key)
206 rcu_read_lock(); 206 rcu_read_lock();
207 sta = rcu_dereference(key->sta); 207 sta = rcu_dereference(key->sta);
208 if (sta) 208 if (sta)
209 sprintf(buf, "../../stations/%s", print_mac(mac, sta->addr)); 209 sprintf(buf, "../../stations/%s",
210 print_mac(mac, sta->sta.addr));
210 rcu_read_unlock(); 211 rcu_read_unlock();
211 212
212 /* using sta as a boolean is fine outside RCU lock */ 213 /* using sta as a boolean is fine outside RCU lock */
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 8165df578c92..2a4515623776 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -173,7 +173,6 @@ IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
173IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX); 173IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
174IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC); 174IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
175IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC); 175IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
176IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
177 176
178static ssize_t ieee80211_if_fmt_flags( 177static ssize_t ieee80211_if_fmt_flags(
179 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) 178 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
@@ -192,7 +191,6 @@ __IEEE80211_IF_FILE(flags);
192/* AP attributes */ 191/* AP attributes */
193IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); 192IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
194IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC); 193IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
195IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
196 194
197static ssize_t ieee80211_if_fmt_num_buffered_multicast( 195static ssize_t ieee80211_if_fmt_num_buffered_multicast(
198 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) 196 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
@@ -207,37 +205,37 @@ IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
207 205
208#ifdef CONFIG_MAC80211_MESH 206#ifdef CONFIG_MAC80211_MESH
209/* Mesh stats attributes */ 207/* Mesh stats attributes */
210IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC); 208IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
211IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC); 209IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
212IEEE80211_IF_FILE(dropped_frames_no_route, 210IEEE80211_IF_FILE(dropped_frames_no_route,
213 u.sta.mshstats.dropped_frames_no_route, DEC); 211 u.mesh.mshstats.dropped_frames_no_route, DEC);
214IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC); 212IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
215 213
216/* Mesh parameters */ 214/* Mesh parameters */
217IEEE80211_IF_WFILE(dot11MeshMaxRetries, 215IEEE80211_IF_WFILE(dot11MeshMaxRetries,
218 u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8); 216 u.mesh.mshcfg.dot11MeshMaxRetries, DEC, u8);
219IEEE80211_IF_WFILE(dot11MeshRetryTimeout, 217IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
220 u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16); 218 u.mesh.mshcfg.dot11MeshRetryTimeout, DEC, u16);
221IEEE80211_IF_WFILE(dot11MeshConfirmTimeout, 219IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
222 u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16); 220 u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
223IEEE80211_IF_WFILE(dot11MeshHoldingTimeout, 221IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
224 u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16); 222 u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
225IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8); 223IEEE80211_IF_WFILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC, u8);
226IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8); 224IEEE80211_IF_WFILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC, u8);
227IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks, 225IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
228 u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16); 226 u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
229IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout, 227IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
230 u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32); 228 u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
231IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval, 229IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
232 u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16); 230 u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
233IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime, 231IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
234 u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16); 232 u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
235IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries, 233IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
236 u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8); 234 u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
237IEEE80211_IF_WFILE(path_refresh_time, 235IEEE80211_IF_WFILE(path_refresh_time,
238 u.sta.mshcfg.path_refresh_time, DEC, u32); 236 u.mesh.mshcfg.path_refresh_time, DEC, u32);
239IEEE80211_IF_WFILE(min_discovery_timeout, 237IEEE80211_IF_WFILE(min_discovery_timeout,
240 u.sta.mshcfg.min_discovery_timeout, DEC, u16); 238 u.mesh.mshcfg.min_discovery_timeout, DEC, u16);
241#endif 239#endif
242 240
243 241
@@ -265,7 +263,6 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
265 DEBUGFS_ADD(auth_alg, sta); 263 DEBUGFS_ADD(auth_alg, sta);
266 DEBUGFS_ADD(auth_transaction, sta); 264 DEBUGFS_ADD(auth_transaction, sta);
267 DEBUGFS_ADD(flags, sta); 265 DEBUGFS_ADD(flags, sta);
268 DEBUGFS_ADD(num_beacons_sta, sta);
269} 266}
270 267
271static void add_ap_files(struct ieee80211_sub_if_data *sdata) 268static void add_ap_files(struct ieee80211_sub_if_data *sdata)
@@ -276,7 +273,6 @@ static void add_ap_files(struct ieee80211_sub_if_data *sdata)
276 273
277 DEBUGFS_ADD(num_sta_ps, ap); 274 DEBUGFS_ADD(num_sta_ps, ap);
278 DEBUGFS_ADD(dtim_count, ap); 275 DEBUGFS_ADD(dtim_count, ap);
279 DEBUGFS_ADD(num_beacons, ap);
280 DEBUGFS_ADD(num_buffered_multicast, ap); 276 DEBUGFS_ADD(num_buffered_multicast, ap);
281} 277}
282 278
@@ -345,26 +341,26 @@ static void add_files(struct ieee80211_sub_if_data *sdata)
345 return; 341 return;
346 342
347 switch (sdata->vif.type) { 343 switch (sdata->vif.type) {
348 case IEEE80211_IF_TYPE_MESH_POINT: 344 case NL80211_IFTYPE_MESH_POINT:
349#ifdef CONFIG_MAC80211_MESH 345#ifdef CONFIG_MAC80211_MESH
350 add_mesh_stats(sdata); 346 add_mesh_stats(sdata);
351 add_mesh_config(sdata); 347 add_mesh_config(sdata);
352#endif 348#endif
353 /* fall through */ 349 break;
354 case IEEE80211_IF_TYPE_STA: 350 case NL80211_IFTYPE_STATION:
355 case IEEE80211_IF_TYPE_IBSS: 351 case NL80211_IFTYPE_ADHOC:
356 add_sta_files(sdata); 352 add_sta_files(sdata);
357 break; 353 break;
358 case IEEE80211_IF_TYPE_AP: 354 case NL80211_IFTYPE_AP:
359 add_ap_files(sdata); 355 add_ap_files(sdata);
360 break; 356 break;
361 case IEEE80211_IF_TYPE_WDS: 357 case NL80211_IFTYPE_WDS:
362 add_wds_files(sdata); 358 add_wds_files(sdata);
363 break; 359 break;
364 case IEEE80211_IF_TYPE_MNTR: 360 case NL80211_IFTYPE_MONITOR:
365 add_monitor_files(sdata); 361 add_monitor_files(sdata);
366 break; 362 break;
367 case IEEE80211_IF_TYPE_VLAN: 363 case NL80211_IFTYPE_AP_VLAN:
368 add_vlan_files(sdata); 364 add_vlan_files(sdata);
369 break; 365 break;
370 default: 366 default:
@@ -398,7 +394,6 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
398 DEBUGFS_DEL(auth_alg, sta); 394 DEBUGFS_DEL(auth_alg, sta);
399 DEBUGFS_DEL(auth_transaction, sta); 395 DEBUGFS_DEL(auth_transaction, sta);
400 DEBUGFS_DEL(flags, sta); 396 DEBUGFS_DEL(flags, sta);
401 DEBUGFS_DEL(num_beacons_sta, sta);
402} 397}
403 398
404static void del_ap_files(struct ieee80211_sub_if_data *sdata) 399static void del_ap_files(struct ieee80211_sub_if_data *sdata)
@@ -409,7 +404,6 @@ static void del_ap_files(struct ieee80211_sub_if_data *sdata)
409 404
410 DEBUGFS_DEL(num_sta_ps, ap); 405 DEBUGFS_DEL(num_sta_ps, ap);
411 DEBUGFS_DEL(dtim_count, ap); 406 DEBUGFS_DEL(dtim_count, ap);
412 DEBUGFS_DEL(num_beacons, ap);
413 DEBUGFS_DEL(num_buffered_multicast, ap); 407 DEBUGFS_DEL(num_buffered_multicast, ap);
414} 408}
415 409
@@ -482,26 +476,26 @@ static void del_files(struct ieee80211_sub_if_data *sdata)
482 return; 476 return;
483 477
484 switch (sdata->vif.type) { 478 switch (sdata->vif.type) {
485 case IEEE80211_IF_TYPE_MESH_POINT: 479 case NL80211_IFTYPE_MESH_POINT:
486#ifdef CONFIG_MAC80211_MESH 480#ifdef CONFIG_MAC80211_MESH
487 del_mesh_stats(sdata); 481 del_mesh_stats(sdata);
488 del_mesh_config(sdata); 482 del_mesh_config(sdata);
489#endif 483#endif
490 /* fall through */ 484 break;
491 case IEEE80211_IF_TYPE_STA: 485 case NL80211_IFTYPE_STATION:
492 case IEEE80211_IF_TYPE_IBSS: 486 case NL80211_IFTYPE_ADHOC:
493 del_sta_files(sdata); 487 del_sta_files(sdata);
494 break; 488 break;
495 case IEEE80211_IF_TYPE_AP: 489 case NL80211_IFTYPE_AP:
496 del_ap_files(sdata); 490 del_ap_files(sdata);
497 break; 491 break;
498 case IEEE80211_IF_TYPE_WDS: 492 case NL80211_IFTYPE_WDS:
499 del_wds_files(sdata); 493 del_wds_files(sdata);
500 break; 494 break;
501 case IEEE80211_IF_TYPE_MNTR: 495 case NL80211_IFTYPE_MONITOR:
502 del_monitor_files(sdata); 496 del_monitor_files(sdata);
503 break; 497 break;
504 case IEEE80211_IF_TYPE_VLAN: 498 case NL80211_IFTYPE_AP_VLAN:
505 del_vlan_files(sdata); 499 del_vlan_files(sdata);
506 break; 500 break;
507 default: 501 default:
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 6abe5427752b..81f350eaf8a3 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -50,7 +50,7 @@ static const struct file_operations sta_ ##name## _ops = { \
50 STA_READ_##format(name, field) \ 50 STA_READ_##format(name, field) \
51 STA_OPS(name) 51 STA_OPS(name)
52 52
53STA_FILE(aid, aid, D); 53STA_FILE(aid, sta.aid, D);
54STA_FILE(dev, sdata->dev->name, S); 54STA_FILE(dev, sdata->dev->name, S);
55STA_FILE(rx_packets, rx_packets, LU); 55STA_FILE(rx_packets, rx_packets, LU);
56STA_FILE(tx_packets, tx_packets, LU); 56STA_FILE(tx_packets, tx_packets, LU);
@@ -176,7 +176,7 @@ static ssize_t sta_agg_status_write(struct file *file,
176 struct net_device *dev = sta->sdata->dev; 176 struct net_device *dev = sta->sdata->dev;
177 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 177 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
178 struct ieee80211_hw *hw = &local->hw; 178 struct ieee80211_hw *hw = &local->hw;
179 u8 *da = sta->addr; 179 u8 *da = sta->sta.addr;
180 static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0, 180 static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
181 0, 0, 0, 0, 0, 0, 0, 0}; 181 0, 0, 0, 0, 0, 0, 0, 0};
182 static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1, 182 static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
@@ -253,7 +253,7 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
253 if (!stations_dir) 253 if (!stations_dir)
254 return; 254 return;
255 255
256 mac = print_mac(mbuf, sta->addr); 256 mac = print_mac(mbuf, sta->sta.addr);
257 257
258 sta->debugfs.dir = debugfs_create_dir(mac, stations_dir); 258 sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
259 if (!sta->debugfs.dir) 259 if (!sta->debugfs.dir)
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index 4dc35c9dabc7..dc7d9a3d70d5 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -89,7 +89,7 @@ static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
89 memset(mgmt, 0, 24); 89 memset(mgmt, 0, 24);
90 memcpy(mgmt->da, da, ETH_ALEN); 90 memcpy(mgmt->da, da, ETH_ALEN);
91 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 91 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
92 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) 92 if (sdata->vif.type == NL80211_IFTYPE_AP)
93 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 93 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
94 else 94 else
95 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); 95 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
@@ -139,7 +139,7 @@ static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *d
139 memset(mgmt, 0, 24); 139 memset(mgmt, 0, 24);
140 memcpy(mgmt->da, da, ETH_ALEN); 140 memcpy(mgmt->da, da, ETH_ALEN);
141 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 141 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
142 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) 142 if (sdata->vif.type == NL80211_IFTYPE_AP)
143 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 143 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
144 else 144 else
145 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); 145 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
@@ -185,7 +185,7 @@ static void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
185 memset(mgmt, 0, 24); 185 memset(mgmt, 0, 24);
186 memcpy(mgmt->da, da, ETH_ALEN); 186 memcpy(mgmt->da, da, ETH_ALEN);
187 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 187 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
188 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) 188 if (sdata->vif.type == NL80211_IFTYPE_AP)
189 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); 189 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
190 else 190 else
191 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); 191 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
@@ -274,7 +274,7 @@ void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *r
274#endif /* CONFIG_MAC80211_HT_DEBUG */ 274#endif /* CONFIG_MAC80211_HT_DEBUG */
275 275
276 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, 276 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
277 ra, tid, NULL); 277 &sta->sta, tid, NULL);
278 if (ret) 278 if (ret)
279 printk(KERN_DEBUG "HW problem - can not stop rx " 279 printk(KERN_DEBUG "HW problem - can not stop rx "
280 "aggregation for tid %d\n", tid); 280 "aggregation for tid %d\n", tid);
@@ -328,7 +328,7 @@ static void sta_addba_resp_timer_expired(unsigned long data)
328 328
329 rcu_read_lock(); 329 rcu_read_lock();
330 330
331 sta = sta_info_get(local, temp_sta->addr); 331 sta = sta_info_get(local, temp_sta->sta.addr);
332 if (!sta) { 332 if (!sta) {
333 rcu_read_unlock(); 333 rcu_read_unlock();
334 return; 334 return;
@@ -354,7 +354,7 @@ static void sta_addba_resp_timer_expired(unsigned long data)
354 /* go through the state check in stop_BA_session */ 354 /* go through the state check in stop_BA_session */
355 *state = HT_AGG_STATE_OPERATIONAL; 355 *state = HT_AGG_STATE_OPERATIONAL;
356 spin_unlock_bh(&sta->lock); 356 spin_unlock_bh(&sta->lock);
357 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid, 357 ieee80211_stop_tx_ba_session(hw, temp_sta->sta.addr, tid,
358 WLAN_BACK_INITIATOR); 358 WLAN_BACK_INITIATOR);
359 359
360timer_expired_exit: 360timer_expired_exit:
@@ -465,7 +465,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
465 465
466 if (local->ops->ampdu_action) 466 if (local->ops->ampdu_action)
467 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, 467 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
468 ra, tid, &start_seq_num); 468 &sta->sta, tid, &start_seq_num);
469 469
470 if (ret) { 470 if (ret) {
471 /* No need to requeue the packets in the agg queue, since we 471 /* No need to requeue the packets in the agg queue, since we
@@ -557,7 +557,7 @@ int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
557 557
558 if (local->ops->ampdu_action) 558 if (local->ops->ampdu_action)
559 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP, 559 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
560 ra, tid, NULL); 560 &sta->sta, tid, NULL);
561 561
562 /* case HW denied going back to legacy */ 562 /* case HW denied going back to legacy */
563 if (ret) { 563 if (ret) {
@@ -767,7 +767,7 @@ static void sta_rx_agg_session_timer_expired(unsigned long data)
767#ifdef CONFIG_MAC80211_HT_DEBUG 767#ifdef CONFIG_MAC80211_HT_DEBUG
768 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); 768 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
769#endif 769#endif
770 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr, 770 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
771 (u16)*ptid, WLAN_BACK_TIMER, 771 (u16)*ptid, WLAN_BACK_TIMER,
772 WLAN_REASON_QSTA_TIMEOUT); 772 WLAN_REASON_QSTA_TIMEOUT);
773} 773}
@@ -874,7 +874,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
874 874
875 if (local->ops->ampdu_action) 875 if (local->ops->ampdu_action)
876 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, 876 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
877 sta->addr, tid, &start_seq_num); 877 &sta->sta, tid, &start_seq_num);
878#ifdef CONFIG_MAC80211_HT_DEBUG 878#ifdef CONFIG_MAC80211_HT_DEBUG
879 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret); 879 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
880#endif /* CONFIG_MAC80211_HT_DEBUG */ 880#endif /* CONFIG_MAC80211_HT_DEBUG */
@@ -899,7 +899,7 @@ end:
899 spin_unlock_bh(&sta->lock); 899 spin_unlock_bh(&sta->lock);
900 900
901end_no_lock: 901end_no_lock:
902 ieee80211_send_addba_resp(sta->sdata, sta->addr, tid, 902 ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
903 dialog_token, status, 1, buf_size, timeout); 903 dialog_token, status, 1, buf_size, timeout);
904} 904}
905 905
@@ -952,7 +952,7 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
952 /* this will allow the state check in stop_BA_session */ 952 /* this will allow the state check in stop_BA_session */
953 *state = HT_AGG_STATE_OPERATIONAL; 953 *state = HT_AGG_STATE_OPERATIONAL;
954 spin_unlock_bh(&sta->lock); 954 spin_unlock_bh(&sta->lock);
955 ieee80211_stop_tx_ba_session(hw, sta->addr, tid, 955 ieee80211_stop_tx_ba_session(hw, sta->sta.addr, tid,
956 WLAN_BACK_INITIATOR); 956 WLAN_BACK_INITIATOR);
957 } 957 }
958} 958}
@@ -979,14 +979,14 @@ void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
979#endif /* CONFIG_MAC80211_HT_DEBUG */ 979#endif /* CONFIG_MAC80211_HT_DEBUG */
980 980
981 if (initiator == WLAN_BACK_INITIATOR) 981 if (initiator == WLAN_BACK_INITIATOR)
982 ieee80211_sta_stop_rx_ba_session(sdata, sta->addr, tid, 982 ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid,
983 WLAN_BACK_INITIATOR, 0); 983 WLAN_BACK_INITIATOR, 0);
984 else { /* WLAN_BACK_RECIPIENT */ 984 else { /* WLAN_BACK_RECIPIENT */
985 spin_lock_bh(&sta->lock); 985 spin_lock_bh(&sta->lock);
986 sta->ampdu_mlme.tid_state_tx[tid] = 986 sta->ampdu_mlme.tid_state_tx[tid] =
987 HT_AGG_STATE_OPERATIONAL; 987 HT_AGG_STATE_OPERATIONAL;
988 spin_unlock_bh(&sta->lock); 988 spin_unlock_bh(&sta->lock);
989 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid, 989 ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
990 WLAN_BACK_RECIPIENT); 990 WLAN_BACK_RECIPIENT);
991 } 991 }
992} 992}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 6f334e4c3d66..3912fba6d3d0 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -29,9 +29,6 @@
29#include "key.h" 29#include "key.h"
30#include "sta_info.h" 30#include "sta_info.h"
31 31
32/* ieee80211.o internal definitions, etc. These are not included into
33 * low-level drivers. */
34
35struct ieee80211_local; 32struct ieee80211_local;
36 33
37/* Maximum number of broadcast/multicast frames to buffer when some of the 34/* Maximum number of broadcast/multicast frames to buffer when some of the
@@ -71,9 +68,9 @@ struct ieee80211_fragment_entry {
71}; 68};
72 69
73 70
74struct ieee80211_sta_bss { 71struct ieee80211_bss {
75 struct list_head list; 72 struct list_head list;
76 struct ieee80211_sta_bss *hnext; 73 struct ieee80211_bss *hnext;
77 size_t ssid_len; 74 size_t ssid_len;
78 75
79 atomic_t users; 76 atomic_t users;
@@ -112,7 +109,7 @@ struct ieee80211_sta_bss {
112 u8 erp_value; 109 u8 erp_value;
113}; 110};
114 111
115static inline u8 *bss_mesh_cfg(struct ieee80211_sta_bss *bss) 112static inline u8 *bss_mesh_cfg(struct ieee80211_bss *bss)
116{ 113{
117#ifdef CONFIG_MAC80211_MESH 114#ifdef CONFIG_MAC80211_MESH
118 return bss->mesh_cfg; 115 return bss->mesh_cfg;
@@ -120,7 +117,7 @@ static inline u8 *bss_mesh_cfg(struct ieee80211_sta_bss *bss)
120 return NULL; 117 return NULL;
121} 118}
122 119
123static inline u8 *bss_mesh_id(struct ieee80211_sta_bss *bss) 120static inline u8 *bss_mesh_id(struct ieee80211_bss *bss)
124{ 121{
125#ifdef CONFIG_MAC80211_MESH 122#ifdef CONFIG_MAC80211_MESH
126 return bss->mesh_id; 123 return bss->mesh_id;
@@ -128,7 +125,7 @@ static inline u8 *bss_mesh_id(struct ieee80211_sta_bss *bss)
128 return NULL; 125 return NULL;
129} 126}
130 127
131static inline u8 bss_mesh_id_len(struct ieee80211_sta_bss *bss) 128static inline u8 bss_mesh_id_len(struct ieee80211_bss *bss)
132{ 129{
133#ifdef CONFIG_MAC80211_MESH 130#ifdef CONFIG_MAC80211_MESH
134 return bss->mesh_id_len; 131 return bss->mesh_id_len;
@@ -232,7 +229,6 @@ struct ieee80211_if_ap {
232 struct sk_buff_head ps_bc_buf; 229 struct sk_buff_head ps_bc_buf;
233 atomic_t num_sta_ps; /* number of stations in PS mode */ 230 atomic_t num_sta_ps; /* number of stations in PS mode */
234 int dtim_count; 231 int dtim_count;
235 int num_beacons; /* number of TXed beacon frames for this BSS */
236}; 232};
237 233
238struct ieee80211_if_wds { 234struct ieee80211_if_wds {
@@ -293,13 +289,13 @@ struct mesh_config {
293#define IEEE80211_STA_AUTO_BSSID_SEL BIT(11) 289#define IEEE80211_STA_AUTO_BSSID_SEL BIT(11)
294#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12) 290#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12)
295#define IEEE80211_STA_PRIVACY_INVOKED BIT(13) 291#define IEEE80211_STA_PRIVACY_INVOKED BIT(13)
296/* flags for MLME request*/ 292/* flags for MLME request */
297#define IEEE80211_STA_REQ_SCAN 0 293#define IEEE80211_STA_REQ_SCAN 0
298#define IEEE80211_STA_REQ_DIRECT_PROBE 1 294#define IEEE80211_STA_REQ_DIRECT_PROBE 1
299#define IEEE80211_STA_REQ_AUTH 2 295#define IEEE80211_STA_REQ_AUTH 2
300#define IEEE80211_STA_REQ_RUN 3 296#define IEEE80211_STA_REQ_RUN 3
301 297
302/* flags used for setting mlme state */ 298/* STA/IBSS MLME states */
303enum ieee80211_sta_mlme_state { 299enum ieee80211_sta_mlme_state {
304 IEEE80211_STA_MLME_DISABLED, 300 IEEE80211_STA_MLME_DISABLED,
305 IEEE80211_STA_MLME_DIRECT_PROBE, 301 IEEE80211_STA_MLME_DIRECT_PROBE,
@@ -308,7 +304,6 @@ enum ieee80211_sta_mlme_state {
308 IEEE80211_STA_MLME_ASSOCIATED, 304 IEEE80211_STA_MLME_ASSOCIATED,
309 IEEE80211_STA_MLME_IBSS_SEARCH, 305 IEEE80211_STA_MLME_IBSS_SEARCH,
310 IEEE80211_STA_MLME_IBSS_JOINED, 306 IEEE80211_STA_MLME_IBSS_JOINED,
311 IEEE80211_STA_MLME_MESH_UP
312}; 307};
313 308
314/* bitfield of allowed auth algs */ 309/* bitfield of allowed auth algs */
@@ -325,34 +320,6 @@ struct ieee80211_if_sta {
325 size_t ssid_len; 320 size_t ssid_len;
326 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 321 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
327 size_t scan_ssid_len; 322 size_t scan_ssid_len;
328#ifdef CONFIG_MAC80211_MESH
329 struct timer_list mesh_path_timer;
330 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
331 size_t mesh_id_len;
332 /* Active Path Selection Protocol Identifier */
333 u8 mesh_pp_id[4];
334 /* Active Path Selection Metric Identifier */
335 u8 mesh_pm_id[4];
336 /* Congestion Control Mode Identifier */
337 u8 mesh_cc_id[4];
338 /* Local mesh Destination Sequence Number */
339 u32 dsn;
340 /* Last used PREQ ID */
341 u32 preq_id;
342 atomic_t mpaths;
343 /* Timestamp of last DSN update */
344 unsigned long last_dsn_update;
345 /* Timestamp of last DSN sent */
346 unsigned long last_preq;
347 struct mesh_rmc *rmc;
348 spinlock_t mesh_preq_queue_lock;
349 struct mesh_preq_queue preq_queue;
350 int preq_queue_len;
351 struct mesh_stats mshstats;
352 struct mesh_config mshcfg;
353 u32 mesh_seqnum;
354 bool accepting_plinks;
355#endif
356 u16 aid; 323 u16 aid;
357 u16 ap_capab, capab; 324 u16 ap_capab, capab;
358 u8 *extra_ie; /* to be added to the end of AssocReq */ 325 u8 *extra_ie; /* to be added to the end of AssocReq */
@@ -384,31 +351,70 @@ struct ieee80211_if_sta {
384 u32 supp_rates_bits[IEEE80211_NUM_BANDS]; 351 u32 supp_rates_bits[IEEE80211_NUM_BANDS];
385 352
386 int wmm_last_param_set; 353 int wmm_last_param_set;
387 int num_beacons; /* number of TXed beacon frames by this STA */
388}; 354};
389 355
390static inline void ieee80211_if_sta_set_mesh_id(struct ieee80211_if_sta *ifsta, 356struct ieee80211_if_mesh {
391 u8 mesh_id_len, u8 *mesh_id) 357 struct work_struct work;
392{ 358 struct timer_list housekeeping_timer;
393#ifdef CONFIG_MAC80211_MESH 359 struct timer_list mesh_path_timer;
394 ifsta->mesh_id_len = mesh_id_len; 360 struct sk_buff_head skb_queue;
395 memcpy(ifsta->mesh_id, mesh_id, mesh_id_len); 361
396#endif 362 bool housekeeping;
397} 363
364 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
365 size_t mesh_id_len;
366 /* Active Path Selection Protocol Identifier */
367 u8 mesh_pp_id[4];
368 /* Active Path Selection Metric Identifier */
369 u8 mesh_pm_id[4];
370 /* Congestion Control Mode Identifier */
371 u8 mesh_cc_id[4];
372 /* Local mesh Destination Sequence Number */
373 u32 dsn;
374 /* Last used PREQ ID */
375 u32 preq_id;
376 atomic_t mpaths;
377 /* Timestamp of last DSN update */
378 unsigned long last_dsn_update;
379 /* Timestamp of last DSN sent */
380 unsigned long last_preq;
381 struct mesh_rmc *rmc;
382 spinlock_t mesh_preq_queue_lock;
383 struct mesh_preq_queue preq_queue;
384 int preq_queue_len;
385 struct mesh_stats mshstats;
386 struct mesh_config mshcfg;
387 u32 mesh_seqnum;
388 bool accepting_plinks;
389};
398 390
399#ifdef CONFIG_MAC80211_MESH 391#ifdef CONFIG_MAC80211_MESH
400#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \ 392#define IEEE80211_IFSTA_MESH_CTR_INC(msh, name) \
401 do { (sta)->mshstats.name++; } while (0) 393 do { (msh)->mshstats.name++; } while (0)
402#else 394#else
403#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \ 395#define IEEE80211_IFSTA_MESH_CTR_INC(msh, name) \
404 do { } while (0) 396 do { } while (0)
405#endif 397#endif
406 398
407/* flags used in struct ieee80211_sub_if_data.flags */ 399/**
408#define IEEE80211_SDATA_ALLMULTI BIT(0) 400 * enum ieee80211_sub_if_data_flags - virtual interface flags
409#define IEEE80211_SDATA_PROMISC BIT(1) 401 *
410#define IEEE80211_SDATA_USERSPACE_MLME BIT(2) 402 * @IEEE80211_SDATA_ALLMULTI: interface wants all multicast packets
411#define IEEE80211_SDATA_OPERATING_GMODE BIT(3) 403 * @IEEE80211_SDATA_PROMISC: interface is promisc
404 * @IEEE80211_SDATA_USERSPACE_MLME: userspace MLME is active
405 * @IEEE80211_SDATA_OPERATING_GMODE: operating in G-only mode
406 * @IEEE80211_SDATA_DONT_BRIDGE_PACKETS: bridge packets between
407 * associated stations and deliver multicast frames both
408 * back to wireless media and to the local net stack.
409 */
410enum ieee80211_sub_if_data_flags {
411 IEEE80211_SDATA_ALLMULTI = BIT(0),
412 IEEE80211_SDATA_PROMISC = BIT(1),
413 IEEE80211_SDATA_USERSPACE_MLME = BIT(2),
414 IEEE80211_SDATA_OPERATING_GMODE = BIT(3),
415 IEEE80211_SDATA_DONT_BRIDGE_PACKETS = BIT(4),
416};
417
412struct ieee80211_sub_if_data { 418struct ieee80211_sub_if_data {
413 struct list_head list; 419 struct list_head list;
414 420
@@ -424,11 +430,6 @@ struct ieee80211_sub_if_data {
424 430
425 int drop_unencrypted; 431 int drop_unencrypted;
426 432
427 /*
428 * basic rates of this AP or the AP we're associated to
429 */
430 u64 basic_rates;
431
432 /* Fragment table for host-based reassembly */ 433 /* Fragment table for host-based reassembly */
433 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX]; 434 struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
434 unsigned int fragment_next; 435 unsigned int fragment_next;
@@ -455,6 +456,9 @@ struct ieee80211_sub_if_data {
455 struct ieee80211_if_wds wds; 456 struct ieee80211_if_wds wds;
456 struct ieee80211_if_vlan vlan; 457 struct ieee80211_if_vlan vlan;
457 struct ieee80211_if_sta sta; 458 struct ieee80211_if_sta sta;
459#ifdef CONFIG_MAC80211_MESH
460 struct ieee80211_if_mesh mesh;
461#endif
458 u32 mntr_flags; 462 u32 mntr_flags;
459 } u; 463 } u;
460 464
@@ -477,7 +481,6 @@ struct ieee80211_sub_if_data {
477 struct dentry *auth_alg; 481 struct dentry *auth_alg;
478 struct dentry *auth_transaction; 482 struct dentry *auth_transaction;
479 struct dentry *flags; 483 struct dentry *flags;
480 struct dentry *num_beacons_sta;
481 struct dentry *force_unicast_rateidx; 484 struct dentry *force_unicast_rateidx;
482 struct dentry *max_ratectrl_rateidx; 485 struct dentry *max_ratectrl_rateidx;
483 } sta; 486 } sta;
@@ -485,7 +488,6 @@ struct ieee80211_sub_if_data {
485 struct dentry *drop_unencrypted; 488 struct dentry *drop_unencrypted;
486 struct dentry *num_sta_ps; 489 struct dentry *num_sta_ps;
487 struct dentry *dtim_count; 490 struct dentry *dtim_count;
488 struct dentry *num_beacons;
489 struct dentry *force_unicast_rateidx; 491 struct dentry *force_unicast_rateidx;
490 struct dentry *max_ratectrl_rateidx; 492 struct dentry *max_ratectrl_rateidx;
491 struct dentry *num_buffered_multicast; 493 struct dentry *num_buffered_multicast;
@@ -548,6 +550,19 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
548 return container_of(p, struct ieee80211_sub_if_data, vif); 550 return container_of(p, struct ieee80211_sub_if_data, vif);
549} 551}
550 552
553static inline void
554ieee80211_sdata_set_mesh_id(struct ieee80211_sub_if_data *sdata,
555 u8 mesh_id_len, u8 *mesh_id)
556{
557#ifdef CONFIG_MAC80211_MESH
558 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
559 ifmsh->mesh_id_len = mesh_id_len;
560 memcpy(ifmsh->mesh_id, mesh_id, mesh_id_len);
561#else
562 WARN_ON(1);
563#endif
564}
565
551enum { 566enum {
552 IEEE80211_RX_MSG = 1, 567 IEEE80211_RX_MSG = 1,
553 IEEE80211_TX_STATUS_MSG = 2, 568 IEEE80211_TX_STATUS_MSG = 2,
@@ -621,10 +636,6 @@ struct ieee80211_local {
621 struct crypto_blkcipher *wep_rx_tfm; 636 struct crypto_blkcipher *wep_rx_tfm;
622 u32 wep_iv; 637 u32 wep_iv;
623 638
624 int bridge_packets; /* bridge packets between associated stations and
625 * deliver multicast frames both back to wireless
626 * media and to the local net stack */
627
628 struct list_head interfaces; 639 struct list_head interfaces;
629 640
630 /* 641 /*
@@ -634,8 +645,8 @@ struct ieee80211_local {
634 spinlock_t key_lock; 645 spinlock_t key_lock;
635 646
636 647
637 bool sta_sw_scanning; 648 /* Scanning and BSS list */
638 bool sta_hw_scanning; 649 bool sw_scanning, hw_scanning;
639 int scan_channel_idx; 650 int scan_channel_idx;
640 enum ieee80211_band scan_band; 651 enum ieee80211_band scan_band;
641 652
@@ -646,9 +657,9 @@ struct ieee80211_local {
646 struct ieee80211_channel *oper_channel, *scan_channel; 657 struct ieee80211_channel *oper_channel, *scan_channel;
647 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 658 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
648 size_t scan_ssid_len; 659 size_t scan_ssid_len;
649 struct list_head sta_bss_list; 660 struct list_head bss_list;
650 struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE]; 661 struct ieee80211_bss *bss_hash[STA_HASH_SIZE];
651 spinlock_t sta_bss_lock; 662 spinlock_t bss_lock;
652 663
653 /* SNMP counters */ 664 /* SNMP counters */
654 /* dot11CountersTable */ 665 /* dot11CountersTable */
@@ -712,7 +723,6 @@ struct ieee80211_local {
712 struct dentry *frequency; 723 struct dentry *frequency;
713 struct dentry *antenna_sel_tx; 724 struct dentry *antenna_sel_tx;
714 struct dentry *antenna_sel_rx; 725 struct dentry *antenna_sel_rx;
715 struct dentry *bridge_packets;
716 struct dentry *rts_threshold; 726 struct dentry *rts_threshold;
717 struct dentry *fragmentation_threshold; 727 struct dentry *fragmentation_threshold;
718 struct dentry *short_retry_limit; 728 struct dentry *short_retry_limit;
@@ -868,87 +878,81 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
868} 878}
869 879
870 880
871/* ieee80211.c */
872int ieee80211_hw_config(struct ieee80211_local *local); 881int ieee80211_hw_config(struct ieee80211_local *local);
873int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed); 882int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed);
874void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx); 883void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
875u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht, 884u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
876 struct ieee80211_ht_info *req_ht_cap, 885 struct ieee80211_ht_info *req_ht_cap,
877 struct ieee80211_ht_bss_info *req_bss_cap); 886 struct ieee80211_ht_bss_info *req_bss_cap);
887void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
888 u32 changed);
889void ieee80211_configure_filter(struct ieee80211_local *local);
878 890
879/* ieee80211_ioctl.c */ 891/* wireless extensions */
880extern const struct iw_handler_def ieee80211_iw_handler_def; 892extern const struct iw_handler_def ieee80211_iw_handler_def;
881int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
882 893
883/* ieee80211_sta.c */ 894/* STA/IBSS code */
884void ieee80211_sta_timer(unsigned long data); 895void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata);
885void ieee80211_sta_work(struct work_struct *work); 896void ieee80211_scan_work(struct work_struct *work);
886void ieee80211_sta_scan_work(struct work_struct *work);
887void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 897void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
888 struct ieee80211_rx_status *rx_status); 898 struct ieee80211_rx_status *rx_status);
889int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len); 899int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len);
890int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len); 900int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len);
891int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid); 901int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
892int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len);
893void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata, 902void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
894 struct ieee80211_if_sta *ifsta); 903 struct ieee80211_if_sta *ifsta);
895int ieee80211_sta_scan_results(struct ieee80211_local *local,
896 struct iw_request_info *info,
897 char *buf, size_t len);
898ieee80211_rx_result ieee80211_sta_rx_scan(
899 struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
900 struct ieee80211_rx_status *rx_status);
901void ieee80211_rx_bss_list_init(struct ieee80211_local *local);
902void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local);
903int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len);
904struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 904struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
905 struct sk_buff *skb, u8 *bssid, 905 struct sk_buff *skb, u8 *bssid,
906 u8 *addr, u64 supp_rates); 906 u8 *addr, u64 supp_rates);
907int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason); 907int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason);
908int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason); 908int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
909void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
910 u32 changed);
911u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata); 909u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata);
912u64 ieee80211_sta_get_rates(struct ieee80211_local *local, 910u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
913 struct ieee802_11_elems *elems, 911 struct ieee802_11_elems *elems,
914 enum ieee80211_band band); 912 enum ieee80211_band band);
915void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 913void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
916 u8 *ssid, size_t ssid_len); 914 u8 *ssid, size_t ssid_len);
917void ieee802_11_parse_elems(u8 *start, size_t len, 915
918 struct ieee802_11_elems *elems); 916/* scan/BSS handling */
917int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
918 u8 *ssid, size_t ssid_len);
919int ieee80211_scan_results(struct ieee80211_local *local,
920 struct iw_request_info *info,
921 char *buf, size_t len);
922ieee80211_rx_result
923ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata,
924 struct sk_buff *skb,
925 struct ieee80211_rx_status *rx_status);
926void ieee80211_rx_bss_list_init(struct ieee80211_local *local);
927void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local);
928int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
929 char *ie, size_t len);
930
919void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); 931void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
920int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, 932int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
921 u8 *ssid, size_t ssid_len); 933 u8 *ssid, size_t ssid_len);
922struct ieee80211_sta_bss * 934struct ieee80211_bss *
923ieee80211_bss_info_update(struct ieee80211_local *local, 935ieee80211_bss_info_update(struct ieee80211_local *local,
924 struct ieee80211_rx_status *rx_status, 936 struct ieee80211_rx_status *rx_status,
925 struct ieee80211_mgmt *mgmt, 937 struct ieee80211_mgmt *mgmt,
926 size_t len, 938 size_t len,
927 struct ieee802_11_elems *elems, 939 struct ieee802_11_elems *elems,
928 int freq, bool beacon); 940 int freq, bool beacon);
929struct ieee80211_sta_bss * 941struct ieee80211_bss *
930ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, 942ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq,
931 u8 *ssid, u8 ssid_len); 943 u8 *ssid, u8 ssid_len);
932struct ieee80211_sta_bss * 944struct ieee80211_bss *
933ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, 945ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
934 u8 *ssid, u8 ssid_len); 946 u8 *ssid, u8 ssid_len);
935void ieee80211_rx_bss_put(struct ieee80211_local *local, 947void ieee80211_rx_bss_put(struct ieee80211_local *local,
936 struct ieee80211_sta_bss *bss); 948 struct ieee80211_bss *bss);
937
938#ifdef CONFIG_MAC80211_MESH
939void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
940#else
941static inline void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
942{}
943#endif
944 949
945/* interface handling */ 950/* interface handling */
946void ieee80211_if_setup(struct net_device *dev);
947int ieee80211_if_add(struct ieee80211_local *local, const char *name, 951int ieee80211_if_add(struct ieee80211_local *local, const char *name,
948 struct net_device **new_dev, enum ieee80211_if_types type, 952 struct net_device **new_dev, enum nl80211_iftype type,
949 struct vif_params *params); 953 struct vif_params *params);
950int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, 954int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
951 enum ieee80211_if_types type); 955 enum nl80211_iftype type);
952void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata); 956void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata);
953void ieee80211_remove_interfaces(struct ieee80211_local *local); 957void ieee80211_remove_interfaces(struct ieee80211_local *local);
954 958
@@ -992,7 +996,7 @@ extern void *mac80211_wiphy_privid; /* for wiphy privid */
992extern const unsigned char rfc1042_header[6]; 996extern const unsigned char rfc1042_header[6];
993extern const unsigned char bridge_tunnel_header[6]; 997extern const unsigned char bridge_tunnel_header[6];
994u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 998u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
995 enum ieee80211_if_types type); 999 enum nl80211_iftype type);
996int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1000int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
997 int rate, int erp, int short_preamble); 1001 int rate, int erp, int short_preamble);
998void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1002void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
@@ -1000,6 +1004,11 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
1000void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1004void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1001void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1005void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1002 int encrypt); 1006 int encrypt);
1007void ieee802_11_parse_elems(u8 *start, size_t len,
1008 struct ieee802_11_elems *elems);
1009int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
1010u64 ieee80211_mandatory_rates(struct ieee80211_local *local,
1011 enum ieee80211_band band);
1003 1012
1004#ifdef CONFIG_MAC80211_NOINLINE 1013#ifdef CONFIG_MAC80211_NOINLINE
1005#define debug_noinline noinline 1014#define debug_noinline noinline
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 672cec60a2fb..a72fbebb8ea2 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1,4 +1,6 @@
1/* 1/*
2 * Interface handling (except master interface)
3 *
2 * Copyright 2002-2005, Instant802 Networks, Inc. 4 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc. 5 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> 6 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
@@ -17,7 +19,540 @@
17#include "sta_info.h" 19#include "sta_info.h"
18#include "debugfs_netdev.h" 20#include "debugfs_netdev.h"
19#include "mesh.h" 21#include "mesh.h"
22#include "led.h"
23
24static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
25{
26 int meshhdrlen;
27 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28
29 meshhdrlen = (sdata->vif.type == NL80211_IFTYPE_MESH_POINT) ? 5 : 0;
30
31 /* FIX: what would be proper limits for MTU?
32 * This interface uses 802.3 frames. */
33 if (new_mtu < 256 ||
34 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
35 return -EINVAL;
36 }
37
38#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
39 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
40#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
41 dev->mtu = new_mtu;
42 return 0;
43}
44
45static inline int identical_mac_addr_allowed(int type1, int type2)
46{
47 return type1 == NL80211_IFTYPE_MONITOR ||
48 type2 == NL80211_IFTYPE_MONITOR ||
49 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_WDS) ||
50 (type1 == NL80211_IFTYPE_WDS &&
51 (type2 == NL80211_IFTYPE_WDS ||
52 type2 == NL80211_IFTYPE_AP)) ||
53 (type1 == NL80211_IFTYPE_AP && type2 == NL80211_IFTYPE_AP_VLAN) ||
54 (type1 == NL80211_IFTYPE_AP_VLAN &&
55 (type2 == NL80211_IFTYPE_AP ||
56 type2 == NL80211_IFTYPE_AP_VLAN));
57}
58
59static int ieee80211_open(struct net_device *dev)
60{
61 struct ieee80211_sub_if_data *sdata, *nsdata;
62 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
63 struct sta_info *sta;
64 struct ieee80211_if_init_conf conf;
65 u32 changed = 0;
66 int res;
67 bool need_hw_reconfig = 0;
68 u8 null_addr[ETH_ALEN] = {0};
69
70 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
71
72 /* fail early if user set an invalid address */
73 if (compare_ether_addr(dev->dev_addr, null_addr) &&
74 !is_valid_ether_addr(dev->dev_addr))
75 return -EADDRNOTAVAIL;
76
77 /* we hold the RTNL here so can safely walk the list */
78 list_for_each_entry(nsdata, &local->interfaces, list) {
79 struct net_device *ndev = nsdata->dev;
80
81 if (ndev != dev && netif_running(ndev)) {
82 /*
83 * Allow only a single IBSS interface to be up at any
84 * time. This is restricted because beacon distribution
85 * cannot work properly if both are in the same IBSS.
86 *
87 * To remove this restriction we'd have to disallow them
88 * from setting the same SSID on different IBSS interfaces
89 * belonging to the same hardware. Then, however, we're
90 * faced with having to adopt two different TSF timers...
91 */
92 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
93 nsdata->vif.type == NL80211_IFTYPE_ADHOC)
94 return -EBUSY;
95
96 /*
97 * The remaining checks are only performed for interfaces
98 * with the same MAC address.
99 */
100 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
101 continue;
102
103 /*
104 * check whether it may have the same address
105 */
106 if (!identical_mac_addr_allowed(sdata->vif.type,
107 nsdata->vif.type))
108 return -ENOTUNIQ;
109
110 /*
111 * can only add VLANs to enabled APs
112 */
113 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
114 nsdata->vif.type == NL80211_IFTYPE_AP)
115 sdata->bss = &nsdata->u.ap;
116 }
117 }
118
119 switch (sdata->vif.type) {
120 case NL80211_IFTYPE_WDS:
121 if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
122 return -ENOLINK;
123 break;
124 case NL80211_IFTYPE_AP_VLAN:
125 if (!sdata->bss)
126 return -ENOLINK;
127 list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
128 break;
129 case NL80211_IFTYPE_AP:
130 sdata->bss = &sdata->u.ap;
131 break;
132 case NL80211_IFTYPE_MESH_POINT:
133 if (!ieee80211_vif_is_mesh(&sdata->vif))
134 break;
135 /* mesh ifaces must set allmulti to forward mcast traffic */
136 atomic_inc(&local->iff_allmultis);
137 break;
138 case NL80211_IFTYPE_STATION:
139 case NL80211_IFTYPE_MONITOR:
140 case NL80211_IFTYPE_ADHOC:
141 /* no special treatment */
142 break;
143 case NL80211_IFTYPE_UNSPECIFIED:
144 case __NL80211_IFTYPE_AFTER_LAST:
145 /* cannot happen */
146 WARN_ON(1);
147 break;
148 }
149
150 if (local->open_count == 0) {
151 res = 0;
152 if (local->ops->start)
153 res = local->ops->start(local_to_hw(local));
154 if (res)
155 goto err_del_bss;
156 need_hw_reconfig = 1;
157 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
158 }
159
160 /*
161 * Check all interfaces and copy the hopefully now-present
162 * MAC address to those that have the special null one.
163 */
164 list_for_each_entry(nsdata, &local->interfaces, list) {
165 struct net_device *ndev = nsdata->dev;
166
167 /*
168 * No need to check netif_running since we do not allow
169 * it to start up with this invalid address.
170 */
171 if (compare_ether_addr(null_addr, ndev->dev_addr) == 0)
172 memcpy(ndev->dev_addr,
173 local->hw.wiphy->perm_addr,
174 ETH_ALEN);
175 }
176
177 if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0)
178 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr,
179 ETH_ALEN);
180
181 /*
182 * Validate the MAC address for this device.
183 */
184 if (!is_valid_ether_addr(dev->dev_addr)) {
185 if (!local->open_count && local->ops->stop)
186 local->ops->stop(local_to_hw(local));
187 return -EADDRNOTAVAIL;
188 }
189
190 switch (sdata->vif.type) {
191 case NL80211_IFTYPE_AP_VLAN:
192 /* no need to tell driver */
193 break;
194 case NL80211_IFTYPE_MONITOR:
195 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
196 local->cooked_mntrs++;
197 break;
198 }
199
200 /* must be before the call to ieee80211_configure_filter */
201 local->monitors++;
202 if (local->monitors == 1)
203 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
204
205 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
206 local->fif_fcsfail++;
207 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
208 local->fif_plcpfail++;
209 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
210 local->fif_control++;
211 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
212 local->fif_other_bss++;
213
214 netif_addr_lock_bh(local->mdev);
215 ieee80211_configure_filter(local);
216 netif_addr_unlock_bh(local->mdev);
217 break;
218 case NL80211_IFTYPE_STATION:
219 case NL80211_IFTYPE_ADHOC:
220 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
221 /* fall through */
222 default:
223 conf.vif = &sdata->vif;
224 conf.type = sdata->vif.type;
225 conf.mac_addr = dev->dev_addr;
226 res = local->ops->add_interface(local_to_hw(local), &conf);
227 if (res)
228 goto err_stop;
229
230 if (ieee80211_vif_is_mesh(&sdata->vif))
231 ieee80211_start_mesh(sdata);
232 changed |= ieee80211_reset_erp_info(sdata);
233 ieee80211_bss_info_change_notify(sdata, changed);
234 ieee80211_enable_keys(sdata);
235
236 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
237 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
238 netif_carrier_off(dev);
239 else
240 netif_carrier_on(dev);
241 }
242
243 if (sdata->vif.type == NL80211_IFTYPE_WDS) {
244 /* Create STA entry for the WDS peer */
245 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
246 GFP_KERNEL);
247 if (!sta) {
248 res = -ENOMEM;
249 goto err_del_interface;
250 }
251
252 /* no locking required since STA is not live yet */
253 sta->flags |= WLAN_STA_AUTHORIZED;
254
255 res = sta_info_insert(sta);
256 if (res) {
257 /* STA has been freed */
258 goto err_del_interface;
259 }
260 }
20 261
262 if (local->open_count == 0) {
263 res = dev_open(local->mdev);
264 WARN_ON(res);
265 if (res)
266 goto err_del_interface;
267 tasklet_enable(&local->tx_pending_tasklet);
268 tasklet_enable(&local->tasklet);
269 }
270
271 /*
272 * set_multicast_list will be invoked by the networking core
273 * which will check whether any increments here were done in
274 * error and sync them down to the hardware as filter flags.
275 */
276 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
277 atomic_inc(&local->iff_allmultis);
278
279 if (sdata->flags & IEEE80211_SDATA_PROMISC)
280 atomic_inc(&local->iff_promiscs);
281
282 local->open_count++;
283 if (need_hw_reconfig) {
284 ieee80211_hw_config(local);
285 /*
286 * set default queue parameters so drivers don't
287 * need to initialise the hardware if the hardware
288 * doesn't start up with sane defaults
289 */
290 ieee80211_set_wmm_default(sdata);
291 }
292
293 /*
294 * ieee80211_sta_work is disabled while network interface
295 * is down. Therefore, some configuration changes may not
296 * yet be effective. Trigger execution of ieee80211_sta_work
297 * to fix this.
298 */
299 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
300 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
301 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
302 queue_work(local->hw.workqueue, &ifsta->work);
303 }
304
305 netif_tx_start_all_queues(dev);
306
307 return 0;
308 err_del_interface:
309 local->ops->remove_interface(local_to_hw(local), &conf);
310 err_stop:
311 if (!local->open_count && local->ops->stop)
312 local->ops->stop(local_to_hw(local));
313 err_del_bss:
314 sdata->bss = NULL;
315 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
316 list_del(&sdata->u.vlan.list);
317 return res;
318}
319
320static int ieee80211_stop(struct net_device *dev)
321{
322 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
323 struct ieee80211_local *local = sdata->local;
324 struct ieee80211_if_init_conf conf;
325 struct sta_info *sta;
326
327 /*
328 * Stop TX on this interface first.
329 */
330 netif_tx_stop_all_queues(dev);
331
332 /*
333 * Now delete all active aggregation sessions.
334 */
335 rcu_read_lock();
336
337 list_for_each_entry_rcu(sta, &local->sta_list, list) {
338 if (sta->sdata == sdata)
339 ieee80211_sta_tear_down_BA_sessions(sdata,
340 sta->sta.addr);
341 }
342
343 rcu_read_unlock();
344
345 /*
346 * Remove all stations associated with this interface.
347 *
348 * This must be done before calling ops->remove_interface()
349 * because otherwise we can later invoke ops->sta_notify()
350 * whenever the STAs are removed, and that invalidates driver
351 * assumptions about always getting a vif pointer that is valid
352 * (because if we remove a STA after ops->remove_interface()
353 * the driver will have removed the vif info already!)
354 *
355 * We could relax this and only unlink the stations from the
356 * hash table and list but keep them on a per-sdata list that
357 * will be inserted back again when the interface is brought
358 * up again, but I don't currently see a use case for that,
359 * except with WDS which gets a STA entry created when it is
360 * brought up.
361 */
362 sta_info_flush(local, sdata);
363
364 /*
365 * Don't count this interface for promisc/allmulti while it
366 * is down. dev_mc_unsync() will invoke set_multicast_list
367 * on the master interface which will sync these down to the
368 * hardware as filter flags.
369 */
370 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
371 atomic_dec(&local->iff_allmultis);
372
373 if (sdata->flags & IEEE80211_SDATA_PROMISC)
374 atomic_dec(&local->iff_promiscs);
375
376 dev_mc_unsync(local->mdev, dev);
377
378 /* APs need special treatment */
379 if (sdata->vif.type == NL80211_IFTYPE_AP) {
380 struct ieee80211_sub_if_data *vlan, *tmp;
381 struct beacon_data *old_beacon = sdata->u.ap.beacon;
382
383 /* remove beacon */
384 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
385 synchronize_rcu();
386 kfree(old_beacon);
387
388 /* down all dependent devices, that is VLANs */
389 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
390 u.vlan.list)
391 dev_close(vlan->dev);
392 WARN_ON(!list_empty(&sdata->u.ap.vlans));
393 }
394
395 local->open_count--;
396
397 switch (sdata->vif.type) {
398 case NL80211_IFTYPE_AP_VLAN:
399 list_del(&sdata->u.vlan.list);
400 /* no need to tell driver */
401 break;
402 case NL80211_IFTYPE_MONITOR:
403 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
404 local->cooked_mntrs--;
405 break;
406 }
407
408 local->monitors--;
409 if (local->monitors == 0)
410 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
411
412 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
413 local->fif_fcsfail--;
414 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
415 local->fif_plcpfail--;
416 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
417 local->fif_control--;
418 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
419 local->fif_other_bss--;
420
421 netif_addr_lock_bh(local->mdev);
422 ieee80211_configure_filter(local);
423 netif_addr_unlock_bh(local->mdev);
424 break;
425 case NL80211_IFTYPE_STATION:
426 case NL80211_IFTYPE_ADHOC:
427 sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED;
428 memset(sdata->u.sta.bssid, 0, ETH_ALEN);
429 del_timer_sync(&sdata->u.sta.timer);
430 /*
431 * If the timer fired while we waited for it, it will have
432 * requeued the work. Now the work will be running again
433 * but will not rearm the timer again because it checks
434 * whether the interface is running, which, at this point,
435 * it no longer is.
436 */
437 cancel_work_sync(&sdata->u.sta.work);
438 /*
439 * When we get here, the interface is marked down.
440 * Call synchronize_rcu() to wait for the RX path
441 * should it be using the interface and enqueuing
442 * frames at this very time on another CPU.
443 */
444 synchronize_rcu();
445 skb_queue_purge(&sdata->u.sta.skb_queue);
446
447 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
448 kfree(sdata->u.sta.extra_ie);
449 sdata->u.sta.extra_ie = NULL;
450 sdata->u.sta.extra_ie_len = 0;
451 /* fall through */
452 case NL80211_IFTYPE_MESH_POINT:
453 if (ieee80211_vif_is_mesh(&sdata->vif)) {
454 /* allmulti is always set on mesh ifaces */
455 atomic_dec(&local->iff_allmultis);
456 ieee80211_stop_mesh(sdata);
457 }
458 /* fall through */
459 default:
460 if (local->scan_sdata == sdata) {
461 if (!local->ops->hw_scan)
462 cancel_delayed_work_sync(&local->scan_work);
463 /*
464 * The software scan can no longer run now, so we can
465 * clear out the scan_sdata reference. However, the
466 * hardware scan may still be running. The complete
467 * function must be prepared to handle a NULL value.
468 */
469 local->scan_sdata = NULL;
470 /*
471 * The memory barrier guarantees that another CPU
472 * that is hardware-scanning will now see the fact
473 * that this interface is gone.
474 */
475 smp_mb();
476 /*
477 * If software scanning, complete the scan but since
478 * the scan_sdata is NULL already don't send out a
479 * scan event to userspace -- the scan is incomplete.
480 */
481 if (local->sw_scanning)
482 ieee80211_scan_completed(&local->hw);
483 }
484
485 conf.vif = &sdata->vif;
486 conf.type = sdata->vif.type;
487 conf.mac_addr = dev->dev_addr;
488 /* disable all keys for as long as this netdev is down */
489 ieee80211_disable_keys(sdata);
490 local->ops->remove_interface(local_to_hw(local), &conf);
491 }
492
493 sdata->bss = NULL;
494
495 if (local->open_count == 0) {
496 if (netif_running(local->mdev))
497 dev_close(local->mdev);
498
499 if (local->ops->stop)
500 local->ops->stop(local_to_hw(local));
501
502 ieee80211_led_radio(local, 0);
503
504 flush_workqueue(local->hw.workqueue);
505
506 tasklet_disable(&local->tx_pending_tasklet);
507 tasklet_disable(&local->tasklet);
508 }
509
510 return 0;
511}
512
513static void ieee80211_set_multicast_list(struct net_device *dev)
514{
515 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
516 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
517 int allmulti, promisc, sdata_allmulti, sdata_promisc;
518
519 allmulti = !!(dev->flags & IFF_ALLMULTI);
520 promisc = !!(dev->flags & IFF_PROMISC);
521 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
522 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
523
524 if (allmulti != sdata_allmulti) {
525 if (dev->flags & IFF_ALLMULTI)
526 atomic_inc(&local->iff_allmultis);
527 else
528 atomic_dec(&local->iff_allmultis);
529 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
530 }
531
532 if (promisc != sdata_promisc) {
533 if (dev->flags & IFF_PROMISC)
534 atomic_inc(&local->iff_promiscs);
535 else
536 atomic_dec(&local->iff_promiscs);
537 sdata->flags ^= IEEE80211_SDATA_PROMISC;
538 }
539
540 dev_mc_sync(local->mdev, dev);
541}
542
543static void ieee80211_if_setup(struct net_device *dev)
544{
545 ether_setup(dev);
546 dev->hard_start_xmit = ieee80211_subif_start_xmit;
547 dev->wireless_handlers = &ieee80211_iw_handler_def;
548 dev->set_multicast_list = ieee80211_set_multicast_list;
549 dev->change_mtu = ieee80211_change_mtu;
550 dev->open = ieee80211_open;
551 dev->stop = ieee80211_stop;
552 dev->destructor = free_netdev;
553 /* we will validate the address ourselves in ->open */
554 dev->validate_addr = NULL;
555}
21/* 556/*
22 * Called when the netdev is removed or, by the code below, before 557 * Called when the netdev is removed or, by the code below, before
23 * the interface type changes. 558 * the interface type changes.
@@ -41,7 +576,7 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
41 sdata->fragment_next = 0; 576 sdata->fragment_next = 0;
42 577
43 switch (sdata->vif.type) { 578 switch (sdata->vif.type) {
44 case IEEE80211_IF_TYPE_AP: 579 case NL80211_IFTYPE_AP:
45 beacon = sdata->u.ap.beacon; 580 beacon = sdata->u.ap.beacon;
46 rcu_assign_pointer(sdata->u.ap.beacon, NULL); 581 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
47 synchronize_rcu(); 582 synchronize_rcu();
@@ -53,23 +588,23 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
53 } 588 }
54 589
55 break; 590 break;
56 case IEEE80211_IF_TYPE_MESH_POINT: 591 case NL80211_IFTYPE_MESH_POINT:
57 /* Allow compiler to elide mesh_rmc_free call. */
58 if (ieee80211_vif_is_mesh(&sdata->vif)) 592 if (ieee80211_vif_is_mesh(&sdata->vif))
59 mesh_rmc_free(sdata); 593 mesh_rmc_free(sdata);
60 /* fall through */ 594 break;
61 case IEEE80211_IF_TYPE_STA: 595 case NL80211_IFTYPE_STATION:
62 case IEEE80211_IF_TYPE_IBSS: 596 case NL80211_IFTYPE_ADHOC:
63 kfree(sdata->u.sta.extra_ie); 597 kfree(sdata->u.sta.extra_ie);
64 kfree(sdata->u.sta.assocreq_ies); 598 kfree(sdata->u.sta.assocreq_ies);
65 kfree(sdata->u.sta.assocresp_ies); 599 kfree(sdata->u.sta.assocresp_ies);
66 kfree_skb(sdata->u.sta.probe_resp); 600 kfree_skb(sdata->u.sta.probe_resp);
67 break; 601 break;
68 case IEEE80211_IF_TYPE_WDS: 602 case NL80211_IFTYPE_WDS:
69 case IEEE80211_IF_TYPE_VLAN: 603 case NL80211_IFTYPE_AP_VLAN:
70 case IEEE80211_IF_TYPE_MNTR: 604 case NL80211_IFTYPE_MONITOR:
71 break; 605 break;
72 case IEEE80211_IF_TYPE_INVALID: 606 case NL80211_IFTYPE_UNSPECIFIED:
607 case __NL80211_IFTYPE_AFTER_LAST:
73 BUG(); 608 BUG();
74 break; 609 break;
75 } 610 }
@@ -82,55 +617,42 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
82 * Helper function to initialise an interface to a specific type. 617 * Helper function to initialise an interface to a specific type.
83 */ 618 */
84static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata, 619static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
85 enum ieee80211_if_types type) 620 enum nl80211_iftype type)
86{ 621{
87 struct ieee80211_if_sta *ifsta;
88
89 /* clear type-dependent union */ 622 /* clear type-dependent union */
90 memset(&sdata->u, 0, sizeof(sdata->u)); 623 memset(&sdata->u, 0, sizeof(sdata->u));
91 624
92 /* and set some type-dependent values */ 625 /* and set some type-dependent values */
93 sdata->vif.type = type; 626 sdata->vif.type = type;
627 sdata->dev->hard_start_xmit = ieee80211_subif_start_xmit;
94 628
95 /* only monitor differs */ 629 /* only monitor differs */
96 sdata->dev->type = ARPHRD_ETHER; 630 sdata->dev->type = ARPHRD_ETHER;
97 631
98 switch (type) { 632 switch (type) {
99 case IEEE80211_IF_TYPE_AP: 633 case NL80211_IFTYPE_AP:
100 skb_queue_head_init(&sdata->u.ap.ps_bc_buf); 634 skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
101 INIT_LIST_HEAD(&sdata->u.ap.vlans); 635 INIT_LIST_HEAD(&sdata->u.ap.vlans);
102 break; 636 break;
103 case IEEE80211_IF_TYPE_MESH_POINT: 637 case NL80211_IFTYPE_STATION:
104 case IEEE80211_IF_TYPE_STA: 638 case NL80211_IFTYPE_ADHOC:
105 case IEEE80211_IF_TYPE_IBSS: 639 ieee80211_sta_setup_sdata(sdata);
106 ifsta = &sdata->u.sta; 640 break;
107 INIT_WORK(&ifsta->work, ieee80211_sta_work); 641 case NL80211_IFTYPE_MESH_POINT:
108 setup_timer(&ifsta->timer, ieee80211_sta_timer,
109 (unsigned long) sdata);
110 skb_queue_head_init(&ifsta->skb_queue);
111
112 ifsta->capab = WLAN_CAPABILITY_ESS;
113 ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
114 IEEE80211_AUTH_ALG_SHARED_KEY;
115 ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
116 IEEE80211_STA_AUTO_BSSID_SEL |
117 IEEE80211_STA_AUTO_CHANNEL_SEL;
118 if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
119 ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
120
121 if (ieee80211_vif_is_mesh(&sdata->vif)) 642 if (ieee80211_vif_is_mesh(&sdata->vif))
122 ieee80211_mesh_init_sdata(sdata); 643 ieee80211_mesh_init_sdata(sdata);
123 break; 644 break;
124 case IEEE80211_IF_TYPE_MNTR: 645 case NL80211_IFTYPE_MONITOR:
125 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP; 646 sdata->dev->type = ARPHRD_IEEE80211_RADIOTAP;
126 sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit; 647 sdata->dev->hard_start_xmit = ieee80211_monitor_start_xmit;
127 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL | 648 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
128 MONITOR_FLAG_OTHER_BSS; 649 MONITOR_FLAG_OTHER_BSS;
129 break; 650 break;
130 case IEEE80211_IF_TYPE_WDS: 651 case NL80211_IFTYPE_WDS:
131 case IEEE80211_IF_TYPE_VLAN: 652 case NL80211_IFTYPE_AP_VLAN:
132 break; 653 break;
133 case IEEE80211_IF_TYPE_INVALID: 654 case NL80211_IFTYPE_UNSPECIFIED:
655 case __NL80211_IFTYPE_AFTER_LAST:
134 BUG(); 656 BUG();
135 break; 657 break;
136 } 658 }
@@ -139,7 +661,7 @@ static void ieee80211_setup_sdata(struct ieee80211_sub_if_data *sdata,
139} 661}
140 662
141int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata, 663int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
142 enum ieee80211_if_types type) 664 enum nl80211_iftype type)
143{ 665{
144 ASSERT_RTNL(); 666 ASSERT_RTNL();
145 667
@@ -160,14 +682,16 @@ int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
160 ieee80211_setup_sdata(sdata, type); 682 ieee80211_setup_sdata(sdata, type);
161 683
162 /* reset some values that shouldn't be kept across type changes */ 684 /* reset some values that shouldn't be kept across type changes */
163 sdata->basic_rates = 0; 685 sdata->bss_conf.basic_rates =
686 ieee80211_mandatory_rates(sdata->local,
687 sdata->local->hw.conf.channel->band);
164 sdata->drop_unencrypted = 0; 688 sdata->drop_unencrypted = 0;
165 689
166 return 0; 690 return 0;
167} 691}
168 692
169int ieee80211_if_add(struct ieee80211_local *local, const char *name, 693int ieee80211_if_add(struct ieee80211_local *local, const char *name,
170 struct net_device **new_dev, enum ieee80211_if_types type, 694 struct net_device **new_dev, enum nl80211_iftype type,
171 struct vif_params *params) 695 struct vif_params *params)
172{ 696{
173 struct net_device *ndev; 697 struct net_device *ndev;
@@ -225,9 +749,9 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
225 749
226 if (ieee80211_vif_is_mesh(&sdata->vif) && 750 if (ieee80211_vif_is_mesh(&sdata->vif) &&
227 params && params->mesh_id_len) 751 params && params->mesh_id_len)
228 ieee80211_if_sta_set_mesh_id(&sdata->u.sta, 752 ieee80211_sdata_set_mesh_id(sdata,
229 params->mesh_id_len, 753 params->mesh_id_len,
230 params->mesh_id); 754 params->mesh_id);
231 755
232 list_add_tail_rcu(&sdata->list, &local->interfaces); 756 list_add_tail_rcu(&sdata->list, &local->interfaces);
233 757
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index 6597c779e35a..57afcd38cd9e 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -118,12 +118,12 @@ static const u8 *get_mac_for_key(struct ieee80211_key *key)
118 * address to indicate a transmit-only key. 118 * address to indicate a transmit-only key.
119 */ 119 */
120 if (key->conf.alg != ALG_WEP && 120 if (key->conf.alg != ALG_WEP &&
121 (key->sdata->vif.type == IEEE80211_IF_TYPE_AP || 121 (key->sdata->vif.type == NL80211_IFTYPE_AP ||
122 key->sdata->vif.type == IEEE80211_IF_TYPE_VLAN)) 122 key->sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
123 addr = zero_addr; 123 addr = zero_addr;
124 124
125 if (key->sta) 125 if (key->sta)
126 addr = key->sta->addr; 126 addr = key->sta->sta.addr;
127 127
128 return addr; 128 return addr;
129} 129}
@@ -331,7 +331,7 @@ void ieee80211_key_link(struct ieee80211_key *key,
331 */ 331 */
332 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; 332 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
333 } else { 333 } else {
334 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 334 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
335 struct sta_info *ap; 335 struct sta_info *ap;
336 336
337 /* 337 /*
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 6a7f4fae18c2..c307dba7ec03 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -45,16 +45,9 @@ struct ieee80211_tx_status_rtap_hdr {
45 u8 data_retries; 45 u8 data_retries;
46} __attribute__ ((packed)); 46} __attribute__ ((packed));
47 47
48/* common interface routines */
49
50static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
51{
52 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
53 return ETH_ALEN;
54}
55 48
56/* must be called under mdev tx lock */ 49/* must be called under mdev tx lock */
57static void ieee80211_configure_filter(struct ieee80211_local *local) 50void ieee80211_configure_filter(struct ieee80211_local *local)
58{ 51{
59 unsigned int changed_flags; 52 unsigned int changed_flags;
60 unsigned int new_flags = 0; 53 unsigned int new_flags = 0;
@@ -97,6 +90,20 @@ static void ieee80211_configure_filter(struct ieee80211_local *local)
97 90
98/* master interface */ 91/* master interface */
99 92
93static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
94{
95 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
96 return ETH_ALEN;
97}
98
99static const struct header_ops ieee80211_header_ops = {
100 .create = eth_header,
101 .parse = header_parse_80211,
102 .rebuild = eth_rebuild_header,
103 .cache = eth_header_cache,
104 .cache_update = eth_header_cache_update,
105};
106
100static int ieee80211_master_open(struct net_device *dev) 107static int ieee80211_master_open(struct net_device *dev)
101{ 108{
102 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -139,519 +146,6 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev)
139 ieee80211_configure_filter(local); 146 ieee80211_configure_filter(local);
140} 147}
141 148
142/* regular interfaces */
143
144static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
145{
146 int meshhdrlen;
147 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
148
149 meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
150
151 /* FIX: what would be proper limits for MTU?
152 * This interface uses 802.3 frames. */
153 if (new_mtu < 256 ||
154 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
155 return -EINVAL;
156 }
157
158#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
159 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
160#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
161 dev->mtu = new_mtu;
162 return 0;
163}
164
165static inline int identical_mac_addr_allowed(int type1, int type2)
166{
167 return (type1 == IEEE80211_IF_TYPE_MNTR ||
168 type2 == IEEE80211_IF_TYPE_MNTR ||
169 (type1 == IEEE80211_IF_TYPE_AP &&
170 type2 == IEEE80211_IF_TYPE_WDS) ||
171 (type1 == IEEE80211_IF_TYPE_WDS &&
172 (type2 == IEEE80211_IF_TYPE_WDS ||
173 type2 == IEEE80211_IF_TYPE_AP)) ||
174 (type1 == IEEE80211_IF_TYPE_AP &&
175 type2 == IEEE80211_IF_TYPE_VLAN) ||
176 (type1 == IEEE80211_IF_TYPE_VLAN &&
177 (type2 == IEEE80211_IF_TYPE_AP ||
178 type2 == IEEE80211_IF_TYPE_VLAN)));
179}
180
181static int ieee80211_open(struct net_device *dev)
182{
183 struct ieee80211_sub_if_data *sdata, *nsdata;
184 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
185 struct sta_info *sta;
186 struct ieee80211_if_init_conf conf;
187 u32 changed = 0;
188 int res;
189 bool need_hw_reconfig = 0;
190 u8 null_addr[ETH_ALEN] = {0};
191
192 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
193
194 /* fail early if user set an invalid address */
195 if (compare_ether_addr(dev->dev_addr, null_addr) &&
196 !is_valid_ether_addr(dev->dev_addr))
197 return -EADDRNOTAVAIL;
198
199 /* we hold the RTNL here so can safely walk the list */
200 list_for_each_entry(nsdata, &local->interfaces, list) {
201 struct net_device *ndev = nsdata->dev;
202
203 if (ndev != dev && netif_running(ndev)) {
204 /*
205 * Allow only a single IBSS interface to be up at any
206 * time. This is restricted because beacon distribution
207 * cannot work properly if both are in the same IBSS.
208 *
209 * To remove this restriction we'd have to disallow them
210 * from setting the same SSID on different IBSS interfaces
211 * belonging to the same hardware. Then, however, we're
212 * faced with having to adopt two different TSF timers...
213 */
214 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
215 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
216 return -EBUSY;
217
218 /*
219 * The remaining checks are only performed for interfaces
220 * with the same MAC address.
221 */
222 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
223 continue;
224
225 /*
226 * check whether it may have the same address
227 */
228 if (!identical_mac_addr_allowed(sdata->vif.type,
229 nsdata->vif.type))
230 return -ENOTUNIQ;
231
232 /*
233 * can only add VLANs to enabled APs
234 */
235 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
236 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
237 sdata->bss = &nsdata->u.ap;
238 }
239 }
240
241 switch (sdata->vif.type) {
242 case IEEE80211_IF_TYPE_WDS:
243 if (!is_valid_ether_addr(sdata->u.wds.remote_addr))
244 return -ENOLINK;
245 break;
246 case IEEE80211_IF_TYPE_VLAN:
247 if (!sdata->bss)
248 return -ENOLINK;
249 list_add(&sdata->u.vlan.list, &sdata->bss->vlans);
250 break;
251 case IEEE80211_IF_TYPE_AP:
252 sdata->bss = &sdata->u.ap;
253 break;
254 case IEEE80211_IF_TYPE_MESH_POINT:
255 /* mesh ifaces must set allmulti to forward mcast traffic */
256 atomic_inc(&local->iff_allmultis);
257 break;
258 case IEEE80211_IF_TYPE_STA:
259 case IEEE80211_IF_TYPE_MNTR:
260 case IEEE80211_IF_TYPE_IBSS:
261 /* no special treatment */
262 break;
263 case IEEE80211_IF_TYPE_INVALID:
264 /* cannot happen */
265 WARN_ON(1);
266 break;
267 }
268
269 if (local->open_count == 0) {
270 res = 0;
271 if (local->ops->start)
272 res = local->ops->start(local_to_hw(local));
273 if (res)
274 goto err_del_bss;
275 need_hw_reconfig = 1;
276 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
277 }
278
279 /*
280 * Check all interfaces and copy the hopefully now-present
281 * MAC address to those that have the special null one.
282 */
283 list_for_each_entry(nsdata, &local->interfaces, list) {
284 struct net_device *ndev = nsdata->dev;
285
286 /*
287 * No need to check netif_running since we do not allow
288 * it to start up with this invalid address.
289 */
290 if (compare_ether_addr(null_addr, ndev->dev_addr) == 0)
291 memcpy(ndev->dev_addr,
292 local->hw.wiphy->perm_addr,
293 ETH_ALEN);
294 }
295
296 if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0)
297 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr,
298 ETH_ALEN);
299
300 /*
301 * Validate the MAC address for this device.
302 */
303 if (!is_valid_ether_addr(dev->dev_addr)) {
304 if (!local->open_count && local->ops->stop)
305 local->ops->stop(local_to_hw(local));
306 return -EADDRNOTAVAIL;
307 }
308
309 switch (sdata->vif.type) {
310 case IEEE80211_IF_TYPE_VLAN:
311 /* no need to tell driver */
312 break;
313 case IEEE80211_IF_TYPE_MNTR:
314 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
315 local->cooked_mntrs++;
316 break;
317 }
318
319 /* must be before the call to ieee80211_configure_filter */
320 local->monitors++;
321 if (local->monitors == 1)
322 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
323
324 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
325 local->fif_fcsfail++;
326 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
327 local->fif_plcpfail++;
328 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
329 local->fif_control++;
330 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
331 local->fif_other_bss++;
332
333 netif_addr_lock_bh(local->mdev);
334 ieee80211_configure_filter(local);
335 netif_addr_unlock_bh(local->mdev);
336 break;
337 case IEEE80211_IF_TYPE_STA:
338 case IEEE80211_IF_TYPE_IBSS:
339 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
340 /* fall through */
341 default:
342 conf.vif = &sdata->vif;
343 conf.type = sdata->vif.type;
344 conf.mac_addr = dev->dev_addr;
345 res = local->ops->add_interface(local_to_hw(local), &conf);
346 if (res)
347 goto err_stop;
348
349 if (ieee80211_vif_is_mesh(&sdata->vif))
350 ieee80211_start_mesh(sdata);
351 changed |= ieee80211_reset_erp_info(sdata);
352 ieee80211_bss_info_change_notify(sdata, changed);
353 ieee80211_enable_keys(sdata);
354
355 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
356 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
357 netif_carrier_off(dev);
358 else
359 netif_carrier_on(dev);
360 }
361
362 if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
363 /* Create STA entry for the WDS peer */
364 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
365 GFP_KERNEL);
366 if (!sta) {
367 res = -ENOMEM;
368 goto err_del_interface;
369 }
370
371 /* no locking required since STA is not live yet */
372 sta->flags |= WLAN_STA_AUTHORIZED;
373
374 res = sta_info_insert(sta);
375 if (res) {
376 /* STA has been freed */
377 goto err_del_interface;
378 }
379 }
380
381 if (local->open_count == 0) {
382 res = dev_open(local->mdev);
383 WARN_ON(res);
384 if (res)
385 goto err_del_interface;
386 tasklet_enable(&local->tx_pending_tasklet);
387 tasklet_enable(&local->tasklet);
388 }
389
390 /*
391 * set_multicast_list will be invoked by the networking core
392 * which will check whether any increments here were done in
393 * error and sync them down to the hardware as filter flags.
394 */
395 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
396 atomic_inc(&local->iff_allmultis);
397
398 if (sdata->flags & IEEE80211_SDATA_PROMISC)
399 atomic_inc(&local->iff_promiscs);
400
401 local->open_count++;
402 if (need_hw_reconfig) {
403 ieee80211_hw_config(local);
404 /*
405 * set default queue parameters so drivers don't
406 * need to initialise the hardware if the hardware
407 * doesn't start up with sane defaults
408 */
409 ieee80211_set_wmm_default(sdata);
410 }
411
412 /*
413 * ieee80211_sta_work is disabled while network interface
414 * is down. Therefore, some configuration changes may not
415 * yet be effective. Trigger execution of ieee80211_sta_work
416 * to fix this.
417 */
418 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
419 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
420 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
421 queue_work(local->hw.workqueue, &ifsta->work);
422 }
423
424 netif_tx_start_all_queues(dev);
425
426 return 0;
427 err_del_interface:
428 local->ops->remove_interface(local_to_hw(local), &conf);
429 err_stop:
430 if (!local->open_count && local->ops->stop)
431 local->ops->stop(local_to_hw(local));
432 err_del_bss:
433 sdata->bss = NULL;
434 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
435 list_del(&sdata->u.vlan.list);
436 return res;
437}
438
439static int ieee80211_stop(struct net_device *dev)
440{
441 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
442 struct ieee80211_local *local = sdata->local;
443 struct ieee80211_if_init_conf conf;
444 struct sta_info *sta;
445
446 /*
447 * Stop TX on this interface first.
448 */
449 netif_tx_stop_all_queues(dev);
450
451 /*
452 * Now delete all active aggregation sessions.
453 */
454 rcu_read_lock();
455
456 list_for_each_entry_rcu(sta, &local->sta_list, list) {
457 if (sta->sdata == sdata)
458 ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr);
459 }
460
461 rcu_read_unlock();
462
463 /*
464 * Remove all stations associated with this interface.
465 *
466 * This must be done before calling ops->remove_interface()
467 * because otherwise we can later invoke ops->sta_notify()
468 * whenever the STAs are removed, and that invalidates driver
469 * assumptions about always getting a vif pointer that is valid
470 * (because if we remove a STA after ops->remove_interface()
471 * the driver will have removed the vif info already!)
472 *
473 * We could relax this and only unlink the stations from the
474 * hash table and list but keep them on a per-sdata list that
475 * will be inserted back again when the interface is brought
476 * up again, but I don't currently see a use case for that,
477 * except with WDS which gets a STA entry created when it is
478 * brought up.
479 */
480 sta_info_flush(local, sdata);
481
482 /*
483 * Don't count this interface for promisc/allmulti while it
484 * is down. dev_mc_unsync() will invoke set_multicast_list
485 * on the master interface which will sync these down to the
486 * hardware as filter flags.
487 */
488 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
489 atomic_dec(&local->iff_allmultis);
490
491 if (sdata->flags & IEEE80211_SDATA_PROMISC)
492 atomic_dec(&local->iff_promiscs);
493
494 dev_mc_unsync(local->mdev, dev);
495
496 /* APs need special treatment */
497 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
498 struct ieee80211_sub_if_data *vlan, *tmp;
499 struct beacon_data *old_beacon = sdata->u.ap.beacon;
500
501 /* remove beacon */
502 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
503 synchronize_rcu();
504 kfree(old_beacon);
505
506 /* down all dependent devices, that is VLANs */
507 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
508 u.vlan.list)
509 dev_close(vlan->dev);
510 WARN_ON(!list_empty(&sdata->u.ap.vlans));
511 }
512
513 local->open_count--;
514
515 switch (sdata->vif.type) {
516 case IEEE80211_IF_TYPE_VLAN:
517 list_del(&sdata->u.vlan.list);
518 /* no need to tell driver */
519 break;
520 case IEEE80211_IF_TYPE_MNTR:
521 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
522 local->cooked_mntrs--;
523 break;
524 }
525
526 local->monitors--;
527 if (local->monitors == 0)
528 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
529
530 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
531 local->fif_fcsfail--;
532 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
533 local->fif_plcpfail--;
534 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
535 local->fif_control--;
536 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
537 local->fif_other_bss--;
538
539 netif_addr_lock_bh(local->mdev);
540 ieee80211_configure_filter(local);
541 netif_addr_unlock_bh(local->mdev);
542 break;
543 case IEEE80211_IF_TYPE_MESH_POINT:
544 /* allmulti is always set on mesh ifaces */
545 atomic_dec(&local->iff_allmultis);
546 /* fall through */
547 case IEEE80211_IF_TYPE_STA:
548 case IEEE80211_IF_TYPE_IBSS:
549 sdata->u.sta.state = IEEE80211_STA_MLME_DISABLED;
550 memset(sdata->u.sta.bssid, 0, ETH_ALEN);
551 del_timer_sync(&sdata->u.sta.timer);
552 /*
553 * When we get here, the interface is marked down.
554 * Call synchronize_rcu() to wait for the RX path
555 * should it be using the interface and enqueuing
556 * frames at this very time on another CPU.
557 */
558 synchronize_rcu();
559 skb_queue_purge(&sdata->u.sta.skb_queue);
560
561 if (local->scan_sdata == sdata) {
562 if (!local->ops->hw_scan) {
563 local->sta_sw_scanning = 0;
564 cancel_delayed_work(&local->scan_work);
565 } else
566 local->sta_hw_scanning = 0;
567 }
568
569 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
570 kfree(sdata->u.sta.extra_ie);
571 sdata->u.sta.extra_ie = NULL;
572 sdata->u.sta.extra_ie_len = 0;
573 /* fall through */
574 default:
575 conf.vif = &sdata->vif;
576 conf.type = sdata->vif.type;
577 conf.mac_addr = dev->dev_addr;
578 /* disable all keys for as long as this netdev is down */
579 ieee80211_disable_keys(sdata);
580 local->ops->remove_interface(local_to_hw(local), &conf);
581 }
582
583 sdata->bss = NULL;
584
585 if (local->open_count == 0) {
586 if (netif_running(local->mdev))
587 dev_close(local->mdev);
588
589 if (local->ops->stop)
590 local->ops->stop(local_to_hw(local));
591
592 ieee80211_led_radio(local, 0);
593
594 flush_workqueue(local->hw.workqueue);
595
596 tasklet_disable(&local->tx_pending_tasklet);
597 tasklet_disable(&local->tasklet);
598 }
599
600 return 0;
601}
602
603static void ieee80211_set_multicast_list(struct net_device *dev)
604{
605 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
606 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
607 int allmulti, promisc, sdata_allmulti, sdata_promisc;
608
609 allmulti = !!(dev->flags & IFF_ALLMULTI);
610 promisc = !!(dev->flags & IFF_PROMISC);
611 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
612 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
613
614 if (allmulti != sdata_allmulti) {
615 if (dev->flags & IFF_ALLMULTI)
616 atomic_inc(&local->iff_allmultis);
617 else
618 atomic_dec(&local->iff_allmultis);
619 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
620 }
621
622 if (promisc != sdata_promisc) {
623 if (dev->flags & IFF_PROMISC)
624 atomic_inc(&local->iff_promiscs);
625 else
626 atomic_dec(&local->iff_promiscs);
627 sdata->flags ^= IEEE80211_SDATA_PROMISC;
628 }
629
630 dev_mc_sync(local->mdev, dev);
631}
632
633static const struct header_ops ieee80211_header_ops = {
634 .create = eth_header,
635 .parse = header_parse_80211,
636 .rebuild = eth_rebuild_header,
637 .cache = eth_header_cache,
638 .cache_update = eth_header_cache_update,
639};
640
641void ieee80211_if_setup(struct net_device *dev)
642{
643 ether_setup(dev);
644 dev->hard_start_xmit = ieee80211_subif_start_xmit;
645 dev->wireless_handlers = &ieee80211_iw_handler_def;
646 dev->set_multicast_list = ieee80211_set_multicast_list;
647 dev->change_mtu = ieee80211_change_mtu;
648 dev->open = ieee80211_open;
649 dev->stop = ieee80211_stop;
650 dev->destructor = free_netdev;
651 /* we will validate the address ourselves in ->open */
652 dev->validate_addr = NULL;
653}
654
655/* everything else */ 149/* everything else */
656 150
657int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed) 151int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
@@ -662,18 +156,21 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
662 if (WARN_ON(!netif_running(sdata->dev))) 156 if (WARN_ON(!netif_running(sdata->dev)))
663 return 0; 157 return 0;
664 158
159 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
160 return -EINVAL;
161
665 if (!local->ops->config_interface) 162 if (!local->ops->config_interface)
666 return 0; 163 return 0;
667 164
668 memset(&conf, 0, sizeof(conf)); 165 memset(&conf, 0, sizeof(conf));
669 conf.changed = changed; 166 conf.changed = changed;
670 167
671 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 168 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
672 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 169 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
673 conf.bssid = sdata->u.sta.bssid; 170 conf.bssid = sdata->u.sta.bssid;
674 conf.ssid = sdata->u.sta.ssid; 171 conf.ssid = sdata->u.sta.ssid;
675 conf.ssid_len = sdata->u.sta.ssid_len; 172 conf.ssid_len = sdata->u.sta.ssid_len;
676 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 173 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
677 conf.bssid = sdata->dev->dev_addr; 174 conf.bssid = sdata->dev->dev_addr;
678 conf.ssid = sdata->u.ap.ssid; 175 conf.ssid = sdata->u.ap.ssid;
679 conf.ssid_len = sdata->u.ap.ssid_len; 176 conf.ssid_len = sdata->u.ap.ssid_len;
@@ -702,7 +199,7 @@ int ieee80211_hw_config(struct ieee80211_local *local)
702 struct ieee80211_channel *chan; 199 struct ieee80211_channel *chan;
703 int ret = 0; 200 int ret = 0;
704 201
705 if (local->sta_sw_scanning) 202 if (local->sw_scanning)
706 chan = local->scan_channel; 203 chan = local->scan_channel;
707 else 204 else
708 chan = local->oper_channel; 205 chan = local->oper_channel;
@@ -827,6 +324,9 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
827{ 324{
828 struct ieee80211_local *local = sdata->local; 325 struct ieee80211_local *local = sdata->local;
829 326
327 if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
328 return;
329
830 if (!changed) 330 if (!changed)
831 return; 331 return;
832 332
@@ -1046,29 +546,27 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
1046 546
1047 rcu_read_lock(); 547 rcu_read_lock();
1048 548
1049 if (info->status.excessive_retries) { 549 sta = sta_info_get(local, hdr->addr1);
1050 sta = sta_info_get(local, hdr->addr1); 550
1051 if (sta) { 551 if (sta) {
1052 if (test_sta_flags(sta, WLAN_STA_PS)) { 552 if (info->status.excessive_retries &&
1053 /* 553 test_sta_flags(sta, WLAN_STA_PS)) {
1054 * The STA is in power save mode, so assume 554 /*
1055 * that this TX packet failed because of that. 555 * The STA is in power save mode, so assume
1056 */ 556 * that this TX packet failed because of that.
1057 ieee80211_handle_filtered_frame(local, sta, skb); 557 */
1058 rcu_read_unlock(); 558 ieee80211_handle_filtered_frame(local, sta, skb);
1059 return; 559 rcu_read_unlock();
1060 } 560 return;
1061 } 561 }
1062 }
1063 562
1064 fc = hdr->frame_control; 563 fc = hdr->frame_control;
564
565 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
566 (ieee80211_is_data_qos(fc))) {
567 u16 tid, ssn;
568 u8 *qc;
1065 569
1066 if ((info->flags & IEEE80211_TX_STAT_AMPDU_NO_BACK) &&
1067 (ieee80211_is_data_qos(fc))) {
1068 u16 tid, ssn;
1069 u8 *qc;
1070 sta = sta_info_get(local, hdr->addr1);
1071 if (sta) {
1072 qc = ieee80211_get_qos_ctl(hdr); 570 qc = ieee80211_get_qos_ctl(hdr);
1073 tid = qc[0] & 0xf; 571 tid = qc[0] & 0xf;
1074 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10) 572 ssn = ((le16_to_cpu(hdr->seq_ctrl) + 0x10)
@@ -1076,17 +574,19 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
1076 ieee80211_send_bar(sta->sdata, hdr->addr1, 574 ieee80211_send_bar(sta->sdata, hdr->addr1,
1077 tid, ssn); 575 tid, ssn);
1078 } 576 }
1079 }
1080 577
1081 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) { 578 if (info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
1082 sta = sta_info_get(local, hdr->addr1);
1083 if (sta) {
1084 ieee80211_handle_filtered_frame(local, sta, skb); 579 ieee80211_handle_filtered_frame(local, sta, skb);
1085 rcu_read_unlock(); 580 rcu_read_unlock();
1086 return; 581 return;
582 } else {
583 if (info->status.excessive_retries)
584 sta->tx_retry_failed++;
585 sta->tx_retry_count += info->status.retry_count;
1087 } 586 }
1088 } else 587
1089 rate_control_tx_status(local->mdev, skb); 588 rate_control_tx_status(local->mdev, skb);
589 }
1090 590
1091 rcu_read_unlock(); 591 rcu_read_unlock();
1092 592
@@ -1174,7 +674,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
1174 674
1175 rcu_read_lock(); 675 rcu_read_lock();
1176 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 676 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1177 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { 677 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
1178 if (!netif_running(sdata->dev)) 678 if (!netif_running(sdata->dev))
1179 continue; 679 continue;
1180 680
@@ -1250,8 +750,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1250 750
1251 local->hw.queues = 1; /* default */ 751 local->hw.queues = 1; /* default */
1252 752
1253 local->bridge_packets = 1;
1254
1255 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 753 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1256 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 754 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1257 local->short_retry_limit = 7; 755 local->short_retry_limit = 7;
@@ -1262,7 +760,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1262 760
1263 spin_lock_init(&local->key_lock); 761 spin_lock_init(&local->key_lock);
1264 762
1265 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); 763 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
1266 764
1267 sta_info_init(local); 765 sta_info_init(local);
1268 766
@@ -1422,7 +920,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1422 920
1423 /* add one default STA interface */ 921 /* add one default STA interface */
1424 result = ieee80211_if_add(local, "wlan%d", NULL, 922 result = ieee80211_if_add(local, "wlan%d", NULL,
1425 IEEE80211_IF_TYPE_STA, NULL); 923 NL80211_IFTYPE_STATION, NULL);
1426 if (result) 924 if (result)
1427 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 925 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1428 wiphy_name(local->hw.wiphy)); 926 wiphy_name(local->hw.wiphy));
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 3ccb3599c04f..30cf891fd3a8 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -12,6 +12,9 @@
12#include "ieee80211_i.h" 12#include "ieee80211_i.h"
13#include "mesh.h" 13#include "mesh.h"
14 14
15#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
16#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
17
15#define PP_OFFSET 1 /* Path Selection Protocol */ 18#define PP_OFFSET 1 /* Path Selection Protocol */
16#define PM_OFFSET 5 /* Path Selection Metric */ 19#define PM_OFFSET 5 /* Path Selection Metric */
17#define CC_OFFSET 9 /* Congestion Control Mode */ 20#define CC_OFFSET 9 /* Congestion Control Mode */
@@ -35,6 +38,16 @@ void ieee80211s_stop(void)
35 kmem_cache_destroy(rm_cache); 38 kmem_cache_destroy(rm_cache);
36} 39}
37 40
41static void ieee80211_mesh_housekeeping_timer(unsigned long data)
42{
43 struct ieee80211_sub_if_data *sdata = (void *) data;
44 struct ieee80211_local *local = sdata->local;
45 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
46
47 ifmsh->housekeeping = true;
48 queue_work(local->hw.workqueue, &ifmsh->work);
49}
50
38/** 51/**
39 * mesh_matches_local - check if the config of a mesh point matches ours 52 * mesh_matches_local - check if the config of a mesh point matches ours
40 * 53 *
@@ -46,7 +59,7 @@ void ieee80211s_stop(void)
46 */ 59 */
47bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata) 60bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata)
48{ 61{
49 struct ieee80211_if_sta *sta = &sdata->u.sta; 62 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
50 63
51 /* 64 /*
52 * As support for each feature is added, check for matching 65 * As support for each feature is added, check for matching
@@ -58,11 +71,11 @@ bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_dat
58 * - MDA enabled 71 * - MDA enabled
59 * - Power management control on fc 72 * - Power management control on fc
60 */ 73 */
61 if (sta->mesh_id_len == ie->mesh_id_len && 74 if (ifmsh->mesh_id_len == ie->mesh_id_len &&
62 memcmp(sta->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && 75 memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
63 memcmp(sta->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 && 76 memcmp(ifmsh->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 &&
64 memcmp(sta->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 && 77 memcmp(ifmsh->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 &&
65 memcmp(sta->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0) 78 memcmp(ifmsh->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0)
66 return true; 79 return true;
67 80
68 return false; 81 return false;
@@ -95,11 +108,11 @@ void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
95 */ 108 */
96 free_plinks = mesh_plink_availables(sdata); 109 free_plinks = mesh_plink_availables(sdata);
97 110
98 if (free_plinks != sdata->u.sta.accepting_plinks) 111 if (free_plinks != sdata->u.mesh.accepting_plinks)
99 ieee80211_sta_timer((unsigned long) sdata); 112 ieee80211_mesh_housekeeping_timer((unsigned long) sdata);
100} 113}
101 114
102void mesh_ids_set_default(struct ieee80211_if_sta *sta) 115void mesh_ids_set_default(struct ieee80211_if_mesh *sta)
103{ 116{
104 u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff}; 117 u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff};
105 118
@@ -112,22 +125,22 @@ int mesh_rmc_init(struct ieee80211_sub_if_data *sdata)
112{ 125{
113 int i; 126 int i;
114 127
115 sdata->u.sta.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); 128 sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
116 if (!sdata->u.sta.rmc) 129 if (!sdata->u.mesh.rmc)
117 return -ENOMEM; 130 return -ENOMEM;
118 sdata->u.sta.rmc->idx_mask = RMC_BUCKETS - 1; 131 sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1;
119 for (i = 0; i < RMC_BUCKETS; i++) 132 for (i = 0; i < RMC_BUCKETS; i++)
120 INIT_LIST_HEAD(&sdata->u.sta.rmc->bucket[i].list); 133 INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list);
121 return 0; 134 return 0;
122} 135}
123 136
124void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) 137void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
125{ 138{
126 struct mesh_rmc *rmc = sdata->u.sta.rmc; 139 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
127 struct rmc_entry *p, *n; 140 struct rmc_entry *p, *n;
128 int i; 141 int i;
129 142
130 if (!sdata->u.sta.rmc) 143 if (!sdata->u.mesh.rmc)
131 return; 144 return;
132 145
133 for (i = 0; i < RMC_BUCKETS; i++) 146 for (i = 0; i < RMC_BUCKETS; i++)
@@ -137,7 +150,7 @@ void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
137 } 150 }
138 151
139 kfree(rmc); 152 kfree(rmc);
140 sdata->u.sta.rmc = NULL; 153 sdata->u.mesh.rmc = NULL;
141} 154}
142 155
143/** 156/**
@@ -155,7 +168,7 @@ void mesh_rmc_free(struct ieee80211_sub_if_data *sdata)
155int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr, 168int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
156 struct ieee80211_sub_if_data *sdata) 169 struct ieee80211_sub_if_data *sdata)
157{ 170{
158 struct mesh_rmc *rmc = sdata->u.sta.rmc; 171 struct mesh_rmc *rmc = sdata->u.mesh.rmc;
159 u32 seqnum = 0; 172 u32 seqnum = 0;
160 int entries = 0; 173 int entries = 0;
161 u8 idx; 174 u8 idx;
@@ -217,11 +230,11 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
217 } 230 }
218 } 231 }
219 232
220 pos = skb_put(skb, 2 + sdata->u.sta.mesh_id_len); 233 pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len);
221 *pos++ = WLAN_EID_MESH_ID; 234 *pos++ = WLAN_EID_MESH_ID;
222 *pos++ = sdata->u.sta.mesh_id_len; 235 *pos++ = sdata->u.mesh.mesh_id_len;
223 if (sdata->u.sta.mesh_id_len) 236 if (sdata->u.mesh.mesh_id_len)
224 memcpy(pos, sdata->u.sta.mesh_id, sdata->u.sta.mesh_id_len); 237 memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len);
225 238
226 pos = skb_put(skb, 21); 239 pos = skb_put(skb, 21);
227 *pos++ = WLAN_EID_MESH_CONFIG; 240 *pos++ = WLAN_EID_MESH_CONFIG;
@@ -230,15 +243,15 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
230 *pos++ = 1; 243 *pos++ = 1;
231 244
232 /* Active path selection protocol ID */ 245 /* Active path selection protocol ID */
233 memcpy(pos, sdata->u.sta.mesh_pp_id, 4); 246 memcpy(pos, sdata->u.mesh.mesh_pp_id, 4);
234 pos += 4; 247 pos += 4;
235 248
236 /* Active path selection metric ID */ 249 /* Active path selection metric ID */
237 memcpy(pos, sdata->u.sta.mesh_pm_id, 4); 250 memcpy(pos, sdata->u.mesh.mesh_pm_id, 4);
238 pos += 4; 251 pos += 4;
239 252
240 /* Congestion control mode identifier */ 253 /* Congestion control mode identifier */
241 memcpy(pos, sdata->u.sta.mesh_cc_id, 4); 254 memcpy(pos, sdata->u.mesh.mesh_cc_id, 4);
242 pos += 4; 255 pos += 4;
243 256
244 /* Channel precedence: 257 /* Channel precedence:
@@ -248,8 +261,8 @@ void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata)
248 pos += 4; 261 pos += 4;
249 262
250 /* Mesh capability */ 263 /* Mesh capability */
251 sdata->u.sta.accepting_plinks = mesh_plink_availables(sdata); 264 sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata);
252 *pos++ = sdata->u.sta.accepting_plinks ? ACCEPT_PLINKS : 0x00; 265 *pos++ = sdata->u.mesh.accepting_plinks ? ACCEPT_PLINKS : 0x00;
253 *pos++ = 0x00; 266 *pos++ = 0x00;
254 267
255 return; 268 return;
@@ -337,10 +350,10 @@ static void ieee80211_mesh_path_timer(unsigned long data)
337{ 350{
338 struct ieee80211_sub_if_data *sdata = 351 struct ieee80211_sub_if_data *sdata =
339 (struct ieee80211_sub_if_data *) data; 352 (struct ieee80211_sub_if_data *) data;
340 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 353 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
341 struct ieee80211_local *local = wdev_priv(&sdata->wdev); 354 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
342 355
343 queue_work(local->hw.workqueue, &ifsta->work); 356 queue_work(local->hw.workqueue, &ifmsh->work);
344} 357}
345 358
346struct mesh_table *mesh_table_grow(struct mesh_table *tbl) 359struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
@@ -392,50 +405,264 @@ int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
392 struct ieee80211_sub_if_data *sdata) 405 struct ieee80211_sub_if_data *sdata)
393{ 406{
394 meshhdr->flags = 0; 407 meshhdr->flags = 0;
395 meshhdr->ttl = sdata->u.sta.mshcfg.dot11MeshTTL; 408 meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
396 put_unaligned(cpu_to_le32(sdata->u.sta.mesh_seqnum), &meshhdr->seqnum); 409 put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum);
397 sdata->u.sta.mesh_seqnum++; 410 sdata->u.mesh.mesh_seqnum++;
398 411
399 return 6; 412 return 6;
400} 413}
401 414
415static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
416 struct ieee80211_if_mesh *ifmsh)
417{
418 bool free_plinks;
419
420#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
421 printk(KERN_DEBUG "%s: running mesh housekeeping\n",
422 sdata->dev->name);
423#endif
424
425 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
426 mesh_path_expire(sdata);
427
428 free_plinks = mesh_plink_availables(sdata);
429 if (free_plinks != sdata->u.mesh.accepting_plinks)
430 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
431
432 ifmsh->housekeeping = false;
433 mod_timer(&ifmsh->housekeeping_timer,
434 round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL));
435}
436
437
438void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
439{
440 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
441 struct ieee80211_local *local = sdata->local;
442
443 ifmsh->housekeeping = true;
444 queue_work(local->hw.workqueue, &ifmsh->work);
445 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
446}
447
448void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata)
449{
450 del_timer_sync(&sdata->u.mesh.housekeeping_timer);
451 /*
452 * If the timer fired while we waited for it, it will have
453 * requeued the work. Now the work will be running again
454 * but will not rearm the timer again because it checks
455 * whether the interface is running, which, at this point,
456 * it no longer is.
457 */
458 cancel_work_sync(&sdata->u.mesh.work);
459
460 /*
461 * When we get here, the interface is marked down.
462 * Call synchronize_rcu() to wait for the RX path
463 * should it be using the interface and enqueuing
464 * frames at this very time on another CPU.
465 */
466 synchronize_rcu();
467 skb_queue_purge(&sdata->u.mesh.skb_queue);
468}
469
470static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
471 u16 stype,
472 struct ieee80211_mgmt *mgmt,
473 size_t len,
474 struct ieee80211_rx_status *rx_status)
475{
476 struct ieee80211_local *local= sdata->local;
477 struct ieee802_11_elems elems;
478 struct ieee80211_channel *channel;
479 u64 supp_rates = 0;
480 size_t baselen;
481 int freq;
482 enum ieee80211_band band = rx_status->band;
483
484 /* ignore ProbeResp to foreign address */
485 if (stype == IEEE80211_STYPE_PROBE_RESP &&
486 compare_ether_addr(mgmt->da, sdata->dev->dev_addr))
487 return;
488
489 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
490 if (baselen > len)
491 return;
492
493 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
494 &elems);
495
496 if (elems.ds_params && elems.ds_params_len == 1)
497 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
498 else
499 freq = rx_status->freq;
500
501 channel = ieee80211_get_channel(local->hw.wiphy, freq);
502
503 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
504 return;
505
506 if (elems.mesh_id && elems.mesh_config &&
507 mesh_matches_local(&elems, sdata)) {
508 supp_rates = ieee80211_sta_get_rates(local, &elems, band);
509
510 mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
511 mesh_peer_accepts_plinks(&elems));
512 }
513}
514
515static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
516 struct ieee80211_mgmt *mgmt,
517 size_t len,
518 struct ieee80211_rx_status *rx_status)
519{
520 switch (mgmt->u.action.category) {
521 case PLINK_CATEGORY:
522 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
523 break;
524 case MESH_PATH_SEL_CATEGORY:
525 mesh_rx_path_sel_frame(sdata, mgmt, len);
526 break;
527 }
528}
529
530static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
531 struct sk_buff *skb)
532{
533 struct ieee80211_rx_status *rx_status;
534 struct ieee80211_if_mesh *ifmsh;
535 struct ieee80211_mgmt *mgmt;
536 u16 stype;
537
538 ifmsh = &sdata->u.mesh;
539
540 rx_status = (struct ieee80211_rx_status *) skb->cb;
541 mgmt = (struct ieee80211_mgmt *) skb->data;
542 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
543
544 switch (stype) {
545 case IEEE80211_STYPE_PROBE_RESP:
546 case IEEE80211_STYPE_BEACON:
547 ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len,
548 rx_status);
549 break;
550 case IEEE80211_STYPE_ACTION:
551 ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status);
552 break;
553 }
554
555 kfree_skb(skb);
556}
557
558static void ieee80211_mesh_work(struct work_struct *work)
559{
560 struct ieee80211_sub_if_data *sdata =
561 container_of(work, struct ieee80211_sub_if_data, u.mesh.work);
562 struct ieee80211_local *local = sdata->local;
563 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
564 struct sk_buff *skb;
565
566 if (!netif_running(sdata->dev))
567 return;
568
569 if (local->sw_scanning || local->hw_scanning)
570 return;
571
572 while ((skb = skb_dequeue(&ifmsh->skb_queue)))
573 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
574
575 if (ifmsh->preq_queue_len &&
576 time_after(jiffies,
577 ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval)))
578 mesh_path_start_discovery(sdata);
579
580 if (ifmsh->housekeeping)
581 ieee80211_mesh_housekeeping(sdata, ifmsh);
582}
583
584void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
585{
586 struct ieee80211_sub_if_data *sdata;
587
588 rcu_read_lock();
589 list_for_each_entry_rcu(sdata, &local->interfaces, list)
590 if (ieee80211_vif_is_mesh(&sdata->vif))
591 queue_work(local->hw.workqueue, &sdata->u.mesh.work);
592 rcu_read_unlock();
593}
594
402void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) 595void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
403{ 596{
404 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 597 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
405 598
406 ifsta->mshcfg.dot11MeshRetryTimeout = MESH_RET_T; 599 INIT_WORK(&ifmsh->work, ieee80211_mesh_work);
407 ifsta->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T; 600 setup_timer(&ifmsh->housekeeping_timer,
408 ifsta->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T; 601 ieee80211_mesh_housekeeping_timer,
409 ifsta->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR; 602 (unsigned long) sdata);
410 ifsta->mshcfg.dot11MeshTTL = MESH_TTL; 603 skb_queue_head_init(&sdata->u.mesh.skb_queue);
411 ifsta->mshcfg.auto_open_plinks = true; 604
412 ifsta->mshcfg.dot11MeshMaxPeerLinks = 605 ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
606 ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
607 ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
608 ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
609 ifmsh->mshcfg.dot11MeshTTL = MESH_TTL;
610 ifmsh->mshcfg.auto_open_plinks = true;
611 ifmsh->mshcfg.dot11MeshMaxPeerLinks =
413 MESH_MAX_ESTAB_PLINKS; 612 MESH_MAX_ESTAB_PLINKS;
414 ifsta->mshcfg.dot11MeshHWMPactivePathTimeout = 613 ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout =
415 MESH_PATH_TIMEOUT; 614 MESH_PATH_TIMEOUT;
416 ifsta->mshcfg.dot11MeshHWMPpreqMinInterval = 615 ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval =
417 MESH_PREQ_MIN_INT; 616 MESH_PREQ_MIN_INT;
418 ifsta->mshcfg.dot11MeshHWMPnetDiameterTraversalTime = 617 ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
419 MESH_DIAM_TRAVERSAL_TIME; 618 MESH_DIAM_TRAVERSAL_TIME;
420 ifsta->mshcfg.dot11MeshHWMPmaxPREQretries = 619 ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries =
421 MESH_MAX_PREQ_RETRIES; 620 MESH_MAX_PREQ_RETRIES;
422 ifsta->mshcfg.path_refresh_time = 621 ifmsh->mshcfg.path_refresh_time =
423 MESH_PATH_REFRESH_TIME; 622 MESH_PATH_REFRESH_TIME;
424 ifsta->mshcfg.min_discovery_timeout = 623 ifmsh->mshcfg.min_discovery_timeout =
425 MESH_MIN_DISCOVERY_TIMEOUT; 624 MESH_MIN_DISCOVERY_TIMEOUT;
426 ifsta->accepting_plinks = true; 625 ifmsh->accepting_plinks = true;
427 ifsta->preq_id = 0; 626 ifmsh->preq_id = 0;
428 ifsta->dsn = 0; 627 ifmsh->dsn = 0;
429 atomic_set(&ifsta->mpaths, 0); 628 atomic_set(&ifmsh->mpaths, 0);
430 mesh_rmc_init(sdata); 629 mesh_rmc_init(sdata);
431 ifsta->last_preq = jiffies; 630 ifmsh->last_preq = jiffies;
432 /* Allocate all mesh structures when creating the first mesh interface. */ 631 /* Allocate all mesh structures when creating the first mesh interface. */
433 if (!mesh_allocated) 632 if (!mesh_allocated)
434 ieee80211s_init(); 633 ieee80211s_init();
435 mesh_ids_set_default(ifsta); 634 mesh_ids_set_default(ifmsh);
436 setup_timer(&ifsta->mesh_path_timer, 635 setup_timer(&ifmsh->mesh_path_timer,
437 ieee80211_mesh_path_timer, 636 ieee80211_mesh_path_timer,
438 (unsigned long) sdata); 637 (unsigned long) sdata);
439 INIT_LIST_HEAD(&ifsta->preq_queue.list); 638 INIT_LIST_HEAD(&ifmsh->preq_queue.list);
440 spin_lock_init(&ifsta->mesh_preq_queue_lock); 639 spin_lock_init(&ifmsh->mesh_preq_queue_lock);
640}
641
642ieee80211_rx_result
643ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
644 struct ieee80211_rx_status *rx_status)
645{
646 struct ieee80211_local *local = sdata->local;
647 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
648 struct ieee80211_mgmt *mgmt;
649 u16 fc;
650
651 if (skb->len < 24)
652 return RX_DROP_MONITOR;
653
654 mgmt = (struct ieee80211_mgmt *) skb->data;
655 fc = le16_to_cpu(mgmt->frame_control);
656
657 switch (fc & IEEE80211_FCTL_STYPE) {
658 case IEEE80211_STYPE_PROBE_RESP:
659 case IEEE80211_STYPE_BEACON:
660 case IEEE80211_STYPE_ACTION:
661 memcpy(skb->cb, rx_status, sizeof(*rx_status));
662 skb_queue_tail(&ifmsh->skb_queue, skb);
663 queue_work(local->hw.workqueue, &ifmsh->work);
664 return RX_QUEUED;
665 }
666
667 return RX_CONTINUE;
441} 668}
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index 84ff5d828fdb..8ee414a0447c 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -206,7 +206,7 @@ int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr,
206 struct ieee80211_sub_if_data *sdata); 206 struct ieee80211_sub_if_data *sdata);
207bool mesh_matches_local(struct ieee802_11_elems *ie, 207bool mesh_matches_local(struct ieee802_11_elems *ie,
208 struct ieee80211_sub_if_data *sdata); 208 struct ieee80211_sub_if_data *sdata);
209void mesh_ids_set_default(struct ieee80211_if_sta *sta); 209void mesh_ids_set_default(struct ieee80211_if_mesh *mesh);
210void mesh_mgmt_ies_add(struct sk_buff *skb, 210void mesh_mgmt_ies_add(struct sk_buff *skb,
211 struct ieee80211_sub_if_data *sdata); 211 struct ieee80211_sub_if_data *sdata);
212void mesh_rmc_free(struct ieee80211_sub_if_data *sdata); 212void mesh_rmc_free(struct ieee80211_sub_if_data *sdata);
@@ -214,6 +214,11 @@ int mesh_rmc_init(struct ieee80211_sub_if_data *sdata);
214void ieee80211s_init(void); 214void ieee80211s_init(void);
215void ieee80211s_stop(void); 215void ieee80211s_stop(void);
216void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata); 216void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
217ieee80211_rx_result
218ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
219 struct ieee80211_rx_status *rx_status);
220void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
221void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
217 222
218/* Mesh paths */ 223/* Mesh paths */
219int mesh_nexthop_lookup(struct sk_buff *skb, 224int mesh_nexthop_lookup(struct sk_buff *skb,
@@ -269,8 +274,8 @@ extern int mesh_allocated;
269 274
270static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata) 275static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
271{ 276{
272 return sdata->u.sta.mshcfg.dot11MeshMaxPeerLinks - 277 return sdata->u.mesh.mshcfg.dot11MeshMaxPeerLinks -
273 atomic_read(&sdata->u.sta.mshstats.estab_plinks); 278 atomic_read(&sdata->u.mesh.mshstats.estab_plinks);
274} 279}
275 280
276static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata) 281static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
@@ -288,8 +293,12 @@ static inline void mesh_path_activate(struct mesh_path *mpath)
288 for (i = 0; i <= x->hash_mask; i++) \ 293 for (i = 0; i <= x->hash_mask; i++) \
289 hlist_for_each_entry_rcu(node, p, &x->hash_buckets[i], list) 294 hlist_for_each_entry_rcu(node, p, &x->hash_buckets[i], list)
290 295
296void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local);
297
291#else 298#else
292#define mesh_allocated 0 299#define mesh_allocated 0
300static inline void
301ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) {}
293#endif 302#endif
294 303
295#endif /* IEEE80211S_H */ 304#endif /* IEEE80211S_H */
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 210d6b852406..501c7831adb4 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -64,14 +64,14 @@ static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
64#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0) 64#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0)
65 65
66#define net_traversal_jiffies(s) \ 66#define net_traversal_jiffies(s) \
67 msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime) 67 msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
68#define default_lifetime(s) \ 68#define default_lifetime(s) \
69 MSEC_TO_TU(s->u.sta.mshcfg.dot11MeshHWMPactivePathTimeout) 69 MSEC_TO_TU(s->u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout)
70#define min_preq_int_jiff(s) \ 70#define min_preq_int_jiff(s) \
71 (msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPpreqMinInterval)) 71 (msecs_to_jiffies(s->u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval))
72#define max_preq_retries(s) (s->u.sta.mshcfg.dot11MeshHWMPmaxPREQretries) 72#define max_preq_retries(s) (s->u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries)
73#define disc_timeout_jiff(s) \ 73#define disc_timeout_jiff(s) \
74 msecs_to_jiffies(sdata->u.sta.mshcfg.min_discovery_timeout) 74 msecs_to_jiffies(sdata->u.mesh.mshcfg.min_discovery_timeout)
75 75
76enum mpath_frame_type { 76enum mpath_frame_type {
77 MPATH_PREQ = 0, 77 MPATH_PREQ = 0,
@@ -223,7 +223,7 @@ static u32 airtime_link_metric_get(struct ieee80211_local *local,
223 /* bitrate is in units of 100 Kbps, while we need rate in units of 223 /* bitrate is in units of 100 Kbps, while we need rate in units of
224 * 1Mbps. This will be corrected on tx_time computation. 224 * 1Mbps. This will be corrected on tx_time computation.
225 */ 225 */
226 rate = sband->bitrates[sta->txrate_idx].bitrate; 226 rate = sband->bitrates[sta->last_txrate_idx].bitrate;
227 tx_time = (device_constant + 10 * test_frame_len / rate); 227 tx_time = (device_constant + 10 * test_frame_len / rate);
228 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err)); 228 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
229 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ; 229 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
@@ -395,7 +395,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
395static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata, 395static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
396 struct ieee80211_mgmt *mgmt, 396 struct ieee80211_mgmt *mgmt,
397 u8 *preq_elem, u32 metric) { 397 u8 *preq_elem, u32 metric) {
398 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 398 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
399 struct mesh_path *mpath; 399 struct mesh_path *mpath;
400 u8 *dst_addr, *orig_addr; 400 u8 *dst_addr, *orig_addr;
401 u8 dst_flags, ttl; 401 u8 dst_flags, ttl;
@@ -414,11 +414,11 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
414 forward = false; 414 forward = false;
415 reply = true; 415 reply = true;
416 metric = 0; 416 metric = 0;
417 if (time_after(jiffies, ifsta->last_dsn_update + 417 if (time_after(jiffies, ifmsh->last_dsn_update +
418 net_traversal_jiffies(sdata)) || 418 net_traversal_jiffies(sdata)) ||
419 time_before(jiffies, ifsta->last_dsn_update)) { 419 time_before(jiffies, ifmsh->last_dsn_update)) {
420 dst_dsn = ++ifsta->dsn; 420 dst_dsn = ++ifmsh->dsn;
421 ifsta->last_dsn_update = jiffies; 421 ifmsh->last_dsn_update = jiffies;
422 } 422 }
423 } else { 423 } else {
424 rcu_read_lock(); 424 rcu_read_lock();
@@ -444,7 +444,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
444 444
445 if (reply) { 445 if (reply) {
446 lifetime = PREQ_IE_LIFETIME(preq_elem); 446 lifetime = PREQ_IE_LIFETIME(preq_elem);
447 ttl = ifsta->mshcfg.dot11MeshTTL; 447 ttl = ifmsh->mshcfg.dot11MeshTTL;
448 if (ttl != 0) 448 if (ttl != 0)
449 mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr, 449 mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr,
450 cpu_to_le32(dst_dsn), 0, orig_addr, 450 cpu_to_le32(dst_dsn), 0, orig_addr,
@@ -452,7 +452,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
452 cpu_to_le32(lifetime), cpu_to_le32(metric), 452 cpu_to_le32(lifetime), cpu_to_le32(metric),
453 0, sdata); 453 0, sdata);
454 else 454 else
455 ifsta->mshstats.dropped_frames_ttl++; 455 ifmsh->mshstats.dropped_frames_ttl++;
456 } 456 }
457 457
458 if (forward) { 458 if (forward) {
@@ -462,7 +462,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
462 ttl = PREQ_IE_TTL(preq_elem); 462 ttl = PREQ_IE_TTL(preq_elem);
463 lifetime = PREQ_IE_LIFETIME(preq_elem); 463 lifetime = PREQ_IE_LIFETIME(preq_elem);
464 if (ttl <= 1) { 464 if (ttl <= 1) {
465 ifsta->mshstats.dropped_frames_ttl++; 465 ifmsh->mshstats.dropped_frames_ttl++;
466 return; 466 return;
467 } 467 }
468 --ttl; 468 --ttl;
@@ -475,7 +475,7 @@ static void hwmp_preq_frame_process(struct ieee80211_sub_if_data *sdata,
475 hopcount, ttl, cpu_to_le32(lifetime), 475 hopcount, ttl, cpu_to_le32(lifetime),
476 cpu_to_le32(metric), cpu_to_le32(preq_id), 476 cpu_to_le32(metric), cpu_to_le32(preq_id),
477 sdata); 477 sdata);
478 ifsta->mshstats.fwded_frames++; 478 ifmsh->mshstats.fwded_frames++;
479 } 479 }
480} 480}
481 481
@@ -503,7 +503,7 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
503 503
504 ttl = PREP_IE_TTL(prep_elem); 504 ttl = PREP_IE_TTL(prep_elem);
505 if (ttl <= 1) { 505 if (ttl <= 1) {
506 sdata->u.sta.mshstats.dropped_frames_ttl++; 506 sdata->u.mesh.mshstats.dropped_frames_ttl++;
507 return; 507 return;
508 } 508 }
509 509
@@ -517,7 +517,7 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
517 spin_unlock_bh(&mpath->state_lock); 517 spin_unlock_bh(&mpath->state_lock);
518 goto fail; 518 goto fail;
519 } 519 }
520 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN); 520 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
521 spin_unlock_bh(&mpath->state_lock); 521 spin_unlock_bh(&mpath->state_lock);
522 --ttl; 522 --ttl;
523 flags = PREP_IE_FLAGS(prep_elem); 523 flags = PREP_IE_FLAGS(prep_elem);
@@ -529,16 +529,16 @@ static void hwmp_prep_frame_process(struct ieee80211_sub_if_data *sdata,
529 529
530 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr, 530 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
531 cpu_to_le32(orig_dsn), 0, dst_addr, 531 cpu_to_le32(orig_dsn), 0, dst_addr,
532 cpu_to_le32(dst_dsn), mpath->next_hop->addr, hopcount, ttl, 532 cpu_to_le32(dst_dsn), mpath->next_hop->sta.addr, hopcount, ttl,
533 cpu_to_le32(lifetime), cpu_to_le32(metric), 533 cpu_to_le32(lifetime), cpu_to_le32(metric),
534 0, sdata); 534 0, sdata);
535 rcu_read_unlock(); 535 rcu_read_unlock();
536 sdata->u.sta.mshstats.fwded_frames++; 536 sdata->u.mesh.mshstats.fwded_frames++;
537 return; 537 return;
538 538
539fail: 539fail:
540 rcu_read_unlock(); 540 rcu_read_unlock();
541 sdata->u.sta.mshstats.dropped_frames_no_route++; 541 sdata->u.mesh.mshstats.dropped_frames_no_route++;
542 return; 542 return;
543} 543}
544 544
@@ -557,7 +557,7 @@ static void hwmp_perr_frame_process(struct ieee80211_sub_if_data *sdata,
557 if (mpath) { 557 if (mpath) {
558 spin_lock_bh(&mpath->state_lock); 558 spin_lock_bh(&mpath->state_lock);
559 if (mpath->flags & MESH_PATH_ACTIVE && 559 if (mpath->flags & MESH_PATH_ACTIVE &&
560 memcmp(ta, mpath->next_hop->addr, ETH_ALEN) == 0 && 560 memcmp(ta, mpath->next_hop->sta.addr, ETH_ALEN) == 0 &&
561 (!(mpath->flags & MESH_PATH_DSN_VALID) || 561 (!(mpath->flags & MESH_PATH_DSN_VALID) ||
562 DSN_GT(dst_dsn, mpath->dsn))) { 562 DSN_GT(dst_dsn, mpath->dsn))) {
563 mpath->flags &= ~MESH_PATH_ACTIVE; 563 mpath->flags &= ~MESH_PATH_ACTIVE;
@@ -631,7 +631,7 @@ void mesh_rx_path_sel_frame(struct ieee80211_sub_if_data *sdata,
631static void mesh_queue_preq(struct mesh_path *mpath, u8 flags) 631static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
632{ 632{
633 struct ieee80211_sub_if_data *sdata = mpath->sdata; 633 struct ieee80211_sub_if_data *sdata = mpath->sdata;
634 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 634 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
635 struct mesh_preq_queue *preq_node; 635 struct mesh_preq_queue *preq_node;
636 636
637 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL); 637 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL);
@@ -640,9 +640,9 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
640 return; 640 return;
641 } 641 }
642 642
643 spin_lock(&ifsta->mesh_preq_queue_lock); 643 spin_lock(&ifmsh->mesh_preq_queue_lock);
644 if (ifsta->preq_queue_len == MAX_PREQ_QUEUE_LEN) { 644 if (ifmsh->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
645 spin_unlock(&ifsta->mesh_preq_queue_lock); 645 spin_unlock(&ifmsh->mesh_preq_queue_lock);
646 kfree(preq_node); 646 kfree(preq_node);
647 if (printk_ratelimit()) 647 if (printk_ratelimit())
648 printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n"); 648 printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n");
@@ -652,21 +652,21 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
652 memcpy(preq_node->dst, mpath->dst, ETH_ALEN); 652 memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
653 preq_node->flags = flags; 653 preq_node->flags = flags;
654 654
655 list_add_tail(&preq_node->list, &ifsta->preq_queue.list); 655 list_add_tail(&preq_node->list, &ifmsh->preq_queue.list);
656 ++ifsta->preq_queue_len; 656 ++ifmsh->preq_queue_len;
657 spin_unlock(&ifsta->mesh_preq_queue_lock); 657 spin_unlock(&ifmsh->mesh_preq_queue_lock);
658 658
659 if (time_after(jiffies, ifsta->last_preq + min_preq_int_jiff(sdata))) 659 if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
660 queue_work(sdata->local->hw.workqueue, &ifsta->work); 660 queue_work(sdata->local->hw.workqueue, &ifmsh->work);
661 661
662 else if (time_before(jiffies, ifsta->last_preq)) { 662 else if (time_before(jiffies, ifmsh->last_preq)) {
663 /* avoid long wait if did not send preqs for a long time 663 /* avoid long wait if did not send preqs for a long time
664 * and jiffies wrapped around 664 * and jiffies wrapped around
665 */ 665 */
666 ifsta->last_preq = jiffies - min_preq_int_jiff(sdata) - 1; 666 ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
667 queue_work(sdata->local->hw.workqueue, &ifsta->work); 667 queue_work(sdata->local->hw.workqueue, &ifmsh->work);
668 } else 668 } else
669 mod_timer(&ifsta->mesh_path_timer, ifsta->last_preq + 669 mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
670 min_preq_int_jiff(sdata)); 670 min_preq_int_jiff(sdata));
671} 671}
672 672
@@ -677,25 +677,25 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
677 */ 677 */
678void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata) 678void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
679{ 679{
680 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 680 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
681 struct mesh_preq_queue *preq_node; 681 struct mesh_preq_queue *preq_node;
682 struct mesh_path *mpath; 682 struct mesh_path *mpath;
683 u8 ttl, dst_flags; 683 u8 ttl, dst_flags;
684 u32 lifetime; 684 u32 lifetime;
685 685
686 spin_lock(&ifsta->mesh_preq_queue_lock); 686 spin_lock(&ifmsh->mesh_preq_queue_lock);
687 if (!ifsta->preq_queue_len || 687 if (!ifmsh->preq_queue_len ||
688 time_before(jiffies, ifsta->last_preq + 688 time_before(jiffies, ifmsh->last_preq +
689 min_preq_int_jiff(sdata))) { 689 min_preq_int_jiff(sdata))) {
690 spin_unlock(&ifsta->mesh_preq_queue_lock); 690 spin_unlock(&ifmsh->mesh_preq_queue_lock);
691 return; 691 return;
692 } 692 }
693 693
694 preq_node = list_first_entry(&ifsta->preq_queue.list, 694 preq_node = list_first_entry(&ifmsh->preq_queue.list,
695 struct mesh_preq_queue, list); 695 struct mesh_preq_queue, list);
696 list_del(&preq_node->list); 696 list_del(&preq_node->list);
697 --ifsta->preq_queue_len; 697 --ifmsh->preq_queue_len;
698 spin_unlock(&ifsta->mesh_preq_queue_lock); 698 spin_unlock(&ifmsh->mesh_preq_queue_lock);
699 699
700 rcu_read_lock(); 700 rcu_read_lock();
701 mpath = mesh_path_lookup(preq_node->dst, sdata); 701 mpath = mesh_path_lookup(preq_node->dst, sdata);
@@ -720,18 +720,18 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
720 goto enddiscovery; 720 goto enddiscovery;
721 } 721 }
722 722
723 ifsta->last_preq = jiffies; 723 ifmsh->last_preq = jiffies;
724 724
725 if (time_after(jiffies, ifsta->last_dsn_update + 725 if (time_after(jiffies, ifmsh->last_dsn_update +
726 net_traversal_jiffies(sdata)) || 726 net_traversal_jiffies(sdata)) ||
727 time_before(jiffies, ifsta->last_dsn_update)) { 727 time_before(jiffies, ifmsh->last_dsn_update)) {
728 ++ifsta->dsn; 728 ++ifmsh->dsn;
729 sdata->u.sta.last_dsn_update = jiffies; 729 sdata->u.mesh.last_dsn_update = jiffies;
730 } 730 }
731 lifetime = default_lifetime(sdata); 731 lifetime = default_lifetime(sdata);
732 ttl = sdata->u.sta.mshcfg.dot11MeshTTL; 732 ttl = sdata->u.mesh.mshcfg.dot11MeshTTL;
733 if (ttl == 0) { 733 if (ttl == 0) {
734 sdata->u.sta.mshstats.dropped_frames_ttl++; 734 sdata->u.mesh.mshstats.dropped_frames_ttl++;
735 spin_unlock_bh(&mpath->state_lock); 735 spin_unlock_bh(&mpath->state_lock);
736 goto enddiscovery; 736 goto enddiscovery;
737 } 737 }
@@ -743,10 +743,10 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
743 743
744 spin_unlock_bh(&mpath->state_lock); 744 spin_unlock_bh(&mpath->state_lock);
745 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->dev->dev_addr, 745 mesh_path_sel_frame_tx(MPATH_PREQ, 0, sdata->dev->dev_addr,
746 cpu_to_le32(ifsta->dsn), dst_flags, mpath->dst, 746 cpu_to_le32(ifmsh->dsn), dst_flags, mpath->dst,
747 cpu_to_le32(mpath->dsn), sdata->dev->broadcast, 0, 747 cpu_to_le32(mpath->dsn), sdata->dev->broadcast, 0,
748 ttl, cpu_to_le32(lifetime), 0, 748 ttl, cpu_to_le32(lifetime), 0,
749 cpu_to_le32(ifsta->preq_id++), sdata); 749 cpu_to_le32(ifmsh->preq_id++), sdata);
750 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout); 750 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
751 751
752enddiscovery: 752enddiscovery:
@@ -783,7 +783,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
783 mpath = mesh_path_lookup(dst_addr, sdata); 783 mpath = mesh_path_lookup(dst_addr, sdata);
784 if (!mpath) { 784 if (!mpath) {
785 dev_kfree_skb(skb); 785 dev_kfree_skb(skb);
786 sdata->u.sta.mshstats.dropped_frames_no_route++; 786 sdata->u.mesh.mshstats.dropped_frames_no_route++;
787 err = -ENOSPC; 787 err = -ENOSPC;
788 goto endlookup; 788 goto endlookup;
789 } 789 }
@@ -791,7 +791,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
791 791
792 if (mpath->flags & MESH_PATH_ACTIVE) { 792 if (mpath->flags & MESH_PATH_ACTIVE) {
793 if (time_after(jiffies, mpath->exp_time - 793 if (time_after(jiffies, mpath->exp_time -
794 msecs_to_jiffies(sdata->u.sta.mshcfg.path_refresh_time)) 794 msecs_to_jiffies(sdata->u.mesh.mshcfg.path_refresh_time))
795 && !memcmp(sdata->dev->dev_addr, hdr->addr4, 795 && !memcmp(sdata->dev->dev_addr, hdr->addr4,
796 ETH_ALEN) 796 ETH_ALEN)
797 && !(mpath->flags & MESH_PATH_RESOLVING) 797 && !(mpath->flags & MESH_PATH_RESOLVING)
@@ -799,7 +799,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
799 mesh_queue_preq(mpath, 799 mesh_queue_preq(mpath,
800 PREQ_Q_F_START | PREQ_Q_F_REFRESH); 800 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
801 } 801 }
802 memcpy(hdr->addr1, mpath->next_hop->addr, 802 memcpy(hdr->addr1, mpath->next_hop->sta.addr,
803 ETH_ALEN); 803 ETH_ALEN);
804 } else { 804 } else {
805 if (!(mpath->flags & MESH_PATH_RESOLVING)) { 805 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 0a60f55f32ab..e4fa2905fadc 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -153,7 +153,7 @@ int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata)
153 if (is_multicast_ether_addr(dst)) 153 if (is_multicast_ether_addr(dst))
154 return -ENOTSUPP; 154 return -ENOTSUPP;
155 155
156 if (atomic_add_unless(&sdata->u.sta.mpaths, 1, MESH_MAX_MPATHS) == 0) 156 if (atomic_add_unless(&sdata->u.mesh.mpaths, 1, MESH_MAX_MPATHS) == 0)
157 return -ENOSPC; 157 return -ENOSPC;
158 158
159 err = -ENOMEM; 159 err = -ENOMEM;
@@ -221,7 +221,7 @@ err_exists:
221err_node_alloc: 221err_node_alloc:
222 kfree(new_mpath); 222 kfree(new_mpath);
223err_path_alloc: 223err_path_alloc:
224 atomic_dec(&sdata->u.sta.mpaths); 224 atomic_dec(&sdata->u.mesh.mpaths);
225 return err; 225 return err;
226} 226}
227 227
@@ -306,7 +306,7 @@ static void mesh_path_node_reclaim(struct rcu_head *rp)
306 struct ieee80211_sub_if_data *sdata = node->mpath->sdata; 306 struct ieee80211_sub_if_data *sdata = node->mpath->sdata;
307 307
308 del_timer_sync(&node->mpath->timer); 308 del_timer_sync(&node->mpath->timer);
309 atomic_dec(&sdata->u.sta.mpaths); 309 atomic_dec(&sdata->u.mesh.mpaths);
310 kfree(node->mpath); 310 kfree(node->mpath);
311 kfree(node); 311 kfree(node);
312} 312}
@@ -401,7 +401,7 @@ void mesh_path_discard_frame(struct sk_buff *skb,
401 } 401 }
402 402
403 kfree_skb(skb); 403 kfree_skb(skb);
404 sdata->u.sta.mshstats.dropped_frames_no_route++; 404 sdata->u.mesh.mshstats.dropped_frames_no_route++;
405} 405}
406 406
407/** 407/**
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 7356462dee96..faac101c0f85 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -36,11 +36,11 @@
36#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9 36#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
37#define MESH_SECURITY_FAILED_VERIFICATION 10 37#define MESH_SECURITY_FAILED_VERIFICATION 10
38 38
39#define dot11MeshMaxRetries(s) (s->u.sta.mshcfg.dot11MeshMaxRetries) 39#define dot11MeshMaxRetries(s) (s->u.mesh.mshcfg.dot11MeshMaxRetries)
40#define dot11MeshRetryTimeout(s) (s->u.sta.mshcfg.dot11MeshRetryTimeout) 40#define dot11MeshRetryTimeout(s) (s->u.mesh.mshcfg.dot11MeshRetryTimeout)
41#define dot11MeshConfirmTimeout(s) (s->u.sta.mshcfg.dot11MeshConfirmTimeout) 41#define dot11MeshConfirmTimeout(s) (s->u.mesh.mshcfg.dot11MeshConfirmTimeout)
42#define dot11MeshHoldingTimeout(s) (s->u.sta.mshcfg.dot11MeshHoldingTimeout) 42#define dot11MeshHoldingTimeout(s) (s->u.mesh.mshcfg.dot11MeshHoldingTimeout)
43#define dot11MeshMaxPeerLinks(s) (s->u.sta.mshcfg.dot11MeshMaxPeerLinks) 43#define dot11MeshMaxPeerLinks(s) (s->u.mesh.mshcfg.dot11MeshMaxPeerLinks)
44 44
45enum plink_frame_type { 45enum plink_frame_type {
46 PLINK_OPEN = 0, 46 PLINK_OPEN = 0,
@@ -63,14 +63,14 @@ enum plink_event {
63static inline 63static inline
64void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata) 64void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
65{ 65{
66 atomic_inc(&sdata->u.sta.mshstats.estab_plinks); 66 atomic_inc(&sdata->u.mesh.mshstats.estab_plinks);
67 mesh_accept_plinks_update(sdata); 67 mesh_accept_plinks_update(sdata);
68} 68}
69 69
70static inline 70static inline
71void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata) 71void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
72{ 72{
73 atomic_dec(&sdata->u.sta.mshstats.estab_plinks); 73 atomic_dec(&sdata->u.mesh.mshstats.estab_plinks);
74 mesh_accept_plinks_update(sdata); 74 mesh_accept_plinks_update(sdata);
75} 75}
76 76
@@ -106,7 +106,7 @@ static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
106 return NULL; 106 return NULL;
107 107
108 sta->flags = WLAN_STA_AUTHORIZED; 108 sta->flags = WLAN_STA_AUTHORIZED;
109 sta->supp_rates[local->hw.conf.channel->band] = rates; 109 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
110 110
111 return sta; 111 return sta;
112} 112}
@@ -243,10 +243,10 @@ void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct ieee80211_sub_if_data
243 } 243 }
244 244
245 sta->last_rx = jiffies; 245 sta->last_rx = jiffies;
246 sta->supp_rates[local->hw.conf.channel->band] = rates; 246 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
247 if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN && 247 if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
248 sdata->u.sta.accepting_plinks && 248 sdata->u.mesh.accepting_plinks &&
249 sdata->u.sta.mshcfg.auto_open_plinks) 249 sdata->u.mesh.mshcfg.auto_open_plinks)
250 mesh_plink_open(sta); 250 mesh_plink_open(sta);
251 251
252 rcu_read_unlock(); 252 rcu_read_unlock();
@@ -275,7 +275,7 @@ static void mesh_plink_timer(unsigned long data)
275 return; 275 return;
276 } 276 }
277 mpl_dbg("Mesh plink timer for %s fired on state %d\n", 277 mpl_dbg("Mesh plink timer for %s fired on state %d\n",
278 print_mac(mac, sta->addr), sta->plink_state); 278 print_mac(mac, sta->sta.addr), sta->plink_state);
279 reason = 0; 279 reason = 0;
280 llid = sta->llid; 280 llid = sta->llid;
281 plid = sta->plid; 281 plid = sta->plid;
@@ -288,7 +288,7 @@ static void mesh_plink_timer(unsigned long data)
288 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) { 288 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
289 u32 rand; 289 u32 rand;
290 mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n", 290 mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
291 print_mac(mac, sta->addr), 291 print_mac(mac, sta->sta.addr),
292 sta->plink_retries, sta->plink_timeout); 292 sta->plink_retries, sta->plink_timeout);
293 get_random_bytes(&rand, sizeof(u32)); 293 get_random_bytes(&rand, sizeof(u32));
294 sta->plink_timeout = sta->plink_timeout + 294 sta->plink_timeout = sta->plink_timeout +
@@ -296,7 +296,7 @@ static void mesh_plink_timer(unsigned long data)
296 ++sta->plink_retries; 296 ++sta->plink_retries;
297 mod_plink_timer(sta, sta->plink_timeout); 297 mod_plink_timer(sta, sta->plink_timeout);
298 spin_unlock_bh(&sta->lock); 298 spin_unlock_bh(&sta->lock);
299 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->addr, llid, 299 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
300 0, 0); 300 0, 0);
301 break; 301 break;
302 } 302 }
@@ -309,7 +309,7 @@ static void mesh_plink_timer(unsigned long data)
309 sta->plink_state = PLINK_HOLDING; 309 sta->plink_state = PLINK_HOLDING;
310 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); 310 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
311 spin_unlock_bh(&sta->lock); 311 spin_unlock_bh(&sta->lock);
312 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, plid, 312 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid, plid,
313 reason); 313 reason);
314 break; 314 break;
315 case PLINK_HOLDING: 315 case PLINK_HOLDING:
@@ -352,10 +352,10 @@ int mesh_plink_open(struct sta_info *sta)
352 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); 352 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
353 spin_unlock_bh(&sta->lock); 353 spin_unlock_bh(&sta->lock);
354 mpl_dbg("Mesh plink: starting establishment with %s\n", 354 mpl_dbg("Mesh plink: starting establishment with %s\n",
355 print_mac(mac, sta->addr)); 355 print_mac(mac, sta->sta.addr));
356 356
357 return mesh_plink_frame_tx(sdata, PLINK_OPEN, 357 return mesh_plink_frame_tx(sdata, PLINK_OPEN,
358 sta->addr, llid, 0, 0); 358 sta->sta.addr, llid, 0, 0);
359} 359}
360 360
361void mesh_plink_block(struct sta_info *sta) 361void mesh_plink_block(struct sta_info *sta)
@@ -379,7 +379,7 @@ int mesh_plink_close(struct sta_info *sta)
379#endif 379#endif
380 380
381 mpl_dbg("Mesh plink: closing link with %s\n", 381 mpl_dbg("Mesh plink: closing link with %s\n",
382 print_mac(mac, sta->addr)); 382 print_mac(mac, sta->sta.addr));
383 spin_lock_bh(&sta->lock); 383 spin_lock_bh(&sta->lock);
384 sta->reason = cpu_to_le16(MESH_LINK_CANCELLED); 384 sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
385 reason = sta->reason; 385 reason = sta->reason;
@@ -400,7 +400,7 @@ int mesh_plink_close(struct sta_info *sta)
400 llid = sta->llid; 400 llid = sta->llid;
401 plid = sta->plid; 401 plid = sta->plid;
402 spin_unlock_bh(&sta->lock); 402 spin_unlock_bh(&sta->lock);
403 mesh_plink_frame_tx(sta->sdata, PLINK_CLOSE, sta->addr, llid, 403 mesh_plink_frame_tx(sta->sdata, PLINK_CLOSE, sta->sta.addr, llid,
404 plid, reason); 404 plid, reason);
405 return 0; 405 return 0;
406} 406}
@@ -577,9 +577,9 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
577 sta->llid = llid; 577 sta->llid = llid;
578 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata)); 578 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
579 spin_unlock_bh(&sta->lock); 579 spin_unlock_bh(&sta->lock);
580 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->addr, llid, 580 mesh_plink_frame_tx(sdata, PLINK_OPEN, sta->sta.addr, llid,
581 0, 0); 581 0, 0);
582 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, 582 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr,
583 llid, plid, 0); 583 llid, plid, 0);
584 break; 584 break;
585 default: 585 default:
@@ -604,7 +604,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
604 604
605 llid = sta->llid; 605 llid = sta->llid;
606 spin_unlock_bh(&sta->lock); 606 spin_unlock_bh(&sta->lock);
607 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, 607 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
608 plid, reason); 608 plid, reason);
609 break; 609 break;
610 case OPN_ACPT: 610 case OPN_ACPT:
@@ -613,7 +613,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
613 sta->plid = plid; 613 sta->plid = plid;
614 llid = sta->llid; 614 llid = sta->llid;
615 spin_unlock_bh(&sta->lock); 615 spin_unlock_bh(&sta->lock);
616 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid, 616 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
617 plid, 0); 617 plid, 0);
618 break; 618 break;
619 case CNF_ACPT: 619 case CNF_ACPT:
@@ -646,13 +646,13 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
646 646
647 llid = sta->llid; 647 llid = sta->llid;
648 spin_unlock_bh(&sta->lock); 648 spin_unlock_bh(&sta->lock);
649 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, 649 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
650 plid, reason); 650 plid, reason);
651 break; 651 break;
652 case OPN_ACPT: 652 case OPN_ACPT:
653 llid = sta->llid; 653 llid = sta->llid;
654 spin_unlock_bh(&sta->lock); 654 spin_unlock_bh(&sta->lock);
655 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid, 655 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
656 plid, 0); 656 plid, 0);
657 break; 657 break;
658 case CNF_ACPT: 658 case CNF_ACPT:
@@ -661,7 +661,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
661 mesh_plink_inc_estab_count(sdata); 661 mesh_plink_inc_estab_count(sdata);
662 spin_unlock_bh(&sta->lock); 662 spin_unlock_bh(&sta->lock);
663 mpl_dbg("Mesh plink with %s ESTABLISHED\n", 663 mpl_dbg("Mesh plink with %s ESTABLISHED\n",
664 print_mac(mac, sta->addr)); 664 print_mac(mac, sta->sta.addr));
665 break; 665 break;
666 default: 666 default:
667 spin_unlock_bh(&sta->lock); 667 spin_unlock_bh(&sta->lock);
@@ -685,7 +685,7 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
685 685
686 llid = sta->llid; 686 llid = sta->llid;
687 spin_unlock_bh(&sta->lock); 687 spin_unlock_bh(&sta->lock);
688 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, 688 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
689 plid, reason); 689 plid, reason);
690 break; 690 break;
691 case OPN_ACPT: 691 case OPN_ACPT:
@@ -694,8 +694,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
694 mesh_plink_inc_estab_count(sdata); 694 mesh_plink_inc_estab_count(sdata);
695 spin_unlock_bh(&sta->lock); 695 spin_unlock_bh(&sta->lock);
696 mpl_dbg("Mesh plink with %s ESTABLISHED\n", 696 mpl_dbg("Mesh plink with %s ESTABLISHED\n",
697 print_mac(mac, sta->addr)); 697 print_mac(mac, sta->sta.addr));
698 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid, 698 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
699 plid, 0); 699 plid, 0);
700 break; 700 break;
701 default: 701 default:
@@ -714,13 +714,13 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
714 llid = sta->llid; 714 llid = sta->llid;
715 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)); 715 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
716 spin_unlock_bh(&sta->lock); 716 spin_unlock_bh(&sta->lock);
717 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, 717 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr, llid,
718 plid, reason); 718 plid, reason);
719 break; 719 break;
720 case OPN_ACPT: 720 case OPN_ACPT:
721 llid = sta->llid; 721 llid = sta->llid;
722 spin_unlock_bh(&sta->lock); 722 spin_unlock_bh(&sta->lock);
723 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->addr, llid, 723 mesh_plink_frame_tx(sdata, PLINK_CONFIRM, sta->sta.addr, llid,
724 plid, 0); 724 plid, 0);
725 break; 725 break;
726 default: 726 default:
@@ -743,8 +743,8 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata, struct ieee80211_m
743 llid = sta->llid; 743 llid = sta->llid;
744 reason = sta->reason; 744 reason = sta->reason;
745 spin_unlock_bh(&sta->lock); 745 spin_unlock_bh(&sta->lock);
746 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->addr, llid, 746 mesh_plink_frame_tx(sdata, PLINK_CLOSE, sta->sta.addr,
747 plid, reason); 747 llid, plid, reason);
748 break; 748 break;
749 default: 749 default:
750 spin_unlock_bh(&sta->lock); 750 spin_unlock_bh(&sta->lock);
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 2c06f6965b7d..8611a8318c9c 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -22,11 +22,11 @@
22#include <linux/rtnetlink.h> 22#include <linux/rtnetlink.h>
23#include <net/iw_handler.h> 23#include <net/iw_handler.h>
24#include <net/mac80211.h> 24#include <net/mac80211.h>
25#include <asm/unaligned.h>
25 26
26#include "ieee80211_i.h" 27#include "ieee80211_i.h"
27#include "rate.h" 28#include "rate.h"
28#include "led.h" 29#include "led.h"
29#include "mesh.h"
30 30
31#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2 31#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
32#define IEEE80211_AUTH_TIMEOUT (HZ / 5) 32#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
@@ -34,7 +34,6 @@
34#define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 34#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
35#define IEEE80211_ASSOC_MAX_TRIES 3 35#define IEEE80211_ASSOC_MAX_TRIES 3
36#define IEEE80211_MONITORING_INTERVAL (2 * HZ) 36#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
37#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
38#define IEEE80211_PROBE_INTERVAL (60 * HZ) 37#define IEEE80211_PROBE_INTERVAL (60 * HZ)
39#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) 38#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
40#define IEEE80211_SCAN_INTERVAL (2 * HZ) 39#define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -43,7 +42,6 @@
43 42
44#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) 43#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
45#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) 44#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
46#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
47 45
48#define IEEE80211_IBSS_MAX_STA_ENTRIES 128 46#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
49 47
@@ -54,7 +52,7 @@ static int ecw2cw(int ecw)
54 return (1 << ecw) - 1; 52 return (1 << ecw) - 1;
55} 53}
56 54
57static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) 55static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie)
58{ 56{
59 u8 *end, *pos; 57 u8 *end, *pos;
60 58
@@ -74,7 +72,7 @@ static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie)
74 return NULL; 72 return NULL;
75} 73}
76 74
77static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss, 75static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
78 struct ieee80211_supported_band *sband, 76 struct ieee80211_supported_band *sband,
79 u64 *rates) 77 u64 *rates)
80{ 78{
@@ -95,44 +93,46 @@ static int ieee80211_compatible_rates(struct ieee80211_sta_bss *bss,
95 return count; 93 return count;
96} 94}
97 95
98/* frame sending functions */ 96/* also used by mesh code */
99static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 97u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
100 struct ieee80211_if_sta *ifsta, 98 struct ieee802_11_elems *elems,
101 int transaction, u8 *extra, size_t extra_len, 99 enum ieee80211_band band)
102 int encrypt)
103{ 100{
104 struct ieee80211_local *local = sdata->local; 101 struct ieee80211_supported_band *sband;
105 struct sk_buff *skb; 102 struct ieee80211_rate *bitrates;
106 struct ieee80211_mgmt *mgmt; 103 size_t num_rates;
104 u64 supp_rates;
105 int i, j;
106 sband = local->hw.wiphy->bands[band];
107 107
108 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 108 if (!sband) {
109 sizeof(*mgmt) + 6 + extra_len); 109 WARN_ON(1);
110 if (!skb) { 110 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
111 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
112 "frame\n", sdata->dev->name);
113 return;
114 } 111 }
115 skb_reserve(skb, local->hw.extra_tx_headroom);
116
117 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
118 memset(mgmt, 0, 24 + 6);
119 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
120 IEEE80211_STYPE_AUTH);
121 if (encrypt)
122 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
123 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
124 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
125 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
126 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
127 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
128 ifsta->auth_transaction = transaction + 1;
129 mgmt->u.auth.status_code = cpu_to_le16(0);
130 if (extra)
131 memcpy(skb_put(skb, extra_len), extra, extra_len);
132 112
133 ieee80211_tx_skb(sdata, skb, encrypt); 113 bitrates = sband->bitrates;
114 num_rates = sband->n_bitrates;
115 supp_rates = 0;
116 for (i = 0; i < elems->supp_rates_len +
117 elems->ext_supp_rates_len; i++) {
118 u8 rate = 0;
119 int own_rate;
120 if (i < elems->supp_rates_len)
121 rate = elems->supp_rates[i];
122 else if (elems->ext_supp_rates)
123 rate = elems->ext_supp_rates
124 [i - elems->supp_rates_len];
125 own_rate = 5 * (rate & 0x7f);
126 for (j = 0; j < num_rates; j++)
127 if (bitrates[j].bitrate == own_rate)
128 supp_rates |= BIT(j);
129 }
130 return supp_rates;
134} 131}
135 132
133/* frame sending functions */
134
135/* also used by scanning code */
136void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 136void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
137 u8 *ssid, size_t ssid_len) 137 u8 *ssid, size_t ssid_len)
138{ 138{
@@ -193,6 +193,43 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
193 ieee80211_tx_skb(sdata, skb, 0); 193 ieee80211_tx_skb(sdata, skb, 0);
194} 194}
195 195
196static void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
197 struct ieee80211_if_sta *ifsta,
198 int transaction, u8 *extra, size_t extra_len,
199 int encrypt)
200{
201 struct ieee80211_local *local = sdata->local;
202 struct sk_buff *skb;
203 struct ieee80211_mgmt *mgmt;
204
205 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
206 sizeof(*mgmt) + 6 + extra_len);
207 if (!skb) {
208 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
209 "frame\n", sdata->dev->name);
210 return;
211 }
212 skb_reserve(skb, local->hw.extra_tx_headroom);
213
214 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
215 memset(mgmt, 0, 24 + 6);
216 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
217 IEEE80211_STYPE_AUTH);
218 if (encrypt)
219 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
220 memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
221 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
222 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
223 mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
224 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
225 ifsta->auth_transaction = transaction + 1;
226 mgmt->u.auth.status_code = cpu_to_le16(0);
227 if (extra)
228 memcpy(skb_put(skb, extra_len), extra, extra_len);
229
230 ieee80211_tx_skb(sdata, skb, encrypt);
231}
232
196static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, 233static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
197 struct ieee80211_if_sta *ifsta) 234 struct ieee80211_if_sta *ifsta)
198{ 235{
@@ -202,7 +239,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
202 u8 *pos, *ies, *ht_add_ie; 239 u8 *pos, *ies, *ht_add_ie;
203 int i, len, count, rates_len, supp_rates_len; 240 int i, len, count, rates_len, supp_rates_len;
204 u16 capab; 241 u16 capab;
205 struct ieee80211_sta_bss *bss; 242 struct ieee80211_bss *bss;
206 int wmm = 0; 243 int wmm = 0;
207 struct ieee80211_supported_band *sband; 244 struct ieee80211_supported_band *sband;
208 u64 rates = 0; 245 u64 rates = 0;
@@ -433,7 +470,7 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
433 470
434/* MLME */ 471/* MLME */
435static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 472static void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
436 struct ieee80211_sta_bss *bss) 473 struct ieee80211_bss *bss)
437{ 474{
438 struct ieee80211_local *local = sdata->local; 475 struct ieee80211_local *local = sdata->local;
439 int i, have_higher_than_11mbit = 0; 476 int i, have_higher_than_11mbit = 0;
@@ -584,7 +621,7 @@ static u32 ieee80211_handle_erp_ie(struct ieee80211_sub_if_data *sdata,
584} 621}
585 622
586static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, 623static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
587 struct ieee80211_sta_bss *bss) 624 struct ieee80211_bss *bss)
588{ 625{
589 u32 changed = 0; 626 u32 changed = 0;
590 627
@@ -637,11 +674,11 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
637 struct ieee80211_conf *conf = &local_to_hw(local)->conf; 674 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
638 u32 changed = BSS_CHANGED_ASSOC; 675 u32 changed = BSS_CHANGED_ASSOC;
639 676
640 struct ieee80211_sta_bss *bss; 677 struct ieee80211_bss *bss;
641 678
642 ifsta->flags |= IEEE80211_STA_ASSOCIATED; 679 ifsta->flags |= IEEE80211_STA_ASSOCIATED;
643 680
644 if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 681 if (sdata->vif.type != NL80211_IFTYPE_STATION)
645 return; 682 return;
646 683
647 bss = ieee80211_rx_bss_get(local, ifsta->bssid, 684 bss = ieee80211_rx_bss_get(local, ifsta->bssid,
@@ -673,6 +710,12 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
673 ieee80211_led_assoc(local, 1); 710 ieee80211_led_assoc(local, 1);
674 711
675 sdata->bss_conf.assoc = 1; 712 sdata->bss_conf.assoc = 1;
713 /*
714 * For now just always ask the driver to update the basic rateset
715 * when we have associated, we aren't checking whether it actually
716 * changed or not.
717 */
718 changed |= BSS_CHANGED_BASIC_RATES;
676 ieee80211_bss_info_change_notify(sdata, changed); 719 ieee80211_bss_info_change_notify(sdata, changed);
677 720
678 netif_tx_start_all_queues(sdata->dev); 721 netif_tx_start_all_queues(sdata->dev);
@@ -761,7 +804,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
761 netif_tx_stop_all_queues(sdata->dev); 804 netif_tx_stop_all_queues(sdata->dev);
762 netif_carrier_off(sdata->dev); 805 netif_carrier_off(sdata->dev);
763 806
764 ieee80211_sta_tear_down_BA_sessions(sdata, sta->addr); 807 ieee80211_sta_tear_down_BA_sessions(sdata, sta->sta.addr);
765 808
766 if (self_disconnected) { 809 if (self_disconnected) {
767 if (deauth) 810 if (deauth)
@@ -809,7 +852,7 @@ static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata,
809 struct ieee80211_if_sta *ifsta) 852 struct ieee80211_if_sta *ifsta)
810{ 853{
811 struct ieee80211_local *local = sdata->local; 854 struct ieee80211_local *local = sdata->local;
812 struct ieee80211_sta_bss *bss; 855 struct ieee80211_bss *bss;
813 int bss_privacy; 856 int bss_privacy;
814 int wep_privacy; 857 int wep_privacy;
815 int privacy_invoked; 858 int privacy_invoked;
@@ -959,17 +1002,17 @@ static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
959 DECLARE_MAC_BUF(mac); 1002 DECLARE_MAC_BUF(mac);
960 1003
961 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && 1004 if (ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
962 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) 1005 sdata->vif.type != NL80211_IFTYPE_ADHOC)
963 return; 1006 return;
964 1007
965 if (len < 24 + 6) 1008 if (len < 24 + 6)
966 return; 1009 return;
967 1010
968 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 1011 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
969 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) 1012 memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0)
970 return; 1013 return;
971 1014
972 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 1015 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
973 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) 1016 memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
974 return; 1017 return;
975 1018
@@ -977,7 +1020,7 @@ static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
977 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 1020 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
978 status_code = le16_to_cpu(mgmt->u.auth.status_code); 1021 status_code = le16_to_cpu(mgmt->u.auth.status_code);
979 1022
980 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 1023 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
981 /* 1024 /*
982 * IEEE 802.11 standard does not require authentication in IBSS 1025 * IEEE 802.11 standard does not require authentication in IBSS
983 * networks and most implementations do not seem to use it. 1026 * networks and most implementations do not seem to use it.
@@ -1182,7 +1225,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1182 /* Add STA entry for the AP */ 1225 /* Add STA entry for the AP */
1183 sta = sta_info_get(local, ifsta->bssid); 1226 sta = sta_info_get(local, ifsta->bssid);
1184 if (!sta) { 1227 if (!sta) {
1185 struct ieee80211_sta_bss *bss; 1228 struct ieee80211_bss *bss;
1186 int err; 1229 int err;
1187 1230
1188 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC); 1231 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
@@ -1258,8 +1301,8 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1258 } 1301 }
1259 } 1302 }
1260 1303
1261 sta->supp_rates[local->hw.conf.channel->band] = rates; 1304 sta->sta.supp_rates[local->hw.conf.channel->band] = rates;
1262 sdata->basic_rates = basic_rates; 1305 sdata->bss_conf.basic_rates = basic_rates;
1263 1306
1264 /* cf. IEEE 802.11 9.2.12 */ 1307 /* cf. IEEE 802.11 9.2.12 */
1265 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && 1308 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
@@ -1273,11 +1316,11 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1273 struct ieee80211_ht_bss_info bss_info; 1316 struct ieee80211_ht_bss_info bss_info;
1274 ieee80211_ht_cap_ie_to_ht_info( 1317 ieee80211_ht_cap_ie_to_ht_info(
1275 (struct ieee80211_ht_cap *) 1318 (struct ieee80211_ht_cap *)
1276 elems.ht_cap_elem, &sta->ht_info); 1319 elems.ht_cap_elem, &sta->sta.ht_info);
1277 ieee80211_ht_addt_info_ie_to_ht_bss_info( 1320 ieee80211_ht_addt_info_ie_to_ht_bss_info(
1278 (struct ieee80211_ht_addt_info *) 1321 (struct ieee80211_ht_addt_info *)
1279 elems.ht_info_elem, &bss_info); 1322 elems.ht_info_elem, &bss_info);
1280 ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info); 1323 ieee80211_handle_ht(local, 1, &sta->sta.ht_info, &bss_info);
1281 } 1324 }
1282 1325
1283 rate_control_rate_init(sta, local); 1326 rate_control_rate_init(sta, local);
@@ -1302,7 +1345,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1302 1345
1303static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 1346static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1304 struct ieee80211_if_sta *ifsta, 1347 struct ieee80211_if_sta *ifsta,
1305 struct ieee80211_sta_bss *bss) 1348 struct ieee80211_bss *bss)
1306{ 1349{
1307 struct ieee80211_local *local = sdata->local; 1350 struct ieee80211_local *local = sdata->local;
1308 int res, rates, i, j; 1351 int res, rates, i, j;
@@ -1416,70 +1459,6 @@ static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
1416 return res; 1459 return res;
1417} 1460}
1418 1461
1419u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
1420 struct ieee802_11_elems *elems,
1421 enum ieee80211_band band)
1422{
1423 struct ieee80211_supported_band *sband;
1424 struct ieee80211_rate *bitrates;
1425 size_t num_rates;
1426 u64 supp_rates;
1427 int i, j;
1428 sband = local->hw.wiphy->bands[band];
1429
1430 if (!sband) {
1431 WARN_ON(1);
1432 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1433 }
1434
1435 bitrates = sband->bitrates;
1436 num_rates = sband->n_bitrates;
1437 supp_rates = 0;
1438 for (i = 0; i < elems->supp_rates_len +
1439 elems->ext_supp_rates_len; i++) {
1440 u8 rate = 0;
1441 int own_rate;
1442 if (i < elems->supp_rates_len)
1443 rate = elems->supp_rates[i];
1444 else if (elems->ext_supp_rates)
1445 rate = elems->ext_supp_rates
1446 [i - elems->supp_rates_len];
1447 own_rate = 5 * (rate & 0x7f);
1448 for (j = 0; j < num_rates; j++)
1449 if (bitrates[j].bitrate == own_rate)
1450 supp_rates |= BIT(j);
1451 }
1452 return supp_rates;
1453}
1454
1455static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local,
1456 enum ieee80211_band band)
1457{
1458 struct ieee80211_supported_band *sband;
1459 struct ieee80211_rate *bitrates;
1460 u64 mandatory_rates;
1461 enum ieee80211_rate_flags mandatory_flag;
1462 int i;
1463
1464 sband = local->hw.wiphy->bands[band];
1465 if (!sband) {
1466 WARN_ON(1);
1467 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1468 }
1469
1470 if (band == IEEE80211_BAND_2GHZ)
1471 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
1472 else
1473 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
1474
1475 bitrates = sband->bitrates;
1476 mandatory_rates = 0;
1477 for (i = 0; i < sband->n_bitrates; i++)
1478 if (bitrates[i].flags & mandatory_flag)
1479 mandatory_rates |= BIT(i);
1480 return mandatory_rates;
1481}
1482
1483static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 1462static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1484 struct ieee80211_mgmt *mgmt, 1463 struct ieee80211_mgmt *mgmt,
1485 size_t len, 1464 size_t len,
@@ -1489,7 +1468,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1489{ 1468{
1490 struct ieee80211_local *local = sdata->local; 1469 struct ieee80211_local *local = sdata->local;
1491 int freq; 1470 int freq;
1492 struct ieee80211_sta_bss *bss; 1471 struct ieee80211_bss *bss;
1493 struct sta_info *sta; 1472 struct sta_info *sta;
1494 struct ieee80211_channel *channel; 1473 struct ieee80211_channel *channel;
1495 u64 beacon_timestamp, rx_timestamp; 1474 u64 beacon_timestamp, rx_timestamp;
@@ -1508,15 +1487,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1508 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) 1487 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
1509 return; 1488 return;
1510 1489
1511 if (ieee80211_vif_is_mesh(&sdata->vif) && elems->mesh_id && 1490 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && elems->supp_rates &&
1512 elems->mesh_config && mesh_matches_local(elems, sdata)) {
1513 supp_rates = ieee80211_sta_get_rates(local, elems, band);
1514
1515 mesh_neighbour_update(mgmt->sa, supp_rates, sdata,
1516 mesh_peer_accepts_plinks(elems));
1517 }
1518
1519 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems->supp_rates &&
1520 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { 1491 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
1521 supp_rates = ieee80211_sta_get_rates(local, elems, band); 1492 supp_rates = ieee80211_sta_get_rates(local, elems, band);
1522 1493
@@ -1526,20 +1497,21 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1526 if (sta) { 1497 if (sta) {
1527 u64 prev_rates; 1498 u64 prev_rates;
1528 1499
1529 prev_rates = sta->supp_rates[band]; 1500 prev_rates = sta->sta.supp_rates[band];
1530 /* make sure mandatory rates are always added */ 1501 /* make sure mandatory rates are always added */
1531 sta->supp_rates[band] = supp_rates | 1502 sta->sta.supp_rates[band] = supp_rates |
1532 ieee80211_sta_get_mandatory_rates(local, band); 1503 ieee80211_mandatory_rates(local, band);
1533 1504
1534#ifdef CONFIG_MAC80211_IBSS_DEBUG 1505#ifdef CONFIG_MAC80211_IBSS_DEBUG
1535 if (sta->supp_rates[band] != prev_rates) 1506 if (sta->sta.supp_rates[band] != prev_rates)
1536 printk(KERN_DEBUG "%s: updated supp_rates set " 1507 printk(KERN_DEBUG "%s: updated supp_rates set "
1537 "for %s based on beacon info (0x%llx | " 1508 "for %s based on beacon info (0x%llx | "
1538 "0x%llx -> 0x%llx)\n", 1509 "0x%llx -> 0x%llx)\n",
1539 sdata->dev->name, print_mac(mac, sta->addr), 1510 sdata->dev->name,
1511 print_mac(mac, sta->sta.addr),
1540 (unsigned long long) prev_rates, 1512 (unsigned long long) prev_rates,
1541 (unsigned long long) supp_rates, 1513 (unsigned long long) supp_rates,
1542 (unsigned long long) sta->supp_rates[band]); 1514 (unsigned long long) sta->sta.supp_rates[band]);
1543#endif 1515#endif
1544 } else { 1516 } else {
1545 ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid, 1517 ieee80211_ibss_add_sta(sdata, NULL, mgmt->bssid,
@@ -1561,14 +1533,14 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1561 * In STA mode, the remaining parameters should not be overridden 1533 * In STA mode, the remaining parameters should not be overridden
1562 * by beacons because they're not necessarily accurate there. 1534 * by beacons because they're not necessarily accurate there.
1563 */ 1535 */
1564 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 1536 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1565 bss->last_probe_resp && beacon) { 1537 bss->last_probe_resp && beacon) {
1566 ieee80211_rx_bss_put(local, bss); 1538 ieee80211_rx_bss_put(local, bss);
1567 return; 1539 return;
1568 } 1540 }
1569 1541
1570 /* check if we need to merge IBSS */ 1542 /* check if we need to merge IBSS */
1571 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && 1543 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && beacon &&
1572 bss->capability & WLAN_CAPABILITY_IBSS && 1544 bss->capability & WLAN_CAPABILITY_IBSS &&
1573 bss->freq == local->oper_channel->center_freq && 1545 bss->freq == local->oper_channel->center_freq &&
1574 elems->ssid_len == sdata->u.sta.ssid_len && 1546 elems->ssid_len == sdata->u.sta.ssid_len &&
@@ -1678,7 +1650,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1678 1650
1679 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true); 1651 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1680 1652
1681 if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 1653 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1682 return; 1654 return;
1683 ifsta = &sdata->u.sta; 1655 ifsta = &sdata->u.sta;
1684 1656
@@ -1729,7 +1701,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1729 DECLARE_MAC_BUF(mac3); 1701 DECLARE_MAC_BUF(mac3);
1730#endif 1702#endif
1731 1703
1732 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS || 1704 if (sdata->vif.type != NL80211_IFTYPE_ADHOC ||
1733 ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED || 1705 ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED ||
1734 len < 24 + 2 || !ifsta->probe_resp) 1706 len < 24 + 2 || !ifsta->probe_resp)
1735 return; 1707 return;
@@ -1785,26 +1757,6 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
1785 ieee80211_tx_skb(sdata, skb, 0); 1757 ieee80211_tx_skb(sdata, skb, 0);
1786} 1758}
1787 1759
1788static void ieee80211_rx_mgmt_action(struct ieee80211_sub_if_data *sdata,
1789 struct ieee80211_if_sta *ifsta,
1790 struct ieee80211_mgmt *mgmt,
1791 size_t len,
1792 struct ieee80211_rx_status *rx_status)
1793{
1794 /* currently we only handle mesh interface action frames here */
1795 if (!ieee80211_vif_is_mesh(&sdata->vif))
1796 return;
1797
1798 switch (mgmt->u.action.category) {
1799 case PLINK_CATEGORY:
1800 mesh_rx_plink_frame(sdata, mgmt, len, rx_status);
1801 break;
1802 case MESH_PATH_SEL_CATEGORY:
1803 mesh_rx_path_sel_frame(sdata, mgmt, len);
1804 break;
1805 }
1806}
1807
1808void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1760void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1809 struct ieee80211_rx_status *rx_status) 1761 struct ieee80211_rx_status *rx_status)
1810{ 1762{
@@ -1825,7 +1777,6 @@ void ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *
1825 case IEEE80211_STYPE_PROBE_REQ: 1777 case IEEE80211_STYPE_PROBE_REQ:
1826 case IEEE80211_STYPE_PROBE_RESP: 1778 case IEEE80211_STYPE_PROBE_RESP:
1827 case IEEE80211_STYPE_BEACON: 1779 case IEEE80211_STYPE_BEACON:
1828 case IEEE80211_STYPE_ACTION:
1829 memcpy(skb->cb, rx_status, sizeof(*rx_status)); 1780 memcpy(skb->cb, rx_status, sizeof(*rx_status));
1830 case IEEE80211_STYPE_AUTH: 1781 case IEEE80211_STYPE_AUTH:
1831 case IEEE80211_STYPE_ASSOC_RESP: 1782 case IEEE80211_STYPE_ASSOC_RESP:
@@ -1881,9 +1832,6 @@ static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
1881 case IEEE80211_STYPE_DISASSOC: 1832 case IEEE80211_STYPE_DISASSOC:
1882 ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len); 1833 ieee80211_rx_mgmt_disassoc(sdata, ifsta, mgmt, skb->len);
1883 break; 1834 break;
1884 case IEEE80211_STYPE_ACTION:
1885 ieee80211_rx_mgmt_action(sdata, ifsta, mgmt, skb->len, rx_status);
1886 break;
1887 } 1835 }
1888 1836
1889 kfree_skb(skb); 1837 kfree_skb(skb);
@@ -1913,32 +1861,6 @@ static int ieee80211_sta_active_ibss(struct ieee80211_sub_if_data *sdata)
1913} 1861}
1914 1862
1915 1863
1916static void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, unsigned long exp_time)
1917{
1918 struct ieee80211_local *local = sdata->local;
1919 struct sta_info *sta, *tmp;
1920 LIST_HEAD(tmp_list);
1921 DECLARE_MAC_BUF(mac);
1922 unsigned long flags;
1923
1924 spin_lock_irqsave(&local->sta_lock, flags);
1925 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
1926 if (time_after(jiffies, sta->last_rx + exp_time)) {
1927#ifdef CONFIG_MAC80211_IBSS_DEBUG
1928 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
1929 sdata->dev->name, print_mac(mac, sta->addr));
1930#endif
1931 __sta_info_unlink(&sta);
1932 if (sta)
1933 list_add(&sta->list, &tmp_list);
1934 }
1935 spin_unlock_irqrestore(&local->sta_lock, flags);
1936
1937 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
1938 sta_info_destroy(sta);
1939}
1940
1941
1942static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata, 1864static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
1943 struct ieee80211_if_sta *ifsta) 1865 struct ieee80211_if_sta *ifsta)
1944{ 1866{
@@ -1950,40 +1872,11 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata,
1950 1872
1951 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " 1873 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
1952 "IBSS networks with same SSID (merge)\n", sdata->dev->name); 1874 "IBSS networks with same SSID (merge)\n", sdata->dev->name);
1953 ieee80211_sta_req_scan(sdata, ifsta->ssid, ifsta->ssid_len); 1875 ieee80211_request_scan(sdata, ifsta->ssid, ifsta->ssid_len);
1954} 1876}
1955 1877
1956 1878
1957#ifdef CONFIG_MAC80211_MESH 1879static void ieee80211_sta_timer(unsigned long data)
1958static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
1959 struct ieee80211_if_sta *ifsta)
1960{
1961 bool free_plinks;
1962
1963 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
1964 mesh_path_expire(sdata);
1965
1966 free_plinks = mesh_plink_availables(sdata);
1967 if (free_plinks != sdata->u.sta.accepting_plinks)
1968 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
1969
1970 mod_timer(&ifsta->timer, jiffies +
1971 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
1972}
1973
1974
1975void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
1976{
1977 struct ieee80211_if_sta *ifsta;
1978 ifsta = &sdata->u.sta;
1979 ifsta->state = IEEE80211_STA_MLME_MESH_UP;
1980 ieee80211_sta_timer((unsigned long)sdata);
1981 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
1982}
1983#endif
1984
1985
1986void ieee80211_sta_timer(unsigned long data)
1987{ 1880{
1988 struct ieee80211_sub_if_data *sdata = 1881 struct ieee80211_sub_if_data *sdata =
1989 (struct ieee80211_sub_if_data *) data; 1882 (struct ieee80211_sub_if_data *) data;
@@ -2026,28 +1919,6 @@ static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata,
2026} 1919}
2027 1920
2028 1921
2029void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
2030 struct ieee80211_if_sta *ifsta)
2031{
2032 struct ieee80211_local *local = sdata->local;
2033
2034 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2035 return;
2036
2037 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
2038 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2039 (ifsta->flags & (IEEE80211_STA_SSID_SET |
2040 IEEE80211_STA_AUTO_SSID_SEL))) {
2041
2042 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED)
2043 ieee80211_set_disassoc(sdata, ifsta, true, true,
2044 WLAN_REASON_DEAUTH_LEAVING);
2045
2046 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2047 queue_work(local->hw.workqueue, &ifsta->work);
2048 }
2049}
2050
2051static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta, 1922static int ieee80211_sta_match_ssid(struct ieee80211_if_sta *ifsta,
2052 const char *ssid, int ssid_len) 1923 const char *ssid, int ssid_len)
2053{ 1924{
@@ -2082,7 +1953,7 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata,
2082 struct ieee80211_if_sta *ifsta) 1953 struct ieee80211_if_sta *ifsta)
2083{ 1954{
2084 struct ieee80211_local *local = sdata->local; 1955 struct ieee80211_local *local = sdata->local;
2085 struct ieee80211_sta_bss *bss; 1956 struct ieee80211_bss *bss;
2086 struct ieee80211_supported_band *sband; 1957 struct ieee80211_supported_band *sband;
2087 u8 bssid[ETH_ALEN], *pos; 1958 u8 bssid[ETH_ALEN], *pos;
2088 int i; 1959 int i;
@@ -2143,7 +2014,7 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2143 struct ieee80211_if_sta *ifsta) 2014 struct ieee80211_if_sta *ifsta)
2144{ 2015{
2145 struct ieee80211_local *local = sdata->local; 2016 struct ieee80211_local *local = sdata->local;
2146 struct ieee80211_sta_bss *bss; 2017 struct ieee80211_bss *bss;
2147 int found = 0; 2018 int found = 0;
2148 u8 bssid[ETH_ALEN]; 2019 u8 bssid[ETH_ALEN];
2149 int active_ibss; 2020 int active_ibss;
@@ -2158,8 +2029,8 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2158 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", 2029 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
2159 sdata->dev->name, active_ibss); 2030 sdata->dev->name, active_ibss);
2160#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 2031#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2161 spin_lock_bh(&local->sta_bss_lock); 2032 spin_lock_bh(&local->bss_lock);
2162 list_for_each_entry(bss, &local->sta_bss_list, list) { 2033 list_for_each_entry(bss, &local->bss_list, list) {
2163 if (ifsta->ssid_len != bss->ssid_len || 2034 if (ifsta->ssid_len != bss->ssid_len ||
2164 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0 2035 memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
2165 || !(bss->capability & WLAN_CAPABILITY_IBSS)) 2036 || !(bss->capability & WLAN_CAPABILITY_IBSS))
@@ -2173,7 +2044,7 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata,
2173 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0) 2044 if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
2174 break; 2045 break;
2175 } 2046 }
2176 spin_unlock_bh(&local->sta_bss_lock); 2047 spin_unlock_bh(&local->bss_lock);
2177 2048
2178#ifdef CONFIG_MAC80211_IBSS_DEBUG 2049#ifdef CONFIG_MAC80211_IBSS_DEBUG
2179 if (found) 2050 if (found)
@@ -2218,7 +2089,7 @@ dont_join:
2218 IEEE80211_SCAN_INTERVAL)) { 2089 IEEE80211_SCAN_INTERVAL)) {
2219 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " 2090 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
2220 "join\n", sdata->dev->name); 2091 "join\n", sdata->dev->name);
2221 return ieee80211_sta_req_scan(sdata, ifsta->ssid, 2092 return ieee80211_request_scan(sdata, ifsta->ssid,
2222 ifsta->ssid_len); 2093 ifsta->ssid_len);
2223 } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) { 2094 } else if (ifsta->state != IEEE80211_STA_MLME_IBSS_JOINED) {
2224 int interval = IEEE80211_SCAN_INTERVAL; 2095 int interval = IEEE80211_SCAN_INTERVAL;
@@ -2249,169 +2120,16 @@ dont_join:
2249} 2120}
2250 2121
2251 2122
2252int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2253{
2254 struct ieee80211_if_sta *ifsta;
2255 int res;
2256
2257 if (len > IEEE80211_MAX_SSID_LEN)
2258 return -EINVAL;
2259
2260 ifsta = &sdata->u.sta;
2261
2262 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
2263 memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
2264 memcpy(ifsta->ssid, ssid, len);
2265 ifsta->ssid_len = len;
2266 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2267
2268 res = 0;
2269 /*
2270 * Hack! MLME code needs to be cleaned up to have different
2271 * entry points for configuration and internal selection change
2272 */
2273 if (netif_running(sdata->dev))
2274 res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
2275 if (res) {
2276 printk(KERN_DEBUG "%s: Failed to config new SSID to "
2277 "the low-level driver\n", sdata->dev->name);
2278 return res;
2279 }
2280 }
2281
2282 if (len)
2283 ifsta->flags |= IEEE80211_STA_SSID_SET;
2284 else
2285 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
2286
2287 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
2288 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
2289 ifsta->ibss_join_req = jiffies;
2290 ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
2291 return ieee80211_sta_find_ibss(sdata, ifsta);
2292 }
2293
2294 return 0;
2295}
2296
2297
2298int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2299{
2300 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2301 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
2302 *len = ifsta->ssid_len;
2303 return 0;
2304}
2305
2306
2307int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2308{
2309 struct ieee80211_if_sta *ifsta;
2310 int res;
2311
2312 ifsta = &sdata->u.sta;
2313
2314 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
2315 memcpy(ifsta->bssid, bssid, ETH_ALEN);
2316 res = 0;
2317 /*
2318 * Hack! See also ieee80211_sta_set_ssid.
2319 */
2320 if (netif_running(sdata->dev))
2321 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
2322 if (res) {
2323 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2324 "the low-level driver\n", sdata->dev->name);
2325 return res;
2326 }
2327 }
2328
2329 if (is_valid_ether_addr(bssid))
2330 ifsta->flags |= IEEE80211_STA_BSSID_SET;
2331 else
2332 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
2333
2334 return 0;
2335}
2336
2337
2338int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
2339{
2340 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2341
2342 kfree(ifsta->extra_ie);
2343 if (len == 0) {
2344 ifsta->extra_ie = NULL;
2345 ifsta->extra_ie_len = 0;
2346 return 0;
2347 }
2348 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
2349 if (!ifsta->extra_ie) {
2350 ifsta->extra_ie_len = 0;
2351 return -ENOMEM;
2352 }
2353 memcpy(ifsta->extra_ie, ie, len);
2354 ifsta->extra_ie_len = len;
2355 return 0;
2356}
2357
2358
2359struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
2360 struct sk_buff *skb, u8 *bssid,
2361 u8 *addr, u64 supp_rates)
2362{
2363 struct ieee80211_local *local = sdata->local;
2364 struct sta_info *sta;
2365 DECLARE_MAC_BUF(mac);
2366 int band = local->hw.conf.channel->band;
2367
2368 /* TODO: Could consider removing the least recently used entry and
2369 * allow new one to be added. */
2370 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
2371 if (net_ratelimit()) {
2372 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
2373 "entry %s\n", sdata->dev->name, print_mac(mac, addr));
2374 }
2375 return NULL;
2376 }
2377
2378 if (compare_ether_addr(bssid, sdata->u.sta.bssid))
2379 return NULL;
2380
2381#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2382 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
2383 wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name);
2384#endif
2385
2386 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
2387 if (!sta)
2388 return NULL;
2389
2390 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
2391
2392 /* make sure mandatory rates are always added */
2393 sta->supp_rates[band] = supp_rates |
2394 ieee80211_sta_get_mandatory_rates(local, band);
2395
2396 rate_control_rate_init(sta, local);
2397
2398 if (sta_info_insert(sta))
2399 return NULL;
2400
2401 return sta;
2402}
2403
2404
2405static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata, 2123static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
2406 struct ieee80211_if_sta *ifsta) 2124 struct ieee80211_if_sta *ifsta)
2407{ 2125{
2408 struct ieee80211_local *local = sdata->local; 2126 struct ieee80211_local *local = sdata->local;
2409 struct ieee80211_sta_bss *bss, *selected = NULL; 2127 struct ieee80211_bss *bss, *selected = NULL;
2410 int top_rssi = 0, freq; 2128 int top_rssi = 0, freq;
2411 2129
2412 spin_lock_bh(&local->sta_bss_lock); 2130 spin_lock_bh(&local->bss_lock);
2413 freq = local->oper_channel->center_freq; 2131 freq = local->oper_channel->center_freq;
2414 list_for_each_entry(bss, &local->sta_bss_list, list) { 2132 list_for_each_entry(bss, &local->bss_list, list) {
2415 if (!(bss->capability & WLAN_CAPABILITY_ESS)) 2133 if (!(bss->capability & WLAN_CAPABILITY_ESS))
2416 continue; 2134 continue;
2417 2135
@@ -2441,7 +2159,7 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
2441 } 2159 }
2442 if (selected) 2160 if (selected)
2443 atomic_inc(&selected->users); 2161 atomic_inc(&selected->users);
2444 spin_unlock_bh(&local->sta_bss_lock); 2162 spin_unlock_bh(&local->bss_lock);
2445 2163
2446 if (selected) { 2164 if (selected) {
2447 ieee80211_set_freq(sdata, selected->freq); 2165 ieee80211_set_freq(sdata, selected->freq);
@@ -2468,9 +2186,9 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
2468 if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { 2186 if (ifsta->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) {
2469 ifsta->assoc_scan_tries++; 2187 ifsta->assoc_scan_tries++;
2470 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL) 2188 if (ifsta->flags & IEEE80211_STA_AUTO_SSID_SEL)
2471 ieee80211_sta_start_scan(sdata, NULL, 0); 2189 ieee80211_start_scan(sdata, NULL, 0);
2472 else 2190 else
2473 ieee80211_sta_start_scan(sdata, ifsta->ssid, 2191 ieee80211_start_scan(sdata, ifsta->ssid,
2474 ifsta->ssid_len); 2192 ifsta->ssid_len);
2475 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE; 2193 ifsta->state = IEEE80211_STA_MLME_AUTHENTICATE;
2476 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request); 2194 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
@@ -2481,61 +2199,7 @@ static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata,
2481} 2199}
2482 2200
2483 2201
2484int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) 2202static void ieee80211_sta_work(struct work_struct *work)
2485{
2486 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2487
2488 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2489 sdata->dev->name, reason);
2490
2491 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
2492 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
2493 return -EINVAL;
2494
2495 ieee80211_set_disassoc(sdata, ifsta, true, true, reason);
2496 return 0;
2497}
2498
2499
2500int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2501{
2502 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2503
2504 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2505 sdata->dev->name, reason);
2506
2507 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2508 return -EINVAL;
2509
2510 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
2511 return -1;
2512
2513 ieee80211_set_disassoc(sdata, ifsta, false, true, reason);
2514 return 0;
2515}
2516
2517void ieee80211_notify_mac(struct ieee80211_hw *hw,
2518 enum ieee80211_notification_types notif_type)
2519{
2520 struct ieee80211_local *local = hw_to_local(hw);
2521 struct ieee80211_sub_if_data *sdata;
2522
2523 switch (notif_type) {
2524 case IEEE80211_NOTIFY_RE_ASSOC:
2525 rcu_read_lock();
2526 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2527 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
2528 continue;
2529
2530 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
2531 }
2532 rcu_read_unlock();
2533 break;
2534 }
2535}
2536EXPORT_SYMBOL(ieee80211_notify_mac);
2537
2538void ieee80211_sta_work(struct work_struct *work)
2539{ 2203{
2540 struct ieee80211_sub_if_data *sdata = 2204 struct ieee80211_sub_if_data *sdata =
2541 container_of(work, struct ieee80211_sub_if_data, u.sta.work); 2205 container_of(work, struct ieee80211_sub_if_data, u.sta.work);
@@ -2546,30 +2210,23 @@ void ieee80211_sta_work(struct work_struct *work)
2546 if (!netif_running(sdata->dev)) 2210 if (!netif_running(sdata->dev))
2547 return; 2211 return;
2548 2212
2549 if (local->sta_sw_scanning || local->sta_hw_scanning) 2213 if (local->sw_scanning || local->hw_scanning)
2550 return; 2214 return;
2551 2215
2552 if (WARN_ON(sdata->vif.type != IEEE80211_IF_TYPE_STA && 2216 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION &&
2553 sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 2217 sdata->vif.type != NL80211_IFTYPE_ADHOC))
2554 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT))
2555 return; 2218 return;
2556 ifsta = &sdata->u.sta; 2219 ifsta = &sdata->u.sta;
2557 2220
2558 while ((skb = skb_dequeue(&ifsta->skb_queue))) 2221 while ((skb = skb_dequeue(&ifsta->skb_queue)))
2559 ieee80211_sta_rx_queued_mgmt(sdata, skb); 2222 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2560 2223
2561#ifdef CONFIG_MAC80211_MESH
2562 if (ifsta->preq_queue_len &&
2563 time_after(jiffies,
2564 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
2565 mesh_path_start_discovery(sdata);
2566#endif
2567
2568 if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE && 2224 if (ifsta->state != IEEE80211_STA_MLME_DIRECT_PROBE &&
2569 ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE && 2225 ifsta->state != IEEE80211_STA_MLME_AUTHENTICATE &&
2570 ifsta->state != IEEE80211_STA_MLME_ASSOCIATE && 2226 ifsta->state != IEEE80211_STA_MLME_ASSOCIATE &&
2571 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { 2227 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
2572 ieee80211_sta_start_scan(sdata, ifsta->scan_ssid, ifsta->scan_ssid_len); 2228 ieee80211_start_scan(sdata, ifsta->scan_ssid,
2229 ifsta->scan_ssid_len);
2573 return; 2230 return;
2574 } 2231 }
2575 2232
@@ -2601,11 +2258,6 @@ void ieee80211_sta_work(struct work_struct *work)
2601 case IEEE80211_STA_MLME_IBSS_JOINED: 2258 case IEEE80211_STA_MLME_IBSS_JOINED:
2602 ieee80211_sta_merge_ibss(sdata, ifsta); 2259 ieee80211_sta_merge_ibss(sdata, ifsta);
2603 break; 2260 break;
2604#ifdef CONFIG_MAC80211_MESH
2605 case IEEE80211_STA_MLME_MESH_UP:
2606 ieee80211_mesh_housekeeping(sdata, ifsta);
2607 break;
2608#endif
2609 default: 2261 default:
2610 WARN_ON(1); 2262 WARN_ON(1);
2611 break; 2263 break;
@@ -2620,16 +2272,281 @@ void ieee80211_sta_work(struct work_struct *work)
2620 } 2272 }
2621} 2273}
2622 2274
2275static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2276{
2277 if (sdata->vif.type == NL80211_IFTYPE_STATION)
2278 queue_work(sdata->local->hw.workqueue,
2279 &sdata->u.sta.work);
2280}
2281
2282/* interface setup */
2283void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2284{
2285 struct ieee80211_if_sta *ifsta;
2286
2287 ifsta = &sdata->u.sta;
2288 INIT_WORK(&ifsta->work, ieee80211_sta_work);
2289 setup_timer(&ifsta->timer, ieee80211_sta_timer,
2290 (unsigned long) sdata);
2291 skb_queue_head_init(&ifsta->skb_queue);
2292
2293 ifsta->capab = WLAN_CAPABILITY_ESS;
2294 ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
2295 IEEE80211_AUTH_ALG_SHARED_KEY;
2296 ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
2297 IEEE80211_STA_AUTO_BSSID_SEL |
2298 IEEE80211_STA_AUTO_CHANNEL_SEL;
2299 if (ieee80211_num_regular_queues(&sdata->local->hw) >= 4)
2300 ifsta->flags |= IEEE80211_STA_WMM_ENABLED;
2301}
2302
2303/*
2304 * Add a new IBSS station, will also be called by the RX code when,
2305 * in IBSS mode, receiving a frame from a yet-unknown station, hence
2306 * must be callable in atomic context.
2307 */
2308struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
2309 struct sk_buff *skb, u8 *bssid,
2310 u8 *addr, u64 supp_rates)
2311{
2312 struct ieee80211_local *local = sdata->local;
2313 struct sta_info *sta;
2314 DECLARE_MAC_BUF(mac);
2315 int band = local->hw.conf.channel->band;
2316
2317 /* TODO: Could consider removing the least recently used entry and
2318 * allow new one to be added. */
2319 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
2320 if (net_ratelimit()) {
2321 printk(KERN_DEBUG "%s: No room for a new IBSS STA "
2322 "entry %s\n", sdata->dev->name, print_mac(mac, addr));
2323 }
2324 return NULL;
2325 }
2326
2327 if (compare_ether_addr(bssid, sdata->u.sta.bssid))
2328 return NULL;
2329
2330#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2331 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
2332 wiphy_name(local->hw.wiphy), print_mac(mac, addr), sdata->dev->name);
2333#endif
2334
2335 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
2336 if (!sta)
2337 return NULL;
2338
2339 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
2340
2341 /* make sure mandatory rates are always added */
2342 sta->sta.supp_rates[band] = supp_rates |
2343 ieee80211_mandatory_rates(local, band);
2344
2345 rate_control_rate_init(sta, local);
2346
2347 if (sta_info_insert(sta))
2348 return NULL;
2349
2350 return sta;
2351}
2352
2353/* configuration hooks */
2354void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata,
2355 struct ieee80211_if_sta *ifsta)
2356{
2357 struct ieee80211_local *local = sdata->local;
2358
2359 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2360 return;
2361
2362 if ((ifsta->flags & (IEEE80211_STA_BSSID_SET |
2363 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2364 (ifsta->flags & (IEEE80211_STA_SSID_SET |
2365 IEEE80211_STA_AUTO_SSID_SEL))) {
2366
2367 if (ifsta->state == IEEE80211_STA_MLME_ASSOCIATED)
2368 ieee80211_set_disassoc(sdata, ifsta, true, true,
2369 WLAN_REASON_DEAUTH_LEAVING);
2370
2371 set_bit(IEEE80211_STA_REQ_AUTH, &ifsta->request);
2372 queue_work(local->hw.workqueue, &ifsta->work);
2373 }
2374}
2375
2376int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
2377{
2378 struct ieee80211_if_sta *ifsta;
2379 int res;
2380
2381 if (len > IEEE80211_MAX_SSID_LEN)
2382 return -EINVAL;
2383
2384 ifsta = &sdata->u.sta;
2385
2386 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) {
2387 memset(ifsta->ssid, 0, sizeof(ifsta->ssid));
2388 memcpy(ifsta->ssid, ssid, len);
2389 ifsta->ssid_len = len;
2390 ifsta->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2391
2392 res = 0;
2393 /*
2394 * Hack! MLME code needs to be cleaned up to have different
2395 * entry points for configuration and internal selection change
2396 */
2397 if (netif_running(sdata->dev))
2398 res = ieee80211_if_config(sdata, IEEE80211_IFCC_SSID);
2399 if (res) {
2400 printk(KERN_DEBUG "%s: Failed to config new SSID to "
2401 "the low-level driver\n", sdata->dev->name);
2402 return res;
2403 }
2404 }
2405
2406 if (len)
2407 ifsta->flags |= IEEE80211_STA_SSID_SET;
2408 else
2409 ifsta->flags &= ~IEEE80211_STA_SSID_SET;
2410
2411 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
2412 !(ifsta->flags & IEEE80211_STA_BSSID_SET)) {
2413 ifsta->ibss_join_req = jiffies;
2414 ifsta->state = IEEE80211_STA_MLME_IBSS_SEARCH;
2415 return ieee80211_sta_find_ibss(sdata, ifsta);
2416 }
2417
2418 return 0;
2419}
2420
2421int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
2422{
2423 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2424 memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
2425 *len = ifsta->ssid_len;
2426 return 0;
2427}
2428
2429int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
2430{
2431 struct ieee80211_if_sta *ifsta;
2432 int res;
2433
2434 ifsta = &sdata->u.sta;
2435
2436 if (memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0) {
2437 memcpy(ifsta->bssid, bssid, ETH_ALEN);
2438 res = 0;
2439 /*
2440 * Hack! See also ieee80211_sta_set_ssid.
2441 */
2442 if (netif_running(sdata->dev))
2443 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
2444 if (res) {
2445 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
2446 "the low-level driver\n", sdata->dev->name);
2447 return res;
2448 }
2449 }
2450
2451 if (is_valid_ether_addr(bssid))
2452 ifsta->flags |= IEEE80211_STA_BSSID_SET;
2453 else
2454 ifsta->flags &= ~IEEE80211_STA_BSSID_SET;
2455
2456 return 0;
2457}
2458
2459int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, char *ie, size_t len)
2460{
2461 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2462
2463 kfree(ifsta->extra_ie);
2464 if (len == 0) {
2465 ifsta->extra_ie = NULL;
2466 ifsta->extra_ie_len = 0;
2467 return 0;
2468 }
2469 ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
2470 if (!ifsta->extra_ie) {
2471 ifsta->extra_ie_len = 0;
2472 return -ENOMEM;
2473 }
2474 memcpy(ifsta->extra_ie, ie, len);
2475 ifsta->extra_ie_len = len;
2476 return 0;
2477}
2478
2479int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason)
2480{
2481 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2482
2483 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2484 sdata->dev->name, reason);
2485
2486 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2487 sdata->vif.type != NL80211_IFTYPE_ADHOC)
2488 return -EINVAL;
2489
2490 ieee80211_set_disassoc(sdata, ifsta, true, true, reason);
2491 return 0;
2492}
2493
2494int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2495{
2496 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
2497
2498 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2499 sdata->dev->name, reason);
2500
2501 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2502 return -EINVAL;
2503
2504 if (!(ifsta->flags & IEEE80211_STA_ASSOCIATED))
2505 return -1;
2506
2507 ieee80211_set_disassoc(sdata, ifsta, false, true, reason);
2508 return 0;
2509}
2510
2511/* scan finished notification */
2623void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) 2512void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2624{ 2513{
2625 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 2514 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2626 struct ieee80211_if_sta *ifsta; 2515 struct ieee80211_if_sta *ifsta;
2627 2516
2628 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 2517 if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2629 ifsta = &sdata->u.sta; 2518 ifsta = &sdata->u.sta;
2630 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) || 2519 if (!(ifsta->flags & IEEE80211_STA_BSSID_SET) ||
2631 (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) && 2520 (!(ifsta->state == IEEE80211_STA_MLME_IBSS_JOINED) &&
2632 !ieee80211_sta_active_ibss(sdata))) 2521 !ieee80211_sta_active_ibss(sdata)))
2633 ieee80211_sta_find_ibss(sdata, ifsta); 2522 ieee80211_sta_find_ibss(sdata, ifsta);
2634 } 2523 }
2524
2525 /* Restart STA timers */
2526 rcu_read_lock();
2527 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2528 ieee80211_restart_sta_timer(sdata);
2529 rcu_read_unlock();
2530}
2531
2532/* driver notification call */
2533void ieee80211_notify_mac(struct ieee80211_hw *hw,
2534 enum ieee80211_notification_types notif_type)
2535{
2536 struct ieee80211_local *local = hw_to_local(hw);
2537 struct ieee80211_sub_if_data *sdata;
2538
2539 switch (notif_type) {
2540 case IEEE80211_NOTIFY_RE_ASSOC:
2541 rcu_read_lock();
2542 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
2543 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2544 continue;
2545
2546 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
2547 }
2548 rcu_read_unlock();
2549 break;
2550 }
2635} 2551}
2552EXPORT_SYMBOL(ieee80211_notify_mac);
diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
index ede7ab56f65b..5f18c27eb900 100644
--- a/net/mac80211/rate.h
+++ b/net/mac80211/rate.h
@@ -134,7 +134,7 @@ static inline int rate_supported(struct sta_info *sta,
134 enum ieee80211_band band, 134 enum ieee80211_band band,
135 int index) 135 int index)
136{ 136{
137 return (sta == NULL || sta->supp_rates[band] & BIT(index)); 137 return (sta == NULL || sta->sta.supp_rates[band] & BIT(index));
138} 138}
139 139
140static inline s8 140static inline s8
diff --git a/net/mac80211/rc80211_pid.h b/net/mac80211/rc80211_pid.h
index 0a9135b974b5..ffafc5da572e 100644
--- a/net/mac80211/rc80211_pid.h
+++ b/net/mac80211/rc80211_pid.h
@@ -180,6 +180,8 @@ struct rc_pid_sta_info {
180 u32 tx_num_failed; 180 u32 tx_num_failed;
181 u32 tx_num_xmit; 181 u32 tx_num_xmit;
182 182
183 int txrate_idx;
184
183 /* Average failed frames percentage error (i.e. actual vs. target 185 /* Average failed frames percentage error (i.e. actual vs. target
184 * percentage), scaled by RC_PID_SMOOTHING. This value is computed 186 * percentage), scaled by RC_PID_SMOOTHING. This value is computed
185 * using using an exponential weighted average technique: 187 * using using an exponential weighted average technique:
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index a914ba73ccf5..bc1c4569caa1 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -75,7 +75,8 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
75 struct ieee80211_sub_if_data *sdata; 75 struct ieee80211_sub_if_data *sdata;
76 struct ieee80211_supported_band *sband; 76 struct ieee80211_supported_band *sband;
77 int cur_sorted, new_sorted, probe, tmp, n_bitrates, band; 77 int cur_sorted, new_sorted, probe, tmp, n_bitrates, band;
78 int cur = sta->txrate_idx; 78 struct rc_pid_sta_info *spinfo = (void *)sta->rate_ctrl_priv;
79 int cur = spinfo->txrate_idx;
79 80
80 sdata = sta->sdata; 81 sdata = sta->sdata;
81 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 82 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
@@ -111,7 +112,7 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
111 /* Fit the rate found to the nearest supported rate. */ 112 /* Fit the rate found to the nearest supported rate. */
112 do { 113 do {
113 if (rate_supported(sta, band, rinfo[tmp].index)) { 114 if (rate_supported(sta, band, rinfo[tmp].index)) {
114 sta->txrate_idx = rinfo[tmp].index; 115 spinfo->txrate_idx = rinfo[tmp].index;
115 break; 116 break;
116 } 117 }
117 if (adj < 0) 118 if (adj < 0)
@@ -121,9 +122,9 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
121 } while (tmp < n_bitrates && tmp >= 0); 122 } while (tmp < n_bitrates && tmp >= 0);
122 123
123#ifdef CONFIG_MAC80211_DEBUGFS 124#ifdef CONFIG_MAC80211_DEBUGFS
124 rate_control_pid_event_rate_change( 125 rate_control_pid_event_rate_change(&spinfo->events,
125 &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events, 126 spinfo->txrate_idx,
126 sta->txrate_idx, sband->bitrates[sta->txrate_idx].bitrate); 127 sband->bitrates[spinfo->txrate_idx].bitrate);
127#endif 128#endif
128} 129}
129 130
@@ -148,9 +149,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
148 struct ieee80211_local *local, 149 struct ieee80211_local *local,
149 struct sta_info *sta) 150 struct sta_info *sta)
150{ 151{
151#ifdef CONFIG_MAC80211_MESH
152 struct ieee80211_sub_if_data *sdata = sta->sdata; 152 struct ieee80211_sub_if_data *sdata = sta->sdata;
153#endif
154 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv; 153 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
155 struct rc_pid_rateinfo *rinfo = pinfo->rinfo; 154 struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
156 struct ieee80211_supported_band *sband; 155 struct ieee80211_supported_band *sband;
@@ -181,11 +180,8 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
181 pf = spinfo->last_pf; 180 pf = spinfo->last_pf;
182 else { 181 else {
183 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit; 182 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
184#ifdef CONFIG_MAC80211_MESH 183 if (ieee80211_vif_is_mesh(&sdata->vif) && pf == 100)
185 if (pf == 100 &&
186 sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
187 mesh_plink_broken(sta); 184 mesh_plink_broken(sta);
188#endif
189 pf <<= RC_PID_ARITH_SHIFT; 185 pf <<= RC_PID_ARITH_SHIFT;
190 sta->fail_avg = ((pf + (spinfo->last_pf << 3)) / 9) 186 sta->fail_avg = ((pf + (spinfo->last_pf << 3)) / 9)
191 >> RC_PID_ARITH_SHIFT; 187 >> RC_PID_ARITH_SHIFT;
@@ -195,16 +191,16 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
195 spinfo->tx_num_failed = 0; 191 spinfo->tx_num_failed = 0;
196 192
197 /* If we just switched rate, update the rate behaviour info. */ 193 /* If we just switched rate, update the rate behaviour info. */
198 if (pinfo->oldrate != sta->txrate_idx) { 194 if (pinfo->oldrate != spinfo->txrate_idx) {
199 195
200 i = rinfo[pinfo->oldrate].rev_index; 196 i = rinfo[pinfo->oldrate].rev_index;
201 j = rinfo[sta->txrate_idx].rev_index; 197 j = rinfo[spinfo->txrate_idx].rev_index;
202 198
203 tmp = (pf - spinfo->last_pf); 199 tmp = (pf - spinfo->last_pf);
204 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT); 200 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
205 201
206 rinfo[j].diff = rinfo[i].diff + tmp; 202 rinfo[j].diff = rinfo[i].diff + tmp;
207 pinfo->oldrate = sta->txrate_idx; 203 pinfo->oldrate = spinfo->txrate_idx;
208 } 204 }
209 rate_control_pid_normalize(pinfo, sband->n_bitrates); 205 rate_control_pid_normalize(pinfo, sband->n_bitrates);
210 206
@@ -257,19 +253,20 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
257 if (!sta) 253 if (!sta)
258 goto unlock; 254 goto unlock;
259 255
256 spinfo = sta->rate_ctrl_priv;
257
260 /* Don't update the state if we're not controlling the rate. */ 258 /* Don't update the state if we're not controlling the rate. */
261 sdata = sta->sdata; 259 sdata = sta->sdata;
262 if (sdata->force_unicast_rateidx > -1) { 260 if (sdata->force_unicast_rateidx > -1) {
263 sta->txrate_idx = sdata->max_ratectrl_rateidx; 261 spinfo->txrate_idx = sdata->max_ratectrl_rateidx;
264 goto unlock; 262 goto unlock;
265 } 263 }
266 264
267 /* Ignore all frames that were sent with a different rate than the rate 265 /* Ignore all frames that were sent with a different rate than the rate
268 * we currently advise mac80211 to use. */ 266 * we currently advise mac80211 to use. */
269 if (info->tx_rate_idx != sta->txrate_idx) 267 if (info->tx_rate_idx != spinfo->txrate_idx)
270 goto unlock; 268 goto unlock;
271 269
272 spinfo = sta->rate_ctrl_priv;
273 spinfo->tx_num_xmit++; 270 spinfo->tx_num_xmit++;
274 271
275#ifdef CONFIG_MAC80211_DEBUGFS 272#ifdef CONFIG_MAC80211_DEBUGFS
@@ -287,17 +284,6 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
287 spinfo->tx_num_xmit++; 284 spinfo->tx_num_xmit++;
288 } 285 }
289 286
290 if (info->status.excessive_retries) {
291 sta->tx_retry_failed++;
292 sta->tx_num_consecutive_failures++;
293 sta->tx_num_mpdu_fail++;
294 } else {
295 sta->tx_num_consecutive_failures = 0;
296 sta->tx_num_mpdu_ok++;
297 }
298 sta->tx_retry_count += info->status.retry_count;
299 sta->tx_num_mpdu_fail += info->status.retry_count;
300
301 /* Update PID controller state. */ 287 /* Update PID controller state. */
302 period = (HZ * pinfo->sampling_period + 500) / 1000; 288 period = (HZ * pinfo->sampling_period + 500) / 1000;
303 if (!period) 289 if (!period)
@@ -317,6 +303,7 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
317 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 303 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
318 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 304 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
319 struct ieee80211_sub_if_data *sdata; 305 struct ieee80211_sub_if_data *sdata;
306 struct rc_pid_sta_info *spinfo;
320 struct sta_info *sta; 307 struct sta_info *sta;
321 int rateidx; 308 int rateidx;
322 u16 fc; 309 u16 fc;
@@ -337,16 +324,15 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
337 324
338 /* If a forced rate is in effect, select it. */ 325 /* If a forced rate is in effect, select it. */
339 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 326 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
327 spinfo = (struct rc_pid_sta_info *)sta->rate_ctrl_priv;
340 if (sdata->force_unicast_rateidx > -1) 328 if (sdata->force_unicast_rateidx > -1)
341 sta->txrate_idx = sdata->force_unicast_rateidx; 329 spinfo->txrate_idx = sdata->force_unicast_rateidx;
342 330
343 rateidx = sta->txrate_idx; 331 rateidx = spinfo->txrate_idx;
344 332
345 if (rateidx >= sband->n_bitrates) 333 if (rateidx >= sband->n_bitrates)
346 rateidx = sband->n_bitrates - 1; 334 rateidx = sband->n_bitrates - 1;
347 335
348 sta->last_txrate_idx = rateidx;
349
350 rcu_read_unlock(); 336 rcu_read_unlock();
351 337
352 sel->rate_idx = rateidx; 338 sel->rate_idx = rateidx;
@@ -367,9 +353,10 @@ static void rate_control_pid_rate_init(void *priv, void *priv_sta,
367 * Until that method is implemented, we will use the lowest supported 353 * Until that method is implemented, we will use the lowest supported
368 * rate as a workaround. */ 354 * rate as a workaround. */
369 struct ieee80211_supported_band *sband; 355 struct ieee80211_supported_band *sband;
356 struct rc_pid_sta_info *spinfo = (void *)sta->rate_ctrl_priv;
370 357
371 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 358 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
372 sta->txrate_idx = rate_lowest_index(local, sband, sta); 359 spinfo->txrate_idx = rate_lowest_index(local, sband, sta);
373 sta->fail_avg = 0; 360 sta->fail_avg = 0;
374} 361}
375 362
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index d0803797902b..92d898b901e9 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -295,7 +295,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
295 if (!netif_running(sdata->dev)) 295 if (!netif_running(sdata->dev))
296 continue; 296 continue;
297 297
298 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR) 298 if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
299 continue; 299 continue;
300 300
301 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) 301 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
@@ -403,12 +403,12 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
403 struct ieee80211_local *local = rx->local; 403 struct ieee80211_local *local = rx->local;
404 struct sk_buff *skb = rx->skb; 404 struct sk_buff *skb = rx->skb;
405 405
406 if (unlikely(local->sta_hw_scanning)) 406 if (unlikely(local->hw_scanning))
407 return ieee80211_sta_rx_scan(rx->sdata, skb, rx->status); 407 return ieee80211_scan_rx(rx->sdata, skb, rx->status);
408 408
409 if (unlikely(local->sta_sw_scanning)) { 409 if (unlikely(local->sw_scanning)) {
410 /* drop all the other packets during a software scan anyway */ 410 /* drop all the other packets during a software scan anyway */
411 if (ieee80211_sta_rx_scan(rx->sdata, skb, rx->status) 411 if (ieee80211_scan_rx(rx->sdata, skb, rx->status)
412 != RX_QUEUED) 412 != RX_QUEUED)
413 dev_kfree_skb(skb); 413 dev_kfree_skb(skb);
414 return RX_QUEUED; 414 return RX_QUEUED;
@@ -501,8 +501,8 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
501 /* Drop disallowed frame classes based on STA auth/assoc state; 501 /* Drop disallowed frame classes based on STA auth/assoc state;
502 * IEEE 802.11, Chap 5.5. 502 * IEEE 802.11, Chap 5.5.
503 * 503 *
504 * 80211.o does filtering only based on association state, i.e., it 504 * mac80211 filters only based on association state, i.e. it drops
505 * drops Class 3 frames from not associated stations. hostapd sends 505 * Class 3 frames from not associated stations. hostapd sends
506 * deauth/disassoc frames when needed. In addition, hostapd is 506 * deauth/disassoc frames when needed. In addition, hostapd is
507 * responsible for filtering on both auth and assoc states. 507 * responsible for filtering on both auth and assoc states.
508 */ 508 */
@@ -512,7 +512,7 @@ ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
512 512
513 if (unlikely((ieee80211_is_data(hdr->frame_control) || 513 if (unlikely((ieee80211_is_data(hdr->frame_control) ||
514 ieee80211_is_pspoll(hdr->frame_control)) && 514 ieee80211_is_pspoll(hdr->frame_control)) &&
515 rx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 515 rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
516 (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) { 516 (!rx->sta || !test_sta_flags(rx->sta, WLAN_STA_ASSOC)))) {
517 if ((!ieee80211_has_fromds(hdr->frame_control) && 517 if ((!ieee80211_has_fromds(hdr->frame_control) &&
518 !ieee80211_has_tods(hdr->frame_control) && 518 !ieee80211_has_tods(hdr->frame_control) &&
@@ -661,7 +661,7 @@ static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
661 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL); 661 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL);
662#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 662#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
663 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", 663 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
664 dev->name, print_mac(mac, sta->addr), sta->aid); 664 dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
665#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 665#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
666} 666}
667 667
@@ -685,7 +685,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
685 685
686#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 686#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
687 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", 687 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
688 dev->name, print_mac(mac, sta->addr), sta->aid); 688 dev->name, print_mac(mac, sta->sta.addr), sta->sta.aid);
689#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 689#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
690 690
691 /* Send all buffered frames to the station */ 691 /* Send all buffered frames to the station */
@@ -702,7 +702,7 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
702#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 702#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
703 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame " 703 printk(KERN_DEBUG "%s: STA %s aid %d send PS frame "
704 "since STA not sleeping anymore\n", dev->name, 704 "since STA not sleeping anymore\n", dev->name,
705 print_mac(mac, sta->addr), sta->aid); 705 print_mac(mac, sta->sta.addr), sta->sta.aid);
706#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 706#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
707 info->flags |= IEEE80211_TX_CTL_REQUEUE; 707 info->flags |= IEEE80211_TX_CTL_REQUEUE;
708 dev_queue_xmit(skb); 708 dev_queue_xmit(skb);
@@ -724,14 +724,14 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
724 /* Update last_rx only for IBSS packets which are for the current 724 /* Update last_rx only for IBSS packets which are for the current
725 * BSSID to avoid keeping the current IBSS network alive in cases where 725 * BSSID to avoid keeping the current IBSS network alive in cases where
726 * other STAs are using different BSSID. */ 726 * other STAs are using different BSSID. */
727 if (rx->sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 727 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
728 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, 728 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
729 IEEE80211_IF_TYPE_IBSS); 729 NL80211_IFTYPE_ADHOC);
730 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0) 730 if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
731 sta->last_rx = jiffies; 731 sta->last_rx = jiffies;
732 } else 732 } else
733 if (!is_multicast_ether_addr(hdr->addr1) || 733 if (!is_multicast_ether_addr(hdr->addr1) ||
734 rx->sdata->vif.type == IEEE80211_IF_TYPE_STA) { 734 rx->sdata->vif.type == NL80211_IFTYPE_STATION) {
735 /* Update last_rx only for unicast frames in order to prevent 735 /* Update last_rx only for unicast frames in order to prevent
736 * the Probe Request frames (the only broadcast frames from a 736 * the Probe Request frames (the only broadcast frames from a
737 * STA in infrastructure mode) from keeping a connection alive. 737 * STA in infrastructure mode) from keeping a connection alive.
@@ -751,8 +751,8 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
751 sta->last_noise = rx->status->noise; 751 sta->last_noise = rx->status->noise;
752 752
753 if (!ieee80211_has_morefrags(hdr->frame_control) && 753 if (!ieee80211_has_morefrags(hdr->frame_control) &&
754 (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP || 754 (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
755 rx->sdata->vif.type == IEEE80211_IF_TYPE_VLAN)) { 755 rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
756 /* Change STA power saving mode only in the end of a frame 756 /* Change STA power saving mode only in the end of a frame
757 * exchange sequence */ 757 * exchange sequence */
758 if (test_sta_flags(sta, WLAN_STA_PS) && 758 if (test_sta_flags(sta, WLAN_STA_PS) &&
@@ -982,8 +982,8 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
982 !(rx->flags & IEEE80211_RX_RA_MATCH))) 982 !(rx->flags & IEEE80211_RX_RA_MATCH)))
983 return RX_CONTINUE; 983 return RX_CONTINUE;
984 984
985 if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) && 985 if ((sdata->vif.type != NL80211_IFTYPE_AP) &&
986 (sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) 986 (sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
987 return RX_DROP_UNUSABLE; 987 return RX_DROP_UNUSABLE;
988 988
989 skb = skb_dequeue(&rx->sta->tx_filtered); 989 skb = skb_dequeue(&rx->sta->tx_filtered);
@@ -1007,7 +1007,7 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1007 1007
1008#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1008#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1009 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", 1009 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
1010 print_mac(mac, rx->sta->addr), rx->sta->aid, 1010 print_mac(mac, rx->sta->sta.addr), rx->sta->sta.aid,
1011 skb_queue_len(&rx->sta->ps_tx_buf)); 1011 skb_queue_len(&rx->sta->ps_tx_buf));
1012#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1012#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1013 1013
@@ -1032,7 +1032,7 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1032 */ 1032 */
1033 printk(KERN_DEBUG "%s: STA %s sent PS Poll even " 1033 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
1034 "though there are no buffered frames for it\n", 1034 "though there are no buffered frames for it\n",
1035 rx->dev->name, print_mac(mac, rx->sta->addr)); 1035 rx->dev->name, print_mac(mac, rx->sta->sta.addr));
1036#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1036#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1037 } 1037 }
1038 1038
@@ -1131,23 +1131,23 @@ ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1131 switch (hdr->frame_control & 1131 switch (hdr->frame_control &
1132 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { 1132 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
1133 case __constant_cpu_to_le16(IEEE80211_FCTL_TODS): 1133 case __constant_cpu_to_le16(IEEE80211_FCTL_TODS):
1134 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_AP && 1134 if (unlikely(sdata->vif.type != NL80211_IFTYPE_AP &&
1135 sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) 1135 sdata->vif.type != NL80211_IFTYPE_AP_VLAN))
1136 return -1; 1136 return -1;
1137 break; 1137 break;
1138 case __constant_cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS): 1138 case __constant_cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
1139 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS && 1139 if (unlikely(sdata->vif.type != NL80211_IFTYPE_WDS &&
1140 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) 1140 sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
1141 return -1; 1141 return -1;
1142 break; 1142 break;
1143 case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS): 1143 case __constant_cpu_to_le16(IEEE80211_FCTL_FROMDS):
1144 if (sdata->vif.type != IEEE80211_IF_TYPE_STA || 1144 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
1145 (is_multicast_ether_addr(dst) && 1145 (is_multicast_ether_addr(dst) &&
1146 !compare_ether_addr(src, dev->dev_addr))) 1146 !compare_ether_addr(src, dev->dev_addr)))
1147 return -1; 1147 return -1;
1148 break; 1148 break;
1149 case __constant_cpu_to_le16(0): 1149 case __constant_cpu_to_le16(0):
1150 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS) 1150 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
1151 return -1; 1151 return -1;
1152 break; 1152 break;
1153 } 1153 }
@@ -1221,8 +1221,9 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1221 skb = rx->skb; 1221 skb = rx->skb;
1222 xmit_skb = NULL; 1222 xmit_skb = NULL;
1223 1223
1224 if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP || 1224 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1225 sdata->vif.type == IEEE80211_IF_TYPE_VLAN) && 1225 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1226 !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
1226 (rx->flags & IEEE80211_RX_RA_MATCH)) { 1227 (rx->flags & IEEE80211_RX_RA_MATCH)) {
1227 if (is_multicast_ether_addr(ehdr->h_dest)) { 1228 if (is_multicast_ether_addr(ehdr->h_dest)) {
1228 /* 1229 /*
@@ -1404,7 +1405,7 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1404 1405
1405 if (rx->flags & IEEE80211_RX_RA_MATCH) { 1406 if (rx->flags & IEEE80211_RX_RA_MATCH) {
1406 if (!mesh_hdr->ttl) 1407 if (!mesh_hdr->ttl)
1407 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.sta, 1408 IEEE80211_IFSTA_MESH_CTR_INC(&rx->sdata->u.mesh,
1408 dropped_frames_ttl); 1409 dropped_frames_ttl);
1409 else { 1410 else {
1410 struct ieee80211_hdr *fwd_hdr; 1411 struct ieee80211_hdr *fwd_hdr;
@@ -1535,8 +1536,8 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1535 * FIXME: revisit this, I'm sure we should handle most 1536 * FIXME: revisit this, I'm sure we should handle most
1536 * of these frames in other modes as well! 1537 * of these frames in other modes as well!
1537 */ 1538 */
1538 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 1539 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1539 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) 1540 sdata->vif.type != NL80211_IFTYPE_ADHOC)
1540 return RX_DROP_MONITOR; 1541 return RX_DROP_MONITOR;
1541 1542
1542 switch (mgmt->u.action.category) { 1543 switch (mgmt->u.action.category) {
@@ -1591,9 +1592,11 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
1591 if (!(rx->flags & IEEE80211_RX_RA_MATCH)) 1592 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1592 return RX_DROP_MONITOR; 1593 return RX_DROP_MONITOR;
1593 1594
1594 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 1595 if (ieee80211_vif_is_mesh(&sdata->vif))
1595 sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 1596 return ieee80211_mesh_rx_mgmt(sdata, rx->skb, rx->status);
1596 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) 1597
1598 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1599 sdata->vif.type != NL80211_IFTYPE_ADHOC)
1597 return RX_DROP_MONITOR; 1600 return RX_DROP_MONITOR;
1598 1601
1599 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) 1602 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
@@ -1629,7 +1632,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1629 if (!ieee80211_has_protected(hdr->frame_control)) 1632 if (!ieee80211_has_protected(hdr->frame_control))
1630 goto ignore; 1633 goto ignore;
1631 1634
1632 if (rx->sdata->vif.type == IEEE80211_IF_TYPE_AP && keyidx) { 1635 if (rx->sdata->vif.type == NL80211_IFTYPE_AP && keyidx) {
1633 /* 1636 /*
1634 * APs with pairwise keys should never receive Michael MIC 1637 * APs with pairwise keys should never receive Michael MIC
1635 * errors for non-zero keyidx because these are reserved for 1638 * errors for non-zero keyidx because these are reserved for
@@ -1699,7 +1702,7 @@ static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1699 if (!netif_running(sdata->dev)) 1702 if (!netif_running(sdata->dev))
1700 continue; 1703 continue;
1701 1704
1702 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || 1705 if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
1703 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) 1706 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1704 continue; 1707 continue;
1705 1708
@@ -1798,7 +1801,7 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1798 int multicast = is_multicast_ether_addr(hdr->addr1); 1801 int multicast = is_multicast_ether_addr(hdr->addr1);
1799 1802
1800 switch (sdata->vif.type) { 1803 switch (sdata->vif.type) {
1801 case IEEE80211_IF_TYPE_STA: 1804 case NL80211_IFTYPE_STATION:
1802 if (!bssid) 1805 if (!bssid)
1803 return 0; 1806 return 0;
1804 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { 1807 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
@@ -1813,7 +1816,7 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1813 rx->flags &= ~IEEE80211_RX_RA_MATCH; 1816 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1814 } 1817 }
1815 break; 1818 break;
1816 case IEEE80211_IF_TYPE_IBSS: 1819 case NL80211_IFTYPE_ADHOC:
1817 if (!bssid) 1820 if (!bssid)
1818 return 0; 1821 return 0;
1819 if (ieee80211_is_beacon(hdr->frame_control)) { 1822 if (ieee80211_is_beacon(hdr->frame_control)) {
@@ -1834,7 +1837,7 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1834 bssid, hdr->addr2, 1837 bssid, hdr->addr2,
1835 BIT(rx->status->rate_idx)); 1838 BIT(rx->status->rate_idx));
1836 break; 1839 break;
1837 case IEEE80211_IF_TYPE_MESH_POINT: 1840 case NL80211_IFTYPE_MESH_POINT:
1838 if (!multicast && 1841 if (!multicast &&
1839 compare_ether_addr(sdata->dev->dev_addr, 1842 compare_ether_addr(sdata->dev->dev_addr,
1840 hdr->addr1) != 0) { 1843 hdr->addr1) != 0) {
@@ -1844,8 +1847,8 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1844 rx->flags &= ~IEEE80211_RX_RA_MATCH; 1847 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1845 } 1848 }
1846 break; 1849 break;
1847 case IEEE80211_IF_TYPE_VLAN: 1850 case NL80211_IFTYPE_AP_VLAN:
1848 case IEEE80211_IF_TYPE_AP: 1851 case NL80211_IFTYPE_AP:
1849 if (!bssid) { 1852 if (!bssid) {
1850 if (compare_ether_addr(sdata->dev->dev_addr, 1853 if (compare_ether_addr(sdata->dev->dev_addr,
1851 hdr->addr1)) 1854 hdr->addr1))
@@ -1857,16 +1860,17 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1857 rx->flags &= ~IEEE80211_RX_RA_MATCH; 1860 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1858 } 1861 }
1859 break; 1862 break;
1860 case IEEE80211_IF_TYPE_WDS: 1863 case NL80211_IFTYPE_WDS:
1861 if (bssid || !ieee80211_is_data(hdr->frame_control)) 1864 if (bssid || !ieee80211_is_data(hdr->frame_control))
1862 return 0; 1865 return 0;
1863 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2)) 1866 if (compare_ether_addr(sdata->u.wds.remote_addr, hdr->addr2))
1864 return 0; 1867 return 0;
1865 break; 1868 break;
1866 case IEEE80211_IF_TYPE_MNTR: 1869 case NL80211_IFTYPE_MONITOR:
1867 /* take everything */ 1870 /* take everything */
1868 break; 1871 break;
1869 case IEEE80211_IF_TYPE_INVALID: 1872 case NL80211_IFTYPE_UNSPECIFIED:
1873 case __NL80211_IFTYPE_AFTER_LAST:
1870 /* should never get here */ 1874 /* should never get here */
1871 WARN_ON(1); 1875 WARN_ON(1);
1872 break; 1876 break;
@@ -1915,7 +1919,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1915 return; 1919 return;
1916 } 1920 }
1917 1921
1918 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning)) 1922 if (unlikely(local->sw_scanning || local->hw_scanning))
1919 rx.flags |= IEEE80211_RX_IN_SCAN; 1923 rx.flags |= IEEE80211_RX_IN_SCAN;
1920 1924
1921 ieee80211_parse_qos(&rx); 1925 ieee80211_parse_qos(&rx);
@@ -1927,7 +1931,7 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1927 if (!netif_running(sdata->dev)) 1931 if (!netif_running(sdata->dev))
1928 continue; 1932 continue;
1929 1933
1930 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) 1934 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
1931 continue; 1935 continue;
1932 1936
1933 bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); 1937 bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
@@ -2136,7 +2140,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2136 /* if this mpdu is fragmented - terminate rx aggregation session */ 2140 /* if this mpdu is fragmented - terminate rx aggregation session */
2137 sc = le16_to_cpu(hdr->seq_ctrl); 2141 sc = le16_to_cpu(hdr->seq_ctrl);
2138 if (sc & IEEE80211_SCTL_FRAG) { 2142 if (sc & IEEE80211_SCTL_FRAG) {
2139 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->addr, 2143 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
2140 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP); 2144 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
2141 ret = 1; 2145 ret = 1;
2142 goto end_reorder; 2146 goto end_reorder;
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 010781b806f3..8e6685e7ae85 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -32,26 +32,26 @@
32 32
33void ieee80211_rx_bss_list_init(struct ieee80211_local *local) 33void ieee80211_rx_bss_list_init(struct ieee80211_local *local)
34{ 34{
35 spin_lock_init(&local->sta_bss_lock); 35 spin_lock_init(&local->bss_lock);
36 INIT_LIST_HEAD(&local->sta_bss_list); 36 INIT_LIST_HEAD(&local->bss_list);
37} 37}
38 38
39void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) 39void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local)
40{ 40{
41 struct ieee80211_sta_bss *bss, *tmp; 41 struct ieee80211_bss *bss, *tmp;
42 42
43 list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) 43 list_for_each_entry_safe(bss, tmp, &local->bss_list, list)
44 ieee80211_rx_bss_put(local, bss); 44 ieee80211_rx_bss_put(local, bss);
45} 45}
46 46
47struct ieee80211_sta_bss * 47struct ieee80211_bss *
48ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, 48ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
49 u8 *ssid, u8 ssid_len) 49 u8 *ssid, u8 ssid_len)
50{ 50{
51 struct ieee80211_sta_bss *bss; 51 struct ieee80211_bss *bss;
52 52
53 spin_lock_bh(&local->sta_bss_lock); 53 spin_lock_bh(&local->bss_lock);
54 bss = local->sta_bss_hash[STA_HASH(bssid)]; 54 bss = local->bss_hash[STA_HASH(bssid)];
55 while (bss) { 55 while (bss) {
56 if (!bss_mesh_cfg(bss) && 56 if (!bss_mesh_cfg(bss) &&
57 !memcmp(bss->bssid, bssid, ETH_ALEN) && 57 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
@@ -63,13 +63,13 @@ ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
63 } 63 }
64 bss = bss->hnext; 64 bss = bss->hnext;
65 } 65 }
66 spin_unlock_bh(&local->sta_bss_lock); 66 spin_unlock_bh(&local->bss_lock);
67 return bss; 67 return bss;
68} 68}
69 69
70/* Caller must hold local->sta_bss_lock */ 70/* Caller must hold local->bss_lock */
71static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, 71static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local,
72 struct ieee80211_sta_bss *bss) 72 struct ieee80211_bss *bss)
73{ 73{
74 u8 hash_idx; 74 u8 hash_idx;
75 75
@@ -79,20 +79,20 @@ static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local,
79 else 79 else
80 hash_idx = STA_HASH(bss->bssid); 80 hash_idx = STA_HASH(bss->bssid);
81 81
82 bss->hnext = local->sta_bss_hash[hash_idx]; 82 bss->hnext = local->bss_hash[hash_idx];
83 local->sta_bss_hash[hash_idx] = bss; 83 local->bss_hash[hash_idx] = bss;
84} 84}
85 85
86/* Caller must hold local->sta_bss_lock */ 86/* Caller must hold local->bss_lock */
87static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, 87static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local,
88 struct ieee80211_sta_bss *bss) 88 struct ieee80211_bss *bss)
89{ 89{
90 struct ieee80211_sta_bss *b, *prev = NULL; 90 struct ieee80211_bss *b, *prev = NULL;
91 b = local->sta_bss_hash[STA_HASH(bss->bssid)]; 91 b = local->bss_hash[STA_HASH(bss->bssid)];
92 while (b) { 92 while (b) {
93 if (b == bss) { 93 if (b == bss) {
94 if (!prev) 94 if (!prev)
95 local->sta_bss_hash[STA_HASH(bss->bssid)] = 95 local->bss_hash[STA_HASH(bss->bssid)] =
96 bss->hnext; 96 bss->hnext;
97 else 97 else
98 prev->hnext = bss->hnext; 98 prev->hnext = bss->hnext;
@@ -103,11 +103,11 @@ static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local,
103 } 103 }
104} 104}
105 105
106struct ieee80211_sta_bss * 106struct ieee80211_bss *
107ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, 107ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq,
108 u8 *ssid, u8 ssid_len) 108 u8 *ssid, u8 ssid_len)
109{ 109{
110 struct ieee80211_sta_bss *bss; 110 struct ieee80211_bss *bss;
111 111
112 bss = kzalloc(sizeof(*bss), GFP_ATOMIC); 112 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
113 if (!bss) 113 if (!bss)
@@ -120,23 +120,23 @@ ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq,
120 bss->ssid_len = ssid_len; 120 bss->ssid_len = ssid_len;
121 } 121 }
122 122
123 spin_lock_bh(&local->sta_bss_lock); 123 spin_lock_bh(&local->bss_lock);
124 /* TODO: order by RSSI? */ 124 /* TODO: order by RSSI? */
125 list_add_tail(&bss->list, &local->sta_bss_list); 125 list_add_tail(&bss->list, &local->bss_list);
126 __ieee80211_rx_bss_hash_add(local, bss); 126 __ieee80211_rx_bss_hash_add(local, bss);
127 spin_unlock_bh(&local->sta_bss_lock); 127 spin_unlock_bh(&local->bss_lock);
128 return bss; 128 return bss;
129} 129}
130 130
131#ifdef CONFIG_MAC80211_MESH 131#ifdef CONFIG_MAC80211_MESH
132static struct ieee80211_sta_bss * 132static struct ieee80211_bss *
133ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, 133ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
134 u8 *mesh_cfg, int freq) 134 u8 *mesh_cfg, int freq)
135{ 135{
136 struct ieee80211_sta_bss *bss; 136 struct ieee80211_bss *bss;
137 137
138 spin_lock_bh(&local->sta_bss_lock); 138 spin_lock_bh(&local->bss_lock);
139 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; 139 bss = local->bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
140 while (bss) { 140 while (bss) {
141 if (bss_mesh_cfg(bss) && 141 if (bss_mesh_cfg(bss) &&
142 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && 142 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
@@ -149,15 +149,15 @@ ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_i
149 } 149 }
150 bss = bss->hnext; 150 bss = bss->hnext;
151 } 151 }
152 spin_unlock_bh(&local->sta_bss_lock); 152 spin_unlock_bh(&local->bss_lock);
153 return bss; 153 return bss;
154} 154}
155 155
156static struct ieee80211_sta_bss * 156static struct ieee80211_bss *
157ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, 157ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len,
158 u8 *mesh_cfg, int mesh_config_len, int freq) 158 u8 *mesh_cfg, int mesh_config_len, int freq)
159{ 159{
160 struct ieee80211_sta_bss *bss; 160 struct ieee80211_bss *bss;
161 161
162 if (mesh_config_len != MESH_CFG_LEN) 162 if (mesh_config_len != MESH_CFG_LEN)
163 return NULL; 163 return NULL;
@@ -186,16 +186,16 @@ ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_i
186 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); 186 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
187 bss->mesh_id_len = mesh_id_len; 187 bss->mesh_id_len = mesh_id_len;
188 bss->freq = freq; 188 bss->freq = freq;
189 spin_lock_bh(&local->sta_bss_lock); 189 spin_lock_bh(&local->bss_lock);
190 /* TODO: order by RSSI? */ 190 /* TODO: order by RSSI? */
191 list_add_tail(&bss->list, &local->sta_bss_list); 191 list_add_tail(&bss->list, &local->bss_list);
192 __ieee80211_rx_bss_hash_add(local, bss); 192 __ieee80211_rx_bss_hash_add(local, bss);
193 spin_unlock_bh(&local->sta_bss_lock); 193 spin_unlock_bh(&local->bss_lock);
194 return bss; 194 return bss;
195} 195}
196#endif 196#endif
197 197
198static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) 198static void ieee80211_rx_bss_free(struct ieee80211_bss *bss)
199{ 199{
200 kfree(bss->ies); 200 kfree(bss->ies);
201 kfree(bss_mesh_id(bss)); 201 kfree(bss_mesh_id(bss));
@@ -204,21 +204,21 @@ static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
204} 204}
205 205
206void ieee80211_rx_bss_put(struct ieee80211_local *local, 206void ieee80211_rx_bss_put(struct ieee80211_local *local,
207 struct ieee80211_sta_bss *bss) 207 struct ieee80211_bss *bss)
208{ 208{
209 local_bh_disable(); 209 local_bh_disable();
210 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) { 210 if (!atomic_dec_and_lock(&bss->users, &local->bss_lock)) {
211 local_bh_enable(); 211 local_bh_enable();
212 return; 212 return;
213 } 213 }
214 214
215 __ieee80211_rx_bss_hash_del(local, bss); 215 __ieee80211_rx_bss_hash_del(local, bss);
216 list_del(&bss->list); 216 list_del(&bss->list);
217 spin_unlock_bh(&local->sta_bss_lock); 217 spin_unlock_bh(&local->bss_lock);
218 ieee80211_rx_bss_free(bss); 218 ieee80211_rx_bss_free(bss);
219} 219}
220 220
221struct ieee80211_sta_bss * 221struct ieee80211_bss *
222ieee80211_bss_info_update(struct ieee80211_local *local, 222ieee80211_bss_info_update(struct ieee80211_local *local,
223 struct ieee80211_rx_status *rx_status, 223 struct ieee80211_rx_status *rx_status,
224 struct ieee80211_mgmt *mgmt, 224 struct ieee80211_mgmt *mgmt,
@@ -226,7 +226,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
226 struct ieee802_11_elems *elems, 226 struct ieee802_11_elems *elems,
227 int freq, bool beacon) 227 int freq, bool beacon)
228{ 228{
229 struct ieee80211_sta_bss *bss; 229 struct ieee80211_bss *bss;
230 int clen; 230 int clen;
231 231
232#ifdef CONFIG_MAC80211_MESH 232#ifdef CONFIG_MAC80211_MESH
@@ -252,9 +252,9 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
252 } else { 252 } else {
253#if 0 253#if 0
254 /* TODO: order by RSSI? */ 254 /* TODO: order by RSSI? */
255 spin_lock_bh(&local->sta_bss_lock); 255 spin_lock_bh(&local->bss_lock);
256 list_move_tail(&bss->list, &local->sta_bss_list); 256 list_move_tail(&bss->list, &local->bss_list);
257 spin_unlock_bh(&local->sta_bss_lock); 257 spin_unlock_bh(&local->bss_lock);
258#endif 258#endif
259 } 259 }
260 260
@@ -327,11 +327,11 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
327} 327}
328 328
329ieee80211_rx_result 329ieee80211_rx_result
330ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 330ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
331 struct ieee80211_rx_status *rx_status) 331 struct ieee80211_rx_status *rx_status)
332{ 332{
333 struct ieee80211_mgmt *mgmt; 333 struct ieee80211_mgmt *mgmt;
334 struct ieee80211_sta_bss *bss; 334 struct ieee80211_bss *bss;
335 u8 *elements; 335 u8 *elements;
336 struct ieee80211_channel *channel; 336 struct ieee80211_channel *channel;
337 size_t baselen; 337 size_t baselen;
@@ -424,38 +424,37 @@ static void ieee80211_send_nullfunc(struct ieee80211_local *local,
424 ieee80211_tx_skb(sdata, skb, 0); 424 ieee80211_tx_skb(sdata, skb, 0);
425} 425}
426 426
427static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
428{
429 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
430 ieee80211_vif_is_mesh(&sdata->vif))
431 ieee80211_sta_timer((unsigned long)sdata);
432}
433
434void ieee80211_scan_completed(struct ieee80211_hw *hw) 427void ieee80211_scan_completed(struct ieee80211_hw *hw)
435{ 428{
436 struct ieee80211_local *local = hw_to_local(hw); 429 struct ieee80211_local *local = hw_to_local(hw);
437 struct ieee80211_sub_if_data *sdata; 430 struct ieee80211_sub_if_data *sdata;
438 union iwreq_data wrqu; 431 union iwreq_data wrqu;
439 432
433 if (WARN_ON(!local->hw_scanning && !local->sw_scanning))
434 return;
435
440 local->last_scan_completed = jiffies; 436 local->last_scan_completed = jiffies;
441 memset(&wrqu, 0, sizeof(wrqu)); 437 memset(&wrqu, 0, sizeof(wrqu));
442 wireless_send_event(local->scan_sdata->dev, SIOCGIWSCAN, &wrqu, NULL);
443 438
444 if (local->sta_hw_scanning) { 439 /*
445 local->sta_hw_scanning = 0; 440 * local->scan_sdata could have been NULLed by the interface
441 * down code in case we were scanning on an interface that is
442 * being taken down.
443 */
444 sdata = local->scan_sdata;
445 if (sdata)
446 wireless_send_event(sdata->dev, SIOCGIWSCAN, &wrqu, NULL);
447
448 if (local->hw_scanning) {
449 local->hw_scanning = false;
446 if (ieee80211_hw_config(local)) 450 if (ieee80211_hw_config(local))
447 printk(KERN_DEBUG "%s: failed to restore operational " 451 printk(KERN_DEBUG "%s: failed to restore operational "
448 "channel after scan\n", wiphy_name(local->hw.wiphy)); 452 "channel after scan\n", wiphy_name(local->hw.wiphy));
449 /* Restart STA timer for HW scan case */
450 rcu_read_lock();
451 list_for_each_entry_rcu(sdata, &local->interfaces, list)
452 ieee80211_restart_sta_timer(sdata);
453 rcu_read_unlock();
454 453
455 goto done; 454 goto done;
456 } 455 }
457 456
458 local->sta_sw_scanning = 0; 457 local->sw_scanning = false;
459 if (ieee80211_hw_config(local)) 458 if (ieee80211_hw_config(local))
460 printk(KERN_DEBUG "%s: failed to restore operational " 459 printk(KERN_DEBUG "%s: failed to restore operational "
461 "channel after scan\n", wiphy_name(local->hw.wiphy)); 460 "channel after scan\n", wiphy_name(local->hw.wiphy));
@@ -476,25 +475,24 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
476 rcu_read_lock(); 475 rcu_read_lock();
477 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 476 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
478 /* Tell AP we're back */ 477 /* Tell AP we're back */
479 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 478 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
480 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { 479 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
481 ieee80211_send_nullfunc(local, sdata, 0); 480 ieee80211_send_nullfunc(local, sdata, 0);
482 netif_tx_wake_all_queues(sdata->dev); 481 netif_tx_wake_all_queues(sdata->dev);
483 } 482 }
484 } else 483 } else
485 netif_tx_wake_all_queues(sdata->dev); 484 netif_tx_wake_all_queues(sdata->dev);
486
487 ieee80211_restart_sta_timer(sdata);
488 } 485 }
489 rcu_read_unlock(); 486 rcu_read_unlock();
490 487
491 done: 488 done:
492 ieee80211_mlme_notify_scan_completed(local); 489 ieee80211_mlme_notify_scan_completed(local);
490 ieee80211_mesh_notify_scan_completed(local);
493} 491}
494EXPORT_SYMBOL(ieee80211_scan_completed); 492EXPORT_SYMBOL(ieee80211_scan_completed);
495 493
496 494
497void ieee80211_sta_scan_work(struct work_struct *work) 495void ieee80211_scan_work(struct work_struct *work)
498{ 496{
499 struct ieee80211_local *local = 497 struct ieee80211_local *local =
500 container_of(work, struct ieee80211_local, scan_work.work); 498 container_of(work, struct ieee80211_local, scan_work.work);
@@ -504,7 +502,10 @@ void ieee80211_sta_scan_work(struct work_struct *work)
504 int skip; 502 int skip;
505 unsigned long next_delay = 0; 503 unsigned long next_delay = 0;
506 504
507 if (!local->sta_sw_scanning) 505 /*
506 * Avoid re-scheduling when the sdata is going away.
507 */
508 if (!netif_running(sdata->dev))
508 return; 509 return;
509 510
510 switch (local->scan_state) { 511 switch (local->scan_state) {
@@ -538,7 +539,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
538 chan = &sband->channels[local->scan_channel_idx]; 539 chan = &sband->channels[local->scan_channel_idx];
539 540
540 if (chan->flags & IEEE80211_CHAN_DISABLED || 541 if (chan->flags & IEEE80211_CHAN_DISABLED ||
541 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && 542 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
542 chan->flags & IEEE80211_CHAN_NO_IBSS)) 543 chan->flags & IEEE80211_CHAN_NO_IBSS))
543 skip = 1; 544 skip = 1;
544 545
@@ -583,14 +584,13 @@ void ieee80211_sta_scan_work(struct work_struct *work)
583 break; 584 break;
584 } 585 }
585 586
586 if (local->sta_sw_scanning) 587 queue_delayed_work(local->hw.workqueue, &local->scan_work,
587 queue_delayed_work(local->hw.workqueue, &local->scan_work, 588 next_delay);
588 next_delay);
589} 589}
590 590
591 591
592int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata, 592int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
593 u8 *ssid, size_t ssid_len) 593 u8 *ssid, size_t ssid_len)
594{ 594{
595 struct ieee80211_local *local = scan_sdata->local; 595 struct ieee80211_local *local = scan_sdata->local;
596 struct ieee80211_sub_if_data *sdata; 596 struct ieee80211_sub_if_data *sdata;
@@ -615,27 +615,30 @@ int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata,
615 * ResultCode: SUCCESS, INVALID_PARAMETERS 615 * ResultCode: SUCCESS, INVALID_PARAMETERS
616 */ 616 */
617 617
618 if (local->sta_sw_scanning || local->sta_hw_scanning) { 618 if (local->sw_scanning || local->hw_scanning) {
619 if (local->scan_sdata == scan_sdata) 619 if (local->scan_sdata == scan_sdata)
620 return 0; 620 return 0;
621 return -EBUSY; 621 return -EBUSY;
622 } 622 }
623 623
624 if (local->ops->hw_scan) { 624 if (local->ops->hw_scan) {
625 int rc = local->ops->hw_scan(local_to_hw(local), 625 int rc;
626 ssid, ssid_len); 626
627 if (!rc) { 627 local->hw_scanning = true;
628 local->sta_hw_scanning = 1; 628 rc = local->ops->hw_scan(local_to_hw(local), ssid, ssid_len);
629 local->scan_sdata = scan_sdata; 629 if (rc) {
630 local->hw_scanning = false;
631 return rc;
630 } 632 }
631 return rc; 633 local->scan_sdata = scan_sdata;
634 return 0;
632 } 635 }
633 636
634 local->sta_sw_scanning = 1; 637 local->sw_scanning = true;
635 638
636 rcu_read_lock(); 639 rcu_read_lock();
637 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 640 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
638 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 641 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
639 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { 642 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) {
640 netif_tx_stop_all_queues(sdata->dev); 643 netif_tx_stop_all_queues(sdata->dev);
641 ieee80211_send_nullfunc(local, sdata, 1); 644 ieee80211_send_nullfunc(local, sdata, 1);
@@ -672,13 +675,14 @@ int ieee80211_sta_start_scan(struct ieee80211_sub_if_data *scan_sdata,
672} 675}
673 676
674 677
675int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t ssid_len) 678int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
679 u8 *ssid, size_t ssid_len)
676{ 680{
677 struct ieee80211_local *local = sdata->local; 681 struct ieee80211_local *local = sdata->local;
678 struct ieee80211_if_sta *ifsta; 682 struct ieee80211_if_sta *ifsta;
679 683
680 if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 684 if (sdata->vif.type != NL80211_IFTYPE_STATION)
681 return ieee80211_sta_start_scan(sdata, ssid, ssid_len); 685 return ieee80211_start_scan(sdata, ssid, ssid_len);
682 686
683 /* 687 /*
684 * STA has a state machine that might need to defer scanning 688 * STA has a state machine that might need to defer scanning
@@ -686,7 +690,7 @@ int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t
686 * queue it up to the state machine in that case. 690 * queue it up to the state machine in that case.
687 */ 691 */
688 692
689 if (local->sta_sw_scanning || local->sta_hw_scanning) { 693 if (local->sw_scanning || local->hw_scanning) {
690 if (local->scan_sdata == sdata) 694 if (local->scan_sdata == sdata)
691 return 0; 695 return 0;
692 return -EBUSY; 696 return -EBUSY;
@@ -704,9 +708,9 @@ int ieee80211_sta_req_scan(struct ieee80211_sub_if_data *sdata, u8 *ssid, size_t
704} 708}
705 709
706 710
707static void ieee80211_sta_add_scan_ies(struct iw_request_info *info, 711static void ieee80211_scan_add_ies(struct iw_request_info *info,
708 struct ieee80211_sta_bss *bss, 712 struct ieee80211_bss *bss,
709 char **current_ev, char *end_buf) 713 char **current_ev, char *end_buf)
710{ 714{
711 u8 *pos, *end, *next; 715 u8 *pos, *end, *next;
712 struct iw_event iwe; 716 struct iw_event iwe;
@@ -746,10 +750,10 @@ static void ieee80211_sta_add_scan_ies(struct iw_request_info *info,
746 750
747 751
748static char * 752static char *
749ieee80211_sta_scan_result(struct ieee80211_local *local, 753ieee80211_scan_result(struct ieee80211_local *local,
750 struct iw_request_info *info, 754 struct iw_request_info *info,
751 struct ieee80211_sta_bss *bss, 755 struct ieee80211_bss *bss,
752 char *current_ev, char *end_buf) 756 char *current_ev, char *end_buf)
753{ 757{
754 struct iw_event iwe; 758 struct iw_event iwe;
755 char *buf; 759 char *buf;
@@ -825,7 +829,7 @@ ieee80211_sta_scan_result(struct ieee80211_local *local,
825 current_ev = iwe_stream_add_point(info, current_ev, end_buf, 829 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
826 &iwe, ""); 830 &iwe, "");
827 831
828 ieee80211_sta_add_scan_ies(info, bss, &current_ev, end_buf); 832 ieee80211_scan_add_ies(info, bss, &current_ev, end_buf);
829 833
830 if (bss->supp_rates_len > 0) { 834 if (bss->supp_rates_len > 0) {
831 /* display all supported rates in readable format */ 835 /* display all supported rates in readable format */
@@ -911,23 +915,23 @@ ieee80211_sta_scan_result(struct ieee80211_local *local,
911} 915}
912 916
913 917
914int ieee80211_sta_scan_results(struct ieee80211_local *local, 918int ieee80211_scan_results(struct ieee80211_local *local,
915 struct iw_request_info *info, 919 struct iw_request_info *info,
916 char *buf, size_t len) 920 char *buf, size_t len)
917{ 921{
918 char *current_ev = buf; 922 char *current_ev = buf;
919 char *end_buf = buf + len; 923 char *end_buf = buf + len;
920 struct ieee80211_sta_bss *bss; 924 struct ieee80211_bss *bss;
921 925
922 spin_lock_bh(&local->sta_bss_lock); 926 spin_lock_bh(&local->bss_lock);
923 list_for_each_entry(bss, &local->sta_bss_list, list) { 927 list_for_each_entry(bss, &local->bss_list, list) {
924 if (buf + len - current_ev <= IW_EV_ADDR_LEN) { 928 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
925 spin_unlock_bh(&local->sta_bss_lock); 929 spin_unlock_bh(&local->bss_lock);
926 return -E2BIG; 930 return -E2BIG;
927 } 931 }
928 current_ev = ieee80211_sta_scan_result(local, info, bss, 932 current_ev = ieee80211_scan_result(local, info, bss,
929 current_ev, end_buf); 933 current_ev, end_buf);
930 } 934 }
931 spin_unlock_bh(&local->sta_bss_lock); 935 spin_unlock_bh(&local->bss_lock);
932 return current_ev - buf; 936 return current_ev - buf;
933} 937}
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index f2ba653b9d69..d9774ac2e0f7 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -73,11 +73,11 @@ static int sta_info_hash_del(struct ieee80211_local *local,
73{ 73{
74 struct sta_info *s; 74 struct sta_info *s;
75 75
76 s = local->sta_hash[STA_HASH(sta->addr)]; 76 s = local->sta_hash[STA_HASH(sta->sta.addr)];
77 if (!s) 77 if (!s)
78 return -ENOENT; 78 return -ENOENT;
79 if (s == sta) { 79 if (s == sta) {
80 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], 80 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
81 s->hnext); 81 s->hnext);
82 return 0; 82 return 0;
83 } 83 }
@@ -94,13 +94,13 @@ static int sta_info_hash_del(struct ieee80211_local *local,
94 94
95/* protected by RCU */ 95/* protected by RCU */
96static struct sta_info *__sta_info_find(struct ieee80211_local *local, 96static struct sta_info *__sta_info_find(struct ieee80211_local *local,
97 u8 *addr) 97 const u8 *addr)
98{ 98{
99 struct sta_info *sta; 99 struct sta_info *sta;
100 100
101 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]); 101 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
102 while (sta) { 102 while (sta) {
103 if (compare_ether_addr(sta->addr, addr) == 0) 103 if (compare_ether_addr(sta->sta.addr, addr) == 0)
104 break; 104 break;
105 sta = rcu_dereference(sta->hnext); 105 sta = rcu_dereference(sta->hnext);
106 } 106 }
@@ -151,7 +151,7 @@ static void __sta_info_free(struct ieee80211_local *local,
151 151
152#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 152#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
153 printk(KERN_DEBUG "%s: Destroyed STA %s\n", 153 printk(KERN_DEBUG "%s: Destroyed STA %s\n",
154 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr)); 154 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->sta.addr));
155#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 155#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
156 156
157 kfree(sta); 157 kfree(sta);
@@ -219,8 +219,8 @@ void sta_info_destroy(struct sta_info *sta)
219static void sta_info_hash_add(struct ieee80211_local *local, 219static void sta_info_hash_add(struct ieee80211_local *local,
220 struct sta_info *sta) 220 struct sta_info *sta)
221{ 221{
222 sta->hnext = local->sta_hash[STA_HASH(sta->addr)]; 222 sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
223 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta); 223 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
224} 224}
225 225
226struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, 226struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
@@ -231,14 +231,14 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
231 int i; 231 int i;
232 DECLARE_MAC_BUF(mbuf); 232 DECLARE_MAC_BUF(mbuf);
233 233
234 sta = kzalloc(sizeof(*sta), gfp); 234 sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
235 if (!sta) 235 if (!sta)
236 return NULL; 236 return NULL;
237 237
238 spin_lock_init(&sta->lock); 238 spin_lock_init(&sta->lock);
239 spin_lock_init(&sta->flaglock); 239 spin_lock_init(&sta->flaglock);
240 240
241 memcpy(sta->addr, addr, ETH_ALEN); 241 memcpy(sta->sta.addr, addr, ETH_ALEN);
242 sta->local = local; 242 sta->local = local;
243 sta->sdata = sdata; 243 sta->sdata = sdata;
244 244
@@ -271,7 +271,7 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
271 271
272#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 272#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
273 printk(KERN_DEBUG "%s: Allocated STA %s\n", 273 printk(KERN_DEBUG "%s: Allocated STA %s\n",
274 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr)); 274 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->sta.addr));
275#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 275#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
276 276
277#ifdef CONFIG_MAC80211_MESH 277#ifdef CONFIG_MAC80211_MESH
@@ -300,15 +300,15 @@ int sta_info_insert(struct sta_info *sta)
300 goto out_free; 300 goto out_free;
301 } 301 }
302 302
303 if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0 || 303 if (WARN_ON(compare_ether_addr(sta->sta.addr, sdata->dev->dev_addr) == 0 ||
304 is_multicast_ether_addr(sta->addr))) { 304 is_multicast_ether_addr(sta->sta.addr))) {
305 err = -EINVAL; 305 err = -EINVAL;
306 goto out_free; 306 goto out_free;
307 } 307 }
308 308
309 spin_lock_irqsave(&local->sta_lock, flags); 309 spin_lock_irqsave(&local->sta_lock, flags);
310 /* check if STA exists already */ 310 /* check if STA exists already */
311 if (__sta_info_find(local, sta->addr)) { 311 if (__sta_info_find(local, sta->sta.addr)) {
312 spin_unlock_irqrestore(&local->sta_lock, flags); 312 spin_unlock_irqrestore(&local->sta_lock, flags);
313 err = -EEXIST; 313 err = -EEXIST;
314 goto out_free; 314 goto out_free;
@@ -319,18 +319,18 @@ int sta_info_insert(struct sta_info *sta)
319 319
320 /* notify driver */ 320 /* notify driver */
321 if (local->ops->sta_notify) { 321 if (local->ops->sta_notify) {
322 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 322 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
323 sdata = container_of(sdata->bss, 323 sdata = container_of(sdata->bss,
324 struct ieee80211_sub_if_data, 324 struct ieee80211_sub_if_data,
325 u.ap); 325 u.ap);
326 326
327 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 327 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
328 STA_NOTIFY_ADD, sta->addr); 328 STA_NOTIFY_ADD, &sta->sta);
329 } 329 }
330 330
331#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 331#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
332 printk(KERN_DEBUG "%s: Inserted STA %s\n", 332 printk(KERN_DEBUG "%s: Inserted STA %s\n",
333 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr)); 333 wiphy_name(local->hw.wiphy), print_mac(mac, sta->sta.addr));
334#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 334#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
335 335
336 spin_unlock_irqrestore(&local->sta_lock, flags); 336 spin_unlock_irqrestore(&local->sta_lock, flags);
@@ -379,11 +379,12 @@ static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
379{ 379{
380 BUG_ON(!bss); 380 BUG_ON(!bss);
381 381
382 __bss_tim_set(bss, sta->aid); 382 __bss_tim_set(bss, sta->sta.aid);
383 383
384 if (sta->local->ops->set_tim) { 384 if (sta->local->ops->set_tim) {
385 sta->local->tim_in_locked_section = true; 385 sta->local->tim_in_locked_section = true;
386 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1); 386 sta->local->ops->set_tim(local_to_hw(sta->local),
387 &sta->sta, true);
387 sta->local->tim_in_locked_section = false; 388 sta->local->tim_in_locked_section = false;
388 } 389 }
389} 390}
@@ -404,11 +405,12 @@ static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
404{ 405{
405 BUG_ON(!bss); 406 BUG_ON(!bss);
406 407
407 __bss_tim_clear(bss, sta->aid); 408 __bss_tim_clear(bss, sta->sta.aid);
408 409
409 if (sta->local->ops->set_tim) { 410 if (sta->local->ops->set_tim) {
410 sta->local->tim_in_locked_section = true; 411 sta->local->tim_in_locked_section = true;
411 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0); 412 sta->local->ops->set_tim(local_to_hw(sta->local),
413 &sta->sta, false);
412 sta->local->tim_in_locked_section = false; 414 sta->local->tim_in_locked_section = false;
413 } 415 }
414} 416}
@@ -424,7 +426,7 @@ void sta_info_clear_tim_bit(struct sta_info *sta)
424 spin_unlock_irqrestore(&sta->local->sta_lock, flags); 426 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
425} 427}
426 428
427void __sta_info_unlink(struct sta_info **sta) 429static void __sta_info_unlink(struct sta_info **sta)
428{ 430{
429 struct ieee80211_local *local = (*sta)->local; 431 struct ieee80211_local *local = (*sta)->local;
430 struct ieee80211_sub_if_data *sdata = (*sta)->sdata; 432 struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
@@ -456,13 +458,13 @@ void __sta_info_unlink(struct sta_info **sta)
456 local->num_sta--; 458 local->num_sta--;
457 459
458 if (local->ops->sta_notify) { 460 if (local->ops->sta_notify) {
459 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 461 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
460 sdata = container_of(sdata->bss, 462 sdata = container_of(sdata->bss,
461 struct ieee80211_sub_if_data, 463 struct ieee80211_sub_if_data,
462 u.ap); 464 u.ap);
463 465
464 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 466 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
465 STA_NOTIFY_REMOVE, (*sta)->addr); 467 STA_NOTIFY_REMOVE, &(*sta)->sta);
466 } 468 }
467 469
468 if (ieee80211_vif_is_mesh(&sdata->vif)) { 470 if (ieee80211_vif_is_mesh(&sdata->vif)) {
@@ -474,7 +476,7 @@ void __sta_info_unlink(struct sta_info **sta)
474 476
475#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 477#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
476 printk(KERN_DEBUG "%s: Removed STA %s\n", 478 printk(KERN_DEBUG "%s: Removed STA %s\n",
477 wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->addr)); 479 wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->sta.addr));
478#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 480#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
479 481
480 /* 482 /*
@@ -570,7 +572,7 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
570 local->total_ps_buffered--; 572 local->total_ps_buffered--;
571#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 573#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
572 printk(KERN_DEBUG "Buffered frame expired (STA " 574 printk(KERN_DEBUG "Buffered frame expired (STA "
573 "%s)\n", print_mac(mac, sta->addr)); 575 "%s)\n", print_mac(mac, sta->sta.addr));
574#endif 576#endif
575 dev_kfree_skb(skb); 577 dev_kfree_skb(skb);
576 578
@@ -802,3 +804,40 @@ void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata)
802 schedule_work(&local->sta_flush_work); 804 schedule_work(&local->sta_flush_work);
803 spin_unlock_irqrestore(&local->sta_lock, flags); 805 spin_unlock_irqrestore(&local->sta_lock, flags);
804} 806}
807
808void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
809 unsigned long exp_time)
810{
811 struct ieee80211_local *local = sdata->local;
812 struct sta_info *sta, *tmp;
813 LIST_HEAD(tmp_list);
814 DECLARE_MAC_BUF(mac);
815 unsigned long flags;
816
817 spin_lock_irqsave(&local->sta_lock, flags);
818 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
819 if (time_after(jiffies, sta->last_rx + exp_time)) {
820#ifdef CONFIG_MAC80211_IBSS_DEBUG
821 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
822 sdata->dev->name, print_mac(mac, sta->sta.addr));
823#endif
824 __sta_info_unlink(&sta);
825 if (sta)
826 list_add(&sta->list, &tmp_list);
827 }
828 spin_unlock_irqrestore(&local->sta_lock, flags);
829
830 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
831 sta_info_destroy(sta);
832}
833
834struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_hw *hw,
835 const u8 *addr)
836{
837 struct sta_info *sta = __sta_info_find(hw_to_local(hw), addr);
838
839 if (!sta)
840 return NULL;
841 return &sta->sta;
842}
843EXPORT_SYMBOL(ieee80211_find_sta);
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 4a581a5b5766..daedfa9e1c63 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -167,8 +167,6 @@ struct sta_ampdu_mlme {
167 * @lock: used for locking all fields that require locking, see comments 167 * @lock: used for locking all fields that require locking, see comments
168 * in the header file. 168 * in the header file.
169 * @flaglock: spinlock for flags accesses 169 * @flaglock: spinlock for flags accesses
170 * @ht_info: HT capabilities of this STA
171 * @supp_rates: Bitmap of supported rates (per band)
172 * @addr: MAC address of this STA 170 * @addr: MAC address of this STA
173 * @aid: STA's unique AID (1..2007, 0 = not assigned yet), 171 * @aid: STA's unique AID (1..2007, 0 = not assigned yet),
174 * only used in AP (and IBSS?) mode 172 * only used in AP (and IBSS?) mode
@@ -195,15 +193,11 @@ struct sta_ampdu_mlme {
195 * @tx_filtered_count: TBD 193 * @tx_filtered_count: TBD
196 * @tx_retry_failed: TBD 194 * @tx_retry_failed: TBD
197 * @tx_retry_count: TBD 195 * @tx_retry_count: TBD
198 * @tx_num_consecutive_failures: TBD
199 * @tx_num_mpdu_ok: TBD
200 * @tx_num_mpdu_fail: TBD
201 * @fail_avg: moving percentage of failed MSDUs 196 * @fail_avg: moving percentage of failed MSDUs
202 * @tx_packets: number of RX/TX MSDUs 197 * @tx_packets: number of RX/TX MSDUs
203 * @tx_bytes: TBD 198 * @tx_bytes: TBD
204 * @tx_fragments: number of transmitted MPDUs 199 * @tx_fragments: number of transmitted MPDUs
205 * @txrate_idx: TBD 200 * @last_txrate_idx: Index of the last used transmit rate
206 * @last_txrate_idx: TBD
207 * @tid_seq: TBD 201 * @tid_seq: TBD
208 * @wme_tx_queue: TBD 202 * @wme_tx_queue: TBD
209 * @ampdu_mlme: TBD 203 * @ampdu_mlme: TBD
@@ -218,6 +212,7 @@ struct sta_ampdu_mlme {
218 * @plink_timeout: TBD 212 * @plink_timeout: TBD
219 * @plink_timer: TBD 213 * @plink_timer: TBD
220 * @debugfs: debug filesystem info 214 * @debugfs: debug filesystem info
215 * @sta: station information we share with the driver
221 */ 216 */
222struct sta_info { 217struct sta_info {
223 /* General information, mostly static */ 218 /* General information, mostly static */
@@ -230,10 +225,7 @@ struct sta_info {
230 void *rate_ctrl_priv; 225 void *rate_ctrl_priv;
231 spinlock_t lock; 226 spinlock_t lock;
232 spinlock_t flaglock; 227 spinlock_t flaglock;
233 struct ieee80211_ht_info ht_info; 228
234 u64 supp_rates[IEEE80211_NUM_BANDS];
235 u8 addr[ETH_ALEN];
236 u16 aid;
237 u16 listen_interval; 229 u16 listen_interval;
238 230
239 /* 231 /*
@@ -273,10 +265,6 @@ struct sta_info {
273 /* Updated from TX status path only, no locking requirements */ 265 /* Updated from TX status path only, no locking requirements */
274 unsigned long tx_filtered_count; 266 unsigned long tx_filtered_count;
275 unsigned long tx_retry_failed, tx_retry_count; 267 unsigned long tx_retry_failed, tx_retry_count;
276 /* TODO: update in generic code not rate control? */
277 u32 tx_num_consecutive_failures;
278 u32 tx_num_mpdu_ok;
279 u32 tx_num_mpdu_fail;
280 /* moving percentage of failed MSDUs */ 268 /* moving percentage of failed MSDUs */
281 unsigned int fail_avg; 269 unsigned int fail_avg;
282 270
@@ -284,8 +272,7 @@ struct sta_info {
284 unsigned long tx_packets; 272 unsigned long tx_packets;
285 unsigned long tx_bytes; 273 unsigned long tx_bytes;
286 unsigned long tx_fragments; 274 unsigned long tx_fragments;
287 int txrate_idx; 275 unsigned int last_txrate_idx;
288 int last_txrate_idx;
289 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1]; 276 u16 tid_seq[IEEE80211_QOS_CTL_TID_MASK + 1];
290#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 277#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
291 unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES]; 278 unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
@@ -327,6 +314,9 @@ struct sta_info {
327 struct dentry *agg_status; 314 struct dentry *agg_status;
328 } debugfs; 315 } debugfs;
329#endif 316#endif
317
318 /* keep last! */
319 struct ieee80211_sta sta;
330}; 320};
331 321
332static inline enum plink_state sta_plink_state(struct sta_info *sta) 322static inline enum plink_state sta_plink_state(struct sta_info *sta)
@@ -452,7 +442,6 @@ int sta_info_insert(struct sta_info *sta);
452 * has already unlinked it. 442 * has already unlinked it.
453 */ 443 */
454void sta_info_unlink(struct sta_info **sta); 444void sta_info_unlink(struct sta_info **sta);
455void __sta_info_unlink(struct sta_info **sta);
456 445
457void sta_info_destroy(struct sta_info *sta); 446void sta_info_destroy(struct sta_info *sta);
458void sta_info_set_tim_bit(struct sta_info *sta); 447void sta_info_set_tim_bit(struct sta_info *sta);
@@ -464,5 +453,7 @@ void sta_info_stop(struct ieee80211_local *local);
464int sta_info_flush(struct ieee80211_local *local, 453int sta_info_flush(struct ieee80211_local *local,
465 struct ieee80211_sub_if_data *sdata); 454 struct ieee80211_sub_if_data *sdata);
466void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata); 455void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata);
456void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
457 unsigned long exp_time);
467 458
468#endif /* STA_INFO_H */ 459#endif /* STA_INFO_H */
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 995f7af3d25e..34b32bc8f609 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -304,7 +304,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
304 key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 304 key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
305 u8 bcast[ETH_ALEN] = 305 u8 bcast[ETH_ALEN] =
306 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 306 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
307 u8 *sta_addr = key->sta->addr; 307 u8 *sta_addr = key->sta->sta.addr;
308 308
309 if (is_multicast_ether_addr(ra)) 309 if (is_multicast_ether_addr(ra))
310 sta_addr = bcast; 310 sta_addr = bcast;
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index c413d4836afe..20d683641b42 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -38,43 +38,6 @@
38 38
39/* misc utils */ 39/* misc utils */
40 40
41#ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
42static void ieee80211_dump_frame(const char *ifname, const char *title,
43 const struct sk_buff *skb)
44{
45 const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
46 unsigned int hdrlen;
47 DECLARE_MAC_BUF(mac);
48
49 printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
50 if (skb->len < 4) {
51 printk("\n");
52 return;
53 }
54
55 hdrlen = ieee80211_hdrlen(hdr->frame_control);
56 if (hdrlen > skb->len)
57 hdrlen = skb->len;
58 if (hdrlen >= 4)
59 printk(" FC=0x%04x DUR=0x%04x",
60 le16_to_cpu(hdr->frame_control), le16_to_cpu(hdr->duration_id));
61 if (hdrlen >= 10)
62 printk(" A1=%s", print_mac(mac, hdr->addr1));
63 if (hdrlen >= 16)
64 printk(" A2=%s", print_mac(mac, hdr->addr2));
65 if (hdrlen >= 24)
66 printk(" A3=%s", print_mac(mac, hdr->addr3));
67 if (hdrlen >= 30)
68 printk(" A4=%s", print_mac(mac, hdr->addr4));
69 printk("\n");
70}
71#else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
72static inline void ieee80211_dump_frame(const char *ifname, const char *title,
73 struct sk_buff *skb)
74{
75}
76#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
77
78static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr, 41static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
79 int next_frag_len) 42 int next_frag_len)
80{ 43{
@@ -111,7 +74,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
111 hdr = (struct ieee80211_hdr *)tx->skb->data; 74 hdr = (struct ieee80211_hdr *)tx->skb->data;
112 if (ieee80211_is_ctl(hdr->frame_control)) { 75 if (ieee80211_is_ctl(hdr->frame_control)) {
113 /* TODO: These control frames are not currently sent by 76 /* TODO: These control frames are not currently sent by
114 * 80211.o, but should they be implemented, this function 77 * mac80211, but should they be implemented, this function
115 * needs to be updated to support duration field calculation. 78 * needs to be updated to support duration field calculation.
116 * 79 *
117 * RTS: time needed to transmit pending data/mgmt frame plus 80 * RTS: time needed to transmit pending data/mgmt frame plus
@@ -153,7 +116,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
153 if (r->bitrate > txrate->bitrate) 116 if (r->bitrate > txrate->bitrate)
154 break; 117 break;
155 118
156 if (tx->sdata->basic_rates & BIT(i)) 119 if (tx->sdata->bss_conf.basic_rates & BIT(i))
157 rate = r->bitrate; 120 rate = r->bitrate;
158 121
159 switch (sband->band) { 122 switch (sband->band) {
@@ -222,11 +185,11 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
222 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) 185 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
223 return TX_CONTINUE; 186 return TX_CONTINUE;
224 187
225 if (unlikely(tx->local->sta_sw_scanning) && 188 if (unlikely(tx->local->sw_scanning) &&
226 !ieee80211_is_probe_req(hdr->frame_control)) 189 !ieee80211_is_probe_req(hdr->frame_control))
227 return TX_DROP; 190 return TX_DROP;
228 191
229 if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) 192 if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
230 return TX_CONTINUE; 193 return TX_CONTINUE;
231 194
232 if (tx->flags & IEEE80211_TX_PS_BUFFERED) 195 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
@@ -236,7 +199,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
236 199
237 if (likely(tx->flags & IEEE80211_TX_UNICAST)) { 200 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
238 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) && 201 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
239 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 202 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
240 ieee80211_is_data(hdr->frame_control))) { 203 ieee80211_is_data(hdr->frame_control))) {
241#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 204#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
242 DECLARE_MAC_BUF(mac); 205 DECLARE_MAC_BUF(mac);
@@ -250,7 +213,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
250 } else { 213 } else {
251 if (unlikely(ieee80211_is_data(hdr->frame_control) && 214 if (unlikely(ieee80211_is_data(hdr->frame_control) &&
252 tx->local->num_sta == 0 && 215 tx->local->num_sta == 0 &&
253 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS)) { 216 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
254 /* 217 /*
255 * No associated STAs - no need to send multicast 218 * No associated STAs - no need to send multicast
256 * frames. 219 * frames.
@@ -281,7 +244,7 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
281 244
282 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 245 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
283 struct ieee80211_if_ap *ap; 246 struct ieee80211_if_ap *ap;
284 if (sdata->vif.type != IEEE80211_IF_TYPE_AP) 247 if (sdata->vif.type != NL80211_IFTYPE_AP)
285 continue; 248 continue;
286 ap = &sdata->u.ap; 249 ap = &sdata->u.ap;
287 skb = skb_dequeue(&ap->ps_bc_buf); 250 skb = skb_dequeue(&ap->ps_bc_buf);
@@ -381,7 +344,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
381#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 344#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
382 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries " 345 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries "
383 "before %d)\n", 346 "before %d)\n",
384 print_mac(mac, sta->addr), sta->aid, 347 print_mac(mac, sta->sta.addr), sta->sta.aid,
385 skb_queue_len(&sta->ps_tx_buf)); 348 skb_queue_len(&sta->ps_tx_buf));
386#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 349#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
387 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 350 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
@@ -392,7 +355,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
392 if (net_ratelimit()) { 355 if (net_ratelimit()) {
393 printk(KERN_DEBUG "%s: STA %s TX " 356 printk(KERN_DEBUG "%s: STA %s TX "
394 "buffer full - dropping oldest frame\n", 357 "buffer full - dropping oldest frame\n",
395 tx->dev->name, print_mac(mac, sta->addr)); 358 tx->dev->name, print_mac(mac, sta->sta.addr));
396 } 359 }
397#endif 360#endif
398 dev_kfree_skb(old); 361 dev_kfree_skb(old);
@@ -411,7 +374,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
411 else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) { 374 else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) {
412 printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll " 375 printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll "
413 "set -> send frame\n", tx->dev->name, 376 "set -> send frame\n", tx->dev->name,
414 print_mac(mac, sta->addr)); 377 print_mac(mac, sta->sta.addr));
415 } 378 }
416#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 379#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
417 clear_sta_flags(sta, WLAN_STA_PSPOLL); 380 clear_sta_flags(sta, WLAN_STA_PSPOLL);
@@ -485,6 +448,8 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
485 448
486 if (likely(tx->rate_idx < 0)) { 449 if (likely(tx->rate_idx < 0)) {
487 rate_control_get_rate(tx->dev, sband, tx->skb, &rsel); 450 rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
451 if (tx->sta)
452 tx->sta->last_txrate_idx = rsel.rate_idx;
488 tx->rate_idx = rsel.rate_idx; 453 tx->rate_idx = rsel.rate_idx;
489 if (unlikely(rsel.probe_idx >= 0)) { 454 if (unlikely(rsel.probe_idx >= 0)) {
490 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE; 455 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
@@ -528,7 +493,7 @@ ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
528 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 493 sband = tx->local->hw.wiphy->bands[tx->channel->band];
529 494
530 if (tx->sta) 495 if (tx->sta)
531 info->control.aid = tx->sta->aid; 496 info->control.sta = &tx->sta->sta;
532 497
533 if (!info->control.retry_limit) { 498 if (!info->control.retry_limit) {
534 if (!is_multicast_ether_addr(hdr->addr1)) { 499 if (!is_multicast_ether_addr(hdr->addr1)) {
@@ -594,7 +559,7 @@ ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
594 for (idx = 0; idx < sband->n_bitrates; idx++) { 559 for (idx = 0; idx < sband->n_bitrates; idx++) {
595 if (sband->bitrates[idx].bitrate > rate->bitrate) 560 if (sband->bitrates[idx].bitrate > rate->bitrate)
596 continue; 561 continue;
597 if (tx->sdata->basic_rates & BIT(idx) && 562 if (tx->sdata->bss_conf.basic_rates & BIT(idx) &&
598 (baserate < 0 || 563 (baserate < 0 ||
599 (sband->bitrates[baserate].bitrate 564 (sband->bitrates[baserate].bitrate
600 < sband->bitrates[idx].bitrate))) 565 < sband->bitrates[idx].bitrate)))
@@ -608,7 +573,7 @@ ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
608 } 573 }
609 574
610 if (tx->sta) 575 if (tx->sta)
611 info->control.aid = tx->sta->aid; 576 info->control.sta = &tx->sta->sta;
612 577
613 return TX_CONTINUE; 578 return TX_CONTINUE;
614} 579}
@@ -622,7 +587,14 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
622 u8 *qc; 587 u8 *qc;
623 int tid; 588 int tid;
624 589
625 /* only for injected frames */ 590 /*
591 * Packet injection may want to control the sequence
592 * number, if we have no matching interface then we
593 * neither assign one ourselves nor ask the driver to.
594 */
595 if (unlikely(!info->control.vif))
596 return TX_CONTINUE;
597
626 if (unlikely(ieee80211_is_ctl(hdr->frame_control))) 598 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
627 return TX_CONTINUE; 599 return TX_CONTINUE;
628 600
@@ -847,7 +819,6 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
847 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 819 sband = tx->local->hw.wiphy->bands[tx->channel->band];
848 820
849 skb->do_not_encrypt = 1; 821 skb->do_not_encrypt = 1;
850 info->flags |= IEEE80211_TX_CTL_INJECTED;
851 tx->flags &= ~IEEE80211_TX_FRAGMENTED; 822 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
852 823
853 /* 824 /*
@@ -979,7 +950,7 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
979 950
980 /* process and remove the injection radiotap header */ 951 /* process and remove the injection radiotap header */
981 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 952 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
982 if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) { 953 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
983 if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP) 954 if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP)
984 return TX_DROP; 955 return TX_DROP;
985 956
@@ -1060,8 +1031,6 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1060 return IEEE80211_TX_AGAIN; 1031 return IEEE80211_TX_AGAIN;
1061 info = IEEE80211_SKB_CB(skb); 1032 info = IEEE80211_SKB_CB(skb);
1062 1033
1063 ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
1064 "TX to low-level driver", skb);
1065 ret = local->ops->tx(local_to_hw(local), skb); 1034 ret = local->ops->tx(local_to_hw(local), skb);
1066 if (ret) 1035 if (ret)
1067 return IEEE80211_TX_AGAIN; 1036 return IEEE80211_TX_AGAIN;
@@ -1091,9 +1060,6 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1091 ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; 1060 ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
1092 } 1061 }
1093 1062
1094 ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
1095 "TX to low-level driver",
1096 tx->extra_frag[i]);
1097 ret = local->ops->tx(local_to_hw(local), 1063 ret = local->ops->tx(local_to_hw(local),
1098 tx->extra_frag[i]); 1064 tx->extra_frag[i]);
1099 if (ret) 1065 if (ret)
@@ -1298,6 +1264,11 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
1298 struct ieee80211_sub_if_data *osdata; 1264 struct ieee80211_sub_if_data *osdata;
1299 int headroom; 1265 int headroom;
1300 bool may_encrypt; 1266 bool may_encrypt;
1267 enum {
1268 NOT_MONITOR,
1269 FOUND_SDATA,
1270 UNKNOWN_ADDRESS,
1271 } monitor_iface = NOT_MONITOR;
1301 int ret; 1272 int ret;
1302 1273
1303 if (skb->iif) 1274 if (skb->iif)
@@ -1330,9 +1301,53 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
1330 if (mesh_nexthop_lookup(skb, osdata)) 1301 if (mesh_nexthop_lookup(skb, osdata))
1331 return 0; 1302 return 0;
1332 if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0) 1303 if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0)
1333 IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.sta, 1304 IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.mesh,
1334 fwded_frames); 1305 fwded_frames);
1335 } 1306 }
1307 } else if (unlikely(osdata->vif.type == NL80211_IFTYPE_MONITOR)) {
1308 struct ieee80211_sub_if_data *sdata;
1309 struct ieee80211_local *local = osdata->local;
1310 struct ieee80211_hdr *hdr;
1311 int hdrlen;
1312 u16 len_rthdr;
1313
1314 info->flags |= IEEE80211_TX_CTL_INJECTED;
1315 monitor_iface = UNKNOWN_ADDRESS;
1316
1317 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1318 hdr = (struct ieee80211_hdr *)skb->data + len_rthdr;
1319 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1320
1321 /* check the header is complete in the frame */
1322 if (likely(skb->len >= len_rthdr + hdrlen)) {
1323 /*
1324 * We process outgoing injected frames that have a
1325 * local address we handle as though they are our
1326 * own frames.
1327 * This code here isn't entirely correct, the local
1328 * MAC address is not necessarily enough to find
1329 * the interface to use; for that proper VLAN/WDS
1330 * support we will need a different mechanism.
1331 */
1332
1333 rcu_read_lock();
1334 list_for_each_entry_rcu(sdata, &local->interfaces,
1335 list) {
1336 if (!netif_running(sdata->dev))
1337 continue;
1338 if (compare_ether_addr(sdata->dev->dev_addr,
1339 hdr->addr2)) {
1340 dev_hold(sdata->dev);
1341 dev_put(odev);
1342 osdata = sdata;
1343 odev = osdata->dev;
1344 skb->iif = sdata->dev->ifindex;
1345 monitor_iface = FOUND_SDATA;
1346 break;
1347 }
1348 }
1349 rcu_read_unlock();
1350 }
1336 } 1351 }
1337 1352
1338 may_encrypt = !skb->do_not_encrypt; 1353 may_encrypt = !skb->do_not_encrypt;
@@ -1349,7 +1364,12 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
1349 return 0; 1364 return 0;
1350 } 1365 }
1351 1366
1352 info->control.vif = &osdata->vif; 1367 if (osdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1368 osdata = container_of(osdata->bss,
1369 struct ieee80211_sub_if_data,
1370 u.ap);
1371 if (likely(monitor_iface != UNKNOWN_ADDRESS))
1372 info->control.vif = &osdata->vif;
1353 ret = ieee80211_tx(odev, skb); 1373 ret = ieee80211_tx(odev, skb);
1354 dev_put(odev); 1374 dev_put(odev);
1355 1375
@@ -1457,8 +1477,8 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1457 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); 1477 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
1458 1478
1459 switch (sdata->vif.type) { 1479 switch (sdata->vif.type) {
1460 case IEEE80211_IF_TYPE_AP: 1480 case NL80211_IFTYPE_AP:
1461 case IEEE80211_IF_TYPE_VLAN: 1481 case NL80211_IFTYPE_AP_VLAN:
1462 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); 1482 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
1463 /* DA BSSID SA */ 1483 /* DA BSSID SA */
1464 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1484 memcpy(hdr.addr1, skb->data, ETH_ALEN);
@@ -1466,7 +1486,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1466 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); 1486 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1467 hdrlen = 24; 1487 hdrlen = 24;
1468 break; 1488 break;
1469 case IEEE80211_IF_TYPE_WDS: 1489 case NL80211_IFTYPE_WDS:
1470 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1490 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1471 /* RA TA DA SA */ 1491 /* RA TA DA SA */
1472 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); 1492 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
@@ -1476,16 +1496,16 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1476 hdrlen = 30; 1496 hdrlen = 30;
1477 break; 1497 break;
1478#ifdef CONFIG_MAC80211_MESH 1498#ifdef CONFIG_MAC80211_MESH
1479 case IEEE80211_IF_TYPE_MESH_POINT: 1499 case NL80211_IFTYPE_MESH_POINT:
1480 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); 1500 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1481 /* RA TA DA SA */ 1501 /* RA TA DA SA */
1482 memset(hdr.addr1, 0, ETH_ALEN); 1502 memset(hdr.addr1, 0, ETH_ALEN);
1483 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); 1503 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1484 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1504 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1485 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1505 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1486 if (!sdata->u.sta.mshcfg.dot11MeshTTL) { 1506 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1487 /* Do not send frames with mesh_ttl == 0 */ 1507 /* Do not send frames with mesh_ttl == 0 */
1488 sdata->u.sta.mshstats.dropped_frames_ttl++; 1508 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1489 ret = 0; 1509 ret = 0;
1490 goto fail; 1510 goto fail;
1491 } 1511 }
@@ -1493,7 +1513,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1493 hdrlen = 30; 1513 hdrlen = 30;
1494 break; 1514 break;
1495#endif 1515#endif
1496 case IEEE80211_IF_TYPE_STA: 1516 case NL80211_IFTYPE_STATION:
1497 fc |= cpu_to_le16(IEEE80211_FCTL_TODS); 1517 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
1498 /* BSSID SA DA */ 1518 /* BSSID SA DA */
1499 memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN); 1519 memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
@@ -1501,7 +1521,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1501 memcpy(hdr.addr3, skb->data, ETH_ALEN); 1521 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1502 hdrlen = 24; 1522 hdrlen = 24;
1503 break; 1523 break;
1504 case IEEE80211_IF_TYPE_IBSS: 1524 case NL80211_IFTYPE_ADHOC:
1505 /* DA SA BSSID */ 1525 /* DA SA BSSID */
1506 memcpy(hdr.addr1, skb->data, ETH_ALEN); 1526 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1507 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); 1527 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
@@ -1580,19 +1600,6 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1580 nh_pos -= skip_header_bytes; 1600 nh_pos -= skip_header_bytes;
1581 h_pos -= skip_header_bytes; 1601 h_pos -= skip_header_bytes;
1582 1602
1583 /* TODO: implement support for fragments so that there is no need to
1584 * reallocate and copy payload; it might be enough to support one
1585 * extra fragment that would be copied in the beginning of the frame
1586 * data.. anyway, it would be nice to include this into skb structure
1587 * somehow
1588 *
1589 * There are few options for this:
1590 * use skb->cb as an extra space for 802.11 header
1591 * allocate new buffer if not enough headroom
1592 * make sure that there is enough headroom in every skb by increasing
1593 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1594 * alloc_skb() (net/core/skbuff.c)
1595 */
1596 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb); 1603 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
1597 1604
1598 /* 1605 /*
@@ -1815,10 +1822,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1815 struct rate_selection rsel; 1822 struct rate_selection rsel;
1816 struct beacon_data *beacon; 1823 struct beacon_data *beacon;
1817 struct ieee80211_supported_band *sband; 1824 struct ieee80211_supported_band *sband;
1818 struct ieee80211_mgmt *mgmt;
1819 int *num_beacons;
1820 enum ieee80211_band band = local->hw.conf.channel->band; 1825 enum ieee80211_band band = local->hw.conf.channel->band;
1821 u8 *pos;
1822 1826
1823 sband = local->hw.wiphy->bands[band]; 1827 sband = local->hw.wiphy->bands[band];
1824 1828
@@ -1827,7 +1831,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1827 sdata = vif_to_sdata(vif); 1831 sdata = vif_to_sdata(vif);
1828 bdev = sdata->dev; 1832 bdev = sdata->dev;
1829 1833
1830 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 1834 if (sdata->vif.type == NL80211_IFTYPE_AP) {
1831 ap = &sdata->u.ap; 1835 ap = &sdata->u.ap;
1832 beacon = rcu_dereference(ap->beacon); 1836 beacon = rcu_dereference(ap->beacon);
1833 if (ap && beacon) { 1837 if (ap && beacon) {
@@ -1865,11 +1869,9 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1865 if (beacon->tail) 1869 if (beacon->tail)
1866 memcpy(skb_put(skb, beacon->tail_len), 1870 memcpy(skb_put(skb, beacon->tail_len),
1867 beacon->tail, beacon->tail_len); 1871 beacon->tail, beacon->tail_len);
1868
1869 num_beacons = &ap->num_beacons;
1870 } else 1872 } else
1871 goto out; 1873 goto out;
1872 } else if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 1874 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
1873 struct ieee80211_hdr *hdr; 1875 struct ieee80211_hdr *hdr;
1874 ifsta = &sdata->u.sta; 1876 ifsta = &sdata->u.sta;
1875 1877
@@ -1884,8 +1886,10 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1884 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1886 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
1885 IEEE80211_STYPE_BEACON); 1887 IEEE80211_STYPE_BEACON);
1886 1888
1887 num_beacons = &ifsta->num_beacons;
1888 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 1889 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
1890 struct ieee80211_mgmt *mgmt;
1891 u8 *pos;
1892
1889 /* headroom, head length, tail length and maximum TIM length */ 1893 /* headroom, head length, tail length and maximum TIM length */
1890 skb = dev_alloc_skb(local->tx_headroom + 400); 1894 skb = dev_alloc_skb(local->tx_headroom + 400);
1891 if (!skb) 1895 if (!skb)
@@ -1909,8 +1913,6 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1909 *pos++ = 0x0; 1913 *pos++ = 0x0;
1910 1914
1911 mesh_mgmt_ies_add(skb, sdata); 1915 mesh_mgmt_ies_add(skb, sdata);
1912
1913 num_beacons = &sdata->u.sta.num_beacons;
1914 } else { 1916 } else {
1915 WARN_ON(1); 1917 WARN_ON(1);
1916 goto out; 1918 goto out;
@@ -1947,7 +1949,6 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1947 info->antenna_sel_tx = local->hw.conf.antenna_sel_tx; 1949 info->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
1948 info->control.retry_limit = 1; 1950 info->control.retry_limit = 1;
1949 1951
1950 (*num_beacons)++;
1951out: 1952out:
1952 rcu_read_unlock(); 1953 rcu_read_unlock();
1953 return skb; 1954 return skb;
@@ -2009,7 +2010,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2009 rcu_read_lock(); 2010 rcu_read_lock();
2010 beacon = rcu_dereference(bss->beacon); 2011 beacon = rcu_dereference(bss->beacon);
2011 2012
2012 if (sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon || !beacon->head) 2013 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
2013 goto out; 2014 goto out;
2014 2015
2015 if (bss->dtim_count != 0) 2016 if (bss->dtim_count != 0)
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index c3a22ab2ad2e..f32561ec224c 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -43,7 +43,7 @@ const unsigned char bridge_tunnel_header[] __aligned(2) =
43 43
44 44
45u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 45u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
46 enum ieee80211_if_types type) 46 enum nl80211_iftype type)
47{ 47{
48 __le16 fc = hdr->frame_control; 48 __le16 fc = hdr->frame_control;
49 49
@@ -77,10 +77,10 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
77 77
78 if (ieee80211_is_back_req(fc)) { 78 if (ieee80211_is_back_req(fc)) {
79 switch (type) { 79 switch (type) {
80 case IEEE80211_IF_TYPE_STA: 80 case NL80211_IFTYPE_STATION:
81 return hdr->addr2; 81 return hdr->addr2;
82 case IEEE80211_IF_TYPE_AP: 82 case NL80211_IFTYPE_AP:
83 case IEEE80211_IF_TYPE_VLAN: 83 case NL80211_IFTYPE_AP_VLAN:
84 return hdr->addr1; 84 return hdr->addr1;
85 default: 85 default:
86 break; /* fall through to the return */ 86 break; /* fall through to the return */
@@ -231,16 +231,21 @@ __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
231 struct ieee80211_rate *rate) 231 struct ieee80211_rate *rate)
232{ 232{
233 struct ieee80211_local *local = hw_to_local(hw); 233 struct ieee80211_local *local = hw_to_local(hw);
234 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 234 struct ieee80211_sub_if_data *sdata;
235 u16 dur; 235 u16 dur;
236 int erp; 236 int erp;
237 bool short_preamble = false;
237 238
238 erp = 0; 239 erp = 0;
239 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 240 if (vif) {
240 erp = rate->flags & IEEE80211_RATE_ERP_G; 241 sdata = vif_to_sdata(vif);
242 short_preamble = sdata->bss_conf.use_short_preamble;
243 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
244 erp = rate->flags & IEEE80211_RATE_ERP_G;
245 }
241 246
242 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, 247 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
243 sdata->bss_conf.use_short_preamble); 248 short_preamble);
244 249
245 return cpu_to_le16(dur); 250 return cpu_to_le16(dur);
246} 251}
@@ -252,7 +257,7 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
252{ 257{
253 struct ieee80211_local *local = hw_to_local(hw); 258 struct ieee80211_local *local = hw_to_local(hw);
254 struct ieee80211_rate *rate; 259 struct ieee80211_rate *rate;
255 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 260 struct ieee80211_sub_if_data *sdata;
256 bool short_preamble; 261 bool short_preamble;
257 int erp; 262 int erp;
258 u16 dur; 263 u16 dur;
@@ -260,13 +265,17 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
260 265
261 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 266 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
262 267
263 short_preamble = sdata->bss_conf.use_short_preamble; 268 short_preamble = false;
264 269
265 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; 270 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
266 271
267 erp = 0; 272 erp = 0;
268 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 273 if (vif) {
269 erp = rate->flags & IEEE80211_RATE_ERP_G; 274 sdata = vif_to_sdata(vif);
275 short_preamble = sdata->bss_conf.use_short_preamble;
276 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
277 erp = rate->flags & IEEE80211_RATE_ERP_G;
278 }
270 279
271 /* CTS duration */ 280 /* CTS duration */
272 dur = ieee80211_frame_duration(local, 10, rate->bitrate, 281 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
@@ -289,7 +298,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
289{ 298{
290 struct ieee80211_local *local = hw_to_local(hw); 299 struct ieee80211_local *local = hw_to_local(hw);
291 struct ieee80211_rate *rate; 300 struct ieee80211_rate *rate;
292 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 301 struct ieee80211_sub_if_data *sdata;
293 bool short_preamble; 302 bool short_preamble;
294 int erp; 303 int erp;
295 u16 dur; 304 u16 dur;
@@ -297,12 +306,16 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
297 306
298 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 307 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
299 308
300 short_preamble = sdata->bss_conf.use_short_preamble; 309 short_preamble = false;
301 310
302 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; 311 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
303 erp = 0; 312 erp = 0;
304 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 313 if (vif) {
305 erp = rate->flags & IEEE80211_RATE_ERP_G; 314 sdata = vif_to_sdata(vif);
315 short_preamble = sdata->bss_conf.use_short_preamble;
316 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
317 erp = rate->flags & IEEE80211_RATE_ERP_G;
318 }
306 319
307 /* Data frame duration */ 320 /* Data frame duration */
308 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, 321 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
@@ -376,15 +389,16 @@ void ieee80211_iterate_active_interfaces(
376 389
377 list_for_each_entry(sdata, &local->interfaces, list) { 390 list_for_each_entry(sdata, &local->interfaces, list) {
378 switch (sdata->vif.type) { 391 switch (sdata->vif.type) {
379 case IEEE80211_IF_TYPE_INVALID: 392 case __NL80211_IFTYPE_AFTER_LAST:
380 case IEEE80211_IF_TYPE_MNTR: 393 case NL80211_IFTYPE_UNSPECIFIED:
381 case IEEE80211_IF_TYPE_VLAN: 394 case NL80211_IFTYPE_MONITOR:
395 case NL80211_IFTYPE_AP_VLAN:
382 continue; 396 continue;
383 case IEEE80211_IF_TYPE_AP: 397 case NL80211_IFTYPE_AP:
384 case IEEE80211_IF_TYPE_STA: 398 case NL80211_IFTYPE_STATION:
385 case IEEE80211_IF_TYPE_IBSS: 399 case NL80211_IFTYPE_ADHOC:
386 case IEEE80211_IF_TYPE_WDS: 400 case NL80211_IFTYPE_WDS:
387 case IEEE80211_IF_TYPE_MESH_POINT: 401 case NL80211_IFTYPE_MESH_POINT:
388 break; 402 break;
389 } 403 }
390 if (netif_running(sdata->dev)) 404 if (netif_running(sdata->dev))
@@ -409,15 +423,16 @@ void ieee80211_iterate_active_interfaces_atomic(
409 423
410 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 424 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
411 switch (sdata->vif.type) { 425 switch (sdata->vif.type) {
412 case IEEE80211_IF_TYPE_INVALID: 426 case __NL80211_IFTYPE_AFTER_LAST:
413 case IEEE80211_IF_TYPE_MNTR: 427 case NL80211_IFTYPE_UNSPECIFIED:
414 case IEEE80211_IF_TYPE_VLAN: 428 case NL80211_IFTYPE_MONITOR:
429 case NL80211_IFTYPE_AP_VLAN:
415 continue; 430 continue;
416 case IEEE80211_IF_TYPE_AP: 431 case NL80211_IFTYPE_AP:
417 case IEEE80211_IF_TYPE_STA: 432 case NL80211_IFTYPE_STATION:
418 case IEEE80211_IF_TYPE_IBSS: 433 case NL80211_IFTYPE_ADHOC:
419 case IEEE80211_IF_TYPE_WDS: 434 case NL80211_IFTYPE_WDS:
420 case IEEE80211_IF_TYPE_MESH_POINT: 435 case NL80211_IFTYPE_MESH_POINT:
421 break; 436 break;
422 } 437 }
423 if (netif_running(sdata->dev)) 438 if (netif_running(sdata->dev))
@@ -612,3 +627,59 @@ void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
612 627
613 dev_queue_xmit(skb); 628 dev_queue_xmit(skb);
614} 629}
630
631int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
632{
633 int ret = -EINVAL;
634 struct ieee80211_channel *chan;
635 struct ieee80211_local *local = sdata->local;
636
637 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
638
639 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
640 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
641 chan->flags & IEEE80211_CHAN_NO_IBSS) {
642 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
643 "%d MHz\n", sdata->dev->name, chan->center_freq);
644 return ret;
645 }
646 local->oper_channel = chan;
647
648 if (local->sw_scanning || local->hw_scanning)
649 ret = 0;
650 else
651 ret = ieee80211_hw_config(local);
652
653 rate_control_clear(local);
654 }
655
656 return ret;
657}
658
659u64 ieee80211_mandatory_rates(struct ieee80211_local *local,
660 enum ieee80211_band band)
661{
662 struct ieee80211_supported_band *sband;
663 struct ieee80211_rate *bitrates;
664 u64 mandatory_rates;
665 enum ieee80211_rate_flags mandatory_flag;
666 int i;
667
668 sband = local->hw.wiphy->bands[band];
669 if (!sband) {
670 WARN_ON(1);
671 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
672 }
673
674 if (band == IEEE80211_BAND_2GHZ)
675 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
676 else
677 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
678
679 bitrates = sband->bitrates;
680 mandatory_rates = 0;
681 for (i = 0; i < sband->n_bitrates; i++)
682 if (bitrates[i].flags & mandatory_flag)
683 mandatory_rates |= BIT(i);
684 return mandatory_rates;
685}
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index beae664ab480..7e0d53abde24 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -122,8 +122,8 @@ static int ieee80211_ioctl_siwgenie(struct net_device *dev,
122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) 122 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
123 return -EOPNOTSUPP; 123 return -EOPNOTSUPP;
124 124
125 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 125 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
126 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 126 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length); 127 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
128 if (ret) 128 if (ret)
129 return ret; 129 return ret;
@@ -273,21 +273,21 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev,
273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
274 int type; 274 int type;
275 275
276 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 276 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
277 return -EOPNOTSUPP; 277 return -EOPNOTSUPP;
278 278
279 switch (*mode) { 279 switch (*mode) {
280 case IW_MODE_INFRA: 280 case IW_MODE_INFRA:
281 type = IEEE80211_IF_TYPE_STA; 281 type = NL80211_IFTYPE_STATION;
282 break; 282 break;
283 case IW_MODE_ADHOC: 283 case IW_MODE_ADHOC:
284 type = IEEE80211_IF_TYPE_IBSS; 284 type = NL80211_IFTYPE_ADHOC;
285 break; 285 break;
286 case IW_MODE_REPEAT: 286 case IW_MODE_REPEAT:
287 type = IEEE80211_IF_TYPE_WDS; 287 type = NL80211_IFTYPE_WDS;
288 break; 288 break;
289 case IW_MODE_MONITOR: 289 case IW_MODE_MONITOR:
290 type = IEEE80211_IF_TYPE_MNTR; 290 type = NL80211_IFTYPE_MONITOR;
291 break; 291 break;
292 default: 292 default:
293 return -EINVAL; 293 return -EINVAL;
@@ -305,22 +305,22 @@ static int ieee80211_ioctl_giwmode(struct net_device *dev,
305 305
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307 switch (sdata->vif.type) { 307 switch (sdata->vif.type) {
308 case IEEE80211_IF_TYPE_AP: 308 case NL80211_IFTYPE_AP:
309 *mode = IW_MODE_MASTER; 309 *mode = IW_MODE_MASTER;
310 break; 310 break;
311 case IEEE80211_IF_TYPE_STA: 311 case NL80211_IFTYPE_STATION:
312 *mode = IW_MODE_INFRA; 312 *mode = IW_MODE_INFRA;
313 break; 313 break;
314 case IEEE80211_IF_TYPE_IBSS: 314 case NL80211_IFTYPE_ADHOC:
315 *mode = IW_MODE_ADHOC; 315 *mode = IW_MODE_ADHOC;
316 break; 316 break;
317 case IEEE80211_IF_TYPE_MNTR: 317 case NL80211_IFTYPE_MONITOR:
318 *mode = IW_MODE_MONITOR; 318 *mode = IW_MODE_MONITOR;
319 break; 319 break;
320 case IEEE80211_IF_TYPE_WDS: 320 case NL80211_IFTYPE_WDS:
321 *mode = IW_MODE_REPEAT; 321 *mode = IW_MODE_REPEAT;
322 break; 322 break;
323 case IEEE80211_IF_TYPE_VLAN: 323 case NL80211_IFTYPE_AP_VLAN:
324 *mode = IW_MODE_SECOND; /* FIXME */ 324 *mode = IW_MODE_SECOND; /* FIXME */
325 break; 325 break;
326 default: 326 default:
@@ -330,47 +330,19 @@ static int ieee80211_ioctl_giwmode(struct net_device *dev,
330 return 0; 330 return 0;
331} 331}
332 332
333int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
334{
335 int ret = -EINVAL;
336 struct ieee80211_channel *chan;
337 struct ieee80211_local *local = sdata->local;
338
339 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
340
341 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
342 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
343 chan->flags & IEEE80211_CHAN_NO_IBSS) {
344 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
345 "%d MHz\n", sdata->dev->name, chan->center_freq);
346 return ret;
347 }
348 local->oper_channel = chan;
349
350 if (local->sta_sw_scanning || local->sta_hw_scanning)
351 ret = 0;
352 else
353 ret = ieee80211_hw_config(local);
354
355 rate_control_clear(local);
356 }
357
358 return ret;
359}
360
361static int ieee80211_ioctl_siwfreq(struct net_device *dev, 333static int ieee80211_ioctl_siwfreq(struct net_device *dev,
362 struct iw_request_info *info, 334 struct iw_request_info *info,
363 struct iw_freq *freq, char *extra) 335 struct iw_freq *freq, char *extra)
364{ 336{
365 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
366 338
367 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) 339 if (sdata->vif.type == NL80211_IFTYPE_STATION)
368 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; 340 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
369 341
370 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ 342 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
371 if (freq->e == 0) { 343 if (freq->e == 0) {
372 if (freq->m < 0) { 344 if (freq->m < 0) {
373 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) 345 if (sdata->vif.type == NL80211_IFTYPE_STATION)
374 sdata->u.sta.flags |= 346 sdata->u.sta.flags |=
375 IEEE80211_STA_AUTO_CHANNEL_SEL; 347 IEEE80211_STA_AUTO_CHANNEL_SEL;
376 return 0; 348 return 0;
@@ -414,8 +386,8 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
414 len--; 386 len--;
415 387
416 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 388 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
417 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 389 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
418 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 390 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
419 int ret; 391 int ret;
420 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { 392 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
421 if (len > IEEE80211_MAX_SSID_LEN) 393 if (len > IEEE80211_MAX_SSID_LEN)
@@ -435,7 +407,7 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
435 return 0; 407 return 0;
436 } 408 }
437 409
438 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 410 if (sdata->vif.type == NL80211_IFTYPE_AP) {
439 memcpy(sdata->u.ap.ssid, ssid, len); 411 memcpy(sdata->u.ap.ssid, ssid, len);
440 memset(sdata->u.ap.ssid + len, 0, 412 memset(sdata->u.ap.ssid + len, 0,
441 IEEE80211_MAX_SSID_LEN - len); 413 IEEE80211_MAX_SSID_LEN - len);
@@ -454,8 +426,8 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
454 426
455 struct ieee80211_sub_if_data *sdata; 427 struct ieee80211_sub_if_data *sdata;
456 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 428 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
457 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 429 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
458 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 430 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
459 int res = ieee80211_sta_get_ssid(sdata, ssid, &len); 431 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
460 if (res == 0) { 432 if (res == 0) {
461 data->length = len; 433 data->length = len;
@@ -465,7 +437,7 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
465 return res; 437 return res;
466 } 438 }
467 439
468 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 440 if (sdata->vif.type == NL80211_IFTYPE_AP) {
469 len = sdata->u.ap.ssid_len; 441 len = sdata->u.ap.ssid_len;
470 if (len > IW_ESSID_MAX_SIZE) 442 if (len > IW_ESSID_MAX_SIZE)
471 len = IW_ESSID_MAX_SIZE; 443 len = IW_ESSID_MAX_SIZE;
@@ -485,8 +457,8 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
485 struct ieee80211_sub_if_data *sdata; 457 struct ieee80211_sub_if_data *sdata;
486 458
487 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 459 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
488 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 460 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
489 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 461 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
490 int ret; 462 int ret;
491 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) { 463 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
492 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data, 464 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
@@ -505,7 +477,7 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
505 return ret; 477 return ret;
506 ieee80211_sta_req_auth(sdata, &sdata->u.sta); 478 ieee80211_sta_req_auth(sdata, &sdata->u.sta);
507 return 0; 479 return 0;
508 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) { 480 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
509 /* 481 /*
510 * If it is necessary to update the WDS peer address 482 * If it is necessary to update the WDS peer address
511 * while the interface is running, then we need to do 483 * while the interface is running, then we need to do
@@ -533,8 +505,8 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
533 struct ieee80211_sub_if_data *sdata; 505 struct ieee80211_sub_if_data *sdata;
534 506
535 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 507 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
536 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 508 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
537 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { 509 sdata->vif.type == NL80211_IFTYPE_ADHOC) {
538 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED || 510 if (sdata->u.sta.state == IEEE80211_STA_MLME_ASSOCIATED ||
539 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) { 511 sdata->u.sta.state == IEEE80211_STA_MLME_IBSS_JOINED) {
540 ap_addr->sa_family = ARPHRD_ETHER; 512 ap_addr->sa_family = ARPHRD_ETHER;
@@ -544,7 +516,7 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
544 memset(&ap_addr->sa_data, 0, ETH_ALEN); 516 memset(&ap_addr->sa_data, 0, ETH_ALEN);
545 return 0; 517 return 0;
546 } 518 }
547 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) { 519 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
548 ap_addr->sa_family = ARPHRD_ETHER; 520 ap_addr->sa_family = ARPHRD_ETHER;
549 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); 521 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
550 return 0; 522 return 0;
@@ -566,10 +538,10 @@ static int ieee80211_ioctl_siwscan(struct net_device *dev,
566 if (!netif_running(dev)) 538 if (!netif_running(dev))
567 return -ENETDOWN; 539 return -ENETDOWN;
568 540
569 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 541 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
570 sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 542 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
571 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT && 543 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
572 sdata->vif.type != IEEE80211_IF_TYPE_AP) 544 sdata->vif.type != NL80211_IFTYPE_AP)
573 return -EOPNOTSUPP; 545 return -EOPNOTSUPP;
574 546
575 /* if SSID was specified explicitly then use that */ 547 /* if SSID was specified explicitly then use that */
@@ -580,7 +552,7 @@ static int ieee80211_ioctl_siwscan(struct net_device *dev,
580 ssid_len = req->essid_len; 552 ssid_len = req->essid_len;
581 } 553 }
582 554
583 return ieee80211_sta_req_scan(sdata, ssid, ssid_len); 555 return ieee80211_request_scan(sdata, ssid, ssid_len);
584} 556}
585 557
586 558
@@ -594,10 +566,10 @@ static int ieee80211_ioctl_giwscan(struct net_device *dev,
594 566
595 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 567 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
596 568
597 if (local->sta_sw_scanning || local->sta_hw_scanning) 569 if (local->sw_scanning || local->hw_scanning)
598 return -EAGAIN; 570 return -EAGAIN;
599 571
600 res = ieee80211_sta_scan_results(local, info, extra, data->length); 572 res = ieee80211_scan_results(local, info, extra, data->length);
601 if (res >= 0) { 573 if (res >= 0) {
602 data->length = res; 574 data->length = res;
603 return 0; 575 return 0;
@@ -655,7 +627,7 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
655 627
656 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 628 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
657 629
658 if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 630 if (sdata->vif.type != NL80211_IFTYPE_STATION)
659 return -EOPNOTSUPP; 631 return -EOPNOTSUPP;
660 632
661 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 633 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
@@ -664,8 +636,8 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
664 636
665 sta = sta_info_get(local, sdata->u.sta.bssid); 637 sta = sta_info_get(local, sdata->u.sta.bssid);
666 638
667 if (sta && sta->txrate_idx < sband->n_bitrates) 639 if (sta && sta->last_txrate_idx < sband->n_bitrates)
668 rate->value = sband->bitrates[sta->txrate_idx].bitrate; 640 rate->value = sband->bitrates[sta->last_txrate_idx].bitrate;
669 else 641 else
670 rate->value = 0; 642 rate->value = 0;
671 643
@@ -886,8 +858,8 @@ static int ieee80211_ioctl_siwmlme(struct net_device *dev,
886 struct iw_mlme *mlme = (struct iw_mlme *) extra; 858 struct iw_mlme *mlme = (struct iw_mlme *) extra;
887 859
888 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 860 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
889 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 861 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
890 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) 862 sdata->vif.type != NL80211_IFTYPE_ADHOC)
891 return -EINVAL; 863 return -EINVAL;
892 864
893 switch (mlme->cmd) { 865 switch (mlme->cmd) {
@@ -982,7 +954,7 @@ static int ieee80211_ioctl_giwencode(struct net_device *dev,
982 erq->length = sdata->keys[idx]->conf.keylen; 954 erq->length = sdata->keys[idx]->conf.keylen;
983 erq->flags |= IW_ENCODE_ENABLED; 955 erq->flags |= IW_ENCODE_ENABLED;
984 956
985 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 957 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
986 struct ieee80211_if_sta *ifsta = &sdata->u.sta; 958 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
987 switch (ifsta->auth_alg) { 959 switch (ifsta->auth_alg) {
988 case WLAN_AUTH_OPEN: 960 case WLAN_AUTH_OPEN:
@@ -1056,7 +1028,7 @@ static int ieee80211_ioctl_siwauth(struct net_device *dev,
1056 sdata->drop_unencrypted = !!data->value; 1028 sdata->drop_unencrypted = !!data->value;
1057 break; 1029 break;
1058 case IW_AUTH_PRIVACY_INVOKED: 1030 case IW_AUTH_PRIVACY_INVOKED:
1059 if (sdata->vif.type != IEEE80211_IF_TYPE_STA) 1031 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1060 ret = -EINVAL; 1032 ret = -EINVAL;
1061 else { 1033 else {
1062 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; 1034 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
@@ -1071,8 +1043,8 @@ static int ieee80211_ioctl_siwauth(struct net_device *dev,
1071 } 1043 }
1072 break; 1044 break;
1073 case IW_AUTH_80211_AUTH_ALG: 1045 case IW_AUTH_80211_AUTH_ALG:
1074 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 1046 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1075 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) 1047 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1076 sdata->u.sta.auth_algs = data->value; 1048 sdata->u.sta.auth_algs = data->value;
1077 else 1049 else
1078 ret = -EOPNOTSUPP; 1050 ret = -EOPNOTSUPP;
@@ -1094,8 +1066,8 @@ static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev
1094 1066
1095 rcu_read_lock(); 1067 rcu_read_lock();
1096 1068
1097 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 1069 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1098 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) 1070 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1099 sta = sta_info_get(local, sdata->u.sta.bssid); 1071 sta = sta_info_get(local, sdata->u.sta.bssid);
1100 if (!sta) { 1072 if (!sta) {
1101 wstats->discard.fragment = 0; 1073 wstats->discard.fragment = 0;
@@ -1125,8 +1097,8 @@ static int ieee80211_ioctl_giwauth(struct net_device *dev,
1125 1097
1126 switch (data->flags & IW_AUTH_INDEX) { 1098 switch (data->flags & IW_AUTH_INDEX) {
1127 case IW_AUTH_80211_AUTH_ALG: 1099 case IW_AUTH_80211_AUTH_ALG:
1128 if (sdata->vif.type == IEEE80211_IF_TYPE_STA || 1100 if (sdata->vif.type == NL80211_IFTYPE_STATION ||
1129 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) 1101 sdata->vif.type == NL80211_IFTYPE_ADHOC)
1130 data->value = sdata->u.sta.auth_algs; 1102 data->value = sdata->u.sta.auth_algs;
1131 else 1103 else
1132 ret = -EOPNOTSUPP; 1104 ret = -EOPNOTSUPP;
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 7229e958879d..6748dedcab50 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -210,7 +210,7 @@ int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
210 DECLARE_MAC_BUF(mac); 210 DECLARE_MAC_BUF(mac);
211 printk(KERN_DEBUG "allocated aggregation queue" 211 printk(KERN_DEBUG "allocated aggregation queue"
212 " %d tid %d addr %s pool=0x%lX\n", 212 " %d tid %d addr %s pool=0x%lX\n",
213 i, tid, print_mac(mac, sta->addr), 213 i, tid, print_mac(mac, sta->sta.addr),
214 local->queue_pool[0]); 214 local->queue_pool[0]);
215 } 215 }
216#endif /* CONFIG_MAC80211_HT_DEBUG */ 216#endif /* CONFIG_MAC80211_HT_DEBUG */
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index 465e274df7c5..bc62f28a4d3d 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -1,5 +1,4 @@
1/* 1/*
2 * IEEE 802.11 driver (80211.o) - QoS datatypes
3 * Copyright 2004, Instant802 Networks, Inc. 2 * Copyright 2004, Instant802 Networks, Inc.
4 * Copyright 2005, Devicescape Software, Inc. 3 * Copyright 2005, Devicescape Software, Inc.
5 * 4 *
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 78021780b885..37ae9a959f63 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -256,7 +256,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
256 256
257 res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm, 257 res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
258 key, skb->data + hdrlen, 258 key, skb->data + hdrlen,
259 skb->len - hdrlen, rx->sta->addr, 259 skb->len - hdrlen, rx->sta->sta.addr,
260 hdr->addr1, hwaccel, rx->queue, 260 hdr->addr1, hwaccel, rx->queue,
261 &rx->tkip_iv32, 261 &rx->tkip_iv32,
262 &rx->tkip_iv16); 262 &rx->tkip_iv16);
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index d5735799ccd9..ea0dc04b3c77 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -512,21 +512,9 @@ static void rfkill_release(struct device *dev)
512#ifdef CONFIG_PM 512#ifdef CONFIG_PM
513static int rfkill_suspend(struct device *dev, pm_message_t state) 513static int rfkill_suspend(struct device *dev, pm_message_t state)
514{ 514{
515 struct rfkill *rfkill = to_rfkill(dev); 515 /* mark class device as suspended */
516 516 if (dev->power.power_state.event != state.event)
517 if (dev->power.power_state.event != state.event) {
518 if (state.event & PM_EVENT_SLEEP) {
519 /* Stop transmitter, keep state, no notifies */
520 update_rfkill_state(rfkill);
521
522 mutex_lock(&rfkill->mutex);
523 rfkill->toggle_radio(rfkill->data,
524 RFKILL_STATE_SOFT_BLOCKED);
525 mutex_unlock(&rfkill->mutex);
526 }
527
528 dev->power.power_state = state; 517 dev->power.power_state = state;
529 }
530 518
531 return 0; 519 return 0;
532} 520}
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 833b024f8f66..b97bd9fe6b79 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -14,6 +14,38 @@ config NL80211
14 14
15 If unsure, say Y. 15 If unsure, say Y.
16 16
17config WIRELESS_OLD_REGULATORY
18 bool "Old wireless static regulatory defintions"
19 default n
20 ---help---
21 This option enables the old static regulatory information
22 and uses it within the new framework. This is available
23 temporarily as an option to help prevent immediate issues
24 due to the switch to the new regulatory framework which
25 does require a new userspace application which has the
26 database of regulatory information (CRDA) and another for
27 setting regulatory domains (iw).
28
29 For more information see:
30
31 http://wireless.kernel.org/en/developers/Regulatory/CRDA
32 http://wireless.kernel.org/en/users/Documentation/iw
33
34 It is important to note though that if you *do* have CRDA present
35 and if this option is enabled CRDA *will* be called to update the
36 regulatory domain (for US and JP only). Support for letting the user
37 set the regulatory domain through iw is also supported. This option
38 mainly exists to leave around for a kernel release some old static
39 regulatory domains that were defined and to keep around the old
40 ieee80211_regdom module parameter. This is being phased out and you
41 should stop using them ASAP.
42
43 Say N unless you cannot install a new userspace application
44 or have one currently depending on the ieee80211_regdom module
45 parameter and cannot port it to use the new userspace interfaces.
46
47 This is scheduled for removal for 2.6.29.
48
17config WIRELESS_EXT 49config WIRELESS_EXT
18 bool "Wireless extensions" 50 bool "Wireless extensions"
19 default n 51 default n
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 7e995ac06a0c..a910cd2d0fd1 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -13,12 +13,14 @@
13#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/list.h>
16#include <net/genetlink.h> 17#include <net/genetlink.h>
17#include <net/cfg80211.h> 18#include <net/cfg80211.h>
18#include <net/wireless.h> 19#include <net/wireless.h>
19#include "nl80211.h" 20#include "nl80211.h"
20#include "core.h" 21#include "core.h"
21#include "sysfs.h" 22#include "sysfs.h"
23#include "reg.h"
22 24
23/* name for sysfs, %d is appended */ 25/* name for sysfs, %d is appended */
24#define PHY_NAME "phy" 26#define PHY_NAME "phy"
@@ -27,6 +29,107 @@ MODULE_AUTHOR("Johannes Berg");
27MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
28MODULE_DESCRIPTION("wireless configuration support"); 30MODULE_DESCRIPTION("wireless configuration support");
29 31
32struct list_head regulatory_requests;
33
34/* Central wireless core regulatory domains, we only need two,
35 * the current one and a world regulatory domain in case we have no
36 * information to give us an alpha2 */
37struct ieee80211_regdomain *cfg80211_regdomain;
38
39/* We keep a static world regulatory domain in case of the absence of CRDA */
40const struct ieee80211_regdomain world_regdom = {
41 .n_reg_rules = 1,
42 .alpha2 = "00",
43 .reg_rules = {
44 REG_RULE(2402, 2472, 40, 6, 20,
45 NL80211_RRF_PASSIVE_SCAN |
46 NL80211_RRF_NO_IBSS),
47 }
48};
49
50#ifdef CONFIG_WIRELESS_OLD_REGULATORY
51/* All this fucking static junk will be removed soon, so
52 * don't fucking count on it !@#$ */
53
54static char *ieee80211_regdom = "US";
55module_param(ieee80211_regdom, charp, 0444);
56MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
57
58/* We assume 40 MHz bandwidth for the old regulatory work.
59 * We make emphasis we are using the exact same frequencies
60 * as before */
61
62const struct ieee80211_regdomain us_regdom = {
63 .n_reg_rules = 6,
64 .alpha2 = "US",
65 .reg_rules = {
66 /* IEEE 802.11b/g, channels 1..11 */
67 REG_RULE(2412-20, 2462+20, 40, 6, 27, 0),
68 /* IEEE 802.11a, channel 36 */
69 REG_RULE(5180-20, 5180+20, 40, 6, 23, 0),
70 /* IEEE 802.11a, channel 40 */
71 REG_RULE(5200-20, 5200+20, 40, 6, 23, 0),
72 /* IEEE 802.11a, channel 44 */
73 REG_RULE(5220-20, 5220+20, 40, 6, 23, 0),
74 /* IEEE 802.11a, channels 48..64 */
75 REG_RULE(5240-20, 5320+20, 40, 6, 23, 0),
76 /* IEEE 802.11a, channels 149..165, outdoor */
77 REG_RULE(5745-20, 5825+20, 40, 6, 30, 0),
78 }
79};
80
81const struct ieee80211_regdomain jp_regdom = {
82 .n_reg_rules = 3,
83 .alpha2 = "JP",
84 .reg_rules = {
85 /* IEEE 802.11b/g, channels 1..14 */
86 REG_RULE(2412-20, 2484+20, 40, 6, 20, 0),
87 /* IEEE 802.11a, channels 34..48 */
88 REG_RULE(5170-20, 5240+20, 40, 6, 20,
89 NL80211_RRF_PASSIVE_SCAN),
90 /* IEEE 802.11a, channels 52..64 */
91 REG_RULE(5260-20, 5320+20, 40, 6, 20,
92 NL80211_RRF_NO_IBSS |
93 NL80211_RRF_DFS),
94 }
95};
96
97const struct ieee80211_regdomain eu_regdom = {
98 .n_reg_rules = 6,
99 /* This alpha2 is bogus, we leave it here just for stupid
100 * backward compatibility */
101 .alpha2 = "EU",
102 .reg_rules = {
103 /* IEEE 802.11b/g, channels 1..13 */
104 REG_RULE(2412-20, 2472+20, 40, 6, 20, 0),
105 /* IEEE 802.11a, channel 36 */
106 REG_RULE(5180-20, 5180+20, 40, 6, 23,
107 NL80211_RRF_PASSIVE_SCAN),
108 /* IEEE 802.11a, channel 40 */
109 REG_RULE(5200-20, 5200+20, 40, 6, 23,
110 NL80211_RRF_PASSIVE_SCAN),
111 /* IEEE 802.11a, channel 44 */
112 REG_RULE(5220-20, 5220+20, 40, 6, 23,
113 NL80211_RRF_PASSIVE_SCAN),
114 /* IEEE 802.11a, channels 48..64 */
115 REG_RULE(5240-20, 5320+20, 40, 6, 20,
116 NL80211_RRF_NO_IBSS |
117 NL80211_RRF_DFS),
118 /* IEEE 802.11a, channels 100..140 */
119 REG_RULE(5500-20, 5700+20, 40, 6, 30,
120 NL80211_RRF_NO_IBSS |
121 NL80211_RRF_DFS),
122 }
123};
124
125#endif
126
127struct ieee80211_regdomain *cfg80211_world_regdom =
128 (struct ieee80211_regdomain *) &world_regdom;
129
130LIST_HEAD(regulatory_requests);
131DEFINE_MUTEX(cfg80211_reg_mutex);
132
30/* RCU might be appropriate here since we usually 133/* RCU might be appropriate here since we usually
31 * only read the list, and that can happen quite 134 * only read the list, and that can happen quite
32 * often because we need to do it for each command */ 135 * often because we need to do it for each command */
@@ -302,7 +405,9 @@ int wiphy_register(struct wiphy *wiphy)
302 ieee80211_set_bitrate_flags(wiphy); 405 ieee80211_set_bitrate_flags(wiphy);
303 406
304 /* set up regulatory info */ 407 /* set up regulatory info */
305 wiphy_update_regulatory(wiphy); 408 mutex_lock(&cfg80211_reg_mutex);
409 wiphy_update_regulatory(wiphy, REGDOM_SET_BY_CORE);
410 mutex_unlock(&cfg80211_reg_mutex);
306 411
307 mutex_lock(&cfg80211_drv_mutex); 412 mutex_lock(&cfg80211_drv_mutex);
308 413
@@ -409,9 +514,35 @@ static struct notifier_block cfg80211_netdev_notifier = {
409 .notifier_call = cfg80211_netdev_notifier_call, 514 .notifier_call = cfg80211_netdev_notifier_call,
410}; 515};
411 516
517#ifdef CONFIG_WIRELESS_OLD_REGULATORY
518const struct ieee80211_regdomain *static_regdom(char *alpha2)
519{
520 if (alpha2[0] == 'U' && alpha2[1] == 'S')
521 return &us_regdom;
522 if (alpha2[0] == 'J' && alpha2[1] == 'P')
523 return &jp_regdom;
524 if (alpha2[0] == 'E' && alpha2[1] == 'U')
525 return &eu_regdom;
526 /* Default, as per the old rules */
527 return &us_regdom;
528}
529#endif
530
412static int cfg80211_init(void) 531static int cfg80211_init(void)
413{ 532{
414 int err = wiphy_sysfs_init(); 533 int err;
534
535#ifdef CONFIG_WIRELESS_OLD_REGULATORY
536 cfg80211_regdomain =
537 (struct ieee80211_regdomain *) static_regdom(ieee80211_regdom);
538 /* Used during reset_regdomains_static() */
539 cfg80211_world_regdom = cfg80211_regdomain;
540#else
541 cfg80211_regdomain =
542 (struct ieee80211_regdomain *) cfg80211_world_regdom;
543#endif
544
545 err = wiphy_sysfs_init();
415 if (err) 546 if (err)
416 goto out_fail_sysfs; 547 goto out_fail_sysfs;
417 548
@@ -425,8 +556,33 @@ static int cfg80211_init(void)
425 556
426 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL); 557 ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
427 558
559 err = regulatory_init();
560 if (err)
561 goto out_fail_reg;
562
563#ifdef CONFIG_WIRELESS_OLD_REGULATORY
564 printk(KERN_INFO "cfg80211: Using old static regulatory domain:\n");
565 print_regdomain_info(cfg80211_regdomain);
566 /* The old code still requests for a new regdomain and if
567 * you have CRDA you get it updated, otherwise you get
568 * stuck with the static values. We ignore "EU" code as
569 * that is not a valid ISO / IEC 3166 alpha2 */
570 if (ieee80211_regdom[0] != 'E' &&
571 ieee80211_regdom[1] != 'U')
572 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE,
573 ieee80211_regdom, NULL);
574#else
575 err = __regulatory_hint(NULL, REGDOM_SET_BY_CORE, "00", NULL);
576 if (err)
577 printk(KERN_ERR "cfg80211: calling CRDA failed - "
578 "unable to update world regulatory domain, "
579 "using static definition\n");
580#endif
581
428 return 0; 582 return 0;
429 583
584out_fail_reg:
585 debugfs_remove(ieee80211_debugfs_dir);
430out_fail_nl80211: 586out_fail_nl80211:
431 unregister_netdevice_notifier(&cfg80211_netdev_notifier); 587 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
432out_fail_notifier: 588out_fail_notifier:
@@ -434,6 +590,7 @@ out_fail_notifier:
434out_fail_sysfs: 590out_fail_sysfs:
435 return err; 591 return err;
436} 592}
593
437subsys_initcall(cfg80211_init); 594subsys_initcall(cfg80211_init);
438 595
439static void cfg80211_exit(void) 596static void cfg80211_exit(void)
@@ -442,5 +599,6 @@ static void cfg80211_exit(void)
442 nl80211_exit(); 599 nl80211_exit();
443 unregister_netdevice_notifier(&cfg80211_netdev_notifier); 600 unregister_netdevice_notifier(&cfg80211_netdev_notifier);
444 wiphy_sysfs_exit(); 601 wiphy_sysfs_exit();
602 regulatory_exit();
445} 603}
446module_exit(cfg80211_exit); 604module_exit(cfg80211_exit);
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 7a02c356d63d..771cc5cc7658 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -79,6 +79,6 @@ extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
79 char *newname); 79 char *newname);
80 80
81void ieee80211_set_bitrate_flags(struct wiphy *wiphy); 81void ieee80211_set_bitrate_flags(struct wiphy *wiphy);
82void wiphy_update_regulatory(struct wiphy *wiphy); 82void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby);
83 83
84#endif /* __NET_WIRELESS_CORE_H */ 84#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 77880ba8b619..1221d726ed50 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -18,6 +18,7 @@
18#include <net/cfg80211.h> 18#include <net/cfg80211.h>
19#include "core.h" 19#include "core.h"
20#include "nl80211.h" 20#include "nl80211.h"
21#include "reg.h"
21 22
22/* the netlink family */ 23/* the netlink family */
23static struct genl_family nl80211_fam = { 24static struct genl_family nl80211_fam = {
@@ -88,6 +89,9 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
88 .len = IEEE80211_MAX_MESH_ID_LEN }, 89 .len = IEEE80211_MAX_MESH_ID_LEN },
89 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, 90 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
90 91
92 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
93 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
94
91 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, 95 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
92 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, 96 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
93 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, 97 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
@@ -1599,6 +1603,141 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
1599 return err; 1603 return err;
1600} 1604}
1601 1605
1606static const struct nla_policy
1607 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
1608 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
1609 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
1610 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
1611 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
1612 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
1613 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
1614};
1615
1616static int parse_reg_rule(struct nlattr *tb[],
1617 struct ieee80211_reg_rule *reg_rule)
1618{
1619 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
1620 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
1621
1622 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
1623 return -EINVAL;
1624 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
1625 return -EINVAL;
1626 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
1627 return -EINVAL;
1628 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
1629 return -EINVAL;
1630 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
1631 return -EINVAL;
1632
1633 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
1634
1635 freq_range->start_freq_khz =
1636 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
1637 freq_range->end_freq_khz =
1638 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
1639 freq_range->max_bandwidth_khz =
1640 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
1641
1642 power_rule->max_eirp =
1643 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
1644
1645 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
1646 power_rule->max_antenna_gain =
1647 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
1648
1649 return 0;
1650}
1651
1652static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
1653{
1654 int r;
1655 char *data = NULL;
1656
1657 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
1658 return -EINVAL;
1659
1660 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
1661
1662#ifdef CONFIG_WIRELESS_OLD_REGULATORY
1663 /* We ignore world regdom requests with the old regdom setup */
1664 if (is_world_regdom(data))
1665 return -EINVAL;
1666#endif
1667 mutex_lock(&cfg80211_drv_mutex);
1668 r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, NULL);
1669 mutex_unlock(&cfg80211_drv_mutex);
1670 return r;
1671}
1672
1673static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
1674{
1675 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
1676 struct nlattr *nl_reg_rule;
1677 char *alpha2 = NULL;
1678 int rem_reg_rules = 0, r = 0;
1679 u32 num_rules = 0, rule_idx = 0, size_of_regd;
1680 struct ieee80211_regdomain *rd = NULL;
1681
1682 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
1683 return -EINVAL;
1684
1685 if (!info->attrs[NL80211_ATTR_REG_RULES])
1686 return -EINVAL;
1687
1688 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
1689
1690 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
1691 rem_reg_rules) {
1692 num_rules++;
1693 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
1694 goto bad_reg;
1695 }
1696
1697 if (!reg_is_valid_request(alpha2))
1698 return -EINVAL;
1699
1700 size_of_regd = sizeof(struct ieee80211_regdomain) +
1701 (num_rules * sizeof(struct ieee80211_reg_rule));
1702
1703 rd = kzalloc(size_of_regd, GFP_KERNEL);
1704 if (!rd)
1705 return -ENOMEM;
1706
1707 rd->n_reg_rules = num_rules;
1708 rd->alpha2[0] = alpha2[0];
1709 rd->alpha2[1] = alpha2[1];
1710
1711 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
1712 rem_reg_rules) {
1713 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
1714 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
1715 reg_rule_policy);
1716 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
1717 if (r)
1718 goto bad_reg;
1719
1720 rule_idx++;
1721
1722 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
1723 goto bad_reg;
1724 }
1725
1726 BUG_ON(rule_idx != num_rules);
1727
1728 mutex_lock(&cfg80211_drv_mutex);
1729 r = set_regdom(rd);
1730 mutex_unlock(&cfg80211_drv_mutex);
1731 if (r)
1732 goto bad_reg;
1733
1734 return r;
1735
1736bad_reg:
1737 kfree(rd);
1738 return -EINVAL;
1739}
1740
1602static struct genl_ops nl80211_ops[] = { 1741static struct genl_ops nl80211_ops[] = {
1603 { 1742 {
1604 .cmd = NL80211_CMD_GET_WIPHY, 1743 .cmd = NL80211_CMD_GET_WIPHY,
@@ -1736,6 +1875,18 @@ static struct genl_ops nl80211_ops[] = {
1736 .policy = nl80211_policy, 1875 .policy = nl80211_policy,
1737 .flags = GENL_ADMIN_PERM, 1876 .flags = GENL_ADMIN_PERM,
1738 }, 1877 },
1878 {
1879 .cmd = NL80211_CMD_SET_REG,
1880 .doit = nl80211_set_reg,
1881 .policy = nl80211_policy,
1882 .flags = GENL_ADMIN_PERM,
1883 },
1884 {
1885 .cmd = NL80211_CMD_REQ_SET_REG,
1886 .doit = nl80211_req_set_reg,
1887 .policy = nl80211_policy,
1888 .flags = GENL_ADMIN_PERM,
1889 },
1739}; 1890};
1740 1891
1741/* multicast groups */ 1892/* multicast groups */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 855bff4b3250..592b2e391d42 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -2,179 +2,758 @@
2 * Copyright 2002-2005, Instant802 Networks, Inc. 2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc. 3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
5 * Copyright 2008 Luis R. Rodriguez <lrodriguz@atheros.com>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
9 */ 10 */
10 11
11/* 12/**
12 * This regulatory domain control implementation is highly incomplete, it 13 * DOC: Wireless regulatory infrastructure
13 * only exists for the purpose of not regressing mac80211.
14 *
15 * For now, drivers can restrict the set of allowed channels by either
16 * not registering those channels or setting the IEEE80211_CHAN_DISABLED
17 * flag; that flag will only be *set* by this code, never *cleared.
18 * 14 *
19 * The usual implementation is for a driver to read a device EEPROM to 15 * The usual implementation is for a driver to read a device EEPROM to
20 * determine which regulatory domain it should be operating under, then 16 * determine which regulatory domain it should be operating under, then
21 * looking up the allowable channels in a driver-local table and finally 17 * looking up the allowable channels in a driver-local table and finally
22 * registering those channels in the wiphy structure. 18 * registering those channels in the wiphy structure.
23 * 19 *
24 * Alternatively, drivers that trust the regulatory domain control here 20 * Another set of compliance enforcement is for drivers to use their
25 * will register a complete set of capabilities and the control code 21 * own compliance limits which can be stored on the EEPROM. The host
26 * will restrict the set by setting the IEEE80211_CHAN_* flags. 22 * driver or firmware may ensure these are used.
23 *
24 * In addition to all this we provide an extra layer of regulatory
25 * conformance. For drivers which do not have any regulatory
26 * information CRDA provides the complete regulatory solution.
27 * For others it provides a community effort on further restrictions
28 * to enhance compliance.
29 *
30 * Note: When number of rules --> infinity we will not be able to
31 * index on alpha2 any more, instead we'll probably have to
32 * rely on some SHA1 checksum of the regdomain for example.
33 *
27 */ 34 */
28#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/list.h>
37#include <linux/random.h>
38#include <linux/nl80211.h>
39#include <linux/platform_device.h>
29#include <net/wireless.h> 40#include <net/wireless.h>
41#include <net/cfg80211.h>
30#include "core.h" 42#include "core.h"
43#include "reg.h"
31 44
32static char *ieee80211_regdom = "US"; 45/* To trigger userspace events */
33module_param(ieee80211_regdom, charp, 0444); 46static struct platform_device *reg_pdev;
34MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain code");
35 47
36struct ieee80211_channel_range { 48/* Keep the ordering from large to small */
37 short start_freq; 49static u32 supported_bandwidths[] = {
38 short end_freq; 50 MHZ_TO_KHZ(40),
39 int max_power; 51 MHZ_TO_KHZ(20),
40 int max_antenna_gain;
41 u32 flags;
42}; 52};
43 53
44struct ieee80211_regdomain { 54bool is_world_regdom(char *alpha2)
45 const char *code; 55{
46 const struct ieee80211_channel_range *ranges; 56 if (!alpha2)
47 int n_ranges; 57 return false;
48}; 58 if (alpha2[0] == '0' && alpha2[1] == '0')
59 return true;
60 return false;
61}
49 62
50#define RANGE_PWR(_start, _end, _pwr, _ag, _flags) \ 63static bool is_alpha2_set(char *alpha2)
51 { _start, _end, _pwr, _ag, _flags } 64{
65 if (!alpha2)
66 return false;
67 if (alpha2[0] != 0 && alpha2[1] != 0)
68 return true;
69 return false;
70}
52 71
72static bool is_alpha_upper(char letter)
73{
74 /* ASCII A - Z */
75 if (letter >= 65 && letter <= 90)
76 return true;
77 return false;
78}
53 79
54/* 80static bool is_unknown_alpha2(char *alpha2)
55 * Ideally, in the future, these definitions will be loaded from a 81{
56 * userspace table via some daemon. 82 if (!alpha2)
57 */ 83 return false;
58static const struct ieee80211_channel_range ieee80211_US_channels[] = { 84 /* Special case where regulatory domain was built by driver
59 /* IEEE 802.11b/g, channels 1..11 */ 85 * but a specific alpha2 cannot be determined */
60 RANGE_PWR(2412, 2462, 27, 6, 0), 86 if (alpha2[0] == '9' && alpha2[1] == '9')
61 /* IEEE 802.11a, channel 36*/ 87 return true;
62 RANGE_PWR(5180, 5180, 23, 6, 0), 88 return false;
63 /* IEEE 802.11a, channel 40*/ 89}
64 RANGE_PWR(5200, 5200, 23, 6, 0),
65 /* IEEE 802.11a, channel 44*/
66 RANGE_PWR(5220, 5220, 23, 6, 0),
67 /* IEEE 802.11a, channels 48..64 */
68 RANGE_PWR(5240, 5320, 23, 6, 0),
69 /* IEEE 802.11a, channels 149..165, outdoor */
70 RANGE_PWR(5745, 5825, 30, 6, 0),
71};
72 90
73static const struct ieee80211_channel_range ieee80211_JP_channels[] = { 91static bool is_an_alpha2(char *alpha2)
74 /* IEEE 802.11b/g, channels 1..14 */ 92{
75 RANGE_PWR(2412, 2484, 20, 6, 0), 93 if (!alpha2)
76 /* IEEE 802.11a, channels 34..48 */ 94 return false;
77 RANGE_PWR(5170, 5240, 20, 6, IEEE80211_CHAN_PASSIVE_SCAN), 95 if (is_alpha_upper(alpha2[0]) && is_alpha_upper(alpha2[1]))
78 /* IEEE 802.11a, channels 52..64 */ 96 return true;
79 RANGE_PWR(5260, 5320, 20, 6, IEEE80211_CHAN_NO_IBSS | 97 return false;
80 IEEE80211_CHAN_RADAR), 98}
81};
82 99
83static const struct ieee80211_channel_range ieee80211_EU_channels[] = { 100static bool alpha2_equal(char *alpha2_x, char *alpha2_y)
84 /* IEEE 802.11b/g, channels 1..13 */ 101{
85 RANGE_PWR(2412, 2472, 20, 6, 0), 102 if (!alpha2_x || !alpha2_y)
86 /* IEEE 802.11a, channel 36*/ 103 return false;
87 RANGE_PWR(5180, 5180, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), 104 if (alpha2_x[0] == alpha2_y[0] &&
88 /* IEEE 802.11a, channel 40*/ 105 alpha2_x[1] == alpha2_y[1])
89 RANGE_PWR(5200, 5200, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), 106 return true;
90 /* IEEE 802.11a, channel 44*/ 107 return false;
91 RANGE_PWR(5220, 5220, 23, 6, IEEE80211_CHAN_PASSIVE_SCAN), 108}
92 /* IEEE 802.11a, channels 48..64 */ 109
93 RANGE_PWR(5240, 5320, 23, 6, IEEE80211_CHAN_NO_IBSS | 110static bool regdom_changed(char *alpha2)
94 IEEE80211_CHAN_RADAR), 111{
95 /* IEEE 802.11a, channels 100..140 */ 112 if (!cfg80211_regdomain)
96 RANGE_PWR(5500, 5700, 30, 6, IEEE80211_CHAN_NO_IBSS | 113 return true;
97 IEEE80211_CHAN_RADAR), 114 if (alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
98}; 115 return false;
116 return true;
117}
118
119/* This lets us keep regulatory code which is updated on a regulatory
120 * basis in userspace. */
121static int call_crda(const char *alpha2)
122{
123 char country_env[9 + 2] = "COUNTRY=";
124 char *envp[] = {
125 country_env,
126 NULL
127 };
128
129 if (!is_world_regdom((char *) alpha2))
130 printk(KERN_INFO "cfg80211: Calling CRDA for country: %c%c\n",
131 alpha2[0], alpha2[1]);
132 else
133#ifdef CONFIG_WIRELESS_OLD_REGULATORY
134 return -EINVAL;
135#else
136 printk(KERN_INFO "cfg80211: Calling CRDA to update world "
137 "regulatory domain\n");
138#endif
139
140 country_env[8] = alpha2[0];
141 country_env[9] = alpha2[1];
142
143 return kobject_uevent_env(&reg_pdev->dev.kobj, KOBJ_CHANGE, envp);
144}
145
146/* This has the logic which determines when a new request
147 * should be ignored. */
148static int ignore_request(struct wiphy *wiphy, enum reg_set_by set_by,
149 char *alpha2, struct ieee80211_regdomain *rd)
150{
151 struct regulatory_request *last_request = NULL;
99 152
100#define REGDOM(_code) \ 153 /* All initial requests are respected */
101 { \ 154 if (list_empty(&regulatory_requests))
102 .code = __stringify(_code), \ 155 return 0;
103 .ranges = ieee80211_ ##_code## _channels, \ 156
104 .n_ranges = ARRAY_SIZE(ieee80211_ ##_code## _channels), \ 157 last_request = list_first_entry(&regulatory_requests,
158 struct regulatory_request, list);
159
160 switch (set_by) {
161 case REGDOM_SET_BY_INIT:
162 return -EINVAL;
163 case REGDOM_SET_BY_CORE:
164 /* Always respect new wireless core hints, should only
165 * come in for updating the world regulatory domain at init
166 * anyway */
167 return 0;
168 case REGDOM_SET_BY_COUNTRY_IE:
169 if (last_request->initiator == set_by) {
170 if (last_request->wiphy != wiphy) {
171 /* Two cards with two APs claiming different
172 * different Country IE alpha2s!
173 * You're special!! */
174 if (!alpha2_equal(last_request->alpha2,
175 cfg80211_regdomain->alpha2)) {
176 /* XXX: Deal with conflict, consider
177 * building a new one out of the
178 * intersection */
179 WARN_ON(1);
180 return -EOPNOTSUPP;
181 }
182 return -EALREADY;
183 }
184 /* Two consecutive Country IE hints on the same wiphy */
185 if (!alpha2_equal(cfg80211_regdomain->alpha2, alpha2))
186 return 0;
187 return -EALREADY;
188 }
189 if (WARN_ON(!is_alpha2_set(alpha2) || !is_an_alpha2(alpha2)),
190 "Invalid Country IE regulatory hint passed "
191 "to the wireless core\n")
192 return -EINVAL;
193 /* We ignore Country IE hints for now, as we haven't yet
194 * added the dot11MultiDomainCapabilityEnabled flag
195 * for wiphys */
196 return 1;
197 case REGDOM_SET_BY_DRIVER:
198 BUG_ON(!wiphy);
199 if (last_request->initiator == set_by) {
200 /* Two separate drivers hinting different things,
201 * this is possible if you have two devices present
202 * on a system with different EEPROM regulatory
203 * readings. XXX: Do intersection, we support only
204 * the first regulatory hint for now */
205 if (last_request->wiphy != wiphy)
206 return -EALREADY;
207 if (rd)
208 return -EALREADY;
209 /* Driver should not be trying to hint different
210 * regulatory domains! */
211 BUG_ON(!alpha2_equal(alpha2,
212 cfg80211_regdomain->alpha2));
213 return -EALREADY;
214 }
215 if (last_request->initiator == REGDOM_SET_BY_CORE)
216 return 0;
217 /* XXX: Handle intersection, and add the
218 * dot11MultiDomainCapabilityEnabled flag to wiphy. For now
219 * we assume the driver has this set to false, following the
220 * 802.11d dot11MultiDomainCapabilityEnabled documentation */
221 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
222 return 0;
223 return 0;
224 case REGDOM_SET_BY_USER:
225 if (last_request->initiator == set_by ||
226 last_request->initiator == REGDOM_SET_BY_CORE)
227 return 0;
228 /* Drivers can use their wiphy's reg_notifier()
229 * to override any information */
230 if (last_request->initiator == REGDOM_SET_BY_DRIVER)
231 return 0;
232 /* XXX: Handle intersection */
233 if (last_request->initiator == REGDOM_SET_BY_COUNTRY_IE)
234 return -EOPNOTSUPP;
235 return 0;
236 default:
237 return -EINVAL;
105 } 238 }
239}
106 240
107static const struct ieee80211_regdomain ieee80211_regdoms[] = { 241static bool __reg_is_valid_request(char *alpha2,
108 REGDOM(US), 242 struct regulatory_request **request)
109 REGDOM(JP), 243{
110 REGDOM(EU), 244 struct regulatory_request *req;
111}; 245 if (list_empty(&regulatory_requests))
246 return false;
247 list_for_each_entry(req, &regulatory_requests, list) {
248 if (alpha2_equal(req->alpha2, alpha2)) {
249 *request = req;
250 return true;
251 }
252 }
253 return false;
254}
112 255
256/* Used by nl80211 before kmalloc'ing our regulatory domain */
257bool reg_is_valid_request(char *alpha2)
258{
259 struct regulatory_request *request = NULL;
260 return __reg_is_valid_request(alpha2, &request);
261}
113 262
114static const struct ieee80211_regdomain *get_regdom(void) 263/* Sanity check on a regulatory rule */
264static bool is_valid_reg_rule(struct ieee80211_reg_rule *rule)
115{ 265{
116 static const struct ieee80211_channel_range 266 struct ieee80211_freq_range *freq_range = &rule->freq_range;
117 ieee80211_world_channels[] = { 267 u32 freq_diff;
118 /* IEEE 802.11b/g, channels 1..11 */ 268
119 RANGE_PWR(2412, 2462, 27, 6, 0), 269 if (freq_range->start_freq_khz == 0 || freq_range->end_freq_khz == 0)
120 }; 270 return false;
121 static const struct ieee80211_regdomain regdom_world = REGDOM(world); 271
122 int i; 272 if (freq_range->start_freq_khz > freq_range->end_freq_khz)
273 return false;
274
275 freq_diff = freq_range->end_freq_khz - freq_range->start_freq_khz;
276
277 if (freq_range->max_bandwidth_khz > freq_diff)
278 return false;
279
280 return true;
281}
282
283static bool is_valid_rd(struct ieee80211_regdomain *rd)
284{
285 struct ieee80211_reg_rule *reg_rule = NULL;
286 unsigned int i;
123 287
124 for (i = 0; i < ARRAY_SIZE(ieee80211_regdoms); i++) 288 if (!rd->n_reg_rules)
125 if (strcmp(ieee80211_regdom, ieee80211_regdoms[i].code) == 0) 289 return false;
126 return &ieee80211_regdoms[i];
127 290
128 return &regdom_world; 291 for (i = 0; i < rd->n_reg_rules; i++) {
292 reg_rule = &rd->reg_rules[i];
293 if (!is_valid_reg_rule(reg_rule))
294 return false;
295 }
296
297 return true;
129} 298}
130 299
300/* Returns value in KHz */
301static u32 freq_max_bandwidth(const struct ieee80211_freq_range *freq_range,
302 u32 freq)
303{
304 unsigned int i;
305 for (i = 0; i < ARRAY_SIZE(supported_bandwidths); i++) {
306 u32 start_freq_khz = freq - supported_bandwidths[i]/2;
307 u32 end_freq_khz = freq + supported_bandwidths[i]/2;
308 if (start_freq_khz >= freq_range->start_freq_khz &&
309 end_freq_khz <= freq_range->end_freq_khz)
310 return supported_bandwidths[i];
311 }
312 return 0;
313}
131 314
132static void handle_channel(struct ieee80211_channel *chan, 315/* XXX: add support for the rest of enum nl80211_reg_rule_flags, we may
133 const struct ieee80211_regdomain *rd) 316 * want to just have the channel structure use these */
317static u32 map_regdom_flags(u32 rd_flags)
318{
319 u32 channel_flags = 0;
320 if (rd_flags & NL80211_RRF_PASSIVE_SCAN)
321 channel_flags |= IEEE80211_CHAN_PASSIVE_SCAN;
322 if (rd_flags & NL80211_RRF_NO_IBSS)
323 channel_flags |= IEEE80211_CHAN_NO_IBSS;
324 if (rd_flags & NL80211_RRF_DFS)
325 channel_flags |= IEEE80211_CHAN_RADAR;
326 return channel_flags;
327}
328
329/**
330 * freq_reg_info - get regulatory information for the given frequency
331 * @center_freq: Frequency in KHz for which we want regulatory information for
332 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
333 * you can set this to 0. If this frequency is allowed we then set
334 * this value to the maximum allowed bandwidth.
335 * @reg_rule: the regulatory rule which we have for this frequency
336 *
337 * Use this function to get the regulatory rule for a specific frequency.
338 */
339static int freq_reg_info(u32 center_freq, u32 *bandwidth,
340 const struct ieee80211_reg_rule **reg_rule)
134{ 341{
135 int i; 342 int i;
136 u32 flags = chan->orig_flags; 343 u32 max_bandwidth = 0;
137 const struct ieee80211_channel_range *rg = NULL;
138 344
139 for (i = 0; i < rd->n_ranges; i++) { 345 if (!cfg80211_regdomain)
140 if (rd->ranges[i].start_freq <= chan->center_freq && 346 return -EINVAL;
141 chan->center_freq <= rd->ranges[i].end_freq) { 347
142 rg = &rd->ranges[i]; 348 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
349 const struct ieee80211_reg_rule *rr;
350 const struct ieee80211_freq_range *fr = NULL;
351 const struct ieee80211_power_rule *pr = NULL;
352
353 rr = &cfg80211_regdomain->reg_rules[i];
354 fr = &rr->freq_range;
355 pr = &rr->power_rule;
356 max_bandwidth = freq_max_bandwidth(fr, center_freq);
357 if (max_bandwidth && *bandwidth <= max_bandwidth) {
358 *reg_rule = rr;
359 *bandwidth = max_bandwidth;
143 break; 360 break;
144 } 361 }
145 } 362 }
146 363
147 if (!rg) { 364 return !max_bandwidth;
148 /* not found */ 365}
366
367static void handle_channel(struct ieee80211_channel *chan)
368{
369 int r;
370 u32 flags = chan->orig_flags;
371 u32 max_bandwidth = 0;
372 const struct ieee80211_reg_rule *reg_rule = NULL;
373 const struct ieee80211_power_rule *power_rule = NULL;
374
375 r = freq_reg_info(MHZ_TO_KHZ(chan->center_freq),
376 &max_bandwidth, &reg_rule);
377
378 if (r) {
149 flags |= IEEE80211_CHAN_DISABLED; 379 flags |= IEEE80211_CHAN_DISABLED;
150 chan->flags = flags; 380 chan->flags = flags;
151 return; 381 return;
152 } 382 }
153 383
154 chan->flags = flags; 384 power_rule = &reg_rule->power_rule;
385
386 chan->flags = flags | map_regdom_flags(reg_rule->flags);
155 chan->max_antenna_gain = min(chan->orig_mag, 387 chan->max_antenna_gain = min(chan->orig_mag,
156 rg->max_antenna_gain); 388 (int) MBI_TO_DBI(power_rule->max_antenna_gain));
389 chan->max_bandwidth = KHZ_TO_MHZ(max_bandwidth);
157 if (chan->orig_mpwr) 390 if (chan->orig_mpwr)
158 chan->max_power = min(chan->orig_mpwr, rg->max_power); 391 chan->max_power = min(chan->orig_mpwr,
392 (int) MBM_TO_DBM(power_rule->max_eirp));
159 else 393 else
160 chan->max_power = rg->max_power; 394 chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
161} 395}
162 396
163static void handle_band(struct ieee80211_supported_band *sband, 397static void handle_band(struct ieee80211_supported_band *sband)
164 const struct ieee80211_regdomain *rd)
165{ 398{
166 int i; 399 int i;
167 400
168 for (i = 0; i < sband->n_channels; i++) 401 for (i = 0; i < sband->n_channels; i++)
169 handle_channel(&sband->channels[i], rd); 402 handle_channel(&sband->channels[i]);
170} 403}
171 404
172void wiphy_update_regulatory(struct wiphy *wiphy) 405static void update_all_wiphy_regulatory(enum reg_set_by setby)
173{ 406{
174 enum ieee80211_band band; 407 struct cfg80211_registered_device *drv;
175 const struct ieee80211_regdomain *rd = get_regdom();
176 408
177 for (band = 0; band < IEEE80211_NUM_BANDS; band++) 409 list_for_each_entry(drv, &cfg80211_drv_list, list)
410 wiphy_update_regulatory(&drv->wiphy, setby);
411}
412
413void wiphy_update_regulatory(struct wiphy *wiphy, enum reg_set_by setby)
414{
415 enum ieee80211_band band;
416 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
178 if (wiphy->bands[band]) 417 if (wiphy->bands[band])
179 handle_band(wiphy->bands[band], rd); 418 handle_band(wiphy->bands[band]);
419 if (wiphy->reg_notifier)
420 wiphy->reg_notifier(wiphy, setby);
421 }
422}
423
424/* Caller must hold &cfg80211_drv_mutex */
425int __regulatory_hint(struct wiphy *wiphy, enum reg_set_by set_by,
426 const char *alpha2, struct ieee80211_regdomain *rd)
427{
428 struct regulatory_request *request;
429 char *rd_alpha2;
430 int r = 0;
431
432 r = ignore_request(wiphy, set_by, (char *) alpha2, rd);
433 if (r)
434 return r;
435
436 if (rd)
437 rd_alpha2 = rd->alpha2;
438 else
439 rd_alpha2 = (char *) alpha2;
440
441 switch (set_by) {
442 case REGDOM_SET_BY_CORE:
443 case REGDOM_SET_BY_COUNTRY_IE:
444 case REGDOM_SET_BY_DRIVER:
445 case REGDOM_SET_BY_USER:
446 request = kzalloc(sizeof(struct regulatory_request),
447 GFP_KERNEL);
448 if (!request)
449 return -ENOMEM;
450
451 request->alpha2[0] = rd_alpha2[0];
452 request->alpha2[1] = rd_alpha2[1];
453 request->initiator = set_by;
454 request->wiphy = wiphy;
455
456 list_add_tail(&request->list, &regulatory_requests);
457 if (rd)
458 break;
459 r = call_crda(alpha2);
460#ifndef CONFIG_WIRELESS_OLD_REGULATORY
461 if (r)
462 printk(KERN_ERR "cfg80211: Failed calling CRDA\n");
463#endif
464 break;
465 default:
466 r = -ENOTSUPP;
467 break;
468 }
469
470 return r;
471}
472
473/* If rd is not NULL and if this call fails the caller must free it */
474int regulatory_hint(struct wiphy *wiphy, const char *alpha2,
475 struct ieee80211_regdomain *rd)
476{
477 int r;
478 BUG_ON(!rd && !alpha2);
479
480 mutex_lock(&cfg80211_drv_mutex);
481
482 r = __regulatory_hint(wiphy, REGDOM_SET_BY_DRIVER, alpha2, rd);
483 if (r || !rd)
484 goto unlock_and_exit;
485
486 /* If the driver passed a regulatory domain we skipped asking
487 * userspace for one so we can now go ahead and set it */
488 r = set_regdom(rd);
489
490unlock_and_exit:
491 mutex_unlock(&cfg80211_drv_mutex);
492 return r;
493}
494EXPORT_SYMBOL(regulatory_hint);
495
496
497static void print_rd_rules(struct ieee80211_regdomain *rd)
498{
499 unsigned int i;
500 struct ieee80211_reg_rule *reg_rule = NULL;
501 struct ieee80211_freq_range *freq_range = NULL;
502 struct ieee80211_power_rule *power_rule = NULL;
503
504 printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), "
505 "(max_antenna_gain, max_eirp)\n");
506
507 for (i = 0; i < rd->n_reg_rules; i++) {
508 reg_rule = &rd->reg_rules[i];
509 freq_range = &reg_rule->freq_range;
510 power_rule = &reg_rule->power_rule;
511
512 /* There may not be documentation for max antenna gain
513 * in certain regions */
514 if (power_rule->max_antenna_gain)
515 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
516 "(%d mBi, %d mBm)\n",
517 freq_range->start_freq_khz,
518 freq_range->end_freq_khz,
519 freq_range->max_bandwidth_khz,
520 power_rule->max_antenna_gain,
521 power_rule->max_eirp);
522 else
523 printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
524 "(N/A, %d mBm)\n",
525 freq_range->start_freq_khz,
526 freq_range->end_freq_khz,
527 freq_range->max_bandwidth_khz,
528 power_rule->max_eirp);
529 }
530}
531
532static void print_regdomain(struct ieee80211_regdomain *rd)
533{
534
535 if (is_world_regdom(rd->alpha2))
536 printk(KERN_INFO "cfg80211: World regulatory "
537 "domain updated:\n");
538 else {
539 if (is_unknown_alpha2(rd->alpha2))
540 printk(KERN_INFO "cfg80211: Regulatory domain "
541 "changed to driver built-in settings "
542 "(unknown country)\n");
543 else
544 printk(KERN_INFO "cfg80211: Regulatory domain "
545 "changed to country: %c%c\n",
546 rd->alpha2[0], rd->alpha2[1]);
547 }
548 print_rd_rules(rd);
549}
550
551void print_regdomain_info(struct ieee80211_regdomain *rd)
552{
553 printk(KERN_INFO "cfg80211: Regulatory domain: %c%c\n",
554 rd->alpha2[0], rd->alpha2[1]);
555 print_rd_rules(rd);
556}
557
558#ifdef CONFIG_WIRELESS_OLD_REGULATORY
559
560static bool is_old_static_regdom(struct ieee80211_regdomain *rd)
561{
562 if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
563 return true;
564 return false;
565}
566
567/* The old crap never deals with a world regulatory domain, it only
568 * deals with the static regulatory domain passed and if possible
569 * an updated "US" or "JP" regulatory domain. We do however store the
570 * old static regulatory domain in cfg80211_world_regdom for convenience
571 * of use here */
572static void reset_regdomains_static(void)
573{
574 if (!is_old_static_regdom(cfg80211_regdomain))
575 kfree(cfg80211_regdomain);
576 /* This is setting the regdom to the old static regdom */
577 cfg80211_regdomain =
578 (struct ieee80211_regdomain *) cfg80211_world_regdom;
579}
580#else
581static void reset_regdomains(void)
582{
583 if (cfg80211_world_regdom && cfg80211_world_regdom != &world_regdom) {
584 if (cfg80211_world_regdom == cfg80211_regdomain) {
585 kfree(cfg80211_regdomain);
586 } else {
587 kfree(cfg80211_world_regdom);
588 kfree(cfg80211_regdomain);
589 }
590 } else if (cfg80211_regdomain && cfg80211_regdomain != &world_regdom)
591 kfree(cfg80211_regdomain);
592
593 cfg80211_world_regdom = (struct ieee80211_regdomain *) &world_regdom;
594 cfg80211_regdomain = NULL;
595}
596
597/* Dynamic world regulatory domain requested by the wireless
598 * core upon initialization */
599static void update_world_regdomain(struct ieee80211_regdomain *rd)
600{
601 BUG_ON(list_empty(&regulatory_requests));
602
603 reset_regdomains();
604
605 cfg80211_world_regdom = rd;
606 cfg80211_regdomain = rd;
607}
608#endif
609
610static int __set_regdom(struct ieee80211_regdomain *rd)
611{
612 struct regulatory_request *request = NULL;
613
614 /* Some basic sanity checks first */
615
616#ifdef CONFIG_WIRELESS_OLD_REGULATORY
617 /* We ignore the world regdom with the old static regdomains setup
618 * as there is no point to it with satic regulatory definitions :(
619 * Don't worry this shit will be removed soon... */
620 if (is_world_regdom(rd->alpha2))
621 return -EINVAL;
622#else
623 if (is_world_regdom(rd->alpha2)) {
624 if (WARN_ON(!__reg_is_valid_request(rd->alpha2, &request)))
625 return -EINVAL;
626 update_world_regdomain(rd);
627 return 0;
628 }
629#endif
630
631 if (!is_alpha2_set(rd->alpha2) && !is_an_alpha2(rd->alpha2) &&
632 !is_unknown_alpha2(rd->alpha2))
633 return -EINVAL;
634
635 if (list_empty(&regulatory_requests))
636 return -EINVAL;
637
638#ifdef CONFIG_WIRELESS_OLD_REGULATORY
639 /* Static "US" and "JP" will be overridden, but just once */
640 if (!is_old_static_regdom(cfg80211_regdomain) &&
641 !regdom_changed(rd->alpha2))
642 return -EINVAL;
643#else
644 if (!regdom_changed(rd->alpha2))
645 return -EINVAL;
646#endif
647
648 /* Now lets set the regulatory domain, update all driver channels
649 * and finally inform them of what we have done, in case they want
650 * to review or adjust their own settings based on their own
651 * internal EEPROM data */
652
653 if (WARN_ON(!__reg_is_valid_request(rd->alpha2, &request)))
654 return -EINVAL;
655
656#ifdef CONFIG_WIRELESS_OLD_REGULATORY
657 reset_regdomains_static();
658#else
659 reset_regdomains();
660#endif
661
662 /* Country IE parsing coming soon */
663 switch (request->initiator) {
664 case REGDOM_SET_BY_CORE:
665 case REGDOM_SET_BY_DRIVER:
666 case REGDOM_SET_BY_USER:
667 if (!is_valid_rd(rd)) {
668 printk(KERN_ERR "cfg80211: Invalid "
669 "regulatory domain detected:\n");
670 print_regdomain_info(rd);
671 return -EINVAL;
672 }
673 break;
674 case REGDOM_SET_BY_COUNTRY_IE: /* Not yet */
675 WARN_ON(1);
676 default:
677 return -EOPNOTSUPP;
678 }
679
680 /* Tada! */
681 cfg80211_regdomain = rd;
682 request->granted = 1;
683
684 return 0;
685}
686
687
688/* Use this call to set the current regulatory domain. Conflicts with
689 * multiple drivers can be ironed out later. Caller must've already
690 * kmalloc'd the rd structure. If this calls fails you should kfree()
691 * the passed rd. Caller must hold cfg80211_drv_mutex */
692int set_regdom(struct ieee80211_regdomain *rd)
693{
694 struct regulatory_request *this_request = NULL, *prev_request = NULL;
695 int r;
696
697 if (!list_empty(&regulatory_requests))
698 prev_request = list_first_entry(&regulatory_requests,
699 struct regulatory_request, list);
700
701 /* Note that this doesn't update the wiphys, this is done below */
702 r = __set_regdom(rd);
703 if (r)
704 return r;
705
706 BUG_ON((!__reg_is_valid_request(rd->alpha2, &this_request)));
707
708 /* The initial standard core update of the world regulatory domain, no
709 * need to keep that request info around if it didn't fail. */
710 if (is_world_regdom(rd->alpha2) &&
711 this_request->initiator == REGDOM_SET_BY_CORE &&
712 this_request->granted) {
713 list_del(&this_request->list);
714 kfree(this_request);
715 this_request = NULL;
716 }
717
718 /* Remove old requests, we only leave behind the last one */
719 if (prev_request) {
720 list_del(&prev_request->list);
721 kfree(prev_request);
722 prev_request = NULL;
723 }
724
725 /* This would make this whole thing pointless */
726 BUG_ON(rd != cfg80211_regdomain);
727
728 /* update all wiphys now with the new established regulatory domain */
729 update_all_wiphy_regulatory(this_request->initiator);
730
731 print_regdomain(rd);
732
733 return r;
734}
735
736int regulatory_init(void)
737{
738 reg_pdev = platform_device_register_simple("regulatory", 0, NULL, 0);
739 if (IS_ERR(reg_pdev))
740 return PTR_ERR(reg_pdev);
741 return 0;
742}
743
744void regulatory_exit(void)
745{
746 struct regulatory_request *req, *req_tmp;
747 mutex_lock(&cfg80211_drv_mutex);
748#ifdef CONFIG_WIRELESS_OLD_REGULATORY
749 reset_regdomains_static();
750#else
751 reset_regdomains();
752#endif
753 list_for_each_entry_safe(req, req_tmp, &regulatory_requests, list) {
754 list_del(&req->list);
755 kfree(req);
756 }
757 platform_device_unregister(reg_pdev);
758 mutex_unlock(&cfg80211_drv_mutex);
180} 759}
diff --git a/net/wireless/reg.h b/net/wireless/reg.h
new file mode 100644
index 000000000000..d75fd0232972
--- /dev/null
+++ b/net/wireless/reg.h
@@ -0,0 +1,44 @@
1#ifndef __NET_WIRELESS_REG_H
2#define __NET_WIRELESS_REG_H
3
4extern const struct ieee80211_regdomain world_regdom;
5#ifdef CONFIG_WIRELESS_OLD_REGULATORY
6extern const struct ieee80211_regdomain us_regdom;
7extern const struct ieee80211_regdomain jp_regdom;
8extern const struct ieee80211_regdomain eu_regdom;
9#endif
10
11extern struct ieee80211_regdomain *cfg80211_regdomain;
12extern struct ieee80211_regdomain *cfg80211_world_regdom;
13extern struct list_head regulatory_requests;
14
15struct regdom_last_setby {
16 struct wiphy *wiphy;
17 u8 initiator;
18};
19
20/* wiphy is set if this request's initiator is REGDOM_SET_BY_DRIVER */
21struct regulatory_request {
22 struct list_head list;
23 struct wiphy *wiphy;
24 int granted;
25 enum reg_set_by initiator;
26 char alpha2[2];
27};
28
29bool is_world_regdom(char *alpha2);
30bool reg_is_valid_request(char *alpha2);
31
32int set_regdom(struct ieee80211_regdomain *rd);
33int __regulatory_hint_alpha2(struct wiphy *wiphy, enum reg_set_by set_by,
34 const char *alpha2);
35
36int regulatory_init(void);
37void regulatory_exit(void);
38
39void print_regdomain_info(struct ieee80211_regdomain *);
40
41/* If a char is A-Z */
42#define IS_ALPHA(letter) (letter >= 65 && letter <= 90)
43
44#endif /* __NET_WIRELESS_REG_H */