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