blob: a00858dbab187c36ebcd117b17980cc652e390fb [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)
Michael Wu8cc9a732008-01-31 19:48:23 +010070 new_flags |= FIF_BCN_PRBRESP_PROMISC;
71
72 if (local->fif_fcsfail)
73 new_flags |= FIF_FCSFAIL;
74
75 if (local->fif_plcpfail)
76 new_flags |= FIF_PLCPFAIL;
77
78 if (local->fif_control)
79 new_flags |= FIF_CONTROL;
80
81 if (local->fif_other_bss)
82 new_flags |= FIF_OTHER_BSS;
Johannes Berg4150c572007-09-17 01:29:23 -040083
84 changed_flags = local->filter_flags ^ new_flags;
85
86 /* be a bit nasty */
87 new_flags |= (1<<31);
88
89 local->ops->configure_filter(local_to_hw(local),
90 changed_flags, &new_flags,
91 local->mdev->mc_count,
92 local->mdev->mc_list);
93
94 WARN_ON(new_flags & (1<<31));
95
96 local->filter_flags = new_flags & ~(1<<31);
97}
98
Johannes Bergb2c258f2007-07-27 15:43:23 +020099/* master interface */
Jiri Bencf0706e82007-05-05 11:45:53 -0700100
101static int ieee80211_master_open(struct net_device *dev)
102{
103 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
104 struct ieee80211_sub_if_data *sdata;
105 int res = -EOPNOTSUPP;
106
Johannes Berg79010422007-09-18 17:29:21 -0400107 /* we hold the RTNL here so can safely walk the list */
108 list_for_each_entry(sdata, &local->interfaces, list) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700109 if (sdata->dev != dev && netif_running(sdata->dev)) {
110 res = 0;
111 break;
112 }
113 }
Jiri Bencf0706e82007-05-05 11:45:53 -0700114 return res;
115}
116
117static int ieee80211_master_stop(struct net_device *dev)
118{
119 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
120 struct ieee80211_sub_if_data *sdata;
121
Johannes Berg79010422007-09-18 17:29:21 -0400122 /* we hold the RTNL here so can safely walk the list */
123 list_for_each_entry(sdata, &local->interfaces, list)
Jiri Bencf0706e82007-05-05 11:45:53 -0700124 if (sdata->dev != dev && netif_running(sdata->dev))
125 dev_close(sdata->dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700126
127 return 0;
128}
129
Johannes Berg4150c572007-09-17 01:29:23 -0400130static void ieee80211_master_set_multicast_list(struct net_device *dev)
131{
132 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
133
134 ieee80211_configure_filter(local);
135}
136
Johannes Bergb2c258f2007-07-27 15:43:23 +0200137/* regular interfaces */
138
139static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
140{
141 /* FIX: what would be proper limits for MTU?
142 * This interface uses 802.3 frames. */
143 if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
144 printk(KERN_WARNING "%s: invalid MTU %d\n",
145 dev->name, new_mtu);
146 return -EINVAL;
147 }
148
149#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
150 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
151#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
152 dev->mtu = new_mtu;
153 return 0;
154}
155
156static inline int identical_mac_addr_allowed(int type1, int type2)
157{
158 return (type1 == IEEE80211_IF_TYPE_MNTR ||
159 type2 == IEEE80211_IF_TYPE_MNTR ||
160 (type1 == IEEE80211_IF_TYPE_AP &&
161 type2 == IEEE80211_IF_TYPE_WDS) ||
162 (type1 == IEEE80211_IF_TYPE_WDS &&
163 (type2 == IEEE80211_IF_TYPE_WDS ||
164 type2 == IEEE80211_IF_TYPE_AP)) ||
165 (type1 == IEEE80211_IF_TYPE_AP &&
166 type2 == IEEE80211_IF_TYPE_VLAN) ||
167 (type1 == IEEE80211_IF_TYPE_VLAN &&
168 (type2 == IEEE80211_IF_TYPE_AP ||
169 type2 == IEEE80211_IF_TYPE_VLAN)));
170}
171
Johannes Bergb2c258f2007-07-27 15:43:23 +0200172static int ieee80211_open(struct net_device *dev)
173{
174 struct ieee80211_sub_if_data *sdata, *nsdata;
175 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
176 struct ieee80211_if_init_conf conf;
177 int res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100178 bool need_hw_reconfig = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200179
180 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400181
Johannes Berg79010422007-09-18 17:29:21 -0400182 /* we hold the RTNL here so can safely walk the list */
183 list_for_each_entry(nsdata, &local->interfaces, list) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200184 struct net_device *ndev = nsdata->dev;
185
186 if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400187 compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0) {
188 /*
189 * check whether it may have the same address
190 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100191 if (!identical_mac_addr_allowed(sdata->vif.type,
192 nsdata->vif.type))
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400193 return -ENOTUNIQ;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400194
195 /*
196 * can only add VLANs to enabled APs
197 */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100198 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN &&
199 nsdata->vif.type == IEEE80211_IF_TYPE_AP &&
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400200 netif_running(nsdata->dev))
201 sdata->u.vlan.ap = nsdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200202 }
203 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200204
Johannes Berg51fb61e2007-12-19 01:31:27 +0100205 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400206 case IEEE80211_IF_TYPE_WDS:
207 if (is_zero_ether_addr(sdata->u.wds.remote_addr))
208 return -ENOLINK;
209 break;
210 case IEEE80211_IF_TYPE_VLAN:
211 if (!sdata->u.vlan.ap)
212 return -ENOLINK;
213 break;
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200214 case IEEE80211_IF_TYPE_AP:
Johannes Bergfb1c1cd2007-09-26 15:19:43 +0200215 case IEEE80211_IF_TYPE_STA:
216 case IEEE80211_IF_TYPE_MNTR:
217 case IEEE80211_IF_TYPE_IBSS:
218 /* no special treatment */
219 break;
Johannes Berga2897552007-09-28 14:01:25 +0200220 case IEEE80211_IF_TYPE_INVALID:
221 /* cannot happen */
222 WARN_ON(1);
223 break;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400224 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200225
Johannes Bergb2c258f2007-07-27 15:43:23 +0200226 if (local->open_count == 0) {
227 res = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400228 if (local->ops->start)
229 res = local->ops->start(local_to_hw(local));
230 if (res)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200231 return res;
Michael Bueschceffefd2008-02-10 14:16:52 +0100232 need_hw_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100233 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200234 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200235
Johannes Berg51fb61e2007-12-19 01:31:27 +0100236 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400237 case IEEE80211_IF_TYPE_VLAN:
238 list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
239 /* no need to tell driver */
240 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400241 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100242 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
243 local->cooked_mntrs++;
244 break;
245 }
246
Johannes Berg4150c572007-09-17 01:29:23 -0400247 /* must be before the call to ieee80211_configure_filter */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200248 local->monitors++;
Michael Wu8cc9a732008-01-31 19:48:23 +0100249 if (local->monitors == 1)
Johannes Berg4150c572007-09-17 01:29:23 -0400250 local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100251
252 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
253 local->fif_fcsfail++;
254 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
255 local->fif_plcpfail++;
256 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
257 local->fif_control++;
258 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
259 local->fif_other_bss++;
260
261 netif_tx_lock_bh(local->mdev);
262 ieee80211_configure_filter(local);
263 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400264 break;
265 case IEEE80211_IF_TYPE_STA:
266 case IEEE80211_IF_TYPE_IBSS:
267 sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
268 /* fall through */
269 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100270 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100271 conf.type = sdata->vif.type;
Johannes Berg4150c572007-09-17 01:29:23 -0400272 conf.mac_addr = dev->dev_addr;
273 res = local->ops->add_interface(local_to_hw(local), &conf);
274 if (res && !local->open_count && local->ops->stop)
275 local->ops->stop(local_to_hw(local));
276 if (res)
277 return res;
278
Johannes Bergb2c258f2007-07-27 15:43:23 +0200279 ieee80211_if_config(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200280 ieee80211_reset_erp_info(dev);
Johannes Berg11a843b2007-08-28 17:01:55 -0400281 ieee80211_enable_keys(sdata);
Johannes Berg4150c572007-09-17 01:29:23 -0400282
Johannes Berg51fb61e2007-12-19 01:31:27 +0100283 if (sdata->vif.type == IEEE80211_IF_TYPE_STA &&
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200284 !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME))
Johannes Berg4150c572007-09-17 01:29:23 -0400285 netif_carrier_off(dev);
286 else
287 netif_carrier_on(dev);
Daniel Draked9430a32007-07-27 15:43:24 +0200288 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200289
Johannes Berg4150c572007-09-17 01:29:23 -0400290 if (local->open_count == 0) {
291 res = dev_open(local->mdev);
292 WARN_ON(res);
Johannes Berg4150c572007-09-17 01:29:23 -0400293 tasklet_enable(&local->tx_pending_tasklet);
294 tasklet_enable(&local->tasklet);
295 }
296
Johannes Bergc1428b32007-11-16 02:54:53 +0100297 /*
298 * set_multicast_list will be invoked by the networking core
299 * which will check whether any increments here were done in
300 * error and sync them down to the hardware as filter flags.
301 */
302 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
303 atomic_inc(&local->iff_allmultis);
304
305 if (sdata->flags & IEEE80211_SDATA_PROMISC)
306 atomic_inc(&local->iff_promiscs);
307
Johannes Berg4150c572007-09-17 01:29:23 -0400308 local->open_count++;
Michael Bueschceffefd2008-02-10 14:16:52 +0100309 if (need_hw_reconfig)
310 ieee80211_hw_config(local);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200311
312 netif_start_queue(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400313
Johannes Bergb2c258f2007-07-27 15:43:23 +0200314 return 0;
315}
316
Johannes Berg4150c572007-09-17 01:29:23 -0400317static int ieee80211_stop(struct net_device *dev)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200318{
Johannes Berg4150c572007-09-17 01:29:23 -0400319 struct ieee80211_sub_if_data *sdata;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200320 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg4150c572007-09-17 01:29:23 -0400321 struct ieee80211_if_init_conf conf;
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200322 struct sta_info *sta;
323 int i;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200324
Johannes Berg4150c572007-09-17 01:29:23 -0400325 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
326
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200327 list_for_each_entry(sta, &local->sta_list, list) {
Ron Rindjunsky5b3d71d2008-01-13 18:21:58 +0200328 if (sta->dev == dev)
329 for (i = 0; i < STA_TID_NUM; i++)
330 ieee80211_sta_stop_rx_ba_session(sta->dev,
331 sta->addr, i,
332 WLAN_BACK_RECIPIENT,
Ron Rindjunsky07db2182007-12-25 17:00:33 +0200333 WLAN_REASON_QSTA_LEAVE_QBSS);
334 }
335
Johannes Berg4150c572007-09-17 01:29:23 -0400336 netif_stop_queue(dev);
337
Johannes Bergc1428b32007-11-16 02:54:53 +0100338 /*
339 * Don't count this interface for promisc/allmulti while it
340 * is down. dev_mc_unsync() will invoke set_multicast_list
341 * on the master interface which will sync these down to the
342 * hardware as filter flags.
343 */
344 if (sdata->flags & IEEE80211_SDATA_ALLMULTI)
345 atomic_dec(&local->iff_allmultis);
346
347 if (sdata->flags & IEEE80211_SDATA_PROMISC)
348 atomic_dec(&local->iff_promiscs);
349
Johannes Berg4150c572007-09-17 01:29:23 -0400350 dev_mc_unsync(local->mdev, dev);
351
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100352 /* APs need special treatment */
Johannes Berg51fb61e2007-12-19 01:31:27 +0100353 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400354 struct ieee80211_sub_if_data *vlan, *tmp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100355 struct beacon_data *old_beacon = sdata->u.ap.beacon;
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400356
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100357 /* remove beacon */
358 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
359 synchronize_rcu();
360 kfree(old_beacon);
361
362 /* down all dependent devices, that is VLANs */
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400363 list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans,
364 u.vlan.list)
365 dev_close(vlan->dev);
366 WARN_ON(!list_empty(&sdata->u.ap.vlans));
367 }
368
Johannes Berg4150c572007-09-17 01:29:23 -0400369 local->open_count--;
370
Johannes Berg51fb61e2007-12-19 01:31:27 +0100371 switch (sdata->vif.type) {
Johannes Berg0ec3ca42007-09-17 01:29:24 -0400372 case IEEE80211_IF_TYPE_VLAN:
373 list_del(&sdata->u.vlan.list);
374 sdata->u.vlan.ap = NULL;
375 /* no need to tell driver */
376 break;
Johannes Berg4150c572007-09-17 01:29:23 -0400377 case IEEE80211_IF_TYPE_MNTR:
Michael Wu3d30d942008-01-31 19:48:27 +0100378 if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) {
379 local->cooked_mntrs--;
380 break;
381 }
382
Johannes Berg4150c572007-09-17 01:29:23 -0400383 local->monitors--;
Michael Wu8cc9a732008-01-31 19:48:23 +0100384 if (local->monitors == 0)
Michael Wu8b393f12007-11-28 01:57:08 -0500385 local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
Michael Wu8cc9a732008-01-31 19:48:23 +0100386
387 if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL)
388 local->fif_fcsfail--;
389 if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL)
390 local->fif_plcpfail--;
391 if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL)
392 local->fif_control--;
393 if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS)
394 local->fif_other_bss--;
395
396 netif_tx_lock_bh(local->mdev);
397 ieee80211_configure_filter(local);
398 netif_tx_unlock_bh(local->mdev);
Johannes Berg4150c572007-09-17 01:29:23 -0400399 break;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200400 case IEEE80211_IF_TYPE_STA:
401 case IEEE80211_IF_TYPE_IBSS:
402 sdata->u.sta.state = IEEE80211_DISABLED;
403 del_timer_sync(&sdata->u.sta.timer);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400404 /*
Johannes Berg79010422007-09-18 17:29:21 -0400405 * When we get here, the interface is marked down.
406 * Call synchronize_rcu() to wait for the RX path
407 * should it be using the interface and enqueuing
408 * frames at this very time on another CPU.
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400409 */
Johannes Berg79010422007-09-18 17:29:21 -0400410 synchronize_rcu();
Johannes Bergb2c258f2007-07-27 15:43:23 +0200411 skb_queue_purge(&sdata->u.sta.skb_queue);
Johannes Berg2a8a9a82007-08-28 17:01:52 -0400412
Zhu Yiece8edd2007-11-22 10:53:21 +0800413 if (local->scan_dev == sdata->dev) {
414 if (!local->ops->hw_scan) {
415 local->sta_sw_scanning = 0;
416 cancel_delayed_work(&local->scan_work);
417 } else
418 local->sta_hw_scanning = 0;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200419 }
Zhu Yiece8edd2007-11-22 10:53:21 +0800420
Johannes Bergb2c258f2007-07-27 15:43:23 +0200421 flush_workqueue(local->hw.workqueue);
Zhu Yia10605e2007-11-22 11:10:22 +0800422
423 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
424 kfree(sdata->u.sta.extra_ie);
425 sdata->u.sta.extra_ie = NULL;
426 sdata->u.sta.extra_ie_len = 0;
Johannes Berg4150c572007-09-17 01:29:23 -0400427 /* fall through */
428 default:
Johannes Berg32bfd352007-12-19 01:31:26 +0100429 conf.vif = &sdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100430 conf.type = sdata->vif.type;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200431 conf.mac_addr = dev->dev_addr;
Johannes Berg4150c572007-09-17 01:29:23 -0400432 /* disable all keys for as long as this netdev is down */
433 ieee80211_disable_keys(sdata);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200434 local->ops->remove_interface(local_to_hw(local), &conf);
435 }
436
Johannes Berg4150c572007-09-17 01:29:23 -0400437 if (local->open_count == 0) {
438 if (netif_running(local->mdev))
439 dev_close(local->mdev);
440
Johannes Berg4150c572007-09-17 01:29:23 -0400441 if (local->ops->stop)
442 local->ops->stop(local_to_hw(local));
443
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100444 ieee80211_led_radio(local, 0);
445
Johannes Berg4150c572007-09-17 01:29:23 -0400446 tasklet_disable(&local->tx_pending_tasklet);
447 tasklet_disable(&local->tasklet);
448 }
Johannes Bergb2c258f2007-07-27 15:43:23 +0200449
450 return 0;
451}
452
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200453int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
454{
455 struct ieee80211_local *local = hw_to_local(hw);
456 struct sta_info *sta;
457 struct ieee80211_sub_if_data *sdata;
458 u16 start_seq_num = 0;
459 u8 *state;
460 int ret;
461 DECLARE_MAC_BUF(mac);
462
463 if (tid >= STA_TID_NUM)
464 return -EINVAL;
465
466#ifdef CONFIG_MAC80211_HT_DEBUG
467 printk(KERN_DEBUG "Open BA session requested for %s tid %u\n",
468 print_mac(mac, ra), tid);
469#endif /* CONFIG_MAC80211_HT_DEBUG */
470
471 sta = sta_info_get(local, ra);
472 if (!sta) {
473 printk(KERN_DEBUG "Could not find the station\n");
474 return -ENOENT;
475 }
476
477 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
478
479 /* we have tried too many times, receiver does not want A-MPDU */
480 if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) {
481 ret = -EBUSY;
482 goto start_ba_exit;
483 }
484
485 state = &sta->ampdu_mlme.tid_tx[tid].state;
486 /* check if the TID is not in aggregation flow already */
487 if (*state != HT_AGG_STATE_IDLE) {
488#ifdef CONFIG_MAC80211_HT_DEBUG
489 printk(KERN_DEBUG "BA request denied - session is not "
490 "idle on tid %u\n", tid);
491#endif /* CONFIG_MAC80211_HT_DEBUG */
492 ret = -EAGAIN;
493 goto start_ba_exit;
494 }
495
496 /* ensure that TX flow won't interrupt us
497 * until the end of the call to requeue function */
498 spin_lock_bh(&local->mdev->queue_lock);
499
500 /* create a new queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200501 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200502
503 /* case no queue is available to aggregation
504 * don't switch to aggregation */
505 if (ret) {
506#ifdef CONFIG_MAC80211_HT_DEBUG
507 printk(KERN_DEBUG "BA request denied - no queue available for"
508 " tid %d\n", tid);
509#endif /* CONFIG_MAC80211_HT_DEBUG */
510 spin_unlock_bh(&local->mdev->queue_lock);
511 goto start_ba_exit;
512 }
513 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
514
515 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
516 * call back right away, it must see that the flow has begun */
517 *state |= HT_ADDBA_REQUESTED_MSK;
518
519 if (local->ops->ampdu_action)
520 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
521 ra, tid, &start_seq_num);
522
523 if (ret) {
524 /* No need to requeue the packets in the agg queue, since we
525 * held the tx lock: no packet could be enqueued to the newly
526 * allocated queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200527 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200528#ifdef CONFIG_MAC80211_HT_DEBUG
529 printk(KERN_DEBUG "BA request denied - HW or queue unavailable"
530 " for tid %d\n", tid);
531#endif /* CONFIG_MAC80211_HT_DEBUG */
532 spin_unlock_bh(&local->mdev->queue_lock);
533 *state = HT_AGG_STATE_IDLE;
534 goto start_ba_exit;
535 }
536
537 /* Will put all the packets in the new SW queue */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200538 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200539 spin_unlock_bh(&local->mdev->queue_lock);
540
541 /* We have most probably almost emptied the legacy queue */
542 /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */
543
544 /* send an addBA request */
545 sta->ampdu_mlme.dialog_token_allocator++;
546 sta->ampdu_mlme.tid_tx[tid].dialog_token =
547 sta->ampdu_mlme.dialog_token_allocator;
548 sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num;
549
550 ieee80211_send_addba_request(sta->dev, ra, tid,
551 sta->ampdu_mlme.tid_tx[tid].dialog_token,
552 sta->ampdu_mlme.tid_tx[tid].ssn,
553 0x40, 5000);
554
555 /* activate the timer for the recipient's addBA response */
556 sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires =
557 jiffies + ADDBA_RESP_INTERVAL;
558 add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer);
559 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
560
561start_ba_exit:
562 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
563 sta_info_put(sta);
564 return ret;
565}
566EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
567
568int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
569 u8 *ra, u16 tid,
570 enum ieee80211_back_parties initiator)
571{
572 struct ieee80211_local *local = hw_to_local(hw);
573 struct sta_info *sta;
574 u8 *state;
575 int ret = 0;
576 DECLARE_MAC_BUF(mac);
577
578 if (tid >= STA_TID_NUM)
579 return -EINVAL;
580
581#ifdef CONFIG_MAC80211_HT_DEBUG
582 printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n",
583 print_mac(mac, ra), tid);
584#endif /* CONFIG_MAC80211_HT_DEBUG */
585
586 sta = sta_info_get(local, ra);
587 if (!sta)
588 return -ENOENT;
589
590 /* check if the TID is in aggregation */
591 state = &sta->ampdu_mlme.tid_tx[tid].state;
592 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
593
594 if (*state != HT_AGG_STATE_OPERATIONAL) {
595#ifdef CONFIG_MAC80211_HT_DEBUG
596 printk(KERN_DEBUG "Try to stop Tx aggregation on"
597 " non active TID\n");
598#endif /* CONFIG_MAC80211_HT_DEBUG */
599 ret = -ENOENT;
600 goto stop_BA_exit;
601 }
602
603 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
604
605 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
606 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
607
608 if (local->ops->ampdu_action)
609 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
610 ra, tid, NULL);
611
612 /* case HW denied going back to legacy */
613 if (ret) {
614 WARN_ON(ret != -EBUSY);
615 *state = HT_AGG_STATE_OPERATIONAL;
616 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
617 goto stop_BA_exit;
618 }
619
620stop_BA_exit:
621 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
622 sta_info_put(sta);
623 return ret;
624}
625EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
626
627void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
628{
629 struct ieee80211_local *local = hw_to_local(hw);
630 struct sta_info *sta;
631 u8 *state;
632 DECLARE_MAC_BUF(mac);
633
634 if (tid >= STA_TID_NUM) {
635 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
636 tid, STA_TID_NUM);
637 return;
638 }
639
640 sta = sta_info_get(local, ra);
641 if (!sta) {
642 printk(KERN_DEBUG "Could not find station: %s\n",
643 print_mac(mac, ra));
644 return;
645 }
646
647 state = &sta->ampdu_mlme.tid_tx[tid].state;
648 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
649
650 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
651 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
652 *state);
653 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
654 sta_info_put(sta);
655 return;
656 }
657
658 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
659
660 *state |= HT_ADDBA_DRV_READY_MSK;
661
662 if (*state == HT_AGG_STATE_OPERATIONAL) {
663 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
664 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
665 }
666 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
667 sta_info_put(sta);
668}
669EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
670
671void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
672{
673 struct ieee80211_local *local = hw_to_local(hw);
674 struct sta_info *sta;
675 u8 *state;
676 int agg_queue;
677 DECLARE_MAC_BUF(mac);
678
679 if (tid >= STA_TID_NUM) {
680 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
681 tid, STA_TID_NUM);
682 return;
683 }
684
685 printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n",
686 print_mac(mac, ra), tid);
687
688 sta = sta_info_get(local, ra);
689 if (!sta) {
690 printk(KERN_DEBUG "Could not find station: %s\n",
691 print_mac(mac, ra));
692 return;
693 }
694 state = &sta->ampdu_mlme.tid_tx[tid].state;
695
696 spin_lock_bh(&sta->ampdu_mlme.ampdu_tx);
697 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
698 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
699 sta_info_put(sta);
700 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
701 return;
702 }
703
704 if (*state & HT_AGG_STATE_INITIATOR_MSK)
705 ieee80211_send_delba(sta->dev, ra, tid,
706 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
707
708 agg_queue = sta->tid_to_tx_q[tid];
709
710 /* avoid ordering issues: we are the only one that can modify
711 * the content of the qdiscs */
712 spin_lock_bh(&local->mdev->queue_lock);
713 /* remove the queue for this aggregation */
Ron Rindjunsky9e723492008-01-28 14:07:18 +0200714 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +0200715 spin_unlock_bh(&local->mdev->queue_lock);
716
717 /* we just requeued the all the frames that were in the removed
718 * queue, and since we might miss a softirq we do netif_schedule.
719 * ieee80211_wake_queue is not used here as this queue is not
720 * necessarily stopped */
721 netif_schedule(local->mdev);
722 *state = HT_AGG_STATE_IDLE;
723 sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0;
724 spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx);
725
726 sta_info_put(sta);
727}
728EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
729
730void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
731 const u8 *ra, u16 tid)
732{
733 struct ieee80211_local *local = hw_to_local(hw);
734 struct ieee80211_ra_tid *ra_tid;
735 struct sk_buff *skb = dev_alloc_skb(0);
736
737 if (unlikely(!skb)) {
738 if (net_ratelimit())
739 printk(KERN_WARNING "%s: Not enough memory, "
740 "dropping start BA session", skb->dev->name);
741 return;
742 }
743 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
744 memcpy(&ra_tid->ra, ra, ETH_ALEN);
745 ra_tid->tid = tid;
746
747 skb->pkt_type = IEEE80211_ADDBA_MSG;
748 skb_queue_tail(&local->skb_queue, skb);
749 tasklet_schedule(&local->tasklet);
750}
751EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
752
753void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
754 const u8 *ra, u16 tid)
755{
756 struct ieee80211_local *local = hw_to_local(hw);
757 struct ieee80211_ra_tid *ra_tid;
758 struct sk_buff *skb = dev_alloc_skb(0);
759
760 if (unlikely(!skb)) {
761 if (net_ratelimit())
762 printk(KERN_WARNING "%s: Not enough memory, "
763 "dropping stop BA session", skb->dev->name);
764 return;
765 }
766 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
767 memcpy(&ra_tid->ra, ra, ETH_ALEN);
768 ra_tid->tid = tid;
769
770 skb->pkt_type = IEEE80211_DELBA_MSG;
771 skb_queue_tail(&local->skb_queue, skb);
772 tasklet_schedule(&local->tasklet);
773}
774EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
775
Johannes Bergb2c258f2007-07-27 15:43:23 +0200776static void ieee80211_set_multicast_list(struct net_device *dev)
777{
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
779 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg4150c572007-09-17 01:29:23 -0400780 int allmulti, promisc, sdata_allmulti, sdata_promisc;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200781
Johannes Berg4150c572007-09-17 01:29:23 -0400782 allmulti = !!(dev->flags & IFF_ALLMULTI);
783 promisc = !!(dev->flags & IFF_PROMISC);
Johannes Bergb52f2192007-11-16 01:49:11 +0100784 sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI);
785 sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC);
Johannes Berg4150c572007-09-17 01:29:23 -0400786
787 if (allmulti != sdata_allmulti) {
788 if (dev->flags & IFF_ALLMULTI)
Johannes Berg53918992007-09-26 15:19:47 +0200789 atomic_inc(&local->iff_allmultis);
Johannes Berg4150c572007-09-17 01:29:23 -0400790 else
Johannes Berg53918992007-09-26 15:19:47 +0200791 atomic_dec(&local->iff_allmultis);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400792 sdata->flags ^= IEEE80211_SDATA_ALLMULTI;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200793 }
Johannes Berg4150c572007-09-17 01:29:23 -0400794
795 if (promisc != sdata_promisc) {
796 if (dev->flags & IFF_PROMISC)
Johannes Berg53918992007-09-26 15:19:47 +0200797 atomic_inc(&local->iff_promiscs);
Johannes Berg4150c572007-09-17 01:29:23 -0400798 else
Johannes Berg53918992007-09-26 15:19:47 +0200799 atomic_dec(&local->iff_promiscs);
Jiri Slaby13262ff2007-08-28 17:01:54 -0400800 sdata->flags ^= IEEE80211_SDATA_PROMISC;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200801 }
Johannes Berg4150c572007-09-17 01:29:23 -0400802
803 dev_mc_sync(local->mdev, dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200804}
805
Stephen Hemminger3b04ddd2007-10-09 01:40:57 -0700806static const struct header_ops ieee80211_header_ops = {
807 .create = eth_header,
808 .parse = header_parse_80211,
809 .rebuild = eth_rebuild_header,
810 .cache = eth_header_cache,
811 .cache_update = eth_header_cache_update,
812};
813
Johannes Bergf9d540e2007-09-28 14:02:09 +0200814/* Must not be called for mdev */
Johannes Bergb2c258f2007-07-27 15:43:23 +0200815void ieee80211_if_setup(struct net_device *dev)
816{
817 ether_setup(dev);
818 dev->hard_start_xmit = ieee80211_subif_start_xmit;
819 dev->wireless_handlers = &ieee80211_iw_handler_def;
820 dev->set_multicast_list = ieee80211_set_multicast_list;
821 dev->change_mtu = ieee80211_change_mtu;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200822 dev->open = ieee80211_open;
823 dev->stop = ieee80211_stop;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200824 dev->destructor = ieee80211_if_free;
825}
826
827/* WDS specialties */
828
829int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
830{
831 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
832 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
833 struct sta_info *sta;
Joe Perches0795af52007-10-03 17:59:30 -0700834 DECLARE_MAC_BUF(mac);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200835
836 if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
837 return 0;
838
839 /* Create STA entry for the new peer */
840 sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
841 if (!sta)
842 return -ENOMEM;
Johannes Berg238814f2008-01-28 17:19:37 +0100843
844 sta->flags |= WLAN_STA_AUTHORIZED;
845
Johannes Bergb2c258f2007-07-27 15:43:23 +0200846 sta_info_put(sta);
847
848 /* Remove STA entry for the old peer */
849 sta = sta_info_get(local, sdata->u.wds.remote_addr);
850 if (sta) {
Michael Wube8755e2007-07-27 15:43:23 +0200851 sta_info_free(sta);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200852 sta_info_put(sta);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200853 } else {
854 printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
Joe Perches0795af52007-10-03 17:59:30 -0700855 "peer %s\n",
856 dev->name, print_mac(mac, sdata->u.wds.remote_addr));
Johannes Bergb2c258f2007-07-27 15:43:23 +0200857 }
858
859 /* Update WDS link data */
860 memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
861
862 return 0;
863}
864
865/* everything else */
866
Johannes Bergb2c258f2007-07-27 15:43:23 +0200867static int __ieee80211_if_config(struct net_device *dev,
868 struct sk_buff *beacon,
869 struct ieee80211_tx_control *control)
870{
871 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
872 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
873 struct ieee80211_if_conf conf;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200874
875 if (!local->ops->config_interface || !netif_running(dev))
876 return 0;
877
878 memset(&conf, 0, sizeof(conf));
Johannes Berg51fb61e2007-12-19 01:31:27 +0100879 conf.type = sdata->vif.type;
880 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
881 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Johannes Berg4150c572007-09-17 01:29:23 -0400882 conf.bssid = sdata->u.sta.bssid;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200883 conf.ssid = sdata->u.sta.ssid;
884 conf.ssid_len = sdata->u.sta.ssid_len;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100885 } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Johannes Bergb2c258f2007-07-27 15:43:23 +0200886 conf.ssid = sdata->u.ap.ssid;
887 conf.ssid_len = sdata->u.ap.ssid_len;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200888 conf.beacon = beacon;
889 conf.beacon_control = control;
890 }
891 return local->ops->config_interface(local_to_hw(local),
Johannes Berg32bfd352007-12-19 01:31:26 +0100892 &sdata->vif, &conf);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200893}
894
895int ieee80211_if_config(struct net_device *dev)
896{
897 return __ieee80211_if_config(dev, NULL, NULL);
898}
899
900int ieee80211_if_config_beacon(struct net_device *dev)
901{
902 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
903 struct ieee80211_tx_control control;
Johannes Berg32bfd352007-12-19 01:31:26 +0100904 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200905 struct sk_buff *skb;
906
907 if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
908 return 0;
Johannes Berg32bfd352007-12-19 01:31:26 +0100909 skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif,
910 &control);
Johannes Bergb2c258f2007-07-27 15:43:23 +0200911 if (!skb)
912 return -ENOMEM;
913 return __ieee80211_if_config(dev, skb, &control);
914}
915
916int ieee80211_hw_config(struct ieee80211_local *local)
917{
Johannes Bergb2c258f2007-07-27 15:43:23 +0200918 struct ieee80211_channel *chan;
919 int ret = 0;
920
Johannes Berg8318d782008-01-24 19:38:38 +0100921 if (local->sta_sw_scanning)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200922 chan = local->scan_channel;
Johannes Berg8318d782008-01-24 19:38:38 +0100923 else
Johannes Bergb2c258f2007-07-27 15:43:23 +0200924 chan = local->oper_channel;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200925
Johannes Berg8318d782008-01-24 19:38:38 +0100926 local->hw.conf.channel = chan;
927
928 if (!local->hw.conf.power_level)
929 local->hw.conf.power_level = chan->max_power;
930 else
931 local->hw.conf.power_level = min(chan->max_power,
932 local->hw.conf.power_level);
933
934 local->hw.conf.max_antenna_gain = chan->max_antenna_gain;
Johannes Bergb2c258f2007-07-27 15:43:23 +0200935
936#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Johannes Berg8318d782008-01-24 19:38:38 +0100937 printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n",
938 wiphy_name(local->hw.wiphy), chan->center_freq);
939#endif
Johannes Bergb2c258f2007-07-27 15:43:23 +0200940
Michael Bueschf7c4dae2007-09-24 18:41:49 +0200941 if (local->open_count)
Johannes Bergb2c258f2007-07-27 15:43:23 +0200942 ret = local->ops->config(local_to_hw(local), &local->hw.conf);
943
944 return ret;
945}
946
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200947/**
948 * ieee80211_hw_config_ht should be used only after legacy configuration
949 * has been determined, as ht configuration depends upon the hardware's
950 * HT abilities for a _specific_ band.
951 */
952int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht,
953 struct ieee80211_ht_info *req_ht_cap,
954 struct ieee80211_ht_bss_info *req_bss_cap)
955{
956 struct ieee80211_conf *conf = &local->hw.conf;
Johannes Berg8318d782008-01-24 19:38:38 +0100957 struct ieee80211_supported_band *sband;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200958 int i;
959
Johannes Berg8318d782008-01-24 19:38:38 +0100960 sband = local->hw.wiphy->bands[conf->channel->band];
961
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200962 /* HT is not supported */
Johannes Berg8318d782008-01-24 19:38:38 +0100963 if (!sband->ht_info.ht_supported) {
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200964 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
965 return -EOPNOTSUPP;
966 }
967
968 /* disable HT */
969 if (!enable_ht) {
970 conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE;
971 } else {
972 conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE;
Johannes Berg8318d782008-01-24 19:38:38 +0100973 conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200974 conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS);
975 conf->ht_conf.cap |=
Johannes Berg8318d782008-01-24 19:38:38 +0100976 sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS;
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200977 conf->ht_bss_conf.primary_channel =
978 req_bss_cap->primary_channel;
979 conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap;
980 conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode;
981 for (i = 0; i < SUPP_MCS_SET_LEN; i++)
982 conf->ht_conf.supp_mcs_set[i] =
Johannes Berg8318d782008-01-24 19:38:38 +0100983 sband->ht_info.supp_mcs_set[i] &
Ron Rindjunskyd3c990f2007-11-26 16:14:34 +0200984 req_ht_cap->supp_mcs_set[i];
985
986 /* In STA mode, this gives us indication
987 * to the AP's mode of operation */
988 conf->ht_conf.ht_supported = 1;
989 conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor;
990 conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density;
991 }
992
993 local->ops->conf_ht(local_to_hw(local), &local->hw.conf);
994
995 return 0;
996}
997
Johannes Berg471b3ef2007-12-28 14:32:58 +0100998void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
999 u32 changed)
Daniel Draked9430a32007-07-27 15:43:24 +02001000{
Johannes Berg471b3ef2007-12-28 14:32:58 +01001001 struct ieee80211_local *local = sdata->local;
1002
1003 if (!changed)
1004 return;
1005
1006 if (local->ops->bss_info_changed)
1007 local->ops->bss_info_changed(local_to_hw(local),
1008 &sdata->vif,
1009 &sdata->bss_conf,
1010 changed);
Daniel Draked9430a32007-07-27 15:43:24 +02001011}
1012
1013void ieee80211_reset_erp_info(struct net_device *dev)
1014{
1015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1016
Johannes Berg471b3ef2007-12-28 14:32:58 +01001017 sdata->bss_conf.use_cts_prot = 0;
1018 sdata->bss_conf.use_short_preamble = 0;
1019 ieee80211_bss_info_change_notify(sdata,
1020 BSS_CHANGED_ERP_CTS_PROT |
1021 BSS_CHANGED_ERP_PREAMBLE);
Daniel Draked9430a32007-07-27 15:43:24 +02001022}
1023
Jiri Bencf0706e82007-05-05 11:45:53 -07001024void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
1025 struct sk_buff *skb,
1026 struct ieee80211_tx_status *status)
1027{
1028 struct ieee80211_local *local = hw_to_local(hw);
1029 struct ieee80211_tx_status *saved;
1030 int tmp;
1031
1032 skb->dev = local->mdev;
1033 saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
1034 if (unlikely(!saved)) {
1035 if (net_ratelimit())
1036 printk(KERN_WARNING "%s: Not enough memory, "
1037 "dropping tx status", skb->dev->name);
1038 /* should be dev_kfree_skb_irq, but due to this function being
1039 * named _irqsafe instead of just _irq we can't be sure that
1040 * people won't call it from non-irq contexts */
1041 dev_kfree_skb_any(skb);
1042 return;
1043 }
1044 memcpy(saved, status, sizeof(struct ieee80211_tx_status));
1045 /* copy pointer to saved status into skb->cb for use by tasklet */
1046 memcpy(skb->cb, &saved, sizeof(saved));
1047
1048 skb->pkt_type = IEEE80211_TX_STATUS_MSG;
1049 skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
1050 &local->skb_queue : &local->skb_queue_unreliable, skb);
1051 tmp = skb_queue_len(&local->skb_queue) +
1052 skb_queue_len(&local->skb_queue_unreliable);
1053 while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
1054 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1055 memcpy(&saved, skb->cb, sizeof(saved));
1056 kfree(saved);
1057 dev_kfree_skb_irq(skb);
1058 tmp--;
1059 I802_DEBUG_INC(local->tx_status_drop);
1060 }
1061 tasklet_schedule(&local->tasklet);
1062}
1063EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
1064
1065static void ieee80211_tasklet_handler(unsigned long data)
1066{
1067 struct ieee80211_local *local = (struct ieee80211_local *) data;
1068 struct sk_buff *skb;
1069 struct ieee80211_rx_status rx_status;
1070 struct ieee80211_tx_status *tx_status;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001071 struct ieee80211_ra_tid *ra_tid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001072
1073 while ((skb = skb_dequeue(&local->skb_queue)) ||
1074 (skb = skb_dequeue(&local->skb_queue_unreliable))) {
1075 switch (skb->pkt_type) {
1076 case IEEE80211_RX_MSG:
1077 /* status is in skb->cb */
1078 memcpy(&rx_status, skb->cb, sizeof(rx_status));
Johannes Berg51fb61e2007-12-19 01:31:27 +01001079 /* Clear skb->pkt_type in order to not confuse kernel
Jiri Bencf0706e82007-05-05 11:45:53 -07001080 * netstack. */
1081 skb->pkt_type = 0;
1082 __ieee80211_rx(local_to_hw(local), skb, &rx_status);
1083 break;
1084 case IEEE80211_TX_STATUS_MSG:
1085 /* get pointer to saved status out of skb->cb */
1086 memcpy(&tx_status, skb->cb, sizeof(tx_status));
1087 skb->pkt_type = 0;
1088 ieee80211_tx_status(local_to_hw(local),
1089 skb, tx_status);
1090 kfree(tx_status);
1091 break;
Ron Rindjunskyeadc8d92008-01-28 14:07:17 +02001092 case IEEE80211_DELBA_MSG:
1093 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1094 ieee80211_stop_tx_ba_cb(local_to_hw(local),
1095 ra_tid->ra, ra_tid->tid);
1096 dev_kfree_skb(skb);
1097 break;
1098 case IEEE80211_ADDBA_MSG:
1099 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
1100 ieee80211_start_tx_ba_cb(local_to_hw(local),
1101 ra_tid->ra, ra_tid->tid);
1102 dev_kfree_skb(skb);
1103 break ;
Jiri Bencf0706e82007-05-05 11:45:53 -07001104 default: /* should never get here! */
1105 printk(KERN_ERR "%s: Unknown message type (%d)\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001106 wiphy_name(local->hw.wiphy), skb->pkt_type);
Jiri Bencf0706e82007-05-05 11:45:53 -07001107 dev_kfree_skb(skb);
1108 break;
1109 }
1110 }
1111}
1112
Jiri Bencf0706e82007-05-05 11:45:53 -07001113/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
1114 * make a prepared TX frame (one that has been given to hw) to look like brand
1115 * new IEEE 802.11 frame that is ready to go through TX processing again.
1116 * Also, tx_packet_data in cb is restored from tx_control. */
1117static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
1118 struct ieee80211_key *key,
1119 struct sk_buff *skb,
1120 struct ieee80211_tx_control *control)
1121{
1122 int hdrlen, iv_len, mic_len;
1123 struct ieee80211_tx_packet_data *pkt_data;
1124
1125 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
Johannes Berg32bfd352007-12-19 01:31:26 +01001126 pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001127 pkt_data->flags = 0;
1128 if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS)
1129 pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS;
1130 if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)
1131 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
1132 if (control->flags & IEEE80211_TXCTL_REQUEUE)
1133 pkt_data->flags |= IEEE80211_TXPD_REQUEUE;
Johannes Berg678f5f712007-12-19 01:31:23 +01001134 if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME)
1135 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
Jiri Bencf0706e82007-05-05 11:45:53 -07001136 pkt_data->queue = control->queue;
1137
1138 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1139
1140 if (!key)
1141 goto no_key;
1142
Johannes Berg8f20fc22007-08-28 17:01:54 -04001143 switch (key->conf.alg) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001144 case ALG_WEP:
1145 iv_len = WEP_IV_LEN;
1146 mic_len = WEP_ICV_LEN;
1147 break;
1148 case ALG_TKIP:
1149 iv_len = TKIP_IV_LEN;
1150 mic_len = TKIP_ICV_LEN;
1151 break;
1152 case ALG_CCMP:
1153 iv_len = CCMP_HDR_LEN;
1154 mic_len = CCMP_MIC_LEN;
1155 break;
1156 default:
1157 goto no_key;
1158 }
1159
Johannes Berg8f20fc22007-08-28 17:01:54 -04001160 if (skb->len >= mic_len &&
Johannes Berg11a843b2007-08-28 17:01:55 -04001161 !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Jiri Bencf0706e82007-05-05 11:45:53 -07001162 skb_trim(skb, skb->len - mic_len);
1163 if (skb->len >= iv_len && skb->len > hdrlen) {
1164 memmove(skb->data + iv_len, skb->data, hdrlen);
1165 skb_pull(skb, iv_len);
1166 }
1167
1168no_key:
1169 {
1170 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1171 u16 fc = le16_to_cpu(hdr->frame_control);
1172 if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
1173 fc &= ~IEEE80211_STYPE_QOS_DATA;
1174 hdr->frame_control = cpu_to_le16(fc);
1175 memmove(skb->data + 2, skb->data, hdrlen - 2);
1176 skb_pull(skb, 2);
1177 }
1178 }
1179}
1180
Johannes Bergd46e1442008-02-20 23:59:33 +01001181static void ieee80211_handle_filtered_frame(struct ieee80211_local *local,
1182 struct sta_info *sta,
1183 struct sk_buff *skb,
1184 struct ieee80211_tx_status *status)
1185{
1186 sta->tx_filtered_count++;
1187
1188 /*
1189 * Clear the TX filter mask for this STA when sending the next
1190 * packet. If the STA went to power save mode, this will happen
1191 * happen when it wakes up for the next time.
1192 */
1193 sta->flags |= WLAN_STA_CLEAR_PS_FILT;
1194
1195 /*
1196 * This code races in the following way:
1197 *
1198 * (1) STA sends frame indicating it will go to sleep and does so
1199 * (2) hardware/firmware adds STA to filter list, passes frame up
1200 * (3) hardware/firmware processes TX fifo and suppresses a frame
1201 * (4) we get TX status before having processed the frame and
1202 * knowing that the STA has gone to sleep.
1203 *
1204 * This is actually quite unlikely even when both those events are
1205 * processed from interrupts coming in quickly after one another or
1206 * even at the same time because we queue both TX status events and
1207 * RX frames to be processed by a tasklet and process them in the
1208 * same order that they were received or TX status last. Hence, there
1209 * is no race as long as the frame RX is processed before the next TX
1210 * status, which drivers can ensure, see below.
1211 *
1212 * Note that this can only happen if the hardware or firmware can
1213 * actually add STAs to the filter list, if this is done by the
1214 * driver in response to set_tim() (which will only reduce the race
1215 * this whole filtering tries to solve, not completely solve it)
1216 * this situation cannot happen.
1217 *
1218 * To completely solve this race drivers need to make sure that they
1219 * (a) don't mix the irq-safe/not irq-safe TX status/RX processing
1220 * functions and
1221 * (b) always process RX events before TX status events if ordering
1222 * can be unknown, for example with different interrupt status
1223 * bits.
1224 */
1225 if (sta->flags & WLAN_STA_PS &&
1226 skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) {
1227 ieee80211_remove_tx_extra(local, sta->key, skb,
1228 &status->control);
1229 skb_queue_tail(&sta->tx_filtered, skb);
1230 return;
1231 }
1232
1233 if (!(sta->flags & WLAN_STA_PS) &&
1234 !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
1235 /* Software retry the packet once */
1236 status->control.flags |= IEEE80211_TXCTL_REQUEUE;
1237 ieee80211_remove_tx_extra(local, sta->key, skb,
1238 &status->control);
1239 dev_queue_xmit(skb);
1240 return;
1241 }
1242
1243 if (net_ratelimit())
1244 printk(KERN_DEBUG "%s: dropped TX filtered frame, "
1245 "queue_len=%d PS=%d @%lu\n",
1246 wiphy_name(local->hw.wiphy),
1247 skb_queue_len(&sta->tx_filtered),
1248 !!(sta->flags & WLAN_STA_PS), jiffies);
1249 dev_kfree_skb(skb);
1250}
1251
Jiri Bencf0706e82007-05-05 11:45:53 -07001252void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
1253 struct ieee80211_tx_status *status)
1254{
1255 struct sk_buff *skb2;
1256 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1257 struct ieee80211_local *local = hw_to_local(hw);
1258 u16 frag, type;
Johannes Bergb306f452007-07-10 19:32:08 +02001259 struct ieee80211_tx_status_rtap_hdr *rthdr;
1260 struct ieee80211_sub_if_data *sdata;
Michael Wu3d30d942008-01-31 19:48:27 +01001261 struct net_device *prev_dev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001262
1263 if (!status) {
1264 printk(KERN_ERR
1265 "%s: ieee80211_tx_status called with NULL status\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001266 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001267 dev_kfree_skb(skb);
1268 return;
1269 }
1270
1271 if (status->excessive_retries) {
1272 struct sta_info *sta;
1273 sta = sta_info_get(local, hdr->addr1);
1274 if (sta) {
1275 if (sta->flags & WLAN_STA_PS) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001276 /*
1277 * The STA is in power save mode, so assume
Jiri Bencf0706e82007-05-05 11:45:53 -07001278 * that this TX packet failed because of that.
1279 */
1280 status->excessive_retries = 0;
1281 status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
Johannes Bergd46e1442008-02-20 23:59:33 +01001282 ieee80211_handle_filtered_frame(local, sta,
1283 skb, status);
1284 sta_info_put(sta);
1285 return;
Jiri Bencf0706e82007-05-05 11:45:53 -07001286 }
1287 sta_info_put(sta);
1288 }
1289 }
1290
1291 if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
1292 struct sta_info *sta;
1293 sta = sta_info_get(local, hdr->addr1);
1294 if (sta) {
Johannes Bergd46e1442008-02-20 23:59:33 +01001295 ieee80211_handle_filtered_frame(local, sta, skb,
1296 status);
Jiri Bencf0706e82007-05-05 11:45:53 -07001297 sta_info_put(sta);
1298 return;
1299 }
Mattias Nissler1abbe492007-12-20 13:50:07 +01001300 } else
1301 rate_control_tx_status(local->mdev, skb, status);
Jiri Bencf0706e82007-05-05 11:45:53 -07001302
1303 ieee80211_led_tx(local, 0);
1304
1305 /* SNMP counters
1306 * Fragments are passed to low-level drivers as separate skbs, so these
1307 * are actually fragments, not frames. Update frame counters only for
1308 * the first fragment of the frame. */
1309
1310 frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
1311 type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
1312
1313 if (status->flags & IEEE80211_TX_STATUS_ACK) {
1314 if (frag == 0) {
1315 local->dot11TransmittedFrameCount++;
1316 if (is_multicast_ether_addr(hdr->addr1))
1317 local->dot11MulticastTransmittedFrameCount++;
1318 if (status->retry_count > 0)
1319 local->dot11RetryCount++;
1320 if (status->retry_count > 1)
1321 local->dot11MultipleRetryCount++;
1322 }
1323
1324 /* This counter shall be incremented for an acknowledged MPDU
1325 * with an individual address in the address 1 field or an MPDU
1326 * with a multicast address in the address 1 field of type Data
1327 * or Management. */
1328 if (!is_multicast_ether_addr(hdr->addr1) ||
1329 type == IEEE80211_FTYPE_DATA ||
1330 type == IEEE80211_FTYPE_MGMT)
1331 local->dot11TransmittedFragmentCount++;
1332 } else {
1333 if (frag == 0)
1334 local->dot11FailedCount++;
1335 }
1336
Johannes Bergb306f452007-07-10 19:32:08 +02001337 /* this was a transmitted frame, but now we want to reuse it */
1338 skb_orphan(skb);
1339
Michael Wu3d30d942008-01-31 19:48:27 +01001340 /*
1341 * This is a bit racy but we can avoid a lot of work
1342 * with this test...
1343 */
1344 if (!local->monitors && !local->cooked_mntrs) {
Jiri Bencf0706e82007-05-05 11:45:53 -07001345 dev_kfree_skb(skb);
1346 return;
1347 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001348
Johannes Bergb306f452007-07-10 19:32:08 +02001349 /* send frame to monitor interfaces now */
1350
1351 if (skb_headroom(skb) < sizeof(*rthdr)) {
1352 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n");
1353 dev_kfree_skb(skb);
1354 return;
1355 }
1356
1357 rthdr = (struct ieee80211_tx_status_rtap_hdr*)
1358 skb_push(skb, sizeof(*rthdr));
1359
1360 memset(rthdr, 0, sizeof(*rthdr));
1361 rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
1362 rthdr->hdr.it_present =
1363 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) |
1364 (1 << IEEE80211_RADIOTAP_DATA_RETRIES));
1365
1366 if (!(status->flags & IEEE80211_TX_STATUS_ACK) &&
1367 !is_multicast_ether_addr(hdr->addr1))
1368 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL);
1369
1370 if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) &&
1371 (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT))
1372 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS);
1373 else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS)
1374 rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS);
1375
1376 rthdr->data_retries = status->retry_count;
1377
Michael Wu3d30d942008-01-31 19:48:27 +01001378 /* XXX: is this sufficient for BPF? */
1379 skb_set_mac_header(skb, 0);
1380 skb->ip_summed = CHECKSUM_UNNECESSARY;
1381 skb->pkt_type = PACKET_OTHERHOST;
1382 skb->protocol = htons(ETH_P_802_2);
1383 memset(skb->cb, 0, sizeof(skb->cb));
Johannes Bergb306f452007-07-10 19:32:08 +02001384
Michael Wu3d30d942008-01-31 19:48:27 +01001385 rcu_read_lock();
1386 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg51fb61e2007-12-19 01:31:27 +01001387 if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) {
Johannes Bergb306f452007-07-10 19:32:08 +02001388 if (!netif_running(sdata->dev))
1389 continue;
Michael Wu3d30d942008-01-31 19:48:27 +01001390
1391 if (prev_dev) {
Johannes Berg79010422007-09-18 17:29:21 -04001392 skb2 = skb_clone(skb, GFP_ATOMIC);
Michael Wu3d30d942008-01-31 19:48:27 +01001393 if (skb2) {
1394 skb2->dev = prev_dev;
1395 netif_rx(skb2);
1396 }
1397 }
1398
1399 prev_dev = sdata->dev;
Johannes Bergb306f452007-07-10 19:32:08 +02001400 }
1401 }
Michael Wu3d30d942008-01-31 19:48:27 +01001402 if (prev_dev) {
1403 skb->dev = prev_dev;
1404 netif_rx(skb);
1405 skb = NULL;
1406 }
Johannes Berg79010422007-09-18 17:29:21 -04001407 rcu_read_unlock();
Michael Wu3d30d942008-01-31 19:48:27 +01001408 dev_kfree_skb(skb);
Jiri Bencf0706e82007-05-05 11:45:53 -07001409}
1410EXPORT_SYMBOL(ieee80211_tx_status);
1411
Jiri Bencf0706e82007-05-05 11:45:53 -07001412struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
1413 const struct ieee80211_ops *ops)
1414{
Jiri Bencf0706e82007-05-05 11:45:53 -07001415 struct ieee80211_local *local;
Jiri Bencf0706e82007-05-05 11:45:53 -07001416 int priv_size;
1417 struct wiphy *wiphy;
1418
1419 /* Ensure 32-byte alignment of our private data and hw private data.
1420 * We use the wiphy priv data for both our ieee80211_local and for
1421 * the driver's private data
1422 *
1423 * In memory it'll be like this:
1424 *
1425 * +-------------------------+
1426 * | struct wiphy |
1427 * +-------------------------+
1428 * | struct ieee80211_local |
1429 * +-------------------------+
1430 * | driver's private data |
1431 * +-------------------------+
1432 *
1433 */
1434 priv_size = ((sizeof(struct ieee80211_local) +
1435 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
1436 priv_data_len;
1437
1438 wiphy = wiphy_new(&mac80211_config_ops, priv_size);
1439
1440 if (!wiphy)
1441 return NULL;
1442
1443 wiphy->privid = mac80211_wiphy_privid;
1444
1445 local = wiphy_priv(wiphy);
1446 local->hw.wiphy = wiphy;
1447
1448 local->hw.priv = (char *)local +
1449 ((sizeof(struct ieee80211_local) +
1450 NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
1451
Johannes Berg4480f15c2007-07-10 19:32:10 +02001452 BUG_ON(!ops->tx);
Johannes Berg4150c572007-09-17 01:29:23 -04001453 BUG_ON(!ops->start);
1454 BUG_ON(!ops->stop);
Johannes Berg4480f15c2007-07-10 19:32:10 +02001455 BUG_ON(!ops->config);
1456 BUG_ON(!ops->add_interface);
Johannes Berg4150c572007-09-17 01:29:23 -04001457 BUG_ON(!ops->remove_interface);
1458 BUG_ON(!ops->configure_filter);
Jiri Bencf0706e82007-05-05 11:45:53 -07001459 local->ops = ops;
1460
Jiri Bencf0706e82007-05-05 11:45:53 -07001461 local->hw.queues = 1; /* default */
1462
Jiri Bencf0706e82007-05-05 11:45:53 -07001463 local->bridge_packets = 1;
1464
1465 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1466 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1467 local->short_retry_limit = 7;
1468 local->long_retry_limit = 4;
1469 local->hw.conf.radio_enabled = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001470
Johannes Berg79010422007-09-18 17:29:21 -04001471 INIT_LIST_HEAD(&local->interfaces);
Jiri Bencf0706e82007-05-05 11:45:53 -07001472
1473 INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
Jiri Bencf0706e82007-05-05 11:45:53 -07001474
1475 sta_info_init(local);
1476
Jiri Bencf0706e82007-05-05 11:45:53 -07001477 tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
1478 (unsigned long)local);
1479 tasklet_disable(&local->tx_pending_tasklet);
1480
1481 tasklet_init(&local->tasklet,
1482 ieee80211_tasklet_handler,
1483 (unsigned long) local);
1484 tasklet_disable(&local->tasklet);
1485
1486 skb_queue_head_init(&local->skb_queue);
1487 skb_queue_head_init(&local->skb_queue_unreliable);
1488
1489 return local_to_hw(local);
1490}
1491EXPORT_SYMBOL(ieee80211_alloc_hw);
1492
1493int ieee80211_register_hw(struct ieee80211_hw *hw)
1494{
1495 struct ieee80211_local *local = hw_to_local(hw);
1496 const char *name;
1497 int result;
Johannes Berg8318d782008-01-24 19:38:38 +01001498 enum ieee80211_band band;
Johannes Berg96d51052008-02-08 09:48:13 +01001499 struct net_device *mdev;
1500 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +01001501
1502 /*
1503 * generic code guarantees at least one band,
1504 * set this very early because much code assumes
1505 * that hw.conf.channel is assigned
1506 */
1507 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1508 struct ieee80211_supported_band *sband;
1509
1510 sband = local->hw.wiphy->bands[band];
1511 if (sband) {
1512 /* init channel we're on */
1513 local->hw.conf.channel =
1514 local->oper_channel =
1515 local->scan_channel = &sband->channels[0];
1516 break;
1517 }
1518 }
Jiri Bencf0706e82007-05-05 11:45:53 -07001519
1520 result = wiphy_register(local->hw.wiphy);
1521 if (result < 0)
1522 return result;
1523
Johannes Berg96d51052008-02-08 09:48:13 +01001524 /* for now, mdev needs sub_if_data :/ */
1525 mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
1526 "wmaster%d", ether_setup);
1527 if (!mdev)
1528 goto fail_mdev_alloc;
1529
1530 sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
1531 mdev->ieee80211_ptr = &sdata->wdev;
1532 sdata->wdev.wiphy = local->hw.wiphy;
1533
1534 local->mdev = mdev;
1535
1536 ieee80211_rx_bss_list_init(mdev);
1537
1538 mdev->hard_start_xmit = ieee80211_master_start_xmit;
1539 mdev->open = ieee80211_master_open;
1540 mdev->stop = ieee80211_master_stop;
1541 mdev->type = ARPHRD_IEEE80211;
1542 mdev->header_ops = &ieee80211_header_ops;
1543 mdev->set_multicast_list = ieee80211_master_set_multicast_list;
1544
1545 sdata->vif.type = IEEE80211_IF_TYPE_AP;
1546 sdata->dev = mdev;
1547 sdata->local = local;
1548 sdata->u.ap.force_unicast_rateidx = -1;
1549 sdata->u.ap.max_ratectrl_rateidx = -1;
1550 ieee80211_if_sdata_init(sdata);
1551
1552 /* no RCU needed since we're still during init phase */
1553 list_add_tail(&sdata->list, &local->interfaces);
1554
Jiri Bencf0706e82007-05-05 11:45:53 -07001555 name = wiphy_dev(local->hw.wiphy)->driver->name;
1556 local->hw.workqueue = create_singlethread_workqueue(name);
1557 if (!local->hw.workqueue) {
1558 result = -ENOMEM;
1559 goto fail_workqueue;
1560 }
1561
Johannes Bergb306f452007-07-10 19:32:08 +02001562 /*
1563 * The hardware needs headroom for sending the frame,
1564 * and we need some headroom for passing the frame to monitor
1565 * interfaces, but never both at the same time.
1566 */
Jiri Benc33ccad32007-07-18 17:10:44 +02001567 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1568 sizeof(struct ieee80211_tx_status_rtap_hdr));
Johannes Bergb306f452007-07-10 19:32:08 +02001569
Jiri Bence9f207f2007-05-05 11:46:38 -07001570 debugfs_hw_add(local);
1571
Jiri Bencf0706e82007-05-05 11:45:53 -07001572 local->hw.conf.beacon_int = 1000;
1573
1574 local->wstats_flags |= local->hw.max_rssi ?
1575 IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
1576 local->wstats_flags |= local->hw.max_signal ?
1577 IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
1578 local->wstats_flags |= local->hw.max_noise ?
1579 IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
1580 if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
1581 local->wstats_flags |= IW_QUAL_DBM;
1582
1583 result = sta_info_start(local);
1584 if (result < 0)
1585 goto fail_sta_info;
1586
1587 rtnl_lock();
1588 result = dev_alloc_name(local->mdev, local->mdev->name);
1589 if (result < 0)
1590 goto fail_dev;
1591
1592 memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
1593 SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
1594
1595 result = register_netdevice(local->mdev);
1596 if (result < 0)
1597 goto fail_dev;
1598
Jiri Bence9f207f2007-05-05 11:46:38 -07001599 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Johannes Berg5b2812e2007-09-26 14:27:23 +02001600 ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP);
Jiri Bence9f207f2007-05-05 11:46:38 -07001601
Johannes Berg830f9032007-10-28 14:51:05 +01001602 result = ieee80211_init_rate_ctrl_alg(local,
1603 hw->rate_control_algorithm);
Jiri Bencf0706e82007-05-05 11:45:53 -07001604 if (result < 0) {
1605 printk(KERN_DEBUG "%s: Failed to initialize rate control "
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001606 "algorithm\n", wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001607 goto fail_rate;
1608 }
1609
1610 result = ieee80211_wep_init(local);
1611
1612 if (result < 0) {
1613 printk(KERN_DEBUG "%s: Failed to initialize wep\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001614 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001615 goto fail_wep;
1616 }
1617
1618 ieee80211_install_qdisc(local->mdev);
1619
1620 /* add one default STA interface */
1621 result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
1622 IEEE80211_IF_TYPE_STA);
1623 if (result)
1624 printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001625 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001626
1627 local->reg_state = IEEE80211_DEV_REGISTERED;
1628 rtnl_unlock();
1629
1630 ieee80211_led_init(local);
1631
1632 return 0;
1633
1634fail_wep:
1635 rate_control_deinitialize(local);
1636fail_rate:
Jiri Bence9f207f2007-05-05 11:46:38 -07001637 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001638 unregister_netdevice(local->mdev);
1639fail_dev:
1640 rtnl_unlock();
1641 sta_info_stop(local);
1642fail_sta_info:
Jiri Bence9f207f2007-05-05 11:46:38 -07001643 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001644 destroy_workqueue(local->hw.workqueue);
1645fail_workqueue:
Johannes Berg96d51052008-02-08 09:48:13 +01001646 ieee80211_if_free(local->mdev);
1647 local->mdev = NULL;
1648fail_mdev_alloc:
Jiri Bencf0706e82007-05-05 11:45:53 -07001649 wiphy_unregister(local->hw.wiphy);
1650 return result;
1651}
1652EXPORT_SYMBOL(ieee80211_register_hw);
1653
Jiri Bencf0706e82007-05-05 11:45:53 -07001654void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1655{
1656 struct ieee80211_local *local = hw_to_local(hw);
1657 struct ieee80211_sub_if_data *sdata, *tmp;
Jiri Bencf0706e82007-05-05 11:45:53 -07001658
1659 tasklet_kill(&local->tx_pending_tasklet);
1660 tasklet_kill(&local->tasklet);
1661
1662 rtnl_lock();
1663
1664 BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
1665
1666 local->reg_state = IEEE80211_DEV_UNREGISTERED;
Jiri Bencf0706e82007-05-05 11:45:53 -07001667
Johannes Berg79010422007-09-18 17:29:21 -04001668 /*
1669 * At this point, interface list manipulations are fine
1670 * because the driver cannot be handing us frames any
1671 * more and the tasklet is killed.
1672 */
Johannes Berg5b2812e2007-09-26 14:27:23 +02001673
1674 /*
1675 * First, we remove all non-master interfaces. Do this because they
1676 * may have bss pointer dependency on the master, and when we free
1677 * the master these would be freed as well, breaking our list
1678 * iteration completely.
1679 */
1680 list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) {
1681 if (sdata->dev == local->mdev)
1682 continue;
1683 list_del(&sdata->list);
Jiri Bencf0706e82007-05-05 11:45:53 -07001684 __ieee80211_if_del(local, sdata);
Johannes Berg5b2812e2007-09-26 14:27:23 +02001685 }
1686
1687 /* then, finally, remove the master interface */
1688 __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev));
Jiri Bencf0706e82007-05-05 11:45:53 -07001689
1690 rtnl_unlock();
1691
Jiri Bencf0706e82007-05-05 11:45:53 -07001692 ieee80211_rx_bss_list_deinit(local->mdev);
1693 ieee80211_clear_tx_pending(local);
1694 sta_info_stop(local);
1695 rate_control_deinitialize(local);
Jiri Bence9f207f2007-05-05 11:46:38 -07001696 debugfs_hw_del(local);
Jiri Bencf0706e82007-05-05 11:45:53 -07001697
Jiri Bencf0706e82007-05-05 11:45:53 -07001698 if (skb_queue_len(&local->skb_queue)
1699 || skb_queue_len(&local->skb_queue_unreliable))
1700 printk(KERN_WARNING "%s: skb_queue not empty\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001701 wiphy_name(local->hw.wiphy));
Jiri Bencf0706e82007-05-05 11:45:53 -07001702 skb_queue_purge(&local->skb_queue);
1703 skb_queue_purge(&local->skb_queue_unreliable);
1704
1705 destroy_workqueue(local->hw.workqueue);
1706 wiphy_unregister(local->hw.wiphy);
1707 ieee80211_wep_free(local);
1708 ieee80211_led_exit(local);
Johannes Berg96d51052008-02-08 09:48:13 +01001709 ieee80211_if_free(local->mdev);
1710 local->mdev = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -07001711}
1712EXPORT_SYMBOL(ieee80211_unregister_hw);
1713
1714void ieee80211_free_hw(struct ieee80211_hw *hw)
1715{
1716 struct ieee80211_local *local = hw_to_local(hw);
1717
Jiri Bencf0706e82007-05-05 11:45:53 -07001718 wiphy_free(local->hw.wiphy);
1719}
1720EXPORT_SYMBOL(ieee80211_free_hw);
1721
Jiri Bencf0706e82007-05-05 11:45:53 -07001722static int __init ieee80211_init(void)
1723{
1724 struct sk_buff *skb;
1725 int ret;
1726
1727 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
1728
Johannes Berg4b475892008-01-02 15:17:03 +01001729 ret = rc80211_simple_init();
Johannes Bergac71c692007-10-28 14:17:44 +01001730 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001731 goto out;
Mattias Nisslerad018372007-12-19 01:25:57 +01001732
Johannes Berg4b475892008-01-02 15:17:03 +01001733 ret = rc80211_pid_init();
Mattias Nisslerad018372007-12-19 01:25:57 +01001734 if (ret)
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001735 goto out_cleanup_simple;
Johannes Bergac71c692007-10-28 14:17:44 +01001736
Jiri Bencf0706e82007-05-05 11:45:53 -07001737 ret = ieee80211_wme_register();
1738 if (ret) {
1739 printk(KERN_DEBUG "ieee80211_init: failed to "
1740 "initialize WME (err=%d)\n", ret);
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001741 goto out_cleanup_pid;
Jiri Bencf0706e82007-05-05 11:45:53 -07001742 }
1743
Jiri Bence9f207f2007-05-05 11:46:38 -07001744 ieee80211_debugfs_netdev_init();
1745
Jiri Bencf0706e82007-05-05 11:45:53 -07001746 return 0;
Mattias Nisslerad018372007-12-19 01:25:57 +01001747
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001748 out_cleanup_pid:
Johannes Berg4b475892008-01-02 15:17:03 +01001749 rc80211_pid_exit();
Johannes Berg3eadf5f2008-01-31 19:33:53 +01001750 out_cleanup_simple:
1751 rc80211_simple_exit();
1752 out:
Mattias Nisslerad018372007-12-19 01:25:57 +01001753 return ret;
Jiri Bencf0706e82007-05-05 11:45:53 -07001754}
1755
Jiri Bencf0706e82007-05-05 11:45:53 -07001756static void __exit ieee80211_exit(void)
1757{
Johannes Berg4b475892008-01-02 15:17:03 +01001758 rc80211_simple_exit();
1759 rc80211_pid_exit();
Johannes Bergac71c692007-10-28 14:17:44 +01001760
Jiri Bencf0706e82007-05-05 11:45:53 -07001761 ieee80211_wme_unregister();
Jiri Bence9f207f2007-05-05 11:46:38 -07001762 ieee80211_debugfs_netdev_exit();
Jiri Bencf0706e82007-05-05 11:45:53 -07001763}
1764
1765
Johannes Bergca9938f2007-09-11 12:50:32 +02001766subsys_initcall(ieee80211_init);
Jiri Bencf0706e82007-05-05 11:45:53 -07001767module_exit(ieee80211_exit);
1768
1769MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1770MODULE_LICENSE("GPL");