aboutsummaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/Kconfig29
-rw-r--r--net/mac80211/Makefile4
-rw-r--r--net/mac80211/agg-tx.c3
-rw-r--r--net/mac80211/cfg.c230
-rw-r--r--net/mac80211/debugfs.c2
-rw-r--r--net/mac80211/debugfs_netdev.c46
-rw-r--r--net/mac80211/debugfs_sta.c98
-rw-r--r--net/mac80211/driver-ops.h85
-rw-r--r--net/mac80211/driver-trace.c9
-rw-r--r--net/mac80211/driver-trace.h648
-rw-r--r--net/mac80211/event.c23
-rw-r--r--net/mac80211/ibss.c23
-rw-r--r--net/mac80211/ieee80211_i.h231
-rw-r--r--net/mac80211/iface.c139
-rw-r--r--net/mac80211/key.c28
-rw-r--r--net/mac80211/main.c166
-rw-r--r--net/mac80211/mesh.c23
-rw-r--r--net/mac80211/mesh.h3
-rw-r--r--net/mac80211/mesh_hwmp.c13
-rw-r--r--net/mac80211/mesh_pathtbl.c26
-rw-r--r--net/mac80211/mlme.c1985
-rw-r--r--net/mac80211/pm.c8
-rw-r--r--net/mac80211/rate.c31
-rw-r--r--net/mac80211/rc80211_minstrel.c23
-rw-r--r--net/mac80211/rc80211_pid_algo.c12
-rw-r--r--net/mac80211/rx.c179
-rw-r--r--net/mac80211/scan.c358
-rw-r--r--net/mac80211/sta_info.h30
-rw-r--r--net/mac80211/tx.c426
-rw-r--r--net/mac80211/util.c122
-rw-r--r--net/mac80211/wep.c52
-rw-r--r--net/mac80211/wep.h7
-rw-r--r--net/mac80211/wext.c633
-rw-r--r--net/mac80211/wme.c6
-rw-r--r--net/mac80211/wme.h3
-rw-r--r--net/mac80211/wpa.c3
36 files changed, 2856 insertions, 2851 deletions
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index 7836ee928983..7dd77b6d4c9a 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -6,7 +6,6 @@ config MAC80211
6 select CRYPTO_ARC4 6 select CRYPTO_ARC4
7 select CRYPTO_AES 7 select CRYPTO_AES
8 select CRC32 8 select CRC32
9 select WIRELESS_EXT
10 ---help--- 9 ---help---
11 This option enables the hardware independent IEEE 802.11 10 This option enables the hardware independent IEEE 802.11
12 networking stack. 11 networking stack.
@@ -14,22 +13,6 @@ config MAC80211
14comment "CFG80211 needs to be enabled for MAC80211" 13comment "CFG80211 needs to be enabled for MAC80211"
15 depends on CFG80211=n 14 depends on CFG80211=n
16 15
17config MAC80211_DEFAULT_PS
18 bool "enable powersave by default"
19 depends on MAC80211
20 default y
21 help
22 This option enables powersave mode by default.
23
24 If this causes your applications to misbehave you should fix your
25 applications instead -- they need to register their network
26 latency requirement, see Documentation/power/pm_qos_interface.txt.
27
28config MAC80211_DEFAULT_PS_VALUE
29 int
30 default 1 if MAC80211_DEFAULT_PS
31 default 0
32
33menu "Rate control algorithm selection" 16menu "Rate control algorithm selection"
34 depends on MAC80211 != n 17 depends on MAC80211 != n
35 18
@@ -222,3 +205,15 @@ config MAC80211_DEBUG_COUNTERS
222 and show them in debugfs. 205 and show them in debugfs.
223 206
224 If unsure, say N. 207 If unsure, say N.
208
209config MAC80211_DRIVER_API_TRACER
210 bool "Driver API tracer"
211 depends on MAC80211_DEBUG_MENU
212 depends on EVENT_TRACING
213 help
214 Say Y here to make mac80211 register with the ftrace
215 framework for the driver API -- you can see which
216 driver methods it is calling then by looking at the
217 trace.
218
219 If unsure, say N.
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 0e3ab88bb706..9f3cf7129324 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -3,7 +3,6 @@ obj-$(CONFIG_MAC80211) += mac80211.o
3# mac80211 objects 3# mac80211 objects
4mac80211-y := \ 4mac80211-y := \
5 main.o \ 5 main.o \
6 wext.o \
7 sta_info.o \ 6 sta_info.o \
8 wep.o \ 7 wep.o \
9 wpa.o \ 8 wpa.o \
@@ -41,6 +40,9 @@ mac80211-$(CONFIG_MAC80211_MESH) += \
41 40
42mac80211-$(CONFIG_PM) += pm.o 41mac80211-$(CONFIG_PM) += pm.o
43 42
43mac80211-$(CONFIG_MAC80211_DRIVER_API_TRACER) += driver-trace.o
44CFLAGS_driver-trace.o := -I$(src)
45
44# objects for PID algorithm 46# objects for PID algorithm
45rc80211_pid-y := rc80211_pid_algo.o 47rc80211_pid-y := rc80211_pid_algo.o
46rc80211_pid-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o 48rc80211_pid-$(CONFIG_MAC80211_DEBUGFS) += rc80211_pid_debugfs.o
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index 9e5762ad307d..1958c7c42cd9 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -383,9 +383,6 @@ static void ieee80211_agg_splice_packets(struct ieee80211_local *local,
383 383
384 if (!skb_queue_empty(&sta->ampdu_mlme.tid_tx[tid]->pending)) { 384 if (!skb_queue_empty(&sta->ampdu_mlme.tid_tx[tid]->pending)) {
385 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 385 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
386 /* mark queue as pending, it is stopped already */
387 __set_bit(IEEE80211_QUEUE_STOP_REASON_PENDING,
388 &local->queue_stop_reasons[queue]);
389 /* copy over remaining packets */ 386 /* copy over remaining packets */
390 skb_queue_splice_tail_init( 387 skb_queue_splice_tail_init(
391 &sta->ampdu_mlme.tid_tx[tid]->pending, 388 &sta->ampdu_mlme.tid_tx[tid]->pending,
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 3f47276caeb8..4bbf5007799b 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -57,36 +57,21 @@ static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
57 return 0; 57 return 0;
58} 58}
59 59
60static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) 60static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
61{ 61{
62 struct net_device *dev; 62 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
63 struct ieee80211_sub_if_data *sdata;
64
65 /* we're under RTNL */
66 dev = __dev_get_by_index(&init_net, ifindex);
67 if (!dev)
68 return -ENODEV;
69
70 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
71
72 ieee80211_if_remove(sdata);
73 63
74 return 0; 64 return 0;
75} 65}
76 66
77static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, 67static int ieee80211_change_iface(struct wiphy *wiphy,
68 struct net_device *dev,
78 enum nl80211_iftype type, u32 *flags, 69 enum nl80211_iftype type, u32 *flags,
79 struct vif_params *params) 70 struct vif_params *params)
80{ 71{
81 struct net_device *dev;
82 struct ieee80211_sub_if_data *sdata; 72 struct ieee80211_sub_if_data *sdata;
83 int ret; 73 int ret;
84 74
85 /* we're under RTNL */
86 dev = __dev_get_by_index(&init_net, ifindex);
87 if (!dev)
88 return -ENODEV;
89
90 if (!nl80211_type_check(type)) 75 if (!nl80211_type_check(type))
91 return -EINVAL; 76 return -EINVAL;
92 77
@@ -1177,123 +1162,29 @@ static int ieee80211_scan(struct wiphy *wiphy,
1177static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, 1162static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1178 struct cfg80211_auth_request *req) 1163 struct cfg80211_auth_request *req)
1179{ 1164{
1180 struct ieee80211_sub_if_data *sdata; 1165 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1181
1182 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1183
1184 switch (req->auth_type) {
1185 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1186 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
1187 break;
1188 case NL80211_AUTHTYPE_SHARED_KEY:
1189 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
1190 break;
1191 case NL80211_AUTHTYPE_FT:
1192 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
1193 break;
1194 case NL80211_AUTHTYPE_NETWORK_EAP:
1195 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
1196 break;
1197 default:
1198 return -EOPNOTSUPP;
1199 }
1200
1201 memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
1202 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1203 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1204
1205 /* TODO: req->chan */
1206 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1207
1208 if (req->ssid) {
1209 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1210 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1211 sdata->u.mgd.ssid_len = req->ssid_len;
1212 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1213 }
1214
1215 kfree(sdata->u.mgd.sme_auth_ie);
1216 sdata->u.mgd.sme_auth_ie = NULL;
1217 sdata->u.mgd.sme_auth_ie_len = 0;
1218 if (req->ie) {
1219 sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
1220 if (sdata->u.mgd.sme_auth_ie == NULL)
1221 return -ENOMEM;
1222 memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
1223 sdata->u.mgd.sme_auth_ie_len = req->ie_len;
1224 }
1225
1226 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1227 sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
1228 ieee80211_sta_req_auth(sdata);
1229 return 0;
1230} 1166}
1231 1167
1232static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, 1168static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1233 struct cfg80211_assoc_request *req) 1169 struct cfg80211_assoc_request *req)
1234{ 1170{
1235 struct ieee80211_sub_if_data *sdata; 1171 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1236 int ret;
1237
1238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1239
1240 if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
1241 !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
1242 return -ENOLINK; /* not authenticated */
1243
1244 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1245 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1246
1247 /* TODO: req->chan */
1248 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1249
1250 if (req->ssid) {
1251 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1252 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1253 sdata->u.mgd.ssid_len = req->ssid_len;
1254 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1255 } else
1256 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1257
1258 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1259 if (ret && ret != -EALREADY)
1260 return ret;
1261
1262 if (req->use_mfp) {
1263 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
1264 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
1265 } else {
1266 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
1267 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
1268 }
1269
1270 if (req->control_port)
1271 sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT;
1272 else
1273 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
1274
1275 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1276 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1277 ieee80211_sta_req_auth(sdata);
1278 return 0;
1279} 1172}
1280 1173
1281static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 1174static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1282 struct cfg80211_deauth_request *req) 1175 struct cfg80211_deauth_request *req,
1176 void *cookie)
1283{ 1177{
1284 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1178 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1285 1179 req, cookie);
1286 /* TODO: req->ie, req->peer_addr */
1287 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1288} 1180}
1289 1181
1290static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 1182static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1291 struct cfg80211_disassoc_request *req) 1183 struct cfg80211_disassoc_request *req,
1184 void *cookie)
1292{ 1185{
1293 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1186 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1294 1187 req, cookie);
1295 /* TODO: req->ie, req->peer_addr */
1296 return ieee80211_sta_disassociate(sdata, req->reason_code);
1297} 1188}
1298 1189
1299static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, 1190static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
@@ -1374,6 +1265,16 @@ static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1374 return 0; 1265 return 0;
1375} 1266}
1376 1267
1268static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1269 u8 *addr)
1270{
1271 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1272
1273 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1274
1275 return 0;
1276}
1277
1377static void ieee80211_rfkill_poll(struct wiphy *wiphy) 1278static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1378{ 1279{
1379 struct ieee80211_local *local = wiphy_priv(wiphy); 1280 struct ieee80211_local *local = wiphy_priv(wiphy);
@@ -1381,6 +1282,85 @@ static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1381 drv_rfkill_poll(local); 1282 drv_rfkill_poll(local);
1382} 1283}
1383 1284
1285#ifdef CONFIG_NL80211_TESTMODE
1286static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1287{
1288 struct ieee80211_local *local = wiphy_priv(wiphy);
1289
1290 if (!local->ops->testmode_cmd)
1291 return -EOPNOTSUPP;
1292
1293 return local->ops->testmode_cmd(&local->hw, data, len);
1294}
1295#endif
1296
1297static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1298 bool enabled, int timeout)
1299{
1300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1302 struct ieee80211_conf *conf = &local->hw.conf;
1303
1304 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1305 return -EOPNOTSUPP;
1306
1307 if (enabled == sdata->u.mgd.powersave &&
1308 timeout == conf->dynamic_ps_timeout)
1309 return 0;
1310
1311 sdata->u.mgd.powersave = enabled;
1312 conf->dynamic_ps_timeout = timeout;
1313
1314 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1315 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1316
1317 ieee80211_recalc_ps(local, -1);
1318
1319 return 0;
1320}
1321
1322static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1323 struct net_device *dev,
1324 const u8 *addr,
1325 const struct cfg80211_bitrate_mask *mask)
1326{
1327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1328 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1329 int i, err = -EINVAL;
1330 u32 target_rate;
1331 struct ieee80211_supported_band *sband;
1332
1333 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1334
1335 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1336 * target_rate = X, rate->fixed = 1 means only rate X
1337 * target_rate = X, rate->fixed = 0 means all rates <= X */
1338 sdata->max_ratectrl_rateidx = -1;
1339 sdata->force_unicast_rateidx = -1;
1340
1341 if (mask->fixed)
1342 target_rate = mask->fixed / 100;
1343 else if (mask->maxrate)
1344 target_rate = mask->maxrate / 100;
1345 else
1346 return 0;
1347
1348 for (i=0; i< sband->n_bitrates; i++) {
1349 struct ieee80211_rate *brate = &sband->bitrates[i];
1350 int this_rate = brate->bitrate;
1351
1352 if (target_rate == this_rate) {
1353 sdata->max_ratectrl_rateidx = i;
1354 if (mask->fixed)
1355 sdata->force_unicast_rateidx = i;
1356 err = 0;
1357 break;
1358 }
1359 }
1360
1361 return err;
1362}
1363
1384struct cfg80211_ops mac80211_config_ops = { 1364struct cfg80211_ops mac80211_config_ops = {
1385 .add_virtual_intf = ieee80211_add_iface, 1365 .add_virtual_intf = ieee80211_add_iface,
1386 .del_virtual_intf = ieee80211_del_iface, 1366 .del_virtual_intf = ieee80211_del_iface,
@@ -1422,5 +1402,9 @@ struct cfg80211_ops mac80211_config_ops = {
1422 .set_wiphy_params = ieee80211_set_wiphy_params, 1402 .set_wiphy_params = ieee80211_set_wiphy_params,
1423 .set_tx_power = ieee80211_set_tx_power, 1403 .set_tx_power = ieee80211_set_tx_power,
1424 .get_tx_power = ieee80211_get_tx_power, 1404 .get_tx_power = ieee80211_get_tx_power,
1405 .set_wds_peer = ieee80211_set_wds_peer,
1425 .rfkill_poll = ieee80211_rfkill_poll, 1406 .rfkill_poll = ieee80211_rfkill_poll,
1407 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
1408 .set_power_mgmt = ieee80211_set_power_mgmt,
1409 .set_bitrate_mask = ieee80211_set_bitrate_mask,
1426}; 1410};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 6c439cd5ccea..96991b68f048 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -175,7 +175,7 @@ static ssize_t queues_read(struct file *file, char __user *user_buf,
175 for (q = 0; q < local->hw.queues; q++) 175 for (q = 0; q < local->hw.queues; q++)
176 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q, 176 res += sprintf(buf + res, "%02d: %#.8lx/%d\n", q,
177 local->queue_stop_reasons[q], 177 local->queue_stop_reasons[q],
178 __netif_subqueue_stopped(local->mdev, q)); 178 skb_queue_len(&local->pending[q]));
179 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 179 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
180 180
181 return simple_read_from_buffer(user_buf, count, ppos, buf, res); 181 return simple_read_from_buffer(user_buf, count, ppos, buf, res);
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index e3420329f4e6..e9ec6cae2d39 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -95,33 +95,9 @@ IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC); 95IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
96 96
97/* STA attributes */ 97/* STA attributes */
98IEEE80211_IF_FILE(state, u.mgd.state, DEC);
99IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); 98IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
100IEEE80211_IF_FILE(prev_bssid, u.mgd.prev_bssid, MAC);
101IEEE80211_IF_FILE(ssid_len, u.mgd.ssid_len, SIZE);
102IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); 99IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
103IEEE80211_IF_FILE(ap_capab, u.mgd.ap_capab, HEX);
104IEEE80211_IF_FILE(capab, u.mgd.capab, HEX); 100IEEE80211_IF_FILE(capab, u.mgd.capab, HEX);
105IEEE80211_IF_FILE(extra_ie_len, u.mgd.extra_ie_len, SIZE);
106IEEE80211_IF_FILE(auth_tries, u.mgd.auth_tries, DEC);
107IEEE80211_IF_FILE(assoc_tries, u.mgd.assoc_tries, DEC);
108IEEE80211_IF_FILE(auth_algs, u.mgd.auth_algs, HEX);
109IEEE80211_IF_FILE(auth_alg, u.mgd.auth_alg, DEC);
110IEEE80211_IF_FILE(auth_transaction, u.mgd.auth_transaction, DEC);
111
112static ssize_t ieee80211_if_fmt_flags(
113 const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
114{
115 return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
116 sdata->u.mgd.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
117 sdata->u.mgd.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
118 sdata->u.mgd.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
119 sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
120 sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
121 sdata->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
122 sdata->vif.bss_conf.use_cts_prot ? "CTS prot\n" : "");
123}
124__IEEE80211_IF_FILE(flags);
125 101
126/* AP attributes */ 102/* AP attributes */
127IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC); 103IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
@@ -184,20 +160,9 @@ static void add_sta_files(struct ieee80211_sub_if_data *sdata)
184 DEBUGFS_ADD(force_unicast_rateidx, sta); 160 DEBUGFS_ADD(force_unicast_rateidx, sta);
185 DEBUGFS_ADD(max_ratectrl_rateidx, sta); 161 DEBUGFS_ADD(max_ratectrl_rateidx, sta);
186 162
187 DEBUGFS_ADD(state, sta);
188 DEBUGFS_ADD(bssid, sta); 163 DEBUGFS_ADD(bssid, sta);
189 DEBUGFS_ADD(prev_bssid, sta);
190 DEBUGFS_ADD(ssid_len, sta);
191 DEBUGFS_ADD(aid, sta); 164 DEBUGFS_ADD(aid, sta);
192 DEBUGFS_ADD(ap_capab, sta);
193 DEBUGFS_ADD(capab, sta); 165 DEBUGFS_ADD(capab, sta);
194 DEBUGFS_ADD(extra_ie_len, sta);
195 DEBUGFS_ADD(auth_tries, sta);
196 DEBUGFS_ADD(assoc_tries, sta);
197 DEBUGFS_ADD(auth_algs, sta);
198 DEBUGFS_ADD(auth_alg, sta);
199 DEBUGFS_ADD(auth_transaction, sta);
200 DEBUGFS_ADD(flags, sta);
201} 166}
202 167
203static void add_ap_files(struct ieee80211_sub_if_data *sdata) 168static void add_ap_files(struct ieee80211_sub_if_data *sdata)
@@ -317,20 +282,9 @@ static void del_sta_files(struct ieee80211_sub_if_data *sdata)
317 DEBUGFS_DEL(force_unicast_rateidx, sta); 282 DEBUGFS_DEL(force_unicast_rateidx, sta);
318 DEBUGFS_DEL(max_ratectrl_rateidx, sta); 283 DEBUGFS_DEL(max_ratectrl_rateidx, sta);
319 284
320 DEBUGFS_DEL(state, sta);
321 DEBUGFS_DEL(bssid, sta); 285 DEBUGFS_DEL(bssid, sta);
322 DEBUGFS_DEL(prev_bssid, sta);
323 DEBUGFS_DEL(ssid_len, sta);
324 DEBUGFS_DEL(aid, sta); 286 DEBUGFS_DEL(aid, sta);
325 DEBUGFS_DEL(ap_capab, sta);
326 DEBUGFS_DEL(capab, sta); 287 DEBUGFS_DEL(capab, sta);
327 DEBUGFS_DEL(extra_ie_len, sta);
328 DEBUGFS_DEL(auth_tries, sta);
329 DEBUGFS_DEL(assoc_tries, sta);
330 DEBUGFS_DEL(auth_algs, sta);
331 DEBUGFS_DEL(auth_alg, sta);
332 DEBUGFS_DEL(auth_transaction, sta);
333 DEBUGFS_DEL(flags, sta);
334} 288}
335 289
336static void del_ap_files(struct ieee80211_sub_if_data *sdata) 290static void del_ap_files(struct ieee80211_sub_if_data *sdata)
diff --git a/net/mac80211/debugfs_sta.c b/net/mac80211/debugfs_sta.c
index 90230c718b5b..33a2e892115b 100644
--- a/net/mac80211/debugfs_sta.c
+++ b/net/mac80211/debugfs_sta.c
@@ -120,45 +120,38 @@ STA_OPS(last_seq_ctrl);
120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf, 120static ssize_t sta_agg_status_read(struct file *file, char __user *userbuf,
121 size_t count, loff_t *ppos) 121 size_t count, loff_t *ppos)
122{ 122{
123 char buf[768], *p = buf; 123 char buf[30 + STA_TID_NUM * 70], *p = buf;
124 int i; 124 int i;
125 struct sta_info *sta = file->private_data; 125 struct sta_info *sta = file->private_data;
126 p += scnprintf(p, sizeof(buf)+buf-p, "Agg state for STA is:\n");
127 p += scnprintf(p, sizeof(buf)+buf-p, " STA next dialog_token is %d \n "
128 "TIDs info is: \n TID :",
129 (sta->ampdu_mlme.dialog_token_allocator + 1));
130 for (i = 0; i < STA_TID_NUM; i++)
131 p += scnprintf(p, sizeof(buf)+buf-p, "%5d", i);
132
133 p += scnprintf(p, sizeof(buf)+buf-p, "\n RX :");
134 for (i = 0; i < STA_TID_NUM; i++)
135 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
136 sta->ampdu_mlme.tid_state_rx[i]);
137
138 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
139 for (i = 0; i < STA_TID_NUM; i++)
140 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
141 sta->ampdu_mlme.tid_state_rx[i] ?
142 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
143
144 p += scnprintf(p, sizeof(buf)+buf-p, "\n TX :");
145 for (i = 0; i < STA_TID_NUM; i++)
146 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
147 sta->ampdu_mlme.tid_state_tx[i]);
148
149 p += scnprintf(p, sizeof(buf)+buf-p, "\n DTKN:");
150 for (i = 0; i < STA_TID_NUM; i++)
151 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
152 sta->ampdu_mlme.tid_state_tx[i] ?
153 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
154
155 p += scnprintf(p, sizeof(buf)+buf-p, "\n SSN :");
156 for (i = 0; i < STA_TID_NUM; i++)
157 p += scnprintf(p, sizeof(buf)+buf-p, "%5d",
158 sta->ampdu_mlme.tid_state_tx[i] ?
159 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
160 126
161 p += scnprintf(p, sizeof(buf)+buf-p, "\n"); 127 spin_lock_bh(&sta->lock);
128 p += scnprintf(p, sizeof(buf)+buf-p, "next dialog_token is %#02x\n",
129 sta->ampdu_mlme.dialog_token_allocator + 1);
130 for (i = 0; i < STA_TID_NUM; i++) {
131 p += scnprintf(p, sizeof(buf)+buf-p, "TID %02d:", i);
132 p += scnprintf(p, sizeof(buf)+buf-p, " RX=%x",
133 sta->ampdu_mlme.tid_state_rx[i]);
134 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x",
135 sta->ampdu_mlme.tid_state_rx[i] ?
136 sta->ampdu_mlme.tid_rx[i]->dialog_token : 0);
137 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x",
138 sta->ampdu_mlme.tid_state_rx[i] ?
139 sta->ampdu_mlme.tid_rx[i]->ssn : 0);
140
141 p += scnprintf(p, sizeof(buf)+buf-p, " TX=%x",
142 sta->ampdu_mlme.tid_state_tx[i]);
143 p += scnprintf(p, sizeof(buf)+buf-p, "/DTKN=%#.2x",
144 sta->ampdu_mlme.tid_state_tx[i] ?
145 sta->ampdu_mlme.tid_tx[i]->dialog_token : 0);
146 p += scnprintf(p, sizeof(buf)+buf-p, "/SSN=%#.3x",
147 sta->ampdu_mlme.tid_state_tx[i] ?
148 sta->ampdu_mlme.tid_tx[i]->ssn : 0);
149 p += scnprintf(p, sizeof(buf)+buf-p, "/pending=%03d",
150 sta->ampdu_mlme.tid_state_tx[i] ?
151 skb_queue_len(&sta->ampdu_mlme.tid_tx[i]->pending) : 0);
152 p += scnprintf(p, sizeof(buf)+buf-p, "\n");
153 }
154 spin_unlock_bh(&sta->lock);
162 155
163 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf); 156 return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
164} 157}
@@ -203,6 +196,22 @@ void ieee80211_sta_debugfs_add(struct sta_info *sta)
203 DEBUGFS_ADD(inactive_ms); 196 DEBUGFS_ADD(inactive_ms);
204 DEBUGFS_ADD(last_seq_ctrl); 197 DEBUGFS_ADD(last_seq_ctrl);
205 DEBUGFS_ADD(agg_status); 198 DEBUGFS_ADD(agg_status);
199 DEBUGFS_ADD(dev);
200 DEBUGFS_ADD(rx_packets);
201 DEBUGFS_ADD(tx_packets);
202 DEBUGFS_ADD(rx_bytes);
203 DEBUGFS_ADD(tx_bytes);
204 DEBUGFS_ADD(rx_duplicates);
205 DEBUGFS_ADD(rx_fragments);
206 DEBUGFS_ADD(rx_dropped);
207 DEBUGFS_ADD(tx_fragments);
208 DEBUGFS_ADD(tx_filtered);
209 DEBUGFS_ADD(tx_retry_failed);
210 DEBUGFS_ADD(tx_retry_count);
211 DEBUGFS_ADD(last_signal);
212 DEBUGFS_ADD(last_qual);
213 DEBUGFS_ADD(last_noise);
214 DEBUGFS_ADD(wep_weak_iv_count);
206} 215}
207 216
208void ieee80211_sta_debugfs_remove(struct sta_info *sta) 217void ieee80211_sta_debugfs_remove(struct sta_info *sta)
@@ -212,6 +221,23 @@ void ieee80211_sta_debugfs_remove(struct sta_info *sta)
212 DEBUGFS_DEL(inactive_ms); 221 DEBUGFS_DEL(inactive_ms);
213 DEBUGFS_DEL(last_seq_ctrl); 222 DEBUGFS_DEL(last_seq_ctrl);
214 DEBUGFS_DEL(agg_status); 223 DEBUGFS_DEL(agg_status);
224 DEBUGFS_DEL(aid);
225 DEBUGFS_DEL(dev);
226 DEBUGFS_DEL(rx_packets);
227 DEBUGFS_DEL(tx_packets);
228 DEBUGFS_DEL(rx_bytes);
229 DEBUGFS_DEL(tx_bytes);
230 DEBUGFS_DEL(rx_duplicates);
231 DEBUGFS_DEL(rx_fragments);
232 DEBUGFS_DEL(rx_dropped);
233 DEBUGFS_DEL(tx_fragments);
234 DEBUGFS_DEL(tx_filtered);
235 DEBUGFS_DEL(tx_retry_failed);
236 DEBUGFS_DEL(tx_retry_count);
237 DEBUGFS_DEL(last_signal);
238 DEBUGFS_DEL(last_qual);
239 DEBUGFS_DEL(last_noise);
240 DEBUGFS_DEL(wep_weak_iv_count);
215 241
216 debugfs_remove(sta->debugfs.dir); 242 debugfs_remove(sta->debugfs.dir);
217 sta->debugfs.dir = NULL; 243 sta->debugfs.dir = NULL;
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index b13446afd48f..4100c361a99d 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -3,6 +3,7 @@
3 3
4#include <net/mac80211.h> 4#include <net/mac80211.h>
5#include "ieee80211_i.h" 5#include "ieee80211_i.h"
6#include "driver-trace.h"
6 7
7static inline int drv_tx(struct ieee80211_local *local, struct sk_buff *skb) 8static inline int drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
8{ 9{
@@ -11,29 +12,37 @@ static inline int drv_tx(struct ieee80211_local *local, struct sk_buff *skb)
11 12
12static inline int drv_start(struct ieee80211_local *local) 13static inline int drv_start(struct ieee80211_local *local)
13{ 14{
14 return local->ops->start(&local->hw); 15 int ret = local->ops->start(&local->hw);
16 trace_drv_start(local, ret);
17 return ret;
15} 18}
16 19
17static inline void drv_stop(struct ieee80211_local *local) 20static inline void drv_stop(struct ieee80211_local *local)
18{ 21{
19 local->ops->stop(&local->hw); 22 local->ops->stop(&local->hw);
23 trace_drv_stop(local);
20} 24}
21 25
22static inline int drv_add_interface(struct ieee80211_local *local, 26static inline int drv_add_interface(struct ieee80211_local *local,
23 struct ieee80211_if_init_conf *conf) 27 struct ieee80211_if_init_conf *conf)
24{ 28{
25 return local->ops->add_interface(&local->hw, conf); 29 int ret = local->ops->add_interface(&local->hw, conf);
30 trace_drv_add_interface(local, conf->mac_addr, conf->vif, ret);
31 return ret;
26} 32}
27 33
28static inline void drv_remove_interface(struct ieee80211_local *local, 34static inline void drv_remove_interface(struct ieee80211_local *local,
29 struct ieee80211_if_init_conf *conf) 35 struct ieee80211_if_init_conf *conf)
30{ 36{
31 local->ops->remove_interface(&local->hw, conf); 37 local->ops->remove_interface(&local->hw, conf);
38 trace_drv_remove_interface(local, conf->mac_addr, conf->vif);
32} 39}
33 40
34static inline int drv_config(struct ieee80211_local *local, u32 changed) 41static inline int drv_config(struct ieee80211_local *local, u32 changed)
35{ 42{
36 return local->ops->config(&local->hw, changed); 43 int ret = local->ops->config(&local->hw, changed);
44 trace_drv_config(local, changed, ret);
45 return ret;
37} 46}
38 47
39static inline void drv_bss_info_changed(struct ieee80211_local *local, 48static inline void drv_bss_info_changed(struct ieee80211_local *local,
@@ -43,6 +52,7 @@ static inline void drv_bss_info_changed(struct ieee80211_local *local,
43{ 52{
44 if (local->ops->bss_info_changed) 53 if (local->ops->bss_info_changed)
45 local->ops->bss_info_changed(&local->hw, vif, info, changed); 54 local->ops->bss_info_changed(&local->hw, vif, info, changed);
55 trace_drv_bss_info_changed(local, vif, info, changed);
46} 56}
47 57
48static inline void drv_configure_filter(struct ieee80211_local *local, 58static inline void drv_configure_filter(struct ieee80211_local *local,
@@ -53,14 +63,18 @@ static inline void drv_configure_filter(struct ieee80211_local *local,
53{ 63{
54 local->ops->configure_filter(&local->hw, changed_flags, total_flags, 64 local->ops->configure_filter(&local->hw, changed_flags, total_flags,
55 mc_count, mc_list); 65 mc_count, mc_list);
66 trace_drv_configure_filter(local, changed_flags, total_flags,
67 mc_count);
56} 68}
57 69
58static inline int drv_set_tim(struct ieee80211_local *local, 70static inline int drv_set_tim(struct ieee80211_local *local,
59 struct ieee80211_sta *sta, bool set) 71 struct ieee80211_sta *sta, bool set)
60{ 72{
73 int ret = 0;
61 if (local->ops->set_tim) 74 if (local->ops->set_tim)
62 return local->ops->set_tim(&local->hw, sta, set); 75 ret = local->ops->set_tim(&local->hw, sta, set);
63 return 0; 76 trace_drv_set_tim(local, sta, set, ret);
77 return ret;
64} 78}
65 79
66static inline int drv_set_key(struct ieee80211_local *local, 80static inline int drv_set_key(struct ieee80211_local *local,
@@ -68,7 +82,9 @@ static inline int drv_set_key(struct ieee80211_local *local,
68 struct ieee80211_sta *sta, 82 struct ieee80211_sta *sta,
69 struct ieee80211_key_conf *key) 83 struct ieee80211_key_conf *key)
70{ 84{
71 return local->ops->set_key(&local->hw, cmd, vif, sta, key); 85 int ret = local->ops->set_key(&local->hw, cmd, vif, sta, key);
86 trace_drv_set_key(local, cmd, vif, sta, key, ret);
87 return ret;
72} 88}
73 89
74static inline void drv_update_tkip_key(struct ieee80211_local *local, 90static inline void drv_update_tkip_key(struct ieee80211_local *local,
@@ -79,32 +95,41 @@ static inline void drv_update_tkip_key(struct ieee80211_local *local,
79 if (local->ops->update_tkip_key) 95 if (local->ops->update_tkip_key)
80 local->ops->update_tkip_key(&local->hw, conf, address, 96 local->ops->update_tkip_key(&local->hw, conf, address,
81 iv32, phase1key); 97 iv32, phase1key);
98 trace_drv_update_tkip_key(local, conf, address, iv32);
82} 99}
83 100
84static inline int drv_hw_scan(struct ieee80211_local *local, 101static inline int drv_hw_scan(struct ieee80211_local *local,
85 struct cfg80211_scan_request *req) 102 struct cfg80211_scan_request *req)
86{ 103{
87 return local->ops->hw_scan(&local->hw, req); 104 int ret = local->ops->hw_scan(&local->hw, req);
105 trace_drv_hw_scan(local, req, ret);
106 return ret;
88} 107}
89 108
90static inline void drv_sw_scan_start(struct ieee80211_local *local) 109static inline void drv_sw_scan_start(struct ieee80211_local *local)
91{ 110{
92 if (local->ops->sw_scan_start) 111 if (local->ops->sw_scan_start)
93 local->ops->sw_scan_start(&local->hw); 112 local->ops->sw_scan_start(&local->hw);
113 trace_drv_sw_scan_start(local);
94} 114}
95 115
96static inline void drv_sw_scan_complete(struct ieee80211_local *local) 116static inline void drv_sw_scan_complete(struct ieee80211_local *local)
97{ 117{
98 if (local->ops->sw_scan_complete) 118 if (local->ops->sw_scan_complete)
99 local->ops->sw_scan_complete(&local->hw); 119 local->ops->sw_scan_complete(&local->hw);
120 trace_drv_sw_scan_complete(local);
100} 121}
101 122
102static inline int drv_get_stats(struct ieee80211_local *local, 123static inline int drv_get_stats(struct ieee80211_local *local,
103 struct ieee80211_low_level_stats *stats) 124 struct ieee80211_low_level_stats *stats)
104{ 125{
105 if (!local->ops->get_stats) 126 int ret = -EOPNOTSUPP;
106 return -EOPNOTSUPP; 127
107 return local->ops->get_stats(&local->hw, stats); 128 if (local->ops->get_stats)
129 ret = local->ops->get_stats(&local->hw, stats);
130 trace_drv_get_stats(local, stats, ret);
131
132 return ret;
108} 133}
109 134
110static inline void drv_get_tkip_seq(struct ieee80211_local *local, 135static inline void drv_get_tkip_seq(struct ieee80211_local *local,
@@ -112,14 +137,17 @@ static inline void drv_get_tkip_seq(struct ieee80211_local *local,
112{ 137{
113 if (local->ops->get_tkip_seq) 138 if (local->ops->get_tkip_seq)
114 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16); 139 local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
140 trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
115} 141}
116 142
117static inline int drv_set_rts_threshold(struct ieee80211_local *local, 143static inline int drv_set_rts_threshold(struct ieee80211_local *local,
118 u32 value) 144 u32 value)
119{ 145{
146 int ret = 0;
120 if (local->ops->set_rts_threshold) 147 if (local->ops->set_rts_threshold)
121 return local->ops->set_rts_threshold(&local->hw, value); 148 ret = local->ops->set_rts_threshold(&local->hw, value);
122 return 0; 149 trace_drv_set_rts_threshold(local, value, ret);
150 return ret;
123} 151}
124 152
125static inline void drv_sta_notify(struct ieee80211_local *local, 153static inline void drv_sta_notify(struct ieee80211_local *local,
@@ -129,46 +157,57 @@ static inline void drv_sta_notify(struct ieee80211_local *local,
129{ 157{
130 if (local->ops->sta_notify) 158 if (local->ops->sta_notify)
131 local->ops->sta_notify(&local->hw, vif, cmd, sta); 159 local->ops->sta_notify(&local->hw, vif, cmd, sta);
160 trace_drv_sta_notify(local, vif, cmd, sta);
132} 161}
133 162
134static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue, 163static inline int drv_conf_tx(struct ieee80211_local *local, u16 queue,
135 const struct ieee80211_tx_queue_params *params) 164 const struct ieee80211_tx_queue_params *params)
136{ 165{
166 int ret = -EOPNOTSUPP;
137 if (local->ops->conf_tx) 167 if (local->ops->conf_tx)
138 return local->ops->conf_tx(&local->hw, queue, params); 168 ret = local->ops->conf_tx(&local->hw, queue, params);
139 return -EOPNOTSUPP; 169 trace_drv_conf_tx(local, queue, params, ret);
170 return ret;
140} 171}
141 172
142static inline int drv_get_tx_stats(struct ieee80211_local *local, 173static inline int drv_get_tx_stats(struct ieee80211_local *local,
143 struct ieee80211_tx_queue_stats *stats) 174 struct ieee80211_tx_queue_stats *stats)
144{ 175{
145 return local->ops->get_tx_stats(&local->hw, stats); 176 int ret = local->ops->get_tx_stats(&local->hw, stats);
177 trace_drv_get_tx_stats(local, stats, ret);
178 return ret;
146} 179}
147 180
148static inline u64 drv_get_tsf(struct ieee80211_local *local) 181static inline u64 drv_get_tsf(struct ieee80211_local *local)
149{ 182{
183 u64 ret = -1ULL;
150 if (local->ops->get_tsf) 184 if (local->ops->get_tsf)
151 return local->ops->get_tsf(&local->hw); 185 ret = local->ops->get_tsf(&local->hw);
152 return -1ULL; 186 trace_drv_get_tsf(local, ret);
187 return ret;
153} 188}
154 189
155static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf) 190static inline void drv_set_tsf(struct ieee80211_local *local, u64 tsf)
156{ 191{
157 if (local->ops->set_tsf) 192 if (local->ops->set_tsf)
158 local->ops->set_tsf(&local->hw, tsf); 193 local->ops->set_tsf(&local->hw, tsf);
194 trace_drv_set_tsf(local, tsf);
159} 195}
160 196
161static inline void drv_reset_tsf(struct ieee80211_local *local) 197static inline void drv_reset_tsf(struct ieee80211_local *local)
162{ 198{
163 if (local->ops->reset_tsf) 199 if (local->ops->reset_tsf)
164 local->ops->reset_tsf(&local->hw); 200 local->ops->reset_tsf(&local->hw);
201 trace_drv_reset_tsf(local);
165} 202}
166 203
167static inline int drv_tx_last_beacon(struct ieee80211_local *local) 204static inline int drv_tx_last_beacon(struct ieee80211_local *local)
168{ 205{
206 int ret = 1;
169 if (local->ops->tx_last_beacon) 207 if (local->ops->tx_last_beacon)
170 return local->ops->tx_last_beacon(&local->hw); 208 ret = local->ops->tx_last_beacon(&local->hw);
171 return 1; 209 trace_drv_tx_last_beacon(local, ret);
210 return ret;
172} 211}
173 212
174static inline int drv_ampdu_action(struct ieee80211_local *local, 213static inline int drv_ampdu_action(struct ieee80211_local *local,
@@ -176,10 +215,12 @@ static inline int drv_ampdu_action(struct ieee80211_local *local,
176 struct ieee80211_sta *sta, u16 tid, 215 struct ieee80211_sta *sta, u16 tid,
177 u16 *ssn) 216 u16 *ssn)
178{ 217{
218 int ret = -EOPNOTSUPP;
179 if (local->ops->ampdu_action) 219 if (local->ops->ampdu_action)
180 return local->ops->ampdu_action(&local->hw, action, 220 ret = local->ops->ampdu_action(&local->hw, action,
181 sta, tid, ssn); 221 sta, tid, ssn);
182 return -EOPNOTSUPP; 222 trace_drv_ampdu_action(local, action, sta, tid, ssn, ret);
223 return ret;
183} 224}
184 225
185 226
diff --git a/net/mac80211/driver-trace.c b/net/mac80211/driver-trace.c
new file mode 100644
index 000000000000..8ed8711b1a6d
--- /dev/null
+++ b/net/mac80211/driver-trace.c
@@ -0,0 +1,9 @@
1/* bug in tracepoint.h, it should include this */
2#include <linux/module.h>
3
4/* sparse isn't too happy with all macros... */
5#ifndef __CHECKER__
6#include "driver-ops.h"
7#define CREATE_TRACE_POINTS
8#include "driver-trace.h"
9#endif
diff --git a/net/mac80211/driver-trace.h b/net/mac80211/driver-trace.h
new file mode 100644
index 000000000000..5a10da2d70fd
--- /dev/null
+++ b/net/mac80211/driver-trace.h
@@ -0,0 +1,648 @@
1#if !defined(__MAC80211_DRIVER_TRACE) || defined(TRACE_HEADER_MULTI_READ)
2#define __MAC80211_DRIVER_TRACE
3
4#include <linux/tracepoint.h>
5#include <net/mac80211.h>
6#include "ieee80211_i.h"
7
8#if !defined(CONFIG_MAC80211_DRIVER_API_TRACER) || defined(__CHECKER__)
9#undef TRACE_EVENT
10#define TRACE_EVENT(name, proto, ...) \
11static inline void trace_ ## name(proto) {}
12#endif
13
14#undef TRACE_SYSTEM
15#define TRACE_SYSTEM mac80211
16
17#define MAXNAME 32
18#define LOCAL_ENTRY __array(char, wiphy_name, 32)
19#define LOCAL_ASSIGN strlcpy(__entry->wiphy_name, wiphy_name(local->hw.wiphy), MAXNAME)
20#define LOCAL_PR_FMT "%s"
21#define LOCAL_PR_ARG __entry->wiphy_name
22
23#define STA_ENTRY __array(char, sta_addr, ETH_ALEN)
24#define STA_ASSIGN (sta ? memcpy(__entry->sta_addr, sta->addr, ETH_ALEN) : memset(__entry->sta_addr, 0, ETH_ALEN))
25#define STA_PR_FMT " sta:%pM"
26#define STA_PR_ARG __entry->sta_addr
27
28#define VIF_ENTRY __field(enum nl80211_iftype, vif_type) __field(void *, vif)
29#define VIF_ASSIGN __entry->vif_type = vif ? vif->type : 0; __entry->vif = vif
30#define VIF_PR_FMT " vif:%p(%d)"
31#define VIF_PR_ARG __entry->vif, __entry->vif_type
32
33TRACE_EVENT(drv_start,
34 TP_PROTO(struct ieee80211_local *local, int ret),
35
36 TP_ARGS(local, ret),
37
38 TP_STRUCT__entry(
39 LOCAL_ENTRY
40 __field(int, ret)
41 ),
42
43 TP_fast_assign(
44 LOCAL_ASSIGN;
45 __entry->ret = ret;
46 ),
47
48 TP_printk(
49 LOCAL_PR_FMT, LOCAL_PR_ARG
50 )
51);
52
53TRACE_EVENT(drv_stop,
54 TP_PROTO(struct ieee80211_local *local),
55
56 TP_ARGS(local),
57
58 TP_STRUCT__entry(
59 LOCAL_ENTRY
60 ),
61
62 TP_fast_assign(
63 LOCAL_ASSIGN;
64 ),
65
66 TP_printk(
67 LOCAL_PR_FMT, LOCAL_PR_ARG
68 )
69);
70
71TRACE_EVENT(drv_add_interface,
72 TP_PROTO(struct ieee80211_local *local,
73 const u8 *addr,
74 struct ieee80211_vif *vif,
75 int ret),
76
77 TP_ARGS(local, addr, vif, ret),
78
79 TP_STRUCT__entry(
80 LOCAL_ENTRY
81 VIF_ENTRY
82 __array(char, addr, 6)
83 __field(int, ret)
84 ),
85
86 TP_fast_assign(
87 LOCAL_ASSIGN;
88 VIF_ASSIGN;
89 memcpy(__entry->addr, addr, 6);
90 __entry->ret = ret;
91 ),
92
93 TP_printk(
94 LOCAL_PR_FMT VIF_PR_FMT " addr:%pM ret:%d",
95 LOCAL_PR_ARG, VIF_PR_ARG, __entry->addr, __entry->ret
96 )
97);
98
99TRACE_EVENT(drv_remove_interface,
100 TP_PROTO(struct ieee80211_local *local,
101 const u8 *addr, struct ieee80211_vif *vif),
102
103 TP_ARGS(local, addr, vif),
104
105 TP_STRUCT__entry(
106 LOCAL_ENTRY
107 VIF_ENTRY
108 __array(char, addr, 6)
109 ),
110
111 TP_fast_assign(
112 LOCAL_ASSIGN;
113 VIF_ASSIGN;
114 memcpy(__entry->addr, addr, 6);
115 ),
116
117 TP_printk(
118 LOCAL_PR_FMT VIF_PR_FMT " addr:%pM",
119 LOCAL_PR_ARG, VIF_PR_ARG, __entry->addr
120 )
121);
122
123TRACE_EVENT(drv_config,
124 TP_PROTO(struct ieee80211_local *local,
125 u32 changed,
126 int ret),
127
128 TP_ARGS(local, changed, ret),
129
130 TP_STRUCT__entry(
131 LOCAL_ENTRY
132 __field(u32, changed)
133 __field(int, ret)
134 ),
135
136 TP_fast_assign(
137 LOCAL_ASSIGN;
138 __entry->changed = changed;
139 __entry->ret = ret;
140 ),
141
142 TP_printk(
143 LOCAL_PR_FMT " ch:%#x ret:%d",
144 LOCAL_PR_ARG, __entry->changed, __entry->ret
145 )
146);
147
148TRACE_EVENT(drv_bss_info_changed,
149 TP_PROTO(struct ieee80211_local *local,
150 struct ieee80211_vif *vif,
151 struct ieee80211_bss_conf *info,
152 u32 changed),
153
154 TP_ARGS(local, vif, info, changed),
155
156 TP_STRUCT__entry(
157 LOCAL_ENTRY
158 VIF_ENTRY
159 __field(bool, assoc)
160 __field(u16, aid)
161 __field(bool, cts)
162 __field(bool, shortpre)
163 __field(bool, shortslot)
164 __field(u8, dtimper)
165 __field(u16, bcnint)
166 __field(u16, assoc_cap)
167 __field(u64, timestamp)
168 __field(u32, basic_rates)
169 __field(u32, changed)
170 ),
171
172 TP_fast_assign(
173 LOCAL_ASSIGN;
174 VIF_ASSIGN;
175 __entry->changed = changed;
176 __entry->aid = info->aid;
177 __entry->assoc = info->assoc;
178 __entry->shortpre = info->use_short_preamble;
179 __entry->cts = info->use_cts_prot;
180 __entry->shortslot = info->use_short_slot;
181 __entry->dtimper = info->dtim_period;
182 __entry->bcnint = info->beacon_int;
183 __entry->assoc_cap = info->assoc_capability;
184 __entry->timestamp = info->timestamp;
185 __entry->basic_rates = info->basic_rates;
186 ),
187
188 TP_printk(
189 LOCAL_PR_FMT VIF_PR_FMT " changed:%#x",
190 LOCAL_PR_ARG, VIF_PR_ARG, __entry->changed
191 )
192);
193
194TRACE_EVENT(drv_configure_filter,
195 TP_PROTO(struct ieee80211_local *local,
196 unsigned int changed_flags,
197 unsigned int *total_flags,
198 int mc_count),
199
200 TP_ARGS(local, changed_flags, total_flags, mc_count),
201
202 TP_STRUCT__entry(
203 LOCAL_ENTRY
204 __field(unsigned int, changed)
205 __field(unsigned int, total)
206 __field(int, mc)
207 ),
208
209 TP_fast_assign(
210 LOCAL_ASSIGN;
211 __entry->changed = changed_flags;
212 __entry->total = *total_flags;
213 __entry->mc = mc_count;
214 ),
215
216 TP_printk(
217 LOCAL_PR_FMT " changed:%#x total:%#x mc:%d",
218 LOCAL_PR_ARG, __entry->changed, __entry->total, __entry->mc
219 )
220);
221
222TRACE_EVENT(drv_set_tim,
223 TP_PROTO(struct ieee80211_local *local,
224 struct ieee80211_sta *sta, bool set, int ret),
225
226 TP_ARGS(local, sta, set, ret),
227
228 TP_STRUCT__entry(
229 LOCAL_ENTRY
230 STA_ENTRY
231 __field(bool, set)
232 __field(int, ret)
233 ),
234
235 TP_fast_assign(
236 LOCAL_ASSIGN;
237 STA_ASSIGN;
238 __entry->set = set;
239 __entry->ret = ret;
240 ),
241
242 TP_printk(
243 LOCAL_PR_FMT STA_PR_FMT " set:%d ret:%d",
244 LOCAL_PR_ARG, STA_PR_FMT, __entry->set, __entry->ret
245 )
246);
247
248TRACE_EVENT(drv_set_key,
249 TP_PROTO(struct ieee80211_local *local,
250 enum set_key_cmd cmd, struct ieee80211_vif *vif,
251 struct ieee80211_sta *sta,
252 struct ieee80211_key_conf *key, int ret),
253
254 TP_ARGS(local, cmd, vif, sta, key, ret),
255
256 TP_STRUCT__entry(
257 LOCAL_ENTRY
258 VIF_ENTRY
259 STA_ENTRY
260 __field(enum ieee80211_key_alg, alg)
261 __field(u8, hw_key_idx)
262 __field(u8, flags)
263 __field(s8, keyidx)
264 __field(int, ret)
265 ),
266
267 TP_fast_assign(
268 LOCAL_ASSIGN;
269 VIF_ASSIGN;
270 STA_ASSIGN;
271 __entry->alg = key->alg;
272 __entry->flags = key->flags;
273 __entry->keyidx = key->keyidx;
274 __entry->hw_key_idx = key->hw_key_idx;
275 __entry->ret = ret;
276 ),
277
278 TP_printk(
279 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " ret:%d",
280 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->ret
281 )
282);
283
284TRACE_EVENT(drv_update_tkip_key,
285 TP_PROTO(struct ieee80211_local *local,
286 struct ieee80211_key_conf *conf,
287 const u8 *address, u32 iv32),
288
289 TP_ARGS(local, conf, address, iv32),
290
291 TP_STRUCT__entry(
292 LOCAL_ENTRY
293 __array(u8, addr, 6)
294 __field(u32, iv32)
295 ),
296
297 TP_fast_assign(
298 LOCAL_ASSIGN;
299 memcpy(__entry->addr, address, 6);
300 __entry->iv32 = iv32;
301 ),
302
303 TP_printk(
304 LOCAL_PR_FMT " addr:%pM iv32:%#x",
305 LOCAL_PR_ARG, __entry->addr, __entry->iv32
306 )
307);
308
309TRACE_EVENT(drv_hw_scan,
310 TP_PROTO(struct ieee80211_local *local,
311 struct cfg80211_scan_request *req, int ret),
312
313 TP_ARGS(local, req, ret),
314
315 TP_STRUCT__entry(
316 LOCAL_ENTRY
317 __field(int, ret)
318 ),
319
320 TP_fast_assign(
321 LOCAL_ASSIGN;
322 __entry->ret = ret;
323 ),
324
325 TP_printk(
326 LOCAL_PR_FMT " ret:%d",
327 LOCAL_PR_ARG, __entry->ret
328 )
329);
330
331TRACE_EVENT(drv_sw_scan_start,
332 TP_PROTO(struct ieee80211_local *local),
333
334 TP_ARGS(local),
335
336 TP_STRUCT__entry(
337 LOCAL_ENTRY
338 ),
339
340 TP_fast_assign(
341 LOCAL_ASSIGN;
342 ),
343
344 TP_printk(
345 LOCAL_PR_FMT, LOCAL_PR_ARG
346 )
347);
348
349TRACE_EVENT(drv_sw_scan_complete,
350 TP_PROTO(struct ieee80211_local *local),
351
352 TP_ARGS(local),
353
354 TP_STRUCT__entry(
355 LOCAL_ENTRY
356 ),
357
358 TP_fast_assign(
359 LOCAL_ASSIGN;
360 ),
361
362 TP_printk(
363 LOCAL_PR_FMT, LOCAL_PR_ARG
364 )
365);
366
367TRACE_EVENT(drv_get_stats,
368 TP_PROTO(struct ieee80211_local *local,
369 struct ieee80211_low_level_stats *stats,
370 int ret),
371
372 TP_ARGS(local, stats, ret),
373
374 TP_STRUCT__entry(
375 LOCAL_ENTRY
376 __field(int, ret)
377 __field(unsigned int, ackfail)
378 __field(unsigned int, rtsfail)
379 __field(unsigned int, fcserr)
380 __field(unsigned int, rtssucc)
381 ),
382
383 TP_fast_assign(
384 LOCAL_ASSIGN;
385 __entry->ret = ret;
386 __entry->ackfail = stats->dot11ACKFailureCount;
387 __entry->rtsfail = stats->dot11RTSFailureCount;
388 __entry->fcserr = stats->dot11FCSErrorCount;
389 __entry->rtssucc = stats->dot11RTSSuccessCount;
390 ),
391
392 TP_printk(
393 LOCAL_PR_FMT " ret:%d",
394 LOCAL_PR_ARG, __entry->ret
395 )
396);
397
398TRACE_EVENT(drv_get_tkip_seq,
399 TP_PROTO(struct ieee80211_local *local,
400 u8 hw_key_idx, u32 *iv32, u16 *iv16),
401
402 TP_ARGS(local, hw_key_idx, iv32, iv16),
403
404 TP_STRUCT__entry(
405 LOCAL_ENTRY
406 __field(u8, hw_key_idx)
407 __field(u32, iv32)
408 __field(u16, iv16)
409 ),
410
411 TP_fast_assign(
412 LOCAL_ASSIGN;
413 __entry->hw_key_idx = hw_key_idx;
414 __entry->iv32 = *iv32;
415 __entry->iv16 = *iv16;
416 ),
417
418 TP_printk(
419 LOCAL_PR_FMT, LOCAL_PR_ARG
420 )
421);
422
423TRACE_EVENT(drv_set_rts_threshold,
424 TP_PROTO(struct ieee80211_local *local, u32 value, int ret),
425
426 TP_ARGS(local, value, ret),
427
428 TP_STRUCT__entry(
429 LOCAL_ENTRY
430 __field(u32, value)
431 __field(int, ret)
432 ),
433
434 TP_fast_assign(
435 LOCAL_ASSIGN;
436 __entry->ret = ret;
437 __entry->value = value;
438 ),
439
440 TP_printk(
441 LOCAL_PR_FMT " value:%d ret:%d",
442 LOCAL_PR_ARG, __entry->value, __entry->ret
443 )
444);
445
446TRACE_EVENT(drv_sta_notify,
447 TP_PROTO(struct ieee80211_local *local,
448 struct ieee80211_vif *vif,
449 enum sta_notify_cmd cmd,
450 struct ieee80211_sta *sta),
451
452 TP_ARGS(local, vif, cmd, sta),
453
454 TP_STRUCT__entry(
455 LOCAL_ENTRY
456 VIF_ENTRY
457 STA_ENTRY
458 __field(u32, cmd)
459 ),
460
461 TP_fast_assign(
462 LOCAL_ASSIGN;
463 VIF_ASSIGN;
464 STA_ASSIGN;
465 __entry->cmd = cmd;
466 ),
467
468 TP_printk(
469 LOCAL_PR_FMT VIF_PR_FMT STA_PR_FMT " cmd:%d",
470 LOCAL_PR_ARG, VIF_PR_ARG, STA_PR_ARG, __entry->cmd
471 )
472);
473
474TRACE_EVENT(drv_conf_tx,
475 TP_PROTO(struct ieee80211_local *local, u16 queue,
476 const struct ieee80211_tx_queue_params *params,
477 int ret),
478
479 TP_ARGS(local, queue, params, ret),
480
481 TP_STRUCT__entry(
482 LOCAL_ENTRY
483 __field(u16, queue)
484 __field(u16, txop)
485 __field(u16, cw_min)
486 __field(u16, cw_max)
487 __field(u8, aifs)
488 __field(int, ret)
489 ),
490
491 TP_fast_assign(
492 LOCAL_ASSIGN;
493 __entry->queue = queue;
494 __entry->ret = ret;
495 __entry->txop = params->txop;
496 __entry->cw_max = params->cw_max;
497 __entry->cw_min = params->cw_min;
498 __entry->aifs = params->aifs;
499 ),
500
501 TP_printk(
502 LOCAL_PR_FMT " queue:%d ret:%d",
503 LOCAL_PR_ARG, __entry->queue, __entry->ret
504 )
505);
506
507TRACE_EVENT(drv_get_tx_stats,
508 TP_PROTO(struct ieee80211_local *local,
509 struct ieee80211_tx_queue_stats *stats,
510 int ret),
511
512 TP_ARGS(local, stats, ret),
513
514 TP_STRUCT__entry(
515 LOCAL_ENTRY
516 __field(int, ret)
517 ),
518
519 TP_fast_assign(
520 LOCAL_ASSIGN;
521 __entry->ret = ret;
522 ),
523
524 TP_printk(
525 LOCAL_PR_FMT " ret:%d",
526 LOCAL_PR_ARG, __entry->ret
527 )
528);
529
530TRACE_EVENT(drv_get_tsf,
531 TP_PROTO(struct ieee80211_local *local, u64 ret),
532
533 TP_ARGS(local, ret),
534
535 TP_STRUCT__entry(
536 LOCAL_ENTRY
537 __field(u64, ret)
538 ),
539
540 TP_fast_assign(
541 LOCAL_ASSIGN;
542 __entry->ret = ret;
543 ),
544
545 TP_printk(
546 LOCAL_PR_FMT " ret:%llu",
547 LOCAL_PR_ARG, (unsigned long long)__entry->ret
548 )
549);
550
551TRACE_EVENT(drv_set_tsf,
552 TP_PROTO(struct ieee80211_local *local, u64 tsf),
553
554 TP_ARGS(local, tsf),
555
556 TP_STRUCT__entry(
557 LOCAL_ENTRY
558 __field(u64, tsf)
559 ),
560
561 TP_fast_assign(
562 LOCAL_ASSIGN;
563 __entry->tsf = tsf;
564 ),
565
566 TP_printk(
567 LOCAL_PR_FMT " tsf:%llu",
568 LOCAL_PR_ARG, (unsigned long long)__entry->tsf
569 )
570);
571
572TRACE_EVENT(drv_reset_tsf,
573 TP_PROTO(struct ieee80211_local *local),
574
575 TP_ARGS(local),
576
577 TP_STRUCT__entry(
578 LOCAL_ENTRY
579 ),
580
581 TP_fast_assign(
582 LOCAL_ASSIGN;
583 ),
584
585 TP_printk(
586 LOCAL_PR_FMT, LOCAL_PR_ARG
587 )
588);
589
590TRACE_EVENT(drv_tx_last_beacon,
591 TP_PROTO(struct ieee80211_local *local, int ret),
592
593 TP_ARGS(local, ret),
594
595 TP_STRUCT__entry(
596 LOCAL_ENTRY
597 __field(int, ret)
598 ),
599
600 TP_fast_assign(
601 LOCAL_ASSIGN;
602 __entry->ret = ret;
603 ),
604
605 TP_printk(
606 LOCAL_PR_FMT " ret:%d",
607 LOCAL_PR_ARG, __entry->ret
608 )
609);
610
611TRACE_EVENT(drv_ampdu_action,
612 TP_PROTO(struct ieee80211_local *local,
613 enum ieee80211_ampdu_mlme_action action,
614 struct ieee80211_sta *sta, u16 tid,
615 u16 *ssn, int ret),
616
617 TP_ARGS(local, action, sta, tid, ssn, ret),
618
619 TP_STRUCT__entry(
620 LOCAL_ENTRY
621 STA_ENTRY
622 __field(u32, action)
623 __field(u16, tid)
624 __field(u16, ssn)
625 __field(int, ret)
626 ),
627
628 TP_fast_assign(
629 LOCAL_ASSIGN;
630 STA_ASSIGN;
631 __entry->ret = ret;
632 __entry->action = action;
633 __entry->tid = tid;
634 __entry->ssn = *ssn;
635 ),
636
637 TP_printk(
638 LOCAL_PR_FMT STA_PR_FMT " action:%d tid:%d ret:%d",
639 LOCAL_PR_ARG, STA_PR_ARG, __entry->action, __entry->tid, __entry->ret
640 )
641);
642#endif /* !__MAC80211_DRIVER_TRACE || TRACE_HEADER_MULTI_READ */
643
644#undef TRACE_INCLUDE_PATH
645#define TRACE_INCLUDE_PATH .
646#undef TRACE_INCLUDE_FILE
647#define TRACE_INCLUDE_FILE driver-trace
648#include <trace/define_trace.h>
diff --git a/net/mac80211/event.c b/net/mac80211/event.c
index f288d01a6344..01ae759518f6 100644
--- a/net/mac80211/event.c
+++ b/net/mac80211/event.c
@@ -7,8 +7,7 @@
7 * 7 *
8 * mac80211 - events 8 * mac80211 - events
9 */ 9 */
10 10#include <net/cfg80211.h>
11#include <net/iw_handler.h>
12#include "ieee80211_i.h" 11#include "ieee80211_i.h"
13 12
14/* 13/*
@@ -17,26 +16,12 @@
17 * driver or is still in the frame), it should provide that information. 16 * driver or is still in the frame), it should provide that information.
18 */ 17 */
19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 18void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
20 struct ieee80211_hdr *hdr, const u8 *tsc) 19 struct ieee80211_hdr *hdr, const u8 *tsc,
20 gfp_t gfp)
21{ 21{
22 union iwreq_data wrqu;
23 char *buf = kmalloc(128, GFP_ATOMIC);
24
25 if (buf) {
26 /* TODO: needed parameters: count, key type, TSC */
27 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
28 "keyid=%d %scast addr=%pM)",
29 keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
30 hdr->addr2);
31 memset(&wrqu, 0, sizeof(wrqu));
32 wrqu.data.length = strlen(buf);
33 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
34 kfree(buf);
35 }
36
37 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2, 22 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2,
38 (hdr->addr1[0] & 0x01) ? 23 (hdr->addr1[0] & 0x01) ?
39 NL80211_KEYTYPE_GROUP : 24 NL80211_KEYTYPE_GROUP :
40 NL80211_KEYTYPE_PAIRWISE, 25 NL80211_KEYTYPE_PAIRWISE,
41 keyidx, tsc); 26 keyidx, tsc, gfp);
42} 27}
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 0b30277eb366..920ec8792f4b 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -57,7 +57,7 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
57 */ 57 */
58 if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) 58 if (auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1)
59 ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0, 59 ieee80211_send_auth(sdata, 2, WLAN_AUTH_OPEN, NULL, 0,
60 sdata->u.ibss.bssid, 0); 60 sdata->u.ibss.bssid, NULL, 0, 0);
61} 61}
62 62
63static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 63static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
@@ -494,7 +494,7 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
494 494
495 capability = WLAN_CAPABILITY_IBSS; 495 capability = WLAN_CAPABILITY_IBSS;
496 496
497 if (sdata->default_key) 497 if (ifibss->privacy)
498 capability |= WLAN_CAPABILITY_PRIVACY; 498 capability |= WLAN_CAPABILITY_PRIVACY;
499 else 499 else
500 sdata->drop_unencrypted = 0; 500 sdata->drop_unencrypted = 0;
@@ -524,9 +524,8 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
524 return; 524 return;
525 525
526 capability = WLAN_CAPABILITY_IBSS; 526 capability = WLAN_CAPABILITY_IBSS;
527 if (sdata->default_key) 527 if (ifibss->privacy)
528 capability |= WLAN_CAPABILITY_PRIVACY; 528 capability |= WLAN_CAPABILITY_PRIVACY;
529
530 if (ifibss->fixed_bssid) 529 if (ifibss->fixed_bssid)
531 bssid = ifibss->bssid; 530 bssid = ifibss->bssid;
532 if (ifibss->fixed_channel) 531 if (ifibss->fixed_channel)
@@ -705,7 +704,7 @@ static void ieee80211_ibss_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
705 struct ieee80211_mgmt *mgmt; 704 struct ieee80211_mgmt *mgmt;
706 u16 fc; 705 u16 fc;
707 706
708 rx_status = (struct ieee80211_rx_status *) skb->cb; 707 rx_status = IEEE80211_SKB_RXCB(skb);
709 mgmt = (struct ieee80211_mgmt *) skb->data; 708 mgmt = (struct ieee80211_mgmt *) skb->data;
710 fc = le16_to_cpu(mgmt->frame_control); 709 fc = le16_to_cpu(mgmt->frame_control);
711 710
@@ -743,7 +742,7 @@ static void ieee80211_ibss_work(struct work_struct *work)
743 if (!netif_running(sdata->dev)) 742 if (!netif_running(sdata->dev))
744 return; 743 return;
745 744
746 if (local->sw_scanning || local->hw_scanning) 745 if (local->scanning)
747 return; 746 return;
748 747
749 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_ADHOC)) 748 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_ADHOC))
@@ -782,7 +781,7 @@ static void ieee80211_ibss_timer(unsigned long data)
782 } 781 }
783 782
784 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request); 783 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request);
785 queue_work(local->hw.workqueue, &ifibss->work); 784 ieee80211_queue_work(&local->hw, &ifibss->work);
786} 785}
787 786
788#ifdef CONFIG_PM 787#ifdef CONFIG_PM
@@ -836,8 +835,7 @@ void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
836} 835}
837 836
838ieee80211_rx_result 837ieee80211_rx_result
839ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 838ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
840 struct ieee80211_rx_status *rx_status)
841{ 839{
842 struct ieee80211_local *local = sdata->local; 840 struct ieee80211_local *local = sdata->local;
843 struct ieee80211_mgmt *mgmt; 841 struct ieee80211_mgmt *mgmt;
@@ -852,11 +850,10 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
852 switch (fc & IEEE80211_FCTL_STYPE) { 850 switch (fc & IEEE80211_FCTL_STYPE) {
853 case IEEE80211_STYPE_PROBE_RESP: 851 case IEEE80211_STYPE_PROBE_RESP:
854 case IEEE80211_STYPE_BEACON: 852 case IEEE80211_STYPE_BEACON:
855 memcpy(skb->cb, rx_status, sizeof(*rx_status));
856 case IEEE80211_STYPE_PROBE_REQ: 853 case IEEE80211_STYPE_PROBE_REQ:
857 case IEEE80211_STYPE_AUTH: 854 case IEEE80211_STYPE_AUTH:
858 skb_queue_tail(&sdata->u.ibss.skb_queue, skb); 855 skb_queue_tail(&sdata->u.ibss.skb_queue, skb);
859 queue_work(local->hw.workqueue, &sdata->u.ibss.work); 856 ieee80211_queue_work(&local->hw, &sdata->u.ibss.work);
860 return RX_QUEUED; 857 return RX_QUEUED;
861 } 858 }
862 859
@@ -874,6 +871,8 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
874 } else 871 } else
875 sdata->u.ibss.fixed_bssid = false; 872 sdata->u.ibss.fixed_bssid = false;
876 873
874 sdata->u.ibss.privacy = params->privacy;
875
877 sdata->vif.bss_conf.beacon_int = params->beacon_interval; 876 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
878 877
879 sdata->u.ibss.channel = params->channel; 878 sdata->u.ibss.channel = params->channel;
@@ -913,7 +912,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
913 ieee80211_recalc_idle(sdata->local); 912 ieee80211_recalc_idle(sdata->local);
914 913
915 set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request); 914 set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
916 queue_work(sdata->local->hw.workqueue, &sdata->u.ibss.work); 915 ieee80211_queue_work(&sdata->local->hw, &sdata->u.ibss.work);
917 916
918 return 0; 917 return 0;
919} 918}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 68eb5052179a..630a438180fd 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -24,7 +24,6 @@
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <net/cfg80211.h> 26#include <net/cfg80211.h>
27#include <net/iw_handler.h>
28#include <net/mac80211.h> 27#include <net/mac80211.h>
29#include "key.h" 28#include "key.h"
30#include "sta_info.h" 29#include "sta_info.h"
@@ -227,86 +226,80 @@ struct mesh_preq_queue {
227 u8 flags; 226 u8 flags;
228}; 227};
229 228
229enum ieee80211_mgd_state {
230 IEEE80211_MGD_STATE_IDLE,
231 IEEE80211_MGD_STATE_PROBE,
232 IEEE80211_MGD_STATE_AUTH,
233 IEEE80211_MGD_STATE_ASSOC,
234};
235
236struct ieee80211_mgd_work {
237 struct list_head list;
238 struct ieee80211_bss *bss;
239 int ie_len;
240 u8 prev_bssid[ETH_ALEN];
241 u8 ssid[IEEE80211_MAX_SSID_LEN];
242 u8 ssid_len;
243 unsigned long timeout;
244 enum ieee80211_mgd_state state;
245 u16 auth_alg, auth_transaction;
246
247 int tries;
248
249 u8 key[WLAN_KEY_LEN_WEP104];
250 u8 key_len, key_idx;
251
252 /* must be last */
253 u8 ie[0]; /* for auth or assoc frame, not probe */
254};
255
230/* flags used in struct ieee80211_if_managed.flags */ 256/* flags used in struct ieee80211_if_managed.flags */
231#define IEEE80211_STA_SSID_SET BIT(0) 257enum ieee80211_sta_flags {
232#define IEEE80211_STA_BSSID_SET BIT(1) 258 IEEE80211_STA_BEACON_POLL = BIT(0),
233#define IEEE80211_STA_PREV_BSSID_SET BIT(2) 259 IEEE80211_STA_CONNECTION_POLL = BIT(1),
234#define IEEE80211_STA_AUTHENTICATED BIT(3) 260 IEEE80211_STA_CONTROL_PORT = BIT(2),
235#define IEEE80211_STA_ASSOCIATED BIT(4) 261 IEEE80211_STA_WMM_ENABLED = BIT(3),
236#define IEEE80211_STA_PROBEREQ_POLL BIT(5) 262 IEEE80211_STA_DISABLE_11N = BIT(4),
237#define IEEE80211_STA_CREATE_IBSS BIT(6) 263 IEEE80211_STA_CSA_RECEIVED = BIT(5),
238#define IEEE80211_STA_CONTROL_PORT BIT(7) 264 IEEE80211_STA_MFP_ENABLED = BIT(6),
239#define IEEE80211_STA_WMM_ENABLED BIT(8) 265};
240/* hole at 9, please re-use */
241#define IEEE80211_STA_AUTO_SSID_SEL BIT(10)
242#define IEEE80211_STA_AUTO_BSSID_SEL BIT(11)
243#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12)
244#define IEEE80211_STA_PRIVACY_INVOKED BIT(13)
245#define IEEE80211_STA_TKIP_WEP_USED BIT(14)
246#define IEEE80211_STA_CSA_RECEIVED BIT(15)
247#define IEEE80211_STA_MFP_ENABLED BIT(16)
248#define IEEE80211_STA_EXT_SME BIT(17)
249/* flags for MLME request */
250#define IEEE80211_STA_REQ_SCAN 0
251#define IEEE80211_STA_REQ_AUTH 1
252#define IEEE80211_STA_REQ_RUN 2
253 266
254/* bitfield of allowed auth algs */ 267/* flags for MLME request */
255#define IEEE80211_AUTH_ALG_OPEN BIT(0) 268enum ieee80211_sta_request {
256#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1) 269 IEEE80211_STA_REQ_SCAN,
257#define IEEE80211_AUTH_ALG_LEAP BIT(2) 270};
258#define IEEE80211_AUTH_ALG_FT BIT(3)
259 271
260struct ieee80211_if_managed { 272struct ieee80211_if_managed {
261 struct timer_list timer; 273 struct timer_list timer;
274 struct timer_list conn_mon_timer;
275 struct timer_list bcn_mon_timer;
262 struct timer_list chswitch_timer; 276 struct timer_list chswitch_timer;
263 struct work_struct work; 277 struct work_struct work;
278 struct work_struct monitor_work;
264 struct work_struct chswitch_work; 279 struct work_struct chswitch_work;
265 struct work_struct beacon_loss_work; 280 struct work_struct beacon_loss_work;
266 281
267 u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN]; 282 unsigned long probe_timeout;
283 int probe_send_count;
268 284
269 u8 ssid[IEEE80211_MAX_SSID_LEN]; 285 struct mutex mtx;
270 size_t ssid_len; 286 struct ieee80211_bss *associated;
287 struct list_head work_list;
271 288
272 enum { 289 u8 bssid[ETH_ALEN];
273 IEEE80211_STA_MLME_DISABLED,
274 IEEE80211_STA_MLME_DIRECT_PROBE,
275 IEEE80211_STA_MLME_AUTHENTICATE,
276 IEEE80211_STA_MLME_ASSOCIATE,
277 IEEE80211_STA_MLME_ASSOCIATED,
278 } state;
279 290
280 u16 aid; 291 u16 aid;
281 u16 ap_capab, capab; 292 u16 capab;
282 u8 *extra_ie; /* to be added to the end of AssocReq */
283 size_t extra_ie_len;
284
285 /* The last AssocReq/Resp IEs */
286 u8 *assocreq_ies, *assocresp_ies;
287 size_t assocreq_ies_len, assocresp_ies_len;
288 293
289 struct sk_buff_head skb_queue; 294 struct sk_buff_head skb_queue;
290 295
291 int assoc_scan_tries; /* number of scans done pre-association */
292 int direct_probe_tries; /* retries for direct probes */
293 int auth_tries; /* retries for auth req */
294 int assoc_tries; /* retries for assoc req */
295
296 unsigned long timers_running; /* used for quiesce/restart */ 296 unsigned long timers_running; /* used for quiesce/restart */
297 bool powersave; /* powersave requested for this iface */ 297 bool powersave; /* powersave requested for this iface */
298 298
299 unsigned long request; 299 unsigned long request;
300 300
301 unsigned long last_probe;
302 unsigned long last_beacon;
303
304 unsigned int flags; 301 unsigned int flags;
305 302
306 unsigned int auth_algs; /* bitfield of allowed auth algs */
307 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
308 int auth_transaction;
309
310 u32 beacon_crc; 303 u32 beacon_crc;
311 304
312 enum { 305 enum {
@@ -316,10 +309,6 @@ struct ieee80211_if_managed {
316 } mfp; /* management frame protection */ 309 } mfp; /* management frame protection */
317 310
318 int wmm_last_param_set; 311 int wmm_last_param_set;
319
320 /* Extra IE data for management frames */
321 u8 *sme_auth_ie;
322 size_t sme_auth_ie_len;
323}; 312};
324 313
325enum ieee80211_ibss_request { 314enum ieee80211_ibss_request {
@@ -339,6 +328,7 @@ struct ieee80211_if_ibss {
339 328
340 bool fixed_bssid; 329 bool fixed_bssid;
341 bool fixed_channel; 330 bool fixed_channel;
331 bool privacy;
342 332
343 u8 bssid[ETH_ALEN]; 333 u8 bssid[ETH_ALEN];
344 u8 ssid[IEEE80211_MAX_SSID_LEN]; 334 u8 ssid[IEEE80211_MAX_SSID_LEN];
@@ -478,20 +468,9 @@ struct ieee80211_sub_if_data {
478 union { 468 union {
479 struct { 469 struct {
480 struct dentry *drop_unencrypted; 470 struct dentry *drop_unencrypted;
481 struct dentry *state;
482 struct dentry *bssid; 471 struct dentry *bssid;
483 struct dentry *prev_bssid;
484 struct dentry *ssid_len;
485 struct dentry *aid; 472 struct dentry *aid;
486 struct dentry *ap_capab;
487 struct dentry *capab; 473 struct dentry *capab;
488 struct dentry *extra_ie_len;
489 struct dentry *auth_tries;
490 struct dentry *assoc_tries;
491 struct dentry *auth_algs;
492 struct dentry *auth_alg;
493 struct dentry *auth_transaction;
494 struct dentry *flags;
495 struct dentry *force_unicast_rateidx; 474 struct dentry *force_unicast_rateidx;
496 struct dentry *max_ratectrl_rateidx; 475 struct dentry *max_ratectrl_rateidx;
497 } sta; 476 } sta;
@@ -588,12 +567,44 @@ enum queue_stop_reason {
588 IEEE80211_QUEUE_STOP_REASON_CSA, 567 IEEE80211_QUEUE_STOP_REASON_CSA,
589 IEEE80211_QUEUE_STOP_REASON_AGGREGATION, 568 IEEE80211_QUEUE_STOP_REASON_AGGREGATION,
590 IEEE80211_QUEUE_STOP_REASON_SUSPEND, 569 IEEE80211_QUEUE_STOP_REASON_SUSPEND,
591 IEEE80211_QUEUE_STOP_REASON_PENDING,
592 IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 570 IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
593}; 571};
594 572
595struct ieee80211_master_priv { 573/**
596 struct ieee80211_local *local; 574 * mac80211 scan flags - currently active scan mode
575 *
576 * @SCAN_SW_SCANNING: We're currently in the process of scanning but may as
577 * well be on the operating channel
578 * @SCAN_HW_SCANNING: The hardware is scanning for us, we have no way to
579 * determine if we are on the operating channel or not
580 * @SCAN_OFF_CHANNEL: We're off our operating channel for scanning,
581 * gets only set in conjunction with SCAN_SW_SCANNING
582 */
583enum {
584 SCAN_SW_SCANNING,
585 SCAN_HW_SCANNING,
586 SCAN_OFF_CHANNEL,
587};
588
589/**
590 * enum mac80211_scan_state - scan state machine states
591 *
592 * @SCAN_DECISION: Main entry point to the scan state machine, this state
593 * determines if we should keep on scanning or switch back to the
594 * operating channel
595 * @SCAN_SET_CHANNEL: Set the next channel to be scanned
596 * @SCAN_SEND_PROBE: Send probe requests and wait for probe responses
597 * @SCAN_LEAVE_OPER_CHANNEL: Leave the operating channel, notify the AP
598 * about us leaving the channel and stop all associated STA interfaces
599 * @SCAN_ENTER_OPER_CHANNEL: Enter the operating channel again, notify the
600 * AP about us being back and restart all associated STA interfaces
601 */
602enum mac80211_scan_state {
603 SCAN_DECISION,
604 SCAN_SET_CHANNEL,
605 SCAN_SEND_PROBE,
606 SCAN_LEAVE_OPER_CHANNEL,
607 SCAN_ENTER_OPER_CHANNEL,
597}; 608};
598 609
599struct ieee80211_local { 610struct ieee80211_local {
@@ -604,17 +615,30 @@ struct ieee80211_local {
604 615
605 const struct ieee80211_ops *ops; 616 const struct ieee80211_ops *ops;
606 617
618 /*
619 * private workqueue to mac80211. mac80211 makes this accessible
620 * via ieee80211_queue_work()
621 */
622 struct workqueue_struct *workqueue;
623
607 unsigned long queue_stop_reasons[IEEE80211_MAX_QUEUES]; 624 unsigned long queue_stop_reasons[IEEE80211_MAX_QUEUES];
608 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */ 625 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
609 spinlock_t queue_stop_reason_lock; 626 spinlock_t queue_stop_reason_lock;
610 627
611 struct net_device *mdev; /* wmaster# - "master" 802.11 device */
612 int open_count; 628 int open_count;
613 int monitors, cooked_mntrs; 629 int monitors, cooked_mntrs;
614 /* number of interfaces with corresponding FIF_ flags */ 630 /* number of interfaces with corresponding FIF_ flags */
615 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss; 631 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll;
616 unsigned int filter_flags; /* FIF_* */ 632 unsigned int filter_flags; /* FIF_* */
617 struct iw_statistics wstats; 633 struct iw_statistics wstats;
634
635 /* protects the aggregated multicast list and filter calls */
636 spinlock_t filter_lock;
637
638 /* aggregated multicast list */
639 struct dev_addr_list *mc_list;
640 int mc_count;
641
618 bool tim_in_locked_section; /* see ieee80211_beacon_get() */ 642 bool tim_in_locked_section; /* see ieee80211_beacon_get() */
619 643
620 /* 644 /*
@@ -687,7 +711,7 @@ struct ieee80211_local {
687 711
688 /* Scanning and BSS list */ 712 /* Scanning and BSS list */
689 struct mutex scan_mtx; 713 struct mutex scan_mtx;
690 bool sw_scanning, hw_scanning; 714 unsigned long scanning;
691 struct cfg80211_ssid scan_ssid; 715 struct cfg80211_ssid scan_ssid;
692 struct cfg80211_scan_request int_scan_req; 716 struct cfg80211_scan_request int_scan_req;
693 struct cfg80211_scan_request *scan_req; 717 struct cfg80211_scan_request *scan_req;
@@ -697,7 +721,7 @@ struct ieee80211_local {
697 int scan_channel_idx; 721 int scan_channel_idx;
698 int scan_ies_len; 722 int scan_ies_len;
699 723
700 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 724 enum mac80211_scan_state next_scan_state;
701 struct delayed_work scan_work; 725 struct delayed_work scan_work;
702 struct ieee80211_sub_if_data *scan_sdata; 726 struct ieee80211_sub_if_data *scan_sdata;
703 enum nl80211_channel_type oper_channel_type; 727 enum nl80211_channel_type oper_channel_type;
@@ -834,10 +858,6 @@ struct ieee80211_local {
834static inline struct ieee80211_sub_if_data * 858static inline struct ieee80211_sub_if_data *
835IEEE80211_DEV_TO_SUB_IF(struct net_device *dev) 859IEEE80211_DEV_TO_SUB_IF(struct net_device *dev)
836{ 860{
837 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
838
839 BUG_ON(!local || local->mdev == dev);
840
841 return netdev_priv(dev); 861 return netdev_priv(dev);
842} 862}
843 863
@@ -937,21 +957,20 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
937void ieee80211_configure_filter(struct ieee80211_local *local); 957void ieee80211_configure_filter(struct ieee80211_local *local);
938u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata); 958u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata);
939 959
940/* wireless extensions */
941extern const struct iw_handler_def ieee80211_iw_handler_def;
942
943/* STA code */ 960/* STA code */
944void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata); 961void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata);
962int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
963 struct cfg80211_auth_request *req);
964int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
965 struct cfg80211_assoc_request *req);
966int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
967 struct cfg80211_deauth_request *req,
968 void *cookie);
969int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
970 struct cfg80211_disassoc_request *req,
971 void *cookie);
945ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, 972ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
946 struct sk_buff *skb, 973 struct sk_buff *skb);
947 struct ieee80211_rx_status *rx_status);
948int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata);
949int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len);
950int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len);
951int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
952void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata);
953int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason);
954int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
955void ieee80211_send_pspoll(struct ieee80211_local *local, 974void ieee80211_send_pspoll(struct ieee80211_local *local,
956 struct ieee80211_sub_if_data *sdata); 975 struct ieee80211_sub_if_data *sdata);
957void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency); 976void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency);
@@ -967,8 +986,7 @@ void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata);
967void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 986void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
968void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata); 987void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
969ieee80211_rx_result 988ieee80211_rx_result
970ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 989ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
971 struct ieee80211_rx_status *rx_status);
972struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 990struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
973 u8 *bssid, u8 *addr, u32 supp_rates); 991 u8 *bssid, u8 *addr, u32 supp_rates);
974int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata, 992int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
@@ -983,16 +1001,9 @@ int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
983 const u8 *ssid, u8 ssid_len); 1001 const u8 *ssid, u8 ssid_len);
984int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 1002int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
985 struct cfg80211_scan_request *req); 1003 struct cfg80211_scan_request *req);
986int ieee80211_scan_results(struct ieee80211_local *local,
987 struct iw_request_info *info,
988 char *buf, size_t len);
989void ieee80211_scan_cancel(struct ieee80211_local *local); 1004void ieee80211_scan_cancel(struct ieee80211_local *local);
990ieee80211_rx_result 1005ieee80211_rx_result
991ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, 1006ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
992 struct sk_buff *skb,
993 struct ieee80211_rx_status *rx_status);
994int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata,
995 const char *ie, size_t len);
996 1007
997void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local); 1008void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local);
998struct ieee80211_bss * 1009struct ieee80211_bss *
@@ -1008,8 +1019,6 @@ ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
1008 u8 *ssid, u8 ssid_len); 1019 u8 *ssid, u8 ssid_len);
1009void ieee80211_rx_bss_put(struct ieee80211_local *local, 1020void ieee80211_rx_bss_put(struct ieee80211_local *local,
1010 struct ieee80211_bss *bss); 1021 struct ieee80211_bss *bss);
1011void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
1012 int freq, u8 *ssid, u8 ssid_len);
1013 1022
1014/* interface handling */ 1023/* interface handling */
1015int ieee80211_if_add(struct ieee80211_local *local, const char *name, 1024int ieee80211_if_add(struct ieee80211_local *local, const char *name,
@@ -1025,7 +1034,6 @@ void ieee80211_recalc_idle(struct ieee80211_local *local);
1025/* tx handling */ 1034/* tx handling */
1026void ieee80211_clear_tx_pending(struct ieee80211_local *local); 1035void ieee80211_clear_tx_pending(struct ieee80211_local *local);
1027void ieee80211_tx_pending(unsigned long data); 1036void ieee80211_tx_pending(unsigned long data);
1028int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
1029int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev); 1037int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
1030int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev); 1038int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
1031 1039
@@ -1092,7 +1100,8 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1092int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1100int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
1093 int rate, int erp, int short_preamble); 1101 int rate, int erp, int short_preamble);
1094void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1102void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1095 struct ieee80211_hdr *hdr, const u8 *tsc); 1103 struct ieee80211_hdr *hdr, const u8 *tsc,
1104 gfp_t gfp);
1096void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1105void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1097void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1106void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1098 int encrypt); 1107 int encrypt);
@@ -1129,8 +1138,8 @@ int ieee80211_add_pending_skbs(struct ieee80211_local *local,
1129 1138
1130void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1139void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1131 u16 transaction, u16 auth_alg, 1140 u16 transaction, u16 auth_alg,
1132 u8 *extra, size_t extra_len, 1141 u8 *extra, size_t extra_len, const u8 *bssid,
1133 const u8 *bssid, int encrypt); 1142 const u8 *key, u8 key_len, u8 key_idx);
1134int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 1143int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1135 const u8 *ie, size_t ie_len); 1144 const u8 *ie, size_t ie_len);
1136void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 1145void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b7c8a4484298..e8fb03b91a44 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -190,10 +190,6 @@ static int ieee80211_open(struct net_device *dev)
190 ETH_ALEN); 190 ETH_ALEN);
191 } 191 }
192 192
193 if (compare_ether_addr(null_addr, local->mdev->dev_addr) == 0)
194 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr,
195 ETH_ALEN);
196
197 /* 193 /*
198 * Validate the MAC address for this device. 194 * Validate the MAC address for this device.
199 */ 195 */
@@ -224,18 +220,17 @@ static int ieee80211_open(struct net_device *dev)
224 local->fif_fcsfail++; 220 local->fif_fcsfail++;
225 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) 221 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
226 local->fif_plcpfail++; 222 local->fif_plcpfail++;
227 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) 223 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
228 local->fif_control++; 224 local->fif_control++;
225 local->fif_pspoll++;
226 }
229 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) 227 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
230 local->fif_other_bss++; 228 local->fif_other_bss++;
231 229
232 netif_addr_lock_bh(local->mdev); 230 spin_lock_bh(&local->filter_lock);
233 ieee80211_configure_filter(local); 231 ieee80211_configure_filter(local);
234 netif_addr_unlock_bh(local->mdev); 232 spin_unlock_bh(&local->filter_lock);
235 break; 233 break;
236 case NL80211_IFTYPE_STATION:
237 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
238 /* fall through */
239 default: 234 default:
240 conf.vif = &sdata->vif; 235 conf.vif = &sdata->vif;
241 conf.type = sdata->vif.type; 236 conf.type = sdata->vif.type;
@@ -246,12 +241,19 @@ static int ieee80211_open(struct net_device *dev)
246 241
247 if (ieee80211_vif_is_mesh(&sdata->vif)) { 242 if (ieee80211_vif_is_mesh(&sdata->vif)) {
248 local->fif_other_bss++; 243 local->fif_other_bss++;
249 netif_addr_lock_bh(local->mdev); 244 spin_lock_bh(&local->filter_lock);
250 ieee80211_configure_filter(local); 245 ieee80211_configure_filter(local);
251 netif_addr_unlock_bh(local->mdev); 246 spin_unlock_bh(&local->filter_lock);
252 247
253 ieee80211_start_mesh(sdata); 248 ieee80211_start_mesh(sdata);
249 } else if (sdata->vif.type == NL80211_IFTYPE_AP) {
250 local->fif_pspoll++;
251
252 spin_lock_bh(&local->filter_lock);
253 ieee80211_configure_filter(local);
254 spin_unlock_bh(&local->filter_lock);
254 } 255 }
256
255 changed |= ieee80211_reset_erp_info(sdata); 257 changed |= ieee80211_reset_erp_info(sdata);
256 ieee80211_bss_info_change_notify(sdata, changed); 258 ieee80211_bss_info_change_notify(sdata, changed);
257 ieee80211_enable_keys(sdata); 259 ieee80211_enable_keys(sdata);
@@ -282,10 +284,6 @@ static int ieee80211_open(struct net_device *dev)
282 } 284 }
283 285
284 if (local->open_count == 0) { 286 if (local->open_count == 0) {
285 res = dev_open(local->mdev);
286 WARN_ON(res);
287 if (res)
288 goto err_del_interface;
289 tasklet_enable(&local->tx_pending_tasklet); 287 tasklet_enable(&local->tx_pending_tasklet);
290 tasklet_enable(&local->tasklet); 288 tasklet_enable(&local->tasklet);
291 } 289 }
@@ -323,7 +321,7 @@ static int ieee80211_open(struct net_device *dev)
323 * to fix this. 321 * to fix this.
324 */ 322 */
325 if (sdata->vif.type == NL80211_IFTYPE_STATION) 323 if (sdata->vif.type == NL80211_IFTYPE_STATION)
326 queue_work(local->hw.workqueue, &sdata->u.mgd.work); 324 ieee80211_queue_work(&local->hw, &sdata->u.mgd.work);
327 325
328 netif_tx_start_all_queues(dev); 326 netif_tx_start_all_queues(dev);
329 327
@@ -346,7 +344,10 @@ static int ieee80211_stop(struct net_device *dev)
346 struct ieee80211_local *local = sdata->local; 344 struct ieee80211_local *local = sdata->local;
347 struct ieee80211_if_init_conf conf; 345 struct ieee80211_if_init_conf conf;
348 struct sta_info *sta; 346 struct sta_info *sta;
347 unsigned long flags;
348 struct sk_buff *skb, *tmp;
349 u32 hw_reconf_flags = 0; 349 u32 hw_reconf_flags = 0;
350 int i;
350 351
351 /* 352 /*
352 * Stop TX on this interface first. 353 * Stop TX on this interface first.
@@ -366,18 +367,6 @@ static int ieee80211_stop(struct net_device *dev)
366 rcu_read_unlock(); 367 rcu_read_unlock();
367 368
368 /* 369 /*
369 * Announce that we are leaving the network, in case we are a
370 * station interface type. This must be done before removing
371 * all stations associated with sta_info_flush, otherwise STA
372 * information will be gone and no announce being done.
373 */
374 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
375 if (sdata->u.mgd.state != IEEE80211_STA_MLME_DISABLED)
376 ieee80211_sta_deauthenticate(sdata,
377 WLAN_REASON_DEAUTH_LEAVING);
378 }
379
380 /*
381 * Remove all stations associated with this interface. 370 * Remove all stations associated with this interface.
382 * 371 *
383 * This must be done before calling ops->remove_interface() 372 * This must be done before calling ops->remove_interface()
@@ -408,13 +397,23 @@ static int ieee80211_stop(struct net_device *dev)
408 if (sdata->flags & IEEE80211_SDATA_PROMISC) 397 if (sdata->flags & IEEE80211_SDATA_PROMISC)
409 atomic_dec(&local->iff_promiscs); 398 atomic_dec(&local->iff_promiscs);
410 399
411 dev_mc_unsync(local->mdev, dev); 400 if (sdata->vif.type == NL80211_IFTYPE_AP)
401 local->fif_pspoll--;
402
403 netif_addr_lock_bh(dev);
404 spin_lock_bh(&local->filter_lock);
405 __dev_addr_unsync(&local->mc_list, &local->mc_count,
406 &dev->mc_list, &dev->mc_count);
407 ieee80211_configure_filter(local);
408 spin_unlock_bh(&local->filter_lock);
409 netif_addr_unlock_bh(dev);
410
412 del_timer_sync(&local->dynamic_ps_timer); 411 del_timer_sync(&local->dynamic_ps_timer);
413 cancel_work_sync(&local->dynamic_ps_enable_work); 412 cancel_work_sync(&local->dynamic_ps_enable_work);
414 413
415 /* APs need special treatment */ 414 /* APs need special treatment */
416 if (sdata->vif.type == NL80211_IFTYPE_AP) { 415 if (sdata->vif.type == NL80211_IFTYPE_AP) {
417 struct ieee80211_sub_if_data *vlan, *tmp; 416 struct ieee80211_sub_if_data *vlan, *tmpsdata;
418 struct beacon_data *old_beacon = sdata->u.ap.beacon; 417 struct beacon_data *old_beacon = sdata->u.ap.beacon;
419 418
420 /* remove beacon */ 419 /* remove beacon */
@@ -423,7 +422,7 @@ static int ieee80211_stop(struct net_device *dev)
423 kfree(old_beacon); 422 kfree(old_beacon);
424 423
425 /* down all dependent devices, that is VLANs */ 424 /* down all dependent devices, that is VLANs */
426 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, 425 list_for_each_entry_safe(vlan, tmpsdata, &sdata->u.ap.vlans,
427 u.vlan.list) 426 u.vlan.list)
428 dev_close(vlan->dev); 427 dev_close(vlan->dev);
429 WARN_ON(!list_empty(&sdata->u.ap.vlans)); 428 WARN_ON(!list_empty(&sdata->u.ap.vlans));
@@ -452,29 +451,32 @@ static int ieee80211_stop(struct net_device *dev)
452 local->fif_fcsfail--; 451 local->fif_fcsfail--;
453 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) 452 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
454 local->fif_plcpfail--; 453 local->fif_plcpfail--;
455 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) 454 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) {
455 local->fif_pspoll--;
456 local->fif_control--; 456 local->fif_control--;
457 }
457 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) 458 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
458 local->fif_other_bss--; 459 local->fif_other_bss--;
459 460
460 netif_addr_lock_bh(local->mdev); 461 spin_lock_bh(&local->filter_lock);
461 ieee80211_configure_filter(local); 462 ieee80211_configure_filter(local);
462 netif_addr_unlock_bh(local->mdev); 463 spin_unlock_bh(&local->filter_lock);
463 break; 464 break;
464 case NL80211_IFTYPE_STATION: 465 case NL80211_IFTYPE_STATION:
465 memset(sdata->u.mgd.bssid, 0, ETH_ALEN);
466 del_timer_sync(&sdata->u.mgd.chswitch_timer); 466 del_timer_sync(&sdata->u.mgd.chswitch_timer);
467 del_timer_sync(&sdata->u.mgd.timer); 467 del_timer_sync(&sdata->u.mgd.timer);
468 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
469 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
468 /* 470 /*
469 * If the timer fired while we waited for it, it will have 471 * If any of the timers fired while we waited for it, it will
470 * requeued the work. Now the work will be running again 472 * have queued its work. Now the work will be running again
471 * but will not rearm the timer again because it checks 473 * but will not rearm the timer again because it checks
472 * whether the interface is running, which, at this point, 474 * whether the interface is running, which, at this point,
473 * it no longer is. 475 * it no longer is.
474 */ 476 */
475 cancel_work_sync(&sdata->u.mgd.work); 477 cancel_work_sync(&sdata->u.mgd.work);
476 cancel_work_sync(&sdata->u.mgd.chswitch_work); 478 cancel_work_sync(&sdata->u.mgd.chswitch_work);
477 479 cancel_work_sync(&sdata->u.mgd.monitor_work);
478 cancel_work_sync(&sdata->u.mgd.beacon_loss_work); 480 cancel_work_sync(&sdata->u.mgd.beacon_loss_work);
479 481
480 /* 482 /*
@@ -485,12 +487,6 @@ static int ieee80211_stop(struct net_device *dev)
485 */ 487 */
486 synchronize_rcu(); 488 synchronize_rcu();
487 skb_queue_purge(&sdata->u.mgd.skb_queue); 489 skb_queue_purge(&sdata->u.mgd.skb_queue);
488
489 sdata->u.mgd.flags &= ~(IEEE80211_STA_PRIVACY_INVOKED |
490 IEEE80211_STA_TKIP_WEP_USED);
491 kfree(sdata->u.mgd.extra_ie);
492 sdata->u.mgd.extra_ie = NULL;
493 sdata->u.mgd.extra_ie_len = 0;
494 /* fall through */ 490 /* fall through */
495 case NL80211_IFTYPE_ADHOC: 491 case NL80211_IFTYPE_ADHOC:
496 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 492 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
@@ -507,9 +503,9 @@ static int ieee80211_stop(struct net_device *dev)
507 local->fif_other_bss--; 503 local->fif_other_bss--;
508 atomic_dec(&local->iff_allmultis); 504 atomic_dec(&local->iff_allmultis);
509 505
510 netif_addr_lock_bh(local->mdev); 506 spin_lock_bh(&local->filter_lock);
511 ieee80211_configure_filter(local); 507 ieee80211_configure_filter(local);
512 netif_addr_unlock_bh(local->mdev); 508 spin_unlock_bh(&local->filter_lock);
513 509
514 ieee80211_stop_mesh(sdata); 510 ieee80211_stop_mesh(sdata);
515 } 511 }
@@ -536,10 +532,20 @@ static int ieee80211_stop(struct net_device *dev)
536 * the scan_sdata is NULL already don't send out a 532 * the scan_sdata is NULL already don't send out a
537 * scan event to userspace -- the scan is incomplete. 533 * scan event to userspace -- the scan is incomplete.
538 */ 534 */
539 if (local->sw_scanning) 535 if (test_bit(SCAN_SW_SCANNING, &local->scanning))
540 ieee80211_scan_completed(&local->hw, true); 536 ieee80211_scan_completed(&local->hw, true);
541 } 537 }
542 538
539 /*
540 * Disable beaconing for AP and mesh, IBSS can't
541 * still be joined to a network at this point.
542 */
543 if (sdata->vif.type == NL80211_IFTYPE_AP ||
544 sdata->vif.type == NL80211_IFTYPE_MESH_POINT) {
545 ieee80211_bss_info_change_notify(sdata,
546 BSS_CHANGED_BEACON_ENABLED);
547 }
548
543 conf.vif = &sdata->vif; 549 conf.vif = &sdata->vif;
544 conf.type = sdata->vif.type; 550 conf.type = sdata->vif.type;
545 conf.mac_addr = dev->dev_addr; 551 conf.mac_addr = dev->dev_addr;
@@ -555,14 +561,11 @@ static int ieee80211_stop(struct net_device *dev)
555 ieee80211_recalc_ps(local, -1); 561 ieee80211_recalc_ps(local, -1);
556 562
557 if (local->open_count == 0) { 563 if (local->open_count == 0) {
558 if (netif_running(local->mdev))
559 dev_close(local->mdev);
560
561 drv_stop(local); 564 drv_stop(local);
562 565
563 ieee80211_led_radio(local, false); 566 ieee80211_led_radio(local, false);
564 567
565 flush_workqueue(local->hw.workqueue); 568 flush_workqueue(local->workqueue);
566 569
567 tasklet_disable(&local->tx_pending_tasklet); 570 tasklet_disable(&local->tx_pending_tasklet);
568 tasklet_disable(&local->tasklet); 571 tasklet_disable(&local->tasklet);
@@ -575,6 +578,18 @@ static int ieee80211_stop(struct net_device *dev)
575 if (hw_reconf_flags) 578 if (hw_reconf_flags)
576 ieee80211_hw_config(local, hw_reconf_flags); 579 ieee80211_hw_config(local, hw_reconf_flags);
577 580
581 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
582 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
583 skb_queue_walk_safe(&local->pending[i], skb, tmp) {
584 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
585 if (info->control.vif == &sdata->vif) {
586 __skb_unlink(skb, &local->pending[i]);
587 dev_kfree_skb_irq(skb);
588 }
589 }
590 }
591 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
592
578 return 0; 593 return 0;
579} 594}
580 595
@@ -604,8 +619,11 @@ static void ieee80211_set_multicast_list(struct net_device *dev)
604 atomic_dec(&local->iff_promiscs); 619 atomic_dec(&local->iff_promiscs);
605 sdata->flags ^= IEEE80211_SDATA_PROMISC; 620 sdata->flags ^= IEEE80211_SDATA_PROMISC;
606 } 621 }
607 622 spin_lock_bh(&local->filter_lock);
608 dev_mc_sync(local->mdev, dev); 623 __dev_addr_sync(&local->mc_list, &local->mc_count,
624 &dev->mc_list, &dev->mc_count);
625 ieee80211_configure_filter(local);
626 spin_unlock_bh(&local->filter_lock);
609} 627}
610 628
611/* 629/*
@@ -652,11 +670,6 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
652 kfree_skb(sdata->u.ibss.presp); 670 kfree_skb(sdata->u.ibss.presp);
653 break; 671 break;
654 case NL80211_IFTYPE_STATION: 672 case NL80211_IFTYPE_STATION:
655 kfree(sdata->u.mgd.extra_ie);
656 kfree(sdata->u.mgd.assocreq_ies);
657 kfree(sdata->u.mgd.assocresp_ies);
658 kfree(sdata->u.mgd.sme_auth_ie);
659 break;
660 case NL80211_IFTYPE_WDS: 673 case NL80211_IFTYPE_WDS:
661 case NL80211_IFTYPE_AP_VLAN: 674 case NL80211_IFTYPE_AP_VLAN:
662 case NL80211_IFTYPE_MONITOR: 675 case NL80211_IFTYPE_MONITOR:
@@ -695,7 +708,6 @@ static void ieee80211_if_setup(struct net_device *dev)
695{ 708{
696 ether_setup(dev); 709 ether_setup(dev);
697 dev->netdev_ops = &ieee80211_dataif_ops; 710 dev->netdev_ops = &ieee80211_dataif_ops;
698 dev->wireless_handlers = &ieee80211_iw_handler_def;
699 dev->destructor = free_netdev; 711 dev->destructor = free_netdev;
700} 712}
701 713
@@ -798,6 +810,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
798 name, ieee80211_if_setup); 810 name, ieee80211_if_setup);
799 if (!ndev) 811 if (!ndev)
800 return -ENOMEM; 812 return -ENOMEM;
813 dev_net_set(ndev, wiphy_net(local->hw.wiphy));
801 814
802 ndev->needed_headroom = local->tx_headroom + 815 ndev->needed_headroom = local->tx_headroom +
803 4*6 /* four MAC addresses */ 816 4*6 /* four MAC addresses */
@@ -814,7 +827,6 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
814 827
815 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); 828 memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
816 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy)); 829 SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
817 ndev->features |= NETIF_F_NETNS_LOCAL;
818 830
819 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */ 831 /* don't use IEEE80211_DEV_TO_SUB_IF because it checks too much */
820 sdata = netdev_priv(ndev); 832 sdata = netdev_priv(ndev);
@@ -931,7 +943,7 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
931 struct ieee80211_sub_if_data *sdata; 943 struct ieee80211_sub_if_data *sdata;
932 int count = 0; 944 int count = 0;
933 945
934 if (local->hw_scanning || local->sw_scanning) 946 if (local->scanning)
935 return ieee80211_idle_off(local, "scanning"); 947 return ieee80211_idle_off(local, "scanning");
936 948
937 list_for_each_entry(sdata, &local->interfaces, list) { 949 list_for_each_entry(sdata, &local->interfaces, list) {
@@ -939,7 +951,8 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
939 continue; 951 continue;
940 /* do not count disabled managed interfaces */ 952 /* do not count disabled managed interfaces */
941 if (sdata->vif.type == NL80211_IFTYPE_STATION && 953 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
942 sdata->u.mgd.state == IEEE80211_STA_MLME_DISABLED) 954 !sdata->u.mgd.associated &&
955 list_empty(&sdata->u.mgd.work_list))
943 continue; 956 continue;
944 /* do not count unused IBSS interfaces */ 957 /* do not count unused IBSS interfaces */
945 if (sdata->vif.type == NL80211_IFTYPE_ADHOC && 958 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
diff --git a/net/mac80211/key.c b/net/mac80211/key.c
index ce267565e180..659a42d529e3 100644
--- a/net/mac80211/key.c
+++ b/net/mac80211/key.c
@@ -67,6 +67,8 @@ static DECLARE_WORK(todo_work, key_todo);
67 * 67 *
68 * @key: key to add to do item for 68 * @key: key to add to do item for
69 * @flag: todo flag(s) 69 * @flag: todo flag(s)
70 *
71 * Must be called with IRQs or softirqs disabled.
70 */ 72 */
71static void add_todo(struct ieee80211_key *key, u32 flag) 73static void add_todo(struct ieee80211_key *key, u32 flag)
72{ 74{
@@ -140,9 +142,9 @@ static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
140 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf); 142 ret = drv_set_key(key->local, SET_KEY, &sdata->vif, sta, &key->conf);
141 143
142 if (!ret) { 144 if (!ret) {
143 spin_lock(&todo_lock); 145 spin_lock_bh(&todo_lock);
144 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE; 146 key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
145 spin_unlock(&todo_lock); 147 spin_unlock_bh(&todo_lock);
146 } 148 }
147 149
148 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP) 150 if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
@@ -164,12 +166,12 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
164 if (!key || !key->local->ops->set_key) 166 if (!key || !key->local->ops->set_key)
165 return; 167 return;
166 168
167 spin_lock(&todo_lock); 169 spin_lock_bh(&todo_lock);
168 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 170 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
169 spin_unlock(&todo_lock); 171 spin_unlock_bh(&todo_lock);
170 return; 172 return;
171 } 173 }
172 spin_unlock(&todo_lock); 174 spin_unlock_bh(&todo_lock);
173 175
174 sta = get_sta_for_key(key); 176 sta = get_sta_for_key(key);
175 sdata = key->sdata; 177 sdata = key->sdata;
@@ -188,9 +190,9 @@ static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
188 wiphy_name(key->local->hw.wiphy), 190 wiphy_name(key->local->hw.wiphy),
189 key->conf.keyidx, sta ? sta->addr : bcast_addr, ret); 191 key->conf.keyidx, sta ? sta->addr : bcast_addr, ret);
190 192
191 spin_lock(&todo_lock); 193 spin_lock_bh(&todo_lock);
192 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE; 194 key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
193 spin_unlock(&todo_lock); 195 spin_unlock_bh(&todo_lock);
194} 196}
195 197
196static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, 198static void __ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata,
@@ -437,14 +439,14 @@ void ieee80211_key_link(struct ieee80211_key *key,
437 439
438 __ieee80211_key_replace(sdata, sta, old_key, key); 440 __ieee80211_key_replace(sdata, sta, old_key, key);
439 441
440 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
441
442 /* free old key later */ 442 /* free old key later */
443 add_todo(old_key, KEY_FLAG_TODO_DELETE); 443 add_todo(old_key, KEY_FLAG_TODO_DELETE);
444 444
445 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS); 445 add_todo(key, KEY_FLAG_TODO_ADD_DEBUGFS);
446 if (netif_running(sdata->dev)) 446 if (netif_running(sdata->dev))
447 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD); 447 add_todo(key, KEY_FLAG_TODO_HWACCEL_ADD);
448
449 spin_unlock_irqrestore(&sdata->local->key_lock, flags);
448} 450}
449 451
450static void __ieee80211_key_free(struct ieee80211_key *key) 452static void __ieee80211_key_free(struct ieee80211_key *key)
@@ -547,7 +549,7 @@ static void __ieee80211_key_todo(void)
547 */ 549 */
548 synchronize_rcu(); 550 synchronize_rcu();
549 551
550 spin_lock(&todo_lock); 552 spin_lock_bh(&todo_lock);
551 while (!list_empty(&todo_list)) { 553 while (!list_empty(&todo_list)) {
552 key = list_first_entry(&todo_list, struct ieee80211_key, todo); 554 key = list_first_entry(&todo_list, struct ieee80211_key, todo);
553 list_del_init(&key->todo); 555 list_del_init(&key->todo);
@@ -558,7 +560,7 @@ static void __ieee80211_key_todo(void)
558 KEY_FLAG_TODO_HWACCEL_REMOVE | 560 KEY_FLAG_TODO_HWACCEL_REMOVE |
559 KEY_FLAG_TODO_DELETE); 561 KEY_FLAG_TODO_DELETE);
560 key->flags &= ~todoflags; 562 key->flags &= ~todoflags;
561 spin_unlock(&todo_lock); 563 spin_unlock_bh(&todo_lock);
562 564
563 work_done = false; 565 work_done = false;
564 566
@@ -591,9 +593,9 @@ static void __ieee80211_key_todo(void)
591 593
592 WARN_ON(!work_done); 594 WARN_ON(!work_done);
593 595
594 spin_lock(&todo_lock); 596 spin_lock_bh(&todo_lock);
595 } 597 }
596 spin_unlock(&todo_lock); 598 spin_unlock_bh(&todo_lock);
597} 599}
598 600
599void ieee80211_key_todo(void) 601void ieee80211_key_todo(void)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 092a017b237e..0c4f8e122ed6 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -77,81 +77,23 @@ void ieee80211_configure_filter(struct ieee80211_local *local)
77 if (local->fif_other_bss) 77 if (local->fif_other_bss)
78 new_flags |= FIF_OTHER_BSS; 78 new_flags |= FIF_OTHER_BSS;
79 79
80 if (local->fif_pspoll)
81 new_flags |= FIF_PSPOLL;
82
80 changed_flags = local->filter_flags ^ new_flags; 83 changed_flags = local->filter_flags ^ new_flags;
81 84
82 /* be a bit nasty */ 85 /* be a bit nasty */
83 new_flags |= (1<<31); 86 new_flags |= (1<<31);
84 87
85 drv_configure_filter(local, changed_flags, &new_flags, 88 drv_configure_filter(local, changed_flags, &new_flags,
86 local->mdev->mc_count, 89 local->mc_count,
87 local->mdev->mc_list); 90 local->mc_list);
88 91
89 WARN_ON(new_flags & (1<<31)); 92 WARN_ON(new_flags & (1<<31));
90 93
91 local->filter_flags = new_flags & ~(1<<31); 94 local->filter_flags = new_flags & ~(1<<31);
92} 95}
93 96
94/* master interface */
95
96static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
97{
98 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
99 return ETH_ALEN;
100}
101
102static const struct header_ops ieee80211_header_ops = {
103 .create = eth_header,
104 .parse = header_parse_80211,
105 .rebuild = eth_rebuild_header,
106 .cache = eth_header_cache,
107 .cache_update = eth_header_cache_update,
108};
109
110static int ieee80211_master_open(struct net_device *dev)
111{
112 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
113 struct ieee80211_local *local = mpriv->local;
114 struct ieee80211_sub_if_data *sdata;
115 int res = -EOPNOTSUPP;
116
117 /* we hold the RTNL here so can safely walk the list */
118 list_for_each_entry(sdata, &local->interfaces, list) {
119 if (netif_running(sdata->dev)) {
120 res = 0;
121 break;
122 }
123 }
124
125 if (res)
126 return res;
127
128 netif_tx_start_all_queues(local->mdev);
129
130 return 0;
131}
132
133static int ieee80211_master_stop(struct net_device *dev)
134{
135 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
136 struct ieee80211_local *local = mpriv->local;
137 struct ieee80211_sub_if_data *sdata;
138
139 /* we hold the RTNL here so can safely walk the list */
140 list_for_each_entry(sdata, &local->interfaces, list)
141 if (netif_running(sdata->dev))
142 dev_close(sdata->dev);
143
144 return 0;
145}
146
147static void ieee80211_master_set_multicast_list(struct net_device *dev)
148{
149 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
150 struct ieee80211_local *local = mpriv->local;
151
152 ieee80211_configure_filter(local);
153}
154
155int ieee80211_hw_config(struct ieee80211_local *local, u32 changed) 97int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
156{ 98{
157 struct ieee80211_channel *chan, *scan_chan; 99 struct ieee80211_channel *chan, *scan_chan;
@@ -259,7 +201,8 @@ void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
259 } 201 }
260 202
261 if (changed & BSS_CHANGED_BEACON_ENABLED) { 203 if (changed & BSS_CHANGED_BEACON_ENABLED) {
262 if (local->sw_scanning) { 204 if (local->quiescing || !netif_running(sdata->dev) ||
205 test_bit(SCAN_SW_SCANNING, &local->scanning)) {
263 sdata->vif.bss_conf.enable_beacon = false; 206 sdata->vif.bss_conf.enable_beacon = false;
264 } else { 207 } else {
265 /* 208 /*
@@ -310,7 +253,6 @@ void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
310 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 253 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
311 int tmp; 254 int tmp;
312 255
313 skb->dev = local->mdev;
314 skb->pkt_type = IEEE80211_TX_STATUS_MSG; 256 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
315 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ? 257 skb_queue_tail(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS ?
316 &local->skb_queue : &local->skb_queue_unreliable, skb); 258 &local->skb_queue : &local->skb_queue_unreliable, skb);
@@ -330,19 +272,16 @@ static void ieee80211_tasklet_handler(unsigned long data)
330{ 272{
331 struct ieee80211_local *local = (struct ieee80211_local *) data; 273 struct ieee80211_local *local = (struct ieee80211_local *) data;
332 struct sk_buff *skb; 274 struct sk_buff *skb;
333 struct ieee80211_rx_status rx_status;
334 struct ieee80211_ra_tid *ra_tid; 275 struct ieee80211_ra_tid *ra_tid;
335 276
336 while ((skb = skb_dequeue(&local->skb_queue)) || 277 while ((skb = skb_dequeue(&local->skb_queue)) ||
337 (skb = skb_dequeue(&local->skb_queue_unreliable))) { 278 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
338 switch (skb->pkt_type) { 279 switch (skb->pkt_type) {
339 case IEEE80211_RX_MSG: 280 case IEEE80211_RX_MSG:
340 /* status is in skb->cb */
341 memcpy(&rx_status, skb->cb, sizeof(rx_status));
342 /* Clear skb->pkt_type in order to not confuse kernel 281 /* Clear skb->pkt_type in order to not confuse kernel
343 * netstack. */ 282 * netstack. */
344 skb->pkt_type = 0; 283 skb->pkt_type = 0;
345 __ieee80211_rx(local_to_hw(local), skb, &rx_status); 284 ieee80211_rx(local_to_hw(local), skb);
346 break; 285 break;
347 case IEEE80211_TX_STATUS_MSG: 286 case IEEE80211_TX_STATUS_MSG:
348 skb->pkt_type = 0; 287 skb->pkt_type = 0;
@@ -375,6 +314,31 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
375{ 314{
376 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 315 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
377 316
317 /*
318 * XXX: This is temporary!
319 *
320 * The problem here is that when we get here, the driver will
321 * quite likely have pretty much overwritten info->control by
322 * using info->driver_data or info->rate_driver_data. Thus,
323 * when passing out the frame to the driver again, we would be
324 * passing completely bogus data since the driver would then
325 * expect a properly filled info->control. In mac80211 itself
326 * the same problem occurs, since we need info->control.vif
327 * internally.
328 *
329 * To fix this, we should send the frame through TX processing
330 * again. However, it's not that simple, since the frame will
331 * have been software-encrypted (if applicable) already, and
332 * encrypting it again doesn't do much good. So to properly do
333 * that, we not only have to skip the actual 'raw' encryption
334 * (key selection etc. still has to be done!) but also the
335 * sequence number assignment since that impacts the crypto
336 * encapsulation, of course.
337 *
338 * Hence, for now, fix the bug by just dropping the frame.
339 */
340 goto drop;
341
378 sta->tx_filtered_count++; 342 sta->tx_filtered_count++;
379 343
380 /* 344 /*
@@ -428,6 +392,7 @@ static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
428 return; 392 return;
429 } 393 }
430 394
395 drop:
431#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 396#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
432 if (net_ratelimit()) 397 if (net_ratelimit())
433 printk(KERN_DEBUG "%s: dropped TX filtered frame, " 398 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
@@ -685,6 +650,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
685 if (!wiphy) 650 if (!wiphy)
686 return NULL; 651 return NULL;
687 652
653 wiphy->netnsok = true;
688 wiphy->privid = mac80211_wiphy_privid; 654 wiphy->privid = mac80211_wiphy_privid;
689 655
690 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ 656 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */
@@ -719,7 +685,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
719 mutex_init(&local->scan_mtx); 685 mutex_init(&local->scan_mtx);
720 686
721 spin_lock_init(&local->key_lock); 687 spin_lock_init(&local->key_lock);
722 688 spin_lock_init(&local->filter_lock);
723 spin_lock_init(&local->queue_stop_reason_lock); 689 spin_lock_init(&local->queue_stop_reason_lock);
724 690
725 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 691 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
@@ -755,30 +721,11 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
755} 721}
756EXPORT_SYMBOL(ieee80211_alloc_hw); 722EXPORT_SYMBOL(ieee80211_alloc_hw);
757 723
758static const struct net_device_ops ieee80211_master_ops = {
759 .ndo_start_xmit = ieee80211_master_start_xmit,
760 .ndo_open = ieee80211_master_open,
761 .ndo_stop = ieee80211_master_stop,
762 .ndo_set_multicast_list = ieee80211_master_set_multicast_list,
763 .ndo_select_queue = ieee80211_select_queue,
764};
765
766static void ieee80211_master_setup(struct net_device *mdev)
767{
768 mdev->type = ARPHRD_IEEE80211;
769 mdev->netdev_ops = &ieee80211_master_ops;
770 mdev->header_ops = &ieee80211_header_ops;
771 mdev->tx_queue_len = 1000;
772 mdev->addr_len = ETH_ALEN;
773}
774
775int ieee80211_register_hw(struct ieee80211_hw *hw) 724int ieee80211_register_hw(struct ieee80211_hw *hw)
776{ 725{
777 struct ieee80211_local *local = hw_to_local(hw); 726 struct ieee80211_local *local = hw_to_local(hw);
778 int result; 727 int result;
779 enum ieee80211_band band; 728 enum ieee80211_band band;
780 struct net_device *mdev;
781 struct ieee80211_master_priv *mpriv;
782 int channels, i, j, max_bitrates; 729 int channels, i, j, max_bitrates;
783 bool supp_ht; 730 bool supp_ht;
784 static const u32 cipher_suites[] = { 731 static const u32 cipher_suites[] = {
@@ -877,19 +824,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
877 if (hw->queues > IEEE80211_MAX_QUEUES) 824 if (hw->queues > IEEE80211_MAX_QUEUES)
878 hw->queues = IEEE80211_MAX_QUEUES; 825 hw->queues = IEEE80211_MAX_QUEUES;
879 826
880 mdev = alloc_netdev_mq(sizeof(struct ieee80211_master_priv), 827 local->workqueue =
881 "wmaster%d", ieee80211_master_setup,
882 hw->queues);
883 if (!mdev)
884 goto fail_mdev_alloc;
885
886 mpriv = netdev_priv(mdev);
887 mpriv->local = local;
888 local->mdev = mdev;
889
890 local->hw.workqueue =
891 create_singlethread_workqueue(wiphy_name(local->hw.wiphy)); 828 create_singlethread_workqueue(wiphy_name(local->hw.wiphy));
892 if (!local->hw.workqueue) { 829 if (!local->workqueue) {
893 result = -ENOMEM; 830 result = -ENOMEM;
894 goto fail_workqueue; 831 goto fail_workqueue;
895 } 832 }
@@ -921,17 +858,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
921 } 858 }
922 859
923 rtnl_lock(); 860 rtnl_lock();
924 result = dev_alloc_name(local->mdev, local->mdev->name);
925 if (result < 0)
926 goto fail_dev;
927
928 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
929 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
930 local->mdev->features |= NETIF_F_NETNS_LOCAL;
931
932 result = register_netdevice(local->mdev);
933 if (result < 0)
934 goto fail_dev;
935 861
936 result = ieee80211_init_rate_ctrl_alg(local, 862 result = ieee80211_init_rate_ctrl_alg(local,
937 hw->rate_control_algorithm); 863 hw->rate_control_algorithm);
@@ -984,20 +910,14 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
984 ieee80211_led_exit(local); 910 ieee80211_led_exit(local);
985 ieee80211_remove_interfaces(local); 911 ieee80211_remove_interfaces(local);
986 fail_rate: 912 fail_rate:
987 unregister_netdevice(local->mdev);
988 local->mdev = NULL;
989 fail_dev:
990 rtnl_unlock(); 913 rtnl_unlock();
991 ieee80211_wep_free(local); 914 ieee80211_wep_free(local);
992 fail_wep: 915 fail_wep:
993 sta_info_stop(local); 916 sta_info_stop(local);
994 fail_sta_info: 917 fail_sta_info:
995 debugfs_hw_del(local); 918 debugfs_hw_del(local);
996 destroy_workqueue(local->hw.workqueue); 919 destroy_workqueue(local->workqueue);
997 fail_workqueue: 920 fail_workqueue:
998 if (local->mdev)
999 free_netdev(local->mdev);
1000 fail_mdev_alloc:
1001 wiphy_unregister(local->hw.wiphy); 921 wiphy_unregister(local->hw.wiphy);
1002 fail_wiphy_register: 922 fail_wiphy_register:
1003 kfree(local->int_scan_req.channels); 923 kfree(local->int_scan_req.channels);
@@ -1022,13 +942,8 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1022 * because the driver cannot be handing us frames any 942 * because the driver cannot be handing us frames any
1023 * more and the tasklet is killed. 943 * more and the tasklet is killed.
1024 */ 944 */
1025
1026 /* First, we remove all virtual interfaces. */
1027 ieee80211_remove_interfaces(local); 945 ieee80211_remove_interfaces(local);
1028 946
1029 /* then, finally, remove the master interface */
1030 unregister_netdevice(local->mdev);
1031
1032 rtnl_unlock(); 947 rtnl_unlock();
1033 948
1034 ieee80211_clear_tx_pending(local); 949 ieee80211_clear_tx_pending(local);
@@ -1043,11 +958,10 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1043 skb_queue_purge(&local->skb_queue); 958 skb_queue_purge(&local->skb_queue);
1044 skb_queue_purge(&local->skb_queue_unreliable); 959 skb_queue_purge(&local->skb_queue_unreliable);
1045 960
1046 destroy_workqueue(local->hw.workqueue); 961 destroy_workqueue(local->workqueue);
1047 wiphy_unregister(local->hw.wiphy); 962 wiphy_unregister(local->hw.wiphy);
1048 ieee80211_wep_free(local); 963 ieee80211_wep_free(local);
1049 ieee80211_led_exit(local); 964 ieee80211_led_exit(local);
1050 free_netdev(local->mdev);
1051 kfree(local->int_scan_req.channels); 965 kfree(local->int_scan_req.channels);
1052} 966}
1053EXPORT_SYMBOL(ieee80211_unregister_hw); 967EXPORT_SYMBOL(ieee80211_unregister_hw);
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 11cf45bce38a..2f4f518ab45c 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -54,7 +54,7 @@ static void ieee80211_mesh_housekeeping_timer(unsigned long data)
54 return; 54 return;
55 } 55 }
56 56
57 queue_work(local->hw.workqueue, &ifmsh->work); 57 ieee80211_queue_work(local->hw.workqueue, &ifmsh->work);
58} 58}
59 59
60/** 60/**
@@ -357,7 +357,7 @@ static void ieee80211_mesh_path_timer(unsigned long data)
357 return; 357 return;
358 } 358 }
359 359
360 queue_work(local->hw.workqueue, &ifmsh->work); 360 ieee80211_queue_work(local->hw.workqueue, &ifmsh->work);
361} 361}
362 362
363struct mesh_table *mesh_table_grow(struct mesh_table *tbl) 363struct mesh_table *mesh_table_grow(struct mesh_table *tbl)
@@ -471,7 +471,7 @@ void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata)
471 struct ieee80211_local *local = sdata->local; 471 struct ieee80211_local *local = sdata->local;
472 472
473 ifmsh->housekeeping = true; 473 ifmsh->housekeeping = true;
474 queue_work(local->hw.workqueue, &ifmsh->work); 474 ieee80211_queue_work(local->hw.workqueue, &ifmsh->work);
475 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | 475 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON |
476 BSS_CHANGED_BEACON_ENABLED); 476 BSS_CHANGED_BEACON_ENABLED);
477} 477}
@@ -568,7 +568,7 @@ static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
568 568
569 ifmsh = &sdata->u.mesh; 569 ifmsh = &sdata->u.mesh;
570 570
571 rx_status = (struct ieee80211_rx_status *) skb->cb; 571 rx_status = IEEE80211_SKB_RXCB(skb);
572 mgmt = (struct ieee80211_mgmt *) skb->data; 572 mgmt = (struct ieee80211_mgmt *) skb->data;
573 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; 573 stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
574 574
@@ -597,7 +597,7 @@ static void ieee80211_mesh_work(struct work_struct *work)
597 if (!netif_running(sdata->dev)) 597 if (!netif_running(sdata->dev))
598 return; 598 return;
599 599
600 if (local->sw_scanning || local->hw_scanning) 600 if (local->scanning)
601 return; 601 return;
602 602
603 while ((skb = skb_dequeue(&ifmsh->skb_queue))) 603 while ((skb = skb_dequeue(&ifmsh->skb_queue)))
@@ -619,7 +619,7 @@ void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local)
619 rcu_read_lock(); 619 rcu_read_lock();
620 list_for_each_entry_rcu(sdata, &local->interfaces, list) 620 list_for_each_entry_rcu(sdata, &local->interfaces, list)
621 if (ieee80211_vif_is_mesh(&sdata->vif)) 621 if (ieee80211_vif_is_mesh(&sdata->vif))
622 queue_work(local->hw.workqueue, &sdata->u.mesh.work); 622 ieee80211_queue_work(local->hw.workqueue, &sdata->u.mesh.work);
623 rcu_read_unlock(); 623 rcu_read_unlock();
624} 624}
625 625
@@ -671,8 +671,7 @@ void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata)
671} 671}
672 672
673ieee80211_rx_result 673ieee80211_rx_result
674ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 674ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
675 struct ieee80211_rx_status *rx_status)
676{ 675{
677 struct ieee80211_local *local = sdata->local; 676 struct ieee80211_local *local = sdata->local;
678 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 677 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
@@ -686,12 +685,14 @@ ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
686 fc = le16_to_cpu(mgmt->frame_control); 685 fc = le16_to_cpu(mgmt->frame_control);
687 686
688 switch (fc & IEEE80211_FCTL_STYPE) { 687 switch (fc & IEEE80211_FCTL_STYPE) {
688 case IEEE80211_STYPE_ACTION:
689 if (skb->len < IEEE80211_MIN_ACTION_SIZE)
690 return RX_DROP_MONITOR;
691 /* fall through */
689 case IEEE80211_STYPE_PROBE_RESP: 692 case IEEE80211_STYPE_PROBE_RESP:
690 case IEEE80211_STYPE_BEACON: 693 case IEEE80211_STYPE_BEACON:
691 case IEEE80211_STYPE_ACTION:
692 memcpy(skb->cb, rx_status, sizeof(*rx_status));
693 skb_queue_tail(&ifmsh->skb_queue, skb); 694 skb_queue_tail(&ifmsh->skb_queue, skb);
694 queue_work(local->hw.workqueue, &ifmsh->work); 695 ieee80211_queue_work(local->hw.workqueue, &ifmsh->work);
695 return RX_QUEUED; 696 return RX_QUEUED;
696 } 697 }
697 698
diff --git a/net/mac80211/mesh.h b/net/mac80211/mesh.h
index c7d72819cdd2..2a2ed182cb7e 100644
--- a/net/mac80211/mesh.h
+++ b/net/mac80211/mesh.h
@@ -208,8 +208,7 @@ void ieee80211s_init(void);
208void ieee80211s_stop(void); 208void ieee80211s_stop(void);
209void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata); 209void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata);
210ieee80211_rx_result 210ieee80211_rx_result
211ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 211ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
212 struct ieee80211_rx_status *rx_status);
213void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata); 212void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata);
214void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata); 213void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata);
215 214
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index f49ef288e2e2..11ab71a68ff9 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -660,14 +660,14 @@ static void mesh_queue_preq(struct mesh_path *mpath, u8 flags)
660 spin_unlock(&ifmsh->mesh_preq_queue_lock); 660 spin_unlock(&ifmsh->mesh_preq_queue_lock);
661 661
662 if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata))) 662 if (time_after(jiffies, ifmsh->last_preq + min_preq_int_jiff(sdata)))
663 queue_work(sdata->local->hw.workqueue, &ifmsh->work); 663 ieee80211_queue_work(sdata->local->hw.workqueue, &ifmsh->work);
664 664
665 else if (time_before(jiffies, ifmsh->last_preq)) { 665 else if (time_before(jiffies, ifmsh->last_preq)) {
666 /* avoid long wait if did not send preqs for a long time 666 /* avoid long wait if did not send preqs for a long time
667 * and jiffies wrapped around 667 * and jiffies wrapped around
668 */ 668 */
669 ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1; 669 ifmsh->last_preq = jiffies - min_preq_int_jiff(sdata) - 1;
670 queue_work(sdata->local->hw.workqueue, &ifmsh->work); 670 ieee80211_queue_work(sdata->local->hw.workqueue, &ifmsh->work);
671 } else 671 } else
672 mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq + 672 mod_timer(&ifmsh->mesh_path_timer, ifmsh->last_preq +
673 min_preq_int_jiff(sdata)); 673 min_preq_int_jiff(sdata));
@@ -686,11 +686,11 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
686 u8 ttl, dst_flags; 686 u8 ttl, dst_flags;
687 u32 lifetime; 687 u32 lifetime;
688 688
689 spin_lock(&ifmsh->mesh_preq_queue_lock); 689 spin_lock_bh(&ifmsh->mesh_preq_queue_lock);
690 if (!ifmsh->preq_queue_len || 690 if (!ifmsh->preq_queue_len ||
691 time_before(jiffies, ifmsh->last_preq + 691 time_before(jiffies, ifmsh->last_preq +
692 min_preq_int_jiff(sdata))) { 692 min_preq_int_jiff(sdata))) {
693 spin_unlock(&ifmsh->mesh_preq_queue_lock); 693 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
694 return; 694 return;
695 } 695 }
696 696
@@ -698,7 +698,7 @@ void mesh_path_start_discovery(struct ieee80211_sub_if_data *sdata)
698 struct mesh_preq_queue, list); 698 struct mesh_preq_queue, list);
699 list_del(&preq_node->list); 699 list_del(&preq_node->list);
700 --ifmsh->preq_queue_len; 700 --ifmsh->preq_queue_len;
701 spin_unlock(&ifmsh->mesh_preq_queue_lock); 701 spin_unlock_bh(&ifmsh->mesh_preq_queue_lock);
702 702
703 rcu_read_lock(); 703 rcu_read_lock();
704 mpath = mesh_path_lookup(preq_node->dst, sdata); 704 mpath = mesh_path_lookup(preq_node->dst, sdata);
@@ -784,7 +784,6 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
784 mesh_path_add(dst_addr, sdata); 784 mesh_path_add(dst_addr, sdata);
785 mpath = mesh_path_lookup(dst_addr, sdata); 785 mpath = mesh_path_lookup(dst_addr, sdata);
786 if (!mpath) { 786 if (!mpath) {
787 dev_kfree_skb(skb);
788 sdata->u.mesh.mshstats.dropped_frames_no_route++; 787 sdata->u.mesh.mshstats.dropped_frames_no_route++;
789 err = -ENOSPC; 788 err = -ENOSPC;
790 goto endlookup; 789 goto endlookup;
@@ -804,6 +803,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
804 memcpy(hdr->addr1, mpath->next_hop->sta.addr, 803 memcpy(hdr->addr1, mpath->next_hop->sta.addr,
805 ETH_ALEN); 804 ETH_ALEN);
806 } else { 805 } else {
806 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
807 if (!(mpath->flags & MESH_PATH_RESOLVING)) { 807 if (!(mpath->flags & MESH_PATH_RESOLVING)) {
808 /* Start discovery only if it is not running yet */ 808 /* Start discovery only if it is not running yet */
809 mesh_queue_preq(mpath, PREQ_Q_F_START); 809 mesh_queue_preq(mpath, PREQ_Q_F_START);
@@ -815,6 +815,7 @@ int mesh_nexthop_lookup(struct sk_buff *skb,
815 skb_unlink(skb_to_free, &mpath->frame_queue); 815 skb_unlink(skb_to_free, &mpath->frame_queue);
816 } 816 }
817 817
818 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
818 skb_queue_tail(&mpath->frame_queue, skb); 819 skb_queue_tail(&mpath->frame_queue, skb);
819 if (skb_to_free) 820 if (skb_to_free)
820 mesh_path_discard_frame(skb_to_free, sdata); 821 mesh_path_discard_frame(skb_to_free, sdata);
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 479597e88583..04b9e4d61b8e 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -55,7 +55,25 @@ static DEFINE_RWLOCK(pathtbl_resize_lock);
55 */ 55 */
56void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta) 56void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
57{ 57{
58 struct sk_buff *skb;
59 struct ieee80211_hdr *hdr;
60 struct sk_buff_head tmpq;
61 unsigned long flags;
62
58 rcu_assign_pointer(mpath->next_hop, sta); 63 rcu_assign_pointer(mpath->next_hop, sta);
64
65 __skb_queue_head_init(&tmpq);
66
67 spin_lock_irqsave(&mpath->frame_queue.lock, flags);
68
69 while ((skb = __skb_dequeue(&mpath->frame_queue)) != NULL) {
70 hdr = (struct ieee80211_hdr *) skb->data;
71 memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
72 __skb_queue_tail(&tmpq, skb);
73 }
74
75 skb_queue_splice(&tmpq, &mpath->frame_queue);
76 spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
59} 77}
60 78
61 79
@@ -481,11 +499,9 @@ enddel:
481 */ 499 */
482void mesh_path_tx_pending(struct mesh_path *mpath) 500void mesh_path_tx_pending(struct mesh_path *mpath)
483{ 501{
484 struct sk_buff *skb; 502 if (mpath->flags & MESH_PATH_ACTIVE)
485 503 ieee80211_add_pending_skbs(mpath->sdata->local,
486 while ((skb = skb_dequeue(&mpath->frame_queue)) && 504 &mpath->frame_queue);
487 (mpath->flags & MESH_PATH_ACTIVE))
488 dev_queue_xmit(skb);
489} 505}
490 506
491/** 507/**
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 07e7e41816be..6d5a1ee0445f 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -27,43 +27,99 @@
27#include "rate.h" 27#include "rate.h"
28#include "led.h" 28#include "led.h"
29 29
30#define IEEE80211_ASSOC_SCANS_MAX_TRIES 2
31#define IEEE80211_AUTH_TIMEOUT (HZ / 5) 30#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
32#define IEEE80211_AUTH_MAX_TRIES 3 31#define IEEE80211_AUTH_MAX_TRIES 3
33#define IEEE80211_ASSOC_TIMEOUT (HZ / 5) 32#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
34#define IEEE80211_ASSOC_MAX_TRIES 3 33#define IEEE80211_ASSOC_MAX_TRIES 3
35#define IEEE80211_MONITORING_INTERVAL (2 * HZ) 34#define IEEE80211_MAX_PROBE_TRIES 5
36#define IEEE80211_PROBE_WAIT (HZ / 5) 35
37#define IEEE80211_PROBE_IDLE_TIME (60 * HZ) 36/*
38#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ) 37 * beacon loss detection timeout
38 * XXX: should depend on beacon interval
39 */
40#define IEEE80211_BEACON_LOSS_TIME (2 * HZ)
41/*
42 * Time the connection can be idle before we probe
43 * it to see if we can still talk to the AP.
44 */
45#define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
46/*
47 * Time we wait for a probe response after sending
48 * a probe request because of beacon loss or for
49 * checking the connection still works.
50 */
51#define IEEE80211_PROBE_WAIT (HZ / 2)
39 52
40#define TMR_RUNNING_TIMER 0 53#define TMR_RUNNING_TIMER 0
41#define TMR_RUNNING_CHANSW 1 54#define TMR_RUNNING_CHANSW 1
42 55
56/*
57 * All cfg80211 functions have to be called outside a locked
58 * section so that they can acquire a lock themselves... This
59 * is much simpler than queuing up things in cfg80211, but we
60 * do need some indirection for that here.
61 */
62enum rx_mgmt_action {
63 /* no action required */
64 RX_MGMT_NONE,
65
66 /* caller must call cfg80211_send_rx_auth() */
67 RX_MGMT_CFG80211_AUTH,
68
69 /* caller must call cfg80211_send_rx_assoc() */
70 RX_MGMT_CFG80211_ASSOC,
71
72 /* caller must call cfg80211_send_deauth() */
73 RX_MGMT_CFG80211_DEAUTH,
74
75 /* caller must call cfg80211_send_disassoc() */
76 RX_MGMT_CFG80211_DISASSOC,
77
78 /* caller must call cfg80211_auth_timeout() & free work */
79 RX_MGMT_CFG80211_AUTH_TO,
80
81 /* caller must call cfg80211_assoc_timeout() & free work */
82 RX_MGMT_CFG80211_ASSOC_TO,
83};
84
43/* utils */ 85/* utils */
44static int ecw2cw(int ecw) 86static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
45{ 87{
46 return (1 << ecw) - 1; 88 WARN_ON(!mutex_is_locked(&ifmgd->mtx));
47} 89}
48 90
49static u8 *ieee80211_bss_get_ie(struct ieee80211_bss *bss, u8 ie) 91/*
92 * We can have multiple work items (and connection probing)
93 * scheduling this timer, but we need to take care to only
94 * reschedule it when it should fire _earlier_ than it was
95 * asked for before, or if it's not pending right now. This
96 * function ensures that. Note that it then is required to
97 * run this function for all timeouts after the first one
98 * has happened -- the work that runs from this timer will
99 * do that.
100 */
101static void run_again(struct ieee80211_if_managed *ifmgd,
102 unsigned long timeout)
50{ 103{
51 u8 *end, *pos; 104 ASSERT_MGD_MTX(ifmgd);
52 105
53 pos = bss->cbss.information_elements; 106 if (!timer_pending(&ifmgd->timer) ||
54 if (pos == NULL) 107 time_before(timeout, ifmgd->timer.expires))
55 return NULL; 108 mod_timer(&ifmgd->timer, timeout);
56 end = pos + bss->cbss.len_information_elements; 109}
57 110
58 while (pos + 1 < end) { 111static void mod_beacon_timer(struct ieee80211_sub_if_data *sdata)
59 if (pos + 2 + pos[1] > end) 112{
60 break; 113 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
61 if (pos[0] == ie) 114 return;
62 return pos;
63 pos += 2 + pos[1];
64 }
65 115
66 return NULL; 116 mod_timer(&sdata->u.mgd.bcn_mon_timer,
117 round_jiffies_up(jiffies + IEEE80211_BEACON_LOSS_TIME));
118}
119
120static int ecw2cw(int ecw)
121{
122 return (1 << ecw) - 1;
67} 123}
68 124
69static int ieee80211_compatible_rates(struct ieee80211_bss *bss, 125static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
@@ -94,11 +150,10 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
94 */ 150 */
95static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata, 151static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
96 struct ieee80211_ht_info *hti, 152 struct ieee80211_ht_info *hti,
97 u16 ap_ht_cap_flags) 153 const u8 *bssid, u16 ap_ht_cap_flags)
98{ 154{
99 struct ieee80211_local *local = sdata->local; 155 struct ieee80211_local *local = sdata->local;
100 struct ieee80211_supported_band *sband; 156 struct ieee80211_supported_band *sband;
101 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
102 struct sta_info *sta; 157 struct sta_info *sta;
103 u32 changed = 0; 158 u32 changed = 0;
104 u16 ht_opmode; 159 u16 ht_opmode;
@@ -147,12 +202,10 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
147 ieee80211_hw_config(local, 0); 202 ieee80211_hw_config(local, 0);
148 203
149 rcu_read_lock(); 204 rcu_read_lock();
150 205 sta = sta_info_get(local, bssid);
151 sta = sta_info_get(local, ifmgd->bssid);
152 if (sta) 206 if (sta)
153 rate_control_rate_update(local, sband, sta, 207 rate_control_rate_update(local, sband, sta,
154 IEEE80211_RC_HT_CHANGED); 208 IEEE80211_RC_HT_CHANGED);
155
156 rcu_read_unlock(); 209 rcu_read_unlock();
157 } 210 }
158 211
@@ -175,23 +228,24 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
175 228
176/* frame sending functions */ 229/* frame sending functions */
177 230
178static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 231static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata,
232 struct ieee80211_mgd_work *wk)
179{ 233{
180 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 234 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
181 struct ieee80211_local *local = sdata->local; 235 struct ieee80211_local *local = sdata->local;
182 struct sk_buff *skb; 236 struct sk_buff *skb;
183 struct ieee80211_mgmt *mgmt; 237 struct ieee80211_mgmt *mgmt;
184 u8 *pos, *ies, *ht_ie; 238 u8 *pos;
239 const u8 *ies, *ht_ie;
185 int i, len, count, rates_len, supp_rates_len; 240 int i, len, count, rates_len, supp_rates_len;
186 u16 capab; 241 u16 capab;
187 struct ieee80211_bss *bss;
188 int wmm = 0; 242 int wmm = 0;
189 struct ieee80211_supported_band *sband; 243 struct ieee80211_supported_band *sband;
190 u32 rates = 0; 244 u32 rates = 0;
191 245
192 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 246 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
193 sizeof(*mgmt) + 200 + ifmgd->extra_ie_len + 247 sizeof(*mgmt) + 200 + wk->ie_len +
194 ifmgd->ssid_len); 248 wk->ssid_len);
195 if (!skb) { 249 if (!skb) {
196 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc " 250 printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
197 "frame\n", sdata->dev->name); 251 "frame\n", sdata->dev->name);
@@ -210,45 +264,35 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
210 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; 264 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
211 } 265 }
212 266
213 bss = ieee80211_rx_bss_get(local, ifmgd->bssid, 267 if (wk->bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
214 local->hw.conf.channel->center_freq, 268 capab |= WLAN_CAPABILITY_PRIVACY;
215 ifmgd->ssid, ifmgd->ssid_len); 269 if (wk->bss->wmm_used)
216 if (bss) { 270 wmm = 1;
217 if (bss->cbss.capability & WLAN_CAPABILITY_PRIVACY)
218 capab |= WLAN_CAPABILITY_PRIVACY;
219 if (bss->wmm_used)
220 wmm = 1;
221 271
222 /* get all rates supported by the device and the AP as 272 /* get all rates supported by the device and the AP as
223 * some APs don't like getting a superset of their rates 273 * some APs don't like getting a superset of their rates
224 * in the association request (e.g. D-Link DAP 1353 in 274 * in the association request (e.g. D-Link DAP 1353 in
225 * b-only mode) */ 275 * b-only mode) */
226 rates_len = ieee80211_compatible_rates(bss, sband, &rates); 276 rates_len = ieee80211_compatible_rates(wk->bss, sband, &rates);
227 277
228 if ((bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && 278 if ((wk->bss->cbss.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
229 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) 279 (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT))
230 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; 280 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
231
232 ieee80211_rx_bss_put(local, bss);
233 } else {
234 rates = ~0;
235 rates_len = sband->n_bitrates;
236 }
237 281
238 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 282 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
239 memset(mgmt, 0, 24); 283 memset(mgmt, 0, 24);
240 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); 284 memcpy(mgmt->da, wk->bss->cbss.bssid, ETH_ALEN);
241 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 285 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
242 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); 286 memcpy(mgmt->bssid, wk->bss->cbss.bssid, ETH_ALEN);
243 287
244 if (ifmgd->flags & IEEE80211_STA_PREV_BSSID_SET) { 288 if (!is_zero_ether_addr(wk->prev_bssid)) {
245 skb_put(skb, 10); 289 skb_put(skb, 10);
246 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 290 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
247 IEEE80211_STYPE_REASSOC_REQ); 291 IEEE80211_STYPE_REASSOC_REQ);
248 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); 292 mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
249 mgmt->u.reassoc_req.listen_interval = 293 mgmt->u.reassoc_req.listen_interval =
250 cpu_to_le16(local->hw.conf.listen_interval); 294 cpu_to_le16(local->hw.conf.listen_interval);
251 memcpy(mgmt->u.reassoc_req.current_ap, ifmgd->prev_bssid, 295 memcpy(mgmt->u.reassoc_req.current_ap, wk->prev_bssid,
252 ETH_ALEN); 296 ETH_ALEN);
253 } else { 297 } else {
254 skb_put(skb, 4); 298 skb_put(skb, 4);
@@ -260,10 +304,10 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
260 } 304 }
261 305
262 /* SSID */ 306 /* SSID */
263 ies = pos = skb_put(skb, 2 + ifmgd->ssid_len); 307 ies = pos = skb_put(skb, 2 + wk->ssid_len);
264 *pos++ = WLAN_EID_SSID; 308 *pos++ = WLAN_EID_SSID;
265 *pos++ = ifmgd->ssid_len; 309 *pos++ = wk->ssid_len;
266 memcpy(pos, ifmgd->ssid, ifmgd->ssid_len); 310 memcpy(pos, wk->ssid, wk->ssid_len);
267 311
268 /* add all rates which were marked to be used above */ 312 /* add all rates which were marked to be used above */
269 supp_rates_len = rates_len; 313 supp_rates_len = rates_len;
@@ -318,9 +362,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
318 } 362 }
319 } 363 }
320 364
321 if (ifmgd->extra_ie) { 365 if (wk->ie_len && wk->ie) {
322 pos = skb_put(skb, ifmgd->extra_ie_len); 366 pos = skb_put(skb, wk->ie_len);
323 memcpy(pos, ifmgd->extra_ie, ifmgd->extra_ie_len); 367 memcpy(pos, wk->ie, wk->ie_len);
324 } 368 }
325 369
326 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) { 370 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) {
@@ -345,9 +389,9 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
345 */ 389 */
346 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 390 if (wmm && (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
347 sband->ht_cap.ht_supported && 391 sband->ht_cap.ht_supported &&
348 (ht_ie = ieee80211_bss_get_ie(bss, WLAN_EID_HT_INFORMATION)) && 392 (ht_ie = ieee80211_bss_get_ie(&wk->bss->cbss, WLAN_EID_HT_INFORMATION)) &&
349 ht_ie[1] >= sizeof(struct ieee80211_ht_info) && 393 ht_ie[1] >= sizeof(struct ieee80211_ht_info) &&
350 (!(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))) { 394 (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))) {
351 struct ieee80211_ht_info *ht_info = 395 struct ieee80211_ht_info *ht_info =
352 (struct ieee80211_ht_info *)(ht_ie + 2); 396 (struct ieee80211_ht_info *)(ht_ie + 2);
353 u16 cap = sband->ht_cap.cap; 397 u16 cap = sband->ht_cap.cap;
@@ -382,18 +426,13 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
382 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); 426 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
383 } 427 }
384 428
385 kfree(ifmgd->assocreq_ies);
386 ifmgd->assocreq_ies_len = (skb->data + skb->len) - ies;
387 ifmgd->assocreq_ies = kmalloc(ifmgd->assocreq_ies_len, GFP_KERNEL);
388 if (ifmgd->assocreq_ies)
389 memcpy(ifmgd->assocreq_ies, ies, ifmgd->assocreq_ies_len);
390
391 ieee80211_tx_skb(sdata, skb, 0); 429 ieee80211_tx_skb(sdata, skb, 0);
392} 430}
393 431
394 432
395static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 433static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
396 u16 stype, u16 reason) 434 const u8 *bssid, u16 stype, u16 reason,
435 void *cookie)
397{ 436{
398 struct ieee80211_local *local = sdata->local; 437 struct ieee80211_local *local = sdata->local;
399 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 438 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
@@ -410,18 +449,18 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
410 449
411 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); 450 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
412 memset(mgmt, 0, 24); 451 memset(mgmt, 0, 24);
413 memcpy(mgmt->da, ifmgd->bssid, ETH_ALEN); 452 memcpy(mgmt->da, bssid, ETH_ALEN);
414 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 453 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
415 memcpy(mgmt->bssid, ifmgd->bssid, ETH_ALEN); 454 memcpy(mgmt->bssid, bssid, ETH_ALEN);
416 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 455 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
417 skb_put(skb, 2); 456 skb_put(skb, 2);
418 /* u.deauth.reason_code == u.disassoc.reason_code */ 457 /* u.deauth.reason_code == u.disassoc.reason_code */
419 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 458 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
420 459
421 if (stype == IEEE80211_STYPE_DEAUTH) 460 if (stype == IEEE80211_STYPE_DEAUTH)
422 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len); 461 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, cookie);
423 else 462 else
424 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len); 463 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len, cookie);
425 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 464 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
426} 465}
427 466
@@ -494,28 +533,26 @@ static void ieee80211_chswitch_work(struct work_struct *work)
494{ 533{
495 struct ieee80211_sub_if_data *sdata = 534 struct ieee80211_sub_if_data *sdata =
496 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); 535 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
497 struct ieee80211_bss *bss;
498 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 536 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
499 537
500 if (!netif_running(sdata->dev)) 538 if (!netif_running(sdata->dev))
501 return; 539 return;
502 540
503 bss = ieee80211_rx_bss_get(sdata->local, ifmgd->bssid, 541 mutex_lock(&ifmgd->mtx);
504 sdata->local->hw.conf.channel->center_freq, 542 if (!ifmgd->associated)
505 ifmgd->ssid, ifmgd->ssid_len); 543 goto out;
506 if (!bss)
507 goto exit;
508 544
509 sdata->local->oper_channel = sdata->local->csa_channel; 545 sdata->local->oper_channel = sdata->local->csa_channel;
546 ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL);
547
510 /* XXX: shouldn't really modify cfg80211-owned data! */ 548 /* XXX: shouldn't really modify cfg80211-owned data! */
511 if (!ieee80211_hw_config(sdata->local, IEEE80211_CONF_CHANGE_CHANNEL)) 549 ifmgd->associated->cbss.channel = sdata->local->oper_channel;
512 bss->cbss.channel = sdata->local->oper_channel;
513 550
514 ieee80211_rx_bss_put(sdata->local, bss);
515exit:
516 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
517 ieee80211_wake_queues_by_reason(&sdata->local->hw, 551 ieee80211_wake_queues_by_reason(&sdata->local->hw,
518 IEEE80211_QUEUE_STOP_REASON_CSA); 552 IEEE80211_QUEUE_STOP_REASON_CSA);
553 out:
554 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
555 mutex_unlock(&ifmgd->mtx);
519} 556}
520 557
521static void ieee80211_chswitch_timer(unsigned long data) 558static void ieee80211_chswitch_timer(unsigned long data)
@@ -529,7 +566,7 @@ static void ieee80211_chswitch_timer(unsigned long data)
529 return; 566 return;
530 } 567 }
531 568
532 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work); 569 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
533} 570}
534 571
535void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, 572void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
@@ -540,10 +577,12 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
540 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 577 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
541 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num); 578 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num);
542 579
543 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATED) 580 ASSERT_MGD_MTX(ifmgd);
581
582 if (!ifmgd->associated)
544 return; 583 return;
545 584
546 if (sdata->local->sw_scanning || sdata->local->hw_scanning) 585 if (sdata->local->scanning)
547 return; 586 return;
548 587
549 /* Disregard subsequent beacons if we are already running a timer 588 /* Disregard subsequent beacons if we are already running a timer
@@ -559,7 +598,7 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
559 sdata->local->csa_channel = new_ch; 598 sdata->local->csa_channel = new_ch;
560 599
561 if (sw_elem->count <= 1) { 600 if (sw_elem->count <= 1) {
562 queue_work(sdata->local->hw.workqueue, &ifmgd->chswitch_work); 601 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
563 } else { 602 } else {
564 ieee80211_stop_queues_by_reason(&sdata->local->hw, 603 ieee80211_stop_queues_by_reason(&sdata->local->hw,
565 IEEE80211_QUEUE_STOP_REASON_CSA); 604 IEEE80211_QUEUE_STOP_REASON_CSA);
@@ -601,7 +640,7 @@ static void ieee80211_enable_ps(struct ieee80211_local *local,
601 * If we are scanning right now then the parameters will 640 * If we are scanning right now then the parameters will
602 * take effect when scan finishes. 641 * take effect when scan finishes.
603 */ 642 */
604 if (local->hw_scanning || local->sw_scanning) 643 if (local->scanning)
605 return; 644 return;
606 645
607 if (conf->dynamic_ps_timeout > 0 && 646 if (conf->dynamic_ps_timeout > 0 &&
@@ -651,8 +690,9 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
651 } 690 }
652 691
653 if (count == 1 && found->u.mgd.powersave && 692 if (count == 1 && found->u.mgd.powersave &&
654 (found->u.mgd.flags & IEEE80211_STA_ASSOCIATED) && 693 found->u.mgd.associated && list_empty(&found->u.mgd.work_list) &&
655 !(found->u.mgd.flags & IEEE80211_STA_PROBEREQ_POLL)) { 694 !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
695 IEEE80211_STA_CONNECTION_POLL))) {
656 s32 beaconint_us; 696 s32 beaconint_us;
657 697
658 if (latency < 0) 698 if (latency < 0)
@@ -724,7 +764,7 @@ void ieee80211_dynamic_ps_timer(unsigned long data)
724 if (local->quiescing || local->suspended) 764 if (local->quiescing || local->suspended)
725 return; 765 return;
726 766
727 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work); 767 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
728} 768}
729 769
730/* MLME */ 770/* MLME */
@@ -806,9 +846,6 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
806 u16 capab, bool erp_valid, u8 erp) 846 u16 capab, bool erp_valid, u8 erp)
807{ 847{
808 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; 848 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
809#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
810 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
811#endif
812 u32 changed = 0; 849 u32 changed = 0;
813 bool use_protection; 850 bool use_protection;
814 bool use_short_preamble; 851 bool use_short_preamble;
@@ -825,42 +862,16 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
825 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); 862 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
826 863
827 if (use_protection != bss_conf->use_cts_prot) { 864 if (use_protection != bss_conf->use_cts_prot) {
828#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
829 if (net_ratelimit()) {
830 printk(KERN_DEBUG "%s: CTS protection %s (BSSID=%pM)\n",
831 sdata->dev->name,
832 use_protection ? "enabled" : "disabled",
833 ifmgd->bssid);
834 }
835#endif
836 bss_conf->use_cts_prot = use_protection; 865 bss_conf->use_cts_prot = use_protection;
837 changed |= BSS_CHANGED_ERP_CTS_PROT; 866 changed |= BSS_CHANGED_ERP_CTS_PROT;
838 } 867 }
839 868
840 if (use_short_preamble != bss_conf->use_short_preamble) { 869 if (use_short_preamble != bss_conf->use_short_preamble) {
841#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
842 if (net_ratelimit()) {
843 printk(KERN_DEBUG "%s: switched to %s barker preamble"
844 " (BSSID=%pM)\n",
845 sdata->dev->name,
846 use_short_preamble ? "short" : "long",
847 ifmgd->bssid);
848 }
849#endif
850 bss_conf->use_short_preamble = use_short_preamble; 870 bss_conf->use_short_preamble = use_short_preamble;
851 changed |= BSS_CHANGED_ERP_PREAMBLE; 871 changed |= BSS_CHANGED_ERP_PREAMBLE;
852 } 872 }
853 873
854 if (use_short_slot != bss_conf->use_short_slot) { 874 if (use_short_slot != bss_conf->use_short_slot) {
855#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
856 if (net_ratelimit()) {
857 printk(KERN_DEBUG "%s: switched to %s slot time"
858 " (BSSID=%pM)\n",
859 sdata->dev->name,
860 use_short_slot ? "short" : "long",
861 ifmgd->bssid);
862 }
863#endif
864 bss_conf->use_short_slot = use_short_slot; 875 bss_conf->use_short_slot = use_short_slot;
865 changed |= BSS_CHANGED_ERP_SLOT; 876 changed |= BSS_CHANGED_ERP_SLOT;
866 } 877 }
@@ -868,105 +879,29 @@ static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
868 return changed; 879 return changed;
869} 880}
870 881
871static void ieee80211_sta_send_apinfo(struct ieee80211_sub_if_data *sdata)
872{
873 union iwreq_data wrqu;
874
875 memset(&wrqu, 0, sizeof(wrqu));
876 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)
877 memcpy(wrqu.ap_addr.sa_data, sdata->u.mgd.bssid, ETH_ALEN);
878 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
879 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL);
880}
881
882static void ieee80211_sta_send_associnfo(struct ieee80211_sub_if_data *sdata)
883{
884 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
885 char *buf;
886 size_t len;
887 int i;
888 union iwreq_data wrqu;
889
890 if (!ifmgd->assocreq_ies && !ifmgd->assocresp_ies)
891 return;
892
893 buf = kmalloc(50 + 2 * (ifmgd->assocreq_ies_len +
894 ifmgd->assocresp_ies_len), GFP_KERNEL);
895 if (!buf)
896 return;
897
898 len = sprintf(buf, "ASSOCINFO(");
899 if (ifmgd->assocreq_ies) {
900 len += sprintf(buf + len, "ReqIEs=");
901 for (i = 0; i < ifmgd->assocreq_ies_len; i++) {
902 len += sprintf(buf + len, "%02x",
903 ifmgd->assocreq_ies[i]);
904 }
905 }
906 if (ifmgd->assocresp_ies) {
907 if (ifmgd->assocreq_ies)
908 len += sprintf(buf + len, " ");
909 len += sprintf(buf + len, "RespIEs=");
910 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
911 len += sprintf(buf + len, "%02x",
912 ifmgd->assocresp_ies[i]);
913 }
914 }
915 len += sprintf(buf + len, ")");
916
917 if (len > IW_CUSTOM_MAX) {
918 len = sprintf(buf, "ASSOCRESPIE=");
919 for (i = 0; i < ifmgd->assocresp_ies_len; i++) {
920 len += sprintf(buf + len, "%02x",
921 ifmgd->assocresp_ies[i]);
922 }
923 }
924
925 if (len <= IW_CUSTOM_MAX) {
926 memset(&wrqu, 0, sizeof(wrqu));
927 wrqu.data.length = len;
928 wireless_send_event(sdata->dev, IWEVCUSTOM, &wrqu, buf);
929 }
930
931 kfree(buf);
932}
933
934
935static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, 882static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
883 struct ieee80211_bss *bss,
936 u32 bss_info_changed) 884 u32 bss_info_changed)
937{ 885{
938 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
939 struct ieee80211_local *local = sdata->local; 886 struct ieee80211_local *local = sdata->local;
940 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
941
942 struct ieee80211_bss *bss;
943 887
944 bss_info_changed |= BSS_CHANGED_ASSOC; 888 bss_info_changed |= BSS_CHANGED_ASSOC;
945 ifmgd->flags |= IEEE80211_STA_ASSOCIATED; 889 /* set timing information */
890 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
891 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
892 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
946 893
947 bss = ieee80211_rx_bss_get(local, ifmgd->bssid, 894 bss_info_changed |= BSS_CHANGED_BEACON_INT;
948 conf->channel->center_freq, 895 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
949 ifmgd->ssid, ifmgd->ssid_len); 896 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
950 if (bss) {
951 /* set timing information */
952 sdata->vif.bss_conf.beacon_int = bss->cbss.beacon_interval;
953 sdata->vif.bss_conf.timestamp = bss->cbss.tsf;
954 sdata->vif.bss_conf.dtim_period = bss->dtim_period;
955 897
956 bss_info_changed |= BSS_CHANGED_BEACON_INT; 898 sdata->u.mgd.associated = bss;
957 bss_info_changed |= ieee80211_handle_bss_capability(sdata, 899 memcpy(sdata->u.mgd.bssid, bss->cbss.bssid, ETH_ALEN);
958 bss->cbss.capability, bss->has_erp_value, bss->erp_value);
959 900
960 cfg80211_hold_bss(&bss->cbss); 901 /* just to be sure */
902 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
903 IEEE80211_STA_BEACON_POLL);
961 904
962 ieee80211_rx_bss_put(local, bss);
963 }
964
965 ifmgd->flags |= IEEE80211_STA_PREV_BSSID_SET;
966 memcpy(ifmgd->prev_bssid, sdata->u.mgd.bssid, ETH_ALEN);
967 ieee80211_sta_send_associnfo(sdata);
968
969 ifmgd->last_probe = jiffies;
970 ieee80211_led_assoc(local, 1); 905 ieee80211_led_assoc(local, 1);
971 906
972 sdata->vif.bss_conf.assoc = 1; 907 sdata->vif.bss_conf.assoc = 1;
@@ -982,176 +917,146 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
982 917
983 ieee80211_bss_info_change_notify(sdata, bss_info_changed); 918 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
984 919
985 /* will be same as sdata */ 920 mutex_lock(&local->iflist_mtx);
986 if (local->ps_sdata) { 921 ieee80211_recalc_ps(local, -1);
987 mutex_lock(&local->iflist_mtx); 922 mutex_unlock(&local->iflist_mtx);
988 ieee80211_recalc_ps(local, -1);
989 mutex_unlock(&local->iflist_mtx);
990 }
991 923
992 netif_tx_start_all_queues(sdata->dev); 924 netif_tx_start_all_queues(sdata->dev);
993 netif_carrier_on(sdata->dev); 925 netif_carrier_on(sdata->dev);
994
995 ieee80211_sta_send_apinfo(sdata);
996} 926}
997 927
998static void ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata) 928static enum rx_mgmt_action __must_check
929ieee80211_direct_probe(struct ieee80211_sub_if_data *sdata,
930 struct ieee80211_mgd_work *wk)
999{ 931{
1000 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 932 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1001 struct ieee80211_local *local = sdata->local; 933 struct ieee80211_local *local = sdata->local;
1002 934
1003 ifmgd->direct_probe_tries++; 935 wk->tries++;
1004 if (ifmgd->direct_probe_tries > IEEE80211_AUTH_MAX_TRIES) { 936 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
1005 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n", 937 printk(KERN_DEBUG "%s: direct probe to AP %pM timed out\n",
1006 sdata->dev->name, ifmgd->bssid); 938 sdata->dev->name, wk->bss->cbss.bssid);
1007 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1008 ieee80211_recalc_idle(local);
1009 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
1010 939
1011 /* 940 /*
1012 * Most likely AP is not in the range so remove the 941 * Most likely AP is not in the range so remove the
1013 * bss information associated to the AP 942 * bss struct for that AP.
1014 */ 943 */
1015 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 944 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1016 sdata->local->hw.conf.channel->center_freq,
1017 ifmgd->ssid, ifmgd->ssid_len);
1018 945
1019 /* 946 /*
1020 * We might have a pending scan which had no chance to run yet 947 * We might have a pending scan which had no chance to run yet
1021 * due to state == IEEE80211_STA_MLME_DIRECT_PROBE. 948 * due to work needing to be done. Hence, queue the STAs work
1022 * Hence, queue the STAs work again 949 * again for that.
1023 */ 950 */
1024 queue_work(local->hw.workqueue, &ifmgd->work); 951 ieee80211_queue_work(&local->hw, &ifmgd->work);
1025 return; 952 return RX_MGMT_CFG80211_AUTH_TO;
1026 } 953 }
1027 954
1028 printk(KERN_DEBUG "%s: direct probe to AP %pM try %d\n", 955 printk(KERN_DEBUG "%s: direct probe to AP %pM (try %d)\n",
1029 sdata->dev->name, ifmgd->bssid, 956 sdata->dev->name, wk->bss->cbss.bssid,
1030 ifmgd->direct_probe_tries); 957 wk->tries);
1031
1032 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
1033 958
1034 /* Direct probe is sent to broadcast address as some APs 959 /*
960 * Direct probe is sent to broadcast address as some APs
1035 * will not answer to direct packet in unassociated state. 961 * will not answer to direct packet in unassociated state.
1036 */ 962 */
1037 ieee80211_send_probe_req(sdata, NULL, 963 ieee80211_send_probe_req(sdata, NULL, wk->ssid, wk->ssid_len, NULL, 0);
1038 ifmgd->ssid, ifmgd->ssid_len, NULL, 0); 964
965 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
966 run_again(ifmgd, wk->timeout);
1039 967
1040 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); 968 return RX_MGMT_NONE;
1041} 969}
1042 970
1043 971
1044static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata) 972static enum rx_mgmt_action __must_check
973ieee80211_authenticate(struct ieee80211_sub_if_data *sdata,
974 struct ieee80211_mgd_work *wk)
1045{ 975{
1046 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 976 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1047 struct ieee80211_local *local = sdata->local; 977 struct ieee80211_local *local = sdata->local;
1048 u8 *ies;
1049 size_t ies_len;
1050 978
1051 ifmgd->auth_tries++; 979 wk->tries++;
1052 if (ifmgd->auth_tries > IEEE80211_AUTH_MAX_TRIES) { 980 if (wk->tries > IEEE80211_AUTH_MAX_TRIES) {
1053 printk(KERN_DEBUG "%s: authentication with AP %pM" 981 printk(KERN_DEBUG "%s: authentication with AP %pM"
1054 " timed out\n", 982 " timed out\n",
1055 sdata->dev->name, ifmgd->bssid); 983 sdata->dev->name, wk->bss->cbss.bssid);
1056 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 984
1057 ieee80211_recalc_idle(local); 985 /*
1058 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid); 986 * Most likely AP is not in the range so remove the
1059 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 987 * bss struct for that AP.
1060 sdata->local->hw.conf.channel->center_freq, 988 */
1061 ifmgd->ssid, ifmgd->ssid_len); 989 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1062 990
1063 /* 991 /*
1064 * We might have a pending scan which had no chance to run yet 992 * We might have a pending scan which had no chance to run yet
1065 * due to state == IEEE80211_STA_MLME_AUTHENTICATE. 993 * due to work needing to be done. Hence, queue the STAs work
1066 * Hence, queue the STAs work again 994 * again for that.
1067 */ 995 */
1068 queue_work(local->hw.workqueue, &ifmgd->work); 996 ieee80211_queue_work(&local->hw, &ifmgd->work);
1069 return; 997 return RX_MGMT_CFG80211_AUTH_TO;
1070 } 998 }
1071 999
1072 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; 1000 printk(KERN_DEBUG "%s: authenticate with AP %pM (try %d)\n",
1073 printk(KERN_DEBUG "%s: authenticate with AP %pM\n", 1001 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1074 sdata->dev->name, ifmgd->bssid);
1075 1002
1076 if (ifmgd->flags & IEEE80211_STA_EXT_SME) { 1003 ieee80211_send_auth(sdata, 1, wk->auth_alg, wk->ie, wk->ie_len,
1077 ies = ifmgd->sme_auth_ie; 1004 wk->bss->cbss.bssid, NULL, 0, 0);
1078 ies_len = ifmgd->sme_auth_ie_len; 1005 wk->auth_transaction = 2;
1079 } else {
1080 ies = NULL;
1081 ies_len = 0;
1082 }
1083 ieee80211_send_auth(sdata, 1, ifmgd->auth_alg, ies, ies_len,
1084 ifmgd->bssid, 0);
1085 ifmgd->auth_transaction = 2;
1086 1006
1087 mod_timer(&ifmgd->timer, jiffies + IEEE80211_AUTH_TIMEOUT); 1007 wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
1008 run_again(ifmgd, wk->timeout);
1009
1010 return RX_MGMT_NONE;
1088} 1011}
1089 1012
1090/* 1013static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata)
1091 * The disassoc 'reason' argument can be either our own reason
1092 * if self disconnected or a reason code from the AP.
1093 */
1094static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1095 bool deauth, bool self_disconnected,
1096 u16 reason)
1097{ 1014{
1098 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1015 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1099 struct ieee80211_local *local = sdata->local; 1016 struct ieee80211_local *local = sdata->local;
1100 struct ieee80211_conf *conf = &local_to_hw(local)->conf;
1101 struct ieee80211_bss *bss;
1102 struct sta_info *sta; 1017 struct sta_info *sta;
1103 u32 changed = 0, config_changed = 0; 1018 u32 changed = 0, config_changed = 0;
1019 u8 bssid[ETH_ALEN];
1104 1020
1105 if (deauth) { 1021 ASSERT_MGD_MTX(ifmgd);
1106 ifmgd->direct_probe_tries = 0; 1022
1107 ifmgd->auth_tries = 0; 1023 if (WARN_ON(!ifmgd->associated))
1108 } 1024 return;
1109 ifmgd->assoc_scan_tries = 0; 1025
1110 ifmgd->assoc_tries = 0; 1026 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN);
1027
1028 ifmgd->associated = NULL;
1029 memset(ifmgd->bssid, 0, ETH_ALEN);
1030
1031 /*
1032 * we need to commit the associated = NULL change because the
1033 * scan code uses that to determine whether this iface should
1034 * go to/wake up from powersave or not -- and could otherwise
1035 * wake the queues erroneously.
1036 */
1037 smp_mb();
1038
1039 /*
1040 * Thus, we can only afterwards stop the queues -- to account
1041 * for the case where another CPU is finishing a scan at this
1042 * time -- we don't want the scan code to enable queues.
1043 */
1111 1044
1112 netif_tx_stop_all_queues(sdata->dev); 1045 netif_tx_stop_all_queues(sdata->dev);
1113 netif_carrier_off(sdata->dev); 1046 netif_carrier_off(sdata->dev);
1114 1047
1115 rcu_read_lock(); 1048 rcu_read_lock();
1116 sta = sta_info_get(local, ifmgd->bssid); 1049 sta = sta_info_get(local, bssid);
1117 if (sta) 1050 if (sta)
1118 ieee80211_sta_tear_down_BA_sessions(sta); 1051 ieee80211_sta_tear_down_BA_sessions(sta);
1119 rcu_read_unlock(); 1052 rcu_read_unlock();
1120 1053
1121 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1122 conf->channel->center_freq,
1123 ifmgd->ssid, ifmgd->ssid_len);
1124
1125 if (bss) {
1126 cfg80211_unhold_bss(&bss->cbss);
1127 ieee80211_rx_bss_put(local, bss);
1128 }
1129
1130 if (self_disconnected) {
1131 if (deauth)
1132 ieee80211_send_deauth_disassoc(sdata,
1133 IEEE80211_STYPE_DEAUTH, reason);
1134 else
1135 ieee80211_send_deauth_disassoc(sdata,
1136 IEEE80211_STYPE_DISASSOC, reason);
1137 }
1138
1139 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
1140 changed |= ieee80211_reset_erp_info(sdata); 1054 changed |= ieee80211_reset_erp_info(sdata);
1141 1055
1142 ieee80211_led_assoc(local, 0); 1056 ieee80211_led_assoc(local, 0);
1143 changed |= BSS_CHANGED_ASSOC; 1057 changed |= BSS_CHANGED_ASSOC;
1144 sdata->vif.bss_conf.assoc = false; 1058 sdata->vif.bss_conf.assoc = false;
1145 1059
1146 ieee80211_sta_send_apinfo(sdata);
1147
1148 if (self_disconnected || reason == WLAN_REASON_DISASSOC_STA_HAS_LEFT) {
1149 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1150 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
1151 sdata->local->hw.conf.channel->center_freq,
1152 ifmgd->ssid, ifmgd->ssid_len);
1153 }
1154
1155 ieee80211_set_wmm_default(sdata); 1060 ieee80211_set_wmm_default(sdata);
1156 1061
1157 ieee80211_recalc_idle(local); 1062 ieee80211_recalc_idle(local);
@@ -1180,7 +1085,7 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1180 1085
1181 rcu_read_lock(); 1086 rcu_read_lock();
1182 1087
1183 sta = sta_info_get(local, ifmgd->bssid); 1088 sta = sta_info_get(local, bssid);
1184 if (!sta) { 1089 if (!sta) {
1185 rcu_read_unlock(); 1090 rcu_read_unlock();
1186 return; 1091 return;
@@ -1193,83 +1098,42 @@ static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
1193 sta_info_destroy(sta); 1098 sta_info_destroy(sta);
1194} 1099}
1195 1100
1196static int ieee80211_sta_wep_configured(struct ieee80211_sub_if_data *sdata) 1101static enum rx_mgmt_action __must_check
1197{ 1102ieee80211_associate(struct ieee80211_sub_if_data *sdata,
1198 if (!sdata || !sdata->default_key || 1103 struct ieee80211_mgd_work *wk)
1199 sdata->default_key->conf.alg != ALG_WEP)
1200 return 0;
1201 return 1;
1202}
1203
1204static int ieee80211_privacy_mismatch(struct ieee80211_sub_if_data *sdata)
1205{ 1104{
1206 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1105 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1207 struct ieee80211_local *local = sdata->local; 1106 struct ieee80211_local *local = sdata->local;
1208 struct ieee80211_bss *bss;
1209 int bss_privacy;
1210 int wep_privacy;
1211 int privacy_invoked;
1212
1213 if (!ifmgd || (ifmgd->flags & IEEE80211_STA_EXT_SME))
1214 return 0;
1215
1216 bss = ieee80211_rx_bss_get(local, ifmgd->bssid,
1217 local->hw.conf.channel->center_freq,
1218 ifmgd->ssid, ifmgd->ssid_len);
1219 if (!bss)
1220 return 0;
1221
1222 bss_privacy = !!(bss->cbss.capability & WLAN_CAPABILITY_PRIVACY);
1223 wep_privacy = !!ieee80211_sta_wep_configured(sdata);
1224 privacy_invoked = !!(ifmgd->flags & IEEE80211_STA_PRIVACY_INVOKED);
1225
1226 ieee80211_rx_bss_put(local, bss);
1227
1228 if ((bss_privacy == wep_privacy) || (bss_privacy == privacy_invoked))
1229 return 0;
1230 1107
1231 return 1; 1108 wk->tries++;
1232} 1109 if (wk->tries > IEEE80211_ASSOC_MAX_TRIES) {
1233
1234static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
1235{
1236 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1237 struct ieee80211_local *local = sdata->local;
1238
1239 ifmgd->assoc_tries++;
1240 if (ifmgd->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
1241 printk(KERN_DEBUG "%s: association with AP %pM" 1110 printk(KERN_DEBUG "%s: association with AP %pM"
1242 " timed out\n", 1111 " timed out\n",
1243 sdata->dev->name, ifmgd->bssid); 1112 sdata->dev->name, wk->bss->cbss.bssid);
1244 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1113
1245 ieee80211_recalc_idle(local); 1114 /*
1246 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid); 1115 * Most likely AP is not in the range so remove the
1247 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1116 * bss struct for that AP.
1248 sdata->local->hw.conf.channel->center_freq, 1117 */
1249 ifmgd->ssid, ifmgd->ssid_len); 1118 cfg80211_unlink_bss(local->hw.wiphy, &wk->bss->cbss);
1119
1250 /* 1120 /*
1251 * We might have a pending scan which had no chance to run yet 1121 * We might have a pending scan which had no chance to run yet
1252 * due to state == IEEE80211_STA_MLME_ASSOCIATE. 1122 * due to work needing to be done. Hence, queue the STAs work
1253 * Hence, queue the STAs work again 1123 * again for that.
1254 */ 1124 */
1255 queue_work(local->hw.workqueue, &ifmgd->work); 1125 ieee80211_queue_work(&local->hw, &ifmgd->work);
1256 return; 1126 return RX_MGMT_CFG80211_ASSOC_TO;
1257 } 1127 }
1258 1128
1259 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; 1129 printk(KERN_DEBUG "%s: associate with AP %pM (try %d)\n",
1260 printk(KERN_DEBUG "%s: associate with AP %pM\n", 1130 sdata->dev->name, wk->bss->cbss.bssid, wk->tries);
1261 sdata->dev->name, ifmgd->bssid); 1131 ieee80211_send_assoc(sdata, wk);
1262 if (ieee80211_privacy_mismatch(sdata)) {
1263 printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
1264 "mixed-cell disabled - abort association\n", sdata->dev->name);
1265 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1266 ieee80211_recalc_idle(local);
1267 return;
1268 }
1269 1132
1270 ieee80211_send_assoc(sdata); 1133 wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
1134 run_again(ifmgd, wk->timeout);
1271 1135
1272 mod_timer(&ifmgd->timer, jiffies + IEEE80211_ASSOC_TIMEOUT); 1136 return RX_MGMT_NONE;
1273} 1137}
1274 1138
1275void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, 1139void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1280,160 +1144,113 @@ void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
1280 * from AP because we know that the connection is working both ways 1144 * from AP because we know that the connection is working both ways
1281 * at that time. But multicast frames (and hence also beacons) must 1145 * at that time. But multicast frames (and hence also beacons) must
1282 * be ignored here, because we need to trigger the timer during 1146 * be ignored here, because we need to trigger the timer during
1283 * data idle periods for sending the periodical probe request to 1147 * data idle periods for sending the periodic probe request to the
1284 * the AP. 1148 * AP we're connected to.
1285 */ 1149 */
1286 if (!is_multicast_ether_addr(hdr->addr1)) 1150 if (is_multicast_ether_addr(hdr->addr1))
1287 mod_timer(&sdata->u.mgd.timer,
1288 jiffies + IEEE80211_MONITORING_INTERVAL);
1289}
1290
1291void ieee80211_beacon_loss_work(struct work_struct *work)
1292{
1293 struct ieee80211_sub_if_data *sdata =
1294 container_of(work, struct ieee80211_sub_if_data,
1295 u.mgd.beacon_loss_work);
1296 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1297
1298 /*
1299 * The driver has already reported this event and we have
1300 * already sent a probe request. Maybe the AP died and the
1301 * driver keeps reporting until we disassociate... We have
1302 * to ignore that because otherwise we would continually
1303 * reset the timer and never check whether we received a
1304 * probe response!
1305 */
1306 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL)
1307 return; 1151 return;
1308 1152
1309#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1153 mod_timer(&sdata->u.mgd.conn_mon_timer,
1310 if (net_ratelimit()) { 1154 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
1311 printk(KERN_DEBUG "%s: driver reports beacon loss from AP %pM "
1312 "- sending probe request\n", sdata->dev->name,
1313 sdata->u.mgd.bssid);
1314 }
1315#endif
1316
1317 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1318
1319 mutex_lock(&sdata->local->iflist_mtx);
1320 ieee80211_recalc_ps(sdata->local, -1);
1321 mutex_unlock(&sdata->local->iflist_mtx);
1322
1323 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1324 ifmgd->ssid_len, NULL, 0);
1325
1326 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
1327} 1155}
1328 1156
1329void ieee80211_beacon_loss(struct ieee80211_vif *vif) 1157static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
1330{ 1158{
1331 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 1159 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1160 const u8 *ssid;
1161
1162 ssid = ieee80211_bss_get_ie(&ifmgd->associated->cbss, WLAN_EID_SSID);
1163 ieee80211_send_probe_req(sdata, ifmgd->associated->cbss.bssid,
1164 ssid + 2, ssid[1], NULL, 0);
1332 1165
1333 queue_work(sdata->local->hw.workqueue, 1166 ifmgd->probe_send_count++;
1334 &sdata->u.mgd.beacon_loss_work); 1167 ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT;
1168 run_again(ifmgd, ifmgd->probe_timeout);
1335} 1169}
1336EXPORT_SYMBOL(ieee80211_beacon_loss);
1337 1170
1338static void ieee80211_associated(struct ieee80211_sub_if_data *sdata) 1171static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1172 bool beacon)
1339{ 1173{
1340 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1174 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1341 struct ieee80211_local *local = sdata->local; 1175 bool already = false;
1342 struct sta_info *sta;
1343 unsigned long last_rx;
1344 bool disassoc = false;
1345 1176
1346 /* TODO: start monitoring current AP signal quality and number of 1177 if (!netif_running(sdata->dev))
1347 * missed beacons. Scan other channels every now and then and search 1178 return;
1348 * for better APs. */
1349 /* TODO: remove expired BSSes */
1350 1179
1351 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATED; 1180 if (sdata->local->scanning)
1181 return;
1352 1182
1353 rcu_read_lock(); 1183 mutex_lock(&ifmgd->mtx);
1354 1184
1355 sta = sta_info_get(local, ifmgd->bssid); 1185 if (!ifmgd->associated)
1356 if (!sta) {
1357 printk(KERN_DEBUG "%s: No STA entry for own AP %pM\n",
1358 sdata->dev->name, ifmgd->bssid);
1359 disassoc = true;
1360 rcu_read_unlock();
1361 goto out; 1186 goto out;
1362 }
1363 1187
1364 last_rx = sta->last_rx; 1188#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1365 rcu_read_unlock(); 1189 if (beacon && net_ratelimit())
1366 1190 printk(KERN_DEBUG "%s: detected beacon loss from AP "
1367 if ((ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) && 1191 "- sending probe request\n", sdata->dev->name);
1368 time_after(jiffies, last_rx + IEEE80211_PROBE_WAIT)) { 1192#endif
1369 printk(KERN_DEBUG "%s: no probe response from AP %pM "
1370 "- disassociating\n",
1371 sdata->dev->name, ifmgd->bssid);
1372 disassoc = true;
1373 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1374 goto out;
1375 }
1376 1193
1377 /* 1194 /*
1378 * Beacon filtering is only enabled with power save and then the 1195 * The driver/our work has already reported this event or the
1379 * stack should not check for beacon loss. 1196 * connection monitoring has kicked in and we have already sent
1197 * a probe request. Or maybe the AP died and the driver keeps
1198 * reporting until we disassociate...
1199 *
1200 * In either case we have to ignore the current call to this
1201 * function (except for setting the correct probe reason bit)
1202 * because otherwise we would reset the timer every time and
1203 * never check whether we received a probe response!
1380 */ 1204 */
1381 if (!((local->hw.flags & IEEE80211_HW_BEACON_FILTER) && 1205 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1382 (local->hw.conf.flags & IEEE80211_CONF_PS)) && 1206 IEEE80211_STA_CONNECTION_POLL))
1383 time_after(jiffies, 1207 already = true;
1384 ifmgd->last_beacon + IEEE80211_MONITORING_INTERVAL)) { 1208
1385#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1209 if (beacon)
1386 if (net_ratelimit()) { 1210 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
1387 printk(KERN_DEBUG "%s: beacon loss from AP %pM " 1211 else
1388 "- sending probe request\n", 1212 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
1389 sdata->dev->name, ifmgd->bssid); 1213
1390 } 1214 if (already)
1391#endif
1392 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL;
1393 mutex_lock(&local->iflist_mtx);
1394 ieee80211_recalc_ps(local, -1);
1395 mutex_unlock(&local->iflist_mtx);
1396 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1397 ifmgd->ssid_len, NULL, 0);
1398 mod_timer(&ifmgd->timer, jiffies + IEEE80211_PROBE_WAIT);
1399 goto out; 1215 goto out;
1400 }
1401 1216
1402 if (time_after(jiffies, last_rx + IEEE80211_PROBE_IDLE_TIME)) { 1217 mutex_lock(&sdata->local->iflist_mtx);
1403 ifmgd->flags |= IEEE80211_STA_PROBEREQ_POLL; 1218 ieee80211_recalc_ps(sdata->local, -1);
1404 mutex_lock(&local->iflist_mtx); 1219 mutex_unlock(&sdata->local->iflist_mtx);
1405 ieee80211_recalc_ps(local, -1);
1406 mutex_unlock(&local->iflist_mtx);
1407 ieee80211_send_probe_req(sdata, ifmgd->bssid, ifmgd->ssid,
1408 ifmgd->ssid_len, NULL, 0);
1409 }
1410 1220
1221 ifmgd->probe_send_count = 0;
1222 ieee80211_mgd_probe_ap_send(sdata);
1411 out: 1223 out:
1412 if (!disassoc) 1224 mutex_unlock(&ifmgd->mtx);
1413 mod_timer(&ifmgd->timer,
1414 jiffies + IEEE80211_MONITORING_INTERVAL);
1415 else
1416 ieee80211_set_disassoc(sdata, true, true,
1417 WLAN_REASON_PREV_AUTH_NOT_VALID);
1418} 1225}
1419 1226
1227void ieee80211_beacon_loss_work(struct work_struct *work)
1228{
1229 struct ieee80211_sub_if_data *sdata =
1230 container_of(work, struct ieee80211_sub_if_data,
1231 u.mgd.beacon_loss_work);
1420 1232
1421static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata) 1233 ieee80211_mgd_probe_ap(sdata, true);
1234}
1235
1236void ieee80211_beacon_loss(struct ieee80211_vif *vif)
1422{ 1237{
1423 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1238 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
1424 1239
1240 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work);
1241}
1242EXPORT_SYMBOL(ieee80211_beacon_loss);
1243
1244static void ieee80211_auth_completed(struct ieee80211_sub_if_data *sdata,
1245 struct ieee80211_mgd_work *wk)
1246{
1247 wk->state = IEEE80211_MGD_STATE_IDLE;
1425 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name); 1248 printk(KERN_DEBUG "%s: authenticated\n", sdata->dev->name);
1426 ifmgd->flags |= IEEE80211_STA_AUTHENTICATED;
1427 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1428 /* Wait for SME to request association */
1429 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1430 ieee80211_recalc_idle(sdata->local);
1431 } else
1432 ieee80211_associate(sdata);
1433} 1249}
1434 1250
1435 1251
1436static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, 1252static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1253 struct ieee80211_mgd_work *wk,
1437 struct ieee80211_mgmt *mgmt, 1254 struct ieee80211_mgmt *mgmt,
1438 size_t len) 1255 size_t len)
1439{ 1256{
@@ -1444,161 +1261,133 @@ static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
1444 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 1261 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
1445 if (!elems.challenge) 1262 if (!elems.challenge)
1446 return; 1263 return;
1447 ieee80211_send_auth(sdata, 3, sdata->u.mgd.auth_alg, 1264 ieee80211_send_auth(sdata, 3, wk->auth_alg,
1448 elems.challenge - 2, elems.challenge_len + 2, 1265 elems.challenge - 2, elems.challenge_len + 2,
1449 sdata->u.mgd.bssid, 1); 1266 wk->bss->cbss.bssid,
1450 sdata->u.mgd.auth_transaction = 4; 1267 wk->key, wk->key_len, wk->key_idx);
1268 wk->auth_transaction = 4;
1451} 1269}
1452 1270
1453static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, 1271static enum rx_mgmt_action __must_check
1454 struct ieee80211_mgmt *mgmt, 1272ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1455 size_t len) 1273 struct ieee80211_mgd_work *wk,
1274 struct ieee80211_mgmt *mgmt, size_t len)
1456{ 1275{
1457 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1458 u16 auth_alg, auth_transaction, status_code; 1276 u16 auth_alg, auth_transaction, status_code;
1459 1277
1460 if (ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE) 1278 if (wk->state != IEEE80211_MGD_STATE_AUTH)
1461 return; 1279 return RX_MGMT_NONE;
1462 1280
1463 if (len < 24 + 6) 1281 if (len < 24 + 6)
1464 return; 1282 return RX_MGMT_NONE;
1465 1283
1466 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) 1284 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1467 return; 1285 return RX_MGMT_NONE;
1468 1286
1469 if (memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1287 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1470 return; 1288 return RX_MGMT_NONE;
1471 1289
1472 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); 1290 auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
1473 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); 1291 auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
1474 status_code = le16_to_cpu(mgmt->u.auth.status_code); 1292 status_code = le16_to_cpu(mgmt->u.auth.status_code);
1475 1293
1476 if (auth_alg != ifmgd->auth_alg || 1294 if (auth_alg != wk->auth_alg ||
1477 auth_transaction != ifmgd->auth_transaction) 1295 auth_transaction != wk->auth_transaction)
1478 return; 1296 return RX_MGMT_NONE;
1479 1297
1480 if (status_code != WLAN_STATUS_SUCCESS) { 1298 if (status_code != WLAN_STATUS_SUCCESS) {
1481 if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) { 1299 list_del(&wk->list);
1482 u8 algs[3]; 1300 kfree(wk);
1483 const int num_algs = ARRAY_SIZE(algs); 1301 return RX_MGMT_CFG80211_AUTH;
1484 int i, pos;
1485 algs[0] = algs[1] = algs[2] = 0xff;
1486 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN)
1487 algs[0] = WLAN_AUTH_OPEN;
1488 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
1489 algs[1] = WLAN_AUTH_SHARED_KEY;
1490 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP)
1491 algs[2] = WLAN_AUTH_LEAP;
1492 if (ifmgd->auth_alg == WLAN_AUTH_OPEN)
1493 pos = 0;
1494 else if (ifmgd->auth_alg == WLAN_AUTH_SHARED_KEY)
1495 pos = 1;
1496 else
1497 pos = 2;
1498 for (i = 0; i < num_algs; i++) {
1499 pos++;
1500 if (pos >= num_algs)
1501 pos = 0;
1502 if (algs[pos] == ifmgd->auth_alg ||
1503 algs[pos] == 0xff)
1504 continue;
1505 if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
1506 !ieee80211_sta_wep_configured(sdata))
1507 continue;
1508 ifmgd->auth_alg = algs[pos];
1509 break;
1510 }
1511 }
1512 return;
1513 } 1302 }
1514 1303
1515 switch (ifmgd->auth_alg) { 1304 switch (wk->auth_alg) {
1516 case WLAN_AUTH_OPEN: 1305 case WLAN_AUTH_OPEN:
1517 case WLAN_AUTH_LEAP: 1306 case WLAN_AUTH_LEAP:
1518 case WLAN_AUTH_FT: 1307 case WLAN_AUTH_FT:
1519 ieee80211_auth_completed(sdata); 1308 ieee80211_auth_completed(sdata, wk);
1520 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); 1309 return RX_MGMT_CFG80211_AUTH;
1521 break;
1522 case WLAN_AUTH_SHARED_KEY: 1310 case WLAN_AUTH_SHARED_KEY:
1523 if (ifmgd->auth_transaction == 4) { 1311 if (wk->auth_transaction == 4) {
1524 ieee80211_auth_completed(sdata); 1312 ieee80211_auth_completed(sdata, wk);
1525 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len); 1313 return RX_MGMT_CFG80211_AUTH;
1526 } else 1314 } else
1527 ieee80211_auth_challenge(sdata, mgmt, len); 1315 ieee80211_auth_challenge(sdata, wk, mgmt, len);
1528 break; 1316 break;
1529 } 1317 }
1318
1319 return RX_MGMT_NONE;
1530} 1320}
1531 1321
1532 1322
1533static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, 1323static enum rx_mgmt_action __must_check
1534 struct ieee80211_mgmt *mgmt, 1324ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1535 size_t len) 1325 struct ieee80211_mgd_work *wk,
1326 struct ieee80211_mgmt *mgmt, size_t len)
1536{ 1327{
1537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1328 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1329 const u8 *bssid = NULL;
1538 u16 reason_code; 1330 u16 reason_code;
1539 1331
1540 if (len < 24 + 2) 1332 if (len < 24 + 2)
1541 return; 1333 return RX_MGMT_NONE;
1542 1334
1543 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) 1335 ASSERT_MGD_MTX(ifmgd);
1544 return; 1336
1337 if (wk)
1338 bssid = wk->bss->cbss.bssid;
1339 else
1340 bssid = ifmgd->associated->cbss.bssid;
1545 1341
1546 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 1342 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1547 1343
1548 if (ifmgd->flags & IEEE80211_STA_AUTHENTICATED) 1344 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
1549 printk(KERN_DEBUG "%s: deauthenticated (Reason: %u)\n", 1345 sdata->dev->name, bssid, reason_code);
1550 sdata->dev->name, reason_code);
1551 1346
1552 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && 1347 if (!wk) {
1553 (ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE || 1348 ieee80211_set_disassoc(sdata);
1554 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE || 1349 } else {
1555 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)) { 1350 list_del(&wk->list);
1556 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE; 1351 kfree(wk);
1557 mod_timer(&ifmgd->timer, jiffies +
1558 IEEE80211_RETRY_AUTH_INTERVAL);
1559 } 1352 }
1560 1353
1561 ieee80211_set_disassoc(sdata, true, false, 0); 1354 return RX_MGMT_CFG80211_DEAUTH;
1562 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1563 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1564} 1355}
1565 1356
1566 1357
1567static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, 1358static enum rx_mgmt_action __must_check
1568 struct ieee80211_mgmt *mgmt, 1359ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1569 size_t len) 1360 struct ieee80211_mgmt *mgmt, size_t len)
1570{ 1361{
1571 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1362 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1572 u16 reason_code; 1363 u16 reason_code;
1573 1364
1574 if (len < 24 + 2) 1365 if (len < 24 + 2)
1575 return; 1366 return RX_MGMT_NONE;
1576 1367
1577 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN)) 1368 ASSERT_MGD_MTX(ifmgd);
1578 return;
1579 1369
1580 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1370 if (WARN_ON(!ifmgd->associated))
1371 return RX_MGMT_NONE;
1581 1372
1582 if (ifmgd->flags & IEEE80211_STA_ASSOCIATED) 1373 if (WARN_ON(memcmp(ifmgd->associated->cbss.bssid, mgmt->sa, ETH_ALEN)))
1583 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n", 1374 return RX_MGMT_NONE;
1584 sdata->dev->name, reason_code);
1585 1375
1586 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && 1376 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1587 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED) { 1377
1588 ifmgd->state = IEEE80211_STA_MLME_ASSOCIATE; 1378 printk(KERN_DEBUG "%s: disassociated (Reason: %u)\n",
1589 mod_timer(&ifmgd->timer, jiffies + 1379 sdata->dev->name, reason_code);
1590 IEEE80211_RETRY_AUTH_INTERVAL);
1591 }
1592 1380
1593 ieee80211_set_disassoc(sdata, false, false, reason_code); 1381 ieee80211_set_disassoc(sdata);
1594 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len); 1382 return RX_MGMT_CFG80211_DISASSOC;
1595} 1383}
1596 1384
1597 1385
1598static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, 1386static enum rx_mgmt_action __must_check
1599 struct ieee80211_mgmt *mgmt, 1387ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1600 size_t len, 1388 struct ieee80211_mgd_work *wk,
1601 int reassoc) 1389 struct ieee80211_mgmt *mgmt, size_t len,
1390 bool reassoc)
1602{ 1391{
1603 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 1392 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1604 struct ieee80211_local *local = sdata->local; 1393 struct ieee80211_local *local = sdata->local;
@@ -1614,17 +1403,16 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1614 bool have_higher_than_11mbit = false, newsta = false; 1403 bool have_higher_than_11mbit = false, newsta = false;
1615 u16 ap_ht_cap_flags; 1404 u16 ap_ht_cap_flags;
1616 1405
1617 /* AssocResp and ReassocResp have identical structure, so process both 1406 /*
1618 * of them in this function. */ 1407 * AssocResp and ReassocResp have identical structure, so process both
1619 1408 * of them in this function.
1620 if (ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) 1409 */
1621 return;
1622 1410
1623 if (len < 24 + 6) 1411 if (len < 24 + 6)
1624 return; 1412 return RX_MGMT_NONE;
1625 1413
1626 if (memcmp(ifmgd->bssid, mgmt->sa, ETH_ALEN) != 0) 1414 if (memcmp(wk->bss->cbss.bssid, mgmt->sa, ETH_ALEN) != 0)
1627 return; 1415 return RX_MGMT_NONE;
1628 1416
1629 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 1417 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
1630 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 1418 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
@@ -1647,26 +1435,18 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1647 printk(KERN_DEBUG "%s: AP rejected association temporarily; " 1435 printk(KERN_DEBUG "%s: AP rejected association temporarily; "
1648 "comeback duration %u TU (%u ms)\n", 1436 "comeback duration %u TU (%u ms)\n",
1649 sdata->dev->name, tu, ms); 1437 sdata->dev->name, tu, ms);
1438 wk->timeout = jiffies + msecs_to_jiffies(ms);
1650 if (ms > IEEE80211_ASSOC_TIMEOUT) 1439 if (ms > IEEE80211_ASSOC_TIMEOUT)
1651 mod_timer(&ifmgd->timer, 1440 run_again(ifmgd, jiffies + msecs_to_jiffies(ms));
1652 jiffies + msecs_to_jiffies(ms)); 1441 return RX_MGMT_NONE;
1653 return;
1654 } 1442 }
1655 1443
1656 if (status_code != WLAN_STATUS_SUCCESS) { 1444 if (status_code != WLAN_STATUS_SUCCESS) {
1657 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n", 1445 printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
1658 sdata->dev->name, status_code); 1446 sdata->dev->name, status_code);
1659 /* if this was a reassociation, ensure we try a "full" 1447 list_del(&wk->list);
1660 * association next time. This works around some broken APs 1448 kfree(wk);
1661 * which do not correctly reject reassociation requests. */ 1449 return RX_MGMT_CFG80211_ASSOC;
1662 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1663 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1664 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1665 /* Wait for SME to decide what to do next */
1666 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1667 ieee80211_recalc_idle(local);
1668 }
1669 return;
1670 } 1450 }
1671 1451
1672 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1452 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
@@ -1677,51 +1457,35 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1677 if (!elems.supp_rates) { 1457 if (!elems.supp_rates) {
1678 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 1458 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
1679 sdata->dev->name); 1459 sdata->dev->name);
1680 return; 1460 return RX_MGMT_NONE;
1681 } 1461 }
1682 1462
1683 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name); 1463 printk(KERN_DEBUG "%s: associated\n", sdata->dev->name);
1684 ifmgd->aid = aid; 1464 ifmgd->aid = aid;
1685 ifmgd->ap_capab = capab_info;
1686
1687 kfree(ifmgd->assocresp_ies);
1688 ifmgd->assocresp_ies_len = len - (pos - (u8 *) mgmt);
1689 ifmgd->assocresp_ies = kmalloc(ifmgd->assocresp_ies_len, GFP_KERNEL);
1690 if (ifmgd->assocresp_ies)
1691 memcpy(ifmgd->assocresp_ies, pos, ifmgd->assocresp_ies_len);
1692 1465
1693 rcu_read_lock(); 1466 rcu_read_lock();
1694 1467
1695 /* Add STA entry for the AP */ 1468 /* Add STA entry for the AP */
1696 sta = sta_info_get(local, ifmgd->bssid); 1469 sta = sta_info_get(local, wk->bss->cbss.bssid);
1697 if (!sta) { 1470 if (!sta) {
1698 newsta = true; 1471 newsta = true;
1699 1472
1700 sta = sta_info_alloc(sdata, ifmgd->bssid, GFP_ATOMIC); 1473 rcu_read_unlock();
1474
1475 sta = sta_info_alloc(sdata, wk->bss->cbss.bssid, GFP_KERNEL);
1701 if (!sta) { 1476 if (!sta) {
1702 printk(KERN_DEBUG "%s: failed to alloc STA entry for" 1477 printk(KERN_DEBUG "%s: failed to alloc STA entry for"
1703 " the AP\n", sdata->dev->name); 1478 " the AP\n", sdata->dev->name);
1704 rcu_read_unlock(); 1479 return RX_MGMT_NONE;
1705 return;
1706 } 1480 }
1707 1481
1708 /* update new sta with its last rx activity */ 1482 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC |
1709 sta->last_rx = jiffies; 1483 WLAN_STA_ASSOC_AP);
1710 } 1484 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1485 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1711 1486
1712 /* 1487 rcu_read_lock();
1713 * FIXME: Do we really need to update the sta_info's information here? 1488 }
1714 * We already know about the AP (we found it in our list) so it
1715 * should already be filled with the right info, no?
1716 * As is stands, all this is racy because typically we assume
1717 * the information that is filled in here (except flags) doesn't
1718 * change while a STA structure is alive. As such, it should move
1719 * to between the sta_info_alloc() and sta_info_insert() above.
1720 */
1721
1722 set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_AP);
1723 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
1724 set_sta_flags(sta, WLAN_STA_AUTHORIZED);
1725 1489
1726 rates = 0; 1490 rates = 0;
1727 basic_rates = 0; 1491 basic_rates = 0;
@@ -1771,8 +1535,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1771 else 1535 else
1772 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; 1536 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
1773 1537
1774 /* If TKIP/WEP is used, no need to parse AP's HT capabilities */ 1538 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1775 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED))
1776 ieee80211_ht_cap_ie_to_sta_ht_cap(sband, 1539 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
1777 elems.ht_cap_elem, &sta->sta.ht_cap); 1540 elems.ht_cap_elem, &sta->sta.ht_cap);
1778 1541
@@ -1792,7 +1555,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1792 printk(KERN_DEBUG "%s: failed to insert STA entry for" 1555 printk(KERN_DEBUG "%s: failed to insert STA entry for"
1793 " the AP (error %d)\n", sdata->dev->name, err); 1556 " the AP (error %d)\n", sdata->dev->name, err);
1794 rcu_read_unlock(); 1557 rcu_read_unlock();
1795 return; 1558 return RX_MGMT_NONE;
1796 } 1559 }
1797 } 1560 }
1798 1561
@@ -1806,24 +1569,29 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1806 1569
1807 if (elems.ht_info_elem && elems.wmm_param && 1570 if (elems.ht_info_elem && elems.wmm_param &&
1808 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) && 1571 (ifmgd->flags & IEEE80211_STA_WMM_ENABLED) &&
1809 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) 1572 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
1810 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1573 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
1574 wk->bss->cbss.bssid,
1811 ap_ht_cap_flags); 1575 ap_ht_cap_flags);
1812 1576
1577 /* delete work item -- must be before set_associated for PS */
1578 list_del(&wk->list);
1579
1813 /* set AID and assoc capability, 1580 /* set AID and assoc capability,
1814 * ieee80211_set_associated() will tell the driver */ 1581 * ieee80211_set_associated() will tell the driver */
1815 bss_conf->aid = aid; 1582 bss_conf->aid = aid;
1816 bss_conf->assoc_capability = capab_info; 1583 bss_conf->assoc_capability = capab_info;
1817 ieee80211_set_associated(sdata, changed); 1584 ieee80211_set_associated(sdata, wk->bss, changed);
1818 1585
1819 /* 1586 /*
1820 * initialise the time of last beacon to be the association time, 1587 * Start timer to probe the connection to the AP now.
1821 * otherwise beacon loss check will trigger immediately 1588 * Also start the timer that will detect beacon loss.
1822 */ 1589 */
1823 ifmgd->last_beacon = jiffies; 1590 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
1591 mod_beacon_timer(sdata);
1824 1592
1825 ieee80211_associated(sdata); 1593 kfree(wk);
1826 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len); 1594 return RX_MGMT_CFG80211_ASSOC;
1827} 1595}
1828 1596
1829 1597
@@ -1851,23 +1619,25 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
1851 1619
1852 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, 1620 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
1853 channel, beacon); 1621 channel, beacon);
1854 if (!bss) 1622 if (bss)
1623 ieee80211_rx_bss_put(local, bss);
1624
1625 if (!sdata->u.mgd.associated)
1855 return; 1626 return;
1856 1627
1857 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && 1628 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
1858 (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN) == 0)) { 1629 (memcmp(mgmt->bssid, sdata->u.mgd.associated->cbss.bssid,
1630 ETH_ALEN) == 0)) {
1859 struct ieee80211_channel_sw_ie *sw_elem = 1631 struct ieee80211_channel_sw_ie *sw_elem =
1860 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; 1632 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
1861 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss); 1633 ieee80211_sta_process_chanswitch(sdata, sw_elem, bss);
1862 } 1634 }
1863
1864 ieee80211_rx_bss_put(local, bss);
1865} 1635}
1866 1636
1867 1637
1868static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, 1638static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1869 struct ieee80211_mgmt *mgmt, 1639 struct ieee80211_mgd_work *wk,
1870 size_t len, 1640 struct ieee80211_mgmt *mgmt, size_t len,
1871 struct ieee80211_rx_status *rx_status) 1641 struct ieee80211_rx_status *rx_status)
1872{ 1642{
1873 struct ieee80211_if_managed *ifmgd; 1643 struct ieee80211_if_managed *ifmgd;
@@ -1876,6 +1646,8 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1876 1646
1877 ifmgd = &sdata->u.mgd; 1647 ifmgd = &sdata->u.mgd;
1878 1648
1649 ASSERT_MGD_MTX(ifmgd);
1650
1879 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) 1651 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
1880 return; /* ignore ProbeResp to foreign address */ 1652 return; /* ignore ProbeResp to foreign address */
1881 1653
@@ -1889,17 +1661,32 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1889 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); 1661 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
1890 1662
1891 /* direct probe may be part of the association flow */ 1663 /* direct probe may be part of the association flow */
1892 if (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE) { 1664 if (wk && wk->state == IEEE80211_MGD_STATE_PROBE) {
1893 printk(KERN_DEBUG "%s direct probe responded\n", 1665 printk(KERN_DEBUG "%s direct probe responded\n",
1894 sdata->dev->name); 1666 sdata->dev->name);
1895 ieee80211_authenticate(sdata); 1667 wk->tries = 0;
1668 wk->state = IEEE80211_MGD_STATE_AUTH;
1669 WARN_ON(ieee80211_authenticate(sdata, wk) != RX_MGMT_NONE);
1896 } 1670 }
1897 1671
1898 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) { 1672 if (ifmgd->associated &&
1899 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1673 memcmp(mgmt->bssid, ifmgd->associated->cbss.bssid, ETH_ALEN) == 0 &&
1674 ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
1675 IEEE80211_STA_CONNECTION_POLL)) {
1676 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
1677 IEEE80211_STA_BEACON_POLL);
1900 mutex_lock(&sdata->local->iflist_mtx); 1678 mutex_lock(&sdata->local->iflist_mtx);
1901 ieee80211_recalc_ps(sdata->local, -1); 1679 ieee80211_recalc_ps(sdata->local, -1);
1902 mutex_unlock(&sdata->local->iflist_mtx); 1680 mutex_unlock(&sdata->local->iflist_mtx);
1681 /*
1682 * We've received a probe response, but are not sure whether
1683 * we have or will be receiving any beacons or data, so let's
1684 * schedule the timers again, just in case.
1685 */
1686 mod_beacon_timer(sdata);
1687 mod_timer(&ifmgd->conn_mon_timer,
1688 round_jiffies_up(jiffies +
1689 IEEE80211_CONNECTION_IDLE_TIME));
1903 } 1690 }
1904} 1691}
1905 1692
@@ -1937,6 +1724,9 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1937 bool erp_valid, directed_tim = false; 1724 bool erp_valid, directed_tim = false;
1938 u8 erp_value = 0; 1725 u8 erp_value = 0;
1939 u32 ncrc; 1726 u32 ncrc;
1727 u8 *bssid;
1728
1729 ASSERT_MGD_MTX(ifmgd);
1940 1730
1941 /* Process beacon from the current BSS */ 1731 /* Process beacon from the current BSS */
1942 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1732 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
@@ -1946,23 +1736,41 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1946 if (rx_status->freq != local->hw.conf.channel->center_freq) 1736 if (rx_status->freq != local->hw.conf.channel->center_freq)
1947 return; 1737 return;
1948 1738
1949 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || 1739 /*
1950 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1740 * We might have received a number of frames, among them a
1741 * disassoc frame and a beacon...
1742 */
1743 if (!ifmgd->associated)
1951 return; 1744 return;
1952 1745
1953 if (ifmgd->flags & IEEE80211_STA_PROBEREQ_POLL) { 1746 bssid = ifmgd->associated->cbss.bssid;
1747
1748 /*
1749 * And in theory even frames from a different AP we were just
1750 * associated to a split-second ago!
1751 */
1752 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
1753 return;
1754
1755 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
1954#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1756#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1955 if (net_ratelimit()) { 1757 if (net_ratelimit()) {
1956 printk(KERN_DEBUG "%s: cancelling probereq poll due " 1758 printk(KERN_DEBUG "%s: cancelling probereq poll due "
1957 "to a received beacon\n", sdata->dev->name); 1759 "to a received beacon\n", sdata->dev->name);
1958 } 1760 }
1959#endif 1761#endif
1960 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1762 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
1961 mutex_lock(&local->iflist_mtx); 1763 mutex_lock(&local->iflist_mtx);
1962 ieee80211_recalc_ps(local, -1); 1764 ieee80211_recalc_ps(local, -1);
1963 mutex_unlock(&local->iflist_mtx); 1765 mutex_unlock(&local->iflist_mtx);
1964 } 1766 }
1965 1767
1768 /*
1769 * Push the beacon loss detection into the future since
1770 * we are processing a beacon from the AP just now.
1771 */
1772 mod_beacon_timer(sdata);
1773
1966 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); 1774 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1967 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, 1775 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1968 len - baselen, &elems, 1776 len - baselen, &elems,
@@ -2019,15 +1827,15 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2019 1827
2020 1828
2021 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && 1829 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
2022 !(ifmgd->flags & IEEE80211_STA_TKIP_WEP_USED)) { 1830 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
2023 struct sta_info *sta; 1831 struct sta_info *sta;
2024 struct ieee80211_supported_band *sband; 1832 struct ieee80211_supported_band *sband;
2025 u16 ap_ht_cap_flags; 1833 u16 ap_ht_cap_flags;
2026 1834
2027 rcu_read_lock(); 1835 rcu_read_lock();
2028 1836
2029 sta = sta_info_get(local, ifmgd->bssid); 1837 sta = sta_info_get(local, bssid);
2030 if (!sta) { 1838 if (WARN_ON(!sta)) {
2031 rcu_read_unlock(); 1839 rcu_read_unlock();
2032 return; 1840 return;
2033 } 1841 }
@@ -2042,15 +1850,11 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2042 rcu_read_unlock(); 1850 rcu_read_unlock();
2043 1851
2044 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, 1852 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
2045 ap_ht_cap_flags); 1853 bssid, ap_ht_cap_flags);
2046 } 1854 }
2047 1855
1856 /* Note: country IE parsing is done for us by cfg80211 */
2048 if (elems.country_elem) { 1857 if (elems.country_elem) {
2049 /* Note we are only reviewing this on beacons
2050 * for the BSSID we are associated to */
2051 regulatory_hint_11d(local->hw.wiphy,
2052 elems.country_elem, elems.country_elem_len);
2053
2054 /* TODO: IBSS also needs this */ 1858 /* TODO: IBSS also needs this */
2055 if (elems.pwr_constr_elem) 1859 if (elems.pwr_constr_elem)
2056 ieee80211_handle_pwr_constr(sdata, 1860 ieee80211_handle_pwr_constr(sdata,
@@ -2063,8 +1867,7 @@ static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
2063} 1867}
2064 1868
2065ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata, 1869ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2066 struct sk_buff *skb, 1870 struct sk_buff *skb)
2067 struct ieee80211_rx_status *rx_status)
2068{ 1871{
2069 struct ieee80211_local *local = sdata->local; 1872 struct ieee80211_local *local = sdata->local;
2070 struct ieee80211_mgmt *mgmt; 1873 struct ieee80211_mgmt *mgmt;
@@ -2080,14 +1883,14 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2080 case IEEE80211_STYPE_PROBE_REQ: 1883 case IEEE80211_STYPE_PROBE_REQ:
2081 case IEEE80211_STYPE_PROBE_RESP: 1884 case IEEE80211_STYPE_PROBE_RESP:
2082 case IEEE80211_STYPE_BEACON: 1885 case IEEE80211_STYPE_BEACON:
2083 memcpy(skb->cb, rx_status, sizeof(*rx_status));
2084 case IEEE80211_STYPE_AUTH: 1886 case IEEE80211_STYPE_AUTH:
2085 case IEEE80211_STYPE_ASSOC_RESP: 1887 case IEEE80211_STYPE_ASSOC_RESP:
2086 case IEEE80211_STYPE_REASSOC_RESP: 1888 case IEEE80211_STYPE_REASSOC_RESP:
2087 case IEEE80211_STYPE_DEAUTH: 1889 case IEEE80211_STYPE_DEAUTH:
2088 case IEEE80211_STYPE_DISASSOC: 1890 case IEEE80211_STYPE_DISASSOC:
1891 case IEEE80211_STYPE_ACTION:
2089 skb_queue_tail(&sdata->u.mgd.skb_queue, skb); 1892 skb_queue_tail(&sdata->u.mgd.skb_queue, skb);
2090 queue_work(local->hw.workqueue, &sdata->u.mgd.work); 1893 ieee80211_queue_work(&local->hw, &sdata->u.mgd.work);
2091 return RX_QUEUED; 1894 return RX_QUEUED;
2092 } 1895 }
2093 1896
@@ -2097,40 +1900,119 @@ ieee80211_rx_result ieee80211_sta_rx_mgmt(struct ieee80211_sub_if_data *sdata,
2097static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, 1900static void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
2098 struct sk_buff *skb) 1901 struct sk_buff *skb)
2099{ 1902{
1903 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2100 struct ieee80211_rx_status *rx_status; 1904 struct ieee80211_rx_status *rx_status;
2101 struct ieee80211_mgmt *mgmt; 1905 struct ieee80211_mgmt *mgmt;
1906 struct ieee80211_mgd_work *wk;
1907 enum rx_mgmt_action rma = RX_MGMT_NONE;
2102 u16 fc; 1908 u16 fc;
2103 1909
2104 rx_status = (struct ieee80211_rx_status *) skb->cb; 1910 rx_status = (struct ieee80211_rx_status *) skb->cb;
2105 mgmt = (struct ieee80211_mgmt *) skb->data; 1911 mgmt = (struct ieee80211_mgmt *) skb->data;
2106 fc = le16_to_cpu(mgmt->frame_control); 1912 fc = le16_to_cpu(mgmt->frame_control);
2107 1913
2108 switch (fc & IEEE80211_FCTL_STYPE) { 1914 mutex_lock(&ifmgd->mtx);
2109 case IEEE80211_STYPE_PROBE_RESP: 1915
2110 ieee80211_rx_mgmt_probe_resp(sdata, mgmt, skb->len, 1916 if (ifmgd->associated &&
2111 rx_status); 1917 memcmp(ifmgd->associated->cbss.bssid, mgmt->bssid,
2112 break; 1918 ETH_ALEN) == 0) {
2113 case IEEE80211_STYPE_BEACON: 1919 switch (fc & IEEE80211_FCTL_STYPE) {
2114 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, 1920 case IEEE80211_STYPE_BEACON:
2115 rx_status); 1921 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
2116 break; 1922 rx_status);
2117 case IEEE80211_STYPE_AUTH: 1923 break;
2118 ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); 1924 case IEEE80211_STYPE_PROBE_RESP:
1925 ieee80211_rx_mgmt_probe_resp(sdata, NULL, mgmt,
1926 skb->len, rx_status);
1927 break;
1928 case IEEE80211_STYPE_DEAUTH:
1929 rma = ieee80211_rx_mgmt_deauth(sdata, NULL,
1930 mgmt, skb->len);
1931 break;
1932 case IEEE80211_STYPE_DISASSOC:
1933 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
1934 break;
1935 case IEEE80211_STYPE_ACTION:
1936 /* XXX: differentiate, can only happen for CSA now! */
1937 ieee80211_sta_process_chanswitch(sdata,
1938 &mgmt->u.action.u.chan_switch.sw_elem,
1939 ifmgd->associated);
1940 break;
1941 }
1942 mutex_unlock(&ifmgd->mtx);
1943
1944 switch (rma) {
1945 case RX_MGMT_NONE:
1946 /* no action */
1947 break;
1948 case RX_MGMT_CFG80211_DEAUTH:
1949 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len,
1950 NULL);
1951 break;
1952 case RX_MGMT_CFG80211_DISASSOC:
1953 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len,
1954 NULL);
1955 break;
1956 default:
1957 WARN(1, "unexpected: %d", rma);
1958 }
1959 goto out;
1960 }
1961
1962 list_for_each_entry(wk, &ifmgd->work_list, list) {
1963 if (memcmp(wk->bss->cbss.bssid, mgmt->bssid, ETH_ALEN) != 0)
1964 continue;
1965
1966 switch (fc & IEEE80211_FCTL_STYPE) {
1967 case IEEE80211_STYPE_PROBE_RESP:
1968 ieee80211_rx_mgmt_probe_resp(sdata, wk, mgmt, skb->len,
1969 rx_status);
1970 break;
1971 case IEEE80211_STYPE_AUTH:
1972 rma = ieee80211_rx_mgmt_auth(sdata, wk, mgmt, skb->len);
1973 break;
1974 case IEEE80211_STYPE_ASSOC_RESP:
1975 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1976 skb->len, false);
1977 break;
1978 case IEEE80211_STYPE_REASSOC_RESP:
1979 rma = ieee80211_rx_mgmt_assoc_resp(sdata, wk, mgmt,
1980 skb->len, true);
1981 break;
1982 case IEEE80211_STYPE_DEAUTH:
1983 rma = ieee80211_rx_mgmt_deauth(sdata, wk, mgmt,
1984 skb->len);
1985 break;
1986 }
1987 /*
1988 * We've processed this frame for that work, so it can't
1989 * belong to another work struct.
1990 * NB: this is also required for correctness because the
1991 * called functions can free 'wk', and for 'rma'!
1992 */
2119 break; 1993 break;
2120 case IEEE80211_STYPE_ASSOC_RESP: 1994 }
2121 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 0); 1995
1996 mutex_unlock(&ifmgd->mtx);
1997
1998 switch (rma) {
1999 case RX_MGMT_NONE:
2000 /* no action */
2122 break; 2001 break;
2123 case IEEE80211_STYPE_REASSOC_RESP: 2002 case RX_MGMT_CFG80211_AUTH:
2124 ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, 1); 2003 cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, skb->len);
2125 break; 2004 break;
2126 case IEEE80211_STYPE_DEAUTH: 2005 case RX_MGMT_CFG80211_ASSOC:
2127 ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); 2006 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, skb->len);
2128 break; 2007 break;
2129 case IEEE80211_STYPE_DISASSOC: 2008 case RX_MGMT_CFG80211_DEAUTH:
2130 ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); 2009 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len, NULL);
2131 break; 2010 break;
2011 default:
2012 WARN(1, "unexpected: %d", rma);
2132 } 2013 }
2133 2014
2015 out:
2134 kfree_skb(skb); 2016 kfree_skb(skb);
2135} 2017}
2136 2018
@@ -2146,215 +2028,220 @@ static void ieee80211_sta_timer(unsigned long data)
2146 return; 2028 return;
2147 } 2029 }
2148 2030
2149 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); 2031 ieee80211_queue_work(&local->hw, &ifmgd->work);
2150 queue_work(local->hw.workqueue, &ifmgd->work);
2151} 2032}
2152 2033
2153static void ieee80211_sta_reset_auth(struct ieee80211_sub_if_data *sdata) 2034static void ieee80211_sta_work(struct work_struct *work)
2154{ 2035{
2155 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2036 struct ieee80211_sub_if_data *sdata =
2037 container_of(work, struct ieee80211_sub_if_data, u.mgd.work);
2156 struct ieee80211_local *local = sdata->local; 2038 struct ieee80211_local *local = sdata->local;
2039 struct ieee80211_if_managed *ifmgd;
2040 struct sk_buff *skb;
2041 struct ieee80211_mgd_work *wk, *tmp;
2042 LIST_HEAD(free_work);
2043 enum rx_mgmt_action rma;
2044 bool anybusy = false;
2157 2045
2158 /* Reset own TSF to allow time synchronization work. */ 2046 if (!netif_running(sdata->dev))
2159 drv_reset_tsf(local); 2047 return;
2160 2048
2161 ifmgd->wmm_last_param_set = -1; /* allow any WMM update */ 2049 if (local->scanning)
2050 return;
2162 2051
2052 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2053 return;
2163 2054
2164 if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_OPEN) 2055 /*
2165 ifmgd->auth_alg = WLAN_AUTH_OPEN; 2056 * ieee80211_queue_work() should have picked up most cases,
2166 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY) 2057 * here we'll pick the the rest.
2167 ifmgd->auth_alg = WLAN_AUTH_SHARED_KEY; 2058 */
2168 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_LEAP) 2059 if (WARN(local->suspended, "STA MLME work scheduled while "
2169 ifmgd->auth_alg = WLAN_AUTH_LEAP; 2060 "going to suspend\n"))
2170 else if (ifmgd->auth_algs & IEEE80211_AUTH_ALG_FT) 2061 return;
2171 ifmgd->auth_alg = WLAN_AUTH_FT;
2172 else
2173 ifmgd->auth_alg = WLAN_AUTH_OPEN;
2174 ifmgd->auth_transaction = -1;
2175 ifmgd->flags &= ~IEEE80211_STA_ASSOCIATED;
2176 ifmgd->assoc_scan_tries = 0;
2177 ifmgd->direct_probe_tries = 0;
2178 ifmgd->auth_tries = 0;
2179 ifmgd->assoc_tries = 0;
2180 netif_tx_stop_all_queues(sdata->dev);
2181 netif_carrier_off(sdata->dev);
2182}
2183 2062
2184static int ieee80211_sta_config_auth(struct ieee80211_sub_if_data *sdata) 2063 ifmgd = &sdata->u.mgd;
2185{
2186 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2187 struct ieee80211_local *local = sdata->local;
2188 struct ieee80211_bss *bss;
2189 u8 *bssid = ifmgd->bssid, *ssid = ifmgd->ssid;
2190 u8 ssid_len = ifmgd->ssid_len;
2191 u16 capa_mask = WLAN_CAPABILITY_ESS;
2192 u16 capa_val = WLAN_CAPABILITY_ESS;
2193 struct ieee80211_channel *chan = local->oper_channel;
2194 2064
2195 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) && 2065 /* first process frames to avoid timing out while a frame is pending */
2196 ifmgd->flags & (IEEE80211_STA_AUTO_SSID_SEL | 2066 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
2197 IEEE80211_STA_AUTO_BSSID_SEL | 2067 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2198 IEEE80211_STA_AUTO_CHANNEL_SEL)) {
2199 capa_mask |= WLAN_CAPABILITY_PRIVACY;
2200 if (sdata->default_key)
2201 capa_val |= WLAN_CAPABILITY_PRIVACY;
2202 }
2203 2068
2204 if (ifmgd->flags & IEEE80211_STA_AUTO_CHANNEL_SEL) 2069 /* then process the rest of the work */
2205 chan = NULL; 2070 mutex_lock(&ifmgd->mtx);
2206 2071
2207 if (ifmgd->flags & IEEE80211_STA_AUTO_BSSID_SEL) 2072 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
2208 bssid = NULL; 2073 IEEE80211_STA_CONNECTION_POLL) &&
2074 ifmgd->associated) {
2075 u8 bssid[ETH_ALEN];
2209 2076
2210 if (ifmgd->flags & IEEE80211_STA_AUTO_SSID_SEL) { 2077 memcpy(bssid, ifmgd->associated->cbss.bssid, ETH_ALEN);
2211 ssid = NULL; 2078 if (time_is_after_jiffies(ifmgd->probe_timeout))
2212 ssid_len = 0; 2079 run_again(ifmgd, ifmgd->probe_timeout);
2080
2081 else if (ifmgd->probe_send_count < IEEE80211_MAX_PROBE_TRIES) {
2082#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
2083 printk(KERN_DEBUG "No probe response from AP %pM"
2084 " after %dms, try %d\n", bssid,
2085 (1000 * IEEE80211_PROBE_WAIT)/HZ,
2086 ifmgd->probe_send_count);
2087#endif
2088 ieee80211_mgd_probe_ap_send(sdata);
2089 } else {
2090 /*
2091 * We actually lost the connection ... or did we?
2092 * Let's make sure!
2093 */
2094 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
2095 IEEE80211_STA_BEACON_POLL);
2096 printk(KERN_DEBUG "No probe response from AP %pM"
2097 " after %dms, disconnecting.\n",
2098 bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ);
2099 ieee80211_set_disassoc(sdata);
2100 mutex_unlock(&ifmgd->mtx);
2101 /*
2102 * must be outside lock due to cfg80211,
2103 * but that's not a problem.
2104 */
2105 ieee80211_send_deauth_disassoc(sdata, bssid,
2106 IEEE80211_STYPE_DEAUTH,
2107 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
2108 NULL);
2109 mutex_lock(&ifmgd->mtx);
2110 }
2213 } 2111 }
2214 2112
2215 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, 2113 list_for_each_entry(wk, &ifmgd->work_list, list) {
2216 bssid, ssid, ssid_len, 2114 if (wk->state != IEEE80211_MGD_STATE_IDLE) {
2217 capa_mask, capa_val); 2115 anybusy = true;
2116 break;
2117 }
2118 }
2218 2119
2219 if (bss) { 2120 ieee80211_recalc_idle(local);
2220 local->oper_channel = bss->cbss.channel;
2221 local->oper_channel_type = NL80211_CHAN_NO_HT;
2222 ieee80211_hw_config(local, 0);
2223 2121
2224 if (!(ifmgd->flags & IEEE80211_STA_SSID_SET)) 2122 if (!anybusy) {
2225 ieee80211_sta_set_ssid(sdata, bss->ssid, 2123 mutex_unlock(&ifmgd->mtx);
2226 bss->ssid_len);
2227 ieee80211_sta_set_bssid(sdata, bss->cbss.bssid);
2228 ieee80211_sta_def_wmm_params(sdata, bss->supp_rates_len,
2229 bss->supp_rates);
2230 if (sdata->u.mgd.mfp == IEEE80211_MFP_REQUIRED)
2231 sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED;
2232 else
2233 sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED;
2234
2235 /* Send out direct probe if no probe resp was received or
2236 * the one we have is outdated
2237 */
2238 if (!bss->last_probe_resp ||
2239 time_after(jiffies, bss->last_probe_resp
2240 + IEEE80211_SCAN_RESULT_EXPIRE))
2241 ifmgd->state = IEEE80211_STA_MLME_DIRECT_PROBE;
2242 else
2243 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE;
2244 2124
2245 ieee80211_rx_bss_put(local, bss); 2125 if (test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request))
2246 ieee80211_sta_reset_auth(sdata); 2126 ieee80211_queue_delayed_work(&local->hw,
2247 return 0; 2127 &local->scan_work,
2248 } else { 2128 round_jiffies_relative(0));
2249 if (ifmgd->assoc_scan_tries < IEEE80211_ASSOC_SCANS_MAX_TRIES) { 2129 return;
2130 }
2250 2131
2251 ifmgd->assoc_scan_tries++; 2132 list_for_each_entry_safe(wk, tmp, &ifmgd->work_list, list) {
2133 if (time_is_after_jiffies(wk->timeout)) {
2134 /*
2135 * This work item isn't supposed to be worked on
2136 * right now, but take care to adjust the timer
2137 * properly.
2138 */
2139 run_again(ifmgd, wk->timeout);
2140 continue;
2141 }
2252 2142
2253 ieee80211_request_internal_scan(sdata, ifmgd->ssid, 2143 switch (wk->state) {
2254 ssid_len); 2144 default:
2145 WARN_ON(1);
2146 /* fall through */
2147 case IEEE80211_MGD_STATE_IDLE:
2148 /* nothing */
2149 rma = RX_MGMT_NONE;
2150 break;
2151 case IEEE80211_MGD_STATE_PROBE:
2152 rma = ieee80211_direct_probe(sdata, wk);
2153 break;
2154 case IEEE80211_MGD_STATE_AUTH:
2155 rma = ieee80211_authenticate(sdata, wk);
2156 break;
2157 case IEEE80211_MGD_STATE_ASSOC:
2158 rma = ieee80211_associate(sdata, wk);
2159 break;
2160 }
2255 2161
2256 ifmgd->state = IEEE80211_STA_MLME_AUTHENTICATE; 2162 switch (rma) {
2257 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); 2163 case RX_MGMT_NONE:
2258 } else { 2164 /* no action required */
2259 ifmgd->assoc_scan_tries = 0; 2165 break;
2260 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 2166 case RX_MGMT_CFG80211_AUTH_TO:
2261 ieee80211_recalc_idle(local); 2167 case RX_MGMT_CFG80211_ASSOC_TO:
2168 list_del(&wk->list);
2169 list_add(&wk->list, &free_work);
2170 wk->tries = rma; /* small abuse but only local */
2171 break;
2172 default:
2173 WARN(1, "unexpected: %d", rma);
2262 } 2174 }
2263 } 2175 }
2264 return -1;
2265}
2266 2176
2177 mutex_unlock(&ifmgd->mtx);
2267 2178
2268static void ieee80211_sta_work(struct work_struct *work) 2179 list_for_each_entry_safe(wk, tmp, &free_work, list) {
2269{ 2180 switch (wk->tries) {
2270 struct ieee80211_sub_if_data *sdata = 2181 case RX_MGMT_CFG80211_AUTH_TO:
2271 container_of(work, struct ieee80211_sub_if_data, u.mgd.work); 2182 cfg80211_send_auth_timeout(sdata->dev,
2272 struct ieee80211_local *local = sdata->local; 2183 wk->bss->cbss.bssid);
2273 struct ieee80211_if_managed *ifmgd; 2184 break;
2274 struct sk_buff *skb; 2185 case RX_MGMT_CFG80211_ASSOC_TO:
2186 cfg80211_send_assoc_timeout(sdata->dev,
2187 wk->bss->cbss.bssid);
2188 break;
2189 default:
2190 WARN(1, "unexpected: %d", wk->tries);
2191 }
2275 2192
2276 if (!netif_running(sdata->dev)) 2193 list_del(&wk->list);
2277 return; 2194 kfree(wk);
2195 }
2278 2196
2279 if (local->sw_scanning || local->hw_scanning) 2197 ieee80211_recalc_idle(local);
2280 return; 2198}
2281 2199
2282 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 2200static void ieee80211_sta_bcn_mon_timer(unsigned long data)
2283 return; 2201{
2202 struct ieee80211_sub_if_data *sdata =
2203 (struct ieee80211_sub_if_data *) data;
2204 struct ieee80211_local *local = sdata->local;
2284 2205
2285 /* 2206 if (local->quiescing)
2286 * Nothing should have been stuffed into the workqueue during
2287 * the suspend->resume cycle. If this WARN is seen then there
2288 * is a bug with either the driver suspend or something in
2289 * mac80211 stuffing into the workqueue which we haven't yet
2290 * cleared during mac80211's suspend cycle.
2291 */
2292 if (WARN_ON(local->suspended))
2293 return; 2207 return;
2294 2208
2295 ifmgd = &sdata->u.mgd; 2209 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.beacon_loss_work);
2296 2210}
2297 while ((skb = skb_dequeue(&ifmgd->skb_queue)))
2298 ieee80211_sta_rx_queued_mgmt(sdata, skb);
2299 2211
2300 if (ifmgd->state != IEEE80211_STA_MLME_DIRECT_PROBE && 2212static void ieee80211_sta_conn_mon_timer(unsigned long data)
2301 ifmgd->state != IEEE80211_STA_MLME_AUTHENTICATE && 2213{
2302 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE && 2214 struct ieee80211_sub_if_data *sdata =
2303 test_and_clear_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request)) { 2215 (struct ieee80211_sub_if_data *) data;
2304 queue_delayed_work(local->hw.workqueue, &local->scan_work, 2216 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2305 round_jiffies_relative(0)); 2217 struct ieee80211_local *local = sdata->local;
2306 return;
2307 }
2308 2218
2309 if (test_and_clear_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request)) { 2219 if (local->quiescing)
2310 if (ieee80211_sta_config_auth(sdata))
2311 return;
2312 clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request);
2313 } else if (!test_and_clear_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request))
2314 return; 2220 return;
2315 2221
2316 ieee80211_recalc_idle(local); 2222 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
2317 2223}
2318 switch (ifmgd->state) {
2319 case IEEE80211_STA_MLME_DISABLED:
2320 break;
2321 case IEEE80211_STA_MLME_DIRECT_PROBE:
2322 ieee80211_direct_probe(sdata);
2323 break;
2324 case IEEE80211_STA_MLME_AUTHENTICATE:
2325 ieee80211_authenticate(sdata);
2326 break;
2327 case IEEE80211_STA_MLME_ASSOCIATE:
2328 ieee80211_associate(sdata);
2329 break;
2330 case IEEE80211_STA_MLME_ASSOCIATED:
2331 ieee80211_associated(sdata);
2332 break;
2333 default:
2334 WARN_ON(1);
2335 break;
2336 }
2337 2224
2338 if (ieee80211_privacy_mismatch(sdata)) { 2225static void ieee80211_sta_monitor_work(struct work_struct *work)
2339 printk(KERN_DEBUG "%s: privacy configuration mismatch and " 2226{
2340 "mixed-cell disabled - disassociate\n", sdata->dev->name); 2227 struct ieee80211_sub_if_data *sdata =
2228 container_of(work, struct ieee80211_sub_if_data,
2229 u.mgd.monitor_work);
2341 2230
2342 ieee80211_set_disassoc(sdata, false, true, 2231 ieee80211_mgd_probe_ap(sdata, false);
2343 WLAN_REASON_UNSPECIFIED);
2344 }
2345} 2232}
2346 2233
2347static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) 2234static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
2348{ 2235{
2349 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 2236 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
2350 /* 2237 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
2351 * Need to update last_beacon to avoid beacon loss 2238 IEEE80211_STA_CONNECTION_POLL);
2352 * test to trigger. 2239
2353 */ 2240 /* let's probe the connection once */
2354 sdata->u.mgd.last_beacon = jiffies; 2241 ieee80211_queue_work(&sdata->local->hw,
2355 2242 &sdata->u.mgd.monitor_work);
2356 2243 /* and do all the other regular work too */
2357 queue_work(sdata->local->hw.workqueue, 2244 ieee80211_queue_work(&sdata->local->hw,
2358 &sdata->u.mgd.work); 2245 &sdata->u.mgd.work);
2359 } 2246 }
2360} 2247}
@@ -2378,6 +2265,11 @@ void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
2378 cancel_work_sync(&ifmgd->chswitch_work); 2265 cancel_work_sync(&ifmgd->chswitch_work);
2379 if (del_timer_sync(&ifmgd->chswitch_timer)) 2266 if (del_timer_sync(&ifmgd->chswitch_timer))
2380 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); 2267 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
2268
2269 cancel_work_sync(&ifmgd->monitor_work);
2270 /* these will just be re-established on connection */
2271 del_timer_sync(&ifmgd->conn_mon_timer);
2272 del_timer_sync(&ifmgd->bcn_mon_timer);
2381} 2273}
2382 2274
2383void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) 2275void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
@@ -2395,210 +2287,277 @@ void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
2395void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 2287void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
2396{ 2288{
2397 struct ieee80211_if_managed *ifmgd; 2289 struct ieee80211_if_managed *ifmgd;
2398 u32 hw_flags;
2399 2290
2400 ifmgd = &sdata->u.mgd; 2291 ifmgd = &sdata->u.mgd;
2401 INIT_WORK(&ifmgd->work, ieee80211_sta_work); 2292 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
2293 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
2402 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); 2294 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
2403 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work); 2295 INIT_WORK(&ifmgd->beacon_loss_work, ieee80211_beacon_loss_work);
2404 setup_timer(&ifmgd->timer, ieee80211_sta_timer, 2296 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
2405 (unsigned long) sdata); 2297 (unsigned long) sdata);
2298 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
2299 (unsigned long) sdata);
2300 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
2301 (unsigned long) sdata);
2406 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 2302 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
2407 (unsigned long) sdata); 2303 (unsigned long) sdata);
2408 skb_queue_head_init(&ifmgd->skb_queue); 2304 skb_queue_head_init(&ifmgd->skb_queue);
2409 2305
2306 INIT_LIST_HEAD(&ifmgd->work_list);
2307
2410 ifmgd->capab = WLAN_CAPABILITY_ESS; 2308 ifmgd->capab = WLAN_CAPABILITY_ESS;
2411 ifmgd->auth_algs = IEEE80211_AUTH_ALG_OPEN | 2309 ifmgd->flags = 0;
2412 IEEE80211_AUTH_ALG_SHARED_KEY;
2413 ifmgd->flags |= IEEE80211_STA_CREATE_IBSS |
2414 IEEE80211_STA_AUTO_BSSID_SEL |
2415 IEEE80211_STA_AUTO_CHANNEL_SEL;
2416 if (sdata->local->hw.queues >= 4) 2310 if (sdata->local->hw.queues >= 4)
2417 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; 2311 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2418 2312
2419 hw_flags = sdata->local->hw.flags; 2313 mutex_init(&ifmgd->mtx);
2420
2421 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2422 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2423 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2424 }
2425} 2314}
2426 2315
2427/* configuration hooks */ 2316/* scan finished notification */
2428void ieee80211_sta_req_auth(struct ieee80211_sub_if_data *sdata) 2317void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2429{ 2318{
2430 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2319 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2431 struct ieee80211_local *local = sdata->local;
2432
2433 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2434 return;
2435
2436 if ((ifmgd->flags & (IEEE80211_STA_BSSID_SET |
2437 IEEE80211_STA_AUTO_BSSID_SEL)) &&
2438 (ifmgd->flags & (IEEE80211_STA_SSID_SET |
2439 IEEE80211_STA_AUTO_SSID_SEL))) {
2440
2441 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2442 ieee80211_set_disassoc(sdata, true, true,
2443 WLAN_REASON_DEAUTH_LEAVING);
2444
2445 if (ifmgd->ssid_len == 0) {
2446 /*
2447 * Only allow association to be started if a valid SSID
2448 * is configured.
2449 */
2450 return;
2451 }
2452 2320
2453 if (!(ifmgd->flags & IEEE80211_STA_EXT_SME) || 2321 /* Restart STA timers */
2454 ifmgd->state != IEEE80211_STA_MLME_ASSOCIATE) 2322 rcu_read_lock();
2455 set_bit(IEEE80211_STA_REQ_AUTH, &ifmgd->request); 2323 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2456 else if (ifmgd->flags & IEEE80211_STA_EXT_SME) 2324 ieee80211_restart_sta_timer(sdata);
2457 set_bit(IEEE80211_STA_REQ_RUN, &ifmgd->request); 2325 rcu_read_unlock();
2458 queue_work(local->hw.workqueue, &ifmgd->work);
2459 }
2460} 2326}
2461 2327
2462int ieee80211_sta_commit(struct ieee80211_sub_if_data *sdata) 2328int ieee80211_max_network_latency(struct notifier_block *nb,
2329 unsigned long data, void *dummy)
2463{ 2330{
2464 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2331 s32 latency_usec = (s32) data;
2332 struct ieee80211_local *local =
2333 container_of(nb, struct ieee80211_local,
2334 network_latency_notifier);
2465 2335
2466 if (ifmgd->ssid_len) 2336 mutex_lock(&local->iflist_mtx);
2467 ifmgd->flags |= IEEE80211_STA_SSID_SET; 2337 ieee80211_recalc_ps(local, latency_usec);
2468 else 2338 mutex_unlock(&local->iflist_mtx);
2469 ifmgd->flags &= ~IEEE80211_STA_SSID_SET;
2470 2339
2471 return 0; 2340 return 0;
2472} 2341}
2473 2342
2474int ieee80211_sta_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len) 2343/* config hooks */
2344int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
2345 struct cfg80211_auth_request *req)
2475{ 2346{
2476 struct ieee80211_if_managed *ifmgd; 2347 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2348 const u8 *ssid;
2349 struct ieee80211_mgd_work *wk;
2350 u16 auth_alg;
2477 2351
2478 if (len > IEEE80211_MAX_SSID_LEN) 2352 switch (req->auth_type) {
2479 return -EINVAL; 2353 case NL80211_AUTHTYPE_OPEN_SYSTEM:
2354 auth_alg = WLAN_AUTH_OPEN;
2355 break;
2356 case NL80211_AUTHTYPE_SHARED_KEY:
2357 auth_alg = WLAN_AUTH_SHARED_KEY;
2358 break;
2359 case NL80211_AUTHTYPE_FT:
2360 auth_alg = WLAN_AUTH_FT;
2361 break;
2362 case NL80211_AUTHTYPE_NETWORK_EAP:
2363 auth_alg = WLAN_AUTH_LEAP;
2364 break;
2365 default:
2366 return -EOPNOTSUPP;
2367 }
2480 2368
2481 ifmgd = &sdata->u.mgd; 2369 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
2370 if (!wk)
2371 return -ENOMEM;
2482 2372
2483 if (ifmgd->ssid_len != len || memcmp(ifmgd->ssid, ssid, len) != 0) { 2373 wk->bss = (void *)req->bss;
2484 if (ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2485 ieee80211_set_disassoc(sdata, true, true,
2486 WLAN_REASON_DEAUTH_LEAVING);
2487 2374
2488 /* 2375 if (req->ie && req->ie_len) {
2489 * Do not use reassociation if SSID is changed (different ESS). 2376 memcpy(wk->ie, req->ie, req->ie_len);
2490 */ 2377 wk->ie_len = req->ie_len;
2491 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
2492 memset(ifmgd->ssid, 0, sizeof(ifmgd->ssid));
2493 memcpy(ifmgd->ssid, ssid, len);
2494 ifmgd->ssid_len = len;
2495 } 2378 }
2496 2379
2497 return ieee80211_sta_commit(sdata); 2380 if (req->key && req->key_len) {
2498} 2381 wk->key_len = req->key_len;
2382 wk->key_idx = req->key_idx;
2383 memcpy(wk->key, req->key, req->key_len);
2384 }
2499 2385
2500int ieee80211_sta_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len) 2386 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
2501{ 2387 memcpy(wk->ssid, ssid + 2, ssid[1]);
2502 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2388 wk->ssid_len = ssid[1];
2503 memcpy(ssid, ifmgd->ssid, ifmgd->ssid_len); 2389
2504 *len = ifmgd->ssid_len; 2390 wk->state = IEEE80211_MGD_STATE_PROBE;
2391 wk->auth_alg = auth_alg;
2392 wk->timeout = jiffies; /* run right away */
2393
2394 /*
2395 * XXX: if still associated need to tell AP that we're going
2396 * to sleep and then change channel etc.
2397 */
2398 sdata->local->oper_channel = req->bss->channel;
2399 ieee80211_hw_config(sdata->local, 0);
2400
2401 mutex_lock(&ifmgd->mtx);
2402 list_add(&wk->list, &sdata->u.mgd.work_list);
2403 mutex_unlock(&ifmgd->mtx);
2404
2405 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work);
2505 return 0; 2406 return 0;
2506} 2407}
2507 2408
2508int ieee80211_sta_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid) 2409int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
2410 struct cfg80211_assoc_request *req)
2509{ 2411{
2510 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2412 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2413 struct ieee80211_mgd_work *wk, *found = NULL;
2414 int i, err;
2511 2415
2512 if (compare_ether_addr(bssid, ifmgd->bssid) != 0 && 2416 mutex_lock(&ifmgd->mtx);
2513 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATED)
2514 ieee80211_set_disassoc(sdata, true, true,
2515 WLAN_REASON_DEAUTH_LEAVING);
2516 2417
2517 if (is_valid_ether_addr(bssid)) { 2418 list_for_each_entry(wk, &ifmgd->work_list, list) {
2518 memcpy(ifmgd->bssid, bssid, ETH_ALEN); 2419 if (&wk->bss->cbss == req->bss &&
2519 ifmgd->flags |= IEEE80211_STA_BSSID_SET; 2420 wk->state == IEEE80211_MGD_STATE_IDLE) {
2520 } else { 2421 found = wk;
2521 memset(ifmgd->bssid, 0, ETH_ALEN); 2422 break;
2522 ifmgd->flags &= ~IEEE80211_STA_BSSID_SET; 2423 }
2523 } 2424 }
2524 2425
2525 return ieee80211_sta_commit(sdata); 2426 if (!found) {
2526} 2427 err = -ENOLINK;
2428 goto out;
2429 }
2527 2430
2528int ieee80211_sta_set_extra_ie(struct ieee80211_sub_if_data *sdata, 2431 list_del(&found->list);
2529 const char *ie, size_t len)
2530{
2531 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2532 2432
2533 if (len == 0 && ifmgd->extra_ie_len == 0) 2433 wk = krealloc(found, sizeof(*wk) + req->ie_len, GFP_KERNEL);
2534 return -EALREADY; 2434 if (!wk) {
2435 list_add(&found->list, &ifmgd->work_list);
2436 err = -ENOMEM;
2437 goto out;
2438 }
2535 2439
2536 if (len == ifmgd->extra_ie_len && ifmgd->extra_ie && 2440 list_add(&wk->list, &ifmgd->work_list);
2537 memcmp(ifmgd->extra_ie, ie, len) == 0)
2538 return -EALREADY;
2539 2441
2540 kfree(ifmgd->extra_ie); 2442 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
2541 if (len == 0) { 2443
2542 ifmgd->extra_ie = NULL; 2444 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
2543 ifmgd->extra_ie_len = 0; 2445 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
2544 return 0; 2446 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
2545 } 2447 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
2546 ifmgd->extra_ie = kmalloc(len, GFP_KERNEL); 2448 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
2547 if (!ifmgd->extra_ie) { 2449
2548 ifmgd->extra_ie_len = 0; 2450 sdata->local->oper_channel = req->bss->channel;
2549 return -ENOMEM; 2451 ieee80211_hw_config(sdata->local, 0);
2452
2453 if (req->ie && req->ie_len) {
2454 memcpy(wk->ie, req->ie, req->ie_len);
2455 wk->ie_len = req->ie_len;
2456 } else
2457 wk->ie_len = 0;
2458
2459 if (req->prev_bssid)
2460 memcpy(wk->prev_bssid, req->prev_bssid, ETH_ALEN);
2461
2462 wk->state = IEEE80211_MGD_STATE_ASSOC;
2463 wk->tries = 0;
2464 wk->timeout = jiffies; /* run right away */
2465
2466 if (req->use_mfp) {
2467 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
2468 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
2469 } else {
2470 ifmgd->mfp = IEEE80211_MFP_DISABLED;
2471 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
2550 } 2472 }
2551 memcpy(ifmgd->extra_ie, ie, len);
2552 ifmgd->extra_ie_len = len;
2553 return 0;
2554}
2555 2473
2556int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason) 2474 if (req->crypto.control_port)
2557{ 2475 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
2558 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", 2476 else
2559 sdata->dev->name, reason); 2477 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
2560 2478
2561 ieee80211_set_disassoc(sdata, true, true, reason); 2479 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.work);
2562 return 0; 2480
2481 err = 0;
2482
2483 out:
2484 mutex_unlock(&ifmgd->mtx);
2485 return err;
2563} 2486}
2564 2487
2565int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason) 2488int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
2489 struct cfg80211_deauth_request *req,
2490 void *cookie)
2566{ 2491{
2567 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 2492 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2493 struct ieee80211_mgd_work *wk;
2494 const u8 *bssid = NULL;
2568 2495
2569 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", 2496 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2570 sdata->dev->name, reason); 2497 sdata->dev->name, req->reason_code);
2498
2499 mutex_lock(&ifmgd->mtx);
2500
2501 if (ifmgd->associated && &ifmgd->associated->cbss == req->bss) {
2502 bssid = req->bss->bssid;
2503 ieee80211_set_disassoc(sdata);
2504 } else list_for_each_entry(wk, &ifmgd->work_list, list) {
2505 if (&wk->bss->cbss == req->bss) {
2506 bssid = req->bss->bssid;
2507 list_del(&wk->list);
2508 kfree(wk);
2509 break;
2510 }
2511 }
2571 2512
2572 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) 2513 /*
2514 * cfg80211 should catch this ... but it's racy since
2515 * we can receive a deauth frame, process it, hand it
2516 * to cfg80211 while that's in a locked section already
2517 * trying to tell us that the user wants to disconnect.
2518 */
2519 if (!bssid) {
2520 mutex_unlock(&ifmgd->mtx);
2573 return -ENOLINK; 2521 return -ENOLINK;
2522 }
2523
2524 mutex_unlock(&ifmgd->mtx);
2525
2526 ieee80211_send_deauth_disassoc(sdata, bssid,
2527 IEEE80211_STYPE_DEAUTH, req->reason_code,
2528 cookie);
2574 2529
2575 ieee80211_set_disassoc(sdata, false, true, reason);
2576 return 0; 2530 return 0;
2577} 2531}
2578 2532
2579/* scan finished notification */ 2533int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
2580void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) 2534 struct cfg80211_disassoc_request *req,
2535 void *cookie)
2581{ 2536{
2582 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 2537 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2583 2538
2584 /* Restart STA timers */ 2539 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2585 rcu_read_lock(); 2540 sdata->dev->name, req->reason_code);
2586 list_for_each_entry_rcu(sdata, &local->interfaces, list)
2587 ieee80211_restart_sta_timer(sdata);
2588 rcu_read_unlock();
2589}
2590 2541
2591int ieee80211_max_network_latency(struct notifier_block *nb, 2542 mutex_lock(&ifmgd->mtx);
2592 unsigned long data, void *dummy)
2593{
2594 s32 latency_usec = (s32) data;
2595 struct ieee80211_local *local =
2596 container_of(nb, struct ieee80211_local,
2597 network_latency_notifier);
2598 2543
2599 mutex_lock(&local->iflist_mtx); 2544 /*
2600 ieee80211_recalc_ps(local, latency_usec); 2545 * cfg80211 should catch this ... but it's racy since
2601 mutex_unlock(&local->iflist_mtx); 2546 * we can receive a disassoc frame, process it, hand it
2547 * to cfg80211 while that's in a locked section already
2548 * trying to tell us that the user wants to disconnect.
2549 */
2550 if (&ifmgd->associated->cbss != req->bss) {
2551 mutex_unlock(&ifmgd->mtx);
2552 return -ENOLINK;
2553 }
2554
2555 ieee80211_set_disassoc(sdata);
2556
2557 mutex_unlock(&ifmgd->mtx);
2602 2558
2559 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
2560 IEEE80211_STYPE_DISASSOC, req->reason_code,
2561 cookie);
2603 return 0; 2562 return 0;
2604} 2563}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 5e3d476972f9..a5d2f1fb4417 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -26,7 +26,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
26 /* make quiescing visible to timers everywhere */ 26 /* make quiescing visible to timers everywhere */
27 mb(); 27 mb();
28 28
29 flush_workqueue(local->hw.workqueue); 29 flush_workqueue(local->workqueue);
30 30
31 /* Don't try to run timers while suspended. */ 31 /* Don't try to run timers while suspended. */
32 del_timer_sync(&local->sta_cleanup); 32 del_timer_sync(&local->sta_cleanup);
@@ -96,6 +96,10 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
96 if (!netif_running(sdata->dev)) 96 if (!netif_running(sdata->dev))
97 continue; 97 continue;
98 98
99 /* disable beaconing */
100 ieee80211_bss_info_change_notify(sdata,
101 BSS_CHANGED_BEACON_ENABLED);
102
99 conf.vif = &sdata->vif; 103 conf.vif = &sdata->vif;
100 conf.type = sdata->vif.type; 104 conf.type = sdata->vif.type;
101 conf.mac_addr = sdata->dev->dev_addr; 105 conf.mac_addr = sdata->dev->dev_addr;
@@ -113,7 +117,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
113 * shouldn't be doing (or cancel everything in the 117 * shouldn't be doing (or cancel everything in the
114 * stop callback) that but better safe than sorry. 118 * stop callback) that but better safe than sorry.
115 */ 119 */
116 flush_workqueue(local->hw.workqueue); 120 flush_workqueue(local->workqueue);
117 121
118 local->suspended = true; 122 local->suspended = true;
119 /* need suspended to be visible before quiescing is false */ 123 /* need suspended to be visible before quiescing is false */
diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
index 4641f00a1e5c..b33efc4fc267 100644
--- a/net/mac80211/rate.c
+++ b/net/mac80211/rate.c
@@ -198,6 +198,35 @@ static void rate_control_release(struct kref *kref)
198 kfree(ctrl_ref); 198 kfree(ctrl_ref);
199} 199}
200 200
201static bool rc_no_data_or_no_ack(struct ieee80211_tx_rate_control *txrc)
202{
203 struct sk_buff *skb = txrc->skb;
204 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
205 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
206 __le16 fc;
207
208 fc = hdr->frame_control;
209
210 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) || !ieee80211_is_data(fc));
211}
212
213bool rate_control_send_low(struct ieee80211_sta *sta,
214 void *priv_sta,
215 struct ieee80211_tx_rate_control *txrc)
216{
217 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
218
219 if (!sta || !priv_sta || rc_no_data_or_no_ack(txrc)) {
220 info->control.rates[0].idx = rate_lowest_index(txrc->sband, sta);
221 info->control.rates[0].count =
222 (info->flags & IEEE80211_TX_CTL_NO_ACK) ?
223 1 : txrc->hw->max_rate_tries;
224 return true;
225 }
226 return false;
227}
228EXPORT_SYMBOL(rate_control_send_low);
229
201void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 230void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
202 struct sta_info *sta, 231 struct sta_info *sta,
203 struct ieee80211_tx_rate_control *txrc) 232 struct ieee80211_tx_rate_control *txrc)
@@ -258,7 +287,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
258 struct rate_control_ref *ref, *old; 287 struct rate_control_ref *ref, *old;
259 288
260 ASSERT_RTNL(); 289 ASSERT_RTNL();
261 if (local->open_count || netif_running(local->mdev)) 290 if (local->open_count)
262 return -EBUSY; 291 return -EBUSY;
263 292
264 ref = rate_control_alloc(name, local); 293 ref = rate_control_alloc(name, local);
diff --git a/net/mac80211/rc80211_minstrel.c b/net/mac80211/rc80211_minstrel.c
index 37771abd8f5a..7c5142988bbb 100644
--- a/net/mac80211/rc80211_minstrel.c
+++ b/net/mac80211/rc80211_minstrel.c
@@ -70,20 +70,6 @@ rix_to_ndx(struct minstrel_sta_info *mi, int rix)
70 return i; 70 return i;
71} 71}
72 72
73static inline bool
74use_low_rate(struct sk_buff *skb)
75{
76 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
77 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
78 u16 fc;
79
80 fc = le16_to_cpu(hdr->frame_control);
81
82 return ((info->flags & IEEE80211_TX_CTL_NO_ACK) ||
83 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA);
84}
85
86
87static void 73static void
88minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi) 74minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi)
89{ 75{
@@ -232,7 +218,6 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
232 void *priv_sta, struct ieee80211_tx_rate_control *txrc) 218 void *priv_sta, struct ieee80211_tx_rate_control *txrc)
233{ 219{
234 struct sk_buff *skb = txrc->skb; 220 struct sk_buff *skb = txrc->skb;
235 struct ieee80211_supported_band *sband = txrc->sband;
236 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 221 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
237 struct minstrel_sta_info *mi = priv_sta; 222 struct minstrel_sta_info *mi = priv_sta;
238 struct minstrel_priv *mp = priv; 223 struct minstrel_priv *mp = priv;
@@ -245,14 +230,8 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
245 int mrr_ndx[3]; 230 int mrr_ndx[3];
246 int sample_rate; 231 int sample_rate;
247 232
248 if (!sta || !mi || use_low_rate(skb)) { 233 if (rate_control_send_low(sta, priv_sta, txrc))
249 ar[0].idx = rate_lowest_index(sband, sta);
250 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
251 ar[0].count = 1;
252 else
253 ar[0].count = mp->max_retry;
254 return; 234 return;
255 }
256 235
257 mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot; 236 mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot;
258 237
diff --git a/net/mac80211/rc80211_pid_algo.c b/net/mac80211/rc80211_pid_algo.c
index a0bef767ceb5..8c053be9dc24 100644
--- a/net/mac80211/rc80211_pid_algo.c
+++ b/net/mac80211/rc80211_pid_algo.c
@@ -276,11 +276,9 @@ rate_control_pid_get_rate(void *priv, struct ieee80211_sta *sta,
276{ 276{
277 struct sk_buff *skb = txrc->skb; 277 struct sk_buff *skb = txrc->skb;
278 struct ieee80211_supported_band *sband = txrc->sband; 278 struct ieee80211_supported_band *sband = txrc->sband;
279 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
280 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 279 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
281 struct rc_pid_sta_info *spinfo = priv_sta; 280 struct rc_pid_sta_info *spinfo = priv_sta;
282 int rateidx; 281 int rateidx;
283 u16 fc;
284 282
285 if (txrc->rts) 283 if (txrc->rts)
286 info->control.rates[0].count = 284 info->control.rates[0].count =
@@ -290,16 +288,8 @@ rate_control_pid_get_rate(void *priv, struct ieee80211_sta *sta,
290 txrc->hw->conf.short_frame_max_tx_count; 288 txrc->hw->conf.short_frame_max_tx_count;
291 289
292 /* Send management frames and NO_ACK data using lowest rate. */ 290 /* Send management frames and NO_ACK data using lowest rate. */
293 fc = le16_to_cpu(hdr->frame_control); 291 if (rate_control_send_low(sta, priv_sta, txrc))
294 if (!sta || !spinfo ||
295 (fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
296 info->flags & IEEE80211_TX_CTL_NO_ACK) {
297 info->control.rates[0].idx = rate_lowest_index(sband, sta);
298 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
299 info->control.rates[0].count = 1;
300
301 return; 292 return;
302 }
303 293
304 rateidx = spinfo->txrate_idx; 294 rateidx = spinfo->txrate_idx;
305 295
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 0936fc24942d..25a669c86e14 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -30,7 +30,6 @@
30static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 30static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
31 struct tid_ampdu_rx *tid_agg_rx, 31 struct tid_ampdu_rx *tid_agg_rx,
32 struct sk_buff *skb, 32 struct sk_buff *skb,
33 struct ieee80211_rx_status *status,
34 u16 mpdu_seq_num, 33 u16 mpdu_seq_num,
35 int bar_req); 34 int bar_req);
36/* 35/*
@@ -59,11 +58,11 @@ static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
59 return skb; 58 return skb;
60} 59}
61 60
62static inline int should_drop_frame(struct ieee80211_rx_status *status, 61static inline int should_drop_frame(struct sk_buff *skb,
63 struct sk_buff *skb,
64 int present_fcs_len, 62 int present_fcs_len,
65 int radiotap_len) 63 int radiotap_len)
66{ 64{
65 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
67 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 66 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
68 67
69 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC)) 68 if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
@@ -111,10 +110,10 @@ ieee80211_rx_radiotap_len(struct ieee80211_local *local,
111static void 110static void
112ieee80211_add_rx_radiotap_header(struct ieee80211_local *local, 111ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
113 struct sk_buff *skb, 112 struct sk_buff *skb,
114 struct ieee80211_rx_status *status,
115 struct ieee80211_rate *rate, 113 struct ieee80211_rate *rate,
116 int rtap_len) 114 int rtap_len)
117{ 115{
116 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
118 struct ieee80211_radiotap_header *rthdr; 117 struct ieee80211_radiotap_header *rthdr;
119 unsigned char *pos; 118 unsigned char *pos;
120 119
@@ -220,9 +219,9 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
220 */ 219 */
221static struct sk_buff * 220static struct sk_buff *
222ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb, 221ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
223 struct ieee80211_rx_status *status,
224 struct ieee80211_rate *rate) 222 struct ieee80211_rate *rate)
225{ 223{
224 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
226 struct ieee80211_sub_if_data *sdata; 225 struct ieee80211_sub_if_data *sdata;
227 int needed_headroom = 0; 226 int needed_headroom = 0;
228 struct sk_buff *skb, *skb2; 227 struct sk_buff *skb, *skb2;
@@ -248,8 +247,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
248 present_fcs_len = FCS_LEN; 247 present_fcs_len = FCS_LEN;
249 248
250 if (!local->monitors) { 249 if (!local->monitors) {
251 if (should_drop_frame(status, origskb, present_fcs_len, 250 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) {
252 rtap_len)) {
253 dev_kfree_skb(origskb); 251 dev_kfree_skb(origskb);
254 return NULL; 252 return NULL;
255 } 253 }
@@ -257,7 +255,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
257 return remove_monitor_info(local, origskb, rtap_len); 255 return remove_monitor_info(local, origskb, rtap_len);
258 } 256 }
259 257
260 if (should_drop_frame(status, origskb, present_fcs_len, rtap_len)) { 258 if (should_drop_frame(origskb, present_fcs_len, rtap_len)) {
261 /* only need to expand headroom if necessary */ 259 /* only need to expand headroom if necessary */
262 skb = origskb; 260 skb = origskb;
263 origskb = NULL; 261 origskb = NULL;
@@ -289,7 +287,7 @@ ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
289 287
290 /* if necessary, prepend radiotap information */ 288 /* if necessary, prepend radiotap information */
291 if (!(status->flag & RX_FLAG_RADIOTAP)) 289 if (!(status->flag & RX_FLAG_RADIOTAP))
292 ieee80211_add_rx_radiotap_header(local, skb, status, rate, 290 ieee80211_add_rx_radiotap_header(local, skb, rate,
293 needed_headroom); 291 needed_headroom);
294 292
295 skb_reset_mac_header(skb); 293 skb_reset_mac_header(skb);
@@ -420,13 +418,13 @@ ieee80211_rx_h_passive_scan(struct ieee80211_rx_data *rx)
420 struct ieee80211_local *local = rx->local; 418 struct ieee80211_local *local = rx->local;
421 struct sk_buff *skb = rx->skb; 419 struct sk_buff *skb = rx->skb;
422 420
423 if (unlikely(local->hw_scanning)) 421 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning)))
424 return ieee80211_scan_rx(rx->sdata, skb, rx->status); 422 return ieee80211_scan_rx(rx->sdata, skb);
425 423
426 if (unlikely(local->sw_scanning)) { 424 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning) &&
425 (rx->flags & IEEE80211_RX_IN_SCAN))) {
427 /* drop all the other packets during a software scan anyway */ 426 /* drop all the other packets during a software scan anyway */
428 if (ieee80211_scan_rx(rx->sdata, skb, rx->status) 427 if (ieee80211_scan_rx(rx->sdata, skb) != RX_QUEUED)
429 != RX_QUEUED)
430 dev_kfree_skb(skb); 428 dev_kfree_skb(skb);
431 return RX_QUEUED; 429 return RX_QUEUED;
432 } 430 }
@@ -785,7 +783,7 @@ static void ap_sta_ps_start(struct sta_info *sta)
785 struct ieee80211_local *local = sdata->local; 783 struct ieee80211_local *local = sdata->local;
786 784
787 atomic_inc(&sdata->bss->num_sta_ps); 785 atomic_inc(&sdata->bss->num_sta_ps);
788 set_and_clear_sta_flags(sta, WLAN_STA_PS, WLAN_STA_PSPOLL); 786 set_sta_flags(sta, WLAN_STA_PS);
789 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_SLEEP, &sta->sta); 787 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_SLEEP, &sta->sta);
790#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 788#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
791 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", 789 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n",
@@ -801,7 +799,7 @@ static int ap_sta_ps_end(struct sta_info *sta)
801 799
802 atomic_dec(&sdata->bss->num_sta_ps); 800 atomic_dec(&sdata->bss->num_sta_ps);
803 801
804 clear_sta_flags(sta, WLAN_STA_PS | WLAN_STA_PSPOLL); 802 clear_sta_flags(sta, WLAN_STA_PS);
805 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_AWAKE, &sta->sta); 803 drv_sta_notify(local, &sdata->vif, STA_NOTIFY_AWAKE, &sta->sta);
806 804
807 if (!skb_queue_empty(&sta->ps_tx_buf)) 805 if (!skb_queue_empty(&sta->ps_tx_buf))
@@ -836,28 +834,22 @@ ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
836 if (!sta) 834 if (!sta)
837 return RX_CONTINUE; 835 return RX_CONTINUE;
838 836
839 /* Update last_rx only for IBSS packets which are for the current 837 /*
840 * BSSID to avoid keeping the current IBSS network alive in cases where 838 * Update last_rx only for IBSS packets which are for the current
841 * other STAs are using different BSSID. */ 839 * BSSID to avoid keeping the current IBSS network alive in cases
840 * where other STAs start using different BSSID.
841 */
842 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) { 842 if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
843 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len, 843 u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
844 NL80211_IFTYPE_ADHOC); 844 NL80211_IFTYPE_ADHOC);
845 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0) 845 if (compare_ether_addr(bssid, rx->sdata->u.ibss.bssid) == 0)
846 sta->last_rx = jiffies; 846 sta->last_rx = jiffies;
847 } else 847 } else if (!is_multicast_ether_addr(hdr->addr1)) {
848 if (!is_multicast_ether_addr(hdr->addr1) || 848 /*
849 rx->sdata->vif.type == NL80211_IFTYPE_STATION) {
850 /* Update last_rx only for unicast frames in order to prevent
851 * the Probe Request frames (the only broadcast frames from a
852 * STA in infrastructure mode) from keeping a connection alive.
853 * Mesh beacons will update last_rx when if they are found to 849 * Mesh beacons will update last_rx when if they are found to
854 * match the current local configuration when processed. 850 * match the current local configuration when processed.
855 */ 851 */
856 if (rx->sdata->vif.type == NL80211_IFTYPE_STATION && 852 sta->last_rx = jiffies;
857 ieee80211_is_beacon(hdr->frame_control)) {
858 rx->sdata->u.mgd.last_beacon = jiffies;
859 } else
860 sta->last_rx = jiffies;
861 } 853 }
862 854
863 if (!(rx->flags & IEEE80211_RX_RA_MATCH)) 855 if (!(rx->flags & IEEE80211_RX_RA_MATCH))
@@ -1125,14 +1117,15 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1125 skb_queue_empty(&rx->sta->ps_tx_buf); 1117 skb_queue_empty(&rx->sta->ps_tx_buf);
1126 1118
1127 if (skb) { 1119 if (skb) {
1120 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1128 struct ieee80211_hdr *hdr = 1121 struct ieee80211_hdr *hdr =
1129 (struct ieee80211_hdr *) skb->data; 1122 (struct ieee80211_hdr *) skb->data;
1130 1123
1131 /* 1124 /*
1132 * Tell TX path to send one frame even though the STA may 1125 * Tell TX path to send this frame even though the STA may
1133 * still remain is PS mode after this frame exchange. 1126 * still remain is PS mode after this frame exchange.
1134 */ 1127 */
1135 set_sta_flags(rx->sta, WLAN_STA_PSPOLL); 1128 info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE;
1136 1129
1137#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1130#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1138 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n", 1131 printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n",
@@ -1147,7 +1140,7 @@ ieee80211_rx_h_ps_poll(struct ieee80211_rx_data *rx)
1147 else 1140 else
1148 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); 1141 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
1149 1142
1150 dev_queue_xmit(skb); 1143 ieee80211_add_pending_skb(rx->local, skb);
1151 1144
1152 if (no_pending_pkts) 1145 if (no_pending_pkts)
1153 sta_info_clear_tim_bit(rx->sta); 1146 sta_info_clear_tim_bit(rx->sta);
@@ -1487,10 +1480,13 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1487 struct ieee80211s_hdr *mesh_hdr; 1480 struct ieee80211s_hdr *mesh_hdr;
1488 unsigned int hdrlen; 1481 unsigned int hdrlen;
1489 struct sk_buff *skb = rx->skb, *fwd_skb; 1482 struct sk_buff *skb = rx->skb, *fwd_skb;
1483 struct ieee80211_local *local = rx->local;
1484 struct ieee80211_sub_if_data *sdata;
1490 1485
1491 hdr = (struct ieee80211_hdr *) skb->data; 1486 hdr = (struct ieee80211_hdr *) skb->data;
1492 hdrlen = ieee80211_hdrlen(hdr->frame_control); 1487 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1493 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen); 1488 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
1489 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1494 1490
1495 if (!ieee80211_is_data(hdr->frame_control)) 1491 if (!ieee80211_is_data(hdr->frame_control))
1496 return RX_CONTINUE; 1492 return RX_CONTINUE;
@@ -1500,10 +1496,8 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1500 return RX_DROP_MONITOR; 1496 return RX_DROP_MONITOR;
1501 1497
1502 if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6){ 1498 if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6){
1503 struct ieee80211_sub_if_data *sdata;
1504 struct mesh_path *mppath; 1499 struct mesh_path *mppath;
1505 1500
1506 sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1507 rcu_read_lock(); 1501 rcu_read_lock();
1508 mppath = mpp_path_lookup(mesh_hdr->eaddr2, sdata); 1502 mppath = mpp_path_lookup(mesh_hdr->eaddr2, sdata);
1509 if (!mppath) { 1503 if (!mppath) {
@@ -1529,6 +1523,8 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1529 dropped_frames_ttl); 1523 dropped_frames_ttl);
1530 else { 1524 else {
1531 struct ieee80211_hdr *fwd_hdr; 1525 struct ieee80211_hdr *fwd_hdr;
1526 struct ieee80211_tx_info *info;
1527
1532 fwd_skb = skb_copy(skb, GFP_ATOMIC); 1528 fwd_skb = skb_copy(skb, GFP_ATOMIC);
1533 1529
1534 if (!fwd_skb && net_ratelimit()) 1530 if (!fwd_skb && net_ratelimit())
@@ -1542,9 +1538,25 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
1542 */ 1538 */
1543 memcpy(fwd_hdr->addr1, fwd_hdr->addr2, ETH_ALEN); 1539 memcpy(fwd_hdr->addr1, fwd_hdr->addr2, ETH_ALEN);
1544 memcpy(fwd_hdr->addr2, rx->dev->dev_addr, ETH_ALEN); 1540 memcpy(fwd_hdr->addr2, rx->dev->dev_addr, ETH_ALEN);
1545 fwd_skb->dev = rx->local->mdev; 1541 info = IEEE80211_SKB_CB(fwd_skb);
1546 fwd_skb->iif = rx->dev->ifindex; 1542 memset(info, 0, sizeof(*info));
1547 dev_queue_xmit(fwd_skb); 1543 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1544 info->control.vif = &rx->sdata->vif;
1545 ieee80211_select_queue(local, fwd_skb);
1546 if (is_multicast_ether_addr(fwd_hdr->addr3))
1547 memcpy(fwd_hdr->addr1, fwd_hdr->addr3,
1548 ETH_ALEN);
1549 else {
1550 int err = mesh_nexthop_lookup(fwd_skb, sdata);
1551 /* Failed to immediately resolve next hop:
1552 * fwded frame was dropped or will be added
1553 * later to the pending skb queue. */
1554 if (err)
1555 return RX_DROP_MONITOR;
1556 }
1557 IEEE80211_IFSTA_MESH_CTR_INC(&sdata->u.mesh,
1558 fwded_frames);
1559 ieee80211_add_pending_skb(local, fwd_skb);
1548 } 1560 }
1549 } 1561 }
1550 1562
@@ -1620,7 +1632,7 @@ ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx)
1620 /* manage reordering buffer according to requested */ 1632 /* manage reordering buffer according to requested */
1621 /* sequence number */ 1633 /* sequence number */
1622 rcu_read_lock(); 1634 rcu_read_lock();
1623 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL, NULL, 1635 ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, NULL,
1624 start_seq_num, 1); 1636 start_seq_num, 1);
1625 rcu_read_unlock(); 1637 rcu_read_unlock();
1626 return RX_DROP_UNUSABLE; 1638 return RX_DROP_UNUSABLE;
@@ -1644,12 +1656,7 @@ static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
1644 1656
1645 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 || 1657 if (compare_ether_addr(mgmt->sa, sdata->u.mgd.bssid) != 0 ||
1646 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) { 1658 compare_ether_addr(mgmt->bssid, sdata->u.mgd.bssid) != 0) {
1647 /* Not from the current AP. */ 1659 /* Not from the current AP or not associated yet. */
1648 return;
1649 }
1650
1651 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATE) {
1652 /* Association in progress; ignore SA Query */
1653 return; 1660 return;
1654 } 1661 }
1655 1662
@@ -1686,7 +1693,6 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1686 struct ieee80211_local *local = rx->local; 1693 struct ieee80211_local *local = rx->local;
1687 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev); 1694 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
1688 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data; 1695 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
1689 struct ieee80211_bss *bss;
1690 int len = rx->skb->len; 1696 int len = rx->skb->len;
1691 1697
1692 if (!ieee80211_is_action(mgmt->frame_control)) 1698 if (!ieee80211_is_action(mgmt->frame_control))
@@ -1764,17 +1770,7 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
1764 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN)) 1770 if (memcmp(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN))
1765 return RX_DROP_MONITOR; 1771 return RX_DROP_MONITOR;
1766 1772
1767 bss = ieee80211_rx_bss_get(local, sdata->u.mgd.bssid, 1773 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1768 local->hw.conf.channel->center_freq,
1769 sdata->u.mgd.ssid,
1770 sdata->u.mgd.ssid_len);
1771 if (!bss)
1772 return RX_DROP_MONITOR;
1773
1774 ieee80211_sta_process_chanswitch(sdata,
1775 &mgmt->u.action.u.chan_switch.sw_elem, bss);
1776 ieee80211_rx_bss_put(local, bss);
1777 break;
1778 } 1774 }
1779 break; 1775 break;
1780 case WLAN_CATEGORY_SA_QUERY: 1776 case WLAN_CATEGORY_SA_QUERY:
@@ -1817,19 +1813,18 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
1817 return RX_DROP_MONITOR; 1813 return RX_DROP_MONITOR;
1818 1814
1819 if (ieee80211_vif_is_mesh(&sdata->vif)) 1815 if (ieee80211_vif_is_mesh(&sdata->vif))
1820 return ieee80211_mesh_rx_mgmt(sdata, rx->skb, rx->status); 1816 return ieee80211_mesh_rx_mgmt(sdata, rx->skb);
1821 1817
1822 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 1818 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
1823 return ieee80211_ibss_rx_mgmt(sdata, rx->skb, rx->status); 1819 return ieee80211_ibss_rx_mgmt(sdata, rx->skb);
1824 1820
1825 if (sdata->vif.type == NL80211_IFTYPE_STATION) 1821 if (sdata->vif.type == NL80211_IFTYPE_STATION)
1826 return ieee80211_sta_rx_mgmt(sdata, rx->skb, rx->status); 1822 return ieee80211_sta_rx_mgmt(sdata, rx->skb);
1827 1823
1828 return RX_DROP_MONITOR; 1824 return RX_DROP_MONITOR;
1829} 1825}
1830 1826
1831static void ieee80211_rx_michael_mic_report(struct net_device *dev, 1827static void ieee80211_rx_michael_mic_report(struct ieee80211_hdr *hdr,
1832 struct ieee80211_hdr *hdr,
1833 struct ieee80211_rx_data *rx) 1828 struct ieee80211_rx_data *rx)
1834{ 1829{
1835 int keyidx; 1830 int keyidx;
@@ -1866,7 +1861,8 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1866 !ieee80211_is_auth(hdr->frame_control)) 1861 !ieee80211_is_auth(hdr->frame_control))
1867 goto ignore; 1862 goto ignore;
1868 1863
1869 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL); 1864 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL,
1865 GFP_ATOMIC);
1870 ignore: 1866 ignore:
1871 dev_kfree_skb(rx->skb); 1867 dev_kfree_skb(rx->skb);
1872 rx->skb = NULL; 1868 rx->skb = NULL;
@@ -2028,13 +2024,8 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2028 case NL80211_IFTYPE_STATION: 2024 case NL80211_IFTYPE_STATION:
2029 if (!bssid) 2025 if (!bssid)
2030 return 0; 2026 return 0;
2031 if (!ieee80211_bssid_match(bssid, sdata->u.mgd.bssid)) { 2027 if (!multicast &&
2032 if (!(rx->flags & IEEE80211_RX_IN_SCAN)) 2028 compare_ether_addr(sdata->dev->dev_addr, hdr->addr1) != 0) {
2033 return 0;
2034 rx->flags &= ~IEEE80211_RX_RA_MATCH;
2035 } else if (!multicast &&
2036 compare_ether_addr(sdata->dev->dev_addr,
2037 hdr->addr1) != 0) {
2038 if (!(sdata->dev->flags & IFF_PROMISC)) 2029 if (!(sdata->dev->flags & IFF_PROMISC))
2039 return 0; 2030 return 0;
2040 rx->flags &= ~IEEE80211_RX_RA_MATCH; 2031 rx->flags &= ~IEEE80211_RX_RA_MATCH;
@@ -2114,9 +2105,9 @@ static int prepare_for_handlers(struct ieee80211_sub_if_data *sdata,
2114 */ 2105 */
2115static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw, 2106static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2116 struct sk_buff *skb, 2107 struct sk_buff *skb,
2117 struct ieee80211_rx_status *status,
2118 struct ieee80211_rate *rate) 2108 struct ieee80211_rate *rate)
2119{ 2109{
2110 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2120 struct ieee80211_local *local = hw_to_local(hw); 2111 struct ieee80211_local *local = hw_to_local(hw);
2121 struct ieee80211_sub_if_data *sdata; 2112 struct ieee80211_sub_if_data *sdata;
2122 struct ieee80211_hdr *hdr; 2113 struct ieee80211_hdr *hdr;
@@ -2143,11 +2134,12 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
2143 } 2134 }
2144 2135
2145 if ((status->flag & RX_FLAG_MMIC_ERROR)) { 2136 if ((status->flag & RX_FLAG_MMIC_ERROR)) {
2146 ieee80211_rx_michael_mic_report(local->mdev, hdr, &rx); 2137 ieee80211_rx_michael_mic_report(hdr, &rx);
2147 return; 2138 return;
2148 } 2139 }
2149 2140
2150 if (unlikely(local->sw_scanning || local->hw_scanning)) 2141 if (unlikely(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
2142 test_bit(SCAN_OFF_CHANNEL, &local->scanning)))
2151 rx.flags |= IEEE80211_RX_IN_SCAN; 2143 rx.flags |= IEEE80211_RX_IN_SCAN;
2152 2144
2153 ieee80211_parse_qos(&rx); 2145 ieee80211_parse_qos(&rx);
@@ -2227,20 +2219,21 @@ static void ieee80211_release_reorder_frame(struct ieee80211_hw *hw,
2227{ 2219{
2228 struct ieee80211_supported_band *sband; 2220 struct ieee80211_supported_band *sband;
2229 struct ieee80211_rate *rate; 2221 struct ieee80211_rate *rate;
2230 struct ieee80211_rx_status status; 2222 struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
2223 struct ieee80211_rx_status *status;
2231 2224
2232 if (!tid_agg_rx->reorder_buf[index]) 2225 if (!skb)
2233 goto no_frame; 2226 goto no_frame;
2234 2227
2228 status = IEEE80211_SKB_RXCB(skb);
2229
2235 /* release the reordered frames to stack */ 2230 /* release the reordered frames to stack */
2236 memcpy(&status, tid_agg_rx->reorder_buf[index]->cb, sizeof(status)); 2231 sband = hw->wiphy->bands[status->band];
2237 sband = hw->wiphy->bands[status.band]; 2232 if (status->flag & RX_FLAG_HT)
2238 if (status.flag & RX_FLAG_HT)
2239 rate = sband->bitrates; /* TODO: HT rates */ 2233 rate = sband->bitrates; /* TODO: HT rates */
2240 else 2234 else
2241 rate = &sband->bitrates[status.rate_idx]; 2235 rate = &sband->bitrates[status->rate_idx];
2242 __ieee80211_rx_handle_packet(hw, tid_agg_rx->reorder_buf[index], 2236 __ieee80211_rx_handle_packet(hw, skb, rate);
2243 &status, rate);
2244 tid_agg_rx->stored_mpdu_num--; 2237 tid_agg_rx->stored_mpdu_num--;
2245 tid_agg_rx->reorder_buf[index] = NULL; 2238 tid_agg_rx->reorder_buf[index] = NULL;
2246 2239
@@ -2265,7 +2258,6 @@ no_frame:
2265static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw, 2258static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2266 struct tid_ampdu_rx *tid_agg_rx, 2259 struct tid_ampdu_rx *tid_agg_rx,
2267 struct sk_buff *skb, 2260 struct sk_buff *skb,
2268 struct ieee80211_rx_status *rxstatus,
2269 u16 mpdu_seq_num, 2261 u16 mpdu_seq_num,
2270 int bar_req) 2262 int bar_req)
2271{ 2263{
@@ -2324,8 +2316,6 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2324 /* put the frame in the reordering buffer */ 2316 /* put the frame in the reordering buffer */
2325 tid_agg_rx->reorder_buf[index] = skb; 2317 tid_agg_rx->reorder_buf[index] = skb;
2326 tid_agg_rx->reorder_time[index] = jiffies; 2318 tid_agg_rx->reorder_time[index] = jiffies;
2327 memcpy(tid_agg_rx->reorder_buf[index]->cb, rxstatus,
2328 sizeof(*rxstatus));
2329 tid_agg_rx->stored_mpdu_num++; 2319 tid_agg_rx->stored_mpdu_num++;
2330 /* release the buffer until next missing frame */ 2320 /* release the buffer until next missing frame */
2331 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn) 2321 index = seq_sub(tid_agg_rx->head_seq_num, tid_agg_rx->ssn)
@@ -2374,8 +2364,7 @@ static u8 ieee80211_sta_manage_reorder_buf(struct ieee80211_hw *hw,
2374} 2364}
2375 2365
2376static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local, 2366static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2377 struct sk_buff *skb, 2367 struct sk_buff *skb)
2378 struct ieee80211_rx_status *status)
2379{ 2368{
2380 struct ieee80211_hw *hw = &local->hw; 2369 struct ieee80211_hw *hw = &local->hw;
2381 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 2370 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
@@ -2424,7 +2413,7 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2424 2413
2425 /* according to mpdu sequence number deal with reordering buffer */ 2414 /* according to mpdu sequence number deal with reordering buffer */
2426 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4; 2415 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
2427 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb, status, 2416 ret = ieee80211_sta_manage_reorder_buf(hw, tid_agg_rx, skb,
2428 mpdu_seq_num, 0); 2417 mpdu_seq_num, 0);
2429 end_reorder: 2418 end_reorder:
2430 return ret; 2419 return ret;
@@ -2434,12 +2423,12 @@ static u8 ieee80211_rx_reorder_ampdu(struct ieee80211_local *local,
2434 * This is the receive path handler. It is called by a low level driver when an 2423 * This is the receive path handler. It is called by a low level driver when an
2435 * 802.11 MPDU is received from the hardware. 2424 * 802.11 MPDU is received from the hardware.
2436 */ 2425 */
2437void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 2426void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
2438 struct ieee80211_rx_status *status)
2439{ 2427{
2440 struct ieee80211_local *local = hw_to_local(hw); 2428 struct ieee80211_local *local = hw_to_local(hw);
2441 struct ieee80211_rate *rate = NULL; 2429 struct ieee80211_rate *rate = NULL;
2442 struct ieee80211_supported_band *sband; 2430 struct ieee80211_supported_band *sband;
2431 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
2443 2432
2444 if (status->band < 0 || 2433 if (status->band < 0 ||
2445 status->band >= IEEE80211_NUM_BANDS) { 2434 status->band >= IEEE80211_NUM_BANDS) {
@@ -2494,7 +2483,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2494 * if it was previously present. 2483 * if it was previously present.
2495 * Also, frames with less than 16 bytes are dropped. 2484 * Also, frames with less than 16 bytes are dropped.
2496 */ 2485 */
2497 skb = ieee80211_rx_monitor(local, skb, status, rate); 2486 skb = ieee80211_rx_monitor(local, skb, rate);
2498 if (!skb) { 2487 if (!skb) {
2499 rcu_read_unlock(); 2488 rcu_read_unlock();
2500 return; 2489 return;
@@ -2512,8 +2501,8 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2512 * frames from other than operational channel), but that should not 2501 * frames from other than operational channel), but that should not
2513 * happen in normal networks. 2502 * happen in normal networks.
2514 */ 2503 */
2515 if (!ieee80211_rx_reorder_ampdu(local, skb, status)) 2504 if (!ieee80211_rx_reorder_ampdu(local, skb))
2516 __ieee80211_rx_handle_packet(hw, skb, status, rate); 2505 __ieee80211_rx_handle_packet(hw, skb, rate);
2517 2506
2518 rcu_read_unlock(); 2507 rcu_read_unlock();
2519} 2508}
@@ -2521,16 +2510,12 @@ EXPORT_SYMBOL(__ieee80211_rx);
2521 2510
2522/* This is a version of the rx handler that can be called from hard irq 2511/* This is a version of the rx handler that can be called from hard irq
2523 * context. Post the skb on the queue and schedule the tasklet */ 2512 * context. Post the skb on the queue and schedule the tasklet */
2524void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb, 2513void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
2525 struct ieee80211_rx_status *status)
2526{ 2514{
2527 struct ieee80211_local *local = hw_to_local(hw); 2515 struct ieee80211_local *local = hw_to_local(hw);
2528 2516
2529 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb)); 2517 BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
2530 2518
2531 skb->dev = local->mdev;
2532 /* copy status into skb->cb for use by tasklet */
2533 memcpy(skb->cb, status, sizeof(*status));
2534 skb->pkt_type = IEEE80211_RX_MSG; 2519 skb->pkt_type = IEEE80211_RX_MSG;
2535 skb_queue_tail(&local->skb_queue, skb); 2520 skb_queue_tail(&local->skb_queue, skb);
2536 tasklet_schedule(&local->tasklet); 2521 tasklet_schedule(&local->tasklet);
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 2a8d09ad17ff..244f53f3c8b4 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -18,7 +18,6 @@
18#include <linux/if_arp.h> 18#include <linux/if_arp.h>
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <net/mac80211.h> 20#include <net/mac80211.h>
21#include <net/iw_handler.h>
22 21
23#include "ieee80211_i.h" 22#include "ieee80211_i.h"
24#include "driver-ops.h" 23#include "driver-ops.h"
@@ -26,7 +25,7 @@
26 25
27#define IEEE80211_PROBE_DELAY (HZ / 33) 26#define IEEE80211_PROBE_DELAY (HZ / 33)
28#define IEEE80211_CHANNEL_TIME (HZ / 33) 27#define IEEE80211_CHANNEL_TIME (HZ / 33)
29#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) 28#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 8)
30 29
31struct ieee80211_bss * 30struct ieee80211_bss *
32ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, 31ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
@@ -121,23 +120,10 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
121 return bss; 120 return bss;
122} 121}
123 122
124void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
125 int freq, u8 *ssid, u8 ssid_len)
126{
127 struct ieee80211_bss *bss;
128 struct ieee80211_local *local = sdata->local;
129
130 bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len);
131 if (bss) {
132 cfg80211_unlink_bss(local->hw.wiphy, (void *)bss);
133 ieee80211_rx_bss_put(local, bss);
134 }
135}
136
137ieee80211_rx_result 123ieee80211_rx_result
138ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 124ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
139 struct ieee80211_rx_status *rx_status)
140{ 125{
126 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
141 struct ieee80211_mgmt *mgmt; 127 struct ieee80211_mgmt *mgmt;
142 struct ieee80211_bss *bss; 128 struct ieee80211_bss *bss;
143 u8 *elements; 129 u8 *elements;
@@ -278,7 +264,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
278 264
279 mutex_lock(&local->scan_mtx); 265 mutex_lock(&local->scan_mtx);
280 266
281 if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) { 267 if (WARN_ON(!local->scanning)) {
282 mutex_unlock(&local->scan_mtx); 268 mutex_unlock(&local->scan_mtx);
283 return; 269 return;
284 } 270 }
@@ -288,16 +274,15 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
288 return; 274 return;
289 } 275 }
290 276
291 if (local->hw_scanning) 277 if (test_bit(SCAN_HW_SCANNING, &local->scanning))
292 ieee80211_restore_scan_ies(local); 278 ieee80211_restore_scan_ies(local);
293 279
294 if (local->scan_req != &local->int_scan_req) 280 if (local->scan_req != &local->int_scan_req)
295 cfg80211_scan_done(local->scan_req, aborted); 281 cfg80211_scan_done(local->scan_req, aborted);
296 local->scan_req = NULL; 282 local->scan_req = NULL;
297 283
298 was_hw_scan = local->hw_scanning; 284 was_hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
299 local->hw_scanning = false; 285 local->scanning = 0;
300 local->sw_scanning = false;
301 local->scan_channel = NULL; 286 local->scan_channel = NULL;
302 287
303 /* we only have to protect scan_req and hw/sw scan */ 288 /* we only have to protect scan_req and hw/sw scan */
@@ -307,16 +292,13 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
307 if (was_hw_scan) 292 if (was_hw_scan)
308 goto done; 293 goto done;
309 294
310 netif_tx_lock_bh(local->mdev); 295 spin_lock_bh(&local->filter_lock);
311 netif_addr_lock(local->mdev);
312 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; 296 local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
313 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC, 297 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
314 &local->filter_flags, 298 &local->filter_flags,
315 local->mdev->mc_count, 299 local->mc_count,
316 local->mdev->mc_list); 300 local->mc_list);
317 301 spin_unlock_bh(&local->filter_lock);
318 netif_addr_unlock(local->mdev);
319 netif_tx_unlock_bh(local->mdev);
320 302
321 drv_sw_scan_complete(local); 303 drv_sw_scan_complete(local);
322 304
@@ -327,7 +309,7 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
327 309
328 /* Tell AP we're back */ 310 /* Tell AP we're back */
329 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 311 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
330 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { 312 if (sdata->u.mgd.associated) {
331 ieee80211_scan_ps_disable(sdata); 313 ieee80211_scan_ps_disable(sdata);
332 netif_tx_wake_all_queues(sdata->dev); 314 netif_tx_wake_all_queues(sdata->dev);
333 } 315 }
@@ -382,30 +364,30 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
382 ieee80211_bss_info_change_notify( 364 ieee80211_bss_info_change_notify(
383 sdata, BSS_CHANGED_BEACON_ENABLED); 365 sdata, BSS_CHANGED_BEACON_ENABLED);
384 366
385 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 367 /*
386 if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { 368 * only handle non-STA interfaces here, STA interfaces
387 netif_tx_stop_all_queues(sdata->dev); 369 * are handled in the scan state machine
388 ieee80211_scan_ps_enable(sdata); 370 */
389 } 371 if (sdata->vif.type != NL80211_IFTYPE_STATION)
390 } else
391 netif_tx_stop_all_queues(sdata->dev); 372 netif_tx_stop_all_queues(sdata->dev);
392 } 373 }
393 mutex_unlock(&local->iflist_mtx); 374 mutex_unlock(&local->iflist_mtx);
394 375
395 local->scan_state = SCAN_SET_CHANNEL; 376 local->next_scan_state = SCAN_DECISION;
396 local->scan_channel_idx = 0; 377 local->scan_channel_idx = 0;
397 378
398 netif_addr_lock_bh(local->mdev); 379 spin_lock_bh(&local->filter_lock);
399 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; 380 local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
400 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC, 381 drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
401 &local->filter_flags, 382 &local->filter_flags,
402 local->mdev->mc_count, 383 local->mc_count,
403 local->mdev->mc_list); 384 local->mc_list);
404 netif_addr_unlock_bh(local->mdev); 385 spin_unlock_bh(&local->filter_lock);
405 386
406 /* TODO: start scan as soon as all nullfunc frames are ACKed */ 387 /* TODO: start scan as soon as all nullfunc frames are ACKed */
407 queue_delayed_work(local->hw.workqueue, &local->scan_work, 388 ieee80211_queue_delayed_work(&local->hw,
408 IEEE80211_CHANNEL_TIME); 389 &local->scan_work,
390 IEEE80211_CHANNEL_TIME);
409 391
410 return 0; 392 return 0;
411} 393}
@@ -443,18 +425,16 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
443 425
444 if (req != &local->int_scan_req && 426 if (req != &local->int_scan_req &&
445 sdata->vif.type == NL80211_IFTYPE_STATION && 427 sdata->vif.type == NL80211_IFTYPE_STATION &&
446 (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE || 428 !list_empty(&ifmgd->work_list)) {
447 ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE || 429 /* actually wait for the work it's doing to finish/time out */
448 ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE)) {
449 /* actually wait for the assoc to finish/time out */
450 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request); 430 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
451 return 0; 431 return 0;
452 } 432 }
453 433
454 if (local->ops->hw_scan) 434 if (local->ops->hw_scan)
455 local->hw_scanning = true; 435 __set_bit(SCAN_HW_SCANNING, &local->scanning);
456 else 436 else
457 local->sw_scanning = true; 437 __set_bit(SCAN_SW_SCANNING, &local->scanning);
458 /* 438 /*
459 * Kicking off the scan need not be protected, 439 * Kicking off the scan need not be protected,
460 * only the scan variable stuff, since now 440 * only the scan variable stuff, since now
@@ -477,11 +457,9 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
477 mutex_lock(&local->scan_mtx); 457 mutex_lock(&local->scan_mtx);
478 458
479 if (rc) { 459 if (rc) {
480 if (local->ops->hw_scan) { 460 if (local->ops->hw_scan)
481 local->hw_scanning = false;
482 ieee80211_restore_scan_ies(local); 461 ieee80211_restore_scan_ies(local);
483 } else 462 local->scanning = 0;
484 local->sw_scanning = false;
485 463
486 ieee80211_recalc_idle(local); 464 ieee80211_recalc_idle(local);
487 465
@@ -492,13 +470,195 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
492 return rc; 470 return rc;
493} 471}
494 472
473static int ieee80211_scan_state_decision(struct ieee80211_local *local,
474 unsigned long *next_delay)
475{
476 bool associated = false;
477 struct ieee80211_sub_if_data *sdata;
478
479 /* if no more bands/channels left, complete scan and advance to the idle state */
480 if (local->scan_channel_idx >= local->scan_req->n_channels) {
481 ieee80211_scan_completed(&local->hw, false);
482 return 1;
483 }
484
485 /* check if at least one STA interface is associated */
486 mutex_lock(&local->iflist_mtx);
487 list_for_each_entry(sdata, &local->interfaces, list) {
488 if (!netif_running(sdata->dev))
489 continue;
490
491 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
492 if (sdata->u.mgd.associated) {
493 associated = true;
494 break;
495 }
496 }
497 }
498 mutex_unlock(&local->iflist_mtx);
499
500 if (local->scan_channel) {
501 /*
502 * we're currently scanning a different channel, let's
503 * switch back to the operating channel now if at least
504 * one interface is associated. Otherwise just scan the
505 * next channel
506 */
507 if (associated)
508 local->next_scan_state = SCAN_ENTER_OPER_CHANNEL;
509 else
510 local->next_scan_state = SCAN_SET_CHANNEL;
511 } else {
512 /*
513 * we're on the operating channel currently, let's
514 * leave that channel now to scan another one
515 */
516 local->next_scan_state = SCAN_LEAVE_OPER_CHANNEL;
517 }
518
519 *next_delay = 0;
520 return 0;
521}
522
523static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
524 unsigned long *next_delay)
525{
526 struct ieee80211_sub_if_data *sdata;
527
528 /*
529 * notify the AP about us leaving the channel and stop all STA interfaces
530 */
531 mutex_lock(&local->iflist_mtx);
532 list_for_each_entry(sdata, &local->interfaces, list) {
533 if (!netif_running(sdata->dev))
534 continue;
535
536 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
537 netif_tx_stop_all_queues(sdata->dev);
538 if (sdata->u.mgd.associated)
539 ieee80211_scan_ps_enable(sdata);
540 }
541 }
542 mutex_unlock(&local->iflist_mtx);
543
544 __set_bit(SCAN_OFF_CHANNEL, &local->scanning);
545
546 /* advance to the next channel to be scanned */
547 *next_delay = HZ / 10;
548 local->next_scan_state = SCAN_SET_CHANNEL;
549}
550
551static void ieee80211_scan_state_enter_oper_channel(struct ieee80211_local *local,
552 unsigned long *next_delay)
553{
554 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
555
556 /* switch back to the operating channel */
557 local->scan_channel = NULL;
558 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
559
560 /*
561 * notify the AP about us being back and restart all STA interfaces
562 */
563 mutex_lock(&local->iflist_mtx);
564 list_for_each_entry(sdata, &local->interfaces, list) {
565 if (!netif_running(sdata->dev))
566 continue;
567
568 /* Tell AP we're back */
569 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
570 if (sdata->u.mgd.associated)
571 ieee80211_scan_ps_disable(sdata);
572 netif_tx_wake_all_queues(sdata->dev);
573 }
574 }
575 mutex_unlock(&local->iflist_mtx);
576
577 __clear_bit(SCAN_OFF_CHANNEL, &local->scanning);
578
579 *next_delay = HZ / 5;
580 local->next_scan_state = SCAN_DECISION;
581}
582
583static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
584 unsigned long *next_delay)
585{
586 int skip;
587 struct ieee80211_channel *chan;
588 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
589
590 skip = 0;
591 chan = local->scan_req->channels[local->scan_channel_idx];
592
593 if (chan->flags & IEEE80211_CHAN_DISABLED ||
594 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
595 chan->flags & IEEE80211_CHAN_NO_IBSS))
596 skip = 1;
597
598 if (!skip) {
599 local->scan_channel = chan;
600 if (ieee80211_hw_config(local,
601 IEEE80211_CONF_CHANGE_CHANNEL))
602 skip = 1;
603 }
604
605 /* advance state machine to next channel/band */
606 local->scan_channel_idx++;
607
608 if (skip) {
609 /* if we skip this channel return to the decision state */
610 local->next_scan_state = SCAN_DECISION;
611 return;
612 }
613
614 /*
615 * Probe delay is used to update the NAV, cf. 11.1.3.2.2
616 * (which unfortunately doesn't say _why_ step a) is done,
617 * but it waits for the probe delay or until a frame is
618 * received - and the received frame would update the NAV).
619 * For now, we do not support waiting until a frame is
620 * received.
621 *
622 * In any case, it is not necessary for a passive scan.
623 */
624 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
625 !local->scan_req->n_ssids) {
626 *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
627 local->next_scan_state = SCAN_DECISION;
628 return;
629 }
630
631 /* active scan, send probes */
632 *next_delay = IEEE80211_PROBE_DELAY;
633 local->next_scan_state = SCAN_SEND_PROBE;
634}
635
636static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
637 unsigned long *next_delay)
638{
639 int i;
640 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
641
642 for (i = 0; i < local->scan_req->n_ssids; i++)
643 ieee80211_send_probe_req(
644 sdata, NULL,
645 local->scan_req->ssids[i].ssid,
646 local->scan_req->ssids[i].ssid_len,
647 local->scan_req->ie, local->scan_req->ie_len);
648
649 /*
650 * After sending probe requests, wait for probe responses
651 * on the channel.
652 */
653 *next_delay = IEEE80211_CHANNEL_TIME;
654 local->next_scan_state = SCAN_DECISION;
655}
656
495void ieee80211_scan_work(struct work_struct *work) 657void ieee80211_scan_work(struct work_struct *work)
496{ 658{
497 struct ieee80211_local *local = 659 struct ieee80211_local *local =
498 container_of(work, struct ieee80211_local, scan_work.work); 660 container_of(work, struct ieee80211_local, scan_work.work);
499 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 661 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
500 struct ieee80211_channel *chan;
501 int skip, i;
502 unsigned long next_delay = 0; 662 unsigned long next_delay = 0;
503 663
504 mutex_lock(&local->scan_mtx); 664 mutex_lock(&local->scan_mtx);
@@ -507,7 +667,7 @@ void ieee80211_scan_work(struct work_struct *work)
507 return; 667 return;
508 } 668 }
509 669
510 if (local->scan_req && !(local->sw_scanning || local->hw_scanning)) { 670 if (local->scan_req && !local->scanning) {
511 struct cfg80211_scan_request *req = local->scan_req; 671 struct cfg80211_scan_request *req = local->scan_req;
512 int rc; 672 int rc;
513 673
@@ -531,72 +691,32 @@ void ieee80211_scan_work(struct work_struct *work)
531 return; 691 return;
532 } 692 }
533 693
534 switch (local->scan_state) { 694 /*
535 case SCAN_SET_CHANNEL: 695 * as long as no delay is required advance immediately
536 /* if no more bands/channels left, complete scan */ 696 * without scheduling a new work
537 if (local->scan_channel_idx >= local->scan_req->n_channels) { 697 */
538 ieee80211_scan_completed(&local->hw, false); 698 do {
539 return; 699 switch (local->next_scan_state) {
540 } 700 case SCAN_DECISION:
541 skip = 0; 701 if (ieee80211_scan_state_decision(local, &next_delay))
542 chan = local->scan_req->channels[local->scan_channel_idx]; 702 return;
543
544 if (chan->flags & IEEE80211_CHAN_DISABLED ||
545 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
546 chan->flags & IEEE80211_CHAN_NO_IBSS))
547 skip = 1;
548
549 if (!skip) {
550 local->scan_channel = chan;
551 if (ieee80211_hw_config(local,
552 IEEE80211_CONF_CHANGE_CHANNEL))
553 skip = 1;
554 }
555
556 /* advance state machine to next channel/band */
557 local->scan_channel_idx++;
558
559 if (skip)
560 break; 703 break;
561 704 case SCAN_SET_CHANNEL:
562 /* 705 ieee80211_scan_state_set_channel(local, &next_delay);
563 * Probe delay is used to update the NAV, cf. 11.1.3.2.2 706 break;
564 * (which unfortunately doesn't say _why_ step a) is done, 707 case SCAN_SEND_PROBE:
565 * but it waits for the probe delay or until a frame is 708 ieee80211_scan_state_send_probe(local, &next_delay);
566 * received - and the received frame would update the NAV). 709 break;
567 * For now, we do not support waiting until a frame is 710 case SCAN_LEAVE_OPER_CHANNEL:
568 * received. 711 ieee80211_scan_state_leave_oper_channel(local, &next_delay);
569 * 712 break;
570 * In any case, it is not necessary for a passive scan. 713 case SCAN_ENTER_OPER_CHANNEL:
571 */ 714 ieee80211_scan_state_enter_oper_channel(local, &next_delay);
572 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
573 !local->scan_req->n_ssids) {
574 next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
575 break; 715 break;
576 } 716 }
717 } while (next_delay == 0);
577 718
578 next_delay = IEEE80211_PROBE_DELAY; 719 ieee80211_queue_delayed_work(&local->hw, &local->scan_work, next_delay);
579 local->scan_state = SCAN_SEND_PROBE;
580 break;
581 case SCAN_SEND_PROBE:
582 for (i = 0; i < local->scan_req->n_ssids; i++)
583 ieee80211_send_probe_req(
584 sdata, NULL,
585 local->scan_req->ssids[i].ssid,
586 local->scan_req->ssids[i].ssid_len,
587 local->scan_req->ie, local->scan_req->ie_len);
588
589 /*
590 * After sending probe requests, wait for probe responses
591 * on the channel.
592 */
593 next_delay = IEEE80211_CHANNEL_TIME;
594 local->scan_state = SCAN_SET_CHANNEL;
595 break;
596 }
597
598 queue_delayed_work(local->hw.workqueue, &local->scan_work,
599 next_delay);
600} 720}
601 721
602int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, 722int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
@@ -643,7 +763,7 @@ void ieee80211_scan_cancel(struct ieee80211_local *local)
643 * queued -- mostly at suspend under RTNL. 763 * queued -- mostly at suspend under RTNL.
644 */ 764 */
645 mutex_lock(&local->scan_mtx); 765 mutex_lock(&local->scan_mtx);
646 swscan = local->sw_scanning; 766 swscan = test_bit(SCAN_SW_SCANNING, &local->scanning);
647 mutex_unlock(&local->scan_mtx); 767 mutex_unlock(&local->scan_mtx);
648 768
649 if (swscan) 769 if (swscan)
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 49a1a1f76511..ccc3adf962c7 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -30,7 +30,6 @@
30 * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP. 30 * @WLAN_STA_ASSOC_AP: We're associated to that station, it is an AP.
31 * @WLAN_STA_WME: Station is a QoS-STA. 31 * @WLAN_STA_WME: Station is a QoS-STA.
32 * @WLAN_STA_WDS: Station is one of our WDS peers. 32 * @WLAN_STA_WDS: Station is one of our WDS peers.
33 * @WLAN_STA_PSPOLL: Station has just PS-polled us.
34 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the 33 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
35 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next 34 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
36 * frame to this station is transmitted. 35 * frame to this station is transmitted.
@@ -47,7 +46,6 @@ enum ieee80211_sta_info_flags {
47 WLAN_STA_ASSOC_AP = 1<<5, 46 WLAN_STA_ASSOC_AP = 1<<5,
48 WLAN_STA_WME = 1<<6, 47 WLAN_STA_WME = 1<<6,
49 WLAN_STA_WDS = 1<<7, 48 WLAN_STA_WDS = 1<<7,
50 WLAN_STA_PSPOLL = 1<<8,
51 WLAN_STA_CLEAR_PS_FILT = 1<<9, 49 WLAN_STA_CLEAR_PS_FILT = 1<<9,
52 WLAN_STA_MFP = 1<<10, 50 WLAN_STA_MFP = 1<<10,
53 WLAN_STA_SUSPEND = 1<<11 51 WLAN_STA_SUSPEND = 1<<11
@@ -308,6 +306,23 @@ struct sta_info {
308 struct dentry *inactive_ms; 306 struct dentry *inactive_ms;
309 struct dentry *last_seq_ctrl; 307 struct dentry *last_seq_ctrl;
310 struct dentry *agg_status; 308 struct dentry *agg_status;
309 struct dentry *aid;
310 struct dentry *dev;
311 struct dentry *rx_packets;
312 struct dentry *tx_packets;
313 struct dentry *rx_bytes;
314 struct dentry *tx_bytes;
315 struct dentry *rx_duplicates;
316 struct dentry *rx_fragments;
317 struct dentry *rx_dropped;
318 struct dentry *tx_fragments;
319 struct dentry *tx_filtered;
320 struct dentry *tx_retry_failed;
321 struct dentry *tx_retry_count;
322 struct dentry *last_signal;
323 struct dentry *last_qual;
324 struct dentry *last_noise;
325 struct dentry *wep_weak_iv_count;
311 bool add_has_run; 326 bool add_has_run;
312 } debugfs; 327 } debugfs;
313#endif 328#endif
@@ -342,17 +357,6 @@ static inline void clear_sta_flags(struct sta_info *sta, const u32 flags)
342 spin_unlock_irqrestore(&sta->flaglock, irqfl); 357 spin_unlock_irqrestore(&sta->flaglock, irqfl);
343} 358}
344 359
345static inline void set_and_clear_sta_flags(struct sta_info *sta,
346 const u32 set, const u32 clear)
347{
348 unsigned long irqfl;
349
350 spin_lock_irqsave(&sta->flaglock, irqfl);
351 sta->flags |= set;
352 sta->flags &= ~clear;
353 spin_unlock_irqrestore(&sta->flaglock, irqfl);
354}
355
356static inline u32 test_sta_flags(struct sta_info *sta, const u32 flags) 360static inline u32 test_sta_flags(struct sta_info *sta, const u32 flags)
357{ 361{
358 u32 ret; 362 u32 ret;
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 3a8922cd1038..7cffaa046b33 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -192,7 +192,7 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
192 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) 192 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
193 return TX_CONTINUE; 193 return TX_CONTINUE;
194 194
195 if (unlikely(tx->local->sw_scanning) && 195 if (unlikely(test_bit(SCAN_OFF_CHANNEL, &tx->local->scanning)) &&
196 !ieee80211_is_probe_req(hdr->frame_control) && 196 !ieee80211_is_probe_req(hdr->frame_control) &&
197 !ieee80211_is_nullfunc(hdr->frame_control)) 197 !ieee80211_is_nullfunc(hdr->frame_control))
198 /* 198 /*
@@ -373,7 +373,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
373 staflags = get_sta_flags(sta); 373 staflags = get_sta_flags(sta);
374 374
375 if (unlikely((staflags & WLAN_STA_PS) && 375 if (unlikely((staflags & WLAN_STA_PS) &&
376 !(staflags & WLAN_STA_PSPOLL))) { 376 !(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE))) {
377#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 377#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
378 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries " 378 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
379 "before %d)\n", 379 "before %d)\n",
@@ -400,6 +400,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
400 sta_info_set_tim_bit(sta); 400 sta_info_set_tim_bit(sta);
401 401
402 info->control.jiffies = jiffies; 402 info->control.jiffies = jiffies;
403 info->control.vif = &tx->sdata->vif;
403 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 404 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
404 skb_queue_tail(&sta->ps_tx_buf, tx->skb); 405 skb_queue_tail(&sta->ps_tx_buf, tx->skb);
405 return TX_QUEUED; 406 return TX_QUEUED;
@@ -411,24 +412,7 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
411 sta->sta.addr); 412 sta->sta.addr);
412 } 413 }
413#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 414#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
414 if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
415 /*
416 * The sleeping station with pending data is now snoozing.
417 * It queried us for its buffered frames and will go back
418 * to deep sleep once it got everything.
419 *
420 * inform the driver, in case the hardware does powersave
421 * frame filtering and keeps a station blacklist on its own
422 * (e.g: p54), so that frames can be delivered unimpeded.
423 *
424 * Note: It should be safe to disable the filter now.
425 * As, it is really unlikely that we still have any pending
426 * frame for this station in the hw's buffers/fifos left,
427 * that is not rejected with a unsuccessful tx_status yet.
428 */
429 415
430 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
431 }
432 return TX_CONTINUE; 416 return TX_CONTINUE;
433} 417}
434 418
@@ -451,7 +435,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
451 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 435 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
452 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 436 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
453 437
454 if (unlikely(tx->skb->do_not_encrypt)) 438 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
455 tx->key = NULL; 439 tx->key = NULL;
456 else if (tx->sta && (key = rcu_dereference(tx->sta->key))) 440 else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
457 tx->key = key; 441 tx->key = key;
@@ -497,7 +481,7 @@ ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
497 } 481 }
498 482
499 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) 483 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
500 tx->skb->do_not_encrypt = 1; 484 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
501 485
502 return TX_CONTINUE; 486 return TX_CONTINUE;
503} 487}
@@ -512,6 +496,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
512 int i, len; 496 int i, len;
513 bool inval = false, rts = false, short_preamble = false; 497 bool inval = false, rts = false, short_preamble = false;
514 struct ieee80211_tx_rate_control txrc; 498 struct ieee80211_tx_rate_control txrc;
499 u32 sta_flags;
515 500
516 memset(&txrc, 0, sizeof(txrc)); 501 memset(&txrc, 0, sizeof(txrc));
517 502
@@ -544,7 +529,26 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
544 (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) 529 (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
545 txrc.short_preamble = short_preamble = true; 530 txrc.short_preamble = short_preamble = true;
546 531
532 sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0;
547 533
534 /*
535 * Lets not bother rate control if we're associated and cannot
536 * talk to the sta. This should not happen.
537 */
538 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) &&
539 (sta_flags & WLAN_STA_ASSOC) &&
540 !rate_usable_index_exists(sband, &tx->sta->sta),
541 "%s: Dropped data frame as no usable bitrate found while "
542 "scanning and associated. Target station: "
543 "%pM on %d GHz band\n",
544 tx->dev->name, hdr->addr1,
545 tx->channel->band ? 5 : 2))
546 return TX_DROP;
547
548 /*
549 * If we're associated with the sta at this point we know we can at
550 * least send the frame at the lowest bit rate.
551 */
548 rate_control_get_rate(tx->sdata, tx->sta, &txrc); 552 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
549 553
550 if (unlikely(info->control.rates[0].idx < 0)) 554 if (unlikely(info->control.rates[0].idx < 0))
@@ -676,7 +680,7 @@ ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
676 * number, if we have no matching interface then we 680 * number, if we have no matching interface then we
677 * neither assign one ourselves nor ask the driver to. 681 * neither assign one ourselves nor ask the driver to.
678 */ 682 */
679 if (unlikely(!info->control.vif)) 683 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
680 return TX_CONTINUE; 684 return TX_CONTINUE;
681 685
682 if (unlikely(ieee80211_is_ctl(hdr->frame_control))) 686 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
@@ -754,9 +758,7 @@ static int ieee80211_fragment(struct ieee80211_local *local,
754 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb)); 758 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
755 skb_copy_queue_mapping(tmp, skb); 759 skb_copy_queue_mapping(tmp, skb);
756 tmp->priority = skb->priority; 760 tmp->priority = skb->priority;
757 tmp->do_not_encrypt = skb->do_not_encrypt;
758 tmp->dev = skb->dev; 761 tmp->dev = skb->dev;
759 tmp->iif = skb->iif;
760 762
761 /* copy header and data */ 763 /* copy header and data */
762 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen); 764 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
@@ -784,7 +786,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
784 786
785 /* 787 /*
786 * Warn when submitting a fragmented A-MPDU frame and drop it. 788 * Warn when submitting a fragmented A-MPDU frame and drop it.
787 * This scenario is handled in __ieee80211_tx_prepare but extra 789 * This scenario is handled in ieee80211_tx_prepare but extra
788 * caution taken here as fragmented ampdu may cause Tx stop. 790 * caution taken here as fragmented ampdu may cause Tx stop.
789 */ 791 */
790 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU)) 792 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
@@ -923,11 +925,12 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
923 struct ieee80211_radiotap_header *rthdr = 925 struct ieee80211_radiotap_header *rthdr =
924 (struct ieee80211_radiotap_header *) skb->data; 926 (struct ieee80211_radiotap_header *) skb->data;
925 struct ieee80211_supported_band *sband; 927 struct ieee80211_supported_band *sband;
928 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
926 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); 929 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
927 930
928 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 931 sband = tx->local->hw.wiphy->bands[tx->channel->band];
929 932
930 skb->do_not_encrypt = 1; 933 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
931 tx->flags &= ~IEEE80211_TX_FRAGMENTED; 934 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
932 935
933 /* 936 /*
@@ -965,7 +968,7 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
965 skb_trim(skb, skb->len - FCS_LEN); 968 skb_trim(skb, skb->len - FCS_LEN);
966 } 969 }
967 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) 970 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
968 tx->skb->do_not_encrypt = 0; 971 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
969 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) 972 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
970 tx->flags |= IEEE80211_TX_FRAGMENTED; 973 tx->flags |= IEEE80211_TX_FRAGMENTED;
971 break; 974 break;
@@ -998,13 +1001,12 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
998 * initialises @tx 1001 * initialises @tx
999 */ 1002 */
1000static ieee80211_tx_result 1003static ieee80211_tx_result
1001__ieee80211_tx_prepare(struct ieee80211_tx_data *tx, 1004ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1002 struct sk_buff *skb, 1005 struct ieee80211_tx_data *tx,
1003 struct net_device *dev) 1006 struct sk_buff *skb)
1004{ 1007{
1005 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1008 struct ieee80211_local *local = sdata->local;
1006 struct ieee80211_hdr *hdr; 1009 struct ieee80211_hdr *hdr;
1007 struct ieee80211_sub_if_data *sdata;
1008 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1010 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1009 int hdrlen, tid; 1011 int hdrlen, tid;
1010 u8 *qc, *state; 1012 u8 *qc, *state;
@@ -1012,9 +1014,9 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1012 1014
1013 memset(tx, 0, sizeof(*tx)); 1015 memset(tx, 0, sizeof(*tx));
1014 tx->skb = skb; 1016 tx->skb = skb;
1015 tx->dev = dev; /* use original interface */ 1017 tx->dev = sdata->dev; /* use original interface */
1016 tx->local = local; 1018 tx->local = local;
1017 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1019 tx->sdata = sdata;
1018 tx->channel = local->hw.conf.channel; 1020 tx->channel = local->hw.conf.channel;
1019 /* 1021 /*
1020 * Set this flag (used below to indicate "automatic fragmentation"), 1022 * Set this flag (used below to indicate "automatic fragmentation"),
@@ -1023,7 +1025,6 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1023 tx->flags |= IEEE80211_TX_FRAGMENTED; 1025 tx->flags |= IEEE80211_TX_FRAGMENTED;
1024 1026
1025 /* process and remove the injection radiotap header */ 1027 /* process and remove the injection radiotap header */
1026 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1027 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) { 1028 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
1028 if (!__ieee80211_parse_tx_radiotap(tx, skb)) 1029 if (!__ieee80211_parse_tx_radiotap(tx, skb))
1029 return TX_DROP; 1030 return TX_DROP;
@@ -1075,6 +1076,7 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1075 } else if (*state != HT_AGG_STATE_IDLE) { 1076 } else if (*state != HT_AGG_STATE_IDLE) {
1076 /* in progress */ 1077 /* in progress */
1077 queued = true; 1078 queued = true;
1079 info->control.vif = &sdata->vif;
1078 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; 1080 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1079 __skb_queue_tail(&tid_tx->pending, skb); 1081 __skb_queue_tail(&tid_tx->pending, skb);
1080 } 1082 }
@@ -1119,50 +1121,29 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1119 return TX_CONTINUE; 1121 return TX_CONTINUE;
1120} 1122}
1121 1123
1122/*
1123 * NB: @tx is uninitialised when passed in here
1124 */
1125static int ieee80211_tx_prepare(struct ieee80211_local *local,
1126 struct ieee80211_tx_data *tx,
1127 struct sk_buff *skb)
1128{
1129 struct net_device *dev;
1130
1131 dev = dev_get_by_index(&init_net, skb->iif);
1132 if (unlikely(dev && !is_ieee80211_device(local, dev))) {
1133 dev_put(dev);
1134 dev = NULL;
1135 }
1136 if (unlikely(!dev))
1137 return -ENODEV;
1138 /*
1139 * initialises tx with control
1140 *
1141 * return value is safe to ignore here because this function
1142 * can only be invoked for multicast frames
1143 *
1144 * XXX: clean up
1145 */
1146 __ieee80211_tx_prepare(tx, skb, dev);
1147 dev_put(dev);
1148 return 0;
1149}
1150
1151static int __ieee80211_tx(struct ieee80211_local *local, 1124static int __ieee80211_tx(struct ieee80211_local *local,
1152 struct sk_buff **skbp, 1125 struct sk_buff **skbp,
1153 struct sta_info *sta) 1126 struct sta_info *sta,
1127 bool txpending)
1154{ 1128{
1155 struct sk_buff *skb = *skbp, *next; 1129 struct sk_buff *skb = *skbp, *next;
1156 struct ieee80211_tx_info *info; 1130 struct ieee80211_tx_info *info;
1131 struct ieee80211_sub_if_data *sdata;
1132 unsigned long flags;
1157 int ret, len; 1133 int ret, len;
1158 bool fragm = false; 1134 bool fragm = false;
1159 1135
1160 local->mdev->trans_start = jiffies;
1161
1162 while (skb) { 1136 while (skb) {
1163 if (ieee80211_queue_stopped(&local->hw, 1137 int q = skb_get_queue_mapping(skb);
1164 skb_get_queue_mapping(skb))) 1138
1165 return IEEE80211_TX_PENDING; 1139 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1140 ret = IEEE80211_TX_OK;
1141 if (local->queue_stop_reasons[q] ||
1142 (!txpending && !skb_queue_empty(&local->pending[q])))
1143 ret = IEEE80211_TX_PENDING;
1144 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1145 if (ret != IEEE80211_TX_OK)
1146 return ret;
1166 1147
1167 info = IEEE80211_SKB_CB(skb); 1148 info = IEEE80211_SKB_CB(skb);
1168 1149
@@ -1172,13 +1153,32 @@ static int __ieee80211_tx(struct ieee80211_local *local,
1172 1153
1173 next = skb->next; 1154 next = skb->next;
1174 len = skb->len; 1155 len = skb->len;
1156
1157 sdata = vif_to_sdata(info->control.vif);
1158
1159 switch (sdata->vif.type) {
1160 case NL80211_IFTYPE_MONITOR:
1161 info->control.vif = NULL;
1162 break;
1163 case NL80211_IFTYPE_AP_VLAN:
1164 info->control.vif = &container_of(sdata->bss,
1165 struct ieee80211_sub_if_data, u.ap)->vif;
1166 break;
1167 default:
1168 /* keep */
1169 break;
1170 }
1171
1175 ret = drv_tx(local, skb); 1172 ret = drv_tx(local, skb);
1176 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) { 1173 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) {
1177 dev_kfree_skb(skb); 1174 dev_kfree_skb(skb);
1178 ret = NETDEV_TX_OK; 1175 ret = NETDEV_TX_OK;
1179 } 1176 }
1180 if (ret != NETDEV_TX_OK) 1177 if (ret != NETDEV_TX_OK) {
1178 info->control.vif = &sdata->vif;
1181 return IEEE80211_TX_AGAIN; 1179 return IEEE80211_TX_AGAIN;
1180 }
1181
1182 *skbp = skb = next; 1182 *skbp = skb = next;
1183 ieee80211_led_tx(local, 1); 1183 ieee80211_led_tx(local, 1);
1184 fragm = true; 1184 fragm = true;
@@ -1234,10 +1234,10 @@ static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1234 return 0; 1234 return 0;
1235} 1235}
1236 1236
1237static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb, 1237static void ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1238 bool txpending) 1238 struct sk_buff *skb, bool txpending)
1239{ 1239{
1240 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 1240 struct ieee80211_local *local = sdata->local;
1241 struct ieee80211_tx_data tx; 1241 struct ieee80211_tx_data tx;
1242 ieee80211_tx_result res_prepare; 1242 ieee80211_tx_result res_prepare;
1243 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1243 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
@@ -1248,8 +1248,6 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1248 1248
1249 queue = skb_get_queue_mapping(skb); 1249 queue = skb_get_queue_mapping(skb);
1250 1250
1251 WARN_ON(!txpending && !skb_queue_empty(&local->pending[queue]));
1252
1253 if (unlikely(skb->len < 10)) { 1251 if (unlikely(skb->len < 10)) {
1254 dev_kfree_skb(skb); 1252 dev_kfree_skb(skb);
1255 return; 1253 return;
@@ -1258,7 +1256,7 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1258 rcu_read_lock(); 1256 rcu_read_lock();
1259 1257
1260 /* initialises tx */ 1258 /* initialises tx */
1261 res_prepare = __ieee80211_tx_prepare(&tx, skb, dev); 1259 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
1262 1260
1263 if (unlikely(res_prepare == TX_DROP)) { 1261 if (unlikely(res_prepare == TX_DROP)) {
1264 dev_kfree_skb(skb); 1262 dev_kfree_skb(skb);
@@ -1277,7 +1275,7 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1277 1275
1278 retries = 0; 1276 retries = 0;
1279 retry: 1277 retry:
1280 ret = __ieee80211_tx(local, &tx.skb, tx.sta); 1278 ret = __ieee80211_tx(local, &tx.skb, tx.sta, txpending);
1281 switch (ret) { 1279 switch (ret) {
1282 case IEEE80211_TX_OK: 1280 case IEEE80211_TX_OK:
1283 break; 1281 break;
@@ -1295,34 +1293,35 @@ static void ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
1295 1293
1296 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 1294 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1297 1295
1298 if (__netif_subqueue_stopped(local->mdev, queue)) { 1296 if (local->queue_stop_reasons[queue] ||
1297 !skb_queue_empty(&local->pending[queue])) {
1298 /*
1299 * if queue is stopped, queue up frames for later
1300 * transmission from the tasklet
1301 */
1299 do { 1302 do {
1300 next = skb->next; 1303 next = skb->next;
1301 skb->next = NULL; 1304 skb->next = NULL;
1302 if (unlikely(txpending)) 1305 if (unlikely(txpending))
1303 skb_queue_head(&local->pending[queue], 1306 __skb_queue_head(&local->pending[queue],
1304 skb); 1307 skb);
1305 else 1308 else
1306 skb_queue_tail(&local->pending[queue], 1309 __skb_queue_tail(&local->pending[queue],
1307 skb); 1310 skb);
1308 } while ((skb = next)); 1311 } while ((skb = next));
1309 1312
1310 /*
1311 * Make sure nobody will enable the queue on us
1312 * (without going through the tasklet) nor disable the
1313 * netdev queue underneath the pending handling code.
1314 */
1315 __set_bit(IEEE80211_QUEUE_STOP_REASON_PENDING,
1316 &local->queue_stop_reasons[queue]);
1317
1318 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 1313 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1319 flags); 1314 flags);
1320 } else { 1315 } else {
1316 /*
1317 * otherwise retry, but this is a race condition or
1318 * a driver bug (which we warn about if it persists)
1319 */
1321 spin_unlock_irqrestore(&local->queue_stop_reason_lock, 1320 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1322 flags); 1321 flags);
1323 1322
1324 retries++; 1323 retries++;
1325 if (WARN(retries > 10, "tx refused but queue active")) 1324 if (WARN(retries > 10, "tx refused but queue active\n"))
1326 goto drop; 1325 goto drop;
1327 goto retry; 1326 goto retry;
1328 } 1327 }
@@ -1383,44 +1382,25 @@ static int ieee80211_skb_resize(struct ieee80211_local *local,
1383 return 0; 1382 return 0;
1384} 1383}
1385 1384
1386int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev) 1385static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1386 struct sk_buff *skb)
1387{ 1387{
1388 struct ieee80211_master_priv *mpriv = netdev_priv(dev); 1388 struct ieee80211_local *local = sdata->local;
1389 struct ieee80211_local *local = mpriv->local;
1390 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 1389 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1391 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1390 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1392 struct net_device *odev = NULL; 1391 struct ieee80211_sub_if_data *tmp_sdata;
1393 struct ieee80211_sub_if_data *osdata;
1394 int headroom; 1392 int headroom;
1395 bool may_encrypt; 1393 bool may_encrypt;
1396 enum { 1394
1397 NOT_MONITOR, 1395 dev_hold(sdata->dev);
1398 FOUND_SDATA,
1399 UNKNOWN_ADDRESS,
1400 } monitor_iface = NOT_MONITOR;
1401
1402 if (skb->iif)
1403 odev = dev_get_by_index(&init_net, skb->iif);
1404 if (unlikely(odev && !is_ieee80211_device(local, odev))) {
1405 dev_put(odev);
1406 odev = NULL;
1407 }
1408 if (unlikely(!odev)) {
1409#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1410 printk(KERN_DEBUG "%s: Discarded packet with nonexistent "
1411 "originating device\n", dev->name);
1412#endif
1413 dev_kfree_skb(skb);
1414 return NETDEV_TX_OK;
1415 }
1416 1396
1417 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && 1397 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
1418 local->hw.conf.dynamic_ps_timeout > 0 && 1398 local->hw.conf.dynamic_ps_timeout > 0 &&
1419 !local->sw_scanning && !local->hw_scanning && local->ps_sdata) { 1399 !(local->scanning) && local->ps_sdata) {
1420 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 1400 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
1421 ieee80211_stop_queues_by_reason(&local->hw, 1401 ieee80211_stop_queues_by_reason(&local->hw,
1422 IEEE80211_QUEUE_STOP_REASON_PS); 1402 IEEE80211_QUEUE_STOP_REASON_PS);
1423 queue_work(local->hw.workqueue, 1403 ieee80211_queue_work(&local->hw,
1424 &local->dynamic_ps_disable_work); 1404 &local->dynamic_ps_disable_work);
1425 } 1405 }
1426 1406
@@ -1428,31 +1408,22 @@ int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
1428 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); 1408 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
1429 } 1409 }
1430 1410
1431 memset(info, 0, sizeof(*info));
1432
1433 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; 1411 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1434 1412
1435 osdata = IEEE80211_DEV_TO_SUB_IF(odev); 1413 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1436
1437 if (ieee80211_vif_is_mesh(&osdata->vif) &&
1438 ieee80211_is_data(hdr->frame_control)) { 1414 ieee80211_is_data(hdr->frame_control)) {
1439 if (is_multicast_ether_addr(hdr->addr3)) 1415 if (is_multicast_ether_addr(hdr->addr3))
1440 memcpy(hdr->addr1, hdr->addr3, ETH_ALEN); 1416 memcpy(hdr->addr1, hdr->addr3, ETH_ALEN);
1441 else 1417 else
1442 if (mesh_nexthop_lookup(skb, osdata)) { 1418 if (mesh_nexthop_lookup(skb, sdata)) {
1443 dev_put(odev); 1419 dev_put(sdata->dev);
1444 return NETDEV_TX_OK; 1420 return;
1445 } 1421 }
1446 if (memcmp(odev->dev_addr, hdr->addr4, ETH_ALEN) != 0) 1422 } else if (unlikely(sdata->vif.type == NL80211_IFTYPE_MONITOR)) {
1447 IEEE80211_IFSTA_MESH_CTR_INC(&osdata->u.mesh,
1448 fwded_frames);
1449 } else if (unlikely(osdata->vif.type == NL80211_IFTYPE_MONITOR)) {
1450 struct ieee80211_sub_if_data *sdata;
1451 int hdrlen; 1423 int hdrlen;
1452 u16 len_rthdr; 1424 u16 len_rthdr;
1453 1425
1454 info->flags |= IEEE80211_TX_CTL_INJECTED; 1426 info->flags |= IEEE80211_TX_CTL_INJECTED;
1455 monitor_iface = UNKNOWN_ADDRESS;
1456 1427
1457 len_rthdr = ieee80211_get_radiotap_len(skb->data); 1428 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1458 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); 1429 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
@@ -1471,20 +1442,17 @@ int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
1471 */ 1442 */
1472 1443
1473 rcu_read_lock(); 1444 rcu_read_lock();
1474 list_for_each_entry_rcu(sdata, &local->interfaces, 1445 list_for_each_entry_rcu(tmp_sdata, &local->interfaces,
1475 list) { 1446 list) {
1476 if (!netif_running(sdata->dev)) 1447 if (!netif_running(tmp_sdata->dev))
1477 continue; 1448 continue;
1478 if (sdata->vif.type != NL80211_IFTYPE_AP) 1449 if (tmp_sdata->vif.type != NL80211_IFTYPE_AP)
1479 continue; 1450 continue;
1480 if (compare_ether_addr(sdata->dev->dev_addr, 1451 if (compare_ether_addr(tmp_sdata->dev->dev_addr,
1481 hdr->addr2)) { 1452 hdr->addr2)) {
1482 dev_hold(sdata->dev); 1453 dev_hold(tmp_sdata->dev);
1483 dev_put(odev); 1454 dev_put(sdata->dev);
1484 osdata = sdata; 1455 sdata = tmp_sdata;
1485 odev = osdata->dev;
1486 skb->iif = sdata->dev->ifindex;
1487 monitor_iface = FOUND_SDATA;
1488 break; 1456 break;
1489 } 1457 }
1490 } 1458 }
@@ -1492,31 +1460,25 @@ int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
1492 } 1460 }
1493 } 1461 }
1494 1462
1495 may_encrypt = !skb->do_not_encrypt; 1463 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
1496 1464
1497 headroom = osdata->local->tx_headroom; 1465 headroom = local->tx_headroom;
1498 if (may_encrypt) 1466 if (may_encrypt)
1499 headroom += IEEE80211_ENCRYPT_HEADROOM; 1467 headroom += IEEE80211_ENCRYPT_HEADROOM;
1500 headroom -= skb_headroom(skb); 1468 headroom -= skb_headroom(skb);
1501 headroom = max_t(int, 0, headroom); 1469 headroom = max_t(int, 0, headroom);
1502 1470
1503 if (ieee80211_skb_resize(osdata->local, skb, headroom, may_encrypt)) { 1471 if (ieee80211_skb_resize(local, skb, headroom, may_encrypt)) {
1504 dev_kfree_skb(skb); 1472 dev_kfree_skb(skb);
1505 dev_put(odev); 1473 dev_put(sdata->dev);
1506 return NETDEV_TX_OK; 1474 return;
1507 } 1475 }
1508 1476
1509 if (osdata->vif.type == NL80211_IFTYPE_AP_VLAN) 1477 info->control.vif = &sdata->vif;
1510 osdata = container_of(osdata->bss,
1511 struct ieee80211_sub_if_data,
1512 u.ap);
1513 if (likely(monitor_iface != UNKNOWN_ADDRESS))
1514 info->control.vif = &osdata->vif;
1515 1478
1516 ieee80211_tx(odev, skb, false); 1479 ieee80211_select_queue(local, skb);
1517 dev_put(odev); 1480 ieee80211_tx(sdata, skb, false);
1518 1481 dev_put(sdata->dev);
1519 return NETDEV_TX_OK;
1520} 1482}
1521 1483
1522int ieee80211_monitor_start_xmit(struct sk_buff *skb, 1484int ieee80211_monitor_start_xmit(struct sk_buff *skb,
@@ -1526,6 +1488,7 @@ int ieee80211_monitor_start_xmit(struct sk_buff *skb,
1526 struct ieee80211_channel *chan = local->hw.conf.channel; 1488 struct ieee80211_channel *chan = local->hw.conf.channel;
1527 struct ieee80211_radiotap_header *prthdr = 1489 struct ieee80211_radiotap_header *prthdr =
1528 (struct ieee80211_radiotap_header *)skb->data; 1490 (struct ieee80211_radiotap_header *)skb->data;
1491 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1529 u16 len_rthdr; 1492 u16 len_rthdr;
1530 1493
1531 /* 1494 /*
@@ -1563,15 +1526,6 @@ int ieee80211_monitor_start_xmit(struct sk_buff *skb,
1563 if (unlikely(skb->len < len_rthdr)) 1526 if (unlikely(skb->len < len_rthdr))
1564 goto fail; /* skb too short for claimed rt header extent */ 1527 goto fail; /* skb too short for claimed rt header extent */
1565 1528
1566 skb->dev = local->mdev;
1567
1568 /* needed because we set skb device to master */
1569 skb->iif = dev->ifindex;
1570
1571 /* sometimes we do encrypt injected frames, will be fixed
1572 * up in radiotap parser if not wanted */
1573 skb->do_not_encrypt = 0;
1574
1575 /* 1529 /*
1576 * fix up the pointers accounting for the radiotap 1530 * fix up the pointers accounting for the radiotap
1577 * header still being in there. We are being given 1531 * header still being in there. We are being given
@@ -1586,8 +1540,10 @@ int ieee80211_monitor_start_xmit(struct sk_buff *skb,
1586 skb_set_network_header(skb, len_rthdr); 1540 skb_set_network_header(skb, len_rthdr);
1587 skb_set_transport_header(skb, len_rthdr); 1541 skb_set_transport_header(skb, len_rthdr);
1588 1542
1589 /* pass the radiotap header up to the next stage intact */ 1543 memset(info, 0, sizeof(*info));
1590 dev_queue_xmit(skb); 1544
1545 /* pass the radiotap header up to xmit */
1546 ieee80211_xmit(IEEE80211_DEV_TO_SUB_IF(dev), skb);
1591 return NETDEV_TX_OK; 1547 return NETDEV_TX_OK;
1592 1548
1593fail: 1549fail:
@@ -1615,6 +1571,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1615{ 1571{
1616 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 1572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1617 struct ieee80211_local *local = sdata->local; 1573 struct ieee80211_local *local = sdata->local;
1574 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1618 int ret = NETDEV_TX_BUSY, head_need; 1575 int ret = NETDEV_TX_BUSY, head_need;
1619 u16 ethertype, hdrlen, meshhdrlen = 0; 1576 u16 ethertype, hdrlen, meshhdrlen = 0;
1620 __le16 fc; 1577 __le16 fc;
@@ -1627,7 +1584,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1627 u32 sta_flags = 0; 1584 u32 sta_flags = 0;
1628 1585
1629 if (unlikely(skb->len < ETH_HLEN)) { 1586 if (unlikely(skb->len < ETH_HLEN)) {
1630 ret = 0; 1587 ret = NETDEV_TX_OK;
1631 goto fail; 1588 goto fail;
1632 } 1589 }
1633 1590
@@ -1664,7 +1621,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1664 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) { 1621 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1665 /* Do not send frames with mesh_ttl == 0 */ 1622 /* Do not send frames with mesh_ttl == 0 */
1666 sdata->u.mesh.mshstats.dropped_frames_ttl++; 1623 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1667 ret = 0; 1624 ret = NETDEV_TX_OK;
1668 goto fail; 1625 goto fail;
1669 } 1626 }
1670 memset(&mesh_hdr, 0, sizeof(mesh_hdr)); 1627 memset(&mesh_hdr, 0, sizeof(mesh_hdr));
@@ -1724,7 +1681,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1724 hdrlen = 24; 1681 hdrlen = 24;
1725 break; 1682 break;
1726 default: 1683 default:
1727 ret = 0; 1684 ret = NETDEV_TX_OK;
1728 goto fail; 1685 goto fail;
1729 } 1686 }
1730 1687
@@ -1766,7 +1723,7 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1766 1723
1767 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); 1724 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1768 1725
1769 ret = 0; 1726 ret = NETDEV_TX_OK;
1770 goto fail; 1727 goto fail;
1771 } 1728 }
1772 1729
@@ -1842,9 +1799,6 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1842 nh_pos += hdrlen; 1799 nh_pos += hdrlen;
1843 h_pos += hdrlen; 1800 h_pos += hdrlen;
1844 1801
1845 skb->iif = dev->ifindex;
1846
1847 skb->dev = local->mdev;
1848 dev->stats.tx_packets++; 1802 dev->stats.tx_packets++;
1849 dev->stats.tx_bytes += skb->len; 1803 dev->stats.tx_bytes += skb->len;
1850 1804
@@ -1855,13 +1809,15 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb,
1855 skb_set_network_header(skb, nh_pos); 1809 skb_set_network_header(skb, nh_pos);
1856 skb_set_transport_header(skb, h_pos); 1810 skb_set_transport_header(skb, h_pos);
1857 1811
1812 memset(info, 0, sizeof(*info));
1813
1858 dev->trans_start = jiffies; 1814 dev->trans_start = jiffies;
1859 dev_queue_xmit(skb); 1815 ieee80211_xmit(sdata, skb);
1860 1816
1861 return 0; 1817 return NETDEV_TX_OK;
1862 1818
1863 fail: 1819 fail:
1864 if (!ret) 1820 if (ret == NETDEV_TX_OK)
1865 dev_kfree_skb(skb); 1821 dev_kfree_skb(skb);
1866 1822
1867 return ret; 1823 return ret;
@@ -1887,101 +1843,74 @@ static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
1887 struct ieee80211_sub_if_data *sdata; 1843 struct ieee80211_sub_if_data *sdata;
1888 struct sta_info *sta; 1844 struct sta_info *sta;
1889 struct ieee80211_hdr *hdr; 1845 struct ieee80211_hdr *hdr;
1890 struct net_device *dev;
1891 int ret; 1846 int ret;
1892 bool result = true; 1847 bool result = true;
1893 1848
1894 /* does interface still exist? */ 1849 sdata = vif_to_sdata(info->control.vif);
1895 dev = dev_get_by_index(&init_net, skb->iif);
1896 if (!dev) {
1897 dev_kfree_skb(skb);
1898 return true;
1899 }
1900
1901 /* validate info->control.vif against skb->iif */
1902 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1903 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1904 sdata = container_of(sdata->bss,
1905 struct ieee80211_sub_if_data,
1906 u.ap);
1907
1908 if (unlikely(info->control.vif && info->control.vif != &sdata->vif)) {
1909 dev_kfree_skb(skb);
1910 result = true;
1911 goto out;
1912 }
1913 1850
1914 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) { 1851 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
1915 ieee80211_tx(dev, skb, true); 1852 ieee80211_tx(sdata, skb, true);
1916 } else { 1853 } else {
1917 hdr = (struct ieee80211_hdr *)skb->data; 1854 hdr = (struct ieee80211_hdr *)skb->data;
1918 sta = sta_info_get(local, hdr->addr1); 1855 sta = sta_info_get(local, hdr->addr1);
1919 1856
1920 ret = __ieee80211_tx(local, &skb, sta); 1857 ret = __ieee80211_tx(local, &skb, sta, true);
1921 if (ret != IEEE80211_TX_OK) 1858 if (ret != IEEE80211_TX_OK)
1922 result = false; 1859 result = false;
1923 } 1860 }
1924 1861
1925 out:
1926 dev_put(dev);
1927
1928 return result; 1862 return result;
1929} 1863}
1930 1864
1931/* 1865/*
1932 * Transmit all pending packets. Called from tasklet, locks master device 1866 * Transmit all pending packets. Called from tasklet.
1933 * TX lock so that no new packets can come in.
1934 */ 1867 */
1935void ieee80211_tx_pending(unsigned long data) 1868void ieee80211_tx_pending(unsigned long data)
1936{ 1869{
1937 struct ieee80211_local *local = (struct ieee80211_local *)data; 1870 struct ieee80211_local *local = (struct ieee80211_local *)data;
1938 struct net_device *dev = local->mdev;
1939 unsigned long flags; 1871 unsigned long flags;
1940 int i; 1872 int i;
1941 bool next; 1873 bool txok;
1942 1874
1943 rcu_read_lock(); 1875 rcu_read_lock();
1944 netif_tx_lock_bh(dev);
1945 1876
1877 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1946 for (i = 0; i < local->hw.queues; i++) { 1878 for (i = 0; i < local->hw.queues; i++) {
1947 /* 1879 /*
1948 * If queue is stopped by something other than due to pending 1880 * If queue is stopped by something other than due to pending
1949 * frames, or we have no pending frames, proceed to next queue. 1881 * frames, or we have no pending frames, proceed to next queue.
1950 */ 1882 */
1951 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 1883 if (local->queue_stop_reasons[i] ||
1952 next = false;
1953 if (local->queue_stop_reasons[i] !=
1954 BIT(IEEE80211_QUEUE_STOP_REASON_PENDING) ||
1955 skb_queue_empty(&local->pending[i])) 1884 skb_queue_empty(&local->pending[i]))
1956 next = true;
1957 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1958
1959 if (next)
1960 continue; 1885 continue;
1961 1886
1962 /*
1963 * start the queue now to allow processing our packets,
1964 * we're under the tx lock here anyway so nothing will
1965 * happen as a result of this
1966 */
1967 netif_start_subqueue(local->mdev, i);
1968
1969 while (!skb_queue_empty(&local->pending[i])) { 1887 while (!skb_queue_empty(&local->pending[i])) {
1970 struct sk_buff *skb = skb_dequeue(&local->pending[i]); 1888 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
1889 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1890 struct ieee80211_sub_if_data *sdata;
1971 1891
1972 if (!ieee80211_tx_pending_skb(local, skb)) { 1892 if (WARN_ON(!info->control.vif)) {
1973 skb_queue_head(&local->pending[i], skb); 1893 kfree_skb(skb);
1974 break; 1894 continue;
1975 } 1895 }
1976 }
1977 1896
1978 /* Start regular packet processing again. */ 1897 sdata = vif_to_sdata(info->control.vif);
1979 if (skb_queue_empty(&local->pending[i])) 1898 dev_hold(sdata->dev);
1980 ieee80211_wake_queue_by_reason(&local->hw, i, 1899 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1981 IEEE80211_QUEUE_STOP_REASON_PENDING); 1900 flags);
1901
1902 txok = ieee80211_tx_pending_skb(local, skb);
1903 dev_put(sdata->dev);
1904 if (!txok)
1905 __skb_queue_head(&local->pending[i], skb);
1906 spin_lock_irqsave(&local->queue_stop_reason_lock,
1907 flags);
1908 if (!txok)
1909 break;
1910 }
1982 } 1911 }
1912 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1983 1913
1984 netif_tx_unlock_bh(dev);
1985 rcu_read_unlock(); 1914 rcu_read_unlock();
1986} 1915}
1987 1916
@@ -2156,8 +2085,7 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2156 2085
2157 info = IEEE80211_SKB_CB(skb); 2086 info = IEEE80211_SKB_CB(skb);
2158 2087
2159 skb->do_not_encrypt = 1; 2088 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2160
2161 info->band = band; 2089 info->band = band;
2162 /* 2090 /*
2163 * XXX: For now, always use the lowest rate 2091 * XXX: For now, always use the lowest rate
@@ -2228,9 +2156,6 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2228 sdata = vif_to_sdata(vif); 2156 sdata = vif_to_sdata(vif);
2229 bss = &sdata->u.ap; 2157 bss = &sdata->u.ap;
2230 2158
2231 if (!bss)
2232 return NULL;
2233
2234 rcu_read_lock(); 2159 rcu_read_lock();
2235 beacon = rcu_dereference(bss->beacon); 2160 beacon = rcu_dereference(bss->beacon);
2236 2161
@@ -2256,7 +2181,7 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2256 cpu_to_le16(IEEE80211_FCTL_MOREDATA); 2181 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2257 } 2182 }
2258 2183
2259 if (!ieee80211_tx_prepare(local, &tx, skb)) 2184 if (!ieee80211_tx_prepare(sdata, &tx, skb))
2260 break; 2185 break;
2261 dev_kfree_skb_any(skb); 2186 dev_kfree_skb_any(skb);
2262 } 2187 }
@@ -2276,3 +2201,24 @@ ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2276 return skb; 2201 return skb;
2277} 2202}
2278EXPORT_SYMBOL(ieee80211_get_buffered_bc); 2203EXPORT_SYMBOL(ieee80211_get_buffered_bc);
2204
2205void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
2206 int encrypt)
2207{
2208 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2209 skb_set_mac_header(skb, 0);
2210 skb_set_network_header(skb, 0);
2211 skb_set_transport_header(skb, 0);
2212
2213 if (!encrypt)
2214 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2215
2216 /*
2217 * The other path calling ieee80211_xmit is from the tasklet,
2218 * and while we can handle concurrent transmissions locking
2219 * requirements are that we do not come into tx with bhs on.
2220 */
2221 local_bh_disable();
2222 ieee80211_xmit(sdata, skb);
2223 local_bh_enable();
2224}
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 915e77769312..e55d57f559ec 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -31,6 +31,7 @@
31#include "mesh.h" 31#include "mesh.h"
32#include "wme.h" 32#include "wme.h"
33#include "led.h" 33#include "led.h"
34#include "wep.h"
34 35
35/* privid for wiphys to determine whether they belong to us or not */ 36/* privid for wiphys to determine whether they belong to us or not */
36void *mac80211_wiphy_privid = &mac80211_wiphy_privid; 37void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
@@ -274,16 +275,12 @@ static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
274 275
275 __clear_bit(reason, &local->queue_stop_reasons[queue]); 276 __clear_bit(reason, &local->queue_stop_reasons[queue]);
276 277
277 if (!skb_queue_empty(&local->pending[queue]) &&
278 local->queue_stop_reasons[queue] ==
279 BIT(IEEE80211_QUEUE_STOP_REASON_PENDING))
280 tasklet_schedule(&local->tx_pending_tasklet);
281
282 if (local->queue_stop_reasons[queue] != 0) 278 if (local->queue_stop_reasons[queue] != 0)
283 /* someone still has this queue stopped */ 279 /* someone still has this queue stopped */
284 return; 280 return;
285 281
286 netif_wake_subqueue(local->mdev, queue); 282 if (!skb_queue_empty(&local->pending[queue]))
283 tasklet_schedule(&local->tx_pending_tasklet);
287} 284}
288 285
289void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, 286void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
@@ -312,14 +309,6 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
312 if (WARN_ON(queue >= hw->queues)) 309 if (WARN_ON(queue >= hw->queues))
313 return; 310 return;
314 311
315 /*
316 * Only stop if it was previously running, this is necessary
317 * for correct pending packets handling because there we may
318 * start (but not wake) the queue and rely on that.
319 */
320 if (!local->queue_stop_reasons[queue])
321 netif_stop_subqueue(local->mdev, queue);
322
323 __set_bit(reason, &local->queue_stop_reasons[queue]); 312 __set_bit(reason, &local->queue_stop_reasons[queue]);
324} 313}
325 314
@@ -347,11 +336,16 @@ void ieee80211_add_pending_skb(struct ieee80211_local *local,
347 struct ieee80211_hw *hw = &local->hw; 336 struct ieee80211_hw *hw = &local->hw;
348 unsigned long flags; 337 unsigned long flags;
349 int queue = skb_get_queue_mapping(skb); 338 int queue = skb_get_queue_mapping(skb);
339 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
340
341 if (WARN_ON(!info->control.vif)) {
342 kfree(skb);
343 return;
344 }
350 345
351 spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 346 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
352 __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); 347 __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
353 __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_PENDING); 348 __skb_queue_tail(&local->pending[queue], skb);
354 skb_queue_tail(&local->pending[queue], skb);
355 __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); 349 __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
356 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 350 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
357} 351}
@@ -370,18 +364,21 @@ int ieee80211_add_pending_skbs(struct ieee80211_local *local,
370 IEEE80211_QUEUE_STOP_REASON_SKB_ADD); 364 IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
371 365
372 while ((skb = skb_dequeue(skbs))) { 366 while ((skb = skb_dequeue(skbs))) {
367 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
368
369 if (WARN_ON(!info->control.vif)) {
370 kfree(skb);
371 continue;
372 }
373
373 ret++; 374 ret++;
374 queue = skb_get_queue_mapping(skb); 375 queue = skb_get_queue_mapping(skb);
375 skb_queue_tail(&local->pending[queue], skb); 376 __skb_queue_tail(&local->pending[queue], skb);
376 } 377 }
377 378
378 for (i = 0; i < hw->queues; i++) { 379 for (i = 0; i < hw->queues; i++)
379 if (ret)
380 __ieee80211_stop_queue(hw, i,
381 IEEE80211_QUEUE_STOP_REASON_PENDING);
382 __ieee80211_wake_queue(hw, i, 380 __ieee80211_wake_queue(hw, i,
383 IEEE80211_QUEUE_STOP_REASON_SKB_ADD); 381 IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
384 }
385 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 382 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
386 383
387 return ret; 384 return ret;
@@ -412,11 +409,16 @@ EXPORT_SYMBOL(ieee80211_stop_queues);
412int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) 409int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
413{ 410{
414 struct ieee80211_local *local = hw_to_local(hw); 411 struct ieee80211_local *local = hw_to_local(hw);
412 unsigned long flags;
413 int ret;
415 414
416 if (WARN_ON(queue >= hw->queues)) 415 if (WARN_ON(queue >= hw->queues))
417 return true; 416 return true;
418 417
419 return __netif_subqueue_stopped(local->mdev, queue); 418 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
419 ret = !!local->queue_stop_reasons[queue];
420 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
421 return ret;
420} 422}
421EXPORT_SYMBOL(ieee80211_queue_stopped); 423EXPORT_SYMBOL(ieee80211_queue_stopped);
422 424
@@ -509,6 +511,46 @@ void ieee80211_iterate_active_interfaces_atomic(
509} 511}
510EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); 512EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
511 513
514/*
515 * Nothing should have been stuffed into the workqueue during
516 * the suspend->resume cycle. If this WARN is seen then there
517 * is a bug with either the driver suspend or something in
518 * mac80211 stuffing into the workqueue which we haven't yet
519 * cleared during mac80211's suspend cycle.
520 */
521static bool ieee80211_can_queue_work(struct ieee80211_local *local)
522{
523 if (WARN(local->suspended, "queueing ieee80211 work while "
524 "going to suspend\n"))
525 return false;
526
527 return true;
528}
529
530void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
531{
532 struct ieee80211_local *local = hw_to_local(hw);
533
534 if (!ieee80211_can_queue_work(local))
535 return;
536
537 queue_work(local->workqueue, work);
538}
539EXPORT_SYMBOL(ieee80211_queue_work);
540
541void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
542 struct delayed_work *dwork,
543 unsigned long delay)
544{
545 struct ieee80211_local *local = hw_to_local(hw);
546
547 if (!ieee80211_can_queue_work(local))
548 return;
549
550 queue_delayed_work(local->workqueue, dwork, delay);
551}
552EXPORT_SYMBOL(ieee80211_queue_delayed_work);
553
512void ieee802_11_parse_elems(u8 *start, size_t len, 554void ieee802_11_parse_elems(u8 *start, size_t len,
513 struct ieee802_11_elems *elems) 555 struct ieee802_11_elems *elems)
514{ 556{
@@ -760,20 +802,6 @@ void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
760 ieee80211_set_wmm_default(sdata); 802 ieee80211_set_wmm_default(sdata);
761} 803}
762 804
763void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
764 int encrypt)
765{
766 skb->dev = sdata->local->mdev;
767 skb_set_mac_header(skb, 0);
768 skb_set_network_header(skb, 0);
769 skb_set_transport_header(skb, 0);
770
771 skb->iif = sdata->dev->ifindex;
772 skb->do_not_encrypt = !encrypt;
773
774 dev_queue_xmit(skb);
775}
776
777u32 ieee80211_mandatory_rates(struct ieee80211_local *local, 805u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
778 enum ieee80211_band band) 806 enum ieee80211_band band)
779{ 807{
@@ -804,12 +832,13 @@ u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
804 832
805void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 833void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
806 u16 transaction, u16 auth_alg, 834 u16 transaction, u16 auth_alg,
807 u8 *extra, size_t extra_len, 835 u8 *extra, size_t extra_len, const u8 *bssid,
808 const u8 *bssid, int encrypt) 836 const u8 *key, u8 key_len, u8 key_idx)
809{ 837{
810 struct ieee80211_local *local = sdata->local; 838 struct ieee80211_local *local = sdata->local;
811 struct sk_buff *skb; 839 struct sk_buff *skb;
812 struct ieee80211_mgmt *mgmt; 840 struct ieee80211_mgmt *mgmt;
841 int err;
813 842
814 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 843 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
815 sizeof(*mgmt) + 6 + extra_len); 844 sizeof(*mgmt) + 6 + extra_len);
@@ -824,8 +853,6 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
824 memset(mgmt, 0, 24 + 6); 853 memset(mgmt, 0, 24 + 6);
825 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 854 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
826 IEEE80211_STYPE_AUTH); 855 IEEE80211_STYPE_AUTH);
827 if (encrypt)
828 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
829 memcpy(mgmt->da, bssid, ETH_ALEN); 856 memcpy(mgmt->da, bssid, ETH_ALEN);
830 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 857 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
831 memcpy(mgmt->bssid, bssid, ETH_ALEN); 858 memcpy(mgmt->bssid, bssid, ETH_ALEN);
@@ -835,7 +862,13 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
835 if (extra) 862 if (extra)
836 memcpy(skb_put(skb, extra_len), extra, extra_len); 863 memcpy(skb_put(skb, extra_len), extra, extra_len);
837 864
838 ieee80211_tx_skb(sdata, skb, encrypt); 865 if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
866 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
867 err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
868 WARN_ON(err);
869 }
870
871 ieee80211_tx_skb(sdata, skb, 0);
839} 872}
840 873
841int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 874int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
@@ -1043,9 +1076,9 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1043 /* reconfigure hardware */ 1076 /* reconfigure hardware */
1044 ieee80211_hw_config(local, ~0); 1077 ieee80211_hw_config(local, ~0);
1045 1078
1046 netif_addr_lock_bh(local->mdev); 1079 spin_lock_bh(&local->filter_lock);
1047 ieee80211_configure_filter(local); 1080 ieee80211_configure_filter(local);
1048 netif_addr_unlock_bh(local->mdev); 1081 spin_unlock_bh(&local->filter_lock);
1049 1082
1050 /* Finally also reconfigure all the BSS information */ 1083 /* Finally also reconfigure all the BSS information */
1051 list_for_each_entry(sdata, &local->interfaces, list) { 1084 list_for_each_entry(sdata, &local->interfaces, list) {
@@ -1121,3 +1154,4 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1121#endif 1154#endif
1122 return 0; 1155 return 0;
1123} 1156}
1157
diff --git a/net/mac80211/wep.c b/net/mac80211/wep.c
index ef73105b3061..8a980f136941 100644
--- a/net/mac80211/wep.c
+++ b/net/mac80211/wep.c
@@ -67,10 +67,10 @@ static inline bool ieee80211_wep_weak_iv(u32 iv, int keylen)
67 67
68 68
69static void ieee80211_wep_get_iv(struct ieee80211_local *local, 69static void ieee80211_wep_get_iv(struct ieee80211_local *local,
70 struct ieee80211_key *key, u8 *iv) 70 int keylen, int keyidx, u8 *iv)
71{ 71{
72 local->wep_iv++; 72 local->wep_iv++;
73 if (ieee80211_wep_weak_iv(local->wep_iv, key->conf.keylen)) 73 if (ieee80211_wep_weak_iv(local->wep_iv, keylen))
74 local->wep_iv += 0x0100; 74 local->wep_iv += 0x0100;
75 75
76 if (!iv) 76 if (!iv)
@@ -79,13 +79,13 @@ static void ieee80211_wep_get_iv(struct ieee80211_local *local,
79 *iv++ = (local->wep_iv >> 16) & 0xff; 79 *iv++ = (local->wep_iv >> 16) & 0xff;
80 *iv++ = (local->wep_iv >> 8) & 0xff; 80 *iv++ = (local->wep_iv >> 8) & 0xff;
81 *iv++ = local->wep_iv & 0xff; 81 *iv++ = local->wep_iv & 0xff;
82 *iv++ = key->conf.keyidx << 6; 82 *iv++ = keyidx << 6;
83} 83}
84 84
85 85
86static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local, 86static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
87 struct sk_buff *skb, 87 struct sk_buff *skb,
88 struct ieee80211_key *key) 88 int keylen, int keyidx)
89{ 89{
90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
91 unsigned int hdrlen; 91 unsigned int hdrlen;
@@ -100,7 +100,7 @@ static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
100 hdrlen = ieee80211_hdrlen(hdr->frame_control); 100 hdrlen = ieee80211_hdrlen(hdr->frame_control);
101 newhdr = skb_push(skb, WEP_IV_LEN); 101 newhdr = skb_push(skb, WEP_IV_LEN);
102 memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen); 102 memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen);
103 ieee80211_wep_get_iv(local, key, newhdr + hdrlen); 103 ieee80211_wep_get_iv(local, keylen, keyidx, newhdr + hdrlen);
104 return newhdr + hdrlen; 104 return newhdr + hdrlen;
105} 105}
106 106
@@ -144,26 +144,17 @@ void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
144 * 144 *
145 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data)) 145 * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
146 */ 146 */
147int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb, 147int ieee80211_wep_encrypt(struct ieee80211_local *local,
148 struct ieee80211_key *key) 148 struct sk_buff *skb,
149 const u8 *key, int keylen, int keyidx)
149{ 150{
150 u32 klen; 151 u8 *iv;
151 u8 *rc4key, *iv;
152 size_t len; 152 size_t len;
153 u8 rc4key[3 + WLAN_KEY_LEN_WEP104];
153 154
154 if (!key || key->conf.alg != ALG_WEP) 155 iv = ieee80211_wep_add_iv(local, skb, keylen, keyidx);
155 return -1; 156 if (!iv)
156
157 klen = 3 + key->conf.keylen;
158 rc4key = kmalloc(klen, GFP_ATOMIC);
159 if (!rc4key)
160 return -1;
161
162 iv = ieee80211_wep_add_iv(local, skb, key);
163 if (!iv) {
164 kfree(rc4key);
165 return -1; 157 return -1;
166 }
167 158
168 len = skb->len - (iv + WEP_IV_LEN - skb->data); 159 len = skb->len - (iv + WEP_IV_LEN - skb->data);
169 160
@@ -171,16 +162,14 @@ int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
171 memcpy(rc4key, iv, 3); 162 memcpy(rc4key, iv, 3);
172 163
173 /* Copy rest of the WEP key (the secret part) */ 164 /* Copy rest of the WEP key (the secret part) */
174 memcpy(rc4key + 3, key->conf.key, key->conf.keylen); 165 memcpy(rc4key + 3, key, keylen);
175 166
176 /* Add room for ICV */ 167 /* Add room for ICV */
177 skb_put(skb, WEP_ICV_LEN); 168 skb_put(skb, WEP_ICV_LEN);
178 169
179 ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, klen, 170 ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, keylen + 3,
180 iv + WEP_IV_LEN, len); 171 iv + WEP_IV_LEN, len);
181 172
182 kfree(rc4key);
183
184 return 0; 173 return 0;
185} 174}
186 175
@@ -216,8 +205,9 @@ int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
216 * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload 205 * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload
217 * is moved to the beginning of the skb and skb length will be reduced. 206 * is moved to the beginning of the skb and skb length will be reduced.
218 */ 207 */
219int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb, 208static int ieee80211_wep_decrypt(struct ieee80211_local *local,
220 struct ieee80211_key *key) 209 struct sk_buff *skb,
210 struct ieee80211_key *key)
221{ 211{
222 u32 klen; 212 u32 klen;
223 u8 *rc4key; 213 u8 *rc4key;
@@ -314,12 +304,16 @@ static int wep_encrypt_skb(struct ieee80211_tx_data *tx, struct sk_buff *skb)
314 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 304 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
315 305
316 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) { 306 if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
317 if (ieee80211_wep_encrypt(tx->local, skb, tx->key)) 307 if (ieee80211_wep_encrypt(tx->local, skb, tx->key->conf.key,
308 tx->key->conf.keylen,
309 tx->key->conf.keyidx))
318 return -1; 310 return -1;
319 } else { 311 } else {
320 info->control.hw_key = &tx->key->conf; 312 info->control.hw_key = &tx->key->conf;
321 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) { 313 if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
322 if (!ieee80211_wep_add_iv(tx->local, skb, tx->key)) 314 if (!ieee80211_wep_add_iv(tx->local, skb,
315 tx->key->conf.keylen,
316 tx->key->conf.keyidx))
323 return -1; 317 return -1;
324 } 318 }
325 } 319 }
diff --git a/net/mac80211/wep.h b/net/mac80211/wep.h
index d3f0db48314e..fe29d7e5759f 100644
--- a/net/mac80211/wep.h
+++ b/net/mac80211/wep.h
@@ -20,12 +20,11 @@ int ieee80211_wep_init(struct ieee80211_local *local);
20void ieee80211_wep_free(struct ieee80211_local *local); 20void ieee80211_wep_free(struct ieee80211_local *local);
21void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key, 21void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
22 size_t klen, u8 *data, size_t data_len); 22 size_t klen, u8 *data, size_t data_len);
23int ieee80211_wep_encrypt(struct ieee80211_local *local,
24 struct sk_buff *skb,
25 const u8 *key, int keylen, int keyidx);
23int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key, 26int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
24 size_t klen, u8 *data, size_t data_len); 27 size_t klen, u8 *data, size_t data_len);
25int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
26 struct ieee80211_key *key);
27int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
28 struct ieee80211_key *key);
29bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key); 28bool ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
30 29
31ieee80211_rx_result 30ieee80211_rx_result
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
deleted file mode 100644
index 1da81f456744..000000000000
--- a/net/mac80211/wext.c
+++ /dev/null
@@ -1,633 +0,0 @@
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/netdevice.h>
13#include <linux/types.h>
14#include <linux/slab.h>
15#include <linux/skbuff.h>
16#include <linux/etherdevice.h>
17#include <linux/if_arp.h>
18#include <linux/wireless.h>
19#include <net/iw_handler.h>
20#include <asm/uaccess.h>
21
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
24#include "led.h"
25#include "rate.h"
26#include "wpa.h"
27#include "aes_ccm.h"
28
29
30static int ieee80211_ioctl_siwgenie(struct net_device *dev,
31 struct iw_request_info *info,
32 struct iw_point *data, char *extra)
33{
34 struct ieee80211_sub_if_data *sdata;
35
36 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
37
38 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
39 int ret = ieee80211_sta_set_extra_ie(sdata, extra, data->length);
40 if (ret && ret != -EALREADY)
41 return ret;
42 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
43 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
44 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
45 if (ret != -EALREADY)
46 ieee80211_sta_req_auth(sdata);
47 return 0;
48 }
49
50 return -EOPNOTSUPP;
51}
52
53static int ieee80211_ioctl_siwfreq(struct net_device *dev,
54 struct iw_request_info *info,
55 struct iw_freq *freq, char *extra)
56{
57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58 struct ieee80211_local *local = sdata->local;
59 struct ieee80211_channel *chan;
60
61 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
62 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
63 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
64 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
65
66 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
67 if (freq->e == 0) {
68 if (freq->m < 0) {
69 if (sdata->vif.type == NL80211_IFTYPE_STATION)
70 sdata->u.mgd.flags |=
71 IEEE80211_STA_AUTO_CHANNEL_SEL;
72 return 0;
73 } else
74 chan = ieee80211_get_channel(local->hw.wiphy,
75 ieee80211_channel_to_frequency(freq->m));
76 } else {
77 int i, div = 1000000;
78 for (i = 0; i < freq->e; i++)
79 div /= 10;
80 if (div <= 0)
81 return -EINVAL;
82 chan = ieee80211_get_channel(local->hw.wiphy, freq->m / div);
83 }
84
85 if (!chan)
86 return -EINVAL;
87
88 if (chan->flags & IEEE80211_CHAN_DISABLED)
89 return -EINVAL;
90
91 /*
92 * no change except maybe auto -> fixed, ignore the HT
93 * setting so you can fix a channel you're on already
94 */
95 if (local->oper_channel == chan)
96 return 0;
97
98 if (sdata->vif.type == NL80211_IFTYPE_STATION)
99 ieee80211_sta_req_auth(sdata);
100
101 local->oper_channel = chan;
102 local->oper_channel_type = NL80211_CHAN_NO_HT;
103 ieee80211_hw_config(local, 0);
104
105 return 0;
106}
107
108
109static int ieee80211_ioctl_giwfreq(struct net_device *dev,
110 struct iw_request_info *info,
111 struct iw_freq *freq, char *extra)
112{
113 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
114 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
115
116 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
117 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
118
119 freq->m = local->oper_channel->center_freq;
120 freq->e = 6;
121
122 return 0;
123}
124
125
126static int ieee80211_ioctl_siwessid(struct net_device *dev,
127 struct iw_request_info *info,
128 struct iw_point *data, char *ssid)
129{
130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
131 size_t len = data->length;
132 int ret;
133
134 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
135 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
136
137 /* iwconfig uses nul termination in SSID.. */
138 if (len > 0 && ssid[len - 1] == '\0')
139 len--;
140
141 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
142 if (data->flags)
143 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
144 else
145 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
146
147 ret = ieee80211_sta_set_ssid(sdata, ssid, len);
148 if (ret)
149 return ret;
150
151 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
152 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
153 ieee80211_sta_req_auth(sdata);
154 return 0;
155 }
156
157 return -EOPNOTSUPP;
158}
159
160
161static int ieee80211_ioctl_giwessid(struct net_device *dev,
162 struct iw_request_info *info,
163 struct iw_point *data, char *ssid)
164{
165 size_t len;
166 struct ieee80211_sub_if_data *sdata;
167
168 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
169
170 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
171 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
172
173 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
174 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
175 if (res == 0) {
176 data->length = len;
177 data->flags = 1;
178 } else
179 data->flags = 0;
180 return res;
181 }
182
183 return -EOPNOTSUPP;
184}
185
186
187static int ieee80211_ioctl_siwap(struct net_device *dev,
188 struct iw_request_info *info,
189 struct sockaddr *ap_addr, char *extra)
190{
191 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
192
193 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
194 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
195
196 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
197 int ret;
198
199 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
200 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
201 IEEE80211_STA_AUTO_CHANNEL_SEL;
202 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
203 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
204 else
205 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
206 ret = ieee80211_sta_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
207 if (ret)
208 return ret;
209 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
210 sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT;
211 ieee80211_sta_req_auth(sdata);
212 return 0;
213 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
214 /*
215 * If it is necessary to update the WDS peer address
216 * while the interface is running, then we need to do
217 * more work here, namely if it is running we need to
218 * add a new and remove the old STA entry, this is
219 * normally handled by _open() and _stop().
220 */
221 if (netif_running(dev))
222 return -EBUSY;
223
224 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
225 ETH_ALEN);
226
227 return 0;
228 }
229
230 return -EOPNOTSUPP;
231}
232
233
234static int ieee80211_ioctl_giwap(struct net_device *dev,
235 struct iw_request_info *info,
236 struct sockaddr *ap_addr, char *extra)
237{
238 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239
240 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
241 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
242
243 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
244 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
245 ap_addr->sa_family = ARPHRD_ETHER;
246 memcpy(&ap_addr->sa_data, sdata->u.mgd.bssid, ETH_ALEN);
247 } else
248 memset(&ap_addr->sa_data, 0, ETH_ALEN);
249 return 0;
250 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
251 ap_addr->sa_family = ARPHRD_ETHER;
252 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
253 return 0;
254 }
255
256 return -EOPNOTSUPP;
257}
258
259
260static int ieee80211_ioctl_siwrate(struct net_device *dev,
261 struct iw_request_info *info,
262 struct iw_param *rate, char *extra)
263{
264 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
265 int i, err = -EINVAL;
266 u32 target_rate = rate->value / 100000;
267 struct ieee80211_sub_if_data *sdata;
268 struct ieee80211_supported_band *sband;
269
270 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
271
272 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
273
274 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
275 * target_rate = X, rate->fixed = 1 means only rate X
276 * target_rate = X, rate->fixed = 0 means all rates <= X */
277 sdata->max_ratectrl_rateidx = -1;
278 sdata->force_unicast_rateidx = -1;
279 if (rate->value < 0)
280 return 0;
281
282 for (i=0; i< sband->n_bitrates; i++) {
283 struct ieee80211_rate *brate = &sband->bitrates[i];
284 int this_rate = brate->bitrate;
285
286 if (target_rate == this_rate) {
287 sdata->max_ratectrl_rateidx = i;
288 if (rate->fixed)
289 sdata->force_unicast_rateidx = i;
290 err = 0;
291 break;
292 }
293 }
294 return err;
295}
296
297static int ieee80211_ioctl_giwrate(struct net_device *dev,
298 struct iw_request_info *info,
299 struct iw_param *rate, char *extra)
300{
301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
302 struct sta_info *sta;
303 struct ieee80211_sub_if_data *sdata;
304 struct ieee80211_supported_band *sband;
305
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307
308 if (sdata->vif.type != NL80211_IFTYPE_STATION)
309 return -EOPNOTSUPP;
310
311 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
312
313 rcu_read_lock();
314
315 sta = sta_info_get(local, sdata->u.mgd.bssid);
316
317 if (sta && !(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS))
318 rate->value = sband->bitrates[sta->last_tx_rate.idx].bitrate;
319 else
320 rate->value = 0;
321
322 rcu_read_unlock();
323
324 if (!sta)
325 return -ENODEV;
326
327 rate->value *= 100000;
328
329 return 0;
330}
331
332static int ieee80211_ioctl_siwpower(struct net_device *dev,
333 struct iw_request_info *info,
334 struct iw_param *wrq,
335 char *extra)
336{
337 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
338 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
339 struct ieee80211_conf *conf = &local->hw.conf;
340 int timeout = 0;
341 bool ps;
342
343 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
344 return -EOPNOTSUPP;
345
346 if (sdata->vif.type != NL80211_IFTYPE_STATION)
347 return -EINVAL;
348
349 if (wrq->disabled) {
350 ps = false;
351 timeout = 0;
352 goto set;
353 }
354
355 switch (wrq->flags & IW_POWER_MODE) {
356 case IW_POWER_ON: /* If not specified */
357 case IW_POWER_MODE: /* If set all mask */
358 case IW_POWER_ALL_R: /* If explicitely state all */
359 ps = true;
360 break;
361 default: /* Otherwise we ignore */
362 return -EINVAL;
363 }
364
365 if (wrq->flags & ~(IW_POWER_MODE | IW_POWER_TIMEOUT))
366 return -EINVAL;
367
368 if (wrq->flags & IW_POWER_TIMEOUT)
369 timeout = wrq->value / 1000;
370
371 set:
372 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
373 return 0;
374
375 sdata->u.mgd.powersave = ps;
376 conf->dynamic_ps_timeout = timeout;
377
378 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
379 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
380
381 ieee80211_recalc_ps(local, -1);
382
383 return 0;
384}
385
386static int ieee80211_ioctl_giwpower(struct net_device *dev,
387 struct iw_request_info *info,
388 union iwreq_data *wrqu,
389 char *extra)
390{
391 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
392
393 wrqu->power.disabled = !sdata->u.mgd.powersave;
394
395 return 0;
396}
397
398static int ieee80211_ioctl_siwauth(struct net_device *dev,
399 struct iw_request_info *info,
400 struct iw_param *data, char *extra)
401{
402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
403 int ret = 0;
404
405 switch (data->flags & IW_AUTH_INDEX) {
406 case IW_AUTH_WPA_VERSION:
407 case IW_AUTH_CIPHER_GROUP:
408 case IW_AUTH_WPA_ENABLED:
409 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
410 case IW_AUTH_KEY_MGMT:
411 case IW_AUTH_CIPHER_GROUP_MGMT:
412 break;
413 case IW_AUTH_CIPHER_PAIRWISE:
414 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
415 if (data->value & (IW_AUTH_CIPHER_WEP40 |
416 IW_AUTH_CIPHER_WEP104 | IW_AUTH_CIPHER_TKIP))
417 sdata->u.mgd.flags |=
418 IEEE80211_STA_TKIP_WEP_USED;
419 else
420 sdata->u.mgd.flags &=
421 ~IEEE80211_STA_TKIP_WEP_USED;
422 }
423 break;
424 case IW_AUTH_DROP_UNENCRYPTED:
425 sdata->drop_unencrypted = !!data->value;
426 break;
427 case IW_AUTH_PRIVACY_INVOKED:
428 if (sdata->vif.type != NL80211_IFTYPE_STATION)
429 ret = -EINVAL;
430 else {
431 sdata->u.mgd.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
432 /*
433 * Privacy invoked by wpa_supplicant, store the
434 * value and allow associating to a protected
435 * network without having a key up front.
436 */
437 if (data->value)
438 sdata->u.mgd.flags |=
439 IEEE80211_STA_PRIVACY_INVOKED;
440 }
441 break;
442 case IW_AUTH_80211_AUTH_ALG:
443 if (sdata->vif.type == NL80211_IFTYPE_STATION)
444 sdata->u.mgd.auth_algs = data->value;
445 else
446 ret = -EOPNOTSUPP;
447 break;
448 case IW_AUTH_MFP:
449 if (!(sdata->local->hw.flags & IEEE80211_HW_MFP_CAPABLE)) {
450 ret = -EOPNOTSUPP;
451 break;
452 }
453 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
454 switch (data->value) {
455 case IW_AUTH_MFP_DISABLED:
456 sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED;
457 break;
458 case IW_AUTH_MFP_OPTIONAL:
459 sdata->u.mgd.mfp = IEEE80211_MFP_OPTIONAL;
460 break;
461 case IW_AUTH_MFP_REQUIRED:
462 sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED;
463 break;
464 default:
465 ret = -EINVAL;
466 }
467 } else
468 ret = -EOPNOTSUPP;
469 break;
470 default:
471 ret = -EOPNOTSUPP;
472 break;
473 }
474 return ret;
475}
476
477/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
478static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
479{
480 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
481 struct iw_statistics *wstats = &local->wstats;
482 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
483 struct sta_info *sta = NULL;
484
485 rcu_read_lock();
486
487 if (sdata->vif.type == NL80211_IFTYPE_STATION)
488 sta = sta_info_get(local, sdata->u.mgd.bssid);
489
490 if (!sta) {
491 wstats->discard.fragment = 0;
492 wstats->discard.misc = 0;
493 wstats->qual.qual = 0;
494 wstats->qual.level = 0;
495 wstats->qual.noise = 0;
496 wstats->qual.updated = IW_QUAL_ALL_INVALID;
497 } else {
498 wstats->qual.updated = 0;
499 /*
500 * mirror what cfg80211 does for iwrange/scan results,
501 * otherwise userspace gets confused.
502 */
503 if (local->hw.flags & (IEEE80211_HW_SIGNAL_UNSPEC |
504 IEEE80211_HW_SIGNAL_DBM)) {
505 wstats->qual.updated |= IW_QUAL_LEVEL_UPDATED;
506 wstats->qual.updated |= IW_QUAL_QUAL_UPDATED;
507 } else {
508 wstats->qual.updated |= IW_QUAL_LEVEL_INVALID;
509 wstats->qual.updated |= IW_QUAL_QUAL_INVALID;
510 }
511
512 if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
513 wstats->qual.level = sta->last_signal;
514 wstats->qual.qual = sta->last_signal;
515 } else if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
516 int sig = sta->last_signal;
517
518 wstats->qual.updated |= IW_QUAL_DBM;
519 wstats->qual.level = sig;
520 if (sig < -110)
521 sig = -110;
522 else if (sig > -40)
523 sig = -40;
524 wstats->qual.qual = sig + 110;
525 }
526
527 if (local->hw.flags & IEEE80211_HW_NOISE_DBM) {
528 /*
529 * This assumes that if driver reports noise, it also
530 * reports signal in dBm.
531 */
532 wstats->qual.noise = sta->last_noise;
533 wstats->qual.updated |= IW_QUAL_NOISE_UPDATED;
534 } else {
535 wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
536 }
537 }
538
539 rcu_read_unlock();
540
541 return wstats;
542}
543
544static int ieee80211_ioctl_giwauth(struct net_device *dev,
545 struct iw_request_info *info,
546 struct iw_param *data, char *extra)
547{
548 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
549 int ret = 0;
550
551 switch (data->flags & IW_AUTH_INDEX) {
552 case IW_AUTH_80211_AUTH_ALG:
553 if (sdata->vif.type == NL80211_IFTYPE_STATION)
554 data->value = sdata->u.mgd.auth_algs;
555 else
556 ret = -EOPNOTSUPP;
557 break;
558 default:
559 ret = -EOPNOTSUPP;
560 break;
561 }
562 return ret;
563}
564
565
566/* Structures to export the Wireless Handlers */
567
568static const iw_handler ieee80211_handler[] =
569{
570 (iw_handler) NULL, /* SIOCSIWCOMMIT */
571 (iw_handler) cfg80211_wext_giwname, /* SIOCGIWNAME */
572 (iw_handler) NULL, /* SIOCSIWNWID */
573 (iw_handler) NULL, /* SIOCGIWNWID */
574 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
575 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
576 (iw_handler) cfg80211_wext_siwmode, /* SIOCSIWMODE */
577 (iw_handler) cfg80211_wext_giwmode, /* SIOCGIWMODE */
578 (iw_handler) NULL, /* SIOCSIWSENS */
579 (iw_handler) NULL, /* SIOCGIWSENS */
580 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
581 (iw_handler) cfg80211_wext_giwrange, /* SIOCGIWRANGE */
582 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
583 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
584 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
585 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
586 (iw_handler) NULL, /* SIOCSIWSPY */
587 (iw_handler) NULL, /* SIOCGIWSPY */
588 (iw_handler) NULL, /* SIOCSIWTHRSPY */
589 (iw_handler) NULL, /* SIOCGIWTHRSPY */
590 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
591 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
592 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
593 (iw_handler) NULL, /* SIOCGIWAPLIST */
594 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
595 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
596 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
597 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
598 (iw_handler) NULL, /* SIOCSIWNICKN */
599 (iw_handler) NULL, /* SIOCGIWNICKN */
600 (iw_handler) NULL, /* -- hole -- */
601 (iw_handler) NULL, /* -- hole -- */
602 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
603 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
604 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
605 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
606 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
607 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
608 (iw_handler) cfg80211_wext_siwtxpower, /* SIOCSIWTXPOW */
609 (iw_handler) cfg80211_wext_giwtxpower, /* SIOCGIWTXPOW */
610 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
611 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
612 (iw_handler) cfg80211_wext_siwencode, /* SIOCSIWENCODE */
613 (iw_handler) cfg80211_wext_giwencode, /* SIOCGIWENCODE */
614 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
615 (iw_handler) ieee80211_ioctl_giwpower, /* SIOCGIWPOWER */
616 (iw_handler) NULL, /* -- hole -- */
617 (iw_handler) NULL, /* -- hole -- */
618 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
619 (iw_handler) NULL, /* SIOCGIWGENIE */
620 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
621 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
622 (iw_handler) cfg80211_wext_siwencodeext, /* SIOCSIWENCODEEXT */
623 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
624 (iw_handler) NULL, /* SIOCSIWPMKSA */
625 (iw_handler) NULL, /* -- hole -- */
626};
627
628const struct iw_handler_def ieee80211_iw_handler_def =
629{
630 .num_standard = ARRAY_SIZE(ieee80211_handler),
631 .standard = (iw_handler *) ieee80211_handler,
632 .get_wireless_stats = ieee80211_get_wireless_stats,
633};
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 116a923b14d6..b19b7696f3a2 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -85,10 +85,8 @@ static u16 classify80211(struct ieee80211_local *local, struct sk_buff *skb)
85 return ieee802_1d_to_ac[skb->priority]; 85 return ieee802_1d_to_ac[skb->priority];
86} 86}
87 87
88u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb) 88void ieee80211_select_queue(struct ieee80211_local *local, struct sk_buff *skb)
89{ 89{
90 struct ieee80211_master_priv *mpriv = netdev_priv(dev);
91 struct ieee80211_local *local = mpriv->local;
92 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 90 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
93 u16 queue; 91 u16 queue;
94 u8 tid; 92 u8 tid;
@@ -113,5 +111,5 @@ u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb)
113 *p = 0; 111 *p = 0;
114 } 112 }
115 113
116 return queue; 114 skb_set_queue_mapping(skb, queue);
117} 115}
diff --git a/net/mac80211/wme.h b/net/mac80211/wme.h
index 7520d2e014dc..d4fd87ca5118 100644
--- a/net/mac80211/wme.h
+++ b/net/mac80211/wme.h
@@ -20,6 +20,7 @@
20 20
21extern const int ieee802_1d_to_ac[8]; 21extern const int ieee802_1d_to_ac[8];
22 22
23u16 ieee80211_select_queue(struct net_device *dev, struct sk_buff *skb); 23void ieee80211_select_queue(struct ieee80211_local *local,
24 struct sk_buff *skb);
24 25
25#endif /* _WME_H */ 26#endif /* _WME_H */
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index dcfae8884b86..70778694877b 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -122,7 +122,8 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
122 return RX_DROP_UNUSABLE; 122 return RX_DROP_UNUSABLE;
123 123
124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx, 124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx,
125 (void *) skb->data, NULL); 125 (void *) skb->data, NULL,
126 GFP_ATOMIC);
126 return RX_DROP_UNUSABLE; 127 return RX_DROP_UNUSABLE;
127 } 128 }
128 129