2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
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.
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>
23 #include <linux/bitmap.h>
24 #include <net/net_namespace.h>
25 #include <net/cfg80211.h>
27 #include "ieee80211_common.h"
28 #include "ieee80211_i.h"
29 #include "ieee80211_rate.h"
33 #include "ieee80211_led.h"
34 #include "ieee80211_cfg.h"
36 #include "debugfs_netdev.h"
39 * For seeing transmitted packets on monitor interfaces
40 * we have a radiotap header too.
42 struct ieee80211_tx_status_rtap_hdr
{
43 struct ieee80211_radiotap_header hdr
;
46 } __attribute__ ((packed
));
48 /* common interface routines */
50 static int header_parse_80211(struct sk_buff
*skb
, unsigned char *haddr
)
52 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
56 /* master interface */
58 static int ieee80211_master_open(struct net_device
*dev
)
60 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
61 struct ieee80211_sub_if_data
*sdata
;
62 int res
= -EOPNOTSUPP
;
64 read_lock(&local
->sub_if_lock
);
65 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
66 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
71 read_unlock(&local
->sub_if_lock
);
75 static int ieee80211_master_stop(struct net_device
*dev
)
77 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
78 struct ieee80211_sub_if_data
*sdata
;
80 read_lock(&local
->sub_if_lock
);
81 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
82 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
83 dev_close(sdata
->dev
);
84 read_unlock(&local
->sub_if_lock
);
89 /* management interface */
92 ieee80211_fill_frame_info(struct ieee80211_local
*local
,
93 struct ieee80211_frame_info
*fi
,
94 struct ieee80211_rx_status
*status
)
98 struct ieee80211_rate
*rate
;
100 jiffies_to_timespec(jiffies
, &ts
);
101 fi
->hosttime
= cpu_to_be64((u64
) ts
.tv_sec
* 1000000 +
103 fi
->mactime
= cpu_to_be64(status
->mactime
);
104 switch (status
->phymode
) {
105 case MODE_IEEE80211A
:
106 fi
->phytype
= htonl(ieee80211_phytype_ofdm_dot11_a
);
108 case MODE_IEEE80211B
:
109 fi
->phytype
= htonl(ieee80211_phytype_dsss_dot11_b
);
111 case MODE_IEEE80211G
:
112 fi
->phytype
= htonl(ieee80211_phytype_pbcc_dot11_g
);
115 fi
->phytype
= htonl(0xAAAAAAAA);
118 fi
->channel
= htonl(status
->channel
);
119 rate
= ieee80211_get_rate(local
, status
->phymode
,
122 fi
->datarate
= htonl(rate
->rate
);
123 if (rate
->flags
& IEEE80211_RATE_PREAMBLE2
) {
124 if (status
->rate
== rate
->val
)
125 fi
->preamble
= htonl(2); /* long */
126 else if (status
->rate
== rate
->val2
)
127 fi
->preamble
= htonl(1); /* short */
129 fi
->preamble
= htonl(0);
131 fi
->datarate
= htonl(0);
132 fi
->preamble
= htonl(0);
135 fi
->antenna
= htonl(status
->antenna
);
136 fi
->priority
= htonl(0xffffffff); /* no clue */
137 fi
->ssi_type
= htonl(ieee80211_ssi_raw
);
138 fi
->ssi_signal
= htonl(status
->ssi
);
139 fi
->ssi_noise
= 0x00000000;
142 /* clear everything because we really don't know.
143 * the msg_type field isn't present on monitor frames
144 * so we don't know whether it will be present or not,
145 * but it's ok to not clear it since it'll be assigned
147 memset(fi
, 0, sizeof(*fi
) - sizeof(fi
->msg_type
));
149 fi
->ssi_type
= htonl(ieee80211_ssi_none
);
151 fi
->version
= htonl(IEEE80211_FI_VERSION
);
152 fi
->length
= cpu_to_be32(sizeof(*fi
) - sizeof(fi
->msg_type
));
155 /* this routine is actually not just for this, but also
156 * for pushing fake 'management' frames into userspace.
157 * it shall be replaced by a netlink-based system. */
159 ieee80211_rx_mgmt(struct ieee80211_local
*local
, struct sk_buff
*skb
,
160 struct ieee80211_rx_status
*status
, u32 msg_type
)
162 struct ieee80211_frame_info
*fi
;
163 const size_t hlen
= sizeof(struct ieee80211_frame_info
);
164 struct net_device
*dev
= local
->apdev
;
168 if (skb_headroom(skb
) < hlen
) {
169 I802_DEBUG_INC(local
->rx_expand_skb_head
);
170 if (pskb_expand_head(skb
, hlen
, 0, GFP_ATOMIC
)) {
176 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
178 ieee80211_fill_frame_info(local
, fi
, status
);
179 fi
->msg_type
= htonl(msg_type
);
181 dev
->stats
.rx_packets
++;
182 dev
->stats
.rx_bytes
+= skb
->len
;
184 skb_set_mac_header(skb
, 0);
185 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
186 skb
->pkt_type
= PACKET_OTHERHOST
;
187 skb
->protocol
= htons(ETH_P_802_2
);
188 memset(skb
->cb
, 0, sizeof(skb
->cb
));
192 static int ieee80211_mgmt_open(struct net_device
*dev
)
194 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
196 if (!netif_running(local
->mdev
))
201 static int ieee80211_mgmt_stop(struct net_device
*dev
)
206 static int ieee80211_change_mtu_apdev(struct net_device
*dev
, int new_mtu
)
208 /* FIX: what would be proper limits for MTU?
209 * This interface uses 802.11 frames. */
210 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
) {
211 printk(KERN_WARNING
"%s: invalid MTU %d\n",
216 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
217 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
218 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
223 void ieee80211_if_mgmt_setup(struct net_device
*dev
)
226 dev
->hard_start_xmit
= ieee80211_mgmt_start_xmit
;
227 dev
->change_mtu
= ieee80211_change_mtu_apdev
;
228 dev
->open
= ieee80211_mgmt_open
;
229 dev
->stop
= ieee80211_mgmt_stop
;
230 dev
->type
= ARPHRD_IEEE80211_PRISM
;
231 dev
->hard_header_parse
= header_parse_80211
;
232 dev
->uninit
= ieee80211_if_reinit
;
233 dev
->destructor
= ieee80211_if_free
;
236 /* regular interfaces */
238 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
240 /* FIX: what would be proper limits for MTU?
241 * This interface uses 802.3 frames. */
242 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6) {
243 printk(KERN_WARNING
"%s: invalid MTU %d\n",
248 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
249 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
250 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
255 static inline int identical_mac_addr_allowed(int type1
, int type2
)
257 return (type1
== IEEE80211_IF_TYPE_MNTR
||
258 type2
== IEEE80211_IF_TYPE_MNTR
||
259 (type1
== IEEE80211_IF_TYPE_AP
&&
260 type2
== IEEE80211_IF_TYPE_WDS
) ||
261 (type1
== IEEE80211_IF_TYPE_WDS
&&
262 (type2
== IEEE80211_IF_TYPE_WDS
||
263 type2
== IEEE80211_IF_TYPE_AP
)) ||
264 (type1
== IEEE80211_IF_TYPE_AP
&&
265 type2
== IEEE80211_IF_TYPE_VLAN
) ||
266 (type1
== IEEE80211_IF_TYPE_VLAN
&&
267 (type2
== IEEE80211_IF_TYPE_AP
||
268 type2
== IEEE80211_IF_TYPE_VLAN
)));
271 /* Check if running monitor interfaces should go to a "soft monitor" mode
272 * and switch them if necessary. */
273 static inline void ieee80211_start_soft_monitor(struct ieee80211_local
*local
)
275 struct ieee80211_if_init_conf conf
;
277 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
278 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
279 local
->ops
->remove_interface
) {
281 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
282 conf
.mac_addr
= NULL
;
283 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
287 /* Check if running monitor interfaces should go to a "hard monitor" mode
288 * and switch them if necessary. */
289 static void ieee80211_start_hard_monitor(struct ieee80211_local
*local
)
291 struct ieee80211_if_init_conf conf
;
293 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
294 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
296 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
297 conf
.mac_addr
= NULL
;
298 local
->ops
->add_interface(local_to_hw(local
), &conf
);
302 static void ieee80211_if_open(struct net_device
*dev
)
304 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
306 switch (sdata
->type
) {
307 case IEEE80211_IF_TYPE_STA
:
308 case IEEE80211_IF_TYPE_IBSS
:
309 sdata
->u
.sta
.flags
&= ~IEEE80211_STA_PREV_BSSID_SET
;
314 static int ieee80211_open(struct net_device
*dev
)
316 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
317 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
318 struct ieee80211_if_init_conf conf
;
321 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
322 read_lock(&local
->sub_if_lock
);
323 list_for_each_entry(nsdata
, &local
->sub_if_list
, list
) {
324 struct net_device
*ndev
= nsdata
->dev
;
326 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
) &&
327 compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
) == 0 &&
328 !identical_mac_addr_allowed(sdata
->type
, nsdata
->type
)) {
329 read_unlock(&local
->sub_if_lock
);
333 read_unlock(&local
->sub_if_lock
);
335 if (sdata
->type
== IEEE80211_IF_TYPE_WDS
&&
336 is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
339 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&& local
->open_count
&&
340 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
341 /* run the interface in a "soft monitor" mode */
344 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
347 ieee80211_if_open(dev
);
348 ieee80211_start_soft_monitor(local
);
350 conf
.if_id
= dev
->ifindex
;
351 conf
.type
= sdata
->type
;
352 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
353 conf
.mac_addr
= NULL
;
355 conf
.mac_addr
= dev
->dev_addr
;
356 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
358 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
359 ieee80211_start_hard_monitor(local
);
363 if (local
->open_count
== 0) {
365 tasklet_enable(&local
->tx_pending_tasklet
);
366 tasklet_enable(&local
->tasklet
);
367 if (local
->ops
->open
)
368 res
= local
->ops
->open(local_to_hw(local
));
370 res
= dev_open(local
->mdev
);
372 if (local
->ops
->stop
)
373 local
->ops
->stop(local_to_hw(local
));
375 res
= ieee80211_hw_config(local
);
376 if (res
&& local
->ops
->stop
)
377 local
->ops
->stop(local_to_hw(local
));
378 else if (!res
&& local
->apdev
)
379 dev_open(local
->apdev
);
383 if (local
->ops
->remove_interface
)
384 local
->ops
->remove_interface(local_to_hw(local
),
391 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
393 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
395 ieee80211_if_config(dev
);
396 ieee80211_reset_erp_info(dev
);
397 ieee80211_enable_keys(sdata
);
400 if (sdata
->type
== IEEE80211_IF_TYPE_STA
&&
401 !local
->user_space_mlme
)
402 netif_carrier_off(dev
);
404 netif_carrier_on(dev
);
406 netif_start_queue(dev
);
410 static void ieee80211_if_shutdown(struct net_device
*dev
)
412 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
413 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
416 switch (sdata
->type
) {
417 case IEEE80211_IF_TYPE_STA
:
418 case IEEE80211_IF_TYPE_IBSS
:
419 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
420 del_timer_sync(&sdata
->u
.sta
.timer
);
422 * Holding the sub_if_lock for writing here blocks
423 * out the receive path and makes sure it's not
424 * currently processing a packet that may get
425 * added to the queue.
427 write_lock_bh(&local
->sub_if_lock
);
428 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
429 write_unlock_bh(&local
->sub_if_lock
);
431 if (!local
->ops
->hw_scan
&&
432 local
->scan_dev
== sdata
->dev
) {
433 local
->sta_scanning
= 0;
434 cancel_delayed_work(&local
->scan_work
);
436 flush_workqueue(local
->hw
.workqueue
);
441 static int ieee80211_stop(struct net_device
*dev
)
443 struct ieee80211_sub_if_data
*sdata
;
444 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
446 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
448 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&&
449 local
->open_count
> 1 &&
450 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
451 /* remove "soft monitor" interface */
454 if (!local
->monitors
)
455 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
459 netif_stop_queue(dev
);
460 ieee80211_if_shutdown(dev
);
462 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
464 if (!local
->monitors
)
465 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
467 /* disable all keys for as long as this netdev is down */
468 ieee80211_disable_keys(sdata
);
472 if (local
->open_count
== 0) {
473 if (netif_running(local
->mdev
))
474 dev_close(local
->mdev
);
476 dev_close(local
->apdev
);
477 if (local
->ops
->stop
)
478 local
->ops
->stop(local_to_hw(local
));
479 tasklet_disable(&local
->tx_pending_tasklet
);
480 tasklet_disable(&local
->tasklet
);
482 if (local
->ops
->remove_interface
) {
483 struct ieee80211_if_init_conf conf
;
485 conf
.if_id
= dev
->ifindex
;
486 conf
.type
= sdata
->type
;
487 conf
.mac_addr
= dev
->dev_addr
;
488 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
491 ieee80211_start_hard_monitor(local
);
496 enum netif_tx_lock_class
{
501 static inline void netif_tx_lock_nested(struct net_device
*dev
, int subclass
)
503 spin_lock_nested(&dev
->_xmit_lock
, subclass
);
504 dev
->xmit_lock_owner
= smp_processor_id();
507 static void ieee80211_set_multicast_list(struct net_device
*dev
)
509 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
510 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
511 unsigned short flags
;
513 netif_tx_lock_nested(local
->mdev
, TX_LOCK_MASTER
);
514 if (((dev
->flags
& IFF_ALLMULTI
) != 0) ^
515 ((sdata
->flags
& IEEE80211_SDATA_ALLMULTI
) != 0)) {
516 if (sdata
->flags
& IEEE80211_SDATA_ALLMULTI
)
517 local
->iff_allmultis
--;
519 local
->iff_allmultis
++;
520 sdata
->flags
^= IEEE80211_SDATA_ALLMULTI
;
522 if (((dev
->flags
& IFF_PROMISC
) != 0) ^
523 ((sdata
->flags
& IEEE80211_SDATA_PROMISC
) != 0)) {
524 if (sdata
->flags
& IEEE80211_SDATA_PROMISC
)
525 local
->iff_promiscs
--;
527 local
->iff_promiscs
++;
528 sdata
->flags
^= IEEE80211_SDATA_PROMISC
;
530 if (dev
->mc_count
!= sdata
->mc_count
) {
531 local
->mc_count
= local
->mc_count
- sdata
->mc_count
+
533 sdata
->mc_count
= dev
->mc_count
;
535 if (local
->ops
->set_multicast_list
) {
536 flags
= local
->mdev
->flags
;
537 if (local
->iff_allmultis
)
538 flags
|= IFF_ALLMULTI
;
539 if (local
->iff_promiscs
)
540 flags
|= IFF_PROMISC
;
541 read_lock(&local
->sub_if_lock
);
542 local
->ops
->set_multicast_list(local_to_hw(local
), flags
,
544 read_unlock(&local
->sub_if_lock
);
546 netif_tx_unlock(local
->mdev
);
549 /* Must not be called for mdev and apdev */
550 void ieee80211_if_setup(struct net_device
*dev
)
553 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
554 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
555 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
556 dev
->change_mtu
= ieee80211_change_mtu
;
557 dev
->open
= ieee80211_open
;
558 dev
->stop
= ieee80211_stop
;
559 dev
->uninit
= ieee80211_if_reinit
;
560 dev
->destructor
= ieee80211_if_free
;
563 /* WDS specialties */
565 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
567 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
568 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
569 struct sta_info
*sta
;
570 DECLARE_MAC_BUF(mac
);
572 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
575 /* Create STA entry for the new peer */
576 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
581 /* Remove STA entry for the old peer */
582 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
587 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
589 dev
->name
, print_mac(mac
, sdata
->u
.wds
.remote_addr
));
592 /* Update WDS link data */
593 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
598 /* everything else */
600 static int __ieee80211_if_config(struct net_device
*dev
,
601 struct sk_buff
*beacon
,
602 struct ieee80211_tx_control
*control
)
604 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
605 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
606 struct ieee80211_if_conf conf
;
607 static u8 scan_bssid
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
609 if (!local
->ops
->config_interface
|| !netif_running(dev
))
612 memset(&conf
, 0, sizeof(conf
));
613 conf
.type
= sdata
->type
;
614 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
615 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
616 if (local
->sta_scanning
&&
617 local
->scan_dev
== dev
)
618 conf
.bssid
= scan_bssid
;
620 conf
.bssid
= sdata
->u
.sta
.bssid
;
621 conf
.ssid
= sdata
->u
.sta
.ssid
;
622 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
623 conf
.generic_elem
= sdata
->u
.sta
.extra_ie
;
624 conf
.generic_elem_len
= sdata
->u
.sta
.extra_ie_len
;
625 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
626 conf
.ssid
= sdata
->u
.ap
.ssid
;
627 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
628 conf
.generic_elem
= sdata
->u
.ap
.generic_elem
;
629 conf
.generic_elem_len
= sdata
->u
.ap
.generic_elem_len
;
630 conf
.beacon
= beacon
;
631 conf
.beacon_control
= control
;
633 return local
->ops
->config_interface(local_to_hw(local
),
634 dev
->ifindex
, &conf
);
637 int ieee80211_if_config(struct net_device
*dev
)
639 return __ieee80211_if_config(dev
, NULL
, NULL
);
642 int ieee80211_if_config_beacon(struct net_device
*dev
)
644 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
645 struct ieee80211_tx_control control
;
648 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
650 skb
= ieee80211_beacon_get(local_to_hw(local
), dev
->ifindex
, &control
);
653 return __ieee80211_if_config(dev
, skb
, &control
);
656 int ieee80211_hw_config(struct ieee80211_local
*local
)
658 struct ieee80211_hw_mode
*mode
;
659 struct ieee80211_channel
*chan
;
662 if (local
->sta_scanning
) {
663 chan
= local
->scan_channel
;
664 mode
= local
->scan_hw_mode
;
666 chan
= local
->oper_channel
;
667 mode
= local
->oper_hw_mode
;
670 local
->hw
.conf
.channel
= chan
->chan
;
671 local
->hw
.conf
.channel_val
= chan
->val
;
672 if (!local
->hw
.conf
.power_level
) {
673 local
->hw
.conf
.power_level
= chan
->power_level
;
675 local
->hw
.conf
.power_level
= min(chan
->power_level
,
676 local
->hw
.conf
.power_level
);
678 local
->hw
.conf
.freq
= chan
->freq
;
679 local
->hw
.conf
.phymode
= mode
->mode
;
680 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
681 local
->hw
.conf
.chan
= chan
;
682 local
->hw
.conf
.mode
= mode
;
684 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
685 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d "
686 "phymode=%d\n", local
->hw
.conf
.channel
, local
->hw
.conf
.freq
,
687 local
->hw
.conf
.phymode
);
688 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
690 if (local
->ops
->config
)
691 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
696 void ieee80211_erp_info_change_notify(struct net_device
*dev
, u8 changes
)
698 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
699 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
700 if (local
->ops
->erp_ie_changed
)
701 local
->ops
->erp_ie_changed(local_to_hw(local
), changes
,
702 !!(sdata
->flags
& IEEE80211_SDATA_USE_PROTECTION
),
703 !(sdata
->flags
& IEEE80211_SDATA_SHORT_PREAMBLE
));
706 void ieee80211_reset_erp_info(struct net_device
*dev
)
708 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
710 sdata
->flags
&= ~(IEEE80211_SDATA_USE_PROTECTION
|
711 IEEE80211_SDATA_SHORT_PREAMBLE
);
712 ieee80211_erp_info_change_notify(dev
,
713 IEEE80211_ERP_CHANGE_PROTECTION
|
714 IEEE80211_ERP_CHANGE_PREAMBLE
);
717 struct dev_mc_list
*ieee80211_get_mc_list_item(struct ieee80211_hw
*hw
,
718 struct dev_mc_list
*prev
,
721 struct ieee80211_local
*local
= hw_to_local(hw
);
722 struct ieee80211_sub_if_data
*sdata
= *ptr
;
723 struct dev_mc_list
*mc
;
729 if (!prev
|| !prev
->next
) {
731 sdata
= list_entry(sdata
->list
.next
,
732 struct ieee80211_sub_if_data
, list
);
734 sdata
= list_entry(local
->sub_if_list
.next
,
735 struct ieee80211_sub_if_data
, list
);
736 if (&sdata
->list
!= &local
->sub_if_list
)
737 mc
= sdata
->dev
->mc_list
;
746 EXPORT_SYMBOL(ieee80211_get_mc_list_item
);
748 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
750 struct ieee80211_tx_status
*status
)
752 struct ieee80211_local
*local
= hw_to_local(hw
);
753 struct ieee80211_tx_status
*saved
;
756 skb
->dev
= local
->mdev
;
757 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
758 if (unlikely(!saved
)) {
760 printk(KERN_WARNING
"%s: Not enough memory, "
761 "dropping tx status", skb
->dev
->name
);
762 /* should be dev_kfree_skb_irq, but due to this function being
763 * named _irqsafe instead of just _irq we can't be sure that
764 * people won't call it from non-irq contexts */
765 dev_kfree_skb_any(skb
);
768 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
769 /* copy pointer to saved status into skb->cb for use by tasklet */
770 memcpy(skb
->cb
, &saved
, sizeof(saved
));
772 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
773 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
774 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
775 tmp
= skb_queue_len(&local
->skb_queue
) +
776 skb_queue_len(&local
->skb_queue_unreliable
);
777 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
778 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
779 memcpy(&saved
, skb
->cb
, sizeof(saved
));
781 dev_kfree_skb_irq(skb
);
783 I802_DEBUG_INC(local
->tx_status_drop
);
785 tasklet_schedule(&local
->tasklet
);
787 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
789 static void ieee80211_tasklet_handler(unsigned long data
)
791 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
793 struct ieee80211_rx_status rx_status
;
794 struct ieee80211_tx_status
*tx_status
;
796 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
797 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
798 switch (skb
->pkt_type
) {
799 case IEEE80211_RX_MSG
:
800 /* status is in skb->cb */
801 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
802 /* Clear skb->type in order to not confuse kernel
805 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
807 case IEEE80211_TX_STATUS_MSG
:
808 /* get pointer to saved status out of skb->cb */
809 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
811 ieee80211_tx_status(local_to_hw(local
),
815 default: /* should never get here! */
816 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
817 local
->mdev
->name
, skb
->pkt_type
);
824 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
825 * make a prepared TX frame (one that has been given to hw) to look like brand
826 * new IEEE 802.11 frame that is ready to go through TX processing again.
827 * Also, tx_packet_data in cb is restored from tx_control. */
828 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
829 struct ieee80211_key
*key
,
831 struct ieee80211_tx_control
*control
)
833 int hdrlen
, iv_len
, mic_len
;
834 struct ieee80211_tx_packet_data
*pkt_data
;
836 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
837 pkt_data
->ifindex
= control
->ifindex
;
839 if (control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
)
840 pkt_data
->flags
|= IEEE80211_TXPD_REQ_TX_STATUS
;
841 if (control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
)
842 pkt_data
->flags
|= IEEE80211_TXPD_DO_NOT_ENCRYPT
;
843 if (control
->flags
& IEEE80211_TXCTL_REQUEUE
)
844 pkt_data
->flags
|= IEEE80211_TXPD_REQUEUE
;
845 if (control
->type
== IEEE80211_IF_TYPE_MGMT
)
846 pkt_data
->flags
|= IEEE80211_TXPD_MGMT_IFACE
;
847 pkt_data
->queue
= control
->queue
;
849 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
854 switch (key
->conf
.alg
) {
857 mic_len
= WEP_ICV_LEN
;
860 iv_len
= TKIP_IV_LEN
;
861 mic_len
= TKIP_ICV_LEN
;
864 iv_len
= CCMP_HDR_LEN
;
865 mic_len
= CCMP_MIC_LEN
;
871 if (skb
->len
>= mic_len
&&
872 !(key
->flags
& KEY_FLAG_UPLOADED_TO_HARDWARE
))
873 skb_trim(skb
, skb
->len
- mic_len
);
874 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
875 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
876 skb_pull(skb
, iv_len
);
881 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
882 u16 fc
= le16_to_cpu(hdr
->frame_control
);
883 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
884 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
885 hdr
->frame_control
= cpu_to_le16(fc
);
886 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
892 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
893 struct ieee80211_tx_status
*status
)
895 struct sk_buff
*skb2
;
896 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
897 struct ieee80211_local
*local
= hw_to_local(hw
);
900 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
901 struct ieee80211_sub_if_data
*sdata
;
906 "%s: ieee80211_tx_status called with NULL status\n",
912 if (status
->excessive_retries
) {
913 struct sta_info
*sta
;
914 sta
= sta_info_get(local
, hdr
->addr1
);
916 if (sta
->flags
& WLAN_STA_PS
) {
917 /* The STA is in power save mode, so assume
918 * that this TX packet failed because of that.
920 status
->excessive_retries
= 0;
921 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
927 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
928 struct sta_info
*sta
;
929 sta
= sta_info_get(local
, hdr
->addr1
);
931 sta
->tx_filtered_count
++;
933 /* Clear the TX filter mask for this STA when sending
934 * the next packet. If the STA went to power save mode,
935 * this will happen when it is waking up for the next
937 sta
->clear_dst_mask
= 1;
939 /* TODO: Is the WLAN_STA_PS flag always set here or is
940 * the race between RX and TX status causing some
941 * packets to be filtered out before 80211.o gets an
942 * update for PS status? This seems to be the case, so
943 * no changes are likely to be needed. */
944 if (sta
->flags
& WLAN_STA_PS
&&
945 skb_queue_len(&sta
->tx_filtered
) <
947 ieee80211_remove_tx_extra(local
, sta
->key
,
950 skb_queue_tail(&sta
->tx_filtered
, skb
);
951 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
952 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
953 /* Software retry the packet once */
954 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
955 ieee80211_remove_tx_extra(local
, sta
->key
,
960 if (net_ratelimit()) {
961 printk(KERN_DEBUG
"%s: dropped TX "
962 "filtered frame queue_len=%d "
967 !!(sta
->flags
& WLAN_STA_PS
),
976 /* FIXME: STUPID to call this with both local and local->mdev */
977 rate_control_tx_status(local
, local
->mdev
, skb
, status
);
980 ieee80211_led_tx(local
, 0);
983 * Fragments are passed to low-level drivers as separate skbs, so these
984 * are actually fragments, not frames. Update frame counters only for
985 * the first fragment of the frame. */
987 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
988 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
990 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
992 local
->dot11TransmittedFrameCount
++;
993 if (is_multicast_ether_addr(hdr
->addr1
))
994 local
->dot11MulticastTransmittedFrameCount
++;
995 if (status
->retry_count
> 0)
996 local
->dot11RetryCount
++;
997 if (status
->retry_count
> 1)
998 local
->dot11MultipleRetryCount
++;
1001 /* This counter shall be incremented for an acknowledged MPDU
1002 * with an individual address in the address 1 field or an MPDU
1003 * with a multicast address in the address 1 field of type Data
1005 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1006 type
== IEEE80211_FTYPE_DATA
||
1007 type
== IEEE80211_FTYPE_MGMT
)
1008 local
->dot11TransmittedFragmentCount
++;
1011 local
->dot11FailedCount
++;
1014 msg_type
= (status
->flags
& IEEE80211_TX_STATUS_ACK
) ?
1015 ieee80211_msg_tx_callback_ack
: ieee80211_msg_tx_callback_fail
;
1017 /* this was a transmitted frame, but now we want to reuse it */
1020 if ((status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
) &&
1022 if (local
->monitors
) {
1023 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1030 /* Send frame to hostapd */
1031 ieee80211_rx_mgmt(local
, skb2
, NULL
, msg_type
);
1037 if (!local
->monitors
) {
1042 /* send frame to monitor interfaces now */
1044 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1045 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1050 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1051 skb_push(skb
, sizeof(*rthdr
));
1053 memset(rthdr
, 0, sizeof(*rthdr
));
1054 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1055 rthdr
->hdr
.it_present
=
1056 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1057 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1059 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1060 !is_multicast_ether_addr(hdr
->addr1
))
1061 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1063 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1064 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1065 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1066 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1067 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1069 rthdr
->data_retries
= status
->retry_count
;
1071 read_lock(&local
->sub_if_lock
);
1072 monitors
= local
->monitors
;
1073 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1075 * Using the monitors counter is possibly racy, but
1076 * if the value is wrong we simply either clone the skb
1077 * once too much or forget sending it to one monitor iface
1078 * The latter case isn't nice but fixing the race is much
1081 if (!monitors
|| !skb
)
1084 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
1085 if (!netif_running(sdata
->dev
))
1089 skb2
= skb_clone(skb
, GFP_KERNEL
);
1092 skb
->dev
= sdata
->dev
;
1093 /* XXX: is this sufficient for BPF? */
1094 skb_set_mac_header(skb
, 0);
1095 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1096 skb
->pkt_type
= PACKET_OTHERHOST
;
1097 skb
->protocol
= htons(ETH_P_802_2
);
1098 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1104 read_unlock(&local
->sub_if_lock
);
1108 EXPORT_SYMBOL(ieee80211_tx_status
);
1110 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1111 const struct ieee80211_ops
*ops
)
1113 struct net_device
*mdev
;
1114 struct ieee80211_local
*local
;
1115 struct ieee80211_sub_if_data
*sdata
;
1117 struct wiphy
*wiphy
;
1119 /* Ensure 32-byte alignment of our private data and hw private data.
1120 * We use the wiphy priv data for both our ieee80211_local and for
1121 * the driver's private data
1123 * In memory it'll be like this:
1125 * +-------------------------+
1127 * +-------------------------+
1128 * | struct ieee80211_local |
1129 * +-------------------------+
1130 * | driver's private data |
1131 * +-------------------------+
1134 priv_size
= ((sizeof(struct ieee80211_local
) +
1135 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1138 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1143 wiphy
->privid
= mac80211_wiphy_privid
;
1145 local
= wiphy_priv(wiphy
);
1146 local
->hw
.wiphy
= wiphy
;
1148 local
->hw
.priv
= (char *)local
+
1149 ((sizeof(struct ieee80211_local
) +
1150 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1153 BUG_ON(!ops
->config
);
1154 BUG_ON(!ops
->add_interface
);
1157 /* for now, mdev needs sub_if_data :/ */
1158 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1159 "wmaster%d", ether_setup
);
1165 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1166 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1167 sdata
->wdev
.wiphy
= wiphy
;
1169 local
->hw
.queues
= 1; /* default */
1172 local
->rx_pre_handlers
= ieee80211_rx_pre_handlers
;
1173 local
->rx_handlers
= ieee80211_rx_handlers
;
1174 local
->tx_handlers
= ieee80211_tx_handlers
;
1176 local
->bridge_packets
= 1;
1178 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1179 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1180 local
->short_retry_limit
= 7;
1181 local
->long_retry_limit
= 4;
1182 local
->hw
.conf
.radio_enabled
= 1;
1184 local
->enabled_modes
= ~0;
1186 INIT_LIST_HEAD(&local
->modes_list
);
1188 rwlock_init(&local
->sub_if_lock
);
1189 INIT_LIST_HEAD(&local
->sub_if_list
);
1191 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1192 ieee80211_rx_bss_list_init(mdev
);
1194 sta_info_init(local
);
1196 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1197 mdev
->open
= ieee80211_master_open
;
1198 mdev
->stop
= ieee80211_master_stop
;
1199 mdev
->type
= ARPHRD_IEEE80211
;
1200 mdev
->hard_header_parse
= header_parse_80211
;
1202 sdata
->type
= IEEE80211_IF_TYPE_AP
;
1204 sdata
->local
= local
;
1205 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1206 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1207 ieee80211_if_sdata_init(sdata
);
1208 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
1210 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1211 (unsigned long)local
);
1212 tasklet_disable(&local
->tx_pending_tasklet
);
1214 tasklet_init(&local
->tasklet
,
1215 ieee80211_tasklet_handler
,
1216 (unsigned long) local
);
1217 tasklet_disable(&local
->tasklet
);
1219 skb_queue_head_init(&local
->skb_queue
);
1220 skb_queue_head_init(&local
->skb_queue_unreliable
);
1222 return local_to_hw(local
);
1224 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1226 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1228 struct ieee80211_local
*local
= hw_to_local(hw
);
1232 result
= wiphy_register(local
->hw
.wiphy
);
1236 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1237 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1238 if (!local
->hw
.workqueue
) {
1240 goto fail_workqueue
;
1244 * The hardware needs headroom for sending the frame,
1245 * and we need some headroom for passing the frame to monitor
1246 * interfaces, but never both at the same time.
1248 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1249 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1251 debugfs_hw_add(local
);
1253 local
->hw
.conf
.beacon_int
= 1000;
1255 local
->wstats_flags
|= local
->hw
.max_rssi
?
1256 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1257 local
->wstats_flags
|= local
->hw
.max_signal
?
1258 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1259 local
->wstats_flags
|= local
->hw
.max_noise
?
1260 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1261 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1262 local
->wstats_flags
|= IW_QUAL_DBM
;
1264 result
= sta_info_start(local
);
1269 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1273 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1274 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1276 result
= register_netdevice(local
->mdev
);
1280 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1282 result
= ieee80211_init_rate_ctrl_alg(local
, NULL
);
1284 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1285 "algorithm\n", local
->mdev
->name
);
1289 result
= ieee80211_wep_init(local
);
1292 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1297 ieee80211_install_qdisc(local
->mdev
);
1299 /* add one default STA interface */
1300 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1301 IEEE80211_IF_TYPE_STA
);
1303 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1306 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1309 ieee80211_led_init(local
);
1314 rate_control_deinitialize(local
);
1316 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1317 unregister_netdevice(local
->mdev
);
1320 sta_info_stop(local
);
1322 debugfs_hw_del(local
);
1323 destroy_workqueue(local
->hw
.workqueue
);
1325 wiphy_unregister(local
->hw
.wiphy
);
1328 EXPORT_SYMBOL(ieee80211_register_hw
);
1330 int ieee80211_register_hwmode(struct ieee80211_hw
*hw
,
1331 struct ieee80211_hw_mode
*mode
)
1333 struct ieee80211_local
*local
= hw_to_local(hw
);
1334 struct ieee80211_rate
*rate
;
1337 INIT_LIST_HEAD(&mode
->list
);
1338 list_add_tail(&mode
->list
, &local
->modes_list
);
1340 local
->hw_modes
|= (1 << mode
->mode
);
1341 for (i
= 0; i
< mode
->num_rates
; i
++) {
1342 rate
= &(mode
->rates
[i
]);
1343 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
1345 ieee80211_prepare_rates(local
, mode
);
1347 if (!local
->oper_hw_mode
) {
1348 /* Default to this mode */
1349 local
->hw
.conf
.phymode
= mode
->mode
;
1350 local
->oper_hw_mode
= local
->scan_hw_mode
= mode
;
1351 local
->oper_channel
= local
->scan_channel
= &mode
->channels
[0];
1352 local
->hw
.conf
.mode
= local
->oper_hw_mode
;
1353 local
->hw
.conf
.chan
= local
->oper_channel
;
1356 if (!(hw
->flags
& IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
))
1357 ieee80211_set_default_regdomain(mode
);
1361 EXPORT_SYMBOL(ieee80211_register_hwmode
);
1363 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1365 struct ieee80211_local
*local
= hw_to_local(hw
);
1366 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1367 struct list_head tmp_list
;
1370 tasklet_kill(&local
->tx_pending_tasklet
);
1371 tasklet_kill(&local
->tasklet
);
1375 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1377 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1379 ieee80211_if_del_mgmt(local
);
1381 write_lock_bh(&local
->sub_if_lock
);
1382 list_replace_init(&local
->sub_if_list
, &tmp_list
);
1383 write_unlock_bh(&local
->sub_if_lock
);
1385 list_for_each_entry_safe(sdata
, tmp
, &tmp_list
, list
)
1386 __ieee80211_if_del(local
, sdata
);
1390 ieee80211_rx_bss_list_deinit(local
->mdev
);
1391 ieee80211_clear_tx_pending(local
);
1392 sta_info_stop(local
);
1393 rate_control_deinitialize(local
);
1394 debugfs_hw_del(local
);
1396 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
1397 kfree(local
->supp_rates
[i
]);
1398 kfree(local
->basic_rates
[i
]);
1401 if (skb_queue_len(&local
->skb_queue
)
1402 || skb_queue_len(&local
->skb_queue_unreliable
))
1403 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1405 skb_queue_purge(&local
->skb_queue
);
1406 skb_queue_purge(&local
->skb_queue_unreliable
);
1408 destroy_workqueue(local
->hw
.workqueue
);
1409 wiphy_unregister(local
->hw
.wiphy
);
1410 ieee80211_wep_free(local
);
1411 ieee80211_led_exit(local
);
1413 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1415 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1417 struct ieee80211_local
*local
= hw_to_local(hw
);
1419 ieee80211_if_free(local
->mdev
);
1420 wiphy_free(local
->hw
.wiphy
);
1422 EXPORT_SYMBOL(ieee80211_free_hw
);
1424 static int __init
ieee80211_init(void)
1426 struct sk_buff
*skb
;
1429 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1431 ret
= ieee80211_wme_register();
1433 printk(KERN_DEBUG
"ieee80211_init: failed to "
1434 "initialize WME (err=%d)\n", ret
);
1438 ieee80211_debugfs_netdev_init();
1439 ieee80211_regdomain_init();
1444 static void __exit
ieee80211_exit(void)
1446 ieee80211_wme_unregister();
1447 ieee80211_debugfs_netdev_exit();
1451 subsys_initcall(ieee80211_init
);
1452 module_exit(ieee80211_exit
);
1454 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1455 MODULE_LICENSE("GPL");