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) | |
8cc9a739 MW |
70 | new_flags |= FIF_BCN_PRBRESP_PROMISC; |
71 | ||
72 | if (local->fif_fcsfail) | |
73 | new_flags |= FIF_FCSFAIL; | |
74 | ||
75 | if (local->fif_plcpfail) | |
76 | new_flags |= FIF_PLCPFAIL; | |
77 | ||
78 | if (local->fif_control) | |
79 | new_flags |= FIF_CONTROL; | |
80 | ||
81 | if (local->fif_other_bss) | |
82 | new_flags |= FIF_OTHER_BSS; | |
4150c572 JB |
83 | |
84 | changed_flags = local->filter_flags ^ new_flags; | |
85 | ||
86 | /* be a bit nasty */ | |
87 | new_flags |= (1<<31); | |
88 | ||
89 | local->ops->configure_filter(local_to_hw(local), | |
90 | changed_flags, &new_flags, | |
91 | local->mdev->mc_count, | |
92 | local->mdev->mc_list); | |
93 | ||
94 | WARN_ON(new_flags & (1<<31)); | |
95 | ||
96 | local->filter_flags = new_flags & ~(1<<31); | |
97 | } | |
98 | ||
b2c258fb | 99 | /* master interface */ |
f0706e82 | 100 | |
b2c258fb JB |
101 | static int ieee80211_master_open(struct net_device *dev) |
102 | { | |
103 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
104 | struct ieee80211_sub_if_data *sdata; | |
105 | int res = -EOPNOTSUPP; | |
f0706e82 | 106 | |
79010420 JB |
107 | /* we hold the RTNL here so can safely walk the list */ |
108 | list_for_each_entry(sdata, &local->interfaces, list) { | |
b2c258fb JB |
109 | if (sdata->dev != dev && netif_running(sdata->dev)) { |
110 | res = 0; | |
111 | break; | |
112 | } | |
113 | } | |
b2c258fb JB |
114 | return res; |
115 | } | |
f0706e82 | 116 | |
b2c258fb | 117 | static int ieee80211_master_stop(struct net_device *dev) |
f0706e82 | 118 | { |
b2c258fb JB |
119 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
120 | struct ieee80211_sub_if_data *sdata; | |
f0706e82 | 121 | |
79010420 JB |
122 | /* we hold the RTNL here so can safely walk the list */ |
123 | list_for_each_entry(sdata, &local->interfaces, list) | |
b2c258fb JB |
124 | if (sdata->dev != dev && netif_running(sdata->dev)) |
125 | dev_close(sdata->dev); | |
f0706e82 | 126 | |
b2c258fb JB |
127 | return 0; |
128 | } | |
f0706e82 | 129 | |
4150c572 JB |
130 | static void ieee80211_master_set_multicast_list(struct net_device *dev) |
131 | { | |
132 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
133 | ||
134 | ieee80211_configure_filter(local); | |
135 | } | |
136 | ||
b2c258fb | 137 | /* regular interfaces */ |
f0706e82 | 138 | |
b2c258fb | 139 | static int ieee80211_change_mtu(struct net_device *dev, int new_mtu) |
f0706e82 | 140 | { |
b2c258fb JB |
141 | /* FIX: what would be proper limits for MTU? |
142 | * This interface uses 802.3 frames. */ | |
143 | if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) { | |
144 | printk(KERN_WARNING "%s: invalid MTU %d\n", | |
145 | dev->name, new_mtu); | |
146 | return -EINVAL; | |
147 | } | |
f0706e82 | 148 | |
b2c258fb JB |
149 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
150 | printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); | |
151 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ | |
152 | dev->mtu = new_mtu; | |
f0706e82 JB |
153 | return 0; |
154 | } | |
155 | ||
b2c258fb JB |
156 | static inline int identical_mac_addr_allowed(int type1, int type2) |
157 | { | |
158 | return (type1 == IEEE80211_IF_TYPE_MNTR || | |
159 | type2 == IEEE80211_IF_TYPE_MNTR || | |
160 | (type1 == IEEE80211_IF_TYPE_AP && | |
161 | type2 == IEEE80211_IF_TYPE_WDS) || | |
162 | (type1 == IEEE80211_IF_TYPE_WDS && | |
163 | (type2 == IEEE80211_IF_TYPE_WDS || | |
164 | type2 == IEEE80211_IF_TYPE_AP)) || | |
165 | (type1 == IEEE80211_IF_TYPE_AP && | |
166 | type2 == IEEE80211_IF_TYPE_VLAN) || | |
167 | (type1 == IEEE80211_IF_TYPE_VLAN && | |
168 | (type2 == IEEE80211_IF_TYPE_AP || | |
169 | type2 == IEEE80211_IF_TYPE_VLAN))); | |
170 | } | |
f0706e82 | 171 | |
b2c258fb | 172 | static int ieee80211_open(struct net_device *dev) |
e2ebc74d | 173 | { |
b2c258fb JB |
174 | struct ieee80211_sub_if_data *sdata, *nsdata; |
175 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
176 | struct ieee80211_if_init_conf conf; | |
177 | int res; | |
ceffefd1 | 178 | bool need_hw_reconfig = 0; |
f0706e82 | 179 | |
b2c258fb | 180 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
0ec3ca44 | 181 | |
79010420 JB |
182 | /* we hold the RTNL here so can safely walk the list */ |
183 | list_for_each_entry(nsdata, &local->interfaces, list) { | |
b2c258fb | 184 | struct net_device *ndev = nsdata->dev; |
e2ebc74d | 185 | |
665e8aaf JB |
186 | if (ndev != dev && ndev != local->mdev && netif_running(ndev)) { |
187 | /* | |
188 | * Allow only a single IBSS interface to be up at any | |
189 | * time. This is restricted because beacon distribution | |
190 | * cannot work properly if both are in the same IBSS. | |
191 | * | |
192 | * To remove this restriction we'd have to disallow them | |
193 | * from setting the same SSID on different IBSS interfaces | |
194 | * belonging to the same hardware. Then, however, we're | |
195 | * faced with having to adopt two different TSF timers... | |
196 | */ | |
197 | if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS && | |
198 | nsdata->vif.type == IEEE80211_IF_TYPE_IBSS) | |
199 | return -EBUSY; | |
200 | ||
201 | /* | |
202 | * Disallow multiple IBSS/STA mode interfaces. | |
203 | * | |
204 | * This is a technical restriction, it is possible although | |
205 | * most likely not IEEE 802.11 compliant to have multiple | |
206 | * STAs with just a single hardware (the TSF timer will not | |
207 | * be adjusted properly.) | |
208 | * | |
209 | * However, because mac80211 uses the master device's BSS | |
210 | * information for each STA/IBSS interface, doing this will | |
211 | * currently corrupt that BSS information completely, unless, | |
212 | * a not very useful case, both STAs are associated to the | |
213 | * same BSS. | |
214 | * | |
215 | * To remove this restriction, the BSS information needs to | |
216 | * be embedded in the STA/IBSS mode sdata instead of using | |
217 | * the master device's BSS structure. | |
218 | */ | |
219 | if ((sdata->vif.type == IEEE80211_IF_TYPE_STA || | |
220 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) && | |
221 | (nsdata->vif.type == IEEE80211_IF_TYPE_STA || | |
222 | nsdata->vif.type == IEEE80211_IF_TYPE_IBSS)) | |
223 | return -EBUSY; | |
224 | ||
225 | /* | |
226 | * The remaining checks are only performed for interfaces | |
227 | * with the same MAC address. | |
228 | */ | |
229 | if (compare_ether_addr(dev->dev_addr, ndev->dev_addr)) | |
230 | continue; | |
231 | ||
0ec3ca44 JB |
232 | /* |
233 | * check whether it may have the same address | |
234 | */ | |
51fb61e7 JB |
235 | if (!identical_mac_addr_allowed(sdata->vif.type, |
236 | nsdata->vif.type)) | |
0ec3ca44 | 237 | return -ENOTUNIQ; |
0ec3ca44 JB |
238 | |
239 | /* | |
240 | * can only add VLANs to enabled APs | |
241 | */ | |
51fb61e7 | 242 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN && |
665e8aaf | 243 | nsdata->vif.type == IEEE80211_IF_TYPE_AP) |
0ec3ca44 | 244 | sdata->u.vlan.ap = nsdata; |
b2c258fb JB |
245 | } |
246 | } | |
f0706e82 | 247 | |
51fb61e7 | 248 | switch (sdata->vif.type) { |
0ec3ca44 JB |
249 | case IEEE80211_IF_TYPE_WDS: |
250 | if (is_zero_ether_addr(sdata->u.wds.remote_addr)) | |
251 | return -ENOLINK; | |
252 | break; | |
253 | case IEEE80211_IF_TYPE_VLAN: | |
254 | if (!sdata->u.vlan.ap) | |
255 | return -ENOLINK; | |
256 | break; | |
fb1c1cd6 | 257 | case IEEE80211_IF_TYPE_AP: |
fb1c1cd6 JB |
258 | case IEEE80211_IF_TYPE_STA: |
259 | case IEEE80211_IF_TYPE_MNTR: | |
260 | case IEEE80211_IF_TYPE_IBSS: | |
261 | /* no special treatment */ | |
262 | break; | |
a2897552 JB |
263 | case IEEE80211_IF_TYPE_INVALID: |
264 | /* cannot happen */ | |
265 | WARN_ON(1); | |
266 | break; | |
0ec3ca44 | 267 | } |
f0706e82 | 268 | |
b2c258fb JB |
269 | if (local->open_count == 0) { |
270 | res = 0; | |
4150c572 JB |
271 | if (local->ops->start) |
272 | res = local->ops->start(local_to_hw(local)); | |
273 | if (res) | |
b2c258fb | 274 | return res; |
ceffefd1 | 275 | need_hw_reconfig = 1; |
cdcb006f | 276 | ieee80211_led_radio(local, local->hw.conf.radio_enabled); |
b2c258fb | 277 | } |
f0706e82 | 278 | |
51fb61e7 | 279 | switch (sdata->vif.type) { |
0ec3ca44 JB |
280 | case IEEE80211_IF_TYPE_VLAN: |
281 | list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans); | |
282 | /* no need to tell driver */ | |
283 | break; | |
4150c572 | 284 | case IEEE80211_IF_TYPE_MNTR: |
3d30d949 MW |
285 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
286 | local->cooked_mntrs++; | |
287 | break; | |
288 | } | |
289 | ||
4150c572 | 290 | /* must be before the call to ieee80211_configure_filter */ |
b2c258fb | 291 | local->monitors++; |
8cc9a739 | 292 | if (local->monitors == 1) |
4150c572 | 293 | local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP; |
8cc9a739 MW |
294 | |
295 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | |
296 | local->fif_fcsfail++; | |
297 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | |
298 | local->fif_plcpfail++; | |
299 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | |
300 | local->fif_control++; | |
301 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | |
302 | local->fif_other_bss++; | |
303 | ||
304 | netif_tx_lock_bh(local->mdev); | |
305 | ieee80211_configure_filter(local); | |
306 | netif_tx_unlock_bh(local->mdev); | |
4150c572 JB |
307 | break; |
308 | case IEEE80211_IF_TYPE_STA: | |
309 | case IEEE80211_IF_TYPE_IBSS: | |
310 | sdata->u.sta.flags &= ~IEEE80211_STA_PREV_BSSID_SET; | |
311 | /* fall through */ | |
312 | default: | |
32bfd35d | 313 | conf.vif = &sdata->vif; |
51fb61e7 | 314 | conf.type = sdata->vif.type; |
4150c572 JB |
315 | conf.mac_addr = dev->dev_addr; |
316 | res = local->ops->add_interface(local_to_hw(local), &conf); | |
317 | if (res && !local->open_count && local->ops->stop) | |
318 | local->ops->stop(local_to_hw(local)); | |
319 | if (res) | |
320 | return res; | |
321 | ||
b2c258fb | 322 | ieee80211_if_config(dev); |
d9430a32 | 323 | ieee80211_reset_erp_info(dev); |
11a843b7 | 324 | ieee80211_enable_keys(sdata); |
4150c572 | 325 | |
51fb61e7 | 326 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA && |
ddd3d2be | 327 | !(sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)) |
4150c572 JB |
328 | netif_carrier_off(dev); |
329 | else | |
330 | netif_carrier_on(dev); | |
d9430a32 | 331 | } |
f0706e82 | 332 | |
4150c572 JB |
333 | if (local->open_count == 0) { |
334 | res = dev_open(local->mdev); | |
335 | WARN_ON(res); | |
4150c572 JB |
336 | tasklet_enable(&local->tx_pending_tasklet); |
337 | tasklet_enable(&local->tasklet); | |
338 | } | |
339 | ||
c1428b3f JB |
340 | /* |
341 | * set_multicast_list will be invoked by the networking core | |
342 | * which will check whether any increments here were done in | |
343 | * error and sync them down to the hardware as filter flags. | |
344 | */ | |
345 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
346 | atomic_inc(&local->iff_allmultis); | |
347 | ||
348 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
349 | atomic_inc(&local->iff_promiscs); | |
350 | ||
4150c572 | 351 | local->open_count++; |
ceffefd1 MB |
352 | if (need_hw_reconfig) |
353 | ieee80211_hw_config(local); | |
f0706e82 | 354 | |
b2c258fb | 355 | netif_start_queue(dev); |
4150c572 | 356 | |
b2c258fb | 357 | return 0; |
f0706e82 | 358 | } |
f0706e82 | 359 | |
4150c572 | 360 | static int ieee80211_stop(struct net_device *dev) |
f0706e82 | 361 | { |
4150c572 | 362 | struct ieee80211_sub_if_data *sdata; |
f0706e82 | 363 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
4150c572 | 364 | struct ieee80211_if_init_conf conf; |
07db2183 RR |
365 | struct sta_info *sta; |
366 | int i; | |
4150c572 JB |
367 | |
368 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
369 | ||
07db2183 | 370 | list_for_each_entry(sta, &local->sta_list, list) { |
5b3d71d9 RR |
371 | if (sta->dev == dev) |
372 | for (i = 0; i < STA_TID_NUM; i++) | |
373 | ieee80211_sta_stop_rx_ba_session(sta->dev, | |
374 | sta->addr, i, | |
375 | WLAN_BACK_RECIPIENT, | |
07db2183 RR |
376 | WLAN_REASON_QSTA_LEAVE_QBSS); |
377 | } | |
378 | ||
4150c572 JB |
379 | netif_stop_queue(dev); |
380 | ||
c1428b3f JB |
381 | /* |
382 | * Don't count this interface for promisc/allmulti while it | |
383 | * is down. dev_mc_unsync() will invoke set_multicast_list | |
384 | * on the master interface which will sync these down to the | |
385 | * hardware as filter flags. | |
386 | */ | |
387 | if (sdata->flags & IEEE80211_SDATA_ALLMULTI) | |
388 | atomic_dec(&local->iff_allmultis); | |
389 | ||
390 | if (sdata->flags & IEEE80211_SDATA_PROMISC) | |
391 | atomic_dec(&local->iff_promiscs); | |
392 | ||
4150c572 JB |
393 | dev_mc_unsync(local->mdev, dev); |
394 | ||
5dfdaf58 | 395 | /* APs need special treatment */ |
51fb61e7 | 396 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
0ec3ca44 | 397 | struct ieee80211_sub_if_data *vlan, *tmp; |
5dfdaf58 | 398 | struct beacon_data *old_beacon = sdata->u.ap.beacon; |
0ec3ca44 | 399 | |
5dfdaf58 JB |
400 | /* remove beacon */ |
401 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | |
402 | synchronize_rcu(); | |
403 | kfree(old_beacon); | |
404 | ||
405 | /* down all dependent devices, that is VLANs */ | |
0ec3ca44 JB |
406 | list_for_each_entry_safe(vlan, tmp, &sdata->u.ap.vlans, |
407 | u.vlan.list) | |
408 | dev_close(vlan->dev); | |
409 | WARN_ON(!list_empty(&sdata->u.ap.vlans)); | |
410 | } | |
411 | ||
4150c572 | 412 | local->open_count--; |
f0706e82 | 413 | |
51fb61e7 | 414 | switch (sdata->vif.type) { |
0ec3ca44 JB |
415 | case IEEE80211_IF_TYPE_VLAN: |
416 | list_del(&sdata->u.vlan.list); | |
417 | sdata->u.vlan.ap = NULL; | |
418 | /* no need to tell driver */ | |
419 | break; | |
4150c572 | 420 | case IEEE80211_IF_TYPE_MNTR: |
3d30d949 MW |
421 | if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES) { |
422 | local->cooked_mntrs--; | |
423 | break; | |
424 | } | |
425 | ||
4150c572 | 426 | local->monitors--; |
8cc9a739 | 427 | if (local->monitors == 0) |
8b393f1d | 428 | local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP; |
8cc9a739 MW |
429 | |
430 | if (sdata->u.mntr_flags & MONITOR_FLAG_FCSFAIL) | |
431 | local->fif_fcsfail--; | |
432 | if (sdata->u.mntr_flags & MONITOR_FLAG_PLCPFAIL) | |
433 | local->fif_plcpfail--; | |
434 | if (sdata->u.mntr_flags & MONITOR_FLAG_CONTROL) | |
435 | local->fif_control--; | |
436 | if (sdata->u.mntr_flags & MONITOR_FLAG_OTHER_BSS) | |
437 | local->fif_other_bss--; | |
438 | ||
439 | netif_tx_lock_bh(local->mdev); | |
440 | ieee80211_configure_filter(local); | |
441 | netif_tx_unlock_bh(local->mdev); | |
4150c572 | 442 | break; |
b2c258fb JB |
443 | case IEEE80211_IF_TYPE_STA: |
444 | case IEEE80211_IF_TYPE_IBSS: | |
445 | sdata->u.sta.state = IEEE80211_DISABLED; | |
446 | del_timer_sync(&sdata->u.sta.timer); | |
2a8a9a88 | 447 | /* |
79010420 JB |
448 | * When we get here, the interface is marked down. |
449 | * Call synchronize_rcu() to wait for the RX path | |
450 | * should it be using the interface and enqueuing | |
451 | * frames at this very time on another CPU. | |
2a8a9a88 | 452 | */ |
79010420 | 453 | synchronize_rcu(); |
b2c258fb | 454 | skb_queue_purge(&sdata->u.sta.skb_queue); |
2a8a9a88 | 455 | |
ece8eddd ZY |
456 | if (local->scan_dev == sdata->dev) { |
457 | if (!local->ops->hw_scan) { | |
458 | local->sta_sw_scanning = 0; | |
459 | cancel_delayed_work(&local->scan_work); | |
460 | } else | |
461 | local->sta_hw_scanning = 0; | |
b2c258fb | 462 | } |
ece8eddd | 463 | |
b2c258fb | 464 | flush_workqueue(local->hw.workqueue); |
a10605e5 ZY |
465 | |
466 | sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED; | |
467 | kfree(sdata->u.sta.extra_ie); | |
468 | sdata->u.sta.extra_ie = NULL; | |
469 | sdata->u.sta.extra_ie_len = 0; | |
4150c572 JB |
470 | /* fall through */ |
471 | default: | |
32bfd35d | 472 | conf.vif = &sdata->vif; |
51fb61e7 | 473 | conf.type = sdata->vif.type; |
4150c572 | 474 | conf.mac_addr = dev->dev_addr; |
11a843b7 JB |
475 | /* disable all keys for as long as this netdev is down */ |
476 | ieee80211_disable_keys(sdata); | |
4150c572 | 477 | local->ops->remove_interface(local_to_hw(local), &conf); |
f0706e82 JB |
478 | } |
479 | ||
b2c258fb JB |
480 | if (local->open_count == 0) { |
481 | if (netif_running(local->mdev)) | |
482 | dev_close(local->mdev); | |
4150c572 | 483 | |
b2c258fb JB |
484 | if (local->ops->stop) |
485 | local->ops->stop(local_to_hw(local)); | |
4150c572 | 486 | |
cdcb006f ID |
487 | ieee80211_led_radio(local, 0); |
488 | ||
b2c258fb JB |
489 | tasklet_disable(&local->tx_pending_tasklet); |
490 | tasklet_disable(&local->tasklet); | |
491 | } | |
b2c258fb | 492 | |
f0706e82 JB |
493 | return 0; |
494 | } | |
495 | ||
eadc8d9e RR |
496 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
497 | { | |
498 | struct ieee80211_local *local = hw_to_local(hw); | |
499 | struct sta_info *sta; | |
500 | struct ieee80211_sub_if_data *sdata; | |
501 | u16 start_seq_num = 0; | |
502 | u8 *state; | |
503 | int ret; | |
504 | DECLARE_MAC_BUF(mac); | |
505 | ||
506 | if (tid >= STA_TID_NUM) | |
507 | return -EINVAL; | |
508 | ||
509 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
510 | printk(KERN_DEBUG "Open BA session requested for %s tid %u\n", | |
511 | print_mac(mac, ra), tid); | |
512 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
513 | ||
514 | sta = sta_info_get(local, ra); | |
515 | if (!sta) { | |
516 | printk(KERN_DEBUG "Could not find the station\n"); | |
517 | return -ENOENT; | |
518 | } | |
519 | ||
520 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
521 | ||
522 | /* we have tried too many times, receiver does not want A-MPDU */ | |
523 | if (sta->ampdu_mlme.tid_tx[tid].addba_req_num > HT_AGG_MAX_RETRIES) { | |
524 | ret = -EBUSY; | |
525 | goto start_ba_exit; | |
526 | } | |
527 | ||
528 | state = &sta->ampdu_mlme.tid_tx[tid].state; | |
529 | /* check if the TID is not in aggregation flow already */ | |
530 | if (*state != HT_AGG_STATE_IDLE) { | |
531 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
532 | printk(KERN_DEBUG "BA request denied - session is not " | |
533 | "idle on tid %u\n", tid); | |
534 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
535 | ret = -EAGAIN; | |
536 | goto start_ba_exit; | |
537 | } | |
538 | ||
539 | /* ensure that TX flow won't interrupt us | |
540 | * until the end of the call to requeue function */ | |
541 | spin_lock_bh(&local->mdev->queue_lock); | |
542 | ||
543 | /* create a new queue for this aggregation */ | |
9e723492 | 544 | ret = ieee80211_ht_agg_queue_add(local, sta, tid); |
eadc8d9e RR |
545 | |
546 | /* case no queue is available to aggregation | |
547 | * don't switch to aggregation */ | |
548 | if (ret) { | |
549 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
550 | printk(KERN_DEBUG "BA request denied - no queue available for" | |
551 | " tid %d\n", tid); | |
552 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
553 | spin_unlock_bh(&local->mdev->queue_lock); | |
554 | goto start_ba_exit; | |
555 | } | |
556 | sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev); | |
557 | ||
558 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the | |
559 | * call back right away, it must see that the flow has begun */ | |
560 | *state |= HT_ADDBA_REQUESTED_MSK; | |
561 | ||
562 | if (local->ops->ampdu_action) | |
563 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, | |
564 | ra, tid, &start_seq_num); | |
565 | ||
566 | if (ret) { | |
567 | /* No need to requeue the packets in the agg queue, since we | |
568 | * held the tx lock: no packet could be enqueued to the newly | |
569 | * allocated queue */ | |
9e723492 | 570 | ieee80211_ht_agg_queue_remove(local, sta, tid, 0); |
eadc8d9e RR |
571 | #ifdef CONFIG_MAC80211_HT_DEBUG |
572 | printk(KERN_DEBUG "BA request denied - HW or queue unavailable" | |
573 | " for tid %d\n", tid); | |
574 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
575 | spin_unlock_bh(&local->mdev->queue_lock); | |
576 | *state = HT_AGG_STATE_IDLE; | |
577 | goto start_ba_exit; | |
578 | } | |
579 | ||
580 | /* Will put all the packets in the new SW queue */ | |
9e723492 | 581 | ieee80211_requeue(local, ieee802_1d_to_ac[tid]); |
eadc8d9e RR |
582 | spin_unlock_bh(&local->mdev->queue_lock); |
583 | ||
584 | /* We have most probably almost emptied the legacy queue */ | |
585 | /* ieee80211_wake_queue(local_to_hw(local), ieee802_1d_to_ac[tid]); */ | |
586 | ||
587 | /* send an addBA request */ | |
588 | sta->ampdu_mlme.dialog_token_allocator++; | |
589 | sta->ampdu_mlme.tid_tx[tid].dialog_token = | |
590 | sta->ampdu_mlme.dialog_token_allocator; | |
591 | sta->ampdu_mlme.tid_tx[tid].ssn = start_seq_num; | |
592 | ||
593 | ieee80211_send_addba_request(sta->dev, ra, tid, | |
594 | sta->ampdu_mlme.tid_tx[tid].dialog_token, | |
595 | sta->ampdu_mlme.tid_tx[tid].ssn, | |
596 | 0x40, 5000); | |
597 | ||
598 | /* activate the timer for the recipient's addBA response */ | |
599 | sta->ampdu_mlme.tid_tx[tid].addba_resp_timer.expires = | |
600 | jiffies + ADDBA_RESP_INTERVAL; | |
601 | add_timer(&sta->ampdu_mlme.tid_tx[tid].addba_resp_timer); | |
602 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); | |
603 | ||
604 | start_ba_exit: | |
605 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
606 | sta_info_put(sta); | |
607 | return ret; | |
608 | } | |
609 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); | |
610 | ||
611 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, | |
612 | u8 *ra, u16 tid, | |
613 | enum ieee80211_back_parties initiator) | |
614 | { | |
615 | struct ieee80211_local *local = hw_to_local(hw); | |
616 | struct sta_info *sta; | |
617 | u8 *state; | |
618 | int ret = 0; | |
619 | DECLARE_MAC_BUF(mac); | |
620 | ||
621 | if (tid >= STA_TID_NUM) | |
622 | return -EINVAL; | |
623 | ||
624 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
625 | printk(KERN_DEBUG "Stop a BA session requested for %s tid %u\n", | |
626 | print_mac(mac, ra), tid); | |
627 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
628 | ||
629 | sta = sta_info_get(local, ra); | |
630 | if (!sta) | |
631 | return -ENOENT; | |
632 | ||
633 | /* check if the TID is in aggregation */ | |
634 | state = &sta->ampdu_mlme.tid_tx[tid].state; | |
635 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
636 | ||
637 | if (*state != HT_AGG_STATE_OPERATIONAL) { | |
638 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
639 | printk(KERN_DEBUG "Try to stop Tx aggregation on" | |
640 | " non active TID\n"); | |
641 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
642 | ret = -ENOENT; | |
643 | goto stop_BA_exit; | |
644 | } | |
645 | ||
646 | ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]); | |
647 | ||
648 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | | |
649 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); | |
650 | ||
651 | if (local->ops->ampdu_action) | |
652 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP, | |
653 | ra, tid, NULL); | |
654 | ||
655 | /* case HW denied going back to legacy */ | |
656 | if (ret) { | |
657 | WARN_ON(ret != -EBUSY); | |
658 | *state = HT_AGG_STATE_OPERATIONAL; | |
659 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
660 | goto stop_BA_exit; | |
661 | } | |
662 | ||
663 | stop_BA_exit: | |
664 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
665 | sta_info_put(sta); | |
666 | return ret; | |
667 | } | |
668 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); | |
669 | ||
670 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) | |
671 | { | |
672 | struct ieee80211_local *local = hw_to_local(hw); | |
673 | struct sta_info *sta; | |
674 | u8 *state; | |
675 | DECLARE_MAC_BUF(mac); | |
676 | ||
677 | if (tid >= STA_TID_NUM) { | |
678 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
679 | tid, STA_TID_NUM); | |
680 | return; | |
681 | } | |
682 | ||
683 | sta = sta_info_get(local, ra); | |
684 | if (!sta) { | |
685 | printk(KERN_DEBUG "Could not find station: %s\n", | |
686 | print_mac(mac, ra)); | |
687 | return; | |
688 | } | |
689 | ||
690 | state = &sta->ampdu_mlme.tid_tx[tid].state; | |
691 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
692 | ||
693 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { | |
694 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", | |
695 | *state); | |
696 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
697 | sta_info_put(sta); | |
698 | return; | |
699 | } | |
700 | ||
701 | WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK); | |
702 | ||
703 | *state |= HT_ADDBA_DRV_READY_MSK; | |
704 | ||
705 | if (*state == HT_AGG_STATE_OPERATIONAL) { | |
706 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); | |
707 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
708 | } | |
709 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
710 | sta_info_put(sta); | |
711 | } | |
712 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); | |
713 | ||
714 | void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) | |
715 | { | |
716 | struct ieee80211_local *local = hw_to_local(hw); | |
717 | struct sta_info *sta; | |
718 | u8 *state; | |
719 | int agg_queue; | |
720 | DECLARE_MAC_BUF(mac); | |
721 | ||
722 | if (tid >= STA_TID_NUM) { | |
723 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
724 | tid, STA_TID_NUM); | |
725 | return; | |
726 | } | |
727 | ||
728 | printk(KERN_DEBUG "Stop a BA session requested on DA %s tid %d\n", | |
729 | print_mac(mac, ra), tid); | |
730 | ||
731 | sta = sta_info_get(local, ra); | |
732 | if (!sta) { | |
733 | printk(KERN_DEBUG "Could not find station: %s\n", | |
734 | print_mac(mac, ra)); | |
735 | return; | |
736 | } | |
737 | state = &sta->ampdu_mlme.tid_tx[tid].state; | |
738 | ||
739 | spin_lock_bh(&sta->ampdu_mlme.ampdu_tx); | |
740 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { | |
741 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); | |
742 | sta_info_put(sta); | |
743 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
744 | return; | |
745 | } | |
746 | ||
747 | if (*state & HT_AGG_STATE_INITIATOR_MSK) | |
748 | ieee80211_send_delba(sta->dev, ra, tid, | |
749 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); | |
750 | ||
751 | agg_queue = sta->tid_to_tx_q[tid]; | |
752 | ||
753 | /* avoid ordering issues: we are the only one that can modify | |
754 | * the content of the qdiscs */ | |
755 | spin_lock_bh(&local->mdev->queue_lock); | |
756 | /* remove the queue for this aggregation */ | |
9e723492 | 757 | ieee80211_ht_agg_queue_remove(local, sta, tid, 1); |
eadc8d9e RR |
758 | spin_unlock_bh(&local->mdev->queue_lock); |
759 | ||
760 | /* we just requeued the all the frames that were in the removed | |
761 | * queue, and since we might miss a softirq we do netif_schedule. | |
762 | * ieee80211_wake_queue is not used here as this queue is not | |
763 | * necessarily stopped */ | |
764 | netif_schedule(local->mdev); | |
765 | *state = HT_AGG_STATE_IDLE; | |
766 | sta->ampdu_mlme.tid_tx[tid].addba_req_num = 0; | |
767 | spin_unlock_bh(&sta->ampdu_mlme.ampdu_tx); | |
768 | ||
769 | sta_info_put(sta); | |
770 | } | |
771 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); | |
772 | ||
773 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, | |
774 | const u8 *ra, u16 tid) | |
775 | { | |
776 | struct ieee80211_local *local = hw_to_local(hw); | |
777 | struct ieee80211_ra_tid *ra_tid; | |
778 | struct sk_buff *skb = dev_alloc_skb(0); | |
779 | ||
780 | if (unlikely(!skb)) { | |
781 | if (net_ratelimit()) | |
782 | printk(KERN_WARNING "%s: Not enough memory, " | |
783 | "dropping start BA session", skb->dev->name); | |
784 | return; | |
785 | } | |
786 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
787 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
788 | ra_tid->tid = tid; | |
789 | ||
790 | skb->pkt_type = IEEE80211_ADDBA_MSG; | |
791 | skb_queue_tail(&local->skb_queue, skb); | |
792 | tasklet_schedule(&local->tasklet); | |
793 | } | |
794 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); | |
795 | ||
796 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, | |
797 | const u8 *ra, u16 tid) | |
798 | { | |
799 | struct ieee80211_local *local = hw_to_local(hw); | |
800 | struct ieee80211_ra_tid *ra_tid; | |
801 | struct sk_buff *skb = dev_alloc_skb(0); | |
802 | ||
803 | if (unlikely(!skb)) { | |
804 | if (net_ratelimit()) | |
805 | printk(KERN_WARNING "%s: Not enough memory, " | |
806 | "dropping stop BA session", skb->dev->name); | |
807 | return; | |
808 | } | |
809 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
810 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
811 | ra_tid->tid = tid; | |
812 | ||
813 | skb->pkt_type = IEEE80211_DELBA_MSG; | |
814 | skb_queue_tail(&local->skb_queue, skb); | |
815 | tasklet_schedule(&local->tasklet); | |
816 | } | |
817 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); | |
818 | ||
f0706e82 JB |
819 | static void ieee80211_set_multicast_list(struct net_device *dev) |
820 | { | |
821 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
822 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4150c572 | 823 | int allmulti, promisc, sdata_allmulti, sdata_promisc; |
f0706e82 | 824 | |
4150c572 JB |
825 | allmulti = !!(dev->flags & IFF_ALLMULTI); |
826 | promisc = !!(dev->flags & IFF_PROMISC); | |
b52f2198 JB |
827 | sdata_allmulti = !!(sdata->flags & IEEE80211_SDATA_ALLMULTI); |
828 | sdata_promisc = !!(sdata->flags & IEEE80211_SDATA_PROMISC); | |
4150c572 JB |
829 | |
830 | if (allmulti != sdata_allmulti) { | |
831 | if (dev->flags & IFF_ALLMULTI) | |
53918994 | 832 | atomic_inc(&local->iff_allmultis); |
4150c572 | 833 | else |
53918994 | 834 | atomic_dec(&local->iff_allmultis); |
13262ffd | 835 | sdata->flags ^= IEEE80211_SDATA_ALLMULTI; |
f0706e82 | 836 | } |
4150c572 JB |
837 | |
838 | if (promisc != sdata_promisc) { | |
839 | if (dev->flags & IFF_PROMISC) | |
53918994 | 840 | atomic_inc(&local->iff_promiscs); |
4150c572 | 841 | else |
53918994 | 842 | atomic_dec(&local->iff_promiscs); |
13262ffd | 843 | sdata->flags ^= IEEE80211_SDATA_PROMISC; |
f0706e82 | 844 | } |
4150c572 JB |
845 | |
846 | dev_mc_sync(local->mdev, dev); | |
f0706e82 JB |
847 | } |
848 | ||
3b04ddde SH |
849 | static const struct header_ops ieee80211_header_ops = { |
850 | .create = eth_header, | |
851 | .parse = header_parse_80211, | |
852 | .rebuild = eth_rebuild_header, | |
853 | .cache = eth_header_cache, | |
854 | .cache_update = eth_header_cache_update, | |
855 | }; | |
856 | ||
f9d540ee | 857 | /* Must not be called for mdev */ |
b2c258fb | 858 | void ieee80211_if_setup(struct net_device *dev) |
f0706e82 | 859 | { |
b2c258fb JB |
860 | ether_setup(dev); |
861 | dev->hard_start_xmit = ieee80211_subif_start_xmit; | |
862 | dev->wireless_handlers = &ieee80211_iw_handler_def; | |
863 | dev->set_multicast_list = ieee80211_set_multicast_list; | |
864 | dev->change_mtu = ieee80211_change_mtu; | |
b2c258fb JB |
865 | dev->open = ieee80211_open; |
866 | dev->stop = ieee80211_stop; | |
b2c258fb JB |
867 | dev->destructor = ieee80211_if_free; |
868 | } | |
f0706e82 | 869 | |
b2c258fb JB |
870 | /* WDS specialties */ |
871 | ||
872 | int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr) | |
873 | { | |
874 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
875 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
876 | struct sta_info *sta; | |
0795af57 | 877 | DECLARE_MAC_BUF(mac); |
b2c258fb JB |
878 | |
879 | if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0) | |
880 | return 0; | |
881 | ||
882 | /* Create STA entry for the new peer */ | |
883 | sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL); | |
43ba7e95 JB |
884 | if (IS_ERR(sta)) |
885 | return PTR_ERR(sta); | |
238814fd JB |
886 | |
887 | sta->flags |= WLAN_STA_AUTHORIZED; | |
888 | ||
b2c258fb JB |
889 | sta_info_put(sta); |
890 | ||
891 | /* Remove STA entry for the old peer */ | |
892 | sta = sta_info_get(local, sdata->u.wds.remote_addr); | |
893 | if (sta) { | |
be8755e1 | 894 | sta_info_free(sta); |
b2c258fb | 895 | sta_info_put(sta); |
b2c258fb JB |
896 | } else { |
897 | printk(KERN_DEBUG "%s: could not find STA entry for WDS link " | |
0795af57 JP |
898 | "peer %s\n", |
899 | dev->name, print_mac(mac, sdata->u.wds.remote_addr)); | |
b2c258fb JB |
900 | } |
901 | ||
902 | /* Update WDS link data */ | |
903 | memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN); | |
904 | ||
905 | return 0; | |
f0706e82 | 906 | } |
f0706e82 | 907 | |
b2c258fb JB |
908 | /* everything else */ |
909 | ||
b2c258fb JB |
910 | static int __ieee80211_if_config(struct net_device *dev, |
911 | struct sk_buff *beacon, | |
912 | struct ieee80211_tx_control *control) | |
913 | { | |
914 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
915 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
916 | struct ieee80211_if_conf conf; | |
b2c258fb JB |
917 | |
918 | if (!local->ops->config_interface || !netif_running(dev)) | |
f0706e82 | 919 | return 0; |
f0706e82 | 920 | |
b2c258fb | 921 | memset(&conf, 0, sizeof(conf)); |
51fb61e7 JB |
922 | conf.type = sdata->vif.type; |
923 | if (sdata->vif.type == IEEE80211_IF_TYPE_STA || | |
924 | sdata->vif.type == IEEE80211_IF_TYPE_IBSS) { | |
4150c572 | 925 | conf.bssid = sdata->u.sta.bssid; |
b2c258fb JB |
926 | conf.ssid = sdata->u.sta.ssid; |
927 | conf.ssid_len = sdata->u.sta.ssid_len; | |
51fb61e7 | 928 | } else if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
b2c258fb JB |
929 | conf.ssid = sdata->u.ap.ssid; |
930 | conf.ssid_len = sdata->u.ap.ssid_len; | |
b2c258fb JB |
931 | conf.beacon = beacon; |
932 | conf.beacon_control = control; | |
f0706e82 | 933 | } |
b2c258fb | 934 | return local->ops->config_interface(local_to_hw(local), |
32bfd35d | 935 | &sdata->vif, &conf); |
f0706e82 JB |
936 | } |
937 | ||
b2c258fb JB |
938 | int ieee80211_if_config(struct net_device *dev) |
939 | { | |
940 | return __ieee80211_if_config(dev, NULL, NULL); | |
941 | } | |
f0706e82 | 942 | |
b2c258fb | 943 | int ieee80211_if_config_beacon(struct net_device *dev) |
f0706e82 | 944 | { |
f0706e82 | 945 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
b2c258fb | 946 | struct ieee80211_tx_control control; |
32bfd35d | 947 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
b2c258fb | 948 | struct sk_buff *skb; |
f0706e82 | 949 | |
b2c258fb | 950 | if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE)) |
f0706e82 | 951 | return 0; |
32bfd35d JB |
952 | skb = ieee80211_beacon_get(local_to_hw(local), &sdata->vif, |
953 | &control); | |
b2c258fb JB |
954 | if (!skb) |
955 | return -ENOMEM; | |
956 | return __ieee80211_if_config(dev, skb, &control); | |
957 | } | |
f0706e82 | 958 | |
b2c258fb JB |
959 | int ieee80211_hw_config(struct ieee80211_local *local) |
960 | { | |
b2c258fb JB |
961 | struct ieee80211_channel *chan; |
962 | int ret = 0; | |
f0706e82 | 963 | |
8318d78a | 964 | if (local->sta_sw_scanning) |
b2c258fb | 965 | chan = local->scan_channel; |
8318d78a | 966 | else |
b2c258fb | 967 | chan = local->oper_channel; |
f0706e82 | 968 | |
8318d78a JB |
969 | local->hw.conf.channel = chan; |
970 | ||
971 | if (!local->hw.conf.power_level) | |
972 | local->hw.conf.power_level = chan->max_power; | |
973 | else | |
974 | local->hw.conf.power_level = min(chan->max_power, | |
975 | local->hw.conf.power_level); | |
976 | ||
977 | local->hw.conf.max_antenna_gain = chan->max_antenna_gain; | |
f0706e82 | 978 | |
b2c258fb | 979 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
8318d78a JB |
980 | printk(KERN_DEBUG "%s: HW CONFIG: freq=%d\n", |
981 | wiphy_name(local->hw.wiphy), chan->center_freq); | |
982 | #endif | |
b2c258fb | 983 | |
f7c4daed | 984 | if (local->open_count) |
b2c258fb | 985 | ret = local->ops->config(local_to_hw(local), &local->hw.conf); |
f0706e82 | 986 | |
b2c258fb JB |
987 | return ret; |
988 | } | |
f0706e82 | 989 | |
d3c990fb RR |
990 | /** |
991 | * ieee80211_hw_config_ht should be used only after legacy configuration | |
992 | * has been determined, as ht configuration depends upon the hardware's | |
993 | * HT abilities for a _specific_ band. | |
994 | */ | |
995 | int ieee80211_hw_config_ht(struct ieee80211_local *local, int enable_ht, | |
996 | struct ieee80211_ht_info *req_ht_cap, | |
997 | struct ieee80211_ht_bss_info *req_bss_cap) | |
998 | { | |
999 | struct ieee80211_conf *conf = &local->hw.conf; | |
8318d78a | 1000 | struct ieee80211_supported_band *sband; |
d3c990fb RR |
1001 | int i; |
1002 | ||
8318d78a JB |
1003 | sband = local->hw.wiphy->bands[conf->channel->band]; |
1004 | ||
d3c990fb | 1005 | /* HT is not supported */ |
8318d78a | 1006 | if (!sband->ht_info.ht_supported) { |
d3c990fb RR |
1007 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
1008 | return -EOPNOTSUPP; | |
1009 | } | |
1010 | ||
1011 | /* disable HT */ | |
1012 | if (!enable_ht) { | |
1013 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; | |
1014 | } else { | |
1015 | conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; | |
8318d78a | 1016 | conf->ht_conf.cap = req_ht_cap->cap & sband->ht_info.cap; |
d3c990fb RR |
1017 | conf->ht_conf.cap &= ~(IEEE80211_HT_CAP_MIMO_PS); |
1018 | conf->ht_conf.cap |= | |
8318d78a | 1019 | sband->ht_info.cap & IEEE80211_HT_CAP_MIMO_PS; |
d3c990fb RR |
1020 | conf->ht_bss_conf.primary_channel = |
1021 | req_bss_cap->primary_channel; | |
1022 | conf->ht_bss_conf.bss_cap = req_bss_cap->bss_cap; | |
1023 | conf->ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; | |
1024 | for (i = 0; i < SUPP_MCS_SET_LEN; i++) | |
1025 | conf->ht_conf.supp_mcs_set[i] = | |
8318d78a | 1026 | sband->ht_info.supp_mcs_set[i] & |
d3c990fb RR |
1027 | req_ht_cap->supp_mcs_set[i]; |
1028 | ||
1029 | /* In STA mode, this gives us indication | |
1030 | * to the AP's mode of operation */ | |
1031 | conf->ht_conf.ht_supported = 1; | |
1032 | conf->ht_conf.ampdu_factor = req_ht_cap->ampdu_factor; | |
1033 | conf->ht_conf.ampdu_density = req_ht_cap->ampdu_density; | |
1034 | } | |
1035 | ||
1036 | local->ops->conf_ht(local_to_hw(local), &local->hw.conf); | |
1037 | ||
1038 | return 0; | |
1039 | } | |
1040 | ||
471b3efd JB |
1041 | void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata, |
1042 | u32 changed) | |
d9430a32 | 1043 | { |
471b3efd JB |
1044 | struct ieee80211_local *local = sdata->local; |
1045 | ||
1046 | if (!changed) | |
1047 | return; | |
1048 | ||
1049 | if (local->ops->bss_info_changed) | |
1050 | local->ops->bss_info_changed(local_to_hw(local), | |
1051 | &sdata->vif, | |
1052 | &sdata->bss_conf, | |
1053 | changed); | |
d9430a32 DD |
1054 | } |
1055 | ||
1056 | void ieee80211_reset_erp_info(struct net_device *dev) | |
1057 | { | |
1058 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1059 | ||
471b3efd JB |
1060 | sdata->bss_conf.use_cts_prot = 0; |
1061 | sdata->bss_conf.use_short_preamble = 0; | |
1062 | ieee80211_bss_info_change_notify(sdata, | |
1063 | BSS_CHANGED_ERP_CTS_PROT | | |
1064 | BSS_CHANGED_ERP_PREAMBLE); | |
d9430a32 DD |
1065 | } |
1066 | ||
f0706e82 JB |
1067 | void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw, |
1068 | struct sk_buff *skb, | |
1069 | struct ieee80211_tx_status *status) | |
1070 | { | |
1071 | struct ieee80211_local *local = hw_to_local(hw); | |
1072 | struct ieee80211_tx_status *saved; | |
1073 | int tmp; | |
1074 | ||
1075 | skb->dev = local->mdev; | |
1076 | saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC); | |
1077 | if (unlikely(!saved)) { | |
1078 | if (net_ratelimit()) | |
1079 | printk(KERN_WARNING "%s: Not enough memory, " | |
1080 | "dropping tx status", skb->dev->name); | |
1081 | /* should be dev_kfree_skb_irq, but due to this function being | |
1082 | * named _irqsafe instead of just _irq we can't be sure that | |
1083 | * people won't call it from non-irq contexts */ | |
1084 | dev_kfree_skb_any(skb); | |
1085 | return; | |
1086 | } | |
1087 | memcpy(saved, status, sizeof(struct ieee80211_tx_status)); | |
1088 | /* copy pointer to saved status into skb->cb for use by tasklet */ | |
1089 | memcpy(skb->cb, &saved, sizeof(saved)); | |
1090 | ||
1091 | skb->pkt_type = IEEE80211_TX_STATUS_MSG; | |
1092 | skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ? | |
1093 | &local->skb_queue : &local->skb_queue_unreliable, skb); | |
1094 | tmp = skb_queue_len(&local->skb_queue) + | |
1095 | skb_queue_len(&local->skb_queue_unreliable); | |
1096 | while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT && | |
1097 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
1098 | memcpy(&saved, skb->cb, sizeof(saved)); | |
1099 | kfree(saved); | |
1100 | dev_kfree_skb_irq(skb); | |
1101 | tmp--; | |
1102 | I802_DEBUG_INC(local->tx_status_drop); | |
1103 | } | |
1104 | tasklet_schedule(&local->tasklet); | |
1105 | } | |
1106 | EXPORT_SYMBOL(ieee80211_tx_status_irqsafe); | |
1107 | ||
1108 | static void ieee80211_tasklet_handler(unsigned long data) | |
1109 | { | |
1110 | struct ieee80211_local *local = (struct ieee80211_local *) data; | |
1111 | struct sk_buff *skb; | |
1112 | struct ieee80211_rx_status rx_status; | |
1113 | struct ieee80211_tx_status *tx_status; | |
eadc8d9e | 1114 | struct ieee80211_ra_tid *ra_tid; |
f0706e82 JB |
1115 | |
1116 | while ((skb = skb_dequeue(&local->skb_queue)) || | |
1117 | (skb = skb_dequeue(&local->skb_queue_unreliable))) { | |
1118 | switch (skb->pkt_type) { | |
1119 | case IEEE80211_RX_MSG: | |
1120 | /* status is in skb->cb */ | |
1121 | memcpy(&rx_status, skb->cb, sizeof(rx_status)); | |
51fb61e7 | 1122 | /* Clear skb->pkt_type in order to not confuse kernel |
f0706e82 JB |
1123 | * netstack. */ |
1124 | skb->pkt_type = 0; | |
1125 | __ieee80211_rx(local_to_hw(local), skb, &rx_status); | |
1126 | break; | |
1127 | case IEEE80211_TX_STATUS_MSG: | |
1128 | /* get pointer to saved status out of skb->cb */ | |
1129 | memcpy(&tx_status, skb->cb, sizeof(tx_status)); | |
1130 | skb->pkt_type = 0; | |
1131 | ieee80211_tx_status(local_to_hw(local), | |
1132 | skb, tx_status); | |
1133 | kfree(tx_status); | |
1134 | break; | |
eadc8d9e RR |
1135 | case IEEE80211_DELBA_MSG: |
1136 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
1137 | ieee80211_stop_tx_ba_cb(local_to_hw(local), | |
1138 | ra_tid->ra, ra_tid->tid); | |
1139 | dev_kfree_skb(skb); | |
1140 | break; | |
1141 | case IEEE80211_ADDBA_MSG: | |
1142 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
1143 | ieee80211_start_tx_ba_cb(local_to_hw(local), | |
1144 | ra_tid->ra, ra_tid->tid); | |
1145 | dev_kfree_skb(skb); | |
1146 | break ; | |
f0706e82 JB |
1147 | default: /* should never get here! */ |
1148 | printk(KERN_ERR "%s: Unknown message type (%d)\n", | |
dd1cd4c6 | 1149 | wiphy_name(local->hw.wiphy), skb->pkt_type); |
f0706e82 JB |
1150 | dev_kfree_skb(skb); |
1151 | break; | |
1152 | } | |
1153 | } | |
1154 | } | |
1155 | ||
f0706e82 JB |
1156 | /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to |
1157 | * make a prepared TX frame (one that has been given to hw) to look like brand | |
1158 | * new IEEE 802.11 frame that is ready to go through TX processing again. | |
1159 | * Also, tx_packet_data in cb is restored from tx_control. */ | |
1160 | static void ieee80211_remove_tx_extra(struct ieee80211_local *local, | |
1161 | struct ieee80211_key *key, | |
1162 | struct sk_buff *skb, | |
1163 | struct ieee80211_tx_control *control) | |
1164 | { | |
1165 | int hdrlen, iv_len, mic_len; | |
1166 | struct ieee80211_tx_packet_data *pkt_data; | |
1167 | ||
1168 | pkt_data = (struct ieee80211_tx_packet_data *)skb->cb; | |
32bfd35d | 1169 | pkt_data->ifindex = vif_to_sdata(control->vif)->dev->ifindex; |
e8bf9649 JS |
1170 | pkt_data->flags = 0; |
1171 | if (control->flags & IEEE80211_TXCTL_REQ_TX_STATUS) | |
1172 | pkt_data->flags |= IEEE80211_TXPD_REQ_TX_STATUS; | |
1173 | if (control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT) | |
1174 | pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT; | |
1175 | if (control->flags & IEEE80211_TXCTL_REQUEUE) | |
1176 | pkt_data->flags |= IEEE80211_TXPD_REQUEUE; | |
678f5f71 JB |
1177 | if (control->flags & IEEE80211_TXCTL_EAPOL_FRAME) |
1178 | pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME; | |
f0706e82 JB |
1179 | pkt_data->queue = control->queue; |
1180 | ||
1181 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); | |
1182 | ||
1183 | if (!key) | |
1184 | goto no_key; | |
1185 | ||
8f20fc24 | 1186 | switch (key->conf.alg) { |
f0706e82 JB |
1187 | case ALG_WEP: |
1188 | iv_len = WEP_IV_LEN; | |
1189 | mic_len = WEP_ICV_LEN; | |
1190 | break; | |
1191 | case ALG_TKIP: | |
1192 | iv_len = TKIP_IV_LEN; | |
1193 | mic_len = TKIP_ICV_LEN; | |
1194 | break; | |
1195 | case ALG_CCMP: | |
1196 | iv_len = CCMP_HDR_LEN; | |
1197 | mic_len = CCMP_MIC_LEN; | |
1198 | break; | |
1199 | default: | |
1200 | goto no_key; | |
1201 | } | |
1202 | ||
8f20fc24 | 1203 | if (skb->len >= mic_len && |
11a843b7 | 1204 | !(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
f0706e82 JB |
1205 | skb_trim(skb, skb->len - mic_len); |
1206 | if (skb->len >= iv_len && skb->len > hdrlen) { | |
1207 | memmove(skb->data + iv_len, skb->data, hdrlen); | |
1208 | skb_pull(skb, iv_len); | |
1209 | } | |
1210 | ||
1211 | no_key: | |
1212 | { | |
1213 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
1214 | u16 fc = le16_to_cpu(hdr->frame_control); | |
1215 | if ((fc & 0x8C) == 0x88) /* QoS Control Field */ { | |
1216 | fc &= ~IEEE80211_STYPE_QOS_DATA; | |
1217 | hdr->frame_control = cpu_to_le16(fc); | |
1218 | memmove(skb->data + 2, skb->data, hdrlen - 2); | |
1219 | skb_pull(skb, 2); | |
1220 | } | |
1221 | } | |
1222 | } | |
1223 | ||
d46e144b JB |
1224 | static void ieee80211_handle_filtered_frame(struct ieee80211_local *local, |
1225 | struct sta_info *sta, | |
1226 | struct sk_buff *skb, | |
1227 | struct ieee80211_tx_status *status) | |
1228 | { | |
1229 | sta->tx_filtered_count++; | |
1230 | ||
1231 | /* | |
1232 | * Clear the TX filter mask for this STA when sending the next | |
1233 | * packet. If the STA went to power save mode, this will happen | |
1234 | * happen when it wakes up for the next time. | |
1235 | */ | |
1236 | sta->flags |= WLAN_STA_CLEAR_PS_FILT; | |
1237 | ||
1238 | /* | |
1239 | * This code races in the following way: | |
1240 | * | |
1241 | * (1) STA sends frame indicating it will go to sleep and does so | |
1242 | * (2) hardware/firmware adds STA to filter list, passes frame up | |
1243 | * (3) hardware/firmware processes TX fifo and suppresses a frame | |
1244 | * (4) we get TX status before having processed the frame and | |
1245 | * knowing that the STA has gone to sleep. | |
1246 | * | |
1247 | * This is actually quite unlikely even when both those events are | |
1248 | * processed from interrupts coming in quickly after one another or | |
1249 | * even at the same time because we queue both TX status events and | |
1250 | * RX frames to be processed by a tasklet and process them in the | |
1251 | * same order that they were received or TX status last. Hence, there | |
1252 | * is no race as long as the frame RX is processed before the next TX | |
1253 | * status, which drivers can ensure, see below. | |
1254 | * | |
1255 | * Note that this can only happen if the hardware or firmware can | |
1256 | * actually add STAs to the filter list, if this is done by the | |
1257 | * driver in response to set_tim() (which will only reduce the race | |
1258 | * this whole filtering tries to solve, not completely solve it) | |
1259 | * this situation cannot happen. | |
1260 | * | |
1261 | * To completely solve this race drivers need to make sure that they | |
1262 | * (a) don't mix the irq-safe/not irq-safe TX status/RX processing | |
1263 | * functions and | |
1264 | * (b) always process RX events before TX status events if ordering | |
1265 | * can be unknown, for example with different interrupt status | |
1266 | * bits. | |
1267 | */ | |
1268 | if (sta->flags & WLAN_STA_PS && | |
1269 | skb_queue_len(&sta->tx_filtered) < STA_MAX_TX_BUFFER) { | |
1270 | ieee80211_remove_tx_extra(local, sta->key, skb, | |
1271 | &status->control); | |
1272 | skb_queue_tail(&sta->tx_filtered, skb); | |
1273 | return; | |
1274 | } | |
1275 | ||
1276 | if (!(sta->flags & WLAN_STA_PS) && | |
1277 | !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) { | |
1278 | /* Software retry the packet once */ | |
1279 | status->control.flags |= IEEE80211_TXCTL_REQUEUE; | |
1280 | ieee80211_remove_tx_extra(local, sta->key, skb, | |
1281 | &status->control); | |
1282 | dev_queue_xmit(skb); | |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | if (net_ratelimit()) | |
1287 | printk(KERN_DEBUG "%s: dropped TX filtered frame, " | |
1288 | "queue_len=%d PS=%d @%lu\n", | |
1289 | wiphy_name(local->hw.wiphy), | |
1290 | skb_queue_len(&sta->tx_filtered), | |
1291 | !!(sta->flags & WLAN_STA_PS), jiffies); | |
1292 | dev_kfree_skb(skb); | |
1293 | } | |
1294 | ||
f0706e82 JB |
1295 | void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb, |
1296 | struct ieee80211_tx_status *status) | |
1297 | { | |
1298 | struct sk_buff *skb2; | |
1299 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
1300 | struct ieee80211_local *local = hw_to_local(hw); | |
1301 | u16 frag, type; | |
b306f453 JB |
1302 | struct ieee80211_tx_status_rtap_hdr *rthdr; |
1303 | struct ieee80211_sub_if_data *sdata; | |
3d30d949 | 1304 | struct net_device *prev_dev = NULL; |
f0706e82 JB |
1305 | |
1306 | if (!status) { | |
1307 | printk(KERN_ERR | |
1308 | "%s: ieee80211_tx_status called with NULL status\n", | |
dd1cd4c6 | 1309 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1310 | dev_kfree_skb(skb); |
1311 | return; | |
1312 | } | |
1313 | ||
1314 | if (status->excessive_retries) { | |
1315 | struct sta_info *sta; | |
1316 | sta = sta_info_get(local, hdr->addr1); | |
1317 | if (sta) { | |
1318 | if (sta->flags & WLAN_STA_PS) { | |
d46e144b JB |
1319 | /* |
1320 | * The STA is in power save mode, so assume | |
f0706e82 JB |
1321 | * that this TX packet failed because of that. |
1322 | */ | |
1323 | status->excessive_retries = 0; | |
1324 | status->flags |= IEEE80211_TX_STATUS_TX_FILTERED; | |
d46e144b JB |
1325 | ieee80211_handle_filtered_frame(local, sta, |
1326 | skb, status); | |
1327 | sta_info_put(sta); | |
1328 | return; | |
f0706e82 JB |
1329 | } |
1330 | sta_info_put(sta); | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) { | |
1335 | struct sta_info *sta; | |
1336 | sta = sta_info_get(local, hdr->addr1); | |
1337 | if (sta) { | |
d46e144b JB |
1338 | ieee80211_handle_filtered_frame(local, sta, skb, |
1339 | status); | |
f0706e82 JB |
1340 | sta_info_put(sta); |
1341 | return; | |
1342 | } | |
1abbe498 MN |
1343 | } else |
1344 | rate_control_tx_status(local->mdev, skb, status); | |
f0706e82 JB |
1345 | |
1346 | ieee80211_led_tx(local, 0); | |
1347 | ||
1348 | /* SNMP counters | |
1349 | * Fragments are passed to low-level drivers as separate skbs, so these | |
1350 | * are actually fragments, not frames. Update frame counters only for | |
1351 | * the first fragment of the frame. */ | |
1352 | ||
1353 | frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG; | |
1354 | type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE; | |
1355 | ||
1356 | if (status->flags & IEEE80211_TX_STATUS_ACK) { | |
1357 | if (frag == 0) { | |
1358 | local->dot11TransmittedFrameCount++; | |
1359 | if (is_multicast_ether_addr(hdr->addr1)) | |
1360 | local->dot11MulticastTransmittedFrameCount++; | |
1361 | if (status->retry_count > 0) | |
1362 | local->dot11RetryCount++; | |
1363 | if (status->retry_count > 1) | |
1364 | local->dot11MultipleRetryCount++; | |
1365 | } | |
1366 | ||
1367 | /* This counter shall be incremented for an acknowledged MPDU | |
1368 | * with an individual address in the address 1 field or an MPDU | |
1369 | * with a multicast address in the address 1 field of type Data | |
1370 | * or Management. */ | |
1371 | if (!is_multicast_ether_addr(hdr->addr1) || | |
1372 | type == IEEE80211_FTYPE_DATA || | |
1373 | type == IEEE80211_FTYPE_MGMT) | |
1374 | local->dot11TransmittedFragmentCount++; | |
1375 | } else { | |
1376 | if (frag == 0) | |
1377 | local->dot11FailedCount++; | |
1378 | } | |
1379 | ||
b306f453 JB |
1380 | /* this was a transmitted frame, but now we want to reuse it */ |
1381 | skb_orphan(skb); | |
1382 | ||
3d30d949 MW |
1383 | /* |
1384 | * This is a bit racy but we can avoid a lot of work | |
1385 | * with this test... | |
1386 | */ | |
1387 | if (!local->monitors && !local->cooked_mntrs) { | |
f0706e82 JB |
1388 | dev_kfree_skb(skb); |
1389 | return; | |
1390 | } | |
1391 | ||
b306f453 | 1392 | /* send frame to monitor interfaces now */ |
f0706e82 | 1393 | |
b306f453 JB |
1394 | if (skb_headroom(skb) < sizeof(*rthdr)) { |
1395 | printk(KERN_ERR "ieee80211_tx_status: headroom too small\n"); | |
f0706e82 JB |
1396 | dev_kfree_skb(skb); |
1397 | return; | |
1398 | } | |
f0706e82 | 1399 | |
b306f453 JB |
1400 | rthdr = (struct ieee80211_tx_status_rtap_hdr*) |
1401 | skb_push(skb, sizeof(*rthdr)); | |
1402 | ||
1403 | memset(rthdr, 0, sizeof(*rthdr)); | |
1404 | rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr)); | |
1405 | rthdr->hdr.it_present = | |
1406 | cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS) | | |
1407 | (1 << IEEE80211_RADIOTAP_DATA_RETRIES)); | |
1408 | ||
1409 | if (!(status->flags & IEEE80211_TX_STATUS_ACK) && | |
1410 | !is_multicast_ether_addr(hdr->addr1)) | |
1411 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL); | |
1412 | ||
1413 | if ((status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) && | |
1414 | (status->control.flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) | |
1415 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS); | |
1416 | else if (status->control.flags & IEEE80211_TXCTL_USE_RTS_CTS) | |
1417 | rthdr->tx_flags |= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS); | |
1418 | ||
1419 | rthdr->data_retries = status->retry_count; | |
1420 | ||
3d30d949 MW |
1421 | /* XXX: is this sufficient for BPF? */ |
1422 | skb_set_mac_header(skb, 0); | |
1423 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1424 | skb->pkt_type = PACKET_OTHERHOST; | |
1425 | skb->protocol = htons(ETH_P_802_2); | |
1426 | memset(skb->cb, 0, sizeof(skb->cb)); | |
1427 | ||
79010420 | 1428 | rcu_read_lock(); |
79010420 | 1429 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
51fb61e7 | 1430 | if (sdata->vif.type == IEEE80211_IF_TYPE_MNTR) { |
b306f453 JB |
1431 | if (!netif_running(sdata->dev)) |
1432 | continue; | |
3d30d949 MW |
1433 | |
1434 | if (prev_dev) { | |
79010420 | 1435 | skb2 = skb_clone(skb, GFP_ATOMIC); |
3d30d949 MW |
1436 | if (skb2) { |
1437 | skb2->dev = prev_dev; | |
1438 | netif_rx(skb2); | |
1439 | } | |
1440 | } | |
1441 | ||
1442 | prev_dev = sdata->dev; | |
b306f453 JB |
1443 | } |
1444 | } | |
3d30d949 MW |
1445 | if (prev_dev) { |
1446 | skb->dev = prev_dev; | |
1447 | netif_rx(skb); | |
1448 | skb = NULL; | |
1449 | } | |
79010420 | 1450 | rcu_read_unlock(); |
3d30d949 | 1451 | dev_kfree_skb(skb); |
f0706e82 JB |
1452 | } |
1453 | EXPORT_SYMBOL(ieee80211_tx_status); | |
1454 | ||
f0706e82 JB |
1455 | struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, |
1456 | const struct ieee80211_ops *ops) | |
1457 | { | |
f0706e82 | 1458 | struct ieee80211_local *local; |
f0706e82 JB |
1459 | int priv_size; |
1460 | struct wiphy *wiphy; | |
1461 | ||
1462 | /* Ensure 32-byte alignment of our private data and hw private data. | |
1463 | * We use the wiphy priv data for both our ieee80211_local and for | |
1464 | * the driver's private data | |
1465 | * | |
1466 | * In memory it'll be like this: | |
1467 | * | |
1468 | * +-------------------------+ | |
1469 | * | struct wiphy | | |
1470 | * +-------------------------+ | |
1471 | * | struct ieee80211_local | | |
1472 | * +-------------------------+ | |
1473 | * | driver's private data | | |
1474 | * +-------------------------+ | |
1475 | * | |
1476 | */ | |
1477 | priv_size = ((sizeof(struct ieee80211_local) + | |
1478 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) + | |
1479 | priv_data_len; | |
1480 | ||
1481 | wiphy = wiphy_new(&mac80211_config_ops, priv_size); | |
1482 | ||
1483 | if (!wiphy) | |
1484 | return NULL; | |
1485 | ||
1486 | wiphy->privid = mac80211_wiphy_privid; | |
1487 | ||
1488 | local = wiphy_priv(wiphy); | |
1489 | local->hw.wiphy = wiphy; | |
1490 | ||
1491 | local->hw.priv = (char *)local + | |
1492 | ((sizeof(struct ieee80211_local) + | |
1493 | NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST); | |
1494 | ||
4480f15c | 1495 | BUG_ON(!ops->tx); |
4150c572 JB |
1496 | BUG_ON(!ops->start); |
1497 | BUG_ON(!ops->stop); | |
4480f15c JB |
1498 | BUG_ON(!ops->config); |
1499 | BUG_ON(!ops->add_interface); | |
4150c572 JB |
1500 | BUG_ON(!ops->remove_interface); |
1501 | BUG_ON(!ops->configure_filter); | |
f0706e82 JB |
1502 | local->ops = ops; |
1503 | ||
f0706e82 JB |
1504 | local->hw.queues = 1; /* default */ |
1505 | ||
f0706e82 JB |
1506 | local->bridge_packets = 1; |
1507 | ||
1508 | local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; | |
1509 | local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; | |
1510 | local->short_retry_limit = 7; | |
1511 | local->long_retry_limit = 4; | |
1512 | local->hw.conf.radio_enabled = 1; | |
f0706e82 | 1513 | |
79010420 | 1514 | INIT_LIST_HEAD(&local->interfaces); |
f0706e82 JB |
1515 | |
1516 | INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work); | |
f0706e82 JB |
1517 | |
1518 | sta_info_init(local); | |
1519 | ||
f0706e82 JB |
1520 | tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending, |
1521 | (unsigned long)local); | |
1522 | tasklet_disable(&local->tx_pending_tasklet); | |
1523 | ||
1524 | tasklet_init(&local->tasklet, | |
1525 | ieee80211_tasklet_handler, | |
1526 | (unsigned long) local); | |
1527 | tasklet_disable(&local->tasklet); | |
1528 | ||
1529 | skb_queue_head_init(&local->skb_queue); | |
1530 | skb_queue_head_init(&local->skb_queue_unreliable); | |
1531 | ||
1532 | return local_to_hw(local); | |
1533 | } | |
1534 | EXPORT_SYMBOL(ieee80211_alloc_hw); | |
1535 | ||
1536 | int ieee80211_register_hw(struct ieee80211_hw *hw) | |
1537 | { | |
1538 | struct ieee80211_local *local = hw_to_local(hw); | |
1539 | const char *name; | |
1540 | int result; | |
8318d78a | 1541 | enum ieee80211_band band; |
96d51056 JB |
1542 | struct net_device *mdev; |
1543 | struct ieee80211_sub_if_data *sdata; | |
8318d78a JB |
1544 | |
1545 | /* | |
1546 | * generic code guarantees at least one band, | |
1547 | * set this very early because much code assumes | |
1548 | * that hw.conf.channel is assigned | |
1549 | */ | |
1550 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1551 | struct ieee80211_supported_band *sband; | |
1552 | ||
1553 | sband = local->hw.wiphy->bands[band]; | |
1554 | if (sband) { | |
1555 | /* init channel we're on */ | |
1556 | local->hw.conf.channel = | |
1557 | local->oper_channel = | |
1558 | local->scan_channel = &sband->channels[0]; | |
1559 | break; | |
1560 | } | |
1561 | } | |
f0706e82 JB |
1562 | |
1563 | result = wiphy_register(local->hw.wiphy); | |
1564 | if (result < 0) | |
1565 | return result; | |
1566 | ||
96d51056 JB |
1567 | /* for now, mdev needs sub_if_data :/ */ |
1568 | mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), | |
1569 | "wmaster%d", ether_setup); | |
1570 | if (!mdev) | |
1571 | goto fail_mdev_alloc; | |
1572 | ||
1573 | sdata = IEEE80211_DEV_TO_SUB_IF(mdev); | |
1574 | mdev->ieee80211_ptr = &sdata->wdev; | |
1575 | sdata->wdev.wiphy = local->hw.wiphy; | |
1576 | ||
1577 | local->mdev = mdev; | |
1578 | ||
1579 | ieee80211_rx_bss_list_init(mdev); | |
1580 | ||
1581 | mdev->hard_start_xmit = ieee80211_master_start_xmit; | |
1582 | mdev->open = ieee80211_master_open; | |
1583 | mdev->stop = ieee80211_master_stop; | |
1584 | mdev->type = ARPHRD_IEEE80211; | |
1585 | mdev->header_ops = &ieee80211_header_ops; | |
1586 | mdev->set_multicast_list = ieee80211_master_set_multicast_list; | |
1587 | ||
1588 | sdata->vif.type = IEEE80211_IF_TYPE_AP; | |
1589 | sdata->dev = mdev; | |
1590 | sdata->local = local; | |
1591 | sdata->u.ap.force_unicast_rateidx = -1; | |
1592 | sdata->u.ap.max_ratectrl_rateidx = -1; | |
1593 | ieee80211_if_sdata_init(sdata); | |
1594 | ||
1595 | /* no RCU needed since we're still during init phase */ | |
1596 | list_add_tail(&sdata->list, &local->interfaces); | |
1597 | ||
f0706e82 JB |
1598 | name = wiphy_dev(local->hw.wiphy)->driver->name; |
1599 | local->hw.workqueue = create_singlethread_workqueue(name); | |
1600 | if (!local->hw.workqueue) { | |
1601 | result = -ENOMEM; | |
1602 | goto fail_workqueue; | |
1603 | } | |
1604 | ||
b306f453 JB |
1605 | /* |
1606 | * The hardware needs headroom for sending the frame, | |
1607 | * and we need some headroom for passing the frame to monitor | |
1608 | * interfaces, but never both at the same time. | |
1609 | */ | |
33ccad35 JB |
1610 | local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom, |
1611 | sizeof(struct ieee80211_tx_status_rtap_hdr)); | |
b306f453 | 1612 | |
e9f207f0 JB |
1613 | debugfs_hw_add(local); |
1614 | ||
f0706e82 JB |
1615 | local->hw.conf.beacon_int = 1000; |
1616 | ||
1617 | local->wstats_flags |= local->hw.max_rssi ? | |
1618 | IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID; | |
1619 | local->wstats_flags |= local->hw.max_signal ? | |
1620 | IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID; | |
1621 | local->wstats_flags |= local->hw.max_noise ? | |
1622 | IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID; | |
1623 | if (local->hw.max_rssi < 0 || local->hw.max_noise < 0) | |
1624 | local->wstats_flags |= IW_QUAL_DBM; | |
1625 | ||
1626 | result = sta_info_start(local); | |
1627 | if (result < 0) | |
1628 | goto fail_sta_info; | |
1629 | ||
1630 | rtnl_lock(); | |
1631 | result = dev_alloc_name(local->mdev, local->mdev->name); | |
1632 | if (result < 0) | |
1633 | goto fail_dev; | |
1634 | ||
1635 | memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN); | |
1636 | SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy)); | |
1637 | ||
1638 | result = register_netdevice(local->mdev); | |
1639 | if (result < 0) | |
1640 | goto fail_dev; | |
1641 | ||
e9f207f0 | 1642 | ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
5b2812e9 | 1643 | ieee80211_if_set_type(local->mdev, IEEE80211_IF_TYPE_AP); |
e9f207f0 | 1644 | |
830f9038 JB |
1645 | result = ieee80211_init_rate_ctrl_alg(local, |
1646 | hw->rate_control_algorithm); | |
f0706e82 JB |
1647 | if (result < 0) { |
1648 | printk(KERN_DEBUG "%s: Failed to initialize rate control " | |
dd1cd4c6 | 1649 | "algorithm\n", wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1650 | goto fail_rate; |
1651 | } | |
1652 | ||
1653 | result = ieee80211_wep_init(local); | |
1654 | ||
1655 | if (result < 0) { | |
1656 | printk(KERN_DEBUG "%s: Failed to initialize wep\n", | |
dd1cd4c6 | 1657 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1658 | goto fail_wep; |
1659 | } | |
1660 | ||
1661 | ieee80211_install_qdisc(local->mdev); | |
1662 | ||
1663 | /* add one default STA interface */ | |
1664 | result = ieee80211_if_add(local->mdev, "wlan%d", NULL, | |
1665 | IEEE80211_IF_TYPE_STA); | |
1666 | if (result) | |
1667 | printk(KERN_WARNING "%s: Failed to add default virtual iface\n", | |
dd1cd4c6 | 1668 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1669 | |
1670 | local->reg_state = IEEE80211_DEV_REGISTERED; | |
1671 | rtnl_unlock(); | |
1672 | ||
1673 | ieee80211_led_init(local); | |
1674 | ||
1675 | return 0; | |
1676 | ||
1677 | fail_wep: | |
1678 | rate_control_deinitialize(local); | |
1679 | fail_rate: | |
e9f207f0 | 1680 | ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local->mdev)); |
f0706e82 JB |
1681 | unregister_netdevice(local->mdev); |
1682 | fail_dev: | |
1683 | rtnl_unlock(); | |
1684 | sta_info_stop(local); | |
1685 | fail_sta_info: | |
e9f207f0 | 1686 | debugfs_hw_del(local); |
f0706e82 JB |
1687 | destroy_workqueue(local->hw.workqueue); |
1688 | fail_workqueue: | |
96d51056 JB |
1689 | ieee80211_if_free(local->mdev); |
1690 | local->mdev = NULL; | |
1691 | fail_mdev_alloc: | |
f0706e82 JB |
1692 | wiphy_unregister(local->hw.wiphy); |
1693 | return result; | |
1694 | } | |
1695 | EXPORT_SYMBOL(ieee80211_register_hw); | |
1696 | ||
f0706e82 JB |
1697 | void ieee80211_unregister_hw(struct ieee80211_hw *hw) |
1698 | { | |
1699 | struct ieee80211_local *local = hw_to_local(hw); | |
1700 | struct ieee80211_sub_if_data *sdata, *tmp; | |
f0706e82 JB |
1701 | |
1702 | tasklet_kill(&local->tx_pending_tasklet); | |
1703 | tasklet_kill(&local->tasklet); | |
1704 | ||
1705 | rtnl_lock(); | |
1706 | ||
1707 | BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED); | |
1708 | ||
1709 | local->reg_state = IEEE80211_DEV_UNREGISTERED; | |
f0706e82 | 1710 | |
79010420 JB |
1711 | /* |
1712 | * At this point, interface list manipulations are fine | |
1713 | * because the driver cannot be handing us frames any | |
1714 | * more and the tasklet is killed. | |
1715 | */ | |
5b2812e9 JB |
1716 | |
1717 | /* | |
1718 | * First, we remove all non-master interfaces. Do this because they | |
1719 | * may have bss pointer dependency on the master, and when we free | |
1720 | * the master these would be freed as well, breaking our list | |
1721 | * iteration completely. | |
1722 | */ | |
1723 | list_for_each_entry_safe(sdata, tmp, &local->interfaces, list) { | |
1724 | if (sdata->dev == local->mdev) | |
1725 | continue; | |
1726 | list_del(&sdata->list); | |
f0706e82 | 1727 | __ieee80211_if_del(local, sdata); |
5b2812e9 JB |
1728 | } |
1729 | ||
1730 | /* then, finally, remove the master interface */ | |
1731 | __ieee80211_if_del(local, IEEE80211_DEV_TO_SUB_IF(local->mdev)); | |
f0706e82 JB |
1732 | |
1733 | rtnl_unlock(); | |
1734 | ||
f0706e82 JB |
1735 | ieee80211_rx_bss_list_deinit(local->mdev); |
1736 | ieee80211_clear_tx_pending(local); | |
1737 | sta_info_stop(local); | |
1738 | rate_control_deinitialize(local); | |
e9f207f0 | 1739 | debugfs_hw_del(local); |
f0706e82 | 1740 | |
f0706e82 JB |
1741 | if (skb_queue_len(&local->skb_queue) |
1742 | || skb_queue_len(&local->skb_queue_unreliable)) | |
1743 | printk(KERN_WARNING "%s: skb_queue not empty\n", | |
dd1cd4c6 | 1744 | wiphy_name(local->hw.wiphy)); |
f0706e82 JB |
1745 | skb_queue_purge(&local->skb_queue); |
1746 | skb_queue_purge(&local->skb_queue_unreliable); | |
1747 | ||
1748 | destroy_workqueue(local->hw.workqueue); | |
1749 | wiphy_unregister(local->hw.wiphy); | |
1750 | ieee80211_wep_free(local); | |
1751 | ieee80211_led_exit(local); | |
96d51056 JB |
1752 | ieee80211_if_free(local->mdev); |
1753 | local->mdev = NULL; | |
f0706e82 JB |
1754 | } |
1755 | EXPORT_SYMBOL(ieee80211_unregister_hw); | |
1756 | ||
1757 | void ieee80211_free_hw(struct ieee80211_hw *hw) | |
1758 | { | |
1759 | struct ieee80211_local *local = hw_to_local(hw); | |
1760 | ||
f0706e82 JB |
1761 | wiphy_free(local->hw.wiphy); |
1762 | } | |
1763 | EXPORT_SYMBOL(ieee80211_free_hw); | |
1764 | ||
f0706e82 JB |
1765 | static int __init ieee80211_init(void) |
1766 | { | |
1767 | struct sk_buff *skb; | |
1768 | int ret; | |
1769 | ||
1770 | BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb)); | |
1771 | ||
4b475898 | 1772 | ret = rc80211_simple_init(); |
ac71c691 | 1773 | if (ret) |
3eadf5f4 | 1774 | goto out; |
ad018375 | 1775 | |
4b475898 | 1776 | ret = rc80211_pid_init(); |
ad018375 | 1777 | if (ret) |
3eadf5f4 | 1778 | goto out_cleanup_simple; |
ac71c691 | 1779 | |
f0706e82 JB |
1780 | ret = ieee80211_wme_register(); |
1781 | if (ret) { | |
1782 | printk(KERN_DEBUG "ieee80211_init: failed to " | |
1783 | "initialize WME (err=%d)\n", ret); | |
3eadf5f4 | 1784 | goto out_cleanup_pid; |
f0706e82 JB |
1785 | } |
1786 | ||
e9f207f0 JB |
1787 | ieee80211_debugfs_netdev_init(); |
1788 | ||
f0706e82 | 1789 | return 0; |
ad018375 | 1790 | |
3eadf5f4 | 1791 | out_cleanup_pid: |
4b475898 | 1792 | rc80211_pid_exit(); |
3eadf5f4 JB |
1793 | out_cleanup_simple: |
1794 | rc80211_simple_exit(); | |
1795 | out: | |
ad018375 | 1796 | return ret; |
f0706e82 JB |
1797 | } |
1798 | ||
f0706e82 JB |
1799 | static void __exit ieee80211_exit(void) |
1800 | { | |
4b475898 JB |
1801 | rc80211_simple_exit(); |
1802 | rc80211_pid_exit(); | |
ac71c691 | 1803 | |
f0706e82 | 1804 | ieee80211_wme_unregister(); |
e9f207f0 | 1805 | ieee80211_debugfs_netdev_exit(); |
f0706e82 JB |
1806 | } |
1807 | ||
1808 | ||
ca9938fe | 1809 | subsys_initcall(ieee80211_init); |
f0706e82 JB |
1810 | module_exit(ieee80211_exit); |
1811 | ||
1812 | MODULE_DESCRIPTION("IEEE 802.11 subsystem"); | |
1813 | MODULE_LICENSE("GPL"); |