aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig33
-rw-r--r--net/mac80211/Makefile9
-rw-r--r--net/mac80211/cfg.c400
-rw-r--r--net/mac80211/debugfs.c47
-rw-r--r--net/mac80211/debugfs_netdev.c206
-rw-r--r--net/mac80211/debugfs_sta.c174
-rw-r--r--net/mac80211/debugfs_sta.h2
-rw-r--r--net/mac80211/ieee80211.c959
-rw-r--r--net/mac80211/ieee80211_i.h468
-rw-r--r--net/mac80211/ieee80211_iface.c48
-rw-r--r--net/mac80211/ieee80211_ioctl.c234
-rw-r--r--net/mac80211/ieee80211_key.h26
-rw-r--r--net/mac80211/ieee80211_rate.c23
-rw-r--r--net/mac80211/ieee80211_rate.h44
-rw-r--r--net/mac80211/ieee80211_sta.c1525
-rw-r--r--net/mac80211/key.c183
-rw-r--r--net/mac80211/mesh.c449
-rw-r--r--net/mac80211/mesh.h290
-rw-r--r--net/mac80211/mesh_hwmp.c857
-rw-r--r--net/mac80211/mesh_pathtbl.c516
-rw-r--r--net/mac80211/mesh_plink.c761
-rw-r--r--net/mac80211/rc80211_pid_algo.c122
-rw-r--r--net/mac80211/rc80211_simple.c400
-rw-r--r--net/mac80211/regdomain.c152
-rw-r--r--net/mac80211/rx.c857
-rw-r--r--net/mac80211/sta_info.c550
-rw-r--r--net/mac80211/sta_info.h322
-rw-r--r--net/mac80211/tx.c727
-rw-r--r--net/mac80211/util.c170
-rw-r--r--net/mac80211/wep.c40
-rw-r--r--net/mac80211/wep.h8
-rw-r--r--net/mac80211/wme.c139
-rw-r--r--net/mac80211/wme.h23
-rw-r--r--net/mac80211/wpa.c152
-rw-r--r--net/mac80211/wpa.h24
35 files changed, 7892 insertions, 3048 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 45c7c0c3875e..520a5180a4f6 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -32,15 +32,6 @@ config MAC80211_RC_DEFAULT_PID
32 default rate control algorithm. You should choose 32 default rate control algorithm. You should choose
33 this unless you know what you are doing. 33 this unless you know what you are doing.
34 34
35config MAC80211_RC_DEFAULT_SIMPLE
36 bool "Simple rate control algorithm"
37 select MAC80211_RC_SIMPLE
38 ---help---
39 Select the simple rate control as the default rate
40 control algorithm. Note that this is a non-responsive,
41 dumb algorithm. You should choose the PID rate control
42 instead.
43
44config MAC80211_RC_DEFAULT_NONE 35config MAC80211_RC_DEFAULT_NONE
45 bool "No default algorithm" 36 bool "No default algorithm"
46 depends on EMBEDDED 37 depends on EMBEDDED
@@ -57,7 +48,6 @@ comment "build the algorithm into mac80211."
57config MAC80211_RC_DEFAULT 48config MAC80211_RC_DEFAULT
58 string 49 string
59 default "pid" if MAC80211_RC_DEFAULT_PID 50 default "pid" if MAC80211_RC_DEFAULT_PID
60 default "simple" if MAC80211_RC_DEFAULT_SIMPLE
61 default "" 51 default ""
62 52
63config MAC80211_RC_PID 53config MAC80211_RC_PID
@@ -70,16 +60,16 @@ config MAC80211_RC_PID
70 Say Y or M unless you're sure you want to use a 60 Say Y or M unless you're sure you want to use a
71 different rate control algorithm. 61 different rate control algorithm.
72 62
73config MAC80211_RC_SIMPLE 63endmenu
74 tristate "Simple rate control algorithm (DEPRECATED)" 64
65config MAC80211_MESH
66 bool "Enable mac80211 mesh networking (pre-802.11s) support"
67 depends on MAC80211 && EXPERIMENTAL
75 ---help--- 68 ---help---
76 This option enables a very simple, non-responsive TX 69 This options enables support of Draft 802.11s mesh networking.
77 rate control algorithm. This algorithm is deprecated 70 The implementation is based on Draft 1.08 of the Mesh Networking
78 and will be removed from the kernel in the near future. 71 amendment. For more information visit http://o11s.org/.
79 It has been replaced by the PID algorithm.
80 72
81 Say N unless you know what you are doing.
82endmenu
83 73
84config MAC80211_LEDS 74config MAC80211_LEDS
85 bool "Enable LED triggers" 75 bool "Enable LED triggers"
@@ -166,3 +156,10 @@ config MAC80211_VERBOSE_PS_DEBUG
166 ---help--- 156 ---help---
167 Say Y here to print out verbose powersave 157 Say Y here to print out verbose powersave
168 mode debug messages. 158 mode debug messages.
159
160config MAC80211_VERBOSE_MPL_DEBUG
161 bool "Verbose mesh peer link debugging"
162 depends on MAC80211_DEBUG && MAC80211_MESH
163 ---help---
164 Say Y here to print out verbose mesh peer link
165 debug messages.
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 54f46bc80cfe..70f4b26c2d87 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -19,7 +19,6 @@ mac80211-y := \
19 ieee80211_iface.o \ 19 ieee80211_iface.o \
20 ieee80211_rate.o \ 20 ieee80211_rate.o \
21 michael.o \ 21 michael.o \
22 regdomain.o \
23 tkip.o \ 22 tkip.o \
24 aes_ccm.o \ 23 aes_ccm.o \
25 cfg.o \ 24 cfg.o \
@@ -37,11 +36,15 @@ mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
37 debugfs_netdev.o \ 36 debugfs_netdev.o \
38 debugfs_key.o 37 debugfs_key.o
39 38
39mac80211-$(CONFIG_MAC80211_MESH) += \
40 mesh.o \
41 mesh_pathtbl.o \
42 mesh_plink.o \
43 mesh_hwmp.o
44
40 45
41# Build rate control algorithm(s) 46# Build rate control algorithm(s)
42CFLAGS_rc80211_simple.o += -DRC80211_SIMPLE_COMPILE
43CFLAGS_rc80211_pid_algo.o += -DRC80211_PID_COMPILE 47CFLAGS_rc80211_pid_algo.o += -DRC80211_PID_COMPILE
44mac80211-$(CONFIG_MAC80211_RC_SIMPLE) += rc80211_simple.o
45mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc-pid-$(CONFIG_MAC80211_RC_PID)) 48mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc-pid-$(CONFIG_MAC80211_RC_PID))
46 49
47# Modular rate algorithms are assigned to mac80211-m - make separate modules 50# Modular rate algorithms are assigned to mac80211-m - make separate modules
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 22c9619ba776..6b183a3526b0 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -15,6 +15,7 @@
15#include "ieee80211_i.h" 15#include "ieee80211_i.h"
16#include "cfg.h" 16#include "cfg.h"
17#include "ieee80211_rate.h" 17#include "ieee80211_rate.h"
18#include "mesh.h"
18 19
19static enum ieee80211_if_types 20static enum ieee80211_if_types
20nl80211_type_to_mac80211_type(enum nl80211_iftype type) 21nl80211_type_to_mac80211_type(enum nl80211_iftype type)
@@ -28,16 +29,24 @@ nl80211_type_to_mac80211_type(enum nl80211_iftype type)
28 return IEEE80211_IF_TYPE_STA; 29 return IEEE80211_IF_TYPE_STA;
29 case NL80211_IFTYPE_MONITOR: 30 case NL80211_IFTYPE_MONITOR:
30 return IEEE80211_IF_TYPE_MNTR; 31 return IEEE80211_IF_TYPE_MNTR;
32#ifdef CONFIG_MAC80211_MESH
33 case NL80211_IFTYPE_MESH_POINT:
34 return IEEE80211_IF_TYPE_MESH_POINT;
35#endif
31 default: 36 default:
32 return IEEE80211_IF_TYPE_INVALID; 37 return IEEE80211_IF_TYPE_INVALID;
33 } 38 }
34} 39}
35 40
36static int ieee80211_add_iface(struct wiphy *wiphy, char *name, 41static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
37 enum nl80211_iftype type) 42 enum nl80211_iftype type, u32 *flags,
43 struct vif_params *params)
38{ 44{
39 struct ieee80211_local *local = wiphy_priv(wiphy); 45 struct ieee80211_local *local = wiphy_priv(wiphy);
40 enum ieee80211_if_types itype; 46 enum ieee80211_if_types itype;
47 struct net_device *dev;
48 struct ieee80211_sub_if_data *sdata;
49 int err;
41 50
42 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) 51 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
43 return -ENODEV; 52 return -ENODEV;
@@ -46,7 +55,13 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
46 if (itype == IEEE80211_IF_TYPE_INVALID) 55 if (itype == IEEE80211_IF_TYPE_INVALID)
47 return -EINVAL; 56 return -EINVAL;
48 57
49 return ieee80211_if_add(local->mdev, name, NULL, itype); 58 err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
59 if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags)
60 return err;
61
62 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
63 sdata->u.mntr_flags = *flags;
64 return 0;
50} 65}
51 66
52static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) 67static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
@@ -69,7 +84,8 @@ static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
69} 84}
70 85
71static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, 86static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
72 enum nl80211_iftype type) 87 enum nl80211_iftype type, u32 *flags,
88 struct vif_params *params)
73{ 89{
74 struct ieee80211_local *local = wiphy_priv(wiphy); 90 struct ieee80211_local *local = wiphy_priv(wiphy);
75 struct net_device *dev; 91 struct net_device *dev;
@@ -99,6 +115,15 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
99 ieee80211_if_reinit(dev); 115 ieee80211_if_reinit(dev);
100 ieee80211_if_set_type(dev, itype); 116 ieee80211_if_set_type(dev, itype);
101 117
118 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
119 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
120 params->mesh_id_len,
121 params->mesh_id);
122
123 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
124 return 0;
125
126 sdata->u.mntr_flags = *flags;
102 return 0; 127 return 0;
103} 128}
104 129
@@ -109,7 +134,7 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
109 struct ieee80211_sub_if_data *sdata; 134 struct ieee80211_sub_if_data *sdata;
110 struct sta_info *sta = NULL; 135 struct sta_info *sta = NULL;
111 enum ieee80211_key_alg alg; 136 enum ieee80211_key_alg alg;
112 int ret; 137 struct ieee80211_key *key;
113 138
114 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 139 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
115 140
@@ -128,21 +153,21 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
128 return -EINVAL; 153 return -EINVAL;
129 } 154 }
130 155
156 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
157 if (!key)
158 return -ENOMEM;
159
131 if (mac_addr) { 160 if (mac_addr) {
132 sta = sta_info_get(sdata->local, mac_addr); 161 sta = sta_info_get(sdata->local, mac_addr);
133 if (!sta) 162 if (!sta) {
163 ieee80211_key_free(key);
134 return -ENOENT; 164 return -ENOENT;
165 }
135 } 166 }
136 167
137 ret = 0; 168 ieee80211_key_link(key, sdata, sta);
138 if (!ieee80211_key_alloc(sdata, sta, alg, key_idx,
139 params->key_len, params->key))
140 ret = -ENOMEM;
141
142 if (sta)
143 sta_info_put(sta);
144 169
145 return ret; 170 return 0;
146} 171}
147 172
148static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, 173static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
@@ -160,12 +185,12 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
160 return -ENOENT; 185 return -ENOENT;
161 186
162 ret = 0; 187 ret = 0;
163 if (sta->key) 188 if (sta->key) {
164 ieee80211_key_free(sta->key); 189 ieee80211_key_free(sta->key);
165 else 190 WARN_ON(sta->key);
191 } else
166 ret = -ENOENT; 192 ret = -ENOENT;
167 193
168 sta_info_put(sta);
169 return ret; 194 return ret;
170 } 195 }
171 196
@@ -173,6 +198,7 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
173 return -ENOENT; 198 return -ENOENT;
174 199
175 ieee80211_key_free(sdata->keys[key_idx]); 200 ieee80211_key_free(sdata->keys[key_idx]);
201 WARN_ON(sdata->keys[key_idx]);
176 202
177 return 0; 203 return 0;
178} 204}
@@ -254,8 +280,6 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
254 err = 0; 280 err = 0;
255 281
256 out: 282 out:
257 if (sta)
258 sta_info_put(sta);
259 return err; 283 return err;
260} 284}
261 285
@@ -271,29 +295,73 @@ static int ieee80211_config_default_key(struct wiphy *wiphy,
271 return 0; 295 return 0;
272} 296}
273 297
298static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
299{
300 struct ieee80211_sub_if_data *sdata = sta->sdata;
301
302 sinfo->filled = STATION_INFO_INACTIVE_TIME |
303 STATION_INFO_RX_BYTES |
304 STATION_INFO_TX_BYTES;
305
306 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
307 sinfo->rx_bytes = sta->rx_bytes;
308 sinfo->tx_bytes = sta->tx_bytes;
309
310 if (ieee80211_vif_is_mesh(&sdata->vif)) {
311#ifdef CONFIG_MAC80211_MESH
312 sinfo->filled |= STATION_INFO_LLID |
313 STATION_INFO_PLID |
314 STATION_INFO_PLINK_STATE;
315
316 sinfo->llid = le16_to_cpu(sta->llid);
317 sinfo->plid = le16_to_cpu(sta->plid);
318 sinfo->plink_state = sta->plink_state;
319#endif
320 }
321}
322
323
324static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
325 int idx, u8 *mac, struct station_info *sinfo)
326{
327 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
328 struct sta_info *sta;
329 int ret = -ENOENT;
330
331 rcu_read_lock();
332
333 sta = sta_info_get_by_idx(local, idx, dev);
334 if (sta) {
335 ret = 0;
336 memcpy(mac, sta->addr, ETH_ALEN);
337 sta_set_sinfo(sta, sinfo);
338 }
339
340 rcu_read_unlock();
341
342 return ret;
343}
344
274static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, 345static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
275 u8 *mac, struct station_stats *stats) 346 u8 *mac, struct station_info *sinfo)
276{ 347{
277 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 348 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
278 struct sta_info *sta; 349 struct sta_info *sta;
350 int ret = -ENOENT;
279 351
280 sta = sta_info_get(local, mac); 352 rcu_read_lock();
281 if (!sta)
282 return -ENOENT;
283 353
284 /* XXX: verify sta->dev == dev */ 354 /* XXX: verify sta->dev == dev */
285 355
286 stats->filled = STATION_STAT_INACTIVE_TIME | 356 sta = sta_info_get(local, mac);
287 STATION_STAT_RX_BYTES | 357 if (sta) {
288 STATION_STAT_TX_BYTES; 358 ret = 0;
289 359 sta_set_sinfo(sta, sinfo);
290 stats->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); 360 }
291 stats->rx_bytes = sta->rx_bytes;
292 stats->tx_bytes = sta->tx_bytes;
293 361
294 sta_info_put(sta); 362 rcu_read_unlock();
295 363
296 return 0; 364 return ret;
297} 365}
298 366
299/* 367/*
@@ -486,8 +554,8 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
486 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ 554 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
487 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ 555 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
488 556
489 skb->dev = sta->dev; 557 skb->dev = sta->sdata->dev;
490 skb->protocol = eth_type_trans(skb, sta->dev); 558 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
491 memset(skb->cb, 0, sizeof(skb->cb)); 559 memset(skb->cb, 0, sizeof(skb->cb));
492 netif_rx(skb); 560 netif_rx(skb);
493} 561}
@@ -498,7 +566,14 @@ static void sta_apply_parameters(struct ieee80211_local *local,
498{ 566{
499 u32 rates; 567 u32 rates;
500 int i, j; 568 int i, j;
501 struct ieee80211_hw_mode *mode; 569 struct ieee80211_supported_band *sband;
570 struct ieee80211_sub_if_data *sdata = sta->sdata;
571
572 /*
573 * FIXME: updating the flags is racy when this function is
574 * called from ieee80211_change_station(), this will
575 * be resolved in a future patch.
576 */
502 577
503 if (params->station_flags & STATION_FLAG_CHANGED) { 578 if (params->station_flags & STATION_FLAG_CHANGED) {
504 sta->flags &= ~WLAN_STA_AUTHORIZED; 579 sta->flags &= ~WLAN_STA_AUTHORIZED;
@@ -514,6 +589,13 @@ static void sta_apply_parameters(struct ieee80211_local *local,
514 sta->flags |= WLAN_STA_WME; 589 sta->flags |= WLAN_STA_WME;
515 } 590 }
516 591
592 /*
593 * FIXME: updating the following information is racy when this
594 * function is called from ieee80211_change_station().
595 * However, all this information should be static so
596 * maybe we should just reject attemps to change it.
597 */
598
517 if (params->aid) { 599 if (params->aid) {
518 sta->aid = params->aid; 600 sta->aid = params->aid;
519 if (sta->aid > IEEE80211_MAX_AID) 601 if (sta->aid > IEEE80211_MAX_AID)
@@ -525,15 +607,27 @@ static void sta_apply_parameters(struct ieee80211_local *local,
525 607
526 if (params->supported_rates) { 608 if (params->supported_rates) {
527 rates = 0; 609 rates = 0;
528 mode = local->oper_hw_mode; 610 sband = local->hw.wiphy->bands[local->oper_channel->band];
611
529 for (i = 0; i < params->supported_rates_len; i++) { 612 for (i = 0; i < params->supported_rates_len; i++) {
530 int rate = (params->supported_rates[i] & 0x7f) * 5; 613 int rate = (params->supported_rates[i] & 0x7f) * 5;
531 for (j = 0; j < mode->num_rates; j++) { 614 for (j = 0; j < sband->n_bitrates; j++) {
532 if (mode->rates[j].rate == rate) 615 if (sband->bitrates[j].bitrate == rate)
533 rates |= BIT(j); 616 rates |= BIT(j);
534 } 617 }
535 } 618 }
536 sta->supp_rates = rates; 619 sta->supp_rates[local->oper_channel->band] = rates;
620 }
621
622 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
623 switch (params->plink_action) {
624 case PLINK_ACTION_OPEN:
625 mesh_plink_open(sta);
626 break;
627 case PLINK_ACTION_BLOCK:
628 mesh_plink_block(sta);
629 break;
630 }
537 } 631 }
538} 632}
539 633
@@ -543,18 +637,12 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
543 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 637 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
544 struct sta_info *sta; 638 struct sta_info *sta;
545 struct ieee80211_sub_if_data *sdata; 639 struct ieee80211_sub_if_data *sdata;
640 int err;
546 641
547 /* Prevent a race with changing the rate control algorithm */ 642 /* Prevent a race with changing the rate control algorithm */
548 if (!netif_running(dev)) 643 if (!netif_running(dev))
549 return -ENETDOWN; 644 return -ENETDOWN;
550 645
551 /* XXX: get sta belonging to dev */
552 sta = sta_info_get(local, mac);
553 if (sta) {
554 sta_info_put(sta);
555 return -EEXIST;
556 }
557
558 if (params->vlan) { 646 if (params->vlan) {
559 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 647 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
560 648
@@ -564,22 +652,36 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
564 } else 652 } else
565 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 653 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
566 654
567 sta = sta_info_add(local, dev, mac, GFP_KERNEL); 655 if (compare_ether_addr(mac, dev->dev_addr) == 0)
656 return -EINVAL;
657
658 if (is_multicast_ether_addr(mac))
659 return -EINVAL;
660
661 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
568 if (!sta) 662 if (!sta)
569 return -ENOMEM; 663 return -ENOMEM;
570 664
571 sta->dev = sdata->dev;
572 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
573 sdata->vif.type == IEEE80211_IF_TYPE_AP)
574 ieee80211_send_layer2_update(sta);
575
576 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; 665 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
577 666
578 sta_apply_parameters(local, sta, params); 667 sta_apply_parameters(local, sta, params);
579 668
580 rate_control_rate_init(sta, local); 669 rate_control_rate_init(sta, local);
581 670
582 sta_info_put(sta); 671 rcu_read_lock();
672
673 err = sta_info_insert(sta);
674 if (err) {
675 sta_info_destroy(sta);
676 rcu_read_unlock();
677 return err;
678 }
679
680 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
681 sdata->vif.type == IEEE80211_IF_TYPE_AP)
682 ieee80211_send_layer2_update(sta);
683
684 rcu_read_unlock();
583 685
584 return 0; 686 return 0;
585} 687}
@@ -587,7 +689,8 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
587static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, 689static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
588 u8 *mac) 690 u8 *mac)
589{ 691{
590 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 692 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
693 struct ieee80211_local *local = sdata->local;
591 struct sta_info *sta; 694 struct sta_info *sta;
592 695
593 if (mac) { 696 if (mac) {
@@ -596,10 +699,14 @@ static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
596 if (!sta) 699 if (!sta)
597 return -ENOENT; 700 return -ENOENT;
598 701
599 sta_info_free(sta); 702 sta_info_unlink(&sta);
600 sta_info_put(sta); 703
704 if (sta) {
705 synchronize_rcu();
706 sta_info_destroy(sta);
707 }
601 } else 708 } else
602 sta_info_flush(local, dev); 709 sta_info_flush(local, sdata);
603 710
604 return 0; 711 return 0;
605} 712}
@@ -618,23 +725,190 @@ static int ieee80211_change_station(struct wiphy *wiphy,
618 if (!sta) 725 if (!sta)
619 return -ENOENT; 726 return -ENOENT;
620 727
621 if (params->vlan && params->vlan != sta->dev) { 728 if (params->vlan && params->vlan != sta->sdata->dev) {
622 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); 729 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
623 730
624 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN || 731 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
625 vlansdata->vif.type != IEEE80211_IF_TYPE_AP) 732 vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
626 return -EINVAL; 733 return -EINVAL;
627 734
628 sta->dev = params->vlan; 735 sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
629 ieee80211_send_layer2_update(sta); 736 ieee80211_send_layer2_update(sta);
630 } 737 }
631 738
632 sta_apply_parameters(local, sta, params); 739 sta_apply_parameters(local, sta, params);
633 740
634 sta_info_put(sta); 741 return 0;
742}
743
744#ifdef CONFIG_MAC80211_MESH
745static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
746 u8 *dst, u8 *next_hop)
747{
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
749 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
750 struct mesh_path *mpath;
751 struct sta_info *sta;
752 int err;
753
754 if (!netif_running(dev))
755 return -ENETDOWN;
756
757 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
758 return -ENOTSUPP;
759
760 rcu_read_lock();
761 sta = sta_info_get(local, next_hop);
762 if (!sta) {
763 rcu_read_unlock();
764 return -ENOENT;
765 }
766
767 err = mesh_path_add(dst, dev);
768 if (err) {
769 rcu_read_unlock();
770 return err;
771 }
772
773 mpath = mesh_path_lookup(dst, dev);
774 if (!mpath) {
775 rcu_read_unlock();
776 return -ENXIO;
777 }
778 mesh_path_fix_nexthop(mpath, sta);
779
780 rcu_read_unlock();
781 return 0;
782}
635 783
784static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
785 u8 *dst)
786{
787 if (dst)
788 return mesh_path_del(dst, dev);
789
790 mesh_path_flush(dev);
791 return 0;
792}
793
794static int ieee80211_change_mpath(struct wiphy *wiphy,
795 struct net_device *dev,
796 u8 *dst, u8 *next_hop)
797{
798 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
799 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
800 struct mesh_path *mpath;
801 struct sta_info *sta;
802
803 if (!netif_running(dev))
804 return -ENETDOWN;
805
806 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
807 return -ENOTSUPP;
808
809 rcu_read_lock();
810
811 sta = sta_info_get(local, next_hop);
812 if (!sta) {
813 rcu_read_unlock();
814 return -ENOENT;
815 }
816
817 mpath = mesh_path_lookup(dst, dev);
818 if (!mpath) {
819 rcu_read_unlock();
820 return -ENOENT;
821 }
822
823 mesh_path_fix_nexthop(mpath, sta);
824
825 rcu_read_unlock();
826 return 0;
827}
828
829static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
830 struct mpath_info *pinfo)
831{
832 if (mpath->next_hop)
833 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
834 else
835 memset(next_hop, 0, ETH_ALEN);
836
837 pinfo->filled = MPATH_INFO_FRAME_QLEN |
838 MPATH_INFO_DSN |
839 MPATH_INFO_METRIC |
840 MPATH_INFO_EXPTIME |
841 MPATH_INFO_DISCOVERY_TIMEOUT |
842 MPATH_INFO_DISCOVERY_RETRIES |
843 MPATH_INFO_FLAGS;
844
845 pinfo->frame_qlen = mpath->frame_queue.qlen;
846 pinfo->dsn = mpath->dsn;
847 pinfo->metric = mpath->metric;
848 if (time_before(jiffies, mpath->exp_time))
849 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
850 pinfo->discovery_timeout =
851 jiffies_to_msecs(mpath->discovery_timeout);
852 pinfo->discovery_retries = mpath->discovery_retries;
853 pinfo->flags = 0;
854 if (mpath->flags & MESH_PATH_ACTIVE)
855 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
856 if (mpath->flags & MESH_PATH_RESOLVING)
857 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
858 if (mpath->flags & MESH_PATH_DSN_VALID)
859 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
860 if (mpath->flags & MESH_PATH_FIXED)
861 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
862 if (mpath->flags & MESH_PATH_RESOLVING)
863 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
864
865 pinfo->flags = mpath->flags;
866}
867
868static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
869 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
870
871{
872 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
873 struct mesh_path *mpath;
874
875 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
876 return -ENOTSUPP;
877
878 rcu_read_lock();
879 mpath = mesh_path_lookup(dst, dev);
880 if (!mpath) {
881 rcu_read_unlock();
882 return -ENOENT;
883 }
884 memcpy(dst, mpath->dst, ETH_ALEN);
885 mpath_set_pinfo(mpath, next_hop, pinfo);
886 rcu_read_unlock();
887 return 0;
888}
889
890static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
891 int idx, u8 *dst, u8 *next_hop,
892 struct mpath_info *pinfo)
893{
894 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
895 struct mesh_path *mpath;
896
897 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
898 return -ENOTSUPP;
899
900 rcu_read_lock();
901 mpath = mesh_path_lookup_by_idx(idx, dev);
902 if (!mpath) {
903 rcu_read_unlock();
904 return -ENOENT;
905 }
906 memcpy(dst, mpath->dst, ETH_ALEN);
907 mpath_set_pinfo(mpath, next_hop, pinfo);
908 rcu_read_unlock();
636 return 0; 909 return 0;
637} 910}
911#endif
638 912
639struct cfg80211_ops mac80211_config_ops = { 913struct cfg80211_ops mac80211_config_ops = {
640 .add_virtual_intf = ieee80211_add_iface, 914 .add_virtual_intf = ieee80211_add_iface,
@@ -651,4 +925,12 @@ struct cfg80211_ops mac80211_config_ops = {
651 .del_station = ieee80211_del_station, 925 .del_station = ieee80211_del_station,
652 .change_station = ieee80211_change_station, 926 .change_station = ieee80211_change_station,
653 .get_station = ieee80211_get_station, 927 .get_station = ieee80211_get_station,
928 .dump_station = ieee80211_dump_station,
929#ifdef CONFIG_MAC80211_MESH
930 .add_mpath = ieee80211_add_mpath,
931 .del_mpath = ieee80211_del_mpath,
932 .change_mpath = ieee80211_change_mpath,
933 .get_mpath = ieee80211_get_mpath,
934 .dump_mpath = ieee80211_dump_mpath,
935#endif
654}; 936};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 60514b2c97b9..4736c64937b4 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -19,41 +19,6 @@ int mac80211_open_file_generic(struct inode *inode, struct file *file)
19 return 0; 19 return 0;
20} 20}
21 21
22static const char *ieee80211_mode_str(int mode)
23{
24 switch (mode) {
25 case MODE_IEEE80211A:
26 return "IEEE 802.11a";
27 case MODE_IEEE80211B:
28 return "IEEE 802.11b";
29 case MODE_IEEE80211G:
30 return "IEEE 802.11g";
31 default:
32 return "UNKNOWN";
33 }
34}
35
36static ssize_t modes_read(struct file *file, char __user *userbuf,
37 size_t count, loff_t *ppos)
38{
39 struct ieee80211_local *local = file->private_data;
40 struct ieee80211_hw_mode *mode;
41 char buf[150], *p = buf;
42
43 /* FIXME: locking! */
44 list_for_each_entry(mode, &local->modes_list, list) {
45 p += scnprintf(p, sizeof(buf)+buf-p,
46 "%s\n", ieee80211_mode_str(mode->mode));
47 }
48
49 return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
50}
51
52static const struct file_operations modes_ops = {
53 .read = modes_read,
54 .open = mac80211_open_file_generic,
55};
56
57#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \ 22#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
58static ssize_t name## _read(struct file *file, char __user *userbuf, \ 23static ssize_t name## _read(struct file *file, char __user *userbuf, \
59 size_t count, loff_t *ppos) \ 24 size_t count, loff_t *ppos) \
@@ -80,10 +45,8 @@ static const struct file_operations name## _ops = { \
80 local->debugfs.name = NULL; 45 local->debugfs.name = NULL;
81 46
82 47
83DEBUGFS_READONLY_FILE(channel, 20, "%d",
84 local->hw.conf.channel);
85DEBUGFS_READONLY_FILE(frequency, 20, "%d", 48DEBUGFS_READONLY_FILE(frequency, 20, "%d",
86 local->hw.conf.freq); 49 local->hw.conf.channel->center_freq);
87DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d", 50DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
88 local->hw.conf.antenna_sel_tx); 51 local->hw.conf.antenna_sel_tx);
89DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d", 52DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
@@ -100,8 +63,6 @@ DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
100 local->long_retry_limit); 63 local->long_retry_limit);
101DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 64DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
102 local->total_ps_buffered); 65 local->total_ps_buffered);
103DEBUGFS_READONLY_FILE(mode, 20, "%s",
104 ieee80211_mode_str(local->hw.conf.phymode));
105DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x", 66DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
106 local->wep_iv & 0xffffff); 67 local->wep_iv & 0xffffff);
107DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s", 68DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
@@ -294,7 +255,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
294 local->debugfs.stations = debugfs_create_dir("stations", phyd); 255 local->debugfs.stations = debugfs_create_dir("stations", phyd);
295 local->debugfs.keys = debugfs_create_dir("keys", phyd); 256 local->debugfs.keys = debugfs_create_dir("keys", phyd);
296 257
297 DEBUGFS_ADD(channel);
298 DEBUGFS_ADD(frequency); 258 DEBUGFS_ADD(frequency);
299 DEBUGFS_ADD(antenna_sel_tx); 259 DEBUGFS_ADD(antenna_sel_tx);
300 DEBUGFS_ADD(antenna_sel_rx); 260 DEBUGFS_ADD(antenna_sel_rx);
@@ -304,9 +264,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
304 DEBUGFS_ADD(short_retry_limit); 264 DEBUGFS_ADD(short_retry_limit);
305 DEBUGFS_ADD(long_retry_limit); 265 DEBUGFS_ADD(long_retry_limit);
306 DEBUGFS_ADD(total_ps_buffered); 266 DEBUGFS_ADD(total_ps_buffered);
307 DEBUGFS_ADD(mode);
308 DEBUGFS_ADD(wep_iv); 267 DEBUGFS_ADD(wep_iv);
309 DEBUGFS_ADD(modes);
310 268
311 statsd = debugfs_create_dir("statistics", phyd); 269 statsd = debugfs_create_dir("statistics", phyd);
312 local->debugfs.statistics = statsd; 270 local->debugfs.statistics = statsd;
@@ -356,7 +314,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
356 314
357void debugfs_hw_del(struct ieee80211_local *local) 315void debugfs_hw_del(struct ieee80211_local *local)
358{ 316{
359 DEBUGFS_DEL(channel);
360 DEBUGFS_DEL(frequency); 317 DEBUGFS_DEL(frequency);
361 DEBUGFS_DEL(antenna_sel_tx); 318 DEBUGFS_DEL(antenna_sel_tx);
362 DEBUGFS_DEL(antenna_sel_rx); 319 DEBUGFS_DEL(antenna_sel_rx);
@@ -366,9 +323,7 @@ void debugfs_hw_del(struct ieee80211_local *local)
366 DEBUGFS_DEL(short_retry_limit); 323 DEBUGFS_DEL(short_retry_limit);
367 DEBUGFS_DEL(long_retry_limit); 324 DEBUGFS_DEL(long_retry_limit);
368 DEBUGFS_DEL(total_ps_buffered); 325 DEBUGFS_DEL(total_ps_buffered);
369 DEBUGFS_DEL(mode);
370 DEBUGFS_DEL(wep_iv); 326 DEBUGFS_DEL(wep_iv);
371 DEBUGFS_DEL(modes);
372 327
373 DEBUGFS_STATS_DEL(transmitted_fragment_count); 328 DEBUGFS_STATS_DEL(transmitted_fragment_count);
374 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count); 329 DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 829872a3ae81..107b0fe778d6 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -39,6 +39,29 @@ static ssize_t ieee80211_if_read(
39 return ret; 39 return ret;
40} 40}
41 41
42#ifdef CONFIG_MAC80211_MESH
43static ssize_t ieee80211_if_write(
44 struct ieee80211_sub_if_data *sdata,
45 char const __user *userbuf,
46 size_t count, loff_t *ppos,
47 int (*format)(struct ieee80211_sub_if_data *, char *))
48{
49 char buf[10];
50 int buf_size;
51
52 memset(buf, 0x00, sizeof(buf));
53 buf_size = min(count, (sizeof(buf)-1));
54 read_lock(&dev_base_lock);
55 if (copy_from_user(buf, userbuf, buf_size))
56 goto endwrite;
57 if (sdata->dev->reg_state == NETREG_REGISTERED)
58 (*format)(sdata, buf);
59endwrite:
60 read_unlock(&dev_base_lock);
61 return count;
62}
63#endif
64
42#define IEEE80211_IF_FMT(name, field, format_string) \ 65#define IEEE80211_IF_FMT(name, field, format_string) \
43static ssize_t ieee80211_if_fmt_##name( \ 66static ssize_t ieee80211_if_fmt_##name( \
44 const struct ieee80211_sub_if_data *sdata, char *buf, \ 67 const struct ieee80211_sub_if_data *sdata, char *buf, \
@@ -46,6 +69,19 @@ static ssize_t ieee80211_if_fmt_##name( \
46{ \ 69{ \
47 return scnprintf(buf, buflen, format_string, sdata->field); \ 70 return scnprintf(buf, buflen, format_string, sdata->field); \
48} 71}
72#define IEEE80211_IF_WFMT(name, field, type) \
73static int ieee80211_if_wfmt_##name( \
74 struct ieee80211_sub_if_data *sdata, char *buf) \
75{ \
76 unsigned long tmp; \
77 char *endp; \
78 \
79 tmp = simple_strtoul(buf, &endp, 0); \
80 if ((endp == buf) || ((type)tmp != tmp)) \
81 return -EINVAL; \
82 sdata->field = tmp; \
83 return 0; \
84}
49#define IEEE80211_IF_FMT_DEC(name, field) \ 85#define IEEE80211_IF_FMT_DEC(name, field) \
50 IEEE80211_IF_FMT(name, field, "%d\n") 86 IEEE80211_IF_FMT(name, field, "%d\n")
51#define IEEE80211_IF_FMT_HEX(name, field) \ 87#define IEEE80211_IF_FMT_HEX(name, field) \
@@ -88,10 +124,37 @@ static const struct file_operations name##_ops = { \
88 IEEE80211_IF_FMT_##format(name, field) \ 124 IEEE80211_IF_FMT_##format(name, field) \
89 __IEEE80211_IF_FILE(name) 125 __IEEE80211_IF_FILE(name)
90 126
127#define __IEEE80211_IF_WFILE(name) \
128static ssize_t ieee80211_if_read_##name(struct file *file, \
129 char __user *userbuf, \
130 size_t count, loff_t *ppos) \
131{ \
132 return ieee80211_if_read(file->private_data, \
133 userbuf, count, ppos, \
134 ieee80211_if_fmt_##name); \
135} \
136static ssize_t ieee80211_if_write_##name(struct file *file, \
137 const char __user *userbuf, \
138 size_t count, loff_t *ppos) \
139{ \
140 return ieee80211_if_write(file->private_data, \
141 userbuf, count, ppos, \
142 ieee80211_if_wfmt_##name); \
143} \
144static const struct file_operations name##_ops = { \
145 .read = ieee80211_if_read_##name, \
146 .write = ieee80211_if_write_##name, \
147 .open = mac80211_open_file_generic, \
148}
149
150#define IEEE80211_IF_WFILE(name, field, format, type) \
151 IEEE80211_IF_FMT_##format(name, field) \
152 IEEE80211_IF_WFMT(name, field, type) \
153 __IEEE80211_IF_WFILE(name)
154
91/* common attributes */ 155/* common attributes */
92IEEE80211_IF_FILE(channel_use, channel_use, DEC); 156IEEE80211_IF_FILE(channel_use, channel_use, DEC);
93IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC); 157IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
94IEEE80211_IF_FILE(ieee802_1x_pac, ieee802_1x_pac, DEC);
95 158
96/* STA/IBSS attributes */ 159/* STA/IBSS attributes */
97IEEE80211_IF_FILE(state, u.sta.state, DEC); 160IEEE80211_IF_FILE(state, u.sta.state, DEC);
@@ -107,6 +170,7 @@ IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
107IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX); 170IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
108IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC); 171IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
109IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC); 172IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
173IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
110 174
111static ssize_t ieee80211_if_fmt_flags( 175static ssize_t ieee80211_if_fmt_flags(
112 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) 176 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
@@ -140,6 +204,42 @@ __IEEE80211_IF_FILE(num_buffered_multicast);
140/* WDS attributes */ 204/* WDS attributes */
141IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC); 205IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
142 206
207#ifdef CONFIG_MAC80211_MESH
208/* Mesh stats attributes */
209IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
210IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
211IEEE80211_IF_FILE(dropped_frames_no_route,
212 u.sta.mshstats.dropped_frames_no_route, DEC);
213IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);
214
215/* Mesh parameters */
216IEEE80211_IF_WFILE(dot11MeshMaxRetries,
217 u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
218IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
219 u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
220IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
221 u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
222IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
223 u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
224IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
225IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, bool);
226IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
227 u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
228IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
229 u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
230IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
231 u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
232IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
233 u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
234IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
235 u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
236IEEE80211_IF_WFILE(path_refresh_time,
237 u.sta.mshcfg.path_refresh_time, DEC, u32);
238IEEE80211_IF_WFILE(min_discovery_timeout,
239 u.sta.mshcfg.min_discovery_timeout, DEC, u16);
240#endif
241
242
143#define DEBUGFS_ADD(name, type)\ 243#define DEBUGFS_ADD(name, type)\
144 sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\ 244 sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
145 sdata->debugfsdir, sdata, &name##_ops); 245 sdata->debugfsdir, sdata, &name##_ops);
@@ -148,7 +248,6 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
148{ 248{
149 DEBUGFS_ADD(channel_use, sta); 249 DEBUGFS_ADD(channel_use, sta);
150 DEBUGFS_ADD(drop_unencrypted, sta); 250 DEBUGFS_ADD(drop_unencrypted, sta);
151 DEBUGFS_ADD(ieee802_1x_pac, sta);
152 DEBUGFS_ADD(state, sta); 251 DEBUGFS_ADD(state, sta);
153 DEBUGFS_ADD(bssid, sta); 252 DEBUGFS_ADD(bssid, sta);
154 DEBUGFS_ADD(prev_bssid, sta); 253 DEBUGFS_ADD(prev_bssid, sta);
@@ -163,13 +262,13 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
163 DEBUGFS_ADD(auth_alg, sta); 262 DEBUGFS_ADD(auth_alg, sta);
164 DEBUGFS_ADD(auth_transaction, sta); 263 DEBUGFS_ADD(auth_transaction, sta);
165 DEBUGFS_ADD(flags, sta); 264 DEBUGFS_ADD(flags, sta);
265 DEBUGFS_ADD(num_beacons_sta, sta);
166} 266}
167 267
168static void add_ap_files(struct ieee80211_sub_if_data *sdata) 268static void add_ap_files(struct ieee80211_sub_if_data *sdata)
169{ 269{
170 DEBUGFS_ADD(channel_use, ap); 270 DEBUGFS_ADD(channel_use, ap);
171 DEBUGFS_ADD(drop_unencrypted, ap); 271 DEBUGFS_ADD(drop_unencrypted, ap);
172 DEBUGFS_ADD(ieee802_1x_pac, ap);
173 DEBUGFS_ADD(num_sta_ps, ap); 272 DEBUGFS_ADD(num_sta_ps, ap);
174 DEBUGFS_ADD(dtim_count, ap); 273 DEBUGFS_ADD(dtim_count, ap);
175 DEBUGFS_ADD(num_beacons, ap); 274 DEBUGFS_ADD(num_beacons, ap);
@@ -182,7 +281,6 @@ static void add_wds_files(struct ieee80211_sub_if_data *sdata)
182{ 281{
183 DEBUGFS_ADD(channel_use, wds); 282 DEBUGFS_ADD(channel_use, wds);
184 DEBUGFS_ADD(drop_unencrypted, wds); 283 DEBUGFS_ADD(drop_unencrypted, wds);
185 DEBUGFS_ADD(ieee802_1x_pac, wds);
186 DEBUGFS_ADD(peer, wds); 284 DEBUGFS_ADD(peer, wds);
187} 285}
188 286
@@ -190,19 +288,63 @@ static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
190{ 288{
191 DEBUGFS_ADD(channel_use, vlan); 289 DEBUGFS_ADD(channel_use, vlan);
192 DEBUGFS_ADD(drop_unencrypted, vlan); 290 DEBUGFS_ADD(drop_unencrypted, vlan);
193 DEBUGFS_ADD(ieee802_1x_pac, vlan);
194} 291}
195 292
196static void add_monitor_files(struct ieee80211_sub_if_data *sdata) 293static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
197{ 294{
198} 295}
199 296
297#ifdef CONFIG_MAC80211_MESH
298#define MESHSTATS_ADD(name)\
299 sdata->mesh_stats.name = debugfs_create_file(#name, 0444,\
300 sdata->mesh_stats_dir, sdata, &name##_ops);
301
302static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
303{
304 sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
305 sdata->debugfsdir);
306 MESHSTATS_ADD(fwded_frames);
307 MESHSTATS_ADD(dropped_frames_ttl);
308 MESHSTATS_ADD(dropped_frames_no_route);
309 MESHSTATS_ADD(estab_plinks);
310}
311
312#define MESHPARAMS_ADD(name)\
313 sdata->mesh_config.name = debugfs_create_file(#name, 0644,\
314 sdata->mesh_config_dir, sdata, &name##_ops);
315
316static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
317{
318 sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
319 sdata->debugfsdir);
320 MESHPARAMS_ADD(dot11MeshMaxRetries);
321 MESHPARAMS_ADD(dot11MeshRetryTimeout);
322 MESHPARAMS_ADD(dot11MeshConfirmTimeout);
323 MESHPARAMS_ADD(dot11MeshHoldingTimeout);
324 MESHPARAMS_ADD(dot11MeshTTL);
325 MESHPARAMS_ADD(auto_open_plinks);
326 MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
327 MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
328 MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
329 MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
330 MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
331 MESHPARAMS_ADD(path_refresh_time);
332 MESHPARAMS_ADD(min_discovery_timeout);
333}
334#endif
335
200static void add_files(struct ieee80211_sub_if_data *sdata) 336static void add_files(struct ieee80211_sub_if_data *sdata)
201{ 337{
202 if (!sdata->debugfsdir) 338 if (!sdata->debugfsdir)
203 return; 339 return;
204 340
205 switch (sdata->vif.type) { 341 switch (sdata->vif.type) {
342 case IEEE80211_IF_TYPE_MESH_POINT:
343#ifdef CONFIG_MAC80211_MESH
344 add_mesh_stats(sdata);
345 add_mesh_config(sdata);
346#endif
347 /* fall through */
206 case IEEE80211_IF_TYPE_STA: 348 case IEEE80211_IF_TYPE_STA:
207 case IEEE80211_IF_TYPE_IBSS: 349 case IEEE80211_IF_TYPE_IBSS:
208 add_sta_files(sdata); 350 add_sta_files(sdata);
@@ -234,7 +376,6 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
234{ 376{
235 DEBUGFS_DEL(channel_use, sta); 377 DEBUGFS_DEL(channel_use, sta);
236 DEBUGFS_DEL(drop_unencrypted, sta); 378 DEBUGFS_DEL(drop_unencrypted, sta);
237 DEBUGFS_DEL(ieee802_1x_pac, sta);
238 DEBUGFS_DEL(state, sta); 379 DEBUGFS_DEL(state, sta);
239 DEBUGFS_DEL(bssid, sta); 380 DEBUGFS_DEL(bssid, sta);
240 DEBUGFS_DEL(prev_bssid, sta); 381 DEBUGFS_DEL(prev_bssid, sta);
@@ -249,13 +390,13 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
249 DEBUGFS_DEL(auth_alg, sta); 390 DEBUGFS_DEL(auth_alg, sta);
250 DEBUGFS_DEL(auth_transaction, sta); 391 DEBUGFS_DEL(auth_transaction, sta);
251 DEBUGFS_DEL(flags, sta); 392 DEBUGFS_DEL(flags, sta);
393 DEBUGFS_DEL(num_beacons_sta, sta);
252} 394}
253 395
254static void del_ap_files(struct ieee80211_sub_if_data *sdata) 396static void del_ap_files(struct ieee80211_sub_if_data *sdata)
255{ 397{
256 DEBUGFS_DEL(channel_use, ap); 398 DEBUGFS_DEL(channel_use, ap);
257 DEBUGFS_DEL(drop_unencrypted, ap); 399 DEBUGFS_DEL(drop_unencrypted, ap);
258 DEBUGFS_DEL(ieee802_1x_pac, ap);
259 DEBUGFS_DEL(num_sta_ps, ap); 400 DEBUGFS_DEL(num_sta_ps, ap);
260 DEBUGFS_DEL(dtim_count, ap); 401 DEBUGFS_DEL(dtim_count, ap);
261 DEBUGFS_DEL(num_beacons, ap); 402 DEBUGFS_DEL(num_beacons, ap);
@@ -268,7 +409,6 @@ static void del_wds_files(struct ieee80211_sub_if_data *sdata)
268{ 409{
269 DEBUGFS_DEL(channel_use, wds); 410 DEBUGFS_DEL(channel_use, wds);
270 DEBUGFS_DEL(drop_unencrypted, wds); 411 DEBUGFS_DEL(drop_unencrypted, wds);
271 DEBUGFS_DEL(ieee802_1x_pac, wds);
272 DEBUGFS_DEL(peer, wds); 412 DEBUGFS_DEL(peer, wds);
273} 413}
274 414
@@ -276,19 +416,67 @@ static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
276{ 416{
277 DEBUGFS_DEL(channel_use, vlan); 417 DEBUGFS_DEL(channel_use, vlan);
278 DEBUGFS_DEL(drop_unencrypted, vlan); 418 DEBUGFS_DEL(drop_unencrypted, vlan);
279 DEBUGFS_DEL(ieee802_1x_pac, vlan);
280} 419}
281 420
282static void del_monitor_files(struct ieee80211_sub_if_data *sdata) 421static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
283{ 422{
284} 423}
285 424
425#ifdef CONFIG_MAC80211_MESH
426#define MESHSTATS_DEL(name) \
427 do { \
428 debugfs_remove(sdata->mesh_stats.name); \
429 sdata->mesh_stats.name = NULL; \
430 } while (0)
431
432static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
433{
434 MESHSTATS_DEL(fwded_frames);
435 MESHSTATS_DEL(dropped_frames_ttl);
436 MESHSTATS_DEL(dropped_frames_no_route);
437 MESHSTATS_DEL(estab_plinks);
438 debugfs_remove(sdata->mesh_stats_dir);
439 sdata->mesh_stats_dir = NULL;
440}
441
442#define MESHPARAMS_DEL(name) \
443 do { \
444 debugfs_remove(sdata->mesh_config.name); \
445 sdata->mesh_config.name = NULL; \
446 } while (0)
447
448static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
449{
450 MESHPARAMS_DEL(dot11MeshMaxRetries);
451 MESHPARAMS_DEL(dot11MeshRetryTimeout);
452 MESHPARAMS_DEL(dot11MeshConfirmTimeout);
453 MESHPARAMS_DEL(dot11MeshHoldingTimeout);
454 MESHPARAMS_DEL(dot11MeshTTL);
455 MESHPARAMS_DEL(auto_open_plinks);
456 MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
457 MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
458 MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
459 MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
460 MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
461 MESHPARAMS_DEL(path_refresh_time);
462 MESHPARAMS_DEL(min_discovery_timeout);
463 debugfs_remove(sdata->mesh_config_dir);
464 sdata->mesh_config_dir = NULL;
465}
466#endif
467
286static void del_files(struct ieee80211_sub_if_data *sdata, int type) 468static void del_files(struct ieee80211_sub_if_data *sdata, int type)
287{ 469{
288 if (!sdata->debugfsdir) 470 if (!sdata->debugfsdir)
289 return; 471 return;
290 472
291 switch (type) { 473 switch (type) {
474 case IEEE80211_IF_TYPE_MESH_POINT:
475#ifdef CONFIG_MAC80211_MESH
476 del_mesh_stats(sdata);
477 del_mesh_config(sdata);
478#endif
479 /* fall through */
292 case IEEE80211_IF_TYPE_STA: 480 case IEEE80211_IF_TYPE_STA:
293 case IEEE80211_IF_TYPE_IBSS: 481 case IEEE80211_IF_TYPE_IBSS:
294 del_sta_files(sdata); 482 del_sta_files(sdata);
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 8f5944c53d4e..fc2c1a192ed2 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -33,25 +33,16 @@ static ssize_t sta_ ##name## _read(struct file *file, \
33#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n") 33#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
34#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n") 34#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
35 35
36#define STA_READ_RATE(name, field) \ 36#define STA_OPS(name) \
37static ssize_t sta_##name##_read(struct file *file, \ 37static const struct file_operations sta_ ##name## _ops = { \
38 char __user *userbuf, \ 38 .read = sta_##name##_read, \
39 size_t count, loff_t *ppos) \ 39 .open = mac80211_open_file_generic, \
40{ \
41 struct sta_info *sta = file->private_data; \
42 struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
43 struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
44 char buf[20]; \
45 int res = scnprintf(buf, sizeof(buf), "%d\n", \
46 (sta->field >= 0 && \
47 sta->field < mode->num_rates) ? \
48 mode->rates[sta->field].rate : -1); \
49 return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
50} 40}
51 41
52#define STA_OPS(name) \ 42#define STA_OPS_WR(name) \
53static const struct file_operations sta_ ##name## _ops = { \ 43static const struct file_operations sta_ ##name## _ops = { \
54 .read = sta_##name##_read, \ 44 .read = sta_##name##_read, \
45 .write = sta_##name##_write, \
55 .open = mac80211_open_file_generic, \ 46 .open = mac80211_open_file_generic, \
56} 47}
57 48
@@ -60,7 +51,7 @@ static const struct file_operations sta_ ##name## _ops = { \
60 STA_OPS(name) 51 STA_OPS(name)
61 52
62STA_FILE(aid, aid, D); 53STA_FILE(aid, aid, D);
63STA_FILE(dev, dev->name, S); 54STA_FILE(dev, sdata->dev->name, S);
64STA_FILE(rx_packets, rx_packets, LU); 55STA_FILE(rx_packets, rx_packets, LU);
65STA_FILE(tx_packets, tx_packets, LU); 56STA_FILE(tx_packets, tx_packets, LU);
66STA_FILE(rx_bytes, rx_bytes, LU); 57STA_FILE(rx_bytes, rx_bytes, LU);
@@ -70,27 +61,23 @@ STA_FILE(rx_fragments, rx_fragments, LU);
70STA_FILE(rx_dropped, rx_dropped, LU); 61STA_FILE(rx_dropped, rx_dropped, LU);
71STA_FILE(tx_fragments, tx_fragments, LU); 62STA_FILE(tx_fragments, tx_fragments, LU);
72STA_FILE(tx_filtered, tx_filtered_count, LU); 63STA_FILE(tx_filtered, tx_filtered_count, LU);
73STA_FILE(txrate, txrate, RATE);
74STA_FILE(last_txrate, last_txrate, RATE);
75STA_FILE(tx_retry_failed, tx_retry_failed, LU); 64STA_FILE(tx_retry_failed, tx_retry_failed, LU);
76STA_FILE(tx_retry_count, tx_retry_count, LU); 65STA_FILE(tx_retry_count, tx_retry_count, LU);
77STA_FILE(last_rssi, last_rssi, D); 66STA_FILE(last_rssi, last_rssi, D);
78STA_FILE(last_signal, last_signal, D); 67STA_FILE(last_signal, last_signal, D);
79STA_FILE(last_noise, last_noise, D); 68STA_FILE(last_noise, last_noise, D);
80STA_FILE(channel_use, channel_use, D); 69STA_FILE(channel_use, channel_use, D);
81STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D); 70STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
82 71
83static ssize_t sta_flags_read(struct file *file, char __user *userbuf, 72static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
84 size_t count, loff_t *ppos) 73 size_t count, loff_t *ppos)
85{ 74{
86 char buf[100]; 75 char buf[100];
87 struct sta_info *sta = file->private_data; 76 struct sta_info *sta = file->private_data;
88 int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s", 77 int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
89 sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "", 78 sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
90 sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "", 79 sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
91 sta->flags & WLAN_STA_PS ? "PS\n" : "", 80 sta->flags & WLAN_STA_PS ? "PS\n" : "",
92 sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
93 sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
94 sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "", 81 sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
95 sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "", 82 sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
96 sta->flags & WLAN_STA_WME ? "WME\n" : "", 83 sta->flags & WLAN_STA_WME ? "WME\n" : "",
@@ -111,31 +98,6 @@ static ssize_t sta_num_ps_buf_frames_read(struct file *file,
111} 98}
112STA_OPS(num_ps_buf_frames); 99STA_OPS(num_ps_buf_frames);
113 100
114static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
115 size_t count, loff_t *ppos)
116{
117 char buf[100];
118 struct sta_info *sta = file->private_data;
119 int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
120 sta->last_ack_rssi[0],
121 sta->last_ack_rssi[1],
122 sta->last_ack_rssi[2]);
123 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
124}
125STA_OPS(last_ack_rssi);
126
127static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
128 size_t count, loff_t *ppos)
129{
130 char buf[20];
131 struct sta_info *sta = file->private_data;
132 int res = scnprintf(buf, sizeof(buf), "%d\n",
133 sta->last_ack ?
134 jiffies_to_msecs(jiffies - sta->last_ack) : -1);
135 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
136}
137STA_OPS(last_ack_ms);
138
139static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf, 101static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
140 size_t count, loff_t *ppos) 102 size_t count, loff_t *ppos)
141{ 103{
@@ -191,6 +153,113 @@ static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
191STA_OPS(wme_tx_queue); 153STA_OPS(wme_tx_queue);
192#endif 154#endif
193 155
156static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
157 size_t count, loff_t *ppos)
158{
159 char buf[768], *p = buf;
160 int i;
161 struct sta_info *sta = file->private_data;
162 p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
163 p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
164 "TIDs info is: \n TID :",
165 (sta->ampdu_mlme.dialog_token_allocator + 1));
166 for (i = 0; i < STA_TID_NUM; i++)
167 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
168
169 p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
170 for (i = 0; i < STA_TID_NUM; i++)
171 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
172 sta->ampdu_mlme.tid_rx[i].state);
173
174 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
175 for (i = 0; i < STA_TID_NUM; i++)
176 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
177 sta->ampdu_mlme.tid_rx[i].dialog_token);
178
179 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
180 for (i = 0; i < STA_TID_NUM; i++)
181 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
182 sta->ampdu_mlme.tid_tx[i].state);
183
184 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
185 for (i = 0; i < STA_TID_NUM; i++)
186 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
187 sta->ampdu_mlme.tid_tx[i].dialog_token);
188
189 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
190 for (i = 0; i < STA_TID_NUM; i++)
191 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
192 sta->ampdu_mlme.tid_tx[i].ssn);
193
194 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
195
196 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
197}
198
199static ssize_t sta_agg_status_write(struct file *file,
200 const char __user *user_buf, size_t count, loff_t *ppos)
201{
202 struct sta_info *sta = file->private_data;
203 struct net_device *dev = sta->sdata->dev;
204 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
205 struct ieee80211_hw *hw = &local->hw;
206 u8 *da = sta->addr;
207 static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
208 0, 0, 0, 0, 0, 0, 0, 0};
209 static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
210 1, 1, 1, 1, 1, 1, 1, 1};
211 char *endp;
212 char buf[32];
213 int buf_size, rs;
214 unsigned int tid_num;
215 char state[4];
216
217 memset(buf, 0x00, sizeof(buf));
218 buf_size = min(count, (sizeof(buf)-1));
219 if (copy_from_user(buf, user_buf, buf_size))
220 return -EFAULT;
221
222 tid_num = simple_strtoul(buf, &endp, 0);
223 if (endp == buf)
224 return -EINVAL;
225
226 if ((tid_num >= 100) && (tid_num <= 115)) {
227 /* toggle Rx aggregation command */
228 tid_num = tid_num - 100;
229 if (tid_static_rx[tid_num] == 1) {
230 strcpy(state, "off ");
231 ieee80211_sta_stop_rx_ba_session(dev, da, tid_num, 0,
232 WLAN_REASON_QSTA_REQUIRE_SETUP);
233 sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0xFF;
234 tid_static_rx[tid_num] = 0;
235 } else {
236 strcpy(state, "on ");
237 sta->ampdu_mlme.tid_rx[tid_num].buf_size = 0x00;
238 tid_static_rx[tid_num] = 1;
239 }
240 printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
241 tid_num, state);
242 } else if ((tid_num >= 0) && (tid_num <= 15)) {
243 /* toggle Tx aggregation command */
244 if (tid_static_tx[tid_num] == 0) {
245 strcpy(state, "on ");
246 rs = ieee80211_start_tx_ba_session(hw, da, tid_num);
247 if (rs == 0)
248 tid_static_tx[tid_num] = 1;
249 } else {
250 strcpy(state, "off");
251 rs = ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
252 if (rs == 0)
253 tid_static_tx[tid_num] = 0;
254 }
255 printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
256 tid_num, state, rs);
257 }
258
259 return count;
260}
261STA_OPS_WR(agg_status);
262
194#define DEBUGFS_ADD(name) \ 263#define DEBUGFS_ADD(name) \
195 sta->debugfs.name = debugfs_create_file(#name, 0444, \ 264 sta->debugfs.name = debugfs_create_file(#name, 0444, \
196 sta->debugfs.dir, sta, &sta_ ##name## _ops); 265 sta->debugfs.dir, sta, &sta_ ##name## _ops);
@@ -203,12 +272,13 @@ STA_OPS(wme_tx_queue);
203void ieee80211_sta_debugfs_add(struct sta_info *sta) 272void ieee80211_sta_debugfs_add(struct sta_info *sta)
204{ 273{
205 struct dentry *stations_dir = sta->local->debugfs.stations; 274 struct dentry *stations_dir = sta->local->debugfs.stations;
206 DECLARE_MAC_BUF(mac); 275 DECLARE_MAC_BUF(mbuf);
276 u8 *mac;
207 277
208 if (!stations_dir) 278 if (!stations_dir)
209 return; 279 return;
210 280
211 print_mac(mac, sta->addr); 281 mac = print_mac(mbuf, sta->addr);
212 282
213 sta->debugfs.dir = debugfs_create_dir(mac, stations_dir); 283 sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
214 if (!sta->debugfs.dir) 284 if (!sta->debugfs.dir)
@@ -216,28 +286,26 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
216 286
217 DEBUGFS_ADD(flags); 287 DEBUGFS_ADD(flags);
218 DEBUGFS_ADD(num_ps_buf_frames); 288 DEBUGFS_ADD(num_ps_buf_frames);
219 DEBUGFS_ADD(last_ack_rssi);
220 DEBUGFS_ADD(last_ack_ms);
221 DEBUGFS_ADD(inactive_ms); 289 DEBUGFS_ADD(inactive_ms);
222 DEBUGFS_ADD(last_seq_ctrl); 290 DEBUGFS_ADD(last_seq_ctrl);
223#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 291#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
224 DEBUGFS_ADD(wme_rx_queue); 292 DEBUGFS_ADD(wme_rx_queue);
225 DEBUGFS_ADD(wme_tx_queue); 293 DEBUGFS_ADD(wme_tx_queue);
226#endif 294#endif
295 DEBUGFS_ADD(agg_status);
227} 296}
228 297
229void ieee80211_sta_debugfs_remove(struct sta_info *sta) 298void ieee80211_sta_debugfs_remove(struct sta_info *sta)
230{ 299{
231 DEBUGFS_DEL(flags); 300 DEBUGFS_DEL(flags);
232 DEBUGFS_DEL(num_ps_buf_frames); 301 DEBUGFS_DEL(num_ps_buf_frames);
233 DEBUGFS_DEL(last_ack_rssi);
234 DEBUGFS_DEL(last_ack_ms);
235 DEBUGFS_DEL(inactive_ms); 302 DEBUGFS_DEL(inactive_ms);
236 DEBUGFS_DEL(last_seq_ctrl); 303 DEBUGFS_DEL(last_seq_ctrl);
237#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 304#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
238 DEBUGFS_DEL(wme_rx_queue); 305 DEBUGFS_DEL(wme_rx_queue);
239 DEBUGFS_DEL(wme_tx_queue); 306 DEBUGFS_DEL(wme_tx_queue);
240#endif 307#endif
308 DEBUGFS_DEL(agg_status);
241 309
242 debugfs_remove(sta->debugfs.dir); 310 debugfs_remove(sta->debugfs.dir);
243 sta->debugfs.dir = NULL; 311 sta->debugfs.dir = NULL;
diff --git a/net/mac80211/debugfs_sta.h b/net/mac80211/debugfs_sta.h
index 574a1cd54b96..8b608903259f 100644
--- a/net/mac80211/debugfs_sta.h
+++ b/net/mac80211/debugfs_sta.h
@@ -1,6 +1,8 @@
1#ifndef __MAC80211_DEBUGFS_STA_H 1#ifndef __MAC80211_DEBUGFS_STA_H
2#define __MAC80211_DEBUGFS_STA_H 2#define __MAC80211_DEBUGFS_STA_H
3 3
4#include "sta_info.h"
5
4#ifdef CONFIG_MAC80211_DEBUGFS 6#ifdef CONFIG_MAC80211_DEBUGFS
5void ieee80211_sta_debugfs_add(struct sta_info *sta); 7void ieee80211_sta_debugfs_add(struct sta_info *sta);
6void ieee80211_sta_debugfs_remove(struct sta_info *sta); 8void ieee80211_sta_debugfs_remove(struct sta_info *sta);
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c
index 28bcdf9fc3df..55b63712e48c 100644
--- a/net/mac80211/ieee80211.c
+++ b/net/mac80211/ieee80211.c
@@ -26,6 +26,7 @@
26 26
27#include "ieee80211_i.h" 27#include "ieee80211_i.h"
28#include "ieee80211_rate.h" 28#include "ieee80211_rate.h"
29#include "mesh.h"
29#include "wep.h" 30#include "wep.h"
30#include "wme.h" 31#include "wme.h"
31#include "aes_ccm.h" 32#include "aes_ccm.h"
@@ -67,9 +68,19 @@ static void ieee80211_configure_filter(struct ieee80211_local *local)
67 new_flags |= FIF_ALLMULTI; 68 new_flags |= FIF_ALLMULTI;
68 69
69 if (local->monitors) 70 if (local->monitors)
70 new_flags |= FIF_CONTROL | 71 new_flags |= FIF_BCN_PRBRESP_PROMISC;
71 FIF_OTHER_BSS | 72
72 FIF_BCN_PRBRESP_PROMISC; 73 if (local->fif_fcsfail)
74 new_flags |= FIF_FCSFAIL;
75
76 if (local->fif_plcpfail)
77 new_flags |= FIF_PLCPFAIL;
78
79 if (local->fif_control)
80 new_flags |= FIF_CONTROL;
81
82 if (local->fif_other_bss)
83 new_flags |= FIF_OTHER_BSS;
73 84
74 changed_flags = local->filter_flags ^ new_flags; 85 changed_flags = local->filter_flags ^ new_flags;
75 86
@@ -128,9 +139,15 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev)
128 139
129static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) 140static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
130{ 141{
142 int meshhdrlen;
143 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
144
145 meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
146
131 /* FIX: what would be proper limits for MTU? 147 /* FIX: what would be proper limits for MTU?
132 * This interface uses 802.3 frames. */ 148 * This interface uses 802.3 frames. */
133 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) { 149 if (new_mtu < 256 ||
150 new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
134 printk(KERN_WARNING "%s: invalid MTU %d\n", 151 printk(KERN_WARNING "%s: invalid MTU %d\n",
135 dev->name, new_mtu); 152 dev->name, new_mtu);
136 return -EINVAL; 153 return -EINVAL;
@@ -166,6 +183,7 @@ static int ieee80211_open(struct net_device *dev)
166 struct ieee80211_if_init_conf conf; 183 struct ieee80211_if_init_conf conf;
167 int res; 184 int res;
168 bool need_hw_reconfig = 0; 185 bool need_hw_reconfig = 0;
186 struct sta_info *sta;
169 187
170 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 188 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
171 189
@@ -173,8 +191,52 @@ static int ieee80211_open(struct net_device *dev)
173 list_for_each_entry(nsdata, &local->interfaces, list) { 191 list_for_each_entry(nsdata, &local->interfaces, list) {
174 struct net_device *ndev = nsdata->dev; 192 struct net_device *ndev = nsdata->dev;
175 193
176 if (ndev != dev && ndev != local->mdev && netif_running(ndev) && 194 if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
177 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) { 195 /*
196 * Allow only a single IBSS interface to be up at any
197 * time. This is restricted because beacon distribution
198 * cannot work properly if both are in the same IBSS.
199 *
200 * To remove this restriction we'd have to disallow them
201 * from setting the same SSID on different IBSS interfaces
202 * belonging to the same hardware. Then, however, we're
203 * faced with having to adopt two different TSF timers...
204 */
205 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
206 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
207 return -EBUSY;
208
209 /*
210 * Disallow multiple IBSS/STA mode interfaces.
211 *
212 * This is a technical restriction, it is possible although
213 * most likely not IEEE 802.11 compliant to have multiple
214 * STAs with just a single hardware (the TSF timer will not
215 * be adjusted properly.)
216 *
217 * However, because mac80211 uses the master device's BSS
218 * information for each STA/IBSS interface, doing this will
219 * currently corrupt that BSS information completely, unless,
220 * a not very useful case, both STAs are associated to the
221 * same BSS.
222 *
223 * To remove this restriction, the BSS information needs to
224 * be embedded in the STA/IBSS mode sdata instead of using
225 * the master device's BSS structure.
226 */
227 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
228 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
229 (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
230 nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
231 return -EBUSY;
232
233 /*
234 * The remaining checks are only performed for interfaces
235 * with the same MAC address.
236 */
237 if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
238 continue;
239
178 /* 240 /*
179 * check whether it may have the same address 241 * check whether it may have the same address
180 */ 242 */
@@ -186,8 +248,7 @@ static int ieee80211_open(struct net_device *dev)
186 * can only add VLANs to enabled APs 248 * can only add VLANs to enabled APs
187 */ 249 */
188 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN && 250 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
189 nsdata->vif.type == IEEE80211_IF_TYPE_AP && 251 nsdata->vif.type == IEEE80211_IF_TYPE_AP)
190 netif_running(nsdata->dev))
191 sdata->u.vlan.ap = nsdata; 252 sdata->u.vlan.ap = nsdata;
192 } 253 }
193 } 254 }
@@ -196,6 +257,20 @@ static int ieee80211_open(struct net_device *dev)
196 case IEEE80211_IF_TYPE_WDS: 257 case IEEE80211_IF_TYPE_WDS:
197 if (is_zero_ether_addr(sdata->u.wds.remote_addr)) 258 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
198 return -ENOLINK; 259 return -ENOLINK;
260
261 /* Create STA entry for the WDS peer */
262 sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
263 GFP_KERNEL);
264 if (!sta)
265 return -ENOMEM;
266
267 sta->flags |= WLAN_STA_AUTHORIZED;
268
269 res = sta_info_insert(sta);
270 if (res) {
271 sta_info_destroy(sta);
272 return res;
273 }
199 break; 274 break;
200 case IEEE80211_IF_TYPE_VLAN: 275 case IEEE80211_IF_TYPE_VLAN:
201 if (!sdata->u.vlan.ap) 276 if (!sdata->u.vlan.ap)
@@ -205,6 +280,7 @@ static int ieee80211_open(struct net_device *dev)
205 case IEEE80211_IF_TYPE_STA: 280 case IEEE80211_IF_TYPE_STA:
206 case IEEE80211_IF_TYPE_MNTR: 281 case IEEE80211_IF_TYPE_MNTR:
207 case IEEE80211_IF_TYPE_IBSS: 282 case IEEE80211_IF_TYPE_IBSS:
283 case IEEE80211_IF_TYPE_MESH_POINT:
208 /* no special treatment */ 284 /* no special treatment */
209 break; 285 break;
210 case IEEE80211_IF_TYPE_INVALID: 286 case IEEE80211_IF_TYPE_INVALID:
@@ -229,15 +305,28 @@ static int ieee80211_open(struct net_device *dev)
229 /* no need to tell driver */ 305 /* no need to tell driver */
230 break; 306 break;
231 case IEEE80211_IF_TYPE_MNTR: 307 case IEEE80211_IF_TYPE_MNTR:
308 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
309 local->cooked_mntrs++;
310 break;
311 }
312
232 /* must be before the call to ieee80211_configure_filter */ 313 /* must be before the call to ieee80211_configure_filter */
233 local->monitors++; 314 local->monitors++;
234 if (local->monitors == 1) { 315 if (local->monitors == 1)
235 netif_tx_lock_bh(local->mdev);
236 ieee80211_configure_filter(local);
237 netif_tx_unlock_bh(local->mdev);
238
239 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; 316 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
240 } 317
318 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
319 local->fif_fcsfail++;
320 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
321 local->fif_plcpfail++;
322 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
323 local->fif_control++;
324 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
325 local->fif_other_bss++;
326
327 netif_tx_lock_bh(local->mdev);
328 ieee80211_configure_filter(local);
329 netif_tx_unlock_bh(local->mdev);
241 break; 330 break;
242 case IEEE80211_IF_TYPE_STA: 331 case IEEE80211_IF_TYPE_STA:
243 case IEEE80211_IF_TYPE_IBSS: 332 case IEEE80211_IF_TYPE_IBSS:
@@ -293,24 +382,51 @@ static int ieee80211_open(struct net_device *dev)
293 382
294static int ieee80211_stop(struct net_device *dev) 383static int ieee80211_stop(struct net_device *dev)
295{ 384{
296 struct ieee80211_sub_if_data *sdata; 385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
297 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 386 struct ieee80211_local *local = sdata->local;
298 struct ieee80211_if_init_conf conf; 387 struct ieee80211_if_init_conf conf;
299 struct sta_info *sta; 388 struct sta_info *sta;
300 int i; 389 int i;
301 390
302 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 391 /*
392 * Stop TX on this interface first.
393 */
394 netif_stop_queue(dev);
395
396 /*
397 * Now delete all active aggregation sessions.
398 */
399 rcu_read_lock();
303 400
304 list_for_each_entry(sta, &local->sta_list, list) { 401 list_for_each_entry_rcu(sta, &local->sta_list, list) {
305 if (sta->dev == dev) 402 if (sta->sdata == sdata)
306 for (i = 0; i < STA_TID_NUM; i++) 403 for (i = 0; i < STA_TID_NUM; i++)
307 ieee80211_sta_stop_rx_ba_session(sta->dev, 404 ieee80211_sta_stop_rx_ba_session(sdata->dev,
308 sta->addr, i, 405 sta->addr, i,
309 WLAN_BACK_RECIPIENT, 406 WLAN_BACK_RECIPIENT,
310 WLAN_REASON_QSTA_LEAVE_QBSS); 407 WLAN_REASON_QSTA_LEAVE_QBSS);
311 } 408 }
312 409
313 netif_stop_queue(dev); 410 rcu_read_unlock();
411
412 /*
413 * Remove all stations associated with this interface.
414 *
415 * This must be done before calling ops->remove_interface()
416 * because otherwise we can later invoke ops->sta_notify()
417 * whenever the STAs are removed, and that invalidates driver
418 * assumptions about always getting a vif pointer that is valid
419 * (because if we remove a STA after ops->remove_interface()
420 * the driver will have removed the vif info already!)
421 *
422 * We could relax this and only unlink the stations from the
423 * hash table and list but keep them on a per-sdata list that
424 * will be inserted back again when the interface is brought
425 * up again, but I don't currently see a use case for that,
426 * except with WDS which gets a STA entry created when it is
427 * brought up.
428 */
429 sta_info_flush(local, sdata);
314 430
315 /* 431 /*
316 * Don't count this interface for promisc/allmulti while it 432 * Don't count this interface for promisc/allmulti while it
@@ -352,15 +468,29 @@ static int ieee80211_stop(struct net_device *dev)
352 /* no need to tell driver */ 468 /* no need to tell driver */
353 break; 469 break;
354 case IEEE80211_IF_TYPE_MNTR: 470 case IEEE80211_IF_TYPE_MNTR:
355 local->monitors--; 471 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
356 if (local->monitors == 0) { 472 local->cooked_mntrs--;
357 netif_tx_lock_bh(local->mdev); 473 break;
358 ieee80211_configure_filter(local); 474 }
359 netif_tx_unlock_bh(local->mdev);
360 475
476 local->monitors--;
477 if (local->monitors == 0)
361 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; 478 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
362 } 479
480 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
481 local->fif_fcsfail--;
482 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
483 local->fif_plcpfail--;
484 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
485 local->fif_control--;
486 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
487 local->fif_other_bss--;
488
489 netif_tx_lock_bh(local->mdev);
490 ieee80211_configure_filter(local);
491 netif_tx_unlock_bh(local->mdev);
363 break; 492 break;
493 case IEEE80211_IF_TYPE_MESH_POINT:
364 case IEEE80211_IF_TYPE_STA: 494 case IEEE80211_IF_TYPE_STA:
365 case IEEE80211_IF_TYPE_IBSS: 495 case IEEE80211_IF_TYPE_IBSS:
366 sdata->u.sta.state = IEEE80211_DISABLED; 496 sdata->u.sta.state = IEEE80211_DISABLED;
@@ -414,6 +544,339 @@ static int ieee80211_stop(struct net_device *dev)
414 return 0; 544 return 0;
415} 545}
416 546
547int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
548{
549 struct ieee80211_local *local = hw_to_local(hw);
550 struct sta_info *sta;
551 struct ieee80211_sub_if_data *sdata;
552 u16 start_seq_num = 0;
553 u8 *state;
554 int ret;
555 DECLARE_MAC_BUF(mac);
556
557 if (tid >= STA_TID_NUM)
558 return -EINVAL;
559
560#ifdef CONFIG_MAC80211_HT_DEBUG
561 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
562 print_mac(mac, ra), tid);
563#endif /* CONFIG_MAC80211_HT_DEBUG */
564
565 rcu_read_lock();
566
567 sta = sta_info_get(local, ra);
568 if (!sta) {
569 printk(KERN_DEBUG "Could not find the station\n");
570 rcu_read_unlock();
571 return -ENOENT;
572 }
573
574 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
575
576 /* we have tried too many times, receiver does not want A-MPDU */
577 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
578 ret = -EBUSY;
579 goto start_ba_exit;
580 }
581
582 state = &sta->ampdu_mlme.tid_tx[tid].state;
583 /* check if the TID is not in aggregation flow already */
584 if (*state != HT_AGG_STATE_IDLE) {
585#ifdef CONFIG_MAC80211_HT_DEBUG
586 printk(KERN_DEBUG "BA request denied - session is not "
587 "idle on tid %u\n", tid);
588#endif /* CONFIG_MAC80211_HT_DEBUG */
589 ret = -EAGAIN;
590 goto start_ba_exit;
591 }
592
593 /* ensure that TX flow won't interrupt us
594 * until the end of the call to requeue function */
595 spin_lock_bh(&local->mdev->queue_lock);
596
597 /* create a new queue for this aggregation */
598 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
599
600 /* case no queue is available to aggregation
601 * don't switch to aggregation */
602 if (ret) {
603#ifdef CONFIG_MAC80211_HT_DEBUG
604 printk(KERN_DEBUG "BA request denied - no queue available for"
605 " tid %d\n", tid);
606#endif /* CONFIG_MAC80211_HT_DEBUG */
607 spin_unlock_bh(&local->mdev->queue_lock);
608 goto start_ba_exit;
609 }
610 sdata = sta->sdata;
611
612 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
613 * call back right away, it must see that the flow has begun */
614 *state |= HT_ADDBA_REQUESTED_MSK;
615
616 if (local->ops->ampdu_action)
617 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
618 ra, tid, &start_seq_num);
619
620 if (ret) {
621 /* No need to requeue the packets in the agg queue, since we
622 * held the tx lock: no packet could be enqueued to the newly
623 * allocated queue */
624 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
625#ifdef CONFIG_MAC80211_HT_DEBUG
626 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
627 " for tid %d\n", tid);
628#endif /* CONFIG_MAC80211_HT_DEBUG */
629 spin_unlock_bh(&local->mdev->queue_lock);
630 *state = HT_AGG_STATE_IDLE;
631 goto start_ba_exit;
632 }
633
634 /* Will put all the packets in the new SW queue */
635 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
636 spin_unlock_bh(&local->mdev->queue_lock);
637
638 /* We have most probably almost emptied the legacy queue */
639 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
640
641 /* send an addBA request */
642 sta->ampdu_mlme.dialog_token_allocator++;
643 sta->ampdu_mlme.tid_tx[tid].dialog_token =
644 sta->ampdu_mlme.dialog_token_allocator;
645 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
646
647 ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
648 sta->ampdu_mlme.tid_tx[tid].dialog_token,
649 sta->ampdu_mlme.tid_tx[tid].ssn,
650 0x40, 5000);
651
652 /* activate the timer for the recipient's addBA response */
653 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
654 jiffies + ADDBA_RESP_INTERVAL;
655 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
656 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
657
658start_ba_exit:
659 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
660 rcu_read_unlock();
661 return ret;
662}
663EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
664
665int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
666 u8 *ra, u16 tid,
667 enum ieee80211_back_parties initiator)
668{
669 struct ieee80211_local *local = hw_to_local(hw);
670 struct sta_info *sta;
671 u8 *state;
672 int ret = 0;
673 DECLARE_MAC_BUF(mac);
674
675 if (tid >= STA_TID_NUM)
676 return -EINVAL;
677
678#ifdef CONFIG_MAC80211_HT_DEBUG
679 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
680 print_mac(mac, ra), tid);
681#endif /* CONFIG_MAC80211_HT_DEBUG */
682
683 rcu_read_lock();
684 sta = sta_info_get(local, ra);
685 if (!sta) {
686 rcu_read_unlock();
687 return -ENOENT;
688 }
689
690 /* check if the TID is in aggregation */
691 state = &sta->ampdu_mlme.tid_tx[tid].state;
692 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
693
694 if (*state != HT_AGG_STATE_OPERATIONAL) {
695#ifdef CONFIG_MAC80211_HT_DEBUG
696 printk(KERN_DEBUG "Try to stop Tx aggregation on"
697 " non active TID\n");
698#endif /* CONFIG_MAC80211_HT_DEBUG */
699 ret = -ENOENT;
700 goto stop_BA_exit;
701 }
702
703 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
704
705 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
706 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
707
708 if (local->ops->ampdu_action)
709 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
710 ra, tid, NULL);
711
712 /* case HW denied going back to legacy */
713 if (ret) {
714 WARN_ON(ret != -EBUSY);
715 *state = HT_AGG_STATE_OPERATIONAL;
716 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
717 goto stop_BA_exit;
718 }
719
720stop_BA_exit:
721 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
722 rcu_read_unlock();
723 return ret;
724}
725EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
726
727void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
728{
729 struct ieee80211_local *local = hw_to_local(hw);
730 struct sta_info *sta;
731 u8 *state;
732 DECLARE_MAC_BUF(mac);
733
734 if (tid >= STA_TID_NUM) {
735 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
736 tid, STA_TID_NUM);
737 return;
738 }
739
740 rcu_read_lock();
741 sta = sta_info_get(local, ra);
742 if (!sta) {
743 rcu_read_unlock();
744 printk(KERN_DEBUG "Could not find station: %s\n",
745 print_mac(mac, ra));
746 return;
747 }
748
749 state = &sta->ampdu_mlme.tid_tx[tid].state;
750 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
751
752 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
753 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
754 *state);
755 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
756 rcu_read_unlock();
757 return;
758 }
759
760 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
761
762 *state |= HT_ADDBA_DRV_READY_MSK;
763
764 if (*state == HT_AGG_STATE_OPERATIONAL) {
765 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
766 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
767 }
768 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
769 rcu_read_unlock();
770}
771EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
772
773void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
774{
775 struct ieee80211_local *local = hw_to_local(hw);
776 struct sta_info *sta;
777 u8 *state;
778 int agg_queue;
779 DECLARE_MAC_BUF(mac);
780
781 if (tid >= STA_TID_NUM) {
782 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
783 tid, STA_TID_NUM);
784 return;
785 }
786
787 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
788 print_mac(mac, ra), tid);
789
790 rcu_read_lock();
791 sta = sta_info_get(local, ra);
792 if (!sta) {
793 printk(KERN_DEBUG "Could not find station: %s\n",
794 print_mac(mac, ra));
795 rcu_read_unlock();
796 return;
797 }
798 state = &sta->ampdu_mlme.tid_tx[tid].state;
799
800 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
801 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
802 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
803 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
804 rcu_read_unlock();
805 return;
806 }
807
808 if (*state & HT_AGG_STATE_INITIATOR_MSK)
809 ieee80211_send_delba(sta->sdata->dev, ra, tid,
810 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
811
812 agg_queue = sta->tid_to_tx_q[tid];
813
814 /* avoid ordering issues: we are the only one that can modify
815 * the content of the qdiscs */
816 spin_lock_bh(&local->mdev->queue_lock);
817 /* remove the queue for this aggregation */
818 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
819 spin_unlock_bh(&local->mdev->queue_lock);
820
821 /* we just requeued the all the frames that were in the removed
822 * queue, and since we might miss a softirq we do netif_schedule.
823 * ieee80211_wake_queue is not used here as this queue is not
824 * necessarily stopped */
825 netif_schedule(local->mdev);
826 *state = HT_AGG_STATE_IDLE;
827 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
828 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
829
830 rcu_read_unlock();
831}
832EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
833
834void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
835 const u8 *ra, u16 tid)
836{
837 struct ieee80211_local *local = hw_to_local(hw);
838 struct ieee80211_ra_tid *ra_tid;
839 struct sk_buff *skb = dev_alloc_skb(0);
840
841 if (unlikely(!skb)) {
842 if (net_ratelimit())
843 printk(KERN_WARNING "%s: Not enough memory, "
844 "dropping start BA session", skb->dev->name);
845 return;
846 }
847 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
848 memcpy(&ra_tid->ra, ra, ETH_ALEN);
849 ra_tid->tid = tid;
850
851 skb->pkt_type = IEEE80211_ADDBA_MSG;
852 skb_queue_tail(&local->skb_queue, skb);
853 tasklet_schedule(&local->tasklet);
854}
855EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
856
857void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
858 const u8 *ra, u16 tid)
859{
860 struct ieee80211_local *local = hw_to_local(hw);
861 struct ieee80211_ra_tid *ra_tid;
862 struct sk_buff *skb = dev_alloc_skb(0);
863
864 if (unlikely(!skb)) {
865 if (net_ratelimit())
866 printk(KERN_WARNING "%s: Not enough memory, "
867 "dropping stop BA session", skb->dev->name);
868 return;
869 }
870 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
871 memcpy(&ra_tid->ra, ra, ETH_ALEN);
872 ra_tid->tid = tid;
873
874 skb->pkt_type = IEEE80211_DELBA_MSG;
875 skb_queue_tail(&local->skb_queue, skb);
876 tasklet_schedule(&local->tasklet);
877}
878EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
879
417static void ieee80211_set_multicast_list(struct net_device *dev) 880static void ieee80211_set_multicast_list(struct net_device *dev)
418{ 881{
419 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 882 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -465,41 +928,6 @@ void ieee80211_if_setup(struct net_device *dev)
465 dev->destructor = ieee80211_if_free; 928 dev->destructor = ieee80211_if_free;
466} 929}
467 930
468/* WDS specialties */
469
470int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
471{
472 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct sta_info *sta;
475 DECLARE_MAC_BUF(mac);
476
477 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
478 return 0;
479
480 /* Create STA entry for the new peer */
481 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
482 if (!sta)
483 return -ENOMEM;
484 sta_info_put(sta);
485
486 /* Remove STA entry for the old peer */
487 sta = sta_info_get(local, sdata->u.wds.remote_addr);
488 if (sta) {
489 sta_info_free(sta);
490 sta_info_put(sta);
491 } else {
492 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
493 "peer %s\n",
494 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
495 }
496
497 /* Update WDS link data */
498 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
499
500 return 0;
501}
502
503/* everything else */ 931/* everything else */
504 932
505static int __ieee80211_if_config(struct net_device *dev, 933static int __ieee80211_if_config(struct net_device *dev,
@@ -520,6 +948,9 @@ static int __ieee80211_if_config(struct net_device *dev,
520 conf.bssid = sdata->u.sta.bssid; 948 conf.bssid = sdata->u.sta.bssid;
521 conf.ssid = sdata->u.sta.ssid; 949 conf.ssid = sdata->u.sta.ssid;
522 conf.ssid_len = sdata->u.sta.ssid_len; 950 conf.ssid_len = sdata->u.sta.ssid_len;
951 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
952 conf.beacon = beacon;
953 ieee80211_start_mesh(dev);
523 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { 954 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
524 conf.ssid = sdata->u.ap.ssid; 955 conf.ssid = sdata->u.ap.ssid;
525 conf.ssid_len = sdata->u.ap.ssid_len; 956 conf.ssid_len = sdata->u.ap.ssid_len;
@@ -532,6 +963,11 @@ static int __ieee80211_if_config(struct net_device *dev,
532 963
533int ieee80211_if_config(struct net_device *dev) 964int ieee80211_if_config(struct net_device *dev)
534{ 965{
966 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
967 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
968 if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
969 (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
970 return ieee80211_if_config_beacon(dev);
535 return __ieee80211_if_config(dev, NULL, NULL); 971 return __ieee80211_if_config(dev, NULL, NULL);
536} 972}
537 973
@@ -553,37 +989,28 @@ int ieee80211_if_config_beacon(struct net_device *dev)
553 989
554int ieee80211_hw_config(struct ieee80211_local *local) 990int ieee80211_hw_config(struct ieee80211_local *local)
555{ 991{
556 struct ieee80211_hw_mode *mode;
557 struct ieee80211_channel *chan; 992 struct ieee80211_channel *chan;
558 int ret = 0; 993 int ret = 0;
559 994
560 if (local->sta_sw_scanning) { 995 if (local->sta_sw_scanning)
561 chan = local->scan_channel; 996 chan = local->scan_channel;
562 mode = local->scan_hw_mode; 997 else
563 } else {
564 chan = local->oper_channel; 998 chan = local->oper_channel;
565 mode = local->oper_hw_mode;
566 }
567 999
568 local->hw.conf.channel = chan->chan; 1000 local->hw.conf.channel = chan;
569 local->hw.conf.channel_val = chan->val; 1001
570 if (!local->hw.conf.power_level) { 1002 if (!local->hw.conf.power_level)
571 local->hw.conf.power_level = chan->power_level; 1003 local->hw.conf.power_level = chan->max_power;
572 } else { 1004 else
573 local->hw.conf.power_level = min(chan->power_level, 1005 local->hw.conf.power_level = min(chan->max_power,
574 local->hw.conf.power_level); 1006 local->hw.conf.power_level);
575 } 1007
576 local->hw.conf.freq = chan->freq; 1008 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
577 local->hw.conf.phymode = mode->mode;
578 local->hw.conf.antenna_max = chan->antenna_max;
579 local->hw.conf.chan = chan;
580 local->hw.conf.mode = mode;
581 1009
582#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1010#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
583 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d " 1011 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
584 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq, 1012 wiphy_name(local->hw.wiphy), chan->center_freq);
585 local->hw.conf.phymode); 1013#endif
586#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
587 1014
588 if (local->open_count) 1015 if (local->open_count)
589 ret = local->ops->config(local_to_hw(local), &local->hw.conf); 1016 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
@@ -601,11 +1028,13 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
601 struct ieee80211_ht_bss_info *req_bss_cap) 1028 struct ieee80211_ht_bss_info *req_bss_cap)
602{ 1029{
603 struct ieee80211_conf *conf = &local->hw.conf; 1030 struct ieee80211_conf *conf = &local->hw.conf;
604 struct ieee80211_hw_mode *mode = conf->mode; 1031 struct ieee80211_supported_band *sband;
605 int i; 1032 int i;
606 1033
1034 sband = local->hw.wiphy->bands[conf->channel->band];
1035
607 /* HT is not supported */ 1036 /* HT is not supported */
608 if (!mode->ht_info.ht_supported) { 1037 if (!sband->ht_info.ht_supported) {
609 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 1038 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
610 return -EOPNOTSUPP; 1039 return -EOPNOTSUPP;
611 } 1040 }
@@ -615,17 +1044,17 @@ int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
615 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; 1044 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
616 } else { 1045 } else {
617 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; 1046 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
618 conf->ht_conf.cap = req_ht_cap->cap & mode->ht_info.cap; 1047 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
619 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); 1048 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
620 conf->ht_conf.cap |= 1049 conf->ht_conf.cap |=
621 mode->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; 1050 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
622 conf->ht_bss_conf.primary_channel = 1051 conf->ht_bss_conf.primary_channel =
623 req_bss_cap->primary_channel; 1052 req_bss_cap->primary_channel;
624 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap; 1053 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
625 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; 1054 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
626 for (i = 0; i < SUPP_MCS_SET_LEN; i++) 1055 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
627 conf->ht_conf.supp_mcs_set[i] = 1056 conf->ht_conf.supp_mcs_set[i] =
628 mode->ht_info.supp_mcs_set[i] & 1057 sband->ht_info.supp_mcs_set[i] &
629 req_ht_cap->supp_mcs_set[i]; 1058 req_ht_cap->supp_mcs_set[i];
630 1059
631 /* In STA mode, this gives us indication 1060 /* In STA mode, this gives us indication
@@ -713,6 +1142,7 @@ static void ieee80211_tasklet_handler(unsigned long data)
713 struct sk_buff *skb; 1142 struct sk_buff *skb;
714 struct ieee80211_rx_status rx_status; 1143 struct ieee80211_rx_status rx_status;
715 struct ieee80211_tx_status *tx_status; 1144 struct ieee80211_tx_status *tx_status;
1145 struct ieee80211_ra_tid *ra_tid;
716 1146
717 while ((skb = skb_dequeue(&local->skb_queue)) || 1147 while ((skb = skb_dequeue(&local->skb_queue)) ||
718 (skb = skb_dequeue(&local->skb_queue_unreliable))) { 1148 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
@@ -733,6 +1163,18 @@ static void ieee80211_tasklet_handler(unsigned long data)
733 skb, tx_status); 1163 skb, tx_status);
734 kfree(tx_status); 1164 kfree(tx_status);
735 break; 1165 break;
1166 case IEEE80211_DELBA_MSG:
1167 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1168 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1169 ra_tid->ra, ra_tid->tid);
1170 dev_kfree_skb(skb);
1171 break;
1172 case IEEE80211_ADDBA_MSG:
1173 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1174 ieee80211_start_tx_ba_cb(local_to_hw(local),
1175 ra_tid->ra, ra_tid->tid);
1176 dev_kfree_skb(skb);
1177 break ;
736 default: /* should never get here! */ 1178 default: /* should never get here! */
737 printk(KERN_ERR "%s: Unknown message type (%d)\n", 1179 printk(KERN_ERR "%s: Unknown message type (%d)\n",
738 wiphy_name(local->hw.wiphy), skb->pkt_type); 1180 wiphy_name(local->hw.wiphy), skb->pkt_type);
@@ -810,6 +1252,77 @@ no_key:
810 } 1252 }
811} 1253}
812 1254
1255static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1256 struct sta_info *sta,
1257 struct sk_buff *skb,
1258 struct ieee80211_tx_status *status)
1259{
1260 sta->tx_filtered_count++;
1261
1262 /*
1263 * Clear the TX filter mask for this STA when sending the next
1264 * packet. If the STA went to power save mode, this will happen
1265 * happen when it wakes up for the next time.
1266 */
1267 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1268
1269 /*
1270 * This code races in the following way:
1271 *
1272 * (1) STA sends frame indicating it will go to sleep and does so
1273 * (2) hardware/firmware adds STA to filter list, passes frame up
1274 * (3) hardware/firmware processes TX fifo and suppresses a frame
1275 * (4) we get TX status before having processed the frame and
1276 * knowing that the STA has gone to sleep.
1277 *
1278 * This is actually quite unlikely even when both those events are
1279 * processed from interrupts coming in quickly after one another or
1280 * even at the same time because we queue both TX status events and
1281 * RX frames to be processed by a tasklet and process them in the
1282 * same order that they were received or TX status last. Hence, there
1283 * is no race as long as the frame RX is processed before the next TX
1284 * status, which drivers can ensure, see below.
1285 *
1286 * Note that this can only happen if the hardware or firmware can
1287 * actually add STAs to the filter list, if this is done by the
1288 * driver in response to set_tim() (which will only reduce the race
1289 * this whole filtering tries to solve, not completely solve it)
1290 * this situation cannot happen.
1291 *
1292 * To completely solve this race drivers need to make sure that they
1293 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1294 * functions and
1295 * (b) always process RX events before TX status events if ordering
1296 * can be unknown, for example with different interrupt status
1297 * bits.
1298 */
1299 if (sta->flags & WLAN_STA_PS &&
1300 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1301 ieee80211_remove_tx_extra(local, sta->key, skb,
1302 &status->control);
1303 skb_queue_tail(&sta->tx_filtered, skb);
1304 return;
1305 }
1306
1307 if (!(sta->flags & WLAN_STA_PS) &&
1308 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1309 /* Software retry the packet once */
1310 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1311 ieee80211_remove_tx_extra(local, sta->key, skb,
1312 &status->control);
1313 dev_queue_xmit(skb);
1314 return;
1315 }
1316
1317 if (net_ratelimit())
1318 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1319 "queue_len=%d PS=%d @%lu\n",
1320 wiphy_name(local->hw.wiphy),
1321 skb_queue_len(&sta->tx_filtered),
1322 !!(sta->flags & WLAN_STA_PS), jiffies);
1323 dev_kfree_skb(skb);
1324}
1325
813void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, 1326void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
814 struct ieee80211_tx_status *status) 1327 struct ieee80211_tx_status *status)
815{ 1328{
@@ -819,7 +1332,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
819 u16 frag, type; 1332 u16 frag, type;
820 struct ieee80211_tx_status_rtap_hdr *rthdr; 1333 struct ieee80211_tx_status_rtap_hdr *rthdr;
821 struct ieee80211_sub_if_data *sdata; 1334 struct ieee80211_sub_if_data *sdata;
822 int monitors; 1335 struct net_device *prev_dev = NULL;
823 1336
824 if (!status) { 1337 if (!status) {
825 printk(KERN_ERR 1338 printk(KERN_ERR
@@ -829,18 +1342,24 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
829 return; 1342 return;
830 } 1343 }
831 1344
1345 rcu_read_lock();
1346
832 if (status->excessive_retries) { 1347 if (status->excessive_retries) {
833 struct sta_info *sta; 1348 struct sta_info *sta;
834 sta = sta_info_get(local, hdr->addr1); 1349 sta = sta_info_get(local, hdr->addr1);
835 if (sta) { 1350 if (sta) {
836 if (sta->flags & WLAN_STA_PS) { 1351 if (sta->flags & WLAN_STA_PS) {
837 /* The STA is in power save mode, so assume 1352 /*
1353 * The STA is in power save mode, so assume
838 * that this TX packet failed because of that. 1354 * that this TX packet failed because of that.
839 */ 1355 */
840 status->excessive_retries = 0; 1356 status->excessive_retries = 0;
841 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED; 1357 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1358 ieee80211_handle_filtered_frame(local, sta,
1359 skb, status);
1360 rcu_read_unlock();
1361 return;
842 } 1362 }
843 sta_info_put(sta);
844 } 1363 }
845 } 1364 }
846 1365
@@ -848,53 +1367,16 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
848 struct sta_info *sta; 1367 struct sta_info *sta;
849 sta = sta_info_get(local, hdr->addr1); 1368 sta = sta_info_get(local, hdr->addr1);
850 if (sta) { 1369 if (sta) {
851 sta->tx_filtered_count++; 1370 ieee80211_handle_filtered_frame(local, sta, skb,
852 1371 status);
853 /* Clear the TX filter mask for this STA when sending 1372 rcu_read_unlock();
854 * the next packet. If the STA went to power save mode,
855 * this will happen when it is waking up for the next
856 * time. */
857 sta->clear_dst_mask = 1;
858
859 /* TODO: Is the WLAN_STA_PS flag always set here or is
860 * the race between RX and TX status causing some
861 * packets to be filtered out before 80211.o gets an
862 * update for PS status? This seems to be the case, so
863 * no changes are likely to be needed. */
864 if (sta->flags & WLAN_STA_PS &&
865 skb_queue_len(&sta->tx_filtered) <
866 STA_MAX_TX_BUFFER) {
867 ieee80211_remove_tx_extra(local, sta->key,
868 skb,
869 &status->control);
870 skb_queue_tail(&sta->tx_filtered, skb);
871 } else if (!(sta->flags & WLAN_STA_PS) &&
872 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
873 /* Software retry the packet once */
874 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
875 ieee80211_remove_tx_extra(local, sta->key,
876 skb,
877 &status->control);
878 dev_queue_xmit(skb);
879 } else {
880 if (net_ratelimit()) {
881 printk(KERN_DEBUG "%s: dropped TX "
882 "filtered frame queue_len=%d "
883 "PS=%d @%lu\n",
884 wiphy_name(local->hw.wiphy),
885 skb_queue_len(
886 &sta->tx_filtered),
887 !!(sta->flags & WLAN_STA_PS),
888 jiffies);
889 }
890 dev_kfree_skb(skb);
891 }
892 sta_info_put(sta);
893 return; 1373 return;
894 } 1374 }
895 } else 1375 } else
896 rate_control_tx_status(local->mdev, skb, status); 1376 rate_control_tx_status(local->mdev, skb, status);
897 1377
1378 rcu_read_unlock();
1379
898 ieee80211_led_tx(local, 0); 1380 ieee80211_led_tx(local, 0);
899 1381
900 /* SNMP counters 1382 /* SNMP counters
@@ -932,7 +1414,11 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
932 /* this was a transmitted frame, but now we want to reuse it */ 1414 /* this was a transmitted frame, but now we want to reuse it */
933 skb_orphan(skb); 1415 skb_orphan(skb);
934 1416
935 if (!local->monitors) { 1417 /*
1418 * This is a bit racy but we can avoid a lot of work
1419 * with this test...
1420 */
1421 if (!local->monitors && !local->cooked_mntrs) {
936 dev_kfree_skb(skb); 1422 dev_kfree_skb(skb);
937 return; 1423 return;
938 } 1424 }
@@ -966,51 +1452,44 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
966 1452
967 rthdr->data_retries = status->retry_count; 1453 rthdr->data_retries = status->retry_count;
968 1454
1455 /* XXX: is this sufficient for BPF? */
1456 skb_set_mac_header(skb, 0);
1457 skb->ip_summed = CHECKSUM_UNNECESSARY;
1458 skb->pkt_type = PACKET_OTHERHOST;
1459 skb->protocol = htons(ETH_P_802_2);
1460 memset(skb->cb, 0, sizeof(skb->cb));
1461
969 rcu_read_lock(); 1462 rcu_read_lock();
970 monitors = local->monitors;
971 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 1463 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
972 /*
973 * Using the monitors counter is possibly racy, but
974 * if the value is wrong we simply either clone the skb
975 * once too much or forget sending it to one monitor iface
976 * The latter case isn't nice but fixing the race is much
977 * more complicated.
978 */
979 if (!monitors || !skb)
980 goto out;
981
982 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { 1464 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
983 if (!netif_running(sdata->dev)) 1465 if (!netif_running(sdata->dev))
984 continue; 1466 continue;
985 monitors--; 1467
986 if (monitors) 1468 if (prev_dev) {
987 skb2 = skb_clone(skb, GFP_ATOMIC); 1469 skb2 = skb_clone(skb, GFP_ATOMIC);
988 else 1470 if (skb2) {
989 skb2 = NULL; 1471 skb2->dev = prev_dev;
990 skb->dev = sdata->dev; 1472 netif_rx(skb2);
991 /* XXX: is this sufficient for BPF? */ 1473 }
992 skb_set_mac_header(skb, 0); 1474 }
993 skb->ip_summed = CHECKSUM_UNNECESSARY; 1475
994 skb->pkt_type = PACKET_OTHERHOST; 1476 prev_dev = sdata->dev;
995 skb->protocol = htons(ETH_P_802_2);
996 memset(skb->cb, 0, sizeof(skb->cb));
997 netif_rx(skb);
998 skb = skb2;
999 } 1477 }
1000 } 1478 }
1001 out: 1479 if (prev_dev) {
1480 skb->dev = prev_dev;
1481 netif_rx(skb);
1482 skb = NULL;
1483 }
1002 rcu_read_unlock(); 1484 rcu_read_unlock();
1003 if (skb) 1485 dev_kfree_skb(skb);
1004 dev_kfree_skb(skb);
1005} 1486}
1006EXPORT_SYMBOL(ieee80211_tx_status); 1487EXPORT_SYMBOL(ieee80211_tx_status);
1007 1488
1008struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 1489struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1009 const struct ieee80211_ops *ops) 1490 const struct ieee80211_ops *ops)
1010{ 1491{
1011 struct net_device *mdev;
1012 struct ieee80211_local *local; 1492 struct ieee80211_local *local;
1013 struct ieee80211_sub_if_data *sdata;
1014 int priv_size; 1493 int priv_size;
1015 struct wiphy *wiphy; 1494 struct wiphy *wiphy;
1016 1495
@@ -1056,25 +1535,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1056 BUG_ON(!ops->configure_filter); 1535 BUG_ON(!ops->configure_filter);
1057 local->ops = ops; 1536 local->ops = ops;
1058 1537
1059 /* for now, mdev needs sub_if_data :/ */
1060 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1061 "wmaster%d", ether_setup);
1062 if (!mdev) {
1063 wiphy_free(wiphy);
1064 return NULL;
1065 }
1066
1067 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1068 mdev->ieee80211_ptr = &sdata->wdev;
1069 sdata->wdev.wiphy = wiphy;
1070
1071 local->hw.queues = 1; /* default */ 1538 local->hw.queues = 1; /* default */
1072 1539
1073 local->mdev = mdev;
1074 local->rx_pre_handlers = ieee80211_rx_pre_handlers;
1075 local->rx_handlers = ieee80211_rx_handlers;
1076 local->tx_handlers = ieee80211_tx_handlers;
1077
1078 local->bridge_packets = 1; 1540 local->bridge_packets = 1;
1079 1541
1080 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 1542 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
@@ -1083,33 +1545,12 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1083 local->long_retry_limit = 4; 1545 local->long_retry_limit = 4;
1084 local->hw.conf.radio_enabled = 1; 1546 local->hw.conf.radio_enabled = 1;
1085 1547
1086 local->enabled_modes = ~0;
1087
1088 INIT_LIST_HEAD(&local->modes_list);
1089
1090 INIT_LIST_HEAD(&local->interfaces); 1548 INIT_LIST_HEAD(&local->interfaces);
1091 1549
1092 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); 1550 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
1093 ieee80211_rx_bss_list_init(mdev);
1094 1551
1095 sta_info_init(local); 1552 sta_info_init(local);
1096 1553
1097 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1098 mdev->open = ieee80211_master_open;
1099 mdev->stop = ieee80211_master_stop;
1100 mdev->type = ARPHRD_IEEE80211;
1101 mdev->header_ops = &ieee80211_header_ops;
1102 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1103
1104 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1105 sdata->dev = mdev;
1106 sdata->local = local;
1107 sdata->u.ap.force_unicast_rateidx = -1;
1108 sdata->u.ap.max_ratectrl_rateidx = -1;
1109 ieee80211_if_sdata_init(sdata);
1110 /* no RCU needed since we're still during init phase */
1111 list_add_tail(&sdata->list, &local->interfaces);
1112
1113 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, 1554 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1114 (unsigned long)local); 1555 (unsigned long)local);
1115 tasklet_disable(&local->tx_pending_tasklet); 1556 tasklet_disable(&local->tx_pending_tasklet);
@@ -1131,11 +1572,63 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1131 struct ieee80211_local *local = hw_to_local(hw); 1572 struct ieee80211_local *local = hw_to_local(hw);
1132 const char *name; 1573 const char *name;
1133 int result; 1574 int result;
1575 enum ieee80211_band band;
1576 struct net_device *mdev;
1577 struct ieee80211_sub_if_data *sdata;
1578
1579 /*
1580 * generic code guarantees at least one band,
1581 * set this very early because much code assumes
1582 * that hw.conf.channel is assigned
1583 */
1584 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1585 struct ieee80211_supported_band *sband;
1586
1587 sband = local->hw.wiphy->bands[band];
1588 if (sband) {
1589 /* init channel we're on */
1590 local->hw.conf.channel =
1591 local->oper_channel =
1592 local->scan_channel = &sband->channels[0];
1593 break;
1594 }
1595 }
1134 1596
1135 result = wiphy_register(local->hw.wiphy); 1597 result = wiphy_register(local->hw.wiphy);
1136 if (result < 0) 1598 if (result < 0)
1137 return result; 1599 return result;
1138 1600
1601 /* for now, mdev needs sub_if_data :/ */
1602 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1603 "wmaster%d", ether_setup);
1604 if (!mdev)
1605 goto fail_mdev_alloc;
1606
1607 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1608 mdev->ieee80211_ptr = &sdata->wdev;
1609 sdata->wdev.wiphy = local->hw.wiphy;
1610
1611 local->mdev = mdev;
1612
1613 ieee80211_rx_bss_list_init(mdev);
1614
1615 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1616 mdev->open = ieee80211_master_open;
1617 mdev->stop = ieee80211_master_stop;
1618 mdev->type = ARPHRD_IEEE80211;
1619 mdev->header_ops = &ieee80211_header_ops;
1620 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1621
1622 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1623 sdata->dev = mdev;
1624 sdata->local = local;
1625 sdata->u.ap.force_unicast_rateidx = -1;
1626 sdata->u.ap.max_ratectrl_rateidx = -1;
1627 ieee80211_if_sdata_init(sdata);
1628
1629 /* no RCU needed since we're still during init phase */
1630 list_add_tail(&sdata->list, &local->interfaces);
1631
1139 name = wiphy_dev(local->hw.wiphy)->driver->name; 1632 name = wiphy_dev(local->hw.wiphy)->driver->name;
1140 local->hw.workqueue = create_singlethread_workqueue(name); 1633 local->hw.workqueue = create_singlethread_workqueue(name);
1141 if (!local->hw.workqueue) { 1634 if (!local->hw.workqueue) {
@@ -1203,7 +1696,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
1203 1696
1204 /* add one default STA interface */ 1697 /* add one default STA interface */
1205 result = ieee80211_if_add(local->mdev, "wlan%d", NULL, 1698 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1206 IEEE80211_IF_TYPE_STA); 1699 IEEE80211_IF_TYPE_STA, NULL);
1207 if (result) 1700 if (result)
1208 printk(KERN_WARNING "%s: Failed to add default virtual iface\n", 1701 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
1209 wiphy_name(local->hw.wiphy)); 1702 wiphy_name(local->hw.wiphy));
@@ -1227,49 +1720,18 @@ fail_sta_info:
1227 debugfs_hw_del(local); 1720 debugfs_hw_del(local);
1228 destroy_workqueue(local->hw.workqueue); 1721 destroy_workqueue(local->hw.workqueue);
1229fail_workqueue: 1722fail_workqueue:
1723 ieee80211_if_free(local->mdev);
1724 local->mdev = NULL;
1725fail_mdev_alloc:
1230 wiphy_unregister(local->hw.wiphy); 1726 wiphy_unregister(local->hw.wiphy);
1231 return result; 1727 return result;
1232} 1728}
1233EXPORT_SYMBOL(ieee80211_register_hw); 1729EXPORT_SYMBOL(ieee80211_register_hw);
1234 1730
1235int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1236 struct ieee80211_hw_mode *mode)
1237{
1238 struct ieee80211_local *local = hw_to_local(hw);
1239 struct ieee80211_rate *rate;
1240 int i;
1241
1242 INIT_LIST_HEAD(&mode->list);
1243 list_add_tail(&mode->list, &local->modes_list);
1244
1245 local->hw_modes |= (1 << mode->mode);
1246 for (i = 0; i < mode->num_rates; i++) {
1247 rate = &(mode->rates[i]);
1248 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1249 }
1250 ieee80211_prepare_rates(local, mode);
1251
1252 if (!local->oper_hw_mode) {
1253 /* Default to this mode */
1254 local->hw.conf.phymode = mode->mode;
1255 local->oper_hw_mode = local->scan_hw_mode = mode;
1256 local->oper_channel = local->scan_channel = &mode->channels[0];
1257 local->hw.conf.mode = local->oper_hw_mode;
1258 local->hw.conf.chan = local->oper_channel;
1259 }
1260
1261 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
1262 ieee80211_set_default_regdomain(mode);
1263
1264 return 0;
1265}
1266EXPORT_SYMBOL(ieee80211_register_hwmode);
1267
1268void ieee80211_unregister_hw(struct ieee80211_hw *hw) 1731void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1269{ 1732{
1270 struct ieee80211_local *local = hw_to_local(hw); 1733 struct ieee80211_local *local = hw_to_local(hw);
1271 struct ieee80211_sub_if_data *sdata, *tmp; 1734 struct ieee80211_sub_if_data *sdata, *tmp;
1272 int i;
1273 1735
1274 tasklet_kill(&local->tx_pending_tasklet); 1736 tasklet_kill(&local->tx_pending_tasklet);
1275 tasklet_kill(&local->tasklet); 1737 tasklet_kill(&local->tasklet);
@@ -1310,11 +1772,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1310 rate_control_deinitialize(local); 1772 rate_control_deinitialize(local);
1311 debugfs_hw_del(local); 1773 debugfs_hw_del(local);
1312 1774
1313 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1314 kfree(local->supp_rates[i]);
1315 kfree(local->basic_rates[i]);
1316 }
1317
1318 if (skb_queue_len(&local->skb_queue) 1775 if (skb_queue_len(&local->skb_queue)
1319 || skb_queue_len(&local->skb_queue_unreliable)) 1776 || skb_queue_len(&local->skb_queue_unreliable))
1320 printk(KERN_WARNING "%s: skb_queue not empty\n", 1777 printk(KERN_WARNING "%s: skb_queue not empty\n",
@@ -1326,6 +1783,8 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1326 wiphy_unregister(local->hw.wiphy); 1783 wiphy_unregister(local->hw.wiphy);
1327 ieee80211_wep_free(local); 1784 ieee80211_wep_free(local);
1328 ieee80211_led_exit(local); 1785 ieee80211_led_exit(local);
1786 ieee80211_if_free(local->mdev);
1787 local->mdev = NULL;
1329} 1788}
1330EXPORT_SYMBOL(ieee80211_unregister_hw); 1789EXPORT_SYMBOL(ieee80211_unregister_hw);
1331 1790
@@ -1333,7 +1792,6 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
1333{ 1792{
1334 struct ieee80211_local *local = hw_to_local(hw); 1793 struct ieee80211_local *local = hw_to_local(hw);
1335 1794
1336 ieee80211_if_free(local->mdev);
1337 wiphy_free(local->hw.wiphy); 1795 wiphy_free(local->hw.wiphy);
1338} 1796}
1339EXPORT_SYMBOL(ieee80211_free_hw); 1797EXPORT_SYMBOL(ieee80211_free_hw);
@@ -1345,13 +1803,9 @@ static int __init ieee80211_init(void)
1345 1803
1346 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb)); 1804 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1347 1805
1348 ret = rc80211_simple_init();
1349 if (ret)
1350 goto out;
1351
1352 ret = rc80211_pid_init(); 1806 ret = rc80211_pid_init();
1353 if (ret) 1807 if (ret)
1354 goto out_cleanup_simple; 1808 goto out;
1355 1809
1356 ret = ieee80211_wme_register(); 1810 ret = ieee80211_wme_register();
1357 if (ret) { 1811 if (ret) {
@@ -1361,23 +1815,22 @@ static int __init ieee80211_init(void)
1361 } 1815 }
1362 1816
1363 ieee80211_debugfs_netdev_init(); 1817 ieee80211_debugfs_netdev_init();
1364 ieee80211_regdomain_init();
1365 1818
1366 return 0; 1819 return 0;
1367 1820
1368 out_cleanup_pid: 1821 out_cleanup_pid:
1369 rc80211_pid_exit(); 1822 rc80211_pid_exit();
1370 out_cleanup_simple:
1371 rc80211_simple_exit();
1372 out: 1823 out:
1373 return ret; 1824 return ret;
1374} 1825}
1375 1826
1376static void __exit ieee80211_exit(void) 1827static void __exit ieee80211_exit(void)
1377{ 1828{
1378 rc80211_simple_exit();
1379 rc80211_pid_exit(); 1829 rc80211_pid_exit();
1380 1830
1831 if (mesh_allocated)
1832 ieee80211s_stop();
1833
1381 ieee80211_wme_unregister(); 1834 ieee80211_wme_unregister();
1382 ieee80211_debugfs_netdev_exit(); 1835 ieee80211_debugfs_netdev_exit();
1383} 1836}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 72ecbf7bf962..7f10ff5d4a0b 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -79,8 +79,7 @@ struct ieee80211_sta_bss {
79 u8 ssid[IEEE80211_MAX_SSID_LEN]; 79 u8 ssid[IEEE80211_MAX_SSID_LEN];
80 size_t ssid_len; 80 size_t ssid_len;
81 u16 capability; /* host byte order */ 81 u16 capability; /* host byte order */
82 int hw_mode; 82 enum ieee80211_band band;
83 int channel;
84 int freq; 83 int freq;
85 int rssi, signal, noise; 84 int rssi, signal, noise;
86 u8 *wpa_ie; 85 u8 *wpa_ie;
@@ -91,6 +90,11 @@ struct ieee80211_sta_bss {
91 size_t wmm_ie_len; 90 size_t wmm_ie_len;
92 u8 *ht_ie; 91 u8 *ht_ie;
93 size_t ht_ie_len; 92 size_t ht_ie_len;
93#ifdef CONFIG_MAC80211_MESH
94 u8 *mesh_id;
95 size_t mesh_id_len;
96 u8 *mesh_cfg;
97#endif
94#define IEEE80211_MAX_SUPP_RATES 32 98#define IEEE80211_MAX_SUPP_RATES 32
95 u8 supp_rates[IEEE80211_MAX_SUPP_RATES]; 99 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
96 size_t supp_rates_len; 100 size_t supp_rates_len;
@@ -108,23 +112,81 @@ struct ieee80211_sta_bss {
108 u8 erp_value; 112 u8 erp_value;
109}; 113};
110 114
115static inline u8 *bss_mesh_cfg(struct ieee80211_sta_bss *bss)
116{
117#ifdef CONFIG_MAC80211_MESH
118 return bss->mesh_cfg;
119#endif
120 return NULL;
121}
122
123static inline u8 *bss_mesh_id(struct ieee80211_sta_bss *bss)
124{
125#ifdef CONFIG_MAC80211_MESH
126 return bss->mesh_id;
127#endif
128 return NULL;
129}
130
131static inline u8 bss_mesh_id_len(struct ieee80211_sta_bss *bss)
132{
133#ifdef CONFIG_MAC80211_MESH
134 return bss->mesh_id_len;
135#endif
136 return 0;
137}
138
139
140typedef unsigned __bitwise__ ieee80211_tx_result;
141#define TX_CONTINUE ((__force ieee80211_tx_result) 0u)
142#define TX_DROP ((__force ieee80211_tx_result) 1u)
143#define TX_QUEUED ((__force ieee80211_tx_result) 2u)
144
145#define IEEE80211_TX_FRAGMENTED BIT(0)
146#define IEEE80211_TX_UNICAST BIT(1)
147#define IEEE80211_TX_PS_BUFFERED BIT(2)
148#define IEEE80211_TX_PROBE_LAST_FRAG BIT(3)
149#define IEEE80211_TX_INJECTED BIT(4)
150
151struct ieee80211_tx_data {
152 struct sk_buff *skb;
153 struct net_device *dev;
154 struct ieee80211_local *local;
155 struct ieee80211_sub_if_data *sdata;
156 struct sta_info *sta;
157 u16 fc, ethertype;
158 struct ieee80211_key *key;
159 unsigned int flags;
160
161 struct ieee80211_tx_control *control;
162 struct ieee80211_channel *channel;
163 struct ieee80211_rate *rate;
164 /* use this rate (if set) for last fragment; rate can
165 * be set to lower rate for the first fragments, e.g.,
166 * when using CTS protection with IEEE 802.11g. */
167 struct ieee80211_rate *last_frag_rate;
168
169 /* Extra fragments (in addition to the first fragment
170 * in skb) */
171 int num_extra_frag;
172 struct sk_buff **extra_frag;
173};
174
111 175
112typedef enum { 176typedef unsigned __bitwise__ ieee80211_rx_result;
113 TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED 177#define RX_CONTINUE ((__force ieee80211_rx_result) 0u)
114} ieee80211_txrx_result; 178#define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u)
179#define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u)
180#define RX_QUEUED ((__force ieee80211_rx_result) 3u)
115 181
116/* flags used in struct ieee80211_txrx_data.flags */ 182#define IEEE80211_RX_IN_SCAN BIT(0)
117/* whether the MSDU was fragmented */
118#define IEEE80211_TXRXD_FRAGMENTED BIT(0)
119#define IEEE80211_TXRXD_TXUNICAST BIT(1)
120#define IEEE80211_TXRXD_TXPS_BUFFERED BIT(2)
121#define IEEE80211_TXRXD_TXPROBE_LAST_FRAG BIT(3)
122#define IEEE80211_TXRXD_RXIN_SCAN BIT(4)
123/* frame is destined to interface currently processed (incl. multicast frames) */ 183/* frame is destined to interface currently processed (incl. multicast frames) */
124#define IEEE80211_TXRXD_RXRA_MATCH BIT(5) 184#define IEEE80211_RX_RA_MATCH BIT(1)
125#define IEEE80211_TXRXD_TX_INJECTED BIT(6) 185#define IEEE80211_RX_AMSDU BIT(2)
126#define IEEE80211_TXRXD_RX_AMSDU BIT(7) 186#define IEEE80211_RX_CMNTR_REPORTED BIT(3)
127struct ieee80211_txrx_data { 187#define IEEE80211_RX_FRAGMENTED BIT(4)
188
189struct ieee80211_rx_data {
128 struct sk_buff *skb; 190 struct sk_buff *skb;
129 struct net_device *dev; 191 struct net_device *dev;
130 struct ieee80211_local *local; 192 struct ieee80211_local *local;
@@ -133,31 +195,14 @@ struct ieee80211_txrx_data {
133 u16 fc, ethertype; 195 u16 fc, ethertype;
134 struct ieee80211_key *key; 196 struct ieee80211_key *key;
135 unsigned int flags; 197 unsigned int flags;
136 union { 198
137 struct { 199 struct ieee80211_rx_status *status;
138 struct ieee80211_tx_control *control; 200 struct ieee80211_rate *rate;
139 struct ieee80211_hw_mode *mode; 201 int sent_ps_buffered;
140 struct ieee80211_rate *rate; 202 int queue;
141 /* use this rate (if set) for last fragment; rate can 203 int load;
142 * be set to lower rate for the first fragments, e.g., 204 u32 tkip_iv32;
143 * when using CTS protection with IEEE 802.11g. */ 205 u16 tkip_iv16;
144 struct ieee80211_rate *last_frag_rate;
145 int last_frag_hwrate;
146
147 /* Extra fragments (in addition to the first fragment
148 * in skb) */
149 int num_extra_frag;
150 struct sk_buff **extra_frag;
151 } tx;
152 struct {
153 struct ieee80211_rx_status *status;
154 int sent_ps_buffered;
155 int queue;
156 int load;
157 u32 tkip_iv32;
158 u16 tkip_iv16;
159 } rx;
160 } u;
161}; 206};
162 207
163/* flags used in struct ieee80211_tx_packet_data.flags */ 208/* flags used in struct ieee80211_tx_packet_data.flags */
@@ -165,6 +210,7 @@ struct ieee80211_txrx_data {
165#define IEEE80211_TXPD_DO_NOT_ENCRYPT BIT(1) 210#define IEEE80211_TXPD_DO_NOT_ENCRYPT BIT(1)
166#define IEEE80211_TXPD_REQUEUE BIT(2) 211#define IEEE80211_TXPD_REQUEUE BIT(2)
167#define IEEE80211_TXPD_EAPOL_FRAME BIT(3) 212#define IEEE80211_TXPD_EAPOL_FRAME BIT(3)
213#define IEEE80211_TXPD_AMPDU BIT(4)
168/* Stored in sk_buff->cb */ 214/* Stored in sk_buff->cb */
169struct ieee80211_tx_packet_data { 215struct ieee80211_tx_packet_data {
170 int ifindex; 216 int ifindex;
@@ -178,18 +224,10 @@ struct ieee80211_tx_stored_packet {
178 struct sk_buff *skb; 224 struct sk_buff *skb;
179 int num_extra_frag; 225 int num_extra_frag;
180 struct sk_buff **extra_frag; 226 struct sk_buff **extra_frag;
181 int last_frag_rateidx;
182 int last_frag_hwrate;
183 struct ieee80211_rate *last_frag_rate; 227 struct ieee80211_rate *last_frag_rate;
184 unsigned int last_frag_rate_ctrl_probe; 228 unsigned int last_frag_rate_ctrl_probe;
185}; 229};
186 230
187typedef ieee80211_txrx_result (*ieee80211_tx_handler)
188(struct ieee80211_txrx_data *tx);
189
190typedef ieee80211_txrx_result (*ieee80211_rx_handler)
191(struct ieee80211_txrx_data *rx);
192
193struct beacon_data { 231struct beacon_data {
194 u8 *head, *tail; 232 u8 *head, *tail;
195 int head_len, tail_len; 233 int head_len, tail_len;
@@ -206,7 +244,7 @@ struct ieee80211_if_ap {
206 244
207 /* yes, this looks ugly, but guarantees that we can later use 245 /* yes, this looks ugly, but guarantees that we can later use
208 * bitmap_empty :) 246 * bitmap_empty :)
209 * NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */ 247 * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
210 u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)]; 248 u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
211 atomic_t num_sta_ps; /* number of stations in PS mode */ 249 atomic_t num_sta_ps; /* number of stations in PS mode */
212 struct sk_buff_head ps_bc_buf; 250 struct sk_buff_head ps_bc_buf;
@@ -226,6 +264,41 @@ struct ieee80211_if_vlan {
226 struct list_head list; 264 struct list_head list;
227}; 265};
228 266
267struct mesh_stats {
268 __u32 fwded_frames; /* Mesh forwarded frames */
269 __u32 dropped_frames_ttl; /* Not transmitted since mesh_ttl == 0*/
270 __u32 dropped_frames_no_route; /* Not transmitted, no route found */
271 atomic_t estab_plinks;
272};
273
274#define PREQ_Q_F_START 0x1
275#define PREQ_Q_F_REFRESH 0x2
276struct mesh_preq_queue {
277 struct list_head list;
278 u8 dst[ETH_ALEN];
279 u8 flags;
280};
281
282struct mesh_config {
283 /* Timeouts in ms */
284 /* Mesh plink management parameters */
285 u16 dot11MeshRetryTimeout;
286 u16 dot11MeshConfirmTimeout;
287 u16 dot11MeshHoldingTimeout;
288 u16 dot11MeshMaxPeerLinks;
289 u8 dot11MeshMaxRetries;
290 u8 dot11MeshTTL;
291 bool auto_open_plinks;
292 /* HWMP parameters */
293 u32 dot11MeshHWMPactivePathTimeout;
294 u16 dot11MeshHWMPpreqMinInterval;
295 u16 dot11MeshHWMPnetDiameterTraversalTime;
296 u8 dot11MeshHWMPmaxPREQretries;
297 u32 path_refresh_time;
298 u16 min_discovery_timeout;
299};
300
301
229/* flags used in struct ieee80211_if_sta.flags */ 302/* flags used in struct ieee80211_if_sta.flags */
230#define IEEE80211_STA_SSID_SET BIT(0) 303#define IEEE80211_STA_SSID_SET BIT(0)
231#define IEEE80211_STA_BSSID_SET BIT(1) 304#define IEEE80211_STA_BSSID_SET BIT(1)
@@ -244,7 +317,8 @@ struct ieee80211_if_sta {
244 enum { 317 enum {
245 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE, 318 IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
246 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED, 319 IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
247 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED 320 IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED,
321 IEEE80211_MESH_UP
248 } state; 322 } state;
249 struct timer_list timer; 323 struct timer_list timer;
250 struct work_struct work; 324 struct work_struct work;
@@ -253,6 +327,34 @@ struct ieee80211_if_sta {
253 size_t ssid_len; 327 size_t ssid_len;
254 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 328 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
255 size_t scan_ssid_len; 329 size_t scan_ssid_len;
330#ifdef CONFIG_MAC80211_MESH
331 struct timer_list mesh_path_timer;
332 u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
333 bool accepting_plinks;
334 size_t mesh_id_len;
335 /* Active Path Selection Protocol Identifier */
336 u8 mesh_pp_id[4];
337 /* Active Path Selection Metric Identifier */
338 u8 mesh_pm_id[4];
339 /* Congestion Control Mode Identifier */
340 u8 mesh_cc_id[4];
341 /* Local mesh Destination Sequence Number */
342 u32 dsn;
343 /* Last used PREQ ID */
344 u32 preq_id;
345 atomic_t mpaths;
346 /* Timestamp of last DSN update */
347 unsigned long last_dsn_update;
348 /* Timestamp of last DSN sent */
349 unsigned long last_preq;
350 struct mesh_rmc *rmc;
351 spinlock_t mesh_preq_queue_lock;
352 struct mesh_preq_queue preq_queue;
353 int preq_queue_len;
354 struct mesh_stats mshstats;
355 struct mesh_config mshcfg;
356 u8 mesh_seqnum[3];
357#endif
256 u16 aid; 358 u16 aid;
257 u16 ap_capab, capab; 359 u16 ap_capab, capab;
258 u8 *extra_ie; /* to be added to the end of AssocReq */ 360 u8 *extra_ie; /* to be added to the end of AssocReq */
@@ -282,16 +384,34 @@ struct ieee80211_if_sta {
282 384
283 unsigned long ibss_join_req; 385 unsigned long ibss_join_req;
284 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */ 386 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
285 u32 supp_rates_bits; 387 u32 supp_rates_bits[IEEE80211_NUM_BANDS];
286 388
287 int wmm_last_param_set; 389 int wmm_last_param_set;
390 int num_beacons; /* number of TXed beacon frames by this STA */
288}; 391};
289 392
393static inline void ieee80211_if_sta_set_mesh_id(struct ieee80211_if_sta *ifsta,
394 u8 mesh_id_len, u8 *mesh_id)
395{
396#ifdef CONFIG_MAC80211_MESH
397 ifsta->mesh_id_len = mesh_id_len;
398 memcpy(ifsta->mesh_id, mesh_id, mesh_id_len);
399#endif
400}
401
402#ifdef CONFIG_MAC80211_MESH
403#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
404 do { (sta)->mshstats.name++; } while (0)
405#else
406#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
407 do { } while (0)
408#endif
290 409
291/* flags used in struct ieee80211_sub_if_data.flags */ 410/* flags used in struct ieee80211_sub_if_data.flags */
292#define IEEE80211_SDATA_ALLMULTI BIT(0) 411#define IEEE80211_SDATA_ALLMULTI BIT(0)
293#define IEEE80211_SDATA_PROMISC BIT(1) 412#define IEEE80211_SDATA_PROMISC BIT(1)
294#define IEEE80211_SDATA_USERSPACE_MLME BIT(2) 413#define IEEE80211_SDATA_USERSPACE_MLME BIT(2)
414#define IEEE80211_SDATA_OPERATING_GMODE BIT(3)
295struct ieee80211_sub_if_data { 415struct ieee80211_sub_if_data {
296 struct list_head list; 416 struct list_head list;
297 417
@@ -306,11 +426,11 @@ struct ieee80211_sub_if_data {
306 unsigned int flags; 426 unsigned int flags;
307 427
308 int drop_unencrypted; 428 int drop_unencrypted;
429
309 /* 430 /*
310 * IEEE 802.1X Port access control in effect, 431 * basic rates of this AP or the AP we're associated to
311 * drop packets to/from unauthorized port
312 */ 432 */
313 int ieee802_1x_pac; 433 u64 basic_rates;
314 434
315 u16 sequence; 435 u16 sequence;
316 436
@@ -338,6 +458,7 @@ struct ieee80211_sub_if_data {
338 struct ieee80211_if_wds wds; 458 struct ieee80211_if_wds wds;
339 struct ieee80211_if_vlan vlan; 459 struct ieee80211_if_vlan vlan;
340 struct ieee80211_if_sta sta; 460 struct ieee80211_if_sta sta;
461 u32 mntr_flags;
341 } u; 462 } u;
342 int channel_use; 463 int channel_use;
343 int channel_use_raw; 464 int channel_use_raw;
@@ -348,7 +469,6 @@ struct ieee80211_sub_if_data {
348 struct { 469 struct {
349 struct dentry *channel_use; 470 struct dentry *channel_use;
350 struct dentry *drop_unencrypted; 471 struct dentry *drop_unencrypted;
351 struct dentry *ieee802_1x_pac;
352 struct dentry *state; 472 struct dentry *state;
353 struct dentry *bssid; 473 struct dentry *bssid;
354 struct dentry *prev_bssid; 474 struct dentry *prev_bssid;
@@ -363,11 +483,11 @@ struct ieee80211_sub_if_data {
363 struct dentry *auth_alg; 483 struct dentry *auth_alg;
364 struct dentry *auth_transaction; 484 struct dentry *auth_transaction;
365 struct dentry *flags; 485 struct dentry *flags;
486 struct dentry *num_beacons_sta;
366 } sta; 487 } sta;
367 struct { 488 struct {
368 struct dentry *channel_use; 489 struct dentry *channel_use;
369 struct dentry *drop_unencrypted; 490 struct dentry *drop_unencrypted;
370 struct dentry *ieee802_1x_pac;
371 struct dentry *num_sta_ps; 491 struct dentry *num_sta_ps;
372 struct dentry *dtim_count; 492 struct dentry *dtim_count;
373 struct dentry *num_beacons; 493 struct dentry *num_beacons;
@@ -378,19 +498,46 @@ struct ieee80211_sub_if_data {
378 struct { 498 struct {
379 struct dentry *channel_use; 499 struct dentry *channel_use;
380 struct dentry *drop_unencrypted; 500 struct dentry *drop_unencrypted;
381 struct dentry *ieee802_1x_pac;
382 struct dentry *peer; 501 struct dentry *peer;
383 } wds; 502 } wds;
384 struct { 503 struct {
385 struct dentry *channel_use; 504 struct dentry *channel_use;
386 struct dentry *drop_unencrypted; 505 struct dentry *drop_unencrypted;
387 struct dentry *ieee802_1x_pac;
388 } vlan; 506 } vlan;
389 struct { 507 struct {
390 struct dentry *mode; 508 struct dentry *mode;
391 } monitor; 509 } monitor;
392 struct dentry *default_key; 510 struct dentry *default_key;
393 } debugfs; 511 } debugfs;
512
513#ifdef CONFIG_MAC80211_MESH
514 struct dentry *mesh_stats_dir;
515 struct {
516 struct dentry *fwded_frames;
517 struct dentry *dropped_frames_ttl;
518 struct dentry *dropped_frames_no_route;
519 struct dentry *estab_plinks;
520 struct timer_list mesh_path_timer;
521 } mesh_stats;
522
523 struct dentry *mesh_config_dir;
524 struct {
525 struct dentry *dot11MeshRetryTimeout;
526 struct dentry *dot11MeshConfirmTimeout;
527 struct dentry *dot11MeshHoldingTimeout;
528 struct dentry *dot11MeshMaxRetries;
529 struct dentry *dot11MeshTTL;
530 struct dentry *auto_open_plinks;
531 struct dentry *dot11MeshMaxPeerLinks;
532 struct dentry *dot11MeshHWMPactivePathTimeout;
533 struct dentry *dot11MeshHWMPpreqMinInterval;
534 struct dentry *dot11MeshHWMPnetDiameterTraversalTime;
535 struct dentry *dot11MeshHWMPmaxPREQretries;
536 struct dentry *path_refresh_time;
537 struct dentry *min_discovery_timeout;
538 } mesh_config;
539#endif
540
394#endif 541#endif
395 /* must be last, dynamically sized area in this! */ 542 /* must be last, dynamically sized area in this! */
396 struct ieee80211_vif vif; 543 struct ieee80211_vif vif;
@@ -407,6 +554,8 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
407enum { 554enum {
408 IEEE80211_RX_MSG = 1, 555 IEEE80211_RX_MSG = 1,
409 IEEE80211_TX_STATUS_MSG = 2, 556 IEEE80211_TX_STATUS_MSG = 2,
557 IEEE80211_DELBA_MSG = 3,
558 IEEE80211_ADDBA_MSG = 4,
410}; 559};
411 560
412struct ieee80211_local { 561struct ieee80211_local {
@@ -417,15 +566,15 @@ struct ieee80211_local {
417 566
418 const struct ieee80211_ops *ops; 567 const struct ieee80211_ops *ops;
419 568
420 /* List of registered struct ieee80211_hw_mode */
421 struct list_head modes_list;
422
423 struct net_device *mdev; /* wmaster# - "master" 802.11 device */ 569 struct net_device *mdev; /* wmaster# - "master" 802.11 device */
424 int open_count; 570 int open_count;
425 int monitors; 571 int monitors, cooked_mntrs;
572 /* number of interfaces with corresponding FIF_ flags */
573 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss;
426 unsigned int filter_flags; /* FIF_* */ 574 unsigned int filter_flags; /* FIF_* */
427 struct iw_statistics wstats; 575 struct iw_statistics wstats;
428 u8 wstats_flags; 576 u8 wstats_flags;
577 bool tim_in_locked_section; /* see ieee80211_beacon_get() */
429 int tx_headroom; /* required headroom for hardware/radiotap */ 578 int tx_headroom; /* required headroom for hardware/radiotap */
430 579
431 enum { 580 enum {
@@ -443,15 +592,21 @@ struct ieee80211_local {
443 struct sk_buff_head skb_queue; 592 struct sk_buff_head skb_queue;
444 struct sk_buff_head skb_queue_unreliable; 593 struct sk_buff_head skb_queue_unreliable;
445 594
446 /* Station data structures */ 595 /* Station data */
447 rwlock_t sta_lock; /* protects STA data structures */ 596 /*
448 int num_sta; /* number of stations in sta_list */ 597 * The lock only protects the list, hash, timer and counter
598 * against manipulation, reads are done in RCU. Additionally,
599 * the lock protects each BSS's TIM bitmap and a few items
600 * in a STA info structure.
601 */
602 spinlock_t sta_lock;
603 unsigned long num_sta;
449 struct list_head sta_list; 604 struct list_head sta_list;
450 struct sta_info *sta_hash[STA_HASH_SIZE]; 605 struct sta_info *sta_hash[STA_HASH_SIZE];
451 struct timer_list sta_cleanup; 606 struct timer_list sta_cleanup;
452 607
453 unsigned long state[NUM_TX_DATA_QUEUES]; 608 unsigned long state[NUM_TX_DATA_QUEUES_AMPDU];
454 struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES]; 609 struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES_AMPDU];
455 struct tasklet_struct tx_pending_tasklet; 610 struct tasklet_struct tx_pending_tasklet;
456 611
457 /* number of interfaces with corresponding IFF_ flags */ 612 /* number of interfaces with corresponding IFF_ flags */
@@ -459,11 +614,6 @@ struct ieee80211_local {
459 614
460 struct rate_control_ref *rate_ctrl; 615 struct rate_control_ref *rate_ctrl;
461 616
462 /* Supported and basic rate filters for different modes. These are
463 * pointers to -1 terminated lists and rates in 100 kbps units. */
464 int *supp_rates[NUM_IEEE80211_MODES];
465 int *basic_rates[NUM_IEEE80211_MODES];
466
467 int rts_threshold; 617 int rts_threshold;
468 int fragmentation_threshold; 618 int fragmentation_threshold;
469 int short_retry_limit; /* dot11ShortRetryLimit */ 619 int short_retry_limit; /* dot11ShortRetryLimit */
@@ -477,21 +627,18 @@ struct ieee80211_local {
477 * deliver multicast frames both back to wireless 627 * deliver multicast frames both back to wireless
478 * media and to the local net stack */ 628 * media and to the local net stack */
479 629
480 ieee80211_rx_handler *rx_pre_handlers;
481 ieee80211_rx_handler *rx_handlers;
482 ieee80211_tx_handler *tx_handlers;
483
484 struct list_head interfaces; 630 struct list_head interfaces;
485 631
486 bool sta_sw_scanning; 632 bool sta_sw_scanning;
487 bool sta_hw_scanning; 633 bool sta_hw_scanning;
488 int scan_channel_idx; 634 int scan_channel_idx;
635 enum ieee80211_band scan_band;
636
489 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 637 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
490 unsigned long last_scan_completed; 638 unsigned long last_scan_completed;
491 struct delayed_work scan_work; 639 struct delayed_work scan_work;
492 struct net_device *scan_dev; 640 struct net_device *scan_dev;
493 struct ieee80211_channel *oper_channel, *scan_channel; 641 struct ieee80211_channel *oper_channel, *scan_channel;
494 struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
495 u8 scan_ssid[IEEE80211_MAX_SSID_LEN]; 642 u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
496 size_t scan_ssid_len; 643 size_t scan_ssid_len;
497 struct list_head sta_bss_list; 644 struct list_head sta_bss_list;
@@ -560,14 +707,8 @@ struct ieee80211_local {
560 int wifi_wme_noack_test; 707 int wifi_wme_noack_test;
561 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 708 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
562 709
563 unsigned int enabled_modes; /* bitfield of allowed modes;
564 * (1 << MODE_*) */
565 unsigned int hw_modes; /* bitfield of supported hardware modes;
566 * (1 << MODE_*) */
567
568#ifdef CONFIG_MAC80211_DEBUGFS 710#ifdef CONFIG_MAC80211_DEBUGFS
569 struct local_debugfsdentries { 711 struct local_debugfsdentries {
570 struct dentry *channel;
571 struct dentry *frequency; 712 struct dentry *frequency;
572 struct dentry *antenna_sel_tx; 713 struct dentry *antenna_sel_tx;
573 struct dentry *antenna_sel_rx; 714 struct dentry *antenna_sel_rx;
@@ -577,9 +718,7 @@ struct ieee80211_local {
577 struct dentry *short_retry_limit; 718 struct dentry *short_retry_limit;
578 struct dentry *long_retry_limit; 719 struct dentry *long_retry_limit;
579 struct dentry *total_ps_buffered; 720 struct dentry *total_ps_buffered;
580 struct dentry *mode;
581 struct dentry *wep_iv; 721 struct dentry *wep_iv;
582 struct dentry *modes;
583 struct dentry *statistics; 722 struct dentry *statistics;
584 struct local_debugfsdentries_statsdentries { 723 struct local_debugfsdentries_statsdentries {
585 struct dentry *transmitted_fragment_count; 724 struct dentry *transmitted_fragment_count;
@@ -627,6 +766,63 @@ struct ieee80211_local {
627#endif 766#endif
628}; 767};
629 768
769/* this struct represents 802.11n's RA/TID combination */
770struct ieee80211_ra_tid {
771 u8 ra[ETH_ALEN];
772 u16 tid;
773};
774
775/* Parsed Information Elements */
776struct ieee802_11_elems {
777 /* pointers to IEs */
778 u8 *ssid;
779 u8 *supp_rates;
780 u8 *fh_params;
781 u8 *ds_params;
782 u8 *cf_params;
783 u8 *tim;
784 u8 *ibss_params;
785 u8 *challenge;
786 u8 *wpa;
787 u8 *rsn;
788 u8 *erp_info;
789 u8 *ext_supp_rates;
790 u8 *wmm_info;
791 u8 *wmm_param;
792 u8 *ht_cap_elem;
793 u8 *ht_info_elem;
794 u8 *mesh_config;
795 u8 *mesh_id;
796 u8 *peer_link;
797 u8 *preq;
798 u8 *prep;
799 u8 *perr;
800
801 /* length of them, respectively */
802 u8 ssid_len;
803 u8 supp_rates_len;
804 u8 fh_params_len;
805 u8 ds_params_len;
806 u8 cf_params_len;
807 u8 tim_len;
808 u8 ibss_params_len;
809 u8 challenge_len;
810 u8 wpa_len;
811 u8 rsn_len;
812 u8 erp_info_len;
813 u8 ext_supp_rates_len;
814 u8 wmm_info_len;
815 u8 wmm_param_len;
816 u8 ht_cap_elem_len;
817 u8 ht_info_elem_len;
818 u8 mesh_config_len;
819 u8 mesh_id_len;
820 u8 peer_link_len;
821 u8 preq_len;
822 u8 prep_len;
823 u8 perr_len;
824};
825
630static inline struct ieee80211_local *hw_to_local( 826static inline struct ieee80211_local *hw_to_local(
631 struct ieee80211_hw *hw) 827 struct ieee80211_hw *hw)
632{ 828{
@@ -650,57 +846,6 @@ struct sta_attribute {
650 ssize_t (*store)(struct sta_info *, const char *buf, size_t count); 846 ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
651}; 847};
652 848
653static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
654{
655 /*
656 * This format has been mandated by the IEEE specifications,
657 * so this line may not be changed to use the __set_bit() format.
658 */
659 bss->tim[aid / 8] |= (1 << (aid % 8));
660}
661
662static inline void bss_tim_set(struct ieee80211_local *local,
663 struct ieee80211_if_ap *bss, u16 aid)
664{
665 read_lock_bh(&local->sta_lock);
666 __bss_tim_set(bss, aid);
667 read_unlock_bh(&local->sta_lock);
668}
669
670static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
671{
672 /*
673 * This format has been mandated by the IEEE specifications,
674 * so this line may not be changed to use the __clear_bit() format.
675 */
676 bss->tim[aid / 8] &= ~(1 << (aid % 8));
677}
678
679static inline void bss_tim_clear(struct ieee80211_local *local,
680 struct ieee80211_if_ap *bss, u16 aid)
681{
682 read_lock_bh(&local->sta_lock);
683 __bss_tim_clear(bss, aid);
684 read_unlock_bh(&local->sta_lock);
685}
686
687/**
688 * ieee80211_is_erp_rate - Check if a rate is an ERP rate
689 * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
690 * @rate: Transmission rate to check, in 100 kbps
691 *
692 * Check if a given rate is an Extended Rate PHY (ERP) rate.
693 */
694static inline int ieee80211_is_erp_rate(int phymode, int rate)
695{
696 if (phymode == MODE_IEEE80211G) {
697 if (rate != 10 && rate != 20 &&
698 rate != 55 && rate != 110)
699 return 1;
700 }
701 return 0;
702}
703
704static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr) 849static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
705{ 850{
706 return compare_ether_addr(raddr, addr) == 0 || 851 return compare_ether_addr(raddr, addr) == 0 ||
@@ -712,13 +857,8 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
712int ieee80211_hw_config(struct ieee80211_local *local); 857int ieee80211_hw_config(struct ieee80211_local *local);
713int ieee80211_if_config(struct net_device *dev); 858int ieee80211_if_config(struct net_device *dev);
714int ieee80211_if_config_beacon(struct net_device *dev); 859int ieee80211_if_config_beacon(struct net_device *dev);
715void ieee80211_prepare_rates(struct ieee80211_local *local, 860void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
716 struct ieee80211_hw_mode *mode);
717void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
718int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
719void ieee80211_if_setup(struct net_device *dev); 861void ieee80211_if_setup(struct net_device *dev);
720struct ieee80211_rate *ieee80211_get_rate(struct ieee80211_local *local,
721 int phymode, int hwrate);
722int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht, 862int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
723 struct ieee80211_ht_info *req_ht_cap, 863 struct ieee80211_ht_info *req_ht_cap,
724 struct ieee80211_ht_bss_info *req_bss_cap); 864 struct ieee80211_ht_bss_info *req_bss_cap);
@@ -749,8 +889,9 @@ extern const struct iw_handler_def ieee80211_iw_handler_def;
749/* ieee80211_ioctl.c */ 889/* ieee80211_ioctl.c */
750int ieee80211_set_compression(struct ieee80211_local *local, 890int ieee80211_set_compression(struct ieee80211_local *local,
751 struct net_device *dev, struct sta_info *sta); 891 struct net_device *dev, struct sta_info *sta);
752int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq); 892int ieee80211_set_freq(struct ieee80211_local *local, int freq);
753/* ieee80211_sta.c */ 893/* ieee80211_sta.c */
894#define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
754void ieee80211_sta_timer(unsigned long data); 895void ieee80211_sta_timer(unsigned long data);
755void ieee80211_sta_work(struct work_struct *work); 896void ieee80211_sta_work(struct work_struct *work);
756void ieee80211_sta_scan_work(struct work_struct *work); 897void ieee80211_sta_scan_work(struct work_struct *work);
@@ -763,9 +904,9 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
763void ieee80211_sta_req_auth(struct net_device *dev, 904void ieee80211_sta_req_auth(struct net_device *dev,
764 struct ieee80211_if_sta *ifsta); 905 struct ieee80211_if_sta *ifsta);
765int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len); 906int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
766ieee80211_txrx_result ieee80211_sta_rx_scan(struct net_device *dev, 907ieee80211_rx_result ieee80211_sta_rx_scan(
767 struct sk_buff *skb, 908 struct net_device *dev, struct sk_buff *skb,
768 struct ieee80211_rx_status *rx_status); 909 struct ieee80211_rx_status *rx_status);
769void ieee80211_rx_bss_list_init(struct net_device *dev); 910void ieee80211_rx_bss_list_init(struct net_device *dev);
770void ieee80211_rx_bss_list_deinit(struct net_device *dev); 911void ieee80211_rx_bss_list_deinit(struct net_device *dev);
771int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len); 912int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
@@ -782,12 +923,34 @@ int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
782int ieee80211_ht_addt_info_ie_to_ht_bss_info( 923int ieee80211_ht_addt_info_ie_to_ht_bss_info(
783 struct ieee80211_ht_addt_info *ht_add_info_ie, 924 struct ieee80211_ht_addt_info *ht_add_info_ie,
784 struct ieee80211_ht_bss_info *bss_info); 925 struct ieee80211_ht_bss_info *bss_info);
926void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
927 u16 tid, u8 dialog_token, u16 start_seq_num,
928 u16 agg_size, u16 timeout);
929void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
930 u16 initiator, u16 reason_code);
785void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *da, 931void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *da,
786 u16 tid, u16 initiator, u16 reason); 932 u16 tid, u16 initiator, u16 reason);
787void sta_rx_agg_session_timer_expired(unsigned long data); 933void sta_rx_agg_session_timer_expired(unsigned long data);
934void sta_addba_resp_timer_expired(unsigned long data);
935u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
936 struct ieee802_11_elems *elems,
937 enum ieee80211_band band);
938void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
939 int encrypt);
940void ieee802_11_parse_elems(u8 *start, size_t len,
941 struct ieee802_11_elems *elems);
942
943#ifdef CONFIG_MAC80211_MESH
944void ieee80211_start_mesh(struct net_device *dev);
945#else
946static inline void ieee80211_start_mesh(struct net_device *dev)
947{}
948#endif
949
788/* ieee80211_iface.c */ 950/* ieee80211_iface.c */
789int ieee80211_if_add(struct net_device *dev, const char *name, 951int ieee80211_if_add(struct net_device *dev, const char *name,
790 struct net_device **new_dev, int type); 952 struct net_device **new_dev, int type,
953 struct vif_params *params);
791void ieee80211_if_set_type(struct net_device *dev, int type); 954void ieee80211_if_set_type(struct net_device *dev, int type);
792void ieee80211_if_reinit(struct net_device *dev); 955void ieee80211_if_reinit(struct net_device *dev);
793void __ieee80211_if_del(struct ieee80211_local *local, 956void __ieee80211_if_del(struct ieee80211_local *local,
@@ -796,16 +959,7 @@ int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
796void ieee80211_if_free(struct net_device *dev); 959void ieee80211_if_free(struct net_device *dev);
797void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata); 960void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
798 961
799/* regdomain.c */
800void ieee80211_regdomain_init(void);
801void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode);
802
803/* rx handling */
804extern ieee80211_rx_handler ieee80211_rx_pre_handlers[];
805extern ieee80211_rx_handler ieee80211_rx_handlers[];
806
807/* tx handling */ 962/* tx handling */
808extern ieee80211_tx_handler ieee80211_tx_handlers[];
809void ieee80211_clear_tx_pending(struct ieee80211_local *local); 963void ieee80211_clear_tx_pending(struct ieee80211_local *local);
810void ieee80211_tx_pending(unsigned long data); 964void ieee80211_tx_pending(unsigned long data);
811int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev); 965int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
diff --git a/net/mac80211/ieee80211_iface.c b/net/mac80211/ieee80211_iface.c
index 92f1eb2da311..80954a512185 100644
--- a/net/mac80211/ieee80211_iface.c
+++ b/net/mac80211/ieee80211_iface.c
@@ -15,6 +15,7 @@
15#include "ieee80211_i.h" 15#include "ieee80211_i.h"
16#include "sta_info.h" 16#include "sta_info.h"
17#include "debugfs_netdev.h" 17#include "debugfs_netdev.h"
18#include "mesh.h"
18 19
19void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata) 20void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
20{ 21{
@@ -39,7 +40,8 @@ static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata)
39 40
40/* Must be called with rtnl lock held. */ 41/* Must be called with rtnl lock held. */
41int ieee80211_if_add(struct net_device *dev, const char *name, 42int ieee80211_if_add(struct net_device *dev, const char *name,
42 struct net_device **new_dev, int type) 43 struct net_device **new_dev, int type,
44 struct vif_params *params)
43{ 45{
44 struct net_device *ndev; 46 struct net_device *ndev;
45 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 47 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -78,6 +80,12 @@ int ieee80211_if_add(struct net_device *dev, const char *name,
78 ieee80211_debugfs_add_netdev(sdata); 80 ieee80211_debugfs_add_netdev(sdata);
79 ieee80211_if_set_type(ndev, type); 81 ieee80211_if_set_type(ndev, type);
80 82
83 if (ieee80211_vif_is_mesh(&sdata->vif) &&
84 params && params->mesh_id_len)
85 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
86 params->mesh_id_len,
87 params->mesh_id);
88
81 /* we're under RTNL so all this is fine */ 89 /* we're under RTNL so all this is fine */
82 if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) { 90 if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
83 __ieee80211_if_del(local, sdata); 91 __ieee80211_if_del(local, sdata);
@@ -118,6 +126,8 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
118 sdata->bss = NULL; 126 sdata->bss = NULL;
119 sdata->vif.type = type; 127 sdata->vif.type = type;
120 128
129 sdata->basic_rates = 0;
130
121 switch (type) { 131 switch (type) {
122 case IEEE80211_IF_TYPE_WDS: 132 case IEEE80211_IF_TYPE_WDS:
123 /* nothing special */ 133 /* nothing special */
@@ -132,6 +142,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
132 sdata->bss = &sdata->u.ap; 142 sdata->bss = &sdata->u.ap;
133 INIT_LIST_HEAD(&sdata->u.ap.vlans); 143 INIT_LIST_HEAD(&sdata->u.ap.vlans);
134 break; 144 break;
145 case IEEE80211_IF_TYPE_MESH_POINT:
135 case IEEE80211_IF_TYPE_STA: 146 case IEEE80211_IF_TYPE_STA:
136 case IEEE80211_IF_TYPE_IBSS: { 147 case IEEE80211_IF_TYPE_IBSS: {
137 struct ieee80211_sub_if_data *msdata; 148 struct ieee80211_sub_if_data *msdata;
@@ -153,15 +164,20 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
153 164
154 msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev); 165 msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
155 sdata->bss = &msdata->u.ap; 166 sdata->bss = &msdata->u.ap;
167
168 if (ieee80211_vif_is_mesh(&sdata->vif))
169 ieee80211_mesh_init_sdata(sdata);
156 break; 170 break;
157 } 171 }
158 case IEEE80211_IF_TYPE_MNTR: 172 case IEEE80211_IF_TYPE_MNTR:
159 dev->type = ARPHRD_IEEE80211_RADIOTAP; 173 dev->type = ARPHRD_IEEE80211_RADIOTAP;
160 dev->hard_start_xmit = ieee80211_monitor_start_xmit; 174 dev->hard_start_xmit = ieee80211_monitor_start_xmit;
175 sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
176 MONITOR_FLAG_OTHER_BSS;
161 break; 177 break;
162 default: 178 default:
163 printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x", 179 printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
164 dev->name, __FUNCTION__, type); 180 dev->name, __func__, type);
165 } 181 }
166 ieee80211_debugfs_change_if_type(sdata, oldtype); 182 ieee80211_debugfs_change_if_type(sdata, oldtype);
167} 183}
@@ -171,8 +187,8 @@ void ieee80211_if_reinit(struct net_device *dev)
171{ 187{
172 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 188 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
173 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 189 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
174 struct sta_info *sta;
175 struct sk_buff *skb; 190 struct sk_buff *skb;
191 int flushed;
176 192
177 ASSERT_RTNL(); 193 ASSERT_RTNL();
178 194
@@ -180,6 +196,10 @@ void ieee80211_if_reinit(struct net_device *dev)
180 196
181 ieee80211_if_sdata_deinit(sdata); 197 ieee80211_if_sdata_deinit(sdata);
182 198
199 /* Need to handle mesh specially to allow eliding the function call */
200 if (ieee80211_vif_is_mesh(&sdata->vif))
201 mesh_rmc_free(dev);
202
183 switch (sdata->vif.type) { 203 switch (sdata->vif.type) {
184 case IEEE80211_IF_TYPE_INVALID: 204 case IEEE80211_IF_TYPE_INVALID:
185 /* cannot happen */ 205 /* cannot happen */
@@ -189,6 +209,7 @@ void ieee80211_if_reinit(struct net_device *dev)
189 /* Remove all virtual interfaces that use this BSS 209 /* Remove all virtual interfaces that use this BSS
190 * as their sdata->bss */ 210 * as their sdata->bss */
191 struct ieee80211_sub_if_data *tsdata, *n; 211 struct ieee80211_sub_if_data *tsdata, *n;
212 struct beacon_data *beacon;
192 213
193 list_for_each_entry_safe(tsdata, n, &local->interfaces, list) { 214 list_for_each_entry_safe(tsdata, n, &local->interfaces, list) {
194 if (tsdata != sdata && tsdata->bss == &sdata->u.ap) { 215 if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
@@ -206,7 +227,10 @@ void ieee80211_if_reinit(struct net_device *dev)
206 } 227 }
207 } 228 }
208 229
209 kfree(sdata->u.ap.beacon); 230 beacon = sdata->u.ap.beacon;
231 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
232 synchronize_rcu();
233 kfree(beacon);
210 234
211 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) { 235 while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
212 local->total_ps_buffered--; 236 local->total_ps_buffered--;
@@ -216,17 +240,9 @@ void ieee80211_if_reinit(struct net_device *dev)
216 break; 240 break;
217 } 241 }
218 case IEEE80211_IF_TYPE_WDS: 242 case IEEE80211_IF_TYPE_WDS:
219 sta = sta_info_get(local, sdata->u.wds.remote_addr); 243 /* nothing to do */
220 if (sta) {
221 sta_info_free(sta);
222 sta_info_put(sta);
223 } else {
224#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
225 printk(KERN_DEBUG "%s: Someone had deleted my STA "
226 "entry for the WDS link\n", dev->name);
227#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
228 }
229 break; 244 break;
245 case IEEE80211_IF_TYPE_MESH_POINT:
230 case IEEE80211_IF_TYPE_STA: 246 case IEEE80211_IF_TYPE_STA:
231 case IEEE80211_IF_TYPE_IBSS: 247 case IEEE80211_IF_TYPE_IBSS:
232 kfree(sdata->u.sta.extra_ie); 248 kfree(sdata->u.sta.extra_ie);
@@ -249,8 +265,8 @@ void ieee80211_if_reinit(struct net_device *dev)
249 break; 265 break;
250 } 266 }
251 267
252 /* remove all STAs that are bound to this virtual interface */ 268 flushed = sta_info_flush(local, sdata);
253 sta_info_flush(local, dev); 269 WARN_ON(flushed);
254 270
255 memset(&sdata->u, 0, sizeof(sdata->u)); 271 memset(&sdata->u, 0, sizeof(sdata->u));
256 ieee80211_if_sdata_init(sdata); 272 ieee80211_if_sdata_init(sdata);
diff --git a/net/mac80211/ieee80211_ioctl.c b/net/mac80211/ieee80211_ioctl.c
index 5024d3733834..1d91575a0fe9 100644
--- a/net/mac80211/ieee80211_ioctl.c
+++ b/net/mac80211/ieee80211_ioctl.c
@@ -33,7 +33,6 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
33 size_t key_len) 33 size_t key_len)
34{ 34{
35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
36 int ret = 0;
37 struct sta_info *sta; 36 struct sta_info *sta;
38 struct ieee80211_key *key; 37 struct ieee80211_key *key;
39 struct ieee80211_sub_if_data *sdata; 38 struct ieee80211_sub_if_data *sdata;
@@ -46,59 +45,55 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
46 return -EINVAL; 45 return -EINVAL;
47 } 46 }
48 47
49 if (is_broadcast_ether_addr(sta_addr)) { 48 if (remove) {
50 sta = NULL; 49 if (is_broadcast_ether_addr(sta_addr)) {
51 key = sdata->keys[idx]; 50 key = sdata->keys[idx];
52 } else { 51 } else {
53 set_tx_key = 0; 52 sta = sta_info_get(local, sta_addr);
54 /* 53 if (!sta)
55 * According to the standard, the key index of a pairwise 54 return -ENOENT;
56 * key must be zero. However, some AP are broken when it 55 key = sta->key;
57 * comes to WEP key indices, so we work around this.
58 */
59 if (idx != 0 && alg != ALG_WEP) {
60 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
61 "individual key\n", dev->name);
62 return -EINVAL;
63 } 56 }
64 57
65 sta = sta_info_get(local, sta_addr); 58 if (!key)
66 if (!sta) {
67#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
68 DECLARE_MAC_BUF(mac);
69 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
70 "%s\n",
71 dev->name, print_mac(mac, sta_addr));
72#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
73
74 return -ENOENT; 59 return -ENOENT;
75 }
76 60
77 key = sta->key;
78 }
79
80 if (remove) {
81 ieee80211_key_free(key); 61 ieee80211_key_free(key);
82 key = NULL; 62 return 0;
83 } else { 63 } else {
84 /* 64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
85 * Automatically frees any old key if present. 65 if (!key)
86 */ 66 return -ENOMEM;
87 key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key); 67
88 if (!key) { 68 sta = NULL;
89 ret = -ENOMEM; 69
90 goto err_out; 70 if (!is_broadcast_ether_addr(sta_addr)) {
71 set_tx_key = 0;
72 /*
73 * According to the standard, the key index of a
74 * pairwise key must be zero. However, some AP are
75 * broken when it comes to WEP key indices, so we
76 * work around this.
77 */
78 if (idx != 0 && alg != ALG_WEP) {
79 ieee80211_key_free(key);
80 return -EINVAL;
81 }
82
83 sta = sta_info_get(local, sta_addr);
84 if (!sta) {
85 ieee80211_key_free(key);
86 return -ENOENT;
87 }
91 } 88 }
92 }
93 89
94 if (set_tx_key || (!sta && !sdata->default_key && key)) 90 ieee80211_key_link(key, sdata, sta);
95 ieee80211_set_default_key(sdata, idx);
96 91
97 ret = 0; 92 if (set_tx_key || (!sta && !sdata->default_key && key))
98 err_out: 93 ieee80211_set_default_key(sdata, idx);
99 if (sta) 94 }
100 sta_info_put(sta); 95
101 return ret; 96 return 0;
102} 97}
103 98
104static int ieee80211_ioctl_siwgenie(struct net_device *dev, 99static int ieee80211_ioctl_siwgenie(struct net_device *dev,
@@ -129,22 +124,7 @@ static int ieee80211_ioctl_giwname(struct net_device *dev,
129 struct iw_request_info *info, 124 struct iw_request_info *info,
130 char *name, char *extra) 125 char *name, char *extra)
131{ 126{
132 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 127 strcpy(name, "IEEE 802.11");
133
134 switch (local->hw.conf.phymode) {
135 case MODE_IEEE80211A:
136 strcpy(name, "IEEE 802.11a");
137 break;
138 case MODE_IEEE80211B:
139 strcpy(name, "IEEE 802.11b");
140 break;
141 case MODE_IEEE80211G:
142 strcpy(name, "IEEE 802.11g");
143 break;
144 default:
145 strcpy(name, "IEEE 802.11");
146 break;
147 }
148 128
149 return 0; 129 return 0;
150} 130}
@@ -156,7 +136,7 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
156{ 136{
157 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 137 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
158 struct iw_range *range = (struct iw_range *) extra; 138 struct iw_range *range = (struct iw_range *) extra;
159 struct ieee80211_hw_mode *mode = NULL; 139 enum ieee80211_band band;
160 int c = 0; 140 int c = 0;
161 141
162 data->length = sizeof(struct iw_range); 142 data->length = sizeof(struct iw_range);
@@ -191,24 +171,27 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
191 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 171 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
192 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 172 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
193 173
194 list_for_each_entry(mode, &local->modes_list, list) {
195 int i = 0;
196 174
197 if (!(local->enabled_modes & (1 << mode->mode)) || 175 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
198 (local->hw_modes & local->enabled_modes & 176 int i;
199 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B)) 177 struct ieee80211_supported_band *sband;
178
179 sband = local->hw.wiphy->bands[band];
180
181 if (!sband)
200 continue; 182 continue;
201 183
202 while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) { 184 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
203 struct ieee80211_channel *chan = &mode->channels[i]; 185 struct ieee80211_channel *chan = &sband->channels[i];
204 186
205 if (chan->flag & IEEE80211_CHAN_W_SCAN) { 187 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
206 range->freq[c].i = chan->chan; 188 range->freq[c].i =
207 range->freq[c].m = chan->freq * 100000; 189 ieee80211_frequency_to_channel(
208 range->freq[c].e = 1; 190 chan->center_freq);
191 range->freq[c].m = chan->center_freq;
192 range->freq[c].e = 6;
209 c++; 193 c++;
210 } 194 }
211 i++;
212 } 195 }
213 } 196 }
214 range->num_channels = c; 197 range->num_channels = c;
@@ -294,22 +277,29 @@ static int ieee80211_ioctl_giwmode(struct net_device *dev,
294 return 0; 277 return 0;
295} 278}
296 279
297int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq) 280int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
298{ 281{
299 struct ieee80211_hw_mode *mode; 282 int set = 0;
300 int c, set = 0;
301 int ret = -EINVAL; 283 int ret = -EINVAL;
284 enum ieee80211_band band;
285 struct ieee80211_supported_band *sband;
286 int i;
287
288 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
289 sband = local->hw.wiphy->bands[band];
302 290
303 list_for_each_entry(mode, &local->modes_list, list) { 291 if (!sband)
304 if (!(local->enabled_modes & (1 << mode->mode)))
305 continue; 292 continue;
306 for (c = 0; c < mode->num_channels; c++) { 293
307 struct ieee80211_channel *chan = &mode->channels[c]; 294 for (i = 0; i < sband->n_channels; i++) {
308 if (chan->flag & IEEE80211_CHAN_W_SCAN && 295 struct ieee80211_channel *chan = &sband->channels[i];
309 ((chan->chan == channel) || (chan->freq == freq))) { 296
310 local->oper_channel = chan; 297 if (chan->flags & IEEE80211_CHAN_DISABLED)
311 local->oper_hw_mode = mode; 298 continue;
299
300 if (chan->center_freq == freqMHz) {
312 set = 1; 301 set = 1;
302 local->oper_channel = chan;
313 break; 303 break;
314 } 304 }
315 } 305 }
@@ -347,13 +337,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
347 IEEE80211_STA_AUTO_CHANNEL_SEL; 337 IEEE80211_STA_AUTO_CHANNEL_SEL;
348 return 0; 338 return 0;
349 } else 339 } else
350 return ieee80211_set_channel(local, freq->m, -1); 340 return ieee80211_set_freq(local,
341 ieee80211_channel_to_frequency(freq->m));
351 } else { 342 } else {
352 int i, div = 1000000; 343 int i, div = 1000000;
353 for (i = 0; i < freq->e; i++) 344 for (i = 0; i < freq->e; i++)
354 div /= 10; 345 div /= 10;
355 if (div > 0) 346 if (div > 0)
356 return ieee80211_set_channel(local, -1, freq->m / div); 347 return ieee80211_set_freq(local, freq->m / div);
357 else 348 else
358 return -EINVAL; 349 return -EINVAL;
359 } 350 }
@@ -366,10 +357,7 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
366{ 357{
367 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
368 359
369 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level 360 freq->m = local->hw.conf.channel->center_freq;
370 * driver for the current channel with firmware-based management */
371
372 freq->m = local->hw.conf.freq;
373 freq->e = 6; 361 freq->e = 6;
374 362
375 return 0; 363 return 0;
@@ -480,10 +468,20 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
480 ieee80211_sta_req_auth(dev, &sdata->u.sta); 468 ieee80211_sta_req_auth(dev, &sdata->u.sta);
481 return 0; 469 return 0;
482 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) { 470 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
483 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data, 471 /*
484 ETH_ALEN) == 0) 472 * If it is necessary to update the WDS peer address
485 return 0; 473 * while the interface is running, then we need to do
486 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data); 474 * more work here, namely if it is running we need to
475 * add a new and remove the old STA entry, this is
476 * normally handled by _open() and _stop().
477 */
478 if (netif_running(dev))
479 return -EBUSY;
480
481 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
482 ETH_ALEN);
483
484 return 0;
487 } 485 }
488 486
489 return -EOPNOTSUPP; 487 return -EOPNOTSUPP;
@@ -526,6 +524,7 @@ static int ieee80211_ioctl_siwscan(struct net_device *dev,
526 524
527 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 525 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
528 sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 526 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
527 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
529 sdata->vif.type != IEEE80211_IF_TYPE_AP) 528 sdata->vif.type != IEEE80211_IF_TYPE_AP)
530 return -EOPNOTSUPP; 529 return -EOPNOTSUPP;
531 530
@@ -566,15 +565,17 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
566 struct iw_param *rate, char *extra) 565 struct iw_param *rate, char *extra)
567{ 566{
568 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 567 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
569 struct ieee80211_hw_mode *mode; 568 int i, err = -EINVAL;
570 int i;
571 u32 target_rate = rate->value / 100000; 569 u32 target_rate = rate->value / 100000;
572 struct ieee80211_sub_if_data *sdata; 570 struct ieee80211_sub_if_data *sdata;
571 struct ieee80211_supported_band *sband;
573 572
574 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 573 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
575 if (!sdata->bss) 574 if (!sdata->bss)
576 return -ENODEV; 575 return -ENODEV;
577 mode = local->oper_hw_mode; 576
577 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
578
578 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates 579 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
579 * target_rate = X, rate->fixed = 1 means only rate X 580 * target_rate = X, rate->fixed = 1 means only rate X
580 * target_rate = X, rate->fixed = 0 means all rates <= X */ 581 * target_rate = X, rate->fixed = 0 means all rates <= X */
@@ -582,18 +583,20 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
582 sdata->bss->force_unicast_rateidx = -1; 583 sdata->bss->force_unicast_rateidx = -1;
583 if (rate->value < 0) 584 if (rate->value < 0)
584 return 0; 585 return 0;
585 for (i=0; i < mode->num_rates; i++) { 586
586 struct ieee80211_rate *rates = &mode->rates[i]; 587 for (i=0; i< sband->n_bitrates; i++) {
587 int this_rate = rates->rate; 588 struct ieee80211_rate *brate = &sband->bitrates[i];
589 int this_rate = brate->bitrate;
588 590
589 if (target_rate == this_rate) { 591 if (target_rate == this_rate) {
590 sdata->bss->max_ratectrl_rateidx = i; 592 sdata->bss->max_ratectrl_rateidx = i;
591 if (rate->fixed) 593 if (rate->fixed)
592 sdata->bss->force_unicast_rateidx = i; 594 sdata->bss->force_unicast_rateidx = i;
593 return 0; 595 err = 0;
596 break;
594 } 597 }
595 } 598 }
596 return -EINVAL; 599 return err;
597} 600}
598 601
599static int ieee80211_ioctl_giwrate(struct net_device *dev, 602static int ieee80211_ioctl_giwrate(struct net_device *dev,
@@ -603,19 +606,25 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
603 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 606 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
604 struct sta_info *sta; 607 struct sta_info *sta;
605 struct ieee80211_sub_if_data *sdata; 608 struct ieee80211_sub_if_data *sdata;
609 struct ieee80211_supported_band *sband;
606 610
607 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 611 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
612
608 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) 613 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
609 sta = sta_info_get(local, sdata->u.sta.bssid); 614 sta = sta_info_get(local, sdata->u.sta.bssid);
610 else 615 else
611 return -EOPNOTSUPP; 616 return -EOPNOTSUPP;
612 if (!sta) 617 if (!sta)
613 return -ENODEV; 618 return -ENODEV;
614 if (sta->txrate < local->oper_hw_mode->num_rates) 619
615 rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000; 620 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
621
622 if (sta->txrate_idx < sband->n_bitrates)
623 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
616 else 624 else
617 rate->value = 0; 625 rate->value = 0;
618 sta_info_put(sta); 626 rate->value *= 100000;
627
619 return 0; 628 return 0;
620} 629}
621 630
@@ -625,7 +634,7 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
625{ 634{
626 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 635 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
627 bool need_reconfig = 0; 636 bool need_reconfig = 0;
628 u8 new_power_level; 637 int new_power_level;
629 638
630 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) 639 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
631 return -EINVAL; 640 return -EINVAL;
@@ -635,13 +644,15 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
635 if (data->txpower.fixed) { 644 if (data->txpower.fixed) {
636 new_power_level = data->txpower.value; 645 new_power_level = data->txpower.value;
637 } else { 646 } else {
638 /* Automatic power level. Get the px power from the current 647 /*
639 * channel. */ 648 * Automatic power level. Use maximum power for the current
640 struct ieee80211_channel* chan = local->oper_channel; 649 * channel. Should be part of rate control.
650 */
651 struct ieee80211_channel* chan = local->hw.conf.channel;
641 if (!chan) 652 if (!chan)
642 return -EINVAL; 653 return -EINVAL;
643 654
644 new_power_level = chan->power_level; 655 new_power_level = chan->max_power;
645 } 656 }
646 657
647 if (local->hw.conf.power_level != new_power_level) { 658 if (local->hw.conf.power_level != new_power_level) {
@@ -988,7 +999,6 @@ static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev
988 wstats->qual.qual = sta->last_signal; 999 wstats->qual.qual = sta->last_signal;
989 wstats->qual.noise = sta->last_noise; 1000 wstats->qual.noise = sta->last_noise;
990 wstats->qual.updated = local->wstats_flags; 1001 wstats->qual.updated = local->wstats_flags;
991 sta_info_put(sta);
992 } 1002 }
993 return wstats; 1003 return wstats;
994} 1004}
diff --git a/net/mac80211/ieee80211_key.h b/net/mac80211/ieee80211_key.h
index fc770e98d47b..d670e6dbfa39 100644
--- a/net/mac80211/ieee80211_key.h
+++ b/net/mac80211/ieee80211_key.h
@@ -13,6 +13,7 @@
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/crypto.h> 15#include <linux/crypto.h>
16#include <linux/rcupdate.h>
16#include <net/mac80211.h> 17#include <net/mac80211.h>
17 18
18/* ALG_TKIP 19/* ALG_TKIP
@@ -45,7 +46,19 @@ struct ieee80211_local;
45struct ieee80211_sub_if_data; 46struct ieee80211_sub_if_data;
46struct sta_info; 47struct sta_info;
47 48
48#define KEY_FLAG_UPLOADED_TO_HARDWARE (1<<0) 49/**
50 * enum ieee80211_internal_key_flags - internal key flags
51 *
52 * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
53 * in the hardware for TX crypto hardware acceleration.
54 * @KEY_FLAG_REMOVE_FROM_HARDWARE: Indicates to the key code that this
55 * key is present in the hardware (but it cannot be used for
56 * hardware acceleration any more!)
57 */
58enum ieee80211_internal_key_flags {
59 KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
60 KEY_FLAG_REMOVE_FROM_HARDWARE = BIT(1),
61};
49 62
50struct ieee80211_key { 63struct ieee80211_key {
51 struct ieee80211_local *local; 64 struct ieee80211_local *local;
@@ -112,12 +125,17 @@ struct ieee80211_key {
112 struct ieee80211_key_conf conf; 125 struct ieee80211_key_conf conf;
113}; 126};
114 127
115struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata, 128struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
116 struct sta_info *sta,
117 enum ieee80211_key_alg alg,
118 int idx, 129 int idx,
119 size_t key_len, 130 size_t key_len,
120 const u8 *key_data); 131 const u8 *key_data);
132/*
133 * Insert a key into data structures (sdata, sta if necessary)
134 * to make it used, free old key.
135 */
136void ieee80211_key_link(struct ieee80211_key *key,
137 struct ieee80211_sub_if_data *sdata,
138 struct sta_info *sta);
121void ieee80211_key_free(struct ieee80211_key *key); 139void ieee80211_key_free(struct ieee80211_key *key);
122void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx); 140void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
123void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata); 141void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
diff --git a/net/mac80211/ieee80211_rate.c b/net/mac80211/ieee80211_rate.c
index b957e67c5fba..4de06f128d90 100644
--- a/net/mac80211/ieee80211_rate.c
+++ b/net/mac80211/ieee80211_rate.c
@@ -163,34 +163,37 @@ static void rate_control_release(struct kref *kref)
163} 163}
164 164
165void rate_control_get_rate(struct net_device *dev, 165void rate_control_get_rate(struct net_device *dev,
166 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 166 struct ieee80211_supported_band *sband,
167 struct sk_buff *skb,
167 struct rate_selection *sel) 168 struct rate_selection *sel)
168{ 169{
169 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 170 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
170 struct rate_control_ref *ref = local->rate_ctrl; 171 struct rate_control_ref *ref = local->rate_ctrl;
171 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 172 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
172 struct sta_info *sta = sta_info_get(local, hdr->addr1); 173 struct sta_info *sta;
173 int i; 174 int i;
174 175
176 rcu_read_lock();
177 sta = sta_info_get(local, hdr->addr1);
178
175 memset(sel, 0, sizeof(struct rate_selection)); 179 memset(sel, 0, sizeof(struct rate_selection));
176 180
177 ref->ops->get_rate(ref->priv, dev, mode, skb, sel); 181 ref->ops->get_rate(ref->priv, dev, sband, skb, sel);
178 182
179 /* Select a non-ERP backup rate. */ 183 /* Select a non-ERP backup rate. */
180 if (!sel->nonerp) { 184 if (!sel->nonerp) {
181 for (i = 0; i < mode->num_rates - 1; i++) { 185 for (i = 0; i < sband->n_bitrates; i++) {
182 struct ieee80211_rate *rate = &mode->rates[i]; 186 struct ieee80211_rate *rate = &sband->bitrates[i];
183 if (sel->rate->rate < rate->rate) 187 if (sel->rate->bitrate < rate->bitrate)
184 break; 188 break;
185 189
186 if (rate_supported(sta, mode, i) && 190 if (rate_supported(sta, sband->band, i) &&
187 !(rate->flags & IEEE80211_RATE_ERP)) 191 !(rate->flags & IEEE80211_RATE_ERP_G))
188 sel->nonerp = rate; 192 sel->nonerp = rate;
189 } 193 }
190 } 194 }
191 195
192 if (sta) 196 rcu_read_unlock();
193 sta_info_put(sta);
194} 197}
195 198
196struct rate_control_ref *rate_control_get(struct rate_control_ref *ref) 199struct rate_control_ref *rate_control_get(struct rate_control_ref *ref)
diff --git a/net/mac80211/ieee80211_rate.h b/net/mac80211/ieee80211_rate.h
index 73f19e8aa51c..5b45f33cb766 100644
--- a/net/mac80211/ieee80211_rate.h
+++ b/net/mac80211/ieee80211_rate.h
@@ -14,10 +14,12 @@
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/kref.h>
17#include <net/mac80211.h> 18#include <net/mac80211.h>
18#include "ieee80211_i.h" 19#include "ieee80211_i.h"
19#include "sta_info.h" 20#include "sta_info.h"
20 21
22/* TODO: kdoc */
21struct rate_selection { 23struct rate_selection {
22 /* Selected transmission rate */ 24 /* Selected transmission rate */
23 struct ieee80211_rate *rate; 25 struct ieee80211_rate *rate;
@@ -34,7 +36,8 @@ struct rate_control_ops {
34 struct sk_buff *skb, 36 struct sk_buff *skb,
35 struct ieee80211_tx_status *status); 37 struct ieee80211_tx_status *status);
36 void (*get_rate)(void *priv, struct net_device *dev, 38 void (*get_rate)(void *priv, struct net_device *dev,
37 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 39 struct ieee80211_supported_band *band,
40 struct sk_buff *skb,
38 struct rate_selection *sel); 41 struct rate_selection *sel);
39 void (*rate_init)(void *priv, void *priv_sta, 42 void (*rate_init)(void *priv, void *priv_sta,
40 struct ieee80211_local *local, struct sta_info *sta); 43 struct ieee80211_local *local, struct sta_info *sta);
@@ -66,7 +69,8 @@ void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
66struct rate_control_ref *rate_control_alloc(const char *name, 69struct rate_control_ref *rate_control_alloc(const char *name,
67 struct ieee80211_local *local); 70 struct ieee80211_local *local);
68void rate_control_get_rate(struct net_device *dev, 71void rate_control_get_rate(struct net_device *dev,
69 struct ieee80211_hw_mode *mode, struct sk_buff *skb, 72 struct ieee80211_supported_band *sband,
73 struct sk_buff *skb,
70 struct rate_selection *sel); 74 struct rate_selection *sel);
71struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); 75struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
72void rate_control_put(struct rate_control_ref *ref); 76void rate_control_put(struct rate_control_ref *ref);
@@ -127,23 +131,23 @@ static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
127#endif 131#endif
128} 132}
129 133
130static inline int 134static inline int rate_supported(struct sta_info *sta,
131rate_supported(struct sta_info *sta, struct ieee80211_hw_mode *mode, int index) 135 enum ieee80211_band band,
136 int index)
132{ 137{
133 return (sta == NULL || sta->supp_rates & BIT(index)) && 138 return (sta == NULL || sta->supp_rates[band] & BIT(index));
134 (mode->rates[index].flags & IEEE80211_RATE_SUPPORTED);
135} 139}
136 140
137static inline int 141static inline int
138rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode, 142rate_lowest_index(struct ieee80211_local *local,
143 struct ieee80211_supported_band *sband,
139 struct sta_info *sta) 144 struct sta_info *sta)
140{ 145{
141 int i; 146 int i;
142 147
143 for (i = 0; i < mode->num_rates; i++) { 148 for (i = 0; i < sband->n_bitrates; i++)
144 if (rate_supported(sta, mode, i)) 149 if (rate_supported(sta, sband->band, i))
145 return i; 150 return i;
146 }
147 151
148 /* warn when we cannot find a rate. */ 152 /* warn when we cannot find a rate. */
149 WARN_ON(1); 153 WARN_ON(1);
@@ -152,10 +156,11 @@ rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
152} 156}
153 157
154static inline struct ieee80211_rate * 158static inline struct ieee80211_rate *
155rate_lowest(struct ieee80211_local *local, struct ieee80211_hw_mode *mode, 159rate_lowest(struct ieee80211_local *local,
160 struct ieee80211_supported_band *sband,
156 struct sta_info *sta) 161 struct sta_info *sta)
157{ 162{
158 return &mode->rates[rate_lowest_index(local, mode, sta)]; 163 return &sband->bitrates[rate_lowest_index(local, sband, sta)];
159} 164}
160 165
161 166
@@ -166,21 +171,6 @@ void rate_control_deinitialize(struct ieee80211_local *local);
166 171
167 172
168/* Rate control algorithms */ 173/* Rate control algorithms */
169#if defined(RC80211_SIMPLE_COMPILE) || \
170 (defined(CONFIG_MAC80211_RC_SIMPLE) && \
171 !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE))
172extern int rc80211_simple_init(void);
173extern void rc80211_simple_exit(void);
174#else
175static inline int rc80211_simple_init(void)
176{
177 return 0;
178}
179static inline void rc80211_simple_exit(void)
180{
181}
182#endif
183
184#if defined(RC80211_PID_COMPILE) || \ 174#if defined(RC80211_PID_COMPILE) || \
185 (defined(CONFIG_MAC80211_RC_PID) && \ 175 (defined(CONFIG_MAC80211_RC_PID) && \
186 !defined(CONFIG_MAC80211_RC_PID_MODULE)) 176 !defined(CONFIG_MAC80211_RC_PID_MODULE))
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/ieee80211_sta.c
index 9aeed5320228..8b991ebcbb4e 100644
--- a/net/mac80211/ieee80211_sta.c
+++ b/net/mac80211/ieee80211_sta.c
@@ -24,6 +24,7 @@
24#include <linux/wireless.h> 24#include <linux/wireless.h>
25#include <linux/random.h> 25#include <linux/random.h>
26#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
27#include <linux/rtnetlink.h>
27#include <net/iw_handler.h> 28#include <net/iw_handler.h>
28#include <asm/types.h> 29#include <asm/types.h>
29 30
@@ -31,12 +32,14 @@
31#include "ieee80211_i.h" 32#include "ieee80211_i.h"
32#include "ieee80211_rate.h" 33#include "ieee80211_rate.h"
33#include "ieee80211_led.h" 34#include "ieee80211_led.h"
35#include "mesh.h"
34 36
35#define IEEE80211_AUTH_TIMEOUT (HZ / 5) 37#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
36#define IEEE80211_AUTH_MAX_TRIES 3 38#define IEEE80211_AUTH_MAX_TRIES 3
37#define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 39#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
38#define IEEE80211_ASSOC_MAX_TRIES 3 40#define IEEE80211_ASSOC_MAX_TRIES 3
39#define IEEE80211_MONITORING_INTERVAL (2 * HZ) 41#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
42#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
40#define IEEE80211_PROBE_INTERVAL (60 * HZ) 43#define IEEE80211_PROBE_INTERVAL (60 * HZ)
41#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) 44#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
42#define IEEE80211_SCAN_INTERVAL (2 * HZ) 45#define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -49,6 +52,7 @@
49#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ) 52#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
50#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ) 53#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
51#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ) 54#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
55#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
52 56
53#define IEEE80211_IBSS_MAX_STA_ENTRIES 128 57#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
54 58
@@ -74,7 +78,7 @@
74static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst, 78static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
75 u8 *ssid, size_t ssid_len); 79 u8 *ssid, size_t ssid_len);
76static struct ieee80211_sta_bss * 80static struct ieee80211_sta_bss *
77ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel, 81ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
78 u8 *ssid, u8 ssid_len); 82 u8 *ssid, u8 ssid_len);
79static void ieee80211_rx_bss_put(struct net_device *dev, 83static void ieee80211_rx_bss_put(struct net_device *dev,
80 struct ieee80211_sta_bss *bss); 84 struct ieee80211_sta_bss *bss);
@@ -87,46 +91,8 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
87 struct ieee80211_if_sta *ifsta); 91 struct ieee80211_if_sta *ifsta);
88 92
89 93
90/* Parsed Information Elements */ 94void ieee802_11_parse_elems(u8 *start, size_t len,
91struct ieee802_11_elems { 95 struct ieee802_11_elems *elems)
92 /* pointers to IEs */
93 u8 *ssid;
94 u8 *supp_rates;
95 u8 *fh_params;
96 u8 *ds_params;
97 u8 *cf_params;
98 u8 *tim;
99 u8 *ibss_params;
100 u8 *challenge;
101 u8 *wpa;
102 u8 *rsn;
103 u8 *erp_info;
104 u8 *ext_supp_rates;
105 u8 *wmm_info;
106 u8 *wmm_param;
107 u8 *ht_cap_elem;
108 u8 *ht_info_elem;
109 /* length of them, respectively */
110 u8 ssid_len;
111 u8 supp_rates_len;
112 u8 fh_params_len;
113 u8 ds_params_len;
114 u8 cf_params_len;
115 u8 tim_len;
116 u8 ibss_params_len;
117 u8 challenge_len;
118 u8 wpa_len;
119 u8 rsn_len;
120 u8 erp_info_len;
121 u8 ext_supp_rates_len;
122 u8 wmm_info_len;
123 u8 wmm_param_len;
124 u8 ht_cap_elem_len;
125 u8 ht_info_elem_len;
126};
127
128static void ieee802_11_parse_elems(u8 *start, size_t len,
129 struct ieee802_11_elems *elems)
130{ 96{
131 size_t left = len; 97 size_t left = len;
132 u8 *pos = start; 98 u8 *pos = start;
@@ -215,6 +181,30 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
215 elems->ht_info_elem = pos; 181 elems->ht_info_elem = pos;
216 elems->ht_info_elem_len = elen; 182 elems->ht_info_elem_len = elen;
217 break; 183 break;
184 case WLAN_EID_MESH_ID:
185 elems->mesh_id = pos;
186 elems->mesh_id_len = elen;
187 break;
188 case WLAN_EID_MESH_CONFIG:
189 elems->mesh_config = pos;
190 elems->mesh_config_len = elen;
191 break;
192 case WLAN_EID_PEER_LINK:
193 elems->peer_link = pos;
194 elems->peer_link_len = elen;
195 break;
196 case WLAN_EID_PREQ:
197 elems->preq = pos;
198 elems->preq_len = elen;
199 break;
200 case WLAN_EID_PREP:
201 elems->prep = pos;
202 elems->prep_len = elen;
203 break;
204 case WLAN_EID_PERR:
205 elems->perr = pos;
206 elems->perr_len = elen;
207 break;
218 default: 208 default:
219 break; 209 break;
220 } 210 }
@@ -227,12 +217,7 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
227 217
228static int ecw2cw(int ecw) 218static int ecw2cw(int ecw)
229{ 219{
230 int cw = 1; 220 return (1 << ecw) - 1;
231 while (ecw > 0) {
232 cw <<= 1;
233 ecw--;
234 }
235 return cw - 1;
236} 221}
237 222
238static void ieee80211_sta_wmm_params(struct net_device *dev, 223static void ieee80211_sta_wmm_params(struct net_device *dev,
@@ -297,12 +282,13 @@ static void ieee80211_sta_wmm_params(struct net_device *dev,
297 params.aifs = pos[0] & 0x0f; 282 params.aifs = pos[0] & 0x0f;
298 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); 283 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
299 params.cw_min = ecw2cw(pos[1] & 0x0f); 284 params.cw_min = ecw2cw(pos[1] & 0x0f);
300 /* TXOP is in units of 32 usec; burst_time in 0.1 ms */ 285 params.txop = pos[2] | (pos[3] << 8);
301 params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100; 286#ifdef CONFIG_MAC80211_DEBUG
302 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d " 287 printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
303 "cWmin=%d cWmax=%d burst=%d\n", 288 "cWmin=%d cWmax=%d txop=%d\n",
304 dev->name, queue, aci, acm, params.aifs, params.cw_min, 289 dev->name, queue, aci, acm, params.aifs, params.cw_min,
305 params.cw_max, params.burst_time); 290 params.cw_max, params.txop);
291#endif
306 /* TODO: handle ACM (block TX, fallback to next lowest allowed 292 /* TODO: handle ACM (block TX, fallback to next lowest allowed
307 * AC for now) */ 293 * AC for now) */
308 if (local->ops->conf_tx(local_to_hw(local), queue, &params)) { 294 if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
@@ -466,7 +452,7 @@ static void ieee80211_set_associated(struct net_device *dev,
466 return; 452 return;
467 453
468 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, 454 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
469 local->hw.conf.channel, 455 local->hw.conf.channel->center_freq,
470 ifsta->ssid, ifsta->ssid_len); 456 ifsta->ssid, ifsta->ssid_len);
471 if (bss) { 457 if (bss) {
472 if (bss->has_erp_value) 458 if (bss->has_erp_value)
@@ -492,6 +478,7 @@ static void ieee80211_set_associated(struct net_device *dev,
492 ifsta->last_probe = jiffies; 478 ifsta->last_probe = jiffies;
493 ieee80211_led_assoc(local, assoc); 479 ieee80211_led_assoc(local, assoc);
494 480
481 sdata->bss_conf.assoc = assoc;
495 ieee80211_bss_info_change_notify(sdata, changed); 482 ieee80211_bss_info_change_notify(sdata, changed);
496} 483}
497 484
@@ -504,8 +491,8 @@ static void ieee80211_set_disassoc(struct net_device *dev,
504 ieee80211_set_associated(dev, ifsta, 0); 491 ieee80211_set_associated(dev, ifsta, 0);
505} 492}
506 493
507static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb, 494void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
508 int encrypt) 495 int encrypt)
509{ 496{
510 struct ieee80211_sub_if_data *sdata; 497 struct ieee80211_sub_if_data *sdata;
511 struct ieee80211_tx_packet_data *pkt_data; 498 struct ieee80211_tx_packet_data *pkt_data;
@@ -592,7 +579,6 @@ static void ieee80211_send_assoc(struct net_device *dev,
592 struct ieee80211_if_sta *ifsta) 579 struct ieee80211_if_sta *ifsta)
593{ 580{
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 581 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
595 struct ieee80211_hw_mode *mode;
596 struct sk_buff *skb; 582 struct sk_buff *skb;
597 struct ieee80211_mgmt *mgmt; 583 struct ieee80211_mgmt *mgmt;
598 u8 *pos, *ies; 584 u8 *pos, *ies;
@@ -600,6 +586,7 @@ static void ieee80211_send_assoc(struct net_device *dev,
600 u16 capab; 586 u16 capab;
601 struct ieee80211_sta_bss *bss; 587 struct ieee80211_sta_bss *bss;
602 int wmm = 0; 588 int wmm = 0;
589 struct ieee80211_supported_band *sband;
603 590
604 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 591 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
605 sizeof(*mgmt) + 200 + ifsta->extra_ie_len + 592 sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
@@ -611,13 +598,19 @@ static void ieee80211_send_assoc(struct net_device *dev,
611 } 598 }
612 skb_reserve(skb, local->hw.extra_tx_headroom); 599 skb_reserve(skb, local->hw.extra_tx_headroom);
613 600
614 mode = local->oper_hw_mode; 601 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
602
615 capab = ifsta->capab; 603 capab = ifsta->capab;
616 if (mode->mode == MODE_IEEE80211G) { 604
617 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME | 605 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
618 WLAN_CAPABILITY_SHORT_PREAMBLE; 606 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
607 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
608 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
609 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
619 } 610 }
620 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel, 611
612 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
613 local->hw.conf.channel->center_freq,
621 ifsta->ssid, ifsta->ssid_len); 614 ifsta->ssid, ifsta->ssid_len);
622 if (bss) { 615 if (bss) {
623 if (bss->capability & WLAN_CAPABILITY_PRIVACY) 616 if (bss->capability & WLAN_CAPABILITY_PRIVACY)
@@ -656,23 +649,23 @@ static void ieee80211_send_assoc(struct net_device *dev,
656 *pos++ = ifsta->ssid_len; 649 *pos++ = ifsta->ssid_len;
657 memcpy(pos, ifsta->ssid, ifsta->ssid_len); 650 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
658 651
659 len = mode->num_rates; 652 len = sband->n_bitrates;
660 if (len > 8) 653 if (len > 8)
661 len = 8; 654 len = 8;
662 pos = skb_put(skb, len + 2); 655 pos = skb_put(skb, len + 2);
663 *pos++ = WLAN_EID_SUPP_RATES; 656 *pos++ = WLAN_EID_SUPP_RATES;
664 *pos++ = len; 657 *pos++ = len;
665 for (i = 0; i < len; i++) { 658 for (i = 0; i < len; i++) {
666 int rate = mode->rates[i].rate; 659 int rate = sband->bitrates[i].bitrate;
667 *pos++ = (u8) (rate / 5); 660 *pos++ = (u8) (rate / 5);
668 } 661 }
669 662
670 if (mode->num_rates > len) { 663 if (sband->n_bitrates > len) {
671 pos = skb_put(skb, mode->num_rates - len + 2); 664 pos = skb_put(skb, sband->n_bitrates - len + 2);
672 *pos++ = WLAN_EID_EXT_SUPP_RATES; 665 *pos++ = WLAN_EID_EXT_SUPP_RATES;
673 *pos++ = mode->num_rates - len; 666 *pos++ = sband->n_bitrates - len;
674 for (i = len; i < mode->num_rates; i++) { 667 for (i = len; i < sband->n_bitrates; i++) {
675 int rate = mode->rates[i].rate; 668 int rate = sband->bitrates[i].bitrate;
676 *pos++ = (u8) (rate / 5); 669 *pos++ = (u8) (rate / 5);
677 } 670 }
678 } 671 }
@@ -695,17 +688,18 @@ static void ieee80211_send_assoc(struct net_device *dev,
695 *pos++ = 0; 688 *pos++ = 0;
696 } 689 }
697 /* wmm support is a must to HT */ 690 /* wmm support is a must to HT */
698 if (wmm && mode->ht_info.ht_supported) { 691 if (wmm && sband->ht_info.ht_supported) {
699 __le16 tmp = cpu_to_le16(mode->ht_info.cap); 692 __le16 tmp = cpu_to_le16(sband->ht_info.cap);
700 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2); 693 pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
701 *pos++ = WLAN_EID_HT_CAPABILITY; 694 *pos++ = WLAN_EID_HT_CAPABILITY;
702 *pos++ = sizeof(struct ieee80211_ht_cap); 695 *pos++ = sizeof(struct ieee80211_ht_cap);
703 memset(pos, 0, sizeof(struct ieee80211_ht_cap)); 696 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
704 memcpy(pos, &tmp, sizeof(u16)); 697 memcpy(pos, &tmp, sizeof(u16));
705 pos += sizeof(u16); 698 pos += sizeof(u16);
706 *pos++ = (mode->ht_info.ampdu_factor | 699 /* TODO: needs a define here for << 2 */
707 (mode->ht_info.ampdu_density << 2)); 700 *pos++ = sband->ht_info.ampdu_factor |
708 memcpy(pos, mode->ht_info.supp_mcs_set, 16); 701 (sband->ht_info.ampdu_density << 2);
702 memcpy(pos, sband->ht_info.supp_mcs_set, 16);
709 } 703 }
710 704
711 kfree(ifsta->assocreq_ies); 705 kfree(ifsta->assocreq_ies);
@@ -788,7 +782,8 @@ static int ieee80211_privacy_mismatch(struct net_device *dev,
788 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL)) 782 if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
789 return 0; 783 return 0;
790 784
791 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel, 785 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
786 local->hw.conf.channel->center_freq,
792 ifsta->ssid, ifsta->ssid_len); 787 ifsta->ssid, ifsta->ssid_len);
793 if (!bss) 788 if (!bss)
794 return 0; 789 return 0;
@@ -851,6 +846,8 @@ static void ieee80211_associated(struct net_device *dev,
851 846
852 ifsta->state = IEEE80211_ASSOCIATED; 847 ifsta->state = IEEE80211_ASSOCIATED;
853 848
849 rcu_read_lock();
850
854 sta = sta_info_get(local, ifsta->bssid); 851 sta = sta_info_get(local, ifsta->bssid);
855 if (!sta) { 852 if (!sta) {
856 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n", 853 printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
@@ -866,7 +863,7 @@ static void ieee80211_associated(struct net_device *dev,
866 "range\n", 863 "range\n",
867 dev->name, print_mac(mac, ifsta->bssid)); 864 dev->name, print_mac(mac, ifsta->bssid));
868 disassoc = 1; 865 disassoc = 1;
869 sta_info_free(sta); 866 sta_info_unlink(&sta);
870 } else 867 } else
871 ieee80211_send_probe_req(dev, ifsta->bssid, 868 ieee80211_send_probe_req(dev, ifsta->bssid,
872 local->scan_ssid, 869 local->scan_ssid,
@@ -882,8 +879,17 @@ static void ieee80211_associated(struct net_device *dev,
882 ifsta->ssid_len); 879 ifsta->ssid_len);
883 } 880 }
884 } 881 }
885 sta_info_put(sta);
886 } 882 }
883
884 rcu_read_unlock();
885
886 if (disassoc && sta) {
887 synchronize_rcu();
888 rtnl_lock();
889 sta_info_destroy(sta);
890 rtnl_unlock();
891 }
892
887 if (disassoc) { 893 if (disassoc) {
888 ifsta->state = IEEE80211_DISABLED; 894 ifsta->state = IEEE80211_DISABLED;
889 ieee80211_set_associated(dev, ifsta, 0); 895 ieee80211_set_associated(dev, ifsta, 0);
@@ -898,7 +904,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
898 u8 *ssid, size_t ssid_len) 904 u8 *ssid, size_t ssid_len)
899{ 905{
900 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 906 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
901 struct ieee80211_hw_mode *mode; 907 struct ieee80211_supported_band *sband;
902 struct sk_buff *skb; 908 struct sk_buff *skb;
903 struct ieee80211_mgmt *mgmt; 909 struct ieee80211_mgmt *mgmt;
904 u8 *pos, *supp_rates, *esupp_rates = NULL; 910 u8 *pos, *supp_rates, *esupp_rates = NULL;
@@ -932,11 +938,10 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
932 supp_rates = skb_put(skb, 2); 938 supp_rates = skb_put(skb, 2);
933 supp_rates[0] = WLAN_EID_SUPP_RATES; 939 supp_rates[0] = WLAN_EID_SUPP_RATES;
934 supp_rates[1] = 0; 940 supp_rates[1] = 0;
935 mode = local->oper_hw_mode; 941 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
936 for (i = 0; i < mode->num_rates; i++) { 942
937 struct ieee80211_rate *rate = &mode->rates[i]; 943 for (i = 0; i < sband->n_bitrates; i++) {
938 if (!(rate->flags & IEEE80211_RATE_SUPPORTED)) 944 struct ieee80211_rate *rate = &sband->bitrates[i];
939 continue;
940 if (esupp_rates) { 945 if (esupp_rates) {
941 pos = skb_put(skb, 1); 946 pos = skb_put(skb, 1);
942 esupp_rates[1]++; 947 esupp_rates[1]++;
@@ -949,7 +954,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
949 pos = skb_put(skb, 1); 954 pos = skb_put(skb, 1);
950 supp_rates[1]++; 955 supp_rates[1]++;
951 } 956 }
952 *pos = rate->rate / 5; 957 *pos = rate->bitrate / 5;
953 } 958 }
954 959
955 ieee80211_sta_tx(dev, skb, 0); 960 ieee80211_sta_tx(dev, skb, 0);
@@ -1044,6 +1049,58 @@ static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
1044 return; 1049 return;
1045} 1050}
1046 1051
1052void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
1053 u16 tid, u8 dialog_token, u16 start_seq_num,
1054 u16 agg_size, u16 timeout)
1055{
1056 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1058 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
1059 struct sk_buff *skb;
1060 struct ieee80211_mgmt *mgmt;
1061 u16 capab;
1062
1063 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
1064 sizeof(mgmt->u.action.u.addba_req));
1065
1066
1067 if (!skb) {
1068 printk(KERN_ERR "%s: failed to allocate buffer "
1069 "for addba request frame\n", dev->name);
1070 return;
1071 }
1072 skb_reserve(skb, local->hw.extra_tx_headroom);
1073 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
1074 memset(mgmt, 0, 24);
1075 memcpy(mgmt->da, da, ETH_ALEN);
1076 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1077 if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
1078 memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
1079 else
1080 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
1081
1082 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1083 IEEE80211_STYPE_ACTION);
1084
1085 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
1086
1087 mgmt->u.action.category = WLAN_CATEGORY_BACK;
1088 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
1089
1090 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
1091 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
1092 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
1093 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
1094
1095 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
1096
1097 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
1098 mgmt->u.action.u.addba_req.start_seq_num =
1099 cpu_to_le16(start_seq_num << 4);
1100
1101 ieee80211_sta_tx(dev, skb, 0);
1102}
1103
1047static void ieee80211_sta_process_addba_request(struct net_device *dev, 1104static void ieee80211_sta_process_addba_request(struct net_device *dev,
1048 struct ieee80211_mgmt *mgmt, 1105 struct ieee80211_mgmt *mgmt,
1049 size_t len) 1106 size_t len)
@@ -1058,9 +1115,13 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
1058 int ret = -EOPNOTSUPP; 1115 int ret = -EOPNOTSUPP;
1059 DECLARE_MAC_BUF(mac); 1116 DECLARE_MAC_BUF(mac);
1060 1117
1118 rcu_read_lock();
1119
1061 sta = sta_info_get(local, mgmt->sa); 1120 sta = sta_info_get(local, mgmt->sa);
1062 if (!sta) 1121 if (!sta) {
1122 rcu_read_unlock();
1063 return; 1123 return;
1124 }
1064 1125
1065 /* extract session parameters from addba request frame */ 1126 /* extract session parameters from addba request frame */
1066 dialog_token = mgmt->u.action.u.addba_req.dialog_token; 1127 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
@@ -1093,9 +1154,11 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
1093 } 1154 }
1094 /* determine default buffer size */ 1155 /* determine default buffer size */
1095 if (buf_size == 0) { 1156 if (buf_size == 0) {
1096 struct ieee80211_hw_mode *mode = conf->mode; 1157 struct ieee80211_supported_band *sband;
1158
1159 sband = local->hw.wiphy->bands[conf->channel->band];
1097 buf_size = IEEE80211_MIN_AMPDU_BUF; 1160 buf_size = IEEE80211_MIN_AMPDU_BUF;
1098 buf_size = buf_size << mode->ht_info.ampdu_factor; 1161 buf_size = buf_size << sband->ht_info.ampdu_factor;
1099 } 1162 }
1100 1163
1101 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid]; 1164 tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
@@ -1127,7 +1190,7 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
1127 1190
1128 if (local->ops->ampdu_action) 1191 if (local->ops->ampdu_action)
1129 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, 1192 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
1130 sta->addr, tid, start_seq_num); 1193 sta->addr, tid, &start_seq_num);
1131#ifdef CONFIG_MAC80211_HT_DEBUG 1194#ifdef CONFIG_MAC80211_HT_DEBUG
1132 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret); 1195 printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
1133#endif /* CONFIG_MAC80211_HT_DEBUG */ 1196#endif /* CONFIG_MAC80211_HT_DEBUG */
@@ -1150,13 +1213,89 @@ end:
1150 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx); 1213 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1151 1214
1152end_no_lock: 1215end_no_lock:
1153 ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token, 1216 ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
1154 status, 1, buf_size, timeout); 1217 dialog_token, status, 1, buf_size, timeout);
1155 sta_info_put(sta); 1218 rcu_read_unlock();
1219}
1220
1221static void ieee80211_sta_process_addba_resp(struct net_device *dev,
1222 struct ieee80211_mgmt *mgmt,
1223 size_t len)
1224{
1225 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1226 struct ieee80211_hw *hw = &local->hw;
1227 struct sta_info *sta;
1228 u16 capab;
1229 u16 tid;
1230 u8 *state;
1231
1232 rcu_read_lock();
1233
1234 sta = sta_info_get(local, mgmt->sa);
1235 if (!sta) {
1236 rcu_read_unlock();
1237 return;
1238 }
1239
1240 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
1241 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
1242
1243 state = &sta->ampdu_mlme.tid_tx[tid].state;
1244
1245 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1246
1247 if (mgmt->u.action.u.addba_resp.dialog_token !=
1248 sta->ampdu_mlme.tid_tx[tid].dialog_token) {
1249 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1250#ifdef CONFIG_MAC80211_HT_DEBUG
1251 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1252#endif /* CONFIG_MAC80211_HT_DEBUG */
1253 rcu_read_unlock();
1254 return;
1255 }
1256
1257 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
1258#ifdef CONFIG_MAC80211_HT_DEBUG
1259 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1260#endif /* CONFIG_MAC80211_HT_DEBUG */
1261 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1262 == WLAN_STATUS_SUCCESS) {
1263 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1264 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1265 printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
1266 "%d\n", *state);
1267 rcu_read_unlock();
1268 return;
1269 }
1270
1271 if (*state & HT_ADDBA_RECEIVED_MSK)
1272 printk(KERN_DEBUG "double addBA response\n");
1273
1274 *state |= HT_ADDBA_RECEIVED_MSK;
1275 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
1276
1277 if (*state == HT_AGG_STATE_OPERATIONAL) {
1278 printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
1279 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1280 }
1281
1282 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1283 printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
1284 } else {
1285 printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
1286
1287 sta->ampdu_mlme.tid_tx[tid].addba_req_num++;
1288 /* this will allow the state check in stop_BA_session */
1289 *state = HT_AGG_STATE_OPERATIONAL;
1290 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1291 ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
1292 WLAN_BACK_INITIATOR);
1293 }
1294 rcu_read_unlock();
1156} 1295}
1157 1296
1158static void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid, 1297void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
1159 u16 initiator, u16 reason_code) 1298 u16 initiator, u16 reason_code)
1160{ 1299{
1161 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1300 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1162 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1301 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1207,16 +1346,20 @@ void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1207 struct sta_info *sta; 1346 struct sta_info *sta;
1208 int ret, i; 1347 int ret, i;
1209 1348
1349 rcu_read_lock();
1350
1210 sta = sta_info_get(local, ra); 1351 sta = sta_info_get(local, ra);
1211 if (!sta) 1352 if (!sta) {
1353 rcu_read_unlock();
1212 return; 1354 return;
1355 }
1213 1356
1214 /* check if TID is in operational state */ 1357 /* check if TID is in operational state */
1215 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx); 1358 spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
1216 if (sta->ampdu_mlme.tid_rx[tid].state 1359 if (sta->ampdu_mlme.tid_rx[tid].state
1217 != HT_AGG_STATE_OPERATIONAL) { 1360 != HT_AGG_STATE_OPERATIONAL) {
1218 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx); 1361 spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
1219 sta_info_put(sta); 1362 rcu_read_unlock();
1220 return; 1363 return;
1221 } 1364 }
1222 sta->ampdu_mlme.tid_rx[tid].state = 1365 sta->ampdu_mlme.tid_rx[tid].state =
@@ -1229,7 +1372,7 @@ void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1229 BUG_ON(!local->ops->ampdu_action); 1372 BUG_ON(!local->ops->ampdu_action);
1230 1373
1231 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, 1374 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
1232 ra, tid, EINVAL); 1375 ra, tid, NULL);
1233 if (ret) 1376 if (ret)
1234 printk(KERN_DEBUG "HW problem - can not stop rx " 1377 printk(KERN_DEBUG "HW problem - can not stop rx "
1235 "aggergation for tid %d\n", tid); 1378 "aggergation for tid %d\n", tid);
@@ -1255,9 +1398,10 @@ void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
1255 kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf); 1398 kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
1256 1399
1257 sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE; 1400 sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
1258 sta_info_put(sta); 1401 rcu_read_unlock();
1259} 1402}
1260 1403
1404
1261static void ieee80211_sta_process_delba(struct net_device *dev, 1405static void ieee80211_sta_process_delba(struct net_device *dev,
1262 struct ieee80211_mgmt *mgmt, size_t len) 1406 struct ieee80211_mgmt *mgmt, size_t len)
1263{ 1407{
@@ -1267,9 +1411,13 @@ static void ieee80211_sta_process_delba(struct net_device *dev,
1267 u16 initiator; 1411 u16 initiator;
1268 DECLARE_MAC_BUF(mac); 1412 DECLARE_MAC_BUF(mac);
1269 1413
1414 rcu_read_lock();
1415
1270 sta = sta_info_get(local, mgmt->sa); 1416 sta = sta_info_get(local, mgmt->sa);
1271 if (!sta) 1417 if (!sta) {
1418 rcu_read_unlock();
1272 return; 1419 return;
1420 }
1273 1421
1274 params = le16_to_cpu(mgmt->u.action.u.delba.params); 1422 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1275 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; 1423 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
@@ -1277,15 +1425,75 @@ static void ieee80211_sta_process_delba(struct net_device *dev,
1277 1425
1278#ifdef CONFIG_MAC80211_HT_DEBUG 1426#ifdef CONFIG_MAC80211_HT_DEBUG
1279 if (net_ratelimit()) 1427 if (net_ratelimit())
1280 printk(KERN_DEBUG "delba from %s on tid %d reason code %d\n", 1428 printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
1281 print_mac(mac, mgmt->sa), tid, 1429 print_mac(mac, mgmt->sa),
1430 initiator ? "recipient" : "initiator", tid,
1282 mgmt->u.action.u.delba.reason_code); 1431 mgmt->u.action.u.delba.reason_code);
1283#endif /* CONFIG_MAC80211_HT_DEBUG */ 1432#endif /* CONFIG_MAC80211_HT_DEBUG */
1284 1433
1285 if (initiator == WLAN_BACK_INITIATOR) 1434 if (initiator == WLAN_BACK_INITIATOR)
1286 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid, 1435 ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
1287 WLAN_BACK_INITIATOR, 0); 1436 WLAN_BACK_INITIATOR, 0);
1288 sta_info_put(sta); 1437 else { /* WLAN_BACK_RECIPIENT */
1438 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1439 sta->ampdu_mlme.tid_tx[tid].state =
1440 HT_AGG_STATE_OPERATIONAL;
1441 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1442 ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
1443 WLAN_BACK_RECIPIENT);
1444 }
1445 rcu_read_unlock();
1446}
1447
1448/*
1449 * After sending add Block Ack request we activated a timer until
1450 * add Block Ack response will arrive from the recipient.
1451 * If this timer expires sta_addba_resp_timer_expired will be executed.
1452 */
1453void sta_addba_resp_timer_expired(unsigned long data)
1454{
1455 /* not an elegant detour, but there is no choice as the timer passes
1456 * only one argument, and both sta_info and TID are needed, so init
1457 * flow in sta_info_create gives the TID as data, while the timer_to_id
1458 * array gives the sta through container_of */
1459 u16 tid = *(int *)data;
1460 struct sta_info *temp_sta = container_of((void *)data,
1461 struct sta_info, timer_to_tid[tid]);
1462
1463 struct ieee80211_local *local = temp_sta->local;
1464 struct ieee80211_hw *hw = &local->hw;
1465 struct sta_info *sta;
1466 u8 *state;
1467
1468 rcu_read_lock();
1469
1470 sta = sta_info_get(local, temp_sta->addr);
1471 if (!sta) {
1472 rcu_read_unlock();
1473 return;
1474 }
1475
1476 state = &sta->ampdu_mlme.tid_tx[tid].state;
1477 /* check if the TID waits for addBA response */
1478 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
1479 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1480 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1481 *state = HT_AGG_STATE_IDLE;
1482 printk(KERN_DEBUG "timer expired on tid %d but we are not "
1483 "expecting addBA response there", tid);
1484 goto timer_expired_exit;
1485 }
1486
1487 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
1488
1489 /* go through the state check in stop_BA_session */
1490 *state = HT_AGG_STATE_OPERATIONAL;
1491 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
1492 ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
1493 WLAN_BACK_INITIATOR);
1494
1495timer_expired_exit:
1496 rcu_read_unlock();
1289} 1497}
1290 1498
1291/* 1499/*
@@ -1297,7 +1505,7 @@ void sta_rx_agg_session_timer_expired(unsigned long data)
1297{ 1505{
1298 /* not an elegant detour, but there is no choice as the timer passes 1506 /* not an elegant detour, but there is no choice as the timer passes
1299 * only one argument, and verious sta_info are needed here, so init 1507 * only one argument, and verious sta_info are needed here, so init
1300 * flow in sta_info_add gives the TID as data, while the timer_to_id 1508 * flow in sta_info_create gives the TID as data, while the timer_to_id
1301 * array gives the sta through container_of */ 1509 * array gives the sta through container_of */
1302 u8 *ptid = (u8 *)data; 1510 u8 *ptid = (u8 *)data;
1303 u8 *timer_to_id = ptid - *ptid; 1511 u8 *timer_to_id = ptid - *ptid;
@@ -1305,8 +1513,8 @@ void sta_rx_agg_session_timer_expired(unsigned long data)
1305 timer_to_tid[0]); 1513 timer_to_tid[0]);
1306 1514
1307 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); 1515 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
1308 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid, 1516 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1309 WLAN_BACK_TIMER, 1517 (u16)*ptid, WLAN_BACK_TIMER,
1310 WLAN_REASON_QSTA_TIMEOUT); 1518 WLAN_REASON_QSTA_TIMEOUT);
1311} 1519}
1312 1520
@@ -1536,15 +1744,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1536{ 1744{
1537 struct ieee80211_local *local = sdata->local; 1745 struct ieee80211_local *local = sdata->local;
1538 struct net_device *dev = sdata->dev; 1746 struct net_device *dev = sdata->dev;
1539 struct ieee80211_hw_mode *mode; 1747 struct ieee80211_supported_band *sband;
1540 struct sta_info *sta; 1748 struct sta_info *sta;
1541 u32 rates; 1749 u64 rates, basic_rates;
1542 u16 capab_info, status_code, aid; 1750 u16 capab_info, status_code, aid;
1543 struct ieee802_11_elems elems; 1751 struct ieee802_11_elems elems;
1544 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf; 1752 struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
1545 u8 *pos; 1753 u8 *pos;
1546 int i, j; 1754 int i, j;
1547 DECLARE_MAC_BUF(mac); 1755 DECLARE_MAC_BUF(mac);
1756 bool have_higher_than_11mbit = false;
1548 1757
1549 /* AssocResp and ReassocResp have identical structure, so process both 1758 /* AssocResp and ReassocResp have identical structure, so process both
1550 * of them in this function. */ 1759 * of them in this function. */
@@ -1614,22 +1823,23 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1614 if (ifsta->assocresp_ies) 1823 if (ifsta->assocresp_ies)
1615 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len); 1824 memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
1616 1825
1617 /* set AID, ieee80211_set_associated() will tell the driver */ 1826 rcu_read_lock();
1618 bss_conf->aid = aid;
1619 ieee80211_set_associated(dev, ifsta, 1);
1620 1827
1621 /* Add STA entry for the AP */ 1828 /* Add STA entry for the AP */
1622 sta = sta_info_get(local, ifsta->bssid); 1829 sta = sta_info_get(local, ifsta->bssid);
1623 if (!sta) { 1830 if (!sta) {
1624 struct ieee80211_sta_bss *bss; 1831 struct ieee80211_sta_bss *bss;
1625 sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL); 1832 int err;
1833
1834 sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
1626 if (!sta) { 1835 if (!sta) {
1627 printk(KERN_DEBUG "%s: failed to add STA entry for the" 1836 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1628 " AP\n", dev->name); 1837 " the AP\n", dev->name);
1838 rcu_read_unlock();
1629 return; 1839 return;
1630 } 1840 }
1631 bss = ieee80211_rx_bss_get(dev, ifsta->bssid, 1841 bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
1632 local->hw.conf.channel, 1842 local->hw.conf.channel->center_freq,
1633 ifsta->ssid, ifsta->ssid_len); 1843 ifsta->ssid, ifsta->ssid_len);
1634 if (bss) { 1844 if (bss) {
1635 sta->last_rssi = bss->rssi; 1845 sta->last_rssi = bss->rssi;
@@ -1637,26 +1847,71 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1637 sta->last_noise = bss->noise; 1847 sta->last_noise = bss->noise;
1638 ieee80211_rx_bss_put(dev, bss); 1848 ieee80211_rx_bss_put(dev, bss);
1639 } 1849 }
1850
1851 err = sta_info_insert(sta);
1852 if (err) {
1853 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1854 " the AP (error %d)\n", dev->name, err);
1855 sta_info_destroy(sta);
1856 rcu_read_unlock();
1857 return;
1858 }
1640 } 1859 }
1641 1860
1642 sta->dev = dev; 1861 /*
1643 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP; 1862 * FIXME: Do we really need to update the sta_info's information here?
1863 * We already know about the AP (we found it in our list) so it
1864 * should already be filled with the right info, no?
1865 * As is stands, all this is racy because typically we assume
1866 * the information that is filled in here (except flags) doesn't
1867 * change while a STA structure is alive. As such, it should move
1868 * to between the sta_info_alloc() and sta_info_insert() above.
1869 */
1870
1871 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
1872 WLAN_STA_AUTHORIZED;
1644 1873
1645 rates = 0; 1874 rates = 0;
1646 mode = local->oper_hw_mode; 1875 basic_rates = 0;
1876 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1877
1647 for (i = 0; i < elems.supp_rates_len; i++) { 1878 for (i = 0; i < elems.supp_rates_len; i++) {
1648 int rate = (elems.supp_rates[i] & 0x7f) * 5; 1879 int rate = (elems.supp_rates[i] & 0x7f) * 5;
1649 for (j = 0; j < mode->num_rates; j++) 1880
1650 if (mode->rates[j].rate == rate) 1881 if (rate > 110)
1882 have_higher_than_11mbit = true;
1883
1884 for (j = 0; j < sband->n_bitrates; j++) {
1885 if (sband->bitrates[j].bitrate == rate)
1651 rates |= BIT(j); 1886 rates |= BIT(j);
1887 if (elems.supp_rates[i] & 0x80)
1888 basic_rates |= BIT(j);
1889 }
1652 } 1890 }
1891
1653 for (i = 0; i < elems.ext_supp_rates_len; i++) { 1892 for (i = 0; i < elems.ext_supp_rates_len; i++) {
1654 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; 1893 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
1655 for (j = 0; j < mode->num_rates; j++) 1894
1656 if (mode->rates[j].rate == rate) 1895 if (rate > 110)
1896 have_higher_than_11mbit = true;
1897
1898 for (j = 0; j < sband->n_bitrates; j++) {
1899 if (sband->bitrates[j].bitrate == rate)
1657 rates |= BIT(j); 1900 rates |= BIT(j);
1901 if (elems.ext_supp_rates[i] & 0x80)
1902 basic_rates |= BIT(j);
1903 }
1658 } 1904 }
1659 sta->supp_rates = rates; 1905
1906 sta->supp_rates[local->hw.conf.channel->band] = rates;
1907 sdata->basic_rates = basic_rates;
1908
1909 /* cf. IEEE 802.11 9.2.12 */
1910 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
1911 have_higher_than_11mbit)
1912 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
1913 else
1914 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1660 1915
1661 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && 1916 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
1662 local->ops->conf_ht) { 1917 local->ops->conf_ht) {
@@ -1675,12 +1930,15 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1675 1930
1676 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) { 1931 if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
1677 sta->flags |= WLAN_STA_WME; 1932 sta->flags |= WLAN_STA_WME;
1933 rcu_read_unlock();
1678 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param, 1934 ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
1679 elems.wmm_param_len); 1935 elems.wmm_param_len);
1680 } 1936 } else
1681 1937 rcu_read_unlock();
1682 1938
1683 sta_info_put(sta); 1939 /* set AID, ieee80211_set_associated() will tell the driver */
1940 bss_conf->aid = aid;
1941 ieee80211_set_associated(dev, ifsta, 1);
1684 1942
1685 ieee80211_associated(dev, ifsta); 1943 ieee80211_associated(dev, ifsta);
1686} 1944}
@@ -1691,8 +1949,16 @@ static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
1691 struct ieee80211_sta_bss *bss) 1949 struct ieee80211_sta_bss *bss)
1692{ 1950{
1693 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1951 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1694 bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)]; 1952 u8 hash_idx;
1695 local->sta_bss_hash[STA_HASH(bss->bssid)] = bss; 1953
1954 if (bss_mesh_cfg(bss))
1955 hash_idx = mesh_id_hash(bss_mesh_id(bss),
1956 bss_mesh_id_len(bss));
1957 else
1958 hash_idx = STA_HASH(bss->bssid);
1959
1960 bss->hnext = local->sta_bss_hash[hash_idx];
1961 local->sta_bss_hash[hash_idx] = bss;
1696} 1962}
1697 1963
1698 1964
@@ -1719,7 +1985,7 @@ static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
1719 1985
1720 1986
1721static struct ieee80211_sta_bss * 1987static struct ieee80211_sta_bss *
1722ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel, 1988ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
1723 u8 *ssid, u8 ssid_len) 1989 u8 *ssid, u8 ssid_len)
1724{ 1990{
1725 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1991 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1731,7 +1997,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1731 atomic_inc(&bss->users); 1997 atomic_inc(&bss->users);
1732 atomic_inc(&bss->users); 1998 atomic_inc(&bss->users);
1733 memcpy(bss->bssid, bssid, ETH_ALEN); 1999 memcpy(bss->bssid, bssid, ETH_ALEN);
1734 bss->channel = channel; 2000 bss->freq = freq;
1735 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { 2001 if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
1736 memcpy(bss->ssid, ssid, ssid_len); 2002 memcpy(bss->ssid, ssid, ssid_len);
1737 bss->ssid_len = ssid_len; 2003 bss->ssid_len = ssid_len;
@@ -1745,9 +2011,8 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
1745 return bss; 2011 return bss;
1746} 2012}
1747 2013
1748
1749static struct ieee80211_sta_bss * 2014static struct ieee80211_sta_bss *
1750ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel, 2015ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
1751 u8 *ssid, u8 ssid_len) 2016 u8 *ssid, u8 ssid_len)
1752{ 2017{
1753 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2018 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1756,8 +2021,9 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
1756 spin_lock_bh(&local->sta_bss_lock); 2021 spin_lock_bh(&local->sta_bss_lock);
1757 bss = local->sta_bss_hash[STA_HASH(bssid)]; 2022 bss = local->sta_bss_hash[STA_HASH(bssid)];
1758 while (bss) { 2023 while (bss) {
1759 if (!memcmp(bss->bssid, bssid, ETH_ALEN) && 2024 if (!bss_mesh_cfg(bss) &&
1760 bss->channel == channel && 2025 !memcmp(bss->bssid, bssid, ETH_ALEN) &&
2026 bss->freq == freq &&
1761 bss->ssid_len == ssid_len && 2027 bss->ssid_len == ssid_len &&
1762 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { 2028 (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
1763 atomic_inc(&bss->users); 2029 atomic_inc(&bss->users);
@@ -1769,6 +2035,72 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
1769 return bss; 2035 return bss;
1770} 2036}
1771 2037
2038#ifdef CONFIG_MAC80211_MESH
2039static struct ieee80211_sta_bss *
2040ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2041 u8 *mesh_cfg, int freq)
2042{
2043 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2044 struct ieee80211_sta_bss *bss;
2045
2046 spin_lock_bh(&local->sta_bss_lock);
2047 bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
2048 while (bss) {
2049 if (bss_mesh_cfg(bss) &&
2050 !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
2051 bss->freq == freq &&
2052 mesh_id_len == bss->mesh_id_len &&
2053 (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
2054 mesh_id_len))) {
2055 atomic_inc(&bss->users);
2056 break;
2057 }
2058 bss = bss->hnext;
2059 }
2060 spin_unlock_bh(&local->sta_bss_lock);
2061 return bss;
2062}
2063
2064static struct ieee80211_sta_bss *
2065ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
2066 u8 *mesh_cfg, int freq)
2067{
2068 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2069 struct ieee80211_sta_bss *bss;
2070
2071 bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
2072 if (!bss)
2073 return NULL;
2074
2075 bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
2076 if (!bss->mesh_cfg) {
2077 kfree(bss);
2078 return NULL;
2079 }
2080
2081 if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
2082 bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
2083 if (!bss->mesh_id) {
2084 kfree(bss->mesh_cfg);
2085 kfree(bss);
2086 return NULL;
2087 }
2088 memcpy(bss->mesh_id, mesh_id, mesh_id_len);
2089 }
2090
2091 atomic_inc(&bss->users);
2092 atomic_inc(&bss->users);
2093 memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
2094 bss->mesh_id_len = mesh_id_len;
2095 bss->freq = freq;
2096 spin_lock_bh(&local->sta_bss_lock);
2097 /* TODO: order by RSSI? */
2098 list_add_tail(&bss->list, &local->sta_bss_list);
2099 __ieee80211_rx_bss_hash_add(dev, bss);
2100 spin_unlock_bh(&local->sta_bss_lock);
2101 return bss;
2102}
2103#endif
1772 2104
1773static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) 2105static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
1774{ 2106{
@@ -1776,6 +2108,8 @@ static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
1776 kfree(bss->rsn_ie); 2108 kfree(bss->rsn_ie);
1777 kfree(bss->wmm_ie); 2109 kfree(bss->wmm_ie);
1778 kfree(bss->ht_ie); 2110 kfree(bss->ht_ie);
2111 kfree(bss_mesh_id(bss));
2112 kfree(bss_mesh_cfg(bss));
1779 kfree(bss); 2113 kfree(bss);
1780} 2114}
1781 2115
@@ -1813,6 +2147,201 @@ void ieee80211_rx_bss_list_deinit(struct net_device *dev)
1813} 2147}
1814 2148
1815 2149
2150static int ieee80211_sta_join_ibss(struct net_device *dev,
2151 struct ieee80211_if_sta *ifsta,
2152 struct ieee80211_sta_bss *bss)
2153{
2154 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2155 int res, rates, i, j;
2156 struct sk_buff *skb;
2157 struct ieee80211_mgmt *mgmt;
2158 struct ieee80211_tx_control control;
2159 struct rate_selection ratesel;
2160 u8 *pos;
2161 struct ieee80211_sub_if_data *sdata;
2162 struct ieee80211_supported_band *sband;
2163
2164 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2165
2166 /* Remove possible STA entries from other IBSS networks. */
2167 sta_info_flush(local, NULL);
2168
2169 if (local->ops->reset_tsf) {
2170 /* Reset own TSF to allow time synchronization work. */
2171 local->ops->reset_tsf(local_to_hw(local));
2172 }
2173 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2174 res = ieee80211_if_config(dev);
2175 if (res)
2176 return res;
2177
2178 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2179
2180 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2181 sdata->drop_unencrypted = bss->capability &
2182 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2183
2184 res = ieee80211_set_freq(local, bss->freq);
2185
2186 if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
2187 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
2188 "%d MHz\n", dev->name, local->oper_channel->center_freq);
2189 return -1;
2190 }
2191
2192 /* Set beacon template */
2193 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2194 do {
2195 if (!skb)
2196 break;
2197
2198 skb_reserve(skb, local->hw.extra_tx_headroom);
2199
2200 mgmt = (struct ieee80211_mgmt *)
2201 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2202 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2203 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2204 IEEE80211_STYPE_BEACON);
2205 memset(mgmt->da, 0xff, ETH_ALEN);
2206 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2207 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2208 mgmt->u.beacon.beacon_int =
2209 cpu_to_le16(local->hw.conf.beacon_int);
2210 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2211
2212 pos = skb_put(skb, 2 + ifsta->ssid_len);
2213 *pos++ = WLAN_EID_SSID;
2214 *pos++ = ifsta->ssid_len;
2215 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2216
2217 rates = bss->supp_rates_len;
2218 if (rates > 8)
2219 rates = 8;
2220 pos = skb_put(skb, 2 + rates);
2221 *pos++ = WLAN_EID_SUPP_RATES;
2222 *pos++ = rates;
2223 memcpy(pos, bss->supp_rates, rates);
2224
2225 if (bss->band == IEEE80211_BAND_2GHZ) {
2226 pos = skb_put(skb, 2 + 1);
2227 *pos++ = WLAN_EID_DS_PARAMS;
2228 *pos++ = 1;
2229 *pos++ = ieee80211_frequency_to_channel(bss->freq);
2230 }
2231
2232 pos = skb_put(skb, 2 + 2);
2233 *pos++ = WLAN_EID_IBSS_PARAMS;
2234 *pos++ = 2;
2235 /* FIX: set ATIM window based on scan results */
2236 *pos++ = 0;
2237 *pos++ = 0;
2238
2239 if (bss->supp_rates_len > 8) {
2240 rates = bss->supp_rates_len - 8;
2241 pos = skb_put(skb, 2 + rates);
2242 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2243 *pos++ = rates;
2244 memcpy(pos, &bss->supp_rates[8], rates);
2245 }
2246
2247 memset(&control, 0, sizeof(control));
2248 rate_control_get_rate(dev, sband, skb, &ratesel);
2249 if (!ratesel.rate) {
2250 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2251 "for IBSS beacon\n", dev->name);
2252 break;
2253 }
2254 control.vif = &sdata->vif;
2255 control.tx_rate = ratesel.rate;
2256 if (sdata->bss_conf.use_short_preamble &&
2257 ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
2258 control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
2259 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2260 control.flags |= IEEE80211_TXCTL_NO_ACK;
2261 control.retry_limit = 1;
2262
2263 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2264 if (ifsta->probe_resp) {
2265 mgmt = (struct ieee80211_mgmt *)
2266 ifsta->probe_resp->data;
2267 mgmt->frame_control =
2268 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2269 IEEE80211_STYPE_PROBE_RESP);
2270 } else {
2271 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2272 "template for IBSS\n", dev->name);
2273 }
2274
2275 if (local->ops->beacon_update &&
2276 local->ops->beacon_update(local_to_hw(local),
2277 skb, &control) == 0) {
2278 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2279 "template\n", dev->name);
2280 skb = NULL;
2281 }
2282
2283 rates = 0;
2284 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2285 for (i = 0; i < bss->supp_rates_len; i++) {
2286 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2287 for (j = 0; j < sband->n_bitrates; j++)
2288 if (sband->bitrates[j].bitrate == bitrate)
2289 rates |= BIT(j);
2290 }
2291 ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
2292 } while (0);
2293
2294 if (skb) {
2295 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2296 "template\n", dev->name);
2297 dev_kfree_skb(skb);
2298 }
2299
2300 ifsta->state = IEEE80211_IBSS_JOINED;
2301 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2302
2303 ieee80211_rx_bss_put(dev, bss);
2304
2305 return res;
2306}
2307
2308u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
2309 struct ieee802_11_elems *elems,
2310 enum ieee80211_band band)
2311{
2312 struct ieee80211_supported_band *sband;
2313 struct ieee80211_rate *bitrates;
2314 size_t num_rates;
2315 u64 supp_rates;
2316 int i, j;
2317 sband = local->hw.wiphy->bands[band];
2318
2319 if (!sband) {
2320 WARN_ON(1);
2321 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
2322 }
2323
2324 bitrates = sband->bitrates;
2325 num_rates = sband->n_bitrates;
2326 supp_rates = 0;
2327 for (i = 0; i < elems->supp_rates_len +
2328 elems->ext_supp_rates_len; i++) {
2329 u8 rate = 0;
2330 int own_rate;
2331 if (i < elems->supp_rates_len)
2332 rate = elems->supp_rates[i];
2333 else if (elems->ext_supp_rates)
2334 rate = elems->ext_supp_rates
2335 [i - elems->supp_rates_len];
2336 own_rate = 5 * (rate & 0x7f);
2337 for (j = 0; j < num_rates; j++)
2338 if (bitrates[j].bitrate == own_rate)
2339 supp_rates |= BIT(j);
2340 }
2341 return supp_rates;
2342}
2343
2344
1816static void ieee80211_rx_bss_info(struct net_device *dev, 2345static void ieee80211_rx_bss_info(struct net_device *dev,
1817 struct ieee80211_mgmt *mgmt, 2346 struct ieee80211_mgmt *mgmt,
1818 size_t len, 2347 size_t len,
@@ -1822,11 +2351,11 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
1822 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2351 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1823 struct ieee802_11_elems elems; 2352 struct ieee802_11_elems elems;
1824 size_t baselen; 2353 size_t baselen;
1825 int channel, clen; 2354 int freq, clen;
1826 struct ieee80211_sta_bss *bss; 2355 struct ieee80211_sta_bss *bss;
1827 struct sta_info *sta; 2356 struct sta_info *sta;
1828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2357 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1829 u64 timestamp; 2358 u64 beacon_timestamp, rx_timestamp;
1830 DECLARE_MAC_BUF(mac); 2359 DECLARE_MAC_BUF(mac);
1831 DECLARE_MAC_BUF(mac2); 2360 DECLARE_MAC_BUF(mac2);
1832 2361
@@ -1843,104 +2372,71 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
1843 if (baselen > len) 2372 if (baselen > len)
1844 return; 2373 return;
1845 2374
1846 timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); 2375 beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
2376 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
1847 2377
1848 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon && 2378 if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
1849 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) { 2379 elems.mesh_config && mesh_matches_local(&elems, dev)) {
1850#ifdef CONFIG_MAC80211_IBSS_DEBUG 2380 u64 rates = ieee80211_sta_get_rates(local, &elems,
1851 static unsigned long last_tsf_debug = 0; 2381 rx_status->band);
1852 u64 tsf; 2382
1853 if (local->ops->get_tsf) 2383 mesh_neighbour_update(mgmt->sa, rates, dev,
1854 tsf = local->ops->get_tsf(local_to_hw(local)); 2384 mesh_peer_accepts_plinks(&elems, dev));
1855 else
1856 tsf = -1LLU;
1857 if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
1858 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
1859 "%s TSF=0x%llx BCN=0x%llx diff=%lld "
1860 "@%lu\n",
1861 print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
1862 (unsigned long long)tsf,
1863 (unsigned long long)timestamp,
1864 (unsigned long long)(tsf - timestamp),
1865 jiffies);
1866 last_tsf_debug = jiffies;
1867 }
1868#endif /* CONFIG_MAC80211_IBSS_DEBUG */
1869 } 2385 }
1870 2386
1871 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); 2387 rcu_read_lock();
1872 2388
1873 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates && 2389 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
1874 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 && 2390 memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
1875 (sta = sta_info_get(local, mgmt->sa))) { 2391 (sta = sta_info_get(local, mgmt->sa))) {
1876 struct ieee80211_hw_mode *mode; 2392 u64 prev_rates;
1877 struct ieee80211_rate *rates; 2393 u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
1878 size_t num_rates; 2394 rx_status->band);
1879 u32 supp_rates, prev_rates;
1880 int i, j;
1881
1882 mode = local->sta_sw_scanning ?
1883 local->scan_hw_mode : local->oper_hw_mode;
1884
1885 if (local->sta_hw_scanning) {
1886 /* search for the correct mode matches the beacon */
1887 list_for_each_entry(mode, &local->modes_list, list)
1888 if (mode->mode == rx_status->phymode)
1889 break;
1890
1891 if (mode == NULL)
1892 mode = local->oper_hw_mode;
1893 }
1894 rates = mode->rates;
1895 num_rates = mode->num_rates;
1896
1897 supp_rates = 0;
1898 for (i = 0; i < elems.supp_rates_len +
1899 elems.ext_supp_rates_len; i++) {
1900 u8 rate = 0;
1901 int own_rate;
1902 if (i < elems.supp_rates_len)
1903 rate = elems.supp_rates[i];
1904 else if (elems.ext_supp_rates)
1905 rate = elems.ext_supp_rates
1906 [i - elems.supp_rates_len];
1907 own_rate = 5 * (rate & 0x7f);
1908 for (j = 0; j < num_rates; j++)
1909 if (rates[j].rate == own_rate)
1910 supp_rates |= BIT(j);
1911 }
1912 2395
1913 prev_rates = sta->supp_rates; 2396 prev_rates = sta->supp_rates[rx_status->band];
1914 sta->supp_rates &= supp_rates; 2397 sta->supp_rates[rx_status->band] &= supp_rates;
1915 if (sta->supp_rates == 0) { 2398 if (sta->supp_rates[rx_status->band] == 0) {
1916 /* No matching rates - this should not really happen. 2399 /* No matching rates - this should not really happen.
1917 * Make sure that at least one rate is marked 2400 * Make sure that at least one rate is marked
1918 * supported to avoid issues with TX rate ctrl. */ 2401 * supported to avoid issues with TX rate ctrl. */
1919 sta->supp_rates = sdata->u.sta.supp_rates_bits; 2402 sta->supp_rates[rx_status->band] =
2403 sdata->u.sta.supp_rates_bits[rx_status->band];
1920 } 2404 }
1921 if (sta->supp_rates != prev_rates) { 2405 if (sta->supp_rates[rx_status->band] != prev_rates) {
1922 printk(KERN_DEBUG "%s: updated supp_rates set for " 2406 printk(KERN_DEBUG "%s: updated supp_rates set for "
1923 "%s based on beacon info (0x%x & 0x%x -> " 2407 "%s based on beacon info (0x%llx & 0x%llx -> "
1924 "0x%x)\n", 2408 "0x%llx)\n",
1925 dev->name, print_mac(mac, sta->addr), prev_rates, 2409 dev->name, print_mac(mac, sta->addr),
1926 supp_rates, sta->supp_rates); 2410 (unsigned long long) prev_rates,
2411 (unsigned long long) supp_rates,
2412 (unsigned long long) sta->supp_rates[rx_status->band]);
1927 } 2413 }
1928 sta_info_put(sta);
1929 } 2414 }
1930 2415
1931 if (!elems.ssid) 2416 rcu_read_unlock();
1932 return;
1933 2417
1934 if (elems.ds_params && elems.ds_params_len == 1) 2418 if (elems.ds_params && elems.ds_params_len == 1)
1935 channel = elems.ds_params[0]; 2419 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
1936 else 2420 else
1937 channel = rx_status->channel; 2421 freq = rx_status->freq;
1938 2422
1939 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel, 2423#ifdef CONFIG_MAC80211_MESH
1940 elems.ssid, elems.ssid_len); 2424 if (elems.mesh_config)
1941 if (!bss) { 2425 bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
1942 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel, 2426 elems.mesh_id_len, elems.mesh_config, freq);
2427 else
2428#endif
2429 bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
1943 elems.ssid, elems.ssid_len); 2430 elems.ssid, elems.ssid_len);
2431 if (!bss) {
2432#ifdef CONFIG_MAC80211_MESH
2433 if (elems.mesh_config)
2434 bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
2435 elems.mesh_id_len, elems.mesh_config, freq);
2436 else
2437#endif
2438 bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
2439 elems.ssid, elems.ssid_len);
1944 if (!bss) 2440 if (!bss)
1945 return; 2441 return;
1946 } else { 2442 } else {
@@ -1952,8 +2448,12 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
1952#endif 2448#endif
1953 } 2449 }
1954 2450
1955 if (bss->probe_resp && beacon) { 2451 bss->band = rx_status->band;
1956 /* Do not allow beacon to override data from Probe Response. */ 2452
2453 if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
2454 bss->probe_resp && beacon) {
2455 /* STA mode:
2456 * Do not allow beacon to override data from Probe Response. */
1957 ieee80211_rx_bss_put(dev, bss); 2457 ieee80211_rx_bss_put(dev, bss);
1958 return; 2458 return;
1959 } 2459 }
@@ -2050,27 +2550,69 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2050 bss->ht_ie_len = 0; 2550 bss->ht_ie_len = 0;
2051 } 2551 }
2052 2552
2053 bss->hw_mode = rx_status->phymode; 2553 bss->timestamp = beacon_timestamp;
2054 bss->freq = rx_status->freq;
2055 if (channel != rx_status->channel &&
2056 (bss->hw_mode == MODE_IEEE80211G ||
2057 bss->hw_mode == MODE_IEEE80211B) &&
2058 channel >= 1 && channel <= 14) {
2059 static const int freq_list[] = {
2060 2412, 2417, 2422, 2427, 2432, 2437, 2442,
2061 2447, 2452, 2457, 2462, 2467, 2472, 2484
2062 };
2063 /* IEEE 802.11g/b mode can receive packets from neighboring
2064 * channels, so map the channel into frequency. */
2065 bss->freq = freq_list[channel - 1];
2066 }
2067 bss->timestamp = timestamp;
2068 bss->last_update = jiffies; 2554 bss->last_update = jiffies;
2069 bss->rssi = rx_status->ssi; 2555 bss->rssi = rx_status->ssi;
2070 bss->signal = rx_status->signal; 2556 bss->signal = rx_status->signal;
2071 bss->noise = rx_status->noise; 2557 bss->noise = rx_status->noise;
2072 if (!beacon) 2558 if (!beacon)
2073 bss->probe_resp++; 2559 bss->probe_resp++;
2560
2561 /* check if we need to merge IBSS */
2562 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
2563 !local->sta_sw_scanning && !local->sta_hw_scanning &&
2564 bss->capability & WLAN_CAPABILITY_IBSS &&
2565 bss->freq == local->oper_channel->center_freq &&
2566 elems.ssid_len == sdata->u.sta.ssid_len &&
2567 memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
2568 if (rx_status->flag & RX_FLAG_TSFT) {
2569 /* in order for correct IBSS merging we need mactime
2570 *
2571 * since mactime is defined as the time the first data
2572 * symbol of the frame hits the PHY, and the timestamp
2573 * of the beacon is defined as "the time that the data
2574 * symbol containing the first bit of the timestamp is
2575 * transmitted to the PHY plus the transmitting STA’s
2576 * delays through its local PHY from the MAC-PHY
2577 * interface to its interface with the WM"
2578 * (802.11 11.1.2) - equals the time this bit arrives at
2579 * the receiver - we have to take into account the
2580 * offset between the two.
2581 * e.g: at 1 MBit that means mactime is 192 usec earlier
2582 * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
2583 */
2584 int rate = local->hw.wiphy->bands[rx_status->band]->
2585 bitrates[rx_status->rate_idx].bitrate;
2586 rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
2587 } else if (local && local->ops && local->ops->get_tsf)
2588 /* second best option: get current TSF */
2589 rx_timestamp = local->ops->get_tsf(local_to_hw(local));
2590 else
2591 /* can't merge without knowing the TSF */
2592 rx_timestamp = -1LLU;
2593#ifdef CONFIG_MAC80211_IBSS_DEBUG
2594 printk(KERN_DEBUG "RX beacon SA=%s BSSID="
2595 "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
2596 print_mac(mac, mgmt->sa),
2597 print_mac(mac2, mgmt->bssid),
2598 (unsigned long long)rx_timestamp,
2599 (unsigned long long)beacon_timestamp,
2600 (unsigned long long)(rx_timestamp - beacon_timestamp),
2601 jiffies);
2602#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2603 if (beacon_timestamp > rx_timestamp) {
2604#ifndef CONFIG_MAC80211_IBSS_DEBUG
2605 if (net_ratelimit())
2606#endif
2607 printk(KERN_DEBUG "%s: beacon TSF higher than "
2608 "local TSF - IBSS merge with BSSID %s\n",
2609 dev->name, print_mac(mac, mgmt->bssid));
2610 ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
2611 ieee80211_ibss_add_sta(dev, NULL,
2612 mgmt->bssid, mgmt->sa);
2613 }
2614 }
2615
2074 ieee80211_rx_bss_put(dev, bss); 2616 ieee80211_rx_bss_put(dev, bss);
2075} 2617}
2076 2618
@@ -2221,8 +2763,11 @@ static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
2221static void ieee80211_rx_mgmt_action(struct net_device *dev, 2763static void ieee80211_rx_mgmt_action(struct net_device *dev,
2222 struct ieee80211_if_sta *ifsta, 2764 struct ieee80211_if_sta *ifsta,
2223 struct ieee80211_mgmt *mgmt, 2765 struct ieee80211_mgmt *mgmt,
2224 size_t len) 2766 size_t len,
2767 struct ieee80211_rx_status *rx_status)
2225{ 2768{
2769 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2770
2226 if (len < IEEE80211_MIN_ACTION_SIZE) 2771 if (len < IEEE80211_MIN_ACTION_SIZE)
2227 return; 2772 return;
2228 2773
@@ -2235,6 +2780,12 @@ static void ieee80211_rx_mgmt_action(struct net_device *dev,
2235 break; 2780 break;
2236 ieee80211_sta_process_addba_request(dev, mgmt, len); 2781 ieee80211_sta_process_addba_request(dev, mgmt, len);
2237 break; 2782 break;
2783 case WLAN_ACTION_ADDBA_RESP:
2784 if (len < (IEEE80211_MIN_ACTION_SIZE +
2785 sizeof(mgmt->u.action.u.addba_resp)))
2786 break;
2787 ieee80211_sta_process_addba_resp(dev, mgmt, len);
2788 break;
2238 case WLAN_ACTION_DELBA: 2789 case WLAN_ACTION_DELBA:
2239 if (len < (IEEE80211_MIN_ACTION_SIZE + 2790 if (len < (IEEE80211_MIN_ACTION_SIZE +
2240 sizeof(mgmt->u.action.u.delba))) 2791 sizeof(mgmt->u.action.u.delba)))
@@ -2248,7 +2799,18 @@ static void ieee80211_rx_mgmt_action(struct net_device *dev,
2248 break; 2799 break;
2249 } 2800 }
2250 break; 2801 break;
2802 case PLINK_CATEGORY:
2803 if (ieee80211_vif_is_mesh(&sdata->vif))
2804 mesh_rx_plink_frame(dev, mgmt, len, rx_status);
2805 break;
2806 case MESH_PATH_SEL_CATEGORY:
2807 if (ieee80211_vif_is_mesh(&sdata->vif))
2808 mesh_rx_path_sel_frame(dev, mgmt, len);
2809 break;
2251 default: 2810 default:
2811 if (net_ratelimit())
2812 printk(KERN_DEBUG "%s: Rx unknown action frame - "
2813 "category=%d\n", dev->name, mgmt->u.action.category);
2252 break; 2814 break;
2253 } 2815 }
2254} 2816}
@@ -2275,13 +2837,13 @@ void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
2275 case IEEE80211_STYPE_PROBE_REQ: 2837 case IEEE80211_STYPE_PROBE_REQ:
2276 case IEEE80211_STYPE_PROBE_RESP: 2838 case IEEE80211_STYPE_PROBE_RESP:
2277 case IEEE80211_STYPE_BEACON: 2839 case IEEE80211_STYPE_BEACON:
2840 case IEEE80211_STYPE_ACTION:
2278 memcpy(skb->cb, rx_status, sizeof(*rx_status)); 2841 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2279 case IEEE80211_STYPE_AUTH: 2842 case IEEE80211_STYPE_AUTH:
2280 case IEEE80211_STYPE_ASSOC_RESP: 2843 case IEEE80211_STYPE_ASSOC_RESP:
2281 case IEEE80211_STYPE_REASSOC_RESP: 2844 case IEEE80211_STYPE_REASSOC_RESP:
2282 case IEEE80211_STYPE_DEAUTH: 2845 case IEEE80211_STYPE_DEAUTH:
2283 case IEEE80211_STYPE_DISASSOC: 2846 case IEEE80211_STYPE_DISASSOC:
2284 case IEEE80211_STYPE_ACTION:
2285 skb_queue_tail(&ifsta->skb_queue, skb); 2847 skb_queue_tail(&ifsta->skb_queue, skb);
2286 queue_work(local->hw.workqueue, &ifsta->work); 2848 queue_work(local->hw.workqueue, &ifsta->work);
2287 return; 2849 return;
@@ -2340,7 +2902,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2340 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len); 2902 ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
2341 break; 2903 break;
2342 case IEEE80211_STYPE_ACTION: 2904 case IEEE80211_STYPE_ACTION:
2343 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len); 2905 ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
2344 break; 2906 break;
2345 } 2907 }
2346 2908
@@ -2348,7 +2910,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
2348} 2910}
2349 2911
2350 2912
2351ieee80211_txrx_result 2913ieee80211_rx_result
2352ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb, 2914ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2353 struct ieee80211_rx_status *rx_status) 2915 struct ieee80211_rx_status *rx_status)
2354{ 2916{
@@ -2356,31 +2918,31 @@ ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
2356 u16 fc; 2918 u16 fc;
2357 2919
2358 if (skb->len < 2) 2920 if (skb->len < 2)
2359 return TXRX_DROP; 2921 return RX_DROP_UNUSABLE;
2360 2922
2361 mgmt = (struct ieee80211_mgmt *) skb->data; 2923 mgmt = (struct ieee80211_mgmt *) skb->data;
2362 fc = le16_to_cpu(mgmt->frame_control); 2924 fc = le16_to_cpu(mgmt->frame_control);
2363 2925
2364 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) 2926 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
2365 return TXRX_CONTINUE; 2927 return RX_CONTINUE;
2366 2928
2367 if (skb->len < 24) 2929 if (skb->len < 24)
2368 return TXRX_DROP; 2930 return RX_DROP_MONITOR;
2369 2931
2370 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { 2932 if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
2371 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) { 2933 if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
2372 ieee80211_rx_mgmt_probe_resp(dev, mgmt, 2934 ieee80211_rx_mgmt_probe_resp(dev, mgmt,
2373 skb->len, rx_status); 2935 skb->len, rx_status);
2374 dev_kfree_skb(skb); 2936 dev_kfree_skb(skb);
2375 return TXRX_QUEUED; 2937 return RX_QUEUED;
2376 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) { 2938 } else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
2377 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, 2939 ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
2378 rx_status); 2940 rx_status);
2379 dev_kfree_skb(skb); 2941 dev_kfree_skb(skb);
2380 return TXRX_QUEUED; 2942 return RX_QUEUED;
2381 } 2943 }
2382 } 2944 }
2383 return TXRX_CONTINUE; 2945 return RX_CONTINUE;
2384} 2946}
2385 2947
2386 2948
@@ -2389,45 +2951,50 @@ static int ieee80211_sta_active_ibss(struct net_device *dev)
2389 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2951 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2390 int active = 0; 2952 int active = 0;
2391 struct sta_info *sta; 2953 struct sta_info *sta;
2954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2955
2956 rcu_read_lock();
2392 2957
2393 read_lock_bh(&local->sta_lock); 2958 list_for_each_entry_rcu(sta, &local->sta_list, list) {
2394 list_for_each_entry(sta, &local->sta_list, list) { 2959 if (sta->sdata == sdata &&
2395 if (sta->dev == dev &&
2396 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL, 2960 time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
2397 jiffies)) { 2961 jiffies)) {
2398 active++; 2962 active++;
2399 break; 2963 break;
2400 } 2964 }
2401 } 2965 }
2402 read_unlock_bh(&local->sta_lock); 2966
2967 rcu_read_unlock();
2403 2968
2404 return active; 2969 return active;
2405} 2970}
2406 2971
2407 2972
2408static void ieee80211_sta_expire(struct net_device *dev) 2973static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
2409{ 2974{
2410 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2975 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2411 struct sta_info *sta, *tmp; 2976 struct sta_info *sta, *tmp;
2412 LIST_HEAD(tmp_list); 2977 LIST_HEAD(tmp_list);
2413 DECLARE_MAC_BUF(mac); 2978 DECLARE_MAC_BUF(mac);
2979 unsigned long flags;
2414 2980
2415 write_lock_bh(&local->sta_lock); 2981 spin_lock_irqsave(&local->sta_lock, flags);
2416 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) 2982 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
2417 if (time_after(jiffies, sta->last_rx + 2983 if (time_after(jiffies, sta->last_rx + exp_time)) {
2418 IEEE80211_IBSS_INACTIVITY_LIMIT)) {
2419 printk(KERN_DEBUG "%s: expiring inactive STA %s\n", 2984 printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
2420 dev->name, print_mac(mac, sta->addr)); 2985 dev->name, print_mac(mac, sta->addr));
2421 __sta_info_get(sta); 2986 sta_info_unlink(&sta);
2422 sta_info_remove(sta); 2987 if (sta)
2423 list_add(&sta->list, &tmp_list); 2988 list_add(&sta->list, &tmp_list);
2424 } 2989 }
2425 write_unlock_bh(&local->sta_lock); 2990 spin_unlock_irqrestore(&local->sta_lock, flags);
2426 2991
2427 list_for_each_entry_safe(sta, tmp, &tmp_list, list) { 2992 synchronize_rcu();
2428 sta_info_free(sta); 2993
2429 sta_info_put(sta); 2994 rtnl_lock();
2430 } 2995 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
2996 sta_info_destroy(sta);
2997 rtnl_unlock();
2431} 2998}
2432 2999
2433 3000
@@ -2436,7 +3003,7 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
2436{ 3003{
2437 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); 3004 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2438 3005
2439 ieee80211_sta_expire(dev); 3006 ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
2440 if (ieee80211_sta_active_ibss(dev)) 3007 if (ieee80211_sta_active_ibss(dev))
2441 return; 3008 return;
2442 3009
@@ -2446,6 +3013,36 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
2446} 3013}
2447 3014
2448 3015
3016#ifdef CONFIG_MAC80211_MESH
3017static void ieee80211_mesh_housekeeping(struct net_device *dev,
3018 struct ieee80211_if_sta *ifsta)
3019{
3020 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3021 bool free_plinks;
3022
3023 ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
3024 mesh_path_expire(dev);
3025
3026 free_plinks = mesh_plink_availables(sdata);
3027 if (free_plinks != sdata->u.sta.accepting_plinks)
3028 ieee80211_if_config_beacon(dev);
3029
3030 mod_timer(&ifsta->timer, jiffies +
3031 IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
3032}
3033
3034
3035void ieee80211_start_mesh(struct net_device *dev)
3036{
3037 struct ieee80211_if_sta *ifsta;
3038 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3039 ifsta = &sdata->u.sta;
3040 ifsta->state = IEEE80211_MESH_UP;
3041 ieee80211_sta_timer((unsigned long)sdata);
3042}
3043#endif
3044
3045
2449void ieee80211_sta_timer(unsigned long data) 3046void ieee80211_sta_timer(unsigned long data)
2450{ 3047{
2451 struct ieee80211_sub_if_data *sdata = 3048 struct ieee80211_sub_if_data *sdata =
@@ -2457,7 +3054,6 @@ void ieee80211_sta_timer(unsigned long data)
2457 queue_work(local->hw.workqueue, &ifsta->work); 3054 queue_work(local->hw.workqueue, &ifsta->work);
2458} 3055}
2459 3056
2460
2461void ieee80211_sta_work(struct work_struct *work) 3057void ieee80211_sta_work(struct work_struct *work)
2462{ 3058{
2463 struct ieee80211_sub_if_data *sdata = 3059 struct ieee80211_sub_if_data *sdata =
@@ -2474,7 +3070,8 @@ void ieee80211_sta_work(struct work_struct *work)
2474 return; 3070 return;
2475 3071
2476 if (sdata->vif.type != IEEE80211_IF_TYPE_STA && 3072 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
2477 sdata->vif.type != IEEE80211_IF_TYPE_IBSS) { 3073 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
3074 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
2478 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface " 3075 printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
2479 "(type=%d)\n", dev->name, sdata->vif.type); 3076 "(type=%d)\n", dev->name, sdata->vif.type);
2480 return; 3077 return;
@@ -2484,6 +3081,13 @@ void ieee80211_sta_work(struct work_struct *work)
2484 while ((skb = skb_dequeue(&ifsta->skb_queue))) 3081 while ((skb = skb_dequeue(&ifsta->skb_queue)))
2485 ieee80211_sta_rx_queued_mgmt(dev, skb); 3082 ieee80211_sta_rx_queued_mgmt(dev, skb);
2486 3083
3084#ifdef CONFIG_MAC80211_MESH
3085 if (ifsta->preq_queue_len &&
3086 time_after(jiffies,
3087 ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
3088 mesh_path_start_discovery(dev);
3089#endif
3090
2487 if (ifsta->state != IEEE80211_AUTHENTICATE && 3091 if (ifsta->state != IEEE80211_AUTHENTICATE &&
2488 ifsta->state != IEEE80211_ASSOCIATE && 3092 ifsta->state != IEEE80211_ASSOCIATE &&
2489 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) { 3093 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
@@ -2519,6 +3123,11 @@ void ieee80211_sta_work(struct work_struct *work)
2519 case IEEE80211_IBSS_JOINED: 3123 case IEEE80211_IBSS_JOINED:
2520 ieee80211_sta_merge_ibss(dev, ifsta); 3124 ieee80211_sta_merge_ibss(dev, ifsta);
2521 break; 3125 break;
3126#ifdef CONFIG_MAC80211_MESH
3127 case IEEE80211_MESH_UP:
3128 ieee80211_mesh_housekeeping(dev, ifsta);
3129 break;
3130#endif
2522 default: 3131 default:
2523 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n", 3132 printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
2524 ifsta->state); 3133 ifsta->state);
@@ -2629,7 +3238,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
2629 } 3238 }
2630 3239
2631 spin_lock_bh(&local->sta_bss_lock); 3240 spin_lock_bh(&local->sta_bss_lock);
2632 freq = local->oper_channel->freq; 3241 freq = local->oper_channel->center_freq;
2633 list_for_each_entry(bss, &local->sta_bss_list, list) { 3242 list_for_each_entry(bss, &local->sta_bss_list, list) {
2634 if (!(bss->capability & WLAN_CAPABILITY_ESS)) 3243 if (!(bss->capability & WLAN_CAPABILITY_ESS))
2635 continue; 3244 continue;
@@ -2660,7 +3269,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
2660 spin_unlock_bh(&local->sta_bss_lock); 3269 spin_unlock_bh(&local->sta_bss_lock);
2661 3270
2662 if (selected) { 3271 if (selected) {
2663 ieee80211_set_channel(local, -1, selected->freq); 3272 ieee80211_set_freq(local, selected->freq);
2664 if (!(ifsta->flags & IEEE80211_STA_SSID_SET)) 3273 if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
2665 ieee80211_sta_set_ssid(dev, selected->ssid, 3274 ieee80211_sta_set_ssid(dev, selected->ssid,
2666 selected->ssid_len); 3275 selected->ssid_len);
@@ -2684,162 +3293,6 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
2684 return -1; 3293 return -1;
2685} 3294}
2686 3295
2687static int ieee80211_sta_join_ibss(struct net_device *dev,
2688 struct ieee80211_if_sta *ifsta,
2689 struct ieee80211_sta_bss *bss)
2690{
2691 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2692 int res, rates, i, j;
2693 struct sk_buff *skb;
2694 struct ieee80211_mgmt *mgmt;
2695 struct ieee80211_tx_control control;
2696 struct ieee80211_hw_mode *mode;
2697 struct rate_selection ratesel;
2698 u8 *pos;
2699 struct ieee80211_sub_if_data *sdata;
2700
2701 /* Remove possible STA entries from other IBSS networks. */
2702 sta_info_flush(local, NULL);
2703
2704 if (local->ops->reset_tsf) {
2705 /* Reset own TSF to allow time synchronization work. */
2706 local->ops->reset_tsf(local_to_hw(local));
2707 }
2708 memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
2709 res = ieee80211_if_config(dev);
2710 if (res)
2711 return res;
2712
2713 local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
2714
2715 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2716 sdata->drop_unencrypted = bss->capability &
2717 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
2718
2719 res = ieee80211_set_channel(local, -1, bss->freq);
2720
2721 if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) {
2722 printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
2723 "(%d MHz)\n", dev->name, local->hw.conf.channel,
2724 local->hw.conf.freq);
2725 return -1;
2726 }
2727
2728 /* Set beacon template based on scan results */
2729 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
2730 do {
2731 if (!skb)
2732 break;
2733
2734 skb_reserve(skb, local->hw.extra_tx_headroom);
2735
2736 mgmt = (struct ieee80211_mgmt *)
2737 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2738 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2739 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2740 IEEE80211_STYPE_BEACON);
2741 memset(mgmt->da, 0xff, ETH_ALEN);
2742 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
2743 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
2744 mgmt->u.beacon.beacon_int =
2745 cpu_to_le16(local->hw.conf.beacon_int);
2746 mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
2747
2748 pos = skb_put(skb, 2 + ifsta->ssid_len);
2749 *pos++ = WLAN_EID_SSID;
2750 *pos++ = ifsta->ssid_len;
2751 memcpy(pos, ifsta->ssid, ifsta->ssid_len);
2752
2753 rates = bss->supp_rates_len;
2754 if (rates > 8)
2755 rates = 8;
2756 pos = skb_put(skb, 2 + rates);
2757 *pos++ = WLAN_EID_SUPP_RATES;
2758 *pos++ = rates;
2759 memcpy(pos, bss->supp_rates, rates);
2760
2761 pos = skb_put(skb, 2 + 1);
2762 *pos++ = WLAN_EID_DS_PARAMS;
2763 *pos++ = 1;
2764 *pos++ = bss->channel;
2765
2766 pos = skb_put(skb, 2 + 2);
2767 *pos++ = WLAN_EID_IBSS_PARAMS;
2768 *pos++ = 2;
2769 /* FIX: set ATIM window based on scan results */
2770 *pos++ = 0;
2771 *pos++ = 0;
2772
2773 if (bss->supp_rates_len > 8) {
2774 rates = bss->supp_rates_len - 8;
2775 pos = skb_put(skb, 2 + rates);
2776 *pos++ = WLAN_EID_EXT_SUPP_RATES;
2777 *pos++ = rates;
2778 memcpy(pos, &bss->supp_rates[8], rates);
2779 }
2780
2781 memset(&control, 0, sizeof(control));
2782 rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel);
2783 if (!ratesel.rate) {
2784 printk(KERN_DEBUG "%s: Failed to determine TX rate "
2785 "for IBSS beacon\n", dev->name);
2786 break;
2787 }
2788 control.vif = &sdata->vif;
2789 control.tx_rate =
2790 (sdata->bss_conf.use_short_preamble &&
2791 (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
2792 ratesel.rate->val2 : ratesel.rate->val;
2793 control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
2794 control.power_level = local->hw.conf.power_level;
2795 control.flags |= IEEE80211_TXCTL_NO_ACK;
2796 control.retry_limit = 1;
2797
2798 ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
2799 if (ifsta->probe_resp) {
2800 mgmt = (struct ieee80211_mgmt *)
2801 ifsta->probe_resp->data;
2802 mgmt->frame_control =
2803 IEEE80211_FC(IEEE80211_FTYPE_MGMT,
2804 IEEE80211_STYPE_PROBE_RESP);
2805 } else {
2806 printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
2807 "template for IBSS\n", dev->name);
2808 }
2809
2810 if (local->ops->beacon_update &&
2811 local->ops->beacon_update(local_to_hw(local),
2812 skb, &control) == 0) {
2813 printk(KERN_DEBUG "%s: Configured IBSS beacon "
2814 "template based on scan results\n", dev->name);
2815 skb = NULL;
2816 }
2817
2818 rates = 0;
2819 mode = local->oper_hw_mode;
2820 for (i = 0; i < bss->supp_rates_len; i++) {
2821 int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
2822 for (j = 0; j < mode->num_rates; j++)
2823 if (mode->rates[j].rate == bitrate)
2824 rates |= BIT(j);
2825 }
2826 ifsta->supp_rates_bits = rates;
2827 } while (0);
2828
2829 if (skb) {
2830 printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
2831 "template\n", dev->name);
2832 dev_kfree_skb(skb);
2833 }
2834
2835 ifsta->state = IEEE80211_IBSS_JOINED;
2836 mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
2837
2838 ieee80211_rx_bss_put(dev, bss);
2839
2840 return res;
2841}
2842
2843 3296
2844static int ieee80211_sta_create_ibss(struct net_device *dev, 3297static int ieee80211_sta_create_ibss(struct net_device *dev,
2845 struct ieee80211_if_sta *ifsta) 3298 struct ieee80211_if_sta *ifsta)
@@ -2847,7 +3300,7 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
2847 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3300 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2848 struct ieee80211_sta_bss *bss; 3301 struct ieee80211_sta_bss *bss;
2849 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3302 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2850 struct ieee80211_hw_mode *mode; 3303 struct ieee80211_supported_band *sband;
2851 u8 bssid[ETH_ALEN], *pos; 3304 u8 bssid[ETH_ALEN], *pos;
2852 int i; 3305 int i;
2853 DECLARE_MAC_BUF(mac); 3306 DECLARE_MAC_BUF(mac);
@@ -2869,28 +3322,28 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
2869 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n", 3322 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
2870 dev->name, print_mac(mac, bssid)); 3323 dev->name, print_mac(mac, bssid));
2871 3324
2872 bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel, 3325 bss = ieee80211_rx_bss_add(dev, bssid,
3326 local->hw.conf.channel->center_freq,
2873 sdata->u.sta.ssid, sdata->u.sta.ssid_len); 3327 sdata->u.sta.ssid, sdata->u.sta.ssid_len);
2874 if (!bss) 3328 if (!bss)
2875 return -ENOMEM; 3329 return -ENOMEM;
2876 3330
2877 mode = local->oper_hw_mode; 3331 bss->band = local->hw.conf.channel->band;
3332 sband = local->hw.wiphy->bands[bss->band];
2878 3333
2879 if (local->hw.conf.beacon_int == 0) 3334 if (local->hw.conf.beacon_int == 0)
2880 local->hw.conf.beacon_int = 100; 3335 local->hw.conf.beacon_int = 10000;
2881 bss->beacon_int = local->hw.conf.beacon_int; 3336 bss->beacon_int = local->hw.conf.beacon_int;
2882 bss->hw_mode = local->hw.conf.phymode;
2883 bss->freq = local->hw.conf.freq;
2884 bss->last_update = jiffies; 3337 bss->last_update = jiffies;
2885 bss->capability = WLAN_CAPABILITY_IBSS; 3338 bss->capability = WLAN_CAPABILITY_IBSS;
2886 if (sdata->default_key) { 3339 if (sdata->default_key) {
2887 bss->capability |= WLAN_CAPABILITY_PRIVACY; 3340 bss->capability |= WLAN_CAPABILITY_PRIVACY;
2888 } else 3341 } else
2889 sdata->drop_unencrypted = 0; 3342 sdata->drop_unencrypted = 0;
2890 bss->supp_rates_len = mode->num_rates; 3343 bss->supp_rates_len = sband->n_bitrates;
2891 pos = bss->supp_rates; 3344 pos = bss->supp_rates;
2892 for (i = 0; i < mode->num_rates; i++) { 3345 for (i = 0; i < sband->n_bitrates; i++) {
2893 int rate = mode->rates[i].rate; 3346 int rate = sband->bitrates[i].bitrate;
2894 *pos++ = (u8) (rate / 5); 3347 *pos++ = (u8) (rate / 5);
2895 } 3348 }
2896 3349
@@ -2939,7 +3392,8 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
2939 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid)); 3392 "%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
2940#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 3393#endif /* CONFIG_MAC80211_IBSS_DEBUG */
2941 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 && 3394 if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
2942 (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel, 3395 (bss = ieee80211_rx_bss_get(dev, bssid,
3396 local->hw.conf.channel->center_freq,
2943 ifsta->ssid, ifsta->ssid_len))) { 3397 ifsta->ssid, ifsta->ssid_len))) {
2944 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s" 3398 printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
2945 " based on configured SSID\n", 3399 " based on configured SSID\n",
@@ -2967,13 +3421,13 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
2967 if (time_after(jiffies, ifsta->ibss_join_req + 3421 if (time_after(jiffies, ifsta->ibss_join_req +
2968 IEEE80211_IBSS_JOIN_TIMEOUT)) { 3422 IEEE80211_IBSS_JOIN_TIMEOUT)) {
2969 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) && 3423 if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
2970 local->oper_channel->flag & IEEE80211_CHAN_W_IBSS) 3424 (!(local->oper_channel->flags &
3425 IEEE80211_CHAN_NO_IBSS)))
2971 return ieee80211_sta_create_ibss(dev, ifsta); 3426 return ieee80211_sta_create_ibss(dev, ifsta);
2972 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) { 3427 if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
2973 printk(KERN_DEBUG "%s: IBSS not allowed on the" 3428 printk(KERN_DEBUG "%s: IBSS not allowed on"
2974 " configured channel %d (%d MHz)\n", 3429 " %d MHz\n", dev->name,
2975 dev->name, local->hw.conf.channel, 3430 local->hw.conf.channel->center_freq);
2976 local->hw.conf.freq);
2977 } 3431 }
2978 3432
2979 /* No IBSS found - decrease scan interval and continue 3433 /* No IBSS found - decrease scan interval and continue
@@ -2992,7 +3446,7 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
2992 3446
2993int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len) 3447int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
2994{ 3448{
2995 struct ieee80211_sub_if_data *sdata; 3449 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2996 struct ieee80211_if_sta *ifsta; 3450 struct ieee80211_if_sta *ifsta;
2997 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 3451 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2998 3452
@@ -3006,18 +3460,23 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3006 int i; 3460 int i;
3007 3461
3008 memset(&qparam, 0, sizeof(qparam)); 3462 memset(&qparam, 0, sizeof(qparam));
3009 /* TODO: are these ok defaults for all hw_modes? */ 3463
3010 qparam.aifs = 2; 3464 qparam.aifs = 2;
3011 qparam.cw_min = 3465
3012 local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15; 3466 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
3467 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
3468 qparam.cw_min = 31;
3469 else
3470 qparam.cw_min = 15;
3471
3013 qparam.cw_max = 1023; 3472 qparam.cw_max = 1023;
3014 qparam.burst_time = 0; 3473 qparam.txop = 0;
3474
3015 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++) 3475 for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
3016 {
3017 local->ops->conf_tx(local_to_hw(local), 3476 local->ops->conf_tx(local_to_hw(local),
3018 i + IEEE80211_TX_QUEUE_DATA0, 3477 i + IEEE80211_TX_QUEUE_DATA0,
3019 &qparam); 3478 &qparam);
3020 } 3479
3021 /* IBSS uses different parameters for Beacon sending */ 3480 /* IBSS uses different parameters for Beacon sending */
3022 qparam.cw_min++; 3481 qparam.cw_min++;
3023 qparam.cw_min *= 2; 3482 qparam.cw_min *= 2;
@@ -3026,7 +3485,6 @@ int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
3026 IEEE80211_TX_QUEUE_BEACON, &qparam); 3485 IEEE80211_TX_QUEUE_BEACON, &qparam);
3027 } 3486 }
3028 3487
3029 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3030 ifsta = &sdata->u.sta; 3488 ifsta = &sdata->u.sta;
3031 3489
3032 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0) 3490 if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
@@ -3118,6 +3576,13 @@ static void ieee80211_send_nullfunc(struct ieee80211_local *local,
3118} 3576}
3119 3577
3120 3578
3579static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
3580{
3581 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
3582 ieee80211_vif_is_mesh(&sdata->vif))
3583 ieee80211_sta_timer((unsigned long)sdata);
3584}
3585
3121void ieee80211_scan_completed(struct ieee80211_hw *hw) 3586void ieee80211_scan_completed(struct ieee80211_hw *hw)
3122{ 3587{
3123 struct ieee80211_local *local = hw_to_local(hw); 3588 struct ieee80211_local *local = hw_to_local(hw);
@@ -3131,6 +3596,12 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
3131 3596
3132 if (local->sta_hw_scanning) { 3597 if (local->sta_hw_scanning) {
3133 local->sta_hw_scanning = 0; 3598 local->sta_hw_scanning = 0;
3599 /* Restart STA timer for HW scan case */
3600 rcu_read_lock();
3601 list_for_each_entry_rcu(sdata, &local->interfaces, list)
3602 ieee80211_restart_sta_timer(sdata);
3603 rcu_read_unlock();
3604
3134 goto done; 3605 goto done;
3135 } 3606 }
3136 3607
@@ -3157,11 +3628,12 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
3157 if (sdata->dev == local->mdev) 3628 if (sdata->dev == local->mdev)
3158 continue; 3629 continue;
3159 3630
3160 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 3631 /* Tell AP we're back */
3161 if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) 3632 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
3162 ieee80211_send_nullfunc(local, sdata, 0); 3633 sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
3163 ieee80211_sta_timer((unsigned long)sdata); 3634 ieee80211_send_nullfunc(local, sdata, 0);
3164 } 3635
3636 ieee80211_restart_sta_timer(sdata);
3165 3637
3166 netif_wake_queue(sdata->dev); 3638 netif_wake_queue(sdata->dev);
3167 } 3639 }
@@ -3185,7 +3657,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3185 container_of(work, struct ieee80211_local, scan_work.work); 3657 container_of(work, struct ieee80211_local, scan_work.work);
3186 struct net_device *dev = local->scan_dev; 3658 struct net_device *dev = local->scan_dev;
3187 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 3659 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3188 struct ieee80211_hw_mode *mode; 3660 struct ieee80211_supported_band *sband;
3189 struct ieee80211_channel *chan; 3661 struct ieee80211_channel *chan;
3190 int skip; 3662 int skip;
3191 unsigned long next_delay = 0; 3663 unsigned long next_delay = 0;
@@ -3195,44 +3667,59 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3195 3667
3196 switch (local->scan_state) { 3668 switch (local->scan_state) {
3197 case SCAN_SET_CHANNEL: 3669 case SCAN_SET_CHANNEL:
3198 mode = local->scan_hw_mode; 3670 /*
3199 if (local->scan_hw_mode->list.next == &local->modes_list && 3671 * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
3200 local->scan_channel_idx >= mode->num_channels) { 3672 * after we successfully scanned the last channel of the last
3673 * band (and the last band is supported by the hw)
3674 */
3675 if (local->scan_band < IEEE80211_NUM_BANDS)
3676 sband = local->hw.wiphy->bands[local->scan_band];
3677 else
3678 sband = NULL;
3679
3680 /*
3681 * If we are at an unsupported band and have more bands
3682 * left to scan, advance to the next supported one.
3683 */
3684 while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
3685 local->scan_band++;
3686 sband = local->hw.wiphy->bands[local->scan_band];
3687 local->scan_channel_idx = 0;
3688 }
3689
3690 /* if no more bands/channels left, complete scan */
3691 if (!sband || local->scan_channel_idx >= sband->n_channels) {
3201 ieee80211_scan_completed(local_to_hw(local)); 3692 ieee80211_scan_completed(local_to_hw(local));
3202 return; 3693 return;
3203 } 3694 }
3204 skip = !(local->enabled_modes & (1 << mode->mode)); 3695 skip = 0;
3205 chan = &mode->channels[local->scan_channel_idx]; 3696 chan = &sband->channels[local->scan_channel_idx];
3206 if (!(chan->flag & IEEE80211_CHAN_W_SCAN) || 3697
3698 if (chan->flags & IEEE80211_CHAN_DISABLED ||
3207 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && 3699 (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
3208 !(chan->flag & IEEE80211_CHAN_W_IBSS)) || 3700 chan->flags & IEEE80211_CHAN_NO_IBSS))
3209 (local->hw_modes & local->enabled_modes &
3210 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
3211 skip = 1; 3701 skip = 1;
3212 3702
3213 if (!skip) { 3703 if (!skip) {
3214#if 0
3215 printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
3216 dev->name, chan->chan, chan->freq);
3217#endif
3218
3219 local->scan_channel = chan; 3704 local->scan_channel = chan;
3220 if (ieee80211_hw_config(local)) { 3705 if (ieee80211_hw_config(local)) {
3221 printk(KERN_DEBUG "%s: failed to set channel " 3706 printk(KERN_DEBUG "%s: failed to set freq to "
3222 "%d (%d MHz) for scan\n", dev->name, 3707 "%d MHz for scan\n", dev->name,
3223 chan->chan, chan->freq); 3708 chan->center_freq);
3224 skip = 1; 3709 skip = 1;
3225 } 3710 }
3226 } 3711 }
3227 3712
3713 /* advance state machine to next channel/band */
3228 local->scan_channel_idx++; 3714 local->scan_channel_idx++;
3229 if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) { 3715 if (local->scan_channel_idx >= sband->n_channels) {
3230 if (local->scan_hw_mode->list.next != &local->modes_list) { 3716 /*
3231 local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next, 3717 * scan_band may end up == IEEE80211_NUM_BANDS, but
3232 struct ieee80211_hw_mode, 3718 * we'll catch that case above and complete the scan
3233 list); 3719 * if that is the case.
3234 local->scan_channel_idx = 0; 3720 */
3235 } 3721 local->scan_band++;
3722 local->scan_channel_idx = 0;
3236 } 3723 }
3237 3724
3238 if (skip) 3725 if (skip)
@@ -3243,13 +3730,14 @@ void ieee80211_sta_scan_work(struct work_struct *work)
3243 local->scan_state = SCAN_SEND_PROBE; 3730 local->scan_state = SCAN_SEND_PROBE;
3244 break; 3731 break;
3245 case SCAN_SEND_PROBE: 3732 case SCAN_SEND_PROBE:
3246 if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) { 3733 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3247 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3248 local->scan_ssid_len);
3249 next_delay = IEEE80211_CHANNEL_TIME;
3250 } else
3251 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
3252 local->scan_state = SCAN_SET_CHANNEL; 3734 local->scan_state = SCAN_SET_CHANNEL;
3735
3736 if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
3737 break;
3738 ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
3739 local->scan_ssid_len);
3740 next_delay = IEEE80211_CHANNEL_TIME;
3253 break; 3741 break;
3254 } 3742 }
3255 3743
@@ -3324,10 +3812,8 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
3324 } else 3812 } else
3325 local->scan_ssid_len = 0; 3813 local->scan_ssid_len = 0;
3326 local->scan_state = SCAN_SET_CHANNEL; 3814 local->scan_state = SCAN_SET_CHANNEL;
3327 local->scan_hw_mode = list_entry(local->modes_list.next,
3328 struct ieee80211_hw_mode,
3329 list);
3330 local->scan_channel_idx = 0; 3815 local->scan_channel_idx = 0;
3816 local->scan_band = IEEE80211_BAND_2GHZ;
3331 local->scan_dev = dev; 3817 local->scan_dev = dev;
3332 3818
3333 netif_tx_lock_bh(local->mdev); 3819 netif_tx_lock_bh(local->mdev);
@@ -3382,9 +3868,6 @@ ieee80211_sta_scan_result(struct net_device *dev,
3382 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) 3868 bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
3383 return current_ev; 3869 return current_ev;
3384 3870
3385 if (!(local->enabled_modes & (1 << bss->hw_mode)))
3386 return current_ev;
3387
3388 memset(&iwe, 0, sizeof(iwe)); 3871 memset(&iwe, 0, sizeof(iwe));
3389 iwe.cmd = SIOCGIWAP; 3872 iwe.cmd = SIOCGIWAP;
3390 iwe.u.ap_addr.sa_family = ARPHRD_ETHER; 3873 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
@@ -3394,15 +3877,25 @@ ieee80211_sta_scan_result(struct net_device *dev,
3394 3877
3395 memset(&iwe, 0, sizeof(iwe)); 3878 memset(&iwe, 0, sizeof(iwe));
3396 iwe.cmd = SIOCGIWESSID; 3879 iwe.cmd = SIOCGIWESSID;
3397 iwe.u.data.length = bss->ssid_len; 3880 if (bss_mesh_cfg(bss)) {
3398 iwe.u.data.flags = 1; 3881 iwe.u.data.length = bss_mesh_id_len(bss);
3399 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, 3882 iwe.u.data.flags = 1;
3400 bss->ssid); 3883 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3884 bss_mesh_id(bss));
3885 } else {
3886 iwe.u.data.length = bss->ssid_len;
3887 iwe.u.data.flags = 1;
3888 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
3889 bss->ssid);
3890 }
3401 3891
3402 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) { 3892 if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
3893 || bss_mesh_cfg(bss)) {
3403 memset(&iwe, 0, sizeof(iwe)); 3894 memset(&iwe, 0, sizeof(iwe));
3404 iwe.cmd = SIOCGIWMODE; 3895 iwe.cmd = SIOCGIWMODE;
3405 if (bss->capability & WLAN_CAPABILITY_ESS) 3896 if (bss_mesh_cfg(bss))
3897 iwe.u.mode = IW_MODE_MESH;
3898 else if (bss->capability & WLAN_CAPABILITY_ESS)
3406 iwe.u.mode = IW_MODE_MASTER; 3899 iwe.u.mode = IW_MODE_MASTER;
3407 else 3900 else
3408 iwe.u.mode = IW_MODE_ADHOC; 3901 iwe.u.mode = IW_MODE_ADHOC;
@@ -3412,12 +3905,15 @@ ieee80211_sta_scan_result(struct net_device *dev,
3412 3905
3413 memset(&iwe, 0, sizeof(iwe)); 3906 memset(&iwe, 0, sizeof(iwe));
3414 iwe.cmd = SIOCGIWFREQ; 3907 iwe.cmd = SIOCGIWFREQ;
3415 iwe.u.freq.m = bss->channel; 3908 iwe.u.freq.m = bss->freq;
3416 iwe.u.freq.e = 0; 3909 iwe.u.freq.e = 6;
3417 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 3910 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3418 IW_EV_FREQ_LEN); 3911 IW_EV_FREQ_LEN);
3419 iwe.u.freq.m = bss->freq * 100000; 3912
3420 iwe.u.freq.e = 1; 3913 memset(&iwe, 0, sizeof(iwe));
3914 iwe.cmd = SIOCGIWFREQ;
3915 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
3916 iwe.u.freq.e = 0;
3421 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, 3917 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
3422 IW_EV_FREQ_LEN); 3918 IW_EV_FREQ_LEN);
3423 3919
@@ -3488,6 +3984,45 @@ ieee80211_sta_scan_result(struct net_device *dev,
3488 } 3984 }
3489 } 3985 }
3490 3986
3987 if (bss_mesh_cfg(bss)) {
3988 char *buf;
3989 u8 *cfg = bss_mesh_cfg(bss);
3990 buf = kmalloc(50, GFP_ATOMIC);
3991 if (buf) {
3992 memset(&iwe, 0, sizeof(iwe));
3993 iwe.cmd = IWEVCUSTOM;
3994 sprintf(buf, "Mesh network (version %d)", cfg[0]);
3995 iwe.u.data.length = strlen(buf);
3996 current_ev = iwe_stream_add_point(current_ev, end_buf,
3997 &iwe, buf);
3998 sprintf(buf, "Path Selection Protocol ID: "
3999 "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
4000 cfg[4]);
4001 iwe.u.data.length = strlen(buf);
4002 current_ev = iwe_stream_add_point(current_ev, end_buf,
4003 &iwe, buf);
4004 sprintf(buf, "Path Selection Metric ID: "
4005 "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
4006 cfg[8]);
4007 iwe.u.data.length = strlen(buf);
4008 current_ev = iwe_stream_add_point(current_ev, end_buf,
4009 &iwe, buf);
4010 sprintf(buf, "Congestion Control Mode ID: "
4011 "0x%02X%02X%02X%02X", cfg[9], cfg[10],
4012 cfg[11], cfg[12]);
4013 iwe.u.data.length = strlen(buf);
4014 current_ev = iwe_stream_add_point(current_ev, end_buf,
4015 &iwe, buf);
4016 sprintf(buf, "Channel Precedence: "
4017 "0x%02X%02X%02X%02X", cfg[13], cfg[14],
4018 cfg[15], cfg[16]);
4019 iwe.u.data.length = strlen(buf);
4020 current_ev = iwe_stream_add_point(current_ev, end_buf,
4021 &iwe, buf);
4022 kfree(buf);
4023 }
4024 }
4025
3491 return current_ev; 4026 return current_ev;
3492} 4027}
3493 4028
@@ -3556,15 +4091,23 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
3556 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n", 4091 printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
3557 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name); 4092 wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
3558 4093
3559 sta = sta_info_add(local, dev, addr, GFP_ATOMIC); 4094 sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
3560 if (!sta) 4095 if (!sta)
3561 return NULL; 4096 return NULL;
3562 4097
3563 sta->supp_rates = sdata->u.sta.supp_rates_bits; 4098 sta->flags |= WLAN_STA_AUTHORIZED;
4099
4100 sta->supp_rates[local->hw.conf.channel->band] =
4101 sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
3564 4102
3565 rate_control_rate_init(sta, local); 4103 rate_control_rate_init(sta, local);
3566 4104
3567 return sta; /* caller will call sta_info_put() */ 4105 if (sta_info_insert(sta)) {
4106 sta_info_destroy(sta);
4107 return NULL;
4108 }
4109
4110 return sta;
3568} 4111}
3569 4112
3570 4113
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index ed57fb8e82fc..f91fb4092652 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -13,14 +13,15 @@
13#include <linux/etherdevice.h> 13#include <linux/etherdevice.h>
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/rcupdate.h> 15#include <linux/rcupdate.h>
16#include <linux/rtnetlink.h>
16#include <net/mac80211.h> 17#include <net/mac80211.h>
17#include "ieee80211_i.h" 18#include "ieee80211_i.h"
18#include "debugfs_key.h" 19#include "debugfs_key.h"
19#include "aes_ccm.h" 20#include "aes_ccm.h"
20 21
21 22
22/* 23/**
23 * Key handling basics 24 * DOC: Key handling basics
24 * 25 *
25 * Key handling in mac80211 is done based on per-interface (sub_if_data) 26 * Key handling in mac80211 is done based on per-interface (sub_if_data)
26 * keys and per-station keys. Since each station belongs to an interface, 27 * keys and per-station keys. Since each station belongs to an interface,
@@ -34,6 +35,10 @@
34 * 35 *
35 * All operations here are called under RTNL so no extra locking is 36 * All operations here are called under RTNL so no extra locking is
36 * required. 37 * required.
38 *
39 * NOTE: This code requires that sta info *destruction* is done under
40 * RTNL, otherwise it can try to access already freed STA structs
41 * when a STA key is being freed.
37 */ 42 */
38 43
39static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 44static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
@@ -84,16 +89,25 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
84 key->conf.keyidx, print_mac(mac, addr), ret); 89 key->conf.keyidx, print_mac(mac, addr), ret);
85} 90}
86 91
92static void ieee80211_key_mark_hw_accel_off(struct ieee80211_key *key)
93{
94 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
95 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
96 key->flags |= KEY_FLAG_REMOVE_FROM_HARDWARE;
97 }
98}
99
87static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key) 100static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
88{ 101{
89 const u8 *addr; 102 const u8 *addr;
90 int ret; 103 int ret;
91 DECLARE_MAC_BUF(mac); 104 DECLARE_MAC_BUF(mac);
92 105
93 if (!key->local->ops->set_key) 106 if (!key || !key->local->ops->set_key)
94 return; 107 return;
95 108
96 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 109 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
110 !(key->flags & KEY_FLAG_REMOVE_FROM_HARDWARE))
97 return; 111 return;
98 112
99 addr = get_mac_for_key(key); 113 addr = get_mac_for_key(key);
@@ -108,12 +122,11 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
108 wiphy_name(key->local->hw.wiphy), 122 wiphy_name(key->local->hw.wiphy),
109 key->conf.keyidx, print_mac(mac, addr), ret); 123 key->conf.keyidx, print_mac(mac, addr), ret);
110 124
111 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 125 key->flags &= ~(KEY_FLAG_UPLOADED_TO_HARDWARE |
126 KEY_FLAG_REMOVE_FROM_HARDWARE);
112} 127}
113 128
114struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata, 129struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
115 struct sta_info *sta,
116 enum ieee80211_key_alg alg,
117 int idx, 130 int idx,
118 size_t key_len, 131 size_t key_len,
119 const u8 *key_data) 132 const u8 *key_data)
@@ -137,10 +150,7 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
137 key->conf.keyidx = idx; 150 key->conf.keyidx = idx;
138 key->conf.keylen = key_len; 151 key->conf.keylen = key_len;
139 memcpy(key->conf.key, key_data, key_len); 152 memcpy(key->conf.key, key_data, key_len);
140 153 INIT_LIST_HEAD(&key->list);
141 key->local = sdata->local;
142 key->sdata = sdata;
143 key->sta = sta;
144 154
145 if (alg == ALG_CCMP) { 155 if (alg == ALG_CCMP) {
146 /* 156 /*
@@ -154,13 +164,68 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
154 } 164 }
155 } 165 }
156 166
157 ieee80211_debugfs_key_add(key->local, key); 167 return key;
168}
158 169
159 /* remove key first */ 170static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
160 if (sta) 171 struct sta_info *sta,
161 ieee80211_key_free(sta->key); 172 struct ieee80211_key *key,
162 else 173 struct ieee80211_key *new)
163 ieee80211_key_free(sdata->keys[idx]); 174{
175 int idx, defkey;
176
177 if (new)
178 list_add(&new->list, &sdata->key_list);
179
180 if (sta) {
181 rcu_assign_pointer(sta->key, new);
182 } else {
183 WARN_ON(new && key && new->conf.keyidx != key->conf.keyidx);
184
185 if (key)
186 idx = key->conf.keyidx;
187 else
188 idx = new->conf.keyidx;
189
190 defkey = key && sdata->default_key == key;
191
192 if (defkey && !new)
193 ieee80211_set_default_key(sdata, -1);
194
195 rcu_assign_pointer(sdata->keys[idx], new);
196 if (defkey && new)
197 ieee80211_set_default_key(sdata, new->conf.keyidx);
198 }
199
200 if (key) {
201 ieee80211_key_mark_hw_accel_off(key);
202 /*
203 * We'll use an empty list to indicate that the key
204 * has already been removed.
205 */
206 list_del_init(&key->list);
207 }
208}
209
210void ieee80211_key_link(struct ieee80211_key *key,
211 struct ieee80211_sub_if_data *sdata,
212 struct sta_info *sta)
213{
214 struct ieee80211_key *old_key;
215 int idx;
216
217 ASSERT_RTNL();
218 might_sleep();
219
220 BUG_ON(!sdata);
221 BUG_ON(!key);
222
223 idx = key->conf.keyidx;
224 key->local = sdata->local;
225 key->sdata = sdata;
226 key->sta = sta;
227
228 ieee80211_debugfs_key_add(key->local, key);
164 229
165 if (sta) { 230 if (sta) {
166 ieee80211_debugfs_key_sta_link(key, sta); 231 ieee80211_debugfs_key_sta_link(key, sta);
@@ -175,61 +240,76 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
175 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) { 240 if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
176 struct sta_info *ap; 241 struct sta_info *ap;
177 242
243 rcu_read_lock();
244
178 /* same here, the AP could be using QoS */ 245 /* same here, the AP could be using QoS */
179 ap = sta_info_get(key->local, key->sdata->u.sta.bssid); 246 ap = sta_info_get(key->local, key->sdata->u.sta.bssid);
180 if (ap) { 247 if (ap) {
181 if (ap->flags & WLAN_STA_WME) 248 if (ap->flags & WLAN_STA_WME)
182 key->conf.flags |= 249 key->conf.flags |=
183 IEEE80211_KEY_FLAG_WMM_STA; 250 IEEE80211_KEY_FLAG_WMM_STA;
184 sta_info_put(ap);
185 } 251 }
252
253 rcu_read_unlock();
186 } 254 }
187 } 255 }
188 256
189 /* enable hwaccel if appropriate */
190 if (netif_running(key->sdata->dev))
191 ieee80211_key_enable_hw_accel(key);
192
193 if (sta) 257 if (sta)
194 rcu_assign_pointer(sta->key, key); 258 old_key = sta->key;
195 else 259 else
196 rcu_assign_pointer(sdata->keys[idx], key); 260 old_key = sdata->keys[idx];
197 261
198 list_add(&key->list, &sdata->key_list); 262 __ieee80211_key_replace(sdata, sta, old_key, key);
199 263
200 return key; 264 if (old_key) {
265 synchronize_rcu();
266 ieee80211_key_free(old_key);
267 }
268
269 if (netif_running(sdata->dev))
270 ieee80211_key_enable_hw_accel(key);
201} 271}
202 272
203void ieee80211_key_free(struct ieee80211_key *key) 273void ieee80211_key_free(struct ieee80211_key *key)
204{ 274{
275 ASSERT_RTNL();
276 might_sleep();
277
205 if (!key) 278 if (!key)
206 return; 279 return;
207 280
208 if (key->sta) { 281 if (key->sdata) {
209 rcu_assign_pointer(key->sta->key, NULL); 282 /*
210 } else { 283 * Replace key with nothingness.
211 if (key->sdata->default_key == key) 284 *
212 ieee80211_set_default_key(key->sdata, -1); 285 * Because other code may have key reference (RCU protected)
213 if (key->conf.keyidx >= 0 && 286 * right now, we then wait for a grace period before freeing
214 key->conf.keyidx < NUM_DEFAULT_KEYS) 287 * it.
215 rcu_assign_pointer(key->sdata->keys[key->conf.keyidx], 288 * An empty list indicates it was never added to the key list
216 NULL); 289 * or has been removed already. It may, however, still be in
217 else 290 * hardware for acceleration.
218 WARN_ON(1); 291 */
219 } 292 if (!list_empty(&key->list))
293 __ieee80211_key_replace(key->sdata, key->sta,
294 key, NULL);
220 295
221 /* wait for all key users to complete */ 296 /*
222 synchronize_rcu(); 297 * Do NOT remove this without looking at sta_info_destroy()
298 */
299 synchronize_rcu();
223 300
224 /* remove from hwaccel if appropriate */ 301 /*
225 ieee80211_key_disable_hw_accel(key); 302 * Remove from hwaccel if appropriate, this will
303 * only happen when the key is actually unlinked,
304 * it will already be done when the key was replaced.
305 */
306 ieee80211_key_disable_hw_accel(key);
307 }
226 308
227 if (key->conf.alg == ALG_CCMP) 309 if (key->conf.alg == ALG_CCMP)
228 ieee80211_aes_key_free(key->u.ccmp.tfm); 310 ieee80211_aes_key_free(key->u.ccmp.tfm);
229 ieee80211_debugfs_key_remove(key); 311 ieee80211_debugfs_key_remove(key);
230 312
231 list_del(&key->list);
232
233 kfree(key); 313 kfree(key);
234} 314}
235 315
@@ -253,6 +333,10 @@ void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx)
253void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata) 333void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
254{ 334{
255 struct ieee80211_key *key, *tmp; 335 struct ieee80211_key *key, *tmp;
336 LIST_HEAD(tmp_list);
337
338 ASSERT_RTNL();
339 might_sleep();
256 340
257 list_for_each_entry_safe(key, tmp, &sdata->key_list, list) 341 list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
258 ieee80211_key_free(key); 342 ieee80211_key_free(key);
@@ -262,8 +346,10 @@ void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
262{ 346{
263 struct ieee80211_key *key; 347 struct ieee80211_key *key;
264 348
265 WARN_ON(!netif_running(sdata->dev)); 349 ASSERT_RTNL();
266 if (!netif_running(sdata->dev)) 350 might_sleep();
351
352 if (WARN_ON(!netif_running(sdata->dev)))
267 return; 353 return;
268 354
269 list_for_each_entry(key, &sdata->key_list, list) 355 list_for_each_entry(key, &sdata->key_list, list)
@@ -274,6 +360,9 @@ void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
274{ 360{
275 struct ieee80211_key *key; 361 struct ieee80211_key *key;
276 362
363 ASSERT_RTNL();
364 might_sleep();
365
277 list_for_each_entry(key, &sdata->key_list, list) 366 list_for_each_entry(key, &sdata->key_list, list)
278 ieee80211_key_disable_hw_accel(key); 367 ieee80211_key_disable_hw_accel(key);
279} 368}
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
new file mode 100644
index 000000000000..594a3356a508
--- /dev/null
+++ b/net/mac80211/mesh.c
@@ -0,0 +1,449 @@
1/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com>
5 *
6 * 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 * published by the Free Software Foundation.
9 */
10
11#include "ieee80211_i.h"
12#include "mesh.h"
13
14#define PP_OFFSET 1 /* Path Selection Protocol */
15#define PM_OFFSET 5 /* Path Selection Metric */
16#define CC_OFFSET 9 /* Congestion Control Mode */
17#define CAPAB_OFFSET 17
18#define ACCEPT_PLINKS 0x80
19
20int mesh_allocated;
21static struct kmem_cache *rm_cache;
22
23void ieee80211s_init(void)
24{
25 mesh_pathtbl_init();
26 mesh_allocated = 1;
27 rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
28 0, 0, NULL);
29}
30
31void ieee80211s_stop(void)
32{
33 mesh_pathtbl_unregister();
34 kmem_cache_destroy(rm_cache);
35}
36
37/**
38 * mesh_matches_local - check if the config of a mesh point matches ours
39 *
40 * @ie: information elements of a management frame from the mesh peer
41 * @dev: local mesh interface
42 *
43 * This function checks if the mesh configuration of a mesh point matches the
44 * local mesh configuration, i.e. if both nodes belong to the same mesh network.
45 */
46bool mesh_matches_local(struct ieee802_11_elems *ie, struct net_device *dev)
47{
48 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
49 struct ieee80211_if_sta *sta = &sdata->u.sta;
50
51 /*
52 * As support for each feature is added, check for matching
53 * - On mesh config capabilities
54 * - Power Save Support En
55 * - Sync support enabled
56 * - Sync support active
57 * - Sync support required from peer
58 * - MDA enabled
59 * - Power management control on fc
60 */
61 if (sta->mesh_id_len == ie->mesh_id_len &&
62 memcmp(sta->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
63 memcmp(sta->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 &&
64 memcmp(sta->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 &&
65 memcmp(sta->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0)
66 return true;
67
68 return false;
69}
70
71/**
72 * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
73 *
74 * @ie: information elements of a management frame from the mesh peer
75 * @dev: local mesh interface
76 */
77bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie,
78 struct net_device *dev)
79{
80 return (*(ie->mesh_config + CAPAB_OFFSET) & ACCEPT_PLINKS) != 0;
81}
82
83/**
84 * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
85 *
86 * @sdata: mesh interface in which mesh beacons are going to be updated
87 */
88void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
89{
90 bool free_plinks;
91
92 /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
93 * the mesh interface might be able to establish plinks with peers that
94 * are already on the table but are not on PLINK_ESTAB state. However,
95 * in general the mesh interface is not accepting peer link requests
96 * from new peers, and that must be reflected in the beacon
97 */
98 free_plinks = mesh_plink_availables(sdata);
99
100 if (free_plinks != sdata->u.sta.accepting_plinks)
101 ieee80211_sta_timer((unsigned long) sdata);
102}
103
104void mesh_ids_set_default(struct ieee80211_if_sta *sta)
105{
106 u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff};
107
108 memcpy(sta->mesh_pp_id, def_id, 4);
109 memcpy(sta->mesh_pm_id, def_id, 4);
110 memcpy(sta->mesh_cc_id, def_id, 4);
111}
112
113int mesh_rmc_init(struct net_device *dev)
114{
115 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
116 int i;
117
118 sdata->u.sta.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
119 if (!sdata->u.sta.rmc)
120 return -ENOMEM;
121 sdata->u.sta.rmc->idx_mask = RMC_BUCKETS - 1;
122 for (i = 0; i < RMC_BUCKETS; i++)
123 INIT_LIST_HEAD(&sdata->u.sta.rmc->bucket[i].list);
124 return 0;
125}
126
127void mesh_rmc_free(struct net_device *dev)
128{
129 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
130 struct mesh_rmc *rmc = sdata->u.sta.rmc;
131 struct rmc_entry *p, *n;
132 int i;
133
134 if (!sdata->u.sta.rmc)
135 return;
136
137 for (i = 0; i < RMC_BUCKETS; i++)
138 list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
139 list_del(&p->list);
140 kmem_cache_free(rm_cache, p);
141 }
142
143 kfree(rmc);
144 sdata->u.sta.rmc = NULL;
145}
146
147/**
148 * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
149 *
150 * @sa: source address
151 * @mesh_hdr: mesh_header
152 *
153 * Returns: 0 if the frame is not in the cache, nonzero otherwise.
154 *
155 * Checks using the source address and the mesh sequence number if we have
156 * received this frame lately. If the frame is not in the cache, it is added to
157 * it.
158 */
159int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
160 struct net_device *dev)
161{
162 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
163 struct mesh_rmc *rmc = sdata->u.sta.rmc;
164 u32 seqnum = 0;
165 int entries = 0;
166 u8 idx;
167 struct rmc_entry *p, *n;
168
169 /* Don't care about endianness since only match matters */
170 memcpy(&seqnum, mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
171 idx = mesh_hdr->seqnum[0] & rmc->idx_mask;
172 list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
173 ++entries;
174 if (time_after(jiffies, p->exp_time) ||
175 (entries == RMC_QUEUE_MAX_LEN)) {
176 list_del(&p->list);
177 kmem_cache_free(rm_cache, p);
178 --entries;
179 } else if ((seqnum == p->seqnum)
180 && (memcmp(sa, p->sa, ETH_ALEN) == 0))
181 return -1;
182 }
183
184 p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
185 if (!p) {
186 printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
187 return 0;
188 }
189 p->seqnum = seqnum;
190 p->exp_time = jiffies + RMC_TIMEOUT;
191 memcpy(p->sa, sa, ETH_ALEN);
192 list_add(&p->list, &rmc->bucket[idx].list);
193 return 0;
194}
195
196void mesh_mgmt_ies_add(struct sk_buff *skb, struct net_device *dev)
197{
198 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
200 struct ieee80211_supported_band *sband;
201 u8 *pos;
202 int len, i, rate;
203
204 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
205 len = sband->n_bitrates;
206 if (len > 8)
207 len = 8;
208 pos = skb_put(skb, len + 2);
209 *pos++ = WLAN_EID_SUPP_RATES;
210 *pos++ = len;
211 for (i = 0; i < len; i++) {
212 rate = sband->bitrates[i].bitrate;
213 *pos++ = (u8) (rate / 5);
214 }
215
216 if (sband->n_bitrates > len) {
217 pos = skb_put(skb, sband->n_bitrates - len + 2);
218 *pos++ = WLAN_EID_EXT_SUPP_RATES;
219 *pos++ = sband->n_bitrates - len;
220 for (i = len; i < sband->n_bitrates; i++) {
221 rate = sband->bitrates[i].bitrate;
222 *pos++ = (u8) (rate / 5);
223 }
224 }
225
226 pos = skb_put(skb, 2 + sdata->u.sta.mesh_id_len);
227 *pos++ = WLAN_EID_MESH_ID;
228 *pos++ = sdata->u.sta.mesh_id_len;
229 if (sdata->u.sta.mesh_id_len)
230 memcpy(pos, sdata->u.sta.mesh_id, sdata->u.sta.mesh_id_len);
231
232 pos = skb_put(skb, 21);
233 *pos++ = WLAN_EID_MESH_CONFIG;
234 *pos++ = MESH_CFG_LEN;
235 /* Version */
236 *pos++ = 1;
237
238 /* Active path selection protocol ID */
239 memcpy(pos, sdata->u.sta.mesh_pp_id, 4);
240 pos += 4;
241
242 /* Active path selection metric ID */
243 memcpy(pos, sdata->u.sta.mesh_pm_id, 4);
244 pos += 4;
245
246 /* Congestion control mode identifier */
247 memcpy(pos, sdata->u.sta.mesh_cc_id, 4);
248 pos += 4;
249
250 /* Channel precedence:
251 * Not running simple channel unification protocol
252 */
253 memset(pos, 0x00, 4);
254 pos += 4;
255
256 /* Mesh capability */
257 sdata->u.sta.accepting_plinks = mesh_plink_availables(sdata);
258 *pos++ = sdata->u.sta.accepting_plinks ? ACCEPT_PLINKS : 0x00;
259 *pos++ = 0x00;
260
261 return;
262}
263
264u32 mesh_table_hash(u8 *addr, struct net_device *dev, struct mesh_table *tbl)
265{
266 /* Use last four bytes of hw addr and interface index as hash index */
267 return jhash_2words(*(u32 *)(addr+2), dev->ifindex, tbl->hash_rnd)
268 & tbl->hash_mask;
269}
270
271u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len)
272{
273 if (!mesh_id_len)
274 return 1;
275 else if (mesh_id_len == 1)
276 return (u8) mesh_id[0];
277 else
278 return (u8) (mesh_id[0] + 2 * mesh_id[1]);
279}
280
281struct mesh_table *mesh_table_alloc(int size_order)
282{
283 int i;
284 struct mesh_table *newtbl;
285
286 newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
287 if (!newtbl)
288 return NULL;
289
290 newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
291 (1 << size_order), GFP_KERNEL);
292
293 if (!newtbl->hash_buckets) {
294 kfree(newtbl);
295 return NULL;
296 }
297
298 newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
299 (1 << size_order), GFP_KERNEL);
300 if (!newtbl->hashwlock) {
301 kfree(newtbl->hash_buckets);
302 kfree(newtbl);
303 return NULL;
304 }
305
306 newtbl->size_order = size_order;
307 newtbl->hash_mask = (1 << size_order) - 1;
308 atomic_set(&newtbl->entries, 0);
309 get_random_bytes(&newtbl->hash_rnd,
310 sizeof(newtbl->hash_rnd));
311 for (i = 0; i <= newtbl->hash_mask; i++)
312 spin_lock_init(&newtbl->hashwlock[i]);
313
314 return newtbl;
315}
316
317void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
318{
319 struct hlist_head *mesh_hash;
320 struct hlist_node *p, *q;
321 int i;
322
323 mesh_hash = tbl->hash_buckets;
324 for (i = 0; i <= tbl->hash_mask; i++) {
325 spin_lock(&tbl->hashwlock[i]);
326 hlist_for_each_safe(p, q, &mesh_hash[i]) {
327 tbl->free_node(p, free_leafs);
328 atomic_dec(&tbl->entries);
329 }
330 spin_unlock(&tbl->hashwlock[i]);
331 }
332 kfree(tbl->hash_buckets);
333 kfree(tbl->hashwlock);
334 kfree(tbl);
335}
336
337static void ieee80211_mesh_path_timer(unsigned long data)
338{
339 struct ieee80211_sub_if_data *sdata =
340 (struct ieee80211_sub_if_data *) data;
341 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
342 struct ieee80211_local *local = wdev_priv(&sdata->wdev);
343
344 queue_work(local->hw.workqueue, &ifsta->work);
345}
346
347struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
348{
349 struct mesh_table *newtbl;
350 struct hlist_head *oldhash;
351 struct hlist_node *p;
352 int err = 0;
353 int i;
354
355 if (atomic_read(&tbl->entries)
356 < tbl->mean_chain_len * (tbl->hash_mask + 1)) {
357 err = -EPERM;
358 goto endgrow;
359 }
360
361 newtbl = mesh_table_alloc(tbl->size_order + 1);
362 if (!newtbl) {
363 err = -ENOMEM;
364 goto endgrow;
365 }
366
367 newtbl->free_node = tbl->free_node;
368 newtbl->mean_chain_len = tbl->mean_chain_len;
369 newtbl->copy_node = tbl->copy_node;
370 atomic_set(&newtbl->entries, atomic_read(&tbl->entries));
371
372 oldhash = tbl->hash_buckets;
373 for (i = 0; i <= tbl->hash_mask; i++)
374 hlist_for_each(p, &oldhash[i])
375 tbl->copy_node(p, newtbl);
376
377endgrow:
378 if (err)
379 return NULL;
380 else
381 return newtbl;
382}
383
384/**
385 * ieee80211_new_mesh_header - create a new mesh header
386 * @meshhdr: uninitialized mesh header
387 * @sdata: mesh interface to be used
388 *
389 * Return the header length.
390 */
391int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
392 struct ieee80211_sub_if_data *sdata)
393{
394 meshhdr->flags = 0;
395 meshhdr->ttl = sdata->u.sta.mshcfg.dot11MeshTTL;
396
397 meshhdr->seqnum[0] = sdata->u.sta.mesh_seqnum[0]++;
398 meshhdr->seqnum[1] = sdata->u.sta.mesh_seqnum[1];
399 meshhdr->seqnum[2] = sdata->u.sta.mesh_seqnum[2];
400
401 if (sdata->u.sta.mesh_seqnum[0] == 0) {
402 sdata->u.sta.mesh_seqnum[1]++;
403 if (sdata->u.sta.mesh_seqnum[1] == 0)
404 sdata->u.sta.mesh_seqnum[2]++;
405 }
406
407 return 5;
408}
409
410void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
411{
412 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
413
414 ifsta->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
415 ifsta->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
416 ifsta->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
417 ifsta->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
418 ifsta->mshcfg.dot11MeshTTL = MESH_TTL;
419 ifsta->mshcfg.auto_open_plinks = true;
420 ifsta->mshcfg.dot11MeshMaxPeerLinks =
421 MESH_MAX_ESTAB_PLINKS;
422 ifsta->mshcfg.dot11MeshHWMPactivePathTimeout =
423 MESH_PATH_TIMEOUT;
424 ifsta->mshcfg.dot11MeshHWMPpreqMinInterval =
425 MESH_PREQ_MIN_INT;
426 ifsta->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
427 MESH_DIAM_TRAVERSAL_TIME;
428 ifsta->mshcfg.dot11MeshHWMPmaxPREQretries =
429 MESH_MAX_PREQ_RETRIES;
430 ifsta->mshcfg.path_refresh_time =
431 MESH_PATH_REFRESH_TIME;
432 ifsta->mshcfg.min_discovery_timeout =
433 MESH_MIN_DISCOVERY_TIMEOUT;
434 ifsta->accepting_plinks = true;
435 ifsta->preq_id = 0;
436 ifsta->dsn = 0;
437 atomic_set(&ifsta->mpaths, 0);
438 mesh_rmc_init(sdata->dev);
439 ifsta->last_preq = jiffies;
440 /* Allocate all mesh structures when creating the first mesh interface. */
441 if (!mesh_allocated)
442 ieee80211s_init();
443 mesh_ids_set_default(ifsta);
444 setup_timer(&ifsta->mesh_path_timer,
445 ieee80211_mesh_path_timer,
446 (unsigned long) sdata);
447 INIT_LIST_HEAD(&ifsta->preq_queue.list);
448 spin_lock_init(&ifsta->mesh_preq_queue_lock);
449}
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
new file mode 100644
index 000000000000..742003d3a841
--- /dev/null
+++ b/net/mac80211/mesh.h
@@ -0,0 +1,290 @@
1/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Authors: Luis Carlos Cobo <luisca@cozybit.com>
4 * Javier Cardona <javier@cozybit.com>
5 *
6 * 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 * published by the Free Software Foundation.
9 */
10
11#ifndef IEEE80211S_H
12#define IEEE80211S_H
13
14#include <linux/types.h>
15#include <linux/jhash.h>
16#include "ieee80211_i.h"
17
18
19/* Data structures */
20
21/**
22 * enum mesh_path_flags - mac80211 mesh path flags
23 *
24 *
25 *
26 * @MESH_PATH_ACTIVE: the mesh path is can be used for forwarding
27 * @MESH_PATH_RESOLVED: the discovery process is running for this mesh path
28 * @MESH_PATH_DSN_VALID: the mesh path contains a valid destination sequence
29 * number
30 * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
31 * modified
32 * @MESH_PATH_RESOLVED: the mesh path can has been resolved
33 *
34 * MESH_PATH_RESOLVED and MESH_PATH_DELETE are used by the mesh path timer to
35 * decide when to stop or cancel the mesh path discovery.
36 */
37enum mesh_path_flags {
38 MESH_PATH_ACTIVE = BIT(0),
39 MESH_PATH_RESOLVING = BIT(1),
40 MESH_PATH_DSN_VALID = BIT(2),
41 MESH_PATH_FIXED = BIT(3),
42 MESH_PATH_RESOLVED = BIT(4),
43};
44
45/**
46 * struct mesh_path - mac80211 mesh path structure
47 *
48 * @dst: mesh path destination mac address
49 * @dev: mesh path device
50 * @next_hop: mesh neighbor to which frames for this destination will be
51 * forwarded
52 * @timer: mesh path discovery timer
53 * @frame_queue: pending queue for frames sent to this destination while the
54 * path is unresolved
55 * @dsn: destination sequence number of the destination
56 * @metric: current metric to this destination
57 * @hop_count: hops to destination
58 * @exp_time: in jiffies, when the path will expire or when it expired
59 * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
60 * retry
61 * @discovery_retries: number of discovery retries
62 * @flags: mesh path flags, as specified on &enum mesh_path_flags
63 * @state_lock: mesh pat state lock
64 *
65 *
66 * The combination of dst and dev is unique in the mesh path table. Since the
67 * next_hop STA is only protected by RCU as well, deleting the STA must also
68 * remove/substitute the mesh_path structure and wait until that is no longer
69 * reachable before destroying the STA completely.
70 */
71struct mesh_path {
72 u8 dst[ETH_ALEN];
73 struct net_device *dev;
74 struct sta_info *next_hop;
75 struct timer_list timer;
76 struct sk_buff_head frame_queue;
77 struct rcu_head rcu;
78 u32 dsn;
79 u32 metric;
80 u8 hop_count;
81 unsigned long exp_time;
82 u32 discovery_timeout;
83 u8 discovery_retries;
84 enum mesh_path_flags flags;
85 spinlock_t state_lock;
86};
87
88/**
89 * struct mesh_table
90 *
91 * @hash_buckets: array of hash buckets of the table
92 * @hashwlock: array of locks to protect write operations, one per bucket
93 * @hash_mask: 2^size_order - 1, used to compute hash idx
94 * @hash_rnd: random value used for hash computations
95 * @entries: number of entries in the table
96 * @free_node: function to free nodes of the table
97 * @copy_node: fuction to copy nodes of the table
98 * @size_order: determines size of the table, there will be 2^size_order hash
99 * buckets
100 * @mean_chain_len: maximum average length for the hash buckets' list, if it is
101 * reached, the table will grow
102 */
103struct mesh_table {
104 /* Number of buckets will be 2^N */
105 struct hlist_head *hash_buckets;
106 spinlock_t *hashwlock; /* One per bucket, for add/del */
107 unsigned int hash_mask; /* (2^size_order) - 1 */
108 __u32 hash_rnd; /* Used for hash generation */
109 atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
110 void (*free_node) (struct hlist_node *p, bool free_leafs);
111 void (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl);
112 int size_order;
113 int mean_chain_len;
114};
115
116/* Recent multicast cache */
117/* RMC_BUCKETS must be a power of 2, maximum 256 */
118#define RMC_BUCKETS 256
119#define RMC_QUEUE_MAX_LEN 4
120#define RMC_TIMEOUT (3 * HZ)
121
122/**
123 * struct rmc_entry - entry in the Recent Multicast Cache
124 *
125 * @seqnum: mesh sequence number of the frame
126 * @exp_time: expiration time of the entry, in jiffies
127 * @sa: source address of the frame
128 *
129 * The Recent Multicast Cache keeps track of the latest multicast frames that
130 * have been received by a mesh interface and discards received multicast frames
131 * that are found in the cache.
132 */
133struct rmc_entry {
134 struct list_head list;
135 u32 seqnum;
136 unsigned long exp_time;
137 u8 sa[ETH_ALEN];
138};
139
140struct mesh_rmc {
141 struct rmc_entry bucket[RMC_BUCKETS];
142 u8 idx_mask;
143};
144
145
146/* Mesh IEs constants */
147#define MESH_CFG_LEN 19
148
149/*
150 * MESH_CFG_COMP_LEN Includes:
151 * - Active path selection protocol ID.
152 * - Active path selection metric ID.
153 * - Congestion control mode identifier.
154 * - Channel precedence.
155 * Does not include mesh capabilities, which may vary across nodes in the same
156 * mesh
157 */
158#define MESH_CFG_CMP_LEN 17
159
160/* Default values, timeouts in ms */
161#define MESH_TTL 5
162#define MESH_MAX_RETR 3
163#define MESH_RET_T 100
164#define MESH_CONF_T 100
165#define MESH_HOLD_T 100
166
167#define MESH_PATH_TIMEOUT 5000
168/* Minimum interval between two consecutive PREQs originated by the same
169 * interface
170 */
171#define MESH_PREQ_MIN_INT 10
172#define MESH_DIAM_TRAVERSAL_TIME 50
173/* Paths will be refreshed if they are closer than PATH_REFRESH_TIME to their
174 * expiration
175 */
176#define MESH_PATH_REFRESH_TIME 1000
177#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
178
179#define MESH_MAX_PREQ_RETRIES 4
180#define MESH_PATH_EXPIRE (600 * HZ)
181
182/* Default maximum number of established plinks per interface */
183#define MESH_MAX_ESTAB_PLINKS 32
184
185/* Default maximum number of plinks per interface */
186#define MESH_MAX_PLINKS 256
187
188/* Maximum number of paths per interface */
189#define MESH_MAX_MPATHS 1024
190
191/* Pending ANA approval */
192#define PLINK_CATEGORY 30
193#define MESH_PATH_SEL_CATEGORY 32
194
195/* Mesh Header Flags */
196#define IEEE80211S_FLAGS_AE 0x3
197
198/* Public interfaces */
199/* Various */
200u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len);
201int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
202int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
203 struct ieee80211_sub_if_data *sdata);
204int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr,
205 struct net_device *dev);
206bool mesh_matches_local(struct ieee802_11_elems *ie, struct net_device *dev);
207void mesh_ids_set_default(struct ieee80211_if_sta *sta);
208void mesh_mgmt_ies_add(struct sk_buff *skb, struct net_device *dev);
209void mesh_rmc_free(struct net_device *dev);
210int mesh_rmc_init(struct net_device *dev);
211void ieee80211s_init(void);
212void ieee80211s_stop(void);
213void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
214
215/* Mesh paths */
216int mesh_nexthop_lookup(u8 *next_hop, struct sk_buff *skb,
217 struct net_device *dev);
218void mesh_path_start_discovery(struct net_device *dev);
219struct mesh_path *mesh_path_lookup(u8 *dst, struct net_device *dev);
220struct mesh_path *mesh_path_lookup_by_idx(int idx, struct net_device *dev);
221void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
222void mesh_path_expire(struct net_device *dev);
223void mesh_path_flush(struct net_device *dev);
224void mesh_rx_path_sel_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
225 size_t len);
226int mesh_path_add(u8 *dst, struct net_device *dev);
227/* Mesh plinks */
228void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
229 bool add);
230bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie,
231 struct net_device *dev);
232void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
233void mesh_plink_broken(struct sta_info *sta);
234void mesh_plink_deactivate(struct sta_info *sta);
235int mesh_plink_open(struct sta_info *sta);
236int mesh_plink_close(struct sta_info *sta);
237void mesh_plink_block(struct sta_info *sta);
238void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
239 size_t len, struct ieee80211_rx_status *rx_status);
240
241/* Private interfaces */
242/* Mesh tables */
243struct mesh_table *mesh_table_alloc(int size_order);
244void mesh_table_free(struct mesh_table *tbl, bool free_leafs);
245struct mesh_table *mesh_table_grow(struct mesh_table *tbl);
246u32 mesh_table_hash(u8 *addr, struct net_device *dev, struct mesh_table *tbl);
247/* Mesh paths */
248int mesh_path_error_tx(u8 *dest, __le32 dest_dsn, u8 *ra,
249 struct net_device *dev);
250void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
251void mesh_path_flush_pending(struct mesh_path *mpath);
252void mesh_path_tx_pending(struct mesh_path *mpath);
253int mesh_pathtbl_init(void);
254void mesh_pathtbl_unregister(void);
255int mesh_path_del(u8 *addr, struct net_device *dev);
256void mesh_path_timer(unsigned long data);
257void mesh_path_flush_by_nexthop(struct sta_info *sta);
258void mesh_path_discard_frame(struct sk_buff *skb, struct net_device *dev);
259
260#ifdef CONFIG_MAC80211_MESH
261extern int mesh_allocated;
262
263static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
264{
265 return sdata->u.sta.mshcfg.dot11MeshMaxPeerLinks -
266 atomic_read(&sdata->u.sta.mshstats.estab_plinks);
267}
268
269static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
270{
271 return (min_t(long, mesh_plink_free_count(sdata),
272 MESH_MAX_PLINKS - sdata->local->num_sta)) > 0;
273}
274
275static inline void mesh_path_activate(struct mesh_path *mpath)
276{
277 mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED;
278}
279
280#define for_each_mesh_entry(x, p, node, i) \
281 for (i = 0; i <= x->hash_mask; i++) \
282 hlist_for_each_entry_rcu(node, p, &x->hash_buckets[i], list)
283
284#else
285#define mesh_allocated 0
286#endif
287
288#define MESH_PREQ(skb) (skb->cb + 30)
289
290#endif /* IEEE80211S_H */
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
new file mode 100644
index 000000000000..576a6e55323e
--- /dev/null
+++ b/net/mac80211/mesh_hwmp.c
@@ -0,0 +1,857 @@
1/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <asm/unaligned.h>
11#include "mesh.h"
12
13#define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
14
15#define TEST_FRAME_LEN 8192
16#define MAX_METRIC 0xffffffff
17#define ARITH_SHIFT 8
18
19/* Number of frames buffered per destination for unresolved destinations */
20#define MESH_FRAME_QUEUE_LEN 10
21#define MAX_PREQ_QUEUE_LEN 64
22
23/* Destination only */
24#define MP_F_DO 0x1
25/* Reply and forward */
26#define MP_F_RF 0x2
27
28static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
29{
30 if (ae)
31 offset += 6;
32 return le32_to_cpu(get_unaligned((__le32 *) (preq_elem + offset)));
33}
34
35/* HWMP IE processing macros */
36#define AE_F (1<<6)
37#define AE_F_SET(x) (*x & AE_F)
38#define PREQ_IE_FLAGS(x) (*(x))
39#define PREQ_IE_HOPCOUNT(x) (*(x + 1))
40#define PREQ_IE_TTL(x) (*(x + 2))
41#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
42#define PREQ_IE_ORIG_ADDR(x) (x + 7)
43#define PREQ_IE_ORIG_DSN(x) u32_field_get(x, 13, 0);
44#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x));
45#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x));
46#define PREQ_IE_DST_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
47#define PREQ_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
48#define PREQ_IE_DST_DSN(x) u32_field_get(x, 33, AE_F_SET(x));
49
50
51#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
52#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
53#define PREP_IE_TTL(x) PREQ_IE_TTL(x)
54#define PREP_IE_ORIG_ADDR(x) (x + 3)
55#define PREP_IE_ORIG_DSN(x) u32_field_get(x, 9, 0);
56#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x));
57#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x));
58#define PREP_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
59#define PREP_IE_DST_DSN(x) u32_field_get(x, 27, AE_F_SET(x));
60
61#define PERR_IE_DST_ADDR(x) (x + 2)
62#define PERR_IE_DST_DSN(x) u32_field_get(x, 8, 0);
63
64#define TU_TO_EXP_TIME(x) (jiffies + msecs_to_jiffies(x * 1024 / 1000))
65#define MSEC_TO_TU(x) (x*1000/1024)
66#define DSN_GT(x, y) ((long) (y) - (long) (x) < 0)
67#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0)
68
69#define net_traversal_jiffies(s) \
70 msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
71#define default_lifetime(s) \
72 MSEC_TO_TU(s->u.sta.mshcfg.dot11MeshHWMPactivePathTimeout)
73#define min_preq_int_jiff(s) \
74 (msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPpreqMinInterval))
75#define max_preq_retries(s) (s->u.sta.mshcfg.dot11MeshHWMPmaxPREQretries)
76#define disc_timeout_jiff(s) \
77 msecs_to_jiffies(sdata->u.sta.mshcfg.min_discovery_timeout)
78
79enum mpath_frame_type {
80 MPATH_PREQ = 0,
81 MPATH_PREP,
82 MPATH_PERR
83};
84
85static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
86 u8 *orig_addr, __le32 orig_dsn, u8 dst_flags, u8 *dst,
87 __le32 dst_dsn, u8 *da, u8 hop_count, u8 ttl, __le32 lifetime,
88 __le32 metric, __le32 preq_id, struct net_device *dev)
89{
90 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
91 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
92 struct ieee80211_mgmt *mgmt;
93 u8 *pos;
94 int ie_len;
95
96 if (!skb)
97 return -1;
98 skb_reserve(skb, local->hw.extra_tx_headroom);
99 /* 25 is the size of the common mgmt part (24) plus the size of the
100 * common action part (1)
101 */
102 mgmt = (struct ieee80211_mgmt *)
103 skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
104 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
105 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
106 IEEE80211_STYPE_ACTION);
107
108 memcpy(mgmt->da, da, ETH_ALEN);
109 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
110 /* BSSID is left zeroed, wildcard value */
111 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
112 mgmt->u.action.u.mesh_action.action_code = action;
113
114 switch (action) {
115 case MPATH_PREQ:
116 ie_len = 37;
117 pos = skb_put(skb, 2 + ie_len);
118 *pos++ = WLAN_EID_PREQ;
119 break;
120 case MPATH_PREP:
121 ie_len = 31;
122 pos = skb_put(skb, 2 + ie_len);
123 *pos++ = WLAN_EID_PREP;
124 break;
125 default:
126 kfree(skb);
127 return -ENOTSUPP;
128 break;
129 }
130 *pos++ = ie_len;
131 *pos++ = flags;
132 *pos++ = hop_count;
133 *pos++ = ttl;
134 if (action == MPATH_PREQ) {
135 memcpy(pos, &preq_id, 4);
136 pos += 4;
137 }
138 memcpy(pos, orig_addr, ETH_ALEN);
139 pos += ETH_ALEN;
140 memcpy(pos, &orig_dsn, 4);
141 pos += 4;
142 memcpy(pos, &lifetime, 4);
143 pos += 4;
144 memcpy(pos, &metric, 4);
145 pos += 4;
146 if (action == MPATH_PREQ) {
147 /* destination count */
148 *pos++ = 1;
149 *pos++ = dst_flags;
150 }
151 memcpy(pos, dst, ETH_ALEN);
152 pos += ETH_ALEN;
153 memcpy(pos, &dst_dsn, 4);
154
155 ieee80211_sta_tx(dev, skb, 0);
156 return 0;
157}
158
159/**
160 * mesh_send_path error - Sends a PERR mesh management frame
161 *
162 * @dst: broken destination
163 * @dst_dsn: dsn of the broken destination
164 * @ra: node this frame is addressed to
165 */
166int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra,
167 struct net_device *dev)
168{
169 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
170 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
171 struct ieee80211_mgmt *mgmt;
172 u8 *pos;
173 int ie_len;
174
175 if (!skb)
176 return -1;
177 skb_reserve(skb, local->hw.extra_tx_headroom);
178 /* 25 is the size of the common mgmt part (24) plus the size of the
179 * common action part (1)
180 */
181 mgmt = (struct ieee80211_mgmt *)
182 skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
183 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
184 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
185 IEEE80211_STYPE_ACTION);
186
187 memcpy(mgmt->da, ra, ETH_ALEN);
188 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
189 /* BSSID is left zeroed, wildcard value */
190 mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
191 mgmt->u.action.u.mesh_action.action_code = MPATH_PERR;
192 ie_len = 12;
193 pos = skb_put(skb, 2 + ie_len);
194 *pos++ = WLAN_EID_PERR;
195 *pos++ = ie_len;
196 /* mode flags, reserved */
197 *pos++ = 0;
198 /* number of destinations */
199 *pos++ = 1;
200 memcpy(pos, dst, ETH_ALEN);
201 pos += ETH_ALEN;
202 memcpy(pos, &dst_dsn, 4);
203
204 ieee80211_sta_tx(dev, skb, 0);
205 return 0;
206}
207
208static u32 airtime_link_metric_get(struct ieee80211_local *local,
209 struct sta_info *sta)
210{
211 struct ieee80211_supported_band *sband;
212 /* This should be adjusted for each device */
213 int device_constant = 1 << ARITH_SHIFT;
214 int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
215 int s_unit = 1 << ARITH_SHIFT;
216 int rate, err;
217 u32 tx_time, estimated_retx;
218 u64 result;
219
220 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
221
222 if (sta->fail_avg >= 100)
223 return MAX_METRIC;
224 err = (sta->fail_avg << ARITH_SHIFT) / 100;
225
226 /* bitrate is in units of 100 Kbps, while we need rate in units of
227 * 1Mbps. This will be corrected on tx_time computation.
228 */
229 rate = sband->bitrates[sta->txrate_idx].bitrate;
230 tx_time = (device_constant + 10 * test_frame_len / rate);
231 estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
232 result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
233 return (u32)result;
234}
235
236/**
237 * hwmp_route_info_get - Update routing info to originator and transmitter
238 *
239 * @dev: local mesh interface
240 * @mgmt: mesh management frame
241 * @hwmp_ie: hwmp information element (PREP or PREQ)
242 *
243 * This function updates the path routing information to the originator and the
244 * transmitter of a HWMP PREQ or PREP fram.
245 *
246 * Returns: metric to frame originator or 0 if the frame should not be further
247 * processed
248 *
249 * Notes: this function is the only place (besides user-provided info) where
250 * path routing information is updated.
251 */
252static u32 hwmp_route_info_get(struct net_device *dev,
253 struct ieee80211_mgmt *mgmt,
254 u8 *hwmp_ie)
255{
256 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
257 struct mesh_path *mpath;
258 struct sta_info *sta;
259 bool fresh_info;
260 u8 *orig_addr, *ta;
261 u32 orig_dsn, orig_metric;
262 unsigned long orig_lifetime, exp_time;
263 u32 last_hop_metric, new_metric;
264 bool process = true;
265 u8 action = mgmt->u.action.u.mesh_action.action_code;
266
267 rcu_read_lock();
268 sta = sta_info_get(local, mgmt->sa);
269 if (!sta) {
270 rcu_read_unlock();
271 return 0;
272 }
273
274 last_hop_metric = airtime_link_metric_get(local, sta);
275 /* Update and check originator routing info */
276 fresh_info = true;
277
278 switch (action) {
279 case MPATH_PREQ:
280 orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
281 orig_dsn = PREQ_IE_ORIG_DSN(hwmp_ie);
282 orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
283 orig_metric = PREQ_IE_METRIC(hwmp_ie);
284 break;
285 case MPATH_PREP:
286 /* Originator here refers to the MP that was the destination in
287 * the Path Request. The draft refers to that MP as the
288 * destination address, even though usually it is the origin of
289 * the PREP frame. We divert from the nomenclature in the draft
290 * so that we can easily use a single function to gather path
291 * information from both PREQ and PREP frames.
292 */
293 orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie);
294 orig_dsn = PREP_IE_ORIG_DSN(hwmp_ie);
295 orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
296 orig_metric = PREP_IE_METRIC(hwmp_ie);
297 break;
298 default:
299 rcu_read_unlock();
300 return 0;
301 }
302 new_metric = orig_metric + last_hop_metric;
303 if (new_metric < orig_metric)
304 new_metric = MAX_METRIC;
305 exp_time = TU_TO_EXP_TIME(orig_lifetime);
306
307 if (memcmp(orig_addr, dev->dev_addr, ETH_ALEN) == 0) {
308 /* This MP is the originator, we are not interested in this
309 * frame, except for updating transmitter's path info.
310 */
311 process = false;
312 fresh_info = false;
313 } else {
314 mpath = mesh_path_lookup(orig_addr, dev);
315 if (mpath) {
316 spin_lock_bh(&mpath->state_lock);
317 if (mpath->flags & MESH_PATH_FIXED)
318 fresh_info = false;
319 else if ((mpath->flags & MESH_PATH_ACTIVE) &&
320 (mpath->flags & MESH_PATH_DSN_VALID)) {
321 if (DSN_GT(mpath->dsn, orig_dsn) ||
322 (mpath->dsn == orig_dsn &&
323 action == MPATH_PREQ &&
324 new_metric > mpath->metric)) {
325 process = false;
326 fresh_info = false;
327 }
328 }
329 } else {
330 mesh_path_add(orig_addr, dev);
331 mpath = mesh_path_lookup(orig_addr, dev);
332 if (!mpath) {
333 rcu_read_unlock();
334 return 0;
335 }
336 spin_lock_bh(&mpath->state_lock);
337 }
338
339 if (fresh_info) {
340 mesh_path_assign_nexthop(mpath, sta);
341 mpath->flags |= MESH_PATH_DSN_VALID;
342 mpath->metric = new_metric;
343 mpath->dsn = orig_dsn;
344 mpath->exp_time = time_after(mpath->exp_time, exp_time)
345 ? mpath->exp_time : exp_time;
346 mesh_path_activate(mpath);
347 spin_unlock_bh(&mpath->state_lock);
348 mesh_path_tx_pending(mpath);
349 /* draft says preq_id should be saved to, but there does
350 * not seem to be any use for it, skipping by now
351 */
352 } else
353 spin_unlock_bh(&mpath->state_lock);
354 }
355
356 /* Update and check transmitter routing info */
357 ta = mgmt->sa;
358 if (memcmp(orig_addr, ta, ETH_ALEN) == 0)
359 fresh_info = false;
360 else {
361 fresh_info = true;
362
363 mpath = mesh_path_lookup(ta, dev);
364 if (mpath) {
365 spin_lock_bh(&mpath->state_lock);
366 if ((mpath->flags & MESH_PATH_FIXED) ||
367 ((mpath->flags & MESH_PATH_ACTIVE) &&
368 (last_hop_metric > mpath->metric)))
369 fresh_info = false;
370 } else {
371 mesh_path_add(ta, dev);
372 mpath = mesh_path_lookup(ta, dev);
373 if (!mpath) {
374 rcu_read_unlock();
375 return 0;
376 }
377 spin_lock_bh(&mpath->state_lock);
378 }
379
380 if (fresh_info) {
381 mesh_path_assign_nexthop(mpath, sta);
382 mpath->flags &= ~MESH_PATH_DSN_VALID;
383 mpath->metric = last_hop_metric;
384 mpath->exp_time = time_after(mpath->exp_time, exp_time)
385 ? mpath->exp_time : exp_time;
386 mesh_path_activate(mpath);
387 spin_unlock_bh(&mpath->state_lock);
388 mesh_path_tx_pending(mpath);
389 } else
390 spin_unlock_bh(&mpath->state_lock);
391 }
392
393 rcu_read_unlock();
394
395 return process ? new_metric : 0;
396}
397
398static void hwmp_preq_frame_process(struct net_device *dev,
399 struct ieee80211_mgmt *mgmt,
400 u8 *preq_elem, u32 metric) {
401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
402 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
403 struct mesh_path *mpath;
404 u8 *dst_addr, *orig_addr;
405 u8 dst_flags, ttl;
406 u32 orig_dsn, dst_dsn, lifetime;
407 bool reply = false;
408 bool forward = true;
409
410 /* Update destination DSN, if present */
411 dst_addr = PREQ_IE_DST_ADDR(preq_elem);
412 orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
413 dst_dsn = PREQ_IE_DST_DSN(preq_elem);
414 orig_dsn = PREQ_IE_ORIG_DSN(preq_elem);
415 dst_flags = PREQ_IE_DST_F(preq_elem);
416
417 if (memcmp(dst_addr, dev->dev_addr, ETH_ALEN) == 0) {
418 forward = false;
419 reply = true;
420 metric = 0;
421 if (time_after(jiffies, ifsta->last_dsn_update +
422 net_traversal_jiffies(sdata)) ||
423 time_before(jiffies, ifsta->last_dsn_update)) {
424 dst_dsn = ++ifsta->dsn;
425 ifsta->last_dsn_update = jiffies;
426 }
427 } else {
428 rcu_read_lock();
429 mpath = mesh_path_lookup(dst_addr, dev);
430 if (mpath) {
431 if ((!(mpath->flags & MESH_PATH_DSN_VALID)) ||
432 DSN_LT(mpath->dsn, dst_dsn)) {
433 mpath->dsn = dst_dsn;
434 mpath->flags &= MESH_PATH_DSN_VALID;
435 } else if ((!(dst_flags & MP_F_DO)) &&
436 (mpath->flags & MESH_PATH_ACTIVE)) {
437 reply = true;
438 metric = mpath->metric;
439 dst_dsn = mpath->dsn;
440 if (dst_flags & MP_F_RF)
441 dst_flags |= MP_F_DO;
442 else
443 forward = false;
444 }
445 }
446 rcu_read_unlock();
447 }
448
449 if (reply) {
450 lifetime = PREQ_IE_LIFETIME(preq_elem);
451 ttl = ifsta->mshcfg.dot11MeshTTL;
452 if (ttl != 0)
453 mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr,
454 cpu_to_le32(dst_dsn), 0, orig_addr,
455 cpu_to_le32(orig_dsn), mgmt->sa, 0, ttl,
456 cpu_to_le32(lifetime), cpu_to_le32(metric),
457 0, dev);
458 else
459 ifsta->mshstats.dropped_frames_ttl++;
460 }
461
462 if (forward) {
463 u32 preq_id;
464 u8 hopcount, flags;
465
466 ttl = PREQ_IE_TTL(preq_elem);
467 lifetime = PREQ_IE_LIFETIME(preq_elem);
468 if (ttl <= 1) {
469 ifsta->mshstats.dropped_frames_ttl++;
470 return;
471 }
472 --ttl;
473 flags = PREQ_IE_FLAGS(preq_elem);
474 preq_id = PREQ_IE_PREQ_ID(preq_elem);
475 hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
476 mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
477 cpu_to_le32(orig_dsn), dst_flags, dst_addr,
478 cpu_to_le32(dst_dsn), dev->broadcast,
479 hopcount, ttl, cpu_to_le32(lifetime),
480 cpu_to_le32(metric), cpu_to_le32(preq_id),
481 dev);
482 ifsta->mshstats.fwded_frames++;
483 }
484}
485
486
487static void hwmp_prep_frame_process(struct net_device *dev,
488 struct ieee80211_mgmt *mgmt,
489 u8 *prep_elem, u32 metric)
490{
491 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
492 struct mesh_path *mpath;
493 u8 *dst_addr, *orig_addr;
494 u8 ttl, hopcount, flags;
495 u8 next_hop[ETH_ALEN];
496 u32 dst_dsn, orig_dsn, lifetime;
497
498 /* Note that we divert from the draft nomenclature and denominate
499 * destination to what the draft refers to as origininator. So in this
500 * function destnation refers to the final destination of the PREP,
501 * which corresponds with the originator of the PREQ which this PREP
502 * replies
503 */
504 dst_addr = PREP_IE_DST_ADDR(prep_elem);
505 if (memcmp(dst_addr, dev->dev_addr, ETH_ALEN) == 0)
506 /* destination, no forwarding required */
507 return;
508
509 ttl = PREP_IE_TTL(prep_elem);
510 if (ttl <= 1) {
511 sdata->u.sta.mshstats.dropped_frames_ttl++;
512 return;
513 }
514
515 rcu_read_lock();
516 mpath = mesh_path_lookup(dst_addr, dev);
517 if (mpath)
518 spin_lock_bh(&mpath->state_lock);
519 else
520 goto fail;
521 if (!(mpath->flags & MESH_PATH_ACTIVE)) {
522 spin_unlock_bh(&mpath->state_lock);
523 goto fail;
524 }
525 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
526 spin_unlock_bh(&mpath->state_lock);
527 --ttl;
528 flags = PREP_IE_FLAGS(prep_elem);
529 lifetime = PREP_IE_LIFETIME(prep_elem);
530 hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
531 orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
532 dst_dsn = PREP_IE_DST_DSN(prep_elem);
533 orig_dsn = PREP_IE_ORIG_DSN(prep_elem);
534
535 mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
536 cpu_to_le32(orig_dsn), 0, dst_addr,
537 cpu_to_le32(dst_dsn), mpath->next_hop->addr, hopcount, ttl,
538 cpu_to_le32(lifetime), cpu_to_le32(metric),
539 0, dev);
540 rcu_read_unlock();
541 sdata->u.sta.mshstats.fwded_frames++;
542 return;
543
544fail:
545 rcu_read_unlock();
546 sdata->u.sta.mshstats.dropped_frames_no_route++;
547 return;
548}
549
550static void hwmp_perr_frame_process(struct net_device *dev,
551 struct ieee80211_mgmt *mgmt, u8 *perr_elem)
552{
553 struct mesh_path *mpath;
554 u8 *ta, *dst_addr;
555 u32 dst_dsn;
556
557 ta = mgmt->sa;
558 dst_addr = PERR_IE_DST_ADDR(perr_elem);
559 dst_dsn = PERR_IE_DST_DSN(perr_elem);
560 rcu_read_lock();
561 mpath = mesh_path_lookup(dst_addr, dev);
562 if (mpath) {
563 spin_lock_bh(&mpath->state_lock);
564 if (mpath->flags & MESH_PATH_ACTIVE &&
565 memcmp(ta, mpath->next_hop->addr, ETH_ALEN) == 0 &&
566 (!(mpath->flags & MESH_PATH_DSN_VALID) ||
567 DSN_GT(dst_dsn, mpath->dsn))) {
568 mpath->flags &= ~MESH_PATH_ACTIVE;
569 mpath->dsn = dst_dsn;
570 spin_unlock_bh(&mpath->state_lock);
571 mesh_path_error_tx(dst_addr, cpu_to_le32(dst_dsn),
572 dev->broadcast, dev);
573 } else
574 spin_unlock_bh(&mpath->state_lock);
575 }
576 rcu_read_unlock();
577}
578
579
580
581void mesh_rx_path_sel_frame(struct net_device *dev,
582 struct ieee80211_mgmt *mgmt,
583 size_t len)
584{
585 struct ieee802_11_elems elems;
586 size_t baselen;
587 u32 last_hop_metric;
588
589 baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
590 ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
591 len - baselen, &elems);
592
593 switch (mgmt->u.action.u.mesh_action.action_code) {
594 case MPATH_PREQ:
595 if (!elems.preq || elems.preq_len != 37)
596 /* Right now we support just 1 destination and no AE */
597 return;
598 last_hop_metric = hwmp_route_info_get(dev, mgmt, elems.preq);
599 if (!last_hop_metric)
600 return;
601 hwmp_preq_frame_process(dev, mgmt, elems.preq, last_hop_metric);
602 break;
603 case MPATH_PREP:
604 if (!elems.prep || elems.prep_len != 31)
605 /* Right now we support no AE */
606 return;
607 last_hop_metric = hwmp_route_info_get(dev, mgmt, elems.prep);
608 if (!last_hop_metric)
609 return;
610 hwmp_prep_frame_process(dev, mgmt, elems.prep, last_hop_metric);
611 break;
612 case MPATH_PERR:
613 if (!elems.perr || elems.perr_len != 12)
614 /* Right now we support only one destination per PERR */
615 return;
616 hwmp_perr_frame_process(dev, mgmt, elems.perr);
617 default:
618 return;
619 }
620
621}
622
623/**
624 * mesh_queue_preq - queue a PREQ to a given destination
625 *
626 * @mpath: mesh path to discover
627 * @flags: special attributes of the PREQ to be sent
628 *
629 * Locking: the function must be called from within a rcu read lock block.
630 *
631 */
632static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
633{
634 struct ieee80211_sub_if_data *sdata =
635 IEEE80211_DEV_TO_SUB_IF(mpath->dev);
636 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
637 struct mesh_preq_queue *preq_node;
638
639 preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL);
640 if (!preq_node) {
641 printk(KERN_DEBUG "Mesh HWMP: could not allocate PREQ node\n");
642 return;
643 }
644
645 spin_lock(&ifsta->mesh_preq_queue_lock);
646 if (ifsta->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
647 spin_unlock(&ifsta->mesh_preq_queue_lock);
648 kfree(preq_node);
649 if (printk_ratelimit())
650 printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n");
651 return;
652 }
653
654 memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
655 preq_node->flags = flags;
656
657 list_add_tail(&preq_node->list, &ifsta->preq_queue.list);
658 ++ifsta->preq_queue_len;
659 spin_unlock(&ifsta->mesh_preq_queue_lock);
660
661 if (time_after(jiffies, ifsta->last_preq + min_preq_int_jiff(sdata)))
662 queue_work(sdata->local->hw.workqueue, &ifsta->work);
663
664 else if (time_before(jiffies, ifsta->last_preq)) {
665 /* avoid long wait if did not send preqs for a long time
666 * and jiffies wrapped around
667 */
668 ifsta->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
669 queue_work(sdata->local->hw.workqueue, &ifsta->work);
670 } else
671 mod_timer(&ifsta->mesh_path_timer, ifsta->last_preq +
672 min_preq_int_jiff(sdata));
673}
674
675/**
676 * mesh_path_start_discovery - launch a path discovery from the PREQ queue
677 *
678 * @dev: local mesh interface
679 */
680void mesh_path_start_discovery(struct net_device *dev)
681{
682 struct ieee80211_sub_if_data *sdata =
683 IEEE80211_DEV_TO_SUB_IF(dev);
684 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
685 struct mesh_preq_queue *preq_node;
686 struct mesh_path *mpath;
687 u8 ttl, dst_flags;
688 u32 lifetime;
689
690 spin_lock(&ifsta->mesh_preq_queue_lock);
691 if (!ifsta->preq_queue_len ||
692 time_before(jiffies, ifsta->last_preq +
693 min_preq_int_jiff(sdata))) {
694 spin_unlock(&ifsta->mesh_preq_queue_lock);
695 return;
696 }
697
698 preq_node = list_first_entry(&ifsta->preq_queue.list,
699 struct mesh_preq_queue, list);
700 list_del(&preq_node->list);
701 --ifsta->preq_queue_len;
702 spin_unlock(&ifsta->mesh_preq_queue_lock);
703
704 rcu_read_lock();
705 mpath = mesh_path_lookup(preq_node->dst, dev);
706 if (!mpath)
707 goto enddiscovery;
708
709 spin_lock_bh(&mpath->state_lock);
710 if (preq_node->flags & PREQ_Q_F_START) {
711 if (mpath->flags & MESH_PATH_RESOLVING) {
712 spin_unlock_bh(&mpath->state_lock);
713 goto enddiscovery;
714 } else {
715 mpath->flags &= ~MESH_PATH_RESOLVED;
716 mpath->flags |= MESH_PATH_RESOLVING;
717 mpath->discovery_retries = 0;
718 mpath->discovery_timeout = disc_timeout_jiff(sdata);
719 }
720 } else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
721 mpath->flags & MESH_PATH_RESOLVED) {
722 mpath->flags &= ~MESH_PATH_RESOLVING;
723 spin_unlock_bh(&mpath->state_lock);
724 goto enddiscovery;
725 }
726
727 ifsta->last_preq = jiffies;
728
729 if (time_after(jiffies, ifsta->last_dsn_update +
730 net_traversal_jiffies(sdata)) ||
731 time_before(jiffies, ifsta->last_dsn_update)) {
732 ++ifsta->dsn;
733 sdata->u.sta.last_dsn_update = jiffies;
734 }
735 lifetime = default_lifetime(sdata);
736 ttl = sdata->u.sta.mshcfg.dot11MeshTTL;
737 if (ttl == 0) {
738 sdata->u.sta.mshstats.dropped_frames_ttl++;
739 spin_unlock_bh(&mpath->state_lock);
740 goto enddiscovery;
741 }
742
743 if (preq_node->flags & PREQ_Q_F_REFRESH)
744 dst_flags = MP_F_DO;
745 else
746 dst_flags = MP_F_RF;
747
748 spin_unlock_bh(&mpath->state_lock);
749 mesh_path_sel_frame_tx(MPATH_PREQ, 0, dev->dev_addr,
750 cpu_to_le32(ifsta->dsn), dst_flags, mpath->dst,
751 cpu_to_le32(mpath->dsn), dev->broadcast, 0,
752 ttl, cpu_to_le32(lifetime), 0,
753 cpu_to_le32(ifsta->preq_id++), dev);
754 mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
755
756enddiscovery:
757 rcu_read_unlock();
758 kfree(preq_node);
759}
760
761/**
762 * ieee80211s_lookup_nexthop - put the appropriate next hop on a mesh frame
763 *
764 * @next_hop: output argument for next hop address
765 * @skb: frame to be sent
766 * @dev: network device the frame will be sent through
767 *
768 * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
769 * found, the function will start a path discovery and queue the frame so it is
770 * sent when the path is resolved. This means the caller must not free the skb
771 * in this case.
772 */
773int mesh_nexthop_lookup(u8 *next_hop, struct sk_buff *skb,
774 struct net_device *dev)
775{
776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
777 struct sk_buff *skb_to_free = NULL;
778 struct mesh_path *mpath;
779 int err = 0;
780
781 rcu_read_lock();
782 mpath = mesh_path_lookup(skb->data, dev);
783
784 if (!mpath) {
785 mesh_path_add(skb->data, dev);
786 mpath = mesh_path_lookup(skb->data, dev);
787 if (!mpath) {
788 dev_kfree_skb(skb);
789 sdata->u.sta.mshstats.dropped_frames_no_route++;
790 err = -ENOSPC;
791 goto endlookup;
792 }
793 }
794
795 if (mpath->flags & MESH_PATH_ACTIVE) {
796 if (time_after(jiffies, mpath->exp_time -
797 msecs_to_jiffies(sdata->u.sta.mshcfg.path_refresh_time))
798 && skb->pkt_type != PACKET_OTHERHOST
799 && !(mpath->flags & MESH_PATH_RESOLVING)
800 && !(mpath->flags & MESH_PATH_FIXED)) {
801 mesh_queue_preq(mpath,
802 PREQ_Q_F_START | PREQ_Q_F_REFRESH);
803 }
804 memcpy(next_hop, mpath->next_hop->addr,
805 ETH_ALEN);
806 } else {
807 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
808 /* Start discovery only if it is not running yet */
809 mesh_queue_preq(mpath, PREQ_Q_F_START);
810 }
811
812 if (skb_queue_len(&mpath->frame_queue) >=
813 MESH_FRAME_QUEUE_LEN) {
814 skb_to_free = mpath->frame_queue.next;
815 skb_unlink(skb_to_free, &mpath->frame_queue);
816 }
817
818 skb_queue_tail(&mpath->frame_queue, skb);
819 if (skb_to_free)
820 mesh_path_discard_frame(skb_to_free, dev);
821 err = -ENOENT;
822 }
823
824endlookup:
825 rcu_read_unlock();
826 return err;
827}
828
829void mesh_path_timer(unsigned long data)
830{
831 struct ieee80211_sub_if_data *sdata;
832 struct mesh_path *mpath;
833
834 rcu_read_lock();
835 mpath = (struct mesh_path *) data;
836 mpath = rcu_dereference(mpath);
837 if (!mpath)
838 goto endmpathtimer;
839 spin_lock_bh(&mpath->state_lock);
840 sdata = IEEE80211_DEV_TO_SUB_IF(mpath->dev);
841 if (mpath->flags & MESH_PATH_RESOLVED ||
842 (!(mpath->flags & MESH_PATH_RESOLVING)))
843 mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
844 else if (mpath->discovery_retries < max_preq_retries(sdata)) {
845 ++mpath->discovery_retries;
846 mpath->discovery_timeout *= 2;
847 mesh_queue_preq(mpath, 0);
848 } else {
849 mpath->flags = 0;
850 mpath->exp_time = jiffies;
851 mesh_path_flush_pending(mpath);
852 }
853
854 spin_unlock_bh(&mpath->state_lock);
855endmpathtimer:
856 rcu_read_unlock();
857}
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
new file mode 100644
index 000000000000..5845dc21ce85
--- /dev/null
+++ b/net/mac80211/mesh_pathtbl.c
@@ -0,0 +1,516 @@
1/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/etherdevice.h>
11#include <linux/list.h>
12#include <linux/netdevice.h>
13#include <linux/random.h>
14#include <linux/spinlock.h>
15#include <linux/string.h>
16#include <net/mac80211.h>
17#include "ieee80211_i.h"
18#include "mesh.h"
19
20/* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */
21#define INIT_PATHS_SIZE_ORDER 2
22
23/* Keep the mean chain length below this constant */
24#define MEAN_CHAIN_LEN 2
25
26#define MPATH_EXPIRED(mpath) ((mpath->flags & MESH_PATH_ACTIVE) && \
27 time_after(jiffies, mpath->exp_time) && \
28 !(mpath->flags & MESH_PATH_FIXED))
29
30struct mpath_node {
31 struct hlist_node list;
32 struct rcu_head rcu;
33 /* This indirection allows two different tables to point to the same
34 * mesh_path structure, useful when resizing
35 */
36 struct mesh_path *mpath;
37};
38
39static struct mesh_table *mesh_paths;
40
41/* This lock will have the grow table function as writer and add / delete nodes
42 * as readers. When reading the table (i.e. doing lookups) we are well protected
43 * by RCU
44 */
45static DEFINE_RWLOCK(pathtbl_resize_lock);
46
47/**
48 *
49 * mesh_path_assign_nexthop - update mesh path next hop
50 *
51 * @mpath: mesh path to update
52 * @sta: next hop to assign
53 *
54 * Locking: mpath->state_lock must be held when calling this function
55 */
56void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
57{
58 rcu_assign_pointer(mpath->next_hop, sta);
59}
60
61
62/**
63 * mesh_path_lookup - look up a path in the mesh path table
64 * @dst: hardware address (ETH_ALEN length) of destination
65 * @dev: local interface
66 *
67 * Returns: pointer to the mesh path structure, or NULL if not found
68 *
69 * Locking: must be called within a read rcu section.
70 */
71struct mesh_path *mesh_path_lookup(u8 *dst, struct net_device *dev)
72{
73 struct mesh_path *mpath;
74 struct hlist_node *n;
75 struct hlist_head *bucket;
76 struct mesh_table *tbl;
77 struct mpath_node *node;
78
79 tbl = rcu_dereference(mesh_paths);
80
81 bucket = &tbl->hash_buckets[mesh_table_hash(dst, dev, tbl)];
82 hlist_for_each_entry_rcu(node, n, bucket, list) {
83 mpath = node->mpath;
84 if (mpath->dev == dev &&
85 memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
86 if (MPATH_EXPIRED(mpath)) {
87 spin_lock_bh(&mpath->state_lock);
88 if (MPATH_EXPIRED(mpath))
89 mpath->flags &= ~MESH_PATH_ACTIVE;
90 spin_unlock_bh(&mpath->state_lock);
91 }
92 return mpath;
93 }
94 }
95 return NULL;
96}
97
98/**
99 * mesh_path_lookup_by_idx - look up a path in the mesh path table by its index
100 * @idx: index
101 * @dev: local interface, or NULL for all entries
102 *
103 * Returns: pointer to the mesh path structure, or NULL if not found.
104 *
105 * Locking: must be called within a read rcu section.
106 */
107struct mesh_path *mesh_path_lookup_by_idx(int idx, struct net_device *dev)
108{
109 struct mpath_node *node;
110 struct hlist_node *p;
111 int i;
112 int j = 0;
113
114 for_each_mesh_entry(mesh_paths, p, node, i) {
115 if (dev && node->mpath->dev != dev)
116 continue;
117 if (j++ == idx) {
118 if (MPATH_EXPIRED(node->mpath)) {
119 spin_lock_bh(&node->mpath->state_lock);
120 if (MPATH_EXPIRED(node->mpath))
121 node->mpath->flags &= ~MESH_PATH_ACTIVE;
122 spin_unlock_bh(&node->mpath->state_lock);
123 }
124 return node->mpath;
125 }
126 }
127
128 return NULL;
129}
130
131/**
132 * mesh_path_add - allocate and add a new path to the mesh path table
133 * @addr: destination address of the path (ETH_ALEN length)
134 * @dev: local interface
135 *
136 * Returns: 0 on sucess
137 *
138 * State: the initial state of the new path is set to 0
139 */
140int mesh_path_add(u8 *dst, struct net_device *dev)
141{
142 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
143 struct mesh_path *mpath, *new_mpath;
144 struct mpath_node *node, *new_node;
145 struct hlist_head *bucket;
146 struct hlist_node *n;
147 int grow = 0;
148 int err = 0;
149 u32 hash_idx;
150
151 if (memcmp(dst, dev->dev_addr, ETH_ALEN) == 0)
152 /* never add ourselves as neighbours */
153 return -ENOTSUPP;
154
155 if (is_multicast_ether_addr(dst))
156 return -ENOTSUPP;
157
158 if (atomic_add_unless(&sdata->u.sta.mpaths, 1, MESH_MAX_MPATHS) == 0)
159 return -ENOSPC;
160
161 read_lock(&pathtbl_resize_lock);
162
163 new_mpath = kzalloc(sizeof(struct mesh_path), GFP_KERNEL);
164 if (!new_mpath) {
165 atomic_dec(&sdata->u.sta.mpaths);
166 err = -ENOMEM;
167 goto endadd2;
168 }
169 memcpy(new_mpath->dst, dst, ETH_ALEN);
170 new_mpath->dev = dev;
171 new_mpath->flags = 0;
172 skb_queue_head_init(&new_mpath->frame_queue);
173 new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
174 new_node->mpath = new_mpath;
175 new_mpath->timer.data = (unsigned long) new_mpath;
176 new_mpath->timer.function = mesh_path_timer;
177 new_mpath->exp_time = jiffies;
178 spin_lock_init(&new_mpath->state_lock);
179 init_timer(&new_mpath->timer);
180
181 hash_idx = mesh_table_hash(dst, dev, mesh_paths);
182 bucket = &mesh_paths->hash_buckets[hash_idx];
183
184 spin_lock(&mesh_paths->hashwlock[hash_idx]);
185
186 hlist_for_each_entry(node, n, bucket, list) {
187 mpath = node->mpath;
188 if (mpath->dev == dev && memcmp(dst, mpath->dst, ETH_ALEN)
189 == 0) {
190 err = -EEXIST;
191 atomic_dec(&sdata->u.sta.mpaths);
192 kfree(new_node);
193 kfree(new_mpath);
194 goto endadd;
195 }
196 }
197
198 hlist_add_head_rcu(&new_node->list, bucket);
199 if (atomic_inc_return(&mesh_paths->entries) >=
200 mesh_paths->mean_chain_len * (mesh_paths->hash_mask + 1))
201 grow = 1;
202
203endadd:
204 spin_unlock(&mesh_paths->hashwlock[hash_idx]);
205endadd2:
206 read_unlock(&pathtbl_resize_lock);
207 if (!err && grow) {
208 struct mesh_table *oldtbl, *newtbl;
209
210 write_lock(&pathtbl_resize_lock);
211 oldtbl = mesh_paths;
212 newtbl = mesh_table_grow(mesh_paths);
213 if (!newtbl) {
214 write_unlock(&pathtbl_resize_lock);
215 return -ENOMEM;
216 }
217 rcu_assign_pointer(mesh_paths, newtbl);
218 synchronize_rcu();
219 mesh_table_free(oldtbl, false);
220 write_unlock(&pathtbl_resize_lock);
221 }
222 return err;
223}
224
225
226/**
227 * mesh_plink_broken - deactivates paths and sends perr when a link breaks
228 *
229 * @sta: broken peer link
230 *
231 * This function must be called from the rate control algorithm if enough
232 * delivery errors suggest that a peer link is no longer usable.
233 */
234void mesh_plink_broken(struct sta_info *sta)
235{
236 struct mesh_path *mpath;
237 struct mpath_node *node;
238 struct hlist_node *p;
239 struct net_device *dev = sta->sdata->dev;
240 int i;
241
242 rcu_read_lock();
243 for_each_mesh_entry(mesh_paths, p, node, i) {
244 mpath = node->mpath;
245 spin_lock_bh(&mpath->state_lock);
246 if (mpath->next_hop == sta &&
247 mpath->flags & MESH_PATH_ACTIVE &&
248 !(mpath->flags & MESH_PATH_FIXED)) {
249 mpath->flags &= ~MESH_PATH_ACTIVE;
250 ++mpath->dsn;
251 spin_unlock_bh(&mpath->state_lock);
252 mesh_path_error_tx(mpath->dst,
253 cpu_to_le32(mpath->dsn),
254 dev->broadcast, dev);
255 } else
256 spin_unlock_bh(&mpath->state_lock);
257 }
258 rcu_read_unlock();
259}
260EXPORT_SYMBOL(mesh_plink_broken);
261
262/**
263 * mesh_path_flush_by_nexthop - Deletes mesh paths if their next hop matches
264 *
265 * @sta - mesh peer to match
266 *
267 * RCU notes: this function is called when a mesh plink transitions from
268 * PLINK_ESTAB to any other state, since PLINK_ESTAB state is the only one that
269 * allows path creation. This will happen before the sta can be freed (because
270 * sta_info_destroy() calls this) so any reader in a rcu read block will be
271 * protected against the plink disappearing.
272 */
273void mesh_path_flush_by_nexthop(struct sta_info *sta)
274{
275 struct mesh_path *mpath;
276 struct mpath_node *node;
277 struct hlist_node *p;
278 int i;
279
280 for_each_mesh_entry(mesh_paths, p, node, i) {
281 mpath = node->mpath;
282 if (mpath->next_hop == sta)
283 mesh_path_del(mpath->dst, mpath->dev);
284 }
285}
286
287void mesh_path_flush(struct net_device *dev)
288{
289 struct mesh_path *mpath;
290 struct mpath_node *node;
291 struct hlist_node *p;
292 int i;
293
294 for_each_mesh_entry(mesh_paths, p, node, i) {
295 mpath = node->mpath;
296 if (mpath->dev == dev)
297 mesh_path_del(mpath->dst, mpath->dev);
298 }
299}
300
301static void mesh_path_node_reclaim(struct rcu_head *rp)
302{
303 struct mpath_node *node = container_of(rp, struct mpath_node, rcu);
304 struct ieee80211_sub_if_data *sdata =
305 IEEE80211_DEV_TO_SUB_IF(node->mpath->dev);
306
307 del_timer_sync(&node->mpath->timer);
308 atomic_dec(&sdata->u.sta.mpaths);
309 kfree(node->mpath);
310 kfree(node);
311}
312
313/**
314 * mesh_path_del - delete a mesh path from the table
315 *
316 * @addr: dst address (ETH_ALEN length)
317 * @dev: local interface
318 *
319 * Returns: 0 if succesful
320 */
321int mesh_path_del(u8 *addr, struct net_device *dev)
322{
323 struct mesh_path *mpath;
324 struct mpath_node *node;
325 struct hlist_head *bucket;
326 struct hlist_node *n;
327 int hash_idx;
328 int err = 0;
329
330 read_lock(&pathtbl_resize_lock);
331 hash_idx = mesh_table_hash(addr, dev, mesh_paths);
332 bucket = &mesh_paths->hash_buckets[hash_idx];
333
334 spin_lock(&mesh_paths->hashwlock[hash_idx]);
335 hlist_for_each_entry(node, n, bucket, list) {
336 mpath = node->mpath;
337 if (mpath->dev == dev &&
338 memcmp(addr, mpath->dst, ETH_ALEN) == 0) {
339 spin_lock_bh(&mpath->state_lock);
340 mpath->flags |= MESH_PATH_RESOLVING;
341 hlist_del_rcu(&node->list);
342 call_rcu(&node->rcu, mesh_path_node_reclaim);
343 atomic_dec(&mesh_paths->entries);
344 spin_unlock_bh(&mpath->state_lock);
345 goto enddel;
346 }
347 }
348
349 err = -ENXIO;
350enddel:
351 spin_unlock(&mesh_paths->hashwlock[hash_idx]);
352 read_unlock(&pathtbl_resize_lock);
353 return err;
354}
355
356/**
357 * mesh_path_tx_pending - sends pending frames in a mesh path queue
358 *
359 * @mpath: mesh path to activate
360 *
361 * Locking: the state_lock of the mpath structure must NOT be held when calling
362 * this function.
363 */
364void mesh_path_tx_pending(struct mesh_path *mpath)
365{
366 struct sk_buff *skb;
367
368 while ((skb = skb_dequeue(&mpath->frame_queue)) &&
369 (mpath->flags & MESH_PATH_ACTIVE))
370 dev_queue_xmit(skb);
371}
372
373/**
374 * mesh_path_discard_frame - discard a frame whose path could not be resolved
375 *
376 * @skb: frame to discard
377 * @dev: network device the frame was to be sent through
378 *
379 * If the frame was beign forwarded from another MP, a PERR frame will be sent
380 * to the precursor.
381 *
382 * Locking: the function must me called within a rcu_read_lock region
383 */
384void mesh_path_discard_frame(struct sk_buff *skb, struct net_device *dev)
385{
386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
387 struct mesh_path *mpath;
388 u32 dsn = 0;
389
390 if (skb->pkt_type == PACKET_OTHERHOST) {
391 struct ieee80211s_hdr *prev_meshhdr;
392 int mshhdrlen;
393 u8 *ra, *da;
394
395 prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb);
396 mshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr);
397 da = skb->data;
398 ra = MESH_PREQ(skb);
399 mpath = mesh_path_lookup(da, dev);
400 if (mpath)
401 dsn = ++mpath->dsn;
402 mesh_path_error_tx(skb->data, cpu_to_le32(dsn), ra, dev);
403 }
404
405 kfree_skb(skb);
406 sdata->u.sta.mshstats.dropped_frames_no_route++;
407}
408
409/**
410 * mesh_path_flush_pending - free the pending queue of a mesh path
411 *
412 * @mpath: mesh path whose queue has to be freed
413 *
414 * Locking: the function must me called withing a rcu_read_lock region
415 */
416void mesh_path_flush_pending(struct mesh_path *mpath)
417{
418 struct ieee80211_sub_if_data *sdata;
419 struct sk_buff *skb;
420
421 sdata = IEEE80211_DEV_TO_SUB_IF(mpath->dev);
422
423 while ((skb = skb_dequeue(&mpath->frame_queue)) &&
424 (mpath->flags & MESH_PATH_ACTIVE))
425 mesh_path_discard_frame(skb, mpath->dev);
426}
427
428/**
429 * mesh_path_fix_nexthop - force a specific next hop for a mesh path
430 *
431 * @mpath: the mesh path to modify
432 * @next_hop: the next hop to force
433 *
434 * Locking: this function must be called holding mpath->state_lock
435 */
436void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop)
437{
438 spin_lock_bh(&mpath->state_lock);
439 mesh_path_assign_nexthop(mpath, next_hop);
440 mpath->dsn = 0xffff;
441 mpath->metric = 0;
442 mpath->hop_count = 0;
443 mpath->exp_time = 0;
444 mpath->flags |= MESH_PATH_FIXED;
445 mesh_path_activate(mpath);
446 spin_unlock_bh(&mpath->state_lock);
447 mesh_path_tx_pending(mpath);
448}
449
450static void mesh_path_node_free(struct hlist_node *p, bool free_leafs)
451{
452 struct mesh_path *mpath;
453 struct mpath_node *node = hlist_entry(p, struct mpath_node, list);
454 mpath = node->mpath;
455 hlist_del_rcu(p);
456 synchronize_rcu();
457 if (free_leafs)
458 kfree(mpath);
459 kfree(node);
460}
461
462static void mesh_path_node_copy(struct hlist_node *p, struct mesh_table *newtbl)
463{
464 struct mesh_path *mpath;
465 struct mpath_node *node, *new_node;
466 u32 hash_idx;
467
468 node = hlist_entry(p, struct mpath_node, list);
469 mpath = node->mpath;
470 new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
471 new_node->mpath = mpath;
472 hash_idx = mesh_table_hash(mpath->dst, mpath->dev, newtbl);
473 hlist_add_head(&new_node->list,
474 &newtbl->hash_buckets[hash_idx]);
475}
476
477int mesh_pathtbl_init(void)
478{
479 mesh_paths = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
480 mesh_paths->free_node = &mesh_path_node_free;
481 mesh_paths->copy_node = &mesh_path_node_copy;
482 mesh_paths->mean_chain_len = MEAN_CHAIN_LEN;
483 if (!mesh_paths)
484 return -ENOMEM;
485 return 0;
486}
487
488void mesh_path_expire(struct net_device *dev)
489{
490 struct mesh_path *mpath;
491 struct mpath_node *node;
492 struct hlist_node *p;
493 int i;
494
495 read_lock(&pathtbl_resize_lock);
496 for_each_mesh_entry(mesh_paths, p, node, i) {
497 if (node->mpath->dev != dev)
498 continue;
499 mpath = node->mpath;
500 spin_lock_bh(&mpath->state_lock);
501 if ((!(mpath->flags & MESH_PATH_RESOLVING)) &&
502 (!(mpath->flags & MESH_PATH_FIXED)) &&
503 time_after(jiffies,
504 mpath->exp_time + MESH_PATH_EXPIRE)) {
505 spin_unlock_bh(&mpath->state_lock);
506 mesh_path_del(mpath->dst, mpath->dev);
507 } else
508 spin_unlock_bh(&mpath->state_lock);
509 }
510 read_unlock(&pathtbl_resize_lock);
511}
512
513void mesh_pathtbl_unregister(void)
514{
515 mesh_table_free(mesh_paths, true);
516}
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
new file mode 100644
index 000000000000..18fe52436c47
--- /dev/null
+++ b/net/mac80211/mesh_plink.c
@@ -0,0 +1,761 @@
1/*
2 * Copyright (c) 2008 open80211s Ltd.
3 * Author: Luis Carlos Cobo <luisca@cozybit.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9#include <linux/kernel.h>
10#include <linux/random.h>
11#include "ieee80211_i.h"
12#include "ieee80211_rate.h"
13#include "mesh.h"
14
15#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
16#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
17#else
18#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
19#endif
20
21#define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
22#define PLINK_GET_FRAME_SUBTYPE(p) (p)
23#define PLINK_GET_LLID(p) (p + 1)
24#define PLINK_GET_PLID(p) (p + 3)
25
26#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
27 jiffies + HZ * t / 1000))
28
29/* Peer link cancel reasons, all subject to ANA approval */
30#define MESH_LINK_CANCELLED 2
31#define MESH_MAX_NEIGHBORS 3
32#define MESH_CAPABILITY_POLICY_VIOLATION 4
33#define MESH_CLOSE_RCVD 5
34#define MESH_MAX_RETRIES 6
35#define MESH_CONFIRM_TIMEOUT 7
36#define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8
37#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
38#define MESH_SECURITY_FAILED_VERIFICATION 10
39
40#define dot11MeshMaxRetries(s) (s->u.sta.mshcfg.dot11MeshMaxRetries)
41#define dot11MeshRetryTimeout(s) (s->u.sta.mshcfg.dot11MeshRetryTimeout)
42#define dot11MeshConfirmTimeout(s) (s->u.sta.mshcfg.dot11MeshConfirmTimeout)
43#define dot11MeshHoldingTimeout(s) (s->u.sta.mshcfg.dot11MeshHoldingTimeout)
44#define dot11MeshMaxPeerLinks(s) (s->u.sta.mshcfg.dot11MeshMaxPeerLinks)
45
46enum plink_frame_type {
47 PLINK_OPEN = 0,
48 PLINK_CONFIRM,
49 PLINK_CLOSE
50};
51
52enum plink_event {
53 PLINK_UNDEFINED,
54 OPN_ACPT,
55 OPN_RJCT,
56 OPN_IGNR,
57 CNF_ACPT,
58 CNF_RJCT,
59 CNF_IGNR,
60 CLS_ACPT,
61 CLS_IGNR
62};
63
64static inline
65void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
66{
67 atomic_inc(&sdata->u.sta.mshstats.estab_plinks);
68 mesh_accept_plinks_update(sdata);
69}
70
71static inline
72void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
73{
74 atomic_dec(&sdata->u.sta.mshstats.estab_plinks);
75 mesh_accept_plinks_update(sdata);
76}
77
78/**
79 * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
80 *
81 * @sta: mes peer link to restart
82 *
83 * Locking: this function must be called holding sta->plink_lock
84 */
85static inline void mesh_plink_fsm_restart(struct sta_info *sta)
86{
87 sta->plink_state = PLINK_LISTEN;
88 sta->llid = sta->plid = sta->reason = 0;
89 sta->plink_retries = 0;
90}
91
92static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
93 u8 *hw_addr, u64 rates)
94{
95 struct ieee80211_local *local = sdata->local;
96 struct sta_info *sta;
97
98 if (local->num_sta >= MESH_MAX_PLINKS)
99 return NULL;
100
101 sta = sta_info_alloc(sdata, hw_addr, GFP_ATOMIC);
102 if (!sta)
103 return NULL;
104
105 sta->flags |= WLAN_STA_AUTHORIZED;
106 sta->supp_rates[local->hw.conf.channel->band] = rates;
107
108 return sta;
109}
110
111/**
112 * mesh_plink_deactivate - deactivate mesh peer link
113 *
114 * @sta: mesh peer link to deactivate
115 *
116 * All mesh paths with this peer as next hop will be flushed
117 *
118 * Locking: the caller must hold sta->plink_lock
119 */
120static void __mesh_plink_deactivate(struct sta_info *sta)
121{
122 struct ieee80211_sub_if_data *sdata = sta->sdata;
123
124 if (sta->plink_state == PLINK_ESTAB)
125 mesh_plink_dec_estab_count(sdata);
126 sta->plink_state = PLINK_BLOCKED;
127 mesh_path_flush_by_nexthop(sta);
128}
129
130/**
131 * __mesh_plink_deactivate - deactivate mesh peer link
132 *
133 * @sta: mesh peer link to deactivate
134 *
135 * All mesh paths with this peer as next hop will be flushed
136 */
137void mesh_plink_deactivate(struct sta_info *sta)
138{
139 spin_lock_bh(&sta->plink_lock);
140 __mesh_plink_deactivate(sta);
141 spin_unlock_bh(&sta->plink_lock);
142}
143
144static int mesh_plink_frame_tx(struct net_device *dev,
145 enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
146 __le16 reason) {
147 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
148 struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
149 struct ieee80211_mgmt *mgmt;
150 bool include_plid = false;
151 u8 *pos;
152 int ie_len;
153
154 if (!skb)
155 return -1;
156 skb_reserve(skb, local->hw.extra_tx_headroom);
157 /* 25 is the size of the common mgmt part (24) plus the size of the
158 * common action part (1)
159 */
160 mgmt = (struct ieee80211_mgmt *)
161 skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
162 memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
163 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
164 IEEE80211_STYPE_ACTION);
165 memcpy(mgmt->da, da, ETH_ALEN);
166 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
167 /* BSSID is left zeroed, wildcard value */
168 mgmt->u.action.category = PLINK_CATEGORY;
169 mgmt->u.action.u.plink_action.action_code = action;
170
171 if (action == PLINK_CLOSE)
172 mgmt->u.action.u.plink_action.aux = reason;
173 else {
174 mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
175 if (action == PLINK_CONFIRM) {
176 pos = skb_put(skb, 4);
177 /* two-byte status code followed by two-byte AID */
178 memset(pos, 0, 4);
179 }
180 mesh_mgmt_ies_add(skb, dev);
181 }
182
183 /* Add Peer Link Management element */
184 switch (action) {
185 case PLINK_OPEN:
186 ie_len = 3;
187 break;
188 case PLINK_CONFIRM:
189 ie_len = 5;
190 include_plid = true;
191 break;
192 case PLINK_CLOSE:
193 default:
194 if (!plid)
195 ie_len = 5;
196 else {
197 ie_len = 7;
198 include_plid = true;
199 }
200 break;
201 }
202
203 pos = skb_put(skb, 2 + ie_len);
204 *pos++ = WLAN_EID_PEER_LINK;
205 *pos++ = ie_len;
206 *pos++ = action;
207 memcpy(pos, &llid, 2);
208 if (include_plid) {
209 pos += 2;
210 memcpy(pos, &plid, 2);
211 }
212 if (action == PLINK_CLOSE) {
213 pos += 2;
214 memcpy(pos, &reason, 2);
215 }
216
217 ieee80211_sta_tx(dev, skb, 0);
218 return 0;
219}
220
221void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
222 bool peer_accepting_plinks)
223{
224 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
225 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
226 struct sta_info *sta;
227
228 rcu_read_lock();
229
230 sta = sta_info_get(local, hw_addr);
231 if (!sta) {
232 sta = mesh_plink_alloc(sdata, hw_addr, rates);
233 if (!sta) {
234 rcu_read_unlock();
235 return;
236 }
237 if (sta_info_insert(sta)) {
238 sta_info_destroy(sta);
239 rcu_read_unlock();
240 return;
241 }
242 }
243
244 sta->last_rx = jiffies;
245 sta->supp_rates[local->hw.conf.channel->band] = rates;
246 if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
247 sdata->u.sta.accepting_plinks &&
248 sdata->u.sta.mshcfg.auto_open_plinks)
249 mesh_plink_open(sta);
250
251 rcu_read_unlock();
252}
253
254static void mesh_plink_timer(unsigned long data)
255{
256 struct sta_info *sta;
257 __le16 llid, plid, reason;
258 struct net_device *dev = NULL;
259 struct ieee80211_sub_if_data *sdata;
260#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
261 DECLARE_MAC_BUF(mac);
262#endif
263
264 /*
265 * This STA is valid because sta_info_destroy() will
266 * del_timer_sync() this timer after having made sure
267 * it cannot be readded (by deleting the plink.)
268 */
269 sta = (struct sta_info *) data;
270
271 spin_lock_bh(&sta->plink_lock);
272 if (sta->ignore_plink_timer) {
273 sta->ignore_plink_timer = false;
274 spin_unlock_bh(&sta->plink_lock);
275 return;
276 }
277 mpl_dbg("Mesh plink timer for %s fired on state %d\n",
278 print_mac(mac, sta->addr), sta->plink_state);
279 reason = 0;
280 llid = sta->llid;
281 plid = sta->plid;
282 sdata = sta->sdata;
283 dev = sdata->dev;
284
285 switch (sta->plink_state) {
286 case PLINK_OPN_RCVD:
287 case PLINK_OPN_SNT:
288 /* retry timer */
289 if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
290 u32 rand;
291 mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
292 print_mac(mac, sta->addr),
293 sta->plink_retries, sta->plink_timeout);
294 get_random_bytes(&rand, sizeof(u32));
295 sta->plink_timeout = sta->plink_timeout +
296 rand % sta->plink_timeout;
297 ++sta->plink_retries;
298 mod_plink_timer(sta, sta->plink_timeout);
299 spin_unlock_bh(&sta->plink_lock);
300 mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
301 0, 0);
302 break;
303 }
304 reason = cpu_to_le16(MESH_MAX_RETRIES);
305 /* fall through on else */
306 case PLINK_CNF_RCVD:
307 /* confirm timer */
308 if (!reason)
309 reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
310 sta->plink_state = PLINK_HOLDING;
311 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
312 spin_unlock_bh(&sta->plink_lock);
313 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid, plid,
314 reason);
315 break;
316 case PLINK_HOLDING:
317 /* holding timer */
318 del_timer(&sta->plink_timer);
319 mesh_plink_fsm_restart(sta);
320 spin_unlock_bh(&sta->plink_lock);
321 break;
322 default:
323 spin_unlock_bh(&sta->plink_lock);
324 break;
325 }
326}
327
328static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
329{
330 sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
331 sta->plink_timer.data = (unsigned long) sta;
332 sta->plink_timer.function = mesh_plink_timer;
333 sta->plink_timeout = timeout;
334 add_timer(&sta->plink_timer);
335}
336
337int mesh_plink_open(struct sta_info *sta)
338{
339 __le16 llid;
340 struct ieee80211_sub_if_data *sdata = sta->sdata;
341#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
342 DECLARE_MAC_BUF(mac);
343#endif
344
345 spin_lock_bh(&sta->plink_lock);
346 get_random_bytes(&llid, 2);
347 sta->llid = llid;
348 if (sta->plink_state != PLINK_LISTEN) {
349 spin_unlock_bh(&sta->plink_lock);
350 return -EBUSY;
351 }
352 sta->plink_state = PLINK_OPN_SNT;
353 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
354 spin_unlock_bh(&sta->plink_lock);
355 mpl_dbg("Mesh plink: starting establishment with %s\n",
356 print_mac(mac, sta->addr));
357
358 return mesh_plink_frame_tx(sdata->dev, PLINK_OPEN,
359 sta->addr, llid, 0, 0);
360}
361
362void mesh_plink_block(struct sta_info *sta)
363{
364#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
365 DECLARE_MAC_BUF(mac);
366#endif
367
368 spin_lock_bh(&sta->plink_lock);
369 __mesh_plink_deactivate(sta);
370 sta->plink_state = PLINK_BLOCKED;
371 spin_unlock_bh(&sta->plink_lock);
372}
373
374int mesh_plink_close(struct sta_info *sta)
375{
376 struct ieee80211_sub_if_data *sdata = sta->sdata;
377 __le16 llid, plid, reason;
378#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
379 DECLARE_MAC_BUF(mac);
380#endif
381
382 mpl_dbg("Mesh plink: closing link with %s\n",
383 print_mac(mac, sta->addr));
384 spin_lock_bh(&sta->plink_lock);
385 sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
386 reason = sta->reason;
387
388 if (sta->plink_state == PLINK_LISTEN ||
389 sta->plink_state == PLINK_BLOCKED) {
390 mesh_plink_fsm_restart(sta);
391 spin_unlock_bh(&sta->plink_lock);
392 return 0;
393 } else if (sta->plink_state == PLINK_ESTAB) {
394 __mesh_plink_deactivate(sta);
395 /* The timer should not be running */
396 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
397 } else if (!mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)))
398 sta->ignore_plink_timer = true;
399
400 sta->plink_state = PLINK_HOLDING;
401 llid = sta->llid;
402 plid = sta->plid;
403 spin_unlock_bh(&sta->plink_lock);
404 mesh_plink_frame_tx(sta->sdata->dev, PLINK_CLOSE, sta->addr, llid,
405 plid, reason);
406 return 0;
407}
408
409void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
410 size_t len, struct ieee80211_rx_status *rx_status)
411{
412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
413 struct ieee80211_local *local = sdata->local;
414 struct ieee802_11_elems elems;
415 struct sta_info *sta;
416 enum plink_event event;
417 enum plink_frame_type ftype;
418 size_t baselen;
419 u8 ie_len;
420 u8 *baseaddr;
421 __le16 plid, llid, reason;
422#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
423 DECLARE_MAC_BUF(mac);
424#endif
425
426 if (is_multicast_ether_addr(mgmt->da)) {
427 mpl_dbg("Mesh plink: ignore frame from multicast address");
428 return;
429 }
430
431 baseaddr = mgmt->u.action.u.plink_action.variable;
432 baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
433 if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
434 baseaddr += 4;
435 baselen -= 4;
436 }
437 ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
438 if (!elems.peer_link) {
439 mpl_dbg("Mesh plink: missing necessary peer link ie\n");
440 return;
441 }
442
443 ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
444 ie_len = elems.peer_link_len;
445 if ((ftype == PLINK_OPEN && ie_len != 3) ||
446 (ftype == PLINK_CONFIRM && ie_len != 5) ||
447 (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
448 mpl_dbg("Mesh plink: incorrect plink ie length\n");
449 return;
450 }
451
452 if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
453 mpl_dbg("Mesh plink: missing necessary ie\n");
454 return;
455 }
456 /* Note the lines below are correct, the llid in the frame is the plid
457 * from the point of view of this host.
458 */
459 memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
460 if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
461 memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
462
463 rcu_read_lock();
464
465 sta = sta_info_get(local, mgmt->sa);
466 if (!sta && ftype != PLINK_OPEN) {
467 mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
468 rcu_read_unlock();
469 return;
470 }
471
472 if (sta && sta->plink_state == PLINK_BLOCKED) {
473 rcu_read_unlock();
474 return;
475 }
476
477 /* Now we will figure out the appropriate event... */
478 event = PLINK_UNDEFINED;
479 if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, dev))) {
480 switch (ftype) {
481 case PLINK_OPEN:
482 event = OPN_RJCT;
483 break;
484 case PLINK_CONFIRM:
485 event = CNF_RJCT;
486 break;
487 case PLINK_CLOSE:
488 /* avoid warning */
489 break;
490 }
491 spin_lock_bh(&sta->plink_lock);
492 } else if (!sta) {
493 /* ftype == PLINK_OPEN */
494 u64 rates;
495 if (!mesh_plink_free_count(sdata)) {
496 mpl_dbg("Mesh plink error: no more free plinks\n");
497 rcu_read_unlock();
498 return;
499 }
500
501 rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
502 sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
503 if (!sta) {
504 mpl_dbg("Mesh plink error: plink table full\n");
505 rcu_read_unlock();
506 return;
507 }
508 if (sta_info_insert(sta)) {
509 sta_info_destroy(sta);
510 rcu_read_unlock();
511 return;
512 }
513 event = OPN_ACPT;
514 spin_lock_bh(&sta->plink_lock);
515 } else {
516 spin_lock_bh(&sta->plink_lock);
517 switch (ftype) {
518 case PLINK_OPEN:
519 if (!mesh_plink_free_count(sdata) ||
520 (sta->plid && sta->plid != plid))
521 event = OPN_IGNR;
522 else
523 event = OPN_ACPT;
524 break;
525 case PLINK_CONFIRM:
526 if (!mesh_plink_free_count(sdata) ||
527 (sta->llid != llid || sta->plid != plid))
528 event = CNF_IGNR;
529 else
530 event = CNF_ACPT;
531 break;
532 case PLINK_CLOSE:
533 if (sta->plink_state == PLINK_ESTAB)
534 /* Do not check for llid or plid. This does not
535 * follow the standard but since multiple plinks
536 * per sta are not supported, it is necessary in
537 * order to avoid a livelock when MP A sees an
538 * establish peer link to MP B but MP B does not
539 * see it. This can be caused by a timeout in
540 * B's peer link establishment or B beign
541 * restarted.
542 */
543 event = CLS_ACPT;
544 else if (sta->plid != plid)
545 event = CLS_IGNR;
546 else if (ie_len == 7 && sta->llid != llid)
547 event = CLS_IGNR;
548 else
549 event = CLS_ACPT;
550 break;
551 default:
552 mpl_dbg("Mesh plink: unknown frame subtype\n");
553 spin_unlock_bh(&sta->plink_lock);
554 rcu_read_unlock();
555 return;
556 }
557 }
558
559 mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n",
560 print_mac(mac, mgmt->sa), sta->plink_state,
561 le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
562 event);
563 reason = 0;
564 switch (sta->plink_state) {
565 /* spin_unlock as soon as state is updated at each case */
566 case PLINK_LISTEN:
567 switch (event) {
568 case CLS_ACPT:
569 mesh_plink_fsm_restart(sta);
570 spin_unlock_bh(&sta->plink_lock);
571 break;
572 case OPN_ACPT:
573 sta->plink_state = PLINK_OPN_RCVD;
574 sta->plid = plid;
575 get_random_bytes(&llid, 2);
576 sta->llid = llid;
577 mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
578 spin_unlock_bh(&sta->plink_lock);
579 mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
580 0, 0);
581 mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr,
582 llid, plid, 0);
583 break;
584 default:
585 spin_unlock_bh(&sta->plink_lock);
586 break;
587 }
588 break;
589
590 case PLINK_OPN_SNT:
591 switch (event) {
592 case OPN_RJCT:
593 case CNF_RJCT:
594 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
595 case CLS_ACPT:
596 if (!reason)
597 reason = cpu_to_le16(MESH_CLOSE_RCVD);
598 sta->reason = reason;
599 sta->plink_state = PLINK_HOLDING;
600 if (!mod_plink_timer(sta,
601 dot11MeshHoldingTimeout(sdata)))
602 sta->ignore_plink_timer = true;
603
604 llid = sta->llid;
605 spin_unlock_bh(&sta->plink_lock);
606 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
607 plid, reason);
608 break;
609 case OPN_ACPT:
610 /* retry timer is left untouched */
611 sta->plink_state = PLINK_OPN_RCVD;
612 sta->plid = plid;
613 llid = sta->llid;
614 spin_unlock_bh(&sta->plink_lock);
615 mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
616 plid, 0);
617 break;
618 case CNF_ACPT:
619 sta->plink_state = PLINK_CNF_RCVD;
620 if (!mod_plink_timer(sta,
621 dot11MeshConfirmTimeout(sdata)))
622 sta->ignore_plink_timer = true;
623
624 spin_unlock_bh(&sta->plink_lock);
625 break;
626 default:
627 spin_unlock_bh(&sta->plink_lock);
628 break;
629 }
630 break;
631
632 case PLINK_OPN_RCVD:
633 switch (event) {
634 case OPN_RJCT:
635 case CNF_RJCT:
636 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
637 case CLS_ACPT:
638 if (!reason)
639 reason = cpu_to_le16(MESH_CLOSE_RCVD);
640 sta->reason = reason;
641 sta->plink_state = PLINK_HOLDING;
642 if (!mod_plink_timer(sta,
643 dot11MeshHoldingTimeout(sdata)))
644 sta->ignore_plink_timer = true;
645
646 llid = sta->llid;
647 spin_unlock_bh(&sta->plink_lock);
648 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
649 plid, reason);
650 break;
651 case OPN_ACPT:
652 llid = sta->llid;
653 spin_unlock_bh(&sta->plink_lock);
654 mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
655 plid, 0);
656 break;
657 case CNF_ACPT:
658 del_timer(&sta->plink_timer);
659 sta->plink_state = PLINK_ESTAB;
660 mesh_plink_inc_estab_count(sdata);
661 spin_unlock_bh(&sta->plink_lock);
662 mpl_dbg("Mesh plink with %s ESTABLISHED\n",
663 print_mac(mac, sta->addr));
664 break;
665 default:
666 spin_unlock_bh(&sta->plink_lock);
667 break;
668 }
669 break;
670
671 case PLINK_CNF_RCVD:
672 switch (event) {
673 case OPN_RJCT:
674 case CNF_RJCT:
675 reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
676 case CLS_ACPT:
677 if (!reason)
678 reason = cpu_to_le16(MESH_CLOSE_RCVD);
679 sta->reason = reason;
680 sta->plink_state = PLINK_HOLDING;
681 if (!mod_plink_timer(sta,
682 dot11MeshHoldingTimeout(sdata)))
683 sta->ignore_plink_timer = true;
684
685 llid = sta->llid;
686 spin_unlock_bh(&sta->plink_lock);
687 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
688 plid, reason);
689 break;
690 case OPN_ACPT:
691 del_timer(&sta->plink_timer);
692 sta->plink_state = PLINK_ESTAB;
693 mesh_plink_inc_estab_count(sdata);
694 spin_unlock_bh(&sta->plink_lock);
695 mpl_dbg("Mesh plink with %s ESTABLISHED\n",
696 print_mac(mac, sta->addr));
697 mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
698 plid, 0);
699 break;
700 default:
701 spin_unlock_bh(&sta->plink_lock);
702 break;
703 }
704 break;
705
706 case PLINK_ESTAB:
707 switch (event) {
708 case CLS_ACPT:
709 reason = cpu_to_le16(MESH_CLOSE_RCVD);
710 sta->reason = reason;
711 __mesh_plink_deactivate(sta);
712 sta->plink_state = PLINK_HOLDING;
713 llid = sta->llid;
714 mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
715 spin_unlock_bh(&sta->plink_lock);
716 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
717 plid, reason);
718 break;
719 case OPN_ACPT:
720 llid = sta->llid;
721 spin_unlock_bh(&sta->plink_lock);
722 mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
723 plid, 0);
724 break;
725 default:
726 spin_unlock_bh(&sta->plink_lock);
727 break;
728 }
729 break;
730 case PLINK_HOLDING:
731 switch (event) {
732 case CLS_ACPT:
733 if (del_timer(&sta->plink_timer))
734 sta->ignore_plink_timer = 1;
735 mesh_plink_fsm_restart(sta);
736 spin_unlock_bh(&sta->plink_lock);
737 break;
738 case OPN_ACPT:
739 case CNF_ACPT:
740 case OPN_RJCT:
741 case CNF_RJCT:
742 llid = sta->llid;
743 reason = sta->reason;
744 spin_unlock_bh(&sta->plink_lock);
745 mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
746 plid, reason);
747 break;
748 default:
749 spin_unlock_bh(&sta->plink_lock);
750 }
751 break;
752 default:
753 /* should not get here, PLINK_BLOCKED is dealt with at the
754 * beggining of the function
755 */
756 spin_unlock_bh(&sta->plink_lock);
757 break;
758 }
759
760 rcu_read_unlock();
761}
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 3b77410588e7..a1993161de99 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -15,7 +15,7 @@
15#include <linux/debugfs.h> 15#include <linux/debugfs.h>
16#include <net/mac80211.h> 16#include <net/mac80211.h>
17#include "ieee80211_rate.h" 17#include "ieee80211_rate.h"
18 18#include "mesh.h"
19#include "rc80211_pid.h" 19#include "rc80211_pid.h"
20 20
21 21
@@ -63,6 +63,7 @@
63 * RC_PID_ARITH_SHIFT. 63 * RC_PID_ARITH_SHIFT.
64 */ 64 */
65 65
66
66/* Adjust the rate while ensuring that we won't switch to a lower rate if it 67/* Adjust the rate while ensuring that we won't switch to a lower rate if it
67 * exhibited a worse failed frames behaviour and we'll choose the highest rate 68 * exhibited a worse failed frames behaviour and we'll choose the highest rate
68 * whose failed frames behaviour is not worse than the one of the original rate 69 * whose failed frames behaviour is not worse than the one of the original rate
@@ -72,14 +73,14 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
72 struct rc_pid_rateinfo *rinfo) 73 struct rc_pid_rateinfo *rinfo)
73{ 74{
74 struct ieee80211_sub_if_data *sdata; 75 struct ieee80211_sub_if_data *sdata;
75 struct ieee80211_hw_mode *mode; 76 struct ieee80211_supported_band *sband;
76 int cur_sorted, new_sorted, probe, tmp, n_bitrates; 77 int cur_sorted, new_sorted, probe, tmp, n_bitrates, band;
77 int cur = sta->txrate; 78 int cur = sta->txrate_idx;
78
79 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
80 79
81 mode = local->oper_hw_mode; 80 sdata = sta->sdata;
82 n_bitrates = mode->num_rates; 81 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
82 band = sband->band;
83 n_bitrates = sband->n_bitrates;
83 84
84 /* Map passed arguments to sorted values. */ 85 /* Map passed arguments to sorted values. */
85 cur_sorted = rinfo[cur].rev_index; 86 cur_sorted = rinfo[cur].rev_index;
@@ -97,20 +98,20 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
97 /* Ensure that the rate decrease isn't disadvantageous. */ 98 /* Ensure that the rate decrease isn't disadvantageous. */
98 for (probe = cur_sorted; probe >= new_sorted; probe--) 99 for (probe = cur_sorted; probe >= new_sorted; probe--)
99 if (rinfo[probe].diff <= rinfo[cur_sorted].diff && 100 if (rinfo[probe].diff <= rinfo[cur_sorted].diff &&
100 rate_supported(sta, mode, rinfo[probe].index)) 101 rate_supported(sta, band, rinfo[probe].index))
101 tmp = probe; 102 tmp = probe;
102 } else { 103 } else {
103 /* Look for rate increase with zero (or below) cost. */ 104 /* Look for rate increase with zero (or below) cost. */
104 for (probe = new_sorted + 1; probe < n_bitrates; probe++) 105 for (probe = new_sorted + 1; probe < n_bitrates; probe++)
105 if (rinfo[probe].diff <= rinfo[new_sorted].diff && 106 if (rinfo[probe].diff <= rinfo[new_sorted].diff &&
106 rate_supported(sta, mode, rinfo[probe].index)) 107 rate_supported(sta, band, rinfo[probe].index))
107 tmp = probe; 108 tmp = probe;
108 } 109 }
109 110
110 /* Fit the rate found to the nearest supported rate. */ 111 /* Fit the rate found to the nearest supported rate. */
111 do { 112 do {
112 if (rate_supported(sta, mode, rinfo[tmp].index)) { 113 if (rate_supported(sta, band, rinfo[tmp].index)) {
113 sta->txrate = rinfo[tmp].index; 114 sta->txrate_idx = rinfo[tmp].index;
114 break; 115 break;
115 } 116 }
116 if (adj < 0) 117 if (adj < 0)
@@ -122,7 +123,7 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
122#ifdef CONFIG_MAC80211_DEBUGFS 123#ifdef CONFIG_MAC80211_DEBUGFS
123 rate_control_pid_event_rate_change( 124 rate_control_pid_event_rate_change(
124 &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events, 125 &((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events,
125 cur, mode->rates[cur].rate); 126 sta->txrate_idx, sband->bitrates[sta->txrate_idx].bitrate);
126#endif 127#endif
127} 128}
128 129
@@ -147,9 +148,12 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
147 struct ieee80211_local *local, 148 struct ieee80211_local *local,
148 struct sta_info *sta) 149 struct sta_info *sta)
149{ 150{
151#ifdef CONFIG_MAC80211_MESH
152 struct ieee80211_sub_if_data *sdata = sta->sdata;
153#endif
150 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv; 154 struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
151 struct rc_pid_rateinfo *rinfo = pinfo->rinfo; 155 struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
152 struct ieee80211_hw_mode *mode; 156 struct ieee80211_supported_band *sband;
153 u32 pf; 157 u32 pf;
154 s32 err_avg; 158 s32 err_avg;
155 u32 err_prop; 159 u32 err_prop;
@@ -158,7 +162,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
158 int adj, i, j, tmp; 162 int adj, i, j, tmp;
159 unsigned long period; 163 unsigned long period;
160 164
161 mode = local->oper_hw_mode; 165 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
162 spinfo = sta->rate_ctrl_priv; 166 spinfo = sta->rate_ctrl_priv;
163 167
164 /* In case nothing happened during the previous control interval, turn 168 /* In case nothing happened during the previous control interval, turn
@@ -177,25 +181,32 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
177 pf = spinfo->last_pf; 181 pf = spinfo->last_pf;
178 else { 182 else {
179 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit; 183 pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
184#ifdef CONFIG_MAC80211_MESH
185 if (pf == 100 &&
186 sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
187 mesh_plink_broken(sta);
188#endif
180 pf <<= RC_PID_ARITH_SHIFT; 189 pf <<= RC_PID_ARITH_SHIFT;
190 sta->fail_avg = ((pf + (spinfo->last_pf << 3)) / 9)
191 >> RC_PID_ARITH_SHIFT;
181 } 192 }
182 193
183 spinfo->tx_num_xmit = 0; 194 spinfo->tx_num_xmit = 0;
184 spinfo->tx_num_failed = 0; 195 spinfo->tx_num_failed = 0;
185 196
186 /* If we just switched rate, update the rate behaviour info. */ 197 /* If we just switched rate, update the rate behaviour info. */
187 if (pinfo->oldrate != sta->txrate) { 198 if (pinfo->oldrate != sta->txrate_idx) {
188 199
189 i = rinfo[pinfo->oldrate].rev_index; 200 i = rinfo[pinfo->oldrate].rev_index;
190 j = rinfo[sta->txrate].rev_index; 201 j = rinfo[sta->txrate_idx].rev_index;
191 202
192 tmp = (pf - spinfo->last_pf); 203 tmp = (pf - spinfo->last_pf);
193 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT); 204 tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
194 205
195 rinfo[j].diff = rinfo[i].diff + tmp; 206 rinfo[j].diff = rinfo[i].diff + tmp;
196 pinfo->oldrate = sta->txrate; 207 pinfo->oldrate = sta->txrate_idx;
197 } 208 }
198 rate_control_pid_normalize(pinfo, mode->num_rates); 209 rate_control_pid_normalize(pinfo, sband->n_bitrates);
199 210
200 /* Compute the proportional, integral and derivative errors. */ 211 /* Compute the proportional, integral and derivative errors. */
201 err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf; 212 err_prop = (pinfo->target << RC_PID_ARITH_SHIFT) - pf;
@@ -236,23 +247,27 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
236 struct sta_info *sta; 247 struct sta_info *sta;
237 struct rc_pid_sta_info *spinfo; 248 struct rc_pid_sta_info *spinfo;
238 unsigned long period; 249 unsigned long period;
250 struct ieee80211_supported_band *sband;
251
252 rcu_read_lock();
239 253
240 sta = sta_info_get(local, hdr->addr1); 254 sta = sta_info_get(local, hdr->addr1);
255 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
241 256
242 if (!sta) 257 if (!sta)
243 return; 258 goto unlock;
244 259
245 /* Don't update the state if we're not controlling the rate. */ 260 /* Don't update the state if we're not controlling the rate. */
246 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 261 sdata = sta->sdata;
247 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) { 262 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
248 sta->txrate = sdata->bss->max_ratectrl_rateidx; 263 sta->txrate_idx = sdata->bss->max_ratectrl_rateidx;
249 return; 264 goto unlock;
250 } 265 }
251 266
252 /* Ignore all frames that were sent with a different rate than the rate 267 /* Ignore all frames that were sent with a different rate than the rate
253 * we currently advise mac80211 to use. */ 268 * we currently advise mac80211 to use. */
254 if (status->control.rate != &local->oper_hw_mode->rates[sta->txrate]) 269 if (status->control.tx_rate != &sband->bitrates[sta->txrate_idx])
255 goto ignore; 270 goto unlock;
256 271
257 spinfo = sta->rate_ctrl_priv; 272 spinfo = sta->rate_ctrl_priv;
258 spinfo->tx_num_xmit++; 273 spinfo->tx_num_xmit++;
@@ -277,9 +292,6 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
277 sta->tx_num_consecutive_failures++; 292 sta->tx_num_consecutive_failures++;
278 sta->tx_num_mpdu_fail++; 293 sta->tx_num_mpdu_fail++;
279 } else { 294 } else {
280 sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
281 sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
282 sta->last_ack_rssi[2] = status->ack_signal;
283 sta->tx_num_consecutive_failures = 0; 295 sta->tx_num_consecutive_failures = 0;
284 sta->tx_num_mpdu_ok++; 296 sta->tx_num_mpdu_ok++;
285 } 297 }
@@ -293,12 +305,12 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
293 if (time_after(jiffies, spinfo->last_sample + period)) 305 if (time_after(jiffies, spinfo->last_sample + period))
294 rate_control_pid_sample(pinfo, local, sta); 306 rate_control_pid_sample(pinfo, local, sta);
295 307
296ignore: 308 unlock:
297 sta_info_put(sta); 309 rcu_read_unlock();
298} 310}
299 311
300static void rate_control_pid_get_rate(void *priv, struct net_device *dev, 312static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
301 struct ieee80211_hw_mode *mode, 313 struct ieee80211_supported_band *sband,
302 struct sk_buff *skb, 314 struct sk_buff *skb,
303 struct rate_selection *sel) 315 struct rate_selection *sel)
304{ 316{
@@ -309,6 +321,8 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
309 int rateidx; 321 int rateidx;
310 u16 fc; 322 u16 fc;
311 323
324 rcu_read_lock();
325
312 sta = sta_info_get(local, hdr->addr1); 326 sta = sta_info_get(local, hdr->addr1);
313 327
314 /* Send management frames and broadcast/multicast data using lowest 328 /* Send management frames and broadcast/multicast data using lowest
@@ -316,32 +330,31 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
316 fc = le16_to_cpu(hdr->frame_control); 330 fc = le16_to_cpu(hdr->frame_control);
317 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA || 331 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
318 is_multicast_ether_addr(hdr->addr1) || !sta) { 332 is_multicast_ether_addr(hdr->addr1) || !sta) {
319 sel->rate = rate_lowest(local, mode, sta); 333 sel->rate = rate_lowest(local, sband, sta);
320 if (sta) 334 rcu_read_unlock();
321 sta_info_put(sta);
322 return; 335 return;
323 } 336 }
324 337
325 /* If a forced rate is in effect, select it. */ 338 /* If a forced rate is in effect, select it. */
326 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 339 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
327 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) 340 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
328 sta->txrate = sdata->bss->force_unicast_rateidx; 341 sta->txrate_idx = sdata->bss->force_unicast_rateidx;
329 342
330 rateidx = sta->txrate; 343 rateidx = sta->txrate_idx;
331 344
332 if (rateidx >= mode->num_rates) 345 if (rateidx >= sband->n_bitrates)
333 rateidx = mode->num_rates - 1; 346 rateidx = sband->n_bitrates - 1;
334 347
335 sta->last_txrate = rateidx; 348 sta->last_txrate_idx = rateidx;
336 349
337 sta_info_put(sta); 350 rcu_read_unlock();
338 351
339 sel->rate = &mode->rates[rateidx]; 352 sel->rate = &sband->bitrates[rateidx];
340 353
341#ifdef CONFIG_MAC80211_DEBUGFS 354#ifdef CONFIG_MAC80211_DEBUGFS
342 rate_control_pid_event_tx_rate( 355 rate_control_pid_event_tx_rate(
343 &((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events, 356 &((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events,
344 rateidx, mode->rates[rateidx].rate); 357 rateidx, sband->bitrates[rateidx].bitrate);
345#endif 358#endif
346} 359}
347 360
@@ -353,28 +366,33 @@ static void rate_control_pid_rate_init(void *priv, void *priv_sta,
353 * as we need to have IEEE 802.1X auth succeed immediately after assoc.. 366 * as we need to have IEEE 802.1X auth succeed immediately after assoc..
354 * Until that method is implemented, we will use the lowest supported 367 * Until that method is implemented, we will use the lowest supported
355 * rate as a workaround. */ 368 * rate as a workaround. */
356 sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta); 369 struct ieee80211_supported_band *sband;
370
371 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
372 sta->txrate_idx = rate_lowest_index(local, sband, sta);
373 sta->fail_avg = 0;
357} 374}
358 375
359static void *rate_control_pid_alloc(struct ieee80211_local *local) 376static void *rate_control_pid_alloc(struct ieee80211_local *local)
360{ 377{
361 struct rc_pid_info *pinfo; 378 struct rc_pid_info *pinfo;
362 struct rc_pid_rateinfo *rinfo; 379 struct rc_pid_rateinfo *rinfo;
363 struct ieee80211_hw_mode *mode; 380 struct ieee80211_supported_band *sband;
364 int i, j, tmp; 381 int i, j, tmp;
365 bool s; 382 bool s;
366#ifdef CONFIG_MAC80211_DEBUGFS 383#ifdef CONFIG_MAC80211_DEBUGFS
367 struct rc_pid_debugfs_entries *de; 384 struct rc_pid_debugfs_entries *de;
368#endif 385#endif
369 386
387 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
388
370 pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC); 389 pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
371 if (!pinfo) 390 if (!pinfo)
372 return NULL; 391 return NULL;
373 392
374 /* We can safely assume that oper_hw_mode won't change unless we get 393 /* We can safely assume that sband won't change unless we get
375 * reinitialized. */ 394 * reinitialized. */
376 mode = local->oper_hw_mode; 395 rinfo = kmalloc(sizeof(*rinfo) * sband->n_bitrates, GFP_ATOMIC);
377 rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
378 if (!rinfo) { 396 if (!rinfo) {
379 kfree(pinfo); 397 kfree(pinfo);
380 return NULL; 398 return NULL;
@@ -383,7 +401,7 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
383 /* Sort the rates. This is optimized for the most common case (i.e. 401 /* Sort the rates. This is optimized for the most common case (i.e.
384 * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed 402 * almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
385 * mapping too. */ 403 * mapping too. */
386 for (i = 0; i < mode->num_rates; i++) { 404 for (i = 0; i < sband->n_bitrates; i++) {
387 rinfo[i].index = i; 405 rinfo[i].index = i;
388 rinfo[i].rev_index = i; 406 rinfo[i].rev_index = i;
389 if (pinfo->fast_start) 407 if (pinfo->fast_start)
@@ -391,11 +409,11 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
391 else 409 else
392 rinfo[i].diff = i * pinfo->norm_offset; 410 rinfo[i].diff = i * pinfo->norm_offset;
393 } 411 }
394 for (i = 1; i < mode->num_rates; i++) { 412 for (i = 1; i < sband->n_bitrates; i++) {
395 s = 0; 413 s = 0;
396 for (j = 0; j < mode->num_rates - i; j++) 414 for (j = 0; j < sband->n_bitrates - i; j++)
397 if (unlikely(mode->rates[rinfo[j].index].rate > 415 if (unlikely(sband->bitrates[rinfo[j].index].bitrate >
398 mode->rates[rinfo[j + 1].index].rate)) { 416 sband->bitrates[rinfo[j + 1].index].bitrate)) {
399 tmp = rinfo[j].index; 417 tmp = rinfo[j].index;
400 rinfo[j].index = rinfo[j + 1].index; 418 rinfo[j].index = rinfo[j + 1].index;
401 rinfo[j + 1].index = tmp; 419 rinfo[j + 1].index = tmp;
diff --git a/net/mac80211/rc80211_simple.c b/net/mac80211/rc80211_simple.c
deleted file mode 100644
index 9a78b116acff..000000000000
--- a/net/mac80211/rc80211_simple.c
+++ /dev/null
@@ -1,400 +0,0 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/init.h>
11#include <linux/netdevice.h>
12#include <linux/types.h>
13#include <linux/slab.h>
14#include <linux/skbuff.h>
15#include <linux/compiler.h>
16#include <linux/module.h>
17
18#include <net/mac80211.h>
19#include "ieee80211_i.h"
20#include "ieee80211_rate.h"
21#include "debugfs.h"
22
23
24/* This is a minimal implementation of TX rate controlling that can be used
25 * as the default when no improved mechanisms are available. */
26
27#define RATE_CONTROL_NUM_DOWN 20
28#define RATE_CONTROL_NUM_UP 15
29
30#define RATE_CONTROL_EMERG_DEC 2
31#define RATE_CONTROL_INTERVAL (HZ / 20)
32#define RATE_CONTROL_MIN_TX 10
33
34static void rate_control_rate_inc(struct ieee80211_local *local,
35 struct sta_info *sta)
36{
37 struct ieee80211_sub_if_data *sdata;
38 struct ieee80211_hw_mode *mode;
39 int i = sta->txrate;
40 int maxrate;
41
42 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
43 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
44 /* forced unicast rate - do not change STA rate */
45 return;
46 }
47
48 mode = local->oper_hw_mode;
49 maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
50
51 if (i > mode->num_rates)
52 i = mode->num_rates - 2;
53
54 while (i + 1 < mode->num_rates) {
55 i++;
56 if (sta->supp_rates & BIT(i) &&
57 mode->rates[i].flags & IEEE80211_RATE_SUPPORTED &&
58 (maxrate < 0 || i <= maxrate)) {
59 sta->txrate = i;
60 break;
61 }
62 }
63}
64
65
66static void rate_control_rate_dec(struct ieee80211_local *local,
67 struct sta_info *sta)
68{
69 struct ieee80211_sub_if_data *sdata;
70 struct ieee80211_hw_mode *mode;
71 int i = sta->txrate;
72
73 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
74 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
75 /* forced unicast rate - do not change STA rate */
76 return;
77 }
78
79 mode = local->oper_hw_mode;
80 if (i > mode->num_rates)
81 i = mode->num_rates;
82
83 while (i > 0) {
84 i--;
85 if (sta->supp_rates & BIT(i) &&
86 mode->rates[i].flags & IEEE80211_RATE_SUPPORTED) {
87 sta->txrate = i;
88 break;
89 }
90 }
91}
92
93struct global_rate_control {
94 int dummy;
95};
96
97struct sta_rate_control {
98 unsigned long last_rate_change;
99 u32 tx_num_failures;
100 u32 tx_num_xmit;
101
102 unsigned long avg_rate_update;
103 u32 tx_avg_rate_sum;
104 u32 tx_avg_rate_num;
105
106#ifdef CONFIG_MAC80211_DEBUGFS
107 struct dentry *tx_avg_rate_sum_dentry;
108 struct dentry *tx_avg_rate_num_dentry;
109#endif
110};
111
112
113static void rate_control_simple_tx_status(void *priv, struct net_device *dev,
114 struct sk_buff *skb,
115 struct ieee80211_tx_status *status)
116{
117 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
118 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
119 struct sta_info *sta;
120 struct sta_rate_control *srctrl;
121
122 sta = sta_info_get(local, hdr->addr1);
123
124 if (!sta)
125 return;
126
127 srctrl = sta->rate_ctrl_priv;
128 srctrl->tx_num_xmit++;
129 if (status->excessive_retries) {
130 srctrl->tx_num_failures++;
131 sta->tx_retry_failed++;
132 sta->tx_num_consecutive_failures++;
133 sta->tx_num_mpdu_fail++;
134 } else {
135 sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
136 sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
137 sta->last_ack_rssi[2] = status->ack_signal;
138 sta->tx_num_consecutive_failures = 0;
139 sta->tx_num_mpdu_ok++;
140 }
141 sta->tx_retry_count += status->retry_count;
142 sta->tx_num_mpdu_fail += status->retry_count;
143
144 if (time_after(jiffies,
145 srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
146 srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
147 u32 per_failed;
148 srctrl->last_rate_change = jiffies;
149
150 per_failed = (100 * sta->tx_num_mpdu_fail) /
151 (sta->tx_num_mpdu_fail + sta->tx_num_mpdu_ok);
152 /* TODO: calculate average per_failed to make adjusting
153 * parameters easier */
154#if 0
155 if (net_ratelimit()) {
156 printk(KERN_DEBUG "MPDU fail=%d ok=%d per_failed=%d\n",
157 sta->tx_num_mpdu_fail, sta->tx_num_mpdu_ok,
158 per_failed);
159 }
160#endif
161
162 /*
163 * XXX: Make these configurable once we have an
164 * interface to the rate control algorithms
165 */
166 if (per_failed > RATE_CONTROL_NUM_DOWN) {
167 rate_control_rate_dec(local, sta);
168 } else if (per_failed < RATE_CONTROL_NUM_UP) {
169 rate_control_rate_inc(local, sta);
170 }
171 srctrl->tx_avg_rate_sum += status->control.rate->rate;
172 srctrl->tx_avg_rate_num++;
173 srctrl->tx_num_failures = 0;
174 srctrl->tx_num_xmit = 0;
175 } else if (sta->tx_num_consecutive_failures >=
176 RATE_CONTROL_EMERG_DEC) {
177 rate_control_rate_dec(local, sta);
178 }
179
180 if (srctrl->avg_rate_update + 60 * HZ < jiffies) {
181 srctrl->avg_rate_update = jiffies;
182 if (srctrl->tx_avg_rate_num > 0) {
183#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
184 DECLARE_MAC_BUF(mac);
185 printk(KERN_DEBUG "%s: STA %s Average rate: "
186 "%d (%d/%d)\n",
187 dev->name, print_mac(mac, sta->addr),
188 srctrl->tx_avg_rate_sum /
189 srctrl->tx_avg_rate_num,
190 srctrl->tx_avg_rate_sum,
191 srctrl->tx_avg_rate_num);
192#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
193 srctrl->tx_avg_rate_sum = 0;
194 srctrl->tx_avg_rate_num = 0;
195 }
196 }
197
198 sta_info_put(sta);
199}
200
201
202static void
203rate_control_simple_get_rate(void *priv, struct net_device *dev,
204 struct ieee80211_hw_mode *mode,
205 struct sk_buff *skb,
206 struct rate_selection *sel)
207{
208 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
209 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
210 struct ieee80211_sub_if_data *sdata;
211 struct sta_info *sta;
212 int rateidx;
213 u16 fc;
214
215 sta = sta_info_get(local, hdr->addr1);
216
217 /* Send management frames and broadcast/multicast data using lowest
218 * rate. */
219 fc = le16_to_cpu(hdr->frame_control);
220 if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
221 is_multicast_ether_addr(hdr->addr1) || !sta) {
222 sel->rate = rate_lowest(local, mode, sta);
223 if (sta)
224 sta_info_put(sta);
225 return;
226 }
227
228 /* If a forced rate is in effect, select it. */
229 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
230 if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
231 sta->txrate = sdata->bss->force_unicast_rateidx;
232
233 rateidx = sta->txrate;
234
235 if (rateidx >= mode->num_rates)
236 rateidx = mode->num_rates - 1;
237
238 sta->last_txrate = rateidx;
239
240 sta_info_put(sta);
241
242 sel->rate = &mode->rates[rateidx];
243}
244
245
246static void rate_control_simple_rate_init(void *priv, void *priv_sta,
247 struct ieee80211_local *local,
248 struct sta_info *sta)
249{
250 struct ieee80211_hw_mode *mode;
251 int i;
252 sta->txrate = 0;
253 mode = local->oper_hw_mode;
254 /* TODO: This routine should consider using RSSI from previous packets
255 * as we need to have IEEE 802.1X auth succeed immediately after assoc..
256 * Until that method is implemented, we will use the lowest supported rate
257 * as a workaround, */
258 for (i = 0; i < mode->num_rates; i++) {
259 if ((sta->supp_rates & BIT(i)) &&
260 (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) {
261 sta->txrate = i;
262 break;
263 }
264 }
265}
266
267
268static void * rate_control_simple_alloc(struct ieee80211_local *local)
269{
270 struct global_rate_control *rctrl;
271
272 rctrl = kzalloc(sizeof(*rctrl), GFP_ATOMIC);
273
274 return rctrl;
275}
276
277
278static void rate_control_simple_free(void *priv)
279{
280 struct global_rate_control *rctrl = priv;
281 kfree(rctrl);
282}
283
284
285static void rate_control_simple_clear(void *priv)
286{
287}
288
289
290static void * rate_control_simple_alloc_sta(void *priv, gfp_t gfp)
291{
292 struct sta_rate_control *rctrl;
293
294 rctrl = kzalloc(sizeof(*rctrl), gfp);
295
296 return rctrl;
297}
298
299
300static void rate_control_simple_free_sta(void *priv, void *priv_sta)
301{
302 struct sta_rate_control *rctrl = priv_sta;
303 kfree(rctrl);
304}
305
306#ifdef CONFIG_MAC80211_DEBUGFS
307
308static int open_file_generic(struct inode *inode, struct file *file)
309{
310 file->private_data = inode->i_private;
311 return 0;
312}
313
314static ssize_t sta_tx_avg_rate_sum_read(struct file *file,
315 char __user *userbuf,
316 size_t count, loff_t *ppos)
317{
318 struct sta_rate_control *srctrl = file->private_data;
319 char buf[20];
320
321 sprintf(buf, "%d\n", srctrl->tx_avg_rate_sum);
322 return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
323}
324
325static const struct file_operations sta_tx_avg_rate_sum_ops = {
326 .read = sta_tx_avg_rate_sum_read,
327 .open = open_file_generic,
328};
329
330static ssize_t sta_tx_avg_rate_num_read(struct file *file,
331 char __user *userbuf,
332 size_t count, loff_t *ppos)
333{
334 struct sta_rate_control *srctrl = file->private_data;
335 char buf[20];
336
337 sprintf(buf, "%d\n", srctrl->tx_avg_rate_num);
338 return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
339}
340
341static const struct file_operations sta_tx_avg_rate_num_ops = {
342 .read = sta_tx_avg_rate_num_read,
343 .open = open_file_generic,
344};
345
346static void rate_control_simple_add_sta_debugfs(void *priv, void *priv_sta,
347 struct dentry *dir)
348{
349 struct sta_rate_control *srctrl = priv_sta;
350
351 srctrl->tx_avg_rate_num_dentry =
352 debugfs_create_file("rc_simple_sta_tx_avg_rate_num", 0400,
353 dir, srctrl, &sta_tx_avg_rate_num_ops);
354 srctrl->tx_avg_rate_sum_dentry =
355 debugfs_create_file("rc_simple_sta_tx_avg_rate_sum", 0400,
356 dir, srctrl, &sta_tx_avg_rate_sum_ops);
357}
358
359static void rate_control_simple_remove_sta_debugfs(void *priv, void *priv_sta)
360{
361 struct sta_rate_control *srctrl = priv_sta;
362
363 debugfs_remove(srctrl->tx_avg_rate_sum_dentry);
364 debugfs_remove(srctrl->tx_avg_rate_num_dentry);
365}
366#endif
367
368static struct rate_control_ops mac80211_rcsimple = {
369 .name = "simple",
370 .tx_status = rate_control_simple_tx_status,
371 .get_rate = rate_control_simple_get_rate,
372 .rate_init = rate_control_simple_rate_init,
373 .clear = rate_control_simple_clear,
374 .alloc = rate_control_simple_alloc,
375 .free = rate_control_simple_free,
376 .alloc_sta = rate_control_simple_alloc_sta,
377 .free_sta = rate_control_simple_free_sta,
378#ifdef CONFIG_MAC80211_DEBUGFS
379 .add_sta_debugfs = rate_control_simple_add_sta_debugfs,
380 .remove_sta_debugfs = rate_control_simple_remove_sta_debugfs,
381#endif
382};
383
384MODULE_LICENSE("GPL");
385MODULE_DESCRIPTION("Simple rate control algorithm");
386
387int __init rc80211_simple_init(void)
388{
389 return ieee80211_rate_control_register(&mac80211_rcsimple);
390}
391
392void rc80211_simple_exit(void)
393{
394 ieee80211_rate_control_unregister(&mac80211_rcsimple);
395}
396
397#ifdef CONFIG_MAC80211_RC_SIMPLE_MODULE
398module_init(rc80211_simple_init);
399module_exit(rc80211_simple_exit);
400#endif
diff --git a/net/mac80211/regdomain.c b/net/mac80211/regdomain.c
deleted file mode 100644
index f42678fa62d1..000000000000
--- a/net/mac80211/regdomain.c
+++ /dev/null
@@ -1,152 +0,0 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10/*
11 * This regulatory domain control implementation is known to be incomplete
12 * and confusing. mac80211 regulatory domain control will be significantly
13 * reworked in the not-too-distant future.
14 *
15 * For now, drivers wishing to control which channels are and aren't available
16 * are advised as follows:
17 * - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
18 * - continue to include *ALL* possible channels in the modes registered
19 * through ieee80211_register_hwmode()
20 * - for each allowable ieee80211_channel structure registered in the above
21 * call, set the flag member to some meaningful value such as
22 * IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
23 * IEEE80211_CHAN_W_IBSS.
24 * - leave flag as 0 for non-allowable channels
25 *
26 * The usual implementation is for a driver to read a device EEPROM to
27 * determine which regulatory domain it should be operating under, then
28 * looking up the allowable channels in a driver-local table, then performing
29 * the above.
30 */
31
32#include <linux/module.h>
33#include <linux/netdevice.h>
34#include <net/mac80211.h>
35#include "ieee80211_i.h"
36
37static int ieee80211_regdom = 0x10; /* FCC */
38module_param(ieee80211_regdom, int, 0444);
39MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
40
41/*
42 * If firmware is upgraded by the vendor, additional channels can be used based
43 * on the new Japanese regulatory rules. This is indicated by setting
44 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
45 * module.
46 */
47static int ieee80211_japan_5ghz /* = 0 */;
48module_param(ieee80211_japan_5ghz, int, 0444);
49MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
50
51
52struct ieee80211_channel_range {
53 short start_freq;
54 short end_freq;
55 unsigned char power_level;
56 unsigned char antenna_max;
57};
58
59static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
60 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
61 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
62 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
63 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
64 { 0 }
65};
66
67static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
68 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
69 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
70 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
71 { 0 }
72};
73
74
75static const struct ieee80211_channel_range *channel_range =
76 ieee80211_fcc_channels;
77
78
79static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
80{
81 int i;
82
83 chan->flag = 0;
84
85 for (i = 0; channel_range[i].start_freq; i++) {
86 const struct ieee80211_channel_range *r = &channel_range[i];
87 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
88 if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
89 chan->freq >= 5260 && chan->freq <= 5320) {
90 /*
91 * Skip new channels in Japan since the
92 * firmware was not marked having been upgraded
93 * by the vendor.
94 */
95 continue;
96 }
97
98 if (ieee80211_regdom == 0x10 &&
99 (chan->freq == 5190 || chan->freq == 5210 ||
100 chan->freq == 5230)) {
101 /* Skip MKK channels when in FCC domain. */
102 continue;
103 }
104
105 chan->flag |= IEEE80211_CHAN_W_SCAN |
106 IEEE80211_CHAN_W_ACTIVE_SCAN |
107 IEEE80211_CHAN_W_IBSS;
108 chan->power_level = r->power_level;
109 chan->antenna_max = r->antenna_max;
110
111 if (ieee80211_regdom == 64 &&
112 (chan->freq == 5170 || chan->freq == 5190 ||
113 chan->freq == 5210 || chan->freq == 5230)) {
114 /*
115 * New regulatory rules in Japan have backwards
116 * compatibility with old channels in 5.15-5.25
117 * GHz band, but the station is not allowed to
118 * use active scan on these old channels.
119 */
120 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
121 }
122
123 if (ieee80211_regdom == 64 &&
124 (chan->freq == 5260 || chan->freq == 5280 ||
125 chan->freq == 5300 || chan->freq == 5320)) {
126 /*
127 * IBSS is not allowed on 5.25-5.35 GHz band
128 * due to radar detection requirements.
129 */
130 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
131 }
132
133 break;
134 }
135 }
136}
137
138
139void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
140{
141 int c;
142 for (c = 0; c < mode->num_channels; c++)
143 ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
144}
145
146
147void ieee80211_regdomain_init(void)
148{
149 if (ieee80211_regdom == 0x40)
150 channel_range = ieee80211_mkk_channels;
151}
152
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 535407d07fa4..644d2774469d 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -9,6 +9,7 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/jiffies.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/skbuff.h> 14#include <linux/skbuff.h>
14#include <linux/netdevice.h> 15#include <linux/netdevice.h>
@@ -19,6 +20,7 @@
19 20
20#include "ieee80211_i.h" 21#include "ieee80211_i.h"
21#include "ieee80211_led.h" 22#include "ieee80211_led.h"
23#include "mesh.h"
22#include "wep.h" 24#include "wep.h"
23#include "wpa.h" 25#include "wpa.h"
24#include "tkip.h" 26#include "tkip.h"
@@ -82,10 +84,10 @@ static inline int should_drop_frame(struct ieee80211_rx_status *status,
82 */ 84 */
83static struct sk_buff * 85static struct sk_buff *
84ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, 86ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
85 struct ieee80211_rx_status *status) 87 struct ieee80211_rx_status *status,
88 struct ieee80211_rate *rate)
86{ 89{
87 struct ieee80211_sub_if_data *sdata; 90 struct ieee80211_sub_if_data *sdata;
88 struct ieee80211_rate *rate;
89 int needed_headroom = 0; 91 int needed_headroom = 0;
90 struct ieee80211_radiotap_header *rthdr; 92 struct ieee80211_radiotap_header *rthdr;
91 __le64 *rttsft = NULL; 93 __le64 *rttsft = NULL;
@@ -194,14 +196,11 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
194 rtfixed->rx_flags |= 196 rtfixed->rx_flags |=
195 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS); 197 cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
196 198
197 rate = ieee80211_get_rate(local, status->phymode, 199 rtfixed->rate = rate->bitrate / 5;
198 status->rate);
199 if (rate)
200 rtfixed->rate = rate->rate / 5;
201 200
202 rtfixed->chan_freq = cpu_to_le16(status->freq); 201 rtfixed->chan_freq = cpu_to_le16(status->freq);
203 202
204 if (status->phymode == MODE_IEEE80211A) 203 if (status->band == IEEE80211_BAND_5GHZ)
205 rtfixed->chan_flags = 204 rtfixed->chan_flags =
206 cpu_to_le16(IEEE80211_CHAN_OFDM | 205 cpu_to_le16(IEEE80211_CHAN_OFDM |
207 IEEE80211_CHAN_5GHZ); 206 IEEE80211_CHAN_5GHZ);
@@ -226,6 +225,9 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
226 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR) 225 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR)
227 continue; 226 continue;
228 227
228 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
229 continue;
230
229 if (prev_dev) { 231 if (prev_dev) {
230 skb2 = skb_clone(skb, GFP_ATOMIC); 232 skb2 = skb_clone(skb, GFP_ATOMIC);
231 if (skb2) { 233 if (skb2) {
@@ -249,15 +251,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
249} 251}
250 252
251 253
252/* pre-rx handlers 254static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
253 *
254 * these don't have dev/sdata fields in the rx data
255 * The sta value should also not be used because it may
256 * be NULL even though a STA (in IBSS mode) will be added.
257 */
258
259static ieee80211_txrx_result
260ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
261{ 255{
262 u8 *data = rx->skb->data; 256 u8 *data = rx->skb->data;
263 int tid; 257 int tid;
@@ -268,9 +262,9 @@ ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
268 /* frame has qos control */ 262 /* frame has qos control */
269 tid = qc[0] & QOS_CONTROL_TID_MASK; 263 tid = qc[0] & QOS_CONTROL_TID_MASK;
270 if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT) 264 if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
271 rx->flags |= IEEE80211_TXRXD_RX_AMSDU; 265 rx->flags |= IEEE80211_RX_AMSDU;
272 else 266 else
273 rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU; 267 rx->flags &= ~IEEE80211_RX_AMSDU;
274 } else { 268 } else {
275 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) { 269 if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
276 /* Separate TID for management frames */ 270 /* Separate TID for management frames */
@@ -286,68 +280,19 @@ ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
286 if (rx->sta) 280 if (rx->sta)
287 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]); 281 I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
288 282
289 rx->u.rx.queue = tid; 283 rx->queue = tid;
290 /* Set skb->priority to 1d tag if highest order bit of TID is not set. 284 /* Set skb->priority to 1d tag if highest order bit of TID is not set.
291 * For now, set skb->priority to 0 for other cases. */ 285 * For now, set skb->priority to 0 for other cases. */
292 rx->skb->priority = (tid > 7) ? 0 : tid; 286 rx->skb->priority = (tid > 7) ? 0 : tid;
293
294 return TXRX_CONTINUE;
295} 287}
296 288
297 289static void ieee80211_verify_ip_alignment(struct ieee80211_rx_data *rx)
298static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
299 struct sk_buff *skb,
300 struct ieee80211_rx_status *status)
301{ 290{
302 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
303 u32 load = 0, hdrtime;
304 struct ieee80211_rate *rate;
305 struct ieee80211_hw_mode *mode = local->hw.conf.mode;
306 int i;
307
308 /* Estimate total channel use caused by this frame */
309
310 if (unlikely(mode->num_rates < 0))
311 return TXRX_CONTINUE;
312
313 rate = &mode->rates[0];
314 for (i = 0; i < mode->num_rates; i++) {
315 if (mode->rates[i].val == status->rate) {
316 rate = &mode->rates[i];
317 break;
318 }
319 }
320
321 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
322 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
323
324 if (mode->mode == MODE_IEEE80211A ||
325 (mode->mode == MODE_IEEE80211G &&
326 rate->flags & IEEE80211_RATE_ERP))
327 hdrtime = CHAN_UTIL_HDR_SHORT;
328 else
329 hdrtime = CHAN_UTIL_HDR_LONG;
330
331 load = hdrtime;
332 if (!is_multicast_ether_addr(hdr->addr1))
333 load += hdrtime;
334
335 load += skb->len * rate->rate_inv;
336
337 /* Divide channel_use by 8 to avoid wrapping around the counter */
338 load >>= CHAN_UTIL_SHIFT;
339
340 return load;
341}
342
343#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT 291#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
344static ieee80211_txrx_result
345ieee80211_rx_h_verify_ip_alignment(struct ieee80211_txrx_data *rx)
346{
347 int hdrlen; 292 int hdrlen;
348 293
349 if (!WLAN_FC_DATA_PRESENT(rx->fc)) 294 if (!WLAN_FC_DATA_PRESENT(rx->fc))
350 return TXRX_CONTINUE; 295 return;
351 296
352 /* 297 /*
353 * Drivers are required to align the payload data in a way that 298 * Drivers are required to align the payload data in a way that
@@ -369,83 +314,158 @@ ieee80211_rx_h_verify_ip_alignment(struct ieee80211_txrx_data *rx)
369 * to move the 802.11 header further back in that case. 314 * to move the 802.11 header further back in that case.
370 */ 315 */
371 hdrlen = ieee80211_get_hdrlen(rx->fc); 316 hdrlen = ieee80211_get_hdrlen(rx->fc);
372 if (rx->flags & IEEE80211_TXRXD_RX_AMSDU) 317 if (rx->flags & IEEE80211_RX_AMSDU)
373 hdrlen += ETH_HLEN; 318 hdrlen += ETH_HLEN;
374 WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3); 319 WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3);
375
376 return TXRX_CONTINUE;
377}
378#endif 320#endif
321}
379 322
380ieee80211_rx_handler ieee80211_rx_pre_handlers[] = 323
324static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
325 struct sk_buff *skb,
326 struct ieee80211_rx_status *status,
327 struct ieee80211_rate *rate)
381{ 328{
382 ieee80211_rx_h_parse_qos, 329 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
383#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT 330 u32 load = 0, hdrtime;
384 ieee80211_rx_h_verify_ip_alignment, 331
385#endif 332 /* Estimate total channel use caused by this frame */
386 NULL 333
387}; 334 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
335 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
336
337 if (status->band == IEEE80211_BAND_5GHZ ||
338 (status->band == IEEE80211_BAND_5GHZ &&
339 rate->flags & IEEE80211_RATE_ERP_G))
340 hdrtime = CHAN_UTIL_HDR_SHORT;
341 else
342 hdrtime = CHAN_UTIL_HDR_LONG;
343
344 load = hdrtime;
345 if (!is_multicast_ether_addr(hdr->addr1))
346 load += hdrtime;
347
348 /* TODO: optimise again */
349 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
350
351 /* Divide channel_use by 8 to avoid wrapping around the counter */
352 load >>= CHAN_UTIL_SHIFT;
353
354 return load;
355}
388 356
389/* rx handlers */ 357/* rx handlers */
390 358
391static ieee80211_txrx_result 359static ieee80211_rx_result
392ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx) 360ieee80211_rx_h_if_stats(struct ieee80211_rx_data *rx)
393{ 361{
394 if (rx->sta) 362 if (rx->sta)
395 rx->sta->channel_use_raw += rx->u.rx.load; 363 rx->sta->channel_use_raw += rx->load;
396 rx->sdata->channel_use_raw += rx->u.rx.load; 364 rx->sdata->channel_use_raw += rx->load;
397 return TXRX_CONTINUE; 365 return RX_CONTINUE;
398} 366}
399 367
400static ieee80211_txrx_result 368static ieee80211_rx_result
401ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx) 369ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
402{ 370{
403 struct ieee80211_local *local = rx->local; 371 struct ieee80211_local *local = rx->local;
404 struct sk_buff *skb = rx->skb; 372 struct sk_buff *skb = rx->skb;
405 373
406 if (unlikely(local->sta_hw_scanning)) 374 if (unlikely(local->sta_hw_scanning))
407 return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status); 375 return ieee80211_sta_rx_scan(rx->dev, skb, rx->status);
408 376
409 if (unlikely(local->sta_sw_scanning)) { 377 if (unlikely(local->sta_sw_scanning)) {
410 /* drop all the other packets during a software scan anyway */ 378 /* drop all the other packets during a software scan anyway */
411 if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status) 379 if (ieee80211_sta_rx_scan(rx->dev, skb, rx->status)
412 != TXRX_QUEUED) 380 != RX_QUEUED)
413 dev_kfree_skb(skb); 381 dev_kfree_skb(skb);
414 return TXRX_QUEUED; 382 return RX_QUEUED;
415 } 383 }
416 384
417 if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) { 385 if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) {
418 /* scanning finished during invoking of handlers */ 386 /* scanning finished during invoking of handlers */
419 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan); 387 I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
420 return TXRX_DROP; 388 return RX_DROP_UNUSABLE;
421 } 389 }
422 390
423 return TXRX_CONTINUE; 391 return RX_CONTINUE;
392}
393
394static ieee80211_rx_result
395ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
396{
397 int hdrlen = ieee80211_get_hdrlen(rx->fc);
398 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
399
400#define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
401
402 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
403 if (!((rx->fc & IEEE80211_FCTL_FROMDS) &&
404 (rx->fc & IEEE80211_FCTL_TODS)))
405 return RX_DROP_MONITOR;
406 if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0)
407 return RX_DROP_MONITOR;
408 }
409
410 /* If there is not an established peer link and this is not a peer link
411 * establisment frame, beacon or probe, drop the frame.
412 */
413
414 if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
415 struct ieee80211_mgmt *mgmt;
416
417 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
418 return RX_DROP_MONITOR;
419
420 switch (rx->fc & IEEE80211_FCTL_STYPE) {
421 case IEEE80211_STYPE_ACTION:
422 mgmt = (struct ieee80211_mgmt *)hdr;
423 if (mgmt->u.action.category != PLINK_CATEGORY)
424 return RX_DROP_MONITOR;
425 /* fall through on else */
426 case IEEE80211_STYPE_PROBE_REQ:
427 case IEEE80211_STYPE_PROBE_RESP:
428 case IEEE80211_STYPE_BEACON:
429 return RX_CONTINUE;
430 break;
431 default:
432 return RX_DROP_MONITOR;
433 }
434
435 } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
436 is_broadcast_ether_addr(hdr->addr1) &&
437 mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev))
438 return RX_DROP_MONITOR;
439#undef msh_h_get
440
441 return RX_CONTINUE;
424} 442}
425 443
426static ieee80211_txrx_result 444
427ieee80211_rx_h_check(struct ieee80211_txrx_data *rx) 445static ieee80211_rx_result
446ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
428{ 447{
429 struct ieee80211_hdr *hdr; 448 struct ieee80211_hdr *hdr;
449
430 hdr = (struct ieee80211_hdr *) rx->skb->data; 450 hdr = (struct ieee80211_hdr *) rx->skb->data;
431 451
432 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ 452 /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
433 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { 453 if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
434 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY && 454 if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
435 rx->sta->last_seq_ctrl[rx->u.rx.queue] == 455 rx->sta->last_seq_ctrl[rx->queue] ==
436 hdr->seq_ctrl)) { 456 hdr->seq_ctrl)) {
437 if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) { 457 if (rx->flags & IEEE80211_RX_RA_MATCH) {
438 rx->local->dot11FrameDuplicateCount++; 458 rx->local->dot11FrameDuplicateCount++;
439 rx->sta->num_duplicates++; 459 rx->sta->num_duplicates++;
440 } 460 }
441 return TXRX_DROP; 461 return RX_DROP_MONITOR;
442 } else 462 } else
443 rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl; 463 rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
444 } 464 }
445 465
446 if (unlikely(rx->skb->len < 16)) { 466 if (unlikely(rx->skb->len < 16)) {
447 I802_DEBUG_INC(rx->local->rx_handlers_drop_short); 467 I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
448 return TXRX_DROP; 468 return RX_DROP_MONITOR;
449 } 469 }
450 470
451 /* Drop disallowed frame classes based on STA auth/assoc state; 471 /* Drop disallowed frame classes based on STA auth/assoc state;
@@ -456,6 +476,10 @@ ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
456 * deauth/disassoc frames when needed. In addition, hostapd is 476 * deauth/disassoc frames when needed. In addition, hostapd is
457 * responsible for filtering on both auth and assoc states. 477 * responsible for filtering on both auth and assoc states.
458 */ 478 */
479
480 if (ieee80211_vif_is_mesh(&rx->sdata->vif))
481 return ieee80211_rx_mesh_check(rx);
482
459 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA || 483 if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
460 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL && 484 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
461 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) && 485 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
@@ -464,26 +488,26 @@ ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
464 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) && 488 if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
465 !(rx->fc & IEEE80211_FCTL_TODS) && 489 !(rx->fc & IEEE80211_FCTL_TODS) &&
466 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) 490 (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
467 || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { 491 || !(rx->flags & IEEE80211_RX_RA_MATCH)) {
468 /* Drop IBSS frames and frames for other hosts 492 /* Drop IBSS frames and frames for other hosts
469 * silently. */ 493 * silently. */
470 return TXRX_DROP; 494 return RX_DROP_MONITOR;
471 } 495 }
472 496
473 return TXRX_DROP; 497 return RX_DROP_MONITOR;
474 } 498 }
475 499
476 return TXRX_CONTINUE; 500 return RX_CONTINUE;
477} 501}
478 502
479 503
480static ieee80211_txrx_result 504static ieee80211_rx_result
481ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx) 505ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
482{ 506{
483 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; 507 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
484 int keyidx; 508 int keyidx;
485 int hdrlen; 509 int hdrlen;
486 ieee80211_txrx_result result = TXRX_DROP; 510 ieee80211_rx_result result = RX_DROP_UNUSABLE;
487 struct ieee80211_key *stakey = NULL; 511 struct ieee80211_key *stakey = NULL;
488 512
489 /* 513 /*
@@ -513,14 +537,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
513 */ 537 */
514 538
515 if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) 539 if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
516 return TXRX_CONTINUE; 540 return RX_CONTINUE;
517 541
518 /* 542 /*
519 * No point in finding a key and decrypting if the frame is neither 543 * No point in finding a key and decrypting if the frame is neither
520 * addressed to us nor a multicast frame. 544 * addressed to us nor a multicast frame.
521 */ 545 */
522 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) 546 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
523 return TXRX_CONTINUE; 547 return RX_CONTINUE;
524 548
525 if (rx->sta) 549 if (rx->sta)
526 stakey = rcu_dereference(rx->sta->key); 550 stakey = rcu_dereference(rx->sta->key);
@@ -537,14 +561,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
537 * we somehow allow the driver to tell us which key 561 * we somehow allow the driver to tell us which key
538 * the hardware used if this flag is set? 562 * the hardware used if this flag is set?
539 */ 563 */
540 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) && 564 if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
541 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) 565 (rx->status->flag & RX_FLAG_IV_STRIPPED))
542 return TXRX_CONTINUE; 566 return RX_CONTINUE;
543 567
544 hdrlen = ieee80211_get_hdrlen(rx->fc); 568 hdrlen = ieee80211_get_hdrlen(rx->fc);
545 569
546 if (rx->skb->len < 8 + hdrlen) 570 if (rx->skb->len < 8 + hdrlen)
547 return TXRX_DROP; /* TODO: count this? */ 571 return RX_DROP_UNUSABLE; /* TODO: count this? */
548 572
549 /* 573 /*
550 * no need to call ieee80211_wep_get_keyidx, 574 * no need to call ieee80211_wep_get_keyidx,
@@ -573,14 +597,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
573 printk(KERN_DEBUG "%s: RX protected frame," 597 printk(KERN_DEBUG "%s: RX protected frame,"
574 " but have no key\n", rx->dev->name); 598 " but have no key\n", rx->dev->name);
575#endif /* CONFIG_MAC80211_DEBUG */ 599#endif /* CONFIG_MAC80211_DEBUG */
576 return TXRX_DROP; 600 return RX_DROP_MONITOR;
577 } 601 }
578 602
579 /* Check for weak IVs if possible */ 603 /* Check for weak IVs if possible */
580 if (rx->sta && rx->key->conf.alg == ALG_WEP && 604 if (rx->sta && rx->key->conf.alg == ALG_WEP &&
581 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && 605 ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
582 (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) || 606 (!(rx->status->flag & RX_FLAG_IV_STRIPPED) ||
583 !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) && 607 !(rx->status->flag & RX_FLAG_DECRYPTED)) &&
584 ieee80211_wep_is_weak_iv(rx->skb, rx->key)) 608 ieee80211_wep_is_weak_iv(rx->skb, rx->key))
585 rx->sta->wep_weak_iv_count++; 609 rx->sta->wep_weak_iv_count++;
586 610
@@ -597,7 +621,7 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
597 } 621 }
598 622
599 /* either the frame has been decrypted or will be dropped */ 623 /* either the frame has been decrypted or will be dropped */
600 rx->u.rx.status->flag |= RX_FLAG_DECRYPTED; 624 rx->status->flag |= RX_FLAG_DECRYPTED;
601 625
602 return result; 626 return result;
603} 627}
@@ -607,12 +631,12 @@ static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
607 struct ieee80211_sub_if_data *sdata; 631 struct ieee80211_sub_if_data *sdata;
608 DECLARE_MAC_BUF(mac); 632 DECLARE_MAC_BUF(mac);
609 633
610 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 634 sdata = sta->sdata;
611 635
612 if (sdata->bss) 636 if (sdata->bss)
613 atomic_inc(&sdata->bss->num_sta_ps); 637 atomic_inc(&sdata->bss->num_sta_ps);
614 sta->flags |= WLAN_STA_PS; 638 sta->flags |= WLAN_STA_PS;
615 sta->pspoll = 0; 639 sta->flags &= ~WLAN_STA_PSPOLL;
616#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 640#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
617 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n", 641 printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
618 dev->name, print_mac(mac, sta->addr), sta->aid); 642 dev->name, print_mac(mac, sta->addr), sta->aid);
@@ -628,21 +652,21 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
628 struct ieee80211_tx_packet_data *pkt_data; 652 struct ieee80211_tx_packet_data *pkt_data;
629 DECLARE_MAC_BUF(mac); 653 DECLARE_MAC_BUF(mac);
630 654
631 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 655 sdata = sta->sdata;
656
632 if (sdata->bss) 657 if (sdata->bss)
633 atomic_dec(&sdata->bss->num_sta_ps); 658 atomic_dec(&sdata->bss->num_sta_ps);
634 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM); 659
635 sta->pspoll = 0; 660 sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL);
636 if (!skb_queue_empty(&sta->ps_tx_buf)) { 661
637 if (local->ops->set_tim) 662 if (!skb_queue_empty(&sta->ps_tx_buf))
638 local->ops->set_tim(local_to_hw(local), sta->aid, 0); 663 sta_info_clear_tim_bit(sta);
639 if (sdata->bss) 664
640 bss_tim_clear(local, sdata->bss, sta->aid);
641 }
642#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 665#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
643 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n", 666 printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
644 dev->name, print_mac(mac, sta->addr), sta->aid); 667 dev->name, print_mac(mac, sta->addr), sta->aid);
645#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 668#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
669
646 /* Send all buffered frames to the station */ 670 /* Send all buffered frames to the station */
647 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { 671 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
648 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb; 672 pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
@@ -666,15 +690,15 @@ static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
666 return sent; 690 return sent;
667} 691}
668 692
669static ieee80211_txrx_result 693static ieee80211_rx_result
670ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx) 694ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
671{ 695{
672 struct sta_info *sta = rx->sta; 696 struct sta_info *sta = rx->sta;
673 struct net_device *dev = rx->dev; 697 struct net_device *dev = rx->dev;
674 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; 698 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
675 699
676 if (!sta) 700 if (!sta)
677 return TXRX_CONTINUE; 701 return RX_CONTINUE;
678 702
679 /* Update last_rx only for IBSS packets which are for the current 703 /* Update last_rx only for IBSS packets which are for the current
680 * BSSID to avoid keeping the current IBSS network alive in cases where 704 * BSSID to avoid keeping the current IBSS network alive in cases where
@@ -690,24 +714,26 @@ ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
690 /* Update last_rx only for unicast frames in order to prevent 714 /* Update last_rx only for unicast frames in order to prevent
691 * the Probe Request frames (the only broadcast frames from a 715 * the Probe Request frames (the only broadcast frames from a
692 * STA in infrastructure mode) from keeping a connection alive. 716 * STA in infrastructure mode) from keeping a connection alive.
717 * Mesh beacons will update last_rx when if they are found to
718 * match the current local configuration when processed.
693 */ 719 */
694 sta->last_rx = jiffies; 720 sta->last_rx = jiffies;
695 } 721 }
696 722
697 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) 723 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
698 return TXRX_CONTINUE; 724 return RX_CONTINUE;
699 725
700 sta->rx_fragments++; 726 sta->rx_fragments++;
701 sta->rx_bytes += rx->skb->len; 727 sta->rx_bytes += rx->skb->len;
702 sta->last_rssi = rx->u.rx.status->ssi; 728 sta->last_rssi = rx->status->ssi;
703 sta->last_signal = rx->u.rx.status->signal; 729 sta->last_signal = rx->status->signal;
704 sta->last_noise = rx->u.rx.status->noise; 730 sta->last_noise = rx->status->noise;
705 731
706 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) { 732 if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
707 /* Change STA power saving mode only in the end of a frame 733 /* Change STA power saving mode only in the end of a frame
708 * exchange sequence */ 734 * exchange sequence */
709 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM)) 735 if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
710 rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta); 736 rx->sent_ps_buffered += ap_sta_ps_end(dev, sta);
711 else if (!(sta->flags & WLAN_STA_PS) && 737 else if (!(sta->flags & WLAN_STA_PS) &&
712 (rx->fc & IEEE80211_FCTL_PM)) 738 (rx->fc & IEEE80211_FCTL_PM))
713 ap_sta_ps_start(dev, sta); 739 ap_sta_ps_start(dev, sta);
@@ -722,10 +748,10 @@ ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
722 * as a dropped packed. */ 748 * as a dropped packed. */
723 sta->rx_packets++; 749 sta->rx_packets++;
724 dev_kfree_skb(rx->skb); 750 dev_kfree_skb(rx->skb);
725 return TXRX_QUEUED; 751 return RX_QUEUED;
726 } 752 }
727 753
728 return TXRX_CONTINUE; 754 return RX_CONTINUE;
729} /* ieee80211_rx_h_sta_process */ 755} /* ieee80211_rx_h_sta_process */
730 756
731static inline struct ieee80211_fragment_entry * 757static inline struct ieee80211_fragment_entry *
@@ -801,7 +827,7 @@ ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
801 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0) 827 compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
802 continue; 828 continue;
803 829
804 if (entry->first_frag_time + 2 * HZ < jiffies) { 830 if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
805 __skb_queue_purge(&entry->skb_list); 831 __skb_queue_purge(&entry->skb_list);
806 continue; 832 continue;
807 } 833 }
@@ -811,8 +837,8 @@ ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
811 return NULL; 837 return NULL;
812} 838}
813 839
814static ieee80211_txrx_result 840static ieee80211_rx_result
815ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx) 841ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
816{ 842{
817 struct ieee80211_hdr *hdr; 843 struct ieee80211_hdr *hdr;
818 u16 sc; 844 u16 sc;
@@ -838,27 +864,27 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
838 if (frag == 0) { 864 if (frag == 0) {
839 /* This is the first fragment of a new frame. */ 865 /* This is the first fragment of a new frame. */
840 entry = ieee80211_reassemble_add(rx->sdata, frag, seq, 866 entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
841 rx->u.rx.queue, &(rx->skb)); 867 rx->queue, &(rx->skb));
842 if (rx->key && rx->key->conf.alg == ALG_CCMP && 868 if (rx->key && rx->key->conf.alg == ALG_CCMP &&
843 (rx->fc & IEEE80211_FCTL_PROTECTED)) { 869 (rx->fc & IEEE80211_FCTL_PROTECTED)) {
844 /* Store CCMP PN so that we can verify that the next 870 /* Store CCMP PN so that we can verify that the next
845 * fragment has a sequential PN value. */ 871 * fragment has a sequential PN value. */
846 entry->ccmp = 1; 872 entry->ccmp = 1;
847 memcpy(entry->last_pn, 873 memcpy(entry->last_pn,
848 rx->key->u.ccmp.rx_pn[rx->u.rx.queue], 874 rx->key->u.ccmp.rx_pn[rx->queue],
849 CCMP_PN_LEN); 875 CCMP_PN_LEN);
850 } 876 }
851 return TXRX_QUEUED; 877 return RX_QUEUED;
852 } 878 }
853 879
854 /* This is a fragment for a frame that should already be pending in 880 /* This is a fragment for a frame that should already be pending in
855 * fragment cache. Add this fragment to the end of the pending entry. 881 * fragment cache. Add this fragment to the end of the pending entry.
856 */ 882 */
857 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq, 883 entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
858 rx->u.rx.queue, hdr); 884 rx->queue, hdr);
859 if (!entry) { 885 if (!entry) {
860 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); 886 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
861 return TXRX_DROP; 887 return RX_DROP_MONITOR;
862 } 888 }
863 889
864 /* Verify that MPDUs within one MSDU have sequential PN values. 890 /* Verify that MPDUs within one MSDU have sequential PN values.
@@ -867,14 +893,14 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
867 int i; 893 int i;
868 u8 pn[CCMP_PN_LEN], *rpn; 894 u8 pn[CCMP_PN_LEN], *rpn;
869 if (!rx->key || rx->key->conf.alg != ALG_CCMP) 895 if (!rx->key || rx->key->conf.alg != ALG_CCMP)
870 return TXRX_DROP; 896 return RX_DROP_UNUSABLE;
871 memcpy(pn, entry->last_pn, CCMP_PN_LEN); 897 memcpy(pn, entry->last_pn, CCMP_PN_LEN);
872 for (i = CCMP_PN_LEN - 1; i >= 0; i--) { 898 for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
873 pn[i]++; 899 pn[i]++;
874 if (pn[i]) 900 if (pn[i])
875 break; 901 break;
876 } 902 }
877 rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue]; 903 rpn = rx->key->u.ccmp.rx_pn[rx->queue];
878 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) { 904 if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
879 if (net_ratelimit()) 905 if (net_ratelimit())
880 printk(KERN_DEBUG "%s: defrag: CCMP PN not " 906 printk(KERN_DEBUG "%s: defrag: CCMP PN not "
@@ -885,7 +911,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
885 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], 911 rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
886 rpn[5], pn[0], pn[1], pn[2], pn[3], 912 rpn[5], pn[0], pn[1], pn[2], pn[3],
887 pn[4], pn[5]); 913 pn[4], pn[5]);
888 return TXRX_DROP; 914 return RX_DROP_UNUSABLE;
889 } 915 }
890 memcpy(entry->last_pn, pn, CCMP_PN_LEN); 916 memcpy(entry->last_pn, pn, CCMP_PN_LEN);
891 } 917 }
@@ -896,7 +922,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
896 entry->extra_len += rx->skb->len; 922 entry->extra_len += rx->skb->len;
897 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) { 923 if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
898 rx->skb = NULL; 924 rx->skb = NULL;
899 return TXRX_QUEUED; 925 return RX_QUEUED;
900 } 926 }
901 927
902 rx->skb = __skb_dequeue(&entry->skb_list); 928 rx->skb = __skb_dequeue(&entry->skb_list);
@@ -906,7 +932,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
906 GFP_ATOMIC))) { 932 GFP_ATOMIC))) {
907 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag); 933 I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
908 __skb_queue_purge(&entry->skb_list); 934 __skb_queue_purge(&entry->skb_list);
909 return TXRX_DROP; 935 return RX_DROP_UNUSABLE;
910 } 936 }
911 } 937 }
912 while ((skb = __skb_dequeue(&entry->skb_list))) { 938 while ((skb = __skb_dequeue(&entry->skb_list))) {
@@ -915,7 +941,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
915 } 941 }
916 942
917 /* Complete frame has been reassembled - process it now */ 943 /* Complete frame has been reassembled - process it now */
918 rx->flags |= IEEE80211_TXRXD_FRAGMENTED; 944 rx->flags |= IEEE80211_RX_FRAGMENTED;
919 945
920 out: 946 out:
921 if (rx->sta) 947 if (rx->sta)
@@ -924,11 +950,11 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
924 rx->local->dot11MulticastReceivedFrameCount++; 950 rx->local->dot11MulticastReceivedFrameCount++;
925 else 951 else
926 ieee80211_led_rx(rx->local); 952 ieee80211_led_rx(rx->local);
927 return TXRX_CONTINUE; 953 return RX_CONTINUE;
928} 954}
929 955
930static ieee80211_txrx_result 956static ieee80211_rx_result
931ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx) 957ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
932{ 958{
933 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 959 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
934 struct sk_buff *skb; 960 struct sk_buff *skb;
@@ -938,12 +964,12 @@ ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
938 if (likely(!rx->sta || 964 if (likely(!rx->sta ||
939 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL || 965 (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
940 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL || 966 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
941 !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))) 967 !(rx->flags & IEEE80211_RX_RA_MATCH)))
942 return TXRX_CONTINUE; 968 return RX_CONTINUE;
943 969
944 if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) && 970 if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) &&
945 (sdata->vif.type != IEEE80211_IF_TYPE_VLAN)) 971 (sdata->vif.type != IEEE80211_IF_TYPE_VLAN))
946 return TXRX_DROP; 972 return RX_DROP_UNUSABLE;
947 973
948 skb = skb_dequeue(&rx->sta->tx_filtered); 974 skb = skb_dequeue(&rx->sta->tx_filtered);
949 if (!skb) { 975 if (!skb) {
@@ -958,9 +984,11 @@ ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
958 struct ieee80211_hdr *hdr = 984 struct ieee80211_hdr *hdr =
959 (struct ieee80211_hdr *) skb->data; 985 (struct ieee80211_hdr *) skb->data;
960 986
961 /* tell TX path to send one frame even though the STA may 987 /*
962 * still remain is PS mode after this frame exchange */ 988 * Tell TX path to send one frame even though the STA may
963 rx->sta->pspoll = 1; 989 * still remain is PS mode after this frame exchange.
990 */
991 rx->sta->flags |= WLAN_STA_PSPOLL;
964 992
965#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 993#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
966 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n", 994 printk(KERN_DEBUG "STA %s aid %d: PS Poll (entries after %d)\n",
@@ -970,46 +998,45 @@ ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
970 998
971 /* Use MoreData flag to indicate whether there are more 999 /* Use MoreData flag to indicate whether there are more
972 * buffered frames for this STA */ 1000 * buffered frames for this STA */
973 if (no_pending_pkts) { 1001 if (no_pending_pkts)
974 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); 1002 hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
975 rx->sta->flags &= ~WLAN_STA_TIM; 1003 else
976 } else
977 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); 1004 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
978 1005
979 dev_queue_xmit(skb); 1006 dev_queue_xmit(skb);
980 1007
981 if (no_pending_pkts) { 1008 if (no_pending_pkts)
982 if (rx->local->ops->set_tim) 1009 sta_info_clear_tim_bit(rx->sta);
983 rx->local->ops->set_tim(local_to_hw(rx->local),
984 rx->sta->aid, 0);
985 if (rx->sdata->bss)
986 bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
987 }
988#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1010#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
989 } else if (!rx->u.rx.sent_ps_buffered) { 1011 } else if (!rx->sent_ps_buffered) {
1012 /*
1013 * FIXME: This can be the result of a race condition between
1014 * us expiring a frame and the station polling for it.
1015 * Should we send it a null-func frame indicating we
1016 * have nothing buffered for it?
1017 */
990 printk(KERN_DEBUG "%s: STA %s sent PS Poll even " 1018 printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
991 "though there is no buffered frames for it\n", 1019 "though there is no buffered frames for it\n",
992 rx->dev->name, print_mac(mac, rx->sta->addr)); 1020 rx->dev->name, print_mac(mac, rx->sta->addr));
993#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1021#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
994
995 } 1022 }
996 1023
997 /* Free PS Poll skb here instead of returning TXRX_DROP that would 1024 /* Free PS Poll skb here instead of returning RX_DROP that would
998 * count as an dropped frame. */ 1025 * count as an dropped frame. */
999 dev_kfree_skb(rx->skb); 1026 dev_kfree_skb(rx->skb);
1000 1027
1001 return TXRX_QUEUED; 1028 return RX_QUEUED;
1002} 1029}
1003 1030
1004static ieee80211_txrx_result 1031static ieee80211_rx_result
1005ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx) 1032ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
1006{ 1033{
1007 u16 fc = rx->fc; 1034 u16 fc = rx->fc;
1008 u8 *data = rx->skb->data; 1035 u8 *data = rx->skb->data;
1009 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data; 1036 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
1010 1037
1011 if (!WLAN_FC_IS_QOS_DATA(fc)) 1038 if (!WLAN_FC_IS_QOS_DATA(fc))
1012 return TXRX_CONTINUE; 1039 return RX_CONTINUE;
1013 1040
1014 /* remove the qos control field, update frame type and meta-data */ 1041 /* remove the qos control field, update frame type and meta-data */
1015 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2); 1042 memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
@@ -1018,17 +1045,17 @@ ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
1018 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA; 1045 rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
1019 hdr->frame_control = cpu_to_le16(fc); 1046 hdr->frame_control = cpu_to_le16(fc);
1020 1047
1021 return TXRX_CONTINUE; 1048 return RX_CONTINUE;
1022} 1049}
1023 1050
1024static int 1051static int
1025ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx) 1052ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
1026{ 1053{
1027 if (unlikely(rx->sdata->ieee802_1x_pac && 1054 if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) {
1028 (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)))) {
1029#ifdef CONFIG_MAC80211_DEBUG 1055#ifdef CONFIG_MAC80211_DEBUG
1030 printk(KERN_DEBUG "%s: dropped frame " 1056 if (net_ratelimit())
1031 "(unauthorized port)\n", rx->dev->name); 1057 printk(KERN_DEBUG "%s: dropped frame "
1058 "(unauthorized port)\n", rx->dev->name);
1032#endif /* CONFIG_MAC80211_DEBUG */ 1059#endif /* CONFIG_MAC80211_DEBUG */
1033 return -EACCES; 1060 return -EACCES;
1034 } 1061 }
@@ -1037,13 +1064,13 @@ ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
1037} 1064}
1038 1065
1039static int 1066static int
1040ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx) 1067ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx)
1041{ 1068{
1042 /* 1069 /*
1043 * Pass through unencrypted frames if the hardware has 1070 * Pass through unencrypted frames if the hardware has
1044 * decrypted them already. 1071 * decrypted them already.
1045 */ 1072 */
1046 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) 1073 if (rx->status->flag & RX_FLAG_DECRYPTED)
1047 return 0; 1074 return 0;
1048 1075
1049 /* Drop unencrypted frames if key is set. */ 1076 /* Drop unencrypted frames if key is set. */
@@ -1060,7 +1087,7 @@ ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
1060} 1087}
1061 1088
1062static int 1089static int
1063ieee80211_data_to_8023(struct ieee80211_txrx_data *rx) 1090ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
1064{ 1091{
1065 struct net_device *dev = rx->dev; 1092 struct net_device *dev = rx->dev;
1066 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; 1093 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
@@ -1082,6 +1109,21 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1082 1109
1083 hdrlen = ieee80211_get_hdrlen(fc); 1110 hdrlen = ieee80211_get_hdrlen(fc);
1084 1111
1112 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1113 int meshhdrlen = ieee80211_get_mesh_hdrlen(
1114 (struct ieee80211s_hdr *) (skb->data + hdrlen));
1115 /* Copy on cb:
1116 * - mesh header: to be used for mesh forwarding
1117 * decision. It will also be used as mesh header template at
1118 * tx.c:ieee80211_subif_start_xmit() if interface
1119 * type is mesh and skb->pkt_type == PACKET_OTHERHOST
1120 * - ta: to be used if a RERR needs to be sent.
1121 */
1122 memcpy(skb->cb, skb->data + hdrlen, meshhdrlen);
1123 memcpy(MESH_PREQ(skb), hdr->addr2, ETH_ALEN);
1124 hdrlen += meshhdrlen;
1125 }
1126
1085 /* convert IEEE 802.11 header + possible LLC headers into Ethernet 1127 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
1086 * header 1128 * header
1087 * IEEE 802.11 address fields: 1129 * IEEE 802.11 address fields:
@@ -1115,9 +1157,10 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1115 memcpy(dst, hdr->addr3, ETH_ALEN); 1157 memcpy(dst, hdr->addr3, ETH_ALEN);
1116 memcpy(src, hdr->addr4, ETH_ALEN); 1158 memcpy(src, hdr->addr4, ETH_ALEN);
1117 1159
1118 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS)) { 1160 if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS &&
1119 if (net_ratelimit()) 1161 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) {
1120 printk(KERN_DEBUG "%s: dropped FromDS&ToDS " 1162 if (net_ratelimit())
1163 printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
1121 "frame (RA=%s TA=%s DA=%s SA=%s)\n", 1164 "frame (RA=%s TA=%s DA=%s SA=%s)\n",
1122 rx->dev->name, 1165 rx->dev->name,
1123 print_mac(mac, hdr->addr1), 1166 print_mac(mac, hdr->addr1),
@@ -1192,7 +1235,7 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
1192/* 1235/*
1193 * requires that rx->skb is a frame with ethernet header 1236 * requires that rx->skb is a frame with ethernet header
1194 */ 1237 */
1195static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx) 1238static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx)
1196{ 1239{
1197 static const u8 pae_group_addr[ETH_ALEN] 1240 static const u8 pae_group_addr[ETH_ALEN]
1198 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 }; 1241 = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
@@ -1218,7 +1261,7 @@ static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
1218 * requires that rx->skb is a frame with ethernet header 1261 * requires that rx->skb is a frame with ethernet header
1219 */ 1262 */
1220static void 1263static void
1221ieee80211_deliver_skb(struct ieee80211_txrx_data *rx) 1264ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
1222{ 1265{
1223 struct net_device *dev = rx->dev; 1266 struct net_device *dev = rx->dev;
1224 struct ieee80211_local *local = rx->local; 1267 struct ieee80211_local *local = rx->local;
@@ -1232,7 +1275,7 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1232 1275
1233 if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP || 1276 if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP ||
1234 sdata->vif.type == IEEE80211_IF_TYPE_VLAN) && 1277 sdata->vif.type == IEEE80211_IF_TYPE_VLAN) &&
1235 (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) { 1278 (rx->flags & IEEE80211_RX_RA_MATCH)) {
1236 if (is_multicast_ether_addr(ehdr->h_dest)) { 1279 if (is_multicast_ether_addr(ehdr->h_dest)) {
1237 /* 1280 /*
1238 * send multicast frames both to higher layers in 1281 * send multicast frames both to higher layers in
@@ -1244,7 +1287,7 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1244 "multicast frame\n", dev->name); 1287 "multicast frame\n", dev->name);
1245 } else { 1288 } else {
1246 dsta = sta_info_get(local, skb->data); 1289 dsta = sta_info_get(local, skb->data);
1247 if (dsta && dsta->dev == dev) { 1290 if (dsta && dsta->sdata->dev == dev) {
1248 /* 1291 /*
1249 * The destination station is associated to 1292 * The destination station is associated to
1250 * this AP (in this VLAN), so send the frame 1293 * this AP (in this VLAN), so send the frame
@@ -1254,8 +1297,38 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1254 xmit_skb = skb; 1297 xmit_skb = skb;
1255 skb = NULL; 1298 skb = NULL;
1256 } 1299 }
1257 if (dsta) 1300 }
1258 sta_info_put(dsta); 1301 }
1302
1303 /* Mesh forwarding */
1304 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1305 u8 *mesh_ttl = &((struct ieee80211s_hdr *)skb->cb)->ttl;
1306 (*mesh_ttl)--;
1307
1308 if (is_multicast_ether_addr(skb->data)) {
1309 if (*mesh_ttl > 0) {
1310 xmit_skb = skb_copy(skb, GFP_ATOMIC);
1311 if (!xmit_skb && net_ratelimit())
1312 printk(KERN_DEBUG "%s: failed to clone "
1313 "multicast frame\n", dev->name);
1314 else
1315 xmit_skb->pkt_type = PACKET_OTHERHOST;
1316 } else
1317 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
1318 dropped_frames_ttl);
1319 } else if (skb->pkt_type != PACKET_OTHERHOST &&
1320 compare_ether_addr(dev->dev_addr, skb->data) != 0) {
1321 if (*mesh_ttl == 0) {
1322 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
1323 dropped_frames_ttl);
1324 dev_kfree_skb(skb);
1325 skb = NULL;
1326 } else {
1327 xmit_skb = skb;
1328 xmit_skb->pkt_type = PACKET_OTHERHOST;
1329 if (!(dev->flags & IFF_PROMISC))
1330 skb = NULL;
1331 }
1259 } 1332 }
1260 } 1333 }
1261 1334
@@ -1275,8 +1348,8 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
1275 } 1348 }
1276} 1349}
1277 1350
1278static ieee80211_txrx_result 1351static ieee80211_rx_result
1279ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx) 1352ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
1280{ 1353{
1281 struct net_device *dev = rx->dev; 1354 struct net_device *dev = rx->dev;
1282 struct ieee80211_local *local = rx->local; 1355 struct ieee80211_local *local = rx->local;
@@ -1291,17 +1364,17 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1291 1364
1292 fc = rx->fc; 1365 fc = rx->fc;
1293 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) 1366 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1294 return TXRX_CONTINUE; 1367 return RX_CONTINUE;
1295 1368
1296 if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) 1369 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1297 return TXRX_DROP; 1370 return RX_DROP_MONITOR;
1298 1371
1299 if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU)) 1372 if (!(rx->flags & IEEE80211_RX_AMSDU))
1300 return TXRX_CONTINUE; 1373 return RX_CONTINUE;
1301 1374
1302 err = ieee80211_data_to_8023(rx); 1375 err = ieee80211_data_to_8023(rx);
1303 if (unlikely(err)) 1376 if (unlikely(err))
1304 return TXRX_DROP; 1377 return RX_DROP_UNUSABLE;
1305 1378
1306 skb->dev = dev; 1379 skb->dev = dev;
1307 1380
@@ -1311,7 +1384,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1311 /* skip the wrapping header */ 1384 /* skip the wrapping header */
1312 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr)); 1385 eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
1313 if (!eth) 1386 if (!eth)
1314 return TXRX_DROP; 1387 return RX_DROP_UNUSABLE;
1315 1388
1316 while (skb != frame) { 1389 while (skb != frame) {
1317 u8 padding; 1390 u8 padding;
@@ -1326,7 +1399,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1326 /* the last MSDU has no padding */ 1399 /* the last MSDU has no padding */
1327 if (subframe_len > remaining) { 1400 if (subframe_len > remaining) {
1328 printk(KERN_DEBUG "%s: wrong buffer size", dev->name); 1401 printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
1329 return TXRX_DROP; 1402 return RX_DROP_UNUSABLE;
1330 } 1403 }
1331 1404
1332 skb_pull(skb, sizeof(struct ethhdr)); 1405 skb_pull(skb, sizeof(struct ethhdr));
@@ -1338,7 +1411,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1338 subframe_len); 1411 subframe_len);
1339 1412
1340 if (frame == NULL) 1413 if (frame == NULL)
1341 return TXRX_DROP; 1414 return RX_DROP_UNUSABLE;
1342 1415
1343 skb_reserve(frame, local->hw.extra_tx_headroom + 1416 skb_reserve(frame, local->hw.extra_tx_headroom +
1344 sizeof(struct ethhdr)); 1417 sizeof(struct ethhdr));
@@ -1351,7 +1424,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1351 printk(KERN_DEBUG "%s: wrong buffer size ", 1424 printk(KERN_DEBUG "%s: wrong buffer size ",
1352 dev->name); 1425 dev->name);
1353 dev_kfree_skb(frame); 1426 dev_kfree_skb(frame);
1354 return TXRX_DROP; 1427 return RX_DROP_UNUSABLE;
1355 } 1428 }
1356 } 1429 }
1357 1430
@@ -1381,7 +1454,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1381 1454
1382 if (!ieee80211_frame_allowed(rx)) { 1455 if (!ieee80211_frame_allowed(rx)) {
1383 if (skb == frame) /* last frame */ 1456 if (skb == frame) /* last frame */
1384 return TXRX_DROP; 1457 return RX_DROP_UNUSABLE;
1385 dev_kfree_skb(frame); 1458 dev_kfree_skb(frame);
1386 continue; 1459 continue;
1387 } 1460 }
@@ -1389,11 +1462,11 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
1389 ieee80211_deliver_skb(rx); 1462 ieee80211_deliver_skb(rx);
1390 } 1463 }
1391 1464
1392 return TXRX_QUEUED; 1465 return RX_QUEUED;
1393} 1466}
1394 1467
1395static ieee80211_txrx_result 1468static ieee80211_rx_result
1396ieee80211_rx_h_data(struct ieee80211_txrx_data *rx) 1469ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
1397{ 1470{
1398 struct net_device *dev = rx->dev; 1471 struct net_device *dev = rx->dev;
1399 u16 fc; 1472 u16 fc;
@@ -1401,17 +1474,17 @@ ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1401 1474
1402 fc = rx->fc; 1475 fc = rx->fc;
1403 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) 1476 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
1404 return TXRX_CONTINUE; 1477 return RX_CONTINUE;
1405 1478
1406 if (unlikely(!WLAN_FC_DATA_PRESENT(fc))) 1479 if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
1407 return TXRX_DROP; 1480 return RX_DROP_MONITOR;
1408 1481
1409 err = ieee80211_data_to_8023(rx); 1482 err = ieee80211_data_to_8023(rx);
1410 if (unlikely(err)) 1483 if (unlikely(err))
1411 return TXRX_DROP; 1484 return RX_DROP_UNUSABLE;
1412 1485
1413 if (!ieee80211_frame_allowed(rx)) 1486 if (!ieee80211_frame_allowed(rx))
1414 return TXRX_DROP; 1487 return RX_DROP_MONITOR;
1415 1488
1416 rx->skb->dev = dev; 1489 rx->skb->dev = dev;
1417 1490
@@ -1420,11 +1493,11 @@ ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
1420 1493
1421 ieee80211_deliver_skb(rx); 1494 ieee80211_deliver_skb(rx);
1422 1495
1423 return TXRX_QUEUED; 1496 return RX_QUEUED;
1424} 1497}
1425 1498
1426static ieee80211_txrx_result 1499static ieee80211_rx_result
1427ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx) 1500ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1428{ 1501{
1429 struct ieee80211_local *local = rx->local; 1502 struct ieee80211_local *local = rx->local;
1430 struct ieee80211_hw *hw = &local->hw; 1503 struct ieee80211_hw *hw = &local->hw;
@@ -1435,15 +1508,15 @@ ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
1435 u16 tid; 1508 u16 tid;
1436 1509
1437 if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL)) 1510 if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL))
1438 return TXRX_CONTINUE; 1511 return RX_CONTINUE;
1439 1512
1440 if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) { 1513 if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) {
1441 if (!rx->sta) 1514 if (!rx->sta)
1442 return TXRX_CONTINUE; 1515 return RX_CONTINUE;
1443 tid = le16_to_cpu(bar->control) >> 12; 1516 tid = le16_to_cpu(bar->control) >> 12;
1444 tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]); 1517 tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]);
1445 if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL) 1518 if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
1446 return TXRX_CONTINUE; 1519 return RX_CONTINUE;
1447 1520
1448 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4; 1521 start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
1449 1522
@@ -1460,77 +1533,35 @@ ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
1460 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, 1533 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
1461 start_seq_num, 1); 1534 start_seq_num, 1);
1462 rcu_read_unlock(); 1535 rcu_read_unlock();
1463 return TXRX_DROP; 1536 return RX_DROP_UNUSABLE;
1464 } 1537 }
1465 1538
1466 return TXRX_CONTINUE; 1539 return RX_CONTINUE;
1467} 1540}
1468 1541
1469static ieee80211_txrx_result 1542static ieee80211_rx_result
1470ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx) 1543ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
1471{ 1544{
1472 struct ieee80211_sub_if_data *sdata; 1545 struct ieee80211_sub_if_data *sdata;
1473 1546
1474 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) 1547 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
1475 return TXRX_DROP; 1548 return RX_DROP_MONITOR;
1476 1549
1477 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 1550 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1478 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA || 1551 if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1479 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) && 1552 sdata->vif.type == IEEE80211_IF_TYPE_IBSS ||
1553 sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) &&
1480 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) 1554 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
1481 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status); 1555 ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->status);
1482 else 1556 else
1483 return TXRX_DROP; 1557 return RX_DROP_MONITOR;
1484
1485 return TXRX_QUEUED;
1486}
1487
1488static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
1489 struct ieee80211_local *local,
1490 ieee80211_rx_handler *handlers,
1491 struct ieee80211_txrx_data *rx,
1492 struct sta_info *sta)
1493{
1494 ieee80211_rx_handler *handler;
1495 ieee80211_txrx_result res = TXRX_DROP;
1496
1497 for (handler = handlers; *handler != NULL; handler++) {
1498 res = (*handler)(rx);
1499
1500 switch (res) {
1501 case TXRX_CONTINUE:
1502 continue;
1503 case TXRX_DROP:
1504 I802_DEBUG_INC(local->rx_handlers_drop);
1505 if (sta)
1506 sta->rx_dropped++;
1507 break;
1508 case TXRX_QUEUED:
1509 I802_DEBUG_INC(local->rx_handlers_queued);
1510 break;
1511 }
1512 break;
1513 }
1514 1558
1515 if (res == TXRX_DROP) 1559 return RX_QUEUED;
1516 dev_kfree_skb(rx->skb);
1517 return res;
1518}
1519
1520static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
1521 ieee80211_rx_handler *handlers,
1522 struct ieee80211_txrx_data *rx,
1523 struct sta_info *sta)
1524{
1525 if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
1526 TXRX_CONTINUE)
1527 dev_kfree_skb(rx->skb);
1528} 1560}
1529 1561
1530static void ieee80211_rx_michael_mic_report(struct net_device *dev, 1562static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1531 struct ieee80211_hdr *hdr, 1563 struct ieee80211_hdr *hdr,
1532 struct sta_info *sta, 1564 struct ieee80211_rx_data *rx)
1533 struct ieee80211_txrx_data *rx)
1534{ 1565{
1535 int keyidx, hdrlen; 1566 int keyidx, hdrlen;
1536 DECLARE_MAC_BUF(mac); 1567 DECLARE_MAC_BUF(mac);
@@ -1548,7 +1579,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1548 dev->name, print_mac(mac, hdr->addr2), 1579 dev->name, print_mac(mac, hdr->addr2),
1549 print_mac(mac2, hdr->addr1), keyidx); 1580 print_mac(mac2, hdr->addr1), keyidx);
1550 1581
1551 if (!sta) { 1582 if (!rx->sta) {
1552 /* 1583 /*
1553 * Some hardware seem to generate incorrect Michael MIC 1584 * Some hardware seem to generate incorrect Michael MIC
1554 * reports; ignore them to avoid triggering countermeasures. 1585 * reports; ignore them to avoid triggering countermeasures.
@@ -1600,7 +1631,89 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1600 rx->skb = NULL; 1631 rx->skb = NULL;
1601} 1632}
1602 1633
1603ieee80211_rx_handler ieee80211_rx_handlers[] = 1634/* TODO: use IEEE80211_RX_FRAGMENTED */
1635static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
1636{
1637 struct ieee80211_sub_if_data *sdata;
1638 struct ieee80211_local *local = rx->local;
1639 struct ieee80211_rtap_hdr {
1640 struct ieee80211_radiotap_header hdr;
1641 u8 flags;
1642 u8 rate;
1643 __le16 chan_freq;
1644 __le16 chan_flags;
1645 } __attribute__ ((packed)) *rthdr;
1646 struct sk_buff *skb = rx->skb, *skb2;
1647 struct net_device *prev_dev = NULL;
1648 struct ieee80211_rx_status *status = rx->status;
1649
1650 if (rx->flags & IEEE80211_RX_CMNTR_REPORTED)
1651 goto out_free_skb;
1652
1653 if (skb_headroom(skb) < sizeof(*rthdr) &&
1654 pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
1655 goto out_free_skb;
1656
1657 rthdr = (void *)skb_push(skb, sizeof(*rthdr));
1658 memset(rthdr, 0, sizeof(*rthdr));
1659 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1660 rthdr->hdr.it_present =
1661 cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1662 (1 << IEEE80211_RADIOTAP_RATE) |
1663 (1 << IEEE80211_RADIOTAP_CHANNEL));
1664
1665 rthdr->rate = rx->rate->bitrate / 5;
1666 rthdr->chan_freq = cpu_to_le16(status->freq);
1667
1668 if (status->band == IEEE80211_BAND_5GHZ)
1669 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
1670 IEEE80211_CHAN_5GHZ);
1671 else
1672 rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
1673 IEEE80211_CHAN_2GHZ);
1674
1675 skb_set_mac_header(skb, 0);
1676 skb->ip_summed = CHECKSUM_UNNECESSARY;
1677 skb->pkt_type = PACKET_OTHERHOST;
1678 skb->protocol = htons(ETH_P_802_2);
1679
1680 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1681 if (!netif_running(sdata->dev))
1682 continue;
1683
1684 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR ||
1685 !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
1686 continue;
1687
1688 if (prev_dev) {
1689 skb2 = skb_clone(skb, GFP_ATOMIC);
1690 if (skb2) {
1691 skb2->dev = prev_dev;
1692 netif_rx(skb2);
1693 }
1694 }
1695
1696 prev_dev = sdata->dev;
1697 sdata->dev->stats.rx_packets++;
1698 sdata->dev->stats.rx_bytes += skb->len;
1699 }
1700
1701 if (prev_dev) {
1702 skb->dev = prev_dev;
1703 netif_rx(skb);
1704 skb = NULL;
1705 } else
1706 goto out_free_skb;
1707
1708 rx->flags |= IEEE80211_RX_CMNTR_REPORTED;
1709 return;
1710
1711 out_free_skb:
1712 dev_kfree_skb(skb);
1713}
1714
1715typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_rx_data *);
1716static ieee80211_rx_handler ieee80211_rx_handlers[] =
1604{ 1717{
1605 ieee80211_rx_h_if_stats, 1718 ieee80211_rx_h_if_stats,
1606 ieee80211_rx_h_passive_scan, 1719 ieee80211_rx_h_passive_scan,
@@ -1622,10 +1735,51 @@ ieee80211_rx_handler ieee80211_rx_handlers[] =
1622 NULL 1735 NULL
1623}; 1736};
1624 1737
1738static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
1739 struct ieee80211_rx_data *rx,
1740 struct sk_buff *skb)
1741{
1742 ieee80211_rx_handler *handler;
1743 ieee80211_rx_result res = RX_DROP_MONITOR;
1744
1745 rx->skb = skb;
1746 rx->sdata = sdata;
1747 rx->dev = sdata->dev;
1748
1749 for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) {
1750 res = (*handler)(rx);
1751
1752 switch (res) {
1753 case RX_CONTINUE:
1754 continue;
1755 case RX_DROP_UNUSABLE:
1756 case RX_DROP_MONITOR:
1757 I802_DEBUG_INC(sdata->local->rx_handlers_drop);
1758 if (rx->sta)
1759 rx->sta->rx_dropped++;
1760 break;
1761 case RX_QUEUED:
1762 I802_DEBUG_INC(sdata->local->rx_handlers_queued);
1763 break;
1764 }
1765 break;
1766 }
1767
1768 switch (res) {
1769 case RX_CONTINUE:
1770 case RX_DROP_MONITOR:
1771 ieee80211_rx_cooked_monitor(rx);
1772 break;
1773 case RX_DROP_UNUSABLE:
1774 dev_kfree_skb(rx->skb);
1775 break;
1776 }
1777}
1778
1625/* main receive path */ 1779/* main receive path */
1626 1780
1627static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata, 1781static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1628 u8 *bssid, struct ieee80211_txrx_data *rx, 1782 u8 *bssid, struct ieee80211_rx_data *rx,
1629 struct ieee80211_hdr *hdr) 1783 struct ieee80211_hdr *hdr)
1630{ 1784{
1631 int multicast = is_multicast_ether_addr(hdr->addr1); 1785 int multicast = is_multicast_ether_addr(hdr->addr1);
@@ -1635,34 +1789,47 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1635 if (!bssid) 1789 if (!bssid)
1636 return 0; 1790 return 0;
1637 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { 1791 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1638 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) 1792 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
1639 return 0; 1793 return 0;
1640 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; 1794 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1641 } else if (!multicast && 1795 } else if (!multicast &&
1642 compare_ether_addr(sdata->dev->dev_addr, 1796 compare_ether_addr(sdata->dev->dev_addr,
1643 hdr->addr1) != 0) { 1797 hdr->addr1) != 0) {
1644 if (!(sdata->dev->flags & IFF_PROMISC)) 1798 if (!(sdata->dev->flags & IFF_PROMISC))
1645 return 0; 1799 return 0;
1646 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; 1800 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1647 } 1801 }
1648 break; 1802 break;
1649 case IEEE80211_IF_TYPE_IBSS: 1803 case IEEE80211_IF_TYPE_IBSS:
1650 if (!bssid) 1804 if (!bssid)
1651 return 0; 1805 return 0;
1652 if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) { 1806 if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
1653 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) 1807 (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
1808 return 1;
1809 else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
1810 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
1654 return 0; 1811 return 0;
1655 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; 1812 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1656 } else if (!multicast && 1813 } else if (!multicast &&
1657 compare_ether_addr(sdata->dev->dev_addr, 1814 compare_ether_addr(sdata->dev->dev_addr,
1658 hdr->addr1) != 0) { 1815 hdr->addr1) != 0) {
1659 if (!(sdata->dev->flags & IFF_PROMISC)) 1816 if (!(sdata->dev->flags & IFF_PROMISC))
1660 return 0; 1817 return 0;
1661 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; 1818 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1662 } else if (!rx->sta) 1819 } else if (!rx->sta)
1663 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb, 1820 rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
1664 bssid, hdr->addr2); 1821 bssid, hdr->addr2);
1665 break; 1822 break;
1823 case IEEE80211_IF_TYPE_MESH_POINT:
1824 if (!multicast &&
1825 compare_ether_addr(sdata->dev->dev_addr,
1826 hdr->addr1) != 0) {
1827 if (!(sdata->dev->flags & IFF_PROMISC))
1828 return 0;
1829
1830 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1831 }
1832 break;
1666 case IEEE80211_IF_TYPE_VLAN: 1833 case IEEE80211_IF_TYPE_VLAN:
1667 case IEEE80211_IF_TYPE_AP: 1834 case IEEE80211_IF_TYPE_AP:
1668 if (!bssid) { 1835 if (!bssid) {
@@ -1671,12 +1838,12 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1671 return 0; 1838 return 0;
1672 } else if (!ieee80211_bssid_match(bssid, 1839 } else if (!ieee80211_bssid_match(bssid,
1673 sdata->dev->dev_addr)) { 1840 sdata->dev->dev_addr)) {
1674 if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) 1841 if (!(rx->flags & IEEE80211_RX_IN_SCAN))
1675 return 0; 1842 return 0;
1676 rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH; 1843 rx->flags &= ~IEEE80211_RX_RA_MATCH;
1677 } 1844 }
1678 if (sdata->dev == sdata->local->mdev && 1845 if (sdata->dev == sdata->local->mdev &&
1679 !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) 1846 !(rx->flags & IEEE80211_RX_IN_SCAN))
1680 /* do not receive anything via 1847 /* do not receive anything via
1681 * master device when not scanning */ 1848 * master device when not scanning */
1682 return 0; 1849 return 0;
@@ -1707,13 +1874,13 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
1707static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, 1874static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1708 struct sk_buff *skb, 1875 struct sk_buff *skb,
1709 struct ieee80211_rx_status *status, 1876 struct ieee80211_rx_status *status,
1710 u32 load) 1877 u32 load,
1878 struct ieee80211_rate *rate)
1711{ 1879{
1712 struct ieee80211_local *local = hw_to_local(hw); 1880 struct ieee80211_local *local = hw_to_local(hw);
1713 struct ieee80211_sub_if_data *sdata; 1881 struct ieee80211_sub_if_data *sdata;
1714 struct sta_info *sta;
1715 struct ieee80211_hdr *hdr; 1882 struct ieee80211_hdr *hdr;
1716 struct ieee80211_txrx_data rx; 1883 struct ieee80211_rx_data rx;
1717 u16 type; 1884 u16 type;
1718 int prepares; 1885 int prepares;
1719 struct ieee80211_sub_if_data *prev = NULL; 1886 struct ieee80211_sub_if_data *prev = NULL;
@@ -1725,42 +1892,33 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1725 rx.skb = skb; 1892 rx.skb = skb;
1726 rx.local = local; 1893 rx.local = local;
1727 1894
1728 rx.u.rx.status = status; 1895 rx.status = status;
1729 rx.u.rx.load = load; 1896 rx.load = load;
1897 rx.rate = rate;
1730 rx.fc = le16_to_cpu(hdr->frame_control); 1898 rx.fc = le16_to_cpu(hdr->frame_control);
1731 type = rx.fc & IEEE80211_FCTL_FTYPE; 1899 type = rx.fc & IEEE80211_FCTL_FTYPE;
1732 1900
1733 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT) 1901 if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
1734 local->dot11ReceivedFragmentCount++; 1902 local->dot11ReceivedFragmentCount++;
1735 1903
1736 sta = rx.sta = sta_info_get(local, hdr->addr2); 1904 rx.sta = sta_info_get(local, hdr->addr2);
1737 if (sta) { 1905 if (rx.sta) {
1738 rx.dev = rx.sta->dev; 1906 rx.sdata = rx.sta->sdata;
1739 rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev); 1907 rx.dev = rx.sta->sdata->dev;
1740 } 1908 }
1741 1909
1742 if ((status->flag & RX_FLAG_MMIC_ERROR)) { 1910 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
1743 ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx); 1911 ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
1744 goto end; 1912 return;
1745 } 1913 }
1746 1914
1747 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning)) 1915 if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
1748 rx.flags |= IEEE80211_TXRXD_RXIN_SCAN; 1916 rx.flags |= IEEE80211_RX_IN_SCAN;
1749 1917
1750 if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx, 1918 ieee80211_parse_qos(&rx);
1751 sta) != TXRX_CONTINUE) 1919 ieee80211_verify_ip_alignment(&rx);
1752 goto end;
1753 skb = rx.skb;
1754 1920
1755 if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) && 1921 skb = rx.skb;
1756 !atomic_read(&local->iff_promiscs) &&
1757 !is_multicast_ether_addr(hdr->addr1)) {
1758 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
1759 ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
1760 rx.sta);
1761 sta_info_put(sta);
1762 return;
1763 }
1764 1922
1765 list_for_each_entry_rcu(sdata, &local->interfaces, list) { 1923 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1766 if (!netif_running(sdata->dev)) 1924 if (!netif_running(sdata->dev))
@@ -1770,10 +1928,8 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1770 continue; 1928 continue;
1771 1929
1772 bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type); 1930 bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
1773 rx.flags |= IEEE80211_TXRXD_RXRA_MATCH; 1931 rx.flags |= IEEE80211_RX_RA_MATCH;
1774 prepares = prepare_for_handlers(sdata, bssid, &rx, hdr); 1932 prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
1775 /* prepare_for_handlers can change sta */
1776 sta = rx.sta;
1777 1933
1778 if (!prepares) 1934 if (!prepares)
1779 continue; 1935 continue;
@@ -1804,26 +1960,14 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
1804 continue; 1960 continue;
1805 } 1961 }
1806 rx.fc = le16_to_cpu(hdr->frame_control); 1962 rx.fc = le16_to_cpu(hdr->frame_control);
1807 rx.skb = skb_new; 1963 ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
1808 rx.dev = prev->dev;
1809 rx.sdata = prev;
1810 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1811 &rx, sta);
1812 prev = sdata; 1964 prev = sdata;
1813 } 1965 }
1814 if (prev) { 1966 if (prev) {
1815 rx.fc = le16_to_cpu(hdr->frame_control); 1967 rx.fc = le16_to_cpu(hdr->frame_control);
1816 rx.skb = skb; 1968 ieee80211_invoke_rx_handlers(prev, &rx, skb);
1817 rx.dev = prev->dev;
1818 rx.sdata = prev;
1819 ieee80211_invoke_rx_handlers(local, local->rx_handlers,
1820 &rx, sta);
1821 } else 1969 } else
1822 dev_kfree_skb(skb); 1970 dev_kfree_skb(skb);
1823
1824 end:
1825 if (sta)
1826 sta_info_put(sta);
1827} 1971}
1828 1972
1829#define SEQ_MODULO 0x1000 1973#define SEQ_MODULO 0x1000
@@ -1859,6 +2003,8 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1859 u16 head_seq_num, buf_size; 2003 u16 head_seq_num, buf_size;
1860 int index; 2004 int index;
1861 u32 pkt_load; 2005 u32 pkt_load;
2006 struct ieee80211_supported_band *sband;
2007 struct ieee80211_rate *rate;
1862 2008
1863 buf_size = tid_agg_rx->buf_size; 2009 buf_size = tid_agg_rx->buf_size;
1864 head_seq_num = tid_agg_rx->head_seq_num; 2010 head_seq_num = tid_agg_rx->head_seq_num;
@@ -1889,12 +2035,14 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1889 memcpy(&status, 2035 memcpy(&status,
1890 tid_agg_rx->reorder_buf[index]->cb, 2036 tid_agg_rx->reorder_buf[index]->cb,
1891 sizeof(status)); 2037 sizeof(status));
2038 sband = local->hw.wiphy->bands[status.band];
2039 rate = &sband->bitrates[status.rate_idx];
1892 pkt_load = ieee80211_rx_load_stats(local, 2040 pkt_load = ieee80211_rx_load_stats(local,
1893 tid_agg_rx->reorder_buf[index], 2041 tid_agg_rx->reorder_buf[index],
1894 &status); 2042 &status, rate);
1895 __ieee80211_rx_handle_packet(hw, 2043 __ieee80211_rx_handle_packet(hw,
1896 tid_agg_rx->reorder_buf[index], 2044 tid_agg_rx->reorder_buf[index],
1897 &status, pkt_load); 2045 &status, pkt_load, rate);
1898 tid_agg_rx->stored_mpdu_num--; 2046 tid_agg_rx->stored_mpdu_num--;
1899 tid_agg_rx->reorder_buf[index] = NULL; 2047 tid_agg_rx->reorder_buf[index] = NULL;
1900 } 2048 }
@@ -1934,11 +2082,13 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
1934 /* release the reordered frame back to stack */ 2082 /* release the reordered frame back to stack */
1935 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, 2083 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
1936 sizeof(status)); 2084 sizeof(status));
2085 sband = local->hw.wiphy->bands[status.band];
2086 rate = &sband->bitrates[status.rate_idx];
1937 pkt_load = ieee80211_rx_load_stats(local, 2087 pkt_load = ieee80211_rx_load_stats(local,
1938 tid_agg_rx->reorder_buf[index], 2088 tid_agg_rx->reorder_buf[index],
1939 &status); 2089 &status, rate);
1940 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2090 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
1941 &status, pkt_load); 2091 &status, pkt_load, rate);
1942 tid_agg_rx->stored_mpdu_num--; 2092 tid_agg_rx->stored_mpdu_num--;
1943 tid_agg_rx->reorder_buf[index] = NULL; 2093 tid_agg_rx->reorder_buf[index] = NULL;
1944 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num); 2094 tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
@@ -1994,7 +2144,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
1994 /* if this mpdu is fragmented - terminate rx aggregation session */ 2144 /* if this mpdu is fragmented - terminate rx aggregation session */
1995 sc = le16_to_cpu(hdr->seq_ctrl); 2145 sc = le16_to_cpu(hdr->seq_ctrl);
1996 if (sc & IEEE80211_SCTL_FRAG) { 2146 if (sc & IEEE80211_SCTL_FRAG) {
1997 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, 2147 ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
1998 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP); 2148 tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
1999 ret = 1; 2149 ret = 1;
2000 goto end_reorder; 2150 goto end_reorder;
@@ -2004,9 +2154,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2004 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; 2154 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
2005 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, 2155 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
2006 mpdu_seq_num, 0); 2156 mpdu_seq_num, 0);
2007end_reorder: 2157 end_reorder:
2008 if (sta)
2009 sta_info_put(sta);
2010 return ret; 2158 return ret;
2011} 2159}
2012 2160
@@ -2019,6 +2167,25 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2019{ 2167{
2020 struct ieee80211_local *local = hw_to_local(hw); 2168 struct ieee80211_local *local = hw_to_local(hw);
2021 u32 pkt_load; 2169 u32 pkt_load;
2170 struct ieee80211_rate *rate = NULL;
2171 struct ieee80211_supported_band *sband;
2172
2173 if (status->band < 0 ||
2174 status->band > IEEE80211_NUM_BANDS) {
2175 WARN_ON(1);
2176 return;
2177 }
2178
2179 sband = local->hw.wiphy->bands[status->band];
2180
2181 if (!sband ||
2182 status->rate_idx < 0 ||
2183 status->rate_idx >= sband->n_bitrates) {
2184 WARN_ON(1);
2185 return;
2186 }
2187
2188 rate = &sband->bitrates[status->rate_idx];
2022 2189
2023 /* 2190 /*
2024 * key references and virtual interfaces are protected using RCU 2191 * key references and virtual interfaces are protected using RCU
@@ -2033,17 +2200,17 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2033 * if it was previously present. 2200 * if it was previously present.
2034 * Also, frames with less than 16 bytes are dropped. 2201 * Also, frames with less than 16 bytes are dropped.
2035 */ 2202 */
2036 skb = ieee80211_rx_monitor(local, skb, status); 2203 skb = ieee80211_rx_monitor(local, skb, status, rate);
2037 if (!skb) { 2204 if (!skb) {
2038 rcu_read_unlock(); 2205 rcu_read_unlock();
2039 return; 2206 return;
2040 } 2207 }
2041 2208
2042 pkt_load = ieee80211_rx_load_stats(local, skb, status); 2209 pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
2043 local->channel_use_raw += pkt_load; 2210 local->channel_use_raw += pkt_load;
2044 2211
2045 if (!ieee80211_rx_reorder_ampdu(local, skb)) 2212 if (!ieee80211_rx_reorder_ampdu(local, skb))
2046 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load); 2213 __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
2047 2214
2048 rcu_read_unlock(); 2215 rcu_read_unlock();
2049} 2216}
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 1f74bd296357..3b84c16cf054 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -15,21 +15,52 @@
15#include <linux/skbuff.h> 15#include <linux/skbuff.h>
16#include <linux/if_arp.h> 16#include <linux/if_arp.h>
17#include <linux/timer.h> 17#include <linux/timer.h>
18#include <linux/rtnetlink.h>
18 19
19#include <net/mac80211.h> 20#include <net/mac80211.h>
20#include "ieee80211_i.h" 21#include "ieee80211_i.h"
21#include "ieee80211_rate.h" 22#include "ieee80211_rate.h"
22#include "sta_info.h" 23#include "sta_info.h"
23#include "debugfs_sta.h" 24#include "debugfs_sta.h"
25#include "mesh.h"
24 26
25/* Caller must hold local->sta_lock */ 27/**
26static void sta_info_hash_add(struct ieee80211_local *local, 28 * DOC: STA information lifetime rules
27 struct sta_info *sta) 29 *
28{ 30 * STA info structures (&struct sta_info) are managed in a hash table
29 sta->hnext = local->sta_hash[STA_HASH(sta->addr)]; 31 * for faster lookup and a list for iteration. They are managed using
30 local->sta_hash[STA_HASH(sta->addr)] = sta; 32 * RCU, i.e. access to the list and hash table is protected by RCU.
31} 33 *
32 34 * Upon allocating a STA info structure with sta_info_alloc(), the caller owns
35 * that structure. It must then either destroy it using sta_info_destroy()
36 * (which is pretty useless) or insert it into the hash table using
37 * sta_info_insert() which demotes the reference from ownership to a regular
38 * RCU-protected reference; if the function is called without protection by an
39 * RCU critical section the reference is instantly invalidated.
40 *
41 * Because there are debugfs entries for each station, and adding those
42 * must be able to sleep, it is also possible to "pin" a station entry,
43 * that means it can be removed from the hash table but not be freed.
44 * See the comment in __sta_info_unlink() for more information.
45 *
46 * In order to remove a STA info structure, the caller needs to first
47 * unlink it (sta_info_unlink()) from the list and hash tables and
48 * then wait for an RCU synchronisation before it can be freed. Due to
49 * the pinning and the possibility of multiple callers trying to remove
50 * the same STA info at the same time, sta_info_unlink() can clear the
51 * STA info pointer it is passed to indicate that the STA info is owned
52 * by somebody else now.
53 *
54 * If sta_info_unlink() did not clear the pointer then the caller owns
55 * the STA info structure now and is responsible of destroying it with
56 * a call to sta_info_destroy(), not before RCU synchronisation, of
57 * course. Note that sta_info_destroy() must be protected by the RTNL.
58 *
59 * In all other cases, there is no concept of ownership on a STA entry,
60 * each structure is owned by the global hash table/list until it is
61 * removed. All users of the structure need to be RCU protected so that
62 * the structure won't be freed before they are done using it.
63 */
33 64
34/* Caller must hold local->sta_lock */ 65/* Caller must hold local->sta_lock */
35static int sta_info_hash_del(struct ieee80211_local *local, 66static int sta_info_hash_del(struct ieee80211_local *local,
@@ -41,159 +72,238 @@ static int sta_info_hash_del(struct ieee80211_local *local,
41 if (!s) 72 if (!s)
42 return -ENOENT; 73 return -ENOENT;
43 if (s == sta) { 74 if (s == sta) {
44 local->sta_hash[STA_HASH(sta->addr)] = s->hnext; 75 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)],
76 s->hnext);
45 return 0; 77 return 0;
46 } 78 }
47 79
48 while (s->hnext && s->hnext != sta) 80 while (s->hnext && s->hnext != sta)
49 s = s->hnext; 81 s = s->hnext;
50 if (s->hnext) { 82 if (s->hnext) {
51 s->hnext = sta->hnext; 83 rcu_assign_pointer(s->hnext, sta->hnext);
52 return 0; 84 return 0;
53 } 85 }
54 86
55 return -ENOENT; 87 return -ENOENT;
56} 88}
57 89
58struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr) 90/* protected by RCU */
91static struct sta_info *__sta_info_find(struct ieee80211_local *local,
92 u8 *addr)
59{ 93{
60 struct sta_info *sta; 94 struct sta_info *sta;
61 95
62 read_lock_bh(&local->sta_lock); 96 sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
63 sta = local->sta_hash[STA_HASH(addr)];
64 while (sta) { 97 while (sta) {
65 if (memcmp(sta->addr, addr, ETH_ALEN) == 0) { 98 if (compare_ether_addr(sta->addr, addr) == 0)
66 __sta_info_get(sta);
67 break; 99 break;
68 } 100 sta = rcu_dereference(sta->hnext);
69 sta = sta->hnext;
70 } 101 }
71 read_unlock_bh(&local->sta_lock);
72
73 return sta; 102 return sta;
74} 103}
104
105struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
106{
107 return __sta_info_find(local, addr);
108}
75EXPORT_SYMBOL(sta_info_get); 109EXPORT_SYMBOL(sta_info_get);
76 110
77int sta_info_min_txrate_get(struct ieee80211_local *local) 111struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
112 struct net_device *dev)
78{ 113{
79 struct sta_info *sta; 114 struct sta_info *sta;
80 struct ieee80211_hw_mode *mode; 115 int i = 0;
81 int min_txrate = 9999999; 116
82 int i; 117 list_for_each_entry_rcu(sta, &local->sta_list, list) {
83 118 if (dev && dev != sta->sdata->dev)
84 read_lock_bh(&local->sta_lock); 119 continue;
85 mode = local->oper_hw_mode; 120 if (i < idx) {
86 for (i = 0; i < STA_HASH_SIZE; i++) { 121 ++i;
87 sta = local->sta_hash[i]; 122 continue;
88 while (sta) {
89 if (sta->txrate < min_txrate)
90 min_txrate = sta->txrate;
91 sta = sta->hnext;
92 } 123 }
124 return sta;
93 } 125 }
94 read_unlock_bh(&local->sta_lock);
95 if (min_txrate == 9999999)
96 min_txrate = 0;
97 126
98 return mode->rates[min_txrate].rate; 127 return NULL;
99} 128}
100 129
101 130void sta_info_destroy(struct sta_info *sta)
102static void sta_info_release(struct kref *kref)
103{ 131{
104 struct sta_info *sta = container_of(kref, struct sta_info, kref);
105 struct ieee80211_local *local = sta->local; 132 struct ieee80211_local *local = sta->local;
106 struct sk_buff *skb; 133 struct sk_buff *skb;
107 int i; 134 int i;
135 DECLARE_MAC_BUF(mbuf);
136
137 if (!sta)
138 return;
139
140 ASSERT_RTNL();
141 might_sleep();
142
143 rate_control_remove_sta_debugfs(sta);
144 ieee80211_sta_debugfs_remove(sta);
145
146#ifdef CONFIG_MAC80211_MESH
147 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
148 mesh_plink_deactivate(sta);
149#endif
150
151 /*
152 * NOTE: This will call synchronize_rcu() internally to
153 * make sure no key references can be in use. We rely on
154 * that here for the mesh code!
155 */
156 ieee80211_key_free(sta->key);
157 WARN_ON(sta->key);
158
159#ifdef CONFIG_MAC80211_MESH
160 if (ieee80211_vif_is_mesh(&sta->sdata->vif))
161 del_timer_sync(&sta->plink_timer);
162#endif
108 163
109 /* free sta structure; it has already been removed from
110 * hash table etc. external structures. Make sure that all
111 * buffered frames are release (one might have been added
112 * after sta_info_free() was called). */
113 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { 164 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
114 local->total_ps_buffered--; 165 local->total_ps_buffered--;
115 dev_kfree_skb_any(skb); 166 dev_kfree_skb_any(skb);
116 } 167 }
117 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { 168
169 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
118 dev_kfree_skb_any(skb); 170 dev_kfree_skb_any(skb);
119 } 171
120 for (i = 0; i < STA_TID_NUM; i++) 172 for (i = 0; i < STA_TID_NUM; i++) {
121 del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer); 173 del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer);
174 del_timer_sync(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
175 }
122 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv); 176 rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
123 rate_control_put(sta->rate_ctrl); 177 rate_control_put(sta->rate_ctrl);
178
179#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
180 printk(KERN_DEBUG "%s: Destroyed STA %s\n",
181 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
182#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
183
124 kfree(sta); 184 kfree(sta);
125} 185}
126 186
127 187
128void sta_info_put(struct sta_info *sta) 188/* Caller must hold local->sta_lock */
189static void sta_info_hash_add(struct ieee80211_local *local,
190 struct sta_info *sta)
129{ 191{
130 kref_put(&sta->kref, sta_info_release); 192 sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
193 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta);
131} 194}
132EXPORT_SYMBOL(sta_info_put);
133 195
134 196struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
135struct sta_info * sta_info_add(struct ieee80211_local *local, 197 u8 *addr, gfp_t gfp)
136 struct net_device *dev, u8 *addr, gfp_t gfp)
137{ 198{
199 struct ieee80211_local *local = sdata->local;
138 struct sta_info *sta; 200 struct sta_info *sta;
139 int i; 201 int i;
140 DECLARE_MAC_BUF(mac); 202 DECLARE_MAC_BUF(mbuf);
141 203
142 sta = kzalloc(sizeof(*sta), gfp); 204 sta = kzalloc(sizeof(*sta), gfp);
143 if (!sta) 205 if (!sta)
144 return NULL; 206 return NULL;
145 207
146 kref_init(&sta->kref); 208 memcpy(sta->addr, addr, ETH_ALEN);
209 sta->local = local;
210 sta->sdata = sdata;
147 211
148 sta->rate_ctrl = rate_control_get(local->rate_ctrl); 212 sta->rate_ctrl = rate_control_get(local->rate_ctrl);
149 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp); 213 sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
214 gfp);
150 if (!sta->rate_ctrl_priv) { 215 if (!sta->rate_ctrl_priv) {
151 rate_control_put(sta->rate_ctrl); 216 rate_control_put(sta->rate_ctrl);
152 kfree(sta); 217 kfree(sta);
153 return NULL; 218 return NULL;
154 } 219 }
155 220
156 memcpy(sta->addr, addr, ETH_ALEN);
157 sta->local = local;
158 sta->dev = dev;
159 spin_lock_init(&sta->ampdu_mlme.ampdu_rx); 221 spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
222 spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
160 for (i = 0; i < STA_TID_NUM; i++) { 223 for (i = 0; i < STA_TID_NUM; i++) {
161 /* timer_to_tid must be initialized with identity mapping to 224 /* timer_to_tid must be initialized with identity mapping to
162 * enable session_timer's data differentiation. refer to 225 * enable session_timer's data differentiation. refer to
163 * sta_rx_agg_session_timer_expired for useage */ 226 * sta_rx_agg_session_timer_expired for useage */
164 sta->timer_to_tid[i] = i; 227 sta->timer_to_tid[i] = i;
228 /* tid to tx queue: initialize according to HW (0 is valid) */
229 sta->tid_to_tx_q[i] = local->hw.queues;
165 /* rx timers */ 230 /* rx timers */
166 sta->ampdu_mlme.tid_rx[i].session_timer.function = 231 sta->ampdu_mlme.tid_rx[i].session_timer.function =
167 sta_rx_agg_session_timer_expired; 232 sta_rx_agg_session_timer_expired;
168 sta->ampdu_mlme.tid_rx[i].session_timer.data = 233 sta->ampdu_mlme.tid_rx[i].session_timer.data =
169 (unsigned long)&sta->timer_to_tid[i]; 234 (unsigned long)&sta->timer_to_tid[i];
170 init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer); 235 init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer);
236 /* tx timers */
237 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.function =
238 sta_addba_resp_timer_expired;
239 sta->ampdu_mlme.tid_tx[i].addba_resp_timer.data =
240 (unsigned long)&sta->timer_to_tid[i];
241 init_timer(&sta->ampdu_mlme.tid_tx[i].addba_resp_timer);
171 } 242 }
172 skb_queue_head_init(&sta->ps_tx_buf); 243 skb_queue_head_init(&sta->ps_tx_buf);
173 skb_queue_head_init(&sta->tx_filtered); 244 skb_queue_head_init(&sta->tx_filtered);
174 __sta_info_get(sta); /* sta used by caller, decremented by 245
175 * sta_info_put() */ 246#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
176 write_lock_bh(&local->sta_lock); 247 printk(KERN_DEBUG "%s: Allocated STA %s\n",
248 wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
249#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
250
251#ifdef CONFIG_MAC80211_MESH
252 sta->plink_state = PLINK_LISTEN;
253 spin_lock_init(&sta->plink_lock);
254 init_timer(&sta->plink_timer);
255#endif
256
257 return sta;
258}
259
260int sta_info_insert(struct sta_info *sta)
261{
262 struct ieee80211_local *local = sta->local;
263 struct ieee80211_sub_if_data *sdata = sta->sdata;
264 unsigned long flags;
265 DECLARE_MAC_BUF(mac);
266
267 /*
268 * Can't be a WARN_ON because it can be triggered through a race:
269 * something inserts a STA (on one CPU) without holding the RTNL
270 * and another CPU turns off the net device.
271 */
272 if (unlikely(!netif_running(sdata->dev)))
273 return -ENETDOWN;
274
275 if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0))
276 return -EINVAL;
277
278 if (WARN_ON(is_multicast_ether_addr(sta->addr)))
279 return -EINVAL;
280
281 spin_lock_irqsave(&local->sta_lock, flags);
282 /* check if STA exists already */
283 if (__sta_info_find(local, sta->addr)) {
284 spin_unlock_irqrestore(&local->sta_lock, flags);
285 return -EEXIST;
286 }
177 list_add(&sta->list, &local->sta_list); 287 list_add(&sta->list, &local->sta_list);
178 local->num_sta++; 288 local->num_sta++;
179 sta_info_hash_add(local, sta); 289 sta_info_hash_add(local, sta);
180 if (local->ops->sta_notify) {
181 struct ieee80211_sub_if_data *sdata;
182 290
183 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 291 /* notify driver */
292 if (local->ops->sta_notify) {
184 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 293 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
185 sdata = sdata->u.vlan.ap; 294 sdata = sdata->u.vlan.ap;
186 295
187 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 296 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
188 STA_NOTIFY_ADD, addr); 297 STA_NOTIFY_ADD, sta->addr);
189 } 298 }
190 write_unlock_bh(&local->sta_lock);
191 299
192#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 300#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
193 printk(KERN_DEBUG "%s: Added STA %s\n", 301 printk(KERN_DEBUG "%s: Inserted STA %s\n",
194 wiphy_name(local->hw.wiphy), print_mac(mac, addr)); 302 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
195#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 303#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
196 304
305 spin_unlock_irqrestore(&local->sta_lock, flags);
306
197#ifdef CONFIG_MAC80211_DEBUGFS 307#ifdef CONFIG_MAC80211_DEBUGFS
198 /* debugfs entry adding might sleep, so schedule process 308 /* debugfs entry adding might sleep, so schedule process
199 * context task for adding entry for STAs that do not yet 309 * context task for adding entry for STAs that do not yet
@@ -201,77 +311,185 @@ struct sta_info * sta_info_add(struct ieee80211_local *local,
201 queue_work(local->hw.workqueue, &local->sta_debugfs_add); 311 queue_work(local->hw.workqueue, &local->sta_debugfs_add);
202#endif 312#endif
203 313
204 return sta; 314 if (ieee80211_vif_is_mesh(&sdata->vif))
315 mesh_accept_plinks_update(sdata);
316
317 return 0;
205} 318}
206 319
207/* Caller must hold local->sta_lock */ 320static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
208void sta_info_remove(struct sta_info *sta)
209{ 321{
210 struct ieee80211_local *local = sta->local; 322 /*
211 struct ieee80211_sub_if_data *sdata; 323 * This format has been mandated by the IEEE specifications,
324 * so this line may not be changed to use the __set_bit() format.
325 */
326 bss->tim[aid / 8] |= (1 << (aid % 8));
327}
212 328
213 /* don't do anything if we've been removed already */ 329static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
214 if (sta_info_hash_del(local, sta)) 330{
215 return; 331 /*
332 * This format has been mandated by the IEEE specifications,
333 * so this line may not be changed to use the __clear_bit() format.
334 */
335 bss->tim[aid / 8] &= ~(1 << (aid % 8));
336}
216 337
217 list_del(&sta->list); 338static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
218 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 339 struct sta_info *sta)
219 if (sta->flags & WLAN_STA_PS) { 340{
220 sta->flags &= ~WLAN_STA_PS; 341 if (bss)
221 if (sdata->bss) 342 __bss_tim_set(bss, sta->aid);
222 atomic_dec(&sdata->bss->num_sta_ps); 343 if (sta->local->ops->set_tim) {
344 sta->local->tim_in_locked_section = true;
345 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
346 sta->local->tim_in_locked_section = false;
223 } 347 }
224 local->num_sta--; 348}
225 sta_info_remove_aid_ptr(sta); 349
350void sta_info_set_tim_bit(struct sta_info *sta)
351{
352 unsigned long flags;
226 353
354 spin_lock_irqsave(&sta->local->sta_lock, flags);
355 __sta_info_set_tim_bit(sta->sdata->bss, sta);
356 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
227} 357}
228 358
229void sta_info_free(struct sta_info *sta) 359static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
360 struct sta_info *sta)
230{ 361{
231 struct sk_buff *skb; 362 if (bss)
232 struct ieee80211_local *local = sta->local; 363 __bss_tim_clear(bss, sta->aid);
233 DECLARE_MAC_BUF(mac); 364 if (sta->local->ops->set_tim) {
365 sta->local->tim_in_locked_section = true;
366 sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
367 sta->local->tim_in_locked_section = false;
368 }
369}
234 370
235 might_sleep(); 371void sta_info_clear_tim_bit(struct sta_info *sta)
372{
373 unsigned long flags;
236 374
237 write_lock_bh(&local->sta_lock); 375 spin_lock_irqsave(&sta->local->sta_lock, flags);
238 sta_info_remove(sta); 376 __sta_info_clear_tim_bit(sta->sdata->bss, sta);
239 write_unlock_bh(&local->sta_lock); 377 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
378}
240 379
241 while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { 380/*
242 local->total_ps_buffered--; 381 * See comment in __sta_info_unlink,
243 dev_kfree_skb(skb); 382 * caller must hold local->sta_lock.
244 } 383 */
245 while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) { 384static void __sta_info_pin(struct sta_info *sta)
246 dev_kfree_skb(skb); 385{
247 } 386 WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL);
387 sta->pin_status = STA_INFO_PIN_STAT_PINNED;
388}
389
390/*
391 * See comment in __sta_info_unlink, returns sta if it
392 * needs to be destroyed.
393 */
394static struct sta_info *__sta_info_unpin(struct sta_info *sta)
395{
396 struct sta_info *ret = NULL;
397 unsigned long flags;
248 398
399 spin_lock_irqsave(&sta->local->sta_lock, flags);
400 WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY &&
401 sta->pin_status != STA_INFO_PIN_STAT_PINNED);
402 if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY)
403 ret = sta;
404 sta->pin_status = STA_INFO_PIN_STAT_NORMAL;
405 spin_unlock_irqrestore(&sta->local->sta_lock, flags);
406
407 return ret;
408}
409
410static void __sta_info_unlink(struct sta_info **sta)
411{
412 struct ieee80211_local *local = (*sta)->local;
413 struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
249#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 414#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
250 printk(KERN_DEBUG "%s: Removed STA %s\n", 415 DECLARE_MAC_BUF(mbuf);
251 wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr)); 416#endif
252#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 417 /*
418 * pull caller's reference if we're already gone.
419 */
420 if (sta_info_hash_del(local, *sta)) {
421 *sta = NULL;
422 return;
423 }
253 424
254 ieee80211_key_free(sta->key); 425 /*
255 sta->key = NULL; 426 * Also pull caller's reference if the STA is pinned by the
427 * task that is adding the debugfs entries. In that case, we
428 * leave the STA "to be freed".
429 *
430 * The rules are not trivial, but not too complex either:
431 * (1) pin_status is only modified under the sta_lock
432 * (2) sta_info_debugfs_add_work() will set the status
433 * to PINNED when it found an item that needs a new
434 * debugfs directory created. In that case, that item
435 * must not be freed although all *RCU* users are done
436 * with it. Hence, we tell the caller of _unlink()
437 * that the item is already gone (as can happen when
438 * two tasks try to unlink/destroy at the same time)
439 * (3) We set the pin_status to DESTROY here when we
440 * find such an item.
441 * (4) sta_info_debugfs_add_work() will reset the pin_status
442 * from PINNED to NORMAL when it is done with the item,
443 * but will check for DESTROY before resetting it in
444 * which case it will free the item.
445 */
446 if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) {
447 (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY;
448 *sta = NULL;
449 return;
450 }
256 451
257 if (local->ops->sta_notify) { 452 list_del(&(*sta)->list);
258 struct ieee80211_sub_if_data *sdata; 453
454 if ((*sta)->flags & WLAN_STA_PS) {
455 (*sta)->flags &= ~WLAN_STA_PS;
456 if (sdata->bss)
457 atomic_dec(&sdata->bss->num_sta_ps);
458 __sta_info_clear_tim_bit(sdata->bss, *sta);
459 }
259 460
260 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); 461 local->num_sta--;
261 462
463 if (local->ops->sta_notify) {
262 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN) 464 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
263 sdata = sdata->u.vlan.ap; 465 sdata = sdata->u.vlan.ap;
264 466
265 local->ops->sta_notify(local_to_hw(local), &sdata->vif, 467 local->ops->sta_notify(local_to_hw(local), &sdata->vif,
266 STA_NOTIFY_REMOVE, sta->addr); 468 STA_NOTIFY_REMOVE, (*sta)->addr);
267 } 469 }
268 470
269 rate_control_remove_sta_debugfs(sta); 471 if (ieee80211_vif_is_mesh(&sdata->vif)) {
270 ieee80211_sta_debugfs_remove(sta); 472 mesh_accept_plinks_update(sdata);
473#ifdef CONFIG_MAC80211_MESH
474 del_timer(&(*sta)->plink_timer);
475#endif
476 }
271 477
272 sta_info_put(sta); 478#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
479 printk(KERN_DEBUG "%s: Removed STA %s\n",
480 wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->addr));
481#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
273} 482}
274 483
484void sta_info_unlink(struct sta_info **sta)
485{
486 struct ieee80211_local *local = (*sta)->local;
487 unsigned long flags;
488
489 spin_lock_irqsave(&local->sta_lock, flags);
490 __sta_info_unlink(sta);
491 spin_unlock_irqrestore(&local->sta_lock, flags);
492}
275 493
276static inline int sta_info_buffer_expired(struct ieee80211_local *local, 494static inline int sta_info_buffer_expired(struct ieee80211_local *local,
277 struct sta_info *sta, 495 struct sta_info *sta,
@@ -299,6 +517,7 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
299{ 517{
300 unsigned long flags; 518 unsigned long flags;
301 struct sk_buff *skb; 519 struct sk_buff *skb;
520 struct ieee80211_sub_if_data *sdata;
302 DECLARE_MAC_BUF(mac); 521 DECLARE_MAC_BUF(mac);
303 522
304 if (skb_queue_empty(&sta->ps_tx_buf)) 523 if (skb_queue_empty(&sta->ps_tx_buf))
@@ -307,21 +526,23 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
307 for (;;) { 526 for (;;) {
308 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); 527 spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
309 skb = skb_peek(&sta->ps_tx_buf); 528 skb = skb_peek(&sta->ps_tx_buf);
310 if (sta_info_buffer_expired(local, sta, skb)) { 529 if (sta_info_buffer_expired(local, sta, skb))
311 skb = __skb_dequeue(&sta->ps_tx_buf); 530 skb = __skb_dequeue(&sta->ps_tx_buf);
312 if (skb_queue_empty(&sta->ps_tx_buf)) 531 else
313 sta->flags &= ~WLAN_STA_TIM;
314 } else
315 skb = NULL; 532 skb = NULL;
316 spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); 533 spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
317 534
318 if (skb) { 535 if (!skb)
319 local->total_ps_buffered--;
320 printk(KERN_DEBUG "Buffered frame expired (STA "
321 "%s)\n", print_mac(mac, sta->addr));
322 dev_kfree_skb(skb);
323 } else
324 break; 536 break;
537
538 sdata = sta->sdata;
539 local->total_ps_buffered--;
540 printk(KERN_DEBUG "Buffered frame expired (STA "
541 "%s)\n", print_mac(mac, sta->addr));
542 dev_kfree_skb(skb);
543
544 if (skb_queue_empty(&sta->ps_tx_buf))
545 sta_info_clear_tim_bit(sta);
325 } 546 }
326} 547}
327 548
@@ -331,13 +552,10 @@ static void sta_info_cleanup(unsigned long data)
331 struct ieee80211_local *local = (struct ieee80211_local *) data; 552 struct ieee80211_local *local = (struct ieee80211_local *) data;
332 struct sta_info *sta; 553 struct sta_info *sta;
333 554
334 read_lock_bh(&local->sta_lock); 555 rcu_read_lock();
335 list_for_each_entry(sta, &local->sta_list, list) { 556 list_for_each_entry_rcu(sta, &local->sta_list, list)
336 __sta_info_get(sta);
337 sta_info_cleanup_expire_buffered(local, sta); 557 sta_info_cleanup_expire_buffered(local, sta);
338 sta_info_put(sta); 558 rcu_read_unlock();
339 }
340 read_unlock_bh(&local->sta_lock);
341 559
342 local->sta_cleanup.expires = 560 local->sta_cleanup.expires =
343 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 561 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
@@ -345,37 +563,45 @@ static void sta_info_cleanup(unsigned long data)
345} 563}
346 564
347#ifdef CONFIG_MAC80211_DEBUGFS 565#ifdef CONFIG_MAC80211_DEBUGFS
348static void sta_info_debugfs_add_task(struct work_struct *work) 566static void sta_info_debugfs_add_work(struct work_struct *work)
349{ 567{
350 struct ieee80211_local *local = 568 struct ieee80211_local *local =
351 container_of(work, struct ieee80211_local, sta_debugfs_add); 569 container_of(work, struct ieee80211_local, sta_debugfs_add);
352 struct sta_info *sta, *tmp; 570 struct sta_info *sta, *tmp;
571 unsigned long flags;
353 572
354 while (1) { 573 while (1) {
355 sta = NULL; 574 sta = NULL;
356 read_lock_bh(&local->sta_lock); 575
576 spin_lock_irqsave(&local->sta_lock, flags);
357 list_for_each_entry(tmp, &local->sta_list, list) { 577 list_for_each_entry(tmp, &local->sta_list, list) {
358 if (!tmp->debugfs.dir) { 578 if (!tmp->debugfs.dir) {
359 sta = tmp; 579 sta = tmp;
360 __sta_info_get(sta); 580 __sta_info_pin(sta);
361 break; 581 break;
362 } 582 }
363 } 583 }
364 read_unlock_bh(&local->sta_lock); 584 spin_unlock_irqrestore(&local->sta_lock, flags);
365 585
366 if (!sta) 586 if (!sta)
367 break; 587 break;
368 588
369 ieee80211_sta_debugfs_add(sta); 589 ieee80211_sta_debugfs_add(sta);
370 rate_control_add_sta_debugfs(sta); 590 rate_control_add_sta_debugfs(sta);
371 sta_info_put(sta); 591
592 sta = __sta_info_unpin(sta);
593
594 if (sta) {
595 synchronize_rcu();
596 sta_info_destroy(sta);
597 }
372 } 598 }
373} 599}
374#endif 600#endif
375 601
376void sta_info_init(struct ieee80211_local *local) 602void sta_info_init(struct ieee80211_local *local)
377{ 603{
378 rwlock_init(&local->sta_lock); 604 spin_lock_init(&local->sta_lock);
379 INIT_LIST_HEAD(&local->sta_list); 605 INIT_LIST_HEAD(&local->sta_list);
380 606
381 setup_timer(&local->sta_cleanup, sta_info_cleanup, 607 setup_timer(&local->sta_cleanup, sta_info_cleanup,
@@ -384,7 +610,7 @@ void sta_info_init(struct ieee80211_local *local)
384 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL); 610 round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
385 611
386#ifdef CONFIG_MAC80211_DEBUGFS 612#ifdef CONFIG_MAC80211_DEBUGFS
387 INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task); 613 INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work);
388#endif 614#endif
389} 615}
390 616
@@ -400,44 +626,40 @@ void sta_info_stop(struct ieee80211_local *local)
400 sta_info_flush(local, NULL); 626 sta_info_flush(local, NULL);
401} 627}
402 628
403void sta_info_remove_aid_ptr(struct sta_info *sta)
404{
405 struct ieee80211_sub_if_data *sdata;
406
407 if (sta->aid <= 0)
408 return;
409
410 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
411
412 if (sdata->local->ops->set_tim)
413 sdata->local->ops->set_tim(local_to_hw(sdata->local),
414 sta->aid, 0);
415 if (sdata->bss)
416 __bss_tim_clear(sdata->bss, sta->aid);
417}
418
419
420/** 629/**
421 * sta_info_flush - flush matching STA entries from the STA table 630 * sta_info_flush - flush matching STA entries from the STA table
631 *
632 * Returns the number of removed STA entries.
633 *
422 * @local: local interface data 634 * @local: local interface data
423 * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs 635 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
424 */ 636 */
425void sta_info_flush(struct ieee80211_local *local, struct net_device *dev) 637int sta_info_flush(struct ieee80211_local *local,
638 struct ieee80211_sub_if_data *sdata)
426{ 639{
427 struct sta_info *sta, *tmp; 640 struct sta_info *sta, *tmp;
428 LIST_HEAD(tmp_list); 641 LIST_HEAD(tmp_list);
642 int ret = 0;
643 unsigned long flags;
429 644
430 write_lock_bh(&local->sta_lock); 645 might_sleep();
431 list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
432 if (!dev || dev == sta->dev) {
433 __sta_info_get(sta);
434 sta_info_remove(sta);
435 list_add_tail(&sta->list, &tmp_list);
436 }
437 write_unlock_bh(&local->sta_lock);
438 646
439 list_for_each_entry_safe(sta, tmp, &tmp_list, list) { 647 spin_lock_irqsave(&local->sta_lock, flags);
440 sta_info_free(sta); 648 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
441 sta_info_put(sta); 649 if (!sdata || sdata == sta->sdata) {
650 __sta_info_unlink(&sta);
651 if (sta) {
652 list_add_tail(&sta->list, &tmp_list);
653 ret++;
654 }
655 }
442 } 656 }
657 spin_unlock_irqrestore(&local->sta_lock, flags);
658
659 synchronize_rcu();
660
661 list_for_each_entry_safe(sta, tmp, &tmp_list, list)
662 sta_info_destroy(sta);
663
664 return ret;
443} 665}
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 96fe3ed95038..f166c8039f2b 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -12,34 +12,74 @@
12#include <linux/list.h> 12#include <linux/list.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/if_ether.h> 14#include <linux/if_ether.h>
15#include <linux/kref.h>
16#include "ieee80211_key.h" 15#include "ieee80211_key.h"
17 16
18/* Stations flags (struct sta_info::flags) */ 17/**
19#define WLAN_STA_AUTH BIT(0) 18 * enum ieee80211_sta_info_flags - Stations flags
20#define WLAN_STA_ASSOC BIT(1) 19 *
21#define WLAN_STA_PS BIT(2) 20 * These flags are used with &struct sta_info's @flags member.
22#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */ 21 *
23#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */ 22 * @WLAN_STA_AUTH: Station is authenticated.
24#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is 23 * @WLAN_STA_ASSOC: Station is associated.
25 * controlling whether STA is authorized to 24 * @WLAN_STA_PS: Station is in power-save mode
26 * send and receive non-IEEE 802.1X frames 25 * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic.
27 */ 26 * This bit is always checked so needs to be enabled for all stations
28#define WLAN_STA_SHORT_PREAMBLE BIT(7) 27 * when virtual port control is not in use.
29/* whether this is an AP that we are associated with as a client */ 28 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
30#define WLAN_STA_ASSOC_AP BIT(8) 29 * frames.
31#define WLAN_STA_WME BIT(9) 30 * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
32#define WLAN_STA_WDS BIT(27) 31 * @WLAN_STA_WME: Station is a QoS-STA.
32 * @WLAN_STA_WDS: Station is one of our WDS peers.
33 * @WLAN_STA_PSPOLL: Station has just PS-polled us.
34 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
35 * IEEE80211_TXCTL_CLEAR_PS_FILT control flag) when the next
36 * frame to this station is transmitted.
37 */
38enum ieee80211_sta_info_flags {
39 WLAN_STA_AUTH = 1<<0,
40 WLAN_STA_ASSOC = 1<<1,
41 WLAN_STA_PS = 1<<2,
42 WLAN_STA_AUTHORIZED = 1<<3,
43 WLAN_STA_SHORT_PREAMBLE = 1<<4,
44 WLAN_STA_ASSOC_AP = 1<<5,
45 WLAN_STA_WME = 1<<6,
46 WLAN_STA_WDS = 1<<7,
47 WLAN_STA_PSPOLL = 1<<8,
48 WLAN_STA_CLEAR_PS_FILT = 1<<9,
49};
33 50
34#define STA_TID_NUM 16 51#define STA_TID_NUM 16
35#define ADDBA_RESP_INTERVAL HZ 52#define ADDBA_RESP_INTERVAL HZ
53#define HT_AGG_MAX_RETRIES (0x3)
36 54
37#define HT_AGG_STATE_INITIATOR_SHIFT (4) 55#define HT_AGG_STATE_INITIATOR_SHIFT (4)
38 56
57#define HT_ADDBA_REQUESTED_MSK BIT(0)
58#define HT_ADDBA_DRV_READY_MSK BIT(1)
59#define HT_ADDBA_RECEIVED_MSK BIT(2)
39#define HT_AGG_STATE_REQ_STOP_BA_MSK BIT(3) 60#define HT_AGG_STATE_REQ_STOP_BA_MSK BIT(3)
40 61#define HT_AGG_STATE_INITIATOR_MSK BIT(HT_AGG_STATE_INITIATOR_SHIFT)
41#define HT_AGG_STATE_IDLE (0x0) 62#define HT_AGG_STATE_IDLE (0x0)
42#define HT_AGG_STATE_OPERATIONAL (0x7) 63#define HT_AGG_STATE_OPERATIONAL (HT_ADDBA_REQUESTED_MSK | \
64 HT_ADDBA_DRV_READY_MSK | \
65 HT_ADDBA_RECEIVED_MSK)
66
67/**
68 * struct tid_ampdu_tx - TID aggregation information (Tx).
69 *
70 * @state: TID's state in session state machine.
71 * @dialog_token: dialog token for aggregation session
72 * @ssn: Starting Sequence Number expected to be aggregated.
73 * @addba_resp_timer: timer for peer's response to addba request
74 * @addba_req_num: number of times addBA request has been sent.
75 */
76struct tid_ampdu_tx {
77 u8 state;
78 u8 dialog_token;
79 u16 ssn;
80 struct timer_list addba_resp_timer;
81 u8 addba_req_num;
82};
43 83
44/** 84/**
45 * struct tid_ampdu_rx - TID aggregation information (Rx). 85 * struct tid_ampdu_rx - TID aggregation information (Rx).
@@ -67,105 +107,195 @@ struct tid_ampdu_rx {
67}; 107};
68 108
69/** 109/**
110 * enum plink_state - state of a mesh peer link finite state machine
111 *
112 * @PLINK_LISTEN: initial state, considered the implicit state of non existant
113 * mesh peer links
114 * @PLINK_OPN_SNT: mesh plink open frame has been sent to this mesh peer
115 * @PLINK_OPN_RCVD: mesh plink open frame has been received from this mesh peer
116 * @PLINK_CNF_RCVD: mesh plink confirm frame has been received from this mesh
117 * peer
118 * @PLINK_ESTAB: mesh peer link is established
119 * @PLINK_HOLDING: mesh peer link is being closed or cancelled
120 * @PLINK_BLOCKED: all frames transmitted from this mesh plink are discarded
121 */
122enum plink_state {
123 PLINK_LISTEN,
124 PLINK_OPN_SNT,
125 PLINK_OPN_RCVD,
126 PLINK_CNF_RCVD,
127 PLINK_ESTAB,
128 PLINK_HOLDING,
129 PLINK_BLOCKED
130};
131
132/**
70 * struct sta_ampdu_mlme - STA aggregation information. 133 * struct sta_ampdu_mlme - STA aggregation information.
71 * 134 *
72 * @tid_agg_info_rx: aggregation info for Rx per TID 135 * @tid_rx: aggregation info for Rx per TID
136 * @tid_tx: aggregation info for Tx per TID
73 * @ampdu_rx: for locking sections in aggregation Rx flow 137 * @ampdu_rx: for locking sections in aggregation Rx flow
138 * @ampdu_tx: for locking sectionsi in aggregation Tx flow
139 * @dialog_token_allocator: dialog token enumerator for each new session;
74 */ 140 */
75struct sta_ampdu_mlme { 141struct sta_ampdu_mlme {
76 struct tid_ampdu_rx tid_rx[STA_TID_NUM]; 142 struct tid_ampdu_rx tid_rx[STA_TID_NUM];
143 struct tid_ampdu_tx tid_tx[STA_TID_NUM];
77 spinlock_t ampdu_rx; 144 spinlock_t ampdu_rx;
145 spinlock_t ampdu_tx;
146 u8 dialog_token_allocator;
78}; 147};
79 148
149
150/* see __sta_info_unlink */
151#define STA_INFO_PIN_STAT_NORMAL 0
152#define STA_INFO_PIN_STAT_PINNED 1
153#define STA_INFO_PIN_STAT_DESTROY 2
154
155/**
156 * struct sta_info - STA information
157 *
158 * This structure collects information about a station that
159 * mac80211 is communicating with.
160 *
161 * @list: global linked list entry
162 * @hnext: hash table linked list pointer
163 * @local: pointer to the global information
164 * @addr: MAC address of this STA
165 * @aid: STA's unique AID (1..2007, 0 = not assigned yet),
166 * only used in AP (and IBSS?) mode
167 * @flags: STA flags, see &enum ieee80211_sta_info_flags
168 * @ps_tx_buf: buffer of frames to transmit to this station
169 * when it leaves power saving state
170 * @tx_filtered: buffer of frames we already tried to transmit
171 * but were filtered by hardware due to STA having entered
172 * power saving state
173 * @rx_packets: Number of MSDUs received from this STA
174 * @rx_bytes: Number of bytes received from this STA
175 * @supp_rates: Bitmap of supported rates (per band)
176 * @ht_info: HT capabilities of this STA
177 */
80struct sta_info { 178struct sta_info {
81 struct kref kref; 179 /* General information, mostly static */
82 struct list_head list; 180 struct list_head list;
83 struct sta_info *hnext; /* next entry in hash table list */ 181 struct sta_info *hnext;
84
85 struct ieee80211_local *local; 182 struct ieee80211_local *local;
86 183 struct ieee80211_sub_if_data *sdata;
87 u8 addr[ETH_ALEN];
88 u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
89 u32 flags; /* WLAN_STA_ */
90
91 struct sk_buff_head ps_tx_buf; /* buffer of TX frames for station in
92 * power saving state */
93 int pspoll; /* whether STA has send a PS Poll frame */
94 struct sk_buff_head tx_filtered; /* buffer of TX frames that were
95 * already given to low-level driver,
96 * but were filtered */
97 int clear_dst_mask;
98
99 unsigned long rx_packets, tx_packets; /* number of RX/TX MSDUs */
100 unsigned long rx_bytes, tx_bytes;
101 unsigned long tx_retry_failed, tx_retry_count;
102 unsigned long tx_filtered_count;
103
104 unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
105
106 unsigned long last_rx;
107 u32 supp_rates; /* bitmap of supported rates in local->curr_rates */
108 int txrate; /* index in local->curr_rates */
109 int last_txrate; /* last rate used to send a frame to this STA */
110 int last_nonerp_idx;
111
112 struct net_device *dev; /* which net device is this station associated
113 * to */
114
115 struct ieee80211_key *key; 184 struct ieee80211_key *key;
116
117 u32 tx_num_consecutive_failures;
118 u32 tx_num_mpdu_ok;
119 u32 tx_num_mpdu_fail;
120
121 struct rate_control_ref *rate_ctrl; 185 struct rate_control_ref *rate_ctrl;
122 void *rate_ctrl_priv; 186 void *rate_ctrl_priv;
187 struct ieee80211_ht_info ht_info;
188 u64 supp_rates[IEEE80211_NUM_BANDS];
189 u8 addr[ETH_ALEN];
190 u16 aid;
191 u16 listen_interval;
123 192
124 /* last received seq/frag number from this STA (per RX queue) */ 193 /*
125 __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES]; 194 * for use by the internal lifetime management,
195 * see __sta_info_unlink
196 */
197 u8 pin_status;
198
199 /* frequently updated information, needs locking? */
200 u32 flags;
201
202 /*
203 * STA powersave frame queues, no more than the internal
204 * locking required.
205 */
206 struct sk_buff_head ps_tx_buf;
207 struct sk_buff_head tx_filtered;
208
209 /* Updated from RX path only, no locking requirements */
210 unsigned long rx_packets, rx_bytes;
211 unsigned long wep_weak_iv_count;
212 unsigned long last_rx;
126 unsigned long num_duplicates; /* number of duplicate frames received 213 unsigned long num_duplicates; /* number of duplicate frames received
127 * from this STA */ 214 * from this STA */
128 unsigned long tx_fragments; /* number of transmitted MPDUs */
129 unsigned long rx_fragments; /* number of received MPDUs */ 215 unsigned long rx_fragments; /* number of received MPDUs */
130 unsigned long rx_dropped; /* number of dropped MPDUs from this STA */ 216 unsigned long rx_dropped; /* number of dropped MPDUs from this STA */
131
132 int last_rssi; /* RSSI of last received frame from this STA */ 217 int last_rssi; /* RSSI of last received frame from this STA */
133 int last_signal; /* signal of last received frame from this STA */ 218 int last_signal; /* signal of last received frame from this STA */
134 int last_noise; /* noise of last received frame from this STA */ 219 int last_noise; /* noise of last received frame from this STA */
135 int last_ack_rssi[3]; /* RSSI of last received ACKs from this STA */ 220 /* last received seq/frag number from this STA (per RX queue) */
136 unsigned long last_ack; 221 __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
137 int channel_use;
138 int channel_use_raw;
139
140#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 222#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
141 unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES]; 223 unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
224#endif
225
226 /* Updated from TX status path only, no locking requirements */
227 unsigned long tx_filtered_count;
228 unsigned long tx_retry_failed, tx_retry_count;
229 /* TODO: update in generic code not rate control? */
230 u32 tx_num_consecutive_failures;
231 u32 tx_num_mpdu_ok;
232 u32 tx_num_mpdu_fail;
233 /* moving percentage of failed MSDUs */
234 unsigned int fail_avg;
235
236 /* Updated from TX path only, no locking requirements */
237 unsigned long tx_packets; /* number of RX/TX MSDUs */
238 unsigned long tx_bytes;
239 unsigned long tx_fragments; /* number of transmitted MPDUs */
240 int txrate_idx;
241 int last_txrate_idx;
242#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
142 unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES]; 243 unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
143#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */ 244#endif
144 245
145 u16 listen_interval; 246 /* Debug counters, no locking doesn't matter */
247 int channel_use;
248 int channel_use_raw;
146 249
147 struct ieee80211_ht_info ht_info; /* 802.11n HT capabilities 250 /*
148 of this STA */ 251 * Aggregation information, comes with own locking.
252 */
149 struct sta_ampdu_mlme ampdu_mlme; 253 struct sta_ampdu_mlme ampdu_mlme;
150 u8 timer_to_tid[STA_TID_NUM]; /* convert timer id to tid */ 254 u8 timer_to_tid[STA_TID_NUM]; /* identity mapping to ID timers */
255 u8 tid_to_tx_q[STA_TID_NUM]; /* map tid to tx queue */
256
257#ifdef CONFIG_MAC80211_MESH
258 /*
259 * Mesh peer link attributes
260 * TODO: move to a sub-structure that is referenced with pointer?
261 */
262 __le16 llid; /* Local link ID */
263 __le16 plid; /* Peer link ID */
264 __le16 reason; /* Cancel reason on PLINK_HOLDING state */
265 u8 plink_retries; /* Retries in establishment */
266 bool ignore_plink_timer;
267 enum plink_state plink_state;
268 u32 plink_timeout;
269 struct timer_list plink_timer;
270 spinlock_t plink_lock; /* For peer_state reads / updates and other
271 updates in the structure. Ensures robust
272 transitions for the peerlink FSM */
273#endif
151 274
152#ifdef CONFIG_MAC80211_DEBUGFS 275#ifdef CONFIG_MAC80211_DEBUGFS
153 struct sta_info_debugfsdentries { 276 struct sta_info_debugfsdentries {
154 struct dentry *dir; 277 struct dentry *dir;
155 struct dentry *flags; 278 struct dentry *flags;
156 struct dentry *num_ps_buf_frames; 279 struct dentry *num_ps_buf_frames;
157 struct dentry *last_ack_rssi;
158 struct dentry *last_ack_ms;
159 struct dentry *inactive_ms; 280 struct dentry *inactive_ms;
160 struct dentry *last_seq_ctrl; 281 struct dentry *last_seq_ctrl;
161#ifdef CONFIG_MAC80211_DEBUG_COUNTERS 282#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
162 struct dentry *wme_rx_queue; 283 struct dentry *wme_rx_queue;
163 struct dentry *wme_tx_queue; 284 struct dentry *wme_tx_queue;
164#endif 285#endif
286 struct dentry *agg_status;
165 } debugfs; 287 } debugfs;
166#endif 288#endif
167}; 289};
168 290
291static inline enum plink_state sta_plink_state(struct sta_info *sta)
292{
293#ifdef CONFIG_MAC80211_MESH
294 return sta->plink_state;
295#endif
296 return PLINK_LISTEN;
297}
298
169 299
170/* Maximum number of concurrently registered stations */ 300/* Maximum number of concurrently registered stations */
171#define MAX_STA_COUNT 2007 301#define MAX_STA_COUNT 2007
@@ -185,22 +315,44 @@ struct sta_info {
185 */ 315 */
186#define STA_INFO_CLEANUP_INTERVAL (10 * HZ) 316#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
187 317
188static inline void __sta_info_get(struct sta_info *sta) 318/*
189{ 319 * Get a STA info, must have be under RCU read lock.
190 kref_get(&sta->kref); 320 */
191} 321struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr);
322/*
323 * Get STA info by index, BROKEN!
324 */
325struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
326 struct net_device *dev);
327/*
328 * Create a new STA info, caller owns returned structure
329 * until sta_info_insert().
330 */
331struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
332 u8 *addr, gfp_t gfp);
333/*
334 * Insert STA info into hash table/list, returns zero or a
335 * -EEXIST if (if the same MAC address is already present).
336 *
337 * Calling this without RCU protection makes the caller
338 * relinquish its reference to @sta.
339 */
340int sta_info_insert(struct sta_info *sta);
341/*
342 * Unlink a STA info from the hash table/list.
343 * This can NULL the STA pointer if somebody else
344 * has already unlinked it.
345 */
346void sta_info_unlink(struct sta_info **sta);
347
348void sta_info_destroy(struct sta_info *sta);
349void sta_info_set_tim_bit(struct sta_info *sta);
350void sta_info_clear_tim_bit(struct sta_info *sta);
192 351
193struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
194int sta_info_min_txrate_get(struct ieee80211_local *local);
195void sta_info_put(struct sta_info *sta);
196struct sta_info * sta_info_add(struct ieee80211_local *local,
197 struct net_device *dev, u8 *addr, gfp_t gfp);
198void sta_info_remove(struct sta_info *sta);
199void sta_info_free(struct sta_info *sta);
200void sta_info_init(struct ieee80211_local *local); 352void sta_info_init(struct ieee80211_local *local);
201int sta_info_start(struct ieee80211_local *local); 353int sta_info_start(struct ieee80211_local *local);
202void sta_info_stop(struct ieee80211_local *local); 354void sta_info_stop(struct ieee80211_local *local);
203void sta_info_remove_aid_ptr(struct sta_info *sta); 355int sta_info_flush(struct ieee80211_local *local,
204void sta_info_flush(struct ieee80211_local *local, struct net_device *dev); 356 struct ieee80211_sub_if_data *sdata);
205 357
206#endif /* STA_INFO_H */ 358#endif /* STA_INFO_H */
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 67b509edd431..80f4343a3007 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -26,6 +26,7 @@
26 26
27#include "ieee80211_i.h" 27#include "ieee80211_i.h"
28#include "ieee80211_led.h" 28#include "ieee80211_led.h"
29#include "mesh.h"
29#include "wep.h" 30#include "wep.h"
30#include "wpa.h" 31#include "wpa.h"
31#include "wme.h" 32#include "wme.h"
@@ -86,15 +87,19 @@ static inline void ieee80211_dump_frame(const char *ifname, const char *title,
86} 87}
87#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */ 88#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
88 89
89static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr, 90static u16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
90 int next_frag_len) 91 int next_frag_len)
91{ 92{
92 int rate, mrate, erp, dur, i; 93 int rate, mrate, erp, dur, i;
93 struct ieee80211_rate *txrate = tx->u.tx.rate; 94 struct ieee80211_rate *txrate = tx->rate;
94 struct ieee80211_local *local = tx->local; 95 struct ieee80211_local *local = tx->local;
95 struct ieee80211_hw_mode *mode = tx->u.tx.mode; 96 struct ieee80211_supported_band *sband;
96 97
97 erp = txrate->flags & IEEE80211_RATE_ERP; 98 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
99
100 erp = 0;
101 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
102 erp = txrate->flags & IEEE80211_RATE_ERP_G;
98 103
99 /* 104 /*
100 * data and mgmt (except PS Poll): 105 * data and mgmt (except PS Poll):
@@ -150,20 +155,36 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
150 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps 155 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
151 */ 156 */
152 rate = -1; 157 rate = -1;
153 mrate = 10; /* use 1 Mbps if everything fails */ 158 /* use lowest available if everything fails */
154 for (i = 0; i < mode->num_rates; i++) { 159 mrate = sband->bitrates[0].bitrate;
155 struct ieee80211_rate *r = &mode->rates[i]; 160 for (i = 0; i < sband->n_bitrates; i++) {
156 if (r->rate > txrate->rate) 161 struct ieee80211_rate *r = &sband->bitrates[i];
157 break;
158 162
159 if (IEEE80211_RATE_MODULATION(txrate->flags) != 163 if (r->bitrate > txrate->bitrate)
160 IEEE80211_RATE_MODULATION(r->flags)) 164 break;
161 continue;
162 165
163 if (r->flags & IEEE80211_RATE_BASIC) 166 if (tx->sdata->basic_rates & BIT(i))
164 rate = r->rate; 167 rate = r->bitrate;
165 else if (r->flags & IEEE80211_RATE_MANDATORY) 168
166 mrate = r->rate; 169 switch (sband->band) {
170 case IEEE80211_BAND_2GHZ: {
171 u32 flag;
172 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
173 flag = IEEE80211_RATE_MANDATORY_G;
174 else
175 flag = IEEE80211_RATE_MANDATORY_B;
176 if (r->flags & flag)
177 mrate = r->bitrate;
178 break;
179 }
180 case IEEE80211_BAND_5GHZ:
181 if (r->flags & IEEE80211_RATE_MANDATORY_A)
182 mrate = r->bitrate;
183 break;
184 case IEEE80211_NUM_BANDS:
185 WARN_ON(1);
186 break;
187 }
167 } 188 }
168 if (rate == -1) { 189 if (rate == -1) {
169 /* No matching basic rate found; use highest suitable mandatory 190 /* No matching basic rate found; use highest suitable mandatory
@@ -184,7 +205,7 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
184 dur *= 2; /* ACK + SIFS */ 205 dur *= 2; /* ACK + SIFS */
185 /* next fragment */ 206 /* next fragment */
186 dur += ieee80211_frame_duration(local, next_frag_len, 207 dur += ieee80211_frame_duration(local, next_frag_len,
187 txrate->rate, erp, 208 txrate->bitrate, erp,
188 tx->sdata->bss_conf.use_short_preamble); 209 tx->sdata->bss_conf.use_short_preamble);
189 } 210 }
190 211
@@ -212,8 +233,8 @@ static int inline is_ieee80211_device(struct net_device *dev,
212 233
213/* tx handlers */ 234/* tx handlers */
214 235
215static ieee80211_txrx_result 236static ieee80211_tx_result
216ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx) 237ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
217{ 238{
218#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 239#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
219 struct sk_buff *skb = tx->skb; 240 struct sk_buff *skb = tx->skb;
@@ -221,20 +242,23 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
221#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 242#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
222 u32 sta_flags; 243 u32 sta_flags;
223 244
224 if (unlikely(tx->flags & IEEE80211_TXRXD_TX_INJECTED)) 245 if (unlikely(tx->flags & IEEE80211_TX_INJECTED))
225 return TXRX_CONTINUE; 246 return TX_CONTINUE;
226 247
227 if (unlikely(tx->local->sta_sw_scanning) && 248 if (unlikely(tx->local->sta_sw_scanning) &&
228 ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || 249 ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
229 (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ)) 250 (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
230 return TXRX_DROP; 251 return TX_DROP;
231 252
232 if (tx->flags & IEEE80211_TXRXD_TXPS_BUFFERED) 253 if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
233 return TXRX_CONTINUE; 254 return TX_CONTINUE;
255
256 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
257 return TX_CONTINUE;
234 258
235 sta_flags = tx->sta ? tx->sta->flags : 0; 259 sta_flags = tx->sta ? tx->sta->flags : 0;
236 260
237 if (likely(tx->flags & IEEE80211_TXRXD_TXUNICAST)) { 261 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
238 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) && 262 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
239 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && 263 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
240 (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { 264 (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
@@ -245,7 +269,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
245 tx->dev->name, print_mac(mac, hdr->addr1)); 269 tx->dev->name, print_mac(mac, hdr->addr1));
246#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 270#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
247 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 271 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
248 return TXRX_DROP; 272 return TX_DROP;
249 } 273 }
250 } else { 274 } else {
251 if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && 275 if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
@@ -255,23 +279,23 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
255 * No associated STAs - no need to send multicast 279 * No associated STAs - no need to send multicast
256 * frames. 280 * frames.
257 */ 281 */
258 return TXRX_DROP; 282 return TX_DROP;
259 } 283 }
260 return TXRX_CONTINUE; 284 return TX_CONTINUE;
261 } 285 }
262 286
263 return TXRX_CONTINUE; 287 return TX_CONTINUE;
264} 288}
265 289
266static ieee80211_txrx_result 290static ieee80211_tx_result
267ieee80211_tx_h_sequence(struct ieee80211_txrx_data *tx) 291ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
268{ 292{
269 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 293 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
270 294
271 if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24) 295 if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24)
272 ieee80211_include_sequence(tx->sdata, hdr); 296 ieee80211_include_sequence(tx->sdata, hdr);
273 297
274 return TXRX_CONTINUE; 298 return TX_CONTINUE;
275} 299}
276 300
277/* This function is called whenever the AP is about to exceed the maximum limit 301/* This function is called whenever the AP is about to exceed the maximum limit
@@ -303,10 +327,8 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
303 } 327 }
304 total += skb_queue_len(&ap->ps_bc_buf); 328 total += skb_queue_len(&ap->ps_bc_buf);
305 } 329 }
306 rcu_read_unlock();
307 330
308 read_lock_bh(&local->sta_lock); 331 list_for_each_entry_rcu(sta, &local->sta_list, list) {
309 list_for_each_entry(sta, &local->sta_list, list) {
310 skb = skb_dequeue(&sta->ps_tx_buf); 332 skb = skb_dequeue(&sta->ps_tx_buf);
311 if (skb) { 333 if (skb) {
312 purged++; 334 purged++;
@@ -314,15 +336,16 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
314 } 336 }
315 total += skb_queue_len(&sta->ps_tx_buf); 337 total += skb_queue_len(&sta->ps_tx_buf);
316 } 338 }
317 read_unlock_bh(&local->sta_lock); 339
340 rcu_read_unlock();
318 341
319 local->total_ps_buffered = total; 342 local->total_ps_buffered = total;
320 printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n", 343 printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
321 wiphy_name(local->hw.wiphy), purged); 344 wiphy_name(local->hw.wiphy), purged);
322} 345}
323 346
324static ieee80211_txrx_result 347static ieee80211_tx_result
325ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx) 348ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
326{ 349{
327 /* 350 /*
328 * broadcast/multicast frame 351 * broadcast/multicast frame
@@ -334,11 +357,11 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
334 357
335 /* not AP/IBSS or ordered frame */ 358 /* not AP/IBSS or ordered frame */
336 if (!tx->sdata->bss || (tx->fc & IEEE80211_FCTL_ORDER)) 359 if (!tx->sdata->bss || (tx->fc & IEEE80211_FCTL_ORDER))
337 return TXRX_CONTINUE; 360 return TX_CONTINUE;
338 361
339 /* no stations in PS mode */ 362 /* no stations in PS mode */
340 if (!atomic_read(&tx->sdata->bss->num_sta_ps)) 363 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
341 return TXRX_CONTINUE; 364 return TX_CONTINUE;
342 365
343 /* buffered in mac80211 */ 366 /* buffered in mac80211 */
344 if (tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) { 367 if (tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) {
@@ -355,17 +378,17 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
355 } else 378 } else
356 tx->local->total_ps_buffered++; 379 tx->local->total_ps_buffered++;
357 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb); 380 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
358 return TXRX_QUEUED; 381 return TX_QUEUED;
359 } 382 }
360 383
361 /* buffered in hardware */ 384 /* buffered in hardware */
362 tx->u.tx.control->flags |= IEEE80211_TXCTL_SEND_AFTER_DTIM; 385 tx->control->flags |= IEEE80211_TXCTL_SEND_AFTER_DTIM;
363 386
364 return TXRX_CONTINUE; 387 return TX_CONTINUE;
365} 388}
366 389
367static ieee80211_txrx_result 390static ieee80211_tx_result
368ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx) 391ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
369{ 392{
370 struct sta_info *sta = tx->sta; 393 struct sta_info *sta = tx->sta;
371 DECLARE_MAC_BUF(mac); 394 DECLARE_MAC_BUF(mac);
@@ -373,9 +396,10 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
373 if (unlikely(!sta || 396 if (unlikely(!sta ||
374 ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && 397 ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
375 (tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP))) 398 (tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)))
376 return TXRX_CONTINUE; 399 return TX_CONTINUE;
377 400
378 if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) { 401 if (unlikely((sta->flags & WLAN_STA_PS) &&
402 !(sta->flags & WLAN_STA_PSPOLL))) {
379 struct ieee80211_tx_packet_data *pkt_data; 403 struct ieee80211_tx_packet_data *pkt_data;
380#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 404#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
381 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries " 405 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries "
@@ -383,7 +407,6 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
383 print_mac(mac, sta->addr), sta->aid, 407 print_mac(mac, sta->addr), sta->aid,
384 skb_queue_len(&sta->ps_tx_buf)); 408 skb_queue_len(&sta->ps_tx_buf));
385#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 409#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
386 sta->flags |= WLAN_STA_TIM;
387 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 410 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
388 purge_old_ps_buffers(tx->local); 411 purge_old_ps_buffers(tx->local);
389 if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) { 412 if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
@@ -396,18 +419,15 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
396 dev_kfree_skb(old); 419 dev_kfree_skb(old);
397 } else 420 } else
398 tx->local->total_ps_buffered++; 421 tx->local->total_ps_buffered++;
422
399 /* Queue frame to be sent after STA sends an PS Poll frame */ 423 /* Queue frame to be sent after STA sends an PS Poll frame */
400 if (skb_queue_empty(&sta->ps_tx_buf)) { 424 if (skb_queue_empty(&sta->ps_tx_buf))
401 if (tx->local->ops->set_tim) 425 sta_info_set_tim_bit(sta);
402 tx->local->ops->set_tim(local_to_hw(tx->local), 426
403 sta->aid, 1);
404 if (tx->sdata->bss)
405 bss_tim_set(tx->local, tx->sdata->bss, sta->aid);
406 }
407 pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb; 427 pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
408 pkt_data->jiffies = jiffies; 428 pkt_data->jiffies = jiffies;
409 skb_queue_tail(&sta->ps_tx_buf, tx->skb); 429 skb_queue_tail(&sta->ps_tx_buf, tx->skb);
410 return TXRX_QUEUED; 430 return TX_QUEUED;
411 } 431 }
412#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 432#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
413 else if (unlikely(sta->flags & WLAN_STA_PS)) { 433 else if (unlikely(sta->flags & WLAN_STA_PS)) {
@@ -416,40 +436,40 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
416 print_mac(mac, sta->addr)); 436 print_mac(mac, sta->addr));
417 } 437 }
418#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 438#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
419 sta->pspoll = 0; 439 sta->flags &= ~WLAN_STA_PSPOLL;
420 440
421 return TXRX_CONTINUE; 441 return TX_CONTINUE;
422} 442}
423 443
424static ieee80211_txrx_result 444static ieee80211_tx_result
425ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx) 445ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
426{ 446{
427 if (unlikely(tx->flags & IEEE80211_TXRXD_TXPS_BUFFERED)) 447 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
428 return TXRX_CONTINUE; 448 return TX_CONTINUE;
429 449
430 if (tx->flags & IEEE80211_TXRXD_TXUNICAST) 450 if (tx->flags & IEEE80211_TX_UNICAST)
431 return ieee80211_tx_h_unicast_ps_buf(tx); 451 return ieee80211_tx_h_unicast_ps_buf(tx);
432 else 452 else
433 return ieee80211_tx_h_multicast_ps_buf(tx); 453 return ieee80211_tx_h_multicast_ps_buf(tx);
434} 454}
435 455
436static ieee80211_txrx_result 456static ieee80211_tx_result
437ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx) 457ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
438{ 458{
439 struct ieee80211_key *key; 459 struct ieee80211_key *key;
440 u16 fc = tx->fc; 460 u16 fc = tx->fc;
441 461
442 if (unlikely(tx->u.tx.control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) 462 if (unlikely(tx->control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
443 tx->key = NULL; 463 tx->key = NULL;
444 else if (tx->sta && (key = rcu_dereference(tx->sta->key))) 464 else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
445 tx->key = key; 465 tx->key = key;
446 else if ((key = rcu_dereference(tx->sdata->default_key))) 466 else if ((key = rcu_dereference(tx->sdata->default_key)))
447 tx->key = key; 467 tx->key = key;
448 else if (tx->sdata->drop_unencrypted && 468 else if (tx->sdata->drop_unencrypted &&
449 !(tx->u.tx.control->flags & IEEE80211_TXCTL_EAPOL_FRAME) && 469 !(tx->control->flags & IEEE80211_TXCTL_EAPOL_FRAME) &&
450 !(tx->flags & IEEE80211_TXRXD_TX_INJECTED)) { 470 !(tx->flags & IEEE80211_TX_INJECTED)) {
451 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted); 471 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
452 return TXRX_DROP; 472 return TX_DROP;
453 } else 473 } else
454 tx->key = NULL; 474 tx->key = NULL;
455 475
@@ -476,13 +496,13 @@ ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
476 } 496 }
477 497
478 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 498 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
479 tx->u.tx.control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT; 499 tx->control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
480 500
481 return TXRX_CONTINUE; 501 return TX_CONTINUE;
482} 502}
483 503
484static ieee80211_txrx_result 504static ieee80211_tx_result
485ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx) 505ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
486{ 506{
487 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; 507 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
488 size_t hdrlen, per_fragm, num_fragm, payload_len, left; 508 size_t hdrlen, per_fragm, num_fragm, payload_len, left;
@@ -492,8 +512,8 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
492 u8 *pos; 512 u8 *pos;
493 int frag_threshold = tx->local->fragmentation_threshold; 513 int frag_threshold = tx->local->fragmentation_threshold;
494 514
495 if (!(tx->flags & IEEE80211_TXRXD_FRAGMENTED)) 515 if (!(tx->flags & IEEE80211_TX_FRAGMENTED))
496 return TXRX_CONTINUE; 516 return TX_CONTINUE;
497 517
498 first = tx->skb; 518 first = tx->skb;
499 519
@@ -544,10 +564,10 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
544 } 564 }
545 skb_trim(first, hdrlen + per_fragm); 565 skb_trim(first, hdrlen + per_fragm);
546 566
547 tx->u.tx.num_extra_frag = num_fragm - 1; 567 tx->num_extra_frag = num_fragm - 1;
548 tx->u.tx.extra_frag = frags; 568 tx->extra_frag = frags;
549 569
550 return TXRX_CONTINUE; 570 return TX_CONTINUE;
551 571
552 fail: 572 fail:
553 printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name); 573 printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
@@ -558,14 +578,14 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
558 kfree(frags); 578 kfree(frags);
559 } 579 }
560 I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment); 580 I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
561 return TXRX_DROP; 581 return TX_DROP;
562} 582}
563 583
564static ieee80211_txrx_result 584static ieee80211_tx_result
565ieee80211_tx_h_encrypt(struct ieee80211_txrx_data *tx) 585ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
566{ 586{
567 if (!tx->key) 587 if (!tx->key)
568 return TXRX_CONTINUE; 588 return TX_CONTINUE;
569 589
570 switch (tx->key->conf.alg) { 590 switch (tx->key->conf.alg) {
571 case ALG_WEP: 591 case ALG_WEP:
@@ -578,59 +598,60 @@ ieee80211_tx_h_encrypt(struct ieee80211_txrx_data *tx)
578 598
579 /* not reached */ 599 /* not reached */
580 WARN_ON(1); 600 WARN_ON(1);
581 return TXRX_DROP; 601 return TX_DROP;
582} 602}
583 603
584static ieee80211_txrx_result 604static ieee80211_tx_result
585ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx) 605ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
586{ 606{
587 struct rate_selection rsel; 607 struct rate_selection rsel;
608 struct ieee80211_supported_band *sband;
609
610 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
588 611
589 if (likely(!tx->u.tx.rate)) { 612 if (likely(!tx->rate)) {
590 rate_control_get_rate(tx->dev, tx->u.tx.mode, tx->skb, &rsel); 613 rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
591 tx->u.tx.rate = rsel.rate; 614 tx->rate = rsel.rate;
592 if (unlikely(rsel.probe != NULL)) { 615 if (unlikely(rsel.probe)) {
593 tx->u.tx.control->flags |= 616 tx->control->flags |=
594 IEEE80211_TXCTL_RATE_CTRL_PROBE; 617 IEEE80211_TXCTL_RATE_CTRL_PROBE;
595 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 618 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
596 tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val; 619 tx->control->alt_retry_rate = tx->rate;
597 tx->u.tx.rate = rsel.probe; 620 tx->rate = rsel.probe;
598 } else 621 } else
599 tx->u.tx.control->alt_retry_rate = -1; 622 tx->control->alt_retry_rate = NULL;
600 623
601 if (!tx->u.tx.rate) 624 if (!tx->rate)
602 return TXRX_DROP; 625 return TX_DROP;
603 } else 626 } else
604 tx->u.tx.control->alt_retry_rate = -1; 627 tx->control->alt_retry_rate = NULL;
605 628
606 if (tx->u.tx.mode->mode == MODE_IEEE80211G && 629 if (tx->sdata->bss_conf.use_cts_prot &&
607 tx->sdata->bss_conf.use_cts_prot && 630 (tx->flags & IEEE80211_TX_FRAGMENTED) && rsel.nonerp) {
608 (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && rsel.nonerp) { 631 tx->last_frag_rate = tx->rate;
609 tx->u.tx.last_frag_rate = tx->u.tx.rate;
610 if (rsel.probe) 632 if (rsel.probe)
611 tx->flags &= ~IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 633 tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG;
612 else 634 else
613 tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 635 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
614 tx->u.tx.rate = rsel.nonerp; 636 tx->rate = rsel.nonerp;
615 tx->u.tx.control->rate = rsel.nonerp; 637 tx->control->tx_rate = rsel.nonerp;
616 tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE; 638 tx->control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
617 } else { 639 } else {
618 tx->u.tx.last_frag_rate = tx->u.tx.rate; 640 tx->last_frag_rate = tx->rate;
619 tx->u.tx.control->rate = tx->u.tx.rate; 641 tx->control->tx_rate = tx->rate;
620 } 642 }
621 tx->u.tx.control->tx_rate = tx->u.tx.rate->val; 643 tx->control->tx_rate = tx->rate;
622 644
623 return TXRX_CONTINUE; 645 return TX_CONTINUE;
624} 646}
625 647
626static ieee80211_txrx_result 648static ieee80211_tx_result
627ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx) 649ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
628{ 650{
629 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; 651 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
630 u16 fc = le16_to_cpu(hdr->frame_control); 652 u16 fc = le16_to_cpu(hdr->frame_control);
631 u16 dur; 653 u16 dur;
632 struct ieee80211_tx_control *control = tx->u.tx.control; 654 struct ieee80211_tx_control *control = tx->control;
633 struct ieee80211_hw_mode *mode = tx->u.tx.mode;
634 655
635 if (!control->retry_limit) { 656 if (!control->retry_limit) {
636 if (!is_multicast_ether_addr(hdr->addr1)) { 657 if (!is_multicast_ether_addr(hdr->addr1)) {
@@ -652,20 +673,20 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
652 } 673 }
653 } 674 }
654 675
655 if (tx->flags & IEEE80211_TXRXD_FRAGMENTED) { 676 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
656 /* Do not use multiple retry rates when sending fragmented 677 /* Do not use multiple retry rates when sending fragmented
657 * frames. 678 * frames.
658 * TODO: The last fragment could still use multiple retry 679 * TODO: The last fragment could still use multiple retry
659 * rates. */ 680 * rates. */
660 control->alt_retry_rate = -1; 681 control->alt_retry_rate = NULL;
661 } 682 }
662 683
663 /* Use CTS protection for unicast frames sent using extended rates if 684 /* Use CTS protection for unicast frames sent using extended rates if
664 * there are associated non-ERP stations and RTS/CTS is not configured 685 * there are associated non-ERP stations and RTS/CTS is not configured
665 * for the frame. */ 686 * for the frame. */
666 if (mode->mode == MODE_IEEE80211G && 687 if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) &&
667 (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) && 688 (tx->rate->flags & IEEE80211_RATE_ERP_G) &&
668 (tx->flags & IEEE80211_TXRXD_TXUNICAST) && 689 (tx->flags & IEEE80211_TX_UNICAST) &&
669 tx->sdata->bss_conf.use_cts_prot && 690 tx->sdata->bss_conf.use_cts_prot &&
670 !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS)) 691 !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
671 control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT; 692 control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
@@ -674,62 +695,76 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
674 * short preambles at the selected rate and short preambles are 695 * short preambles at the selected rate and short preambles are
675 * available on the network at the current point in time. */ 696 * available on the network at the current point in time. */
676 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && 697 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
677 (tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) && 698 (tx->rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
678 tx->sdata->bss_conf.use_short_preamble && 699 tx->sdata->bss_conf.use_short_preamble &&
679 (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) { 700 (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
680 tx->u.tx.control->tx_rate = tx->u.tx.rate->val2; 701 tx->control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
681 } 702 }
682 703
683 /* Setup duration field for the first fragment of the frame. Duration 704 /* Setup duration field for the first fragment of the frame. Duration
684 * for remaining fragments will be updated when they are being sent 705 * for remaining fragments will be updated when they are being sent
685 * to low-level driver in ieee80211_tx(). */ 706 * to low-level driver in ieee80211_tx(). */
686 dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1), 707 dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1),
687 (tx->flags & IEEE80211_TXRXD_FRAGMENTED) ? 708 (tx->flags & IEEE80211_TX_FRAGMENTED) ?
688 tx->u.tx.extra_frag[0]->len : 0); 709 tx->extra_frag[0]->len : 0);
689 hdr->duration_id = cpu_to_le16(dur); 710 hdr->duration_id = cpu_to_le16(dur);
690 711
691 if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) || 712 if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
692 (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) { 713 (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
693 struct ieee80211_rate *rate; 714 struct ieee80211_supported_band *sband;
715 struct ieee80211_rate *rate, *baserate;
716 int idx;
717
718 sband = tx->local->hw.wiphy->bands[
719 tx->local->hw.conf.channel->band];
694 720
695 /* Do not use multiple retry rates when using RTS/CTS */ 721 /* Do not use multiple retry rates when using RTS/CTS */
696 control->alt_retry_rate = -1; 722 control->alt_retry_rate = NULL;
697 723
698 /* Use min(data rate, max base rate) as CTS/RTS rate */ 724 /* Use min(data rate, max base rate) as CTS/RTS rate */
699 rate = tx->u.tx.rate; 725 rate = tx->rate;
700 while (rate > mode->rates && 726 baserate = NULL;
701 !(rate->flags & IEEE80211_RATE_BASIC)) 727
702 rate--; 728 for (idx = 0; idx < sband->n_bitrates; idx++) {
729 if (sband->bitrates[idx].bitrate > rate->bitrate)
730 continue;
731 if (tx->sdata->basic_rates & BIT(idx) &&
732 (!baserate ||
733 (baserate->bitrate < sband->bitrates[idx].bitrate)))
734 baserate = &sband->bitrates[idx];
735 }
703 736
704 control->rts_cts_rate = rate->val; 737 if (baserate)
705 control->rts_rate = rate; 738 control->rts_cts_rate = baserate;
739 else
740 control->rts_cts_rate = &sband->bitrates[0];
706 } 741 }
707 742
708 if (tx->sta) { 743 if (tx->sta) {
709 tx->sta->tx_packets++; 744 tx->sta->tx_packets++;
710 tx->sta->tx_fragments++; 745 tx->sta->tx_fragments++;
711 tx->sta->tx_bytes += tx->skb->len; 746 tx->sta->tx_bytes += tx->skb->len;
712 if (tx->u.tx.extra_frag) { 747 if (tx->extra_frag) {
713 int i; 748 int i;
714 tx->sta->tx_fragments += tx->u.tx.num_extra_frag; 749 tx->sta->tx_fragments += tx->num_extra_frag;
715 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 750 for (i = 0; i < tx->num_extra_frag; i++) {
716 tx->sta->tx_bytes += 751 tx->sta->tx_bytes +=
717 tx->u.tx.extra_frag[i]->len; 752 tx->extra_frag[i]->len;
718 } 753 }
719 } 754 }
720 } 755 }
721 756
722 return TXRX_CONTINUE; 757 return TX_CONTINUE;
723} 758}
724 759
725static ieee80211_txrx_result 760static ieee80211_tx_result
726ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx) 761ieee80211_tx_h_load_stats(struct ieee80211_tx_data *tx)
727{ 762{
728 struct ieee80211_local *local = tx->local; 763 struct ieee80211_local *local = tx->local;
729 struct ieee80211_hw_mode *mode = tx->u.tx.mode;
730 struct sk_buff *skb = tx->skb; 764 struct sk_buff *skb = tx->skb;
731 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 765 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
732 u32 load = 0, hdrtime; 766 u32 load = 0, hdrtime;
767 struct ieee80211_rate *rate = tx->rate;
733 768
734 /* TODO: this could be part of tx_status handling, so that the number 769 /* TODO: this could be part of tx_status handling, so that the number
735 * of retries would be known; TX rate should in that case be stored 770 * of retries would be known; TX rate should in that case be stored
@@ -740,9 +775,9 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
740 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, 775 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
741 * 1 usec = 1/8 * (1080 / 10) = 13.5 */ 776 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
742 777
743 if (mode->mode == MODE_IEEE80211A || 778 if (tx->channel->band == IEEE80211_BAND_5GHZ ||
744 (mode->mode == MODE_IEEE80211G && 779 (tx->channel->band == IEEE80211_BAND_2GHZ &&
745 tx->u.tx.rate->flags & IEEE80211_RATE_ERP)) 780 rate->flags & IEEE80211_RATE_ERP_G))
746 hdrtime = CHAN_UTIL_HDR_SHORT; 781 hdrtime = CHAN_UTIL_HDR_SHORT;
747 else 782 else
748 hdrtime = CHAN_UTIL_HDR_LONG; 783 hdrtime = CHAN_UTIL_HDR_LONG;
@@ -751,19 +786,20 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
751 if (!is_multicast_ether_addr(hdr->addr1)) 786 if (!is_multicast_ether_addr(hdr->addr1))
752 load += hdrtime; 787 load += hdrtime;
753 788
754 if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_RTS_CTS) 789 if (tx->control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
755 load += 2 * hdrtime; 790 load += 2 * hdrtime;
756 else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) 791 else if (tx->control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
757 load += hdrtime; 792 load += hdrtime;
758 793
759 load += skb->len * tx->u.tx.rate->rate_inv; 794 /* TODO: optimise again */
795 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
760 796
761 if (tx->u.tx.extra_frag) { 797 if (tx->extra_frag) {
762 int i; 798 int i;
763 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 799 for (i = 0; i < tx->num_extra_frag; i++) {
764 load += 2 * hdrtime; 800 load += 2 * hdrtime;
765 load += tx->u.tx.extra_frag[i]->len * 801 load += tx->extra_frag[i]->len *
766 tx->u.tx.rate->rate; 802 tx->rate->bitrate;
767 } 803 }
768 } 804 }
769 805
@@ -774,13 +810,12 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
774 tx->sta->channel_use_raw += load; 810 tx->sta->channel_use_raw += load;
775 tx->sdata->channel_use_raw += load; 811 tx->sdata->channel_use_raw += load;
776 812
777 return TXRX_CONTINUE; 813 return TX_CONTINUE;
778} 814}
779 815
780/* TODO: implement register/unregister functions for adding TX/RX handlers
781 * into ordered list */
782 816
783ieee80211_tx_handler ieee80211_tx_handlers[] = 817typedef ieee80211_tx_result (*ieee80211_tx_handler)(struct ieee80211_tx_data *);
818static ieee80211_tx_handler ieee80211_tx_handlers[] =
784{ 819{
785 ieee80211_tx_h_check_assoc, 820 ieee80211_tx_h_check_assoc,
786 ieee80211_tx_h_sequence, 821 ieee80211_tx_h_sequence,
@@ -801,8 +836,8 @@ ieee80211_tx_handler ieee80211_tx_handlers[] =
801 * deal with packet injection down monitor interface 836 * deal with packet injection down monitor interface
802 * with Radiotap Header -- only called for monitor mode interface 837 * with Radiotap Header -- only called for monitor mode interface
803 */ 838 */
804static ieee80211_txrx_result 839static ieee80211_tx_result
805__ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx, 840__ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
806 struct sk_buff *skb) 841 struct sk_buff *skb)
807{ 842{
808 /* 843 /*
@@ -816,13 +851,15 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
816 struct ieee80211_radiotap_iterator iterator; 851 struct ieee80211_radiotap_iterator iterator;
817 struct ieee80211_radiotap_header *rthdr = 852 struct ieee80211_radiotap_header *rthdr =
818 (struct ieee80211_radiotap_header *) skb->data; 853 (struct ieee80211_radiotap_header *) skb->data;
819 struct ieee80211_hw_mode *mode = tx->local->hw.conf.mode; 854 struct ieee80211_supported_band *sband;
820 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); 855 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
821 struct ieee80211_tx_control *control = tx->u.tx.control; 856 struct ieee80211_tx_control *control = tx->control;
857
858 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
822 859
823 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT; 860 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
824 tx->flags |= IEEE80211_TXRXD_TX_INJECTED; 861 tx->flags |= IEEE80211_TX_INJECTED;
825 tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED; 862 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
826 863
827 /* 864 /*
828 * for every radiotap entry that is present 865 * for every radiotap entry that is present
@@ -852,11 +889,13 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
852 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps 889 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
853 */ 890 */
854 target_rate = (*iterator.this_arg) * 5; 891 target_rate = (*iterator.this_arg) * 5;
855 for (i = 0; i < mode->num_rates; i++) { 892 for (i = 0; i < sband->n_bitrates; i++) {
856 struct ieee80211_rate *r = &mode->rates[i]; 893 struct ieee80211_rate *r;
894
895 r = &sband->bitrates[i];
857 896
858 if (r->rate == target_rate) { 897 if (r->bitrate == target_rate) {
859 tx->u.tx.rate = r; 898 tx->rate = r;
860 break; 899 break;
861 } 900 }
862 } 901 }
@@ -870,9 +909,11 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
870 control->antenna_sel_tx = (*iterator.this_arg) + 1; 909 control->antenna_sel_tx = (*iterator.this_arg) + 1;
871 break; 910 break;
872 911
912#if 0
873 case IEEE80211_RADIOTAP_DBM_TX_POWER: 913 case IEEE80211_RADIOTAP_DBM_TX_POWER:
874 control->power_level = *iterator.this_arg; 914 control->power_level = *iterator.this_arg;
875 break; 915 break;
916#endif
876 917
877 case IEEE80211_RADIOTAP_FLAGS: 918 case IEEE80211_RADIOTAP_FLAGS:
878 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { 919 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
@@ -884,7 +925,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
884 * on transmission 925 * on transmission
885 */ 926 */
886 if (skb->len < (iterator.max_length + FCS_LEN)) 927 if (skb->len < (iterator.max_length + FCS_LEN))
887 return TXRX_DROP; 928 return TX_DROP;
888 929
889 skb_trim(skb, skb->len - FCS_LEN); 930 skb_trim(skb, skb->len - FCS_LEN);
890 } 931 }
@@ -892,7 +933,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
892 control->flags &= 933 control->flags &=
893 ~IEEE80211_TXCTL_DO_NOT_ENCRYPT; 934 ~IEEE80211_TXCTL_DO_NOT_ENCRYPT;
894 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) 935 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
895 tx->flags |= IEEE80211_TXRXD_FRAGMENTED; 936 tx->flags |= IEEE80211_TX_FRAGMENTED;
896 break; 937 break;
897 938
898 /* 939 /*
@@ -907,7 +948,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
907 } 948 }
908 949
909 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ 950 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
910 return TXRX_DROP; 951 return TX_DROP;
911 952
912 /* 953 /*
913 * remove the radiotap header 954 * remove the radiotap header
@@ -916,14 +957,14 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
916 */ 957 */
917 skb_pull(skb, iterator.max_length); 958 skb_pull(skb, iterator.max_length);
918 959
919 return TXRX_CONTINUE; 960 return TX_CONTINUE;
920} 961}
921 962
922/* 963/*
923 * initialises @tx 964 * initialises @tx
924 */ 965 */
925static ieee80211_txrx_result 966static ieee80211_tx_result
926__ieee80211_tx_prepare(struct ieee80211_txrx_data *tx, 967__ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
927 struct sk_buff *skb, 968 struct sk_buff *skb,
928 struct net_device *dev, 969 struct net_device *dev,
929 struct ieee80211_tx_control *control) 970 struct ieee80211_tx_control *control)
@@ -939,18 +980,18 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
939 tx->dev = dev; /* use original interface */ 980 tx->dev = dev; /* use original interface */
940 tx->local = local; 981 tx->local = local;
941 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev); 982 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
942 tx->u.tx.control = control; 983 tx->control = control;
943 /* 984 /*
944 * Set this flag (used below to indicate "automatic fragmentation"), 985 * Set this flag (used below to indicate "automatic fragmentation"),
945 * it will be cleared/left by radiotap as desired. 986 * it will be cleared/left by radiotap as desired.
946 */ 987 */
947 tx->flags |= IEEE80211_TXRXD_FRAGMENTED; 988 tx->flags |= IEEE80211_TX_FRAGMENTED;
948 989
949 /* process and remove the injection radiotap header */ 990 /* process and remove the injection radiotap header */
950 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 991 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
951 if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) { 992 if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) {
952 if (__ieee80211_parse_tx_radiotap(tx, skb) == TXRX_DROP) 993 if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP)
953 return TXRX_DROP; 994 return TX_DROP;
954 995
955 /* 996 /*
956 * __ieee80211_parse_tx_radiotap has now removed 997 * __ieee80211_parse_tx_radiotap has now removed
@@ -965,27 +1006,27 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
965 tx->fc = le16_to_cpu(hdr->frame_control); 1006 tx->fc = le16_to_cpu(hdr->frame_control);
966 1007
967 if (is_multicast_ether_addr(hdr->addr1)) { 1008 if (is_multicast_ether_addr(hdr->addr1)) {
968 tx->flags &= ~IEEE80211_TXRXD_TXUNICAST; 1009 tx->flags &= ~IEEE80211_TX_UNICAST;
969 control->flags |= IEEE80211_TXCTL_NO_ACK; 1010 control->flags |= IEEE80211_TXCTL_NO_ACK;
970 } else { 1011 } else {
971 tx->flags |= IEEE80211_TXRXD_TXUNICAST; 1012 tx->flags |= IEEE80211_TX_UNICAST;
972 control->flags &= ~IEEE80211_TXCTL_NO_ACK; 1013 control->flags &= ~IEEE80211_TXCTL_NO_ACK;
973 } 1014 }
974 1015
975 if (tx->flags & IEEE80211_TXRXD_FRAGMENTED) { 1016 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
976 if ((tx->flags & IEEE80211_TXRXD_TXUNICAST) && 1017 if ((tx->flags & IEEE80211_TX_UNICAST) &&
977 skb->len + FCS_LEN > local->fragmentation_threshold && 1018 skb->len + FCS_LEN > local->fragmentation_threshold &&
978 !local->ops->set_frag_threshold) 1019 !local->ops->set_frag_threshold)
979 tx->flags |= IEEE80211_TXRXD_FRAGMENTED; 1020 tx->flags |= IEEE80211_TX_FRAGMENTED;
980 else 1021 else
981 tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED; 1022 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
982 } 1023 }
983 1024
984 if (!tx->sta) 1025 if (!tx->sta)
985 control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK; 1026 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
986 else if (tx->sta->clear_dst_mask) { 1027 else if (tx->sta->flags & WLAN_STA_CLEAR_PS_FILT) {
987 control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK; 1028 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
988 tx->sta->clear_dst_mask = 0; 1029 tx->sta->flags &= ~WLAN_STA_CLEAR_PS_FILT;
989 } 1030 }
990 1031
991 hdrlen = ieee80211_get_hdrlen(tx->fc); 1032 hdrlen = ieee80211_get_hdrlen(tx->fc);
@@ -995,13 +1036,13 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
995 } 1036 }
996 control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT; 1037 control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
997 1038
998 return TXRX_CONTINUE; 1039 return TX_CONTINUE;
999} 1040}
1000 1041
1001/* 1042/*
1002 * NB: @tx is uninitialised when passed in here 1043 * NB: @tx is uninitialised when passed in here
1003 */ 1044 */
1004static int ieee80211_tx_prepare(struct ieee80211_txrx_data *tx, 1045static int ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1005 struct sk_buff *skb, 1046 struct sk_buff *skb,
1006 struct net_device *mdev, 1047 struct net_device *mdev,
1007 struct ieee80211_tx_control *control) 1048 struct ieee80211_tx_control *control)
@@ -1024,9 +1065,9 @@ static int ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
1024} 1065}
1025 1066
1026static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb, 1067static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1027 struct ieee80211_txrx_data *tx) 1068 struct ieee80211_tx_data *tx)
1028{ 1069{
1029 struct ieee80211_tx_control *control = tx->u.tx.control; 1070 struct ieee80211_tx_control *control = tx->control;
1030 int ret, i; 1071 int ret, i;
1031 1072
1032 if (!ieee80211_qdisc_installed(local->mdev) && 1073 if (!ieee80211_qdisc_installed(local->mdev) &&
@@ -1043,20 +1084,20 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1043 local->mdev->trans_start = jiffies; 1084 local->mdev->trans_start = jiffies;
1044 ieee80211_led_tx(local, 1); 1085 ieee80211_led_tx(local, 1);
1045 } 1086 }
1046 if (tx->u.tx.extra_frag) { 1087 if (tx->extra_frag) {
1047 control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS | 1088 control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
1048 IEEE80211_TXCTL_USE_CTS_PROTECT | 1089 IEEE80211_TXCTL_USE_CTS_PROTECT |
1049 IEEE80211_TXCTL_CLEAR_DST_MASK | 1090 IEEE80211_TXCTL_CLEAR_PS_FILT |
1050 IEEE80211_TXCTL_FIRST_FRAGMENT); 1091 IEEE80211_TXCTL_FIRST_FRAGMENT);
1051 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 1092 for (i = 0; i < tx->num_extra_frag; i++) {
1052 if (!tx->u.tx.extra_frag[i]) 1093 if (!tx->extra_frag[i])
1053 continue; 1094 continue;
1054 if (__ieee80211_queue_stopped(local, control->queue)) 1095 if (__ieee80211_queue_stopped(local, control->queue))
1055 return IEEE80211_TX_FRAG_AGAIN; 1096 return IEEE80211_TX_FRAG_AGAIN;
1056 if (i == tx->u.tx.num_extra_frag) { 1097 if (i == tx->num_extra_frag) {
1057 control->tx_rate = tx->u.tx.last_frag_hwrate; 1098 control->tx_rate = tx->last_frag_rate;
1058 control->rate = tx->u.tx.last_frag_rate; 1099
1059 if (tx->flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG) 1100 if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG)
1060 control->flags |= 1101 control->flags |=
1061 IEEE80211_TXCTL_RATE_CTRL_PROBE; 1102 IEEE80211_TXCTL_RATE_CTRL_PROBE;
1062 else 1103 else
@@ -1066,18 +1107,18 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
1066 1107
1067 ieee80211_dump_frame(wiphy_name(local->hw.wiphy), 1108 ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
1068 "TX to low-level driver", 1109 "TX to low-level driver",
1069 tx->u.tx.extra_frag[i]); 1110 tx->extra_frag[i]);
1070 ret = local->ops->tx(local_to_hw(local), 1111 ret = local->ops->tx(local_to_hw(local),
1071 tx->u.tx.extra_frag[i], 1112 tx->extra_frag[i],
1072 control); 1113 control);
1073 if (ret) 1114 if (ret)
1074 return IEEE80211_TX_FRAG_AGAIN; 1115 return IEEE80211_TX_FRAG_AGAIN;
1075 local->mdev->trans_start = jiffies; 1116 local->mdev->trans_start = jiffies;
1076 ieee80211_led_tx(local, 1); 1117 ieee80211_led_tx(local, 1);
1077 tx->u.tx.extra_frag[i] = NULL; 1118 tx->extra_frag[i] = NULL;
1078 } 1119 }
1079 kfree(tx->u.tx.extra_frag); 1120 kfree(tx->extra_frag);
1080 tx->u.tx.extra_frag = NULL; 1121 tx->extra_frag = NULL;
1081 } 1122 }
1082 return IEEE80211_TX_OK; 1123 return IEEE80211_TX_OK;
1083} 1124}
@@ -1088,8 +1129,8 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1088 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1129 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1089 struct sta_info *sta; 1130 struct sta_info *sta;
1090 ieee80211_tx_handler *handler; 1131 ieee80211_tx_handler *handler;
1091 struct ieee80211_txrx_data tx; 1132 struct ieee80211_tx_data tx;
1092 ieee80211_txrx_result res = TXRX_DROP, res_prepare; 1133 ieee80211_tx_result res = TX_DROP, res_prepare;
1093 int ret, i; 1134 int ret, i;
1094 1135
1095 WARN_ON(__ieee80211_queue_pending(local, control->queue)); 1136 WARN_ON(__ieee80211_queue_pending(local, control->queue));
@@ -1099,59 +1140,52 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1099 return 0; 1140 return 0;
1100 } 1141 }
1101 1142
1143 rcu_read_lock();
1144
1102 /* initialises tx */ 1145 /* initialises tx */
1103 res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control); 1146 res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control);
1104 1147
1105 if (res_prepare == TXRX_DROP) { 1148 if (res_prepare == TX_DROP) {
1106 dev_kfree_skb(skb); 1149 dev_kfree_skb(skb);
1150 rcu_read_unlock();
1107 return 0; 1151 return 0;
1108 } 1152 }
1109 1153
1110 /*
1111 * key references are protected using RCU and this requires that
1112 * we are in a read-site RCU section during receive processing
1113 */
1114 rcu_read_lock();
1115
1116 sta = tx.sta; 1154 sta = tx.sta;
1117 tx.u.tx.mode = local->hw.conf.mode; 1155 tx.channel = local->hw.conf.channel;
1118 1156
1119 for (handler = local->tx_handlers; *handler != NULL; 1157 for (handler = ieee80211_tx_handlers; *handler != NULL;
1120 handler++) { 1158 handler++) {
1121 res = (*handler)(&tx); 1159 res = (*handler)(&tx);
1122 if (res != TXRX_CONTINUE) 1160 if (res != TX_CONTINUE)
1123 break; 1161 break;
1124 } 1162 }
1125 1163
1126 skb = tx.skb; /* handlers are allowed to change skb */ 1164 skb = tx.skb; /* handlers are allowed to change skb */
1127 1165
1128 if (sta) 1166 if (unlikely(res == TX_DROP)) {
1129 sta_info_put(sta);
1130
1131 if (unlikely(res == TXRX_DROP)) {
1132 I802_DEBUG_INC(local->tx_handlers_drop); 1167 I802_DEBUG_INC(local->tx_handlers_drop);
1133 goto drop; 1168 goto drop;
1134 } 1169 }
1135 1170
1136 if (unlikely(res == TXRX_QUEUED)) { 1171 if (unlikely(res == TX_QUEUED)) {
1137 I802_DEBUG_INC(local->tx_handlers_queued); 1172 I802_DEBUG_INC(local->tx_handlers_queued);
1138 rcu_read_unlock(); 1173 rcu_read_unlock();
1139 return 0; 1174 return 0;
1140 } 1175 }
1141 1176
1142 if (tx.u.tx.extra_frag) { 1177 if (tx.extra_frag) {
1143 for (i = 0; i < tx.u.tx.num_extra_frag; i++) { 1178 for (i = 0; i < tx.num_extra_frag; i++) {
1144 int next_len, dur; 1179 int next_len, dur;
1145 struct ieee80211_hdr *hdr = 1180 struct ieee80211_hdr *hdr =
1146 (struct ieee80211_hdr *) 1181 (struct ieee80211_hdr *)
1147 tx.u.tx.extra_frag[i]->data; 1182 tx.extra_frag[i]->data;
1148 1183
1149 if (i + 1 < tx.u.tx.num_extra_frag) { 1184 if (i + 1 < tx.num_extra_frag) {
1150 next_len = tx.u.tx.extra_frag[i + 1]->len; 1185 next_len = tx.extra_frag[i + 1]->len;
1151 } else { 1186 } else {
1152 next_len = 0; 1187 next_len = 0;
1153 tx.u.tx.rate = tx.u.tx.last_frag_rate; 1188 tx.rate = tx.last_frag_rate;
1154 tx.u.tx.last_frag_hwrate = tx.u.tx.rate->val;
1155 } 1189 }
1156 dur = ieee80211_duration(&tx, 0, next_len); 1190 dur = ieee80211_duration(&tx, 0, next_len);
1157 hdr->duration_id = cpu_to_le16(dur); 1191 hdr->duration_id = cpu_to_le16(dur);
@@ -1186,12 +1220,11 @@ retry:
1186 memcpy(&store->control, control, 1220 memcpy(&store->control, control,
1187 sizeof(struct ieee80211_tx_control)); 1221 sizeof(struct ieee80211_tx_control));
1188 store->skb = skb; 1222 store->skb = skb;
1189 store->extra_frag = tx.u.tx.extra_frag; 1223 store->extra_frag = tx.extra_frag;
1190 store->num_extra_frag = tx.u.tx.num_extra_frag; 1224 store->num_extra_frag = tx.num_extra_frag;
1191 store->last_frag_hwrate = tx.u.tx.last_frag_hwrate; 1225 store->last_frag_rate = tx.last_frag_rate;
1192 store->last_frag_rate = tx.u.tx.last_frag_rate;
1193 store->last_frag_rate_ctrl_probe = 1226 store->last_frag_rate_ctrl_probe =
1194 !!(tx.flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG); 1227 !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG);
1195 } 1228 }
1196 rcu_read_unlock(); 1229 rcu_read_unlock();
1197 return 0; 1230 return 0;
@@ -1199,10 +1232,10 @@ retry:
1199 drop: 1232 drop:
1200 if (skb) 1233 if (skb)
1201 dev_kfree_skb(skb); 1234 dev_kfree_skb(skb);
1202 for (i = 0; i < tx.u.tx.num_extra_frag; i++) 1235 for (i = 0; i < tx.num_extra_frag; i++)
1203 if (tx.u.tx.extra_frag[i]) 1236 if (tx.extra_frag[i])
1204 dev_kfree_skb(tx.u.tx.extra_frag[i]); 1237 dev_kfree_skb(tx.extra_frag[i]);
1205 kfree(tx.u.tx.extra_frag); 1238 kfree(tx.extra_frag);
1206 rcu_read_unlock(); 1239 rcu_read_unlock();
1207 return 0; 1240 return 0;
1208} 1241}
@@ -1260,6 +1293,8 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
1260 control.flags |= IEEE80211_TXCTL_REQUEUE; 1293 control.flags |= IEEE80211_TXCTL_REQUEUE;
1261 if (pkt_data->flags & IEEE80211_TXPD_EAPOL_FRAME) 1294 if (pkt_data->flags & IEEE80211_TXPD_EAPOL_FRAME)
1262 control.flags |= IEEE80211_TXCTL_EAPOL_FRAME; 1295 control.flags |= IEEE80211_TXCTL_EAPOL_FRAME;
1296 if (pkt_data->flags & IEEE80211_TXPD_AMPDU)
1297 control.flags |= IEEE80211_TXCTL_AMPDU;
1263 control.queue = pkt_data->queue; 1298 control.queue = pkt_data->queue;
1264 1299
1265 ret = ieee80211_tx(odev, skb, &control); 1300 ret = ieee80211_tx(odev, skb, &control);
@@ -1346,8 +1381,9 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1346 struct ieee80211_tx_packet_data *pkt_data; 1381 struct ieee80211_tx_packet_data *pkt_data;
1347 struct ieee80211_sub_if_data *sdata; 1382 struct ieee80211_sub_if_data *sdata;
1348 int ret = 1, head_need; 1383 int ret = 1, head_need;
1349 u16 ethertype, hdrlen, fc; 1384 u16 ethertype, hdrlen, meshhdrlen = 0, fc;
1350 struct ieee80211_hdr hdr; 1385 struct ieee80211_hdr hdr;
1386 struct ieee80211s_hdr mesh_hdr;
1351 const u8 *encaps_data; 1387 const u8 *encaps_data;
1352 int encaps_len, skip_header_bytes; 1388 int encaps_len, skip_header_bytes;
1353 int nh_pos, h_pos; 1389 int nh_pos, h_pos;
@@ -1389,6 +1425,37 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1389 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); 1425 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1390 hdrlen = 30; 1426 hdrlen = 30;
1391 break; 1427 break;
1428#ifdef CONFIG_MAC80211_MESH
1429 case IEEE80211_IF_TYPE_MESH_POINT:
1430 fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
1431 /* RA TA DA SA */
1432 if (is_multicast_ether_addr(skb->data))
1433 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1434 else if (mesh_nexthop_lookup(hdr.addr1, skb, dev))
1435 return 0;
1436 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1437 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1438 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1439 if (skb->pkt_type == PACKET_OTHERHOST) {
1440 /* Forwarded frame, keep mesh ttl and seqnum */
1441 struct ieee80211s_hdr *prev_meshhdr;
1442 prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb);
1443 meshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr);
1444 memcpy(&mesh_hdr, prev_meshhdr, meshhdrlen);
1445 sdata->u.sta.mshstats.fwded_frames++;
1446 } else {
1447 if (!sdata->u.sta.mshcfg.dot11MeshTTL) {
1448 /* Do not send frames with mesh_ttl == 0 */
1449 sdata->u.sta.mshstats.dropped_frames_ttl++;
1450 ret = 0;
1451 goto fail;
1452 }
1453 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
1454 sdata);
1455 }
1456 hdrlen = 30;
1457 break;
1458#endif
1392 case IEEE80211_IF_TYPE_STA: 1459 case IEEE80211_IF_TYPE_STA:
1393 fc |= IEEE80211_FCTL_TODS; 1460 fc |= IEEE80211_FCTL_TODS;
1394 /* BSSID SA DA */ 1461 /* BSSID SA DA */
@@ -1409,10 +1476,17 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1409 goto fail; 1476 goto fail;
1410 } 1477 }
1411 1478
1412 sta = sta_info_get(local, hdr.addr1); 1479 /*
1413 if (sta) { 1480 * There's no need to try to look up the destination
1414 sta_flags = sta->flags; 1481 * if it is a multicast address (which can only happen
1415 sta_info_put(sta); 1482 * in AP mode)
1483 */
1484 if (!is_multicast_ether_addr(hdr.addr1)) {
1485 rcu_read_lock();
1486 sta = sta_info_get(local, hdr.addr1);
1487 if (sta)
1488 sta_flags = sta->flags;
1489 rcu_read_unlock();
1416 } 1490 }
1417 1491
1418 /* receiver is QoS enabled, use a QoS type frame */ 1492 /* receiver is QoS enabled, use a QoS type frame */
@@ -1422,12 +1496,12 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1422 } 1496 }
1423 1497
1424 /* 1498 /*
1425 * If port access control is enabled, drop frames to unauthorised 1499 * Drop unicast frames to unauthorised stations unless they are
1426 * stations unless they are EAPOL frames from the local station. 1500 * EAPOL frames from the local station.
1427 */ 1501 */
1428 if (unlikely(sdata->ieee802_1x_pac && 1502 if (unlikely(!is_multicast_ether_addr(hdr.addr1) &&
1429 !(sta_flags & WLAN_STA_AUTHORIZED) && 1503 !(sta_flags & WLAN_STA_AUTHORIZED) &&
1430 !(ethertype == ETH_P_PAE && 1504 !(ethertype == ETH_P_PAE &&
1431 compare_ether_addr(dev->dev_addr, 1505 compare_ether_addr(dev->dev_addr,
1432 skb->data + ETH_ALEN) == 0))) { 1506 skb->data + ETH_ALEN) == 0))) {
1433#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1507#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -1480,7 +1554,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1480 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and 1554 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1481 * alloc_skb() (net/core/skbuff.c) 1555 * alloc_skb() (net/core/skbuff.c)
1482 */ 1556 */
1483 head_need = hdrlen + encaps_len + local->tx_headroom; 1557 head_need = hdrlen + encaps_len + meshhdrlen + local->tx_headroom;
1484 head_need -= skb_headroom(skb); 1558 head_need -= skb_headroom(skb);
1485 1559
1486 /* We are going to modify skb data, so make a copy of it if happens to 1560 /* We are going to modify skb data, so make a copy of it if happens to
@@ -1514,6 +1588,12 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1514 h_pos += encaps_len; 1588 h_pos += encaps_len;
1515 } 1589 }
1516 1590
1591 if (meshhdrlen > 0) {
1592 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
1593 nh_pos += meshhdrlen;
1594 h_pos += meshhdrlen;
1595 }
1596
1517 if (fc & IEEE80211_STYPE_QOS_DATA) { 1597 if (fc & IEEE80211_STYPE_QOS_DATA) {
1518 __le16 *qos_control; 1598 __le16 *qos_control;
1519 1599
@@ -1583,7 +1663,7 @@ void ieee80211_tx_pending(unsigned long data)
1583 struct ieee80211_local *local = (struct ieee80211_local *)data; 1663 struct ieee80211_local *local = (struct ieee80211_local *)data;
1584 struct net_device *dev = local->mdev; 1664 struct net_device *dev = local->mdev;
1585 struct ieee80211_tx_stored_packet *store; 1665 struct ieee80211_tx_stored_packet *store;
1586 struct ieee80211_txrx_data tx; 1666 struct ieee80211_tx_data tx;
1587 int i, ret, reschedule = 0; 1667 int i, ret, reschedule = 0;
1588 1668
1589 netif_tx_lock_bh(dev); 1669 netif_tx_lock_bh(dev);
@@ -1595,14 +1675,13 @@ void ieee80211_tx_pending(unsigned long data)
1595 continue; 1675 continue;
1596 } 1676 }
1597 store = &local->pending_packet[i]; 1677 store = &local->pending_packet[i];
1598 tx.u.tx.control = &store->control; 1678 tx.control = &store->control;
1599 tx.u.tx.extra_frag = store->extra_frag; 1679 tx.extra_frag = store->extra_frag;
1600 tx.u.tx.num_extra_frag = store->num_extra_frag; 1680 tx.num_extra_frag = store->num_extra_frag;
1601 tx.u.tx.last_frag_hwrate = store->last_frag_hwrate; 1681 tx.last_frag_rate = store->last_frag_rate;
1602 tx.u.tx.last_frag_rate = store->last_frag_rate;
1603 tx.flags = 0; 1682 tx.flags = 0;
1604 if (store->last_frag_rate_ctrl_probe) 1683 if (store->last_frag_rate_ctrl_probe)
1605 tx.flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG; 1684 tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG;
1606 ret = __ieee80211_tx(local, store->skb, &tx); 1685 ret = __ieee80211_tx(local, store->skb, &tx);
1607 if (ret) { 1686 if (ret) {
1608 if (ret == IEEE80211_TX_FRAG_AGAIN) 1687 if (ret == IEEE80211_TX_FRAG_AGAIN)
@@ -1636,7 +1715,6 @@ static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
1636 1715
1637 /* Generate bitmap for TIM only if there are any STAs in power save 1716 /* Generate bitmap for TIM only if there are any STAs in power save
1638 * mode. */ 1717 * mode. */
1639 read_lock_bh(&local->sta_lock);
1640 if (atomic_read(&bss->num_sta_ps) > 0) 1718 if (atomic_read(&bss->num_sta_ps) > 0)
1641 /* in the hope that this is faster than 1719 /* in the hope that this is faster than
1642 * checking byte-for-byte */ 1720 * checking byte-for-byte */
@@ -1687,7 +1765,6 @@ static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
1687 *pos++ = aid0; /* Bitmap control */ 1765 *pos++ = aid0; /* Bitmap control */
1688 *pos++ = 0; /* Part Virt Bitmap */ 1766 *pos++ = 0; /* Part Virt Bitmap */
1689 } 1767 }
1690 read_unlock_bh(&local->sta_lock);
1691} 1768}
1692 1769
1693struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, 1770struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
@@ -1701,16 +1778,96 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1701 struct ieee80211_if_ap *ap = NULL; 1778 struct ieee80211_if_ap *ap = NULL;
1702 struct rate_selection rsel; 1779 struct rate_selection rsel;
1703 struct beacon_data *beacon; 1780 struct beacon_data *beacon;
1781 struct ieee80211_supported_band *sband;
1782 struct ieee80211_mgmt *mgmt;
1783 int *num_beacons;
1784 bool err = true;
1785 u8 *pos;
1786
1787 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1704 1788
1705 rcu_read_lock(); 1789 rcu_read_lock();
1706 1790
1707 sdata = vif_to_sdata(vif); 1791 sdata = vif_to_sdata(vif);
1708 bdev = sdata->dev; 1792 bdev = sdata->dev;
1709 ap = &sdata->u.ap;
1710 1793
1711 beacon = rcu_dereference(ap->beacon); 1794 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
1795 ap = &sdata->u.ap;
1796 beacon = rcu_dereference(ap->beacon);
1797 if (ap && beacon) {
1798 /*
1799 * headroom, head length,
1800 * tail length and maximum TIM length
1801 */
1802 skb = dev_alloc_skb(local->tx_headroom +
1803 beacon->head_len +
1804 beacon->tail_len + 256);
1805 if (!skb)
1806 goto out;
1807
1808 skb_reserve(skb, local->tx_headroom);
1809 memcpy(skb_put(skb, beacon->head_len), beacon->head,
1810 beacon->head_len);
1811
1812 ieee80211_include_sequence(sdata,
1813 (struct ieee80211_hdr *)skb->data);
1814
1815 /*
1816 * Not very nice, but we want to allow the driver to call
1817 * ieee80211_beacon_get() as a response to the set_tim()
1818 * callback. That, however, is already invoked under the
1819 * sta_lock to guarantee consistent and race-free update
1820 * of the tim bitmap in mac80211 and the driver.
1821 */
1822 if (local->tim_in_locked_section) {
1823 ieee80211_beacon_add_tim(local, ap, skb, beacon);
1824 } else {
1825 unsigned long flags;
1826
1827 spin_lock_irqsave(&local->sta_lock, flags);
1828 ieee80211_beacon_add_tim(local, ap, skb, beacon);
1829 spin_unlock_irqrestore(&local->sta_lock, flags);
1830 }
1831
1832 if (beacon->tail)
1833 memcpy(skb_put(skb, beacon->tail_len),
1834 beacon->tail, beacon->tail_len);
1712 1835
1713 if (!ap || sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon) { 1836 num_beacons = &ap->num_beacons;
1837
1838 err = false;
1839 }
1840 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
1841 /* headroom, head length, tail length and maximum TIM length */
1842 skb = dev_alloc_skb(local->tx_headroom + 400);
1843 if (!skb)
1844 goto out;
1845
1846 skb_reserve(skb, local->hw.extra_tx_headroom);
1847 mgmt = (struct ieee80211_mgmt *)
1848 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
1849 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
1850 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1851 IEEE80211_STYPE_BEACON);
1852 memset(mgmt->da, 0xff, ETH_ALEN);
1853 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
1854 /* BSSID is left zeroed, wildcard value */
1855 mgmt->u.beacon.beacon_int =
1856 cpu_to_le16(local->hw.conf.beacon_int);
1857 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
1858
1859 pos = skb_put(skb, 2);
1860 *pos++ = WLAN_EID_SSID;
1861 *pos++ = 0x0;
1862
1863 mesh_mgmt_ies_add(skb, sdata->dev);
1864
1865 num_beacons = &sdata->u.sta.num_beacons;
1866
1867 err = false;
1868 }
1869
1870 if (err) {
1714#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1871#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1715 if (net_ratelimit()) 1872 if (net_ratelimit())
1716 printk(KERN_DEBUG "no beacon data avail for %s\n", 1873 printk(KERN_DEBUG "no beacon data avail for %s\n",
@@ -1720,27 +1877,8 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1720 goto out; 1877 goto out;
1721 } 1878 }
1722 1879
1723 /* headroom, head length, tail length and maximum TIM length */
1724 skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
1725 beacon->tail_len + 256);
1726 if (!skb)
1727 goto out;
1728
1729 skb_reserve(skb, local->tx_headroom);
1730 memcpy(skb_put(skb, beacon->head_len), beacon->head,
1731 beacon->head_len);
1732
1733 ieee80211_include_sequence(sdata, (struct ieee80211_hdr *)skb->data);
1734
1735 ieee80211_beacon_add_tim(local, ap, skb, beacon);
1736
1737 if (beacon->tail)
1738 memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
1739 beacon->tail_len);
1740
1741 if (control) { 1880 if (control) {
1742 rate_control_get_rate(local->mdev, local->oper_hw_mode, skb, 1881 rate_control_get_rate(local->mdev, sband, skb, &rsel);
1743 &rsel);
1744 if (!rsel.rate) { 1882 if (!rsel.rate) {
1745 if (net_ratelimit()) { 1883 if (net_ratelimit()) {
1746 printk(KERN_DEBUG "%s: ieee80211_beacon_get: " 1884 printk(KERN_DEBUG "%s: ieee80211_beacon_get: "
@@ -1753,20 +1891,17 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1753 } 1891 }
1754 1892
1755 control->vif = vif; 1893 control->vif = vif;
1756 control->tx_rate = 1894 control->tx_rate = rsel.rate;
1757 (sdata->bss_conf.use_short_preamble && 1895 if (sdata->bss_conf.use_short_preamble &&
1758 (rsel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ? 1896 rsel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
1759 rsel.rate->val2 : rsel.rate->val; 1897 control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
1760 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx; 1898 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
1761 control->power_level = local->hw.conf.power_level;
1762 control->flags |= IEEE80211_TXCTL_NO_ACK; 1899 control->flags |= IEEE80211_TXCTL_NO_ACK;
1763 control->retry_limit = 1; 1900 control->retry_limit = 1;
1764 control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK; 1901 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
1765 } 1902 }
1766 1903 (*num_beacons)++;
1767 ap->num_beacons++; 1904out:
1768
1769 out:
1770 rcu_read_unlock(); 1905 rcu_read_unlock();
1771 return skb; 1906 return skb;
1772} 1907}
@@ -1814,8 +1949,8 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
1814 struct sk_buff *skb; 1949 struct sk_buff *skb;
1815 struct sta_info *sta; 1950 struct sta_info *sta;
1816 ieee80211_tx_handler *handler; 1951 ieee80211_tx_handler *handler;
1817 struct ieee80211_txrx_data tx; 1952 struct ieee80211_tx_data tx;
1818 ieee80211_txrx_result res = TXRX_DROP; 1953 ieee80211_tx_result res = TX_DROP;
1819 struct net_device *bdev; 1954 struct net_device *bdev;
1820 struct ieee80211_sub_if_data *sdata; 1955 struct ieee80211_sub_if_data *sdata;
1821 struct ieee80211_if_ap *bss = NULL; 1956 struct ieee80211_if_ap *bss = NULL;
@@ -1836,7 +1971,6 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
1836 rcu_read_unlock(); 1971 rcu_read_unlock();
1837 return NULL; 1972 return NULL;
1838 } 1973 }
1839 rcu_read_unlock();
1840 1974
1841 if (bss->dtim_count != 0) 1975 if (bss->dtim_count != 0)
1842 return NULL; /* send buffered bc/mc only after DTIM beacon */ 1976 return NULL; /* send buffered bc/mc only after DTIM beacon */
@@ -1862,27 +1996,26 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
1862 dev_kfree_skb_any(skb); 1996 dev_kfree_skb_any(skb);
1863 } 1997 }
1864 sta = tx.sta; 1998 sta = tx.sta;
1865 tx.flags |= IEEE80211_TXRXD_TXPS_BUFFERED; 1999 tx.flags |= IEEE80211_TX_PS_BUFFERED;
1866 tx.u.tx.mode = local->hw.conf.mode; 2000 tx.channel = local->hw.conf.channel;
1867 2001
1868 for (handler = local->tx_handlers; *handler != NULL; handler++) { 2002 for (handler = ieee80211_tx_handlers; *handler != NULL; handler++) {
1869 res = (*handler)(&tx); 2003 res = (*handler)(&tx);
1870 if (res == TXRX_DROP || res == TXRX_QUEUED) 2004 if (res == TX_DROP || res == TX_QUEUED)
1871 break; 2005 break;
1872 } 2006 }
1873 skb = tx.skb; /* handlers are allowed to change skb */ 2007 skb = tx.skb; /* handlers are allowed to change skb */
1874 2008
1875 if (res == TXRX_DROP) { 2009 if (res == TX_DROP) {
1876 I802_DEBUG_INC(local->tx_handlers_drop); 2010 I802_DEBUG_INC(local->tx_handlers_drop);
1877 dev_kfree_skb(skb); 2011 dev_kfree_skb(skb);
1878 skb = NULL; 2012 skb = NULL;
1879 } else if (res == TXRX_QUEUED) { 2013 } else if (res == TX_QUEUED) {
1880 I802_DEBUG_INC(local->tx_handlers_queued); 2014 I802_DEBUG_INC(local->tx_handlers_queued);
1881 skb = NULL; 2015 skb = NULL;
1882 } 2016 }
1883 2017
1884 if (sta) 2018 rcu_read_unlock();
1885 sta_info_put(sta);
1886 2019
1887 return skb; 2020 return skb;
1888} 2021}
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 5e631ce98d7e..57c404f3f6d0 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -26,6 +26,7 @@
26 26
27#include "ieee80211_i.h" 27#include "ieee80211_i.h"
28#include "ieee80211_rate.h" 28#include "ieee80211_rate.h"
29#include "mesh.h"
29#include "wme.h" 30#include "wme.h"
30 31
31/* privid for wiphys to determine whether they belong to us or not */ 32/* privid for wiphys to determine whether they belong to us or not */
@@ -41,92 +42,6 @@ const unsigned char bridge_tunnel_header[] =
41 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; 42 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
42 43
43 44
44static int rate_list_match(const int *rate_list, int rate)
45{
46 int i;
47
48 if (!rate_list)
49 return 0;
50
51 for (i = 0; rate_list[i] >= 0; i++)
52 if (rate_list[i] == rate)
53 return 1;
54
55 return 0;
56}
57
58void ieee80211_prepare_rates(struct ieee80211_local *local,
59 struct ieee80211_hw_mode *mode)
60{
61 int i;
62
63 for (i = 0; i < mode->num_rates; i++) {
64 struct ieee80211_rate *rate = &mode->rates[i];
65
66 rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
67 IEEE80211_RATE_BASIC);
68
69 if (local->supp_rates[mode->mode]) {
70 if (!rate_list_match(local->supp_rates[mode->mode],
71 rate->rate))
72 continue;
73 }
74
75 rate->flags |= IEEE80211_RATE_SUPPORTED;
76
77 /* Use configured basic rate set if it is available. If not,
78 * use defaults that are sane for most cases. */
79 if (local->basic_rates[mode->mode]) {
80 if (rate_list_match(local->basic_rates[mode->mode],
81 rate->rate))
82 rate->flags |= IEEE80211_RATE_BASIC;
83 } else switch (mode->mode) {
84 case MODE_IEEE80211A:
85 if (rate->rate == 60 || rate->rate == 120 ||
86 rate->rate == 240)
87 rate->flags |= IEEE80211_RATE_BASIC;
88 break;
89 case MODE_IEEE80211B:
90 if (rate->rate == 10 || rate->rate == 20)
91 rate->flags |= IEEE80211_RATE_BASIC;
92 break;
93 case MODE_IEEE80211G:
94 if (rate->rate == 10 || rate->rate == 20 ||
95 rate->rate == 55 || rate->rate == 110)
96 rate->flags |= IEEE80211_RATE_BASIC;
97 break;
98 case NUM_IEEE80211_MODES:
99 /* not useful */
100 break;
101 }
102
103 /* Set ERP and MANDATORY flags based on phymode */
104 switch (mode->mode) {
105 case MODE_IEEE80211A:
106 if (rate->rate == 60 || rate->rate == 120 ||
107 rate->rate == 240)
108 rate->flags |= IEEE80211_RATE_MANDATORY;
109 break;
110 case MODE_IEEE80211B:
111 if (rate->rate == 10)
112 rate->flags |= IEEE80211_RATE_MANDATORY;
113 break;
114 case MODE_IEEE80211G:
115 if (rate->rate == 10 || rate->rate == 20 ||
116 rate->rate == 55 || rate->rate == 110 ||
117 rate->rate == 60 || rate->rate == 120 ||
118 rate->rate == 240)
119 rate->flags |= IEEE80211_RATE_MANDATORY;
120 break;
121 case NUM_IEEE80211_MODES:
122 /* not useful */
123 break;
124 }
125 if (ieee80211_is_erp_rate(mode->mode, rate->rate))
126 rate->flags |= IEEE80211_RATE_ERP;
127 }
128}
129
130u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, 45u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
131 enum ieee80211_if_types type) 46 enum ieee80211_if_types type)
132{ 47{
@@ -232,17 +147,35 @@ int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
232} 147}
233EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); 148EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
234 149
235void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx) 150int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
151{
152 int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
153 /* 7.1.3.5a.2 */
154 switch (ae) {
155 case 0:
156 return 5;
157 case 1:
158 return 11;
159 case 2:
160 return 17;
161 case 3:
162 return 23;
163 default:
164 return 5;
165 }
166}
167
168void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
236{ 169{
237 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; 170 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
238 171
239 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 172 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
240 if (tx->u.tx.extra_frag) { 173 if (tx->extra_frag) {
241 struct ieee80211_hdr *fhdr; 174 struct ieee80211_hdr *fhdr;
242 int i; 175 int i;
243 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 176 for (i = 0; i < tx->num_extra_frag; i++) {
244 fhdr = (struct ieee80211_hdr *) 177 fhdr = (struct ieee80211_hdr *)
245 tx->u.tx.extra_frag[i]->data; 178 tx->extra_frag[i]->data;
246 fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 179 fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
247 } 180 }
248 } 181 }
@@ -262,7 +195,7 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
262 * DIV_ROUND_UP() operations. 195 * DIV_ROUND_UP() operations.
263 */ 196 */
264 197
265 if (local->hw.conf.phymode == MODE_IEEE80211A || erp) { 198 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
266 /* 199 /*
267 * OFDM: 200 * OFDM:
268 * 201 *
@@ -304,15 +237,19 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
304/* Exported duration function for driver use */ 237/* Exported duration function for driver use */
305__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, 238__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
306 struct ieee80211_vif *vif, 239 struct ieee80211_vif *vif,
307 size_t frame_len, int rate) 240 size_t frame_len,
241 struct ieee80211_rate *rate)
308{ 242{
309 struct ieee80211_local *local = hw_to_local(hw); 243 struct ieee80211_local *local = hw_to_local(hw);
310 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 244 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
311 u16 dur; 245 u16 dur;
312 int erp; 246 int erp;
313 247
314 erp = ieee80211_is_erp_rate(hw->conf.phymode, rate); 248 erp = 0;
315 dur = ieee80211_frame_duration(local, frame_len, rate, erp, 249 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
250 erp = rate->flags & IEEE80211_RATE_ERP_G;
251
252 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
316 sdata->bss_conf.use_short_preamble); 253 sdata->bss_conf.use_short_preamble);
317 254
318 return cpu_to_le16(dur); 255 return cpu_to_le16(dur);
@@ -332,17 +269,20 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
332 269
333 short_preamble = sdata->bss_conf.use_short_preamble; 270 short_preamble = sdata->bss_conf.use_short_preamble;
334 271
335 rate = frame_txctl->rts_rate; 272 rate = frame_txctl->rts_cts_rate;
336 erp = !!(rate->flags & IEEE80211_RATE_ERP); 273
274 erp = 0;
275 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
276 erp = rate->flags & IEEE80211_RATE_ERP_G;
337 277
338 /* CTS duration */ 278 /* CTS duration */
339 dur = ieee80211_frame_duration(local, 10, rate->rate, 279 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
340 erp, short_preamble); 280 erp, short_preamble);
341 /* Data frame duration */ 281 /* Data frame duration */
342 dur += ieee80211_frame_duration(local, frame_len, rate->rate, 282 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
343 erp, short_preamble); 283 erp, short_preamble);
344 /* ACK duration */ 284 /* ACK duration */
345 dur += ieee80211_frame_duration(local, 10, rate->rate, 285 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
346 erp, short_preamble); 286 erp, short_preamble);
347 287
348 return cpu_to_le16(dur); 288 return cpu_to_le16(dur);
@@ -363,15 +303,17 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
363 303
364 short_preamble = sdata->bss_conf.use_short_preamble; 304 short_preamble = sdata->bss_conf.use_short_preamble;
365 305
366 rate = frame_txctl->rts_rate; 306 rate = frame_txctl->rts_cts_rate;
367 erp = !!(rate->flags & IEEE80211_RATE_ERP); 307 erp = 0;
308 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
309 erp = rate->flags & IEEE80211_RATE_ERP_G;
368 310
369 /* Data frame duration */ 311 /* Data frame duration */
370 dur = ieee80211_frame_duration(local, frame_len, rate->rate, 312 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
371 erp, short_preamble); 313 erp, short_preamble);
372 if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) { 314 if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
373 /* ACK duration */ 315 /* ACK duration */
374 dur += ieee80211_frame_duration(local, 10, rate->rate, 316 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
375 erp, short_preamble); 317 erp, short_preamble);
376 } 318 }
377 319
@@ -379,27 +321,6 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
379} 321}
380EXPORT_SYMBOL(ieee80211_ctstoself_duration); 322EXPORT_SYMBOL(ieee80211_ctstoself_duration);
381 323
382struct ieee80211_rate *
383ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
384{
385 struct ieee80211_hw_mode *mode;
386 int r;
387
388 list_for_each_entry(mode, &local->modes_list, list) {
389 if (mode->mode != phymode)
390 continue;
391 for (r = 0; r < mode->num_rates; r++) {
392 struct ieee80211_rate *rate = &mode->rates[r];
393 if (rate->val == hw_rate ||
394 (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
395 rate->val2 == hw_rate))
396 return rate;
397 }
398 }
399
400 return NULL;
401}
402
403void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) 324void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
404{ 325{
405 struct ieee80211_local *local = hw_to_local(hw); 326 struct ieee80211_local *local = hw_to_local(hw);
@@ -480,6 +401,7 @@ void ieee80211_iterate_active_interfaces(
480 case IEEE80211_IF_TYPE_STA: 401 case IEEE80211_IF_TYPE_STA:
481 case IEEE80211_IF_TYPE_IBSS: 402 case IEEE80211_IF_TYPE_IBSS:
482 case IEEE80211_IF_TYPE_WDS: 403 case IEEE80211_IF_TYPE_WDS:
404 case IEEE80211_IF_TYPE_MESH_POINT:
483 break; 405 break;
484 } 406 }
485 if (sdata->dev == local->mdev) 407 if (sdata->dev == local->mdev)
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index a0cff72a580b..affcecd78c10 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -305,39 +305,39 @@ u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
305 return NULL; 305 return NULL;
306} 306}
307 307
308ieee80211_txrx_result 308ieee80211_rx_result
309ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx) 309ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx)
310{ 310{
311 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA && 311 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
312 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || 312 ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
313 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) 313 (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH))
314 return TXRX_CONTINUE; 314 return RX_CONTINUE;
315 315
316 if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) { 316 if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
317 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) { 317 if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
318#ifdef CONFIG_MAC80211_DEBUG 318#ifdef CONFIG_MAC80211_DEBUG
319 if (net_ratelimit()) 319 if (net_ratelimit())
320 printk(KERN_DEBUG "%s: RX WEP frame, decrypt " 320 printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
321 "failed\n", rx->dev->name); 321 "failed\n", rx->dev->name);
322#endif /* CONFIG_MAC80211_DEBUG */ 322#endif /* CONFIG_MAC80211_DEBUG */
323 return TXRX_DROP; 323 return RX_DROP_UNUSABLE;
324 } 324 }
325 } else if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) { 325 } else if (!(rx->status->flag & RX_FLAG_IV_STRIPPED)) {
326 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key); 326 ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
327 /* remove ICV */ 327 /* remove ICV */
328 skb_trim(rx->skb, rx->skb->len - 4); 328 skb_trim(rx->skb, rx->skb->len - 4);
329 } 329 }
330 330
331 return TXRX_CONTINUE; 331 return RX_CONTINUE;
332} 332}
333 333
334static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb) 334static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
335{ 335{
336 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 336 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
337 if (ieee80211_wep_encrypt(tx->local, skb, tx->key)) 337 if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
338 return -1; 338 return -1;
339 } else { 339 } else {
340 tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx; 340 tx->control->key_idx = tx->key->conf.hw_key_idx;
341 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) { 341 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
342 if (!ieee80211_wep_add_iv(tx->local, skb, tx->key)) 342 if (!ieee80211_wep_add_iv(tx->local, skb, tx->key))
343 return -1; 343 return -1;
@@ -346,28 +346,28 @@ static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
346 return 0; 346 return 0;
347} 347}
348 348
349ieee80211_txrx_result 349ieee80211_tx_result
350ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx) 350ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx)
351{ 351{
352 tx->u.tx.control->iv_len = WEP_IV_LEN; 352 tx->control->iv_len = WEP_IV_LEN;
353 tx->u.tx.control->icv_len = WEP_ICV_LEN; 353 tx->control->icv_len = WEP_ICV_LEN;
354 ieee80211_tx_set_iswep(tx); 354 ieee80211_tx_set_protected(tx);
355 355
356 if (wep_encrypt_skb(tx, tx->skb) < 0) { 356 if (wep_encrypt_skb(tx, tx->skb) < 0) {
357 I802_DEBUG_INC(tx->local->tx_handlers_drop_wep); 357 I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
358 return TXRX_DROP; 358 return TX_DROP;
359 } 359 }
360 360
361 if (tx->u.tx.extra_frag) { 361 if (tx->extra_frag) {
362 int i; 362 int i;
363 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 363 for (i = 0; i < tx->num_extra_frag; i++) {
364 if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) { 364 if (wep_encrypt_skb(tx, tx->extra_frag[i]) < 0) {
365 I802_DEBUG_INC(tx->local-> 365 I802_DEBUG_INC(tx->local->
366 tx_handlers_drop_wep); 366 tx_handlers_drop_wep);
367 return TXRX_DROP; 367 return TX_DROP;
368 } 368 }
369 } 369 }
370 } 370 }
371 371
372 return TXRX_CONTINUE; 372 return TX_CONTINUE;
373} 373}
diff --git a/net/mac80211/wep.h b/net/mac80211/wep.h
index 785fbb4e0dd7..9f723938b63f 100644
--- a/net/mac80211/wep.h
+++ b/net/mac80211/wep.h
@@ -28,9 +28,9 @@ int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
28 struct ieee80211_key *key); 28 struct ieee80211_key *key);
29u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key); 29u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
30 30
31ieee80211_txrx_result 31ieee80211_rx_result
32ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx); 32ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx);
33ieee80211_txrx_result 33ieee80211_tx_result
34ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx); 34ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx);
35 35
36#endif /* WEP_H */ 36#endif /* WEP_H */
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 4e236599dd31..4e94e4026e78 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -19,10 +19,13 @@
19#include "wme.h" 19#include "wme.h"
20 20
21/* maximum number of hardware queues we support. */ 21/* maximum number of hardware queues we support. */
22#define TC_80211_MAX_QUEUES 8 22#define TC_80211_MAX_QUEUES 16
23
24const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
23 25
24struct ieee80211_sched_data 26struct ieee80211_sched_data
25{ 27{
28 unsigned long qdisc_pool[BITS_TO_LONGS(TC_80211_MAX_QUEUES)];
26 struct tcf_proto *filter_list; 29 struct tcf_proto *filter_list;
27 struct Qdisc *queues[TC_80211_MAX_QUEUES]; 30 struct Qdisc *queues[TC_80211_MAX_QUEUES];
28 struct sk_buff_head requeued[TC_80211_MAX_QUEUES]; 31 struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
@@ -98,7 +101,6 @@ static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
98 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 101 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
99 unsigned short fc = le16_to_cpu(hdr->frame_control); 102 unsigned short fc = le16_to_cpu(hdr->frame_control);
100 int qos; 103 int qos;
101 const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
102 104
103 /* see if frame is data or non data frame */ 105 /* see if frame is data or non data frame */
104 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) { 106 if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
@@ -146,9 +148,26 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
146 unsigned short fc = le16_to_cpu(hdr->frame_control); 148 unsigned short fc = le16_to_cpu(hdr->frame_control);
147 struct Qdisc *qdisc; 149 struct Qdisc *qdisc;
148 int err, queue; 150 int err, queue;
151 struct sta_info *sta;
152 u8 tid;
149 153
150 if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) { 154 if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
151 skb_queue_tail(&q->requeued[pkt_data->queue], skb); 155 queue = pkt_data->queue;
156 rcu_read_lock();
157 sta = sta_info_get(local, hdr->addr1);
158 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
159 if (sta) {
160 int ampdu_queue = sta->tid_to_tx_q[tid];
161 if ((ampdu_queue < local->hw.queues) &&
162 test_bit(ampdu_queue, q->qdisc_pool)) {
163 queue = ampdu_queue;
164 pkt_data->flags |= IEEE80211_TXPD_AMPDU;
165 } else {
166 pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
167 }
168 }
169 rcu_read_unlock();
170 skb_queue_tail(&q->requeued[queue], skb);
152 qd->q.qlen++; 171 qd->q.qlen++;
153 return 0; 172 return 0;
154 } 173 }
@@ -159,14 +178,31 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
159 */ 178 */
160 if (WLAN_FC_IS_QOS_DATA(fc)) { 179 if (WLAN_FC_IS_QOS_DATA(fc)) {
161 u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2; 180 u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
162 u8 qos_hdr = skb->priority & QOS_CONTROL_TAG1D_MASK; 181 u8 ack_policy = 0;
182 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
163 if (local->wifi_wme_noack_test) 183 if (local->wifi_wme_noack_test)
164 qos_hdr |= QOS_CONTROL_ACK_POLICY_NOACK << 184 ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
165 QOS_CONTROL_ACK_POLICY_SHIFT; 185 QOS_CONTROL_ACK_POLICY_SHIFT;
166 /* qos header is 2 bytes, second reserved */ 186 /* qos header is 2 bytes, second reserved */
167 *p = qos_hdr; 187 *p = ack_policy | tid;
168 p++; 188 p++;
169 *p = 0; 189 *p = 0;
190
191 rcu_read_lock();
192
193 sta = sta_info_get(local, hdr->addr1);
194 if (sta) {
195 int ampdu_queue = sta->tid_to_tx_q[tid];
196 if ((ampdu_queue < local->hw.queues) &&
197 test_bit(ampdu_queue, q->qdisc_pool)) {
198 queue = ampdu_queue;
199 pkt_data->flags |= IEEE80211_TXPD_AMPDU;
200 } else {
201 pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
202 }
203 }
204
205 rcu_read_unlock();
170 } 206 }
171 207
172 if (unlikely(queue >= local->hw.queues)) { 208 if (unlikely(queue >= local->hw.queues)) {
@@ -184,6 +220,7 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
184 kfree_skb(skb); 220 kfree_skb(skb);
185 err = NET_XMIT_DROP; 221 err = NET_XMIT_DROP;
186 } else { 222 } else {
223 tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
187 pkt_data->queue = (unsigned int) queue; 224 pkt_data->queue = (unsigned int) queue;
188 qdisc = q->queues[queue]; 225 qdisc = q->queues[queue];
189 err = qdisc->enqueue(skb, qdisc); 226 err = qdisc->enqueue(skb, qdisc);
@@ -235,10 +272,11 @@ static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
235 /* check all the h/w queues in numeric/priority order */ 272 /* check all the h/w queues in numeric/priority order */
236 for (queue = 0; queue < hw->queues; queue++) { 273 for (queue = 0; queue < hw->queues; queue++) {
237 /* see if there is room in this hardware queue */ 274 /* see if there is room in this hardware queue */
238 if (test_bit(IEEE80211_LINK_STATE_XOFF, 275 if ((test_bit(IEEE80211_LINK_STATE_XOFF,
239 &local->state[queue]) || 276 &local->state[queue])) ||
240 test_bit(IEEE80211_LINK_STATE_PENDING, 277 (test_bit(IEEE80211_LINK_STATE_PENDING,
241 &local->state[queue])) 278 &local->state[queue])) ||
279 (!test_bit(queue, q->qdisc_pool)))
242 continue; 280 continue;
243 281
244 /* there is space - try and get a frame */ 282 /* there is space - try and get a frame */
@@ -360,6 +398,10 @@ static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
360 } 398 }
361 } 399 }
362 400
401 /* reserve all legacy QoS queues */
402 for (i = 0; i < min(IEEE80211_TX_QUEUE_DATA4, queues); i++)
403 set_bit(i, q->qdisc_pool);
404
363 return err; 405 return err;
364} 406}
365 407
@@ -605,3 +647,80 @@ void ieee80211_wme_unregister(void)
605{ 647{
606 unregister_qdisc(&wme_qdisc_ops); 648 unregister_qdisc(&wme_qdisc_ops);
607} 649}
650
651int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
652 struct sta_info *sta, u16 tid)
653{
654 int i;
655 struct ieee80211_sched_data *q =
656 qdisc_priv(local->mdev->qdisc_sleeping);
657 DECLARE_MAC_BUF(mac);
658
659 /* prepare the filter and save it for the SW queue
660 * matching the recieved HW queue */
661
662 /* try to get a Qdisc from the pool */
663 for (i = IEEE80211_TX_QUEUE_BEACON; i < local->hw.queues; i++)
664 if (!test_and_set_bit(i, q->qdisc_pool)) {
665 ieee80211_stop_queue(local_to_hw(local), i);
666 sta->tid_to_tx_q[tid] = i;
667
668 /* IF there are already pending packets
669 * on this tid first we need to drain them
670 * on the previous queue
671 * since HT is strict in order */
672#ifdef CONFIG_MAC80211_HT_DEBUG
673 if (net_ratelimit())
674 printk(KERN_DEBUG "allocated aggregation queue"
675 " %d tid %d addr %s pool=0x%lX",
676 i, tid, print_mac(mac, sta->addr),
677 q->qdisc_pool[0]);
678#endif /* CONFIG_MAC80211_HT_DEBUG */
679 return 0;
680 }
681
682 return -EAGAIN;
683}
684
685/**
686 * the caller needs to hold local->mdev->queue_lock
687 */
688void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
689 struct sta_info *sta, u16 tid,
690 u8 requeue)
691{
692 struct ieee80211_sched_data *q =
693 qdisc_priv(local->mdev->qdisc_sleeping);
694 int agg_queue = sta->tid_to_tx_q[tid];
695
696 /* return the qdisc to the pool */
697 clear_bit(agg_queue, q->qdisc_pool);
698 sta->tid_to_tx_q[tid] = local->hw.queues;
699
700 if (requeue)
701 ieee80211_requeue(local, agg_queue);
702 else
703 q->queues[agg_queue]->ops->reset(q->queues[agg_queue]);
704}
705
706void ieee80211_requeue(struct ieee80211_local *local, int queue)
707{
708 struct Qdisc *root_qd = local->mdev->qdisc_sleeping;
709 struct ieee80211_sched_data *q = qdisc_priv(root_qd);
710 struct Qdisc *qdisc = q->queues[queue];
711 struct sk_buff *skb = NULL;
712 u32 len = qdisc->q.qlen;
713
714 if (!qdisc || !qdisc->dequeue)
715 return;
716
717 printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen);
718 for (len = qdisc->q.qlen; len > 0; len--) {
719 skb = qdisc->dequeue(qdisc);
720 root_qd->q.qlen--;
721 /* packet will be classified again and */
722 /* skb->packet_data->queue will be overridden if needed */
723 if (skb)
724 wme_qdiscop_enqueue(skb, root_qd);
725 }
726}
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index 76c713a6450c..fcc6b05508cc 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -24,6 +24,8 @@
24 24
25#define QOS_CONTROL_TAG1D_MASK 0x07 25#define QOS_CONTROL_TAG1D_MASK 0x07
26 26
27extern const int ieee802_1d_to_ac[8];
28
27static inline int WLAN_FC_IS_QOS_DATA(u16 fc) 29static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
28{ 30{
29 return (fc & 0x8C) == 0x88; 31 return (fc & 0x8C) == 0x88;
@@ -32,7 +34,12 @@ static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
32#ifdef CONFIG_NET_SCHED 34#ifdef CONFIG_NET_SCHED
33void ieee80211_install_qdisc(struct net_device *dev); 35void ieee80211_install_qdisc(struct net_device *dev);
34int ieee80211_qdisc_installed(struct net_device *dev); 36int ieee80211_qdisc_installed(struct net_device *dev);
35 37int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
38 struct sta_info *sta, u16 tid);
39void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
40 struct sta_info *sta, u16 tid,
41 u8 requeue);
42void ieee80211_requeue(struct ieee80211_local *local, int queue);
36int ieee80211_wme_register(void); 43int ieee80211_wme_register(void);
37void ieee80211_wme_unregister(void); 44void ieee80211_wme_unregister(void);
38#else 45#else
@@ -43,7 +50,19 @@ static inline int ieee80211_qdisc_installed(struct net_device *dev)
43{ 50{
44 return 0; 51 return 0;
45} 52}
46 53static inline int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
54 struct sta_info *sta, u16 tid)
55{
56 return -EAGAIN;
57}
58static inline void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
59 struct sta_info *sta, u16 tid,
60 u8 requeue)
61{
62}
63static inline void ieee80211_requeue(struct ieee80211_local *local, int queue)
64{
65}
47static inline int ieee80211_wme_register(void) 66static inline int ieee80211_wme_register(void)
48{ 67{
49 return 0; 68 return 0;
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 6f04311cf0a0..df0b7341efc8 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -70,8 +70,8 @@ static int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
70} 70}
71 71
72 72
73ieee80211_txrx_result 73ieee80211_tx_result
74ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx) 74ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
75{ 75{
76 u8 *data, *sa, *da, *key, *mic, qos_tid; 76 u8 *data, *sa, *da, *key, *mic, qos_tid;
77 size_t data_len; 77 size_t data_len;
@@ -84,18 +84,18 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
84 84
85 if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 || 85 if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 ||
86 !WLAN_FC_DATA_PRESENT(fc)) 86 !WLAN_FC_DATA_PRESENT(fc))
87 return TXRX_CONTINUE; 87 return TX_CONTINUE;
88 88
89 if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)) 89 if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
90 return TXRX_DROP; 90 return TX_DROP;
91 91
92 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 92 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
93 !(tx->flags & IEEE80211_TXRXD_FRAGMENTED) && 93 !(tx->flags & IEEE80211_TX_FRAGMENTED) &&
94 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) && 94 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) &&
95 !wpa_test) { 95 !wpa_test) {
96 /* hwaccel - with no need for preallocated room for Michael MIC 96 /* hwaccel - with no need for preallocated room for Michael MIC
97 */ 97 */
98 return TXRX_CONTINUE; 98 return TX_CONTINUE;
99 } 99 }
100 100
101 if (skb_tailroom(skb) < MICHAEL_MIC_LEN) { 101 if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
@@ -105,7 +105,7 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
105 GFP_ATOMIC))) { 105 GFP_ATOMIC))) {
106 printk(KERN_DEBUG "%s: failed to allocate more memory " 106 printk(KERN_DEBUG "%s: failed to allocate more memory "
107 "for Michael MIC\n", tx->dev->name); 107 "for Michael MIC\n", tx->dev->name);
108 return TXRX_DROP; 108 return TX_DROP;
109 } 109 }
110 } 110 }
111 111
@@ -119,12 +119,12 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
119 mic = skb_put(skb, MICHAEL_MIC_LEN); 119 mic = skb_put(skb, MICHAEL_MIC_LEN);
120 michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic); 120 michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
121 121
122 return TXRX_CONTINUE; 122 return TX_CONTINUE;
123} 123}
124 124
125 125
126ieee80211_txrx_result 126ieee80211_rx_result
127ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx) 127ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
128{ 128{
129 u8 *data, *sa, *da, *key = NULL, qos_tid; 129 u8 *data, *sa, *da, *key = NULL, qos_tid;
130 size_t data_len; 130 size_t data_len;
@@ -139,16 +139,16 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
139 /* 139 /*
140 * No way to verify the MIC if the hardware stripped it 140 * No way to verify the MIC if the hardware stripped it
141 */ 141 */
142 if (rx->u.rx.status->flag & RX_FLAG_MMIC_STRIPPED) 142 if (rx->status->flag & RX_FLAG_MMIC_STRIPPED)
143 return TXRX_CONTINUE; 143 return RX_CONTINUE;
144 144
145 if (!rx->key || rx->key->conf.alg != ALG_TKIP || 145 if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
146 !(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc)) 146 !(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
147 return TXRX_CONTINUE; 147 return RX_CONTINUE;
148 148
149 if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len) 149 if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
150 || data_len < MICHAEL_MIC_LEN) 150 || data_len < MICHAEL_MIC_LEN)
151 return TXRX_DROP; 151 return RX_DROP_UNUSABLE;
152 152
153 data_len -= MICHAEL_MIC_LEN; 153 data_len -= MICHAEL_MIC_LEN;
154 154
@@ -161,29 +161,29 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
161 ALG_TKIP_TEMP_AUTH_TX_MIC_KEY]; 161 ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
162 michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic); 162 michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
163 if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) { 163 if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
164 if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) 164 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
165 return TXRX_DROP; 165 return RX_DROP_UNUSABLE;
166 166
167 printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from " 167 printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
168 "%s\n", rx->dev->name, print_mac(mac, sa)); 168 "%s\n", rx->dev->name, print_mac(mac, sa));
169 169
170 mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx, 170 mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx,
171 (void *) skb->data); 171 (void *) skb->data);
172 return TXRX_DROP; 172 return RX_DROP_UNUSABLE;
173 } 173 }
174 174
175 /* remove Michael MIC from payload */ 175 /* remove Michael MIC from payload */
176 skb_trim(skb, skb->len - MICHAEL_MIC_LEN); 176 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
177 177
178 /* update IV in key information to be able to detect replays */ 178 /* update IV in key information to be able to detect replays */
179 rx->key->u.tkip.iv32_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv32; 179 rx->key->u.tkip.iv32_rx[rx->queue] = rx->tkip_iv32;
180 rx->key->u.tkip.iv16_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv16; 180 rx->key->u.tkip.iv16_rx[rx->queue] = rx->tkip_iv16;
181 181
182 return TXRX_CONTINUE; 182 return RX_CONTINUE;
183} 183}
184 184
185 185
186static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx, 186static int tkip_encrypt_skb(struct ieee80211_tx_data *tx,
187 struct sk_buff *skb, int test) 187 struct sk_buff *skb, int test)
188{ 188{
189 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 189 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -228,7 +228,7 @@ static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
228 0x7f), 228 0x7f),
229 (u8) key->u.tkip.iv16); 229 (u8) key->u.tkip.iv16);
230 230
231 tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx; 231 tx->control->key_idx = tx->key->conf.hw_key_idx;
232 return 0; 232 return 0;
233 } 233 }
234 234
@@ -242,42 +242,42 @@ static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
242} 242}
243 243
244 244
245ieee80211_txrx_result 245ieee80211_tx_result
246ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx) 246ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx)
247{ 247{
248 struct sk_buff *skb = tx->skb; 248 struct sk_buff *skb = tx->skb;
249 int wpa_test = 0, test = 0; 249 int wpa_test = 0, test = 0;
250 250
251 tx->u.tx.control->icv_len = TKIP_ICV_LEN; 251 tx->control->icv_len = TKIP_ICV_LEN;
252 tx->u.tx.control->iv_len = TKIP_IV_LEN; 252 tx->control->iv_len = TKIP_IV_LEN;
253 ieee80211_tx_set_iswep(tx); 253 ieee80211_tx_set_protected(tx);
254 254
255 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 255 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
256 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) && 256 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) &&
257 !wpa_test) { 257 !wpa_test) {
258 /* hwaccel - with no need for preallocated room for IV/ICV */ 258 /* hwaccel - with no need for preallocated room for IV/ICV */
259 tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx; 259 tx->control->key_idx = tx->key->conf.hw_key_idx;
260 return TXRX_CONTINUE; 260 return TX_CONTINUE;
261 } 261 }
262 262
263 if (tkip_encrypt_skb(tx, skb, test) < 0) 263 if (tkip_encrypt_skb(tx, skb, test) < 0)
264 return TXRX_DROP; 264 return TX_DROP;
265 265
266 if (tx->u.tx.extra_frag) { 266 if (tx->extra_frag) {
267 int i; 267 int i;
268 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 268 for (i = 0; i < tx->num_extra_frag; i++) {
269 if (tkip_encrypt_skb(tx, tx->u.tx.extra_frag[i], test) 269 if (tkip_encrypt_skb(tx, tx->extra_frag[i], test)
270 < 0) 270 < 0)
271 return TXRX_DROP; 271 return TX_DROP;
272 } 272 }
273 } 273 }
274 274
275 return TXRX_CONTINUE; 275 return TX_CONTINUE;
276} 276}
277 277
278 278
279ieee80211_txrx_result 279ieee80211_rx_result
280ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx) 280ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
281{ 281{
282 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; 282 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
283 u16 fc; 283 u16 fc;
@@ -290,19 +290,19 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
290 hdrlen = ieee80211_get_hdrlen(fc); 290 hdrlen = ieee80211_get_hdrlen(fc);
291 291
292 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) 292 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
293 return TXRX_CONTINUE; 293 return RX_CONTINUE;
294 294
295 if (!rx->sta || skb->len - hdrlen < 12) 295 if (!rx->sta || skb->len - hdrlen < 12)
296 return TXRX_DROP; 296 return RX_DROP_UNUSABLE;
297 297
298 if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) { 298 if (rx->status->flag & RX_FLAG_DECRYPTED) {
299 if (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) { 299 if (rx->status->flag & RX_FLAG_IV_STRIPPED) {
300 /* 300 /*
301 * Hardware took care of all processing, including 301 * Hardware took care of all processing, including
302 * replay protection, and stripped the ICV/IV so 302 * replay protection, and stripped the ICV/IV so
303 * we cannot do any checks here. 303 * we cannot do any checks here.
304 */ 304 */
305 return TXRX_CONTINUE; 305 return RX_CONTINUE;
306 } 306 }
307 307
308 /* let TKIP code verify IV, but skip decryption */ 308 /* let TKIP code verify IV, but skip decryption */
@@ -312,9 +312,9 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
312 res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm, 312 res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
313 key, skb->data + hdrlen, 313 key, skb->data + hdrlen,
314 skb->len - hdrlen, rx->sta->addr, 314 skb->len - hdrlen, rx->sta->addr,
315 hwaccel, rx->u.rx.queue, 315 hwaccel, rx->queue,
316 &rx->u.rx.tkip_iv32, 316 &rx->tkip_iv32,
317 &rx->u.rx.tkip_iv16); 317 &rx->tkip_iv16);
318 if (res != TKIP_DECRYPT_OK || wpa_test) { 318 if (res != TKIP_DECRYPT_OK || wpa_test) {
319#ifdef CONFIG_MAC80211_DEBUG 319#ifdef CONFIG_MAC80211_DEBUG
320 if (net_ratelimit()) 320 if (net_ratelimit())
@@ -322,7 +322,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
322 "frame from %s (res=%d)\n", rx->dev->name, 322 "frame from %s (res=%d)\n", rx->dev->name,
323 print_mac(mac, rx->sta->addr), res); 323 print_mac(mac, rx->sta->addr), res);
324#endif /* CONFIG_MAC80211_DEBUG */ 324#endif /* CONFIG_MAC80211_DEBUG */
325 return TXRX_DROP; 325 return RX_DROP_UNUSABLE;
326 } 326 }
327 327
328 /* Trim ICV */ 328 /* Trim ICV */
@@ -332,7 +332,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
332 memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen); 332 memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
333 skb_pull(skb, TKIP_IV_LEN); 333 skb_pull(skb, TKIP_IV_LEN);
334 334
335 return TXRX_CONTINUE; 335 return RX_CONTINUE;
336} 336}
337 337
338 338
@@ -429,7 +429,7 @@ static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
429} 429}
430 430
431 431
432static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx, 432static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx,
433 struct sk_buff *skb, int test) 433 struct sk_buff *skb, int test)
434{ 434{
435 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 435 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -478,7 +478,7 @@ static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
478 478
479 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) { 479 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
480 /* hwaccel - with preallocated room for CCMP header */ 480 /* hwaccel - with preallocated room for CCMP header */
481 tx->u.tx.control->key_idx = key->conf.hw_key_idx; 481 tx->control->key_idx = key->conf.hw_key_idx;
482 return 0; 482 return 0;
483 } 483 }
484 484
@@ -491,42 +491,42 @@ static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
491} 491}
492 492
493 493
494ieee80211_txrx_result 494ieee80211_tx_result
495ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx) 495ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx)
496{ 496{
497 struct sk_buff *skb = tx->skb; 497 struct sk_buff *skb = tx->skb;
498 int test = 0; 498 int test = 0;
499 499
500 tx->u.tx.control->icv_len = CCMP_MIC_LEN; 500 tx->control->icv_len = CCMP_MIC_LEN;
501 tx->u.tx.control->iv_len = CCMP_HDR_LEN; 501 tx->control->iv_len = CCMP_HDR_LEN;
502 ieee80211_tx_set_iswep(tx); 502 ieee80211_tx_set_protected(tx);
503 503
504 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) && 504 if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
505 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { 505 !(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
506 /* hwaccel - with no need for preallocated room for CCMP " 506 /* hwaccel - with no need for preallocated room for CCMP "
507 * header or MIC fields */ 507 * header or MIC fields */
508 tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx; 508 tx->control->key_idx = tx->key->conf.hw_key_idx;
509 return TXRX_CONTINUE; 509 return TX_CONTINUE;
510 } 510 }
511 511
512 if (ccmp_encrypt_skb(tx, skb, test) < 0) 512 if (ccmp_encrypt_skb(tx, skb, test) < 0)
513 return TXRX_DROP; 513 return TX_DROP;
514 514
515 if (tx->u.tx.extra_frag) { 515 if (tx->extra_frag) {
516 int i; 516 int i;
517 for (i = 0; i < tx->u.tx.num_extra_frag; i++) { 517 for (i = 0; i < tx->num_extra_frag; i++) {
518 if (ccmp_encrypt_skb(tx, tx->u.tx.extra_frag[i], test) 518 if (ccmp_encrypt_skb(tx, tx->extra_frag[i], test)
519 < 0) 519 < 0)
520 return TXRX_DROP; 520 return TX_DROP;
521 } 521 }
522 } 522 }
523 523
524 return TXRX_CONTINUE; 524 return TX_CONTINUE;
525} 525}
526 526
527 527
528ieee80211_txrx_result 528ieee80211_rx_result
529ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx) 529ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
530{ 530{
531 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data; 531 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
532 u16 fc; 532 u16 fc;
@@ -541,21 +541,21 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
541 hdrlen = ieee80211_get_hdrlen(fc); 541 hdrlen = ieee80211_get_hdrlen(fc);
542 542
543 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) 543 if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
544 return TXRX_CONTINUE; 544 return RX_CONTINUE;
545 545
546 data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN; 546 data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
547 if (!rx->sta || data_len < 0) 547 if (!rx->sta || data_len < 0)
548 return TXRX_DROP; 548 return RX_DROP_UNUSABLE;
549 549
550 if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) && 550 if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
551 (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) 551 (rx->status->flag & RX_FLAG_IV_STRIPPED))
552 return TXRX_CONTINUE; 552 return RX_CONTINUE;
553 553
554 (void) ccmp_hdr2pn(pn, skb->data + hdrlen); 554 (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
555 555
556 if (memcmp(pn, key->u.ccmp.rx_pn[rx->u.rx.queue], CCMP_PN_LEN) <= 0) { 556 if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) {
557#ifdef CONFIG_MAC80211_DEBUG 557#ifdef CONFIG_MAC80211_DEBUG
558 u8 *ppn = key->u.ccmp.rx_pn[rx->u.rx.queue]; 558 u8 *ppn = key->u.ccmp.rx_pn[rx->queue];
559 559
560 printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from " 560 printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
561 "%s (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN " 561 "%s (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
@@ -565,10 +565,10 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
565 ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]); 565 ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
566#endif /* CONFIG_MAC80211_DEBUG */ 566#endif /* CONFIG_MAC80211_DEBUG */
567 key->u.ccmp.replays++; 567 key->u.ccmp.replays++;
568 return TXRX_DROP; 568 return RX_DROP_UNUSABLE;
569 } 569 }
570 570
571 if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) { 571 if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
572 /* hardware didn't decrypt/verify MIC */ 572 /* hardware didn't decrypt/verify MIC */
573 u8 *scratch, *b_0, *aad; 573 u8 *scratch, *b_0, *aad;
574 574
@@ -589,16 +589,16 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
589 "for RX frame from %s\n", rx->dev->name, 589 "for RX frame from %s\n", rx->dev->name,
590 print_mac(mac, rx->sta->addr)); 590 print_mac(mac, rx->sta->addr));
591#endif /* CONFIG_MAC80211_DEBUG */ 591#endif /* CONFIG_MAC80211_DEBUG */
592 return TXRX_DROP; 592 return RX_DROP_UNUSABLE;
593 } 593 }
594 } 594 }
595 595
596 memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN); 596 memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN);
597 597
598 /* Remove CCMP header and MIC */ 598 /* Remove CCMP header and MIC */
599 skb_trim(skb, skb->len - CCMP_MIC_LEN); 599 skb_trim(skb, skb->len - CCMP_MIC_LEN);
600 memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen); 600 memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
601 skb_pull(skb, CCMP_HDR_LEN); 601 skb_pull(skb, CCMP_HDR_LEN);
602 602
603 return TXRX_CONTINUE; 603 return RX_CONTINUE;
604} 604}
diff --git a/net/mac80211/wpa.h b/net/mac80211/wpa.h
index 49d80cf0cd75..d42d221d8a1d 100644
--- a/net/mac80211/wpa.h
+++ b/net/mac80211/wpa.h
@@ -13,19 +13,19 @@
13#include <linux/types.h> 13#include <linux/types.h>
14#include "ieee80211_i.h" 14#include "ieee80211_i.h"
15 15
16ieee80211_txrx_result 16ieee80211_tx_result
17ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx); 17ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx);
18ieee80211_txrx_result 18ieee80211_rx_result
19ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx); 19ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx);
20 20
21ieee80211_txrx_result 21ieee80211_tx_result
22ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx); 22ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx);
23ieee80211_txrx_result 23ieee80211_rx_result
24ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx); 24ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx);
25 25
26ieee80211_txrx_result 26ieee80211_tx_result
27ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx); 27ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx);
28ieee80211_txrx_result 28ieee80211_rx_result
29ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx); 29ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx);
30 30
31#endif /* WPA_H */ 31#endif /* WPA_H */