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