summaryrefslogtreecommitdiff
path: root/net/mac80211
diff options
context:
space:
mode:
authorRussell King <rmk@dyn-67.arm.linux.org.uk>2008-04-19 17:17:34 +0100
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-04-19 17:17:34 +0100
commitcf816ecb533ab96b883dfdc0db174598b5b5c4d2 (patch)
tree1b7705db288ae2917105e624b01fdf81e0882bf1 /net/mac80211
parentadf6d34e460387ee3e8f1e1875d52bff51212c7d (diff)
parent15f7d677ccff6f0f5de8a1ee43a792567e9f9de9 (diff)
Merge branch 'merge-fixes' into devel
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig33
-rw-r--r--net/mac80211/Makefile21
-rw-r--r--net/mac80211/aes_ccm.c2
-rw-r--r--net/mac80211/cfg.c458
-rw-r--r--net/mac80211/debugfs.c53
-rw-r--r--net/mac80211/debugfs_key.c42
-rw-r--r--net/mac80211/debugfs_key.h11
-rw-r--r--net/mac80211/debugfs_netdev.c218
-rw-r--r--net/mac80211/debugfs_sta.c181
-rw-r--r--net/mac80211/debugfs_sta.h2
-rw-r--r--net/mac80211/ieee80211_i.h525
-rw-r--r--net/mac80211/iface.c (renamed from net/mac80211/ieee80211_iface.c)48
-rw-r--r--net/mac80211/key.c393
-rw-r--r--net/mac80211/key.h (renamed from net/mac80211/ieee80211_key.h)42
-rw-r--r--net/mac80211/led.c (renamed from net/mac80211/ieee80211_led.c)2
-rw-r--r--net/mac80211/led.h (renamed from net/mac80211/ieee80211_led.h)0
-rw-r--r--net/mac80211/main.c (renamed from net/mac80211/ieee80211.c)1061
-rw-r--r--net/mac80211/mesh.c449
-rw-r--r--net/mac80211/mesh.h290
-rw-r--r--net/mac80211/mesh_hwmp.c855
-rw-r--r--net/mac80211/mesh_pathtbl.c516
-rw-r--r--net/mac80211/mesh_plink.c762
-rw-r--r--net/mac80211/mlme.c (renamed from net/mac80211/ieee80211_sta.c)1831
-rw-r--r--net/mac80211/rate.c (renamed from net/mac80211/ieee80211_rate.c)25
-rw-r--r--net/mac80211/rate.h (renamed from net/mac80211/ieee80211_rate.h)44
-rw-r--r--net/mac80211/rc80211_pid_algo.c124
-rw-r--r--net/mac80211/rc80211_pid_debugfs.c2
-rw-r--r--net/mac80211/rc80211_simple.c400
-rw-r--r--net/mac80211/regdomain.c152
-rw-r--r--net/mac80211/rx.c876
-rw-r--r--net/mac80211/sta_info.c698
-rw-r--r--net/mac80211/sta_info.h357
-rw-r--r--net/mac80211/tkip.c70
-rw-r--r--net/mac80211/tkip.h4
-rw-r--r--net/mac80211/tx.c732
-rw-r--r--net/mac80211/util.c172
-rw-r--r--net/mac80211/wep.c40
-rw-r--r--net/mac80211/wep.h10
-rw-r--r--net/mac80211/wext.c (renamed from net/mac80211/ieee80211_ioctl.c)270
-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
43 files changed, 8764 insertions, 3345 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
default rate control algorithm. You should choose
this unless you know what you are doing.
-config MAC80211_RC_DEFAULT_SIMPLE
- bool "Simple rate control algorithm"
- select MAC80211_RC_SIMPLE
- ---help---
- Select the simple rate control as the default rate
- control algorithm. Note that this is a non-responsive,
- dumb algorithm. You should choose the PID rate control
- instead.
-
config MAC80211_RC_DEFAULT_NONE
bool "No default algorithm"
depends on EMBEDDED
@@ -57,7 +48,6 @@ comment "build the algorithm into mac80211."
config MAC80211_RC_DEFAULT
string
default "pid" if MAC80211_RC_DEFAULT_PID
- default "simple" if MAC80211_RC_DEFAULT_SIMPLE
default ""
config MAC80211_RC_PID
@@ -70,16 +60,16 @@ config MAC80211_RC_PID
Say Y or M unless you're sure you want to use a
different rate control algorithm.
-config MAC80211_RC_SIMPLE
- tristate "Simple rate control algorithm (DEPRECATED)"
+endmenu
+
+config MAC80211_MESH
+ bool "Enable mac80211 mesh networking (pre-802.11s) support"
+ depends on MAC80211 && EXPERIMENTAL
---help---
- This option enables a very simple, non-responsive TX
- rate control algorithm. This algorithm is deprecated
- and will be removed from the kernel in the near future.
- It has been replaced by the PID algorithm.
+ This options enables support of Draft 802.11s mesh networking.
+ The implementation is based on Draft 1.08 of the Mesh Networking
+ amendment. For more information visit http://o11s.org/.
- Say N unless you know what you are doing.
-endmenu
config MAC80211_LEDS
bool "Enable LED triggers"
@@ -166,3 +156,10 @@ config MAC80211_VERBOSE_PS_DEBUG
---help---
Say Y here to print out verbose powersave
mode debug messages.
+
+config MAC80211_VERBOSE_MPL_DEBUG
+ bool "Verbose mesh peer link debugging"
+ depends on MAC80211_DEBUG && MAC80211_MESH
+ ---help---
+ Say Y here to print out verbose mesh peer link
+ debug messages.
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 54f46bc80cfe..4e5847fd316c 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -10,16 +10,15 @@ rc-pid-m := rc80211_pid.o
# mac80211 objects
mac80211-y := \
- ieee80211.o \
- ieee80211_ioctl.o \
+ main.o \
+ wext.o \
sta_info.o \
wep.o \
wpa.o \
- ieee80211_sta.o \
- ieee80211_iface.o \
- ieee80211_rate.o \
+ mlme.o \
+ iface.o \
+ rate.o \
michael.o \
- regdomain.o \
tkip.o \
aes_ccm.o \
cfg.o \
@@ -29,7 +28,7 @@ mac80211-y := \
util.o \
event.o
-mac80211-$(CONFIG_MAC80211_LEDS) += ieee80211_led.o
+mac80211-$(CONFIG_MAC80211_LEDS) += led.o
mac80211-$(CONFIG_NET_SCHED) += wme.o
mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
debugfs.o \
@@ -37,11 +36,15 @@ mac80211-$(CONFIG_MAC80211_DEBUGFS) += \
debugfs_netdev.o \
debugfs_key.o
+mac80211-$(CONFIG_MAC80211_MESH) += \
+ mesh.o \
+ mesh_pathtbl.o \
+ mesh_plink.o \
+ mesh_hwmp.o
+
# Build rate control algorithm(s)
-CFLAGS_rc80211_simple.o += -DRC80211_SIMPLE_COMPILE
CFLAGS_rc80211_pid_algo.o += -DRC80211_PID_COMPILE
-mac80211-$(CONFIG_MAC80211_RC_SIMPLE) += rc80211_simple.o
mac80211-$(CONFIG_MAC80211_RC_PID) += $(rc-pid-$(CONFIG_MAC80211_RC_PID))
# Modular rate algorithms are assigned to mac80211-m - make separate modules
diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c
index e62fe55944b8..59f1691f62c8 100644
--- a/net/mac80211/aes_ccm.c
+++ b/net/mac80211/aes_ccm.c
@@ -13,7 +13,7 @@
#include <linux/err.h>
#include <net/mac80211.h>
-#include "ieee80211_key.h"
+#include "key.h"
#include "aes_ccm.h"
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 22c9619ba776..699d97b8de5e 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -14,7 +14,8 @@
#include <net/cfg80211.h>
#include "ieee80211_i.h"
#include "cfg.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
+#include "mesh.h"
static enum ieee80211_if_types
nl80211_type_to_mac80211_type(enum nl80211_iftype type)
@@ -28,16 +29,26 @@ nl80211_type_to_mac80211_type(enum nl80211_iftype type)
return IEEE80211_IF_TYPE_STA;
case NL80211_IFTYPE_MONITOR:
return IEEE80211_IF_TYPE_MNTR;
+#ifdef CONFIG_MAC80211_MESH
+ case NL80211_IFTYPE_MESH_POINT:
+ return IEEE80211_IF_TYPE_MESH_POINT;
+#endif
+ case NL80211_IFTYPE_WDS:
+ return IEEE80211_IF_TYPE_WDS;
default:
return IEEE80211_IF_TYPE_INVALID;
}
}
static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
- enum nl80211_iftype type)
+ enum nl80211_iftype type, u32 *flags,
+ struct vif_params *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
enum ieee80211_if_types itype;
+ struct net_device *dev;
+ struct ieee80211_sub_if_data *sdata;
+ int err;
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
return -ENODEV;
@@ -46,7 +57,13 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
if (itype == IEEE80211_IF_TYPE_INVALID)
return -EINVAL;
- return ieee80211_if_add(local->mdev, name, NULL, itype);
+ err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
+ if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags)
+ return err;
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ sdata->u.mntr_flags = *flags;
+ return 0;
}
static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
@@ -69,7 +86,8 @@ static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
}
static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
- enum nl80211_iftype type)
+ enum nl80211_iftype type, u32 *flags,
+ struct vif_params *params)
{
struct ieee80211_local *local = wiphy_priv(wiphy);
struct net_device *dev;
@@ -99,6 +117,15 @@ static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
ieee80211_if_reinit(dev);
ieee80211_if_set_type(dev, itype);
+ if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
+ ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
+ params->mesh_id_len,
+ params->mesh_id);
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
+ return 0;
+
+ sdata->u.mntr_flags = *flags;
return 0;
}
@@ -109,7 +136,8 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta = NULL;
enum ieee80211_key_alg alg;
- int ret;
+ struct ieee80211_key *key;
+ int err;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -128,21 +156,28 @@ static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
return -EINVAL;
}
+ key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
+ if (!key)
+ return -ENOMEM;
+
+ rcu_read_lock();
+
if (mac_addr) {
sta = sta_info_get(sdata->local, mac_addr);
- if (!sta)
- return -ENOENT;
+ if (!sta) {
+ ieee80211_key_free(key);
+ err = -ENOENT;
+ goto out_unlock;
+ }
}
- ret = 0;
- if (!ieee80211_key_alloc(sdata, sta, alg, key_idx,
- params->key_len, params->key))
- ret = -ENOMEM;
+ ieee80211_key_link(key, sdata, sta);
- if (sta)
- sta_info_put(sta);
+ err = 0;
+ out_unlock:
+ rcu_read_unlock();
- return ret;
+ return err;
}
static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
@@ -154,27 +189,37 @@ static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ rcu_read_lock();
+
if (mac_addr) {
+ ret = -ENOENT;
+
sta = sta_info_get(sdata->local, mac_addr);
if (!sta)
- return -ENOENT;
+ goto out_unlock;
- ret = 0;
- if (sta->key)
+ if (sta->key) {
ieee80211_key_free(sta->key);
- else
- ret = -ENOENT;
+ WARN_ON(sta->key);
+ ret = 0;
+ }
- sta_info_put(sta);
- return ret;
+ goto out_unlock;
}
- if (!sdata->keys[key_idx])
- return -ENOENT;
+ if (!sdata->keys[key_idx]) {
+ ret = -ENOENT;
+ goto out_unlock;
+ }
ieee80211_key_free(sdata->keys[key_idx]);
+ WARN_ON(sdata->keys[key_idx]);
- return 0;
+ ret = 0;
+ out_unlock:
+ rcu_read_unlock();
+
+ return ret;
}
static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
@@ -191,6 +236,8 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
u16 iv16;
int err = -ENOENT;
+ rcu_read_lock();
+
if (mac_addr) {
sta = sta_info_get(sdata->local, mac_addr);
if (!sta)
@@ -254,8 +301,7 @@ static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
err = 0;
out:
- if (sta)
- sta_info_put(sta);
+ rcu_read_unlock();
return err;
}
@@ -265,35 +311,83 @@ static int ieee80211_config_default_key(struct wiphy *wiphy,
{
struct ieee80211_sub_if_data *sdata;
+ rcu_read_lock();
+
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ieee80211_set_default_key(sdata, key_idx);
+ rcu_read_unlock();
+
return 0;
}
+static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
+{
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+
+ sinfo->filled = STATION_INFO_INACTIVE_TIME |
+ STATION_INFO_RX_BYTES |
+ STATION_INFO_TX_BYTES;
+
+ sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
+ sinfo->rx_bytes = sta->rx_bytes;
+ sinfo->tx_bytes = sta->tx_bytes;
+
+ if (ieee80211_vif_is_mesh(&sdata->vif)) {
+#ifdef CONFIG_MAC80211_MESH
+ sinfo->filled |= STATION_INFO_LLID |
+ STATION_INFO_PLID |
+ STATION_INFO_PLINK_STATE;
+
+ sinfo->llid = le16_to_cpu(sta->llid);
+ sinfo->plid = le16_to_cpu(sta->plid);
+ sinfo->plink_state = sta->plink_state;
+#endif
+ }
+}
+
+
+static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
+ int idx, u8 *mac, struct station_info *sinfo)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct sta_info *sta;
+ int ret = -ENOENT;
+
+ rcu_read_lock();
+
+ sta = sta_info_get_by_idx(local, idx, dev);
+ if (sta) {
+ ret = 0;
+ memcpy(mac, sta->addr, ETH_ALEN);
+ sta_set_sinfo(sta, sinfo);
+ }
+
+ rcu_read_unlock();
+
+ return ret;
+}
+
static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
- u8 *mac, struct station_stats *stats)
+ u8 *mac, struct station_info *sinfo)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct sta_info *sta;
+ int ret = -ENOENT;
- sta = sta_info_get(local, mac);
- if (!sta)
- return -ENOENT;
+ rcu_read_lock();
/* XXX: verify sta->dev == dev */
- stats->filled = STATION_STAT_INACTIVE_TIME |
- STATION_STAT_RX_BYTES |
- STATION_STAT_TX_BYTES;
-
- stats->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
- stats->rx_bytes = sta->rx_bytes;
- stats->tx_bytes = sta->tx_bytes;
+ sta = sta_info_get(local, mac);
+ if (sta) {
+ ret = 0;
+ sta_set_sinfo(sta, sinfo);
+ }
- sta_info_put(sta);
+ rcu_read_unlock();
- return 0;
+ return ret;
}
/*
@@ -486,8 +580,8 @@ static void ieee80211_send_layer2_update(struct sta_info *sta)
msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
- skb->dev = sta->dev;
- skb->protocol = eth_type_trans(skb, sta->dev);
+ skb->dev = sta->sdata->dev;
+ skb->protocol = eth_type_trans(skb, sta->sdata->dev);
memset(skb->cb, 0, sizeof(skb->cb));
netif_rx(skb);
}
@@ -498,7 +592,14 @@ static void sta_apply_parameters(struct ieee80211_local *local,
{
u32 rates;
int i, j;
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+
+ /*
+ * FIXME: updating the flags is racy when this function is
+ * called from ieee80211_change_station(), this will
+ * be resolved in a future patch.
+ */
if (params->station_flags & STATION_FLAG_CHANGED) {
sta->flags &= ~WLAN_STA_AUTHORIZED;
@@ -514,6 +615,13 @@ static void sta_apply_parameters(struct ieee80211_local *local,
sta->flags |= WLAN_STA_WME;
}
+ /*
+ * FIXME: updating the following information is racy when this
+ * function is called from ieee80211_change_station().
+ * However, all this information should be static so
+ * maybe we should just reject attemps to change it.
+ */
+
if (params->aid) {
sta->aid = params->aid;
if (sta->aid > IEEE80211_MAX_AID)
@@ -525,15 +633,27 @@ static void sta_apply_parameters(struct ieee80211_local *local,
if (params->supported_rates) {
rates = 0;
- mode = local->oper_hw_mode;
+ sband = local->hw.wiphy->bands[local->oper_channel->band];
+
for (i = 0; i < params->supported_rates_len; i++) {
int rate = (params->supported_rates[i] & 0x7f) * 5;
- for (j = 0; j < mode->num_rates; j++) {
- if (mode->rates[j].rate == rate)
+ for (j = 0; j < sband->n_bitrates; j++) {
+ if (sband->bitrates[j].bitrate == rate)
rates |= BIT(j);
}
}
- sta->supp_rates = rates;
+ sta->supp_rates[local->oper_channel->band] = rates;
+ }
+
+ if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
+ switch (params->plink_action) {
+ case PLINK_ACTION_OPEN:
+ mesh_plink_open(sta);
+ break;
+ case PLINK_ACTION_BLOCK:
+ mesh_plink_block(sta);
+ break;
+ }
}
}
@@ -543,18 +663,12 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct sta_info *sta;
struct ieee80211_sub_if_data *sdata;
+ int err;
/* Prevent a race with changing the rate control algorithm */
if (!netif_running(dev))
return -ENETDOWN;
- /* XXX: get sta belonging to dev */
- sta = sta_info_get(local, mac);
- if (sta) {
- sta_info_put(sta);
- return -EEXIST;
- }
-
if (params->vlan) {
sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
@@ -564,22 +678,36 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
} else
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- sta = sta_info_add(local, dev, mac, GFP_KERNEL);
+ if (compare_ether_addr(mac, dev->dev_addr) == 0)
+ return -EINVAL;
+
+ if (is_multicast_ether_addr(mac))
+ return -EINVAL;
+
+ sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
if (!sta)
return -ENOMEM;
- sta->dev = sdata->dev;
- if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
- sdata->vif.type == IEEE80211_IF_TYPE_AP)
- ieee80211_send_layer2_update(sta);
-
sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
sta_apply_parameters(local, sta, params);
rate_control_rate_init(sta, local);
- sta_info_put(sta);
+ rcu_read_lock();
+
+ err = sta_info_insert(sta);
+ if (err) {
+ /* STA has been freed */
+ rcu_read_unlock();
+ return err;
+ }
+
+ if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
+ sdata->vif.type == IEEE80211_IF_TYPE_AP)
+ ieee80211_send_layer2_update(sta);
+
+ rcu_read_unlock();
return 0;
}
@@ -587,19 +715,26 @@ static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
u8 *mac)
{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = sdata->local;
struct sta_info *sta;
if (mac) {
+ rcu_read_lock();
+
/* XXX: get sta belonging to dev */
sta = sta_info_get(local, mac);
- if (!sta)
+ if (!sta) {
+ rcu_read_unlock();
return -ENOENT;
+ }
+
+ sta_info_unlink(&sta);
+ rcu_read_unlock();
- sta_info_free(sta);
- sta_info_put(sta);
+ sta_info_destroy(sta);
} else
- sta_info_flush(local, dev);
+ sta_info_flush(local, sdata);
return 0;
}
@@ -613,28 +748,203 @@ static int ieee80211_change_station(struct wiphy *wiphy,
struct sta_info *sta;
struct ieee80211_sub_if_data *vlansdata;
+ rcu_read_lock();
+
/* XXX: get sta belonging to dev */
sta = sta_info_get(local, mac);
- if (!sta)
+ if (!sta) {
+ rcu_read_unlock();
return -ENOENT;
+ }
- if (params->vlan && params->vlan != sta->dev) {
+ if (params->vlan && params->vlan != sta->sdata->dev) {
vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
- vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
+ vlansdata->vif.type != IEEE80211_IF_TYPE_AP) {
+ rcu_read_unlock();
return -EINVAL;
+ }
- sta->dev = params->vlan;
+ sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
ieee80211_send_layer2_update(sta);
}
sta_apply_parameters(local, sta, params);
- sta_info_put(sta);
+ rcu_read_unlock();
+
+ return 0;
+}
+
+#ifdef CONFIG_MAC80211_MESH
+static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
+ u8 *dst, u8 *next_hop)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+ struct sta_info *sta;
+ int err;
+
+ if (!netif_running(dev))
+ return -ENETDOWN;
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
+ return -ENOTSUPP;
+
+ rcu_read_lock();
+ sta = sta_info_get(local, next_hop);
+ if (!sta) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+ err = mesh_path_add(dst, dev);
+ if (err) {
+ rcu_read_unlock();
+ return err;
+ }
+
+ mpath = mesh_path_lookup(dst, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return -ENXIO;
+ }
+ mesh_path_fix_nexthop(mpath, sta);
+
+ rcu_read_unlock();
+ return 0;
+}
+
+static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
+ u8 *dst)
+{
+ if (dst)
+ return mesh_path_del(dst, dev);
+
+ mesh_path_flush(dev);
+ return 0;
+}
+
+static int ieee80211_change_mpath(struct wiphy *wiphy,
+ struct net_device *dev,
+ u8 *dst, u8 *next_hop)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+ struct sta_info *sta;
+
+ if (!netif_running(dev))
+ return -ENETDOWN;
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
+ return -ENOTSUPP;
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, next_hop);
+ if (!sta) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+
+ mpath = mesh_path_lookup(dst, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+
+ mesh_path_fix_nexthop(mpath, sta);
+
+ rcu_read_unlock();
+ return 0;
+}
+
+static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
+ struct mpath_info *pinfo)
+{
+ if (mpath->next_hop)
+ memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
+ else
+ memset(next_hop, 0, ETH_ALEN);
+
+ pinfo->filled = MPATH_INFO_FRAME_QLEN |
+ MPATH_INFO_DSN |
+ MPATH_INFO_METRIC |
+ MPATH_INFO_EXPTIME |
+ MPATH_INFO_DISCOVERY_TIMEOUT |
+ MPATH_INFO_DISCOVERY_RETRIES |
+ MPATH_INFO_FLAGS;
+
+ pinfo->frame_qlen = mpath->frame_queue.qlen;
+ pinfo->dsn = mpath->dsn;
+ pinfo->metric = mpath->metric;
+ if (time_before(jiffies, mpath->exp_time))
+ pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
+ pinfo->discovery_timeout =
+ jiffies_to_msecs(mpath->discovery_timeout);
+ pinfo->discovery_retries = mpath->discovery_retries;
+ pinfo->flags = 0;
+ if (mpath->flags & MESH_PATH_ACTIVE)
+ pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
+ if (mpath->flags & MESH_PATH_RESOLVING)
+ pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
+ if (mpath->flags & MESH_PATH_DSN_VALID)
+ pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
+ if (mpath->flags & MESH_PATH_FIXED)
+ pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
+ if (mpath->flags & MESH_PATH_RESOLVING)
+ pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
+
+ pinfo->flags = mpath->flags;
+}
+
+static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
+ u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
+
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
+ return -ENOTSUPP;
+
+ rcu_read_lock();
+ mpath = mesh_path_lookup(dst, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+ memcpy(dst, mpath->dst, ETH_ALEN);
+ mpath_set_pinfo(mpath, next_hop, pinfo);
+ rcu_read_unlock();
+ return 0;
+}
+
+static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
+ int idx, u8 *dst, u8 *next_hop,
+ struct mpath_info *pinfo)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
+ return -ENOTSUPP;
+
+ rcu_read_lock();
+ mpath = mesh_path_lookup_by_idx(idx, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+ memcpy(dst, mpath->dst, ETH_ALEN);
+ mpath_set_pinfo(mpath, next_hop, pinfo);
+ rcu_read_unlock();
return 0;
}
+#endif
struct cfg80211_ops mac80211_config_ops = {
.add_virtual_intf = ieee80211_add_iface,
@@ -651,4 +961,12 @@ struct cfg80211_ops mac80211_config_ops = {
.del_station = ieee80211_del_station,
.change_station = ieee80211_change_station,
.get_station = ieee80211_get_station,
+ .dump_station = ieee80211_dump_station,
+#ifdef CONFIG_MAC80211_MESH
+ .add_mpath = ieee80211_add_mpath,
+ .del_mpath = ieee80211_del_mpath,
+ .change_mpath = ieee80211_change_mpath,
+ .get_mpath = ieee80211_get_mpath,
+ .dump_mpath = ieee80211_dump_mpath,
+#endif
};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 60514b2c97b9..1cccbfd781f6 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -10,7 +10,7 @@
#include <linux/debugfs.h>
#include <linux/rtnetlink.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
#include "debugfs.h"
int mac80211_open_file_generic(struct inode *inode, struct file *file)
@@ -19,41 +19,6 @@ int mac80211_open_file_generic(struct inode *inode, struct file *file)
return 0;
}
-static const char *ieee80211_mode_str(int mode)
-{
- switch (mode) {
- case MODE_IEEE80211A:
- return "IEEE 802.11a";
- case MODE_IEEE80211B:
- return "IEEE 802.11b";
- case MODE_IEEE80211G:
- return "IEEE 802.11g";
- default:
- return "UNKNOWN";
- }
-}
-
-static ssize_t modes_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- struct ieee80211_local *local = file->private_data;
- struct ieee80211_hw_mode *mode;
- char buf[150], *p = buf;
-
- /* FIXME: locking! */
- list_for_each_entry(mode, &local->modes_list, list) {
- p += scnprintf(p, sizeof(buf)+buf-p,
- "%s\n", ieee80211_mode_str(mode->mode));
- }
-
- return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
-}
-
-static const struct file_operations modes_ops = {
- .read = modes_read,
- .open = mac80211_open_file_generic,
-};
-
#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
static ssize_t name## _read(struct file *file, char __user *userbuf, \
size_t count, loff_t *ppos) \
@@ -72,7 +37,7 @@ static const struct file_operations name## _ops = { \
};
#define DEBUGFS_ADD(name) \
- local->debugfs.name = debugfs_create_file(#name, 0444, phyd, \
+ local->debugfs.name = debugfs_create_file(#name, 0400, phyd, \
local, &name## _ops);
#define DEBUGFS_DEL(name) \
@@ -80,10 +45,8 @@ static const struct file_operations name## _ops = { \
local->debugfs.name = NULL;
-DEBUGFS_READONLY_FILE(channel, 20, "%d",
- local->hw.conf.channel);
DEBUGFS_READONLY_FILE(frequency, 20, "%d",
- local->hw.conf.freq);
+ local->hw.conf.channel->center_freq);
DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
local->hw.conf.antenna_sel_tx);
DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
@@ -100,8 +63,6 @@ DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
local->long_retry_limit);
DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
local->total_ps_buffered);
-DEBUGFS_READONLY_FILE(mode, 20, "%s",
- ieee80211_mode_str(local->hw.conf.phymode));
DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
local->wep_iv & 0xffffff);
DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
@@ -169,7 +130,7 @@ static const struct file_operations stats_ ##name## _ops = { \
};
#define DEBUGFS_STATS_ADD(name) \
- local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
+ local->debugfs.stats.name = debugfs_create_file(#name, 0400, statsd,\
local, &stats_ ##name## _ops);
#define DEBUGFS_STATS_DEL(name) \
@@ -294,7 +255,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
local->debugfs.stations = debugfs_create_dir("stations", phyd);
local->debugfs.keys = debugfs_create_dir("keys", phyd);
- DEBUGFS_ADD(channel);
DEBUGFS_ADD(frequency);
DEBUGFS_ADD(antenna_sel_tx);
DEBUGFS_ADD(antenna_sel_rx);
@@ -304,9 +264,7 @@ void debugfs_hw_add(struct ieee80211_local *local)
DEBUGFS_ADD(short_retry_limit);
DEBUGFS_ADD(long_retry_limit);
DEBUGFS_ADD(total_ps_buffered);
- DEBUGFS_ADD(mode);
DEBUGFS_ADD(wep_iv);
- DEBUGFS_ADD(modes);
statsd = debugfs_create_dir("statistics", phyd);
local->debugfs.statistics = statsd;
@@ -356,7 +314,6 @@ void debugfs_hw_add(struct ieee80211_local *local)
void debugfs_hw_del(struct ieee80211_local *local)
{
- DEBUGFS_DEL(channel);
DEBUGFS_DEL(frequency);
DEBUGFS_DEL(antenna_sel_tx);
DEBUGFS_DEL(antenna_sel_rx);
@@ -366,9 +323,7 @@ void debugfs_hw_del(struct ieee80211_local *local)
DEBUGFS_DEL(short_retry_limit);
DEBUGFS_DEL(long_retry_limit);
DEBUGFS_DEL(total_ps_buffered);
- DEBUGFS_DEL(mode);
DEBUGFS_DEL(wep_iv);
- DEBUGFS_DEL(modes);
DEBUGFS_STATS_DEL(transmitted_fragment_count);
DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
diff --git a/net/mac80211/debugfs_key.c b/net/mac80211/debugfs_key.c
index c881524c8725..879e7210458a 100644
--- a/net/mac80211/debugfs_key.c
+++ b/net/mac80211/debugfs_key.c
@@ -10,7 +10,7 @@
#include <linux/kobject.h>
#include "ieee80211_i.h"
-#include "ieee80211_key.h"
+#include "key.h"
#include "debugfs.h"
#include "debugfs_key.h"
@@ -184,23 +184,36 @@ KEY_OPS(key);
key->debugfs.name = debugfs_create_file(#name, 0400,\
key->debugfs.dir, key, &key_##name##_ops);
-void ieee80211_debugfs_key_add(struct ieee80211_local *local,
- struct ieee80211_key *key)
-{
+void ieee80211_debugfs_key_add(struct ieee80211_key *key)
+ {
static int keycount;
- char buf[20];
+ char buf[50];
+ DECLARE_MAC_BUF(mac);
+ struct sta_info *sta;
- if (!local->debugfs.keys)
+ if (!key->local->debugfs.keys)
return;
sprintf(buf, "%d", keycount);
+ key->debugfs.cnt = keycount;
keycount++;
key->debugfs.dir = debugfs_create_dir(buf,
- local->debugfs.keys);
+ key->local->debugfs.keys);
if (!key->debugfs.dir)
return;
+ rcu_read_lock();
+ sta = rcu_dereference(key->sta);
+ if (sta)
+ sprintf(buf, "../../stations/%s", print_mac(mac, sta->addr));
+ rcu_read_unlock();
+
+ /* using sta as a boolean is fine outside RCU lock */
+ if (sta)
+ key->debugfs.stalink =
+ debugfs_create_symlink("station", key->debugfs.dir, buf);
+
DEBUGFS_ADD(keylen);
DEBUGFS_ADD(flags);
DEBUGFS_ADD(keyidx);
@@ -246,7 +259,7 @@ void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata)
if (!sdata->debugfsdir)
return;
- sprintf(buf, "../keys/%d", sdata->default_key->conf.keyidx);
+ sprintf(buf, "../keys/%d", sdata->default_key->debugfs.cnt);
sdata->debugfs.default_key =
debugfs_create_symlink("default_key", sdata->debugfsdir, buf);
}
@@ -258,19 +271,6 @@ void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data *sdata)
debugfs_remove(sdata->debugfs.default_key);
sdata->debugfs.default_key = NULL;
}
-void ieee80211_debugfs_key_sta_link(struct ieee80211_key *key,
- struct sta_info *sta)
-{
- char buf[50];
- DECLARE_MAC_BUF(mac);
-
- if (!key->debugfs.dir)
- return;
-
- sprintf(buf, "../../stations/%s", print_mac(mac, sta->addr));
- key->debugfs.stalink =
- debugfs_create_symlink("station", key->debugfs.dir, buf);
-}
void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
struct sta_info *sta)
diff --git a/net/mac80211/debugfs_key.h b/net/mac80211/debugfs_key.h
index aecfce395da6..b1a3754ee240 100644
--- a/net/mac80211/debugfs_key.h
+++ b/net/mac80211/debugfs_key.h
@@ -2,18 +2,14 @@
#define __MAC80211_DEBUGFS_KEY_H
#ifdef CONFIG_MAC80211_DEBUGFS
-void ieee80211_debugfs_key_add(struct ieee80211_local *local,
- struct ieee80211_key *key);
+void ieee80211_debugfs_key_add(struct ieee80211_key *key);
void ieee80211_debugfs_key_remove(struct ieee80211_key *key);
void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata);
void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data *sdata);
-void ieee80211_debugfs_key_sta_link(struct ieee80211_key *key,
- struct sta_info *sta);
void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
struct sta_info *sta);
#else
-static inline void ieee80211_debugfs_key_add(struct ieee80211_local *local,
- struct ieee80211_key *key)
+static inline void ieee80211_debugfs_key_add(struct ieee80211_key *key)
{}
static inline void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
{}
@@ -23,9 +19,6 @@ static inline void ieee80211_debugfs_key_add_default(
static inline void ieee80211_debugfs_key_remove_default(
struct ieee80211_sub_if_data *sdata)
{}
-static inline void ieee80211_debugfs_key_sta_link(
- struct ieee80211_key *key, struct sta_info *sta)
-{}
static inline void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
struct sta_info *sta)
{}
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 829872a3ae81..e3326d046944 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -17,7 +17,7 @@
#include <net/mac80211.h>
#include <net/cfg80211.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
#include "debugfs.h"
#include "debugfs_netdev.h"
@@ -31,14 +31,39 @@ static ssize_t ieee80211_if_read(
ssize_t ret = -EINVAL;
read_lock(&dev_base_lock);
- if (sdata->dev->reg_state == NETREG_REGISTERED) {
+ if (sdata->dev->reg_state == NETREG_REGISTERED)
ret = (*format)(sdata, buf, sizeof(buf));
- ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
- }
read_unlock(&dev_base_lock);
+
+ if (ret != -EINVAL)
+ ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+
return ret;
}
+#ifdef CONFIG_MAC80211_MESH
+static ssize_t ieee80211_if_write(
+ struct ieee80211_sub_if_data *sdata,
+ char const __user *userbuf,
+ size_t count, loff_t *ppos,
+ int (*format)(struct ieee80211_sub_if_data *, char *))
+{
+ char buf[10];
+ int buf_size;
+
+ memset(buf, 0x00, sizeof(buf));
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, userbuf, buf_size))
+ return count;
+ read_lock(&dev_base_lock);
+ if (sdata->dev->reg_state == NETREG_REGISTERED)
+ (*format)(sdata, buf);
+ read_unlock(&dev_base_lock);
+
+ return count;
+}
+#endif
+
#define IEEE80211_IF_FMT(name, field, format_string) \
static ssize_t ieee80211_if_fmt_##name( \
const struct ieee80211_sub_if_data *sdata, char *buf, \
@@ -46,6 +71,19 @@ static ssize_t ieee80211_if_fmt_##name( \
{ \
return scnprintf(buf, buflen, format_string, sdata->field); \
}
+#define IEEE80211_IF_WFMT(name, field, type) \
+static int ieee80211_if_wfmt_##name( \
+ struct ieee80211_sub_if_data *sdata, char *buf) \
+{ \
+ unsigned long tmp; \
+ char *endp; \
+ \
+ tmp = simple_strtoul(buf, &endp, 0); \
+ if ((endp == buf) || ((type)tmp != tmp)) \
+ return -EINVAL; \
+ sdata->field = tmp; \
+ return 0; \
+}
#define IEEE80211_IF_FMT_DEC(name, field) \
IEEE80211_IF_FMT(name, field, "%d\n")
#define IEEE80211_IF_FMT_HEX(name, field) \
@@ -88,10 +126,37 @@ static const struct file_operations name##_ops = { \
IEEE80211_IF_FMT_##format(name, field) \
__IEEE80211_IF_FILE(name)
+#define __IEEE80211_IF_WFILE(name) \
+static ssize_t ieee80211_if_read_##name(struct file *file, \
+ char __user *userbuf, \
+ size_t count, loff_t *ppos) \
+{ \
+ return ieee80211_if_read(file->private_data, \
+ userbuf, count, ppos, \
+ ieee80211_if_fmt_##name); \
+} \
+static ssize_t ieee80211_if_write_##name(struct file *file, \
+ const char __user *userbuf, \
+ size_t count, loff_t *ppos) \
+{ \
+ return ieee80211_if_write(file->private_data, \
+ userbuf, count, ppos, \
+ ieee80211_if_wfmt_##name); \
+} \
+static const struct file_operations name##_ops = { \
+ .read = ieee80211_if_read_##name, \
+ .write = ieee80211_if_write_##name, \
+ .open = mac80211_open_file_generic, \
+}
+
+#define IEEE80211_IF_WFILE(name, field, format, type) \
+ IEEE80211_IF_FMT_##format(name, field) \
+ IEEE80211_IF_WFMT(name, field, type) \
+ __IEEE80211_IF_WFILE(name)
+
/* common attributes */
IEEE80211_IF_FILE(channel_use, channel_use, DEC);
IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
-IEEE80211_IF_FILE(ieee802_1x_pac, ieee802_1x_pac, DEC);
/* STA/IBSS attributes */
IEEE80211_IF_FILE(state, u.sta.state, DEC);
@@ -107,6 +172,7 @@ IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
+IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
static ssize_t ieee80211_if_fmt_flags(
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
@@ -140,15 +206,50 @@ __IEEE80211_IF_FILE(num_buffered_multicast);
/* WDS attributes */
IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
+#ifdef CONFIG_MAC80211_MESH
+/* Mesh stats attributes */
+IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
+IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
+IEEE80211_IF_FILE(dropped_frames_no_route,
+ u.sta.mshstats.dropped_frames_no_route, DEC);
+IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);
+
+/* Mesh parameters */
+IEEE80211_IF_WFILE(dot11MeshMaxRetries,
+ u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
+IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
+ u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
+ u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
+ u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
+IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8);
+IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
+ u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
+ u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
+IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
+ u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
+ u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
+IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
+ u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
+IEEE80211_IF_WFILE(path_refresh_time,
+ u.sta.mshcfg.path_refresh_time, DEC, u32);
+IEEE80211_IF_WFILE(min_discovery_timeout,
+ u.sta.mshcfg.min_discovery_timeout, DEC, u16);
+#endif
+
+
#define DEBUGFS_ADD(name, type)\
- sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
+ sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
sdata->debugfsdir, sdata, &name##_ops);
static void add_sta_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_ADD(channel_use, sta);
DEBUGFS_ADD(drop_unencrypted, sta);
- DEBUGFS_ADD(ieee802_1x_pac, sta);
DEBUGFS_ADD(state, sta);
DEBUGFS_ADD(bssid, sta);
DEBUGFS_ADD(prev_bssid, sta);
@@ -163,13 +264,13 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
DEBUGFS_ADD(auth_alg, sta);
DEBUGFS_ADD(auth_transaction, sta);
DEBUGFS_ADD(flags, sta);
+ DEBUGFS_ADD(num_beacons_sta, sta);
}
static void add_ap_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_ADD(channel_use, ap);
DEBUGFS_ADD(drop_unencrypted, ap);
- DEBUGFS_ADD(ieee802_1x_pac, ap);
DEBUGFS_ADD(num_sta_ps, ap);
DEBUGFS_ADD(dtim_count, ap);
DEBUGFS_ADD(num_beacons, ap);
@@ -182,7 +283,6 @@ static void add_wds_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_ADD(channel_use, wds);
DEBUGFS_ADD(drop_unencrypted, wds);
- DEBUGFS_ADD(ieee802_1x_pac, wds);
DEBUGFS_ADD(peer, wds);
}
@@ -190,19 +290,63 @@ static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_ADD(channel_use, vlan);
DEBUGFS_ADD(drop_unencrypted, vlan);
- DEBUGFS_ADD(ieee802_1x_pac, vlan);
}
static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
{
}
+#ifdef CONFIG_MAC80211_MESH
+#define MESHSTATS_ADD(name)\
+ sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
+ sdata->mesh_stats_dir, sdata, &name##_ops);
+
+static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
+{
+ sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
+ sdata->debugfsdir);
+ MESHSTATS_ADD(fwded_frames);
+ MESHSTATS_ADD(dropped_frames_ttl);
+ MESHSTATS_ADD(dropped_frames_no_route);
+ MESHSTATS_ADD(estab_plinks);
+}
+
+#define MESHPARAMS_ADD(name)\
+ sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
+ sdata->mesh_config_dir, sdata, &name##_ops);
+
+static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
+{
+ sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
+ sdata->debugfsdir);
+ MESHPARAMS_ADD(dot11MeshMaxRetries);
+ MESHPARAMS_ADD(dot11MeshRetryTimeout);
+ MESHPARAMS_ADD(dot11MeshConfirmTimeout);
+ MESHPARAMS_ADD(dot11MeshHoldingTimeout);
+ MESHPARAMS_ADD(dot11MeshTTL);
+ MESHPARAMS_ADD(auto_open_plinks);
+ MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
+ MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
+ MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
+ MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
+ MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
+ MESHPARAMS_ADD(path_refresh_time);
+ MESHPARAMS_ADD(min_discovery_timeout);
+}
+#endif
+
static void add_files(struct ieee80211_sub_if_data *sdata)
{
if (!sdata->debugfsdir)
return;
switch (sdata->vif.type) {
+ case IEEE80211_IF_TYPE_MESH_POINT:
+#ifdef CONFIG_MAC80211_MESH
+ add_mesh_stats(sdata);
+ add_mesh_config(sdata);
+#endif
+ /* fall through */
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
add_sta_files(sdata);
@@ -234,7 +378,6 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_DEL(channel_use, sta);
DEBUGFS_DEL(drop_unencrypted, sta);
- DEBUGFS_DEL(ieee802_1x_pac, sta);
DEBUGFS_DEL(state, sta);
DEBUGFS_DEL(bssid, sta);
DEBUGFS_DEL(prev_bssid, sta);
@@ -249,13 +392,13 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
DEBUGFS_DEL(auth_alg, sta);
DEBUGFS_DEL(auth_transaction, sta);
DEBUGFS_DEL(flags, sta);
+ DEBUGFS_DEL(num_beacons_sta, sta);
}
static void del_ap_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_DEL(channel_use, ap);
DEBUGFS_DEL(drop_unencrypted, ap);
- DEBUGFS_DEL(ieee802_1x_pac, ap);
DEBUGFS_DEL(num_sta_ps, ap);
DEBUGFS_DEL(dtim_count, ap);
DEBUGFS_DEL(num_beacons, ap);
@@ -268,7 +411,6 @@ static void del_wds_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_DEL(channel_use, wds);
DEBUGFS_DEL(drop_unencrypted, wds);
- DEBUGFS_DEL(ieee802_1x_pac, wds);
DEBUGFS_DEL(peer, wds);
}
@@ -276,19 +418,67 @@ static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
{
DEBUGFS_DEL(channel_use, vlan);
DEBUGFS_DEL(drop_unencrypted, vlan);
- DEBUGFS_DEL(ieee802_1x_pac, vlan);
}
static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
{
}
+#ifdef CONFIG_MAC80211_MESH
+#define MESHSTATS_DEL(name) \
+ do { \
+ debugfs_remove(sdata->mesh_stats.name); \
+ sdata->mesh_stats.name = NULL; \
+ } while (0)
+
+static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
+{
+ MESHSTATS_DEL(fwded_frames);
+ MESHSTATS_DEL(dropped_frames_ttl);
+ MESHSTATS_DEL(dropped_frames_no_route);
+ MESHSTATS_DEL(estab_plinks);
+ debugfs_remove(sdata->mesh_stats_dir);
+ sdata->mesh_stats_dir = NULL;
+}
+
+#define MESHPARAMS_DEL(name) \
+ do { \
+ debugfs_remove(sdata->mesh_config.name); \
+ sdata->mesh_config.name = NULL; \
+ } while (0)
+
+static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
+{
+ MESHPARAMS_DEL(dot11MeshMaxRetries);
+ MESHPARAMS_DEL(dot11MeshRetryTimeout);
+ MESHPARAMS_DEL(dot11MeshConfirmTimeout);
+ MESHPARAMS_DEL(dot11MeshHoldingTimeout);
+ MESHPARAMS_DEL(dot11MeshTTL);
+ MESHPARAMS_DEL(auto_open_plinks);
+ MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
+ MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
+ MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
+ MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
+ MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
+ MESHPARAMS_DEL(path_refresh_time);
+ MESHPARAMS_DEL(min_discovery_timeout);
+ debugfs_remove(sdata->mesh_config_dir);
+ sdata->mesh_config_dir = NULL;
+}
+#endif
+
static void del_files(struct ieee80211_sub_if_data *sdata, int type)
{
if (!sdata->debugfsdir)
return;
switch (type) {
+ case IEEE80211_IF_TYPE_MESH_POINT:
+#ifdef CONFIG_MAC80211_MESH
+ del_mesh_stats(sdata);
+ del_mesh_config(sdata);
+#endif
+ /* fall through */
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
del_sta_files(sdata);
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 8f5944c53d4e..6d47a1d31b37 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, \
#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
-#define STA_READ_RATE(name, field) \
-static ssize_t sta_##name##_read(struct file *file, \
- char __user *userbuf, \
- size_t count, loff_t *ppos) \
-{ \
- struct sta_info *sta = file->private_data; \
- struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
- struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
- char buf[20]; \
- int res = scnprintf(buf, sizeof(buf), "%d\n", \
- (sta->field >= 0 && \
- sta->field < mode->num_rates) ? \
- mode->rates[sta->field].rate : -1); \
- return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+#define STA_OPS(name) \
+static const struct file_operations sta_ ##name## _ops = { \
+ .read = sta_##name##_read, \
+ .open = mac80211_open_file_generic, \
}
-#define STA_OPS(name) \
+#define STA_OPS_WR(name) \
static const struct file_operations sta_ ##name## _ops = { \
.read = sta_##name##_read, \
+ .write = sta_##name##_write, \
.open = mac80211_open_file_generic, \
}
@@ -60,7 +51,7 @@ static const struct file_operations sta_ ##name## _ops = { \
STA_OPS(name)
STA_FILE(aid, aid, D);
-STA_FILE(dev, dev->name, S);
+STA_FILE(dev, sdata->dev->name, S);
STA_FILE(rx_packets, rx_packets, LU);
STA_FILE(tx_packets, tx_packets, LU);
STA_FILE(rx_bytes, rx_bytes, LU);
@@ -70,27 +61,23 @@ STA_FILE(rx_fragments, rx_fragments, LU);
STA_FILE(rx_dropped, rx_dropped, LU);
STA_FILE(tx_fragments, tx_fragments, LU);
STA_FILE(tx_filtered, tx_filtered_count, LU);
-STA_FILE(txrate, txrate, RATE);
-STA_FILE(last_txrate, last_txrate, RATE);
STA_FILE(tx_retry_failed, tx_retry_failed, LU);
STA_FILE(tx_retry_count, tx_retry_count, LU);
STA_FILE(last_rssi, last_rssi, D);
STA_FILE(last_signal, last_signal, D);
STA_FILE(last_noise, last_noise, D);
STA_FILE(channel_use, channel_use, D);
-STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
+STA_FILE(wep_weak_iv_count, wep_weak_iv_count, LU);
static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
char buf[100];
struct sta_info *sta = file->private_data;
- int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
+ int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
sta->flags & WLAN_STA_PS ? "PS\n" : "",
- sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
- sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
sta->flags & WLAN_STA_WME ? "WME\n" : "",
@@ -111,31 +98,6 @@ static ssize_t sta_num_ps_buf_frames_read(struct file *file,
}
STA_OPS(num_ps_buf_frames);
-static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- char buf[100];
- struct sta_info *sta = file->private_data;
- int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
- sta->last_ack_rssi[0],
- sta->last_ack_rssi[1],
- sta->last_ack_rssi[2]);
- return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-STA_OPS(last_ack_rssi);
-
-static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- char buf[20];
- struct sta_info *sta = file->private_data;
- int res = scnprintf(buf, sizeof(buf), "%d\n",
- sta->last_ack ?
- jiffies_to_msecs(jiffies - sta->last_ack) : -1);
- return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-STA_OPS(last_ack_ms);
-
static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
size_t count, loff_t *ppos)
{
@@ -191,8 +153,120 @@ static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
STA_OPS(wme_tx_queue);
#endif
+static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
+ size_t count, loff_t *ppos)
+{
+ char buf[768], *p = buf;
+ int i;
+ struct sta_info *sta = file->private_data;
+ p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
+ p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
+ "TIDs info is: \n TID :",
+ (sta->ampdu_mlme.dialog_token_allocator + 1));
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
+ sta->ampdu_mlme.tid_state_rx[i]);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
+ sta->ampdu_mlme.tid_state_rx[i]?
+ sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
+ sta->ampdu_mlme.tid_state_tx[i]);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
+ sta->ampdu_mlme.tid_state_tx[i]?
+ sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
+ for (i = 0; i < STA_TID_NUM; i++)
+ p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
+ sta->ampdu_mlme.tid_state_tx[i]?
+ sta->ampdu_mlme.tid_tx[i]->ssn : 0);
+
+ p += scnprintf(p, sizeof(buf)+buf-p, "\n");
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
+}
+
+static ssize_t sta_agg_status_write(struct file *file,
+ const char __user *user_buf, size_t count, loff_t *ppos)
+{
+ struct sta_info *sta = file->private_data;
+ struct net_device *dev = sta->sdata->dev;
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hw *hw = &local->hw;
+ u8 *da = sta->addr;
+ static int tid_static_tx[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ static int tid_static_rx[16] = {1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1};
+ char *endp;
+ char buf[32];
+ int buf_size, rs;
+ unsigned int tid_num;
+ char state[4];
+
+ memset(buf, 0x00, sizeof(buf));
+ buf_size = min(count, (sizeof(buf)-1));
+ if (copy_from_user(buf, user_buf, buf_size))
+ return -EFAULT;
+
+ tid_num = simple_strtoul(buf, &endp, 0);
+ if (endp == buf)
+ return -EINVAL;
+
+ if ((tid_num >= 100) && (tid_num <= 115)) {
+ /* toggle Rx aggregation command */
+ tid_num = tid_num - 100;
+ if (tid_static_rx[tid_num] == 1) {
+ strcpy(state, "off ");
+ ieee80211_sta_stop_rx_ba_session(dev, da, tid_num, 0,
+ WLAN_REASON_QSTA_REQUIRE_SETUP);
+ sta->ampdu_mlme.tid_state_rx[tid_num] |=
+ HT_AGG_STATE_DEBUGFS_CTL;
+ tid_static_rx[tid_num] = 0;
+ } else {
+ strcpy(state, "on ");
+ sta->ampdu_mlme.tid_state_rx[tid_num] &=
+ ~HT_AGG_STATE_DEBUGFS_CTL;
+ tid_static_rx[tid_num] = 1;
+ }
+ printk(KERN_DEBUG "debugfs - try switching tid %u %s\n",
+ tid_num, state);
+ } else if ((tid_num >= 0) && (tid_num <= 15)) {
+ /* toggle Tx aggregation command */
+ if (tid_static_tx[tid_num] == 0) {
+ strcpy(state, "on ");
+ rs = ieee80211_start_tx_ba_session(hw, da, tid_num);
+ if (rs == 0)
+ tid_static_tx[tid_num] = 1;
+ } else {
+ strcpy(state, "off");
+ rs = ieee80211_stop_tx_ba_session(hw, da, tid_num, 1);
+ if (rs == 0)
+ tid_static_tx[tid_num] = 0;
+ }
+ printk(KERN_DEBUG "debugfs - switching tid %u %s, return=%d\n",
+ tid_num, state, rs);
+ }
+
+ return count;
+}
+STA_OPS_WR(agg_status);
+
#define DEBUGFS_ADD(name) \
- sta->debugfs.name = debugfs_create_file(#name, 0444, \
+ sta->debugfs.name = debugfs_create_file(#name, 0400, \
sta->debugfs.dir, sta, &sta_ ##name## _ops);
#define DEBUGFS_DEL(name) \
@@ -203,12 +277,13 @@ STA_OPS(wme_tx_queue);
void ieee80211_sta_debugfs_add(struct sta_info *sta)
{
struct dentry *stations_dir = sta->local->debugfs.stations;
- DECLARE_MAC_BUF(mac);
+ DECLARE_MAC_BUF(mbuf);
+ u8 *mac;
if (!stations_dir)
return;
- print_mac(mac, sta->addr);
+ mac = print_mac(mbuf, sta->addr);
sta->debugfs.dir = debugfs_create_dir(mac, stations_dir);
if (!sta->debugfs.dir)
@@ -216,28 +291,26 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
DEBUGFS_ADD(flags);
DEBUGFS_ADD(num_ps_buf_frames);
- DEBUGFS_ADD(last_ack_rssi);
- DEBUGFS_ADD(last_ack_ms);
DEBUGFS_ADD(inactive_ms);
DEBUGFS_ADD(last_seq_ctrl);
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
DEBUGFS_ADD(wme_rx_queue);
DEBUGFS_ADD(wme_tx_queue);
#endif
+ DEBUGFS_ADD(agg_status);
}
void ieee80211_sta_debugfs_remove(struct sta_info *sta)
{
DEBUGFS_DEL(flags);
DEBUGFS_DEL(num_ps_buf_frames);
- DEBUGFS_DEL(last_ack_rssi);
- DEBUGFS_DEL(last_ack_ms);
DEBUGFS_DEL(inactive_ms);
DEBUGFS_DEL(last_seq_ctrl);
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
DEBUGFS_DEL(wme_rx_queue);
DEBUGFS_DEL(wme_tx_queue);
#endif
+ DEBUGFS_DEL(agg_status);
debugfs_remove(sta->debugfs.dir);
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 @@
#ifndef __MAC80211_DEBUGFS_STA_H
#define __MAC80211_DEBUGFS_STA_H
+#include "sta_info.h"
+
#ifdef CONFIG_MAC80211_DEBUGFS
void ieee80211_sta_debugfs_add(struct sta_info *sta);
void ieee80211_sta_debugfs_remove(struct sta_info *sta);
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 72ecbf7bf962..8e53ce7ed444 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -23,7 +23,7 @@
#include <linux/spinlock.h>
#include <linux/etherdevice.h>
#include <net/wireless.h>
-#include "ieee80211_key.h"
+#include "key.h"
#include "sta_info.h"
/* ieee80211.o internal definitions, etc. These are not included into
@@ -35,9 +35,9 @@
#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
-struct ieee80211_local;
+#define IEEE80211_FC(type, subtype) cpu_to_le16(type | subtype)
-#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
+struct ieee80211_local;
/* Maximum number of broadcast/multicast frames to buffer when some of the
* associated stations are using power saving. */
@@ -73,14 +73,14 @@ struct ieee80211_fragment_entry {
struct ieee80211_sta_bss {
struct list_head list;
struct ieee80211_sta_bss *hnext;
+ size_t ssid_len;
+
atomic_t users;
u8 bssid[ETH_ALEN];
u8 ssid[IEEE80211_MAX_SSID_LEN];
- size_t ssid_len;
u16 capability; /* host byte order */
- int hw_mode;
- int channel;
+ enum ieee80211_band band;
int freq;
int rssi, signal, noise;
u8 *wpa_ie;
@@ -91,13 +91,18 @@ struct ieee80211_sta_bss {
size_t wmm_ie_len;
u8 *ht_ie;
size_t ht_ie_len;
+#ifdef CONFIG_MAC80211_MESH
+ u8 *mesh_id;
+ size_t mesh_id_len;
+ u8 *mesh_cfg;
+#endif
#define IEEE80211_MAX_SUPP_RATES 32
u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
size_t supp_rates_len;
- int beacon_int;
u64 timestamp;
+ int beacon_int;
- int probe_resp;
+ bool probe_resp;
unsigned long last_update;
/* during assocation, we save an ERP value from a probe response so
@@ -108,56 +113,98 @@ struct ieee80211_sta_bss {
u8 erp_value;
};
+static inline u8 *bss_mesh_cfg(struct ieee80211_sta_bss *bss)
+{
+#ifdef CONFIG_MAC80211_MESH
+ return bss->mesh_cfg;
+#endif
+ return NULL;
+}
-typedef enum {
- TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
-} ieee80211_txrx_result;
+static inline u8 *bss_mesh_id(struct ieee80211_sta_bss *bss)
+{
+#ifdef CONFIG_MAC80211_MESH
+ return bss->mesh_id;
+#endif
+ return NULL;
+}
-/* flags used in struct ieee80211_txrx_data.flags */
-/* whether the MSDU was fragmented */
-#define IEEE80211_TXRXD_FRAGMENTED BIT(0)
-#define IEEE80211_TXRXD_TXUNICAST BIT(1)
-#define IEEE80211_TXRXD_TXPS_BUFFERED BIT(2)
-#define IEEE80211_TXRXD_TXPROBE_LAST_FRAG BIT(3)
-#define IEEE80211_TXRXD_RXIN_SCAN BIT(4)
-/* frame is destined to interface currently processed (incl. multicast frames) */
-#define IEEE80211_TXRXD_RXRA_MATCH BIT(5)
-#define IEEE80211_TXRXD_TX_INJECTED BIT(6)
-#define IEEE80211_TXRXD_RX_AMSDU BIT(7)
-struct ieee80211_txrx_data {
+static inline u8 bss_mesh_id_len(struct ieee80211_sta_bss *bss)
+{
+#ifdef CONFIG_MAC80211_MESH
+ return bss->mesh_id_len;
+#endif
+ return 0;
+}
+
+
+typedef unsigned __bitwise__ ieee80211_tx_result;
+#define TX_CONTINUE ((__force ieee80211_tx_result) 0u)
+#define TX_DROP ((__force ieee80211_tx_result) 1u)
+#define TX_QUEUED ((__force ieee80211_tx_result) 2u)
+
+#define IEEE80211_TX_FRAGMENTED BIT(0)
+#define IEEE80211_TX_UNICAST BIT(1)
+#define IEEE80211_TX_PS_BUFFERED BIT(2)
+#define IEEE80211_TX_PROBE_LAST_FRAG BIT(3)
+#define IEEE80211_TX_INJECTED BIT(4)
+
+struct ieee80211_tx_data {
struct sk_buff *skb;
struct net_device *dev;
struct ieee80211_local *local;
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;
+ struct ieee80211_key *key;
+
+ struct ieee80211_tx_control *control;
+ struct ieee80211_channel *channel;
+ struct ieee80211_rate *rate;
+ /* use this rate (if set) for last fragment; rate can
+ * be set to lower rate for the first fragments, e.g.,
+ * when using CTS protection with IEEE 802.11g. */
+ struct ieee80211_rate *last_frag_rate;
+
+ /* Extra fragments (in addition to the first fragment
+ * in skb) */
+ struct sk_buff **extra_frag;
+ int num_extra_frag;
+
u16 fc, ethertype;
+ unsigned int flags;
+};
+
+
+typedef unsigned __bitwise__ ieee80211_rx_result;
+#define RX_CONTINUE ((__force ieee80211_rx_result) 0u)
+#define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u)
+#define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u)
+#define RX_QUEUED ((__force ieee80211_rx_result) 3u)
+
+#define IEEE80211_RX_IN_SCAN BIT(0)
+/* frame is destined to interface currently processed (incl. multicast frames) */
+#define IEEE80211_RX_RA_MATCH BIT(1)
+#define IEEE80211_RX_AMSDU BIT(2)
+#define IEEE80211_RX_CMNTR_REPORTED BIT(3)
+#define IEEE80211_RX_FRAGMENTED BIT(4)
+
+struct ieee80211_rx_data {
+ struct sk_buff *skb;
+ struct net_device *dev;
+ struct ieee80211_local *local;
+ struct ieee80211_sub_if_data *sdata;
+ struct sta_info *sta;
struct ieee80211_key *key;
+ struct ieee80211_rx_status *status;
+ struct ieee80211_rate *rate;
+
+ u16 fc, ethertype;
unsigned int flags;
- union {
- struct {
- struct ieee80211_tx_control *control;
- struct ieee80211_hw_mode *mode;
- struct ieee80211_rate *rate;
- /* use this rate (if set) for last fragment; rate can
- * be set to lower rate for the first fragments, e.g.,
- * when using CTS protection with IEEE 802.11g. */
- struct ieee80211_rate *last_frag_rate;
- int last_frag_hwrate;
-
- /* Extra fragments (in addition to the first fragment
- * in skb) */
- int num_extra_frag;
- struct sk_buff **extra_frag;
- } tx;
- struct {
- struct ieee80211_rx_status *status;
- int sent_ps_buffered;
- int queue;
- int load;
- u32 tkip_iv32;
- u16 tkip_iv16;
- } rx;
- } u;
+ int sent_ps_buffered;
+ int queue;
+ int load;
+ u32 tkip_iv32;
+ u16 tkip_iv16;
};
/* flags used in struct ieee80211_tx_packet_data.flags */
@@ -165,6 +212,7 @@ struct ieee80211_txrx_data {
#define IEEE80211_TXPD_DO_NOT_ENCRYPT BIT(1)
#define IEEE80211_TXPD_REQUEUE BIT(2)
#define IEEE80211_TXPD_EAPOL_FRAME BIT(3)
+#define IEEE80211_TXPD_AMPDU BIT(4)
/* Stored in sk_buff->cb */
struct ieee80211_tx_packet_data {
int ifindex;
@@ -176,20 +224,12 @@ struct ieee80211_tx_packet_data {
struct ieee80211_tx_stored_packet {
struct ieee80211_tx_control control;
struct sk_buff *skb;
- int num_extra_frag;
struct sk_buff **extra_frag;
- int last_frag_rateidx;
- int last_frag_hwrate;
struct ieee80211_rate *last_frag_rate;
+ int num_extra_frag;
unsigned int last_frag_rate_ctrl_probe;
};
-typedef ieee80211_txrx_result (*ieee80211_tx_handler)
-(struct ieee80211_txrx_data *tx);
-
-typedef ieee80211_txrx_result (*ieee80211_rx_handler)
-(struct ieee80211_txrx_data *rx);
-
struct beacon_data {
u8 *head, *tail;
int head_len, tail_len;
@@ -206,10 +246,10 @@ struct ieee80211_if_ap {
/* yes, this looks ugly, but guarantees that we can later use
* bitmap_empty :)
- * NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */
+ * NB: don't touch this bitmap, use sta_info_{set,clear}_tim_bit */
u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
- atomic_t num_sta_ps; /* number of stations in PS mode */
struct sk_buff_head ps_bc_buf;
+ atomic_t num_sta_ps; /* number of stations in PS mode */
int dtim_count;
int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
int max_ratectrl_rateidx; /* max TX rateidx for rate control */
@@ -217,8 +257,8 @@ struct ieee80211_if_ap {
};
struct ieee80211_if_wds {
- u8 remote_addr[ETH_ALEN];
struct sta_info *sta;
+ u8 remote_addr[ETH_ALEN];
};
struct ieee80211_if_vlan {
@@ -226,6 +266,41 @@ struct ieee80211_if_vlan {
struct list_head list;
};
+struct mesh_stats {
+ __u32 fwded_frames; /* Mesh forwarded frames */
+ __u32 dropped_frames_ttl; /* Not transmitted since mesh_ttl == 0*/
+ __u32 dropped_frames_no_route; /* Not transmitted, no route found */
+ atomic_t estab_plinks;
+};
+
+#define PREQ_Q_F_START 0x1
+#define PREQ_Q_F_REFRESH 0x2
+struct mesh_preq_queue {
+ struct list_head list;
+ u8 dst[ETH_ALEN];
+ u8 flags;
+};
+
+struct mesh_config {
+ /* Timeouts in ms */
+ /* Mesh plink management parameters */
+ u16 dot11MeshRetryTimeout;
+ u16 dot11MeshConfirmTimeout;
+ u16 dot11MeshHoldingTimeout;
+ u16 dot11MeshMaxPeerLinks;
+ u8 dot11MeshMaxRetries;
+ u8 dot11MeshTTL;
+ bool auto_open_plinks;
+ /* HWMP parameters */
+ u8 dot11MeshHWMPmaxPREQretries;
+ u32 path_refresh_time;
+ u16 min_discovery_timeout;
+ u32 dot11MeshHWMPactivePathTimeout;
+ u16 dot11MeshHWMPpreqMinInterval;
+ u16 dot11MeshHWMPnetDiameterTraversalTime;
+};
+
+
/* flags used in struct ieee80211_if_sta.flags */
#define IEEE80211_STA_SSID_SET BIT(0)
#define IEEE80211_STA_BSSID_SET BIT(1)
@@ -241,18 +316,47 @@ struct ieee80211_if_vlan {
#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12)
#define IEEE80211_STA_PRIVACY_INVOKED BIT(13)
struct ieee80211_if_sta {
- enum {
- IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
- IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
- IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
- } state;
struct timer_list timer;
struct work_struct work;
u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
u8 ssid[IEEE80211_MAX_SSID_LEN];
+ enum {
+ IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
+ IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
+ IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED,
+ IEEE80211_MESH_UP
+ } state;
size_t ssid_len;
u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
size_t scan_ssid_len;
+#ifdef CONFIG_MAC80211_MESH
+ struct timer_list mesh_path_timer;
+ u8 mesh_id[IEEE80211_MAX_MESH_ID_LEN];
+ size_t mesh_id_len;
+ /* Active Path Selection Protocol Identifier */
+ u8 mesh_pp_id[4];
+ /* Active Path Selection Metric Identifier */
+ u8 mesh_pm_id[4];
+ /* Congestion Control Mode Identifier */
+ u8 mesh_cc_id[4];
+ /* Local mesh Destination Sequence Number */
+ u32 dsn;
+ /* Last used PREQ ID */
+ u32 preq_id;
+ atomic_t mpaths;
+ /* Timestamp of last DSN update */
+ unsigned long last_dsn_update;
+ /* Timestamp of last DSN sent */
+ unsigned long last_preq;
+ struct mesh_rmc *rmc;
+ spinlock_t mesh_preq_queue_lock;
+ struct mesh_preq_queue preq_queue;
+ int preq_queue_len;
+ struct mesh_stats mshstats;
+ struct mesh_config mshcfg;
+ u8 mesh_seqnum[3];
+ bool accepting_plinks;
+#endif
u16 aid;
u16 ap_capab, capab;
u8 *extra_ie; /* to be added to the end of AssocReq */
@@ -262,16 +366,18 @@ struct ieee80211_if_sta {
u8 *assocreq_ies, *assocresp_ies;
size_t assocreq_ies_len, assocresp_ies_len;
+ struct sk_buff_head skb_queue;
+
int auth_tries, assoc_tries;
+ unsigned long request;
+
+ unsigned long last_probe;
+
unsigned int flags;
#define IEEE80211_STA_REQ_SCAN 0
#define IEEE80211_STA_REQ_AUTH 1
#define IEEE80211_STA_REQ_RUN 2
- unsigned long request;
- struct sk_buff_head skb_queue;
-
- unsigned long last_probe;
#define IEEE80211_AUTH_ALG_OPEN BIT(0)
#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
@@ -282,16 +388,34 @@ struct ieee80211_if_sta {
unsigned long ibss_join_req;
struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
- u32 supp_rates_bits;
+ u32 supp_rates_bits[IEEE80211_NUM_BANDS];
int wmm_last_param_set;
+ int num_beacons; /* number of TXed beacon frames by this STA */
};
+static inline void ieee80211_if_sta_set_mesh_id(struct ieee80211_if_sta *ifsta,
+ u8 mesh_id_len, u8 *mesh_id)
+{
+#ifdef CONFIG_MAC80211_MESH
+ ifsta->mesh_id_len = mesh_id_len;
+ memcpy(ifsta->mesh_id, mesh_id, mesh_id_len);
+#endif
+}
+
+#ifdef CONFIG_MAC80211_MESH
+#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
+ do { (sta)->mshstats.name++; } while (0)
+#else
+#define IEEE80211_IFSTA_MESH_CTR_INC(sta, name) \
+ do { } while (0)
+#endif
/* flags used in struct ieee80211_sub_if_data.flags */
#define IEEE80211_SDATA_ALLMULTI BIT(0)
#define IEEE80211_SDATA_PROMISC BIT(1)
#define IEEE80211_SDATA_USERSPACE_MLME BIT(2)
+#define IEEE80211_SDATA_OPERATING_GMODE BIT(3)
struct ieee80211_sub_if_data {
struct list_head list;
@@ -306,11 +430,11 @@ struct ieee80211_sub_if_data {
unsigned int flags;
int drop_unencrypted;
+
/*
- * IEEE 802.1X Port access control in effect,
- * drop packets to/from unauthorized port
+ * basic rates of this AP or the AP we're associated to
*/
- int ieee802_1x_pac;
+ u64 basic_rates;
u16 sequence;
@@ -338,6 +462,7 @@ struct ieee80211_sub_if_data {
struct ieee80211_if_wds wds;
struct ieee80211_if_vlan vlan;
struct ieee80211_if_sta sta;
+ u32 mntr_flags;
} u;
int channel_use;
int channel_use_raw;
@@ -348,7 +473,6 @@ struct ieee80211_sub_if_data {
struct {
struct dentry *channel_use;
struct dentry *drop_unencrypted;
- struct dentry *ieee802_1x_pac;
struct dentry *state;
struct dentry *bssid;
struct dentry *prev_bssid;
@@ -363,11 +487,11 @@ struct ieee80211_sub_if_data {
struct dentry *auth_alg;
struct dentry *auth_transaction;
struct dentry *flags;
+ struct dentry *num_beacons_sta;
} sta;
struct {
struct dentry *channel_use;
struct dentry *drop_unencrypted;
- struct dentry *ieee802_1x_pac;
struct dentry *num_sta_ps;
struct dentry *dtim_count;
struct dentry *num_beacons;
@@ -378,19 +502,46 @@ struct ieee80211_sub_if_data {
struct {
struct dentry *channel_use;
struct dentry *drop_unencrypted;
- struct dentry *ieee802_1x_pac;
struct dentry *peer;
} wds;
struct {
struct dentry *channel_use;
struct dentry *drop_unencrypted;
- struct dentry *ieee802_1x_pac;
} vlan;
struct {
struct dentry *mode;
} monitor;
struct dentry *default_key;
} debugfs;
+
+#ifdef CONFIG_MAC80211_MESH
+ struct dentry *mesh_stats_dir;
+ struct {
+ struct dentry *fwded_frames;
+ struct dentry *dropped_frames_ttl;
+ struct dentry *dropped_frames_no_route;
+ struct dentry *estab_plinks;
+ struct timer_list mesh_path_timer;
+ } mesh_stats;
+
+ struct dentry *mesh_config_dir;
+ struct {
+ struct dentry *dot11MeshRetryTimeout;
+ struct dentry *dot11MeshConfirmTimeout;
+ struct dentry *dot11MeshHoldingTimeout;
+ struct dentry *dot11MeshMaxRetries;
+ struct dentry *dot11MeshTTL;
+ struct dentry *auto_open_plinks;
+ struct dentry *dot11MeshMaxPeerLinks;
+ struct dentry *dot11MeshHWMPactivePathTimeout;
+ struct dentry *dot11MeshHWMPpreqMinInterval;
+ struct dentry *dot11MeshHWMPnetDiameterTraversalTime;
+ struct dentry *dot11MeshHWMPmaxPREQretries;
+ struct dentry *path_refresh_time;
+ struct dentry *min_discovery_timeout;
+ } mesh_config;
+#endif
+
#endif
/* must be last, dynamically sized area in this! */
struct ieee80211_vif vif;
@@ -407,6 +558,8 @@ struct ieee80211_sub_if_data *vif_to_sdata(struct ieee80211_vif *p)
enum {
IEEE80211_RX_MSG = 1,
IEEE80211_TX_STATUS_MSG = 2,
+ IEEE80211_DELBA_MSG = 3,
+ IEEE80211_ADDBA_MSG = 4,
};
struct ieee80211_local {
@@ -417,15 +570,15 @@ struct ieee80211_local {
const struct ieee80211_ops *ops;
- /* List of registered struct ieee80211_hw_mode */
- struct list_head modes_list;
-
struct net_device *mdev; /* wmaster# - "master" 802.11 device */
int open_count;
- int monitors;
+ int monitors, cooked_mntrs;
+ /* number of interfaces with corresponding FIF_ flags */
+ int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss;
unsigned int filter_flags; /* FIF_* */
struct iw_statistics wstats;
u8 wstats_flags;
+ bool tim_in_locked_section; /* see ieee80211_beacon_get() */
int tx_headroom; /* required headroom for hardware/radiotap */
enum {
@@ -443,15 +596,22 @@ struct ieee80211_local {
struct sk_buff_head skb_queue;
struct sk_buff_head skb_queue_unreliable;
- /* Station data structures */
- rwlock_t sta_lock; /* protects STA data structures */
- int num_sta; /* number of stations in sta_list */
+ /* Station data */
+ /*
+ * The lock only protects the list, hash, timer and counter
+ * against manipulation, reads are done in RCU. Additionally,
+ * the lock protects each BSS's TIM bitmap.
+ */
+ spinlock_t sta_lock;
+ unsigned long num_sta;
struct list_head sta_list;
+ struct list_head sta_flush_list;
+ struct work_struct sta_flush_work;
struct sta_info *sta_hash[STA_HASH_SIZE];
struct timer_list sta_cleanup;
- unsigned long state[NUM_TX_DATA_QUEUES];
- struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES];
+ unsigned long state[NUM_TX_DATA_QUEUES_AMPDU];
+ struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES_AMPDU];
struct tasklet_struct tx_pending_tasklet;
/* number of interfaces with corresponding IFF_ flags */
@@ -459,11 +619,6 @@ struct ieee80211_local {
struct rate_control_ref *rate_ctrl;
- /* Supported and basic rate filters for different modes. These are
- * pointers to -1 terminated lists and rates in 100 kbps units. */
- int *supp_rates[NUM_IEEE80211_MODES];
- int *basic_rates[NUM_IEEE80211_MODES];
-
int rts_threshold;
int fragmentation_threshold;
int short_retry_limit; /* dot11ShortRetryLimit */
@@ -477,21 +632,25 @@ struct ieee80211_local {
* deliver multicast frames both back to wireless
* media and to the local net stack */
- ieee80211_rx_handler *rx_pre_handlers;
- ieee80211_rx_handler *rx_handlers;
- ieee80211_tx_handler *tx_handlers;
-
struct list_head interfaces;
+ /*
+ * Key lock, protects sdata's key_list and sta_info's
+ * key pointers (write access, they're RCU.)
+ */
+ spinlock_t key_lock;
+
+
bool sta_sw_scanning;
bool sta_hw_scanning;
int scan_channel_idx;
+ enum ieee80211_band scan_band;
+
enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
unsigned long last_scan_completed;
struct delayed_work scan_work;
struct net_device *scan_dev;
struct ieee80211_channel *oper_channel, *scan_channel;
- struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
size_t scan_ssid_len;
struct list_head sta_bss_list;
@@ -560,14 +719,8 @@ struct ieee80211_local {
int wifi_wme_noack_test;
unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
- unsigned int enabled_modes; /* bitfield of allowed modes;
- * (1 << MODE_*) */
- unsigned int hw_modes; /* bitfield of supported hardware modes;
- * (1 << MODE_*) */
-
#ifdef CONFIG_MAC80211_DEBUGFS
struct local_debugfsdentries {
- struct dentry *channel;
struct dentry *frequency;
struct dentry *antenna_sel_tx;
struct dentry *antenna_sel_rx;
@@ -577,9 +730,7 @@ struct ieee80211_local {
struct dentry *short_retry_limit;
struct dentry *long_retry_limit;
struct dentry *total_ps_buffered;
- struct dentry *mode;
struct dentry *wep_iv;
- struct dentry *modes;
struct dentry *statistics;
struct local_debugfsdentries_statsdentries {
struct dentry *transmitted_fragment_count;
@@ -627,6 +778,63 @@ struct ieee80211_local {
#endif
};
+/* this struct represents 802.11n's RA/TID combination */
+struct ieee80211_ra_tid {
+ u8 ra[ETH_ALEN];
+ u16 tid;
+};
+
+/* Parsed Information Elements */
+struct ieee802_11_elems {
+ /* pointers to IEs */
+ u8 *ssid;
+ u8 *supp_rates;
+ u8 *fh_params;
+ u8 *ds_params;
+ u8 *cf_params;
+ u8 *tim;
+ u8 *ibss_params;
+ u8 *challenge;
+ u8 *wpa;
+ u8 *rsn;
+ u8 *erp_info;
+ u8 *ext_supp_rates;
+ u8 *wmm_info;
+ u8 *wmm_param;
+ u8 *ht_cap_elem;
+ u8 *ht_info_elem;
+ u8 *mesh_config;
+ u8 *mesh_id;
+ u8 *peer_link;
+ u8 *preq;
+ u8 *prep;
+ u8 *perr;
+
+ /* length of them, respectively */
+ u8 ssid_len;
+ u8 supp_rates_len;
+ u8 fh_params_len;
+ u8 ds_params_len;
+ u8 cf_params_len;
+ u8 tim_len;
+ u8 ibss_params_len;
+ u8 challenge_len;
+ u8 wpa_len;
+ u8 rsn_len;
+ u8 erp_info_len;
+ u8 ext_supp_rates_len;
+ u8 wmm_info_len;
+ u8 wmm_param_len;
+ u8 ht_cap_elem_len;
+ u8 ht_info_elem_len;
+ u8 mesh_config_len;
+ u8 mesh_id_len;
+ u8 peer_link_len;
+ u8 preq_len;
+ u8 prep_len;
+ u8 perr_len;
+};
+
static inline struct ieee80211_local *hw_to_local(
struct ieee80211_hw *hw)
{
@@ -650,57 +858,6 @@ struct sta_attribute {
ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
};
-static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
-{
- /*
- * This format has been mandated by the IEEE specifications,
- * so this line may not be changed to use the __set_bit() format.
- */
- bss->tim[aid / 8] |= (1 << (aid % 8));
-}
-
-static inline void bss_tim_set(struct ieee80211_local *local,
- struct ieee80211_if_ap *bss, u16 aid)
-{
- read_lock_bh(&local->sta_lock);
- __bss_tim_set(bss, aid);
- read_unlock_bh(&local->sta_lock);
-}
-
-static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
-{
- /*
- * This format has been mandated by the IEEE specifications,
- * so this line may not be changed to use the __clear_bit() format.
- */
- bss->tim[aid / 8] &= ~(1 << (aid % 8));
-}
-
-static inline void bss_tim_clear(struct ieee80211_local *local,
- struct ieee80211_if_ap *bss, u16 aid)
-{
- read_lock_bh(&local->sta_lock);
- __bss_tim_clear(bss, aid);
- read_unlock_bh(&local->sta_lock);
-}
-
-/**
- * ieee80211_is_erp_rate - Check if a rate is an ERP rate
- * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
- * @rate: Transmission rate to check, in 100 kbps
- *
- * Check if a given rate is an Extended Rate PHY (ERP) rate.
- */
-static inline int ieee80211_is_erp_rate(int phymode, int rate)
-{
- if (phymode == MODE_IEEE80211G) {
- if (rate != 10 && rate != 20 &&
- rate != 55 && rate != 110)
- return 1;
- }
- return 0;
-}
-
static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
{
return compare_ether_addr(raddr, addr) == 0 ||
@@ -712,16 +869,11 @@ static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
int ieee80211_hw_config(struct ieee80211_local *local);
int ieee80211_if_config(struct net_device *dev);
int ieee80211_if_config_beacon(struct net_device *dev);
-void ieee80211_prepare_rates(struct ieee80211_local *local,
- struct ieee80211_hw_mode *mode);
-void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
-int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
+void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx);
void ieee80211_if_setup(struct net_device *dev);
-struct ieee80211_rate *ieee80211_get_rate(struct ieee80211_local *local,
- int phymode, int hwrate);
-int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
- struct ieee80211_ht_info *req_ht_cap,
- struct ieee80211_ht_bss_info *req_bss_cap);
+u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
+ struct ieee80211_ht_info *req_ht_cap,
+ struct ieee80211_ht_bss_info *req_bss_cap);
/* ieee80211_ioctl.c */
extern const struct iw_handler_def ieee80211_iw_handler_def;
@@ -747,9 +899,7 @@ extern const struct iw_handler_def ieee80211_iw_handler_def;
/* ieee80211_ioctl.c */
-int ieee80211_set_compression(struct ieee80211_local *local,
- struct net_device *dev, struct sta_info *sta);
-int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq);
+int ieee80211_set_freq(struct ieee80211_local *local, int freq);
/* ieee80211_sta.c */
void ieee80211_sta_timer(unsigned long data);
void ieee80211_sta_work(struct work_struct *work);
@@ -763,9 +913,9 @@ int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
void ieee80211_sta_req_auth(struct net_device *dev,
struct ieee80211_if_sta *ifsta);
int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
-ieee80211_txrx_result ieee80211_sta_rx_scan(struct net_device *dev,
- struct sk_buff *skb,
- struct ieee80211_rx_status *rx_status);
+ieee80211_rx_result ieee80211_sta_rx_scan(
+ struct net_device *dev, struct sk_buff *skb,
+ struct ieee80211_rx_status *rx_status);
void ieee80211_rx_bss_list_init(struct net_device *dev);
void ieee80211_rx_bss_list_deinit(struct net_device *dev);
int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
@@ -782,12 +932,36 @@ int ieee80211_ht_cap_ie_to_ht_info(struct ieee80211_ht_cap *ht_cap_ie,
int ieee80211_ht_addt_info_ie_to_ht_bss_info(
struct ieee80211_ht_addt_info *ht_add_info_ie,
struct ieee80211_ht_bss_info *bss_info);
+void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
+ u16 tid, u8 dialog_token, u16 start_seq_num,
+ u16 agg_size, u16 timeout);
+void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
+ u16 initiator, u16 reason_code);
+
void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *da,
u16 tid, u16 initiator, u16 reason);
void sta_rx_agg_session_timer_expired(unsigned long data);
+void sta_addba_resp_timer_expired(unsigned long data);
+void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr);
+u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
+ struct ieee802_11_elems *elems,
+ enum ieee80211_band band);
+void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
+ int encrypt);
+void ieee802_11_parse_elems(u8 *start, size_t len,
+ struct ieee802_11_elems *elems);
+
+#ifdef CONFIG_MAC80211_MESH
+void ieee80211_start_mesh(struct net_device *dev);
+#else
+static inline void ieee80211_start_mesh(struct net_device *dev)
+{}
+#endif
+
/* ieee80211_iface.c */
int ieee80211_if_add(struct net_device *dev, const char *name,
- struct net_device **new_dev, int type);
+ struct net_device **new_dev, int type,
+ struct vif_params *params);
void ieee80211_if_set_type(struct net_device *dev, int type);
void ieee80211_if_reinit(struct net_device *dev);
void __ieee80211_if_del(struct ieee80211_local *local,
@@ -796,16 +970,7 @@ int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
void ieee80211_if_free(struct net_device *dev);
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
-/* regdomain.c */
-void ieee80211_regdomain_init(void);
-void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode);
-
-/* rx handling */
-extern ieee80211_rx_handler ieee80211_rx_pre_handlers[];
-extern ieee80211_rx_handler ieee80211_rx_handlers[];
-
/* tx handling */
-extern ieee80211_tx_handler ieee80211_tx_handlers[];
void ieee80211_clear_tx_pending(struct ieee80211_local *local);
void ieee80211_tx_pending(unsigned long data);
int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
diff --git a/net/mac80211/ieee80211_iface.c b/net/mac80211/iface.c
index 92f1eb2da311..80954a512185 100644
--- a/net/mac80211/ieee80211_iface.c
+++ b/net/mac80211/iface.c
@@ -15,6 +15,7 @@
#include "ieee80211_i.h"
#include "sta_info.h"
#include "debugfs_netdev.h"
+#include "mesh.h"
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
{
@@ -39,7 +40,8 @@ static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata)
/* Must be called with rtnl lock held. */
int ieee80211_if_add(struct net_device *dev, const char *name,
- struct net_device **new_dev, int type)
+ struct net_device **new_dev, int type,
+ struct vif_params *params)
{
struct net_device *ndev;
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -78,6 +80,12 @@ int ieee80211_if_add(struct net_device *dev, const char *name,
ieee80211_debugfs_add_netdev(sdata);
ieee80211_if_set_type(ndev, type);
+ if (ieee80211_vif_is_mesh(&sdata->vif) &&
+ params && params->mesh_id_len)
+ ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
+ params->mesh_id_len,
+ params->mesh_id);
+
/* we're under RTNL so all this is fine */
if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
__ieee80211_if_del(local, sdata);
@@ -118,6 +126,8 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
sdata->bss = NULL;
sdata->vif.type = type;
+ sdata->basic_rates = 0;
+
switch (type) {
case IEEE80211_IF_TYPE_WDS:
/* nothing special */
@@ -132,6 +142,7 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
sdata->bss = &sdata->u.ap;
INIT_LIST_HEAD(&sdata->u.ap.vlans);
break;
+ case IEEE80211_IF_TYPE_MESH_POINT:
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS: {
struct ieee80211_sub_if_data *msdata;
@@ -153,15 +164,20 @@ void ieee80211_if_set_type(struct net_device *dev, int type)
msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
sdata->bss = &msdata->u.ap;
+
+ if (ieee80211_vif_is_mesh(&sdata->vif))
+ ieee80211_mesh_init_sdata(sdata);
break;
}
case IEEE80211_IF_TYPE_MNTR:
dev->type = ARPHRD_IEEE80211_RADIOTAP;
dev->hard_start_xmit = ieee80211_monitor_start_xmit;
+ sdata->u.mntr_flags = MONITOR_FLAG_CONTROL |
+ MONITOR_FLAG_OTHER_BSS;
break;
default:
printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
- dev->name, __FUNCTION__, type);
+ dev->name, __func__, type);
}
ieee80211_debugfs_change_if_type(sdata, oldtype);
}
@@ -171,8 +187,8 @@ void ieee80211_if_reinit(struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- struct sta_info *sta;
struct sk_buff *skb;
+ int flushed;
ASSERT_RTNL();
@@ -180,6 +196,10 @@ void ieee80211_if_reinit(struct net_device *dev)
ieee80211_if_sdata_deinit(sdata);
+ /* Need to handle mesh specially to allow eliding the function call */
+ if (ieee80211_vif_is_mesh(&sdata->vif))
+ mesh_rmc_free(dev);
+
switch (sdata->vif.type) {
case IEEE80211_IF_TYPE_INVALID:
/* cannot happen */
@@ -189,6 +209,7 @@ void ieee80211_if_reinit(struct net_device *dev)
/* Remove all virtual interfaces that use this BSS
* as their sdata->bss */
struct ieee80211_sub_if_data *tsdata, *n;
+ struct beacon_data *beacon;
list_for_each_entry_safe(tsdata, n, &local->interfaces, list) {
if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
@@ -206,7 +227,10 @@ void ieee80211_if_reinit(struct net_device *dev)
}
}
- kfree(sdata->u.ap.beacon);
+ beacon = sdata->u.ap.beacon;
+ rcu_assign_pointer(sdata->u.ap.beacon, NULL);
+ synchronize_rcu();
+ kfree(beacon);
while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
local->total_ps_buffered--;
@@ -216,17 +240,9 @@ void ieee80211_if_reinit(struct net_device *dev)
break;
}
case IEEE80211_IF_TYPE_WDS:
- sta = sta_info_get(local, sdata->u.wds.remote_addr);
- if (sta) {
- sta_info_free(sta);
- sta_info_put(sta);
- } else {
-#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- printk(KERN_DEBUG "%s: Someone had deleted my STA "
- "entry for the WDS link\n", dev->name);
-#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
- }
+ /* nothing to do */
break;
+ case IEEE80211_IF_TYPE_MESH_POINT:
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
kfree(sdata->u.sta.extra_ie);
@@ -249,8 +265,8 @@ void ieee80211_if_reinit(struct net_device *dev)
break;
}
- /* remove all STAs that are bound to this virtual interface */
- sta_info_flush(local, dev);
+ flushed = sta_info_flush(local, sdata);
+ WARN_ON(flushed);
memset(&sdata->u, 0, sizeof(sdata->u));
ieee80211_if_sdata_init(sdata);
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index ed57fb8e82fc..150d66dbda9d 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -2,7 +2,7 @@
* Copyright 2002-2005, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc.
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
- * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
+ * Copyright 2007-2008 Johannes Berg <johannes@sipsolutions.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -13,14 +13,15 @@
#include <linux/etherdevice.h>
#include <linux/list.h>
#include <linux/rcupdate.h>
+#include <linux/rtnetlink.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
#include "debugfs_key.h"
#include "aes_ccm.h"
-/*
- * Key handling basics
+/**
+ * DOC: Key handling basics
*
* Key handling in mac80211 is done based on per-interface (sub_if_data)
* keys and per-station keys. Since each station belongs to an interface,
@@ -32,13 +33,81 @@
* There is currently no way of knowing this except by looking into
* debugfs.
*
- * All operations here are called under RTNL so no extra locking is
- * required.
+ * All key operations are protected internally so you can call them at
+ * any time.
+ *
+ * Within mac80211, key references are, just as STA structure references,
+ * protected by RCU. Note, however, that some things are unprotected,
+ * namely the key->sta dereferences within the hardware acceleration
+ * functions. This means that sta_info_destroy() must flush the key todo
+ * list.
+ *
+ * All the direct key list manipulation functions must not sleep because
+ * they can operate on STA info structs that are protected by RCU.
*/
static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
static const u8 zero_addr[ETH_ALEN];
+/* key mutex: used to synchronise todo runners */
+static DEFINE_MUTEX(key_mutex);
+static DEFINE_SPINLOCK(todo_lock);
+static LIST_HEAD(todo_list);
+
+static void key_todo(struct work_struct *work)
+{
+ ieee80211_key_todo();
+}
+
+static DECLARE_WORK(todo_work, key_todo);
+
+/**
+ * add_todo - add todo item for a key
+ *
+ * @key: key to add to do item for
+ * @flag: todo flag(s)
+ */
+static void add_todo(struct ieee80211_key *key, u32 flag)
+{
+ if (!key)
+ return;
+
+ spin_lock(&todo_lock);
+ key->flags |= flag;
+ /*
+ * Remove again if already on the list so that we move it to the end.
+ */
+ if (!list_empty(&key->todo))
+ list_del(&key->todo);
+ list_add_tail(&key->todo, &todo_list);
+ schedule_work(&todo_work);
+ spin_unlock(&todo_lock);
+}
+
+/**
+ * ieee80211_key_lock - lock the mac80211 key operation lock
+ *
+ * This locks the (global) mac80211 key operation lock, all
+ * key operations must be done under this lock.
+ */
+static void ieee80211_key_lock(void)
+{
+ mutex_lock(&key_mutex);
+}
+
+/**
+ * ieee80211_key_unlock - unlock the mac80211 key operation lock
+ */
+static void ieee80211_key_unlock(void)
+{
+ mutex_unlock(&key_mutex);
+}
+
+static void assert_key_lock(void)
+{
+ WARN_ON(!mutex_is_locked(&key_mutex));
+}
+
static const u8 *get_mac_for_key(struct ieee80211_key *key)
{
const u8 *addr = bcast_addr;
@@ -65,6 +134,9 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
int ret;
DECLARE_MAC_BUF(mac);
+ assert_key_lock();
+ might_sleep();
+
if (!key->local->ops->set_key)
return;
@@ -74,8 +146,11 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
key->sdata->dev->dev_addr, addr,
&key->conf);
- if (!ret)
+ if (!ret) {
+ spin_lock(&todo_lock);
key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
+ spin_unlock(&todo_lock);
+ }
if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
printk(KERN_ERR "mac80211-%s: failed to set key "
@@ -90,11 +165,18 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
int ret;
DECLARE_MAC_BUF(mac);
- if (!key->local->ops->set_key)
+ assert_key_lock();
+ might_sleep();
+
+ if (!key || !key->local->ops->set_key)
return;
- if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
+ spin_lock(&todo_lock);
+ if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
+ spin_unlock(&todo_lock);
return;
+ }
+ spin_unlock(&todo_lock);
addr = get_mac_for_key(key);
@@ -108,12 +190,75 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
wiphy_name(key->local->hw.wiphy),
key->conf.keyidx, print_mac(mac, addr), ret);
+ spin_lock(&todo_lock);
key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
+ spin_unlock(&todo_lock);
}
-struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
- struct sta_info *sta,
- enum ieee80211_key_alg alg,
+static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
+ int idx)
+{
+ struct ieee80211_key *key = NULL;
+
+ if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
+ key = sdata->keys[idx];
+
+ rcu_assign_pointer(sdata->default_key, key);
+
+ if (key)
+ add_todo(key, KEY_FLAG_TODO_DEFKEY);
+}
+
+void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&sdata->local->key_lock, flags);
+ __ieee80211_set_default_key(sdata, idx);
+ spin_unlock_irqrestore(&sdata->local->key_lock, flags);
+}
+
+
+static void __ieee80211_key_replace(struct ieee80211_sub_if_data *sdata,
+ struct sta_info *sta,
+ struct ieee80211_key *old,
+ struct ieee80211_key *new)
+{
+ int idx, defkey;
+
+ if (new)
+ list_add(&new->list, &sdata->key_list);
+
+ if (sta) {
+ rcu_assign_pointer(sta->key, new);
+ } else {
+ WARN_ON(new && old && new->conf.keyidx != old->conf.keyidx);
+
+ if (old)
+ idx = old->conf.keyidx;
+ else
+ idx = new->conf.keyidx;
+
+ defkey = old && sdata->default_key == old;
+
+ if (defkey && !new)
+ __ieee80211_set_default_key(sdata, -1);
+
+ rcu_assign_pointer(sdata->keys[idx], new);
+ if (defkey && new)
+ __ieee80211_set_default_key(sdata, new->conf.keyidx);
+ }
+
+ if (old) {
+ /*
+ * We'll use an empty list to indicate that the key
+ * has already been removed.
+ */
+ list_del_init(&old->list);
+ }
+}
+
+struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
int idx,
size_t key_len,
const u8 *key_data)
@@ -137,10 +282,8 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
key->conf.keyidx = idx;
key->conf.keylen = key_len;
memcpy(key->conf.key, key_data, key_len);
-
- key->local = sdata->local;
- key->sdata = sdata;
- key->sta = sta;
+ INIT_LIST_HEAD(&key->list);
+ INIT_LIST_HEAD(&key->todo);
if (alg == ALG_CCMP) {
/*
@@ -149,22 +292,31 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
*/
key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data);
if (!key->u.ccmp.tfm) {
- ieee80211_key_free(key);
+ kfree(key);
return NULL;
}
}
- ieee80211_debugfs_key_add(key->local, key);
+ return key;
+}
- /* remove key first */
- if (sta)
- ieee80211_key_free(sta->key);
- else
- ieee80211_key_free(sdata->keys[idx]);
+void ieee80211_key_link(struct ieee80211_key *key,
+ struct ieee80211_sub_if_data *sdata,
+ struct sta_info *sta)
+{
+ struct ieee80211_key *old_key;
+ unsigned long flags;
+ int idx;
- if (sta) {
- ieee80211_debugfs_key_sta_link(key, sta);
+ BUG_ON(!sdata);
+ BUG_ON(!key);
+ idx = key->conf.keyidx;
+ key->local = sdata->local;
+ key->sdata = sdata;
+ key->sta = sta;
+
+ if (sta) {
/*
* some hardware cannot handle TKIP with QoS, so
* we indicate whether QoS could be in use.
@@ -175,105 +327,194 @@ struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
struct sta_info *ap;
+ /*
+ * We're getting a sta pointer in,
+ * so must be under RCU read lock.
+ */
+
/* same here, the AP could be using QoS */
ap = sta_info_get(key->local, key->sdata->u.sta.bssid);
if (ap) {
if (ap->flags & WLAN_STA_WME)
key->conf.flags |=
IEEE80211_KEY_FLAG_WMM_STA;
- sta_info_put(ap);
}
}
}
- /* enable hwaccel if appropriate */
- if (netif_running(key->sdata->dev))
- ieee80211_key_enable_hw_accel(key);
+ spin_lock_irqsave(&sdata->local->key_lock, flags);
if (sta)
- rcu_assign_pointer(sta->key, key);
+ old_key = sta->key;
else
- rcu_assign_pointer(sdata->keys[idx], key);
+ old_key = sdata->keys[idx];
- list_add(&key->list, &sdata->key_list);
+ __ieee80211_key_replace(sdata, sta, old_key, key);
- return key;
+ spin_unlock_irqrestore(&sdata->local->key_lock, flags);
+
+ /* free old key later */
+ add_todo(old_key, KEY_FLAG_TODO_DELETE);
+
+ add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
+ if (netif_running(sdata->dev))
+ add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
+}
+
+static void __ieee80211_key_free(struct ieee80211_key *key)
+{
+ /*
+ * Replace key with nothingness if it was ever used.
+ */
+ if (key->sdata)
+ __ieee80211_key_replace(key->sdata, key->sta,
+ key, NULL);
+
+ add_todo(key, KEY_FLAG_TODO_DELETE);
}
void ieee80211_key_free(struct ieee80211_key *key)
{
+ unsigned long flags;
+
if (!key)
return;
- if (key->sta) {
- rcu_assign_pointer(key->sta->key, NULL);
- } else {
- if (key->sdata->default_key == key)
- ieee80211_set_default_key(key->sdata, -1);
- if (key->conf.keyidx >= 0 &&
- key->conf.keyidx < NUM_DEFAULT_KEYS)
- rcu_assign_pointer(key->sdata->keys[key->conf.keyidx],
- NULL);
- else
- WARN_ON(1);
- }
+ spin_lock_irqsave(&key->sdata->local->key_lock, flags);
+ __ieee80211_key_free(key);
+ spin_unlock_irqrestore(&key->sdata->local->key_lock, flags);
+}
- /* wait for all key users to complete */
- synchronize_rcu();
+/*
+ * To be safe against concurrent manipulations of the list (which shouldn't
+ * actually happen) we need to hold the spinlock. But under the spinlock we
+ * can't actually do much, so we defer processing to the todo list. Then run
+ * the todo list to be sure the operation and possibly previously pending
+ * operations are completed.
+ */
+static void ieee80211_todo_for_each_key(struct ieee80211_sub_if_data *sdata,
+ u32 todo_flags)
+{
+ struct ieee80211_key *key;
+ unsigned long flags;
+
+ might_sleep();
+
+ spin_lock_irqsave(&sdata->local->key_lock, flags);
+ list_for_each_entry(key, &sdata->key_list, list)
+ add_todo(key, todo_flags);
+ spin_unlock_irqrestore(&sdata->local->key_lock, flags);
+
+ ieee80211_key_todo();
+}
+
+void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
+{
+ ASSERT_RTNL();
+
+ if (WARN_ON(!netif_running(sdata->dev)))
+ return;
+
+ ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_ADD);
+}
+
+void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
+{
+ ASSERT_RTNL();
+
+ ieee80211_todo_for_each_key(sdata, KEY_FLAG_TODO_HWACCEL_REMOVE);
+}
+
+static void __ieee80211_key_destroy(struct ieee80211_key *key)
+{
+ if (!key)
+ return;
- /* remove from hwaccel if appropriate */
ieee80211_key_disable_hw_accel(key);
if (key->conf.alg == ALG_CCMP)
ieee80211_aes_key_free(key->u.ccmp.tfm);
ieee80211_debugfs_key_remove(key);
- list_del(&key->list);
-
kfree(key);
}
-void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx)
+static void __ieee80211_key_todo(void)
{
- struct ieee80211_key *key = NULL;
+ struct ieee80211_key *key;
+ bool work_done;
+ u32 todoflags;
- if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
- key = sdata->keys[idx];
+ /*
+ * NB: sta_info_destroy relies on this!
+ */
+ synchronize_rcu();
- if (sdata->default_key != key) {
- ieee80211_debugfs_key_remove_default(sdata);
+ spin_lock(&todo_lock);
+ while (!list_empty(&todo_list)) {
+ key = list_first_entry(&todo_list, struct ieee80211_key, todo);
+ list_del_init(&key->todo);
+ todoflags = key->flags & (KEY_FLAG_TODO_ADD_DEBUGFS |
+ KEY_FLAG_TODO_DEFKEY |
+ KEY_FLAG_TODO_HWACCEL_ADD |
+ KEY_FLAG_TODO_HWACCEL_REMOVE |
+ KEY_FLAG_TODO_DELETE);
+ key->flags &= ~todoflags;
+ spin_unlock(&todo_lock);
+
+ work_done = false;
+
+ if (todoflags & KEY_FLAG_TODO_ADD_DEBUGFS) {
+ ieee80211_debugfs_key_add(key);
+ work_done = true;
+ }
+ if (todoflags & KEY_FLAG_TODO_DEFKEY) {
+ ieee80211_debugfs_key_remove_default(key->sdata);
+ ieee80211_debugfs_key_add_default(key->sdata);
+ work_done = true;
+ }
+ if (todoflags & KEY_FLAG_TODO_HWACCEL_ADD) {
+ ieee80211_key_enable_hw_accel(key);
+ work_done = true;
+ }
+ if (todoflags & KEY_FLAG_TODO_HWACCEL_REMOVE) {
+ ieee80211_key_disable_hw_accel(key);
+ work_done = true;
+ }
+ if (todoflags & KEY_FLAG_TODO_DELETE) {
+ __ieee80211_key_destroy(key);
+ work_done = true;
+ }
- rcu_assign_pointer(sdata->default_key, key);
+ WARN_ON(!work_done);
- if (sdata->default_key)
- ieee80211_debugfs_key_add_default(sdata);
+ spin_lock(&todo_lock);
}
+ spin_unlock(&todo_lock);
}
-void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
+void ieee80211_key_todo(void)
{
- struct ieee80211_key *key, *tmp;
-
- list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
- ieee80211_key_free(key);
+ ieee80211_key_lock();
+ __ieee80211_key_todo();
+ ieee80211_key_unlock();
}
-void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
+void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
{
- struct ieee80211_key *key;
+ struct ieee80211_key *key, *tmp;
+ unsigned long flags;
- WARN_ON(!netif_running(sdata->dev));
- if (!netif_running(sdata->dev))
- return;
+ ieee80211_key_lock();
- list_for_each_entry(key, &sdata->key_list, list)
- ieee80211_key_enable_hw_accel(key);
-}
+ ieee80211_debugfs_key_remove_default(sdata);
-void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
-{
- struct ieee80211_key *key;
+ spin_lock_irqsave(&sdata->local->key_lock, flags);
+ list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
+ __ieee80211_key_free(key);
+ spin_unlock_irqrestore(&sdata->local->key_lock, flags);
- list_for_each_entry(key, &sdata->key_list, list)
- ieee80211_key_disable_hw_accel(key);
+ __ieee80211_key_todo();
+
+ ieee80211_key_unlock();
}
diff --git a/net/mac80211/ieee80211_key.h b/net/mac80211/key.h
index fc770e98d47b..f52c3df1fe9a 100644
--- a/net/mac80211/ieee80211_key.h
+++ b/net/mac80211/key.h
@@ -13,6 +13,7 @@
#include <linux/types.h>
#include <linux/list.h>
#include <linux/crypto.h>
+#include <linux/rcupdate.h>
#include <net/mac80211.h>
/* ALG_TKIP
@@ -45,15 +46,40 @@ struct ieee80211_local;
struct ieee80211_sub_if_data;
struct sta_info;
-#define KEY_FLAG_UPLOADED_TO_HARDWARE (1<<0)
+/**
+ * enum ieee80211_internal_key_flags - internal key flags
+ *
+ * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
+ * in the hardware for TX crypto hardware acceleration.
+ * @KEY_FLAG_TODO_DELETE: Key is marked for deletion and will, after an
+ * RCU grace period, no longer be reachable other than from the
+ * todo list.
+ * @KEY_FLAG_TODO_HWACCEL_ADD: Key needs to be added to hardware acceleration.
+ * @KEY_FLAG_TODO_HWACCEL_REMOVE: Key needs to be removed from hardware
+ * acceleration.
+ * @KEY_FLAG_TODO_DEFKEY: Key is default key and debugfs needs to be updated.
+ * @KEY_FLAG_TODO_ADD_DEBUGFS: Key needs to be added to debugfs.
+ */
+enum ieee80211_internal_key_flags {
+ KEY_FLAG_UPLOADED_TO_HARDWARE = BIT(0),
+ KEY_FLAG_TODO_DELETE = BIT(1),
+ KEY_FLAG_TODO_HWACCEL_ADD = BIT(2),
+ KEY_FLAG_TODO_HWACCEL_REMOVE = BIT(3),
+ KEY_FLAG_TODO_DEFKEY = BIT(4),
+ KEY_FLAG_TODO_ADD_DEBUGFS = BIT(5),
+};
struct ieee80211_key {
struct ieee80211_local *local;
struct ieee80211_sub_if_data *sdata;
struct sta_info *sta;
+ /* for sdata list */
struct list_head list;
+ /* for todo list */
+ struct list_head todo;
+ /* protected by todo lock! */
unsigned int flags;
union {
@@ -102,6 +128,7 @@ struct ieee80211_key {
struct dentry *replays;
struct dentry *key;
struct dentry *ifindex;
+ int cnt;
} debugfs;
#endif
@@ -112,16 +139,23 @@ struct ieee80211_key {
struct ieee80211_key_conf conf;
};
-struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
- struct sta_info *sta,
- enum ieee80211_key_alg alg,
+struct ieee80211_key *ieee80211_key_alloc(enum ieee80211_key_alg alg,
int idx,
size_t key_len,
const u8 *key_data);
+/*
+ * Insert a key into data structures (sdata, sta if necessary)
+ * to make it used, free old key.
+ */
+void ieee80211_key_link(struct ieee80211_key *key,
+ struct ieee80211_sub_if_data *sdata,
+ struct sta_info *sta);
void ieee80211_key_free(struct ieee80211_key *key);
void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
+void ieee80211_key_todo(void);
+
#endif /* IEEE80211_KEY_H */
diff --git a/net/mac80211/ieee80211_led.c b/net/mac80211/led.c
index f401484ab6d7..162a643f16b6 100644
--- a/net/mac80211/ieee80211_led.c
+++ b/net/mac80211/led.c
@@ -8,7 +8,7 @@
/* just for IFNAMSIZ */
#include <linux/if.h>
-#include "ieee80211_led.h"
+#include "led.h"
void ieee80211_led_rx(struct ieee80211_local *local)
{
diff --git a/net/mac80211/ieee80211_led.h b/net/mac80211/led.h
index 77b1e1ba6039..77b1e1ba6039 100644
--- a/net/mac80211/ieee80211_led.h
+++ b/net/mac80211/led.h
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/main.c
index 8e586390a2ef..e9a978979d38 100644
--- a/net/mac80211/ieee80211.c
+++ b/net/mac80211/main.c
@@ -25,11 +25,12 @@
#include <net/cfg80211.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
+#include "mesh.h"
#include "wep.h"
#include "wme.h"
#include "aes_ccm.h"
-#include "ieee80211_led.h"
+#include "led.h"
#include "cfg.h"
#include "debugfs.h"
#include "debugfs_netdev.h"
@@ -67,9 +68,19 @@ static void ieee80211_configure_filter(struct ieee80211_local *local)
new_flags |= FIF_ALLMULTI;
if (local->monitors)
- new_flags |= FIF_CONTROL |
- FIF_OTHER_BSS |
- FIF_BCN_PRBRESP_PROMISC;
+ new_flags |= FIF_BCN_PRBRESP_PROMISC;
+
+ if (local->fif_fcsfail)
+ new_flags |= FIF_FCSFAIL;
+
+ if (local->fif_plcpfail)
+ new_flags |= FIF_PLCPFAIL;
+
+ if (local->fif_control)
+ new_flags |= FIF_CONTROL;
+
+ if (local->fif_other_bss)
+ new_flags |= FIF_OTHER_BSS;
changed_flags = local->filter_flags ^ new_flags;
@@ -128,9 +139,15 @@ static void ieee80211_master_set_multicast_list(struct net_device *dev)
static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
{
+ int meshhdrlen;
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+ meshhdrlen = (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) ? 5 : 0;
+
/* FIX: what would be proper limits for MTU?
* This interface uses 802.3 frames. */
- if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
+ if (new_mtu < 256 ||
+ new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6 - meshhdrlen) {
printk(KERN_WARNING "%s: invalid MTU %d\n",
dev->name, new_mtu);
return -EINVAL;
@@ -166,6 +183,7 @@ static int ieee80211_open(struct net_device *dev)
struct ieee80211_if_init_conf conf;
int res;
bool need_hw_reconfig = 0;
+ struct sta_info *sta;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -173,8 +191,52 @@ static int ieee80211_open(struct net_device *dev)
list_for_each_entry(nsdata, &local->interfaces, list) {
struct net_device *ndev = nsdata->dev;
- if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
- compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
+ if (ndev != dev && ndev != local->mdev && netif_running(ndev)) {
+ /*
+ * Allow only a single IBSS interface to be up at any
+ * time. This is restricted because beacon distribution
+ * cannot work properly if both are in the same IBSS.
+ *
+ * To remove this restriction we'd have to disallow them
+ * from setting the same SSID on different IBSS interfaces
+ * belonging to the same hardware. Then, however, we're
+ * faced with having to adopt two different TSF timers...
+ */
+ if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
+ nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)
+ return -EBUSY;
+
+ /*
+ * Disallow multiple IBSS/STA mode interfaces.
+ *
+ * This is a technical restriction, it is possible although
+ * most likely not IEEE 802.11 compliant to have multiple
+ * STAs with just a single hardware (the TSF timer will not
+ * be adjusted properly.)
+ *
+ * However, because mac80211 uses the master device's BSS
+ * information for each STA/IBSS interface, doing this will
+ * currently corrupt that BSS information completely, unless,
+ * a not very useful case, both STAs are associated to the
+ * same BSS.
+ *
+ * To remove this restriction, the BSS information needs to
+ * be embedded in the STA/IBSS mode sdata instead of using
+ * the master device's BSS structure.
+ */
+ if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
+ sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
+ (nsdata->vif.type == IEEE80211_IF_TYPE_STA ||
+ nsdata->vif.type == IEEE80211_IF_TYPE_IBSS))
+ return -EBUSY;
+
+ /*
+ * The remaining checks are only performed for interfaces
+ * with the same MAC address.
+ */
+ if (compare_ether_addr(dev->dev_addr, ndev->dev_addr))
+ continue;
+
/*
* check whether it may have the same address
*/
@@ -186,8 +248,7 @@ static int ieee80211_open(struct net_device *dev)
* can only add VLANs to enabled APs
*/
if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
- nsdata->vif.type == IEEE80211_IF_TYPE_AP &&
- netif_running(nsdata->dev))
+ nsdata->vif.type == IEEE80211_IF_TYPE_AP)
sdata->u.vlan.ap = nsdata;
}
}
@@ -196,6 +257,20 @@ static int ieee80211_open(struct net_device *dev)
case IEEE80211_IF_TYPE_WDS:
if (is_zero_ether_addr(sdata->u.wds.remote_addr))
return -ENOLINK;
+
+ /* Create STA entry for the WDS peer */
+ sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
+ GFP_KERNEL);
+ if (!sta)
+ return -ENOMEM;
+
+ sta->flags |= WLAN_STA_AUTHORIZED;
+
+ res = sta_info_insert(sta);
+ if (res) {
+ /* STA has been freed */
+ return res;
+ }
break;
case IEEE80211_IF_TYPE_VLAN:
if (!sdata->u.vlan.ap)
@@ -205,6 +280,7 @@ static int ieee80211_open(struct net_device *dev)
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_MNTR:
case IEEE80211_IF_TYPE_IBSS:
+ case IEEE80211_IF_TYPE_MESH_POINT:
/* no special treatment */
break;
case IEEE80211_IF_TYPE_INVALID:
@@ -229,15 +305,28 @@ static int ieee80211_open(struct net_device *dev)
/* no need to tell driver */
break;
case IEEE80211_IF_TYPE_MNTR:
+ if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
+ local->cooked_mntrs++;
+ break;
+ }
+
/* must be before the call to ieee80211_configure_filter */
local->monitors++;
- if (local->monitors == 1) {
- netif_tx_lock_bh(local->mdev);
- ieee80211_configure_filter(local);
- netif_tx_unlock_bh(local->mdev);
-
+ if (local->monitors == 1)
local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
- }
+
+ if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
+ local->fif_fcsfail++;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
+ local->fif_plcpfail++;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
+ local->fif_control++;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
+ local->fif_other_bss++;
+
+ netif_tx_lock_bh(local->mdev);
+ ieee80211_configure_filter(local);
+ netif_tx_unlock_bh(local->mdev);
break;
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
@@ -305,24 +394,46 @@ static int ieee80211_open(struct net_device *dev)
static int ieee80211_stop(struct net_device *dev)
{
- struct ieee80211_sub_if_data *sdata;
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = sdata->local;
struct ieee80211_if_init_conf conf;
struct sta_info *sta;
- int i;
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ /*
+ * Stop TX on this interface first.
+ */
+ netif_stop_queue(dev);
- list_for_each_entry(sta, &local->sta_list, list) {
- if (sta->dev == dev)
- for (i = 0; i < STA_TID_NUM; i++)
- ieee80211_sta_stop_rx_ba_session(sta->dev,
- sta->addr, i,
- WLAN_BACK_RECIPIENT,
- WLAN_REASON_QSTA_LEAVE_QBSS);
+ /*
+ * Now delete all active aggregation sessions.
+ */
+ rcu_read_lock();
+
+ list_for_each_entry_rcu(sta, &local->sta_list, list) {
+ if (sta->sdata == sdata)
+ ieee80211_sta_tear_down_BA_sessions(dev, sta->addr);
}
- netif_stop_queue(dev);
+ rcu_read_unlock();
+
+ /*
+ * Remove all stations associated with this interface.
+ *
+ * This must be done before calling ops->remove_interface()
+ * because otherwise we can later invoke ops->sta_notify()
+ * whenever the STAs are removed, and that invalidates driver
+ * assumptions about always getting a vif pointer that is valid
+ * (because if we remove a STA after ops->remove_interface()
+ * the driver will have removed the vif info already!)
+ *
+ * We could relax this and only unlink the stations from the
+ * hash table and list but keep them on a per-sdata list that
+ * will be inserted back again when the interface is brought
+ * up again, but I don't currently see a use case for that,
+ * except with WDS which gets a STA entry created when it is
+ * brought up.
+ */
+ sta_info_flush(local, sdata);
/*
* Don't count this interface for promisc/allmulti while it
@@ -364,15 +475,29 @@ static int ieee80211_stop(struct net_device *dev)
/* no need to tell driver */
break;
case IEEE80211_IF_TYPE_MNTR:
- local->monitors--;
- if (local->monitors == 0) {
- netif_tx_lock_bh(local->mdev);
- ieee80211_configure_filter(local);
- netif_tx_unlock_bh(local->mdev);
+ if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
+ local->cooked_mntrs--;
+ break;
+ }
+ local->monitors--;
+ if (local->monitors == 0)
local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
- }
+
+ if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
+ local->fif_fcsfail--;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
+ local->fif_plcpfail--;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
+ local->fif_control--;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
+ local->fif_other_bss--;
+
+ netif_tx_lock_bh(local->mdev);
+ ieee80211_configure_filter(local);
+ netif_tx_unlock_bh(local->mdev);
break;
+ case IEEE80211_IF_TYPE_MESH_POINT:
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
sdata->u.sta.state = IEEE80211_DISABLED;
@@ -426,6 +551,357 @@ static int ieee80211_stop(struct net_device *dev)
return 0;
}
+int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct sta_info *sta;
+ struct ieee80211_sub_if_data *sdata;
+ u16 start_seq_num = 0;
+ u8 *state;
+ int ret;
+ DECLARE_MAC_BUF(mac);
+
+ if (tid >= STA_TID_NUM)
+ return -EINVAL;
+
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
+ print_mac(mac, ra), tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, ra);
+ if (!sta) {
+ printk(KERN_DEBUG "Could not find the station\n");
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+ /* we have tried too many times, receiver does not want A-MPDU */
+ if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
+ ret = -EBUSY;
+ goto start_ba_exit;
+ }
+
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+ /* check if the TID is not in aggregation flow already */
+ if (*state != HT_AGG_STATE_IDLE) {
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "BA request denied - session is not "
+ "idle on tid %u\n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ ret = -EAGAIN;
+ goto start_ba_exit;
+ }
+
+ /* prepare A-MPDU MLME for Tx aggregation */
+ sta->ampdu_mlme.tid_tx[tid] =
+ kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
+ if (!sta->ampdu_mlme.tid_tx[tid]) {
+ if (net_ratelimit())
+ printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
+ tid);
+ ret = -ENOMEM;
+ goto start_ba_exit;
+ }
+ /* Tx timer */
+ sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
+ sta_addba_resp_timer_expired;
+ sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
+ (unsigned long)&sta->timer_to_tid[tid];
+ init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
+
+ /* ensure that TX flow won't interrupt us
+ * until the end of the call to requeue function */
+ spin_lock_bh(&local->mdev->queue_lock);
+
+ /* create a new queue for this aggregation */
+ ret = ieee80211_ht_agg_queue_add(local, sta, tid);
+
+ /* case no queue is available to aggregation
+ * don't switch to aggregation */
+ if (ret) {
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "BA request denied - queue unavailable for"
+ " tid %d\n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ goto start_ba_err;
+ }
+ sdata = sta->sdata;
+
+ /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
+ * call back right away, it must see that the flow has begun */
+ *state |= HT_ADDBA_REQUESTED_MSK;
+
+ if (local->ops->ampdu_action)
+ ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
+ ra, tid, &start_seq_num);
+
+ if (ret) {
+ /* No need to requeue the packets in the agg queue, since we
+ * held the tx lock: no packet could be enqueued to the newly
+ * allocated queue */
+ ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "BA request denied - HW unavailable for"
+ " tid %d\n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ *state = HT_AGG_STATE_IDLE;
+ goto start_ba_err;
+ }
+
+ /* Will put all the packets in the new SW queue */
+ ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
+ spin_unlock_bh(&local->mdev->queue_lock);
+
+ /* send an addBA request */
+ sta->ampdu_mlme.dialog_token_allocator++;
+ sta->ampdu_mlme.tid_tx[tid]->dialog_token =
+ sta->ampdu_mlme.dialog_token_allocator;
+ sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
+
+ ieee80211_send_addba_request(sta->sdata->dev, ra, tid,
+ sta->ampdu_mlme.tid_tx[tid]->dialog_token,
+ sta->ampdu_mlme.tid_tx[tid]->ssn,
+ 0x40, 5000);
+
+ /* activate the timer for the recipient's addBA response */
+ sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
+ jiffies + ADDBA_RESP_INTERVAL;
+ add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
+ printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
+ goto start_ba_exit;
+
+start_ba_err:
+ kfree(sta->ampdu_mlme.tid_tx[tid]);
+ sta->ampdu_mlme.tid_tx[tid] = NULL;
+ spin_unlock_bh(&local->mdev->queue_lock);
+ ret = -EBUSY;
+start_ba_exit:
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ rcu_read_unlock();
+ return ret;
+}
+EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
+
+int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
+ u8 *ra, u16 tid,
+ enum ieee80211_back_parties initiator)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct sta_info *sta;
+ u8 *state;
+ int ret = 0;
+ DECLARE_MAC_BUF(mac);
+
+ if (tid >= STA_TID_NUM)
+ return -EINVAL;
+
+ rcu_read_lock();
+ sta = sta_info_get(local, ra);
+ if (!sta) {
+ rcu_read_unlock();
+ return -ENOENT;
+ }
+
+ /* check if the TID is in aggregation */
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+ if (*state != HT_AGG_STATE_OPERATIONAL) {
+ ret = -ENOENT;
+ goto stop_BA_exit;
+ }
+
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "Tx BA session stop requested for %s tid %u\n",
+ print_mac(mac, ra), tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
+ ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
+
+ *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
+ (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
+
+ if (local->ops->ampdu_action)
+ ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
+ ra, tid, NULL);
+
+ /* case HW denied going back to legacy */
+ if (ret) {
+ WARN_ON(ret != -EBUSY);
+ *state = HT_AGG_STATE_OPERATIONAL;
+ ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
+ goto stop_BA_exit;
+ }
+
+stop_BA_exit:
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ rcu_read_unlock();
+ return ret;
+}
+EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
+
+void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct sta_info *sta;
+ u8 *state;
+ DECLARE_MAC_BUF(mac);
+
+ if (tid >= STA_TID_NUM) {
+ printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
+ tid, STA_TID_NUM);
+ return;
+ }
+
+ rcu_read_lock();
+ sta = sta_info_get(local, ra);
+ if (!sta) {
+ rcu_read_unlock();
+ printk(KERN_DEBUG "Could not find station: %s\n",
+ print_mac(mac, ra));
+ return;
+ }
+
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+ if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
+ printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
+ *state);
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ rcu_read_unlock();
+ return;
+ }
+
+ WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
+
+ *state |= HT_ADDBA_DRV_READY_MSK;
+
+ if (*state == HT_AGG_STATE_OPERATIONAL) {
+ printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
+ ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
+ }
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
+
+void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct sta_info *sta;
+ u8 *state;
+ int agg_queue;
+ DECLARE_MAC_BUF(mac);
+
+ if (tid >= STA_TID_NUM) {
+ printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
+ tid, STA_TID_NUM);
+ return;
+ }
+
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "Stopping Tx BA session for %s tid %d\n",
+ print_mac(mac, ra), tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
+ rcu_read_lock();
+ sta = sta_info_get(local, ra);
+ if (!sta) {
+ printk(KERN_DEBUG "Could not find station: %s\n",
+ print_mac(mac, ra));
+ rcu_read_unlock();
+ return;
+ }
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+ if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
+ printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ rcu_read_unlock();
+ return;
+ }
+
+ if (*state & HT_AGG_STATE_INITIATOR_MSK)
+ ieee80211_send_delba(sta->sdata->dev, ra, tid,
+ WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
+
+ agg_queue = sta->tid_to_tx_q[tid];
+
+ /* avoid ordering issues: we are the only one that can modify
+ * the content of the qdiscs */
+ spin_lock_bh(&local->mdev->queue_lock);
+ /* remove the queue for this aggregation */
+ ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
+ spin_unlock_bh(&local->mdev->queue_lock);
+
+ /* we just requeued the all the frames that were in the removed
+ * queue, and since we might miss a softirq we do netif_schedule.
+ * ieee80211_wake_queue is not used here as this queue is not
+ * necessarily stopped */
+ netif_schedule(local->mdev);
+ *state = HT_AGG_STATE_IDLE;
+ sta->ampdu_mlme.addba_req_num[tid] = 0;
+ kfree(sta->ampdu_mlme.tid_tx[tid]);
+ sta->ampdu_mlme.tid_tx[tid] = NULL;
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
+
+void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
+ const u8 *ra, u16 tid)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct ieee80211_ra_tid *ra_tid;
+ struct sk_buff *skb = dev_alloc_skb(0);
+
+ if (unlikely(!skb)) {
+ if (net_ratelimit())
+ printk(KERN_WARNING "%s: Not enough memory, "
+ "dropping start BA session", skb->dev->name);
+ return;
+ }
+ ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
+ memcpy(&ra_tid->ra, ra, ETH_ALEN);
+ ra_tid->tid = tid;
+
+ skb->pkt_type = IEEE80211_ADDBA_MSG;
+ skb_queue_tail(&local->skb_queue, skb);
+ tasklet_schedule(&local->tasklet);
+}
+EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
+
+void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
+ const u8 *ra, u16 tid)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct ieee80211_ra_tid *ra_tid;
+ struct sk_buff *skb = dev_alloc_skb(0);
+
+ if (unlikely(!skb)) {
+ if (net_ratelimit())
+ printk(KERN_WARNING "%s: Not enough memory, "
+ "dropping stop BA session", skb->dev->name);
+ return;
+ }
+ ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
+ memcpy(&ra_tid->ra, ra, ETH_ALEN);
+ ra_tid->tid = tid;
+
+ skb->pkt_type = IEEE80211_DELBA_MSG;
+ skb_queue_tail(&local->skb_queue, skb);
+ tasklet_schedule(&local->tasklet);
+}
+EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
+
static void ieee80211_set_multicast_list(struct net_device *dev)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -477,41 +953,6 @@ void ieee80211_if_setup(struct net_device *dev)
dev->destructor = ieee80211_if_free;
}
-/* WDS specialties */
-
-int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- struct sta_info *sta;
- DECLARE_MAC_BUF(mac);
-
- if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
- return 0;
-
- /* Create STA entry for the new peer */
- sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
- if (!sta)
- return -ENOMEM;
- sta_info_put(sta);
-
- /* Remove STA entry for the old peer */
- sta = sta_info_get(local, sdata->u.wds.remote_addr);
- if (sta) {
- sta_info_free(sta);
- sta_info_put(sta);
- } else {
- printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
- "peer %s\n",
- dev->name, print_mac(mac, sdata->u.wds.remote_addr));
- }
-
- /* Update WDS link data */
- memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
-
- return 0;
-}
-
/* everything else */
static int __ieee80211_if_config(struct net_device *dev,
@@ -532,6 +973,9 @@ static int __ieee80211_if_config(struct net_device *dev,
conf.bssid = sdata->u.sta.bssid;
conf.ssid = sdata->u.sta.ssid;
conf.ssid_len = sdata->u.sta.ssid_len;
+ } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
+ conf.beacon = beacon;
+ ieee80211_start_mesh(dev);
} else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
conf.ssid = sdata->u.ap.ssid;
conf.ssid_len = sdata->u.ap.ssid_len;
@@ -544,6 +988,11 @@ static int __ieee80211_if_config(struct net_device *dev,
int ieee80211_if_config(struct net_device *dev)
{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ if (sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT &&
+ (local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
+ return ieee80211_if_config_beacon(dev);
return __ieee80211_if_config(dev, NULL, NULL);
}
@@ -565,37 +1014,28 @@ int ieee80211_if_config_beacon(struct net_device *dev)
int ieee80211_hw_config(struct ieee80211_local *local)
{
- struct ieee80211_hw_mode *mode;
struct ieee80211_channel *chan;
int ret = 0;
- if (local->sta_sw_scanning) {
+ if (local->sta_sw_scanning)
chan = local->scan_channel;
- mode = local->scan_hw_mode;
- } else {
+ else
chan = local->oper_channel;
- mode = local->oper_hw_mode;
- }
- local->hw.conf.channel = chan->chan;
- local->hw.conf.channel_val = chan->val;
- if (!local->hw.conf.power_level) {
- local->hw.conf.power_level = chan->power_level;
- } else {
- local->hw.conf.power_level = min(chan->power_level,
- local->hw.conf.power_level);
- }
- local->hw.conf.freq = chan->freq;
- local->hw.conf.phymode = mode->mode;
- local->hw.conf.antenna_max = chan->antenna_max;
- local->hw.conf.chan = chan;
- local->hw.conf.mode = mode;
+ local->hw.conf.channel = chan;
+
+ if (!local->hw.conf.power_level)
+ local->hw.conf.power_level = chan->max_power;
+ else
+ local->hw.conf.power_level = min(chan->max_power,
+ local->hw.conf.power_level);
+
+ local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
- "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
- local->hw.conf.phymode);
-#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+ printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
+ wiphy_name(local->hw.wiphy), chan->center_freq);
+#endif
if (local->open_count)
ret = local->ops->config(local_to_hw(local), &local->hw.conf);
@@ -604,52 +1044,69 @@ int ieee80211_hw_config(struct ieee80211_local *local)
}
/**
- * ieee80211_hw_config_ht should be used only after legacy configuration
- * has been determined, as ht configuration depends upon the hardware's
- * HT abilities for a _specific_ band.
+ * ieee80211_handle_ht should be used only after legacy configuration
+ * has been determined namely band, as ht configuration depends upon
+ * the hardware's HT abilities for a _specific_ band.
*/
-int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
+u32 ieee80211_handle_ht(struct ieee80211_local *local, int enable_ht,
struct ieee80211_ht_info *req_ht_cap,
struct ieee80211_ht_bss_info *req_bss_cap)
{
struct ieee80211_conf *conf = &local->hw.conf;
- struct ieee80211_hw_mode *mode = conf->mode;
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_ht_info ht_conf;
+ struct ieee80211_ht_bss_info ht_bss_conf;
int i;
+ u32 changed = 0;
+
+ sband = local->hw.wiphy->bands[conf->channel->band];
/* HT is not supported */
- if (!mode->ht_info.ht_supported) {
+ if (!sband->ht_info.ht_supported) {
conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
- return -EOPNOTSUPP;
+ return 0;
}
- /* disable HT */
- if (!enable_ht) {
- conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
- } else {
+ memset(&ht_conf, 0, sizeof(struct ieee80211_ht_info));
+ memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info));
+
+ if (enable_ht) {
+ if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE))
+ changed |= BSS_CHANGED_HT;
+
conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
- conf->ht_conf.cap = req_ht_cap->cap & mode->ht_info.cap;
- conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
- conf->ht_conf.cap |=
- mode->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
- conf->ht_bss_conf.primary_channel =
- req_bss_cap->primary_channel;
- conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
- conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
+ ht_conf.ht_supported = 1;
+
+ ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
+ ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
+ ht_conf.cap |= sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
+
for (i = 0; i < SUPP_MCS_SET_LEN; i++)
- conf->ht_conf.supp_mcs_set[i] =
- mode->ht_info.supp_mcs_set[i] &
- req_ht_cap->supp_mcs_set[i];
-
- /* In STA mode, this gives us indication
- * to the AP's mode of operation */
- conf->ht_conf.ht_supported = 1;
- conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
- conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
+ ht_conf.supp_mcs_set[i] =
+ sband->ht_info.supp_mcs_set[i] &
+ req_ht_cap->supp_mcs_set[i];
+
+ ht_bss_conf.primary_channel = req_bss_cap->primary_channel;
+ ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
+ ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
+
+ ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
+ ht_conf.ampdu_density = req_ht_cap->ampdu_density;
+
+ /* if bss configuration changed store the new one */
+ if (memcmp(&conf->ht_conf, &ht_conf, sizeof(ht_conf)) ||
+ memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) {
+ changed |= BSS_CHANGED_HT;
+ memcpy(&conf->ht_conf, &ht_conf, sizeof(ht_conf));
+ memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf));
+ }
+ } else {
+ if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)
+ changed |= BSS_CHANGED_HT;
+ conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
}
- local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
-
- return 0;
+ return changed;
}
void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
@@ -725,6 +1182,7 @@ static void ieee80211_tasklet_handler(unsigned long data)
struct sk_buff *skb;
struct ieee80211_rx_status rx_status;
struct ieee80211_tx_status *tx_status;
+ struct ieee80211_ra_tid *ra_tid;
while ((skb = skb_dequeue(&local->skb_queue)) ||
(skb = skb_dequeue(&local->skb_queue_unreliable))) {
@@ -745,6 +1203,18 @@ static void ieee80211_tasklet_handler(unsigned long data)
skb, tx_status);
kfree(tx_status);
break;
+ case IEEE80211_DELBA_MSG:
+ ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
+ ieee80211_stop_tx_ba_cb(local_to_hw(local),
+ ra_tid->ra, ra_tid->tid);
+ dev_kfree_skb(skb);
+ break;
+ case IEEE80211_ADDBA_MSG:
+ ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
+ ieee80211_start_tx_ba_cb(local_to_hw(local),
+ ra_tid->ra, ra_tid->tid);
+ dev_kfree_skb(skb);
+ break ;
default: /* should never get here! */
printk(KERN_ERR "%s: Unknown message type (%d)\n",
wiphy_name(local->hw.wiphy), skb->pkt_type);
@@ -822,6 +1292,77 @@ no_key:
}
}
+static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
+ struct sta_info *sta,
+ struct sk_buff *skb,
+ struct ieee80211_tx_status *status)
+{
+ sta->tx_filtered_count++;
+
+ /*
+ * Clear the TX filter mask for this STA when sending the next
+ * packet. If the STA went to power save mode, this will happen
+ * happen when it wakes up for the next time.
+ */
+ sta->flags |= WLAN_STA_CLEAR_PS_FILT;
+
+ /*
+ * This code races in the following way:
+ *
+ * (1) STA sends frame indicating it will go to sleep and does so
+ * (2) hardware/firmware adds STA to filter list, passes frame up
+ * (3) hardware/firmware processes TX fifo and suppresses a frame
+ * (4) we get TX status before having processed the frame and
+ * knowing that the STA has gone to sleep.
+ *
+ * This is actually quite unlikely even when both those events are
+ * processed from interrupts coming in quickly after one another or
+ * even at the same time because we queue both TX status events and
+ * RX frames to be processed by a tasklet and process them in the
+ * same order that they were received or TX status last. Hence, there
+ * is no race as long as the frame RX is processed before the next TX
+ * status, which drivers can ensure, see below.
+ *
+ * Note that this can only happen if the hardware or firmware can
+ * actually add STAs to the filter list, if this is done by the
+ * driver in response to set_tim() (which will only reduce the race
+ * this whole filtering tries to solve, not completely solve it)
+ * this situation cannot happen.
+ *
+ * To completely solve this race drivers need to make sure that they
+ * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
+ * functions and
+ * (b) always process RX events before TX status events if ordering
+ * can be unknown, for example with different interrupt status
+ * bits.
+ */
+ if (sta->flags & WLAN_STA_PS &&
+ skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
+ ieee80211_remove_tx_extra(local, sta->key, skb,
+ &status->control);
+ skb_queue_tail(&sta->tx_filtered, skb);
+ return;
+ }
+
+ if (!(sta->flags & WLAN_STA_PS) &&
+ !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
+ /* Software retry the packet once */
+ status->control.flags |= IEEE80211_TXCTL_REQUEUE;
+ ieee80211_remove_tx_extra(local, sta->key, skb,
+ &status->control);
+ dev_queue_xmit(skb);
+ return;
+ }
+
+ if (net_ratelimit())
+ printk(KERN_DEBUG "%s: dropped TX filtered frame, "
+ "queue_len=%d PS=%d @%lu\n",
+ wiphy_name(local->hw.wiphy),
+ skb_queue_len(&sta->tx_filtered),
+ !!(sta->flags & WLAN_STA_PS), jiffies);
+ dev_kfree_skb(skb);
+}
+
void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
struct ieee80211_tx_status *status)
{
@@ -831,7 +1372,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
u16 frag, type;
struct ieee80211_tx_status_rtap_hdr *rthdr;
struct ieee80211_sub_if_data *sdata;
- int monitors;
+ struct net_device *prev_dev = NULL;
if (!status) {
printk(KERN_ERR
@@ -841,18 +1382,24 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
return;
}
+ rcu_read_lock();
+
if (status->excessive_retries) {
struct sta_info *sta;
sta = sta_info_get(local, hdr->addr1);
if (sta) {
if (sta->flags & WLAN_STA_PS) {
- /* The STA is in power save mode, so assume
+ /*
+ * The STA is in power save mode, so assume
* that this TX packet failed because of that.
*/
status->excessive_retries = 0;
status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
+ ieee80211_handle_filtered_frame(local, sta,
+ skb, status);
+ rcu_read_unlock();
+ return;
}
- sta_info_put(sta);
}
}
@@ -860,53 +1407,16 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
struct sta_info *sta;
sta = sta_info_get(local, hdr->addr1);
if (sta) {
- sta->tx_filtered_count++;
-
- /* Clear the TX filter mask for this STA when sending
- * the next packet. If the STA went to power save mode,
- * this will happen when it is waking up for the next
- * time. */
- sta->clear_dst_mask = 1;
-
- /* TODO: Is the WLAN_STA_PS flag always set here or is
- * the race between RX and TX status causing some
- * packets to be filtered out before 80211.o gets an
- * update for PS status? This seems to be the case, so
- * no changes are likely to be needed. */
- if (sta->flags & WLAN_STA_PS &&
- skb_queue_len(&sta->tx_filtered) <
- STA_MAX_TX_BUFFER) {
- ieee80211_remove_tx_extra(local, sta->key,
- skb,
- &status->control);
- skb_queue_tail(&sta->tx_filtered, skb);
- } else if (!(sta->flags & WLAN_STA_PS) &&
- !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
- /* Software retry the packet once */
- status->control.flags |= IEEE80211_TXCTL_REQUEUE;
- ieee80211_remove_tx_extra(local, sta->key,
- skb,
- &status->control);
- dev_queue_xmit(skb);
- } else {
- if (net_ratelimit()) {
- printk(KERN_DEBUG "%s: dropped TX "
- "filtered frame queue_len=%d "
- "PS=%d @%lu\n",
- wiphy_name(local->hw.wiphy),
- skb_queue_len(
- &sta->tx_filtered),
- !!(sta->flags & WLAN_STA_PS),
- jiffies);
- }
- dev_kfree_skb(skb);
- }
- sta_info_put(sta);
+ ieee80211_handle_filtered_frame(local, sta, skb,
+ status);
+ rcu_read_unlock();
return;
}
} else
rate_control_tx_status(local->mdev, skb, status);
+ rcu_read_unlock();
+
ieee80211_led_tx(local, 0);
/* SNMP counters
@@ -944,7 +1454,11 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
/* this was a transmitted frame, but now we want to reuse it */
skb_orphan(skb);
- if (!local->monitors) {
+ /*
+ * This is a bit racy but we can avoid a lot of work
+ * with this test...
+ */
+ if (!local->monitors && !local->cooked_mntrs) {
dev_kfree_skb(skb);
return;
}
@@ -978,51 +1492,44 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
rthdr->data_retries = status->retry_count;
+ /* XXX: is this sufficient for BPF? */
+ skb_set_mac_header(skb, 0);
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ skb->pkt_type = PACKET_OTHERHOST;
+ skb->protocol = htons(ETH_P_802_2);
+ memset(skb->cb, 0, sizeof(skb->cb));
+
rcu_read_lock();
- monitors = local->monitors;
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
- /*
- * Using the monitors counter is possibly racy, but
- * if the value is wrong we simply either clone the skb
- * once too much or forget sending it to one monitor iface
- * The latter case isn't nice but fixing the race is much
- * more complicated.
- */
- if (!monitors || !skb)
- goto out;
-
if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
if (!netif_running(sdata->dev))
continue;
- monitors--;
- if (monitors)
+
+ if (prev_dev) {
skb2 = skb_clone(skb, GFP_ATOMIC);
- else
- skb2 = NULL;
- skb->dev = sdata->dev;
- /* XXX: is this sufficient for BPF? */
- skb_set_mac_header(skb, 0);
- skb->ip_summed = CHECKSUM_UNNECESSARY;
- skb->pkt_type = PACKET_OTHERHOST;
- skb->protocol = htons(ETH_P_802_2);
- memset(skb->cb, 0, sizeof(skb->cb));
- netif_rx(skb);
- skb = skb2;
+ if (skb2) {
+ skb2->dev = prev_dev;
+ netif_rx(skb2);
+ }
+ }
+
+ prev_dev = sdata->dev;
}
}
- out:
+ if (prev_dev) {
+ skb->dev = prev_dev;
+ netif_rx(skb);
+ skb = NULL;
+ }
rcu_read_unlock();
- if (skb)
- dev_kfree_skb(skb);
+ dev_kfree_skb(skb);
}
EXPORT_SYMBOL(ieee80211_tx_status);
struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
const struct ieee80211_ops *ops)
{
- struct net_device *mdev;
struct ieee80211_local *local;
- struct ieee80211_sub_if_data *sdata;
int priv_size;
struct wiphy *wiphy;
@@ -1068,25 +1575,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
BUG_ON(!ops->configure_filter);
local->ops = ops;
- /* for now, mdev needs sub_if_data :/ */
- mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
- "wmaster%d", ether_setup);
- if (!mdev) {
- wiphy_free(wiphy);
- return NULL;
- }
-
- sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
- mdev->ieee80211_ptr = &sdata->wdev;
- sdata->wdev.wiphy = wiphy;
-
local->hw.queues = 1; /* default */
- local->mdev = mdev;
- local->rx_pre_handlers = ieee80211_rx_pre_handlers;
- local->rx_handlers = ieee80211_rx_handlers;
- local->tx_handlers = ieee80211_tx_handlers;
-
local->bridge_packets = 1;
local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
@@ -1095,33 +1585,14 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
local->long_retry_limit = 4;
local->hw.conf.radio_enabled = 1;
- local->enabled_modes = ~0;
-
- INIT_LIST_HEAD(&local->modes_list);
-
INIT_LIST_HEAD(&local->interfaces);
+ spin_lock_init(&local->key_lock);
+
INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
- ieee80211_rx_bss_list_init(mdev);
sta_info_init(local);
- mdev->hard_start_xmit = ieee80211_master_start_xmit;
- mdev->open = ieee80211_master_open;
- mdev->stop = ieee80211_master_stop;
- mdev->type = ARPHRD_IEEE80211;
- mdev->header_ops = &ieee80211_header_ops;
- mdev->set_multicast_list = ieee80211_master_set_multicast_list;
-
- sdata->vif.type = IEEE80211_IF_TYPE_AP;
- sdata->dev = mdev;
- sdata->local = local;
- sdata->u.ap.force_unicast_rateidx = -1;
- sdata->u.ap.max_ratectrl_rateidx = -1;
- ieee80211_if_sdata_init(sdata);
- /* no RCU needed since we're still during init phase */
- list_add_tail(&sdata->list, &local->interfaces);
-
tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
(unsigned long)local);
tasklet_disable(&local->tx_pending_tasklet);
@@ -1143,11 +1614,63 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
struct ieee80211_local *local = hw_to_local(hw);
const char *name;
int result;
+ enum ieee80211_band band;
+ struct net_device *mdev;
+ struct ieee80211_sub_if_data *sdata;
+
+ /*
+ * generic code guarantees at least one band,
+ * set this very early because much code assumes
+ * that hw.conf.channel is assigned
+ */
+ for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
+ struct ieee80211_supported_band *sband;
+
+ sband = local->hw.wiphy->bands[band];
+ if (sband) {
+ /* init channel we're on */
+ local->hw.conf.channel =
+ local->oper_channel =
+ local->scan_channel = &sband->channels[0];
+ break;
+ }
+ }
result = wiphy_register(local->hw.wiphy);
if (result < 0)
return result;
+ /* for now, mdev needs sub_if_data :/ */
+ mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
+ "wmaster%d", ether_setup);
+ if (!mdev)
+ goto fail_mdev_alloc;
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
+ mdev->ieee80211_ptr = &sdata->wdev;
+ sdata->wdev.wiphy = local->hw.wiphy;
+
+ local->mdev = mdev;
+
+ ieee80211_rx_bss_list_init(mdev);
+
+ mdev->hard_start_xmit = ieee80211_master_start_xmit;
+ mdev->open = ieee80211_master_open;
+ mdev->stop = ieee80211_master_stop;
+ mdev->type = ARPHRD_IEEE80211;
+ mdev->header_ops = &ieee80211_header_ops;
+ mdev->set_multicast_list = ieee80211_master_set_multicast_list;
+
+ sdata->vif.type = IEEE80211_IF_TYPE_AP;
+ sdata->dev = mdev;
+ sdata->local = local;
+ sdata->u.ap.force_unicast_rateidx = -1;
+ sdata->u.ap.max_ratectrl_rateidx = -1;
+ ieee80211_if_sdata_init(sdata);
+
+ /* no RCU needed since we're still during init phase */
+ list_add_tail(&sdata->list, &local->interfaces);
+
name = wiphy_dev(local->hw.wiphy)->driver->name;
local->hw.workqueue = create_singlethread_workqueue(name);
if (!local->hw.workqueue) {
@@ -1215,7 +1738,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
/* add one default STA interface */
result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
- IEEE80211_IF_TYPE_STA);
+ IEEE80211_IF_TYPE_STA, NULL);
if (result)
printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
wiphy_name(local->hw.wiphy));
@@ -1239,49 +1762,18 @@ fail_sta_info:
debugfs_hw_del(local);
destroy_workqueue(local->hw.workqueue);
fail_workqueue:
+ ieee80211_if_free(local->mdev);
+ local->mdev = NULL;
+fail_mdev_alloc:
wiphy_unregister(local->hw.wiphy);
return result;
}
EXPORT_SYMBOL(ieee80211_register_hw);
-int ieee80211_register_hwmode(struct ieee80211_hw *hw,
- struct ieee80211_hw_mode *mode)
-{
- struct ieee80211_local *local = hw_to_local(hw);
- struct ieee80211_rate *rate;
- int i;
-
- INIT_LIST_HEAD(&mode->list);
- list_add_tail(&mode->list, &local->modes_list);
-
- local->hw_modes |= (1 << mode->mode);
- for (i = 0; i < mode->num_rates; i++) {
- rate = &(mode->rates[i]);
- rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
- }
- ieee80211_prepare_rates(local, mode);
-
- if (!local->oper_hw_mode) {
- /* Default to this mode */
- local->hw.conf.phymode = mode->mode;
- local->oper_hw_mode = local->scan_hw_mode = mode;
- local->oper_channel = local->scan_channel = &mode->channels[0];
- local->hw.conf.mode = local->oper_hw_mode;
- local->hw.conf.chan = local->oper_channel;
- }
-
- if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
- ieee80211_set_default_regdomain(mode);
-
- return 0;
-}
-EXPORT_SYMBOL(ieee80211_register_hwmode);
-
void ieee80211_unregister_hw(struct ieee80211_hw *hw)
{
struct ieee80211_local *local = hw_to_local(hw);
struct ieee80211_sub_if_data *sdata, *tmp;
- int i;
tasklet_kill(&local->tx_pending_tasklet);
tasklet_kill(&local->tasklet);
@@ -1322,11 +1814,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
rate_control_deinitialize(local);
debugfs_hw_del(local);
- for (i = 0; i < NUM_IEEE80211_MODES; i++) {
- kfree(local->supp_rates[i]);
- kfree(local->basic_rates[i]);
- }
-
if (skb_queue_len(&local->skb_queue)
|| skb_queue_len(&local->skb_queue_unreliable))
printk(KERN_WARNING "%s: skb_queue not empty\n",
@@ -1338,6 +1825,8 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
wiphy_unregister(local->hw.wiphy);
ieee80211_wep_free(local);
ieee80211_led_exit(local);
+ ieee80211_if_free(local->mdev);
+ local->mdev = NULL;
}
EXPORT_SYMBOL(ieee80211_unregister_hw);
@@ -1345,7 +1834,6 @@ void ieee80211_free_hw(struct ieee80211_hw *hw)
{
struct ieee80211_local *local = hw_to_local(hw);
- ieee80211_if_free(local->mdev);
wiphy_free(local->hw.wiphy);
}
EXPORT_SYMBOL(ieee80211_free_hw);
@@ -1357,13 +1845,9 @@ static int __init ieee80211_init(void)
BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
- ret = rc80211_simple_init();
- if (ret)
- goto out;
-
ret = rc80211_pid_init();
if (ret)
- goto out_cleanup_simple;
+ goto out;
ret = ieee80211_wme_register();
if (ret) {
@@ -1373,23 +1857,28 @@ static int __init ieee80211_init(void)
}
ieee80211_debugfs_netdev_init();
- ieee80211_regdomain_init();
return 0;
out_cleanup_pid:
rc80211_pid_exit();
- out_cleanup_simple:
- rc80211_simple_exit();
out:
return ret;
}
static void __exit ieee80211_exit(void)
{
- rc80211_simple_exit();
rc80211_pid_exit();
+ /*
+ * For key todo, it'll be empty by now but the work
+ * might still be scheduled.
+ */
+ flush_scheduled_work();
+
+ if (mesh_allocated)
+ ieee80211s_stop();
+
ieee80211_wme_unregister();
ieee80211_debugfs_netdev_exit();
}
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 @@
+/*
+ * Copyright (c) 2008 open80211s Ltd.
+ * Authors: Luis Carlos Cobo <luisca@cozybit.com>
+ * Javier Cardona <javier@cozybit.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "ieee80211_i.h"
+#include "mesh.h"
+
+#define PP_OFFSET 1 /* Path Selection Protocol */
+#define PM_OFFSET 5 /* Path Selection Metric */
+#define CC_OFFSET 9 /* Congestion Control Mode */
+#define CAPAB_OFFSET 17
+#define ACCEPT_PLINKS 0x80
+
+int mesh_allocated;
+static struct kmem_cache *rm_cache;
+
+void ieee80211s_init(void)
+{
+ mesh_pathtbl_init();
+ mesh_allocated = 1;
+ rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry),
+ 0, 0, NULL);
+}
+
+void ieee80211s_stop(void)
+{
+ mesh_pathtbl_unregister();
+ kmem_cache_destroy(rm_cache);
+}
+
+/**
+ * mesh_matches_local - check if the config of a mesh point matches ours
+ *
+ * @ie: information elements of a management frame from the mesh peer
+ * @dev: local mesh interface
+ *
+ * This function checks if the mesh configuration of a mesh point matches the
+ * local mesh configuration, i.e. if both nodes belong to the same mesh network.
+ */
+bool mesh_matches_local(struct ieee802_11_elems *ie, struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_if_sta *sta = &sdata->u.sta;
+
+ /*
+ * As support for each feature is added, check for matching
+ * - On mesh config capabilities
+ * - Power Save Support En
+ * - Sync support enabled
+ * - Sync support active
+ * - Sync support required from peer
+ * - MDA enabled
+ * - Power management control on fc
+ */
+ if (sta->mesh_id_len == ie->mesh_id_len &&
+ memcmp(sta->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 &&
+ memcmp(sta->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 &&
+ memcmp(sta->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 &&
+ memcmp(sta->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0)
+ return true;
+
+ return false;
+}
+
+/**
+ * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links
+ *
+ * @ie: information elements of a management frame from the mesh peer
+ * @dev: local mesh interface
+ */
+bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie,
+ struct net_device *dev)
+{
+ return (*(ie->mesh_config + CAPAB_OFFSET) & ACCEPT_PLINKS) != 0;
+}
+
+/**
+ * mesh_accept_plinks_update: update accepting_plink in local mesh beacons
+ *
+ * @sdata: mesh interface in which mesh beacons are going to be updated
+ */
+void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata)
+{
+ bool free_plinks;
+
+ /* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0,
+ * the mesh interface might be able to establish plinks with peers that
+ * are already on the table but are not on PLINK_ESTAB state. However,
+ * in general the mesh interface is not accepting peer link requests
+ * from new peers, and that must be reflected in the beacon
+ */
+ free_plinks = mesh_plink_availables(sdata);
+
+ if (free_plinks != sdata->u.sta.accepting_plinks)
+ ieee80211_sta_timer((unsigned long) sdata);
+}
+
+void mesh_ids_set_default(struct ieee80211_if_sta *sta)
+{
+ u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff};
+
+ memcpy(sta->mesh_pp_id, def_id, 4);
+ memcpy(sta->mesh_pm_id, def_id, 4);
+ memcpy(sta->mesh_cc_id, def_id, 4);
+}
+
+int mesh_rmc_init(struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ int i;
+
+ sdata->u.sta.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL);
+ if (!sdata->u.sta.rmc)
+ return -ENOMEM;
+ sdata->u.sta.rmc->idx_mask = RMC_BUCKETS - 1;
+ for (i = 0; i < RMC_BUCKETS; i++)
+ INIT_LIST_HEAD(&sdata->u.sta.rmc->bucket[i].list);
+ return 0;
+}
+
+void mesh_rmc_free(struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_rmc *rmc = sdata->u.sta.rmc;
+ struct rmc_entry *p, *n;
+ int i;
+
+ if (!sdata->u.sta.rmc)
+ return;
+
+ for (i = 0; i < RMC_BUCKETS; i++)
+ list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) {
+ list_del(&p->list);
+ kmem_cache_free(rm_cache, p);
+ }
+
+ kfree(rmc);
+ sdata->u.sta.rmc = NULL;
+}
+
+/**
+ * mesh_rmc_check - Check frame in recent multicast cache and add if absent.
+ *
+ * @sa: source address
+ * @mesh_hdr: mesh_header
+ *
+ * Returns: 0 if the frame is not in the cache, nonzero otherwise.
+ *
+ * Checks using the source address and the mesh sequence number if we have
+ * received this frame lately. If the frame is not in the cache, it is added to
+ * it.
+ */
+int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr,
+ struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_rmc *rmc = sdata->u.sta.rmc;
+ u32 seqnum = 0;
+ int entries = 0;
+ u8 idx;
+ struct rmc_entry *p, *n;
+
+ /* Don't care about endianness since only match matters */
+ memcpy(&seqnum, mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum));
+ idx = mesh_hdr->seqnum[0] & rmc->idx_mask;
+ list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) {
+ ++entries;
+ if (time_after(jiffies, p->exp_time) ||
+ (entries == RMC_QUEUE_MAX_LEN)) {
+ list_del(&p->list);
+ kmem_cache_free(rm_cache, p);
+ --entries;
+ } else if ((seqnum == p->seqnum)
+ && (memcmp(sa, p->sa, ETH_ALEN) == 0))
+ return -1;
+ }
+
+ p = kmem_cache_alloc(rm_cache, GFP_ATOMIC);
+ if (!p) {
+ printk(KERN_DEBUG "o11s: could not allocate RMC entry\n");
+ return 0;
+ }
+ p->seqnum = seqnum;
+ p->exp_time = jiffies + RMC_TIMEOUT;
+ memcpy(p->sa, sa, ETH_ALEN);
+ list_add(&p->list, &rmc->bucket[idx].list);
+ return 0;
+}
+
+void mesh_mgmt_ies_add(struct sk_buff *skb, struct net_device *dev)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_supported_band *sband;
+ u8 *pos;
+ int len, i, rate;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+ len = sband->n_bitrates;
+ if (len > 8)
+ len = 8;
+ pos = skb_put(skb, len + 2);
+ *pos++ = WLAN_EID_SUPP_RATES;
+ *pos++ = len;
+ for (i = 0; i < len; i++) {
+ rate = sband->bitrates[i].bitrate;
+ *pos++ = (u8) (rate / 5);
+ }
+
+ if (sband->n_bitrates > len) {
+ pos = skb_put(skb, sband->n_bitrates - len + 2);
+ *pos++ = WLAN_EID_EXT_SUPP_RATES;
+ *pos++ = sband->n_bitrates - len;
+ for (i = len; i < sband->n_bitrates; i++) {
+ rate = sband->bitrates[i].bitrate;
+ *pos++ = (u8) (rate / 5);
+ }
+ }
+
+ pos = skb_put(skb, 2 + sdata->u.sta.mesh_id_len);
+ *pos++ = WLAN_EID_MESH_ID;
+ *pos++ = sdata->u.sta.mesh_id_len;
+ if (sdata->u.sta.mesh_id_len)
+ memcpy(pos, sdata->u.sta.mesh_id, sdata->u.sta.mesh_id_len);
+
+ pos = skb_put(skb, 21);
+ *pos++ = WLAN_EID_MESH_CONFIG;
+ *pos++ = MESH_CFG_LEN;
+ /* Version */
+ *pos++ = 1;
+
+ /* Active path selection protocol ID */
+ memcpy(pos, sdata->u.sta.mesh_pp_id, 4);
+ pos += 4;
+
+ /* Active path selection metric ID */
+ memcpy(pos, sdata->u.sta.mesh_pm_id, 4);
+ pos += 4;
+
+ /* Congestion control mode identifier */
+ memcpy(pos, sdata->u.sta.mesh_cc_id, 4);
+ pos += 4;
+
+ /* Channel precedence:
+ * Not running simple channel unification protocol
+ */
+ memset(pos, 0x00, 4);
+ pos += 4;
+
+ /* Mesh capability */
+ sdata->u.sta.accepting_plinks = mesh_plink_availables(sdata);
+ *pos++ = sdata->u.sta.accepting_plinks ? ACCEPT_PLINKS : 0x00;
+ *pos++ = 0x00;
+
+ return;
+}
+
+u32 mesh_table_hash(u8 *addr, struct net_device *dev, struct mesh_table *tbl)
+{
+ /* Use last four bytes of hw addr and interface index as hash index */
+ return jhash_2words(*(u32 *)(addr+2), dev->ifindex, tbl->hash_rnd)
+ & tbl->hash_mask;
+}
+
+u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len)
+{
+ if (!mesh_id_len)
+ return 1;
+ else if (mesh_id_len == 1)
+ return (u8) mesh_id[0];
+ else
+ return (u8) (mesh_id[0] + 2 * mesh_id[1]);
+}
+
+struct mesh_table *mesh_table_alloc(int size_order)
+{
+ int i;
+ struct mesh_table *newtbl;
+
+ newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL);
+ if (!newtbl)
+ return NULL;
+
+ newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) *
+ (1 << size_order), GFP_KERNEL);
+
+ if (!newtbl->hash_buckets) {
+ kfree(newtbl);
+ return NULL;
+ }
+
+ newtbl->hashwlock = kmalloc(sizeof(spinlock_t) *
+ (1 << size_order), GFP_KERNEL);
+ if (!newtbl->hashwlock) {
+ kfree(newtbl->hash_buckets);
+ kfree(newtbl);
+ return NULL;
+ }
+
+ newtbl->size_order = size_order;
+ newtbl->hash_mask = (1 << size_order) - 1;
+ atomic_set(&newtbl->entries, 0);
+ get_random_bytes(&newtbl->hash_rnd,
+ sizeof(newtbl->hash_rnd));
+ for (i = 0; i <= newtbl->hash_mask; i++)
+ spin_lock_init(&newtbl->hashwlock[i]);
+
+ return newtbl;
+}
+
+void mesh_table_free(struct mesh_table *tbl, bool free_leafs)
+{
+ struct hlist_head *mesh_hash;
+ struct hlist_node *p, *q;
+ int i;
+
+ mesh_hash = tbl->hash_buckets;
+ for (i = 0; i <= tbl->hash_mask; i++) {
+ spin_lock(&tbl->hashwlock[i]);
+ hlist_for_each_safe(p, q, &mesh_hash[i]) {
+ tbl->free_node(p, free_leafs);
+ atomic_dec(&tbl->entries);
+ }
+ spin_unlock(&tbl->hashwlock[i]);
+ }
+ kfree(tbl->hash_buckets);
+ kfree(tbl->hashwlock);
+ kfree(tbl);
+}
+
+static void ieee80211_mesh_path_timer(unsigned long data)
+{
+ struct ieee80211_sub_if_data *sdata =
+ (struct ieee80211_sub_if_data *) data;
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+ struct ieee80211_local *local = wdev_priv(&sdata->wdev);
+
+ queue_work(local->hw.workqueue, &ifsta->work);
+}
+
+struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
+{
+ struct mesh_table *newtbl;
+ struct hlist_head *oldhash;
+ struct hlist_node *p;
+ int err = 0;
+ int i;
+
+ if (atomic_read(&tbl->entries)
+ < tbl->mean_chain_len * (tbl->hash_mask + 1)) {
+ err = -EPERM;
+ goto endgrow;
+ }
+
+ newtbl = mesh_table_alloc(tbl->size_order + 1);
+ if (!newtbl) {
+ err = -ENOMEM;
+ goto endgrow;
+ }
+
+ newtbl->free_node = tbl->free_node;
+ newtbl->mean_chain_len = tbl->mean_chain_len;
+ newtbl->copy_node = tbl->copy_node;
+ atomic_set(&newtbl->entries, atomic_read(&tbl->entries));
+
+ oldhash = tbl->hash_buckets;
+ for (i = 0; i <= tbl->hash_mask; i++)
+ hlist_for_each(p, &oldhash[i])
+ tbl->copy_node(p, newtbl);
+
+endgrow:
+ if (err)
+ return NULL;
+ else
+ return newtbl;
+}
+
+/**
+ * ieee80211_new_mesh_header - create a new mesh header
+ * @meshhdr: uninitialized mesh header
+ * @sdata: mesh interface to be used
+ *
+ * Return the header length.
+ */
+int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
+ struct ieee80211_sub_if_data *sdata)
+{
+ meshhdr->flags = 0;
+ meshhdr->ttl = sdata->u.sta.mshcfg.dot11MeshTTL;
+
+ meshhdr->seqnum[0] = sdata->u.sta.mesh_seqnum[0]++;
+ meshhdr->seqnum[1] = sdata->u.sta.mesh_seqnum[1];
+ meshhdr->seqnum[2] = sdata->u.sta.mesh_seqnum[2];
+
+ if (sdata->u.sta.mesh_seqnum[0] == 0) {
+ sdata->u.sta.mesh_seqnum[1]++;
+ if (sdata->u.sta.mesh_seqnum[1] == 0)
+ sdata->u.sta.mesh_seqnum[2]++;
+ }
+
+ return 5;
+}
+
+void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
+{
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+
+ ifsta->mshcfg.dot11MeshRetryTimeout = MESH_RET_T;
+ ifsta->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T;
+ ifsta->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T;
+ ifsta->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR;
+ ifsta->mshcfg.dot11MeshTTL = MESH_TTL;
+ ifsta->mshcfg.auto_open_plinks = true;
+ ifsta->mshcfg.dot11MeshMaxPeerLinks =
+ MESH_MAX_ESTAB_PLINKS;
+ ifsta->mshcfg.dot11MeshHWMPactivePathTimeout =
+ MESH_PATH_TIMEOUT;
+ ifsta->mshcfg.dot11MeshHWMPpreqMinInterval =
+ MESH_PREQ_MIN_INT;
+ ifsta->mshcfg.dot11MeshHWMPnetDiameterTraversalTime =
+ MESH_DIAM_TRAVERSAL_TIME;
+ ifsta->mshcfg.dot11MeshHWMPmaxPREQretries =
+ MESH_MAX_PREQ_RETRIES;
+ ifsta->mshcfg.path_refresh_time =
+ MESH_PATH_REFRESH_TIME;
+ ifsta->mshcfg.min_discovery_timeout =
+ MESH_MIN_DISCOVERY_TIMEOUT;
+ ifsta->accepting_plinks = true;
+ ifsta->preq_id = 0;
+ ifsta->dsn = 0;
+ atomic_set(&ifsta->mpaths, 0);
+ mesh_rmc_init(sdata->dev);
+ ifsta->last_preq = jiffies;
+ /* Allocate all mesh structures when creating the first mesh interface. */
+ if (!mesh_allocated)
+ ieee80211s_init();
+ mesh_ids_set_default(ifsta);
+ setup_timer(&ifsta->mesh_path_timer,
+ ieee80211_mesh_path_timer,
+ (unsigned long) sdata);
+ INIT_LIST_HEAD(&ifsta->preq_queue.list);
+ spin_lock_init(&ifsta->mesh_preq_queue_lock);
+}
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 @@
+/*
+ * Copyright (c) 2008 open80211s Ltd.
+ * Authors: Luis Carlos Cobo <luisca@cozybit.com>
+ * Javier Cardona <javier@cozybit.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef IEEE80211S_H
+#define IEEE80211S_H
+
+#include <linux/types.h>
+#include <linux/jhash.h>
+#include "ieee80211_i.h"
+
+
+/* Data structures */
+
+/**
+ * enum mesh_path_flags - mac80211 mesh path flags
+ *
+ *
+ *
+ * @MESH_PATH_ACTIVE: the mesh path is can be used for forwarding
+ * @MESH_PATH_RESOLVED: the discovery process is running for this mesh path
+ * @MESH_PATH_DSN_VALID: the mesh path contains a valid destination sequence
+ * number
+ * @MESH_PATH_FIXED: the mesh path has been manually set and should not be
+ * modified
+ * @MESH_PATH_RESOLVED: the mesh path can has been resolved
+ *
+ * MESH_PATH_RESOLVED and MESH_PATH_DELETE are used by the mesh path timer to
+ * decide when to stop or cancel the mesh path discovery.
+ */
+enum mesh_path_flags {
+ MESH_PATH_ACTIVE = BIT(0),
+ MESH_PATH_RESOLVING = BIT(1),
+ MESH_PATH_DSN_VALID = BIT(2),
+ MESH_PATH_FIXED = BIT(3),
+ MESH_PATH_RESOLVED = BIT(4),
+};
+
+/**
+ * struct mesh_path - mac80211 mesh path structure
+ *
+ * @dst: mesh path destination mac address
+ * @dev: mesh path device
+ * @next_hop: mesh neighbor to which frames for this destination will be
+ * forwarded
+ * @timer: mesh path discovery timer
+ * @frame_queue: pending queue for frames sent to this destination while the
+ * path is unresolved
+ * @dsn: destination sequence number of the destination
+ * @metric: current metric to this destination
+ * @hop_count: hops to destination
+ * @exp_time: in jiffies, when the path will expire or when it expired
+ * @discovery_timeout: timeout (lapse in jiffies) used for the last discovery
+ * retry
+ * @discovery_retries: number of discovery retries
+ * @flags: mesh path flags, as specified on &enum mesh_path_flags
+ * @state_lock: mesh pat state lock
+ *
+ *
+ * The combination of dst and dev is unique in the mesh path table. Since the
+ * next_hop STA is only protected by RCU as well, deleting the STA must also
+ * remove/substitute the mesh_path structure and wait until that is no longer
+ * reachable before destroying the STA completely.
+ */
+struct mesh_path {
+ u8 dst[ETH_ALEN];
+ struct net_device *dev;
+ struct sta_info *next_hop;
+ struct timer_list timer;
+ struct sk_buff_head frame_queue;
+ struct rcu_head rcu;
+ u32 dsn;
+ u32 metric;
+ u8 hop_count;
+ unsigned long exp_time;
+ u32 discovery_timeout;
+ u8 discovery_retries;
+ enum mesh_path_flags flags;
+ spinlock_t state_lock;
+};
+
+/**
+ * struct mesh_table
+ *
+ * @hash_buckets: array of hash buckets of the table
+ * @hashwlock: array of locks to protect write operations, one per bucket
+ * @hash_mask: 2^size_order - 1, used to compute hash idx
+ * @hash_rnd: random value used for hash computations
+ * @entries: number of entries in the table
+ * @free_node: function to free nodes of the table
+ * @copy_node: fuction to copy nodes of the table
+ * @size_order: determines size of the table, there will be 2^size_order hash
+ * buckets
+ * @mean_chain_len: maximum average length for the hash buckets' list, if it is
+ * reached, the table will grow
+ */
+struct mesh_table {
+ /* Number of buckets will be 2^N */
+ struct hlist_head *hash_buckets;
+ spinlock_t *hashwlock; /* One per bucket, for add/del */
+ unsigned int hash_mask; /* (2^size_order) - 1 */
+ __u32 hash_rnd; /* Used for hash generation */
+ atomic_t entries; /* Up to MAX_MESH_NEIGHBOURS */
+ void (*free_node) (struct hlist_node *p, bool free_leafs);
+ void (*copy_node) (struct hlist_node *p, struct mesh_table *newtbl);
+ int size_order;
+ int mean_chain_len;
+};
+
+/* Recent multicast cache */
+/* RMC_BUCKETS must be a power of 2, maximum 256 */
+#define RMC_BUCKETS 256
+#define RMC_QUEUE_MAX_LEN 4
+#define RMC_TIMEOUT (3 * HZ)
+
+/**
+ * struct rmc_entry - entry in the Recent Multicast Cache
+ *
+ * @seqnum: mesh sequence number of the frame
+ * @exp_time: expiration time of the entry, in jiffies
+ * @sa: source address of the frame
+ *
+ * The Recent Multicast Cache keeps track of the latest multicast frames that
+ * have been received by a mesh interface and discards received multicast frames
+ * that are found in the cache.
+ */
+struct rmc_entry {
+ struct list_head list;
+ u32 seqnum;
+ unsigned long exp_time;
+ u8 sa[ETH_ALEN];
+};
+
+struct mesh_rmc {
+ struct rmc_entry bucket[RMC_BUCKETS];
+ u8 idx_mask;
+};
+
+
+/* Mesh IEs constants */
+#define MESH_CFG_LEN 19
+
+/*
+ * MESH_CFG_COMP_LEN Includes:
+ * - Active path selection protocol ID.
+ * - Active path selection metric ID.
+ * - Congestion control mode identifier.
+ * - Channel precedence.
+ * Does not include mesh capabilities, which may vary across nodes in the same
+ * mesh
+ */
+#define MESH_CFG_CMP_LEN 17
+
+/* Default values, timeouts in ms */
+#define MESH_TTL 5
+#define MESH_MAX_RETR 3
+#define MESH_RET_T 100
+#define MESH_CONF_T 100
+#define MESH_HOLD_T 100
+
+#define MESH_PATH_TIMEOUT 5000
+/* Minimum interval between two consecutive PREQs originated by the same
+ * interface
+ */
+#define MESH_PREQ_MIN_INT 10
+#define MESH_DIAM_TRAVERSAL_TIME 50
+/* Paths will be refreshed if they are closer than PATH_REFRESH_TIME to their
+ * expiration
+ */
+#define MESH_PATH_REFRESH_TIME 1000
+#define MESH_MIN_DISCOVERY_TIMEOUT (2 * MESH_DIAM_TRAVERSAL_TIME)
+
+#define MESH_MAX_PREQ_RETRIES 4
+#define MESH_PATH_EXPIRE (600 * HZ)
+
+/* Default maximum number of established plinks per interface */
+#define MESH_MAX_ESTAB_PLINKS 32
+
+/* Default maximum number of plinks per interface */
+#define MESH_MAX_PLINKS 256
+
+/* Maximum number of paths per interface */
+#define MESH_MAX_MPATHS 1024
+
+/* Pending ANA approval */
+#define PLINK_CATEGORY 30
+#define MESH_PATH_SEL_CATEGORY 32
+
+/* Mesh Header Flags */
+#define IEEE80211S_FLAGS_AE 0x3
+
+/* Public interfaces */
+/* Various */
+u8 mesh_id_hash(u8 *mesh_id, int mesh_id_len);
+int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
+int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr,
+ struct ieee80211_sub_if_data *sdata);
+int mesh_rmc_check(u8 *addr, struct ieee80211s_hdr *mesh_hdr,
+ struct net_device *dev);
+bool mesh_matches_local(struct ieee802_11_elems *ie, struct net_device *dev);
+void mesh_ids_set_default(struct ieee80211_if_sta *sta);
+void mesh_mgmt_ies_add(struct sk_buff *skb, struct net_device *dev);
+void mesh_rmc_free(struct net_device *dev);
+int mesh_rmc_init(struct net_device *dev);
+void ieee80211s_init(void);
+void ieee80211s_stop(void);
+void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
+
+/* Mesh paths */
+int mesh_nexthop_lookup(u8 *next_hop, struct sk_buff *skb,
+ struct net_device *dev);
+void mesh_path_start_discovery(struct net_device *dev);
+struct mesh_path *mesh_path_lookup(u8 *dst, struct net_device *dev);
+struct mesh_path *mesh_path_lookup_by_idx(int idx, struct net_device *dev);
+void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop);
+void mesh_path_expire(struct net_device *dev);
+void mesh_path_flush(struct net_device *dev);
+void mesh_rx_path_sel_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
+ size_t len);
+int mesh_path_add(u8 *dst, struct net_device *dev);
+/* Mesh plinks */
+void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
+ bool add);
+bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie,
+ struct net_device *dev);
+void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata);
+void mesh_plink_broken(struct sta_info *sta);
+void mesh_plink_deactivate(struct sta_info *sta);
+int mesh_plink_open(struct sta_info *sta);
+int mesh_plink_close(struct sta_info *sta);
+void mesh_plink_block(struct sta_info *sta);
+void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
+ size_t len, struct ieee80211_rx_status *rx_status);
+
+/* Private interfaces */
+/* Mesh tables */
+struct mesh_table *mesh_table_alloc(int size_order);
+void mesh_table_free(struct mesh_table *tbl, bool free_leafs);
+struct mesh_table *mesh_table_grow(struct mesh_table *tbl);
+u32 mesh_table_hash(u8 *addr, struct net_device *dev, struct mesh_table *tbl);
+/* Mesh paths */
+int mesh_path_error_tx(u8 *dest, __le32 dest_dsn, u8 *ra,
+ struct net_device *dev);
+void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta);
+void mesh_path_flush_pending(struct mesh_path *mpath);
+void mesh_path_tx_pending(struct mesh_path *mpath);
+int mesh_pathtbl_init(void);
+void mesh_pathtbl_unregister(void);
+int mesh_path_del(u8 *addr, struct net_device *dev);
+void mesh_path_timer(unsigned long data);
+void mesh_path_flush_by_nexthop(struct sta_info *sta);
+void mesh_path_discard_frame(struct sk_buff *skb, struct net_device *dev);
+
+#ifdef CONFIG_MAC80211_MESH
+extern int mesh_allocated;
+
+static inline int mesh_plink_free_count(struct ieee80211_sub_if_data *sdata)
+{
+ return sdata->u.sta.mshcfg.dot11MeshMaxPeerLinks -
+ atomic_read(&sdata->u.sta.mshstats.estab_plinks);
+}
+
+static inline bool mesh_plink_availables(struct ieee80211_sub_if_data *sdata)
+{
+ return (min_t(long, mesh_plink_free_count(sdata),
+ MESH_MAX_PLINKS - sdata->local->num_sta)) > 0;
+}
+
+static inline void mesh_path_activate(struct mesh_path *mpath)
+{
+ mpath->flags |= MESH_PATH_ACTIVE | MESH_PATH_RESOLVED;
+}
+
+#define for_each_mesh_entry(x, p, node, i) \
+ for (i = 0; i <= x->hash_mask; i++) \
+ hlist_for_each_entry_rcu(node, p, &x->hash_buckets[i], list)
+
+#else
+#define mesh_allocated 0
+#endif
+
+#define MESH_PREQ(skb) (skb->cb + 30)
+
+#endif /* IEEE80211S_H */
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
new file mode 100644
index 000000000000..02de8f1522a3
--- /dev/null
+++ b/net/mac80211/mesh_hwmp.c
@@ -0,0 +1,855 @@
+/*
+ * Copyright (c) 2008 open80211s Ltd.
+ * Author: Luis Carlos Cobo <luisca@cozybit.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <asm/unaligned.h>
+#include "mesh.h"
+
+#define TEST_FRAME_LEN 8192
+#define MAX_METRIC 0xffffffff
+#define ARITH_SHIFT 8
+
+/* Number of frames buffered per destination for unresolved destinations */
+#define MESH_FRAME_QUEUE_LEN 10
+#define MAX_PREQ_QUEUE_LEN 64
+
+/* Destination only */
+#define MP_F_DO 0x1
+/* Reply and forward */
+#define MP_F_RF 0x2
+
+static inline u32 u32_field_get(u8 *preq_elem, int offset, bool ae)
+{
+ if (ae)
+ offset += 6;
+ return le32_to_cpu(get_unaligned((__le32 *) (preq_elem + offset)));
+}
+
+/* HWMP IE processing macros */
+#define AE_F (1<<6)
+#define AE_F_SET(x) (*x & AE_F)
+#define PREQ_IE_FLAGS(x) (*(x))
+#define PREQ_IE_HOPCOUNT(x) (*(x + 1))
+#define PREQ_IE_TTL(x) (*(x + 2))
+#define PREQ_IE_PREQ_ID(x) u32_field_get(x, 3, 0)
+#define PREQ_IE_ORIG_ADDR(x) (x + 7)
+#define PREQ_IE_ORIG_DSN(x) u32_field_get(x, 13, 0);
+#define PREQ_IE_LIFETIME(x) u32_field_get(x, 17, AE_F_SET(x));
+#define PREQ_IE_METRIC(x) u32_field_get(x, 21, AE_F_SET(x));
+#define PREQ_IE_DST_F(x) (*(AE_F_SET(x) ? x + 32 : x + 26))
+#define PREQ_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 33 : x + 27)
+#define PREQ_IE_DST_DSN(x) u32_field_get(x, 33, AE_F_SET(x));
+
+
+#define PREP_IE_FLAGS(x) PREQ_IE_FLAGS(x)
+#define PREP_IE_HOPCOUNT(x) PREQ_IE_HOPCOUNT(x)
+#define PREP_IE_TTL(x) PREQ_IE_TTL(x)
+#define PREP_IE_ORIG_ADDR(x) (x + 3)
+#define PREP_IE_ORIG_DSN(x) u32_field_get(x, 9, 0);
+#define PREP_IE_LIFETIME(x) u32_field_get(x, 13, AE_F_SET(x));
+#define PREP_IE_METRIC(x) u32_field_get(x, 17, AE_F_SET(x));
+#define PREP_IE_DST_ADDR(x) (AE_F_SET(x) ? x + 27 : x + 21)
+#define PREP_IE_DST_DSN(x) u32_field_get(x, 27, AE_F_SET(x));
+
+#define PERR_IE_DST_ADDR(x) (x + 2)
+#define PERR_IE_DST_DSN(x) u32_field_get(x, 8, 0);
+
+#define TU_TO_EXP_TIME(x) (jiffies + msecs_to_jiffies(x * 1024 / 1000))
+#define MSEC_TO_TU(x) (x*1000/1024)
+#define DSN_GT(x, y) ((long) (y) - (long) (x) < 0)
+#define DSN_LT(x, y) ((long) (x) - (long) (y) < 0)
+
+#define net_traversal_jiffies(s) \
+ msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime)
+#define default_lifetime(s) \
+ MSEC_TO_TU(s->u.sta.mshcfg.dot11MeshHWMPactivePathTimeout)
+#define min_preq_int_jiff(s) \
+ (msecs_to_jiffies(s->u.sta.mshcfg.dot11MeshHWMPpreqMinInterval))
+#define max_preq_retries(s) (s->u.sta.mshcfg.dot11MeshHWMPmaxPREQretries)
+#define disc_timeout_jiff(s) \
+ msecs_to_jiffies(sdata->u.sta.mshcfg.min_discovery_timeout)
+
+enum mpath_frame_type {
+ MPATH_PREQ = 0,
+ MPATH_PREP,
+ MPATH_PERR
+};
+
+static int mesh_path_sel_frame_tx(enum mpath_frame_type action, u8 flags,
+ u8 *orig_addr, __le32 orig_dsn, u8 dst_flags, u8 *dst,
+ __le32 dst_dsn, u8 *da, u8 hop_count, u8 ttl, __le32 lifetime,
+ __le32 metric, __le32 preq_id, struct net_device *dev)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
+ struct ieee80211_mgmt *mgmt;
+ u8 *pos;
+ int ie_len;
+
+ if (!skb)
+ return -1;
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+ /* 25 is the size of the common mgmt part (24) plus the size of the
+ * common action part (1)
+ */
+ mgmt = (struct ieee80211_mgmt *)
+ skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
+ memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_ACTION);
+
+ memcpy(mgmt->da, da, ETH_ALEN);
+ memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+ /* BSSID is left zeroed, wildcard value */
+ mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
+ mgmt->u.action.u.mesh_action.action_code = action;
+
+ switch (action) {
+ case MPATH_PREQ:
+ ie_len = 37;
+ pos = skb_put(skb, 2 + ie_len);
+ *pos++ = WLAN_EID_PREQ;
+ break;
+ case MPATH_PREP:
+ ie_len = 31;
+ pos = skb_put(skb, 2 + ie_len);
+ *pos++ = WLAN_EID_PREP;
+ break;
+ default:
+ kfree(skb);
+ return -ENOTSUPP;
+ break;
+ }
+ *pos++ = ie_len;
+ *pos++ = flags;
+ *pos++ = hop_count;
+ *pos++ = ttl;
+ if (action == MPATH_PREQ) {
+ memcpy(pos, &preq_id, 4);
+ pos += 4;
+ }
+ memcpy(pos, orig_addr, ETH_ALEN);
+ pos += ETH_ALEN;
+ memcpy(pos, &orig_dsn, 4);
+ pos += 4;
+ memcpy(pos, &lifetime, 4);
+ pos += 4;
+ memcpy(pos, &metric, 4);
+ pos += 4;
+ if (action == MPATH_PREQ) {
+ /* destination count */
+ *pos++ = 1;
+ *pos++ = dst_flags;
+ }
+ memcpy(pos, dst, ETH_ALEN);
+ pos += ETH_ALEN;
+ memcpy(pos, &dst_dsn, 4);
+
+ ieee80211_sta_tx(dev, skb, 0);
+ return 0;
+}
+
+/**
+ * mesh_send_path error - Sends a PERR mesh management frame
+ *
+ * @dst: broken destination
+ * @dst_dsn: dsn of the broken destination
+ * @ra: node this frame is addressed to
+ */
+int mesh_path_error_tx(u8 *dst, __le32 dst_dsn, u8 *ra,
+ struct net_device *dev)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
+ struct ieee80211_mgmt *mgmt;
+ u8 *pos;
+ int ie_len;
+
+ if (!skb)
+ return -1;
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+ /* 25 is the size of the common mgmt part (24) plus the size of the
+ * common action part (1)
+ */
+ mgmt = (struct ieee80211_mgmt *)
+ skb_put(skb, 25 + sizeof(mgmt->u.action.u.mesh_action));
+ memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.mesh_action));
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_ACTION);
+
+ memcpy(mgmt->da, ra, ETH_ALEN);
+ memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+ /* BSSID is left zeroed, wildcard value */
+ mgmt->u.action.category = MESH_PATH_SEL_CATEGORY;
+ mgmt->u.action.u.mesh_action.action_code = MPATH_PERR;
+ ie_len = 12;
+ pos = skb_put(skb, 2 + ie_len);
+ *pos++ = WLAN_EID_PERR;
+ *pos++ = ie_len;
+ /* mode flags, reserved */
+ *pos++ = 0;
+ /* number of destinations */
+ *pos++ = 1;
+ memcpy(pos, dst, ETH_ALEN);
+ pos += ETH_ALEN;
+ memcpy(pos, &dst_dsn, 4);
+
+ ieee80211_sta_tx(dev, skb, 0);
+ return 0;
+}
+
+static u32 airtime_link_metric_get(struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ struct ieee80211_supported_band *sband;
+ /* This should be adjusted for each device */
+ int device_constant = 1 << ARITH_SHIFT;
+ int test_frame_len = TEST_FRAME_LEN << ARITH_SHIFT;
+ int s_unit = 1 << ARITH_SHIFT;
+ int rate, err;
+ u32 tx_time, estimated_retx;
+ u64 result;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+ if (sta->fail_avg >= 100)
+ return MAX_METRIC;
+ err = (sta->fail_avg << ARITH_SHIFT) / 100;
+
+ /* bitrate is in units of 100 Kbps, while we need rate in units of
+ * 1Mbps. This will be corrected on tx_time computation.
+ */
+ rate = sband->bitrates[sta->txrate_idx].bitrate;
+ tx_time = (device_constant + 10 * test_frame_len / rate);
+ estimated_retx = ((1 << (2 * ARITH_SHIFT)) / (s_unit - err));
+ result = (tx_time * estimated_retx) >> (2 * ARITH_SHIFT) ;
+ return (u32)result;
+}
+
+/**
+ * hwmp_route_info_get - Update routing info to originator and transmitter
+ *
+ * @dev: local mesh interface
+ * @mgmt: mesh management frame
+ * @hwmp_ie: hwmp information element (PREP or PREQ)
+ *
+ * This function updates the path routing information to the originator and the
+ * transmitter of a HWMP PREQ or PREP fram.
+ *
+ * Returns: metric to frame originator or 0 if the frame should not be further
+ * processed
+ *
+ * Notes: this function is the only place (besides user-provided info) where
+ * path routing information is updated.
+ */
+static u32 hwmp_route_info_get(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt,
+ u8 *hwmp_ie)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct mesh_path *mpath;
+ struct sta_info *sta;
+ bool fresh_info;
+ u8 *orig_addr, *ta;
+ u32 orig_dsn, orig_metric;
+ unsigned long orig_lifetime, exp_time;
+ u32 last_hop_metric, new_metric;
+ bool process = true;
+ u8 action = mgmt->u.action.u.mesh_action.action_code;
+
+ rcu_read_lock();
+ sta = sta_info_get(local, mgmt->sa);
+ if (!sta) {
+ rcu_read_unlock();
+ return 0;
+ }
+
+ last_hop_metric = airtime_link_metric_get(local, sta);
+ /* Update and check originator routing info */
+ fresh_info = true;
+
+ switch (action) {
+ case MPATH_PREQ:
+ orig_addr = PREQ_IE_ORIG_ADDR(hwmp_ie);
+ orig_dsn = PREQ_IE_ORIG_DSN(hwmp_ie);
+ orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
+ orig_metric = PREQ_IE_METRIC(hwmp_ie);
+ break;
+ case MPATH_PREP:
+ /* Originator here refers to the MP that was the destination in
+ * the Path Request. The draft refers to that MP as the
+ * destination address, even though usually it is the origin of
+ * the PREP frame. We divert from the nomenclature in the draft
+ * so that we can easily use a single function to gather path
+ * information from both PREQ and PREP frames.
+ */
+ orig_addr = PREP_IE_ORIG_ADDR(hwmp_ie);
+ orig_dsn = PREP_IE_ORIG_DSN(hwmp_ie);
+ orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
+ orig_metric = PREP_IE_METRIC(hwmp_ie);
+ break;
+ default:
+ rcu_read_unlock();
+ return 0;
+ }
+ new_metric = orig_metric + last_hop_metric;
+ if (new_metric < orig_metric)
+ new_metric = MAX_METRIC;
+ exp_time = TU_TO_EXP_TIME(orig_lifetime);
+
+ if (memcmp(orig_addr, dev->dev_addr, ETH_ALEN) == 0) {
+ /* This MP is the originator, we are not interested in this
+ * frame, except for updating transmitter's path info.
+ */
+ process = false;
+ fresh_info = false;
+ } else {
+ mpath = mesh_path_lookup(orig_addr, dev);
+ if (mpath) {
+ spin_lock_bh(&mpath->state_lock);
+ if (mpath->flags & MESH_PATH_FIXED)
+ fresh_info = false;
+ else if ((mpath->flags & MESH_PATH_ACTIVE) &&
+ (mpath->flags & MESH_PATH_DSN_VALID)) {
+ if (DSN_GT(mpath->dsn, orig_dsn) ||
+ (mpath->dsn == orig_dsn &&
+ action == MPATH_PREQ &&
+ new_metric > mpath->metric)) {
+ process = false;
+ fresh_info = false;
+ }
+ }
+ } else {
+ mesh_path_add(orig_addr, dev);
+ mpath = mesh_path_lookup(orig_addr, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return 0;
+ }
+ spin_lock_bh(&mpath->state_lock);
+ }
+
+ if (fresh_info) {
+ mesh_path_assign_nexthop(mpath, sta);
+ mpath->flags |= MESH_PATH_DSN_VALID;
+ mpath->metric = new_metric;
+ mpath->dsn = orig_dsn;
+ mpath->exp_time = time_after(mpath->exp_time, exp_time)
+ ? mpath->exp_time : exp_time;
+ mesh_path_activate(mpath);
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_tx_pending(mpath);
+ /* draft says preq_id should be saved to, but there does
+ * not seem to be any use for it, skipping by now
+ */
+ } else
+ spin_unlock_bh(&mpath->state_lock);
+ }
+
+ /* Update and check transmitter routing info */
+ ta = mgmt->sa;
+ if (memcmp(orig_addr, ta, ETH_ALEN) == 0)
+ fresh_info = false;
+ else {
+ fresh_info = true;
+
+ mpath = mesh_path_lookup(ta, dev);
+ if (mpath) {
+ spin_lock_bh(&mpath->state_lock);
+ if ((mpath->flags & MESH_PATH_FIXED) ||
+ ((mpath->flags & MESH_PATH_ACTIVE) &&
+ (last_hop_metric > mpath->metric)))
+ fresh_info = false;
+ } else {
+ mesh_path_add(ta, dev);
+ mpath = mesh_path_lookup(ta, dev);
+ if (!mpath) {
+ rcu_read_unlock();
+ return 0;
+ }
+ spin_lock_bh(&mpath->state_lock);
+ }
+
+ if (fresh_info) {
+ mesh_path_assign_nexthop(mpath, sta);
+ mpath->flags &= ~MESH_PATH_DSN_VALID;
+ mpath->metric = last_hop_metric;
+ mpath->exp_time = time_after(mpath->exp_time, exp_time)
+ ? mpath->exp_time : exp_time;
+ mesh_path_activate(mpath);
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_tx_pending(mpath);
+ } else
+ spin_unlock_bh(&mpath->state_lock);
+ }
+
+ rcu_read_unlock();
+
+ return process ? new_metric : 0;
+}
+
+static void hwmp_preq_frame_process(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt,
+ u8 *preq_elem, u32 metric) {
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+ struct mesh_path *mpath;
+ u8 *dst_addr, *orig_addr;
+ u8 dst_flags, ttl;
+ u32 orig_dsn, dst_dsn, lifetime;
+ bool reply = false;
+ bool forward = true;
+
+ /* Update destination DSN, if present */
+ dst_addr = PREQ_IE_DST_ADDR(preq_elem);
+ orig_addr = PREQ_IE_ORIG_ADDR(preq_elem);
+ dst_dsn = PREQ_IE_DST_DSN(preq_elem);
+ orig_dsn = PREQ_IE_ORIG_DSN(preq_elem);
+ dst_flags = PREQ_IE_DST_F(preq_elem);
+
+ if (memcmp(dst_addr, dev->dev_addr, ETH_ALEN) == 0) {
+ forward = false;
+ reply = true;
+ metric = 0;
+ if (time_after(jiffies, ifsta->last_dsn_update +
+ net_traversal_jiffies(sdata)) ||
+ time_before(jiffies, ifsta->last_dsn_update)) {
+ dst_dsn = ++ifsta->dsn;
+ ifsta->last_dsn_update = jiffies;
+ }
+ } else {
+ rcu_read_lock();
+ mpath = mesh_path_lookup(dst_addr, dev);
+ if (mpath) {
+ if ((!(mpath->flags & MESH_PATH_DSN_VALID)) ||
+ DSN_LT(mpath->dsn, dst_dsn)) {
+ mpath->dsn = dst_dsn;
+ mpath->flags &= MESH_PATH_DSN_VALID;
+ } else if ((!(dst_flags & MP_F_DO)) &&
+ (mpath->flags & MESH_PATH_ACTIVE)) {
+ reply = true;
+ metric = mpath->metric;
+ dst_dsn = mpath->dsn;
+ if (dst_flags & MP_F_RF)
+ dst_flags |= MP_F_DO;
+ else
+ forward = false;
+ }
+ }
+ rcu_read_unlock();
+ }
+
+ if (reply) {
+ lifetime = PREQ_IE_LIFETIME(preq_elem);
+ ttl = ifsta->mshcfg.dot11MeshTTL;
+ if (ttl != 0)
+ mesh_path_sel_frame_tx(MPATH_PREP, 0, dst_addr,
+ cpu_to_le32(dst_dsn), 0, orig_addr,
+ cpu_to_le32(orig_dsn), mgmt->sa, 0, ttl,
+ cpu_to_le32(lifetime), cpu_to_le32(metric),
+ 0, dev);
+ else
+ ifsta->mshstats.dropped_frames_ttl++;
+ }
+
+ if (forward) {
+ u32 preq_id;
+ u8 hopcount, flags;
+
+ ttl = PREQ_IE_TTL(preq_elem);
+ lifetime = PREQ_IE_LIFETIME(preq_elem);
+ if (ttl <= 1) {
+ ifsta->mshstats.dropped_frames_ttl++;
+ return;
+ }
+ --ttl;
+ flags = PREQ_IE_FLAGS(preq_elem);
+ preq_id = PREQ_IE_PREQ_ID(preq_elem);
+ hopcount = PREQ_IE_HOPCOUNT(preq_elem) + 1;
+ mesh_path_sel_frame_tx(MPATH_PREQ, flags, orig_addr,
+ cpu_to_le32(orig_dsn), dst_flags, dst_addr,
+ cpu_to_le32(dst_dsn), dev->broadcast,
+ hopcount, ttl, cpu_to_le32(lifetime),
+ cpu_to_le32(metric), cpu_to_le32(preq_id),
+ dev);
+ ifsta->mshstats.fwded_frames++;
+ }
+}
+
+
+static void hwmp_prep_frame_process(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt,
+ u8 *prep_elem, u32 metric)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+ u8 *dst_addr, *orig_addr;
+ u8 ttl, hopcount, flags;
+ u8 next_hop[ETH_ALEN];
+ u32 dst_dsn, orig_dsn, lifetime;
+
+ /* Note that we divert from the draft nomenclature and denominate
+ * destination to what the draft refers to as origininator. So in this
+ * function destnation refers to the final destination of the PREP,
+ * which corresponds with the originator of the PREQ which this PREP
+ * replies
+ */
+ dst_addr = PREP_IE_DST_ADDR(prep_elem);
+ if (memcmp(dst_addr, dev->dev_addr, ETH_ALEN) == 0)
+ /* destination, no forwarding required */
+ return;
+
+ ttl = PREP_IE_TTL(prep_elem);
+ if (ttl <= 1) {
+ sdata->u.sta.mshstats.dropped_frames_ttl++;
+ return;
+ }
+
+ rcu_read_lock();
+ mpath = mesh_path_lookup(dst_addr, dev);
+ if (mpath)
+ spin_lock_bh(&mpath->state_lock);
+ else
+ goto fail;
+ if (!(mpath->flags & MESH_PATH_ACTIVE)) {
+ spin_unlock_bh(&mpath->state_lock);
+ goto fail;
+ }
+ memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
+ spin_unlock_bh(&mpath->state_lock);
+ --ttl;
+ flags = PREP_IE_FLAGS(prep_elem);
+ lifetime = PREP_IE_LIFETIME(prep_elem);
+ hopcount = PREP_IE_HOPCOUNT(prep_elem) + 1;
+ orig_addr = PREP_IE_ORIG_ADDR(prep_elem);
+ dst_dsn = PREP_IE_DST_DSN(prep_elem);
+ orig_dsn = PREP_IE_ORIG_DSN(prep_elem);
+
+ mesh_path_sel_frame_tx(MPATH_PREP, flags, orig_addr,
+ cpu_to_le32(orig_dsn), 0, dst_addr,
+ cpu_to_le32(dst_dsn), mpath->next_hop->addr, hopcount, ttl,
+ cpu_to_le32(lifetime), cpu_to_le32(metric),
+ 0, dev);
+ rcu_read_unlock();
+ sdata->u.sta.mshstats.fwded_frames++;
+ return;
+
+fail:
+ rcu_read_unlock();
+ sdata->u.sta.mshstats.dropped_frames_no_route++;
+ return;
+}
+
+static void hwmp_perr_frame_process(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt, u8 *perr_elem)
+{
+ struct mesh_path *mpath;
+ u8 *ta, *dst_addr;
+ u32 dst_dsn;
+
+ ta = mgmt->sa;
+ dst_addr = PERR_IE_DST_ADDR(perr_elem);
+ dst_dsn = PERR_IE_DST_DSN(perr_elem);
+ rcu_read_lock();
+ mpath = mesh_path_lookup(dst_addr, dev);
+ if (mpath) {
+ spin_lock_bh(&mpath->state_lock);
+ if (mpath->flags & MESH_PATH_ACTIVE &&
+ memcmp(ta, mpath->next_hop->addr, ETH_ALEN) == 0 &&
+ (!(mpath->flags & MESH_PATH_DSN_VALID) ||
+ DSN_GT(dst_dsn, mpath->dsn))) {
+ mpath->flags &= ~MESH_PATH_ACTIVE;
+ mpath->dsn = dst_dsn;
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_error_tx(dst_addr, cpu_to_le32(dst_dsn),
+ dev->broadcast, dev);
+ } else
+ spin_unlock_bh(&mpath->state_lock);
+ }
+ rcu_read_unlock();
+}
+
+
+
+void mesh_rx_path_sel_frame(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt,
+ size_t len)
+{
+ struct ieee802_11_elems elems;
+ size_t baselen;
+ u32 last_hop_metric;
+
+ baselen = (u8 *) mgmt->u.action.u.mesh_action.variable - (u8 *) mgmt;
+ ieee802_11_parse_elems(mgmt->u.action.u.mesh_action.variable,
+ len - baselen, &elems);
+
+ switch (mgmt->u.action.u.mesh_action.action_code) {
+ case MPATH_PREQ:
+ if (!elems.preq || elems.preq_len != 37)
+ /* Right now we support just 1 destination and no AE */
+ return;
+ last_hop_metric = hwmp_route_info_get(dev, mgmt, elems.preq);
+ if (!last_hop_metric)
+ return;
+ hwmp_preq_frame_process(dev, mgmt, elems.preq, last_hop_metric);
+ break;
+ case MPATH_PREP:
+ if (!elems.prep || elems.prep_len != 31)
+ /* Right now we support no AE */
+ return;
+ last_hop_metric = hwmp_route_info_get(dev, mgmt, elems.prep);
+ if (!last_hop_metric)
+ return;
+ hwmp_prep_frame_process(dev, mgmt, elems.prep, last_hop_metric);
+ break;
+ case MPATH_PERR:
+ if (!elems.perr || elems.perr_len != 12)
+ /* Right now we support only one destination per PERR */
+ return;
+ hwmp_perr_frame_process(dev, mgmt, elems.perr);
+ default:
+ return;
+ }
+
+}
+
+/**
+ * mesh_queue_preq - queue a PREQ to a given destination
+ *
+ * @mpath: mesh path to discover
+ * @flags: special attributes of the PREQ to be sent
+ *
+ * Locking: the function must be called from within a rcu read lock block.
+ *
+ */
+static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
+{
+ struct ieee80211_sub_if_data *sdata =
+ IEEE80211_DEV_TO_SUB_IF(mpath->dev);
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+ struct mesh_preq_queue *preq_node;
+
+ preq_node = kmalloc(sizeof(struct mesh_preq_queue), GFP_KERNEL);
+ if (!preq_node) {
+ printk(KERN_DEBUG "Mesh HWMP: could not allocate PREQ node\n");
+ return;
+ }
+
+ spin_lock(&ifsta->mesh_preq_queue_lock);
+ if (ifsta->preq_queue_len == MAX_PREQ_QUEUE_LEN) {
+ spin_unlock(&ifsta->mesh_preq_queue_lock);
+ kfree(preq_node);
+ if (printk_ratelimit())
+ printk(KERN_DEBUG "Mesh HWMP: PREQ node queue full\n");
+ return;
+ }
+
+ memcpy(preq_node->dst, mpath->dst, ETH_ALEN);
+ preq_node->flags = flags;
+
+ list_add_tail(&preq_node->list, &ifsta->preq_queue.list);
+ ++ifsta->preq_queue_len;
+ spin_unlock(&ifsta->mesh_preq_queue_lock);
+
+ if (time_after(jiffies, ifsta->last_preq + min_preq_int_jiff(sdata)))
+ queue_work(sdata->local->hw.workqueue, &ifsta->work);
+
+ else if (time_before(jiffies, ifsta->last_preq)) {
+ /* avoid long wait if did not send preqs for a long time
+ * and jiffies wrapped around
+ */
+ ifsta->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
+ queue_work(sdata->local->hw.workqueue, &ifsta->work);
+ } else
+ mod_timer(&ifsta->mesh_path_timer, ifsta->last_preq +
+ min_preq_int_jiff(sdata));
+}
+
+/**
+ * mesh_path_start_discovery - launch a path discovery from the PREQ queue
+ *
+ * @dev: local mesh interface
+ */
+void mesh_path_start_discovery(struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata =
+ IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+ struct mesh_preq_queue *preq_node;
+ struct mesh_path *mpath;
+ u8 ttl, dst_flags;
+ u32 lifetime;
+
+ spin_lock(&ifsta->mesh_preq_queue_lock);
+ if (!ifsta->preq_queue_len ||
+ time_before(jiffies, ifsta->last_preq +
+ min_preq_int_jiff(sdata))) {
+ spin_unlock(&ifsta->mesh_preq_queue_lock);
+ return;
+ }
+
+ preq_node = list_first_entry(&ifsta->preq_queue.list,
+ struct mesh_preq_queue, list);
+ list_del(&preq_node->list);
+ --ifsta->preq_queue_len;
+ spin_unlock(&ifsta->mesh_preq_queue_lock);
+
+ rcu_read_lock();
+ mpath = mesh_path_lookup(preq_node->dst, dev);
+ if (!mpath)
+ goto enddiscovery;
+
+ spin_lock_bh(&mpath->state_lock);
+ if (preq_node->flags & PREQ_Q_F_START) {
+ if (mpath->flags & MESH_PATH_RESOLVING) {
+ spin_unlock_bh(&mpath->state_lock);
+ goto enddiscovery;
+ } else {
+ mpath->flags &= ~MESH_PATH_RESOLVED;
+ mpath->flags |= MESH_PATH_RESOLVING;
+ mpath->discovery_retries = 0;
+ mpath->discovery_timeout = disc_timeout_jiff(sdata);
+ }
+ } else if (!(mpath->flags & MESH_PATH_RESOLVING) ||
+ mpath->flags & MESH_PATH_RESOLVED) {
+ mpath->flags &= ~MESH_PATH_RESOLVING;
+ spin_unlock_bh(&mpath->state_lock);
+ goto enddiscovery;
+ }
+
+ ifsta->last_preq = jiffies;
+
+ if (time_after(jiffies, ifsta->last_dsn_update +
+ net_traversal_jiffies(sdata)) ||
+ time_before(jiffies, ifsta->last_dsn_update)) {
+ ++ifsta->dsn;
+ sdata->u.sta.last_dsn_update = jiffies;
+ }
+ lifetime = default_lifetime(sdata);
+ ttl = sdata->u.sta.mshcfg.dot11MeshTTL;
+ if (ttl == 0) {
+ sdata->u.sta.mshstats.dropped_frames_ttl++;
+ spin_unlock_bh(&mpath->state_lock);
+ goto enddiscovery;
+ }
+
+ if (preq_node->flags & PREQ_Q_F_REFRESH)
+ dst_flags = MP_F_DO;
+ else
+ dst_flags = MP_F_RF;
+
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_sel_frame_tx(MPATH_PREQ, 0, dev->dev_addr,
+ cpu_to_le32(ifsta->dsn), dst_flags, mpath->dst,
+ cpu_to_le32(mpath->dsn), dev->broadcast, 0,
+ ttl, cpu_to_le32(lifetime), 0,
+ cpu_to_le32(ifsta->preq_id++), dev);
+ mod_timer(&mpath->timer, jiffies + mpath->discovery_timeout);
+
+enddiscovery:
+ rcu_read_unlock();
+ kfree(preq_node);
+}
+
+/**
+ * ieee80211s_lookup_nexthop - put the appropriate next hop on a mesh frame
+ *
+ * @next_hop: output argument for next hop address
+ * @skb: frame to be sent
+ * @dev: network device the frame will be sent through
+ *
+ * Returns: 0 if the next hop was found. Nonzero otherwise. If no next hop is
+ * found, the function will start a path discovery and queue the frame so it is
+ * sent when the path is resolved. This means the caller must not free the skb
+ * in this case.
+ */
+int mesh_nexthop_lookup(u8 *next_hop, struct sk_buff *skb,
+ struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct sk_buff *skb_to_free = NULL;
+ struct mesh_path *mpath;
+ int err = 0;
+
+ rcu_read_lock();
+ mpath = mesh_path_lookup(skb->data, dev);
+
+ if (!mpath) {
+ mesh_path_add(skb->data, dev);
+ mpath = mesh_path_lookup(skb->data, dev);
+ if (!mpath) {
+ dev_kfree_skb(skb);
+ sdata->u.sta.mshstats.dropped_frames_no_route++;
+ err = -ENOSPC;
+ goto endlookup;
+ }
+ }
+
+ if (mpath->flags & MESH_PATH_ACTIVE) {
+ if (time_after(jiffies, mpath->exp_time -
+ msecs_to_jiffies(sdata->u.sta.mshcfg.path_refresh_time))
+ && skb->pkt_type != PACKET_OTHERHOST
+ && !(mpath->flags & MESH_PATH_RESOLVING)
+ && !(mpath->flags & MESH_PATH_FIXED)) {
+ mesh_queue_preq(mpath,
+ PREQ_Q_F_START | PREQ_Q_F_REFRESH);
+ }
+ memcpy(next_hop, mpath->next_hop->addr,
+ ETH_ALEN);
+ } else {
+ if (!(mpath->flags & MESH_PATH_RESOLVING)) {
+ /* Start discovery only if it is not running yet */
+ mesh_queue_preq(mpath, PREQ_Q_F_START);
+ }
+
+ if (skb_queue_len(&mpath->frame_queue) >=
+ MESH_FRAME_QUEUE_LEN) {
+ skb_to_free = mpath->frame_queue.next;
+ skb_unlink(skb_to_free, &mpath->frame_queue);
+ }
+
+ skb_queue_tail(&mpath->frame_queue, skb);
+ if (skb_to_free)
+ mesh_path_discard_frame(skb_to_free, dev);
+ err = -ENOENT;
+ }
+
+endlookup:
+ rcu_read_unlock();
+ return err;
+}
+
+void mesh_path_timer(unsigned long data)
+{
+ struct ieee80211_sub_if_data *sdata;
+ struct mesh_path *mpath;
+
+ rcu_read_lock();
+ mpath = (struct mesh_path *) data;
+ mpath = rcu_dereference(mpath);
+ if (!mpath)
+ goto endmpathtimer;
+ spin_lock_bh(&mpath->state_lock);
+ sdata = IEEE80211_DEV_TO_SUB_IF(mpath->dev);
+ if (mpath->flags & MESH_PATH_RESOLVED ||
+ (!(mpath->flags & MESH_PATH_RESOLVING)))
+ mpath->flags &= ~(MESH_PATH_RESOLVING | MESH_PATH_RESOLVED);
+ else if (mpath->discovery_retries < max_preq_retries(sdata)) {
+ ++mpath->discovery_retries;
+ mpath->discovery_timeout *= 2;
+ mesh_queue_preq(mpath, 0);
+ } else {
+ mpath->flags = 0;
+ mpath->exp_time = jiffies;
+ mesh_path_flush_pending(mpath);
+ }
+
+ spin_unlock_bh(&mpath->state_lock);
+endmpathtimer:
+ rcu_read_unlock();
+}
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 @@
+/*
+ * Copyright (c) 2008 open80211s Ltd.
+ * Author: Luis Carlos Cobo <luisca@cozybit.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/etherdevice.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/random.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+#include <net/mac80211.h>
+#include "ieee80211_i.h"
+#include "mesh.h"
+
+/* There will be initially 2^INIT_PATHS_SIZE_ORDER buckets */
+#define INIT_PATHS_SIZE_ORDER 2
+
+/* Keep the mean chain length below this constant */
+#define MEAN_CHAIN_LEN 2
+
+#define MPATH_EXPIRED(mpath) ((mpath->flags & MESH_PATH_ACTIVE) && \
+ time_after(jiffies, mpath->exp_time) && \
+ !(mpath->flags & MESH_PATH_FIXED))
+
+struct mpath_node {
+ struct hlist_node list;
+ struct rcu_head rcu;
+ /* This indirection allows two different tables to point to the same
+ * mesh_path structure, useful when resizing
+ */
+ struct mesh_path *mpath;
+};
+
+static struct mesh_table *mesh_paths;
+
+/* This lock will have the grow table function as writer and add / delete nodes
+ * as readers. When reading the table (i.e. doing lookups) we are well protected
+ * by RCU
+ */
+static DEFINE_RWLOCK(pathtbl_resize_lock);
+
+/**
+ *
+ * mesh_path_assign_nexthop - update mesh path next hop
+ *
+ * @mpath: mesh path to update
+ * @sta: next hop to assign
+ *
+ * Locking: mpath->state_lock must be held when calling this function
+ */
+void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
+{
+ rcu_assign_pointer(mpath->next_hop, sta);
+}
+
+
+/**
+ * mesh_path_lookup - look up a path in the mesh path table
+ * @dst: hardware address (ETH_ALEN length) of destination
+ * @dev: local interface
+ *
+ * Returns: pointer to the mesh path structure, or NULL if not found
+ *
+ * Locking: must be called within a read rcu section.
+ */
+struct mesh_path *mesh_path_lookup(u8 *dst, struct net_device *dev)
+{
+ struct mesh_path *mpath;
+ struct hlist_node *n;
+ struct hlist_head *bucket;
+ struct mesh_table *tbl;
+ struct mpath_node *node;
+
+ tbl = rcu_dereference(mesh_paths);
+
+ bucket = &tbl->hash_buckets[mesh_table_hash(dst, dev, tbl)];
+ hlist_for_each_entry_rcu(node, n, bucket, list) {
+ mpath = node->mpath;
+ if (mpath->dev == dev &&
+ memcmp(dst, mpath->dst, ETH_ALEN) == 0) {
+ if (MPATH_EXPIRED(mpath)) {
+ spin_lock_bh(&mpath->state_lock);
+ if (MPATH_EXPIRED(mpath))
+ mpath->flags &= ~MESH_PATH_ACTIVE;
+ spin_unlock_bh(&mpath->state_lock);
+ }
+ return mpath;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * mesh_path_lookup_by_idx - look up a path in the mesh path table by its index
+ * @idx: index
+ * @dev: local interface, or NULL for all entries
+ *
+ * Returns: pointer to the mesh path structure, or NULL if not found.
+ *
+ * Locking: must be called within a read rcu section.
+ */
+struct mesh_path *mesh_path_lookup_by_idx(int idx, struct net_device *dev)
+{
+ struct mpath_node *node;
+ struct hlist_node *p;
+ int i;
+ int j = 0;
+
+ for_each_mesh_entry(mesh_paths, p, node, i) {
+ if (dev && node->mpath->dev != dev)
+ continue;
+ if (j++ == idx) {
+ if (MPATH_EXPIRED(node->mpath)) {
+ spin_lock_bh(&node->mpath->state_lock);
+ if (MPATH_EXPIRED(node->mpath))
+ node->mpath->flags &= ~MESH_PATH_ACTIVE;
+ spin_unlock_bh(&node->mpath->state_lock);
+ }
+ return node->mpath;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * mesh_path_add - allocate and add a new path to the mesh path table
+ * @addr: destination address of the path (ETH_ALEN length)
+ * @dev: local interface
+ *
+ * Returns: 0 on sucess
+ *
+ * State: the initial state of the new path is set to 0
+ */
+int mesh_path_add(u8 *dst, struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath, *new_mpath;
+ struct mpath_node *node, *new_node;
+ struct hlist_head *bucket;
+ struct hlist_node *n;
+ int grow = 0;
+ int err = 0;
+ u32 hash_idx;
+
+ if (memcmp(dst, dev->dev_addr, ETH_ALEN) == 0)
+ /* never add ourselves as neighbours */
+ return -ENOTSUPP;
+
+ if (is_multicast_ether_addr(dst))
+ return -ENOTSUPP;
+
+ if (atomic_add_unless(&sdata->u.sta.mpaths, 1, MESH_MAX_MPATHS) == 0)
+ return -ENOSPC;
+
+ read_lock(&pathtbl_resize_lock);
+
+ new_mpath = kzalloc(sizeof(struct mesh_path), GFP_KERNEL);
+ if (!new_mpath) {
+ atomic_dec(&sdata->u.sta.mpaths);
+ err = -ENOMEM;
+ goto endadd2;
+ }
+ memcpy(new_mpath->dst, dst, ETH_ALEN);
+ new_mpath->dev = dev;
+ new_mpath->flags = 0;
+ skb_queue_head_init(&new_mpath->frame_queue);
+ new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
+ new_node->mpath = new_mpath;
+ new_mpath->timer.data = (unsigned long) new_mpath;
+ new_mpath->timer.function = mesh_path_timer;
+ new_mpath->exp_time = jiffies;
+ spin_lock_init(&new_mpath->state_lock);
+ init_timer(&new_mpath->timer);
+
+ hash_idx = mesh_table_hash(dst, dev, mesh_paths);
+ bucket = &mesh_paths->hash_buckets[hash_idx];
+
+ spin_lock(&mesh_paths->hashwlock[hash_idx]);
+
+ hlist_for_each_entry(node, n, bucket, list) {
+ mpath = node->mpath;
+ if (mpath->dev == dev && memcmp(dst, mpath->dst, ETH_ALEN)
+ == 0) {
+ err = -EEXIST;
+ atomic_dec(&sdata->u.sta.mpaths);
+ kfree(new_node);
+ kfree(new_mpath);
+ goto endadd;
+ }
+ }
+
+ hlist_add_head_rcu(&new_node->list, bucket);
+ if (atomic_inc_return(&mesh_paths->entries) >=
+ mesh_paths->mean_chain_len * (mesh_paths->hash_mask + 1))
+ grow = 1;
+
+endadd:
+ spin_unlock(&mesh_paths->hashwlock[hash_idx]);
+endadd2:
+ read_unlock(&pathtbl_resize_lock);
+ if (!err && grow) {
+ struct mesh_table *oldtbl, *newtbl;
+
+ write_lock(&pathtbl_resize_lock);
+ oldtbl = mesh_paths;
+ newtbl = mesh_table_grow(mesh_paths);
+ if (!newtbl) {
+ write_unlock(&pathtbl_resize_lock);
+ return -ENOMEM;
+ }
+ rcu_assign_pointer(mesh_paths, newtbl);
+ synchronize_rcu();
+ mesh_table_free(oldtbl, false);
+ write_unlock(&pathtbl_resize_lock);
+ }
+ return err;
+}
+
+
+/**
+ * mesh_plink_broken - deactivates paths and sends perr when a link breaks
+ *
+ * @sta: broken peer link
+ *
+ * This function must be called from the rate control algorithm if enough
+ * delivery errors suggest that a peer link is no longer usable.
+ */
+void mesh_plink_broken(struct sta_info *sta)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node;
+ struct hlist_node *p;
+ struct net_device *dev = sta->sdata->dev;
+ int i;
+
+ rcu_read_lock();
+ for_each_mesh_entry(mesh_paths, p, node, i) {
+ mpath = node->mpath;
+ spin_lock_bh(&mpath->state_lock);
+ if (mpath->next_hop == sta &&
+ mpath->flags & MESH_PATH_ACTIVE &&
+ !(mpath->flags & MESH_PATH_FIXED)) {
+ mpath->flags &= ~MESH_PATH_ACTIVE;
+ ++mpath->dsn;
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_error_tx(mpath->dst,
+ cpu_to_le32(mpath->dsn),
+ dev->broadcast, dev);
+ } else
+ spin_unlock_bh(&mpath->state_lock);
+ }
+ rcu_read_unlock();
+}
+EXPORT_SYMBOL(mesh_plink_broken);
+
+/**
+ * mesh_path_flush_by_nexthop - Deletes mesh paths if their next hop matches
+ *
+ * @sta - mesh peer to match
+ *
+ * RCU notes: this function is called when a mesh plink transitions from
+ * PLINK_ESTAB to any other state, since PLINK_ESTAB state is the only one that
+ * allows path creation. This will happen before the sta can be freed (because
+ * sta_info_destroy() calls this) so any reader in a rcu read block will be
+ * protected against the plink disappearing.
+ */
+void mesh_path_flush_by_nexthop(struct sta_info *sta)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node;
+ struct hlist_node *p;
+ int i;
+
+ for_each_mesh_entry(mesh_paths, p, node, i) {
+ mpath = node->mpath;
+ if (mpath->next_hop == sta)
+ mesh_path_del(mpath->dst, mpath->dev);
+ }
+}
+
+void mesh_path_flush(struct net_device *dev)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node;
+ struct hlist_node *p;
+ int i;
+
+ for_each_mesh_entry(mesh_paths, p, node, i) {
+ mpath = node->mpath;
+ if (mpath->dev == dev)
+ mesh_path_del(mpath->dst, mpath->dev);
+ }
+}
+
+static void mesh_path_node_reclaim(struct rcu_head *rp)
+{
+ struct mpath_node *node = container_of(rp, struct mpath_node, rcu);
+ struct ieee80211_sub_if_data *sdata =
+ IEEE80211_DEV_TO_SUB_IF(node->mpath->dev);
+
+ del_timer_sync(&node->mpath->timer);
+ atomic_dec(&sdata->u.sta.mpaths);
+ kfree(node->mpath);
+ kfree(node);
+}
+
+/**
+ * mesh_path_del - delete a mesh path from the table
+ *
+ * @addr: dst address (ETH_ALEN length)
+ * @dev: local interface
+ *
+ * Returns: 0 if succesful
+ */
+int mesh_path_del(u8 *addr, struct net_device *dev)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node;
+ struct hlist_head *bucket;
+ struct hlist_node *n;
+ int hash_idx;
+ int err = 0;
+
+ read_lock(&pathtbl_resize_lock);
+ hash_idx = mesh_table_hash(addr, dev, mesh_paths);
+ bucket = &mesh_paths->hash_buckets[hash_idx];
+
+ spin_lock(&mesh_paths->hashwlock[hash_idx]);
+ hlist_for_each_entry(node, n, bucket, list) {
+ mpath = node->mpath;
+ if (mpath->dev == dev &&
+ memcmp(addr, mpath->dst, ETH_ALEN) == 0) {
+ spin_lock_bh(&mpath->state_lock);
+ mpath->flags |= MESH_PATH_RESOLVING;
+ hlist_del_rcu(&node->list);
+ call_rcu(&node->rcu, mesh_path_node_reclaim);
+ atomic_dec(&mesh_paths->entries);
+ spin_unlock_bh(&mpath->state_lock);
+ goto enddel;
+ }
+ }
+
+ err = -ENXIO;
+enddel:
+ spin_unlock(&mesh_paths->hashwlock[hash_idx]);
+ read_unlock(&pathtbl_resize_lock);
+ return err;
+}
+
+/**
+ * mesh_path_tx_pending - sends pending frames in a mesh path queue
+ *
+ * @mpath: mesh path to activate
+ *
+ * Locking: the state_lock of the mpath structure must NOT be held when calling
+ * this function.
+ */
+void mesh_path_tx_pending(struct mesh_path *mpath)
+{
+ struct sk_buff *skb;
+
+ while ((skb = skb_dequeue(&mpath->frame_queue)) &&
+ (mpath->flags & MESH_PATH_ACTIVE))
+ dev_queue_xmit(skb);
+}
+
+/**
+ * mesh_path_discard_frame - discard a frame whose path could not be resolved
+ *
+ * @skb: frame to discard
+ * @dev: network device the frame was to be sent through
+ *
+ * If the frame was beign forwarded from another MP, a PERR frame will be sent
+ * to the precursor.
+ *
+ * Locking: the function must me called within a rcu_read_lock region
+ */
+void mesh_path_discard_frame(struct sk_buff *skb, struct net_device *dev)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct mesh_path *mpath;
+ u32 dsn = 0;
+
+ if (skb->pkt_type == PACKET_OTHERHOST) {
+ struct ieee80211s_hdr *prev_meshhdr;
+ int mshhdrlen;
+ u8 *ra, *da;
+
+ prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb);
+ mshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr);
+ da = skb->data;
+ ra = MESH_PREQ(skb);
+ mpath = mesh_path_lookup(da, dev);
+ if (mpath)
+ dsn = ++mpath->dsn;
+ mesh_path_error_tx(skb->data, cpu_to_le32(dsn), ra, dev);
+ }
+
+ kfree_skb(skb);
+ sdata->u.sta.mshstats.dropped_frames_no_route++;
+}
+
+/**
+ * mesh_path_flush_pending - free the pending queue of a mesh path
+ *
+ * @mpath: mesh path whose queue has to be freed
+ *
+ * Locking: the function must me called withing a rcu_read_lock region
+ */
+void mesh_path_flush_pending(struct mesh_path *mpath)
+{
+ struct ieee80211_sub_if_data *sdata;
+ struct sk_buff *skb;
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(mpath->dev);
+
+ while ((skb = skb_dequeue(&mpath->frame_queue)) &&
+ (mpath->flags & MESH_PATH_ACTIVE))
+ mesh_path_discard_frame(skb, mpath->dev);
+}
+
+/**
+ * mesh_path_fix_nexthop - force a specific next hop for a mesh path
+ *
+ * @mpath: the mesh path to modify
+ * @next_hop: the next hop to force
+ *
+ * Locking: this function must be called holding mpath->state_lock
+ */
+void mesh_path_fix_nexthop(struct mesh_path *mpath, struct sta_info *next_hop)
+{
+ spin_lock_bh(&mpath->state_lock);
+ mesh_path_assign_nexthop(mpath, next_hop);
+ mpath->dsn = 0xffff;
+ mpath->metric = 0;
+ mpath->hop_count = 0;
+ mpath->exp_time = 0;
+ mpath->flags |= MESH_PATH_FIXED;
+ mesh_path_activate(mpath);
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_tx_pending(mpath);
+}
+
+static void mesh_path_node_free(struct hlist_node *p, bool free_leafs)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node = hlist_entry(p, struct mpath_node, list);
+ mpath = node->mpath;
+ hlist_del_rcu(p);
+ synchronize_rcu();
+ if (free_leafs)
+ kfree(mpath);
+ kfree(node);
+}
+
+static void mesh_path_node_copy(struct hlist_node *p, struct mesh_table *newtbl)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node, *new_node;
+ u32 hash_idx;
+
+ node = hlist_entry(p, struct mpath_node, list);
+ mpath = node->mpath;
+ new_node = kmalloc(sizeof(struct mpath_node), GFP_KERNEL);
+ new_node->mpath = mpath;
+ hash_idx = mesh_table_hash(mpath->dst, mpath->dev, newtbl);
+ hlist_add_head(&new_node->list,
+ &newtbl->hash_buckets[hash_idx]);
+}
+
+int mesh_pathtbl_init(void)
+{
+ mesh_paths = mesh_table_alloc(INIT_PATHS_SIZE_ORDER);
+ mesh_paths->free_node = &mesh_path_node_free;
+ mesh_paths->copy_node = &mesh_path_node_copy;
+ mesh_paths->mean_chain_len = MEAN_CHAIN_LEN;
+ if (!mesh_paths)
+ return -ENOMEM;
+ return 0;
+}
+
+void mesh_path_expire(struct net_device *dev)
+{
+ struct mesh_path *mpath;
+ struct mpath_node *node;
+ struct hlist_node *p;
+ int i;
+
+ read_lock(&pathtbl_resize_lock);
+ for_each_mesh_entry(mesh_paths, p, node, i) {
+ if (node->mpath->dev != dev)
+ continue;
+ mpath = node->mpath;
+ spin_lock_bh(&mpath->state_lock);
+ if ((!(mpath->flags & MESH_PATH_RESOLVING)) &&
+ (!(mpath->flags & MESH_PATH_FIXED)) &&
+ time_after(jiffies,
+ mpath->exp_time + MESH_PATH_EXPIRE)) {
+ spin_unlock_bh(&mpath->state_lock);
+ mesh_path_del(mpath->dst, mpath->dev);
+ } else
+ spin_unlock_bh(&mpath->state_lock);
+ }
+ read_unlock(&pathtbl_resize_lock);
+}
+
+void mesh_pathtbl_unregister(void)
+{
+ mesh_table_free(mesh_paths, true);
+}
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
new file mode 100644
index 000000000000..37f0c2b94ae7
--- /dev/null
+++ b/net/mac80211/mesh_plink.c
@@ -0,0 +1,762 @@
+/*
+ * Copyright (c) 2008 open80211s Ltd.
+ * Author: Luis Carlos Cobo <luisca@cozybit.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/random.h>
+#include "ieee80211_i.h"
+#include "rate.h"
+#include "mesh.h"
+
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args)
+#else
+#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
+#endif
+
+#define PLINK_GET_FRAME_SUBTYPE(p) (p)
+#define PLINK_GET_LLID(p) (p + 1)
+#define PLINK_GET_PLID(p) (p + 3)
+
+#define mod_plink_timer(s, t) (mod_timer(&s->plink_timer, \
+ jiffies + HZ * t / 1000))
+
+/* Peer link cancel reasons, all subject to ANA approval */
+#define MESH_LINK_CANCELLED 2
+#define MESH_MAX_NEIGHBORS 3
+#define MESH_CAPABILITY_POLICY_VIOLATION 4
+#define MESH_CLOSE_RCVD 5
+#define MESH_MAX_RETRIES 6
+#define MESH_CONFIRM_TIMEOUT 7
+#define MESH_SECURITY_ROLE_NEGOTIATION_DIFFERS 8
+#define MESH_SECURITY_AUTHENTICATION_IMPOSSIBLE 9
+#define MESH_SECURITY_FAILED_VERIFICATION 10
+
+#define dot11MeshMaxRetries(s) (s->u.sta.mshcfg.dot11MeshMaxRetries)
+#define dot11MeshRetryTimeout(s) (s->u.sta.mshcfg.dot11MeshRetryTimeout)
+#define dot11MeshConfirmTimeout(s) (s->u.sta.mshcfg.dot11MeshConfirmTimeout)
+#define dot11MeshHoldingTimeout(s) (s->u.sta.mshcfg.dot11MeshHoldingTimeout)
+#define dot11MeshMaxPeerLinks(s) (s->u.sta.mshcfg.dot11MeshMaxPeerLinks)
+
+enum plink_frame_type {
+ PLINK_OPEN = 0,
+ PLINK_CONFIRM,
+ PLINK_CLOSE
+};
+
+enum plink_event {
+ PLINK_UNDEFINED,
+ OPN_ACPT,
+ OPN_RJCT,
+ OPN_IGNR,
+ CNF_ACPT,
+ CNF_RJCT,
+ CNF_IGNR,
+ CLS_ACPT,
+ CLS_IGNR
+};
+
+static inline
+void mesh_plink_inc_estab_count(struct ieee80211_sub_if_data *sdata)
+{
+ atomic_inc(&sdata->u.sta.mshstats.estab_plinks);
+ mesh_accept_plinks_update(sdata);
+}
+
+static inline
+void mesh_plink_dec_estab_count(struct ieee80211_sub_if_data *sdata)
+{
+ atomic_dec(&sdata->u.sta.mshstats.estab_plinks);
+ mesh_accept_plinks_update(sdata);
+}
+
+/**
+ * mesh_plink_fsm_restart - restart a mesh peer link finite state machine
+ *
+ * @sta: mes peer link to restart
+ *
+ * Locking: this function must be called holding sta->plink_lock
+ */
+static inline void mesh_plink_fsm_restart(struct sta_info *sta)
+{
+ sta->plink_state = PLINK_LISTEN;
+ sta->llid = sta->plid = sta->reason = 0;
+ sta->plink_retries = 0;
+}
+
+/*
+ * NOTE: This is just an alias for sta_info_alloc(), see notes
+ * on it in the lifecycle management section!
+ */
+static struct sta_info *mesh_plink_alloc(struct ieee80211_sub_if_data *sdata,
+ u8 *hw_addr, u64 rates)
+{
+ struct ieee80211_local *local = sdata->local;
+ struct sta_info *sta;
+
+ if (local->num_sta >= MESH_MAX_PLINKS)
+ return NULL;
+
+ sta = sta_info_alloc(sdata, hw_addr, GFP_ATOMIC);
+ if (!sta)
+ return NULL;
+
+ sta->flags |= WLAN_STA_AUTHORIZED;
+ sta->supp_rates[local->hw.conf.channel->band] = rates;
+
+ return sta;
+}
+
+/**
+ * mesh_plink_deactivate - deactivate mesh peer link
+ *
+ * @sta: mesh peer link to deactivate
+ *
+ * All mesh paths with this peer as next hop will be flushed
+ *
+ * Locking: the caller must hold sta->plink_lock
+ */
+static void __mesh_plink_deactivate(struct sta_info *sta)
+{
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+
+ if (sta->plink_state == PLINK_ESTAB)
+ mesh_plink_dec_estab_count(sdata);
+ sta->plink_state = PLINK_BLOCKED;
+ mesh_path_flush_by_nexthop(sta);
+}
+
+/**
+ * __mesh_plink_deactivate - deactivate mesh peer link
+ *
+ * @sta: mesh peer link to deactivate
+ *
+ * All mesh paths with this peer as next hop will be flushed
+ */
+void mesh_plink_deactivate(struct sta_info *sta)
+{
+ spin_lock_bh(&sta->plink_lock);
+ __mesh_plink_deactivate(sta);
+ spin_unlock_bh(&sta->plink_lock);
+}
+
+static int mesh_plink_frame_tx(struct net_device *dev,
+ enum plink_frame_type action, u8 *da, __le16 llid, __le16 plid,
+ __le16 reason) {
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct sk_buff *skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
+ struct ieee80211_mgmt *mgmt;
+ bool include_plid = false;
+ u8 *pos;
+ int ie_len;
+
+ if (!skb)
+ return -1;
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+ /* 25 is the size of the common mgmt part (24) plus the size of the
+ * common action part (1)
+ */
+ mgmt = (struct ieee80211_mgmt *)
+ skb_put(skb, 25 + sizeof(mgmt->u.action.u.plink_action));
+ memset(mgmt, 0, 25 + sizeof(mgmt->u.action.u.plink_action));
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_ACTION);
+ memcpy(mgmt->da, da, ETH_ALEN);
+ memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+ /* BSSID is left zeroed, wildcard value */
+ mgmt->u.action.category = PLINK_CATEGORY;
+ mgmt->u.action.u.plink_action.action_code = action;
+
+ if (action == PLINK_CLOSE)
+ mgmt->u.action.u.plink_action.aux = reason;
+ else {
+ mgmt->u.action.u.plink_action.aux = cpu_to_le16(0x0);
+ if (action == PLINK_CONFIRM) {
+ pos = skb_put(skb, 4);
+ /* two-byte status code followed by two-byte AID */
+ memset(pos, 0, 4);
+ }
+ mesh_mgmt_ies_add(skb, dev);
+ }
+
+ /* Add Peer Link Management element */
+ switch (action) {
+ case PLINK_OPEN:
+ ie_len = 3;
+ break;
+ case PLINK_CONFIRM:
+ ie_len = 5;
+ include_plid = true;
+ break;
+ case PLINK_CLOSE:
+ default:
+ if (!plid)
+ ie_len = 5;
+ else {
+ ie_len = 7;
+ include_plid = true;
+ }
+ break;
+ }
+
+ pos = skb_put(skb, 2 + ie_len);
+ *pos++ = WLAN_EID_PEER_LINK;
+ *pos++ = ie_len;
+ *pos++ = action;
+ memcpy(pos, &llid, 2);
+ if (include_plid) {
+ pos += 2;
+ memcpy(pos, &plid, 2);
+ }
+ if (action == PLINK_CLOSE) {
+ pos += 2;
+ memcpy(pos, &reason, 2);
+ }
+
+ ieee80211_sta_tx(dev, skb, 0);
+ return 0;
+}
+
+void mesh_neighbour_update(u8 *hw_addr, u64 rates, struct net_device *dev,
+ bool peer_accepting_plinks)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct sta_info *sta;
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, hw_addr);
+ if (!sta) {
+ sta = mesh_plink_alloc(sdata, hw_addr, rates);
+ if (!sta) {
+ rcu_read_unlock();
+ return;
+ }
+ if (sta_info_insert(sta)) {
+ rcu_read_unlock();
+ return;
+ }
+ }
+
+ sta->last_rx = jiffies;
+ sta->supp_rates[local->hw.conf.channel->band] = rates;
+ if (peer_accepting_plinks && sta->plink_state == PLINK_LISTEN &&
+ sdata->u.sta.accepting_plinks &&
+ sdata->u.sta.mshcfg.auto_open_plinks)
+ mesh_plink_open(sta);
+
+ rcu_read_unlock();
+}
+
+static void mesh_plink_timer(unsigned long data)
+{
+ struct sta_info *sta;
+ __le16 llid, plid, reason;
+ struct net_device *dev = NULL;
+ struct ieee80211_sub_if_data *sdata;
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+ DECLARE_MAC_BUF(mac);
+#endif
+
+ /*
+ * This STA is valid because sta_info_destroy() will
+ * del_timer_sync() this timer after having made sure
+ * it cannot be readded (by deleting the plink.)
+ */
+ sta = (struct sta_info *) data;
+
+ spin_lock_bh(&sta->plink_lock);
+ if (sta->ignore_plink_timer) {
+ sta->ignore_plink_timer = false;
+ spin_unlock_bh(&sta->plink_lock);
+ return;
+ }
+ mpl_dbg("Mesh plink timer for %s fired on state %d\n",
+ print_mac(mac, sta->addr), sta->plink_state);
+ reason = 0;
+ llid = sta->llid;
+ plid = sta->plid;
+ sdata = sta->sdata;
+ dev = sdata->dev;
+
+ switch (sta->plink_state) {
+ case PLINK_OPN_RCVD:
+ case PLINK_OPN_SNT:
+ /* retry timer */
+ if (sta->plink_retries < dot11MeshMaxRetries(sdata)) {
+ u32 rand;
+ mpl_dbg("Mesh plink for %s (retry, timeout): %d %d\n",
+ print_mac(mac, sta->addr),
+ sta->plink_retries, sta->plink_timeout);
+ get_random_bytes(&rand, sizeof(u32));
+ sta->plink_timeout = sta->plink_timeout +
+ rand % sta->plink_timeout;
+ ++sta->plink_retries;
+ mod_plink_timer(sta, sta->plink_timeout);
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
+ 0, 0);
+ break;
+ }
+ reason = cpu_to_le16(MESH_MAX_RETRIES);
+ /* fall through on else */
+ case PLINK_CNF_RCVD:
+ /* confirm timer */
+ if (!reason)
+ reason = cpu_to_le16(MESH_CONFIRM_TIMEOUT);
+ sta->plink_state = PLINK_HOLDING;
+ mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid, plid,
+ reason);
+ break;
+ case PLINK_HOLDING:
+ /* holding timer */
+ del_timer(&sta->plink_timer);
+ mesh_plink_fsm_restart(sta);
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+}
+
+static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout)
+{
+ sta->plink_timer.expires = jiffies + (HZ * timeout / 1000);
+ sta->plink_timer.data = (unsigned long) sta;
+ sta->plink_timer.function = mesh_plink_timer;
+ sta->plink_timeout = timeout;
+ add_timer(&sta->plink_timer);
+}
+
+int mesh_plink_open(struct sta_info *sta)
+{
+ __le16 llid;
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+ DECLARE_MAC_BUF(mac);
+#endif
+
+ spin_lock_bh(&sta->plink_lock);
+ get_random_bytes(&llid, 2);
+ sta->llid = llid;
+ if (sta->plink_state != PLINK_LISTEN) {
+ spin_unlock_bh(&sta->plink_lock);
+ return -EBUSY;
+ }
+ sta->plink_state = PLINK_OPN_SNT;
+ mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
+ spin_unlock_bh(&sta->plink_lock);
+ mpl_dbg("Mesh plink: starting establishment with %s\n",
+ print_mac(mac, sta->addr));
+
+ return mesh_plink_frame_tx(sdata->dev, PLINK_OPEN,
+ sta->addr, llid, 0, 0);
+}
+
+void mesh_plink_block(struct sta_info *sta)
+{
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+ DECLARE_MAC_BUF(mac);
+#endif
+
+ spin_lock_bh(&sta->plink_lock);
+ __mesh_plink_deactivate(sta);
+ sta->plink_state = PLINK_BLOCKED;
+ spin_unlock_bh(&sta->plink_lock);
+}
+
+int mesh_plink_close(struct sta_info *sta)
+{
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+ __le16 llid, plid, reason;
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+ DECLARE_MAC_BUF(mac);
+#endif
+
+ mpl_dbg("Mesh plink: closing link with %s\n",
+ print_mac(mac, sta->addr));
+ spin_lock_bh(&sta->plink_lock);
+ sta->reason = cpu_to_le16(MESH_LINK_CANCELLED);
+ reason = sta->reason;
+
+ if (sta->plink_state == PLINK_LISTEN ||
+ sta->plink_state == PLINK_BLOCKED) {
+ mesh_plink_fsm_restart(sta);
+ spin_unlock_bh(&sta->plink_lock);
+ return 0;
+ } else if (sta->plink_state == PLINK_ESTAB) {
+ __mesh_plink_deactivate(sta);
+ /* The timer should not be running */
+ mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
+ } else if (!mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata)))
+ sta->ignore_plink_timer = true;
+
+ sta->plink_state = PLINK_HOLDING;
+ llid = sta->llid;
+ plid = sta->plid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(sta->sdata->dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ return 0;
+}
+
+void mesh_rx_plink_frame(struct net_device *dev, struct ieee80211_mgmt *mgmt,
+ size_t len, struct ieee80211_rx_status *rx_status)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = sdata->local;
+ struct ieee802_11_elems elems;
+ struct sta_info *sta;
+ enum plink_event event;
+ enum plink_frame_type ftype;
+ size_t baselen;
+ u8 ie_len;
+ u8 *baseaddr;
+ __le16 plid, llid, reason;
+#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
+ DECLARE_MAC_BUF(mac);
+#endif
+
+ if (is_multicast_ether_addr(mgmt->da)) {
+ mpl_dbg("Mesh plink: ignore frame from multicast address");
+ return;
+ }
+
+ baseaddr = mgmt->u.action.u.plink_action.variable;
+ baselen = (u8 *) mgmt->u.action.u.plink_action.variable - (u8 *) mgmt;
+ if (mgmt->u.action.u.plink_action.action_code == PLINK_CONFIRM) {
+ baseaddr += 4;
+ baselen -= 4;
+ }
+ ieee802_11_parse_elems(baseaddr, len - baselen, &elems);
+ if (!elems.peer_link) {
+ mpl_dbg("Mesh plink: missing necessary peer link ie\n");
+ return;
+ }
+
+ ftype = *((u8 *)PLINK_GET_FRAME_SUBTYPE(elems.peer_link));
+ ie_len = elems.peer_link_len;
+ if ((ftype == PLINK_OPEN && ie_len != 3) ||
+ (ftype == PLINK_CONFIRM && ie_len != 5) ||
+ (ftype == PLINK_CLOSE && ie_len != 5 && ie_len != 7)) {
+ mpl_dbg("Mesh plink: incorrect plink ie length\n");
+ return;
+ }
+
+ if (ftype != PLINK_CLOSE && (!elems.mesh_id || !elems.mesh_config)) {
+ mpl_dbg("Mesh plink: missing necessary ie\n");
+ return;
+ }
+ /* Note the lines below are correct, the llid in the frame is the plid
+ * from the point of view of this host.
+ */
+ memcpy(&plid, PLINK_GET_LLID(elems.peer_link), 2);
+ if (ftype == PLINK_CONFIRM || (ftype == PLINK_CLOSE && ie_len == 7))
+ memcpy(&llid, PLINK_GET_PLID(elems.peer_link), 2);
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, mgmt->sa);
+ if (!sta && ftype != PLINK_OPEN) {
+ mpl_dbg("Mesh plink: cls or cnf from unknown peer\n");
+ rcu_read_unlock();
+ return;
+ }
+
+ if (sta && sta->plink_state == PLINK_BLOCKED) {
+ rcu_read_unlock();
+ return;
+ }
+
+ /* Now we will figure out the appropriate event... */
+ event = PLINK_UNDEFINED;
+ if (ftype != PLINK_CLOSE && (!mesh_matches_local(&elems, dev))) {
+ switch (ftype) {
+ case PLINK_OPEN:
+ event = OPN_RJCT;
+ break;
+ case PLINK_CONFIRM:
+ event = CNF_RJCT;
+ break;
+ case PLINK_CLOSE:
+ /* avoid warning */
+ break;
+ }
+ spin_lock_bh(&sta->plink_lock);
+ } else if (!sta) {
+ /* ftype == PLINK_OPEN */
+ u64 rates;
+ if (!mesh_plink_free_count(sdata)) {
+ mpl_dbg("Mesh plink error: no more free plinks\n");
+ rcu_read_unlock();
+ return;
+ }
+
+ rates = ieee80211_sta_get_rates(local, &elems, rx_status->band);
+ sta = mesh_plink_alloc(sdata, mgmt->sa, rates);
+ if (!sta) {
+ mpl_dbg("Mesh plink error: plink table full\n");
+ rcu_read_unlock();
+ return;
+ }
+ if (sta_info_insert(sta)) {
+ rcu_read_unlock();
+ return;
+ }
+ event = OPN_ACPT;
+ spin_lock_bh(&sta->plink_lock);
+ } else {
+ spin_lock_bh(&sta->plink_lock);
+ switch (ftype) {
+ case PLINK_OPEN:
+ if (!mesh_plink_free_count(sdata) ||
+ (sta->plid && sta->plid != plid))
+ event = OPN_IGNR;
+ else
+ event = OPN_ACPT;
+ break;
+ case PLINK_CONFIRM:
+ if (!mesh_plink_free_count(sdata) ||
+ (sta->llid != llid || sta->plid != plid))
+ event = CNF_IGNR;
+ else
+ event = CNF_ACPT;
+ break;
+ case PLINK_CLOSE:
+ if (sta->plink_state == PLINK_ESTAB)
+ /* Do not check for llid or plid. This does not
+ * follow the standard but since multiple plinks
+ * per sta are not supported, it is necessary in
+ * order to avoid a livelock when MP A sees an
+ * establish peer link to MP B but MP B does not
+ * see it. This can be caused by a timeout in
+ * B's peer link establishment or B beign
+ * restarted.
+ */
+ event = CLS_ACPT;
+ else if (sta->plid != plid)
+ event = CLS_IGNR;
+ else if (ie_len == 7 && sta->llid != llid)
+ event = CLS_IGNR;
+ else
+ event = CLS_ACPT;
+ break;
+ default:
+ mpl_dbg("Mesh plink: unknown frame subtype\n");
+ spin_unlock_bh(&sta->plink_lock);
+ rcu_read_unlock();
+ return;
+ }
+ }
+
+ mpl_dbg("Mesh plink (peer, state, llid, plid, event): %s %d %d %d %d\n",
+ print_mac(mac, mgmt->sa), sta->plink_state,
+ le16_to_cpu(sta->llid), le16_to_cpu(sta->plid),
+ event);
+ reason = 0;
+ switch (sta->plink_state) {
+ /* spin_unlock as soon as state is updated at each case */
+ case PLINK_LISTEN:
+ switch (event) {
+ case CLS_ACPT:
+ mesh_plink_fsm_restart(sta);
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ case OPN_ACPT:
+ sta->plink_state = PLINK_OPN_RCVD;
+ sta->plid = plid;
+ get_random_bytes(&llid, 2);
+ sta->llid = llid;
+ mesh_plink_timer_set(sta, dot11MeshRetryTimeout(sdata));
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_OPEN, sta->addr, llid,
+ 0, 0);
+ mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr,
+ llid, plid, 0);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+ break;
+
+ case PLINK_OPN_SNT:
+ switch (event) {
+ case OPN_RJCT:
+ case CNF_RJCT:
+ reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
+ case CLS_ACPT:
+ if (!reason)
+ reason = cpu_to_le16(MESH_CLOSE_RCVD);
+ sta->reason = reason;
+ sta->plink_state = PLINK_HOLDING;
+ if (!mod_plink_timer(sta,
+ dot11MeshHoldingTimeout(sdata)))
+ sta->ignore_plink_timer = true;
+
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ break;
+ case OPN_ACPT:
+ /* retry timer is left untouched */
+ sta->plink_state = PLINK_OPN_RCVD;
+ sta->plid = plid;
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
+ plid, 0);
+ break;
+ case CNF_ACPT:
+ sta->plink_state = PLINK_CNF_RCVD;
+ if (!mod_plink_timer(sta,
+ dot11MeshConfirmTimeout(sdata)))
+ sta->ignore_plink_timer = true;
+
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+ break;
+
+ case PLINK_OPN_RCVD:
+ switch (event) {
+ case OPN_RJCT:
+ case CNF_RJCT:
+ reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
+ case CLS_ACPT:
+ if (!reason)
+ reason = cpu_to_le16(MESH_CLOSE_RCVD);
+ sta->reason = reason;
+ sta->plink_state = PLINK_HOLDING;
+ if (!mod_plink_timer(sta,
+ dot11MeshHoldingTimeout(sdata)))
+ sta->ignore_plink_timer = true;
+
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ break;
+ case OPN_ACPT:
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
+ plid, 0);
+ break;
+ case CNF_ACPT:
+ del_timer(&sta->plink_timer);
+ sta->plink_state = PLINK_ESTAB;
+ mesh_plink_inc_estab_count(sdata);
+ spin_unlock_bh(&sta->plink_lock);
+ mpl_dbg("Mesh plink with %s ESTABLISHED\n",
+ print_mac(mac, sta->addr));
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+ break;
+
+ case PLINK_CNF_RCVD:
+ switch (event) {
+ case OPN_RJCT:
+ case CNF_RJCT:
+ reason = cpu_to_le16(MESH_CAPABILITY_POLICY_VIOLATION);
+ case CLS_ACPT:
+ if (!reason)
+ reason = cpu_to_le16(MESH_CLOSE_RCVD);
+ sta->reason = reason;
+ sta->plink_state = PLINK_HOLDING;
+ if (!mod_plink_timer(sta,
+ dot11MeshHoldingTimeout(sdata)))
+ sta->ignore_plink_timer = true;
+
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ break;
+ case OPN_ACPT:
+ del_timer(&sta->plink_timer);
+ sta->plink_state = PLINK_ESTAB;
+ mesh_plink_inc_estab_count(sdata);
+ spin_unlock_bh(&sta->plink_lock);
+ mpl_dbg("Mesh plink with %s ESTABLISHED\n",
+ print_mac(mac, sta->addr));
+ mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
+ plid, 0);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+ break;
+
+ case PLINK_ESTAB:
+ switch (event) {
+ case CLS_ACPT:
+ reason = cpu_to_le16(MESH_CLOSE_RCVD);
+ sta->reason = reason;
+ __mesh_plink_deactivate(sta);
+ sta->plink_state = PLINK_HOLDING;
+ llid = sta->llid;
+ mod_plink_timer(sta, dot11MeshHoldingTimeout(sdata));
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ break;
+ case OPN_ACPT:
+ llid = sta->llid;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CONFIRM, sta->addr, llid,
+ plid, 0);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+ break;
+ case PLINK_HOLDING:
+ switch (event) {
+ case CLS_ACPT:
+ if (del_timer(&sta->plink_timer))
+ sta->ignore_plink_timer = 1;
+ mesh_plink_fsm_restart(sta);
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ case OPN_ACPT:
+ case CNF_ACPT:
+ case OPN_RJCT:
+ case CNF_RJCT:
+ llid = sta->llid;
+ reason = sta->reason;
+ spin_unlock_bh(&sta->plink_lock);
+ mesh_plink_frame_tx(dev, PLINK_CLOSE, sta->addr, llid,
+ plid, reason);
+ break;
+ default:
+ spin_unlock_bh(&sta->plink_lock);
+ }
+ break;
+ default:
+ /* should not get here, PLINK_BLOCKED is dealt with at the
+ * beggining of the function
+ */
+ spin_unlock_bh(&sta->plink_lock);
+ break;
+ }
+
+ rcu_read_unlock();
+}
diff --git a/net/mac80211/ieee80211_sta.c b/net/mac80211/mlme.c
index c1706855460a..6b75cb6c6300 100644
--- a/net/mac80211/ieee80211_sta.c
+++ b/net/mac80211/mlme.c
@@ -24,19 +24,22 @@
#include <linux/wireless.h>
#include <linux/random.h>
#include <linux/etherdevice.h>
+#include <linux/rtnetlink.h>
#include <net/iw_handler.h>
#include <asm/types.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
-#include "ieee80211_led.h"
+#include "rate.h"
+#include "led.h"
+#include "mesh.h"
#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
#define IEEE80211_AUTH_MAX_TRIES 3
#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
#define IEEE80211_ASSOC_MAX_TRIES 3
#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
+#define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ)
#define IEEE80211_PROBE_INTERVAL (60 * HZ)
#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
#define IEEE80211_SCAN_INTERVAL (2 * HZ)
@@ -49,12 +52,11 @@
#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
+#define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ)
#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
-#define IEEE80211_FC(type, stype) cpu_to_le16(type | stype)
-
#define ERP_INFO_USE_PROTECTION BIT(1)
/* mgmt header + 1 byte action code */
@@ -74,7 +76,7 @@
static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
u8 *ssid, size_t ssid_len);
static struct ieee80211_sta_bss *
-ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
u8 *ssid, u8 ssid_len);
static void ieee80211_rx_bss_put(struct net_device *dev,
struct ieee80211_sta_bss *bss);
@@ -87,46 +89,8 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
struct ieee80211_if_sta *ifsta);
-/* Parsed Information Elements */
-struct ieee802_11_elems {
- /* pointers to IEs */
- u8 *ssid;
- u8 *supp_rates;
- u8 *fh_params;
- u8 *ds_params;
- u8 *cf_params;
- u8 *tim;
- u8 *ibss_params;
- u8 *challenge;
- u8 *wpa;
- u8 *rsn;
- u8 *erp_info;
- u8 *ext_supp_rates;
- u8 *wmm_info;
- u8 *wmm_param;
- u8 *ht_cap_elem;
- u8 *ht_info_elem;
- /* length of them, respectively */
- u8 ssid_len;
- u8 supp_rates_len;
- u8 fh_params_len;
- u8 ds_params_len;
- u8 cf_params_len;
- u8 tim_len;
- u8 ibss_params_len;
- u8 challenge_len;
- u8 wpa_len;
- u8 rsn_len;
- u8 erp_info_len;
- u8 ext_supp_rates_len;
- u8 wmm_info_len;
- u8 wmm_param_len;
- u8 ht_cap_elem_len;
- u8 ht_info_elem_len;
-};
-
-static void ieee802_11_parse_elems(u8 *start, size_t len,
- struct ieee802_11_elems *elems)
+void ieee802_11_parse_elems(u8 *start, size_t len,
+ struct ieee802_11_elems *elems)
{
size_t left = len;
u8 *pos = start;
@@ -215,6 +179,30 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
elems->ht_info_elem = pos;
elems->ht_info_elem_len = elen;
break;
+ case WLAN_EID_MESH_ID:
+ elems->mesh_id = pos;
+ elems->mesh_id_len = elen;
+ break;
+ case WLAN_EID_MESH_CONFIG:
+ elems->mesh_config = pos;
+ elems->mesh_config_len = elen;
+ break;
+ case WLAN_EID_PEER_LINK:
+ elems->peer_link = pos;
+ elems->peer_link_len = elen;
+ break;
+ case WLAN_EID_PREQ:
+ elems->preq = pos;
+ elems->preq_len = elen;
+ break;
+ case WLAN_EID_PREP:
+ elems->prep = pos;
+ elems->prep_len = elen;
+ break;
+ case WLAN_EID_PERR:
+ elems->perr = pos;
+ elems->perr_len = elen;
+ break;
default:
break;
}
@@ -227,12 +215,61 @@ static void ieee802_11_parse_elems(u8 *start, size_t len,
static int ecw2cw(int ecw)
{
- int cw = 1;
- while (ecw > 0) {
- cw <<= 1;
- ecw--;
+ return (1 << ecw) - 1;
+}
+
+
+static void ieee80211_sta_def_wmm_params(struct net_device *dev,
+ struct ieee80211_sta_bss *bss,
+ int ibss)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_local *local = sdata->local;
+ int i, have_higher_than_11mbit = 0;
+
+
+ /* cf. IEEE 802.11 9.2.12 */
+ for (i = 0; i < bss->supp_rates_len; i++)
+ if ((bss->supp_rates[i] & 0x7f) * 5 > 110)
+ have_higher_than_11mbit = 1;
+
+ if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
+ have_higher_than_11mbit)
+ sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
+ else
+ sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
+
+
+ if (local->ops->conf_tx) {
+ struct ieee80211_tx_queue_params qparam;
+
+ memset(&qparam, 0, sizeof(qparam));
+
+ qparam.aifs = 2;
+
+ if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
+ !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
+ qparam.cw_min = 31;
+ else
+ qparam.cw_min = 15;
+
+ qparam.cw_max = 1023;
+ qparam.txop = 0;
+
+ for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
+ local->ops->conf_tx(local_to_hw(local),
+ i + IEEE80211_TX_QUEUE_DATA0,
+ &qparam);
+
+ if (ibss) {
+ /* IBSS uses different parameters for Beacon sending */
+ qparam.cw_min++;
+ qparam.cw_min *= 2;
+ qparam.cw_min--;
+ local->ops->conf_tx(local_to_hw(local),
+ IEEE80211_TX_QUEUE_BEACON, &qparam);
+ }
}
- return cw - 1;
}
static void ieee80211_sta_wmm_params(struct net_device *dev,
@@ -297,12 +334,13 @@ static void ieee80211_sta_wmm_params(struct net_device *dev,
params.aifs = pos[0] & 0x0f;
params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
params.cw_min = ecw2cw(pos[1] & 0x0f);
- /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
- params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
+ params.txop = pos[2] | (pos[3] << 8);
+#ifdef CONFIG_MAC80211_DEBUG
printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
- "cWmin=%d cWmax=%d burst=%d\n",
+ "cWmin=%d cWmax=%d txop=%d\n",
dev->name, queue, aci, acm, params.aifs, params.cw_min,
- params.cw_max, params.burst_time);
+ params.cw_max, params.txop);
+#endif
/* TODO: handle ACM (block TX, fallback to next lowest allowed
* AC for now) */
if (local->ops->conf_tx(local_to_hw(local), queue, &params)) {
@@ -477,6 +515,7 @@ static void ieee80211_set_associated(struct net_device *dev,
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_local *local = sdata->local;
+ struct ieee80211_conf *conf = &local_to_hw(local)->conf;
union iwreq_data wrqu;
u32 changed = BSS_CHANGED_ASSOC;
@@ -489,31 +528,49 @@ static void ieee80211_set_associated(struct net_device *dev,
return;
bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
- local->hw.conf.channel,
+ conf->channel->center_freq,
ifsta->ssid, ifsta->ssid_len);
if (bss) {
+ /* set timing information */
+ sdata->bss_conf.beacon_int = bss->beacon_int;
+ sdata->bss_conf.timestamp = bss->timestamp;
+
changed |= ieee80211_handle_bss_capability(sdata, bss);
+
ieee80211_rx_bss_put(dev, bss);
}
+ if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
+ changed |= BSS_CHANGED_HT;
+ sdata->bss_conf.assoc_ht = 1;
+ sdata->bss_conf.ht_conf = &conf->ht_conf;
+ sdata->bss_conf.ht_bss_conf = &conf->ht_bss_conf;
+ }
+
netif_carrier_on(dev);
ifsta->flags |= IEEE80211_STA_PREV_BSSID_SET;
memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
ieee80211_sta_send_associnfo(dev, ifsta);
} else {
+ ieee80211_sta_tear_down_BA_sessions(dev, ifsta->bssid);
ifsta->flags &= ~IEEE80211_STA_ASSOCIATED;
-
netif_carrier_off(dev);
ieee80211_reset_erp_info(dev);
+
+ sdata->bss_conf.assoc_ht = 0;
+ sdata->bss_conf.ht_conf = NULL;
+ sdata->bss_conf.ht_bss_conf = NULL;
+
memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
}
- wrqu.ap_addr.sa_family = ARPHRD_ETHER;
- wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
ifsta->last_probe = jiffies;
ieee80211_led_assoc(local, assoc);
+ sdata->bss_conf.assoc = assoc;
ieee80211_bss_info_change_notify(sdata, changed);
+ wrqu.ap_addr.sa_family = ARPHRD_ETHER;
+ wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
}
static void ieee80211_set_disassoc(struct net_device *dev,
@@ -525,8 +582,8 @@ static void ieee80211_set_disassoc(struct net_device *dev,
ieee80211_set_associated(dev, ifsta, 0);
}
-static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
- int encrypt)
+void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
+ int encrypt)
{
struct ieee80211_sub_if_data *sdata;
struct ieee80211_tx_packet_data *pkt_data;
@@ -613,7 +670,6 @@ static void ieee80211_send_assoc(struct net_device *dev,
struct ieee80211_if_sta *ifsta)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hw_mode *mode;
struct sk_buff *skb;
struct ieee80211_mgmt *mgmt;
u8 *pos, *ies;
@@ -621,6 +677,7 @@ static void ieee80211_send_assoc(struct net_device *dev,
u16 capab;
struct ieee80211_sta_bss *bss;
int wmm = 0;
+ struct ieee80211_supported_band *sband;
skb = dev_alloc_skb(local->hw.extra_tx_headroom +
sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
@@ -632,13 +689,19 @@ static void ieee80211_send_assoc(struct net_device *dev,
}
skb_reserve(skb, local->hw.extra_tx_headroom);
- mode = local->oper_hw_mode;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
capab = ifsta->capab;
- if (mode->mode == MODE_IEEE80211G) {
- capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
- WLAN_CAPABILITY_SHORT_PREAMBLE;
+
+ if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) {
+ if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
+ capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
+ if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
+ capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
}
- bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
+
+ bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
+ local->hw.conf.channel->center_freq,
ifsta->ssid, ifsta->ssid_len);
if (bss) {
if (bss->capability & WLAN_CAPABILITY_PRIVACY)
@@ -677,23 +740,23 @@ static void ieee80211_send_assoc(struct net_device *dev,
*pos++ = ifsta->ssid_len;
memcpy(pos, ifsta->ssid, ifsta->ssid_len);
- len = mode->num_rates;
+ len = sband->n_bitrates;
if (len > 8)
len = 8;
pos = skb_put(skb, len + 2);
*pos++ = WLAN_EID_SUPP_RATES;
*pos++ = len;
for (i = 0; i < len; i++) {
- int rate = mode->rates[i].rate;
+ int rate = sband->bitrates[i].bitrate;
*pos++ = (u8) (rate / 5);
}
- if (mode->num_rates > len) {
- pos = skb_put(skb, mode->num_rates - len + 2);
+ if (sband->n_bitrates > len) {
+ pos = skb_put(skb, sband->n_bitrates - len + 2);
*pos++ = WLAN_EID_EXT_SUPP_RATES;
- *pos++ = mode->num_rates - len;
- for (i = len; i < mode->num_rates; i++) {
- int rate = mode->rates[i].rate;
+ *pos++ = sband->n_bitrates - len;
+ for (i = len; i < sband->n_bitrates; i++) {
+ int rate = sband->bitrates[i].bitrate;
*pos++ = (u8) (rate / 5);
}
}
@@ -716,17 +779,18 @@ static void ieee80211_send_assoc(struct net_device *dev,
*pos++ = 0;
}
/* wmm support is a must to HT */
- if (wmm && mode->ht_info.ht_supported) {
- __le16 tmp = cpu_to_le16(mode->ht_info.cap);
+ if (wmm && sband->ht_info.ht_supported) {
+ __le16 tmp = cpu_to_le16(sband->ht_info.cap);
pos = skb_put(skb, sizeof(struct ieee80211_ht_cap)+2);
*pos++ = WLAN_EID_HT_CAPABILITY;
*pos++ = sizeof(struct ieee80211_ht_cap);
memset(pos, 0, sizeof(struct ieee80211_ht_cap));
memcpy(pos, &tmp, sizeof(u16));
pos += sizeof(u16);
- *pos++ = (mode->ht_info.ampdu_factor |
- (mode->ht_info.ampdu_density << 2));
- memcpy(pos, mode->ht_info.supp_mcs_set, 16);
+ /* TODO: needs a define here for << 2 */
+ *pos++ = sband->ht_info.ampdu_factor |
+ (sband->ht_info.ampdu_density << 2);
+ memcpy(pos, sband->ht_info.supp_mcs_set, 16);
}
kfree(ifsta->assocreq_ies);
@@ -809,7 +873,8 @@ static int ieee80211_privacy_mismatch(struct net_device *dev,
if (!ifsta || (ifsta->flags & IEEE80211_STA_MIXED_CELL))
return 0;
- bss = ieee80211_rx_bss_get(dev, ifsta->bssid, local->hw.conf.channel,
+ bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
+ local->hw.conf.channel->center_freq,
ifsta->ssid, ifsta->ssid_len);
if (!bss)
return 0;
@@ -872,6 +937,8 @@ static void ieee80211_associated(struct net_device *dev,
ifsta->state = IEEE80211_ASSOCIATED;
+ rcu_read_lock();
+
sta = sta_info_get(local, ifsta->bssid);
if (!sta) {
printk(KERN_DEBUG "%s: No STA entry for own AP %s\n",
@@ -887,7 +954,7 @@ static void ieee80211_associated(struct net_device *dev,
"range\n",
dev->name, print_mac(mac, ifsta->bssid));
disassoc = 1;
- sta_info_free(sta);
+ sta_info_unlink(&sta);
} else
ieee80211_send_probe_req(dev, ifsta->bssid,
local->scan_ssid,
@@ -903,8 +970,13 @@ static void ieee80211_associated(struct net_device *dev,
ifsta->ssid_len);
}
}
- sta_info_put(sta);
}
+
+ rcu_read_unlock();
+
+ if (disassoc && sta)
+ sta_info_destroy(sta);
+
if (disassoc) {
ifsta->state = IEEE80211_DISABLED;
ieee80211_set_associated(dev, ifsta, 0);
@@ -919,7 +991,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
u8 *ssid, size_t ssid_len)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
struct sk_buff *skb;
struct ieee80211_mgmt *mgmt;
u8 *pos, *supp_rates, *esupp_rates = NULL;
@@ -953,11 +1025,10 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
supp_rates = skb_put(skb, 2);
supp_rates[0] = WLAN_EID_SUPP_RATES;
supp_rates[1] = 0;
- mode = local->oper_hw_mode;
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
- if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
- continue;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+ for (i = 0; i < sband->n_bitrates; i++) {
+ struct ieee80211_rate *rate = &sband->bitrates[i];
if (esupp_rates) {
pos = skb_put(skb, 1);
esupp_rates[1]++;
@@ -970,7 +1041,7 @@ static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
pos = skb_put(skb, 1);
supp_rates[1]++;
}
- *pos = rate->rate / 5;
+ *pos = rate->bitrate / 5;
}
ieee80211_sta_tx(dev, skb, 0);
@@ -1065,6 +1136,58 @@ static void ieee80211_send_addba_resp(struct net_device *dev, u8 *da, u16 tid,
return;
}
+void ieee80211_send_addba_request(struct net_device *dev, const u8 *da,
+ u16 tid, u8 dialog_token, u16 start_seq_num,
+ u16 agg_size, u16 timeout)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ struct ieee80211_if_sta *ifsta = &sdata->u.sta;
+ struct sk_buff *skb;
+ struct ieee80211_mgmt *mgmt;
+ u16 capab;
+
+ skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom + 1 +
+ sizeof(mgmt->u.action.u.addba_req));
+
+
+ if (!skb) {
+ printk(KERN_ERR "%s: failed to allocate buffer "
+ "for addba request frame\n", dev->name);
+ return;
+ }
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+ mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
+ memset(mgmt, 0, 24);
+ memcpy(mgmt->da, da, ETH_ALEN);
+ memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+ if (sdata->vif.type == IEEE80211_IF_TYPE_AP)
+ memcpy(mgmt->bssid, dev->dev_addr, ETH_ALEN);
+ else
+ memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
+
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_ACTION);
+
+ skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
+
+ mgmt->u.action.category = WLAN_CATEGORY_BACK;
+ mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
+
+ mgmt->u.action.u.addba_req.dialog_token = dialog_token;
+ capab = (u16)(1 << 1); /* bit 1 aggregation policy */
+ capab |= (u16)(tid << 2); /* bit 5:2 TID number */
+ capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
+
+ mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
+
+ mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
+ mgmt->u.action.u.addba_req.start_seq_num =
+ cpu_to_le16(start_seq_num << 4);
+
+ ieee80211_sta_tx(dev, skb, 0);
+}
+
static void ieee80211_sta_process_addba_request(struct net_device *dev,
struct ieee80211_mgmt *mgmt,
size_t len)
@@ -1079,9 +1202,13 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
int ret = -EOPNOTSUPP;
DECLARE_MAC_BUF(mac);
+ rcu_read_lock();
+
sta = sta_info_get(local, mgmt->sa);
- if (!sta)
+ if (!sta) {
+ rcu_read_unlock();
return;
+ }
/* extract session parameters from addba request frame */
dialog_token = mgmt->u.action.u.addba_req.dialog_token;
@@ -1105,7 +1232,7 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
status = WLAN_STATUS_INVALID_QOS_PARAM;
#ifdef CONFIG_MAC80211_HT_DEBUG
if (net_ratelimit())
- printk(KERN_DEBUG "Block Ack Req with bad params from "
+ printk(KERN_DEBUG "AddBA Req with bad params from "
"%s on tid %u. policy %d, buffer size %d\n",
print_mac(mac, mgmt->sa), tid, ba_policy,
buf_size);
@@ -1114,26 +1241,45 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
}
/* determine default buffer size */
if (buf_size == 0) {
- struct ieee80211_hw_mode *mode = conf->mode;
+ struct ieee80211_supported_band *sband;
+
+ sband = local->hw.wiphy->bands[conf->channel->band];
buf_size = IEEE80211_MIN_AMPDU_BUF;
- buf_size = buf_size << mode->ht_info.ampdu_factor;
+ buf_size = buf_size << sband->ht_info.ampdu_factor;
}
- tid_agg_rx = &sta->ampdu_mlme.tid_rx[tid];
/* examine state machine */
spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
- if (tid_agg_rx->state != HT_AGG_STATE_IDLE) {
+ if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
#ifdef CONFIG_MAC80211_HT_DEBUG
if (net_ratelimit())
- printk(KERN_DEBUG "unexpected Block Ack Req from "
+ printk(KERN_DEBUG "unexpected AddBA Req from "
"%s on tid %u\n",
print_mac(mac, mgmt->sa), tid);
#endif /* CONFIG_MAC80211_HT_DEBUG */
goto end;
}
+ /* prepare A-MPDU MLME for Rx aggregation */
+ sta->ampdu_mlme.tid_rx[tid] =
+ kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
+ if (!sta->ampdu_mlme.tid_rx[tid]) {
+ if (net_ratelimit())
+ printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
+ tid);
+ goto end;
+ }
+ /* rx timer */
+ sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
+ sta_rx_agg_session_timer_expired;
+ sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
+ (unsigned long)&sta->timer_to_tid[tid];
+ init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
+
+ tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
+
/* prepare reordering buffer */
tid_agg_rx->reorder_buf =
kmalloc(buf_size * sizeof(struct sk_buf *), GFP_ATOMIC);
@@ -1141,6 +1287,7 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
if (net_ratelimit())
printk(KERN_ERR "can not allocate reordering buffer "
"to tid %d\n", tid);
+ kfree(sta->ampdu_mlme.tid_rx[tid]);
goto end;
}
memset(tid_agg_rx->reorder_buf, 0,
@@ -1148,18 +1295,20 @@ static void ieee80211_sta_process_addba_request(struct net_device *dev,
if (local->ops->ampdu_action)
ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
- sta->addr, tid, start_seq_num);
+ sta->addr, tid, &start_seq_num);
#ifdef CONFIG_MAC80211_HT_DEBUG
- printk(KERN_DEBUG "Rx A-MPDU on tid %d result %d", tid, ret);
+ printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
#endif /* CONFIG_MAC80211_HT_DEBUG */
if (ret) {
kfree(tid_agg_rx->reorder_buf);
+ kfree(tid_agg_rx);
+ sta->ampdu_mlme.tid_rx[tid] = NULL;
goto end;
}
/* change state and send addba resp */
- tid_agg_rx->state = HT_AGG_STATE_OPERATIONAL;
+ sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
tid_agg_rx->dialog_token = dialog_token;
tid_agg_rx->ssn = start_seq_num;
tid_agg_rx->head_seq_num = start_seq_num;
@@ -1171,13 +1320,89 @@ end:
spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
end_no_lock:
- ieee80211_send_addba_resp(sta->dev, sta->addr, tid, dialog_token,
- status, 1, buf_size, timeout);
- sta_info_put(sta);
+ ieee80211_send_addba_resp(sta->sdata->dev, sta->addr, tid,
+ dialog_token, status, 1, buf_size, timeout);
+ rcu_read_unlock();
}
-static void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
- u16 initiator, u16 reason_code)
+static void ieee80211_sta_process_addba_resp(struct net_device *dev,
+ struct ieee80211_mgmt *mgmt,
+ size_t len)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_hw *hw = &local->hw;
+ struct sta_info *sta;
+ u16 capab;
+ u16 tid;
+ u8 *state;
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, mgmt->sa);
+ if (!sta) {
+ rcu_read_unlock();
+ return;
+ }
+
+ capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
+ tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
+
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+
+ if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ printk(KERN_DEBUG "state not HT_ADDBA_REQUESTED_MSK:"
+ "%d\n", *state);
+ goto addba_resp_exit;
+ }
+
+ if (mgmt->u.action.u.addba_resp.dialog_token !=
+ sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ goto addba_resp_exit;
+ }
+
+ del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
+ == WLAN_STATUS_SUCCESS) {
+ if (*state & HT_ADDBA_RECEIVED_MSK)
+ printk(KERN_DEBUG "double addBA response\n");
+
+ *state |= HT_ADDBA_RECEIVED_MSK;
+ sta->ampdu_mlme.addba_req_num[tid] = 0;
+
+ if (*state == HT_AGG_STATE_OPERATIONAL) {
+ printk(KERN_DEBUG "Aggregation on for tid %d \n", tid);
+ ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
+ }
+
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ printk(KERN_DEBUG "recipient accepted agg: tid %d \n", tid);
+ } else {
+ printk(KERN_DEBUG "recipient rejected agg: tid %d \n", tid);
+
+ sta->ampdu_mlme.addba_req_num[tid]++;
+ /* this will allow the state check in stop_BA_session */
+ *state = HT_AGG_STATE_OPERATIONAL;
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ ieee80211_stop_tx_ba_session(hw, sta->addr, tid,
+ WLAN_BACK_INITIATOR);
+ }
+
+addba_resp_exit:
+ rcu_read_unlock();
+}
+
+void ieee80211_send_delba(struct net_device *dev, const u8 *da, u16 tid,
+ u16 initiator, u16 reason_code)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -1227,58 +1452,71 @@ void ieee80211_sta_stop_rx_ba_session(struct net_device *dev, u8 *ra, u16 tid,
struct ieee80211_hw *hw = &local->hw;
struct sta_info *sta;
int ret, i;
+ DECLARE_MAC_BUF(mac);
+
+ rcu_read_lock();
sta = sta_info_get(local, ra);
- if (!sta)
+ if (!sta) {
+ rcu_read_unlock();
return;
+ }
/* check if TID is in operational state */
spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
- if (sta->ampdu_mlme.tid_rx[tid].state
+ if (sta->ampdu_mlme.tid_state_rx[tid]
!= HT_AGG_STATE_OPERATIONAL) {
spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
- sta_info_put(sta);
+ rcu_read_unlock();
return;
}
- sta->ampdu_mlme.tid_rx[tid].state =
+ sta->ampdu_mlme.tid_state_rx[tid] =
HT_AGG_STATE_REQ_STOP_BA_MSK |
(initiator << HT_AGG_STATE_INITIATOR_SHIFT);
- spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
/* stop HW Rx aggregation. ampdu_action existence
* already verified in session init so we add the BUG_ON */
BUG_ON(!local->ops->ampdu_action);
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ printk(KERN_DEBUG "Rx BA session stop requested for %s tid %u\n",
+ print_mac(mac, ra), tid);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+
ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
- ra, tid, EINVAL);
+ ra, tid, NULL);
if (ret)
printk(KERN_DEBUG "HW problem - can not stop rx "
"aggergation for tid %d\n", tid);
/* shutdown timer has not expired */
if (initiator != WLAN_BACK_TIMER)
- del_timer_sync(&sta->ampdu_mlme.tid_rx[tid].
- session_timer);
+ del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
/* check if this is a self generated aggregation halt */
if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
ieee80211_send_delba(dev, ra, tid, 0, reason);
/* free the reordering buffer */
- for (i = 0; i < sta->ampdu_mlme.tid_rx[tid].buf_size; i++) {
- if (sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]) {
+ for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
+ if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
/* release the reordered frames */
- dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid].reorder_buf[i]);
- sta->ampdu_mlme.tid_rx[tid].stored_mpdu_num--;
- sta->ampdu_mlme.tid_rx[tid].reorder_buf[i] = NULL;
+ dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
+ sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
+ sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
}
}
- kfree(sta->ampdu_mlme.tid_rx[tid].reorder_buf);
+ /* free resources */
+ kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
+ kfree(sta->ampdu_mlme.tid_rx[tid]);
+ sta->ampdu_mlme.tid_rx[tid] = NULL;
+ sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
- sta->ampdu_mlme.tid_rx[tid].state = HT_AGG_STATE_IDLE;
- sta_info_put(sta);
+ rcu_read_unlock();
}
+
static void ieee80211_sta_process_delba(struct net_device *dev,
struct ieee80211_mgmt *mgmt, size_t len)
{
@@ -1288,9 +1526,13 @@ static void ieee80211_sta_process_delba(struct net_device *dev,
u16 initiator;
DECLARE_MAC_BUF(mac);
+ rcu_read_lock();
+
sta = sta_info_get(local, mgmt->sa);
- if (!sta)
+ if (!sta) {
+ rcu_read_unlock();
return;
+ }
params = le16_to_cpu(mgmt->u.action.u.delba.params);
tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
@@ -1298,27 +1540,87 @@ static void ieee80211_sta_process_delba(struct net_device *dev,
#ifdef CONFIG_MAC80211_HT_DEBUG
if (net_ratelimit())
- printk(KERN_DEBUG "delba from %s on tid %d reason code %d\n",
- print_mac(mac, mgmt->sa), tid,
+ printk(KERN_DEBUG "delba from %s (%s) tid %d reason code %d\n",
+ print_mac(mac, mgmt->sa),
+ initiator ? "initiator" : "recipient", tid,
mgmt->u.action.u.delba.reason_code);
#endif /* CONFIG_MAC80211_HT_DEBUG */
if (initiator == WLAN_BACK_INITIATOR)
ieee80211_sta_stop_rx_ba_session(dev, sta->addr, tid,
WLAN_BACK_INITIATOR, 0);
- sta_info_put(sta);
+ else { /* WLAN_BACK_RECIPIENT */
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+ sta->ampdu_mlme.tid_state_tx[tid] =
+ HT_AGG_STATE_OPERATIONAL;
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ ieee80211_stop_tx_ba_session(&local->hw, sta->addr, tid,
+ WLAN_BACK_RECIPIENT);
+ }
+ rcu_read_unlock();
}
/*
- * After receiving Block Ack Request (BAR) we activated a
- * timer after each frame arrives from the originator.
+ * After sending add Block Ack request we activated a timer until
+ * add Block Ack response will arrive from the recipient.
+ * If this timer expires sta_addba_resp_timer_expired will be executed.
+ */
+void sta_addba_resp_timer_expired(unsigned long data)
+{
+ /* not an elegant detour, but there is no choice as the timer passes
+ * only one argument, and both sta_info and TID are needed, so init
+ * flow in sta_info_create gives the TID as data, while the timer_to_id
+ * array gives the sta through container_of */
+ u16 tid = *(int *)data;
+ struct sta_info *temp_sta = container_of((void *)data,
+ struct sta_info, timer_to_tid[tid]);
+
+ struct ieee80211_local *local = temp_sta->local;
+ struct ieee80211_hw *hw = &local->hw;
+ struct sta_info *sta;
+ u8 *state;
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, temp_sta->addr);
+ if (!sta) {
+ rcu_read_unlock();
+ return;
+ }
+
+ state = &sta->ampdu_mlme.tid_state_tx[tid];
+ /* check if the TID waits for addBA response */
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+ if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ *state = HT_AGG_STATE_IDLE;
+ printk(KERN_DEBUG "timer expired on tid %d but we are not "
+ "expecting addBA response there", tid);
+ goto timer_expired_exit;
+ }
+
+ printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
+
+ /* go through the state check in stop_BA_session */
+ *state = HT_AGG_STATE_OPERATIONAL;
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
+ ieee80211_stop_tx_ba_session(hw, temp_sta->addr, tid,
+ WLAN_BACK_INITIATOR);
+
+timer_expired_exit:
+ rcu_read_unlock();
+}
+
+/*
+ * After accepting the AddBA Request we activated a timer,
+ * resetting it after each frame that arrives from the originator.
* if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
*/
void sta_rx_agg_session_timer_expired(unsigned long data)
{
/* not an elegant detour, but there is no choice as the timer passes
* only one argument, and verious sta_info are needed here, so init
- * flow in sta_info_add gives the TID as data, while the timer_to_id
+ * flow in sta_info_create gives the TID as data, while the timer_to_id
* array gives the sta through container_of */
u8 *ptid = (u8 *)data;
u8 *timer_to_id = ptid - *ptid;
@@ -1326,11 +1628,24 @@ void sta_rx_agg_session_timer_expired(unsigned long data)
timer_to_tid[0]);
printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
- ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr, (u16)*ptid,
- WLAN_BACK_TIMER,
+ ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
+ (u16)*ptid, WLAN_BACK_TIMER,
WLAN_REASON_QSTA_TIMEOUT);
}
+void ieee80211_sta_tear_down_BA_sessions(struct net_device *dev, u8 *addr)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ int i;
+
+ for (i = 0; i < STA_TID_NUM; i++) {
+ ieee80211_stop_tx_ba_session(&local->hw, addr, i,
+ WLAN_BACK_INITIATOR);
+ ieee80211_sta_stop_rx_ba_session(dev, addr, i,
+ WLAN_BACK_RECIPIENT,
+ WLAN_REASON_QSTA_LEAVE_QBSS);
+ }
+}
static void ieee80211_rx_mgmt_auth(struct net_device *dev,
struct ieee80211_if_sta *ifsta,
@@ -1557,15 +1872,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
{
struct ieee80211_local *local = sdata->local;
struct net_device *dev = sdata->dev;
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
struct sta_info *sta;
- u32 rates;
+ u64 rates, basic_rates;
u16 capab_info, status_code, aid;
struct ieee802_11_elems elems;
struct ieee80211_bss_conf *bss_conf = &sdata->bss_conf;
u8 *pos;
int i, j;
DECLARE_MAC_BUF(mac);
+ bool have_higher_than_11mbit = false;
/* AssocResp and ReassocResp have identical structure, so process both
* of them in this function. */
@@ -1635,22 +1951,23 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
if (ifsta->assocresp_ies)
memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
- /* set AID, ieee80211_set_associated() will tell the driver */
- bss_conf->aid = aid;
- ieee80211_set_associated(dev, ifsta, 1);
+ rcu_read_lock();
/* Add STA entry for the AP */
sta = sta_info_get(local, ifsta->bssid);
if (!sta) {
struct ieee80211_sta_bss *bss;
- sta = sta_info_add(local, dev, ifsta->bssid, GFP_KERNEL);
+ int err;
+
+ sta = sta_info_alloc(sdata, ifsta->bssid, GFP_ATOMIC);
if (!sta) {
- printk(KERN_DEBUG "%s: failed to add STA entry for the"
- " AP\n", dev->name);
+ printk(KERN_DEBUG "%s: failed to alloc STA entry for"
+ " the AP\n", dev->name);
+ rcu_read_unlock();
return;
}
bss = ieee80211_rx_bss_get(dev, ifsta->bssid,
- local->hw.conf.channel,
+ local->hw.conf.channel->center_freq,
ifsta->ssid, ifsta->ssid_len);
if (bss) {
sta->last_rssi = bss->rssi;
@@ -1658,50 +1975,97 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
sta->last_noise = bss->noise;
ieee80211_rx_bss_put(dev, bss);
}
+
+ err = sta_info_insert(sta);
+ if (err) {
+ printk(KERN_DEBUG "%s: failed to insert STA entry for"
+ " the AP (error %d)\n", dev->name, err);
+ rcu_read_unlock();
+ return;
+ }
}
- sta->dev = dev;
- sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP;
+ /*
+ * FIXME: Do we really need to update the sta_info's information here?
+ * We already know about the AP (we found it in our list) so it
+ * should already be filled with the right info, no?
+ * As is stands, all this is racy because typically we assume
+ * the information that is filled in here (except flags) doesn't
+ * change while a STA structure is alive. As such, it should move
+ * to between the sta_info_alloc() and sta_info_insert() above.
+ */
+
+ sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP |
+ WLAN_STA_AUTHORIZED;
rates = 0;
- mode = local->oper_hw_mode;
+ basic_rates = 0;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
for (i = 0; i < elems.supp_rates_len; i++) {
int rate = (elems.supp_rates[i] & 0x7f) * 5;
- for (j = 0; j < mode->num_rates; j++)
- if (mode->rates[j].rate == rate)
+
+ if (rate > 110)
+ have_higher_than_11mbit = true;
+
+ for (j = 0; j < sband->n_bitrates; j++) {
+ if (sband->bitrates[j].bitrate == rate)
rates |= BIT(j);
+ if (elems.supp_rates[i] & 0x80)
+ basic_rates |= BIT(j);
+ }
}
+
for (i = 0; i < elems.ext_supp_rates_len; i++) {
int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
- for (j = 0; j < mode->num_rates; j++)
- if (mode->rates[j].rate == rate)
+
+ if (rate > 110)
+ have_higher_than_11mbit = true;
+
+ for (j = 0; j < sband->n_bitrates; j++) {
+ if (sband->bitrates[j].bitrate == rate)
rates |= BIT(j);
+ if (elems.ext_supp_rates[i] & 0x80)
+ basic_rates |= BIT(j);
+ }
}
- sta->supp_rates = rates;
- if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
- local->ops->conf_ht) {
- struct ieee80211_ht_bss_info bss_info;
+ sta->supp_rates[local->hw.conf.channel->band] = rates;
+ sdata->basic_rates = basic_rates;
+ /* cf. IEEE 802.11 9.2.12 */
+ if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
+ have_higher_than_11mbit)
+ sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
+ else
+ sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
+
+ if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param) {
+ struct ieee80211_ht_bss_info bss_info;
ieee80211_ht_cap_ie_to_ht_info(
(struct ieee80211_ht_cap *)
elems.ht_cap_elem, &sta->ht_info);
ieee80211_ht_addt_info_ie_to_ht_bss_info(
(struct ieee80211_ht_addt_info *)
elems.ht_info_elem, &bss_info);
- ieee80211_hw_config_ht(local, 1, &sta->ht_info, &bss_info);
+ ieee80211_handle_ht(local, 1, &sta->ht_info, &bss_info);
}
rate_control_rate_init(sta, local);
if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
sta->flags |= WLAN_STA_WME;
+ rcu_read_unlock();
ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
elems.wmm_param_len);
- }
-
+ } else
+ rcu_read_unlock();
- sta_info_put(sta);
+ /* set AID and assoc capability,
+ * ieee80211_set_associated() will tell the driver */
+ bss_conf->aid = aid;
+ bss_conf->assoc_capability = capab_info;
+ ieee80211_set_associated(dev, ifsta, 1);
ieee80211_associated(dev, ifsta);
}
@@ -1712,8 +2076,16 @@ static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
struct ieee80211_sta_bss *bss)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
- local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
+ u8 hash_idx;
+
+ if (bss_mesh_cfg(bss))
+ hash_idx = mesh_id_hash(bss_mesh_id(bss),
+ bss_mesh_id_len(bss));
+ else
+ hash_idx = STA_HASH(bss->bssid);
+
+ bss->hnext = local->sta_bss_hash[hash_idx];
+ local->sta_bss_hash[hash_idx] = bss;
}
@@ -1740,7 +2112,7 @@ static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
static struct ieee80211_sta_bss *
-ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int freq,
u8 *ssid, u8 ssid_len)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1752,7 +2124,7 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
atomic_inc(&bss->users);
atomic_inc(&bss->users);
memcpy(bss->bssid, bssid, ETH_ALEN);
- bss->channel = channel;
+ bss->freq = freq;
if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) {
memcpy(bss->ssid, ssid, ssid_len);
bss->ssid_len = ssid_len;
@@ -1766,9 +2138,8 @@ ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid, int channel,
return bss;
}
-
static struct ieee80211_sta_bss *
-ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
+ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int freq,
u8 *ssid, u8 ssid_len)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
@@ -1777,8 +2148,9 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
spin_lock_bh(&local->sta_bss_lock);
bss = local->sta_bss_hash[STA_HASH(bssid)];
while (bss) {
- if (!memcmp(bss->bssid, bssid, ETH_ALEN) &&
- bss->channel == channel &&
+ if (!bss_mesh_cfg(bss) &&
+ !memcmp(bss->bssid, bssid, ETH_ALEN) &&
+ bss->freq == freq &&
bss->ssid_len == ssid_len &&
(ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) {
atomic_inc(&bss->users);
@@ -1790,6 +2162,75 @@ ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid, int channel,
return bss;
}
+#ifdef CONFIG_MAC80211_MESH
+static struct ieee80211_sta_bss *
+ieee80211_rx_mesh_bss_get(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
+ u8 *mesh_cfg, int freq)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sta_bss *bss;
+
+ spin_lock_bh(&local->sta_bss_lock);
+ bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)];
+ while (bss) {
+ if (bss_mesh_cfg(bss) &&
+ !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) &&
+ bss->freq == freq &&
+ mesh_id_len == bss->mesh_id_len &&
+ (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id,
+ mesh_id_len))) {
+ atomic_inc(&bss->users);
+ break;
+ }
+ bss = bss->hnext;
+ }
+ spin_unlock_bh(&local->sta_bss_lock);
+ return bss;
+}
+
+static struct ieee80211_sta_bss *
+ieee80211_rx_mesh_bss_add(struct net_device *dev, u8 *mesh_id, int mesh_id_len,
+ u8 *mesh_cfg, int mesh_config_len, int freq)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ struct ieee80211_sta_bss *bss;
+
+ if (mesh_config_len != MESH_CFG_LEN)
+ return NULL;
+
+ bss = kzalloc(sizeof(*bss), GFP_ATOMIC);
+ if (!bss)
+ return NULL;
+
+ bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC);
+ if (!bss->mesh_cfg) {
+ kfree(bss);
+ return NULL;
+ }
+
+ if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) {
+ bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC);
+ if (!bss->mesh_id) {
+ kfree(bss->mesh_cfg);
+ kfree(bss);
+ return NULL;
+ }
+ memcpy(bss->mesh_id, mesh_id, mesh_id_len);
+ }
+
+ atomic_inc(&bss->users);
+ atomic_inc(&bss->users);
+ memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN);
+ bss->mesh_id_len = mesh_id_len;
+ bss->freq = freq;
+ spin_lock_bh(&local->sta_bss_lock);
+ /* TODO: order by RSSI? */
+ list_add_tail(&bss->list, &local->sta_bss_list);
+ __ieee80211_rx_bss_hash_add(dev, bss);
+ spin_unlock_bh(&local->sta_bss_lock);
+ return bss;
+}
+#endif
static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
{
@@ -1797,6 +2238,8 @@ static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
kfree(bss->rsn_ie);
kfree(bss->wmm_ie);
kfree(bss->ht_ie);
+ kfree(bss_mesh_id(bss));
+ kfree(bss_mesh_cfg(bss));
kfree(bss);
}
@@ -1834,6 +2277,204 @@ void ieee80211_rx_bss_list_deinit(struct net_device *dev)
}
+static int ieee80211_sta_join_ibss(struct net_device *dev,
+ struct ieee80211_if_sta *ifsta,
+ struct ieee80211_sta_bss *bss)
+{
+ struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+ int res, rates, i, j;
+ struct sk_buff *skb;
+ struct ieee80211_mgmt *mgmt;
+ struct ieee80211_tx_control control;
+ struct rate_selection ratesel;
+ u8 *pos;
+ struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_supported_band *sband;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+ sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+ /* Remove possible STA entries from other IBSS networks. */
+ sta_info_flush_delayed(sdata);
+
+ if (local->ops->reset_tsf) {
+ /* Reset own TSF to allow time synchronization work. */
+ local->ops->reset_tsf(local_to_hw(local));
+ }
+ memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
+ res = ieee80211_if_config(dev);
+ if (res)
+ return res;
+
+ local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
+
+ sdata->drop_unencrypted = bss->capability &
+ WLAN_CAPABILITY_PRIVACY ? 1 : 0;
+
+ res = ieee80211_set_freq(local, bss->freq);
+
+ if (local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS) {
+ printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
+ "%d MHz\n", dev->name, local->oper_channel->center_freq);
+ return -1;
+ }
+
+ /* Set beacon template */
+ skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
+ do {
+ if (!skb)
+ break;
+
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+
+ mgmt = (struct ieee80211_mgmt *)
+ skb_put(skb, 24 + sizeof(mgmt->u.beacon));
+ memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_BEACON);
+ memset(mgmt->da, 0xff, ETH_ALEN);
+ memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
+ memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
+ mgmt->u.beacon.beacon_int =
+ cpu_to_le16(local->hw.conf.beacon_int);
+ mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
+
+ pos = skb_put(skb, 2 + ifsta->ssid_len);
+ *pos++ = WLAN_EID_SSID;
+ *pos++ = ifsta->ssid_len;
+ memcpy(pos, ifsta->ssid, ifsta->ssid_len);
+
+ rates = bss->supp_rates_len;
+ if (rates > 8)
+ rates = 8;
+ pos = skb_put(skb, 2 + rates);
+ *pos++ = WLAN_EID_SUPP_RATES;
+ *pos++ = rates;
+ memcpy(pos, bss->supp_rates, rates);
+
+ if (bss->band == IEEE80211_BAND_2GHZ) {
+ pos = skb_put(skb, 2 + 1);
+ *pos++ = WLAN_EID_DS_PARAMS;
+ *pos++ = 1;
+ *pos++ = ieee80211_frequency_to_channel(bss->freq);
+ }
+
+ pos = skb_put(skb, 2 + 2);
+ *pos++ = WLAN_EID_IBSS_PARAMS;
+ *pos++ = 2;
+ /* FIX: set ATIM window based on scan results */
+ *pos++ = 0;
+ *pos++ = 0;
+
+ if (bss->supp_rates_len > 8) {
+ rates = bss->supp_rates_len - 8;
+ pos = skb_put(skb, 2 + rates);
+ *pos++ = WLAN_EID_EXT_SUPP_RATES;
+ *pos++ = rates;
+ memcpy(pos, &bss->supp_rates[8], rates);
+ }
+
+ memset(&control, 0, sizeof(control));
+ rate_control_get_rate(dev, sband, skb, &ratesel);
+ if (!ratesel.rate) {
+ printk(KERN_DEBUG "%s: Failed to determine TX rate "
+ "for IBSS beacon\n", dev->name);
+ break;
+ }
+ control.vif = &sdata->vif;
+ control.tx_rate = ratesel.rate;
+ if (sdata->bss_conf.use_short_preamble &&
+ ratesel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
+ control.flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
+ control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
+ control.flags |= IEEE80211_TXCTL_NO_ACK;
+ control.retry_limit = 1;
+
+ ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
+ if (ifsta->probe_resp) {
+ mgmt = (struct ieee80211_mgmt *)
+ ifsta->probe_resp->data;
+ mgmt->frame_control =
+ IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_PROBE_RESP);
+ } else {
+ printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
+ "template for IBSS\n", dev->name);
+ }
+
+ if (local->ops->beacon_update &&
+ local->ops->beacon_update(local_to_hw(local),
+ skb, &control) == 0) {
+ printk(KERN_DEBUG "%s: Configured IBSS beacon "
+ "template\n", dev->name);
+ skb = NULL;
+ }
+
+ rates = 0;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+ for (i = 0; i < bss->supp_rates_len; i++) {
+ int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
+ for (j = 0; j < sband->n_bitrates; j++)
+ if (sband->bitrates[j].bitrate == bitrate)
+ rates |= BIT(j);
+ }
+ ifsta->supp_rates_bits[local->hw.conf.channel->band] = rates;
+
+ ieee80211_sta_def_wmm_params(dev, bss, 1);
+ } while (0);
+
+ if (skb) {
+ printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
+ "template\n", dev->name);
+ dev_kfree_skb(skb);
+ }
+
+ ifsta->state = IEEE80211_IBSS_JOINED;
+ mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
+
+ ieee80211_rx_bss_put(dev, bss);
+
+ return res;
+}
+
+u64 ieee80211_sta_get_rates(struct ieee80211_local *local,
+ struct ieee802_11_elems *elems,
+ enum ieee80211_band band)
+{
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_rate *bitrates;
+ size_t num_rates;
+ u64 supp_rates;
+ int i, j;
+ sband = local->hw.wiphy->bands[band];
+
+ if (!sband) {
+ WARN_ON(1);
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+ }
+
+ bitrates = sband->bitrates;
+ num_rates = sband->n_bitrates;
+ supp_rates = 0;
+ for (i = 0; i < elems->supp_rates_len +
+ elems->ext_supp_rates_len; i++) {
+ u8 rate = 0;
+ int own_rate;
+ if (i < elems->supp_rates_len)
+ rate = elems->supp_rates[i];
+ else if (elems->ext_supp_rates)
+ rate = elems->ext_supp_rates
+ [i - elems->supp_rates_len];
+ own_rate = 5 * (rate & 0x7f);
+ for (j = 0; j < num_rates; j++)
+ if (bitrates[j].bitrate == own_rate)
+ supp_rates |= BIT(j);
+ }
+ return supp_rates;
+}
+
+
static void ieee80211_rx_bss_info(struct net_device *dev,
struct ieee80211_mgmt *mgmt,
size_t len,
@@ -1843,11 +2484,12 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee802_11_elems elems;
size_t baselen;
- int channel, clen;
+ int freq, clen;
struct ieee80211_sta_bss *bss;
struct sta_info *sta;
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- u64 timestamp;
+ u64 beacon_timestamp, rx_timestamp;
+ struct ieee80211_channel *channel;
DECLARE_MAC_BUF(mac);
DECLARE_MAC_BUF(mac2);
@@ -1864,104 +2506,77 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
if (baselen > len)
return;
- timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
+ beacon_timestamp = le64_to_cpu(mgmt->u.beacon.timestamp);
+ ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
- if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
- memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
-#ifdef CONFIG_MAC80211_IBSS_DEBUG
- static unsigned long last_tsf_debug = 0;
- u64 tsf;
- if (local->ops->get_tsf)
- tsf = local->ops->get_tsf(local_to_hw(local));
- else
- tsf = -1LLU;
- if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
- printk(KERN_DEBUG "RX beacon SA=%s BSSID="
- "%s TSF=0x%llx BCN=0x%llx diff=%lld "
- "@%lu\n",
- print_mac(mac, mgmt->sa), print_mac(mac2, mgmt->bssid),
- (unsigned long long)tsf,
- (unsigned long long)timestamp,
- (unsigned long long)(tsf - timestamp),
- jiffies);
- last_tsf_debug = jiffies;
- }
-#endif /* CONFIG_MAC80211_IBSS_DEBUG */
+ if (ieee80211_vif_is_mesh(&sdata->vif) && elems.mesh_id &&
+ elems.mesh_config && mesh_matches_local(&elems, dev)) {
+ u64 rates = ieee80211_sta_get_rates(local, &elems,
+ rx_status->band);
+
+ mesh_neighbour_update(mgmt->sa, rates, dev,
+ mesh_peer_accepts_plinks(&elems, dev));
}
- ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
+ rcu_read_lock();
if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && elems.supp_rates &&
memcmp(mgmt->bssid, sdata->u.sta.bssid, ETH_ALEN) == 0 &&
(sta = sta_info_get(local, mgmt->sa))) {
- struct ieee80211_hw_mode *mode;
- struct ieee80211_rate *rates;
- size_t num_rates;
- u32 supp_rates, prev_rates;
- int i, j;
-
- mode = local->sta_sw_scanning ?
- local->scan_hw_mode : local->oper_hw_mode;
-
- if (local->sta_hw_scanning) {
- /* search for the correct mode matches the beacon */
- list_for_each_entry(mode, &local->modes_list, list)
- if (mode->mode == rx_status->phymode)
- break;
-
- if (mode == NULL)
- mode = local->oper_hw_mode;
- }
- rates = mode->rates;
- num_rates = mode->num_rates;
-
- supp_rates = 0;
- for (i = 0; i < elems.supp_rates_len +
- elems.ext_supp_rates_len; i++) {
- u8 rate = 0;
- int own_rate;
- if (i < elems.supp_rates_len)
- rate = elems.supp_rates[i];
- else if (elems.ext_supp_rates)
- rate = elems.ext_supp_rates
- [i - elems.supp_rates_len];
- own_rate = 5 * (rate & 0x7f);
- for (j = 0; j < num_rates; j++)
- if (rates[j].rate == own_rate)
- supp_rates |= BIT(j);
- }
+ u64 prev_rates;
+ u64 supp_rates = ieee80211_sta_get_rates(local, &elems,
+ rx_status->band);
- prev_rates = sta->supp_rates;
- sta->supp_rates &= supp_rates;
- if (sta->supp_rates == 0) {
+ prev_rates = sta->supp_rates[rx_status->band];
+ sta->supp_rates[rx_status->band] &= supp_rates;
+ if (sta->supp_rates[rx_status->band] == 0) {
/* No matching rates - this should not really happen.
* Make sure that at least one rate is marked
* supported to avoid issues with TX rate ctrl. */
- sta->supp_rates = sdata->u.sta.supp_rates_bits;
+ sta->supp_rates[rx_status->band] =
+ sdata->u.sta.supp_rates_bits[rx_status->band];
}
- if (sta->supp_rates != prev_rates) {
+ if (sta->supp_rates[rx_status->band] != prev_rates) {
printk(KERN_DEBUG "%s: updated supp_rates set for "
- "%s based on beacon info (0x%x & 0x%x -> "
- "0x%x)\n",
- dev->name, print_mac(mac, sta->addr), prev_rates,
- supp_rates, sta->supp_rates);
+ "%s based on beacon info (0x%llx & 0x%llx -> "
+ "0x%llx)\n",
+ dev->name, print_mac(mac, sta->addr),
+ (unsigned long long) prev_rates,
+ (unsigned long long) supp_rates,
+ (unsigned long long) sta->supp_rates[rx_status->band]);
}
- sta_info_put(sta);
}
- if (!elems.ssid)
- return;
+ rcu_read_unlock();
if (elems.ds_params && elems.ds_params_len == 1)
- channel = elems.ds_params[0];
+ freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
else
- channel = rx_status->channel;
+ freq = rx_status->freq;
- bss = ieee80211_rx_bss_get(dev, mgmt->bssid, channel,
- elems.ssid, elems.ssid_len);
- if (!bss) {
- bss = ieee80211_rx_bss_add(dev, mgmt->bssid, channel,
+ channel = ieee80211_get_channel(local->hw.wiphy, freq);
+
+ if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
+ return;
+
+#ifdef CONFIG_MAC80211_MESH
+ if (elems.mesh_config)
+ bss = ieee80211_rx_mesh_bss_get(dev, elems.mesh_id,
+ elems.mesh_id_len, elems.mesh_config, freq);
+ else
+#endif
+ bss = ieee80211_rx_bss_get(dev, mgmt->bssid, freq,
elems.ssid, elems.ssid_len);
+ if (!bss) {
+#ifdef CONFIG_MAC80211_MESH
+ if (elems.mesh_config)
+ bss = ieee80211_rx_mesh_bss_add(dev, elems.mesh_id,
+ elems.mesh_id_len, elems.mesh_config,
+ elems.mesh_config_len, freq);
+ else
+#endif
+ bss = ieee80211_rx_bss_add(dev, mgmt->bssid, freq,
+ elems.ssid, elems.ssid_len);
if (!bss)
return;
} else {
@@ -1973,18 +2588,29 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
#endif
}
- if (bss->probe_resp && beacon) {
- /* Do not allow beacon to override data from Probe Response. */
- ieee80211_rx_bss_put(dev, bss);
- return;
- }
-
/* save the ERP value so that it is available at association time */
if (elems.erp_info && elems.erp_info_len >= 1) {
bss->erp_value = elems.erp_info[0];
bss->has_erp_value = 1;
}
+ if (elems.ht_cap_elem &&
+ (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
+ memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
+ kfree(bss->ht_ie);
+ bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
+ if (bss->ht_ie) {
+ memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
+ elems.ht_cap_elem_len + 2);
+ bss->ht_ie_len = elems.ht_cap_elem_len + 2;
+ } else
+ bss->ht_ie_len = 0;
+ } else if (!elems.ht_cap_elem && bss->ht_ie) {
+ kfree(bss->ht_ie);
+ bss->ht_ie = NULL;
+ bss->ht_ie_len = 0;
+ }
+
bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
@@ -2006,6 +2632,26 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
bss->supp_rates_len += clen;
}
+ bss->band = rx_status->band;
+
+ bss->timestamp = beacon_timestamp;
+ bss->last_update = jiffies;
+ bss->rssi = rx_status->ssi;
+ bss->signal = rx_status->signal;
+ bss->noise = rx_status->noise;
+ if (!beacon && !bss->probe_resp)
+ bss->probe_resp = true;
+
+ /*
+ * In STA mode, the remaining parameters should not be overridden
+ * by beacons because they're not necessarily accurate there.
+ */
+ if (sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+ bss->probe_resp && beacon) {
+ ieee80211_rx_bss_put(dev, bss);
+ return;
+ }
+
if (elems.wpa &&
(!bss->wpa_ie || bss->wpa_ie_len != elems.wpa_len ||
memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
@@ -2038,6 +2684,20 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
bss->rsn_ie_len = 0;
}
+ /*
+ * Cf.
+ * http://www.wipo.int/pctdb/en/wo.jsp?wo=2007047181&IA=WO2007047181&DISPLAY=DESC
+ *
+ * quoting:
+ *
+ * In particular, "Wi-Fi CERTIFIED for WMM - Support for Multimedia
+ * Applications with Quality of Service in Wi-Fi Networks," Wi- Fi
+ * Alliance (September 1, 2004) is incorporated by reference herein.
+ * The inclusion of the WMM Parameters in probe responses and
+ * association responses is mandatory for WMM enabled networks. The
+ * inclusion of the WMM Parameters in beacons, however, is optional.
+ */
+
if (elems.wmm_param &&
(!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_param_len ||
memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
@@ -2054,44 +2714,62 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
bss->wmm_ie = NULL;
bss->wmm_ie_len = 0;
}
- if (elems.ht_cap_elem &&
- (!bss->ht_ie || bss->ht_ie_len != elems.ht_cap_elem_len ||
- memcmp(bss->ht_ie, elems.ht_cap_elem, elems.ht_cap_elem_len))) {
- kfree(bss->ht_ie);
- bss->ht_ie = kmalloc(elems.ht_cap_elem_len + 2, GFP_ATOMIC);
- if (bss->ht_ie) {
- memcpy(bss->ht_ie, elems.ht_cap_elem - 2,
- elems.ht_cap_elem_len + 2);
- bss->ht_ie_len = elems.ht_cap_elem_len + 2;
- } else
- bss->ht_ie_len = 0;
- } else if (!elems.ht_cap_elem && bss->ht_ie) {
- kfree(bss->ht_ie);
- bss->ht_ie = NULL;
- bss->ht_ie_len = 0;
+
+ /* check if we need to merge IBSS */
+ if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && beacon &&
+ !local->sta_sw_scanning && !local->sta_hw_scanning &&
+ bss->capability & WLAN_CAPABILITY_IBSS &&
+ bss->freq == local->oper_channel->center_freq &&
+ elems.ssid_len == sdata->u.sta.ssid_len &&
+ memcmp(elems.ssid, sdata->u.sta.ssid, sdata->u.sta.ssid_len) == 0) {
+ if (rx_status->flag & RX_FLAG_TSFT) {
+ /* in order for correct IBSS merging we need mactime
+ *
+ * since mactime is defined as the time the first data
+ * symbol of the frame hits the PHY, and the timestamp
+ * of the beacon is defined as "the time that the data
+ * symbol containing the first bit of the timestamp is
+ * transmitted to the PHY plus the transmitting STA’s
+ * delays through its local PHY from the MAC-PHY
+ * interface to its interface with the WM"
+ * (802.11 11.1.2) - equals the time this bit arrives at
+ * the receiver - we have to take into account the
+ * offset between the two.
+ * e.g: at 1 MBit that means mactime is 192 usec earlier
+ * (=24 bytes * 8 usecs/byte) than the beacon timestamp.
+ */
+ int rate = local->hw.wiphy->bands[rx_status->band]->
+ bitrates[rx_status->rate_idx].bitrate;
+ rx_timestamp = rx_status->mactime + (24 * 8 * 10 / rate);
+ } else if (local && local->ops && local->ops->get_tsf)
+ /* second best option: get current TSF */
+ rx_timestamp = local->ops->get_tsf(local_to_hw(local));
+ else
+ /* can't merge without knowing the TSF */
+ rx_timestamp = -1LLU;
+#ifdef CONFIG_MAC80211_IBSS_DEBUG
+ printk(KERN_DEBUG "RX beacon SA=%s BSSID="
+ "%s TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
+ print_mac(mac, mgmt->sa),
+ print_mac(mac2, mgmt->bssid),
+ (unsigned long long)rx_timestamp,
+ (unsigned long long)beacon_timestamp,
+ (unsigned long long)(rx_timestamp - beacon_timestamp),
+ jiffies);
+#endif /* CONFIG_MAC80211_IBSS_DEBUG */
+ if (beacon_timestamp > rx_timestamp) {
+#ifndef CONFIG_MAC80211_IBSS_DEBUG
+ if (net_ratelimit())
+#endif
+ printk(KERN_DEBUG "%s: beacon TSF higher than "
+ "local TSF - IBSS merge with BSSID %s\n",
+ dev->name, print_mac(mac, mgmt->bssid));
+ ieee80211_sta_join_ibss(dev, &sdata->u.sta, bss);
+ ieee80211_ibss_add_sta(dev, NULL,
+ mgmt->bssid, mgmt->sa);
+ }
}
- bss->hw_mode = rx_status->phymode;
- bss->freq = rx_status->freq;
- if (channel != rx_status->channel &&
- (bss->hw_mode == MODE_IEEE80211G ||
- bss->hw_mode == MODE_IEEE80211B) &&
- channel >= 1 && channel <= 14) {
- static const int freq_list[] = {
- 2412, 2417, 2422, 2427, 2432, 2437, 2442,
- 2447, 2452, 2457, 2462, 2467, 2472, 2484
- };
- /* IEEE 802.11g/b mode can receive packets from neighboring
- * channels, so map the channel into frequency. */
- bss->freq = freq_list[channel - 1];
- }
- bss->timestamp = timestamp;
- bss->last_update = jiffies;
- bss->rssi = rx_status->ssi;
- bss->signal = rx_status->signal;
- bss->noise = rx_status->noise;
- if (!beacon)
- bss->probe_resp++;
ieee80211_rx_bss_put(dev, bss);
}
@@ -2136,6 +2814,17 @@ static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems);
+ if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
+ ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
+ elems.wmm_param_len);
+ }
+
+ /* Do not send changes to driver if we are scanning. This removes
+ * requirement that driver's bss_info_changed function needs to be
+ * atomic. */
+ if (local->sta_sw_scanning || local->sta_hw_scanning)
+ return;
+
if (elems.erp_info && elems.erp_info_len >= 1)
changed |= ieee80211_handle_erp_ie(sdata, elems.erp_info[0]);
else {
@@ -2145,25 +2834,14 @@ static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
}
if (elems.ht_cap_elem && elems.ht_info_elem &&
- elems.wmm_param && local->ops->conf_ht &&
- conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
+ elems.wmm_param && conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) {
struct ieee80211_ht_bss_info bss_info;
ieee80211_ht_addt_info_ie_to_ht_bss_info(
(struct ieee80211_ht_addt_info *)
elems.ht_info_elem, &bss_info);
- /* check if AP changed bss inforamation */
- if ((conf->ht_bss_conf.primary_channel !=
- bss_info.primary_channel) ||
- (conf->ht_bss_conf.bss_cap != bss_info.bss_cap) ||
- (conf->ht_bss_conf.bss_op_mode != bss_info.bss_op_mode))
- ieee80211_hw_config_ht(local, 1, &conf->ht_conf,
- &bss_info);
- }
-
- if (elems.wmm_param && (ifsta->flags & IEEE80211_STA_WMM_ENABLED)) {
- ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
- elems.wmm_param_len);
+ changed |= ieee80211_handle_ht(local, 1, &conf->ht_conf,
+ &bss_info);
}
ieee80211_bss_info_change_notify(sdata, changed);
@@ -2247,8 +2925,11 @@ static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
static void ieee80211_rx_mgmt_action(struct net_device *dev,
struct ieee80211_if_sta *ifsta,
struct ieee80211_mgmt *mgmt,
- size_t len)
+ size_t len,
+ struct ieee80211_rx_status *rx_status)
{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
if (len < IEEE80211_MIN_ACTION_SIZE)
return;
@@ -2261,6 +2942,12 @@ static void ieee80211_rx_mgmt_action(struct net_device *dev,
break;
ieee80211_sta_process_addba_request(dev, mgmt, len);
break;
+ case WLAN_ACTION_ADDBA_RESP:
+ if (len < (IEEE80211_MIN_ACTION_SIZE +
+ sizeof(mgmt->u.action.u.addba_resp)))
+ break;
+ ieee80211_sta_process_addba_resp(dev, mgmt, len);
+ break;
case WLAN_ACTION_DELBA:
if (len < (IEEE80211_MIN_ACTION_SIZE +
sizeof(mgmt->u.action.u.delba)))
@@ -2274,7 +2961,18 @@ static void ieee80211_rx_mgmt_action(struct net_device *dev,
break;
}
break;
+ case PLINK_CATEGORY:
+ if (ieee80211_vif_is_mesh(&sdata->vif))
+ mesh_rx_plink_frame(dev, mgmt, len, rx_status);
+ break;
+ case MESH_PATH_SEL_CATEGORY:
+ if (ieee80211_vif_is_mesh(&sdata->vif))
+ mesh_rx_path_sel_frame(dev, mgmt, len);
+ break;
default:
+ if (net_ratelimit())
+ printk(KERN_DEBUG "%s: Rx unknown action frame - "
+ "category=%d\n", dev->name, mgmt->u.action.category);
break;
}
}
@@ -2301,13 +2999,13 @@ void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
case IEEE80211_STYPE_PROBE_REQ:
case IEEE80211_STYPE_PROBE_RESP:
case IEEE80211_STYPE_BEACON:
+ case IEEE80211_STYPE_ACTION:
memcpy(skb->cb, rx_status, sizeof(*rx_status));
case IEEE80211_STYPE_AUTH:
case IEEE80211_STYPE_ASSOC_RESP:
case IEEE80211_STYPE_REASSOC_RESP:
case IEEE80211_STYPE_DEAUTH:
case IEEE80211_STYPE_DISASSOC:
- case IEEE80211_STYPE_ACTION:
skb_queue_tail(&ifsta->skb_queue, skb);
queue_work(local->hw.workqueue, &ifsta->work);
return;
@@ -2366,7 +3064,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len);
break;
case IEEE80211_STYPE_ACTION:
- ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len);
+ ieee80211_rx_mgmt_action(dev, ifsta, mgmt, skb->len, rx_status);
break;
}
@@ -2374,7 +3072,7 @@ static void ieee80211_sta_rx_queued_mgmt(struct net_device *dev,
}
-ieee80211_txrx_result
+ieee80211_rx_result
ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
struct ieee80211_rx_status *rx_status)
{
@@ -2382,31 +3080,31 @@ ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
u16 fc;
if (skb->len < 2)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
mgmt = (struct ieee80211_mgmt *) skb->data;
fc = le16_to_cpu(mgmt->frame_control);
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL)
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if (skb->len < 24)
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP) {
ieee80211_rx_mgmt_probe_resp(dev, mgmt,
skb->len, rx_status);
dev_kfree_skb(skb);
- return TXRX_QUEUED;
+ return RX_QUEUED;
} else if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON) {
ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
rx_status);
dev_kfree_skb(skb);
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
@@ -2415,45 +3113,46 @@ static int ieee80211_sta_active_ibss(struct net_device *dev)
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
int active = 0;
struct sta_info *sta;
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+ rcu_read_lock();
- read_lock_bh(&local->sta_lock);
- list_for_each_entry(sta, &local->sta_list, list) {
- if (sta->dev == dev &&
+ list_for_each_entry_rcu(sta, &local->sta_list, list) {
+ if (sta->sdata == sdata &&
time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
jiffies)) {
active++;
break;
}
}
- read_unlock_bh(&local->sta_lock);
+
+ rcu_read_unlock();
return active;
}
-static void ieee80211_sta_expire(struct net_device *dev)
+static void ieee80211_sta_expire(struct net_device *dev, unsigned long exp_time)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct sta_info *sta, *tmp;
LIST_HEAD(tmp_list);
DECLARE_MAC_BUF(mac);
+ unsigned long flags;
- write_lock_bh(&local->sta_lock);
+ spin_lock_irqsave(&local->sta_lock, flags);
list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
- if (time_after(jiffies, sta->last_rx +
- IEEE80211_IBSS_INACTIVITY_LIMIT)) {
+ if (time_after(jiffies, sta->last_rx + exp_time)) {
printk(KERN_DEBUG "%s: expiring inactive STA %s\n",
dev->name, print_mac(mac, sta->addr));
- __sta_info_get(sta);
- sta_info_remove(sta);
- list_add(&sta->list, &tmp_list);
+ __sta_info_unlink(&sta);
+ if (sta)
+ list_add(&sta->list, &tmp_list);
}
- write_unlock_bh(&local->sta_lock);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
- list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
- sta_info_free(sta);
- sta_info_put(sta);
- }
+ list_for_each_entry_safe(sta, tmp, &tmp_list, list)
+ sta_info_destroy(sta);
}
@@ -2462,7 +3161,7 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
{
mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
- ieee80211_sta_expire(dev);
+ ieee80211_sta_expire(dev, IEEE80211_IBSS_INACTIVITY_LIMIT);
if (ieee80211_sta_active_ibss(dev))
return;
@@ -2472,6 +3171,36 @@ static void ieee80211_sta_merge_ibss(struct net_device *dev,
}
+#ifdef CONFIG_MAC80211_MESH
+static void ieee80211_mesh_housekeeping(struct net_device *dev,
+ struct ieee80211_if_sta *ifsta)
+{
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ bool free_plinks;
+
+ ieee80211_sta_expire(dev, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
+ mesh_path_expire(dev);
+
+ free_plinks = mesh_plink_availables(sdata);
+ if (free_plinks != sdata->u.sta.accepting_plinks)
+ ieee80211_if_config_beacon(dev);
+
+ mod_timer(&ifsta->timer, jiffies +
+ IEEE80211_MESH_HOUSEKEEPING_INTERVAL);
+}
+
+
+void ieee80211_start_mesh(struct net_device *dev)
+{
+ struct ieee80211_if_sta *ifsta;
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ ifsta = &sdata->u.sta;
+ ifsta->state = IEEE80211_MESH_UP;
+ ieee80211_sta_timer((unsigned long)sdata);
+}
+#endif
+
+
void ieee80211_sta_timer(unsigned long data)
{
struct ieee80211_sub_if_data *sdata =
@@ -2483,7 +3212,6 @@ void ieee80211_sta_timer(unsigned long data)
queue_work(local->hw.workqueue, &ifsta->work);
}
-
void ieee80211_sta_work(struct work_struct *work)
{
struct ieee80211_sub_if_data *sdata =
@@ -2500,7 +3228,8 @@ void ieee80211_sta_work(struct work_struct *work)
return;
if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
- sdata->vif.type != IEEE80211_IF_TYPE_IBSS) {
+ sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+ sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) {
printk(KERN_DEBUG "%s: ieee80211_sta_work: non-STA interface "
"(type=%d)\n", dev->name, sdata->vif.type);
return;
@@ -2510,6 +3239,13 @@ void ieee80211_sta_work(struct work_struct *work)
while ((skb = skb_dequeue(&ifsta->skb_queue)))
ieee80211_sta_rx_queued_mgmt(dev, skb);
+#ifdef CONFIG_MAC80211_MESH
+ if (ifsta->preq_queue_len &&
+ time_after(jiffies,
+ ifsta->last_preq + msecs_to_jiffies(ifsta->mshcfg.dot11MeshHWMPpreqMinInterval)))
+ mesh_path_start_discovery(dev);
+#endif
+
if (ifsta->state != IEEE80211_AUTHENTICATE &&
ifsta->state != IEEE80211_ASSOCIATE &&
test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request)) {
@@ -2545,6 +3281,11 @@ void ieee80211_sta_work(struct work_struct *work)
case IEEE80211_IBSS_JOINED:
ieee80211_sta_merge_ibss(dev, ifsta);
break;
+#ifdef CONFIG_MAC80211_MESH
+ case IEEE80211_MESH_UP:
+ ieee80211_mesh_housekeeping(dev, ifsta);
+ break;
+#endif
default:
printk(KERN_DEBUG "ieee80211_sta_work: Unknown state %d\n",
ifsta->state);
@@ -2655,7 +3396,7 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
}
spin_lock_bh(&local->sta_bss_lock);
- freq = local->oper_channel->freq;
+ freq = local->oper_channel->center_freq;
list_for_each_entry(bss, &local->sta_bss_list, list) {
if (!(bss->capability & WLAN_CAPABILITY_ESS))
continue;
@@ -2686,11 +3427,12 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
spin_unlock_bh(&local->sta_bss_lock);
if (selected) {
- ieee80211_set_channel(local, -1, selected->freq);
+ ieee80211_set_freq(local, selected->freq);
if (!(ifsta->flags & IEEE80211_STA_SSID_SET))
ieee80211_sta_set_ssid(dev, selected->ssid,
selected->ssid_len);
ieee80211_sta_set_bssid(dev, selected->bssid);
+ ieee80211_sta_def_wmm_params(dev, selected, 0);
ieee80211_rx_bss_put(dev, selected);
ifsta->state = IEEE80211_AUTHENTICATE;
ieee80211_sta_reset_auth(dev, ifsta);
@@ -2710,162 +3452,6 @@ static int ieee80211_sta_config_auth(struct net_device *dev,
return -1;
}
-static int ieee80211_sta_join_ibss(struct net_device *dev,
- struct ieee80211_if_sta *ifsta,
- struct ieee80211_sta_bss *bss)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- int res, rates, i, j;
- struct sk_buff *skb;
- struct ieee80211_mgmt *mgmt;
- struct ieee80211_tx_control control;
- struct ieee80211_hw_mode *mode;
- struct rate_selection ratesel;
- u8 *pos;
- struct ieee80211_sub_if_data *sdata;
-
- /* Remove possible STA entries from other IBSS networks. */
- sta_info_flush(local, NULL);
-
- if (local->ops->reset_tsf) {
- /* Reset own TSF to allow time synchronization work. */
- local->ops->reset_tsf(local_to_hw(local));
- }
- memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
- res = ieee80211_if_config(dev);
- if (res)
- return res;
-
- local->hw.conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
-
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- sdata->drop_unencrypted = bss->capability &
- WLAN_CAPABILITY_PRIVACY ? 1 : 0;
-
- res = ieee80211_set_channel(local, -1, bss->freq);
-
- if (!(local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)) {
- printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
- "(%d MHz)\n", dev->name, local->hw.conf.channel,
- local->hw.conf.freq);
- return -1;
- }
-
- /* Set beacon template based on scan results */
- skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400);
- do {
- if (!skb)
- break;
-
- skb_reserve(skb, local->hw.extra_tx_headroom);
-
- mgmt = (struct ieee80211_mgmt *)
- skb_put(skb, 24 + sizeof(mgmt->u.beacon));
- memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
- mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
- IEEE80211_STYPE_BEACON);
- memset(mgmt->da, 0xff, ETH_ALEN);
- memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
- memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
- mgmt->u.beacon.beacon_int =
- cpu_to_le16(local->hw.conf.beacon_int);
- mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
-
- pos = skb_put(skb, 2 + ifsta->ssid_len);
- *pos++ = WLAN_EID_SSID;
- *pos++ = ifsta->ssid_len;
- memcpy(pos, ifsta->ssid, ifsta->ssid_len);
-
- rates = bss->supp_rates_len;
- if (rates > 8)
- rates = 8;
- pos = skb_put(skb, 2 + rates);
- *pos++ = WLAN_EID_SUPP_RATES;
- *pos++ = rates;
- memcpy(pos, bss->supp_rates, rates);
-
- pos = skb_put(skb, 2 + 1);
- *pos++ = WLAN_EID_DS_PARAMS;
- *pos++ = 1;
- *pos++ = bss->channel;
-
- pos = skb_put(skb, 2 + 2);
- *pos++ = WLAN_EID_IBSS_PARAMS;
- *pos++ = 2;
- /* FIX: set ATIM window based on scan results */
- *pos++ = 0;
- *pos++ = 0;
-
- if (bss->supp_rates_len > 8) {
- rates = bss->supp_rates_len - 8;
- pos = skb_put(skb, 2 + rates);
- *pos++ = WLAN_EID_EXT_SUPP_RATES;
- *pos++ = rates;
- memcpy(pos, &bss->supp_rates[8], rates);
- }
-
- memset(&control, 0, sizeof(control));
- rate_control_get_rate(dev, local->oper_hw_mode, skb, &ratesel);
- if (!ratesel.rate) {
- printk(KERN_DEBUG "%s: Failed to determine TX rate "
- "for IBSS beacon\n", dev->name);
- break;
- }
- control.vif = &sdata->vif;
- control.tx_rate =
- (sdata->bss_conf.use_short_preamble &&
- (ratesel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
- ratesel.rate->val2 : ratesel.rate->val;
- control.antenna_sel_tx = local->hw.conf.antenna_sel_tx;
- control.power_level = local->hw.conf.power_level;
- control.flags |= IEEE80211_TXCTL_NO_ACK;
- control.retry_limit = 1;
-
- ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
- if (ifsta->probe_resp) {
- mgmt = (struct ieee80211_mgmt *)
- ifsta->probe_resp->data;
- mgmt->frame_control =
- IEEE80211_FC(IEEE80211_FTYPE_MGMT,
- IEEE80211_STYPE_PROBE_RESP);
- } else {
- printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
- "template for IBSS\n", dev->name);
- }
-
- if (local->ops->beacon_update &&
- local->ops->beacon_update(local_to_hw(local),
- skb, &control) == 0) {
- printk(KERN_DEBUG "%s: Configured IBSS beacon "
- "template based on scan results\n", dev->name);
- skb = NULL;
- }
-
- rates = 0;
- mode = local->oper_hw_mode;
- for (i = 0; i < bss->supp_rates_len; i++) {
- int bitrate = (bss->supp_rates[i] & 0x7f) * 5;
- for (j = 0; j < mode->num_rates; j++)
- if (mode->rates[j].rate == bitrate)
- rates |= BIT(j);
- }
- ifsta->supp_rates_bits = rates;
- } while (0);
-
- if (skb) {
- printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
- "template\n", dev->name);
- dev_kfree_skb(skb);
- }
-
- ifsta->state = IEEE80211_IBSS_JOINED;
- mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
-
- ieee80211_rx_bss_put(dev, bss);
-
- return res;
-}
-
static int ieee80211_sta_create_ibss(struct net_device *dev,
struct ieee80211_if_sta *ifsta)
@@ -2873,7 +3459,7 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct ieee80211_sta_bss *bss;
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
u8 bssid[ETH_ALEN], *pos;
int i;
DECLARE_MAC_BUF(mac);
@@ -2895,28 +3481,28 @@ static int ieee80211_sta_create_ibss(struct net_device *dev,
printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %s\n",
dev->name, print_mac(mac, bssid));
- bss = ieee80211_rx_bss_add(dev, bssid, local->hw.conf.channel,
+ bss = ieee80211_rx_bss_add(dev, bssid,
+ local->hw.conf.channel->center_freq,
sdata->u.sta.ssid, sdata->u.sta.ssid_len);
if (!bss)
return -ENOMEM;
- mode = local->oper_hw_mode;
+ bss->band = local->hw.conf.channel->band;
+ sband = local->hw.wiphy->bands[bss->band];
if (local->hw.conf.beacon_int == 0)
- local->hw.conf.beacon_int = 100;
+ local->hw.conf.beacon_int = 10000;
bss->beacon_int = local->hw.conf.beacon_int;
- bss->hw_mode = local->hw.conf.phymode;
- bss->freq = local->hw.conf.freq;
bss->last_update = jiffies;
bss->capability = WLAN_CAPABILITY_IBSS;
if (sdata->default_key) {
bss->capability |= WLAN_CAPABILITY_PRIVACY;
} else
sdata->drop_unencrypted = 0;
- bss->supp_rates_len = mode->num_rates;
+ bss->supp_rates_len = sband->n_bitrates;
pos = bss->supp_rates;
- for (i = 0; i < mode->num_rates; i++) {
- int rate = mode->rates[i].rate;
+ for (i = 0; i < sband->n_bitrates; i++) {
+ int rate = sband->bitrates[i].bitrate;
*pos++ = (u8) (rate / 5);
}
@@ -2965,7 +3551,8 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
"%s\n", print_mac(mac, bssid), print_mac(mac2, ifsta->bssid));
#endif /* CONFIG_MAC80211_IBSS_DEBUG */
if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
- (bss = ieee80211_rx_bss_get(dev, bssid, local->hw.conf.channel,
+ (bss = ieee80211_rx_bss_get(dev, bssid,
+ local->hw.conf.channel->center_freq,
ifsta->ssid, ifsta->ssid_len))) {
printk(KERN_DEBUG "%s: Selected IBSS BSSID %s"
" based on configured SSID\n",
@@ -2993,13 +3580,13 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
if (time_after(jiffies, ifsta->ibss_join_req +
IEEE80211_IBSS_JOIN_TIMEOUT)) {
if ((ifsta->flags & IEEE80211_STA_CREATE_IBSS) &&
- local->oper_channel->flag & IEEE80211_CHAN_W_IBSS)
+ (!(local->oper_channel->flags &
+ IEEE80211_CHAN_NO_IBSS)))
return ieee80211_sta_create_ibss(dev, ifsta);
if (ifsta->flags & IEEE80211_STA_CREATE_IBSS) {
- printk(KERN_DEBUG "%s: IBSS not allowed on the"
- " configured channel %d (%d MHz)\n",
- dev->name, local->hw.conf.channel,
- local->hw.conf.freq);
+ printk(KERN_DEBUG "%s: IBSS not allowed on"
+ " %d MHz\n", dev->name,
+ local->hw.conf.channel->center_freq);
}
/* No IBSS found - decrease scan interval and continue
@@ -3018,41 +3605,12 @@ static int ieee80211_sta_find_ibss(struct net_device *dev,
int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
{
- struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct ieee80211_if_sta *ifsta;
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
if (len > IEEE80211_MAX_SSID_LEN)
return -EINVAL;
- /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
- * not defined. */
- if (local->ops->conf_tx) {
- struct ieee80211_tx_queue_params qparam;
- int i;
-
- memset(&qparam, 0, sizeof(qparam));
- /* TODO: are these ok defaults for all hw_modes? */
- qparam.aifs = 2;
- qparam.cw_min =
- local->hw.conf.phymode == MODE_IEEE80211B ? 31 : 15;
- qparam.cw_max = 1023;
- qparam.burst_time = 0;
- for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
- {
- local->ops->conf_tx(local_to_hw(local),
- i + IEEE80211_TX_QUEUE_DATA0,
- &qparam);
- }
- /* IBSS uses different parameters for Beacon sending */
- qparam.cw_min++;
- qparam.cw_min *= 2;
- qparam.cw_min--;
- local->ops->conf_tx(local_to_hw(local),
- IEEE80211_TX_QUEUE_BEACON, &qparam);
- }
-
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
ifsta = &sdata->u.sta;
if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
@@ -3144,6 +3702,13 @@ static void ieee80211_send_nullfunc(struct ieee80211_local *local,
}
+static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
+{
+ if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
+ ieee80211_vif_is_mesh(&sdata->vif))
+ ieee80211_sta_timer((unsigned long)sdata);
+}
+
void ieee80211_scan_completed(struct ieee80211_hw *hw)
{
struct ieee80211_local *local = hw_to_local(hw);
@@ -3157,6 +3722,15 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
if (local->sta_hw_scanning) {
local->sta_hw_scanning = 0;
+ if (ieee80211_hw_config(local))
+ printk(KERN_DEBUG "%s: failed to restore operational "
+ "channel after scan\n", dev->name);
+ /* Restart STA timer for HW scan case */
+ rcu_read_lock();
+ list_for_each_entry_rcu(sdata, &local->interfaces, list)
+ ieee80211_restart_sta_timer(sdata);
+ rcu_read_unlock();
+
goto done;
}
@@ -3183,11 +3757,12 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw)
if (sdata->dev == local->mdev)
continue;
- if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
- if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
- ieee80211_send_nullfunc(local, sdata, 0);
- ieee80211_sta_timer((unsigned long)sdata);
- }
+ /* Tell AP we're back */
+ if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
+ sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED)
+ ieee80211_send_nullfunc(local, sdata, 0);
+
+ ieee80211_restart_sta_timer(sdata);
netif_wake_queue(sdata->dev);
}
@@ -3211,7 +3786,7 @@ void ieee80211_sta_scan_work(struct work_struct *work)
container_of(work, struct ieee80211_local, scan_work.work);
struct net_device *dev = local->scan_dev;
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
struct ieee80211_channel *chan;
int skip;
unsigned long next_delay = 0;
@@ -3221,44 +3796,59 @@ void ieee80211_sta_scan_work(struct work_struct *work)
switch (local->scan_state) {
case SCAN_SET_CHANNEL:
- mode = local->scan_hw_mode;
- if (local->scan_hw_mode->list.next == &local->modes_list &&
- local->scan_channel_idx >= mode->num_channels) {
+ /*
+ * Get current scan band. scan_band may be IEEE80211_NUM_BANDS
+ * after we successfully scanned the last channel of the last
+ * band (and the last band is supported by the hw)
+ */
+ if (local->scan_band < IEEE80211_NUM_BANDS)
+ sband = local->hw.wiphy->bands[local->scan_band];
+ else
+ sband = NULL;
+
+ /*
+ * If we are at an unsupported band and have more bands
+ * left to scan, advance to the next supported one.
+ */
+ while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) {
+ local->scan_band++;
+ sband = local->hw.wiphy->bands[local->scan_band];
+ local->scan_channel_idx = 0;
+ }
+
+ /* if no more bands/channels left, complete scan */
+ if (!sband || local->scan_channel_idx >= sband->n_channels) {
ieee80211_scan_completed(local_to_hw(local));
return;
}
- skip = !(local->enabled_modes & (1 << mode->mode));
- chan = &mode->channels[local->scan_channel_idx];
- if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
+ skip = 0;
+ chan = &sband->channels[local->scan_channel_idx];
+
+ if (chan->flags & IEEE80211_CHAN_DISABLED ||
(sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
- !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
- (local->hw_modes & local->enabled_modes &
- (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
+ chan->flags & IEEE80211_CHAN_NO_IBSS))
skip = 1;
if (!skip) {
-#if 0
- printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
- dev->name, chan->chan, chan->freq);
-#endif
-
local->scan_channel = chan;
if (ieee80211_hw_config(local)) {
- printk(KERN_DEBUG "%s: failed to set channel "
- "%d (%d MHz) for scan\n", dev->name,
- chan->chan, chan->freq);
+ printk(KERN_DEBUG "%s: failed to set freq to "
+ "%d MHz for scan\n", dev->name,
+ chan->center_freq);
skip = 1;
}
}
+ /* advance state machine to next channel/band */
local->scan_channel_idx++;
- if (local->scan_channel_idx >= local->scan_hw_mode->num_channels) {
- if (local->scan_hw_mode->list.next != &local->modes_list) {
- local->scan_hw_mode = list_entry(local->scan_hw_mode->list.next,
- struct ieee80211_hw_mode,
- list);
- local->scan_channel_idx = 0;
- }
+ if (local->scan_channel_idx >= sband->n_channels) {
+ /*
+ * scan_band may end up == IEEE80211_NUM_BANDS, but
+ * we'll catch that case above and complete the scan
+ * if that is the case.
+ */
+ local->scan_band++;
+ local->scan_channel_idx = 0;
}
if (skip)
@@ -3269,13 +3859,14 @@ void ieee80211_sta_scan_work(struct work_struct *work)
local->scan_state = SCAN_SEND_PROBE;
break;
case SCAN_SEND_PROBE:
- if (local->scan_channel->flag & IEEE80211_CHAN_W_ACTIVE_SCAN) {
- ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
- local->scan_ssid_len);
- next_delay = IEEE80211_CHANNEL_TIME;
- } else
- next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
+ next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
local->scan_state = SCAN_SET_CHANNEL;
+
+ if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN)
+ break;
+ ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
+ local->scan_ssid_len);
+ next_delay = IEEE80211_CHANNEL_TIME;
break;
}
@@ -3350,10 +3941,8 @@ static int ieee80211_sta_start_scan(struct net_device *dev,
} else
local->scan_ssid_len = 0;
local->scan_state = SCAN_SET_CHANNEL;
- local->scan_hw_mode = list_entry(local->modes_list.next,
- struct ieee80211_hw_mode,
- list);
local->scan_channel_idx = 0;
+ local->scan_band = IEEE80211_BAND_2GHZ;
local->scan_dev = dev;
netif_tx_lock_bh(local->mdev);
@@ -3408,9 +3997,6 @@ ieee80211_sta_scan_result(struct net_device *dev,
bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
return current_ev;
- if (!(local->enabled_modes & (1 << bss->hw_mode)))
- return current_ev;
-
memset(&iwe, 0, sizeof(iwe));
iwe.cmd = SIOCGIWAP;
iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
@@ -3420,15 +4006,25 @@ ieee80211_sta_scan_result(struct net_device *dev,
memset(&iwe, 0, sizeof(iwe));
iwe.cmd = SIOCGIWESSID;
- iwe.u.data.length = bss->ssid_len;
- iwe.u.data.flags = 1;
- current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
- bss->ssid);
+ if (bss_mesh_cfg(bss)) {
+ iwe.u.data.length = bss_mesh_id_len(bss);
+ iwe.u.data.flags = 1;
+ current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
+ bss_mesh_id(bss));
+ } else {
+ iwe.u.data.length = bss->ssid_len;
+ iwe.u.data.flags = 1;
+ current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
+ bss->ssid);
+ }
- if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
+ if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)
+ || bss_mesh_cfg(bss)) {
memset(&iwe, 0, sizeof(iwe));
iwe.cmd = SIOCGIWMODE;
- if (bss->capability & WLAN_CAPABILITY_ESS)
+ if (bss_mesh_cfg(bss))
+ iwe.u.mode = IW_MODE_MESH;
+ else if (bss->capability & WLAN_CAPABILITY_ESS)
iwe.u.mode = IW_MODE_MASTER;
else
iwe.u.mode = IW_MODE_ADHOC;
@@ -3438,12 +4034,15 @@ ieee80211_sta_scan_result(struct net_device *dev,
memset(&iwe, 0, sizeof(iwe));
iwe.cmd = SIOCGIWFREQ;
- iwe.u.freq.m = bss->channel;
- iwe.u.freq.e = 0;
+ iwe.u.freq.m = bss->freq;
+ iwe.u.freq.e = 6;
current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
IW_EV_FREQ_LEN);
- iwe.u.freq.m = bss->freq * 100000;
- iwe.u.freq.e = 1;
+
+ memset(&iwe, 0, sizeof(iwe));
+ iwe.cmd = SIOCGIWFREQ;
+ iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq);
+ iwe.u.freq.e = 0;
current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
IW_EV_FREQ_LEN);
@@ -3514,6 +4113,45 @@ ieee80211_sta_scan_result(struct net_device *dev,
}
}
+ if (bss_mesh_cfg(bss)) {
+ char *buf;
+ u8 *cfg = bss_mesh_cfg(bss);
+ buf = kmalloc(50, GFP_ATOMIC);
+ if (buf) {
+ memset(&iwe, 0, sizeof(iwe));
+ iwe.cmd = IWEVCUSTOM;
+ sprintf(buf, "Mesh network (version %d)", cfg[0]);
+ iwe.u.data.length = strlen(buf);
+ current_ev = iwe_stream_add_point(current_ev, end_buf,
+ &iwe, buf);
+ sprintf(buf, "Path Selection Protocol ID: "
+ "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3],
+ cfg[4]);
+ iwe.u.data.length = strlen(buf);
+ current_ev = iwe_stream_add_point(current_ev, end_buf,
+ &iwe, buf);
+ sprintf(buf, "Path Selection Metric ID: "
+ "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7],
+ cfg[8]);
+ iwe.u.data.length = strlen(buf);
+ current_ev = iwe_stream_add_point(current_ev, end_buf,
+ &iwe, buf);
+ sprintf(buf, "Congestion Control Mode ID: "
+ "0x%02X%02X%02X%02X", cfg[9], cfg[10],
+ cfg[11], cfg[12]);
+ iwe.u.data.length = strlen(buf);
+ current_ev = iwe_stream_add_point(current_ev, end_buf,
+ &iwe, buf);
+ sprintf(buf, "Channel Precedence: "
+ "0x%02X%02X%02X%02X", cfg[13], cfg[14],
+ cfg[15], cfg[16]);
+ iwe.u.data.length = strlen(buf);
+ current_ev = iwe_stream_add_point(current_ev, end_buf,
+ &iwe, buf);
+ kfree(buf);
+ }
+ }
+
return current_ev;
}
@@ -3582,15 +4220,21 @@ struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
printk(KERN_DEBUG "%s: Adding new IBSS station %s (dev=%s)\n",
wiphy_name(local->hw.wiphy), print_mac(mac, addr), dev->name);
- sta = sta_info_add(local, dev, addr, GFP_ATOMIC);
+ sta = sta_info_alloc(sdata, addr, GFP_ATOMIC);
if (!sta)
return NULL;
- sta->supp_rates = sdata->u.sta.supp_rates_bits;
+ sta->flags |= WLAN_STA_AUTHORIZED;
+
+ sta->supp_rates[local->hw.conf.channel->band] =
+ sdata->u.sta.supp_rates_bits[local->hw.conf.channel->band];
rate_control_rate_init(sta, local);
- return sta; /* caller will call sta_info_put() */
+ if (sta_info_insert(sta))
+ return NULL;
+
+ return sta;
}
@@ -3630,3 +4274,26 @@ int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
ieee80211_set_disassoc(dev, ifsta, 0);
return 0;
}
+
+void ieee80211_notify_mac(struct ieee80211_hw *hw,
+ enum ieee80211_notification_types notif_type)
+{
+ struct ieee80211_local *local = hw_to_local(hw);
+ struct ieee80211_sub_if_data *sdata;
+
+ switch (notif_type) {
+ case IEEE80211_NOTIFY_RE_ASSOC:
+ rcu_read_lock();
+ list_for_each_entry_rcu(sdata, &local->interfaces, list) {
+
+ if (sdata->vif.type == IEEE80211_IF_TYPE_STA) {
+ ieee80211_sta_req_auth(sdata->dev,
+ &sdata->u.sta);
+ }
+
+ }
+ rcu_read_unlock();
+ break;
+ }
+}
+EXPORT_SYMBOL(ieee80211_notify_mac);
diff --git a/net/mac80211/ieee80211_rate.c b/net/mac80211/rate.c
index b957e67c5fba..841df93807fc 100644
--- a/net/mac80211/ieee80211_rate.c
+++ b/net/mac80211/rate.c
@@ -10,7 +10,7 @@
#include <linux/kernel.h>
#include <linux/rtnetlink.h>
-#include "ieee80211_rate.h"
+#include "rate.h"
#include "ieee80211_i.h"
struct rate_control_alg {
@@ -163,34 +163,37 @@ static void rate_control_release(struct kref *kref)
}
void rate_control_get_rate(struct net_device *dev,
- struct ieee80211_hw_mode *mode, struct sk_buff *skb,
+ struct ieee80211_supported_band *sband,
+ struct sk_buff *skb,
struct rate_selection *sel)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct rate_control_ref *ref = local->rate_ctrl;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct sta_info *sta = sta_info_get(local, hdr->addr1);
+ struct sta_info *sta;
int i;
+ rcu_read_lock();
+ sta = sta_info_get(local, hdr->addr1);
+
memset(sel, 0, sizeof(struct rate_selection));
- ref->ops->get_rate(ref->priv, dev, mode, skb, sel);
+ ref->ops->get_rate(ref->priv, dev, sband, skb, sel);
/* Select a non-ERP backup rate. */
if (!sel->nonerp) {
- for (i = 0; i < mode->num_rates - 1; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
- if (sel->rate->rate < rate->rate)
+ for (i = 0; i < sband->n_bitrates; i++) {
+ struct ieee80211_rate *rate = &sband->bitrates[i];
+ if (sel->rate->bitrate < rate->bitrate)
break;
- if (rate_supported(sta, mode, i) &&
- !(rate->flags & IEEE80211_RATE_ERP))
+ if (rate_supported(sta, sband->band, i) &&
+ !(rate->flags & IEEE80211_RATE_ERP_G))
sel->nonerp = rate;
}
}
- if (sta)
- sta_info_put(sta);
+ rcu_read_unlock();
}
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref)
diff --git a/net/mac80211/ieee80211_rate.h b/net/mac80211/rate.h
index 73f19e8aa51c..5b45f33cb766 100644
--- a/net/mac80211/ieee80211_rate.h
+++ b/net/mac80211/rate.h
@@ -14,10 +14,12 @@
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/types.h>
+#include <linux/kref.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
#include "sta_info.h"
+/* TODO: kdoc */
struct rate_selection {
/* Selected transmission rate */
struct ieee80211_rate *rate;
@@ -34,7 +36,8 @@ struct rate_control_ops {
struct sk_buff *skb,
struct ieee80211_tx_status *status);
void (*get_rate)(void *priv, struct net_device *dev,
- struct ieee80211_hw_mode *mode, struct sk_buff *skb,
+ struct ieee80211_supported_band *band,
+ struct sk_buff *skb,
struct rate_selection *sel);
void (*rate_init)(void *priv, void *priv_sta,
struct ieee80211_local *local, struct sta_info *sta);
@@ -66,7 +69,8 @@ void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
struct rate_control_ref *rate_control_alloc(const char *name,
struct ieee80211_local *local);
void rate_control_get_rate(struct net_device *dev,
- struct ieee80211_hw_mode *mode, struct sk_buff *skb,
+ struct ieee80211_supported_band *sband,
+ struct sk_buff *skb,
struct rate_selection *sel);
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
void rate_control_put(struct rate_control_ref *ref);
@@ -127,23 +131,23 @@ static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
#endif
}
-static inline int
-rate_supported(struct sta_info *sta, struct ieee80211_hw_mode *mode, int index)
+static inline int rate_supported(struct sta_info *sta,
+ enum ieee80211_band band,
+ int index)
{
- return (sta == NULL || sta->supp_rates & BIT(index)) &&
- (mode->rates[index].flags & IEEE80211_RATE_SUPPORTED);
+ return (sta == NULL || sta->supp_rates[band] & BIT(index));
}
static inline int
-rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
+rate_lowest_index(struct ieee80211_local *local,
+ struct ieee80211_supported_band *sband,
struct sta_info *sta)
{
int i;
- for (i = 0; i < mode->num_rates; i++) {
- if (rate_supported(sta, mode, i))
+ for (i = 0; i < sband->n_bitrates; i++)
+ if (rate_supported(sta, sband->band, i))
return i;
- }
/* warn when we cannot find a rate. */
WARN_ON(1);
@@ -152,10 +156,11 @@ rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
}
static inline struct ieee80211_rate *
-rate_lowest(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
+rate_lowest(struct ieee80211_local *local,
+ struct ieee80211_supported_band *sband,
struct sta_info *sta)
{
- return &mode->rates[rate_lowest_index(local, mode, sta)];
+ return &sband->bitrates[rate_lowest_index(local, sband, sta)];
}
@@ -166,21 +171,6 @@ void rate_control_deinitialize(struct ieee80211_local *local);
/* Rate control algorithms */
-#if defined(RC80211_SIMPLE_COMPILE) || \
- (defined(CONFIG_MAC80211_RC_SIMPLE) && \
- !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE))
-extern int rc80211_simple_init(void);
-extern void rc80211_simple_exit(void);
-#else
-static inline int rc80211_simple_init(void)
-{
- return 0;
-}
-static inline void rc80211_simple_exit(void)
-{
-}
-#endif
-
#if defined(RC80211_PID_COMPILE) || \
(defined(CONFIG_MAC80211_RC_PID) && \
!defined(CONFIG_MAC80211_RC_PID_MODULE))
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index 3b77410588e7..a849b745bdb5 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -14,8 +14,8 @@
#include <linux/skbuff.h>
#include <linux/debugfs.h>
#include <net/mac80211.h>
-#include "ieee80211_rate.h"
-
+#include "rate.h"
+#include "mesh.h"
#include "rc80211_pid.h"
@@ -63,6 +63,7 @@
* RC_PID_ARITH_SHIFT.
*/
+
/* Adjust the rate while ensuring that we won't switch to a lower rate if it
* exhibited a worse failed frames behaviour and we'll choose the highest rate
* 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,
struct rc_pid_rateinfo *rinfo)
{
struct ieee80211_sub_if_data *sdata;
- struct ieee80211_hw_mode *mode;
- int cur_sorted, new_sorted, probe, tmp, n_bitrates;
- int cur = sta->txrate;
-
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ struct ieee80211_supported_band *sband;
+ int cur_sorted, new_sorted, probe, tmp, n_bitrates, band;
+ int cur = sta->txrate_idx;
- mode = local->oper_hw_mode;
- n_bitrates = mode->num_rates;
+ sdata = sta->sdata;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+ band = sband->band;
+ n_bitrates = sband->n_bitrates;
/* Map passed arguments to sorted values. */
cur_sorted = rinfo[cur].rev_index;
@@ -97,20 +98,20 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
/* Ensure that the rate decrease isn't disadvantageous. */
for (probe = cur_sorted; probe >= new_sorted; probe--)
if (rinfo[probe].diff <= rinfo[cur_sorted].diff &&
- rate_supported(sta, mode, rinfo[probe].index))
+ rate_supported(sta, band, rinfo[probe].index))
tmp = probe;
} else {
/* Look for rate increase with zero (or below) cost. */
for (probe = new_sorted + 1; probe < n_bitrates; probe++)
if (rinfo[probe].diff <= rinfo[new_sorted].diff &&
- rate_supported(sta, mode, rinfo[probe].index))
+ rate_supported(sta, band, rinfo[probe].index))
tmp = probe;
}
/* Fit the rate found to the nearest supported rate. */
do {
- if (rate_supported(sta, mode, rinfo[tmp].index)) {
- sta->txrate = rinfo[tmp].index;
+ if (rate_supported(sta, band, rinfo[tmp].index)) {
+ sta->txrate_idx = rinfo[tmp].index;
break;
}
if (adj < 0)
@@ -122,7 +123,7 @@ static void rate_control_pid_adjust_rate(struct ieee80211_local *local,
#ifdef CONFIG_MAC80211_DEBUGFS
rate_control_pid_event_rate_change(
&((struct rc_pid_sta_info *)sta->rate_ctrl_priv)->events,
- cur, mode->rates[cur].rate);
+ sta->txrate_idx, sband->bitrates[sta->txrate_idx].bitrate);
#endif
}
@@ -147,9 +148,12 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
struct ieee80211_local *local,
struct sta_info *sta)
{
+#ifdef CONFIG_MAC80211_MESH
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+#endif
struct rc_pid_sta_info *spinfo = sta->rate_ctrl_priv;
struct rc_pid_rateinfo *rinfo = pinfo->rinfo;
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
u32 pf;
s32 err_avg;
u32 err_prop;
@@ -158,7 +162,7 @@ static void rate_control_pid_sample(struct rc_pid_info *pinfo,
int adj, i, j, tmp;
unsigned long period;
- mode = local->oper_hw_mode;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
spinfo = sta->rate_ctrl_priv;
/* 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,
pf = spinfo->last_pf;
else {
pf = spinfo->tx_num_failed * 100 / spinfo->tx_num_xmit;
+#ifdef CONFIG_MAC80211_MESH
+ if (pf == 100 &&
+ sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
+ mesh_plink_broken(sta);
+#endif
pf <<= RC_PID_ARITH_SHIFT;
+ sta->fail_avg = ((pf + (spinfo->last_pf << 3)) / 9)
+ >> RC_PID_ARITH_SHIFT;
}
spinfo->tx_num_xmit = 0;
spinfo->tx_num_failed = 0;
/* If we just switched rate, update the rate behaviour info. */
- if (pinfo->oldrate != sta->txrate) {
+ if (pinfo->oldrate != sta->txrate_idx) {
i = rinfo[pinfo->oldrate].rev_index;
- j = rinfo[sta->txrate].rev_index;
+ j = rinfo[sta->txrate_idx].rev_index;
tmp = (pf - spinfo->last_pf);
tmp = RC_PID_DO_ARITH_RIGHT_SHIFT(tmp, RC_PID_ARITH_SHIFT);
rinfo[j].diff = rinfo[i].diff + tmp;
- pinfo->oldrate = sta->txrate;
+ pinfo->oldrate = sta->txrate_idx;
}
- rate_control_pid_normalize(pinfo, mode->num_rates);
+ rate_control_pid_normalize(pinfo, sband->n_bitrates);
/* Compute the proportional, integral and derivative errors. */
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,
struct sta_info *sta;
struct rc_pid_sta_info *spinfo;
unsigned long period;
+ struct ieee80211_supported_band *sband;
+
+ rcu_read_lock();
sta = sta_info_get(local, hdr->addr1);
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
if (!sta)
- return;
+ goto unlock;
/* Don't update the state if we're not controlling the rate. */
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ sdata = sta->sdata;
if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
- sta->txrate = sdata->bss->max_ratectrl_rateidx;
- return;
+ sta->txrate_idx = sdata->bss->max_ratectrl_rateidx;
+ goto unlock;
}
/* Ignore all frames that were sent with a different rate than the rate
* we currently advise mac80211 to use. */
- if (status->control.rate != &local->oper_hw_mode->rates[sta->txrate])
- goto ignore;
+ if (status->control.tx_rate != &sband->bitrates[sta->txrate_idx])
+ goto unlock;
spinfo = sta->rate_ctrl_priv;
spinfo->tx_num_xmit++;
@@ -277,9 +292,6 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
sta->tx_num_consecutive_failures++;
sta->tx_num_mpdu_fail++;
} else {
- sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
- sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
- sta->last_ack_rssi[2] = status->ack_signal;
sta->tx_num_consecutive_failures = 0;
sta->tx_num_mpdu_ok++;
}
@@ -293,12 +305,12 @@ static void rate_control_pid_tx_status(void *priv, struct net_device *dev,
if (time_after(jiffies, spinfo->last_sample + period))
rate_control_pid_sample(pinfo, local, sta);
-ignore:
- sta_info_put(sta);
+ unlock:
+ rcu_read_unlock();
}
static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
- struct ieee80211_hw_mode *mode,
+ struct ieee80211_supported_band *sband,
struct sk_buff *skb,
struct rate_selection *sel)
{
@@ -309,6 +321,8 @@ static void rate_control_pid_get_rate(void *priv, struct net_device *dev,
int rateidx;
u16 fc;
+ rcu_read_lock();
+
sta = sta_info_get(local, hdr->addr1);
/* 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,
fc = le16_to_cpu(hdr->frame_control);
if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
is_multicast_ether_addr(hdr->addr1) || !sta) {
- sel->rate = rate_lowest(local, mode, sta);
- if (sta)
- sta_info_put(sta);
+ sel->rate = rate_lowest(local, sband, sta);
+ rcu_read_unlock();
return;
}
/* If a forced rate is in effect, select it. */
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
- sta->txrate = sdata->bss->force_unicast_rateidx;
+ sta->txrate_idx = sdata->bss->force_unicast_rateidx;
- rateidx = sta->txrate;
+ rateidx = sta->txrate_idx;
- if (rateidx >= mode->num_rates)
- rateidx = mode->num_rates - 1;
+ if (rateidx >= sband->n_bitrates)
+ rateidx = sband->n_bitrates - 1;
- sta->last_txrate = rateidx;
+ sta->last_txrate_idx = rateidx;
- sta_info_put(sta);
+ rcu_read_unlock();
- sel->rate = &mode->rates[rateidx];
+ sel->rate = &sband->bitrates[rateidx];
#ifdef CONFIG_MAC80211_DEBUGFS
rate_control_pid_event_tx_rate(
&((struct rc_pid_sta_info *) sta->rate_ctrl_priv)->events,
- rateidx, mode->rates[rateidx].rate);
+ rateidx, sband->bitrates[rateidx].bitrate);
#endif
}
@@ -353,28 +366,33 @@ static void rate_control_pid_rate_init(void *priv, void *priv_sta,
* as we need to have IEEE 802.1X auth succeed immediately after assoc..
* Until that method is implemented, we will use the lowest supported
* rate as a workaround. */
- sta->txrate = rate_lowest_index(local, local->oper_hw_mode, sta);
+ struct ieee80211_supported_band *sband;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+ sta->txrate_idx = rate_lowest_index(local, sband, sta);
+ sta->fail_avg = 0;
}
static void *rate_control_pid_alloc(struct ieee80211_local *local)
{
struct rc_pid_info *pinfo;
struct rc_pid_rateinfo *rinfo;
- struct ieee80211_hw_mode *mode;
+ struct ieee80211_supported_band *sband;
int i, j, tmp;
bool s;
#ifdef CONFIG_MAC80211_DEBUGFS
struct rc_pid_debugfs_entries *de;
#endif
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
pinfo = kmalloc(sizeof(*pinfo), GFP_ATOMIC);
if (!pinfo)
return NULL;
- /* We can safely assume that oper_hw_mode won't change unless we get
+ /* We can safely assume that sband won't change unless we get
* reinitialized. */
- mode = local->oper_hw_mode;
- rinfo = kmalloc(sizeof(*rinfo) * mode->num_rates, GFP_ATOMIC);
+ rinfo = kmalloc(sizeof(*rinfo) * sband->n_bitrates, GFP_ATOMIC);
if (!rinfo) {
kfree(pinfo);
return NULL;
@@ -383,7 +401,7 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
/* Sort the rates. This is optimized for the most common case (i.e.
* almost-sorted CCK+OFDM rates). Kind of bubble-sort with reversed
* mapping too. */
- for (i = 0; i < mode->num_rates; i++) {
+ for (i = 0; i < sband->n_bitrates; i++) {
rinfo[i].index = i;
rinfo[i].rev_index = i;
if (pinfo->fast_start)
@@ -391,11 +409,11 @@ static void *rate_control_pid_alloc(struct ieee80211_local *local)
else
rinfo[i].diff = i * pinfo->norm_offset;
}
- for (i = 1; i < mode->num_rates; i++) {
+ for (i = 1; i < sband->n_bitrates; i++) {
s = 0;
- for (j = 0; j < mode->num_rates - i; j++)
- if (unlikely(mode->rates[rinfo[j].index].rate >
- mode->rates[rinfo[j + 1].index].rate)) {
+ for (j = 0; j < sband->n_bitrates - i; j++)
+ if (unlikely(sband->bitrates[rinfo[j].index].bitrate >
+ sband->bitrates[rinfo[j + 1].index].bitrate)) {
tmp = rinfo[j].index;
rinfo[j].index = rinfo[j + 1].index;
rinfo[j + 1].index = tmp;
diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
index 88b8dc9999bb..ae75d4178739 100644
--- a/net/mac80211/rc80211_pid_debugfs.c
+++ b/net/mac80211/rc80211_pid_debugfs.c
@@ -13,7 +13,7 @@
#include <linux/skbuff.h>
#include <net/mac80211.h>
-#include "ieee80211_rate.h"
+#include "rate.h"
#include "rc80211_pid.h"
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 @@
-/*
- * Copyright 2002-2005, Instant802 Networks, Inc.
- * Copyright 2005, Devicescape Software, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/init.h>
-#include <linux/netdevice.h>
-#include <linux/types.h>
-#include <linux/slab.h>
-#include <linux/skbuff.h>
-#include <linux/compiler.h>
-#include <linux/module.h>
-
-#include <net/mac80211.h>
-#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
-#include "debugfs.h"
-
-
-/* This is a minimal implementation of TX rate controlling that can be used
- * as the default when no improved mechanisms are available. */
-
-#define RATE_CONTROL_NUM_DOWN 20
-#define RATE_CONTROL_NUM_UP 15
-
-#define RATE_CONTROL_EMERG_DEC 2
-#define RATE_CONTROL_INTERVAL (HZ / 20)
-#define RATE_CONTROL_MIN_TX 10
-
-static void rate_control_rate_inc(struct ieee80211_local *local,
- struct sta_info *sta)
-{
- struct ieee80211_sub_if_data *sdata;
- struct ieee80211_hw_mode *mode;
- int i = sta->txrate;
- int maxrate;
-
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
- if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
- /* forced unicast rate - do not change STA rate */
- return;
- }
-
- mode = local->oper_hw_mode;
- maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
-
- if (i > mode->num_rates)
- i = mode->num_rates - 2;
-
- while (i + 1 < mode->num_rates) {
- i++;
- if (sta->supp_rates & BIT(i) &&
- mode->rates[i].flags & IEEE80211_RATE_SUPPORTED &&
- (maxrate < 0 || i <= maxrate)) {
- sta->txrate = i;
- break;
- }
- }
-}
-
-
-static void rate_control_rate_dec(struct ieee80211_local *local,
- struct sta_info *sta)
-{
- struct ieee80211_sub_if_data *sdata;
- struct ieee80211_hw_mode *mode;
- int i = sta->txrate;
-
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
- if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
- /* forced unicast rate - do not change STA rate */
- return;
- }
-
- mode = local->oper_hw_mode;
- if (i > mode->num_rates)
- i = mode->num_rates;
-
- while (i > 0) {
- i--;
- if (sta->supp_rates & BIT(i) &&
- mode->rates[i].flags & IEEE80211_RATE_SUPPORTED) {
- sta->txrate = i;
- break;
- }
- }
-}
-
-struct global_rate_control {
- int dummy;
-};
-
-struct sta_rate_control {
- unsigned long last_rate_change;
- u32 tx_num_failures;
- u32 tx_num_xmit;
-
- unsigned long avg_rate_update;
- u32 tx_avg_rate_sum;
- u32 tx_avg_rate_num;
-
-#ifdef CONFIG_MAC80211_DEBUGFS
- struct dentry *tx_avg_rate_sum_dentry;
- struct dentry *tx_avg_rate_num_dentry;
-#endif
-};
-
-
-static void rate_control_simple_tx_status(void *priv, struct net_device *dev,
- struct sk_buff *skb,
- struct ieee80211_tx_status *status)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct sta_info *sta;
- struct sta_rate_control *srctrl;
-
- sta = sta_info_get(local, hdr->addr1);
-
- if (!sta)
- return;
-
- srctrl = sta->rate_ctrl_priv;
- srctrl->tx_num_xmit++;
- if (status->excessive_retries) {
- srctrl->tx_num_failures++;
- sta->tx_retry_failed++;
- sta->tx_num_consecutive_failures++;
- sta->tx_num_mpdu_fail++;
- } else {
- sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
- sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
- sta->last_ack_rssi[2] = status->ack_signal;
- sta->tx_num_consecutive_failures = 0;
- sta->tx_num_mpdu_ok++;
- }
- sta->tx_retry_count += status->retry_count;
- sta->tx_num_mpdu_fail += status->retry_count;
-
- if (time_after(jiffies,
- srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
- srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
- u32 per_failed;
- srctrl->last_rate_change = jiffies;
-
- per_failed = (100 * sta->tx_num_mpdu_fail) /
- (sta->tx_num_mpdu_fail + sta->tx_num_mpdu_ok);
- /* TODO: calculate average per_failed to make adjusting
- * parameters easier */
-#if 0
- if (net_ratelimit()) {
- printk(KERN_DEBUG "MPDU fail=%d ok=%d per_failed=%d\n",
- sta->tx_num_mpdu_fail, sta->tx_num_mpdu_ok,
- per_failed);
- }
-#endif
-
- /*
- * XXX: Make these configurable once we have an
- * interface to the rate control algorithms
- */
- if (per_failed > RATE_CONTROL_NUM_DOWN) {
- rate_control_rate_dec(local, sta);
- } else if (per_failed < RATE_CONTROL_NUM_UP) {
- rate_control_rate_inc(local, sta);
- }
- srctrl->tx_avg_rate_sum += status->control.rate->rate;
- srctrl->tx_avg_rate_num++;
- srctrl->tx_num_failures = 0;
- srctrl->tx_num_xmit = 0;
- } else if (sta->tx_num_consecutive_failures >=
- RATE_CONTROL_EMERG_DEC) {
- rate_control_rate_dec(local, sta);
- }
-
- if (srctrl->avg_rate_update + 60 * HZ < jiffies) {
- srctrl->avg_rate_update = jiffies;
- if (srctrl->tx_avg_rate_num > 0) {
-#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- DECLARE_MAC_BUF(mac);
- printk(KERN_DEBUG "%s: STA %s Average rate: "
- "%d (%d/%d)\n",
- dev->name, print_mac(mac, sta->addr),
- srctrl->tx_avg_rate_sum /
- srctrl->tx_avg_rate_num,
- srctrl->tx_avg_rate_sum,
- srctrl->tx_avg_rate_num);
-#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
- srctrl->tx_avg_rate_sum = 0;
- srctrl->tx_avg_rate_num = 0;
- }
- }
-
- sta_info_put(sta);
-}
-
-
-static void
-rate_control_simple_get_rate(void *priv, struct net_device *dev,
- struct ieee80211_hw_mode *mode,
- struct sk_buff *skb,
- struct rate_selection *sel)
-{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- struct ieee80211_sub_if_data *sdata;
- struct sta_info *sta;
- int rateidx;
- u16 fc;
-
- sta = sta_info_get(local, hdr->addr1);
-
- /* Send management frames and broadcast/multicast data using lowest
- * rate. */
- fc = le16_to_cpu(hdr->frame_control);
- if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
- is_multicast_ether_addr(hdr->addr1) || !sta) {
- sel->rate = rate_lowest(local, mode, sta);
- if (sta)
- sta_info_put(sta);
- return;
- }
-
- /* If a forced rate is in effect, select it. */
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
- sta->txrate = sdata->bss->force_unicast_rateidx;
-
- rateidx = sta->txrate;
-
- if (rateidx >= mode->num_rates)
- rateidx = mode->num_rates - 1;
-
- sta->last_txrate = rateidx;
-
- sta_info_put(sta);
-
- sel->rate = &mode->rates[rateidx];
-}
-
-
-static void rate_control_simple_rate_init(void *priv, void *priv_sta,
- struct ieee80211_local *local,
- struct sta_info *sta)
-{
- struct ieee80211_hw_mode *mode;
- int i;
- sta->txrate = 0;
- mode = local->oper_hw_mode;
- /* TODO: This routine should consider using RSSI from previous packets
- * as we need to have IEEE 802.1X auth succeed immediately after assoc..
- * Until that method is implemented, we will use the lowest supported rate
- * as a workaround, */
- for (i = 0; i < mode->num_rates; i++) {
- if ((sta->supp_rates & BIT(i)) &&
- (mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) {
- sta->txrate = i;
- break;
- }
- }
-}
-
-
-static void * rate_control_simple_alloc(struct ieee80211_local *local)
-{
- struct global_rate_control *rctrl;
-
- rctrl = kzalloc(sizeof(*rctrl), GFP_ATOMIC);
-
- return rctrl;
-}
-
-
-static void rate_control_simple_free(void *priv)
-{
- struct global_rate_control *rctrl = priv;
- kfree(rctrl);
-}
-
-
-static void rate_control_simple_clear(void *priv)
-{
-}
-
-
-static void * rate_control_simple_alloc_sta(void *priv, gfp_t gfp)
-{
- struct sta_rate_control *rctrl;
-
- rctrl = kzalloc(sizeof(*rctrl), gfp);
-
- return rctrl;
-}
-
-
-static void rate_control_simple_free_sta(void *priv, void *priv_sta)
-{
- struct sta_rate_control *rctrl = priv_sta;
- kfree(rctrl);
-}
-
-#ifdef CONFIG_MAC80211_DEBUGFS
-
-static int open_file_generic(struct inode *inode, struct file *file)
-{
- file->private_data = inode->i_private;
- return 0;
-}
-
-static ssize_t sta_tx_avg_rate_sum_read(struct file *file,
- char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- struct sta_rate_control *srctrl = file->private_data;
- char buf[20];
-
- sprintf(buf, "%d\n", srctrl->tx_avg_rate_sum);
- return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
-}
-
-static const struct file_operations sta_tx_avg_rate_sum_ops = {
- .read = sta_tx_avg_rate_sum_read,
- .open = open_file_generic,
-};
-
-static ssize_t sta_tx_avg_rate_num_read(struct file *file,
- char __user *userbuf,
- size_t count, loff_t *ppos)
-{
- struct sta_rate_control *srctrl = file->private_data;
- char buf[20];
-
- sprintf(buf, "%d\n", srctrl->tx_avg_rate_num);
- return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
-}
-
-static const struct file_operations sta_tx_avg_rate_num_ops = {
- .read = sta_tx_avg_rate_num_read,
- .open = open_file_generic,
-};
-
-static void rate_control_simple_add_sta_debugfs(void *priv, void *priv_sta,
- struct dentry *dir)
-{
- struct sta_rate_control *srctrl = priv_sta;
-
- srctrl->tx_avg_rate_num_dentry =
- debugfs_create_file("rc_simple_sta_tx_avg_rate_num", 0400,
- dir, srctrl, &sta_tx_avg_rate_num_ops);
- srctrl->tx_avg_rate_sum_dentry =
- debugfs_create_file("rc_simple_sta_tx_avg_rate_sum", 0400,
- dir, srctrl, &sta_tx_avg_rate_sum_ops);
-}
-
-static void rate_control_simple_remove_sta_debugfs(void *priv, void *priv_sta)
-{
- struct sta_rate_control *srctrl = priv_sta;
-
- debugfs_remove(srctrl->tx_avg_rate_sum_dentry);
- debugfs_remove(srctrl->tx_avg_rate_num_dentry);
-}
-#endif
-
-static struct rate_control_ops mac80211_rcsimple = {
- .name = "simple",
- .tx_status = rate_control_simple_tx_status,
- .get_rate = rate_control_simple_get_rate,
- .rate_init = rate_control_simple_rate_init,
- .clear = rate_control_simple_clear,
- .alloc = rate_control_simple_alloc,
- .free = rate_control_simple_free,
- .alloc_sta = rate_control_simple_alloc_sta,
- .free_sta = rate_control_simple_free_sta,
-#ifdef CONFIG_MAC80211_DEBUGFS
- .add_sta_debugfs = rate_control_simple_add_sta_debugfs,
- .remove_sta_debugfs = rate_control_simple_remove_sta_debugfs,
-#endif
-};
-
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Simple rate control algorithm");
-
-int __init rc80211_simple_init(void)
-{
- return ieee80211_rate_control_register(&mac80211_rcsimple);
-}
-
-void rc80211_simple_exit(void)
-{
- ieee80211_rate_control_unregister(&mac80211_rcsimple);
-}
-
-#ifdef CONFIG_MAC80211_RC_SIMPLE_MODULE
-module_init(rc80211_simple_init);
-module_exit(rc80211_simple_exit);
-#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 @@
-/*
- * Copyright 2002-2005, Instant802 Networks, Inc.
- * Copyright 2005-2006, Devicescape Software, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-/*
- * This regulatory domain control implementation is known to be incomplete
- * and confusing. mac80211 regulatory domain control will be significantly
- * reworked in the not-too-distant future.
- *
- * For now, drivers wishing to control which channels are and aren't available
- * are advised as follows:
- * - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
- * - continue to include *ALL* possible channels in the modes registered
- * through ieee80211_register_hwmode()
- * - for each allowable ieee80211_channel structure registered in the above
- * call, set the flag member to some meaningful value such as
- * IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
- * IEEE80211_CHAN_W_IBSS.
- * - leave flag as 0 for non-allowable channels
- *
- * The usual implementation is for a driver to read a device EEPROM to
- * determine which regulatory domain it should be operating under, then
- * looking up the allowable channels in a driver-local table, then performing
- * the above.
- */
-
-#include <linux/module.h>
-#include <linux/netdevice.h>
-#include <net/mac80211.h>
-#include "ieee80211_i.h"
-
-static int ieee80211_regdom = 0x10; /* FCC */
-module_param(ieee80211_regdom, int, 0444);
-MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
-
-/*
- * If firmware is upgraded by the vendor, additional channels can be used based
- * on the new Japanese regulatory rules. This is indicated by setting
- * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
- * module.
- */
-static int ieee80211_japan_5ghz /* = 0 */;
-module_param(ieee80211_japan_5ghz, int, 0444);
-MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
-
-
-struct ieee80211_channel_range {
- short start_freq;
- short end_freq;
- unsigned char power_level;
- unsigned char antenna_max;
-};
-
-static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
- { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
- { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
- { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
- { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
- { 0 }
-};
-
-static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
- { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
- { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
- { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
- { 0 }
-};
-
-
-static const struct ieee80211_channel_range *channel_range =
- ieee80211_fcc_channels;
-
-
-static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
-{
- int i;
-
- chan->flag = 0;
-
- for (i = 0; channel_range[i].start_freq; i++) {
- const struct ieee80211_channel_range *r = &channel_range[i];
- if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
- if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
- chan->freq >= 5260 && chan->freq <= 5320) {
- /*
- * Skip new channels in Japan since the
- * firmware was not marked having been upgraded
- * by the vendor.
- */
- continue;
- }
-
- if (ieee80211_regdom == 0x10 &&
- (chan->freq == 5190 || chan->freq == 5210 ||
- chan->freq == 5230)) {
- /* Skip MKK channels when in FCC domain. */
- continue;
- }
-
- chan->flag |= IEEE80211_CHAN_W_SCAN |
- IEEE80211_CHAN_W_ACTIVE_SCAN |
- IEEE80211_CHAN_W_IBSS;
- chan->power_level = r->power_level;
- chan->antenna_max = r->antenna_max;
-
- if (ieee80211_regdom == 64 &&
- (chan->freq == 5170 || chan->freq == 5190 ||
- chan->freq == 5210 || chan->freq == 5230)) {
- /*
- * New regulatory rules in Japan have backwards
- * compatibility with old channels in 5.15-5.25
- * GHz band, but the station is not allowed to
- * use active scan on these old channels.
- */
- chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
- }
-
- if (ieee80211_regdom == 64 &&
- (chan->freq == 5260 || chan->freq == 5280 ||
- chan->freq == 5300 || chan->freq == 5320)) {
- /*
- * IBSS is not allowed on 5.25-5.35 GHz band
- * due to radar detection requirements.
- */
- chan->flag &= ~IEEE80211_CHAN_W_IBSS;
- }
-
- break;
- }
- }
-}
-
-
-void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
-{
- int c;
- for (c = 0; c < mode->num_channels; c++)
- ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
-}
-
-
-void ieee80211_regdomain_init(void)
-{
- if (ieee80211_regdom == 0x40)
- channel_range = ieee80211_mkk_channels;
-}
-
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 535407d07fa4..52e4554fdde7 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -9,6 +9,7 @@
* published by the Free Software Foundation.
*/
+#include <linux/jiffies.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
@@ -18,7 +19,8 @@
#include <net/ieee80211_radiotap.h>
#include "ieee80211_i.h"
-#include "ieee80211_led.h"
+#include "led.h"
+#include "mesh.h"
#include "wep.h"
#include "wpa.h"
#include "tkip.h"
@@ -82,10 +84,10 @@ static inline int should_drop_frame(struct ieee80211_rx_status *status,
*/
static struct sk_buff *
ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
- struct ieee80211_rx_status *status)
+ struct ieee80211_rx_status *status,
+ struct ieee80211_rate *rate)
{
struct ieee80211_sub_if_data *sdata;
- struct ieee80211_rate *rate;
int needed_headroom = 0;
struct ieee80211_radiotap_header *rthdr;
__le64 *rttsft = NULL;
@@ -194,14 +196,11 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
rtfixed->rx_flags |=
cpu_to_le16(IEEE80211_RADIOTAP_F_RX_BADFCS);
- rate = ieee80211_get_rate(local, status->phymode,
- status->rate);
- if (rate)
- rtfixed->rate = rate->rate / 5;
+ rtfixed->rate = rate->bitrate / 5;
rtfixed->chan_freq = cpu_to_le16(status->freq);
- if (status->phymode == MODE_IEEE80211A)
+ if (status->band == IEEE80211_BAND_5GHZ)
rtfixed->chan_flags =
cpu_to_le16(IEEE80211_CHAN_OFDM |
IEEE80211_CHAN_5GHZ);
@@ -226,6 +225,9 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR)
continue;
+ if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
+ continue;
+
if (prev_dev) {
skb2 = skb_clone(skb, GFP_ATOMIC);
if (skb2) {
@@ -249,15 +251,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
}
-/* pre-rx handlers
- *
- * these don't have dev/sdata fields in the rx data
- * The sta value should also not be used because it may
- * be NULL even though a STA (in IBSS mode) will be added.
- */
-
-static ieee80211_txrx_result
-ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
+static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
{
u8 *data = rx->skb->data;
int tid;
@@ -268,9 +262,9 @@ ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
/* frame has qos control */
tid = qc[0] & QOS_CONTROL_TID_MASK;
if (qc[0] & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT)
- rx->flags |= IEEE80211_TXRXD_RX_AMSDU;
+ rx->flags |= IEEE80211_RX_AMSDU;
else
- rx->flags &= ~IEEE80211_TXRXD_RX_AMSDU;
+ rx->flags &= ~IEEE80211_RX_AMSDU;
} else {
if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
/* Separate TID for management frames */
@@ -286,68 +280,19 @@ ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
if (rx->sta)
I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
- rx->u.rx.queue = tid;
+ rx->queue = tid;
/* Set skb->priority to 1d tag if highest order bit of TID is not set.
* For now, set skb->priority to 0 for other cases. */
rx->skb->priority = (tid > 7) ? 0 : tid;
-
- return TXRX_CONTINUE;
}
-
-static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
- struct sk_buff *skb,
- struct ieee80211_rx_status *status)
+static void ieee80211_verify_ip_alignment(struct ieee80211_rx_data *rx)
{
- struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
- u32 load = 0, hdrtime;
- struct ieee80211_rate *rate;
- struct ieee80211_hw_mode *mode = local->hw.conf.mode;
- int i;
-
- /* Estimate total channel use caused by this frame */
-
- if (unlikely(mode->num_rates < 0))
- return TXRX_CONTINUE;
-
- rate = &mode->rates[0];
- for (i = 0; i < mode->num_rates; i++) {
- if (mode->rates[i].val == status->rate) {
- rate = &mode->rates[i];
- break;
- }
- }
-
- /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
- * 1 usec = 1/8 * (1080 / 10) = 13.5 */
-
- if (mode->mode == MODE_IEEE80211A ||
- (mode->mode == MODE_IEEE80211G &&
- rate->flags & IEEE80211_RATE_ERP))
- hdrtime = CHAN_UTIL_HDR_SHORT;
- else
- hdrtime = CHAN_UTIL_HDR_LONG;
-
- load = hdrtime;
- if (!is_multicast_ether_addr(hdr->addr1))
- load += hdrtime;
-
- load += skb->len * rate->rate_inv;
-
- /* Divide channel_use by 8 to avoid wrapping around the counter */
- load >>= CHAN_UTIL_SHIFT;
-
- return load;
-}
-
#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
-static ieee80211_txrx_result
-ieee80211_rx_h_verify_ip_alignment(struct ieee80211_txrx_data *rx)
-{
int hdrlen;
if (!WLAN_FC_DATA_PRESENT(rx->fc))
- return TXRX_CONTINUE;
+ return;
/*
* 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)
* to move the 802.11 header further back in that case.
*/
hdrlen = ieee80211_get_hdrlen(rx->fc);
- if (rx->flags & IEEE80211_TXRXD_RX_AMSDU)
+ if (rx->flags & IEEE80211_RX_AMSDU)
hdrlen += ETH_HLEN;
WARN_ON_ONCE(((unsigned long)(rx->skb->data + hdrlen)) & 3);
-
- return TXRX_CONTINUE;
-}
#endif
+}
+
-ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
+static u32 ieee80211_rx_load_stats(struct ieee80211_local *local,
+ struct sk_buff *skb,
+ struct ieee80211_rx_status *status,
+ struct ieee80211_rate *rate)
{
- ieee80211_rx_h_parse_qos,
-#ifdef CONFIG_MAC80211_DEBUG_PACKET_ALIGNMENT
- ieee80211_rx_h_verify_ip_alignment,
-#endif
- NULL
-};
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ u32 load = 0, hdrtime;
+
+ /* Estimate total channel use caused by this frame */
+
+ /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
+ * 1 usec = 1/8 * (1080 / 10) = 13.5 */
+
+ if (status->band == IEEE80211_BAND_5GHZ ||
+ (status->band == IEEE80211_BAND_5GHZ &&
+ rate->flags & IEEE80211_RATE_ERP_G))
+ hdrtime = CHAN_UTIL_HDR_SHORT;
+ else
+ hdrtime = CHAN_UTIL_HDR_LONG;
+
+ load = hdrtime;
+ if (!is_multicast_ether_addr(hdr->addr1))
+ load += hdrtime;
+
+ /* TODO: optimise again */
+ load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
+
+ /* Divide channel_use by 8 to avoid wrapping around the counter */
+ load >>= CHAN_UTIL_SHIFT;
+
+ return load;
+}
/* rx handlers */
-static ieee80211_txrx_result
-ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_if_stats(struct ieee80211_rx_data *rx)
{
if (rx->sta)
- rx->sta->channel_use_raw += rx->u.rx.load;
- rx->sdata->channel_use_raw += rx->u.rx.load;
- return TXRX_CONTINUE;
+ rx->sta->channel_use_raw += rx->load;
+ rx->sdata->channel_use_raw += rx->load;
+ return RX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
{
struct ieee80211_local *local = rx->local;
struct sk_buff *skb = rx->skb;
if (unlikely(local->sta_hw_scanning))
- return ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
+ return ieee80211_sta_rx_scan(rx->dev, skb, rx->status);
if (unlikely(local->sta_sw_scanning)) {
/* drop all the other packets during a software scan anyway */
- if (ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status)
- != TXRX_QUEUED)
+ if (ieee80211_sta_rx_scan(rx->dev, skb, rx->status)
+ != RX_QUEUED)
dev_kfree_skb(skb);
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
- if (unlikely(rx->flags & IEEE80211_TXRXD_RXIN_SCAN)) {
+ if (unlikely(rx->flags & IEEE80211_RX_IN_SCAN)) {
/* scanning finished during invoking of handlers */
I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
+{
+ int hdrlen = ieee80211_get_hdrlen(rx->fc);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
+
+#define msh_h_get(h, l) ((struct ieee80211s_hdr *) ((u8 *)h + l))
+
+ if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) {
+ if (!((rx->fc & IEEE80211_FCTL_FROMDS) &&
+ (rx->fc & IEEE80211_FCTL_TODS)))
+ return RX_DROP_MONITOR;
+ if (memcmp(hdr->addr4, rx->dev->dev_addr, ETH_ALEN) == 0)
+ return RX_DROP_MONITOR;
+ }
+
+ /* If there is not an established peer link and this is not a peer link
+ * establisment frame, beacon or probe, drop the frame.
+ */
+
+ if (!rx->sta || sta_plink_state(rx->sta) != PLINK_ESTAB) {
+ struct ieee80211_mgmt *mgmt;
+
+ if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT)
+ return RX_DROP_MONITOR;
+
+ switch (rx->fc & IEEE80211_FCTL_STYPE) {
+ case IEEE80211_STYPE_ACTION:
+ mgmt = (struct ieee80211_mgmt *)hdr;
+ if (mgmt->u.action.category != PLINK_CATEGORY)
+ return RX_DROP_MONITOR;
+ /* fall through on else */
+ case IEEE80211_STYPE_PROBE_REQ:
+ case IEEE80211_STYPE_PROBE_RESP:
+ case IEEE80211_STYPE_BEACON:
+ return RX_CONTINUE;
+ break;
+ default:
+ return RX_DROP_MONITOR;
+ }
+
+ } else if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
+ is_multicast_ether_addr(hdr->addr1) &&
+ mesh_rmc_check(hdr->addr4, msh_h_get(hdr, hdrlen), rx->dev))
+ return RX_DROP_MONITOR;
+#undef msh_h_get
+
+ return RX_CONTINUE;
+}
+
+
+static ieee80211_rx_result
+ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
{
struct ieee80211_hdr *hdr;
+
hdr = (struct ieee80211_hdr *) rx->skb->data;
/* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
- rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
+ rx->sta->last_seq_ctrl[rx->queue] ==
hdr->seq_ctrl)) {
- if (rx->flags & IEEE80211_TXRXD_RXRA_MATCH) {
+ if (rx->flags & IEEE80211_RX_RA_MATCH) {
rx->local->dot11FrameDuplicateCount++;
rx->sta->num_duplicates++;
}
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
} else
- rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
+ rx->sta->last_seq_ctrl[rx->queue] = hdr->seq_ctrl;
}
if (unlikely(rx->skb->len < 16)) {
I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
}
/* Drop disallowed frame classes based on STA auth/assoc state;
@@ -456,6 +476,10 @@ ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
* deauth/disassoc frames when needed. In addition, hostapd is
* responsible for filtering on both auth and assoc states.
*/
+
+ if (ieee80211_vif_is_mesh(&rx->sdata->vif))
+ return ieee80211_rx_mesh_check(rx);
+
if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
(rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
@@ -464,26 +488,26 @@ ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
!(rx->fc & IEEE80211_FCTL_TODS) &&
(rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
- || !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
+ || !(rx->flags & IEEE80211_RX_RA_MATCH)) {
/* Drop IBSS frames and frames for other hosts
* silently. */
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
}
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
int keyidx;
int hdrlen;
- ieee80211_txrx_result result = TXRX_DROP;
+ ieee80211_rx_result result = RX_DROP_UNUSABLE;
struct ieee80211_key *stakey = NULL;
/*
@@ -513,14 +537,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
*/
if (!(rx->fc & IEEE80211_FCTL_PROTECTED))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
/*
* No point in finding a key and decrypting if the frame is neither
* addressed to us nor a multicast frame.
*/
- if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
- return TXRX_CONTINUE;
+ if (!(rx->flags & IEEE80211_RX_RA_MATCH))
+ return RX_CONTINUE;
if (rx->sta)
stakey = rcu_dereference(rx->sta->key);
@@ -537,14 +561,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
* we somehow allow the driver to tell us which key
* the hardware used if this flag is set?
*/
- if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
- (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
- return TXRX_CONTINUE;
+ if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
+ (rx->status->flag & RX_FLAG_IV_STRIPPED))
+ return RX_CONTINUE;
hdrlen = ieee80211_get_hdrlen(rx->fc);
if (rx->skb->len < 8 + hdrlen)
- return TXRX_DROP; /* TODO: count this? */
+ return RX_DROP_UNUSABLE; /* TODO: count this? */
/*
* no need to call ieee80211_wep_get_keyidx,
@@ -573,14 +597,14 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
printk(KERN_DEBUG "%s: RX protected frame,"
" but have no key\n", rx->dev->name);
#endif /* CONFIG_MAC80211_DEBUG */
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
}
/* Check for weak IVs if possible */
if (rx->sta && rx->key->conf.alg == ALG_WEP &&
((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
- (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) ||
- !(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) &&
+ (!(rx->status->flag & RX_FLAG_IV_STRIPPED) ||
+ !(rx->status->flag & RX_FLAG_DECRYPTED)) &&
ieee80211_wep_is_weak_iv(rx->skb, rx->key))
rx->sta->wep_weak_iv_count++;
@@ -597,7 +621,7 @@ ieee80211_rx_h_decrypt(struct ieee80211_txrx_data *rx)
}
/* either the frame has been decrypted or will be dropped */
- rx->u.rx.status->flag |= RX_FLAG_DECRYPTED;
+ rx->status->flag |= RX_FLAG_DECRYPTED;
return result;
}
@@ -607,12 +631,12 @@ static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
struct ieee80211_sub_if_data *sdata;
DECLARE_MAC_BUF(mac);
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ sdata = sta->sdata;
if (sdata->bss)
atomic_inc(&sdata->bss->num_sta_ps);
sta->flags |= WLAN_STA_PS;
- sta->pspoll = 0;
+ sta->flags &= ~WLAN_STA_PSPOLL;
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
printk(KERN_DEBUG "%s: STA %s aid %d enters power save mode\n",
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)
struct ieee80211_tx_packet_data *pkt_data;
DECLARE_MAC_BUF(mac);
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ sdata = sta->sdata;
+
if (sdata->bss)
atomic_dec(&sdata->bss->num_sta_ps);
- sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
- sta->pspoll = 0;
- if (!skb_queue_empty(&sta->ps_tx_buf)) {
- if (local->ops->set_tim)
- local->ops->set_tim(local_to_hw(local), sta->aid, 0);
- if (sdata->bss)
- bss_tim_clear(local, sdata->bss, sta->aid);
- }
+
+ sta->flags &= ~(WLAN_STA_PS | WLAN_STA_PSPOLL);
+
+ if (!skb_queue_empty(&sta->ps_tx_buf))
+ sta_info_clear_tim_bit(sta);
+
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
printk(KERN_DEBUG "%s: STA %s aid %d exits power save mode\n",
dev->name, print_mac(mac, sta->addr), sta->aid);
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+
/* Send all buffered frames to the station */
while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
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)
return sent;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
{
struct sta_info *sta = rx->sta;
struct net_device *dev = rx->dev;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
if (!sta)
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
/* Update last_rx only for IBSS packets which are for the current
* 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)
/* Update last_rx only for unicast frames in order to prevent
* the Probe Request frames (the only broadcast frames from a
* STA in infrastructure mode) from keeping a connection alive.
+ * Mesh beacons will update last_rx when if they are found to
+ * match the current local configuration when processed.
*/
sta->last_rx = jiffies;
}
- if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
- return TXRX_CONTINUE;
+ if (!(rx->flags & IEEE80211_RX_RA_MATCH))
+ return RX_CONTINUE;
sta->rx_fragments++;
sta->rx_bytes += rx->skb->len;
- sta->last_rssi = rx->u.rx.status->ssi;
- sta->last_signal = rx->u.rx.status->signal;
- sta->last_noise = rx->u.rx.status->noise;
+ sta->last_rssi = rx->status->ssi;
+ sta->last_signal = rx->status->signal;
+ sta->last_noise = rx->status->noise;
if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
/* Change STA power saving mode only in the end of a frame
* exchange sequence */
if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
- rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
+ rx->sent_ps_buffered += ap_sta_ps_end(dev, sta);
else if (!(sta->flags & WLAN_STA_PS) &&
(rx->fc & IEEE80211_FCTL_PM))
ap_sta_ps_start(dev, sta);
@@ -722,10 +748,10 @@ ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
* as a dropped packed. */
sta->rx_packets++;
dev_kfree_skb(rx->skb);
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
} /* ieee80211_rx_h_sta_process */
static inline struct ieee80211_fragment_entry *
@@ -801,7 +827,7 @@ ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
continue;
- if (entry->first_frag_time + 2 * HZ < jiffies) {
+ if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
__skb_queue_purge(&entry->skb_list);
continue;
}
@@ -811,8 +837,8 @@ ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
return NULL;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
{
struct ieee80211_hdr *hdr;
u16 sc;
@@ -838,27 +864,27 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
if (frag == 0) {
/* This is the first fragment of a new frame. */
entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
- rx->u.rx.queue, &(rx->skb));
+ rx->queue, &(rx->skb));
if (rx->key && rx->key->conf.alg == ALG_CCMP &&
(rx->fc & IEEE80211_FCTL_PROTECTED)) {
/* Store CCMP PN so that we can verify that the next
* fragment has a sequential PN value. */
entry->ccmp = 1;
memcpy(entry->last_pn,
- rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
+ rx->key->u.ccmp.rx_pn[rx->queue],
CCMP_PN_LEN);
}
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
/* This is a fragment for a frame that should already be pending in
* fragment cache. Add this fragment to the end of the pending entry.
*/
entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
- rx->u.rx.queue, hdr);
+ rx->queue, hdr);
if (!entry) {
I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
}
/* Verify that MPDUs within one MSDU have sequential PN values.
@@ -867,14 +893,14 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
int i;
u8 pn[CCMP_PN_LEN], *rpn;
if (!rx->key || rx->key->conf.alg != ALG_CCMP)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
memcpy(pn, entry->last_pn, CCMP_PN_LEN);
for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
pn[i]++;
if (pn[i])
break;
}
- rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
+ rpn = rx->key->u.ccmp.rx_pn[rx->queue];
if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
if (net_ratelimit())
printk(KERN_DEBUG "%s: defrag: CCMP PN not "
@@ -885,7 +911,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
rpn[5], pn[0], pn[1], pn[2], pn[3],
pn[4], pn[5]);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
memcpy(entry->last_pn, pn, CCMP_PN_LEN);
}
@@ -896,7 +922,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
entry->extra_len += rx->skb->len;
if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
rx->skb = NULL;
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
rx->skb = __skb_dequeue(&entry->skb_list);
@@ -906,7 +932,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
GFP_ATOMIC))) {
I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
__skb_queue_purge(&entry->skb_list);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
}
while ((skb = __skb_dequeue(&entry->skb_list))) {
@@ -915,7 +941,7 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
}
/* Complete frame has been reassembled - process it now */
- rx->flags |= IEEE80211_TXRXD_FRAGMENTED;
+ rx->flags |= IEEE80211_RX_FRAGMENTED;
out:
if (rx->sta)
@@ -924,11 +950,11 @@ ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
rx->local->dot11MulticastReceivedFrameCount++;
else
ieee80211_led_rx(rx->local);
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
{
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
struct sk_buff *skb;
@@ -938,12 +964,12 @@ ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
if (likely(!rx->sta ||
(rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
- !(rx->flags & IEEE80211_TXRXD_RXRA_MATCH)))
- return TXRX_CONTINUE;
+ !(rx->flags & IEEE80211_RX_RA_MATCH)))
+ return RX_CONTINUE;
if ((sdata->vif.type != IEEE80211_IF_TYPE_AP) &&
(sdata->vif.type != IEEE80211_IF_TYPE_VLAN))
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
skb = skb_dequeue(&rx->sta->tx_filtered);
if (!skb) {
@@ -958,9 +984,11 @@ ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
struct ieee80211_hdr *hdr =
(struct ieee80211_hdr *) skb->data;
- /* tell TX path to send one frame even though the STA may
- * still remain is PS mode after this frame exchange */
- rx->sta->pspoll = 1;
+ /*
+ * Tell TX path to send one frame even though the STA may
+ * still remain is PS mode after this frame exchange.
+ */
+ rx->sta->flags |= WLAN_STA_PSPOLL;
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
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)
/* Use MoreData flag to indicate whether there are more
* buffered frames for this STA */
- if (no_pending_pkts) {
+ if (no_pending_pkts)
hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
- rx->sta->flags &= ~WLAN_STA_TIM;
- } else
+ else
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
dev_queue_xmit(skb);
- if (no_pending_pkts) {
- if (rx->local->ops->set_tim)
- rx->local->ops->set_tim(local_to_hw(rx->local),
- rx->sta->aid, 0);
- if (rx->sdata->bss)
- bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
- }
+ if (no_pending_pkts)
+ sta_info_clear_tim_bit(rx->sta);
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
- } else if (!rx->u.rx.sent_ps_buffered) {
+ } else if (!rx->sent_ps_buffered) {
+ /*
+ * FIXME: This can be the result of a race condition between
+ * us expiring a frame and the station polling for it.
+ * Should we send it a null-func frame indicating we
+ * have nothing buffered for it?
+ */
printk(KERN_DEBUG "%s: STA %s sent PS Poll even "
"though there is no buffered frames for it\n",
rx->dev->name, print_mac(mac, rx->sta->addr));
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
-
}
- /* Free PS Poll skb here instead of returning TXRX_DROP that would
+ /* Free PS Poll skb here instead of returning RX_DROP that would
* count as an dropped frame. */
dev_kfree_skb(rx->skb);
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_remove_qos_control(struct ieee80211_rx_data *rx)
{
u16 fc = rx->fc;
u8 *data = rx->skb->data;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
if (!WLAN_FC_IS_QOS_DATA(fc))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
/* remove the qos control field, update frame type and meta-data */
memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
@@ -1018,17 +1045,17 @@ ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
hdr->frame_control = cpu_to_le16(fc);
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
static int
-ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
+ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
{
- if (unlikely(rx->sdata->ieee802_1x_pac &&
- (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)))) {
+ if (unlikely(!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED))) {
#ifdef CONFIG_MAC80211_DEBUG
- printk(KERN_DEBUG "%s: dropped frame "
- "(unauthorized port)\n", rx->dev->name);
+ if (net_ratelimit())
+ printk(KERN_DEBUG "%s: dropped frame "
+ "(unauthorized port)\n", rx->dev->name);
#endif /* CONFIG_MAC80211_DEBUG */
return -EACCES;
}
@@ -1037,30 +1064,27 @@ ieee80211_802_1x_port_control(struct ieee80211_txrx_data *rx)
}
static int
-ieee80211_drop_unencrypted(struct ieee80211_txrx_data *rx)
+ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx)
{
/*
* Pass through unencrypted frames if the hardware has
* decrypted them already.
*/
- if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED)
+ if (rx->status->flag & RX_FLAG_DECRYPTED)
return 0;
/* Drop unencrypted frames if key is set. */
if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
(rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
- (rx->key || rx->sdata->drop_unencrypted))) {
- if (net_ratelimit())
- printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
- "encryption\n", rx->dev->name);
+ (rx->key || rx->sdata->drop_unencrypted)))
return -EACCES;
- }
+
return 0;
}
static int
-ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
+ieee80211_data_to_8023(struct ieee80211_rx_data *rx)
{
struct net_device *dev = rx->dev;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
@@ -1082,6 +1106,21 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
hdrlen = ieee80211_get_hdrlen(fc);
+ if (ieee80211_vif_is_mesh(&sdata->vif)) {
+ int meshhdrlen = ieee80211_get_mesh_hdrlen(
+ (struct ieee80211s_hdr *) (skb->data + hdrlen));
+ /* Copy on cb:
+ * - mesh header: to be used for mesh forwarding
+ * decision. It will also be used as mesh header template at
+ * tx.c:ieee80211_subif_start_xmit() if interface
+ * type is mesh and skb->pkt_type == PACKET_OTHERHOST
+ * - ta: to be used if a RERR needs to be sent.
+ */
+ memcpy(skb->cb, skb->data + hdrlen, meshhdrlen);
+ memcpy(MESH_PREQ(skb), hdr->addr2, ETH_ALEN);
+ hdrlen += meshhdrlen;
+ }
+
/* convert IEEE 802.11 header + possible LLC headers into Ethernet
* header
* IEEE 802.11 address fields:
@@ -1115,9 +1154,10 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
memcpy(dst, hdr->addr3, ETH_ALEN);
memcpy(src, hdr->addr4, ETH_ALEN);
- if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS)) {
- if (net_ratelimit())
- printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
+ if (unlikely(sdata->vif.type != IEEE80211_IF_TYPE_WDS &&
+ sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)) {
+ if (net_ratelimit())
+ printk(KERN_DEBUG "%s: dropped FromDS&ToDS "
"frame (RA=%s TA=%s DA=%s SA=%s)\n",
rx->dev->name,
print_mac(mac, hdr->addr1),
@@ -1192,7 +1232,7 @@ ieee80211_data_to_8023(struct ieee80211_txrx_data *rx)
/*
* requires that rx->skb is a frame with ethernet header
*/
-static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
+static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx)
{
static const u8 pae_group_addr[ETH_ALEN]
= { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
@@ -1218,7 +1258,7 @@ static bool ieee80211_frame_allowed(struct ieee80211_txrx_data *rx)
* requires that rx->skb is a frame with ethernet header
*/
static void
-ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
+ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
{
struct net_device *dev = rx->dev;
struct ieee80211_local *local = rx->local;
@@ -1232,7 +1272,7 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
if (local->bridge_packets && (sdata->vif.type == IEEE80211_IF_TYPE_AP ||
sdata->vif.type == IEEE80211_IF_TYPE_VLAN) &&
- (rx->flags & IEEE80211_TXRXD_RXRA_MATCH)) {
+ (rx->flags & IEEE80211_RX_RA_MATCH)) {
if (is_multicast_ether_addr(ehdr->h_dest)) {
/*
* send multicast frames both to higher layers in
@@ -1244,7 +1284,7 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
"multicast frame\n", dev->name);
} else {
dsta = sta_info_get(local, skb->data);
- if (dsta && dsta->dev == dev) {
+ if (dsta && dsta->sdata->dev == dev) {
/*
* The destination station is associated to
* this AP (in this VLAN), so send the frame
@@ -1254,8 +1294,38 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
xmit_skb = skb;
skb = NULL;
}
- if (dsta)
- sta_info_put(dsta);
+ }
+ }
+
+ /* Mesh forwarding */
+ if (ieee80211_vif_is_mesh(&sdata->vif)) {
+ u8 *mesh_ttl = &((struct ieee80211s_hdr *)skb->cb)->ttl;
+ (*mesh_ttl)--;
+
+ if (is_multicast_ether_addr(skb->data)) {
+ if (*mesh_ttl > 0) {
+ xmit_skb = skb_copy(skb, GFP_ATOMIC);
+ if (!xmit_skb && net_ratelimit())
+ printk(KERN_DEBUG "%s: failed to clone "
+ "multicast frame\n", dev->name);
+ else
+ xmit_skb->pkt_type = PACKET_OTHERHOST;
+ } else
+ IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
+ dropped_frames_ttl);
+ } else if (skb->pkt_type != PACKET_OTHERHOST &&
+ compare_ether_addr(dev->dev_addr, skb->data) != 0) {
+ if (*mesh_ttl == 0) {
+ IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.sta,
+ dropped_frames_ttl);
+ dev_kfree_skb(skb);
+ skb = NULL;
+ } else {
+ xmit_skb = skb;
+ xmit_skb->pkt_type = PACKET_OTHERHOST;
+ if (!(dev->flags & IFF_PROMISC))
+ skb = NULL;
+ }
}
}
@@ -1275,8 +1345,8 @@ ieee80211_deliver_skb(struct ieee80211_txrx_data *rx)
}
}
-static ieee80211_txrx_result
-ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
{
struct net_device *dev = rx->dev;
struct ieee80211_local *local = rx->local;
@@ -1291,17 +1361,17 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
fc = rx->fc;
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
- if (!(rx->flags & IEEE80211_TXRXD_RX_AMSDU))
- return TXRX_CONTINUE;
+ if (!(rx->flags & IEEE80211_RX_AMSDU))
+ return RX_CONTINUE;
err = ieee80211_data_to_8023(rx);
if (unlikely(err))
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
skb->dev = dev;
@@ -1311,7 +1381,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
/* skip the wrapping header */
eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
if (!eth)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
while (skb != frame) {
u8 padding;
@@ -1326,7 +1396,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
/* the last MSDU has no padding */
if (subframe_len > remaining) {
printk(KERN_DEBUG "%s: wrong buffer size", dev->name);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
skb_pull(skb, sizeof(struct ethhdr));
@@ -1338,7 +1408,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
subframe_len);
if (frame == NULL)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
skb_reserve(frame, local->hw.extra_tx_headroom +
sizeof(struct ethhdr));
@@ -1351,7 +1421,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
printk(KERN_DEBUG "%s: wrong buffer size ",
dev->name);
dev_kfree_skb(frame);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
}
@@ -1381,7 +1451,7 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
if (!ieee80211_frame_allowed(rx)) {
if (skb == frame) /* last frame */
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
dev_kfree_skb(frame);
continue;
}
@@ -1389,11 +1459,11 @@ ieee80211_rx_h_amsdu(struct ieee80211_txrx_data *rx)
ieee80211_deliver_skb(rx);
}
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
{
struct net_device *dev = rx->dev;
u16 fc;
@@ -1401,17 +1471,17 @@ ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
fc = rx->fc;
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
err = ieee80211_data_to_8023(rx);
if (unlikely(err))
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
if (!ieee80211_frame_allowed(rx))
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
rx->skb->dev = dev;
@@ -1420,11 +1490,11 @@ ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
ieee80211_deliver_skb(rx);
- return TXRX_QUEUED;
+ return RX_QUEUED;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
{
struct ieee80211_local *local = rx->local;
struct ieee80211_hw *hw = &local->hw;
@@ -1435,15 +1505,16 @@ ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
u16 tid;
if (likely((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if ((rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BACK_REQ) {
if (!rx->sta)
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
tid = le16_to_cpu(bar->control) >> 12;
- tid_agg_rx = &(rx->sta->ampdu_mlme.tid_rx[tid]);
- if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
- return TXRX_CONTINUE;
+ if (rx->sta->ampdu_mlme.tid_state_rx[tid]
+ != HT_AGG_STATE_OPERATIONAL)
+ return RX_CONTINUE;
+ tid_agg_rx = rx->sta->ampdu_mlme.tid_rx[tid];
start_seq_num = le16_to_cpu(bar->start_seq_num) >> 4;
@@ -1460,77 +1531,35 @@ ieee80211_rx_h_ctrl(struct ieee80211_txrx_data *rx)
ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
start_seq_num, 1);
rcu_read_unlock();
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
+static ieee80211_rx_result
+ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
{
struct ieee80211_sub_if_data *sdata;
- if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
- return TXRX_DROP;
+ if (!(rx->flags & IEEE80211_RX_RA_MATCH))
+ return RX_DROP_MONITOR;
sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
if ((sdata->vif.type == IEEE80211_IF_TYPE_STA ||
- sdata->vif.type == IEEE80211_IF_TYPE_IBSS) &&
+ sdata->vif.type == IEEE80211_IF_TYPE_IBSS ||
+ sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) &&
!(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
- ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
+ ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->status);
else
- return TXRX_DROP;
+ return RX_DROP_MONITOR;
- return TXRX_QUEUED;
-}
-
-static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
- struct ieee80211_local *local,
- ieee80211_rx_handler *handlers,
- struct ieee80211_txrx_data *rx,
- struct sta_info *sta)
-{
- ieee80211_rx_handler *handler;
- ieee80211_txrx_result res = TXRX_DROP;
-
- for (handler = handlers; *handler != NULL; handler++) {
- res = (*handler)(rx);
-
- switch (res) {
- case TXRX_CONTINUE:
- continue;
- case TXRX_DROP:
- I802_DEBUG_INC(local->rx_handlers_drop);
- if (sta)
- sta->rx_dropped++;
- break;
- case TXRX_QUEUED:
- I802_DEBUG_INC(local->rx_handlers_queued);
- break;
- }
- break;
- }
-
- if (res == TXRX_DROP)
- dev_kfree_skb(rx->skb);
- return res;
-}
-
-static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
- ieee80211_rx_handler *handlers,
- struct ieee80211_txrx_data *rx,
- struct sta_info *sta)
-{
- if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
- TXRX_CONTINUE)
- dev_kfree_skb(rx->skb);
+ return RX_QUEUED;
}
static void ieee80211_rx_michael_mic_report(struct net_device *dev,
struct ieee80211_hdr *hdr,
- struct sta_info *sta,
- struct ieee80211_txrx_data *rx)
+ struct ieee80211_rx_data *rx)
{
int keyidx, hdrlen;
DECLARE_MAC_BUF(mac);
@@ -1548,7 +1577,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
dev->name, print_mac(mac, hdr->addr2),
print_mac(mac2, hdr->addr1), keyidx);
- if (!sta) {
+ if (!rx->sta) {
/*
* Some hardware seem to generate incorrect Michael MIC
* reports; ignore them to avoid triggering countermeasures.
@@ -1600,7 +1629,89 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
rx->skb = NULL;
}
-ieee80211_rx_handler ieee80211_rx_handlers[] =
+/* TODO: use IEEE80211_RX_FRAGMENTED */
+static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx)
+{
+ struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_local *local = rx->local;
+ struct ieee80211_rtap_hdr {
+ struct ieee80211_radiotap_header hdr;
+ u8 flags;
+ u8 rate;
+ __le16 chan_freq;
+ __le16 chan_flags;
+ } __attribute__ ((packed)) *rthdr;
+ struct sk_buff *skb = rx->skb, *skb2;
+ struct net_device *prev_dev = NULL;
+ struct ieee80211_rx_status *status = rx->status;
+
+ if (rx->flags & IEEE80211_RX_CMNTR_REPORTED)
+ goto out_free_skb;
+
+ if (skb_headroom(skb) < sizeof(*rthdr) &&
+ pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC))
+ goto out_free_skb;
+
+ rthdr = (void *)skb_push(skb, sizeof(*rthdr));
+ memset(rthdr, 0, sizeof(*rthdr));
+ rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
+ rthdr->hdr.it_present =
+ cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
+ (1 << IEEE80211_RADIOTAP_RATE) |
+ (1 << IEEE80211_RADIOTAP_CHANNEL));
+
+ rthdr->rate = rx->rate->bitrate / 5;
+ rthdr->chan_freq = cpu_to_le16(status->freq);
+
+ if (status->band == IEEE80211_BAND_5GHZ)
+ rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_OFDM |
+ IEEE80211_CHAN_5GHZ);
+ else
+ rthdr->chan_flags = cpu_to_le16(IEEE80211_CHAN_DYN |
+ IEEE80211_CHAN_2GHZ);
+
+ skb_set_mac_header(skb, 0);
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ skb->pkt_type = PACKET_OTHERHOST;
+ skb->protocol = htons(ETH_P_802_2);
+
+ list_for_each_entry_rcu(sdata, &local->interfaces, list) {
+ if (!netif_running(sdata->dev))
+ continue;
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR ||
+ !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
+ continue;
+
+ if (prev_dev) {
+ skb2 = skb_clone(skb, GFP_ATOMIC);
+ if (skb2) {
+ skb2->dev = prev_dev;
+ netif_rx(skb2);
+ }
+ }
+
+ prev_dev = sdata->dev;
+ sdata->dev->stats.rx_packets++;
+ sdata->dev->stats.rx_bytes += skb->len;
+ }
+
+ if (prev_dev) {
+ skb->dev = prev_dev;
+ netif_rx(skb);
+ skb = NULL;
+ } else
+ goto out_free_skb;
+
+ rx->flags |= IEEE80211_RX_CMNTR_REPORTED;
+ return;
+
+ out_free_skb:
+ dev_kfree_skb(skb);
+}
+
+typedef ieee80211_rx_result (*ieee80211_rx_handler)(struct ieee80211_rx_data *);
+static ieee80211_rx_handler ieee80211_rx_handlers[] =
{
ieee80211_rx_h_if_stats,
ieee80211_rx_h_passive_scan,
@@ -1622,10 +1733,51 @@ ieee80211_rx_handler ieee80211_rx_handlers[] =
NULL
};
+static void ieee80211_invoke_rx_handlers(struct ieee80211_sub_if_data *sdata,
+ struct ieee80211_rx_data *rx,
+ struct sk_buff *skb)
+{
+ ieee80211_rx_handler *handler;
+ ieee80211_rx_result res = RX_DROP_MONITOR;
+
+ rx->skb = skb;
+ rx->sdata = sdata;
+ rx->dev = sdata->dev;
+
+ for (handler = ieee80211_rx_handlers; *handler != NULL; handler++) {
+ res = (*handler)(rx);
+
+ switch (res) {
+ case RX_CONTINUE:
+ continue;
+ case RX_DROP_UNUSABLE:
+ case RX_DROP_MONITOR:
+ I802_DEBUG_INC(sdata->local->rx_handlers_drop);
+ if (rx->sta)
+ rx->sta->rx_dropped++;
+ break;
+ case RX_QUEUED:
+ I802_DEBUG_INC(sdata->local->rx_handlers_queued);
+ break;
+ }
+ break;
+ }
+
+ switch (res) {
+ case RX_CONTINUE:
+ case RX_DROP_MONITOR:
+ ieee80211_rx_cooked_monitor(rx);
+ break;
+ case RX_DROP_UNUSABLE:
+ dev_kfree_skb(rx->skb);
+ break;
+ }
+}
+
/* main receive path */
static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
- u8 *bssid, struct ieee80211_txrx_data *rx,
+ u8 *bssid, struct ieee80211_rx_data *rx,
struct ieee80211_hdr *hdr)
{
int multicast = is_multicast_ether_addr(hdr->addr1);
@@ -1635,34 +1787,47 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
if (!bssid)
return 0;
if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
- if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
+ if (!(rx->flags & IEEE80211_RX_IN_SCAN))
return 0;
- rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
} else if (!multicast &&
compare_ether_addr(sdata->dev->dev_addr,
hdr->addr1) != 0) {
if (!(sdata->dev->flags & IFF_PROMISC))
return 0;
- rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
}
break;
case IEEE80211_IF_TYPE_IBSS:
if (!bssid)
return 0;
- if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
- if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
+ if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
+ (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
+ return 1;
+ else if (!ieee80211_bssid_match(bssid, sdata->u.sta.bssid)) {
+ if (!(rx->flags & IEEE80211_RX_IN_SCAN))
return 0;
- rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
} else if (!multicast &&
compare_ether_addr(sdata->dev->dev_addr,
hdr->addr1) != 0) {
if (!(sdata->dev->flags & IFF_PROMISC))
return 0;
- rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
} else if (!rx->sta)
rx->sta = ieee80211_ibss_add_sta(sdata->dev, rx->skb,
bssid, hdr->addr2);
break;
+ case IEEE80211_IF_TYPE_MESH_POINT:
+ if (!multicast &&
+ compare_ether_addr(sdata->dev->dev_addr,
+ hdr->addr1) != 0) {
+ if (!(sdata->dev->flags & IFF_PROMISC))
+ return 0;
+
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
+ }
+ break;
case IEEE80211_IF_TYPE_VLAN:
case IEEE80211_IF_TYPE_AP:
if (!bssid) {
@@ -1671,12 +1836,12 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
return 0;
} else if (!ieee80211_bssid_match(bssid,
sdata->dev->dev_addr)) {
- if (!(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
+ if (!(rx->flags & IEEE80211_RX_IN_SCAN))
return 0;
- rx->flags &= ~IEEE80211_TXRXD_RXRA_MATCH;
+ rx->flags &= ~IEEE80211_RX_RA_MATCH;
}
if (sdata->dev == sdata->local->mdev &&
- !(rx->flags & IEEE80211_TXRXD_RXIN_SCAN))
+ !(rx->flags & IEEE80211_RX_IN_SCAN))
/* do not receive anything via
* master device when not scanning */
return 0;
@@ -1707,13 +1872,13 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
struct sk_buff *skb,
struct ieee80211_rx_status *status,
- u32 load)
+ u32 load,
+ struct ieee80211_rate *rate)
{
struct ieee80211_local *local = hw_to_local(hw);
struct ieee80211_sub_if_data *sdata;
- struct sta_info *sta;
struct ieee80211_hdr *hdr;
- struct ieee80211_txrx_data rx;
+ struct ieee80211_rx_data rx;
u16 type;
int prepares;
struct ieee80211_sub_if_data *prev = NULL;
@@ -1725,42 +1890,33 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
rx.skb = skb;
rx.local = local;
- rx.u.rx.status = status;
- rx.u.rx.load = load;
+ rx.status = status;
+ rx.load = load;
+ rx.rate = rate;
rx.fc = le16_to_cpu(hdr->frame_control);
type = rx.fc & IEEE80211_FCTL_FTYPE;
if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
local->dot11ReceivedFragmentCount++;
- sta = rx.sta = sta_info_get(local, hdr->addr2);
- if (sta) {
- rx.dev = rx.sta->dev;
- rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
+ rx.sta = sta_info_get(local, hdr->addr2);
+ if (rx.sta) {
+ rx.sdata = rx.sta->sdata;
+ rx.dev = rx.sta->sdata->dev;
}
if ((status->flag & RX_FLAG_MMIC_ERROR)) {
- ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
- goto end;
+ ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx);
+ return;
}
if (unlikely(local->sta_sw_scanning || local->sta_hw_scanning))
- rx.flags |= IEEE80211_TXRXD_RXIN_SCAN;
+ rx.flags |= IEEE80211_RX_IN_SCAN;
- if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
- sta) != TXRX_CONTINUE)
- goto end;
- skb = rx.skb;
+ ieee80211_parse_qos(&rx);
+ ieee80211_verify_ip_alignment(&rx);
- if (sta && !(sta->flags & (WLAN_STA_WDS | WLAN_STA_ASSOC_AP)) &&
- !atomic_read(&local->iff_promiscs) &&
- !is_multicast_ether_addr(hdr->addr1)) {
- rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
- ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
- rx.sta);
- sta_info_put(sta);
- return;
- }
+ skb = rx.skb;
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
if (!netif_running(sdata->dev))
@@ -1770,10 +1926,8 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
continue;
bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
- rx.flags |= IEEE80211_TXRXD_RXRA_MATCH;
+ rx.flags |= IEEE80211_RX_RA_MATCH;
prepares = prepare_for_handlers(sdata, bssid, &rx, hdr);
- /* prepare_for_handlers can change sta */
- sta = rx.sta;
if (!prepares)
continue;
@@ -1804,26 +1958,14 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
continue;
}
rx.fc = le16_to_cpu(hdr->frame_control);
- rx.skb = skb_new;
- rx.dev = prev->dev;
- rx.sdata = prev;
- ieee80211_invoke_rx_handlers(local, local->rx_handlers,
- &rx, sta);
+ ieee80211_invoke_rx_handlers(prev, &rx, skb_new);
prev = sdata;
}
if (prev) {
rx.fc = le16_to_cpu(hdr->frame_control);
- rx.skb = skb;
- rx.dev = prev->dev;
- rx.sdata = prev;
- ieee80211_invoke_rx_handlers(local, local->rx_handlers,
- &rx, sta);
+ ieee80211_invoke_rx_handlers(prev, &rx, skb);
} else
dev_kfree_skb(skb);
-
- end:
- if (sta)
- sta_info_put(sta);
}
#define SEQ_MODULO 0x1000
@@ -1859,6 +2001,8 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
u16 head_seq_num, buf_size;
int index;
u32 pkt_load;
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_rate *rate;
buf_size = tid_agg_rx->buf_size;
head_seq_num = tid_agg_rx->head_seq_num;
@@ -1889,12 +2033,14 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
memcpy(&status,
tid_agg_rx->reorder_buf[index]->cb,
sizeof(status));
+ sband = local->hw.wiphy->bands[status.band];
+ rate = &sband->bitrates[status.rate_idx];
pkt_load = ieee80211_rx_load_stats(local,
tid_agg_rx->reorder_buf[index],
- &status);
+ &status, rate);
__ieee80211_rx_handle_packet(hw,
tid_agg_rx->reorder_buf[index],
- &status, pkt_load);
+ &status, pkt_load, rate);
tid_agg_rx->stored_mpdu_num--;
tid_agg_rx->reorder_buf[index] = NULL;
}
@@ -1934,11 +2080,13 @@ u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
/* release the reordered frame back to stack */
memcpy(&status, tid_agg_rx->reorder_buf[index]->cb,
sizeof(status));
+ sband = local->hw.wiphy->bands[status.band];
+ rate = &sband->bitrates[status.rate_idx];
pkt_load = ieee80211_rx_load_stats(local,
tid_agg_rx->reorder_buf[index],
- &status);
+ &status, rate);
__ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index],
- &status, pkt_load);
+ &status, pkt_load, rate);
tid_agg_rx->stored_mpdu_num--;
tid_agg_rx->reorder_buf[index] = NULL;
tid_agg_rx->head_seq_num = seq_inc(tid_agg_rx->head_seq_num);
@@ -1973,11 +2121,12 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
qc = skb->data + ieee80211_get_hdrlen(fc) - QOS_CONTROL_LEN;
tid = qc[0] & QOS_CONTROL_TID_MASK;
- tid_agg_rx = &(sta->ampdu_mlme.tid_rx[tid]);
- if (tid_agg_rx->state != HT_AGG_STATE_OPERATIONAL)
+ if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_OPERATIONAL)
goto end_reorder;
+ tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
+
/* null data frames are excluded */
if (unlikely(fc & IEEE80211_STYPE_NULLFUNC))
goto end_reorder;
@@ -1994,7 +2143,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
/* if this mpdu is fragmented - terminate rx aggregation session */
sc = le16_to_cpu(hdr->seq_ctrl);
if (sc & IEEE80211_SCTL_FRAG) {
- ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr,
+ ieee80211_sta_stop_rx_ba_session(sta->sdata->dev, sta->addr,
tid, 0, WLAN_REASON_QSTA_REQUIRE_SETUP);
ret = 1;
goto end_reorder;
@@ -2004,9 +2153,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
mpdu_seq_num, 0);
-end_reorder:
- if (sta)
- sta_info_put(sta);
+ end_reorder:
return ret;
}
@@ -2019,6 +2166,25 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
{
struct ieee80211_local *local = hw_to_local(hw);
u32 pkt_load;
+ struct ieee80211_rate *rate = NULL;
+ struct ieee80211_supported_band *sband;
+
+ if (status->band < 0 ||
+ status->band > IEEE80211_NUM_BANDS) {
+ WARN_ON(1);
+ return;
+ }
+
+ sband = local->hw.wiphy->bands[status->band];
+
+ if (!sband ||
+ status->rate_idx < 0 ||
+ status->rate_idx >= sband->n_bitrates) {
+ WARN_ON(1);
+ return;
+ }
+
+ rate = &sband->bitrates[status->rate_idx];
/*
* key references and virtual interfaces are protected using RCU
@@ -2033,17 +2199,17 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
* if it was previously present.
* Also, frames with less than 16 bytes are dropped.
*/
- skb = ieee80211_rx_monitor(local, skb, status);
+ skb = ieee80211_rx_monitor(local, skb, status, rate);
if (!skb) {
rcu_read_unlock();
return;
}
- pkt_load = ieee80211_rx_load_stats(local, skb, status);
+ pkt_load = ieee80211_rx_load_stats(local, skb, status, rate);
local->channel_use_raw += pkt_load;
if (!ieee80211_rx_reorder_ampdu(local, skb))
- __ieee80211_rx_handle_packet(hw, skb, status, pkt_load);
+ __ieee80211_rx_handle_packet(hw, skb, status, pkt_load, rate);
rcu_read_unlock();
}
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index 1f74bd296357..7d4fe4a52929 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -15,21 +15,57 @@
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/timer.h>
+#include <linux/rtnetlink.h>
#include <net/mac80211.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
#include "sta_info.h"
#include "debugfs_sta.h"
+#include "mesh.h"
-/* Caller must hold local->sta_lock */
-static void sta_info_hash_add(struct ieee80211_local *local,
- struct sta_info *sta)
-{
- sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
- local->sta_hash[STA_HASH(sta->addr)] = sta;
-}
-
+/**
+ * DOC: STA information lifetime rules
+ *
+ * STA info structures (&struct sta_info) are managed in a hash table
+ * for faster lookup and a list for iteration. They are managed using
+ * RCU, i.e. access to the list and hash table is protected by RCU.
+ *
+ * Upon allocating a STA info structure with sta_info_alloc(), the caller owns
+ * that structure. It must then either destroy it using sta_info_destroy()
+ * (which is pretty useless) or insert it into the hash table using
+ * sta_info_insert() which demotes the reference from ownership to a regular
+ * RCU-protected reference; if the function is called without protection by an
+ * RCU critical section the reference is instantly invalidated. Note that the
+ * caller may not do much with the STA info before inserting it, in particular,
+ * it may not start any mesh peer link management or add encryption keys.
+ *
+ * When the insertion fails (sta_info_insert()) returns non-zero), the
+ * structure will have been freed by sta_info_insert()!
+ *
+ * Because there are debugfs entries for each station, and adding those
+ * must be able to sleep, it is also possible to "pin" a station entry,
+ * that means it can be removed from the hash table but not be freed.
+ * See the comment in __sta_info_unlink() for more information, this is
+ * an internal capability only.
+ *
+ * In order to remove a STA info structure, the caller needs to first
+ * unlink it (sta_info_unlink()) from the list and hash tables and
+ * then destroy it; sta_info_destroy() will wait for an RCU grace period
+ * to elapse before actually freeing it. Due to the pinning and the
+ * possibility of multiple callers trying to remove the same STA info at
+ * the same time, sta_info_unlink() can clear the STA info pointer it is
+ * passed to indicate that the STA info is owned by somebody else now.
+ *
+ * If sta_info_unlink() did not clear the pointer then the caller owns
+ * the STA info structure now and is responsible of destroying it with
+ * a call to sta_info_destroy().
+ *
+ * In all other cases, there is no concept of ownership on a STA entry,
+ * each structure is owned by the global hash table/list until it is
+ * removed. All users of the structure need to be RCU protected so that
+ * the structure won't be freed before they are done using it.
+ */
/* Caller must hold local->sta_lock */
static int sta_info_hash_del(struct ieee80211_local *local,
@@ -41,237 +77,439 @@ static int sta_info_hash_del(struct ieee80211_local *local,
if (!s)
return -ENOENT;
if (s == sta) {
- local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
+ rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)],
+ s->hnext);
return 0;
}
while (s->hnext && s->hnext != sta)
s = s->hnext;
if (s->hnext) {
- s->hnext = sta->hnext;
+ rcu_assign_pointer(s->hnext, sta->hnext);
return 0;
}
return -ENOENT;
}
-struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
+/* protected by RCU */
+static struct sta_info *__sta_info_find(struct ieee80211_local *local,
+ u8 *addr)
{
struct sta_info *sta;
- read_lock_bh(&local->sta_lock);
- sta = local->sta_hash[STA_HASH(addr)];
+ sta = rcu_dereference(local->sta_hash[STA_HASH(addr)]);
while (sta) {
- if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
- __sta_info_get(sta);
+ if (compare_ether_addr(sta->addr, addr) == 0)
break;
- }
- sta = sta->hnext;
+ sta = rcu_dereference(sta->hnext);
}
- read_unlock_bh(&local->sta_lock);
-
return sta;
}
+
+struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
+{
+ return __sta_info_find(local, addr);
+}
EXPORT_SYMBOL(sta_info_get);
-int sta_info_min_txrate_get(struct ieee80211_local *local)
+struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
+ struct net_device *dev)
{
struct sta_info *sta;
- struct ieee80211_hw_mode *mode;
- int min_txrate = 9999999;
- int i;
-
- read_lock_bh(&local->sta_lock);
- mode = local->oper_hw_mode;
- for (i = 0; i < STA_HASH_SIZE; i++) {
- sta = local->sta_hash[i];
- while (sta) {
- if (sta->txrate < min_txrate)
- min_txrate = sta->txrate;
- sta = sta->hnext;
+ int i = 0;
+
+ list_for_each_entry_rcu(sta, &local->sta_list, list) {
+ if (dev && dev != sta->sdata->dev)
+ continue;
+ if (i < idx) {
+ ++i;
+ continue;
}
+ return sta;
}
- read_unlock_bh(&local->sta_lock);
- if (min_txrate == 9999999)
- min_txrate = 0;
- return mode->rates[min_txrate].rate;
+ return NULL;
}
+/**
+ * __sta_info_free - internal STA free helper
+ *
+ * @sta: STA info to free
+ *
+ * This function must undo everything done by sta_info_alloc()
+ * that may happen before sta_info_insert().
+ */
+static void __sta_info_free(struct ieee80211_local *local,
+ struct sta_info *sta)
+{
+ DECLARE_MAC_BUF(mbuf);
+
+ rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
+ rate_control_put(sta->rate_ctrl);
+
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+ printk(KERN_DEBUG "%s: Destroyed STA %s\n",
+ wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
-static void sta_info_release(struct kref *kref)
+ kfree(sta);
+}
+
+void sta_info_destroy(struct sta_info *sta)
{
- struct sta_info *sta = container_of(kref, struct sta_info, kref);
- struct ieee80211_local *local = sta->local;
+ struct ieee80211_local *local;
struct sk_buff *skb;
int i;
- /* free sta structure; it has already been removed from
- * hash table etc. external structures. Make sure that all
- * buffered frames are release (one might have been added
- * after sta_info_free() was called). */
+ might_sleep();
+
+ if (!sta)
+ return;
+
+ local = sta->local;
+
+ rate_control_remove_sta_debugfs(sta);
+ ieee80211_sta_debugfs_remove(sta);
+
+#ifdef CONFIG_MAC80211_MESH
+ if (ieee80211_vif_is_mesh(&sta->sdata->vif))
+ mesh_plink_deactivate(sta);
+#endif
+
+ /*
+ * We have only unlinked the key, and actually destroying it
+ * may mean it is removed from hardware which requires that
+ * the key->sta pointer is still valid, so flush the key todo
+ * list here.
+ *
+ * ieee80211_key_todo() will synchronize_rcu() so after this
+ * nothing can reference this sta struct any more.
+ */
+ ieee80211_key_todo();
+
+#ifdef CONFIG_MAC80211_MESH
+ if (ieee80211_vif_is_mesh(&sta->sdata->vif))
+ del_timer_sync(&sta->plink_timer);
+#endif
+
while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
local->total_ps_buffered--;
dev_kfree_skb_any(skb);
}
- while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
+
+ while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL)
dev_kfree_skb_any(skb);
+
+ for (i = 0; i < STA_TID_NUM; i++) {
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_rx);
+ if (sta->ampdu_mlme.tid_rx[i])
+ del_timer_sync(&sta->ampdu_mlme.tid_rx[i]->session_timer);
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_rx);
+ spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
+ if (sta->ampdu_mlme.tid_tx[i])
+ del_timer_sync(&sta->ampdu_mlme.tid_tx[i]->addba_resp_timer);
+ spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
}
- for (i = 0; i < STA_TID_NUM; i++)
- del_timer_sync(&sta->ampdu_mlme.tid_rx[i].session_timer);
- rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
- rate_control_put(sta->rate_ctrl);
- kfree(sta);
+
+ __sta_info_free(local, sta);
}
-void sta_info_put(struct sta_info *sta)
+/* Caller must hold local->sta_lock */
+static void sta_info_hash_add(struct ieee80211_local *local,
+ struct sta_info *sta)
{
- kref_put(&sta->kref, sta_info_release);
+ sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
+ rcu_assign_pointer(local->sta_hash[STA_HASH(sta->addr)], sta);
}
-EXPORT_SYMBOL(sta_info_put);
-
-struct sta_info * sta_info_add(struct ieee80211_local *local,
- struct net_device *dev, u8 *addr, gfp_t gfp)
+struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
+ u8 *addr, gfp_t gfp)
{
+ struct ieee80211_local *local = sdata->local;
struct sta_info *sta;
int i;
- DECLARE_MAC_BUF(mac);
+ DECLARE_MAC_BUF(mbuf);
sta = kzalloc(sizeof(*sta), gfp);
if (!sta)
return NULL;
- kref_init(&sta->kref);
+ memcpy(sta->addr, addr, ETH_ALEN);
+ sta->local = local;
+ sta->sdata = sdata;
sta->rate_ctrl = rate_control_get(local->rate_ctrl);
- sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
+ sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
+ gfp);
if (!sta->rate_ctrl_priv) {
rate_control_put(sta->rate_ctrl);
kfree(sta);
return NULL;
}
- memcpy(sta->addr, addr, ETH_ALEN);
- sta->local = local;
- sta->dev = dev;
spin_lock_init(&sta->ampdu_mlme.ampdu_rx);
+ spin_lock_init(&sta->ampdu_mlme.ampdu_tx);
for (i = 0; i < STA_TID_NUM; i++) {
/* timer_to_tid must be initialized with identity mapping to
* enable session_timer's data differentiation. refer to
* sta_rx_agg_session_timer_expired for useage */
sta->timer_to_tid[i] = i;
- /* rx timers */
- sta->ampdu_mlme.tid_rx[i].session_timer.function =
- sta_rx_agg_session_timer_expired;
- sta->ampdu_mlme.tid_rx[i].session_timer.data =
- (unsigned long)&sta->timer_to_tid[i];
- init_timer(&sta->ampdu_mlme.tid_rx[i].session_timer);
+ /* tid to tx queue: initialize according to HW (0 is valid) */
+ sta->tid_to_tx_q[i] = local->hw.queues;
+ /* rx */
+ sta->ampdu_mlme.tid_state_rx[i] = HT_AGG_STATE_IDLE;
+ sta->ampdu_mlme.tid_rx[i] = NULL;
+ /* tx */
+ sta->ampdu_mlme.tid_state_tx[i] = HT_AGG_STATE_IDLE;
+ sta->ampdu_mlme.tid_tx[i] = NULL;
+ sta->ampdu_mlme.addba_req_num[i] = 0;
}
skb_queue_head_init(&sta->ps_tx_buf);
skb_queue_head_init(&sta->tx_filtered);
- __sta_info_get(sta); /* sta used by caller, decremented by
- * sta_info_put() */
- write_lock_bh(&local->sta_lock);
+
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+ printk(KERN_DEBUG "%s: Allocated STA %s\n",
+ wiphy_name(local->hw.wiphy), print_mac(mbuf, sta->addr));
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+
+#ifdef CONFIG_MAC80211_MESH
+ sta->plink_state = PLINK_LISTEN;
+ spin_lock_init(&sta->plink_lock);
+ init_timer(&sta->plink_timer);
+#endif
+
+ return sta;
+}
+
+int sta_info_insert(struct sta_info *sta)
+{
+ struct ieee80211_local *local = sta->local;
+ struct ieee80211_sub_if_data *sdata = sta->sdata;
+ unsigned long flags;
+ int err = 0;
+ DECLARE_MAC_BUF(mac);
+
+ /*
+ * Can't be a WARN_ON because it can be triggered through a race:
+ * something inserts a STA (on one CPU) without holding the RTNL
+ * and another CPU turns off the net device.
+ */
+ if (unlikely(!netif_running(sdata->dev))) {
+ err = -ENETDOWN;
+ goto out_free;
+ }
+
+ if (WARN_ON(compare_ether_addr(sta->addr, sdata->dev->dev_addr) == 0 ||
+ is_multicast_ether_addr(sta->addr))) {
+ err = -EINVAL;
+ goto out_free;
+ }
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ /* check if STA exists already */
+ if (__sta_info_find(local, sta->addr)) {
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+ err = -EEXIST;
+ goto out_free;
+ }
list_add(&sta->list, &local->sta_list);
local->num_sta++;
sta_info_hash_add(local, sta);
- if (local->ops->sta_notify) {
- struct ieee80211_sub_if_data *sdata;
- sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+ /* notify driver */
+ if (local->ops->sta_notify) {
if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
sdata = sdata->u.vlan.ap;
local->ops->sta_notify(local_to_hw(local), &sdata->vif,
- STA_NOTIFY_ADD, addr);
+ STA_NOTIFY_ADD, sta->addr);
}
- write_unlock_bh(&local->sta_lock);
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- printk(KERN_DEBUG "%s: Added STA %s\n",
- wiphy_name(local->hw.wiphy), print_mac(mac, addr));
+ printk(KERN_DEBUG "%s: Inserted STA %s\n",
+ wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+
#ifdef CONFIG_MAC80211_DEBUGFS
- /* debugfs entry adding might sleep, so schedule process
+ /*
+ * Debugfs entry adding might sleep, so schedule process
* context task for adding entry for STAs that do not yet
- * have one. */
- queue_work(local->hw.workqueue, &local->sta_debugfs_add);
+ * have one.
+ * NOTE: due to auto-freeing semantics this may only be done
+ * if the insertion is successful!
+ */
+ schedule_work(&local->sta_debugfs_add);
#endif
- return sta;
+ if (ieee80211_vif_is_mesh(&sdata->vif))
+ mesh_accept_plinks_update(sdata);
+
+ return 0;
+ out_free:
+ BUG_ON(!err);
+ __sta_info_free(local, sta);
+ return err;
}
-/* Caller must hold local->sta_lock */
-void sta_info_remove(struct sta_info *sta)
+static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
{
- struct ieee80211_local *local = sta->local;
- struct ieee80211_sub_if_data *sdata;
+ /*
+ * This format has been mandated by the IEEE specifications,
+ * so this line may not be changed to use the __set_bit() format.
+ */
+ bss->tim[aid / 8] |= (1 << (aid % 8));
+}
- /* don't do anything if we've been removed already */
- if (sta_info_hash_del(local, sta))
- return;
+static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
+{
+ /*
+ * This format has been mandated by the IEEE specifications,
+ * so this line may not be changed to use the __clear_bit() format.
+ */
+ bss->tim[aid / 8] &= ~(1 << (aid % 8));
+}
- list_del(&sta->list);
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
- if (sta->flags & WLAN_STA_PS) {
- sta->flags &= ~WLAN_STA_PS;
- if (sdata->bss)
- atomic_dec(&sdata->bss->num_sta_ps);
+static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss,
+ struct sta_info *sta)
+{
+ if (bss)
+ __bss_tim_set(bss, sta->aid);
+ if (sta->local->ops->set_tim) {
+ sta->local->tim_in_locked_section = true;
+ sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 1);
+ sta->local->tim_in_locked_section = false;
}
- local->num_sta--;
- sta_info_remove_aid_ptr(sta);
+}
+
+void sta_info_set_tim_bit(struct sta_info *sta)
+{
+ unsigned long flags;
+ spin_lock_irqsave(&sta->local->sta_lock, flags);
+ __sta_info_set_tim_bit(sta->sdata->bss, sta);
+ spin_unlock_irqrestore(&sta->local->sta_lock, flags);
}
-void sta_info_free(struct sta_info *sta)
+static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss,
+ struct sta_info *sta)
{
- struct sk_buff *skb;
- struct ieee80211_local *local = sta->local;
- DECLARE_MAC_BUF(mac);
+ if (bss)
+ __bss_tim_clear(bss, sta->aid);
+ if (sta->local->ops->set_tim) {
+ sta->local->tim_in_locked_section = true;
+ sta->local->ops->set_tim(local_to_hw(sta->local), sta->aid, 0);
+ sta->local->tim_in_locked_section = false;
+ }
+}
- might_sleep();
+void sta_info_clear_tim_bit(struct sta_info *sta)
+{
+ unsigned long flags;
- write_lock_bh(&local->sta_lock);
- sta_info_remove(sta);
- write_unlock_bh(&local->sta_lock);
+ spin_lock_irqsave(&sta->local->sta_lock, flags);
+ __sta_info_clear_tim_bit(sta->sdata->bss, sta);
+ spin_unlock_irqrestore(&sta->local->sta_lock, flags);
+}
- while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
- local->total_ps_buffered--;
- dev_kfree_skb(skb);
- }
- while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
- dev_kfree_skb(skb);
+void __sta_info_unlink(struct sta_info **sta)
+{
+ struct ieee80211_local *local = (*sta)->local;
+ struct ieee80211_sub_if_data *sdata = (*sta)->sdata;
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+ DECLARE_MAC_BUF(mbuf);
+#endif
+ /*
+ * pull caller's reference if we're already gone.
+ */
+ if (sta_info_hash_del(local, *sta)) {
+ *sta = NULL;
+ return;
}
-#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- printk(KERN_DEBUG "%s: Removed STA %s\n",
- wiphy_name(local->hw.wiphy), print_mac(mac, sta->addr));
-#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+ if ((*sta)->key) {
+ ieee80211_key_free((*sta)->key);
+ WARN_ON((*sta)->key);
+ }
- ieee80211_key_free(sta->key);
- sta->key = NULL;
+ list_del(&(*sta)->list);
- if (local->ops->sta_notify) {
- struct ieee80211_sub_if_data *sdata;
+ if ((*sta)->flags & WLAN_STA_PS) {
+ (*sta)->flags &= ~WLAN_STA_PS;
+ if (sdata->bss)
+ atomic_dec(&sdata->bss->num_sta_ps);
+ __sta_info_clear_tim_bit(sdata->bss, *sta);
+ }
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ local->num_sta--;
+ if (local->ops->sta_notify) {
if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
sdata = sdata->u.vlan.ap;
local->ops->sta_notify(local_to_hw(local), &sdata->vif,
- STA_NOTIFY_REMOVE, sta->addr);
+ STA_NOTIFY_REMOVE, (*sta)->addr);
}
- rate_control_remove_sta_debugfs(sta);
- ieee80211_sta_debugfs_remove(sta);
+ if (ieee80211_vif_is_mesh(&sdata->vif)) {
+ mesh_accept_plinks_update(sdata);
+#ifdef CONFIG_MAC80211_MESH
+ del_timer(&(*sta)->plink_timer);
+#endif
+ }
- sta_info_put(sta);
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+ printk(KERN_DEBUG "%s: Removed STA %s\n",
+ wiphy_name(local->hw.wiphy), print_mac(mbuf, (*sta)->addr));
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+
+ /*
+ * Finally, pull caller's reference if the STA is pinned by the
+ * task that is adding the debugfs entries. In that case, we
+ * leave the STA "to be freed".
+ *
+ * The rules are not trivial, but not too complex either:
+ * (1) pin_status is only modified under the sta_lock
+ * (2) STAs may only be pinned under the RTNL so that
+ * sta_info_flush() is guaranteed to actually destroy
+ * all STAs that are active for a given interface, this
+ * is required for correctness because otherwise we
+ * could notify a driver that an interface is going
+ * away and only after that (!) notify it about a STA
+ * on that interface going away.
+ * (3) sta_info_debugfs_add_work() will set the status
+ * to PINNED when it found an item that needs a new
+ * debugfs directory created. In that case, that item
+ * must not be freed although all *RCU* users are done
+ * with it. Hence, we tell the caller of _unlink()
+ * that the item is already gone (as can happen when
+ * two tasks try to unlink/destroy at the same time)
+ * (4) We set the pin_status to DESTROY here when we
+ * find such an item.
+ * (5) sta_info_debugfs_add_work() will reset the pin_status
+ * from PINNED to NORMAL when it is done with the item,
+ * but will check for DESTROY before resetting it in
+ * which case it will free the item.
+ */
+ if ((*sta)->pin_status == STA_INFO_PIN_STAT_PINNED) {
+ (*sta)->pin_status = STA_INFO_PIN_STAT_DESTROY;
+ *sta = NULL;
+ return;
+ }
}
+void sta_info_unlink(struct sta_info **sta)
+{
+ struct ieee80211_local *local = (*sta)->local;
+ unsigned long flags;
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ __sta_info_unlink(sta);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+}
static inline int sta_info_buffer_expired(struct ieee80211_local *local,
struct sta_info *sta,
@@ -299,6 +537,7 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
{
unsigned long flags;
struct sk_buff *skb;
+ struct ieee80211_sub_if_data *sdata;
DECLARE_MAC_BUF(mac);
if (skb_queue_empty(&sta->ps_tx_buf))
@@ -307,21 +546,23 @@ static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
for (;;) {
spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
skb = skb_peek(&sta->ps_tx_buf);
- if (sta_info_buffer_expired(local, sta, skb)) {
+ if (sta_info_buffer_expired(local, sta, skb))
skb = __skb_dequeue(&sta->ps_tx_buf);
- if (skb_queue_empty(&sta->ps_tx_buf))
- sta->flags &= ~WLAN_STA_TIM;
- } else
+ else
skb = NULL;
spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
- if (skb) {
- local->total_ps_buffered--;
- printk(KERN_DEBUG "Buffered frame expired (STA "
- "%s)\n", print_mac(mac, sta->addr));
- dev_kfree_skb(skb);
- } else
+ if (!skb)
break;
+
+ sdata = sta->sdata;
+ local->total_ps_buffered--;
+ printk(KERN_DEBUG "Buffered frame expired (STA "
+ "%s)\n", print_mac(mac, sta->addr));
+ dev_kfree_skb(skb);
+
+ if (skb_queue_empty(&sta->ps_tx_buf))
+ sta_info_clear_tim_bit(sta);
}
}
@@ -331,13 +572,10 @@ static void sta_info_cleanup(unsigned long data)
struct ieee80211_local *local = (struct ieee80211_local *) data;
struct sta_info *sta;
- read_lock_bh(&local->sta_lock);
- list_for_each_entry(sta, &local->sta_list, list) {
- __sta_info_get(sta);
+ rcu_read_lock();
+ list_for_each_entry_rcu(sta, &local->sta_list, list)
sta_info_cleanup_expire_buffered(local, sta);
- sta_info_put(sta);
- }
- read_unlock_bh(&local->sta_lock);
+ rcu_read_unlock();
local->sta_cleanup.expires =
round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
@@ -345,38 +583,106 @@ static void sta_info_cleanup(unsigned long data)
}
#ifdef CONFIG_MAC80211_DEBUGFS
-static void sta_info_debugfs_add_task(struct work_struct *work)
+/*
+ * See comment in __sta_info_unlink,
+ * caller must hold local->sta_lock.
+ */
+static void __sta_info_pin(struct sta_info *sta)
+{
+ WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_NORMAL);
+ sta->pin_status = STA_INFO_PIN_STAT_PINNED;
+}
+
+/*
+ * See comment in __sta_info_unlink, returns sta if it
+ * needs to be destroyed.
+ */
+static struct sta_info *__sta_info_unpin(struct sta_info *sta)
+{
+ struct sta_info *ret = NULL;
+ unsigned long flags;
+
+ spin_lock_irqsave(&sta->local->sta_lock, flags);
+ WARN_ON(sta->pin_status != STA_INFO_PIN_STAT_DESTROY &&
+ sta->pin_status != STA_INFO_PIN_STAT_PINNED);
+ if (sta->pin_status == STA_INFO_PIN_STAT_DESTROY)
+ ret = sta;
+ sta->pin_status = STA_INFO_PIN_STAT_NORMAL;
+ spin_unlock_irqrestore(&sta->local->sta_lock, flags);
+
+ return ret;
+}
+
+static void sta_info_debugfs_add_work(struct work_struct *work)
{
struct ieee80211_local *local =
container_of(work, struct ieee80211_local, sta_debugfs_add);
struct sta_info *sta, *tmp;
+ unsigned long flags;
+ /* We need to keep the RTNL across the whole pinned status. */
+ rtnl_lock();
while (1) {
sta = NULL;
- read_lock_bh(&local->sta_lock);
+
+ spin_lock_irqsave(&local->sta_lock, flags);
list_for_each_entry(tmp, &local->sta_list, list) {
if (!tmp->debugfs.dir) {
sta = tmp;
- __sta_info_get(sta);
+ __sta_info_pin(sta);
break;
}
}
- read_unlock_bh(&local->sta_lock);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
if (!sta)
break;
ieee80211_sta_debugfs_add(sta);
rate_control_add_sta_debugfs(sta);
- sta_info_put(sta);
+
+ sta = __sta_info_unpin(sta);
+ sta_info_destroy(sta);
}
+ rtnl_unlock();
}
#endif
+static void __ieee80211_run_pending_flush(struct ieee80211_local *local)
+{
+ struct sta_info *sta;
+ unsigned long flags;
+
+ ASSERT_RTNL();
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ while (!list_empty(&local->sta_flush_list)) {
+ sta = list_first_entry(&local->sta_flush_list,
+ struct sta_info, list);
+ list_del(&sta->list);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+ sta_info_destroy(sta);
+ spin_lock_irqsave(&local->sta_lock, flags);
+ }
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+}
+
+static void ieee80211_sta_flush_work(struct work_struct *work)
+{
+ struct ieee80211_local *local =
+ container_of(work, struct ieee80211_local, sta_flush_work);
+
+ rtnl_lock();
+ __ieee80211_run_pending_flush(local);
+ rtnl_unlock();
+}
+
void sta_info_init(struct ieee80211_local *local)
{
- rwlock_init(&local->sta_lock);
+ spin_lock_init(&local->sta_lock);
INIT_LIST_HEAD(&local->sta_list);
+ INIT_LIST_HEAD(&local->sta_flush_list);
+ INIT_WORK(&local->sta_flush_work, ieee80211_sta_flush_work);
setup_timer(&local->sta_cleanup, sta_info_cleanup,
(unsigned long)local);
@@ -384,7 +690,7 @@ void sta_info_init(struct ieee80211_local *local)
round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL);
#ifdef CONFIG_MAC80211_DEBUGFS
- INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
+ INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_work);
#endif
}
@@ -397,47 +703,89 @@ int sta_info_start(struct ieee80211_local *local)
void sta_info_stop(struct ieee80211_local *local)
{
del_timer(&local->sta_cleanup);
+ cancel_work_sync(&local->sta_flush_work);
+#ifdef CONFIG_MAC80211_DEBUGFS
+ /*
+ * Make sure the debugfs adding work isn't pending after this
+ * because we're about to be destroyed. It doesn't matter
+ * whether it ran or not since we're going to flush all STAs
+ * anyway.
+ */
+ cancel_work_sync(&local->sta_debugfs_add);
+#endif
+
+ rtnl_lock();
sta_info_flush(local, NULL);
+ __ieee80211_run_pending_flush(local);
+ rtnl_unlock();
}
-void sta_info_remove_aid_ptr(struct sta_info *sta)
+/**
+ * sta_info_flush - flush matching STA entries from the STA table
+ *
+ * Returns the number of removed STA entries.
+ *
+ * @local: local interface data
+ * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
+ */
+int sta_info_flush(struct ieee80211_local *local,
+ struct ieee80211_sub_if_data *sdata)
{
- struct ieee80211_sub_if_data *sdata;
+ struct sta_info *sta, *tmp;
+ LIST_HEAD(tmp_list);
+ int ret = 0;
+ unsigned long flags;
- if (sta->aid <= 0)
- return;
+ might_sleep();
+ ASSERT_RTNL();
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
+ if (!sdata || sdata == sta->sdata) {
+ __sta_info_unlink(&sta);
+ if (sta) {
+ list_add_tail(&sta->list, &tmp_list);
+ ret++;
+ }
+ }
+ }
+ spin_unlock_irqrestore(&local->sta_lock, flags);
- sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+ list_for_each_entry_safe(sta, tmp, &tmp_list, list)
+ sta_info_destroy(sta);
- if (sdata->local->ops->set_tim)
- sdata->local->ops->set_tim(local_to_hw(sdata->local),
- sta->aid, 0);
- if (sdata->bss)
- __bss_tim_clear(sdata->bss, sta->aid);
+ return ret;
}
-
/**
- * sta_info_flush - flush matching STA entries from the STA table
- * @local: local interface data
- * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
+ * sta_info_flush_delayed - flush matching STA entries from the STA table
+ *
+ * This function unlinks all stations for a given interface and queues
+ * them for freeing. Note that the workqueue function scheduled here has
+ * to run before any new keys can be added to the system to avoid set_key()
+ * callback ordering issues.
+ *
+ * @sdata: the interface
*/
-void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
+void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata)
{
+ struct ieee80211_local *local = sdata->local;
struct sta_info *sta, *tmp;
- LIST_HEAD(tmp_list);
-
- write_lock_bh(&local->sta_lock);
- list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
- if (!dev || dev == sta->dev) {
- __sta_info_get(sta);
- sta_info_remove(sta);
- list_add_tail(&sta->list, &tmp_list);
+ unsigned long flags;
+ bool work = false;
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
+ if (sdata == sta->sdata) {
+ __sta_info_unlink(&sta);
+ if (sta) {
+ list_add_tail(&sta->list,
+ &local->sta_flush_list);
+ work = true;
+ }
}
- write_unlock_bh(&local->sta_lock);
-
- list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
- sta_info_free(sta);
- sta_info_put(sta);
}
+ if (work)
+ schedule_work(&local->sta_flush_work);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
}
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 96fe3ed95038..f8c95bc9659c 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -12,160 +12,293 @@
#include <linux/list.h>
#include <linux/types.h>
#include <linux/if_ether.h>
-#include <linux/kref.h>
-#include "ieee80211_key.h"
-
-/* Stations flags (struct sta_info::flags) */
-#define WLAN_STA_AUTH BIT(0)
-#define WLAN_STA_ASSOC BIT(1)
-#define WLAN_STA_PS BIT(2)
-#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
-#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
-#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
- * controlling whether STA is authorized to
- * send and receive non-IEEE 802.1X frames
- */
-#define WLAN_STA_SHORT_PREAMBLE BIT(7)
-/* whether this is an AP that we are associated with as a client */
-#define WLAN_STA_ASSOC_AP BIT(8)
-#define WLAN_STA_WME BIT(9)
-#define WLAN_STA_WDS BIT(27)
+#include "key.h"
+
+/**
+ * enum ieee80211_sta_info_flags - Stations flags
+ *
+ * These flags are used with &struct sta_info's @flags member.
+ *
+ * @WLAN_STA_AUTH: Station is authenticated.
+ * @WLAN_STA_ASSOC: Station is associated.
+ * @WLAN_STA_PS: Station is in power-save mode
+ * @WLAN_STA_AUTHORIZED: Station is authorized to send/receive traffic.
+ * This bit is always checked so needs to be enabled for all stations
+ * when virtual port control is not in use.
+ * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
+ * frames.
+ * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
+ * @WLAN_STA_WME: Station is a QoS-STA.
+ * @WLAN_STA_WDS: Station is one of our WDS peers.
+ * @WLAN_STA_PSPOLL: Station has just PS-polled us.
+ * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
+ * IEEE80211_TXCTL_CLEAR_PS_FILT control flag) when the next
+ * frame to this station is transmitted.
+ */
+enum ieee80211_sta_info_flags {
+ WLAN_STA_AUTH = 1<<0,
+ WLAN_STA_ASSOC = 1<<1,
+ WLAN_STA_PS = 1<<2,
+ WLAN_STA_AUTHORIZED = 1<<3,
+ WLAN_STA_SHORT_PREAMBLE = 1<<4,
+ WLAN_STA_ASSOC_AP = 1<<5,
+ WLAN_STA_WME = 1<<6,
+ WLAN_STA_WDS = 1<<7,
+ WLAN_STA_PSPOLL = 1<<8,
+ WLAN_STA_CLEAR_PS_FILT = 1<<9,
+};
#define STA_TID_NUM 16
#define ADDBA_RESP_INTERVAL HZ
+#define HT_AGG_MAX_RETRIES (0x3)
#define HT_AGG_STATE_INITIATOR_SHIFT (4)
+#define HT_ADDBA_REQUESTED_MSK BIT(0)
+#define HT_ADDBA_DRV_READY_MSK BIT(1)
+#define HT_ADDBA_RECEIVED_MSK BIT(2)
#define HT_AGG_STATE_REQ_STOP_BA_MSK BIT(3)
-
+#define HT_AGG_STATE_INITIATOR_MSK BIT(HT_AGG_STATE_INITIATOR_SHIFT)
#define HT_AGG_STATE_IDLE (0x0)
-#define HT_AGG_STATE_OPERATIONAL (0x7)
+#define HT_AGG_STATE_OPERATIONAL (HT_ADDBA_REQUESTED_MSK | \
+ HT_ADDBA_DRV_READY_MSK | \
+ HT_ADDBA_RECEIVED_MSK)
+#define HT_AGG_STATE_DEBUGFS_CTL BIT(7)
/**
- * struct tid_ampdu_rx - TID aggregation information (Rx).
+ * struct tid_ampdu_tx - TID aggregation information (Tx).
*
- * @state: TID's state in session state machine.
+ * @addba_resp_timer: timer for peer's response to addba request
+ * @ssn: Starting Sequence Number expected to be aggregated.
* @dialog_token: dialog token for aggregation session
+ */
+struct tid_ampdu_tx {
+ struct timer_list addba_resp_timer;
+ u16 ssn;
+ u8 dialog_token;
+};
+
+/**
+ * struct tid_ampdu_rx - TID aggregation information (Rx).
+ *
+ * @reorder_buf: buffer to reorder incoming aggregated MPDUs
+ * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
+ * @head_seq_num: head sequence number in reordering buffer.
+ * @stored_mpdu_num: number of MPDUs in reordering buffer
* @ssn: Starting Sequence Number expected to be aggregated.
* @buf_size: buffer size for incoming A-MPDUs
* @timeout: reset timer value.
- * @head_seq_num: head sequence number in reordering buffer.
- * @stored_mpdu_num: number of MPDUs in reordering buffer
- * @reorder_buf: buffer to reorder incoming aggregated MPDUs
- * @session_timer: check if peer keeps Tx-ing on the TID (by timeout value)
+ * @dialog_token: dialog token for aggregation session
*/
struct tid_ampdu_rx {
- u8 state;
- u8 dialog_token;
+ struct sk_buff **reorder_buf;
+ struct timer_list session_timer;
+ u16 head_seq_num;
+ u16 stored_mpdu_num;
u16 ssn;
u16 buf_size;
u16 timeout;
- u16 head_seq_num;
- u16 stored_mpdu_num;
- struct sk_buff **reorder_buf;
- struct timer_list session_timer;
+ u8 dialog_token;
+};
+
+/**
+ * enum plink_state - state of a mesh peer link finite state machine
+ *
+ * @PLINK_LISTEN: initial state, considered the implicit state of non existant
+ * mesh peer links
+ * @PLINK_OPN_SNT: mesh plink open frame has been sent to this mesh peer
+ * @PLINK_OPN_RCVD: mesh plink open frame has been received from this mesh peer
+ * @PLINK_CNF_RCVD: mesh plink confirm frame has been received from this mesh
+ * peer
+ * @PLINK_ESTAB: mesh peer link is established
+ * @PLINK_HOLDING: mesh peer link is being closed or cancelled
+ * @PLINK_BLOCKED: all frames transmitted from this mesh plink are discarded
+ */
+enum plink_state {
+ PLINK_LISTEN,
+ PLINK_OPN_SNT,
+ PLINK_OPN_RCVD,
+ PLINK_CNF_RCVD,
+ PLINK_ESTAB,
+ PLINK_HOLDING,
+ PLINK_BLOCKED
};
/**
* struct sta_ampdu_mlme - STA aggregation information.
*
- * @tid_agg_info_rx: aggregation info for Rx per TID
+ * @tid_state_rx: TID's state in Rx session state machine.
+ * @tid_rx: aggregation info for Rx per TID
* @ampdu_rx: for locking sections in aggregation Rx flow
+ * @tid_state_tx: TID's state in Tx session state machine.
+ * @tid_tx: aggregation info for Tx per TID
+ * @addba_req_num: number of times addBA request has been sent.
+ * @ampdu_tx: for locking sectionsi in aggregation Tx flow
+ * @dialog_token_allocator: dialog token enumerator for each new session;
*/
struct sta_ampdu_mlme {
- struct tid_ampdu_rx tid_rx[STA_TID_NUM];
+ /* rx */
+ u8 tid_state_rx[STA_TID_NUM];
+ struct tid_ampdu_rx *tid_rx[STA_TID_NUM];
spinlock_t ampdu_rx;
+ /* tx */
+ u8 tid_state_tx[STA_TID_NUM];
+ struct tid_ampdu_tx *tid_tx[STA_TID_NUM];
+ u8 addba_req_num[STA_TID_NUM];
+ spinlock_t ampdu_tx;
+ u8 dialog_token_allocator;
};
+
+/* see __sta_info_unlink */
+#define STA_INFO_PIN_STAT_NORMAL 0
+#define STA_INFO_PIN_STAT_PINNED 1
+#define STA_INFO_PIN_STAT_DESTROY 2
+
+/**
+ * struct sta_info - STA information
+ *
+ * This structure collects information about a station that
+ * mac80211 is communicating with.
+ *
+ * @list: global linked list entry
+ * @hnext: hash table linked list pointer
+ * @local: pointer to the global information
+ * @addr: MAC address of this STA
+ * @aid: STA's unique AID (1..2007, 0 = not assigned yet),
+ * only used in AP (and IBSS?) mode
+ * @flags: STA flags, see &enum ieee80211_sta_info_flags
+ * @ps_tx_buf: buffer of frames to transmit to this station
+ * when it leaves power saving state
+ * @tx_filtered: buffer of frames we already tried to transmit
+ * but were filtered by hardware due to STA having entered
+ * power saving state
+ * @rx_packets: Number of MSDUs received from this STA
+ * @rx_bytes: Number of bytes received from this STA
+ * @supp_rates: Bitmap of supported rates (per band)
+ * @ht_info: HT capabilities of this STA
+ */
struct sta_info {
- struct kref kref;
+ /* General information, mostly static */
struct list_head list;
- struct sta_info *hnext; /* next entry in hash table list */
-
+ struct sta_info *hnext;
struct ieee80211_local *local;
-
- u8 addr[ETH_ALEN];
- u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
- u32 flags; /* WLAN_STA_ */
-
- struct sk_buff_head ps_tx_buf; /* buffer of TX frames for station in
- * power saving state */
- int pspoll; /* whether STA has send a PS Poll frame */
- struct sk_buff_head tx_filtered; /* buffer of TX frames that were
- * already given to low-level driver,
- * but were filtered */
- int clear_dst_mask;
-
- unsigned long rx_packets, tx_packets; /* number of RX/TX MSDUs */
- unsigned long rx_bytes, tx_bytes;
- unsigned long tx_retry_failed, tx_retry_count;
- unsigned long tx_filtered_count;
-
- unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
-
- unsigned long last_rx;
- u32 supp_rates; /* bitmap of supported rates in local->curr_rates */
- int txrate; /* index in local->curr_rates */
- int last_txrate; /* last rate used to send a frame to this STA */
- int last_nonerp_idx;
-
- struct net_device *dev; /* which net device is this station associated
- * to */
-
+ struct ieee80211_sub_if_data *sdata;
struct ieee80211_key *key;
-
- u32 tx_num_consecutive_failures;
- u32 tx_num_mpdu_ok;
- u32 tx_num_mpdu_fail;
-
struct rate_control_ref *rate_ctrl;
void *rate_ctrl_priv;
+ struct ieee80211_ht_info ht_info;
+ u64 supp_rates[IEEE80211_NUM_BANDS];
+ u8 addr[ETH_ALEN];
+ u16 aid;
+ u16 listen_interval;
- /* last received seq/frag number from this STA (per RX queue) */
- __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
+ /*
+ * for use by the internal lifetime management,
+ * see __sta_info_unlink
+ */
+ u8 pin_status;
+
+ /* frequently updated information, needs locking? */
+ u32 flags;
+
+ /*
+ * STA powersave frame queues, no more than the internal
+ * locking required.
+ */
+ struct sk_buff_head ps_tx_buf;
+ struct sk_buff_head tx_filtered;
+
+ /* Updated from RX path only, no locking requirements */
+ unsigned long rx_packets, rx_bytes;
+ unsigned long wep_weak_iv_count;
+ unsigned long last_rx;
unsigned long num_duplicates; /* number of duplicate frames received
* from this STA */
- unsigned long tx_fragments; /* number of transmitted MPDUs */
unsigned long rx_fragments; /* number of received MPDUs */
unsigned long rx_dropped; /* number of dropped MPDUs from this STA */
-
int last_rssi; /* RSSI of last received frame from this STA */
int last_signal; /* signal of last received frame from this STA */
int last_noise; /* noise of last received frame from this STA */
- int last_ack_rssi[3]; /* RSSI of last received ACKs from this STA */
- unsigned long last_ack;
- int channel_use;
- int channel_use_raw;
-
+ /* last received seq/frag number from this STA (per RX queue) */
+ __le16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
+#endif
+
+ /* Updated from TX status path only, no locking requirements */
+ unsigned long tx_filtered_count;
+ unsigned long tx_retry_failed, tx_retry_count;
+ /* TODO: update in generic code not rate control? */
+ u32 tx_num_consecutive_failures;
+ u32 tx_num_mpdu_ok;
+ u32 tx_num_mpdu_fail;
+ /* moving percentage of failed MSDUs */
+ unsigned int fail_avg;
+
+ /* Updated from TX path only, no locking requirements */
+ unsigned long tx_packets; /* number of RX/TX MSDUs */
+ unsigned long tx_bytes;
+ unsigned long tx_fragments; /* number of transmitted MPDUs */
+ int txrate_idx;
+ int last_txrate_idx;
+#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
-#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
+#endif
- u16 listen_interval;
+ /* Debug counters, no locking doesn't matter */
+ int channel_use;
+ int channel_use_raw;
- struct ieee80211_ht_info ht_info; /* 802.11n HT capabilities
- of this STA */
+ /*
+ * Aggregation information, comes with own locking.
+ */
struct sta_ampdu_mlme ampdu_mlme;
- u8 timer_to_tid[STA_TID_NUM]; /* convert timer id to tid */
+ u8 timer_to_tid[STA_TID_NUM]; /* identity mapping to ID timers */
+ u8 tid_to_tx_q[STA_TID_NUM]; /* map tid to tx queue */
+
+#ifdef CONFIG_MAC80211_MESH
+ /*
+ * Mesh peer link attributes
+ * TODO: move to a sub-structure that is referenced with pointer?
+ */
+ __le16 llid; /* Local link ID */
+ __le16 plid; /* Peer link ID */
+ __le16 reason; /* Cancel reason on PLINK_HOLDING state */
+ u8 plink_retries; /* Retries in establishment */
+ bool ignore_plink_timer;
+ enum plink_state plink_state;
+ u32 plink_timeout;
+ struct timer_list plink_timer;
+ spinlock_t plink_lock; /* For peer_state reads / updates and other
+ updates in the structure. Ensures robust
+ transitions for the peerlink FSM */
+#endif
#ifdef CONFIG_MAC80211_DEBUGFS
struct sta_info_debugfsdentries {
struct dentry *dir;
struct dentry *flags;
struct dentry *num_ps_buf_frames;
- struct dentry *last_ack_rssi;
- struct dentry *last_ack_ms;
struct dentry *inactive_ms;
struct dentry *last_seq_ctrl;
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
struct dentry *wme_rx_queue;
struct dentry *wme_tx_queue;
#endif
+ struct dentry *agg_status;
} debugfs;
#endif
};
+static inline enum plink_state sta_plink_state(struct sta_info *sta)
+{
+#ifdef CONFIG_MAC80211_MESH
+ return sta->plink_state;
+#endif
+ return PLINK_LISTEN;
+}
+
/* Maximum number of concurrently registered stations */
#define MAX_STA_COUNT 2007
@@ -185,22 +318,46 @@ struct sta_info {
*/
#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
-static inline void __sta_info_get(struct sta_info *sta)
-{
- kref_get(&sta->kref);
-}
+/*
+ * Get a STA info, must have be under RCU read lock.
+ */
+struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr);
+/*
+ * Get STA info by index, BROKEN!
+ */
+struct sta_info *sta_info_get_by_idx(struct ieee80211_local *local, int idx,
+ struct net_device *dev);
+/*
+ * Create a new STA info, caller owns returned structure
+ * until sta_info_insert().
+ */
+struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
+ u8 *addr, gfp_t gfp);
+/*
+ * Insert STA info into hash table/list, returns zero or a
+ * -EEXIST if (if the same MAC address is already present).
+ *
+ * Calling this without RCU protection makes the caller
+ * relinquish its reference to @sta.
+ */
+int sta_info_insert(struct sta_info *sta);
+/*
+ * Unlink a STA info from the hash table/list.
+ * This can NULL the STA pointer if somebody else
+ * has already unlinked it.
+ */
+void sta_info_unlink(struct sta_info **sta);
+void __sta_info_unlink(struct sta_info **sta);
+
+void sta_info_destroy(struct sta_info *sta);
+void sta_info_set_tim_bit(struct sta_info *sta);
+void sta_info_clear_tim_bit(struct sta_info *sta);
-struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
-int sta_info_min_txrate_get(struct ieee80211_local *local);
-void sta_info_put(struct sta_info *sta);
-struct sta_info * sta_info_add(struct ieee80211_local *local,
- struct net_device *dev, u8 *addr, gfp_t gfp);
-void sta_info_remove(struct sta_info *sta);
-void sta_info_free(struct sta_info *sta);
void sta_info_init(struct ieee80211_local *local);
int sta_info_start(struct ieee80211_local *local);
void sta_info_stop(struct ieee80211_local *local);
-void sta_info_remove_aid_ptr(struct sta_info *sta);
-void sta_info_flush(struct ieee80211_local *local, struct net_device *dev);
+int sta_info_flush(struct ieee80211_local *local,
+ struct ieee80211_sub_if_data *sdata);
+void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata);
#endif /* STA_INFO_H */
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 3abe194e4d55..dddbfd60f351 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -12,7 +12,7 @@
#include <linux/netdevice.h>
#include <net/mac80211.h>
-#include "ieee80211_key.h"
+#include "key.h"
#include "tkip.h"
#include "wep.h"
@@ -214,6 +214,59 @@ void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
key->u.tkip.iv16, rc4key);
}
+void ieee80211_get_tkip_key(struct ieee80211_key_conf *keyconf,
+ struct sk_buff *skb, enum ieee80211_tkip_key_type type,
+ u8 *outkey)
+{
+ struct ieee80211_key *key = (struct ieee80211_key *)
+ container_of(keyconf, struct ieee80211_key, conf);
+ struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+ u8 *data = (u8 *) hdr;
+ u16 fc = le16_to_cpu(hdr->frame_control);
+ int hdr_len = ieee80211_get_hdrlen(fc);
+ u8 *ta = hdr->addr2;
+ u16 iv16;
+ u32 iv32;
+
+ iv16 = data[hdr_len] << 8;
+ iv16 += data[hdr_len + 2];
+ iv32 = data[hdr_len + 4] +
+ (data[hdr_len + 5] >> 8) +
+ (data[hdr_len + 6] >> 16) +
+ (data[hdr_len + 7] >> 24);
+
+#ifdef CONFIG_TKIP_DEBUG
+ printk(KERN_DEBUG "TKIP encrypt: iv16 = 0x%04x, iv32 = 0x%08x\n",
+ iv16, iv32);
+
+ if (iv32 != key->u.tkip.iv32) {
+ printk(KERN_DEBUG "skb: iv32 = 0x%08x key: iv32 = 0x%08x\n",
+ iv32, key->u.tkip.iv32);
+ printk(KERN_DEBUG "Wrap around of iv16 in the middle of a "
+ "fragmented packet\n");
+ }
+#endif /* CONFIG_TKIP_DEBUG */
+
+ /* Update the p1k only when the iv16 in the packet wraps around, this
+ * might occur after the wrap around of iv16 in the key in case of
+ * fragmented packets. */
+ if (iv16 == 0 || !key->u.tkip.tx_initialized) {
+ /* IV16 wrapped around - perform TKIP phase 1 */
+ tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
+ iv32, key->u.tkip.p1k);
+ key->u.tkip.tx_initialized = 1;
+ }
+
+ if (type == IEEE80211_TKIP_P1_KEY) {
+ memcpy(outkey, key->u.tkip.p1k, sizeof(u16) * 5);
+ return;
+ }
+
+ tkip_mixing_phase2(key->u.tkip.p1k,
+ &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY], iv16, outkey);
+}
+EXPORT_SYMBOL(ieee80211_get_tkip_key);
+
/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the
* beginning of the buffer containing payload. This payload must include
* headroom of eight octets for IV and Ext. IV and taildroom of four octets
@@ -238,7 +291,7 @@ void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
struct ieee80211_key *key,
u8 *payload, size_t payload_len, u8 *ta,
- int only_iv, int queue,
+ u8 *ra, int only_iv, int queue,
u32 *out_iv32, u16 *out_iv16)
{
u32 iv32;
@@ -315,6 +368,19 @@ int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
printk("\n");
}
#endif /* CONFIG_TKIP_DEBUG */
+ if (key->local->ops->update_tkip_key &&
+ key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
+ u8 bcast[ETH_ALEN] =
+ {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
+ u8 *sta_addr = key->sta->addr;
+
+ if (is_multicast_ether_addr(ra))
+ sta_addr = bcast;
+
+ key->local->ops->update_tkip_key(
+ local_to_hw(key->local), &key->conf,
+ sta_addr, iv32, key->u.tkip.p1k_rx[queue]);
+ }
}
tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
diff --git a/net/mac80211/tkip.h b/net/mac80211/tkip.h
index 73d8ef2a93b0..b7c2ee763d9d 100644
--- a/net/mac80211/tkip.h
+++ b/net/mac80211/tkip.h
@@ -11,7 +11,7 @@
#include <linux/types.h>
#include <linux/crypto.h>
-#include "ieee80211_key.h"
+#include "key.h"
u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
u8 iv0, u8 iv1, u8 iv2);
@@ -31,7 +31,7 @@ enum {
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
struct ieee80211_key *key,
u8 *payload, size_t payload_len, u8 *ta,
- int only_iv, int queue,
+ u8 *ra, int only_iv, int queue,
u32 *out_iv32, u16 *out_iv16);
#endif /* TKIP_H */
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 67b509edd431..f35eaea98e73 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -25,11 +25,12 @@
#include <asm/unaligned.h>
#include "ieee80211_i.h"
-#include "ieee80211_led.h"
+#include "led.h"
+#include "mesh.h"
#include "wep.h"
#include "wpa.h"
#include "wme.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
#define IEEE80211_TX_OK 0
#define IEEE80211_TX_AGAIN 1
@@ -86,15 +87,19 @@ static inline void ieee80211_dump_frame(const char *ifname, const char *title,
}
#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
-static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
+static u16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
int next_frag_len)
{
int rate, mrate, erp, dur, i;
- struct ieee80211_rate *txrate = tx->u.tx.rate;
+ struct ieee80211_rate *txrate = tx->rate;
struct ieee80211_local *local = tx->local;
- struct ieee80211_hw_mode *mode = tx->u.tx.mode;
+ struct ieee80211_supported_band *sband;
- erp = txrate->flags & IEEE80211_RATE_ERP;
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+ erp = 0;
+ if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
+ erp = txrate->flags & IEEE80211_RATE_ERP_G;
/*
* data and mgmt (except PS Poll):
@@ -150,20 +155,36 @@ static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
* Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
*/
rate = -1;
- mrate = 10; /* use 1 Mbps if everything fails */
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *r = &mode->rates[i];
- if (r->rate > txrate->rate)
- break;
+ /* use lowest available if everything fails */
+ mrate = sband->bitrates[0].bitrate;
+ for (i = 0; i < sband->n_bitrates; i++) {
+ struct ieee80211_rate *r = &sband->bitrates[i];
- if (IEEE80211_RATE_MODULATION(txrate->flags) !=
- IEEE80211_RATE_MODULATION(r->flags))
- continue;
+ if (r->bitrate > txrate->bitrate)
+ break;
- if (r->flags & IEEE80211_RATE_BASIC)
- rate = r->rate;
- else if (r->flags & IEEE80211_RATE_MANDATORY)
- mrate = r->rate;
+ if (tx->sdata->basic_rates & BIT(i))
+ rate = r->bitrate;
+
+ switch (sband->band) {
+ case IEEE80211_BAND_2GHZ: {
+ u32 flag;
+ if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
+ flag = IEEE80211_RATE_MANDATORY_G;
+ else
+ flag = IEEE80211_RATE_MANDATORY_B;
+ if (r->flags & flag)
+ mrate = r->bitrate;
+ break;
+ }
+ case IEEE80211_BAND_5GHZ:
+ if (r->flags & IEEE80211_RATE_MANDATORY_A)
+ mrate = r->bitrate;
+ break;
+ case IEEE80211_NUM_BANDS:
+ WARN_ON(1);
+ break;
+ }
}
if (rate == -1) {
/* 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,
dur *= 2; /* ACK + SIFS */
/* next fragment */
dur += ieee80211_frame_duration(local, next_frag_len,
- txrate->rate, erp,
+ txrate->bitrate, erp,
tx->sdata->bss_conf.use_short_preamble);
}
@@ -212,8 +233,8 @@ static int inline is_ieee80211_device(struct net_device *dev,
/* tx handlers */
-static ieee80211_txrx_result
-ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
{
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
struct sk_buff *skb = tx->skb;
@@ -221,20 +242,23 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
u32 sta_flags;
- if (unlikely(tx->flags & IEEE80211_TXRXD_TX_INJECTED))
- return TXRX_CONTINUE;
+ if (unlikely(tx->flags & IEEE80211_TX_INJECTED))
+ return TX_CONTINUE;
if (unlikely(tx->local->sta_sw_scanning) &&
((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
(tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
- return TXRX_DROP;
+ return TX_DROP;
- if (tx->flags & IEEE80211_TXRXD_TXPS_BUFFERED)
- return TXRX_CONTINUE;
+ if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
+ return TX_CONTINUE;
+
+ if (tx->flags & IEEE80211_TX_PS_BUFFERED)
+ return TX_CONTINUE;
sta_flags = tx->sta ? tx->sta->flags : 0;
- if (likely(tx->flags & IEEE80211_TXRXD_TXUNICAST)) {
+ if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
(tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
@@ -245,7 +269,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
tx->dev->name, print_mac(mac, hdr->addr1));
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
- return TXRX_DROP;
+ return TX_DROP;
}
} else {
if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
@@ -255,23 +279,23 @@ ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
* No associated STAs - no need to send multicast
* frames.
*/
- return TXRX_DROP;
+ return TX_DROP;
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_sequence(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24)
ieee80211_include_sequence(tx->sdata, hdr);
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
/* 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)
}
total += skb_queue_len(&ap->ps_bc_buf);
}
- rcu_read_unlock();
- read_lock_bh(&local->sta_lock);
- list_for_each_entry(sta, &local->sta_list, list) {
+ list_for_each_entry_rcu(sta, &local->sta_list, list) {
skb = skb_dequeue(&sta->ps_tx_buf);
if (skb) {
purged++;
@@ -314,15 +336,16 @@ static void purge_old_ps_buffers(struct ieee80211_local *local)
}
total += skb_queue_len(&sta->ps_tx_buf);
}
- read_unlock_bh(&local->sta_lock);
+
+ rcu_read_unlock();
local->total_ps_buffered = total;
printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
wiphy_name(local->hw.wiphy), purged);
}
-static ieee80211_txrx_result
-ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
{
/*
* broadcast/multicast frame
@@ -334,11 +357,11 @@ ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
/* not AP/IBSS or ordered frame */
if (!tx->sdata->bss || (tx->fc & IEEE80211_FCTL_ORDER))
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
/* no stations in PS mode */
if (!atomic_read(&tx->sdata->bss->num_sta_ps))
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
/* buffered in mac80211 */
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)
} else
tx->local->total_ps_buffered++;
skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
- return TXRX_QUEUED;
+ return TX_QUEUED;
}
/* buffered in hardware */
- tx->u.tx.control->flags |= IEEE80211_TXCTL_SEND_AFTER_DTIM;
+ tx->control->flags |= IEEE80211_TXCTL_SEND_AFTER_DTIM;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
{
struct sta_info *sta = tx->sta;
DECLARE_MAC_BUF(mac);
@@ -373,9 +396,10 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
if (unlikely(!sta ||
((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
(tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)))
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
- if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
+ if (unlikely((sta->flags & WLAN_STA_PS) &&
+ !(sta->flags & WLAN_STA_PSPOLL))) {
struct ieee80211_tx_packet_data *pkt_data;
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
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)
print_mac(mac, sta->addr), sta->aid,
skb_queue_len(&sta->ps_tx_buf));
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
- sta->flags |= WLAN_STA_TIM;
if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
purge_old_ps_buffers(tx->local);
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)
dev_kfree_skb(old);
} else
tx->local->total_ps_buffered++;
+
/* Queue frame to be sent after STA sends an PS Poll frame */
- if (skb_queue_empty(&sta->ps_tx_buf)) {
- if (tx->local->ops->set_tim)
- tx->local->ops->set_tim(local_to_hw(tx->local),
- sta->aid, 1);
- if (tx->sdata->bss)
- bss_tim_set(tx->local, tx->sdata->bss, sta->aid);
- }
+ if (skb_queue_empty(&sta->ps_tx_buf))
+ sta_info_set_tim_bit(sta);
+
pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
pkt_data->jiffies = jiffies;
skb_queue_tail(&sta->ps_tx_buf, tx->skb);
- return TXRX_QUEUED;
+ return TX_QUEUED;
}
#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
else if (unlikely(sta->flags & WLAN_STA_PS)) {
@@ -416,40 +436,40 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
print_mac(mac, sta->addr));
}
#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
- sta->pspoll = 0;
+ sta->flags &= ~WLAN_STA_PSPOLL;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
{
- if (unlikely(tx->flags & IEEE80211_TXRXD_TXPS_BUFFERED))
- return TXRX_CONTINUE;
+ if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
+ return TX_CONTINUE;
- if (tx->flags & IEEE80211_TXRXD_TXUNICAST)
+ if (tx->flags & IEEE80211_TX_UNICAST)
return ieee80211_tx_h_unicast_ps_buf(tx);
else
return ieee80211_tx_h_multicast_ps_buf(tx);
}
-static ieee80211_txrx_result
-ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
{
struct ieee80211_key *key;
u16 fc = tx->fc;
- if (unlikely(tx->u.tx.control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
+ if (unlikely(tx->control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
tx->key = NULL;
else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
tx->key = key;
else if ((key = rcu_dereference(tx->sdata->default_key)))
tx->key = key;
else if (tx->sdata->drop_unencrypted &&
- !(tx->u.tx.control->flags & IEEE80211_TXCTL_EAPOL_FRAME) &&
- !(tx->flags & IEEE80211_TXRXD_TX_INJECTED)) {
+ !(tx->control->flags & IEEE80211_TXCTL_EAPOL_FRAME) &&
+ !(tx->flags & IEEE80211_TX_INJECTED)) {
I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
- return TXRX_DROP;
+ return TX_DROP;
} else
tx->key = NULL;
@@ -476,13 +496,13 @@ ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
}
if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
- tx->u.tx.control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
+ tx->control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
size_t hdrlen, per_fragm, num_fragm, payload_len, left;
@@ -492,8 +512,8 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
u8 *pos;
int frag_threshold = tx->local->fragmentation_threshold;
- if (!(tx->flags & IEEE80211_TXRXD_FRAGMENTED))
- return TXRX_CONTINUE;
+ if (!(tx->flags & IEEE80211_TX_FRAGMENTED))
+ return TX_CONTINUE;
first = tx->skb;
@@ -544,10 +564,10 @@ ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
}
skb_trim(first, hdrlen + per_fragm);
- tx->u.tx.num_extra_frag = num_fragm - 1;
- tx->u.tx.extra_frag = frags;
+ tx->num_extra_frag = num_fragm - 1;
+ tx->extra_frag = frags;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
fail:
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)
kfree(frags);
}
I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
- return TXRX_DROP;
+ return TX_DROP;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_encrypt(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
{
if (!tx->key)
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
switch (tx->key->conf.alg) {
case ALG_WEP:
@@ -578,59 +598,60 @@ ieee80211_tx_h_encrypt(struct ieee80211_txrx_data *tx)
/* not reached */
WARN_ON(1);
- return TXRX_DROP;
+ return TX_DROP;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
{
struct rate_selection rsel;
+ struct ieee80211_supported_band *sband;
+
+ sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
- if (likely(!tx->u.tx.rate)) {
- rate_control_get_rate(tx->dev, tx->u.tx.mode, tx->skb, &rsel);
- tx->u.tx.rate = rsel.rate;
- if (unlikely(rsel.probe != NULL)) {
- tx->u.tx.control->flags |=
+ if (likely(!tx->rate)) {
+ rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
+ tx->rate = rsel.rate;
+ if (unlikely(rsel.probe)) {
+ tx->control->flags |=
IEEE80211_TXCTL_RATE_CTRL_PROBE;
- tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
- tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
- tx->u.tx.rate = rsel.probe;
+ tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
+ tx->control->alt_retry_rate = tx->rate;
+ tx->rate = rsel.probe;
} else
- tx->u.tx.control->alt_retry_rate = -1;
+ tx->control->alt_retry_rate = NULL;
- if (!tx->u.tx.rate)
- return TXRX_DROP;
+ if (!tx->rate)
+ return TX_DROP;
} else
- tx->u.tx.control->alt_retry_rate = -1;
+ tx->control->alt_retry_rate = NULL;
- if (tx->u.tx.mode->mode == MODE_IEEE80211G &&
- tx->sdata->bss_conf.use_cts_prot &&
- (tx->flags & IEEE80211_TXRXD_FRAGMENTED) && rsel.nonerp) {
- tx->u.tx.last_frag_rate = tx->u.tx.rate;
+ if (tx->sdata->bss_conf.use_cts_prot &&
+ (tx->flags & IEEE80211_TX_FRAGMENTED) && rsel.nonerp) {
+ tx->last_frag_rate = tx->rate;
if (rsel.probe)
- tx->flags &= ~IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
+ tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG;
else
- tx->flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
- tx->u.tx.rate = rsel.nonerp;
- tx->u.tx.control->rate = rsel.nonerp;
- tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
+ tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
+ tx->rate = rsel.nonerp;
+ tx->control->tx_rate = rsel.nonerp;
+ tx->control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
} else {
- tx->u.tx.last_frag_rate = tx->u.tx.rate;
- tx->u.tx.control->rate = tx->u.tx.rate;
+ tx->last_frag_rate = tx->rate;
+ tx->control->tx_rate = tx->rate;
}
- tx->u.tx.control->tx_rate = tx->u.tx.rate->val;
+ tx->control->tx_rate = tx->rate;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
u16 fc = le16_to_cpu(hdr->frame_control);
u16 dur;
- struct ieee80211_tx_control *control = tx->u.tx.control;
- struct ieee80211_hw_mode *mode = tx->u.tx.mode;
+ struct ieee80211_tx_control *control = tx->control;
if (!control->retry_limit) {
if (!is_multicast_ether_addr(hdr->addr1)) {
@@ -652,20 +673,20 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
}
}
- if (tx->flags & IEEE80211_TXRXD_FRAGMENTED) {
+ if (tx->flags & IEEE80211_TX_FRAGMENTED) {
/* Do not use multiple retry rates when sending fragmented
* frames.
* TODO: The last fragment could still use multiple retry
* rates. */
- control->alt_retry_rate = -1;
+ control->alt_retry_rate = NULL;
}
/* Use CTS protection for unicast frames sent using extended rates if
* there are associated non-ERP stations and RTS/CTS is not configured
* for the frame. */
- if (mode->mode == MODE_IEEE80211G &&
- (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
- (tx->flags & IEEE80211_TXRXD_TXUNICAST) &&
+ if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) &&
+ (tx->rate->flags & IEEE80211_RATE_ERP_G) &&
+ (tx->flags & IEEE80211_TX_UNICAST) &&
tx->sdata->bss_conf.use_cts_prot &&
!(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
@@ -674,62 +695,77 @@ ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
* short preambles at the selected rate and short preambles are
* available on the network at the current point in time. */
if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
- (tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
+ (tx->rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
tx->sdata->bss_conf.use_short_preamble &&
(!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
- tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
+ tx->control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
}
/* Setup duration field for the first fragment of the frame. Duration
* for remaining fragments will be updated when they are being sent
* to low-level driver in ieee80211_tx(). */
dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1),
- (tx->flags & IEEE80211_TXRXD_FRAGMENTED) ?
- tx->u.tx.extra_frag[0]->len : 0);
+ (tx->flags & IEEE80211_TX_FRAGMENTED) ?
+ tx->extra_frag[0]->len : 0);
hdr->duration_id = cpu_to_le16(dur);
if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
(control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
- struct ieee80211_rate *rate;
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_rate *rate, *baserate;
+ int idx;
+
+ sband = tx->local->hw.wiphy->bands[
+ tx->local->hw.conf.channel->band];
/* Do not use multiple retry rates when using RTS/CTS */
- control->alt_retry_rate = -1;
+ control->alt_retry_rate = NULL;
/* Use min(data rate, max base rate) as CTS/RTS rate */
- rate = tx->u.tx.rate;
- while (rate > mode->rates &&
- !(rate->flags & IEEE80211_RATE_BASIC))
- rate--;
+ rate = tx->rate;
+ baserate = NULL;
+
+ for (idx = 0; idx < sband->n_bitrates; idx++) {
+ if (sband->bitrates[idx].bitrate > rate->bitrate)
+ continue;
+ if (tx->sdata->basic_rates & BIT(idx) &&
+ (!baserate ||
+ (baserate->bitrate < sband->bitrates[idx].bitrate)))
+ baserate = &sband->bitrates[idx];
+ }
- control->rts_cts_rate = rate->val;
- control->rts_rate = rate;
+ if (baserate)
+ control->rts_cts_rate = baserate;
+ else
+ control->rts_cts_rate = &sband->bitrates[0];
}
if (tx->sta) {
+ control->aid = tx->sta->aid;
tx->sta->tx_packets++;
tx->sta->tx_fragments++;
tx->sta->tx_bytes += tx->skb->len;
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
int i;
- tx->sta->tx_fragments += tx->u.tx.num_extra_frag;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+ tx->sta->tx_fragments += tx->num_extra_frag;
+ for (i = 0; i < tx->num_extra_frag; i++) {
tx->sta->tx_bytes +=
- tx->u.tx.extra_frag[i]->len;
+ tx->extra_frag[i]->len;
}
}
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-static ieee80211_txrx_result
-ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
+static ieee80211_tx_result
+ieee80211_tx_h_load_stats(struct ieee80211_tx_data *tx)
{
struct ieee80211_local *local = tx->local;
- struct ieee80211_hw_mode *mode = tx->u.tx.mode;
struct sk_buff *skb = tx->skb;
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
u32 load = 0, hdrtime;
+ struct ieee80211_rate *rate = tx->rate;
/* TODO: this could be part of tx_status handling, so that the number
* of retries would be known; TX rate should in that case be stored
@@ -740,9 +776,9 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
/* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
* 1 usec = 1/8 * (1080 / 10) = 13.5 */
- if (mode->mode == MODE_IEEE80211A ||
- (mode->mode == MODE_IEEE80211G &&
- tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
+ if (tx->channel->band == IEEE80211_BAND_5GHZ ||
+ (tx->channel->band == IEEE80211_BAND_2GHZ &&
+ rate->flags & IEEE80211_RATE_ERP_G))
hdrtime = CHAN_UTIL_HDR_SHORT;
else
hdrtime = CHAN_UTIL_HDR_LONG;
@@ -751,19 +787,20 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
if (!is_multicast_ether_addr(hdr->addr1))
load += hdrtime;
- if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
+ if (tx->control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
load += 2 * hdrtime;
- else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
+ else if (tx->control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
load += hdrtime;
- load += skb->len * tx->u.tx.rate->rate_inv;
+ /* TODO: optimise again */
+ load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
int i;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+ for (i = 0; i < tx->num_extra_frag; i++) {
load += 2 * hdrtime;
- load += tx->u.tx.extra_frag[i]->len *
- tx->u.tx.rate->rate;
+ load += tx->extra_frag[i]->len *
+ tx->rate->bitrate;
}
}
@@ -774,13 +811,12 @@ ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
tx->sta->channel_use_raw += load;
tx->sdata->channel_use_raw += load;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-/* TODO: implement register/unregister functions for adding TX/RX handlers
- * into ordered list */
-ieee80211_tx_handler ieee80211_tx_handlers[] =
+typedef ieee80211_tx_result (*ieee80211_tx_handler)(struct ieee80211_tx_data *);
+static ieee80211_tx_handler ieee80211_tx_handlers[] =
{
ieee80211_tx_h_check_assoc,
ieee80211_tx_h_sequence,
@@ -801,8 +837,8 @@ ieee80211_tx_handler ieee80211_tx_handlers[] =
* deal with packet injection down monitor interface
* with Radiotap Header -- only called for monitor mode interface
*/
-static ieee80211_txrx_result
-__ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
+static ieee80211_tx_result
+__ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
struct sk_buff *skb)
{
/*
@@ -816,13 +852,15 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
struct ieee80211_radiotap_iterator iterator;
struct ieee80211_radiotap_header *rthdr =
(struct ieee80211_radiotap_header *) skb->data;
- struct ieee80211_hw_mode *mode = tx->local->hw.conf.mode;
+ struct ieee80211_supported_band *sband;
int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
- struct ieee80211_tx_control *control = tx->u.tx.control;
+ struct ieee80211_tx_control *control = tx->control;
+
+ sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
- tx->flags |= IEEE80211_TXRXD_TX_INJECTED;
- tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED;
+ tx->flags |= IEEE80211_TX_INJECTED;
+ tx->flags &= ~IEEE80211_TX_FRAGMENTED;
/*
* for every radiotap entry that is present
@@ -852,11 +890,13 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
* ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
*/
target_rate = (*iterator.this_arg) * 5;
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *r = &mode->rates[i];
+ for (i = 0; i < sband->n_bitrates; i++) {
+ struct ieee80211_rate *r;
+
+ r = &sband->bitrates[i];
- if (r->rate == target_rate) {
- tx->u.tx.rate = r;
+ if (r->bitrate == target_rate) {
+ tx->rate = r;
break;
}
}
@@ -870,9 +910,11 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
control->antenna_sel_tx = (*iterator.this_arg) + 1;
break;
+#if 0
case IEEE80211_RADIOTAP_DBM_TX_POWER:
control->power_level = *iterator.this_arg;
break;
+#endif
case IEEE80211_RADIOTAP_FLAGS:
if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
@@ -884,7 +926,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
* on transmission
*/
if (skb->len < (iterator.max_length + FCS_LEN))
- return TXRX_DROP;
+ return TX_DROP;
skb_trim(skb, skb->len - FCS_LEN);
}
@@ -892,7 +934,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
control->flags &=
~IEEE80211_TXCTL_DO_NOT_ENCRYPT;
if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
- tx->flags |= IEEE80211_TXRXD_FRAGMENTED;
+ tx->flags |= IEEE80211_TX_FRAGMENTED;
break;
/*
@@ -907,7 +949,7 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
}
if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
- return TXRX_DROP;
+ return TX_DROP;
/*
* remove the radiotap header
@@ -916,14 +958,14 @@ __ieee80211_parse_tx_radiotap(struct ieee80211_txrx_data *tx,
*/
skb_pull(skb, iterator.max_length);
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
/*
* initialises @tx
*/
-static ieee80211_txrx_result
-__ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
+static ieee80211_tx_result
+__ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
struct sk_buff *skb,
struct net_device *dev,
struct ieee80211_tx_control *control)
@@ -939,18 +981,18 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
tx->dev = dev; /* use original interface */
tx->local = local;
tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- tx->u.tx.control = control;
+ tx->control = control;
/*
* Set this flag (used below to indicate "automatic fragmentation"),
* it will be cleared/left by radiotap as desired.
*/
- tx->flags |= IEEE80211_TXRXD_FRAGMENTED;
+ tx->flags |= IEEE80211_TX_FRAGMENTED;
/* process and remove the injection radiotap header */
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) {
- if (__ieee80211_parse_tx_radiotap(tx, skb) == TXRX_DROP)
- return TXRX_DROP;
+ if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP)
+ return TX_DROP;
/*
* __ieee80211_parse_tx_radiotap has now removed
@@ -965,27 +1007,27 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
tx->fc = le16_to_cpu(hdr->frame_control);
if (is_multicast_ether_addr(hdr->addr1)) {
- tx->flags &= ~IEEE80211_TXRXD_TXUNICAST;
+ tx->flags &= ~IEEE80211_TX_UNICAST;
control->flags |= IEEE80211_TXCTL_NO_ACK;
} else {
- tx->flags |= IEEE80211_TXRXD_TXUNICAST;
+ tx->flags |= IEEE80211_TX_UNICAST;
control->flags &= ~IEEE80211_TXCTL_NO_ACK;
}
- if (tx->flags & IEEE80211_TXRXD_FRAGMENTED) {
- if ((tx->flags & IEEE80211_TXRXD_TXUNICAST) &&
+ if (tx->flags & IEEE80211_TX_FRAGMENTED) {
+ if ((tx->flags & IEEE80211_TX_UNICAST) &&
skb->len + FCS_LEN > local->fragmentation_threshold &&
!local->ops->set_frag_threshold)
- tx->flags |= IEEE80211_TXRXD_FRAGMENTED;
+ tx->flags |= IEEE80211_TX_FRAGMENTED;
else
- tx->flags &= ~IEEE80211_TXRXD_FRAGMENTED;
+ tx->flags &= ~IEEE80211_TX_FRAGMENTED;
}
if (!tx->sta)
- control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
- else if (tx->sta->clear_dst_mask) {
- control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
- tx->sta->clear_dst_mask = 0;
+ control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
+ else if (tx->sta->flags & WLAN_STA_CLEAR_PS_FILT) {
+ control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
+ tx->sta->flags &= ~WLAN_STA_CLEAR_PS_FILT;
}
hdrlen = ieee80211_get_hdrlen(tx->fc);
@@ -995,13 +1037,13 @@ __ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
}
control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
/*
* NB: @tx is uninitialised when passed in here
*/
-static int ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
+static int ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
struct sk_buff *skb,
struct net_device *mdev,
struct ieee80211_tx_control *control)
@@ -1024,9 +1066,9 @@ static int ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
}
static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
- struct ieee80211_txrx_data *tx)
+ struct ieee80211_tx_data *tx)
{
- struct ieee80211_tx_control *control = tx->u.tx.control;
+ struct ieee80211_tx_control *control = tx->control;
int ret, i;
if (!ieee80211_qdisc_installed(local->mdev) &&
@@ -1043,20 +1085,20 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
local->mdev->trans_start = jiffies;
ieee80211_led_tx(local, 1);
}
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
IEEE80211_TXCTL_USE_CTS_PROTECT |
- IEEE80211_TXCTL_CLEAR_DST_MASK |
+ IEEE80211_TXCTL_CLEAR_PS_FILT |
IEEE80211_TXCTL_FIRST_FRAGMENT);
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
- if (!tx->u.tx.extra_frag[i])
+ for (i = 0; i < tx->num_extra_frag; i++) {
+ if (!tx->extra_frag[i])
continue;
if (__ieee80211_queue_stopped(local, control->queue))
return IEEE80211_TX_FRAG_AGAIN;
- if (i == tx->u.tx.num_extra_frag) {
- control->tx_rate = tx->u.tx.last_frag_hwrate;
- control->rate = tx->u.tx.last_frag_rate;
- if (tx->flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG)
+ if (i == tx->num_extra_frag) {
+ control->tx_rate = tx->last_frag_rate;
+
+ if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG)
control->flags |=
IEEE80211_TXCTL_RATE_CTRL_PROBE;
else
@@ -1066,18 +1108,18 @@ static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
"TX to low-level driver",
- tx->u.tx.extra_frag[i]);
+ tx->extra_frag[i]);
ret = local->ops->tx(local_to_hw(local),
- tx->u.tx.extra_frag[i],
+ tx->extra_frag[i],
control);
if (ret)
return IEEE80211_TX_FRAG_AGAIN;
local->mdev->trans_start = jiffies;
ieee80211_led_tx(local, 1);
- tx->u.tx.extra_frag[i] = NULL;
+ tx->extra_frag[i] = NULL;
}
- kfree(tx->u.tx.extra_frag);
- tx->u.tx.extra_frag = NULL;
+ kfree(tx->extra_frag);
+ tx->extra_frag = NULL;
}
return IEEE80211_TX_OK;
}
@@ -1088,8 +1130,8 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct sta_info *sta;
ieee80211_tx_handler *handler;
- struct ieee80211_txrx_data tx;
- ieee80211_txrx_result res = TXRX_DROP, res_prepare;
+ struct ieee80211_tx_data tx;
+ ieee80211_tx_result res = TX_DROP, res_prepare;
int ret, i;
WARN_ON(__ieee80211_queue_pending(local, control->queue));
@@ -1099,59 +1141,52 @@ static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
return 0;
}
+ rcu_read_lock();
+
/* initialises tx */
res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control);
- if (res_prepare == TXRX_DROP) {
+ if (res_prepare == TX_DROP) {
dev_kfree_skb(skb);
+ rcu_read_unlock();
return 0;
}
- /*
- * key references are protected using RCU and this requires that
- * we are in a read-site RCU section during receive processing
- */
- rcu_read_lock();
-
sta = tx.sta;
- tx.u.tx.mode = local->hw.conf.mode;
+ tx.channel = local->hw.conf.channel;
- for (handler = local->tx_handlers; *handler != NULL;
+ for (handler = ieee80211_tx_handlers; *handler != NULL;
handler++) {
res = (*handler)(&tx);
- if (res != TXRX_CONTINUE)
+ if (res != TX_CONTINUE)
break;
}
skb = tx.skb; /* handlers are allowed to change skb */
- if (sta)
- sta_info_put(sta);
-
- if (unlikely(res == TXRX_DROP)) {
+ if (unlikely(res == TX_DROP)) {
I802_DEBUG_INC(local->tx_handlers_drop);
goto drop;
}
- if (unlikely(res == TXRX_QUEUED)) {
+ if (unlikely(res == TX_QUEUED)) {
I802_DEBUG_INC(local->tx_handlers_queued);
rcu_read_unlock();
return 0;
}
- if (tx.u.tx.extra_frag) {
- for (i = 0; i < tx.u.tx.num_extra_frag; i++) {
+ if (tx.extra_frag) {
+ for (i = 0; i < tx.num_extra_frag; i++) {
int next_len, dur;
struct ieee80211_hdr *hdr =
(struct ieee80211_hdr *)
- tx.u.tx.extra_frag[i]->data;
+ tx.extra_frag[i]->data;
- if (i + 1 < tx.u.tx.num_extra_frag) {
- next_len = tx.u.tx.extra_frag[i + 1]->len;
+ if (i + 1 < tx.num_extra_frag) {
+ next_len = tx.extra_frag[i + 1]->len;
} else {
next_len = 0;
- tx.u.tx.rate = tx.u.tx.last_frag_rate;
- tx.u.tx.last_frag_hwrate = tx.u.tx.rate->val;
+ tx.rate = tx.last_frag_rate;
}
dur = ieee80211_duration(&tx, 0, next_len);
hdr->duration_id = cpu_to_le16(dur);
@@ -1186,12 +1221,11 @@ retry:
memcpy(&store->control, control,
sizeof(struct ieee80211_tx_control));
store->skb = skb;
- store->extra_frag = tx.u.tx.extra_frag;
- store->num_extra_frag = tx.u.tx.num_extra_frag;
- store->last_frag_hwrate = tx.u.tx.last_frag_hwrate;
- store->last_frag_rate = tx.u.tx.last_frag_rate;
+ store->extra_frag = tx.extra_frag;
+ store->num_extra_frag = tx.num_extra_frag;
+ store->last_frag_rate = tx.last_frag_rate;
store->last_frag_rate_ctrl_probe =
- !!(tx.flags & IEEE80211_TXRXD_TXPROBE_LAST_FRAG);
+ !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG);
}
rcu_read_unlock();
return 0;
@@ -1199,10 +1233,10 @@ retry:
drop:
if (skb)
dev_kfree_skb(skb);
- for (i = 0; i < tx.u.tx.num_extra_frag; i++)
- if (tx.u.tx.extra_frag[i])
- dev_kfree_skb(tx.u.tx.extra_frag[i]);
- kfree(tx.u.tx.extra_frag);
+ for (i = 0; i < tx.num_extra_frag; i++)
+ if (tx.extra_frag[i])
+ dev_kfree_skb(tx.extra_frag[i]);
+ kfree(tx.extra_frag);
rcu_read_unlock();
return 0;
}
@@ -1260,6 +1294,8 @@ int ieee80211_master_start_xmit(struct sk_buff *skb,
control.flags |= IEEE80211_TXCTL_REQUEUE;
if (pkt_data->flags & IEEE80211_TXPD_EAPOL_FRAME)
control.flags |= IEEE80211_TXCTL_EAPOL_FRAME;
+ if (pkt_data->flags & IEEE80211_TXPD_AMPDU)
+ control.flags |= IEEE80211_TXCTL_AMPDU;
control.queue = pkt_data->queue;
ret = ieee80211_tx(odev, skb, &control);
@@ -1346,8 +1382,9 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
struct ieee80211_tx_packet_data *pkt_data;
struct ieee80211_sub_if_data *sdata;
int ret = 1, head_need;
- u16 ethertype, hdrlen, fc;
+ u16 ethertype, hdrlen, meshhdrlen = 0, fc;
struct ieee80211_hdr hdr;
+ struct ieee80211s_hdr mesh_hdr;
const u8 *encaps_data;
int encaps_len, skip_header_bytes;
int nh_pos, h_pos;
@@ -1389,6 +1426,37 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
hdrlen = 30;
break;
+#ifdef CONFIG_MAC80211_MESH
+ case IEEE80211_IF_TYPE_MESH_POINT:
+ fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
+ /* RA TA DA SA */
+ if (is_multicast_ether_addr(skb->data))
+ memcpy(hdr.addr1, skb->data, ETH_ALEN);
+ else if (mesh_nexthop_lookup(hdr.addr1, skb, dev))
+ return 0;
+ memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
+ memcpy(hdr.addr3, skb->data, ETH_ALEN);
+ memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
+ if (skb->pkt_type == PACKET_OTHERHOST) {
+ /* Forwarded frame, keep mesh ttl and seqnum */
+ struct ieee80211s_hdr *prev_meshhdr;
+ prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb);
+ meshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr);
+ memcpy(&mesh_hdr, prev_meshhdr, meshhdrlen);
+ sdata->u.sta.mshstats.fwded_frames++;
+ } else {
+ if (!sdata->u.sta.mshcfg.dot11MeshTTL) {
+ /* Do not send frames with mesh_ttl == 0 */
+ sdata->u.sta.mshstats.dropped_frames_ttl++;
+ ret = 0;
+ goto fail;
+ }
+ meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
+ sdata);
+ }
+ hdrlen = 30;
+ break;
+#endif
case IEEE80211_IF_TYPE_STA:
fc |= IEEE80211_FCTL_TODS;
/* BSSID SA DA */
@@ -1409,10 +1477,17 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
goto fail;
}
- sta = sta_info_get(local, hdr.addr1);
- if (sta) {
- sta_flags = sta->flags;
- sta_info_put(sta);
+ /*
+ * There's no need to try to look up the destination
+ * if it is a multicast address (which can only happen
+ * in AP mode)
+ */
+ if (!is_multicast_ether_addr(hdr.addr1)) {
+ rcu_read_lock();
+ sta = sta_info_get(local, hdr.addr1);
+ if (sta)
+ sta_flags = sta->flags;
+ rcu_read_unlock();
}
/* receiver is QoS enabled, use a QoS type frame */
@@ -1422,12 +1497,12 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
}
/*
- * If port access control is enabled, drop frames to unauthorised
- * stations unless they are EAPOL frames from the local station.
+ * Drop unicast frames to unauthorised stations unless they are
+ * EAPOL frames from the local station.
*/
- if (unlikely(sdata->ieee802_1x_pac &&
- !(sta_flags & WLAN_STA_AUTHORIZED) &&
- !(ethertype == ETH_P_PAE &&
+ if (unlikely(!is_multicast_ether_addr(hdr.addr1) &&
+ !(sta_flags & WLAN_STA_AUTHORIZED) &&
+ !(ethertype == ETH_P_PAE &&
compare_ether_addr(dev->dev_addr,
skb->data + ETH_ALEN) == 0))) {
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
@@ -1480,7 +1555,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
* build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
* alloc_skb() (net/core/skbuff.c)
*/
- head_need = hdrlen + encaps_len + local->tx_headroom;
+ head_need = hdrlen + encaps_len + meshhdrlen + local->tx_headroom;
head_need -= skb_headroom(skb);
/* We are going to modify skb data, so make a copy of it if happens to
@@ -1514,6 +1589,12 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
h_pos += encaps_len;
}
+ if (meshhdrlen > 0) {
+ memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
+ nh_pos += meshhdrlen;
+ h_pos += meshhdrlen;
+ }
+
if (fc & IEEE80211_STYPE_QOS_DATA) {
__le16 *qos_control;
@@ -1583,7 +1664,7 @@ void ieee80211_tx_pending(unsigned long data)
struct ieee80211_local *local = (struct ieee80211_local *)data;
struct net_device *dev = local->mdev;
struct ieee80211_tx_stored_packet *store;
- struct ieee80211_txrx_data tx;
+ struct ieee80211_tx_data tx;
int i, ret, reschedule = 0;
netif_tx_lock_bh(dev);
@@ -1595,14 +1676,13 @@ void ieee80211_tx_pending(unsigned long data)
continue;
}
store = &local->pending_packet[i];
- tx.u.tx.control = &store->control;
- tx.u.tx.extra_frag = store->extra_frag;
- tx.u.tx.num_extra_frag = store->num_extra_frag;
- tx.u.tx.last_frag_hwrate = store->last_frag_hwrate;
- tx.u.tx.last_frag_rate = store->last_frag_rate;
+ tx.control = &store->control;
+ tx.extra_frag = store->extra_frag;
+ tx.num_extra_frag = store->num_extra_frag;
+ tx.last_frag_rate = store->last_frag_rate;
tx.flags = 0;
if (store->last_frag_rate_ctrl_probe)
- tx.flags |= IEEE80211_TXRXD_TXPROBE_LAST_FRAG;
+ tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG;
ret = __ieee80211_tx(local, store->skb, &tx);
if (ret) {
if (ret == IEEE80211_TX_FRAG_AGAIN)
@@ -1636,7 +1716,6 @@ static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
/* Generate bitmap for TIM only if there are any STAs in power save
* mode. */
- read_lock_bh(&local->sta_lock);
if (atomic_read(&bss->num_sta_ps) > 0)
/* in the hope that this is faster than
* checking byte-for-byte */
@@ -1687,7 +1766,6 @@ static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
*pos++ = aid0; /* Bitmap control */
*pos++ = 0; /* Part Virt Bitmap */
}
- read_unlock_bh(&local->sta_lock);
}
struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
@@ -1701,16 +1779,96 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
struct ieee80211_if_ap *ap = NULL;
struct rate_selection rsel;
struct beacon_data *beacon;
+ struct ieee80211_supported_band *sband;
+ struct ieee80211_mgmt *mgmt;
+ int *num_beacons;
+ bool err = true;
+ u8 *pos;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
rcu_read_lock();
sdata = vif_to_sdata(vif);
bdev = sdata->dev;
- ap = &sdata->u.ap;
- beacon = rcu_dereference(ap->beacon);
+ if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
+ ap = &sdata->u.ap;
+ beacon = rcu_dereference(ap->beacon);
+ if (ap && beacon) {
+ /*
+ * headroom, head length,
+ * tail length and maximum TIM length
+ */
+ skb = dev_alloc_skb(local->tx_headroom +
+ beacon->head_len +
+ beacon->tail_len + 256);
+ if (!skb)
+ goto out;
+
+ skb_reserve(skb, local->tx_headroom);
+ memcpy(skb_put(skb, beacon->head_len), beacon->head,
+ beacon->head_len);
+
+ ieee80211_include_sequence(sdata,
+ (struct ieee80211_hdr *)skb->data);
+
+ /*
+ * Not very nice, but we want to allow the driver to call
+ * ieee80211_beacon_get() as a response to the set_tim()
+ * callback. That, however, is already invoked under the
+ * sta_lock to guarantee consistent and race-free update
+ * of the tim bitmap in mac80211 and the driver.
+ */
+ if (local->tim_in_locked_section) {
+ ieee80211_beacon_add_tim(local, ap, skb, beacon);
+ } else {
+ unsigned long flags;
+
+ spin_lock_irqsave(&local->sta_lock, flags);
+ ieee80211_beacon_add_tim(local, ap, skb, beacon);
+ spin_unlock_irqrestore(&local->sta_lock, flags);
+ }
+
+ if (beacon->tail)
+ memcpy(skb_put(skb, beacon->tail_len),
+ beacon->tail, beacon->tail_len);
- if (!ap || sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon) {
+ num_beacons = &ap->num_beacons;
+
+ err = false;
+ }
+ } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
+ /* headroom, head length, tail length and maximum TIM length */
+ skb = dev_alloc_skb(local->tx_headroom + 400);
+ if (!skb)
+ goto out;
+
+ skb_reserve(skb, local->hw.extra_tx_headroom);
+ mgmt = (struct ieee80211_mgmt *)
+ skb_put(skb, 24 + sizeof(mgmt->u.beacon));
+ memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
+ mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
+ IEEE80211_STYPE_BEACON);
+ memset(mgmt->da, 0xff, ETH_ALEN);
+ memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
+ /* BSSID is left zeroed, wildcard value */
+ mgmt->u.beacon.beacon_int =
+ cpu_to_le16(local->hw.conf.beacon_int);
+ mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
+
+ pos = skb_put(skb, 2);
+ *pos++ = WLAN_EID_SSID;
+ *pos++ = 0x0;
+
+ mesh_mgmt_ies_add(skb, sdata->dev);
+
+ num_beacons = &sdata->u.sta.num_beacons;
+
+ err = false;
+ }
+
+ if (err) {
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
if (net_ratelimit())
printk(KERN_DEBUG "no beacon data avail for %s\n",
@@ -1720,27 +1878,8 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
goto out;
}
- /* headroom, head length, tail length and maximum TIM length */
- skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
- beacon->tail_len + 256);
- if (!skb)
- goto out;
-
- skb_reserve(skb, local->tx_headroom);
- memcpy(skb_put(skb, beacon->head_len), beacon->head,
- beacon->head_len);
-
- ieee80211_include_sequence(sdata, (struct ieee80211_hdr *)skb->data);
-
- ieee80211_beacon_add_tim(local, ap, skb, beacon);
-
- if (beacon->tail)
- memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
- beacon->tail_len);
-
if (control) {
- rate_control_get_rate(local->mdev, local->oper_hw_mode, skb,
- &rsel);
+ rate_control_get_rate(local->mdev, sband, skb, &rsel);
if (!rsel.rate) {
if (net_ratelimit()) {
printk(KERN_DEBUG "%s: ieee80211_beacon_get: "
@@ -1753,20 +1892,17 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
}
control->vif = vif;
- control->tx_rate =
- (sdata->bss_conf.use_short_preamble &&
- (rsel.rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
- rsel.rate->val2 : rsel.rate->val;
+ control->tx_rate = rsel.rate;
+ if (sdata->bss_conf.use_short_preamble &&
+ rsel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
+ control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
- control->power_level = local->hw.conf.power_level;
control->flags |= IEEE80211_TXCTL_NO_ACK;
control->retry_limit = 1;
- control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
+ control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
}
-
- ap->num_beacons++;
-
- out:
+ (*num_beacons)++;
+out:
rcu_read_unlock();
return skb;
}
@@ -1814,8 +1950,8 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
struct sk_buff *skb;
struct sta_info *sta;
ieee80211_tx_handler *handler;
- struct ieee80211_txrx_data tx;
- ieee80211_txrx_result res = TXRX_DROP;
+ struct ieee80211_tx_data tx;
+ ieee80211_tx_result res = TX_DROP;
struct net_device *bdev;
struct ieee80211_sub_if_data *sdata;
struct ieee80211_if_ap *bss = NULL;
@@ -1836,7 +1972,6 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
rcu_read_unlock();
return NULL;
}
- rcu_read_unlock();
if (bss->dtim_count != 0)
return NULL; /* send buffered bc/mc only after DTIM beacon */
@@ -1862,27 +1997,26 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
dev_kfree_skb_any(skb);
}
sta = tx.sta;
- tx.flags |= IEEE80211_TXRXD_TXPS_BUFFERED;
- tx.u.tx.mode = local->hw.conf.mode;
+ tx.flags |= IEEE80211_TX_PS_BUFFERED;
+ tx.channel = local->hw.conf.channel;
- for (handler = local->tx_handlers; *handler != NULL; handler++) {
+ for (handler = ieee80211_tx_handlers; *handler != NULL; handler++) {
res = (*handler)(&tx);
- if (res == TXRX_DROP || res == TXRX_QUEUED)
+ if (res == TX_DROP || res == TX_QUEUED)
break;
}
skb = tx.skb; /* handlers are allowed to change skb */
- if (res == TXRX_DROP) {
+ if (res == TX_DROP) {
I802_DEBUG_INC(local->tx_handlers_drop);
dev_kfree_skb(skb);
skb = NULL;
- } else if (res == TXRX_QUEUED) {
+ } else if (res == TX_QUEUED) {
I802_DEBUG_INC(local->tx_handlers_queued);
skb = NULL;
}
- if (sta)
- sta_info_put(sta);
+ rcu_read_unlock();
return skb;
}
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 5e631ce98d7e..cc9f715c7bfc 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -25,7 +25,8 @@
#include <net/rtnetlink.h>
#include "ieee80211_i.h"
-#include "ieee80211_rate.h"
+#include "rate.h"
+#include "mesh.h"
#include "wme.h"
/* privid for wiphys to determine whether they belong to us or not */
@@ -41,92 +42,6 @@ const unsigned char bridge_tunnel_header[] =
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
-static int rate_list_match(const int *rate_list, int rate)
-{
- int i;
-
- if (!rate_list)
- return 0;
-
- for (i = 0; rate_list[i] >= 0; i++)
- if (rate_list[i] == rate)
- return 1;
-
- return 0;
-}
-
-void ieee80211_prepare_rates(struct ieee80211_local *local,
- struct ieee80211_hw_mode *mode)
-{
- int i;
-
- for (i = 0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rate = &mode->rates[i];
-
- rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
- IEEE80211_RATE_BASIC);
-
- if (local->supp_rates[mode->mode]) {
- if (!rate_list_match(local->supp_rates[mode->mode],
- rate->rate))
- continue;
- }
-
- rate->flags |= IEEE80211_RATE_SUPPORTED;
-
- /* Use configured basic rate set if it is available. If not,
- * use defaults that are sane for most cases. */
- if (local->basic_rates[mode->mode]) {
- if (rate_list_match(local->basic_rates[mode->mode],
- rate->rate))
- rate->flags |= IEEE80211_RATE_BASIC;
- } else switch (mode->mode) {
- case MODE_IEEE80211A:
- if (rate->rate == 60 || rate->rate == 120 ||
- rate->rate == 240)
- rate->flags |= IEEE80211_RATE_BASIC;
- break;
- case MODE_IEEE80211B:
- if (rate->rate == 10 || rate->rate == 20)
- rate->flags |= IEEE80211_RATE_BASIC;
- break;
- case MODE_IEEE80211G:
- if (rate->rate == 10 || rate->rate == 20 ||
- rate->rate == 55 || rate->rate == 110)
- rate->flags |= IEEE80211_RATE_BASIC;
- break;
- case NUM_IEEE80211_MODES:
- /* not useful */
- break;
- }
-
- /* Set ERP and MANDATORY flags based on phymode */
- switch (mode->mode) {
- case MODE_IEEE80211A:
- if (rate->rate == 60 || rate->rate == 120 ||
- rate->rate == 240)
- rate->flags |= IEEE80211_RATE_MANDATORY;
- break;
- case MODE_IEEE80211B:
- if (rate->rate == 10)
- rate->flags |= IEEE80211_RATE_MANDATORY;
- break;
- case MODE_IEEE80211G:
- if (rate->rate == 10 || rate->rate == 20 ||
- rate->rate == 55 || rate->rate == 110 ||
- rate->rate == 60 || rate->rate == 120 ||
- rate->rate == 240)
- rate->flags |= IEEE80211_RATE_MANDATORY;
- break;
- case NUM_IEEE80211_MODES:
- /* not useful */
- break;
- }
- if (ieee80211_is_erp_rate(mode->mode, rate->rate))
- rate->flags |= IEEE80211_RATE_ERP;
- }
-}
-
u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
enum ieee80211_if_types type)
{
@@ -232,17 +147,35 @@ int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
}
EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
-void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
+int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
+{
+ int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
+ /* 7.1.3.5a.2 */
+ switch (ae) {
+ case 0:
+ return 5;
+ case 1:
+ return 11;
+ case 2:
+ return 17;
+ case 3:
+ return 23;
+ default:
+ return 5;
+ }
+}
+
+void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
struct ieee80211_hdr *fhdr;
int i;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+ for (i = 0; i < tx->num_extra_frag; i++) {
fhdr = (struct ieee80211_hdr *)
- tx->u.tx.extra_frag[i]->data;
+ tx->extra_frag[i]->data;
fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
}
}
@@ -262,7 +195,7 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
* DIV_ROUND_UP() operations.
*/
- if (local->hw.conf.phymode == MODE_IEEE80211A || erp) {
+ if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
/*
* OFDM:
*
@@ -304,15 +237,19 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
/* Exported duration function for driver use */
__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
struct ieee80211_vif *vif,
- size_t frame_len, int rate)
+ size_t frame_len,
+ struct ieee80211_rate *rate)
{
struct ieee80211_local *local = hw_to_local(hw);
struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
u16 dur;
int erp;
- erp = ieee80211_is_erp_rate(hw->conf.phymode, rate);
- dur = ieee80211_frame_duration(local, frame_len, rate, erp,
+ erp = 0;
+ if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
+ erp = rate->flags & IEEE80211_RATE_ERP_G;
+
+ dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
sdata->bss_conf.use_short_preamble);
return cpu_to_le16(dur);
@@ -332,17 +269,20 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
short_preamble = sdata->bss_conf.use_short_preamble;
- rate = frame_txctl->rts_rate;
- erp = !!(rate->flags & IEEE80211_RATE_ERP);
+ rate = frame_txctl->rts_cts_rate;
+
+ erp = 0;
+ if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
+ erp = rate->flags & IEEE80211_RATE_ERP_G;
/* CTS duration */
- dur = ieee80211_frame_duration(local, 10, rate->rate,
+ dur = ieee80211_frame_duration(local, 10, rate->bitrate,
erp, short_preamble);
/* Data frame duration */
- dur += ieee80211_frame_duration(local, frame_len, rate->rate,
+ dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
erp, short_preamble);
/* ACK duration */
- dur += ieee80211_frame_duration(local, 10, rate->rate,
+ dur += ieee80211_frame_duration(local, 10, rate->bitrate,
erp, short_preamble);
return cpu_to_le16(dur);
@@ -363,15 +303,17 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
short_preamble = sdata->bss_conf.use_short_preamble;
- rate = frame_txctl->rts_rate;
- erp = !!(rate->flags & IEEE80211_RATE_ERP);
+ rate = frame_txctl->rts_cts_rate;
+ erp = 0;
+ if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
+ erp = rate->flags & IEEE80211_RATE_ERP_G;
/* Data frame duration */
- dur = ieee80211_frame_duration(local, frame_len, rate->rate,
+ dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
erp, short_preamble);
if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
/* ACK duration */
- dur += ieee80211_frame_duration(local, 10, rate->rate,
+ dur += ieee80211_frame_duration(local, 10, rate->bitrate,
erp, short_preamble);
}
@@ -379,27 +321,6 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
}
EXPORT_SYMBOL(ieee80211_ctstoself_duration);
-struct ieee80211_rate *
-ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
-{
- struct ieee80211_hw_mode *mode;
- int r;
-
- list_for_each_entry(mode, &local->modes_list, list) {
- if (mode->mode != phymode)
- continue;
- for (r = 0; r < mode->num_rates; r++) {
- struct ieee80211_rate *rate = &mode->rates[r];
- if (rate->val == hw_rate ||
- (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
- rate->val2 == hw_rate))
- return rate;
- }
- }
-
- return NULL;
-}
-
void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
{
struct ieee80211_local *local = hw_to_local(hw);
@@ -480,6 +401,7 @@ void ieee80211_iterate_active_interfaces(
case IEEE80211_IF_TYPE_STA:
case IEEE80211_IF_TYPE_IBSS:
case IEEE80211_IF_TYPE_WDS:
+ case IEEE80211_IF_TYPE_MESH_POINT:
break;
}
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)
return NULL;
}
-ieee80211_txrx_result
-ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx)
+ieee80211_rx_result
+ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx)
{
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
- if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) {
+ if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
#ifdef CONFIG_MAC80211_DEBUG
if (net_ratelimit())
printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
"failed\n", rx->dev->name);
#endif /* CONFIG_MAC80211_DEBUG */
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
- } else if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) {
+ } else if (!(rx->status->flag & RX_FLAG_IV_STRIPPED)) {
ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
/* remove ICV */
skb_trim(rx->skb, rx->skb->len - 4);
}
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
+static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
{
if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
return -1;
} else {
- tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
+ tx->control->key_idx = tx->key->conf.hw_key_idx;
if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
if (!ieee80211_wep_add_iv(tx->local, skb, tx->key))
return -1;
@@ -346,28 +346,28 @@ static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
return 0;
}
-ieee80211_txrx_result
-ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx)
+ieee80211_tx_result
+ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx)
{
- tx->u.tx.control->iv_len = WEP_IV_LEN;
- tx->u.tx.control->icv_len = WEP_ICV_LEN;
- ieee80211_tx_set_iswep(tx);
+ tx->control->iv_len = WEP_IV_LEN;
+ tx->control->icv_len = WEP_ICV_LEN;
+ ieee80211_tx_set_protected(tx);
if (wep_encrypt_skb(tx, tx->skb) < 0) {
I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
- return TXRX_DROP;
+ return TX_DROP;
}
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
int i;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
- if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
+ for (i = 0; i < tx->num_extra_frag; i++) {
+ if (wep_encrypt_skb(tx, tx->extra_frag[i]) < 0) {
I802_DEBUG_INC(tx->local->
tx_handlers_drop_wep);
- return TXRX_DROP;
+ return TX_DROP;
}
}
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
diff --git a/net/mac80211/wep.h b/net/mac80211/wep.h
index 785fbb4e0dd7..363779c50658 100644
--- a/net/mac80211/wep.h
+++ b/net/mac80211/wep.h
@@ -14,7 +14,7 @@
#include <linux/skbuff.h>
#include <linux/types.h>
#include "ieee80211_i.h"
-#include "ieee80211_key.h"
+#include "key.h"
int ieee80211_wep_init(struct ieee80211_local *local);
void ieee80211_wep_free(struct ieee80211_local *local);
@@ -28,9 +28,9 @@ int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
struct ieee80211_key *key);
u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
-ieee80211_txrx_result
-ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx);
-ieee80211_txrx_result
-ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx);
+ieee80211_rx_result
+ieee80211_crypto_wep_decrypt(struct ieee80211_rx_data *rx);
+ieee80211_tx_result
+ieee80211_crypto_wep_encrypt(struct ieee80211_tx_data *tx);
#endif /* WEP_H */
diff --git a/net/mac80211/ieee80211_ioctl.c b/net/mac80211/wext.c
index 5024d3733834..76e1de1dc735 100644
--- a/net/mac80211/ieee80211_ioctl.c
+++ b/net/mac80211/wext.c
@@ -21,8 +21,8 @@
#include <net/mac80211.h>
#include "ieee80211_i.h"
-#include "ieee80211_led.h"
-#include "ieee80211_rate.h"
+#include "led.h"
+#include "rate.h"
#include "wpa.h"
#include "aes_ccm.h"
@@ -33,10 +33,10 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
size_t key_len)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- int ret = 0;
struct sta_info *sta;
struct ieee80211_key *key;
struct ieee80211_sub_if_data *sdata;
+ int err;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
@@ -46,59 +46,65 @@ static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
return -EINVAL;
}
- if (is_broadcast_ether_addr(sta_addr)) {
- sta = NULL;
- key = sdata->keys[idx];
- } else {
- set_tx_key = 0;
- /*
- * According to the standard, the key index of a pairwise
- * key must be zero. However, some AP are broken when it
- * comes to WEP key indices, so we work around this.
- */
- if (idx != 0 && alg != ALG_WEP) {
- printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
- "individual key\n", dev->name);
- return -EINVAL;
- }
+ if (remove) {
+ rcu_read_lock();
- sta = sta_info_get(local, sta_addr);
- if (!sta) {
-#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
- DECLARE_MAC_BUF(mac);
- printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
- "%s\n",
- dev->name, print_mac(mac, sta_addr));
-#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+ err = 0;
- return -ENOENT;
+ if (is_broadcast_ether_addr(sta_addr)) {
+ key = sdata->keys[idx];
+ } else {
+ sta = sta_info_get(local, sta_addr);
+ if (!sta) {
+ err = -ENOENT;
+ goto out_unlock;
+ }
+ key = sta->key;
}
- key = sta->key;
- }
-
- if (remove) {
ieee80211_key_free(key);
- key = NULL;
} else {
- /*
- * Automatically frees any old key if present.
- */
- key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key);
- if (!key) {
- ret = -ENOMEM;
- goto err_out;
+ key = ieee80211_key_alloc(alg, idx, key_len, _key);
+ if (!key)
+ return -ENOMEM;
+
+ sta = NULL;
+ err = 0;
+
+ rcu_read_lock();
+
+ if (!is_broadcast_ether_addr(sta_addr)) {
+ set_tx_key = 0;
+ /*
+ * According to the standard, the key index of a
+ * pairwise key must be zero. However, some AP are
+ * broken when it comes to WEP key indices, so we
+ * work around this.
+ */
+ if (idx != 0 && alg != ALG_WEP) {
+ ieee80211_key_free(key);
+ err = -EINVAL;
+ goto out_unlock;
+ }
+
+ sta = sta_info_get(local, sta_addr);
+ if (!sta) {
+ ieee80211_key_free(key);
+ err = -ENOENT;
+ goto out_unlock;
+ }
}
+
+ ieee80211_key_link(key, sdata, sta);
+
+ if (set_tx_key || (!sta && !sdata->default_key && key))
+ ieee80211_set_default_key(sdata, idx);
}
- if (set_tx_key || (!sta && !sdata->default_key && key))
- ieee80211_set_default_key(sdata, idx);
+ out_unlock:
+ rcu_read_unlock();
- ret = 0;
- err_out:
- if (sta)
- sta_info_put(sta);
- return ret;
+ return err;
}
static int ieee80211_ioctl_siwgenie(struct net_device *dev,
@@ -129,22 +135,7 @@ static int ieee80211_ioctl_giwname(struct net_device *dev,
struct iw_request_info *info,
char *name, char *extra)
{
- struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
-
- switch (local->hw.conf.phymode) {
- case MODE_IEEE80211A:
- strcpy(name, "IEEE 802.11a");
- break;
- case MODE_IEEE80211B:
- strcpy(name, "IEEE 802.11b");
- break;
- case MODE_IEEE80211G:
- strcpy(name, "IEEE 802.11g");
- break;
- default:
- strcpy(name, "IEEE 802.11");
- break;
- }
+ strcpy(name, "IEEE 802.11");
return 0;
}
@@ -156,7 +147,7 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct iw_range *range = (struct iw_range *) extra;
- struct ieee80211_hw_mode *mode = NULL;
+ enum ieee80211_band band;
int c = 0;
data->length = sizeof(struct iw_range);
@@ -191,24 +182,27 @@ static int ieee80211_ioctl_giwrange(struct net_device *dev,
range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
- list_for_each_entry(mode, &local->modes_list, list) {
- int i = 0;
- if (!(local->enabled_modes & (1 << mode->mode)) ||
- (local->hw_modes & local->enabled_modes &
- (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
+ for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
+ int i;
+ struct ieee80211_supported_band *sband;
+
+ sband = local->hw.wiphy->bands[band];
+
+ if (!sband)
continue;
- while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) {
- struct ieee80211_channel *chan = &mode->channels[i];
+ for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
+ struct ieee80211_channel *chan = &sband->channels[i];
- if (chan->flag & IEEE80211_CHAN_W_SCAN) {
- range->freq[c].i = chan->chan;
- range->freq[c].m = chan->freq * 100000;
- range->freq[c].e = 1;
+ if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
+ range->freq[c].i =
+ ieee80211_frequency_to_channel(
+ chan->center_freq);
+ range->freq[c].m = chan->center_freq;
+ range->freq[c].e = 6;
c++;
}
- i++;
}
}
range->num_channels = c;
@@ -242,6 +236,9 @@ static int ieee80211_ioctl_siwmode(struct net_device *dev,
case IW_MODE_ADHOC:
type = IEEE80211_IF_TYPE_IBSS;
break;
+ case IW_MODE_REPEAT:
+ type = IEEE80211_IF_TYPE_WDS;
+ break;
case IW_MODE_MONITOR:
type = IEEE80211_IF_TYPE_MNTR;
break;
@@ -294,31 +291,17 @@ static int ieee80211_ioctl_giwmode(struct net_device *dev,
return 0;
}
-int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
+int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
{
- struct ieee80211_hw_mode *mode;
- int c, set = 0;
int ret = -EINVAL;
+ struct ieee80211_channel *chan;
- list_for_each_entry(mode, &local->modes_list, list) {
- if (!(local->enabled_modes & (1 << mode->mode)))
- continue;
- for (c = 0; c < mode->num_channels; c++) {
- struct ieee80211_channel *chan = &mode->channels[c];
- if (chan->flag & IEEE80211_CHAN_W_SCAN &&
- ((chan->chan == channel) || (chan->freq == freq))) {
- local->oper_channel = chan;
- local->oper_hw_mode = mode;
- set = 1;
- break;
- }
- }
- if (set)
- break;
- }
+ chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
- if (set) {
- if (local->sta_sw_scanning)
+ if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
+ local->oper_channel = chan;
+
+ if (local->sta_sw_scanning || local->sta_hw_scanning)
ret = 0;
else
ret = ieee80211_hw_config(local);
@@ -347,13 +330,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
IEEE80211_STA_AUTO_CHANNEL_SEL;
return 0;
} else
- return ieee80211_set_channel(local, freq->m, -1);
+ return ieee80211_set_freq(local,
+ ieee80211_channel_to_frequency(freq->m));
} else {
int i, div = 1000000;
for (i = 0; i < freq->e; i++)
div /= 10;
if (div > 0)
- return ieee80211_set_channel(local, -1, freq->m / div);
+ return ieee80211_set_freq(local, freq->m / div);
else
return -EINVAL;
}
@@ -366,10 +350,7 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
- * driver for the current channel with firmware-based management */
-
- freq->m = local->hw.conf.freq;
+ freq->m = local->hw.conf.channel->center_freq;
freq->e = 6;
return 0;
@@ -480,10 +461,20 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
ieee80211_sta_req_auth(dev, &sdata->u.sta);
return 0;
} else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
- if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
- ETH_ALEN) == 0)
- return 0;
- return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
+ /*
+ * If it is necessary to update the WDS peer address
+ * while the interface is running, then we need to do
+ * more work here, namely if it is running we need to
+ * add a new and remove the old STA entry, this is
+ * normally handled by _open() and _stop().
+ */
+ if (netif_running(dev))
+ return -EBUSY;
+
+ memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
+ ETH_ALEN);
+
+ return 0;
}
return -EOPNOTSUPP;
@@ -526,6 +517,7 @@ static int ieee80211_ioctl_siwscan(struct net_device *dev,
if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
+ sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
sdata->vif.type != IEEE80211_IF_TYPE_AP)
return -EOPNOTSUPP;
@@ -566,15 +558,17 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
struct iw_param *rate, char *extra)
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
- struct ieee80211_hw_mode *mode;
- int i;
+ int i, err = -EINVAL;
u32 target_rate = rate->value / 100000;
struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_supported_band *sband;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
if (!sdata->bss)
return -ENODEV;
- mode = local->oper_hw_mode;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
/* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
* target_rate = X, rate->fixed = 1 means only rate X
* target_rate = X, rate->fixed = 0 means all rates <= X */
@@ -582,18 +576,20 @@ static int ieee80211_ioctl_siwrate(struct net_device *dev,
sdata->bss->force_unicast_rateidx = -1;
if (rate->value < 0)
return 0;
- for (i=0; i < mode->num_rates; i++) {
- struct ieee80211_rate *rates = &mode->rates[i];
- int this_rate = rates->rate;
+
+ for (i=0; i< sband->n_bitrates; i++) {
+ struct ieee80211_rate *brate = &sband->bitrates[i];
+ int this_rate = brate->bitrate;
if (target_rate == this_rate) {
sdata->bss->max_ratectrl_rateidx = i;
if (rate->fixed)
sdata->bss->force_unicast_rateidx = i;
- return 0;
+ err = 0;
+ break;
}
}
- return -EINVAL;
+ return err;
}
static int ieee80211_ioctl_giwrate(struct net_device *dev,
@@ -603,19 +599,31 @@ static int ieee80211_ioctl_giwrate(struct net_device *dev,
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
struct sta_info *sta;
struct ieee80211_sub_if_data *sdata;
+ struct ieee80211_supported_band *sband;
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
- if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
- sta = sta_info_get(local, sdata->u.sta.bssid);
- else
+
+ if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
return -EOPNOTSUPP;
- if (!sta)
- return -ENODEV;
- if (sta->txrate < local->oper_hw_mode->num_rates)
- rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
+
+ sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, sdata->u.sta.bssid);
+
+ if (sta && sta->txrate_idx < sband->n_bitrates)
+ rate->value = sband->bitrates[sta->txrate_idx].bitrate;
else
rate->value = 0;
- sta_info_put(sta);
+
+ rcu_read_unlock();
+
+ if (!sta)
+ return -ENODEV;
+
+ rate->value *= 100000;
+
return 0;
}
@@ -625,7 +633,7 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
{
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
bool need_reconfig = 0;
- u8 new_power_level;
+ int new_power_level;
if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
return -EINVAL;
@@ -635,13 +643,15 @@ static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
if (data->txpower.fixed) {
new_power_level = data->txpower.value;
} else {
- /* Automatic power level. Get the px power from the current
- * channel. */
- struct ieee80211_channel* chan = local->oper_channel;
+ /*
+ * Automatic power level. Use maximum power for the current
+ * channel. Should be part of rate control.
+ */
+ struct ieee80211_channel* chan = local->hw.conf.channel;
if (!chan)
return -EINVAL;
- new_power_level = chan->power_level;
+ new_power_level = chan->max_power;
}
if (local->hw.conf.power_level != new_power_level) {
@@ -973,6 +983,8 @@ static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
struct sta_info *sta = NULL;
+ rcu_read_lock();
+
if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
sta = sta_info_get(local, sdata->u.sta.bssid);
@@ -988,8 +1000,10 @@ static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev
wstats->qual.qual = sta->last_signal;
wstats->qual.noise = sta->last_noise;
wstats->qual.updated = local->wstats_flags;
- sta_info_put(sta);
}
+
+ rcu_read_unlock();
+
return wstats;
}
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 @@
#include "wme.h"
/* maximum number of hardware queues we support. */
-#define TC_80211_MAX_QUEUES 8
+#define TC_80211_MAX_QUEUES 16
+
+const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
struct ieee80211_sched_data
{
+ unsigned long qdisc_pool[BITS_TO_LONGS(TC_80211_MAX_QUEUES)];
struct tcf_proto *filter_list;
struct Qdisc *queues[TC_80211_MAX_QUEUES];
struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
@@ -98,7 +101,6 @@ static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
unsigned short fc = le16_to_cpu(hdr->frame_control);
int qos;
- const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
/* see if frame is data or non data frame */
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)
unsigned short fc = le16_to_cpu(hdr->frame_control);
struct Qdisc *qdisc;
int err, queue;
+ struct sta_info *sta;
+ u8 tid;
if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
- skb_queue_tail(&q->requeued[pkt_data->queue], skb);
+ queue = pkt_data->queue;
+ rcu_read_lock();
+ sta = sta_info_get(local, hdr->addr1);
+ tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
+ if (sta) {
+ int ampdu_queue = sta->tid_to_tx_q[tid];
+ if ((ampdu_queue < local->hw.queues) &&
+ test_bit(ampdu_queue, q->qdisc_pool)) {
+ queue = ampdu_queue;
+ pkt_data->flags |= IEEE80211_TXPD_AMPDU;
+ } else {
+ pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
+ }
+ }
+ rcu_read_unlock();
+ skb_queue_tail(&q->requeued[queue], skb);
qd->q.qlen++;
return 0;
}
@@ -159,14 +178,31 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
*/
if (WLAN_FC_IS_QOS_DATA(fc)) {
u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
- u8 qos_hdr = skb->priority & QOS_CONTROL_TAG1D_MASK;
+ u8 ack_policy = 0;
+ tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
if (local->wifi_wme_noack_test)
- qos_hdr |= QOS_CONTROL_ACK_POLICY_NOACK <<
+ ack_policy |= QOS_CONTROL_ACK_POLICY_NOACK <<
QOS_CONTROL_ACK_POLICY_SHIFT;
/* qos header is 2 bytes, second reserved */
- *p = qos_hdr;
+ *p = ack_policy | tid;
p++;
*p = 0;
+
+ rcu_read_lock();
+
+ sta = sta_info_get(local, hdr->addr1);
+ if (sta) {
+ int ampdu_queue = sta->tid_to_tx_q[tid];
+ if ((ampdu_queue < local->hw.queues) &&
+ test_bit(ampdu_queue, q->qdisc_pool)) {
+ queue = ampdu_queue;
+ pkt_data->flags |= IEEE80211_TXPD_AMPDU;
+ } else {
+ pkt_data->flags &= ~IEEE80211_TXPD_AMPDU;
+ }
+ }
+
+ rcu_read_unlock();
}
if (unlikely(queue >= local->hw.queues)) {
@@ -184,6 +220,7 @@ static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
kfree_skb(skb);
err = NET_XMIT_DROP;
} else {
+ tid = skb->priority & QOS_CONTROL_TAG1D_MASK;
pkt_data->queue = (unsigned int) queue;
qdisc = q->queues[queue];
err = qdisc->enqueue(skb, qdisc);
@@ -235,10 +272,11 @@ static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
/* check all the h/w queues in numeric/priority order */
for (queue = 0; queue < hw->queues; queue++) {
/* see if there is room in this hardware queue */
- if (test_bit(IEEE80211_LINK_STATE_XOFF,
- &local->state[queue]) ||
- test_bit(IEEE80211_LINK_STATE_PENDING,
- &local->state[queue]))
+ if ((test_bit(IEEE80211_LINK_STATE_XOFF,
+ &local->state[queue])) ||
+ (test_bit(IEEE80211_LINK_STATE_PENDING,
+ &local->state[queue])) ||
+ (!test_bit(queue, q->qdisc_pool)))
continue;
/* there is space - try and get a frame */
@@ -360,6 +398,10 @@ static int wme_qdiscop_init(struct Qdisc *qd, struct nlattr *opt)
}
}
+ /* reserve all legacy QoS queues */
+ for (i = 0; i < min(IEEE80211_TX_QUEUE_DATA4, queues); i++)
+ set_bit(i, q->qdisc_pool);
+
return err;
}
@@ -605,3 +647,80 @@ void ieee80211_wme_unregister(void)
{
unregister_qdisc(&wme_qdisc_ops);
}
+
+int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid)
+{
+ int i;
+ struct ieee80211_sched_data *q =
+ qdisc_priv(local->mdev->qdisc_sleeping);
+ DECLARE_MAC_BUF(mac);
+
+ /* prepare the filter and save it for the SW queue
+ * matching the recieved HW queue */
+
+ /* try to get a Qdisc from the pool */
+ for (i = IEEE80211_TX_QUEUE_BEACON; i < local->hw.queues; i++)
+ if (!test_and_set_bit(i, q->qdisc_pool)) {
+ ieee80211_stop_queue(local_to_hw(local), i);
+ sta->tid_to_tx_q[tid] = i;
+
+ /* IF there are already pending packets
+ * on this tid first we need to drain them
+ * on the previous queue
+ * since HT is strict in order */
+#ifdef CONFIG_MAC80211_HT_DEBUG
+ if (net_ratelimit())
+ printk(KERN_DEBUG "allocated aggregation queue"
+ " %d tid %d addr %s pool=0x%lX",
+ i, tid, print_mac(mac, sta->addr),
+ q->qdisc_pool[0]);
+#endif /* CONFIG_MAC80211_HT_DEBUG */
+ return 0;
+ }
+
+ return -EAGAIN;
+}
+
+/**
+ * the caller needs to hold local->mdev->queue_lock
+ */
+void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid,
+ u8 requeue)
+{
+ struct ieee80211_sched_data *q =
+ qdisc_priv(local->mdev->qdisc_sleeping);
+ int agg_queue = sta->tid_to_tx_q[tid];
+
+ /* return the qdisc to the pool */
+ clear_bit(agg_queue, q->qdisc_pool);
+ sta->tid_to_tx_q[tid] = local->hw.queues;
+
+ if (requeue)
+ ieee80211_requeue(local, agg_queue);
+ else
+ q->queues[agg_queue]->ops->reset(q->queues[agg_queue]);
+}
+
+void ieee80211_requeue(struct ieee80211_local *local, int queue)
+{
+ struct Qdisc *root_qd = local->mdev->qdisc_sleeping;
+ struct ieee80211_sched_data *q = qdisc_priv(root_qd);
+ struct Qdisc *qdisc = q->queues[queue];
+ struct sk_buff *skb = NULL;
+ u32 len = qdisc->q.qlen;
+
+ if (!qdisc || !qdisc->dequeue)
+ return;
+
+ printk(KERN_DEBUG "requeue: qlen = %d\n", qdisc->q.qlen);
+ for (len = qdisc->q.qlen; len > 0; len--) {
+ skb = qdisc->dequeue(qdisc);
+ root_qd->q.qlen--;
+ /* packet will be classified again and */
+ /* skb->packet_data->queue will be overridden if needed */
+ if (skb)
+ wme_qdiscop_enqueue(skb, root_qd);
+ }
+}
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 @@
#define QOS_CONTROL_TAG1D_MASK 0x07
+extern const int ieee802_1d_to_ac[8];
+
static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
{
return (fc & 0x8C) == 0x88;
@@ -32,7 +34,12 @@ static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
#ifdef CONFIG_NET_SCHED
void ieee80211_install_qdisc(struct net_device *dev);
int ieee80211_qdisc_installed(struct net_device *dev);
-
+int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid);
+void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid,
+ u8 requeue);
+void ieee80211_requeue(struct ieee80211_local *local, int queue);
int ieee80211_wme_register(void);
void ieee80211_wme_unregister(void);
#else
@@ -43,7 +50,19 @@ static inline int ieee80211_qdisc_installed(struct net_device *dev)
{
return 0;
}
-
+static inline int ieee80211_ht_agg_queue_add(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid)
+{
+ return -EAGAIN;
+}
+static inline void ieee80211_ht_agg_queue_remove(struct ieee80211_local *local,
+ struct sta_info *sta, u16 tid,
+ u8 requeue)
+{
+}
+static inline void ieee80211_requeue(struct ieee80211_local *local, int queue)
+{
+}
static inline int ieee80211_wme_register(void)
{
return 0;
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 6f04311cf0a0..45709ada8fee 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,
}
-ieee80211_txrx_result
-ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
+ieee80211_tx_result
+ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx)
{
u8 *data, *sa, *da, *key, *mic, qos_tid;
size_t data_len;
@@ -84,18 +84,18 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 ||
!WLAN_FC_DATA_PRESENT(fc))
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
- return TXRX_DROP;
+ return TX_DROP;
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
- !(tx->flags & IEEE80211_TXRXD_FRAGMENTED) &&
+ !(tx->flags & IEEE80211_TX_FRAGMENTED) &&
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) &&
!wpa_test) {
/* hwaccel - with no need for preallocated room for Michael MIC
*/
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
@@ -105,7 +105,7 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
GFP_ATOMIC))) {
printk(KERN_DEBUG "%s: failed to allocate more memory "
"for Michael MIC\n", tx->dev->name);
- return TXRX_DROP;
+ return TX_DROP;
}
}
@@ -119,12 +119,12 @@ ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
mic = skb_put(skb, MICHAEL_MIC_LEN);
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-ieee80211_txrx_result
-ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
+ieee80211_rx_result
+ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
{
u8 *data, *sa, *da, *key = NULL, qos_tid;
size_t data_len;
@@ -139,16 +139,16 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
/*
* No way to verify the MIC if the hardware stripped it
*/
- if (rx->u.rx.status->flag & RX_FLAG_MMIC_STRIPPED)
- return TXRX_CONTINUE;
+ if (rx->status->flag & RX_FLAG_MMIC_STRIPPED)
+ return RX_CONTINUE;
if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
!(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
|| data_len < MICHAEL_MIC_LEN)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
data_len -= MICHAEL_MIC_LEN;
@@ -161,29 +161,29 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
- if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
- return TXRX_DROP;
+ if (!(rx->flags & IEEE80211_RX_RA_MATCH))
+ return RX_DROP_UNUSABLE;
printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
"%s\n", rx->dev->name, print_mac(mac, sa));
mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx,
(void *) skb->data);
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
/* remove Michael MIC from payload */
skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
/* update IV in key information to be able to detect replays */
- rx->key->u.tkip.iv32_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv32;
- rx->key->u.tkip.iv16_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv16;
+ rx->key->u.tkip.iv32_rx[rx->queue] = rx->tkip_iv32;
+ rx->key->u.tkip.iv16_rx[rx->queue] = rx->tkip_iv16;
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
-static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
+static int tkip_encrypt_skb(struct ieee80211_tx_data *tx,
struct sk_buff *skb, int test)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -228,7 +228,7 @@ static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
0x7f),
(u8) key->u.tkip.iv16);
- tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
+ tx->control->key_idx = tx->key->conf.hw_key_idx;
return 0;
}
@@ -242,42 +242,42 @@ static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
}
-ieee80211_txrx_result
-ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx)
+ieee80211_tx_result
+ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx)
{
struct sk_buff *skb = tx->skb;
int wpa_test = 0, test = 0;
- tx->u.tx.control->icv_len = TKIP_ICV_LEN;
- tx->u.tx.control->iv_len = TKIP_IV_LEN;
- ieee80211_tx_set_iswep(tx);
+ tx->control->icv_len = TKIP_ICV_LEN;
+ tx->control->iv_len = TKIP_IV_LEN;
+ ieee80211_tx_set_protected(tx);
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) &&
!wpa_test) {
/* hwaccel - with no need for preallocated room for IV/ICV */
- tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
- return TXRX_CONTINUE;
+ tx->control->key_idx = tx->key->conf.hw_key_idx;
+ return TX_CONTINUE;
}
if (tkip_encrypt_skb(tx, skb, test) < 0)
- return TXRX_DROP;
+ return TX_DROP;
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
int i;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
- if (tkip_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
+ for (i = 0; i < tx->num_extra_frag; i++) {
+ if (tkip_encrypt_skb(tx, tx->extra_frag[i], test)
< 0)
- return TXRX_DROP;
+ return TX_DROP;
}
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-ieee80211_txrx_result
-ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
+ieee80211_rx_result
+ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
u16 fc;
@@ -290,19 +290,19 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
hdrlen = ieee80211_get_hdrlen(fc);
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
if (!rx->sta || skb->len - hdrlen < 12)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
- if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) {
- if (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) {
+ if (rx->status->flag & RX_FLAG_DECRYPTED) {
+ if (rx->status->flag & RX_FLAG_IV_STRIPPED) {
/*
* Hardware took care of all processing, including
* replay protection, and stripped the ICV/IV so
* we cannot do any checks here.
*/
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
/* let TKIP code verify IV, but skip decryption */
@@ -312,9 +312,9 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
key, skb->data + hdrlen,
skb->len - hdrlen, rx->sta->addr,
- hwaccel, rx->u.rx.queue,
- &rx->u.rx.tkip_iv32,
- &rx->u.rx.tkip_iv16);
+ hdr->addr1, hwaccel, rx->queue,
+ &rx->tkip_iv32,
+ &rx->tkip_iv16);
if (res != TKIP_DECRYPT_OK || wpa_test) {
#ifdef CONFIG_MAC80211_DEBUG
if (net_ratelimit())
@@ -322,7 +322,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
"frame from %s (res=%d)\n", rx->dev->name,
print_mac(mac, rx->sta->addr), res);
#endif /* CONFIG_MAC80211_DEBUG */
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
/* Trim ICV */
@@ -332,7 +332,7 @@ ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
skb_pull(skb, TKIP_IV_LEN);
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
@@ -429,7 +429,7 @@ static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
}
-static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
+static int ccmp_encrypt_skb(struct ieee80211_tx_data *tx,
struct sk_buff *skb, int test)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -478,7 +478,7 @@ static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
/* hwaccel - with preallocated room for CCMP header */
- tx->u.tx.control->key_idx = key->conf.hw_key_idx;
+ tx->control->key_idx = key->conf.hw_key_idx;
return 0;
}
@@ -491,42 +491,42 @@ static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
}
-ieee80211_txrx_result
-ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx)
+ieee80211_tx_result
+ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx)
{
struct sk_buff *skb = tx->skb;
int test = 0;
- tx->u.tx.control->icv_len = CCMP_MIC_LEN;
- tx->u.tx.control->iv_len = CCMP_HDR_LEN;
- ieee80211_tx_set_iswep(tx);
+ tx->control->icv_len = CCMP_MIC_LEN;
+ tx->control->iv_len = CCMP_HDR_LEN;
+ ieee80211_tx_set_protected(tx);
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
/* hwaccel - with no need for preallocated room for CCMP "
* header or MIC fields */
- tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
- return TXRX_CONTINUE;
+ tx->control->key_idx = tx->key->conf.hw_key_idx;
+ return TX_CONTINUE;
}
if (ccmp_encrypt_skb(tx, skb, test) < 0)
- return TXRX_DROP;
+ return TX_DROP;
- if (tx->u.tx.extra_frag) {
+ if (tx->extra_frag) {
int i;
- for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
- if (ccmp_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
+ for (i = 0; i < tx->num_extra_frag; i++) {
+ if (ccmp_encrypt_skb(tx, tx->extra_frag[i], test)
< 0)
- return TXRX_DROP;
+ return TX_DROP;
}
}
- return TXRX_CONTINUE;
+ return TX_CONTINUE;
}
-ieee80211_txrx_result
-ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
+ieee80211_rx_result
+ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx)
{
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
u16 fc;
@@ -541,21 +541,21 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
hdrlen = ieee80211_get_hdrlen(fc);
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
if (!rx->sta || data_len < 0)
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
- if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
- (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
- return TXRX_CONTINUE;
+ if ((rx->status->flag & RX_FLAG_DECRYPTED) &&
+ (rx->status->flag & RX_FLAG_IV_STRIPPED))
+ return RX_CONTINUE;
(void) ccmp_hdr2pn(pn, skb->data + hdrlen);
- if (memcmp(pn, key->u.ccmp.rx_pn[rx->u.rx.queue], CCMP_PN_LEN) <= 0) {
+ if (memcmp(pn, key->u.ccmp.rx_pn[rx->queue], CCMP_PN_LEN) <= 0) {
#ifdef CONFIG_MAC80211_DEBUG
- u8 *ppn = key->u.ccmp.rx_pn[rx->u.rx.queue];
+ u8 *ppn = key->u.ccmp.rx_pn[rx->queue];
printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
"%s (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
@@ -565,10 +565,10 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
#endif /* CONFIG_MAC80211_DEBUG */
key->u.ccmp.replays++;
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
- if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) {
+ if (!(rx->status->flag & RX_FLAG_DECRYPTED)) {
/* hardware didn't decrypt/verify MIC */
u8 *scratch, *b_0, *aad;
@@ -589,16 +589,16 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
"for RX frame from %s\n", rx->dev->name,
print_mac(mac, rx->sta->addr));
#endif /* CONFIG_MAC80211_DEBUG */
- return TXRX_DROP;
+ return RX_DROP_UNUSABLE;
}
}
- memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
+ memcpy(key->u.ccmp.rx_pn[rx->queue], pn, CCMP_PN_LEN);
/* Remove CCMP header and MIC */
skb_trim(skb, skb->len - CCMP_MIC_LEN);
memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
skb_pull(skb, CCMP_HDR_LEN);
- return TXRX_CONTINUE;
+ return RX_CONTINUE;
}
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 @@
#include <linux/types.h>
#include "ieee80211_i.h"
-ieee80211_txrx_result
-ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx);
-ieee80211_txrx_result
-ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx);
+ieee80211_tx_result
+ieee80211_tx_h_michael_mic_add(struct ieee80211_tx_data *tx);
+ieee80211_rx_result
+ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx);
-ieee80211_txrx_result
-ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx);
-ieee80211_txrx_result
-ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx);
+ieee80211_tx_result
+ieee80211_crypto_tkip_encrypt(struct ieee80211_tx_data *tx);
+ieee80211_rx_result
+ieee80211_crypto_tkip_decrypt(struct ieee80211_rx_data *rx);
-ieee80211_txrx_result
-ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx);
-ieee80211_txrx_result
-ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx);
+ieee80211_tx_result
+ieee80211_crypto_ccmp_encrypt(struct ieee80211_tx_data *tx);
+ieee80211_rx_result
+ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx);
#endif /* WPA_H */