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