mac80211: A-MPDU Rx handling DELBA requests
[deliverable/linux.git] / net / mac80211 / ieee80211.c
CommitLineData
f0706e82
JB
1/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <net/mac80211.h>
12#include <net/ieee80211_radiotap.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/netdevice.h>
16#include <linux/types.h>
17#include <linux/slab.h>
18#include <linux/skbuff.h>
19#include <linux/etherdevice.h>
20#include <linux/if_arp.h>
21#include <linux/wireless.h>
22#include <linux/rtnetlink.h>
f0706e82 23#include <linux/bitmap.h>
881d966b 24#include <net/net_namespace.h>
f0706e82
JB
25#include <net/cfg80211.h>
26
f0706e82
JB
27#include "ieee80211_i.h"
28#include "ieee80211_rate.h"
29#include "wep.h"
f0706e82
JB
30#include "wme.h"
31#include "aes_ccm.h"
32#include "ieee80211_led.h"
e0eb6859 33#include "cfg.h"
e9f207f0
JB
34#include "debugfs.h"
35#include "debugfs_netdev.h"
f0706e82 36
d3c990fb
RR
37#define SUPP_MCS_SET_LEN 16
38
b306f453
JB
39/*
40 * For seeing transmitted packets on monitor interfaces
41 * we have a radiotap header too.
42 */
43struct ieee80211_tx_status_rtap_hdr {
44 struct ieee80211_radiotap_header hdr;
45 __le16 tx_flags;
46 u8 data_retries;
47} __attribute__ ((packed));
48
b2c258fb 49/* common interface routines */
b306f453 50
b95cce35 51static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
b2c258fb
JB
52{
53 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
54 return ETH_ALEN;
55}
f0706e82 56
4150c572
JB
57/* must be called under mdev tx lock */
58static void ieee80211_configure_filter(struct ieee80211_local *local)
59{
60 unsigned int changed_flags;
61 unsigned int new_flags = 0;
62
53918994 63 if (atomic_read(&local->iff_promiscs))
4150c572
JB
64 new_flags |= FIF_PROMISC_IN_BSS;
65
53918994 66 if (atomic_read(&local->iff_allmultis))
4150c572
JB
67 new_flags |= FIF_ALLMULTI;
68
69 if (local->monitors)
70 new_flags |= FIF_CONTROL |
71 FIF_OTHER_BSS |
72 FIF_BCN_PRBRESP_PROMISC;
73
74 changed_flags = local->filter_flags ^ new_flags;
75
76 /* be a bit nasty */
77 new_flags |= (1<<31);
78
79 local->ops->configure_filter(local_to_hw(local),
80 changed_flags, &new_flags,
81 local->mdev->mc_count,
82 local->mdev->mc_list);
83
84 WARN_ON(new_flags & (1<<31));
85
86 local->filter_flags = new_flags & ~(1<<31);
87}
88
b2c258fb 89/* master interface */
f0706e82 90
b2c258fb
JB
91static int ieee80211_master_open(struct net_device *dev)
92{
93 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
94 struct ieee80211_sub_if_data *sdata;
95 int res = -EOPNOTSUPP;
f0706e82 96
79010420
JB
97 /* we hold the RTNL here so can safely walk the list */
98 list_for_each_entry(sdata, &local->interfaces, list) {
b2c258fb
JB
99 if (sdata->dev != dev && netif_running(sdata->dev)) {
100 res = 0;
101 break;
102 }
103 }
b2c258fb
JB
104 return res;
105}
f0706e82 106
b2c258fb 107static int ieee80211_master_stop(struct net_device *dev)
f0706e82 108{
b2c258fb
JB
109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
110 struct ieee80211_sub_if_data *sdata;
f0706e82 111
79010420
JB
112 /* we hold the RTNL here so can safely walk the list */
113 list_for_each_entry(sdata, &local->interfaces, list)
b2c258fb
JB
114 if (sdata->dev != dev && netif_running(sdata->dev))
115 dev_close(sdata->dev);
f0706e82 116
b2c258fb
JB
117 return 0;
118}
f0706e82 119
4150c572
JB
120static void ieee80211_master_set_multicast_list(struct net_device *dev)
121{
122 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
123
124 ieee80211_configure_filter(local);
125}
126
b2c258fb 127/* regular interfaces */
f0706e82 128
b2c258fb 129static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
f0706e82 130{
b2c258fb
JB
131 /* FIX: what would be proper limits for MTU?
132 * This interface uses 802.3 frames. */
133 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
134 printk(KERN_WARNING "%s: invalid MTU %d\n",
135 dev->name, new_mtu);
136 return -EINVAL;
137 }
f0706e82 138
b2c258fb
JB
139#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
140 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
141#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
142 dev->mtu = new_mtu;
f0706e82
JB
143 return 0;
144}
145
b2c258fb
JB
146static inline int identical_mac_addr_allowed(int type1, int type2)
147{
148 return (type1 == IEEE80211_IF_TYPE_MNTR ||
149 type2 == IEEE80211_IF_TYPE_MNTR ||
150 (type1 == IEEE80211_IF_TYPE_AP &&
151 type2 == IEEE80211_IF_TYPE_WDS) ||
152 (type1 == IEEE80211_IF_TYPE_WDS &&
153 (type2 == IEEE80211_IF_TYPE_WDS ||
154 type2 == IEEE80211_IF_TYPE_AP)) ||
155 (type1 == IEEE80211_IF_TYPE_AP &&
156 type2 == IEEE80211_IF_TYPE_VLAN) ||
157 (type1 == IEEE80211_IF_TYPE_VLAN &&
158 (type2 == IEEE80211_IF_TYPE_AP ||
159 type2 == IEEE80211_IF_TYPE_VLAN)));
160}
f0706e82 161
b2c258fb 162static int ieee80211_open(struct net_device *dev)
e2ebc74d 163{
b2c258fb
JB
164 struct ieee80211_sub_if_data *sdata, *nsdata;
165 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
166 struct ieee80211_if_init_conf conf;
167 int res;
f0706e82 168
b2c258fb 169 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
0ec3ca44 170
79010420
JB
171 /* we hold the RTNL here so can safely walk the list */
172 list_for_each_entry(nsdata, &local->interfaces, list) {
b2c258fb 173 struct net_device *ndev = nsdata->dev;
e2ebc74d 174
b2c258fb 175 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
0ec3ca44
JB
176 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
177 /*
178 * check whether it may have the same address
179 */
180 if (!identical_mac_addr_allowed(sdata->type,
79010420 181 nsdata->type))
0ec3ca44 182 return -ENOTUNIQ;
0ec3ca44
JB
183
184 /*
185 * can only add VLANs to enabled APs
186 */
187 if (sdata->type == IEEE80211_IF_TYPE_VLAN &&
188 nsdata->type == IEEE80211_IF_TYPE_AP &&
189 netif_running(nsdata->dev))
190 sdata->u.vlan.ap = nsdata;
b2c258fb
JB
191 }
192 }
f0706e82 193
0ec3ca44
JB
194 switch (sdata->type) {
195 case IEEE80211_IF_TYPE_WDS:
196 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
197 return -ENOLINK;
198 break;
199 case IEEE80211_IF_TYPE_VLAN:
200 if (!sdata->u.vlan.ap)
201 return -ENOLINK;
202 break;
fb1c1cd6 203 case IEEE80211_IF_TYPE_AP:
fb1c1cd6
JB
204 case IEEE80211_IF_TYPE_STA:
205 case IEEE80211_IF_TYPE_MNTR:
206 case IEEE80211_IF_TYPE_IBSS:
207 /* no special treatment */
208 break;
a2897552
JB
209 case IEEE80211_IF_TYPE_INVALID:
210 /* cannot happen */
211 WARN_ON(1);
212 break;
0ec3ca44 213 }
f0706e82 214
b2c258fb
JB
215 if (local->open_count == 0) {
216 res = 0;
4150c572
JB
217 if (local->ops->start)
218 res = local->ops->start(local_to_hw(local));
219 if (res)
b2c258fb 220 return res;
8b393f1d 221 ieee80211_hw_config(local);
b2c258fb 222 }
f0706e82 223
4150c572 224 switch (sdata->type) {
0ec3ca44
JB
225 case IEEE80211_IF_TYPE_VLAN:
226 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
227 /* no need to tell driver */
228 break;
4150c572
JB
229 case IEEE80211_IF_TYPE_MNTR:
230 /* must be before the call to ieee80211_configure_filter */
b2c258fb 231 local->monitors++;
4150c572
JB
232 if (local->monitors == 1) {
233 netif_tx_lock_bh(local->mdev);
234 ieee80211_configure_filter(local);
235 netif_tx_unlock_bh(local->mdev);
236
237 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
4150c572
JB
238 }
239 break;
240 case IEEE80211_IF_TYPE_STA:
241 case IEEE80211_IF_TYPE_IBSS:
242 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
243 /* fall through */
244 default:
245 conf.if_id = dev->ifindex;
246 conf.type = sdata->type;
247 conf.mac_addr = dev->dev_addr;
248 res = local->ops->add_interface(local_to_hw(local), &conf);
249 if (res && !local->open_count && local->ops->stop)
250 local->ops->stop(local_to_hw(local));
251 if (res)
252 return res;
253
b2c258fb 254 ieee80211_if_config(dev);
d9430a32 255 ieee80211_reset_erp_info(dev);
11a843b7 256 ieee80211_enable_keys(sdata);
4150c572
JB
257
258 if (sdata->type == IEEE80211_IF_TYPE_STA &&
ddd3d2be 259 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
4150c572
JB
260 netif_carrier_off(dev);
261 else
262 netif_carrier_on(dev);
d9430a32 263 }
f0706e82 264
4150c572
JB
265 if (local->open_count == 0) {
266 res = dev_open(local->mdev);
267 WARN_ON(res);
4150c572
JB
268 tasklet_enable(&local->tx_pending_tasklet);
269 tasklet_enable(&local->tasklet);
270 }
271
c1428b3f
JB
272 /*
273 * set_multicast_list will be invoked by the networking core
274 * which will check whether any increments here were done in
275 * error and sync them down to the hardware as filter flags.
276 */
277 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
278 atomic_inc(&local->iff_allmultis);
279
280 if (sdata->flags & IEEE80211_SDATA_PROMISC)
281 atomic_inc(&local->iff_promiscs);
282
4150c572 283 local->open_count++;
f0706e82 284
b2c258fb 285 netif_start_queue(dev);
4150c572 286
b2c258fb 287 return 0;
f0706e82 288}
f0706e82 289
4150c572 290static int ieee80211_stop(struct net_device *dev)
f0706e82 291{
4150c572 292 struct ieee80211_sub_if_data *sdata;
f0706e82 293 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
4150c572 294 struct ieee80211_if_init_conf conf;
07db2183
RR
295 struct sta_info *sta;
296 int i;
4150c572
JB
297
298 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
299
07db2183
RR
300 list_for_each_entry(sta, &local->sta_list, list) {
301 for (i = 0; i < STA_TID_NUM; i++)
302 ieee80211_sta_stop_rx_ba_session(sta->dev, sta->addr,
303 i, WLAN_BACK_RECIPIENT,
304 WLAN_REASON_QSTA_LEAVE_QBSS);
305 }
306
4150c572
JB
307 netif_stop_queue(dev);
308
c1428b3f
JB
309 /*
310 * Don't count this interface for promisc/allmulti while it
311 * is down. dev_mc_unsync() will invoke set_multicast_list
312 * on the master interface which will sync these down to the
313 * hardware as filter flags.
314 */
315 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
316 atomic_dec(&local->iff_allmultis);
317
318 if (sdata->flags & IEEE80211_SDATA_PROMISC)
319 atomic_dec(&local->iff_promiscs);
320
4150c572
JB
321 dev_mc_unsync(local->mdev, dev);
322
0ec3ca44
JB
323 /* down all dependent devices, that is VLANs */
324 if (sdata->type == IEEE80211_IF_TYPE_AP) {
325 struct ieee80211_sub_if_data *vlan, *tmp;
326
327 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
328 u.vlan.list)
329 dev_close(vlan->dev);
330 WARN_ON(!list_empty(&sdata->u.ap.vlans));
331 }
332
4150c572 333 local->open_count--;
f0706e82 334
b2c258fb 335 switch (sdata->type) {
0ec3ca44
JB
336 case IEEE80211_IF_TYPE_VLAN:
337 list_del(&sdata->u.vlan.list);
338 sdata->u.vlan.ap = NULL;
339 /* no need to tell driver */
340 break;
4150c572
JB
341 case IEEE80211_IF_TYPE_MNTR:
342 local->monitors--;
343 if (local->monitors == 0) {
344 netif_tx_lock_bh(local->mdev);
345 ieee80211_configure_filter(local);
346 netif_tx_unlock_bh(local->mdev);
347
8b393f1d 348 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
4150c572
JB
349 }
350 break;
b2c258fb
JB
351 case IEEE80211_IF_TYPE_STA:
352 case IEEE80211_IF_TYPE_IBSS:
353 sdata->u.sta.state = IEEE80211_DISABLED;
354 del_timer_sync(&sdata->u.sta.timer);
2a8a9a88 355 /*
79010420
JB
356 * When we get here, the interface is marked down.
357 * Call synchronize_rcu() to wait for the RX path
358 * should it be using the interface and enqueuing
359 * frames at this very time on another CPU.
2a8a9a88 360 */
79010420 361 synchronize_rcu();
b2c258fb 362 skb_queue_purge(&sdata->u.sta.skb_queue);
2a8a9a88 363
ece8eddd
ZY
364 if (local->scan_dev == sdata->dev) {
365 if (!local->ops->hw_scan) {
366 local->sta_sw_scanning = 0;
367 cancel_delayed_work(&local->scan_work);
368 } else
369 local->sta_hw_scanning = 0;
b2c258fb 370 }
ece8eddd 371
b2c258fb 372 flush_workqueue(local->hw.workqueue);
a10605e5
ZY
373
374 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
375 kfree(sdata->u.sta.extra_ie);
376 sdata->u.sta.extra_ie = NULL;
377 sdata->u.sta.extra_ie_len = 0;
4150c572
JB
378 /* fall through */
379 default:
380 conf.if_id = dev->ifindex;
381 conf.type = sdata->type;
382 conf.mac_addr = dev->dev_addr;
11a843b7
JB
383 /* disable all keys for as long as this netdev is down */
384 ieee80211_disable_keys(sdata);
4150c572 385 local->ops->remove_interface(local_to_hw(local), &conf);
f0706e82
JB
386 }
387
b2c258fb
JB
388 if (local->open_count == 0) {
389 if (netif_running(local->mdev))
390 dev_close(local->mdev);
4150c572 391
b2c258fb
JB
392 if (local->ops->stop)
393 local->ops->stop(local_to_hw(local));
4150c572 394
b2c258fb
JB
395 tasklet_disable(&local->tx_pending_tasklet);
396 tasklet_disable(&local->tasklet);
397 }
b2c258fb 398
f0706e82
JB
399 return 0;
400}
401
f0706e82
JB
402static void ieee80211_set_multicast_list(struct net_device *dev)
403{
404 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
405 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4150c572 406 int allmulti, promisc, sdata_allmulti, sdata_promisc;
f0706e82 407
4150c572
JB
408 allmulti = !!(dev->flags & IFF_ALLMULTI);
409 promisc = !!(dev->flags & IFF_PROMISC);
b52f2198
JB
410 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
411 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
4150c572
JB
412
413 if (allmulti != sdata_allmulti) {
414 if (dev->flags & IFF_ALLMULTI)
53918994 415 atomic_inc(&local->iff_allmultis);
4150c572 416 else
53918994 417 atomic_dec(&local->iff_allmultis);
13262ffd 418 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
f0706e82 419 }
4150c572
JB
420
421 if (promisc != sdata_promisc) {
422 if (dev->flags & IFF_PROMISC)
53918994 423 atomic_inc(&local->iff_promiscs);
4150c572 424 else
53918994 425 atomic_dec(&local->iff_promiscs);
13262ffd 426 sdata->flags ^= IEEE80211_SDATA_PROMISC;
f0706e82 427 }
4150c572
JB
428
429 dev_mc_sync(local->mdev, dev);
f0706e82
JB
430}
431
3b04ddde
SH
432static const struct header_ops ieee80211_header_ops = {
433 .create = eth_header,
434 .parse = header_parse_80211,
435 .rebuild = eth_rebuild_header,
436 .cache = eth_header_cache,
437 .cache_update = eth_header_cache_update,
438};
439
f9d540ee 440/* Must not be called for mdev */
b2c258fb 441void ieee80211_if_setup(struct net_device *dev)
f0706e82 442{
b2c258fb
JB
443 ether_setup(dev);
444 dev->hard_start_xmit = ieee80211_subif_start_xmit;
445 dev->wireless_handlers = &ieee80211_iw_handler_def;
446 dev->set_multicast_list = ieee80211_set_multicast_list;
447 dev->change_mtu = ieee80211_change_mtu;
b2c258fb
JB
448 dev->open = ieee80211_open;
449 dev->stop = ieee80211_stop;
b2c258fb
JB
450 dev->destructor = ieee80211_if_free;
451}
f0706e82 452
b2c258fb
JB
453/* WDS specialties */
454
455int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
456{
457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
458 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
459 struct sta_info *sta;
0795af57 460 DECLARE_MAC_BUF(mac);
b2c258fb
JB
461
462 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
463 return 0;
464
465 /* Create STA entry for the new peer */
466 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
467 if (!sta)
468 return -ENOMEM;
469 sta_info_put(sta);
470
471 /* Remove STA entry for the old peer */
472 sta = sta_info_get(local, sdata->u.wds.remote_addr);
473 if (sta) {
be8755e1 474 sta_info_free(sta);
b2c258fb 475 sta_info_put(sta);
b2c258fb
JB
476 } else {
477 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
0795af57
JP
478 "peer %s\n",
479 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
b2c258fb
JB
480 }
481
482 /* Update WDS link data */
483 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
484
485 return 0;
f0706e82 486}
f0706e82 487
b2c258fb
JB
488/* everything else */
489
b2c258fb
JB
490static int __ieee80211_if_config(struct net_device *dev,
491 struct sk_buff *beacon,
492 struct ieee80211_tx_control *control)
493{
494 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
495 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
496 struct ieee80211_if_conf conf;
b2c258fb
JB
497
498 if (!local->ops->config_interface || !netif_running(dev))
f0706e82 499 return 0;
f0706e82 500
b2c258fb 501 memset(&conf, 0, sizeof(conf));
4480f15c 502 conf.type = sdata->type;
b2c258fb
JB
503 if (sdata->type == IEEE80211_IF_TYPE_STA ||
504 sdata->type == IEEE80211_IF_TYPE_IBSS) {
4150c572 505 conf.bssid = sdata->u.sta.bssid;
b2c258fb
JB
506 conf.ssid = sdata->u.sta.ssid;
507 conf.ssid_len = sdata->u.sta.ssid_len;
b2c258fb
JB
508 } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
509 conf.ssid = sdata->u.ap.ssid;
510 conf.ssid_len = sdata->u.ap.ssid_len;
b2c258fb
JB
511 conf.beacon = beacon;
512 conf.beacon_control = control;
f0706e82 513 }
b2c258fb
JB
514 return local->ops->config_interface(local_to_hw(local),
515 dev->ifindex, &conf);
f0706e82
JB
516}
517
b2c258fb
JB
518int ieee80211_if_config(struct net_device *dev)
519{
520 return __ieee80211_if_config(dev, NULL, NULL);
521}
f0706e82 522
b2c258fb 523int ieee80211_if_config_beacon(struct net_device *dev)
f0706e82 524{
f0706e82 525 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
b2c258fb
JB
526 struct ieee80211_tx_control control;
527 struct sk_buff *skb;
f0706e82 528
b2c258fb 529 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
f0706e82 530 return 0;
b2c258fb
JB
531 skb = ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
532 if (!skb)
533 return -ENOMEM;
534 return __ieee80211_if_config(dev, skb, &control);
535}
f0706e82 536
b2c258fb
JB
537int ieee80211_hw_config(struct ieee80211_local *local)
538{
539 struct ieee80211_hw_mode *mode;
540 struct ieee80211_channel *chan;
541 int ret = 0;
f0706e82 542
ece8eddd 543 if (local->sta_sw_scanning) {
b2c258fb
JB
544 chan = local->scan_channel;
545 mode = local->scan_hw_mode;
546 } else {
547 chan = local->oper_channel;
548 mode = local->oper_hw_mode;
f0706e82
JB
549 }
550
b2c258fb
JB
551 local->hw.conf.channel = chan->chan;
552 local->hw.conf.channel_val = chan->val;
61609bc0
MB
553 if (!local->hw.conf.power_level) {
554 local->hw.conf.power_level = chan->power_level;
555 } else {
556 local->hw.conf.power_level = min(chan->power_level,
557 local->hw.conf.power_level);
558 }
b2c258fb
JB
559 local->hw.conf.freq = chan->freq;
560 local->hw.conf.phymode = mode->mode;
561 local->hw.conf.antenna_max = chan->antenna_max;
562 local->hw.conf.chan = chan;
563 local->hw.conf.mode = mode;
f0706e82 564
b2c258fb
JB
565#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
566 printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
567 "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
568 local->hw.conf.phymode);
569#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
570
f7c4daed 571 if (local->open_count)
b2c258fb 572 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
f0706e82 573
b2c258fb
JB
574 return ret;
575}
f0706e82 576
d3c990fb
RR
577/**
578 * ieee80211_hw_config_ht should be used only after legacy configuration
579 * has been determined, as ht configuration depends upon the hardware's
580 * HT abilities for a _specific_ band.
581 */
582int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
583 struct ieee80211_ht_info *req_ht_cap,
584 struct ieee80211_ht_bss_info *req_bss_cap)
585{
586 struct ieee80211_conf *conf = &local->hw.conf;
587 struct ieee80211_hw_mode *mode = conf->mode;
588 int i;
589
590 /* HT is not supported */
591 if (!mode->ht_info.ht_supported) {
592 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
593 return -EOPNOTSUPP;
594 }
595
596 /* disable HT */
597 if (!enable_ht) {
598 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
599 } else {
600 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
601 conf->ht_conf.cap = req_ht_cap->cap & mode->ht_info.cap;
602 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
603 conf->ht_conf.cap |=
604 mode->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
605 conf->ht_bss_conf.primary_channel =
606 req_bss_cap->primary_channel;
607 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
608 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
609 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
610 conf->ht_conf.supp_mcs_set[i] =
611 mode->ht_info.supp_mcs_set[i] &
612 req_ht_cap->supp_mcs_set[i];
613
614 /* In STA mode, this gives us indication
615 * to the AP's mode of operation */
616 conf->ht_conf.ht_supported = 1;
617 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
618 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
619 }
620
621 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
622
623 return 0;
624}
625
d9430a32
DD
626void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes)
627{
628 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
629 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
630 if (local->ops->erp_ie_changed)
631 local->ops->erp_ie_changed(local_to_hw(local), changes,
13262ffd
JS
632 !!(sdata->flags & IEEE80211_SDATA_USE_PROTECTION),
633 !(sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE));
d9430a32
DD
634}
635
636void ieee80211_reset_erp_info(struct net_device *dev)
637{
638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
639
13262ffd
JS
640 sdata->flags &= ~(IEEE80211_SDATA_USE_PROTECTION |
641 IEEE80211_SDATA_SHORT_PREAMBLE);
d9430a32
DD
642 ieee80211_erp_info_change_notify(dev,
643 IEEE80211_ERP_CHANGE_PROTECTION |
644 IEEE80211_ERP_CHANGE_PREAMBLE);
645}
646
f0706e82
JB
647void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
648 struct sk_buff *skb,
649 struct ieee80211_tx_status *status)
650{
651 struct ieee80211_local *local = hw_to_local(hw);
652 struct ieee80211_tx_status *saved;
653 int tmp;
654
655 skb->dev = local->mdev;
656 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
657 if (unlikely(!saved)) {
658 if (net_ratelimit())
659 printk(KERN_WARNING "%s: Not enough memory, "
660 "dropping tx status", skb->dev->name);
661 /* should be dev_kfree_skb_irq, but due to this function being
662 * named _irqsafe instead of just _irq we can't be sure that
663 * people won't call it from non-irq contexts */
664 dev_kfree_skb_any(skb);
665 return;
666 }
667 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
668 /* copy pointer to saved status into skb->cb for use by tasklet */
669 memcpy(skb->cb, &saved, sizeof(saved));
670
671 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
672 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
673 &local->skb_queue : &local->skb_queue_unreliable, skb);
674 tmp = skb_queue_len(&local->skb_queue) +
675 skb_queue_len(&local->skb_queue_unreliable);
676 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
677 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
678 memcpy(&saved, skb->cb, sizeof(saved));
679 kfree(saved);
680 dev_kfree_skb_irq(skb);
681 tmp--;
682 I802_DEBUG_INC(local->tx_status_drop);
683 }
684 tasklet_schedule(&local->tasklet);
685}
686EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
687
688static void ieee80211_tasklet_handler(unsigned long data)
689{
690 struct ieee80211_local *local = (struct ieee80211_local *) data;
691 struct sk_buff *skb;
692 struct ieee80211_rx_status rx_status;
693 struct ieee80211_tx_status *tx_status;
694
695 while ((skb = skb_dequeue(&local->skb_queue)) ||
696 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
697 switch (skb->pkt_type) {
698 case IEEE80211_RX_MSG:
699 /* status is in skb->cb */
700 memcpy(&rx_status, skb->cb, sizeof(rx_status));
701 /* Clear skb->type in order to not confuse kernel
702 * netstack. */
703 skb->pkt_type = 0;
704 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
705 break;
706 case IEEE80211_TX_STATUS_MSG:
707 /* get pointer to saved status out of skb->cb */
708 memcpy(&tx_status, skb->cb, sizeof(tx_status));
709 skb->pkt_type = 0;
710 ieee80211_tx_status(local_to_hw(local),
711 skb, tx_status);
712 kfree(tx_status);
713 break;
714 default: /* should never get here! */
715 printk(KERN_ERR "%s: Unknown message type (%d)\n",
dd1cd4c6 716 wiphy_name(local->hw.wiphy), skb->pkt_type);
f0706e82
JB
717 dev_kfree_skb(skb);
718 break;
719 }
720 }
721}
722
f0706e82
JB
723/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
724 * make a prepared TX frame (one that has been given to hw) to look like brand
725 * new IEEE 802.11 frame that is ready to go through TX processing again.
726 * Also, tx_packet_data in cb is restored from tx_control. */
727static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
728 struct ieee80211_key *key,
729 struct sk_buff *skb,
730 struct ieee80211_tx_control *control)
731{
732 int hdrlen, iv_len, mic_len;
733 struct ieee80211_tx_packet_data *pkt_data;
734
735 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
736 pkt_data->ifindex = control->ifindex;
e8bf9649
JS
737 pkt_data->flags = 0;
738 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
739 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
740 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
741 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
742 if (control->flags & IEEE80211_TXCTL_REQUEUE)
743 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
678f5f71
JB
744 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
745 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
f0706e82
JB
746 pkt_data->queue = control->queue;
747
748 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
749
750 if (!key)
751 goto no_key;
752
8f20fc24 753 switch (key->conf.alg) {
f0706e82
JB
754 case ALG_WEP:
755 iv_len = WEP_IV_LEN;
756 mic_len = WEP_ICV_LEN;
757 break;
758 case ALG_TKIP:
759 iv_len = TKIP_IV_LEN;
760 mic_len = TKIP_ICV_LEN;
761 break;
762 case ALG_CCMP:
763 iv_len = CCMP_HDR_LEN;
764 mic_len = CCMP_MIC_LEN;
765 break;
766 default:
767 goto no_key;
768 }
769
8f20fc24 770 if (skb->len >= mic_len &&
11a843b7 771 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
f0706e82
JB
772 skb_trim(skb, skb->len - mic_len);
773 if (skb->len >= iv_len && skb->len > hdrlen) {
774 memmove(skb->data + iv_len, skb->data, hdrlen);
775 skb_pull(skb, iv_len);
776 }
777
778no_key:
779 {
780 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
781 u16 fc = le16_to_cpu(hdr->frame_control);
782 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
783 fc &= ~IEEE80211_STYPE_QOS_DATA;
784 hdr->frame_control = cpu_to_le16(fc);
785 memmove(skb->data + 2, skb->data, hdrlen - 2);
786 skb_pull(skb, 2);
787 }
788 }
789}
790
f0706e82
JB
791void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
792 struct ieee80211_tx_status *status)
793{
794 struct sk_buff *skb2;
795 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
796 struct ieee80211_local *local = hw_to_local(hw);
797 u16 frag, type;
b306f453
JB
798 struct ieee80211_tx_status_rtap_hdr *rthdr;
799 struct ieee80211_sub_if_data *sdata;
800 int monitors;
f0706e82
JB
801
802 if (!status) {
803 printk(KERN_ERR
804 "%s: ieee80211_tx_status called with NULL status\n",
dd1cd4c6 805 wiphy_name(local->hw.wiphy));
f0706e82
JB
806 dev_kfree_skb(skb);
807 return;
808 }
809
810 if (status->excessive_retries) {
811 struct sta_info *sta;
812 sta = sta_info_get(local, hdr->addr1);
813 if (sta) {
814 if (sta->flags & WLAN_STA_PS) {
815 /* The STA is in power save mode, so assume
816 * that this TX packet failed because of that.
817 */
818 status->excessive_retries = 0;
819 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
820 }
821 sta_info_put(sta);
822 }
823 }
824
825 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
826 struct sta_info *sta;
827 sta = sta_info_get(local, hdr->addr1);
828 if (sta) {
829 sta->tx_filtered_count++;
830
831 /* Clear the TX filter mask for this STA when sending
832 * the next packet. If the STA went to power save mode,
833 * this will happen when it is waking up for the next
834 * time. */
835 sta->clear_dst_mask = 1;
836
837 /* TODO: Is the WLAN_STA_PS flag always set here or is
838 * the race between RX and TX status causing some
839 * packets to be filtered out before 80211.o gets an
840 * update for PS status? This seems to be the case, so
841 * no changes are likely to be needed. */
842 if (sta->flags & WLAN_STA_PS &&
843 skb_queue_len(&sta->tx_filtered) <
844 STA_MAX_TX_BUFFER) {
845 ieee80211_remove_tx_extra(local, sta->key,
846 skb,
847 &status->control);
848 skb_queue_tail(&sta->tx_filtered, skb);
849 } else if (!(sta->flags & WLAN_STA_PS) &&
850 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
851 /* Software retry the packet once */
852 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
853 ieee80211_remove_tx_extra(local, sta->key,
854 skb,
855 &status->control);
856 dev_queue_xmit(skb);
857 } else {
858 if (net_ratelimit()) {
859 printk(KERN_DEBUG "%s: dropped TX "
860 "filtered frame queue_len=%d "
861 "PS=%d @%lu\n",
dd1cd4c6 862 wiphy_name(local->hw.wiphy),
f0706e82
JB
863 skb_queue_len(
864 &sta->tx_filtered),
865 !!(sta->flags & WLAN_STA_PS),
866 jiffies);
867 }
868 dev_kfree_skb(skb);
869 }
870 sta_info_put(sta);
871 return;
872 }
1abbe498
MN
873 } else
874 rate_control_tx_status(local->mdev, skb, status);
f0706e82
JB
875
876 ieee80211_led_tx(local, 0);
877
878 /* SNMP counters
879 * Fragments are passed to low-level drivers as separate skbs, so these
880 * are actually fragments, not frames. Update frame counters only for
881 * the first fragment of the frame. */
882
883 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
884 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
885
886 if (status->flags & IEEE80211_TX_STATUS_ACK) {
887 if (frag == 0) {
888 local->dot11TransmittedFrameCount++;
889 if (is_multicast_ether_addr(hdr->addr1))
890 local->dot11MulticastTransmittedFrameCount++;
891 if (status->retry_count > 0)
892 local->dot11RetryCount++;
893 if (status->retry_count > 1)
894 local->dot11MultipleRetryCount++;
895 }
896
897 /* This counter shall be incremented for an acknowledged MPDU
898 * with an individual address in the address 1 field or an MPDU
899 * with a multicast address in the address 1 field of type Data
900 * or Management. */
901 if (!is_multicast_ether_addr(hdr->addr1) ||
902 type == IEEE80211_FTYPE_DATA ||
903 type == IEEE80211_FTYPE_MGMT)
904 local->dot11TransmittedFragmentCount++;
905 } else {
906 if (frag == 0)
907 local->dot11FailedCount++;
908 }
909
b306f453
JB
910 /* this was a transmitted frame, but now we want to reuse it */
911 skb_orphan(skb);
912
b306f453 913 if (!local->monitors) {
f0706e82
JB
914 dev_kfree_skb(skb);
915 return;
916 }
917
b306f453 918 /* send frame to monitor interfaces now */
f0706e82 919
b306f453
JB
920 if (skb_headroom(skb) < sizeof(*rthdr)) {
921 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
f0706e82
JB
922 dev_kfree_skb(skb);
923 return;
924 }
f0706e82 925
b306f453
JB
926 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
927 skb_push(skb, sizeof(*rthdr));
928
929 memset(rthdr, 0, sizeof(*rthdr));
930 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
931 rthdr->hdr.it_present =
932 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
933 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
934
935 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
936 !is_multicast_ether_addr(hdr->addr1))
937 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
938
939 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
940 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
941 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
942 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
943 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
944
945 rthdr->data_retries = status->retry_count;
946
79010420 947 rcu_read_lock();
b306f453 948 monitors = local->monitors;
79010420 949 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
b306f453
JB
950 /*
951 * Using the monitors counter is possibly racy, but
952 * if the value is wrong we simply either clone the skb
953 * once too much or forget sending it to one monitor iface
954 * The latter case isn't nice but fixing the race is much
955 * more complicated.
956 */
957 if (!monitors || !skb)
958 goto out;
959
960 if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
961 if (!netif_running(sdata->dev))
962 continue;
963 monitors--;
964 if (monitors)
79010420 965 skb2 = skb_clone(skb, GFP_ATOMIC);
b306f453
JB
966 else
967 skb2 = NULL;
968 skb->dev = sdata->dev;
969 /* XXX: is this sufficient for BPF? */
970 skb_set_mac_header(skb, 0);
971 skb->ip_summed = CHECKSUM_UNNECESSARY;
972 skb->pkt_type = PACKET_OTHERHOST;
973 skb->protocol = htons(ETH_P_802_2);
974 memset(skb->cb, 0, sizeof(skb->cb));
975 netif_rx(skb);
976 skb = skb2;
b306f453
JB
977 }
978 }
979 out:
79010420 980 rcu_read_unlock();
b306f453
JB
981 if (skb)
982 dev_kfree_skb(skb);
f0706e82
JB
983}
984EXPORT_SYMBOL(ieee80211_tx_status);
985
f0706e82
JB
986struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
987 const struct ieee80211_ops *ops)
988{
989 struct net_device *mdev;
990 struct ieee80211_local *local;
991 struct ieee80211_sub_if_data *sdata;
992 int priv_size;
993 struct wiphy *wiphy;
994
995 /* Ensure 32-byte alignment of our private data and hw private data.
996 * We use the wiphy priv data for both our ieee80211_local and for
997 * the driver's private data
998 *
999 * In memory it'll be like this:
1000 *
1001 * +-------------------------+
1002 * | struct wiphy |
1003 * +-------------------------+
1004 * | struct ieee80211_local |
1005 * +-------------------------+
1006 * | driver's private data |
1007 * +-------------------------+
1008 *
1009 */
1010 priv_size = ((sizeof(struct ieee80211_local) +
1011 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1012 priv_data_len;
1013
1014 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1015
1016 if (!wiphy)
1017 return NULL;
1018
1019 wiphy->privid = mac80211_wiphy_privid;
1020
1021 local = wiphy_priv(wiphy);
1022 local->hw.wiphy = wiphy;
1023
1024 local->hw.priv = (char *)local +
1025 ((sizeof(struct ieee80211_local) +
1026 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1027
4480f15c 1028 BUG_ON(!ops->tx);
4150c572
JB
1029 BUG_ON(!ops->start);
1030 BUG_ON(!ops->stop);
4480f15c
JB
1031 BUG_ON(!ops->config);
1032 BUG_ON(!ops->add_interface);
4150c572
JB
1033 BUG_ON(!ops->remove_interface);
1034 BUG_ON(!ops->configure_filter);
f0706e82
JB
1035 local->ops = ops;
1036
1037 /* for now, mdev needs sub_if_data :/ */
1038 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1039 "wmaster%d", ether_setup);
1040 if (!mdev) {
1041 wiphy_free(wiphy);
1042 return NULL;
1043 }
1044
1045 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1046 mdev->ieee80211_ptr = &sdata->wdev;
1047 sdata->wdev.wiphy = wiphy;
1048
1049 local->hw.queues = 1; /* default */
1050
1051 local->mdev = mdev;
1052 local->rx_pre_handlers = ieee80211_rx_pre_handlers;
1053 local->rx_handlers = ieee80211_rx_handlers;
1054 local->tx_handlers = ieee80211_tx_handlers;
1055
1056 local->bridge_packets = 1;
1057
1058 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1059 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1060 local->short_retry_limit = 7;
1061 local->long_retry_limit = 4;
1062 local->hw.conf.radio_enabled = 1;
f0706e82 1063
b708e610 1064 local->enabled_modes = ~0;
f0706e82
JB
1065
1066 INIT_LIST_HEAD(&local->modes_list);
1067
79010420 1068 INIT_LIST_HEAD(&local->interfaces);
f0706e82
JB
1069
1070 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
f0706e82
JB
1071 ieee80211_rx_bss_list_init(mdev);
1072
1073 sta_info_init(local);
1074
1075 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1076 mdev->open = ieee80211_master_open;
1077 mdev->stop = ieee80211_master_stop;
1078 mdev->type = ARPHRD_IEEE80211;
3b04ddde 1079 mdev->header_ops = &ieee80211_header_ops;
4150c572 1080 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
f0706e82
JB
1081
1082 sdata->type = IEEE80211_IF_TYPE_AP;
1083 sdata->dev = mdev;
1084 sdata->local = local;
1085 sdata->u.ap.force_unicast_rateidx = -1;
1086 sdata->u.ap.max_ratectrl_rateidx = -1;
1087 ieee80211_if_sdata_init(sdata);
79010420
JB
1088 /* no RCU needed since we're still during init phase */
1089 list_add_tail(&sdata->list, &local->interfaces);
f0706e82
JB
1090
1091 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1092 (unsigned long)local);
1093 tasklet_disable(&local->tx_pending_tasklet);
1094
1095 tasklet_init(&local->tasklet,
1096 ieee80211_tasklet_handler,
1097 (unsigned long) local);
1098 tasklet_disable(&local->tasklet);
1099
1100 skb_queue_head_init(&local->skb_queue);
1101 skb_queue_head_init(&local->skb_queue_unreliable);
1102
1103 return local_to_hw(local);
1104}
1105EXPORT_SYMBOL(ieee80211_alloc_hw);
1106
1107int ieee80211_register_hw(struct ieee80211_hw *hw)
1108{
1109 struct ieee80211_local *local = hw_to_local(hw);
1110 const char *name;
1111 int result;
1112
1113 result = wiphy_register(local->hw.wiphy);
1114 if (result < 0)
1115 return result;
1116
1117 name = wiphy_dev(local->hw.wiphy)->driver->name;
1118 local->hw.workqueue = create_singlethread_workqueue(name);
1119 if (!local->hw.workqueue) {
1120 result = -ENOMEM;
1121 goto fail_workqueue;
1122 }
1123
b306f453
JB
1124 /*
1125 * The hardware needs headroom for sending the frame,
1126 * and we need some headroom for passing the frame to monitor
1127 * interfaces, but never both at the same time.
1128 */
33ccad35
JB
1129 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1130 sizeof(struct ieee80211_tx_status_rtap_hdr));
b306f453 1131
e9f207f0
JB
1132 debugfs_hw_add(local);
1133
f0706e82
JB
1134 local->hw.conf.beacon_int = 1000;
1135
1136 local->wstats_flags |= local->hw.max_rssi ?
1137 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1138 local->wstats_flags |= local->hw.max_signal ?
1139 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1140 local->wstats_flags |= local->hw.max_noise ?
1141 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1142 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1143 local->wstats_flags |= IW_QUAL_DBM;
1144
1145 result = sta_info_start(local);
1146 if (result < 0)
1147 goto fail_sta_info;
1148
1149 rtnl_lock();
1150 result = dev_alloc_name(local->mdev, local->mdev->name);
1151 if (result < 0)
1152 goto fail_dev;
1153
1154 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1155 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1156
1157 result = register_netdevice(local->mdev);
1158 if (result < 0)
1159 goto fail_dev;
1160
e9f207f0 1161 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
5b2812e9 1162 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
e9f207f0 1163
830f9038
JB
1164 result = ieee80211_init_rate_ctrl_alg(local,
1165 hw->rate_control_algorithm);
f0706e82
JB
1166 if (result < 0) {
1167 printk(KERN_DEBUG "%s: Failed to initialize rate control "
dd1cd4c6 1168 "algorithm\n", wiphy_name(local->hw.wiphy));
f0706e82
JB
1169 goto fail_rate;
1170 }
1171
1172 result = ieee80211_wep_init(local);
1173
1174 if (result < 0) {
1175 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
dd1cd4c6 1176 wiphy_name(local->hw.wiphy));
f0706e82
JB
1177 goto fail_wep;
1178 }
1179
1180 ieee80211_install_qdisc(local->mdev);
1181
1182 /* add one default STA interface */
1183 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1184 IEEE80211_IF_TYPE_STA);
1185 if (result)
1186 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
dd1cd4c6 1187 wiphy_name(local->hw.wiphy));
f0706e82
JB
1188
1189 local->reg_state = IEEE80211_DEV_REGISTERED;
1190 rtnl_unlock();
1191
1192 ieee80211_led_init(local);
1193
1194 return 0;
1195
1196fail_wep:
1197 rate_control_deinitialize(local);
1198fail_rate:
e9f207f0 1199 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
f0706e82
JB
1200 unregister_netdevice(local->mdev);
1201fail_dev:
1202 rtnl_unlock();
1203 sta_info_stop(local);
1204fail_sta_info:
e9f207f0 1205 debugfs_hw_del(local);
f0706e82
JB
1206 destroy_workqueue(local->hw.workqueue);
1207fail_workqueue:
1208 wiphy_unregister(local->hw.wiphy);
1209 return result;
1210}
1211EXPORT_SYMBOL(ieee80211_register_hw);
1212
1213int ieee80211_register_hwmode(struct ieee80211_hw *hw,
1214 struct ieee80211_hw_mode *mode)
1215{
1216 struct ieee80211_local *local = hw_to_local(hw);
1217 struct ieee80211_rate *rate;
1218 int i;
1219
1220 INIT_LIST_HEAD(&mode->list);
1221 list_add_tail(&mode->list, &local->modes_list);
1222
1223 local->hw_modes |= (1 << mode->mode);
1224 for (i = 0; i < mode->num_rates; i++) {
1225 rate = &(mode->rates[i]);
1226 rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
1227 }
1228 ieee80211_prepare_rates(local, mode);
1229
1230 if (!local->oper_hw_mode) {
1231 /* Default to this mode */
1232 local->hw.conf.phymode = mode->mode;
1233 local->oper_hw_mode = local->scan_hw_mode = mode;
1234 local->oper_channel = local->scan_channel = &mode->channels[0];
1235 local->hw.conf.mode = local->oper_hw_mode;
1236 local->hw.conf.chan = local->oper_channel;
1237 }
1238
1239 if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
fd8bacc9 1240 ieee80211_set_default_regdomain(mode);
f0706e82
JB
1241
1242 return 0;
1243}
1244EXPORT_SYMBOL(ieee80211_register_hwmode);
1245
1246void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1247{
1248 struct ieee80211_local *local = hw_to_local(hw);
1249 struct ieee80211_sub_if_data *sdata, *tmp;
f0706e82
JB
1250 int i;
1251
1252 tasklet_kill(&local->tx_pending_tasklet);
1253 tasklet_kill(&local->tasklet);
1254
1255 rtnl_lock();
1256
1257 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1258
1259 local->reg_state = IEEE80211_DEV_UNREGISTERED;
f0706e82 1260
79010420
JB
1261 /*
1262 * At this point, interface list manipulations are fine
1263 * because the driver cannot be handing us frames any
1264 * more and the tasklet is killed.
1265 */
5b2812e9
JB
1266
1267 /*
1268 * First, we remove all non-master interfaces. Do this because they
1269 * may have bss pointer dependency on the master, and when we free
1270 * the master these would be freed as well, breaking our list
1271 * iteration completely.
1272 */
1273 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1274 if (sdata->dev == local->mdev)
1275 continue;
1276 list_del(&sdata->list);
f0706e82 1277 __ieee80211_if_del(local, sdata);
5b2812e9
JB
1278 }
1279
1280 /* then, finally, remove the master interface */
1281 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
f0706e82
JB
1282
1283 rtnl_unlock();
1284
f0706e82
JB
1285 ieee80211_rx_bss_list_deinit(local->mdev);
1286 ieee80211_clear_tx_pending(local);
1287 sta_info_stop(local);
1288 rate_control_deinitialize(local);
e9f207f0 1289 debugfs_hw_del(local);
f0706e82
JB
1290
1291 for (i = 0; i < NUM_IEEE80211_MODES; i++) {
1292 kfree(local->supp_rates[i]);
1293 kfree(local->basic_rates[i]);
1294 }
1295
1296 if (skb_queue_len(&local->skb_queue)
1297 || skb_queue_len(&local->skb_queue_unreliable))
1298 printk(KERN_WARNING "%s: skb_queue not empty\n",
dd1cd4c6 1299 wiphy_name(local->hw.wiphy));
f0706e82
JB
1300 skb_queue_purge(&local->skb_queue);
1301 skb_queue_purge(&local->skb_queue_unreliable);
1302
1303 destroy_workqueue(local->hw.workqueue);
1304 wiphy_unregister(local->hw.wiphy);
1305 ieee80211_wep_free(local);
1306 ieee80211_led_exit(local);
1307}
1308EXPORT_SYMBOL(ieee80211_unregister_hw);
1309
1310void ieee80211_free_hw(struct ieee80211_hw *hw)
1311{
1312 struct ieee80211_local *local = hw_to_local(hw);
1313
1314 ieee80211_if_free(local->mdev);
1315 wiphy_free(local->hw.wiphy);
1316}
1317EXPORT_SYMBOL(ieee80211_free_hw);
1318
f0706e82
JB
1319static int __init ieee80211_init(void)
1320{
1321 struct sk_buff *skb;
1322 int ret;
1323
1324 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1325
c21b39ac 1326#ifdef CONFIG_MAC80211_RC_SIMPLE
ac71c691
JB
1327 ret = ieee80211_rate_control_register(&mac80211_rcsimple);
1328 if (ret)
ad018375
MN
1329 goto fail;
1330#endif
1331
c21b39ac 1332#ifdef CONFIG_MAC80211_RC_PID
ad018375
MN
1333 ret = ieee80211_rate_control_register(&mac80211_rcpid);
1334 if (ret)
1335 goto fail;
ac71c691
JB
1336#endif
1337
f0706e82
JB
1338 ret = ieee80211_wme_register();
1339 if (ret) {
1340 printk(KERN_DEBUG "ieee80211_init: failed to "
1341 "initialize WME (err=%d)\n", ret);
ad018375 1342 goto fail;
f0706e82
JB
1343 }
1344
e9f207f0 1345 ieee80211_debugfs_netdev_init();
fd8bacc9 1346 ieee80211_regdomain_init();
e9f207f0 1347
f0706e82 1348 return 0;
ad018375
MN
1349
1350fail:
1351
c21b39ac 1352#ifdef CONFIG_MAC80211_RC_SIMPLE
ad018375
MN
1353 ieee80211_rate_control_unregister(&mac80211_rcsimple);
1354#endif
c21b39ac 1355#ifdef CONFIG_MAC80211_RC_PID
ad018375
MN
1356 ieee80211_rate_control_unregister(&mac80211_rcpid);
1357#endif
1358
1359 return ret;
f0706e82
JB
1360}
1361
f0706e82
JB
1362static void __exit ieee80211_exit(void)
1363{
c21b39ac 1364#ifdef CONFIG_MAC80211_RC_SIMPLE
ac71c691
JB
1365 ieee80211_rate_control_unregister(&mac80211_rcsimple);
1366#endif
c21b39ac 1367#ifdef CONFIG_MAC80211_RC_PID
ad018375
MN
1368 ieee80211_rate_control_unregister(&mac80211_rcpid);
1369#endif
ac71c691 1370
f0706e82 1371 ieee80211_wme_unregister();
e9f207f0 1372 ieee80211_debugfs_netdev_exit();
f0706e82
JB
1373}
1374
1375
ca9938fe 1376subsys_initcall(ieee80211_init);
f0706e82
JB
1377module_exit(ieee80211_exit);
1378
1379MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1380MODULE_LICENSE("GPL");
This page took 0.196999 seconds and 5 git commands to generate.