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