blob: cb09931af86a2f7bd90a9cf93f1483d550f4b517 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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>
Jiri Bencf0706e82007-05-05 11:45:53 -070023#include <linux/bitmap.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070024#include <net/net_namespace.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include <net/cfg80211.h>
26
Jiri Bencf0706e82007-05-05 11:45:53 -070027#include "ieee80211_i.h"
28#include "ieee80211_rate.h"
29#include "wep.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070030#include "wme.h"
31#include "aes_ccm.h"
32#include "ieee80211_led.h"
Michael Wue0eb6852007-09-18 17:29:21 -040033#include "cfg.h"
Jiri Bence9f207f2007-05-05 11:46:38 -070034#include "debugfs.h"
35#include "debugfs_netdev.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070036
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +020037#define SUPP_MCS_SET_LEN 16
38
Johannes Bergb306f452007-07-10 19:32:08 +020039/*
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
Johannes Bergb2c258f2007-07-27 15:43:23 +020049/* common interface routines */
Jiri Bencf0706e82007-05-05 11:45:53 -070050
Stephen Hemmingerb95cce32007-09-26 22:13:38 -070051static int header_parse_80211(const struct sk_buff *skb, unsigned char *haddr)
Jiri Bencf0706e82007-05-05 11:45:53 -070052{
Johannes Bergb2c258f2007-07-27 15:43:23 +020053 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
54 return ETH_ALEN;
Jiri Bencf0706e82007-05-05 11:45:53 -070055}
56
Johannes Berg4150c572007-09-17 01:29:23 -040057/* 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
Johannes Berg53918992007-09-26 15:19:47 +020063 if (atomic_read(&local->iff_promiscs))
Johannes Berg4150c572007-09-17 01:29:23 -040064 new_flags |= FIF_PROMISC_IN_BSS;
65
Johannes Berg53918992007-09-26 15:19:47 +020066 if (atomic_read(&local->iff_allmultis))
Johannes Berg4150c572007-09-17 01:29:23 -040067 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
Johannes Bergb2c258f2007-07-27 15:43:23 +020089/* master interface */
Jiri Bencf0706e82007-05-05 11:45:53 -070090
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;
96
Johannes Berg79010422007-09-18 17:29:21 -040097 /* we hold the RTNL here so can safely walk the list */
98 list_for_each_entry(sdata, &local->interfaces, list) {
Jiri Bencf0706e82007-05-05 11:45:53 -070099 if (sdata->dev != dev && netif_running(sdata->dev)) {
100 res = 0;
101 break;
102 }
103 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700104 return res;
105}
106
107static int ieee80211_master_stop(struct net_device *dev)
108{
109 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
110 struct ieee80211_sub_if_data *sdata;
111
Johannes Berg79010422007-09-18 17:29:21 -0400112 /* we hold the RTNL here so can safely walk the list */
113 list_for_each_entry(sdata, &local->interfaces, list)
Jiri Bencf0706e82007-05-05 11:45:53 -0700114 if (sdata->dev != dev && netif_running(sdata->dev))
115 dev_close(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700116
117 return 0;
118}
119
Johannes Berg4150c572007-09-17 01:29:23 -0400120static 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
Johannes Bergb2c258f2007-07-27 15:43:23 +0200127/* regular interfaces */
128
129static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
130{
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 }
138
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;
143 return 0;
144}
145
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}
161
Johannes Bergb2c258f2007-07-27 15:43:23 +0200162static int ieee80211_open(struct net_device *dev)
163{
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;
Michael Bueschceffefd2008-02-10 14:16:52 +0100168 bool need_hw_reconfig = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200169
170 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400171
Johannes Berg79010422007-09-18 17:29:21 -0400172 /* we hold the RTNL here so can safely walk the list */
173 list_for_each_entry(nsdata, &local->interfaces, list) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200174 struct net_device *ndev = nsdata->dev;
175
176 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400177 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
178 /*
179 * check whether it may have the same address
180 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100181 if (!identical_mac_addr_allowed(sdata->vif.type,
182 nsdata->vif.type))
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400183 return -ENOTUNIQ;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400184
185 /*
186 * can only add VLANs to enabled APs
187 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100188 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
189 nsdata->vif.type == IEEE80211_IF_TYPE_AP &&
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400190 netif_running(nsdata->dev))
191 sdata->u.vlan.ap = nsdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200192 }
193 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200194
Johannes Berg51fb61e2007-12-19 01:31:27 +0100195 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400196 case IEEE80211_IF_TYPE_WDS:
197 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
198 return -ENOLINK;
199 break;
200 case IEEE80211_IF_TYPE_VLAN:
201 if (!sdata->u.vlan.ap)
202 return -ENOLINK;
203 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200204 case IEEE80211_IF_TYPE_AP:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200205 case IEEE80211_IF_TYPE_STA:
206 case IEEE80211_IF_TYPE_MNTR:
207 case IEEE80211_IF_TYPE_IBSS:
208 /* no special treatment */
209 break;
Johannes Berga2897552007-09-28 14:01:25 +0200210 case IEEE80211_IF_TYPE_INVALID:
211 /* cannot happen */
212 WARN_ON(1);
213 break;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400214 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200215
Johannes Bergb2c258f2007-07-27 15:43:23 +0200216 if (local->open_count == 0) {
217 res = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400218 if (local->ops->start)
219 res = local->ops->start(local_to_hw(local));
220 if (res)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200221 return res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100222 need_hw_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100223 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200224 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200225
Johannes Berg51fb61e2007-12-19 01:31:27 +0100226 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400227 case IEEE80211_IF_TYPE_VLAN:
228 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
229 /* no need to tell driver */
230 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400231 case IEEE80211_IF_TYPE_MNTR:
232 /* must be before the call to ieee80211_configure_filter */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200233 local->monitors++;
Johannes Berg4150c572007-09-17 01:29:23 -0400234 if (local->monitors == 1) {
235 netif_tx_lock_bh(local->mdev);
236 ieee80211_configure_filter(local);
237 netif_tx_unlock_bh(local->mdev);
238
239 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
Johannes Berg4150c572007-09-17 01:29:23 -0400240 }
241 break;
242 case IEEE80211_IF_TYPE_STA:
243 case IEEE80211_IF_TYPE_IBSS:
244 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
245 /* fall through */
246 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100247 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100248 conf.type = sdata->vif.type;
Johannes Berg4150c572007-09-17 01:29:23 -0400249 conf.mac_addr = dev->dev_addr;
250 res = local->ops->add_interface(local_to_hw(local), &conf);
251 if (res && !local->open_count && local->ops->stop)
252 local->ops->stop(local_to_hw(local));
253 if (res)
254 return res;
255
Johannes Bergb2c258f2007-07-27 15:43:23 +0200256 ieee80211_if_config(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200257 ieee80211_reset_erp_info(dev);
Johannes Berg11a843b2007-08-28 17:01:55 -0400258 ieee80211_enable_keys(sdata);
Johannes Berg4150c572007-09-17 01:29:23 -0400259
Johannes Berg51fb61e2007-12-19 01:31:27 +0100260 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200261 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
Johannes Berg4150c572007-09-17 01:29:23 -0400262 netif_carrier_off(dev);
263 else
264 netif_carrier_on(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200265 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200266
Johannes Berg4150c572007-09-17 01:29:23 -0400267 if (local->open_count == 0) {
268 res = dev_open(local->mdev);
269 WARN_ON(res);
Johannes Berg4150c572007-09-17 01:29:23 -0400270 tasklet_enable(&local->tx_pending_tasklet);
271 tasklet_enable(&local->tasklet);
272 }
273
Johannes Bergc1428b32007-11-16 02:54:53 +0100274 /*
275 * set_multicast_list will be invoked by the networking core
276 * which will check whether any increments here were done in
277 * error and sync them down to the hardware as filter flags.
278 */
279 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
280 atomic_inc(&local->iff_allmultis);
281
282 if (sdata->flags & IEEE80211_SDATA_PROMISC)
283 atomic_inc(&local->iff_promiscs);
284
Johannes Berg4150c572007-09-17 01:29:23 -0400285 local->open_count++;
Michael Bueschceffefd2008-02-10 14:16:52 +0100286 if (need_hw_reconfig)
287 ieee80211_hw_config(local);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200288
289 netif_start_queue(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400290
Johannes Bergb2c258f2007-07-27 15:43:23 +0200291 return 0;
292}
293
Johannes Berg4150c572007-09-17 01:29:23 -0400294static int ieee80211_stop(struct net_device *dev)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200295{
Johannes Berg4150c572007-09-17 01:29:23 -0400296 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200297 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg4150c572007-09-17 01:29:23 -0400298 struct ieee80211_if_init_conf conf;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200299 struct sta_info *sta;
300 int i;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200301
Johannes Berg4150c572007-09-17 01:29:23 -0400302 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
303
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200304 list_for_each_entry(sta, &local->sta_list, list) {
Ron Rindjunsky5b3d71d2008-01-13 18:21:58 +0200305 if (sta->dev == dev)
306 for (i = 0; i < STA_TID_NUM; i++)
307 ieee80211_sta_stop_rx_ba_session(sta->dev,
308 sta->addr, i,
309 WLAN_BACK_RECIPIENT,
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200310 WLAN_REASON_QSTA_LEAVE_QBSS);
311 }
312
Johannes Berg4150c572007-09-17 01:29:23 -0400313 netif_stop_queue(dev);
314
Johannes Bergc1428b32007-11-16 02:54:53 +0100315 /*
316 * Don't count this interface for promisc/allmulti while it
317 * is down. dev_mc_unsync() will invoke set_multicast_list
318 * on the master interface which will sync these down to the
319 * hardware as filter flags.
320 */
321 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
322 atomic_dec(&local->iff_allmultis);
323
324 if (sdata->flags & IEEE80211_SDATA_PROMISC)
325 atomic_dec(&local->iff_promiscs);
326
Johannes Berg4150c572007-09-17 01:29:23 -0400327 dev_mc_unsync(local->mdev, dev);
328
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100329 /* APs need special treatment */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100330 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400331 struct ieee80211_sub_if_data *vlan, *tmp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100332 struct beacon_data *old_beacon = sdata->u.ap.beacon;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400333
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100334 /* remove beacon */
335 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
336 synchronize_rcu();
337 kfree(old_beacon);
338
339 /* down all dependent devices, that is VLANs */
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400340 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
341 u.vlan.list)
342 dev_close(vlan->dev);
343 WARN_ON(!list_empty(&sdata->u.ap.vlans));
344 }
345
Johannes Berg4150c572007-09-17 01:29:23 -0400346 local->open_count--;
347
Johannes Berg51fb61e2007-12-19 01:31:27 +0100348 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400349 case IEEE80211_IF_TYPE_VLAN:
350 list_del(&sdata->u.vlan.list);
351 sdata->u.vlan.ap = NULL;
352 /* no need to tell driver */
353 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400354 case IEEE80211_IF_TYPE_MNTR:
355 local->monitors--;
356 if (local->monitors == 0) {
357 netif_tx_lock_bh(local->mdev);
358 ieee80211_configure_filter(local);
359 netif_tx_unlock_bh(local->mdev);
360
Michael Wu8b393f12007-11-28 01:57:08 -0500361 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
Johannes Berg4150c572007-09-17 01:29:23 -0400362 }
363 break;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200364 case IEEE80211_IF_TYPE_STA:
365 case IEEE80211_IF_TYPE_IBSS:
366 sdata->u.sta.state = IEEE80211_DISABLED;
367 del_timer_sync(&sdata->u.sta.timer);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400368 /*
Johannes Berg79010422007-09-18 17:29:21 -0400369 * When we get here, the interface is marked down.
370 * Call synchronize_rcu() to wait for the RX path
371 * should it be using the interface and enqueuing
372 * frames at this very time on another CPU.
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400373 */
Johannes Berg79010422007-09-18 17:29:21 -0400374 synchronize_rcu();
Johannes Bergb2c258f2007-07-27 15:43:23 +0200375 skb_queue_purge(&sdata->u.sta.skb_queue);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400376
Zhu Yiece8edd2007-11-22 10:53:21 +0800377 if (local->scan_dev == sdata->dev) {
378 if (!local->ops->hw_scan) {
379 local->sta_sw_scanning = 0;
380 cancel_delayed_work(&local->scan_work);
381 } else
382 local->sta_hw_scanning = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200383 }
Zhu Yiece8edd2007-11-22 10:53:21 +0800384
Johannes Bergb2c258f2007-07-27 15:43:23 +0200385 flush_workqueue(local->hw.workqueue);
Zhu Yia10605e2007-11-22 11:10:22 +0800386
387 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
388 kfree(sdata->u.sta.extra_ie);
389 sdata->u.sta.extra_ie = NULL;
390 sdata->u.sta.extra_ie_len = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400391 /* fall through */
392 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100393 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100394 conf.type = sdata->vif.type;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200395 conf.mac_addr = dev->dev_addr;
Johannes Berg4150c572007-09-17 01:29:23 -0400396 /* disable all keys for as long as this netdev is down */
397 ieee80211_disable_keys(sdata);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200398 local->ops->remove_interface(local_to_hw(local), &conf);
399 }
400
Johannes Berg4150c572007-09-17 01:29:23 -0400401 if (local->open_count == 0) {
402 if (netif_running(local->mdev))
403 dev_close(local->mdev);
404
Johannes Berg4150c572007-09-17 01:29:23 -0400405 if (local->ops->stop)
406 local->ops->stop(local_to_hw(local));
407
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100408 ieee80211_led_radio(local, 0);
409
Johannes Berg4150c572007-09-17 01:29:23 -0400410 tasklet_disable(&local->tx_pending_tasklet);
411 tasklet_disable(&local->tasklet);
412 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200413
414 return 0;
415}
416
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200417int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
418{
419 struct ieee80211_local *local = hw_to_local(hw);
420 struct sta_info *sta;
421 struct ieee80211_sub_if_data *sdata;
422 u16 start_seq_num = 0;
423 u8 *state;
424 int ret;
425 DECLARE_MAC_BUF(mac);
426
427 if (tid >= STA_TID_NUM)
428 return -EINVAL;
429
430#ifdef CONFIG_MAC80211_HT_DEBUG
431 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
432 print_mac(mac, ra), tid);
433#endif /* CONFIG_MAC80211_HT_DEBUG */
434
435 sta = sta_info_get(local, ra);
436 if (!sta) {
437 printk(KERN_DEBUG "Could not find the station\n");
438 return -ENOENT;
439 }
440
441 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
442
443 /* we have tried too many times, receiver does not want A-MPDU */
444 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
445 ret = -EBUSY;
446 goto start_ba_exit;
447 }
448
449 state = &sta->ampdu_mlme.tid_tx[tid].state;
450 /* check if the TID is not in aggregation flow already */
451 if (*state != HT_AGG_STATE_IDLE) {
452#ifdef CONFIG_MAC80211_HT_DEBUG
453 printk(KERN_DEBUG "BA request denied - session is not "
454 "idle on tid %u\n", tid);
455#endif /* CONFIG_MAC80211_HT_DEBUG */
456 ret = -EAGAIN;
457 goto start_ba_exit;
458 }
459
460 /* ensure that TX flow won't interrupt us
461 * until the end of the call to requeue function */
462 spin_lock_bh(&local->mdev->queue_lock);
463
464 /* create a new queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200465 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200466
467 /* case no queue is available to aggregation
468 * don't switch to aggregation */
469 if (ret) {
470#ifdef CONFIG_MAC80211_HT_DEBUG
471 printk(KERN_DEBUG "BA request denied - no queue available for"
472 " tid %d\n", tid);
473#endif /* CONFIG_MAC80211_HT_DEBUG */
474 spin_unlock_bh(&local->mdev->queue_lock);
475 goto start_ba_exit;
476 }
477 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
478
479 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
480 * call back right away, it must see that the flow has begun */
481 *state |= HT_ADDBA_REQUESTED_MSK;
482
483 if (local->ops->ampdu_action)
484 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
485 ra, tid, &start_seq_num);
486
487 if (ret) {
488 /* No need to requeue the packets in the agg queue, since we
489 * held the tx lock: no packet could be enqueued to the newly
490 * allocated queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200491 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200492#ifdef CONFIG_MAC80211_HT_DEBUG
493 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
494 " for tid %d\n", tid);
495#endif /* CONFIG_MAC80211_HT_DEBUG */
496 spin_unlock_bh(&local->mdev->queue_lock);
497 *state = HT_AGG_STATE_IDLE;
498 goto start_ba_exit;
499 }
500
501 /* Will put all the packets in the new SW queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200502 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200503 spin_unlock_bh(&local->mdev->queue_lock);
504
505 /* We have most probably almost emptied the legacy queue */
506 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
507
508 /* send an addBA request */
509 sta->ampdu_mlme.dialog_token_allocator++;
510 sta->ampdu_mlme.tid_tx[tid].dialog_token =
511 sta->ampdu_mlme.dialog_token_allocator;
512 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
513
514 ieee80211_send_addba_request(sta->dev, ra, tid,
515 sta->ampdu_mlme.tid_tx[tid].dialog_token,
516 sta->ampdu_mlme.tid_tx[tid].ssn,
517 0x40, 5000);
518
519 /* activate the timer for the recipient's addBA response */
520 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
521 jiffies + ADDBA_RESP_INTERVAL;
522 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
523 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
524
525start_ba_exit:
526 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
527 sta_info_put(sta);
528 return ret;
529}
530EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
531
532int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
533 u8 *ra, u16 tid,
534 enum ieee80211_back_parties initiator)
535{
536 struct ieee80211_local *local = hw_to_local(hw);
537 struct sta_info *sta;
538 u8 *state;
539 int ret = 0;
540 DECLARE_MAC_BUF(mac);
541
542 if (tid >= STA_TID_NUM)
543 return -EINVAL;
544
545#ifdef CONFIG_MAC80211_HT_DEBUG
546 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
547 print_mac(mac, ra), tid);
548#endif /* CONFIG_MAC80211_HT_DEBUG */
549
550 sta = sta_info_get(local, ra);
551 if (!sta)
552 return -ENOENT;
553
554 /* check if the TID is in aggregation */
555 state = &sta->ampdu_mlme.tid_tx[tid].state;
556 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
557
558 if (*state != HT_AGG_STATE_OPERATIONAL) {
559#ifdef CONFIG_MAC80211_HT_DEBUG
560 printk(KERN_DEBUG "Try to stop Tx aggregation on"
561 " non active TID\n");
562#endif /* CONFIG_MAC80211_HT_DEBUG */
563 ret = -ENOENT;
564 goto stop_BA_exit;
565 }
566
567 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
568
569 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
570 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
571
572 if (local->ops->ampdu_action)
573 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
574 ra, tid, NULL);
575
576 /* case HW denied going back to legacy */
577 if (ret) {
578 WARN_ON(ret != -EBUSY);
579 *state = HT_AGG_STATE_OPERATIONAL;
580 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
581 goto stop_BA_exit;
582 }
583
584stop_BA_exit:
585 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
586 sta_info_put(sta);
587 return ret;
588}
589EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
590
591void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
592{
593 struct ieee80211_local *local = hw_to_local(hw);
594 struct sta_info *sta;
595 u8 *state;
596 DECLARE_MAC_BUF(mac);
597
598 if (tid >= STA_TID_NUM) {
599 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
600 tid, STA_TID_NUM);
601 return;
602 }
603
604 sta = sta_info_get(local, ra);
605 if (!sta) {
606 printk(KERN_DEBUG "Could not find station: %s\n",
607 print_mac(mac, ra));
608 return;
609 }
610
611 state = &sta->ampdu_mlme.tid_tx[tid].state;
612 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
613
614 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
615 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
616 *state);
617 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
618 sta_info_put(sta);
619 return;
620 }
621
622 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
623
624 *state |= HT_ADDBA_DRV_READY_MSK;
625
626 if (*state == HT_AGG_STATE_OPERATIONAL) {
627 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
628 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
629 }
630 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
631 sta_info_put(sta);
632}
633EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
634
635void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
636{
637 struct ieee80211_local *local = hw_to_local(hw);
638 struct sta_info *sta;
639 u8 *state;
640 int agg_queue;
641 DECLARE_MAC_BUF(mac);
642
643 if (tid >= STA_TID_NUM) {
644 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
645 tid, STA_TID_NUM);
646 return;
647 }
648
649 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
650 print_mac(mac, ra), tid);
651
652 sta = sta_info_get(local, ra);
653 if (!sta) {
654 printk(KERN_DEBUG "Could not find station: %s\n",
655 print_mac(mac, ra));
656 return;
657 }
658 state = &sta->ampdu_mlme.tid_tx[tid].state;
659
660 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
661 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
662 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
663 sta_info_put(sta);
664 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
665 return;
666 }
667
668 if (*state & HT_AGG_STATE_INITIATOR_MSK)
669 ieee80211_send_delba(sta->dev, ra, tid,
670 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
671
672 agg_queue = sta->tid_to_tx_q[tid];
673
674 /* avoid ordering issues: we are the only one that can modify
675 * the content of the qdiscs */
676 spin_lock_bh(&local->mdev->queue_lock);
677 /* remove the queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200678 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200679 spin_unlock_bh(&local->mdev->queue_lock);
680
681 /* we just requeued the all the frames that were in the removed
682 * queue, and since we might miss a softirq we do netif_schedule.
683 * ieee80211_wake_queue is not used here as this queue is not
684 * necessarily stopped */
685 netif_schedule(local->mdev);
686 *state = HT_AGG_STATE_IDLE;
687 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
688 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
689
690 sta_info_put(sta);
691}
692EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
693
694void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
695 const u8 *ra, u16 tid)
696{
697 struct ieee80211_local *local = hw_to_local(hw);
698 struct ieee80211_ra_tid *ra_tid;
699 struct sk_buff *skb = dev_alloc_skb(0);
700
701 if (unlikely(!skb)) {
702 if (net_ratelimit())
703 printk(KERN_WARNING "%s: Not enough memory, "
704 "dropping start BA session", skb->dev->name);
705 return;
706 }
707 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
708 memcpy(&ra_tid->ra, ra, ETH_ALEN);
709 ra_tid->tid = tid;
710
711 skb->pkt_type = IEEE80211_ADDBA_MSG;
712 skb_queue_tail(&local->skb_queue, skb);
713 tasklet_schedule(&local->tasklet);
714}
715EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
716
717void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
718 const u8 *ra, u16 tid)
719{
720 struct ieee80211_local *local = hw_to_local(hw);
721 struct ieee80211_ra_tid *ra_tid;
722 struct sk_buff *skb = dev_alloc_skb(0);
723
724 if (unlikely(!skb)) {
725 if (net_ratelimit())
726 printk(KERN_WARNING "%s: Not enough memory, "
727 "dropping stop BA session", skb->dev->name);
728 return;
729 }
730 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
731 memcpy(&ra_tid->ra, ra, ETH_ALEN);
732 ra_tid->tid = tid;
733
734 skb->pkt_type = IEEE80211_DELBA_MSG;
735 skb_queue_tail(&local->skb_queue, skb);
736 tasklet_schedule(&local->tasklet);
737}
738EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
739
Johannes Bergb2c258f2007-07-27 15:43:23 +0200740static void ieee80211_set_multicast_list(struct net_device *dev)
741{
742 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
743 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400744 int allmulti, promisc, sdata_allmulti, sdata_promisc;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200745
Johannes Berg4150c572007-09-17 01:29:23 -0400746 allmulti = !!(dev->flags & IFF_ALLMULTI);
747 promisc = !!(dev->flags & IFF_PROMISC);
Johannes Bergb52f2192007-11-16 01:49:11 +0100748 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
749 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
Johannes Berg4150c572007-09-17 01:29:23 -0400750
751 if (allmulti != sdata_allmulti) {
752 if (dev->flags & IFF_ALLMULTI)
Johannes Berg53918992007-09-26 15:19:47 +0200753 atomic_inc(&local->iff_allmultis);
Johannes Berg4150c572007-09-17 01:29:23 -0400754 else
Johannes Berg53918992007-09-26 15:19:47 +0200755 atomic_dec(&local->iff_allmultis);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400756 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200757 }
Johannes Berg4150c572007-09-17 01:29:23 -0400758
759 if (promisc != sdata_promisc) {
760 if (dev->flags & IFF_PROMISC)
Johannes Berg53918992007-09-26 15:19:47 +0200761 atomic_inc(&local->iff_promiscs);
Johannes Berg4150c572007-09-17 01:29:23 -0400762 else
Johannes Berg53918992007-09-26 15:19:47 +0200763 atomic_dec(&local->iff_promiscs);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400764 sdata->flags ^= IEEE80211_SDATA_PROMISC;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200765 }
Johannes Berg4150c572007-09-17 01:29:23 -0400766
767 dev_mc_sync(local->mdev, dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200768}
769
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700770static const struct header_ops ieee80211_header_ops = {
771 .create = eth_header,
772 .parse = header_parse_80211,
773 .rebuild = eth_rebuild_header,
774 .cache = eth_header_cache,
775 .cache_update = eth_header_cache_update,
776};
777
Johannes Bergf9d540e2007-09-28 14:02:09 +0200778/* Must not be called for mdev */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200779void ieee80211_if_setup(struct net_device *dev)
780{
781 ether_setup(dev);
782 dev->hard_start_xmit = ieee80211_subif_start_xmit;
783 dev->wireless_handlers = &ieee80211_iw_handler_def;
784 dev->set_multicast_list = ieee80211_set_multicast_list;
785 dev->change_mtu = ieee80211_change_mtu;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200786 dev->open = ieee80211_open;
787 dev->stop = ieee80211_stop;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200788 dev->destructor = ieee80211_if_free;
789}
790
791/* WDS specialties */
792
793int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
794{
795 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
796 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
797 struct sta_info *sta;
Joe Perches0795af52007-10-03 17:59:30 -0700798 DECLARE_MAC_BUF(mac);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200799
800 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
801 return 0;
802
803 /* Create STA entry for the new peer */
804 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
805 if (!sta)
806 return -ENOMEM;
Johannes Berg238814f2008-01-28 17:19:37 +0100807
808 sta->flags |= WLAN_STA_AUTHORIZED;
809
Johannes Bergb2c258f2007-07-27 15:43:23 +0200810 sta_info_put(sta);
811
812 /* Remove STA entry for the old peer */
813 sta = sta_info_get(local, sdata->u.wds.remote_addr);
814 if (sta) {
Michael Wube8755e2007-07-27 15:43:23 +0200815 sta_info_free(sta);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200816 sta_info_put(sta);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200817 } else {
818 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
Joe Perches0795af52007-10-03 17:59:30 -0700819 "peer %s\n",
820 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
Johannes Bergb2c258f2007-07-27 15:43:23 +0200821 }
822
823 /* Update WDS link data */
824 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
825
826 return 0;
827}
828
829/* everything else */
830
Johannes Bergb2c258f2007-07-27 15:43:23 +0200831static int __ieee80211_if_config(struct net_device *dev,
832 struct sk_buff *beacon,
833 struct ieee80211_tx_control *control)
834{
835 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
836 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
837 struct ieee80211_if_conf conf;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200838
839 if (!local->ops->config_interface || !netif_running(dev))
840 return 0;
841
842 memset(&conf, 0, sizeof(conf));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100843 conf.type = sdata->vif.type;
844 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
845 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg4150c572007-09-17 01:29:23 -0400846 conf.bssid = sdata->u.sta.bssid;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200847 conf.ssid = sdata->u.sta.ssid;
848 conf.ssid_len = sdata->u.sta.ssid_len;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100849 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200850 conf.ssid = sdata->u.ap.ssid;
851 conf.ssid_len = sdata->u.ap.ssid_len;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200852 conf.beacon = beacon;
853 conf.beacon_control = control;
854 }
855 return local->ops->config_interface(local_to_hw(local),
Johannes Berg32bfd352007-12-19 01:31:26 +0100856 &sdata->vif, &conf);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200857}
858
859int ieee80211_if_config(struct net_device *dev)
860{
861 return __ieee80211_if_config(dev, NULL, NULL);
862}
863
864int ieee80211_if_config_beacon(struct net_device *dev)
865{
866 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
867 struct ieee80211_tx_control control;
Johannes Berg32bfd352007-12-19 01:31:26 +0100868 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200869 struct sk_buff *skb;
870
871 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
872 return 0;
Johannes Berg32bfd352007-12-19 01:31:26 +0100873 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
874 &control);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200875 if (!skb)
876 return -ENOMEM;
877 return __ieee80211_if_config(dev, skb, &control);
878}
879
880int ieee80211_hw_config(struct ieee80211_local *local)
881{
Johannes Bergb2c258f2007-07-27 15:43:23 +0200882 struct ieee80211_channel *chan;
883 int ret = 0;
884
Johannes Berg8318d782008-01-24 19:38:38 +0100885 if (local->sta_sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200886 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +0100887 else
Johannes Bergb2c258f2007-07-27 15:43:23 +0200888 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200889
Johannes Berg8318d782008-01-24 19:38:38 +0100890 local->hw.conf.channel = chan;
891
892 if (!local->hw.conf.power_level)
893 local->hw.conf.power_level = chan->max_power;
894 else
895 local->hw.conf.power_level = min(chan->max_power,
896 local->hw.conf.power_level);
897
898 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200899
900#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg8318d782008-01-24 19:38:38 +0100901 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
902 wiphy_name(local->hw.wiphy), chan->center_freq);
903#endif
Johannes Bergb2c258f2007-07-27 15:43:23 +0200904
Michael Bueschf7c4dae2007-09-24 18:41:49 +0200905 if (local->open_count)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200906 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
907
908 return ret;
909}
910
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200911/**
912 * ieee80211_hw_config_ht should be used only after legacy configuration
913 * has been determined, as ht configuration depends upon the hardware's
914 * HT abilities for a _specific_ band.
915 */
916int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
917 struct ieee80211_ht_info *req_ht_cap,
918 struct ieee80211_ht_bss_info *req_bss_cap)
919{
920 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg8318d782008-01-24 19:38:38 +0100921 struct ieee80211_supported_band *sband;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200922 int i;
923
Johannes Berg8318d782008-01-24 19:38:38 +0100924 sband = local->hw.wiphy->bands[conf->channel->band];
925
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200926 /* HT is not supported */
Johannes Berg8318d782008-01-24 19:38:38 +0100927 if (!sband->ht_info.ht_supported) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200928 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
929 return -EOPNOTSUPP;
930 }
931
932 /* disable HT */
933 if (!enable_ht) {
934 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
935 } else {
936 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
Johannes Berg8318d782008-01-24 19:38:38 +0100937 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200938 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
939 conf->ht_conf.cap |=
Johannes Berg8318d782008-01-24 19:38:38 +0100940 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200941 conf->ht_bss_conf.primary_channel =
942 req_bss_cap->primary_channel;
943 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
944 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
945 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
946 conf->ht_conf.supp_mcs_set[i] =
Johannes Berg8318d782008-01-24 19:38:38 +0100947 sband->ht_info.supp_mcs_set[i] &
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200948 req_ht_cap->supp_mcs_set[i];
949
950 /* In STA mode, this gives us indication
951 * to the AP's mode of operation */
952 conf->ht_conf.ht_supported = 1;
953 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
954 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
955 }
956
957 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
958
959 return 0;
960}
961
Johannes Berg471b3ef2007-12-28 14:32:58 +0100962void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
963 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +0200964{
Johannes Berg471b3ef2007-12-28 14:32:58 +0100965 struct ieee80211_local *local = sdata->local;
966
967 if (!changed)
968 return;
969
970 if (local->ops->bss_info_changed)
971 local->ops->bss_info_changed(local_to_hw(local),
972 &sdata->vif,
973 &sdata->bss_conf,
974 changed);
Daniel Draked9430a32007-07-27 15:43:24 +0200975}
976
977void ieee80211_reset_erp_info(struct net_device *dev)
978{
979 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
980
Johannes Berg471b3ef2007-12-28 14:32:58 +0100981 sdata->bss_conf.use_cts_prot = 0;
982 sdata->bss_conf.use_short_preamble = 0;
983 ieee80211_bss_info_change_notify(sdata,
984 BSS_CHANGED_ERP_CTS_PROT |
985 BSS_CHANGED_ERP_PREAMBLE);
Daniel Draked9430a32007-07-27 15:43:24 +0200986}
987
Jiri Bencf0706e82007-05-05 11:45:53 -0700988void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
989 struct sk_buff *skb,
990 struct ieee80211_tx_status *status)
991{
992 struct ieee80211_local *local = hw_to_local(hw);
993 struct ieee80211_tx_status *saved;
994 int tmp;
995
996 skb->dev = local->mdev;
997 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
998 if (unlikely(!saved)) {
999 if (net_ratelimit())
1000 printk(KERN_WARNING "%s: Not enough memory, "
1001 "dropping tx status", skb->dev->name);
1002 /* should be dev_kfree_skb_irq, but due to this function being
1003 * named _irqsafe instead of just _irq we can't be sure that
1004 * people won't call it from non-irq contexts */
1005 dev_kfree_skb_any(skb);
1006 return;
1007 }
1008 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1009 /* copy pointer to saved status into skb->cb for use by tasklet */
1010 memcpy(skb->cb, &saved, sizeof(saved));
1011
1012 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1013 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1014 &local->skb_queue : &local->skb_queue_unreliable, skb);
1015 tmp = skb_queue_len(&local->skb_queue) +
1016 skb_queue_len(&local->skb_queue_unreliable);
1017 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1018 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1019 memcpy(&saved, skb->cb, sizeof(saved));
1020 kfree(saved);
1021 dev_kfree_skb_irq(skb);
1022 tmp--;
1023 I802_DEBUG_INC(local->tx_status_drop);
1024 }
1025 tasklet_schedule(&local->tasklet);
1026}
1027EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1028
1029static void ieee80211_tasklet_handler(unsigned long data)
1030{
1031 struct ieee80211_local *local = (struct ieee80211_local *) data;
1032 struct sk_buff *skb;
1033 struct ieee80211_rx_status rx_status;
1034 struct ieee80211_tx_status *tx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001035 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001036
1037 while ((skb = skb_dequeue(&local->skb_queue)) ||
1038 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1039 switch (skb->pkt_type) {
1040 case IEEE80211_RX_MSG:
1041 /* status is in skb->cb */
1042 memcpy(&rx_status, skb->cb, sizeof(rx_status));
Johannes Berg51fb61e2007-12-19 01:31:27 +01001043 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -07001044 * netstack. */
1045 skb->pkt_type = 0;
1046 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1047 break;
1048 case IEEE80211_TX_STATUS_MSG:
1049 /* get pointer to saved status out of skb->cb */
1050 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1051 skb->pkt_type = 0;
1052 ieee80211_tx_status(local_to_hw(local),
1053 skb, tx_status);
1054 kfree(tx_status);
1055 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001056 case IEEE80211_DELBA_MSG:
1057 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1058 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1059 ra_tid->ra, ra_tid->tid);
1060 dev_kfree_skb(skb);
1061 break;
1062 case IEEE80211_ADDBA_MSG:
1063 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1064 ieee80211_start_tx_ba_cb(local_to_hw(local),
1065 ra_tid->ra, ra_tid->tid);
1066 dev_kfree_skb(skb);
1067 break ;
Jiri Bencf0706e82007-05-05 11:45:53 -07001068 default: /* should never get here! */
1069 printk(KERN_ERR "%s: Unknown message type (%d)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001070 wiphy_name(local->hw.wiphy), skb->pkt_type);
Jiri Bencf0706e82007-05-05 11:45:53 -07001071 dev_kfree_skb(skb);
1072 break;
1073 }
1074 }
1075}
1076
Jiri Bencf0706e82007-05-05 11:45:53 -07001077/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1078 * make a prepared TX frame (one that has been given to hw) to look like brand
1079 * new IEEE 802.11 frame that is ready to go through TX processing again.
1080 * Also, tx_packet_data in cb is restored from tx_control. */
1081static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1082 struct ieee80211_key *key,
1083 struct sk_buff *skb,
1084 struct ieee80211_tx_control *control)
1085{
1086 int hdrlen, iv_len, mic_len;
1087 struct ieee80211_tx_packet_data *pkt_data;
1088
1089 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
Johannes Berg32bfd352007-12-19 01:31:26 +01001090 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001091 pkt_data->flags = 0;
1092 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1093 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1094 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1095 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1096 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1097 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg678f5f712007-12-19 01:31:23 +01001098 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1099 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
Jiri Bencf0706e82007-05-05 11:45:53 -07001100 pkt_data->queue = control->queue;
1101
1102 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1103
1104 if (!key)
1105 goto no_key;
1106
Johannes Berg8f20fc22007-08-28 17:01:54 -04001107 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001108 case ALG_WEP:
1109 iv_len = WEP_IV_LEN;
1110 mic_len = WEP_ICV_LEN;
1111 break;
1112 case ALG_TKIP:
1113 iv_len = TKIP_IV_LEN;
1114 mic_len = TKIP_ICV_LEN;
1115 break;
1116 case ALG_CCMP:
1117 iv_len = CCMP_HDR_LEN;
1118 mic_len = CCMP_MIC_LEN;
1119 break;
1120 default:
1121 goto no_key;
1122 }
1123
Johannes Berg8f20fc22007-08-28 17:01:54 -04001124 if (skb->len >= mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -04001125 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 skb_trim(skb, skb->len - mic_len);
1127 if (skb->len >= iv_len && skb->len > hdrlen) {
1128 memmove(skb->data + iv_len, skb->data, hdrlen);
1129 skb_pull(skb, iv_len);
1130 }
1131
1132no_key:
1133 {
1134 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1135 u16 fc = le16_to_cpu(hdr->frame_control);
1136 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1137 fc &= ~IEEE80211_STYPE_QOS_DATA;
1138 hdr->frame_control = cpu_to_le16(fc);
1139 memmove(skb->data + 2, skb->data, hdrlen - 2);
1140 skb_pull(skb, 2);
1141 }
1142 }
1143}
1144
Jiri Bencf0706e82007-05-05 11:45:53 -07001145void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1146 struct ieee80211_tx_status *status)
1147{
1148 struct sk_buff *skb2;
1149 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1150 struct ieee80211_local *local = hw_to_local(hw);
1151 u16 frag, type;
Johannes Bergb306f452007-07-10 19:32:08 +02001152 struct ieee80211_tx_status_rtap_hdr *rthdr;
1153 struct ieee80211_sub_if_data *sdata;
1154 int monitors;
Jiri Bencf0706e82007-05-05 11:45:53 -07001155
1156 if (!status) {
1157 printk(KERN_ERR
1158 "%s: ieee80211_tx_status called with NULL status\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001159 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001160 dev_kfree_skb(skb);
1161 return;
1162 }
1163
1164 if (status->excessive_retries) {
1165 struct sta_info *sta;
1166 sta = sta_info_get(local, hdr->addr1);
1167 if (sta) {
1168 if (sta->flags & WLAN_STA_PS) {
1169 /* The STA is in power save mode, so assume
1170 * that this TX packet failed because of that.
1171 */
1172 status->excessive_retries = 0;
1173 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
1174 }
1175 sta_info_put(sta);
1176 }
1177 }
1178
1179 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1180 struct sta_info *sta;
1181 sta = sta_info_get(local, hdr->addr1);
1182 if (sta) {
1183 sta->tx_filtered_count++;
1184
1185 /* Clear the TX filter mask for this STA when sending
1186 * the next packet. If the STA went to power save mode,
1187 * this will happen when it is waking up for the next
1188 * time. */
1189 sta->clear_dst_mask = 1;
1190
1191 /* TODO: Is the WLAN_STA_PS flag always set here or is
1192 * the race between RX and TX status causing some
1193 * packets to be filtered out before 80211.o gets an
1194 * update for PS status? This seems to be the case, so
1195 * no changes are likely to be needed. */
1196 if (sta->flags & WLAN_STA_PS &&
1197 skb_queue_len(&sta->tx_filtered) <
1198 STA_MAX_TX_BUFFER) {
1199 ieee80211_remove_tx_extra(local, sta->key,
1200 skb,
1201 &status->control);
1202 skb_queue_tail(&sta->tx_filtered, skb);
1203 } else if (!(sta->flags & WLAN_STA_PS) &&
1204 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1205 /* Software retry the packet once */
1206 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1207 ieee80211_remove_tx_extra(local, sta->key,
1208 skb,
1209 &status->control);
1210 dev_queue_xmit(skb);
1211 } else {
1212 if (net_ratelimit()) {
1213 printk(KERN_DEBUG "%s: dropped TX "
1214 "filtered frame queue_len=%d "
1215 "PS=%d @%lu\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001216 wiphy_name(local->hw.wiphy),
Jiri Bencf0706e82007-05-05 11:45:53 -07001217 skb_queue_len(
1218 &sta->tx_filtered),
1219 !!(sta->flags & WLAN_STA_PS),
1220 jiffies);
1221 }
1222 dev_kfree_skb(skb);
1223 }
1224 sta_info_put(sta);
1225 return;
1226 }
Mattias Nissler1abbe492007-12-20 13:50:07 +01001227 } else
1228 rate_control_tx_status(local->mdev, skb, status);
Jiri Bencf0706e82007-05-05 11:45:53 -07001229
1230 ieee80211_led_tx(local, 0);
1231
1232 /* SNMP counters
1233 * Fragments are passed to low-level drivers as separate skbs, so these
1234 * are actually fragments, not frames. Update frame counters only for
1235 * the first fragment of the frame. */
1236
1237 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1238 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1239
1240 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1241 if (frag == 0) {
1242 local->dot11TransmittedFrameCount++;
1243 if (is_multicast_ether_addr(hdr->addr1))
1244 local->dot11MulticastTransmittedFrameCount++;
1245 if (status->retry_count > 0)
1246 local->dot11RetryCount++;
1247 if (status->retry_count > 1)
1248 local->dot11MultipleRetryCount++;
1249 }
1250
1251 /* This counter shall be incremented for an acknowledged MPDU
1252 * with an individual address in the address 1 field or an MPDU
1253 * with a multicast address in the address 1 field of type Data
1254 * or Management. */
1255 if (!is_multicast_ether_addr(hdr->addr1) ||
1256 type == IEEE80211_FTYPE_DATA ||
1257 type == IEEE80211_FTYPE_MGMT)
1258 local->dot11TransmittedFragmentCount++;
1259 } else {
1260 if (frag == 0)
1261 local->dot11FailedCount++;
1262 }
1263
Johannes Bergb306f452007-07-10 19:32:08 +02001264 /* this was a transmitted frame, but now we want to reuse it */
1265 skb_orphan(skb);
1266
Johannes Bergb306f452007-07-10 19:32:08 +02001267 if (!local->monitors) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001268 dev_kfree_skb(skb);
1269 return;
1270 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001271
Johannes Bergb306f452007-07-10 19:32:08 +02001272 /* send frame to monitor interfaces now */
1273
1274 if (skb_headroom(skb) < sizeof(*rthdr)) {
1275 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1276 dev_kfree_skb(skb);
1277 return;
1278 }
1279
1280 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1281 skb_push(skb, sizeof(*rthdr));
1282
1283 memset(rthdr, 0, sizeof(*rthdr));
1284 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1285 rthdr->hdr.it_present =
1286 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1287 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1288
1289 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1290 !is_multicast_ether_addr(hdr->addr1))
1291 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1292
1293 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1294 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1295 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1296 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1297 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1298
1299 rthdr->data_retries = status->retry_count;
1300
Johannes Berg79010422007-09-18 17:29:21 -04001301 rcu_read_lock();
Johannes Bergb306f452007-07-10 19:32:08 +02001302 monitors = local->monitors;
Johannes Berg79010422007-09-18 17:29:21 -04001303 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Bergb306f452007-07-10 19:32:08 +02001304 /*
1305 * Using the monitors counter is possibly racy, but
1306 * if the value is wrong we simply either clone the skb
1307 * once too much or forget sending it to one monitor iface
1308 * The latter case isn't nice but fixing the race is much
1309 * more complicated.
1310 */
1311 if (!monitors || !skb)
1312 goto out;
1313
Johannes Berg51fb61e2007-12-19 01:31:27 +01001314 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
Johannes Bergb306f452007-07-10 19:32:08 +02001315 if (!netif_running(sdata->dev))
1316 continue;
1317 monitors--;
1318 if (monitors)
Johannes Berg79010422007-09-18 17:29:21 -04001319 skb2 = skb_clone(skb, GFP_ATOMIC);
Johannes Bergb306f452007-07-10 19:32:08 +02001320 else
1321 skb2 = NULL;
1322 skb->dev = sdata->dev;
1323 /* XXX: is this sufficient for BPF? */
1324 skb_set_mac_header(skb, 0);
1325 skb->ip_summed = CHECKSUM_UNNECESSARY;
1326 skb->pkt_type = PACKET_OTHERHOST;
1327 skb->protocol = htons(ETH_P_802_2);
1328 memset(skb->cb, 0, sizeof(skb->cb));
1329 netif_rx(skb);
1330 skb = skb2;
Johannes Bergb306f452007-07-10 19:32:08 +02001331 }
1332 }
1333 out:
Johannes Berg79010422007-09-18 17:29:21 -04001334 rcu_read_unlock();
Johannes Bergb306f452007-07-10 19:32:08 +02001335 if (skb)
1336 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -07001337}
1338EXPORT_SYMBOL(ieee80211_tx_status);
1339
Jiri Bencf0706e82007-05-05 11:45:53 -07001340struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1341 const struct ieee80211_ops *ops)
1342{
1343 struct net_device *mdev;
1344 struct ieee80211_local *local;
1345 struct ieee80211_sub_if_data *sdata;
1346 int priv_size;
1347 struct wiphy *wiphy;
1348
1349 /* Ensure 32-byte alignment of our private data and hw private data.
1350 * We use the wiphy priv data for both our ieee80211_local and for
1351 * the driver's private data
1352 *
1353 * In memory it'll be like this:
1354 *
1355 * +-------------------------+
1356 * | struct wiphy |
1357 * +-------------------------+
1358 * | struct ieee80211_local |
1359 * +-------------------------+
1360 * | driver's private data |
1361 * +-------------------------+
1362 *
1363 */
1364 priv_size = ((sizeof(struct ieee80211_local) +
1365 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1366 priv_data_len;
1367
1368 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1369
1370 if (!wiphy)
1371 return NULL;
1372
1373 wiphy->privid = mac80211_wiphy_privid;
1374
1375 local = wiphy_priv(wiphy);
1376 local->hw.wiphy = wiphy;
1377
1378 local->hw.priv = (char *)local +
1379 ((sizeof(struct ieee80211_local) +
1380 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1381
Johannes Berg4480f15c2007-07-10 19:32:10 +02001382 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -04001383 BUG_ON(!ops->start);
1384 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +02001385 BUG_ON(!ops->config);
1386 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -04001387 BUG_ON(!ops->remove_interface);
1388 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -07001389 local->ops = ops;
1390
1391 /* for now, mdev needs sub_if_data :/ */
1392 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1393 "wmaster%d", ether_setup);
1394 if (!mdev) {
1395 wiphy_free(wiphy);
1396 return NULL;
1397 }
1398
1399 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1400 mdev->ieee80211_ptr = &sdata->wdev;
1401 sdata->wdev.wiphy = wiphy;
1402
1403 local->hw.queues = 1; /* default */
1404
1405 local->mdev = mdev;
Jiri Bencf0706e82007-05-05 11:45:53 -07001406 local->rx_handlers = ieee80211_rx_handlers;
1407 local->tx_handlers = ieee80211_tx_handlers;
1408
1409 local->bridge_packets = 1;
1410
1411 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1412 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1413 local->short_retry_limit = 7;
1414 local->long_retry_limit = 4;
1415 local->hw.conf.radio_enabled = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001416
Johannes Berg79010422007-09-18 17:29:21 -04001417 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -07001418
1419 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001420 ieee80211_rx_bss_list_init(mdev);
1421
1422 sta_info_init(local);
1423
1424 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1425 mdev->open = ieee80211_master_open;
1426 mdev->stop = ieee80211_master_stop;
1427 mdev->type = ARPHRD_IEEE80211;
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -07001428 mdev->header_ops = &ieee80211_header_ops;
Johannes Berg4150c572007-09-17 01:29:23 -04001429 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
Jiri Bencf0706e82007-05-05 11:45:53 -07001430
Johannes Berg51fb61e2007-12-19 01:31:27 +01001431 sdata->vif.type = IEEE80211_IF_TYPE_AP;
Jiri Bencf0706e82007-05-05 11:45:53 -07001432 sdata->dev = mdev;
1433 sdata->local = local;
1434 sdata->u.ap.force_unicast_rateidx = -1;
1435 sdata->u.ap.max_ratectrl_rateidx = -1;
1436 ieee80211_if_sdata_init(sdata);
Johannes Berg79010422007-09-18 17:29:21 -04001437 /* no RCU needed since we're still during init phase */
1438 list_add_tail(&sdata->list, &local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -07001439
1440 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1441 (unsigned long)local);
1442 tasklet_disable(&local->tx_pending_tasklet);
1443
1444 tasklet_init(&local->tasklet,
1445 ieee80211_tasklet_handler,
1446 (unsigned long) local);
1447 tasklet_disable(&local->tasklet);
1448
1449 skb_queue_head_init(&local->skb_queue);
1450 skb_queue_head_init(&local->skb_queue_unreliable);
1451
1452 return local_to_hw(local);
1453}
1454EXPORT_SYMBOL(ieee80211_alloc_hw);
1455
1456int ieee80211_register_hw(struct ieee80211_hw *hw)
1457{
1458 struct ieee80211_local *local = hw_to_local(hw);
1459 const char *name;
1460 int result;
Johannes Berg8318d782008-01-24 19:38:38 +01001461 enum ieee80211_band band;
1462
1463 /*
1464 * generic code guarantees at least one band,
1465 * set this very early because much code assumes
1466 * that hw.conf.channel is assigned
1467 */
1468 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1469 struct ieee80211_supported_band *sband;
1470
1471 sband = local->hw.wiphy->bands[band];
1472 if (sband) {
1473 /* init channel we're on */
1474 local->hw.conf.channel =
1475 local->oper_channel =
1476 local->scan_channel = &sband->channels[0];
1477 break;
1478 }
1479 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001480
1481 result = wiphy_register(local->hw.wiphy);
1482 if (result < 0)
1483 return result;
1484
1485 name = wiphy_dev(local->hw.wiphy)->driver->name;
1486 local->hw.workqueue = create_singlethread_workqueue(name);
1487 if (!local->hw.workqueue) {
1488 result = -ENOMEM;
1489 goto fail_workqueue;
1490 }
1491
Johannes Bergb306f452007-07-10 19:32:08 +02001492 /*
1493 * The hardware needs headroom for sending the frame,
1494 * and we need some headroom for passing the frame to monitor
1495 * interfaces, but never both at the same time.
1496 */
Jiri Benc33ccad32007-07-18 17:10:44 +02001497 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1498 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +02001499
Jiri Bence9f207f2007-05-05 11:46:38 -07001500 debugfs_hw_add(local);
1501
Jiri Bencf0706e82007-05-05 11:45:53 -07001502 local->hw.conf.beacon_int = 1000;
1503
1504 local->wstats_flags |= local->hw.max_rssi ?
1505 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1506 local->wstats_flags |= local->hw.max_signal ?
1507 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1508 local->wstats_flags |= local->hw.max_noise ?
1509 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1510 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1511 local->wstats_flags |= IW_QUAL_DBM;
1512
1513 result = sta_info_start(local);
1514 if (result < 0)
1515 goto fail_sta_info;
1516
1517 rtnl_lock();
1518 result = dev_alloc_name(local->mdev, local->mdev->name);
1519 if (result < 0)
1520 goto fail_dev;
1521
1522 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1523 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1524
1525 result = register_netdevice(local->mdev);
1526 if (result < 0)
1527 goto fail_dev;
1528
Jiri Bence9f207f2007-05-05 11:46:38 -07001529 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Johannes Berg5b2812e2007-09-26 14:27:23 +02001530 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
Jiri Bence9f207f2007-05-05 11:46:38 -07001531
Johannes Berg830f9032007-10-28 14:51:05 +01001532 result = ieee80211_init_rate_ctrl_alg(local,
1533 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -07001534 if (result < 0) {
1535 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001536 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001537 goto fail_rate;
1538 }
1539
1540 result = ieee80211_wep_init(local);
1541
1542 if (result < 0) {
1543 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001544 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001545 goto fail_wep;
1546 }
1547
1548 ieee80211_install_qdisc(local->mdev);
1549
1550 /* add one default STA interface */
1551 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1552 IEEE80211_IF_TYPE_STA);
1553 if (result)
1554 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001555 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001556
1557 local->reg_state = IEEE80211_DEV_REGISTERED;
1558 rtnl_unlock();
1559
1560 ieee80211_led_init(local);
1561
1562 return 0;
1563
1564fail_wep:
1565 rate_control_deinitialize(local);
1566fail_rate:
Jiri Bence9f207f2007-05-05 11:46:38 -07001567 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001568 unregister_netdevice(local->mdev);
1569fail_dev:
1570 rtnl_unlock();
1571 sta_info_stop(local);
1572fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -07001573 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001574 destroy_workqueue(local->hw.workqueue);
1575fail_workqueue:
1576 wiphy_unregister(local->hw.wiphy);
1577 return result;
1578}
1579EXPORT_SYMBOL(ieee80211_register_hw);
1580
Jiri Bencf0706e82007-05-05 11:45:53 -07001581void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1582{
1583 struct ieee80211_local *local = hw_to_local(hw);
1584 struct ieee80211_sub_if_data *sdata, *tmp;
Jiri Bencf0706e82007-05-05 11:45:53 -07001585
1586 tasklet_kill(&local->tx_pending_tasklet);
1587 tasklet_kill(&local->tasklet);
1588
1589 rtnl_lock();
1590
1591 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1592
1593 local->reg_state = IEEE80211_DEV_UNREGISTERED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001594
Johannes Berg79010422007-09-18 17:29:21 -04001595 /*
1596 * At this point, interface list manipulations are fine
1597 * because the driver cannot be handing us frames any
1598 * more and the tasklet is killed.
1599 */
Johannes Berg5b2812e2007-09-26 14:27:23 +02001600
1601 /*
1602 * First, we remove all non-master interfaces. Do this because they
1603 * may have bss pointer dependency on the master, and when we free
1604 * the master these would be freed as well, breaking our list
1605 * iteration completely.
1606 */
1607 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1608 if (sdata->dev == local->mdev)
1609 continue;
1610 list_del(&sdata->list);
Jiri Bencf0706e82007-05-05 11:45:53 -07001611 __ieee80211_if_del(local, sdata);
Johannes Berg5b2812e2007-09-26 14:27:23 +02001612 }
1613
1614 /* then, finally, remove the master interface */
1615 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001616
1617 rtnl_unlock();
1618
Jiri Bencf0706e82007-05-05 11:45:53 -07001619 ieee80211_rx_bss_list_deinit(local->mdev);
1620 ieee80211_clear_tx_pending(local);
1621 sta_info_stop(local);
1622 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -07001623 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001624
Jiri Bencf0706e82007-05-05 11:45:53 -07001625 if (skb_queue_len(&local->skb_queue)
1626 || skb_queue_len(&local->skb_queue_unreliable))
1627 printk(KERN_WARNING "%s: skb_queue not empty\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001628 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001629 skb_queue_purge(&local->skb_queue);
1630 skb_queue_purge(&local->skb_queue_unreliable);
1631
1632 destroy_workqueue(local->hw.workqueue);
1633 wiphy_unregister(local->hw.wiphy);
1634 ieee80211_wep_free(local);
1635 ieee80211_led_exit(local);
1636}
1637EXPORT_SYMBOL(ieee80211_unregister_hw);
1638
1639void ieee80211_free_hw(struct ieee80211_hw *hw)
1640{
1641 struct ieee80211_local *local = hw_to_local(hw);
1642
1643 ieee80211_if_free(local->mdev);
1644 wiphy_free(local->hw.wiphy);
1645}
1646EXPORT_SYMBOL(ieee80211_free_hw);
1647
Jiri Bencf0706e82007-05-05 11:45:53 -07001648static int __init ieee80211_init(void)
1649{
1650 struct sk_buff *skb;
1651 int ret;
1652
1653 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1654
Johannes Berg4b475892008-01-02 15:17:03 +01001655 ret = rc80211_simple_init();
Johannes Bergac71c692007-10-28 14:17:44 +01001656 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001657 goto out;
Mattias Nisslerad018372007-12-19 01:25:57 +01001658
Johannes Berg4b475892008-01-02 15:17:03 +01001659 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +01001660 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001661 goto out_cleanup_simple;
Johannes Bergac71c692007-10-28 14:17:44 +01001662
Jiri Bencf0706e82007-05-05 11:45:53 -07001663 ret = ieee80211_wme_register();
1664 if (ret) {
1665 printk(KERN_DEBUG "ieee80211_init: failed to "
1666 "initialize WME (err=%d)\n", ret);
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001667 goto out_cleanup_pid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001668 }
1669
Jiri Bence9f207f2007-05-05 11:46:38 -07001670 ieee80211_debugfs_netdev_init();
1671
Jiri Bencf0706e82007-05-05 11:45:53 -07001672 return 0;
Mattias Nisslerad018372007-12-19 01:25:57 +01001673
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001674 out_cleanup_pid:
Johannes Berg4b475892008-01-02 15:17:03 +01001675 rc80211_pid_exit();
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001676 out_cleanup_simple:
1677 rc80211_simple_exit();
1678 out:
Mattias Nisslerad018372007-12-19 01:25:57 +01001679 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07001680}
1681
Jiri Bencf0706e82007-05-05 11:45:53 -07001682static void __exit ieee80211_exit(void)
1683{
Johannes Berg4b475892008-01-02 15:17:03 +01001684 rc80211_simple_exit();
1685 rc80211_pid_exit();
Johannes Bergac71c692007-10-28 14:17:44 +01001686
Jiri Bencf0706e82007-05-05 11:45:53 -07001687 ieee80211_wme_unregister();
Jiri Bence9f207f2007-05-05 11:46:38 -07001688 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -07001689}
1690
1691
Johannes Bergca9938f2007-09-11 12:50:32 +02001692subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -07001693module_exit(ieee80211_exit);
1694
1695MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1696MODULE_LICENSE("GPL");