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