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