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/cfg80211.h>
26 #include "ieee80211_common.h"
27 #include "ieee80211_i.h"
28 #include "ieee80211_rate.h"
32 #include "ieee80211_led.h"
33 #include "ieee80211_cfg.h"
35 #include "debugfs_netdev.h"
38 * For seeing transmitted packets on monitor interfaces
39 * we have a radiotap header too.
41 struct ieee80211_tx_status_rtap_hdr
{
42 struct ieee80211_radiotap_header hdr
;
45 } __attribute__ ((packed
));
47 /* common interface routines */
49 static struct net_device_stats
*ieee80211_get_stats(struct net_device
*dev
)
51 struct ieee80211_sub_if_data
*sdata
;
52 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
53 return &(sdata
->stats
);
56 static int header_parse_80211(struct sk_buff
*skb
, unsigned char *haddr
)
58 memcpy(haddr
, skb_mac_header(skb
) + 10, ETH_ALEN
); /* addr2 */
62 /* master interface */
64 static int ieee80211_master_open(struct net_device
*dev
)
66 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
67 struct ieee80211_sub_if_data
*sdata
;
68 int res
= -EOPNOTSUPP
;
70 read_lock(&local
->sub_if_lock
);
71 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
72 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
)) {
77 read_unlock(&local
->sub_if_lock
);
81 static int ieee80211_master_stop(struct net_device
*dev
)
83 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
84 struct ieee80211_sub_if_data
*sdata
;
86 read_lock(&local
->sub_if_lock
);
87 list_for_each_entry(sdata
, &local
->sub_if_list
, list
)
88 if (sdata
->dev
!= dev
&& netif_running(sdata
->dev
))
89 dev_close(sdata
->dev
);
90 read_unlock(&local
->sub_if_lock
);
95 /* management interface */
98 ieee80211_fill_frame_info(struct ieee80211_local
*local
,
99 struct ieee80211_frame_info
*fi
,
100 struct ieee80211_rx_status
*status
)
104 struct ieee80211_rate
*rate
;
106 jiffies_to_timespec(jiffies
, &ts
);
107 fi
->hosttime
= cpu_to_be64((u64
) ts
.tv_sec
* 1000000 +
109 fi
->mactime
= cpu_to_be64(status
->mactime
);
110 switch (status
->phymode
) {
111 case MODE_IEEE80211A
:
112 fi
->phytype
= htonl(ieee80211_phytype_ofdm_dot11_a
);
114 case MODE_IEEE80211B
:
115 fi
->phytype
= htonl(ieee80211_phytype_dsss_dot11_b
);
117 case MODE_IEEE80211G
:
118 fi
->phytype
= htonl(ieee80211_phytype_pbcc_dot11_g
);
120 case MODE_ATHEROS_TURBO
:
122 htonl(ieee80211_phytype_dsss_dot11_turbo
);
125 fi
->phytype
= htonl(0xAAAAAAAA);
128 fi
->channel
= htonl(status
->channel
);
129 rate
= ieee80211_get_rate(local
, status
->phymode
,
132 fi
->datarate
= htonl(rate
->rate
);
133 if (rate
->flags
& IEEE80211_RATE_PREAMBLE2
) {
134 if (status
->rate
== rate
->val
)
135 fi
->preamble
= htonl(2); /* long */
136 else if (status
->rate
== rate
->val2
)
137 fi
->preamble
= htonl(1); /* short */
139 fi
->preamble
= htonl(0);
141 fi
->datarate
= htonl(0);
142 fi
->preamble
= htonl(0);
145 fi
->antenna
= htonl(status
->antenna
);
146 fi
->priority
= htonl(0xffffffff); /* no clue */
147 fi
->ssi_type
= htonl(ieee80211_ssi_raw
);
148 fi
->ssi_signal
= htonl(status
->ssi
);
149 fi
->ssi_noise
= 0x00000000;
152 /* clear everything because we really don't know.
153 * the msg_type field isn't present on monitor frames
154 * so we don't know whether it will be present or not,
155 * but it's ok to not clear it since it'll be assigned
157 memset(fi
, 0, sizeof(*fi
) - sizeof(fi
->msg_type
));
159 fi
->ssi_type
= htonl(ieee80211_ssi_none
);
161 fi
->version
= htonl(IEEE80211_FI_VERSION
);
162 fi
->length
= cpu_to_be32(sizeof(*fi
) - sizeof(fi
->msg_type
));
165 /* this routine is actually not just for this, but also
166 * for pushing fake 'management' frames into userspace.
167 * it shall be replaced by a netlink-based system. */
169 ieee80211_rx_mgmt(struct ieee80211_local
*local
, struct sk_buff
*skb
,
170 struct ieee80211_rx_status
*status
, u32 msg_type
)
172 struct ieee80211_frame_info
*fi
;
173 const size_t hlen
= sizeof(struct ieee80211_frame_info
);
174 struct ieee80211_sub_if_data
*sdata
;
176 skb
->dev
= local
->apdev
;
178 sdata
= IEEE80211_DEV_TO_SUB_IF(local
->apdev
);
180 if (skb_headroom(skb
) < hlen
) {
181 I802_DEBUG_INC(local
->rx_expand_skb_head
);
182 if (pskb_expand_head(skb
, hlen
, 0, GFP_ATOMIC
)) {
188 fi
= (struct ieee80211_frame_info
*) skb_push(skb
, hlen
);
190 ieee80211_fill_frame_info(local
, fi
, status
);
191 fi
->msg_type
= htonl(msg_type
);
193 sdata
->stats
.rx_packets
++;
194 sdata
->stats
.rx_bytes
+= skb
->len
;
196 skb_set_mac_header(skb
, 0);
197 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
198 skb
->pkt_type
= PACKET_OTHERHOST
;
199 skb
->protocol
= htons(ETH_P_802_2
);
200 memset(skb
->cb
, 0, sizeof(skb
->cb
));
204 int ieee80211_radar_status(struct ieee80211_hw
*hw
, int channel
,
205 int radar
, int radar_type
)
208 struct ieee80211_radar_info
*msg
;
209 struct ieee80211_local
*local
= hw_to_local(hw
);
214 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
215 sizeof(struct ieee80211_radar_info
));
219 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
221 msg
= (struct ieee80211_radar_info
*)
222 skb_put(skb
, sizeof(struct ieee80211_radar_info
));
223 msg
->channel
= channel
;
225 msg
->radar_type
= radar_type
;
227 ieee80211_rx_mgmt(local
, skb
, NULL
, ieee80211_msg_radar
);
230 EXPORT_SYMBOL(ieee80211_radar_status
);
232 void ieee80211_key_threshold_notify(struct net_device
*dev
,
233 struct ieee80211_key
*key
,
234 struct sta_info
*sta
)
236 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
238 struct ieee80211_msg_key_notification
*msg
;
240 /* if no one will get it anyway, don't even allocate it.
241 * unlikely because this is only relevant for APs
242 * where the device must be open... */
243 if (unlikely(!local
->apdev
))
246 skb
= dev_alloc_skb(sizeof(struct ieee80211_frame_info
) +
247 sizeof(struct ieee80211_msg_key_notification
));
251 skb_reserve(skb
, sizeof(struct ieee80211_frame_info
));
252 msg
= (struct ieee80211_msg_key_notification
*)
253 skb_put(skb
, sizeof(struct ieee80211_msg_key_notification
));
254 msg
->tx_rx_count
= key
->tx_rx_count
;
255 memcpy(msg
->ifname
, dev
->name
, IFNAMSIZ
);
257 memcpy(msg
->addr
, sta
->addr
, ETH_ALEN
);
259 memset(msg
->addr
, 0xff, ETH_ALEN
);
261 key
->tx_rx_count
= 0;
263 ieee80211_rx_mgmt(local
, skb
, NULL
,
264 ieee80211_msg_key_threshold_notification
);
267 static int ieee80211_mgmt_open(struct net_device
*dev
)
269 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
271 if (!netif_running(local
->mdev
))
276 static int ieee80211_mgmt_stop(struct net_device
*dev
)
281 static int ieee80211_change_mtu_apdev(struct net_device
*dev
, int new_mtu
)
283 /* FIX: what would be proper limits for MTU?
284 * This interface uses 802.11 frames. */
285 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
) {
286 printk(KERN_WARNING
"%s: invalid MTU %d\n",
291 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
292 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
293 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
298 void ieee80211_if_mgmt_setup(struct net_device
*dev
)
301 dev
->hard_start_xmit
= ieee80211_mgmt_start_xmit
;
302 dev
->change_mtu
= ieee80211_change_mtu_apdev
;
303 dev
->get_stats
= ieee80211_get_stats
;
304 dev
->open
= ieee80211_mgmt_open
;
305 dev
->stop
= ieee80211_mgmt_stop
;
306 dev
->type
= ARPHRD_IEEE80211_PRISM
;
307 dev
->hard_header_parse
= header_parse_80211
;
308 dev
->uninit
= ieee80211_if_reinit
;
309 dev
->destructor
= ieee80211_if_free
;
312 /* regular interfaces */
314 static int ieee80211_change_mtu(struct net_device
*dev
, int new_mtu
)
316 /* FIX: what would be proper limits for MTU?
317 * This interface uses 802.3 frames. */
318 if (new_mtu
< 256 || new_mtu
> IEEE80211_MAX_DATA_LEN
- 24 - 6) {
319 printk(KERN_WARNING
"%s: invalid MTU %d\n",
324 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
325 printk(KERN_DEBUG
"%s: setting MTU %d\n", dev
->name
, new_mtu
);
326 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
331 static inline int identical_mac_addr_allowed(int type1
, int type2
)
333 return (type1
== IEEE80211_IF_TYPE_MNTR
||
334 type2
== IEEE80211_IF_TYPE_MNTR
||
335 (type1
== IEEE80211_IF_TYPE_AP
&&
336 type2
== IEEE80211_IF_TYPE_WDS
) ||
337 (type1
== IEEE80211_IF_TYPE_WDS
&&
338 (type2
== IEEE80211_IF_TYPE_WDS
||
339 type2
== IEEE80211_IF_TYPE_AP
)) ||
340 (type1
== IEEE80211_IF_TYPE_AP
&&
341 type2
== IEEE80211_IF_TYPE_VLAN
) ||
342 (type1
== IEEE80211_IF_TYPE_VLAN
&&
343 (type2
== IEEE80211_IF_TYPE_AP
||
344 type2
== IEEE80211_IF_TYPE_VLAN
)));
347 /* Check if running monitor interfaces should go to a "soft monitor" mode
348 * and switch them if necessary. */
349 static inline void ieee80211_start_soft_monitor(struct ieee80211_local
*local
)
351 struct ieee80211_if_init_conf conf
;
353 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
354 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
) &&
355 local
->ops
->remove_interface
) {
357 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
358 conf
.mac_addr
= NULL
;
359 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
363 /* Check if running monitor interfaces should go to a "hard monitor" mode
364 * and switch them if necessary. */
365 static void ieee80211_start_hard_monitor(struct ieee80211_local
*local
)
367 struct ieee80211_if_init_conf conf
;
369 if (local
->open_count
&& local
->open_count
== local
->monitors
&&
370 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
372 conf
.type
= IEEE80211_IF_TYPE_MNTR
;
373 conf
.mac_addr
= NULL
;
374 local
->ops
->add_interface(local_to_hw(local
), &conf
);
378 static int ieee80211_open(struct net_device
*dev
)
380 struct ieee80211_sub_if_data
*sdata
, *nsdata
;
381 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
382 struct ieee80211_if_init_conf conf
;
385 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
386 read_lock(&local
->sub_if_lock
);
387 list_for_each_entry(nsdata
, &local
->sub_if_list
, list
) {
388 struct net_device
*ndev
= nsdata
->dev
;
390 if (ndev
!= dev
&& ndev
!= local
->mdev
&& netif_running(ndev
) &&
391 compare_ether_addr(dev
->dev_addr
, ndev
->dev_addr
) == 0 &&
392 !identical_mac_addr_allowed(sdata
->type
, nsdata
->type
)) {
393 read_unlock(&local
->sub_if_lock
);
397 read_unlock(&local
->sub_if_lock
);
399 if (sdata
->type
== IEEE80211_IF_TYPE_WDS
&&
400 is_zero_ether_addr(sdata
->u
.wds
.remote_addr
))
403 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&& local
->open_count
&&
404 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
405 /* run the interface in a "soft monitor" mode */
408 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
411 ieee80211_start_soft_monitor(local
);
413 conf
.if_id
= dev
->ifindex
;
414 conf
.type
= sdata
->type
;
415 conf
.mac_addr
= dev
->dev_addr
;
416 res
= local
->ops
->add_interface(local_to_hw(local
), &conf
);
418 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
)
419 ieee80211_start_hard_monitor(local
);
423 if (local
->open_count
== 0) {
425 tasklet_enable(&local
->tx_pending_tasklet
);
426 tasklet_enable(&local
->tasklet
);
427 if (local
->ops
->open
)
428 res
= local
->ops
->open(local_to_hw(local
));
430 res
= dev_open(local
->mdev
);
432 if (local
->ops
->stop
)
433 local
->ops
->stop(local_to_hw(local
));
435 res
= ieee80211_hw_config(local
);
436 if (res
&& local
->ops
->stop
)
437 local
->ops
->stop(local_to_hw(local
));
438 else if (!res
&& local
->apdev
)
439 dev_open(local
->apdev
);
443 if (local
->ops
->remove_interface
)
444 local
->ops
->remove_interface(local_to_hw(local
),
451 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
453 local
->hw
.conf
.flags
|= IEEE80211_CONF_RADIOTAP
;
455 ieee80211_if_config(dev
);
457 if (sdata
->type
== IEEE80211_IF_TYPE_STA
&&
458 !local
->user_space_mlme
)
459 netif_carrier_off(dev
);
461 netif_carrier_on(dev
);
463 netif_start_queue(dev
);
467 static void ieee80211_if_shutdown(struct net_device
*dev
)
469 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
470 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
473 switch (sdata
->type
) {
474 case IEEE80211_IF_TYPE_STA
:
475 case IEEE80211_IF_TYPE_IBSS
:
476 sdata
->u
.sta
.state
= IEEE80211_DISABLED
;
477 del_timer_sync(&sdata
->u
.sta
.timer
);
478 skb_queue_purge(&sdata
->u
.sta
.skb_queue
);
479 if (!local
->ops
->hw_scan
&&
480 local
->scan_dev
== sdata
->dev
) {
481 local
->sta_scanning
= 0;
482 cancel_delayed_work(&local
->scan_work
);
484 flush_workqueue(local
->hw
.workqueue
);
489 static int ieee80211_stop(struct net_device
*dev
)
491 struct ieee80211_sub_if_data
*sdata
;
492 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
494 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
496 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
&&
497 local
->open_count
> 1 &&
498 !(local
->hw
.flags
& IEEE80211_HW_MONITOR_DURING_OPER
)) {
499 /* remove "soft monitor" interface */
502 if (!local
->monitors
)
503 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
507 netif_stop_queue(dev
);
508 ieee80211_if_shutdown(dev
);
510 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
512 if (!local
->monitors
)
513 local
->hw
.conf
.flags
&= ~IEEE80211_CONF_RADIOTAP
;
517 if (local
->open_count
== 0) {
518 if (netif_running(local
->mdev
))
519 dev_close(local
->mdev
);
521 dev_close(local
->apdev
);
522 if (local
->ops
->stop
)
523 local
->ops
->stop(local_to_hw(local
));
524 tasklet_disable(&local
->tx_pending_tasklet
);
525 tasklet_disable(&local
->tasklet
);
527 if (local
->ops
->remove_interface
) {
528 struct ieee80211_if_init_conf conf
;
530 conf
.if_id
= dev
->ifindex
;
531 conf
.type
= sdata
->type
;
532 conf
.mac_addr
= dev
->dev_addr
;
533 local
->ops
->remove_interface(local_to_hw(local
), &conf
);
536 ieee80211_start_hard_monitor(local
);
541 enum netif_tx_lock_class
{
546 static inline void netif_tx_lock_nested(struct net_device
*dev
, int subclass
)
548 spin_lock_nested(&dev
->_xmit_lock
, subclass
);
549 dev
->xmit_lock_owner
= smp_processor_id();
552 static void ieee80211_set_multicast_list(struct net_device
*dev
)
554 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
555 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
556 unsigned short flags
;
558 netif_tx_lock_nested(local
->mdev
, TX_LOCK_MASTER
);
559 if (((dev
->flags
& IFF_ALLMULTI
) != 0) ^ (sdata
->allmulti
!= 0)) {
560 if (sdata
->allmulti
) {
562 local
->iff_allmultis
--;
565 local
->iff_allmultis
++;
568 if (((dev
->flags
& IFF_PROMISC
) != 0) ^ (sdata
->promisc
!= 0)) {
569 if (sdata
->promisc
) {
571 local
->iff_promiscs
--;
574 local
->iff_promiscs
++;
577 if (dev
->mc_count
!= sdata
->mc_count
) {
578 local
->mc_count
= local
->mc_count
- sdata
->mc_count
+
580 sdata
->mc_count
= dev
->mc_count
;
582 if (local
->ops
->set_multicast_list
) {
583 flags
= local
->mdev
->flags
;
584 if (local
->iff_allmultis
)
585 flags
|= IFF_ALLMULTI
;
586 if (local
->iff_promiscs
)
587 flags
|= IFF_PROMISC
;
588 read_lock(&local
->sub_if_lock
);
589 local
->ops
->set_multicast_list(local_to_hw(local
), flags
,
591 read_unlock(&local
->sub_if_lock
);
593 netif_tx_unlock(local
->mdev
);
596 /* Must not be called for mdev and apdev */
597 void ieee80211_if_setup(struct net_device
*dev
)
600 dev
->hard_start_xmit
= ieee80211_subif_start_xmit
;
601 dev
->wireless_handlers
= &ieee80211_iw_handler_def
;
602 dev
->set_multicast_list
= ieee80211_set_multicast_list
;
603 dev
->change_mtu
= ieee80211_change_mtu
;
604 dev
->get_stats
= ieee80211_get_stats
;
605 dev
->open
= ieee80211_open
;
606 dev
->stop
= ieee80211_stop
;
607 dev
->uninit
= ieee80211_if_reinit
;
608 dev
->destructor
= ieee80211_if_free
;
611 /* WDS specialties */
613 int ieee80211_if_update_wds(struct net_device
*dev
, u8
*remote_addr
)
615 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
616 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
617 struct sta_info
*sta
;
619 if (compare_ether_addr(remote_addr
, sdata
->u
.wds
.remote_addr
) == 0)
622 /* Create STA entry for the new peer */
623 sta
= sta_info_add(local
, dev
, remote_addr
, GFP_KERNEL
);
628 /* Remove STA entry for the old peer */
629 sta
= sta_info_get(local
, sdata
->u
.wds
.remote_addr
);
632 sta_info_free(sta
, 0);
634 printk(KERN_DEBUG
"%s: could not find STA entry for WDS link "
635 "peer " MAC_FMT
"\n",
636 dev
->name
, MAC_ARG(sdata
->u
.wds
.remote_addr
));
639 /* Update WDS link data */
640 memcpy(&sdata
->u
.wds
.remote_addr
, remote_addr
, ETH_ALEN
);
645 /* everything else */
647 static int __ieee80211_if_config(struct net_device
*dev
,
648 struct sk_buff
*beacon
,
649 struct ieee80211_tx_control
*control
)
651 struct ieee80211_sub_if_data
*sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
652 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
653 struct ieee80211_if_conf conf
;
654 static u8 scan_bssid
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
656 if (!local
->ops
->config_interface
|| !netif_running(dev
))
659 memset(&conf
, 0, sizeof(conf
));
660 conf
.type
= sdata
->type
;
661 if (sdata
->type
== IEEE80211_IF_TYPE_STA
||
662 sdata
->type
== IEEE80211_IF_TYPE_IBSS
) {
663 if (local
->sta_scanning
&&
664 local
->scan_dev
== dev
)
665 conf
.bssid
= scan_bssid
;
667 conf
.bssid
= sdata
->u
.sta
.bssid
;
668 conf
.ssid
= sdata
->u
.sta
.ssid
;
669 conf
.ssid_len
= sdata
->u
.sta
.ssid_len
;
670 conf
.generic_elem
= sdata
->u
.sta
.extra_ie
;
671 conf
.generic_elem_len
= sdata
->u
.sta
.extra_ie_len
;
672 } else if (sdata
->type
== IEEE80211_IF_TYPE_AP
) {
673 conf
.ssid
= sdata
->u
.ap
.ssid
;
674 conf
.ssid_len
= sdata
->u
.ap
.ssid_len
;
675 conf
.generic_elem
= sdata
->u
.ap
.generic_elem
;
676 conf
.generic_elem_len
= sdata
->u
.ap
.generic_elem_len
;
677 conf
.beacon
= beacon
;
678 conf
.beacon_control
= control
;
680 return local
->ops
->config_interface(local_to_hw(local
),
681 dev
->ifindex
, &conf
);
684 int ieee80211_if_config(struct net_device
*dev
)
686 return __ieee80211_if_config(dev
, NULL
, NULL
);
689 int ieee80211_if_config_beacon(struct net_device
*dev
)
691 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
692 struct ieee80211_tx_control control
;
695 if (!(local
->hw
.flags
& IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
))
697 skb
= ieee80211_beacon_get(local_to_hw(local
), dev
->ifindex
, &control
);
700 return __ieee80211_if_config(dev
, skb
, &control
);
703 int ieee80211_hw_config(struct ieee80211_local
*local
)
705 struct ieee80211_hw_mode
*mode
;
706 struct ieee80211_channel
*chan
;
709 if (local
->sta_scanning
) {
710 chan
= local
->scan_channel
;
711 mode
= local
->scan_hw_mode
;
713 chan
= local
->oper_channel
;
714 mode
= local
->oper_hw_mode
;
717 local
->hw
.conf
.channel
= chan
->chan
;
718 local
->hw
.conf
.channel_val
= chan
->val
;
719 local
->hw
.conf
.power_level
= chan
->power_level
;
720 local
->hw
.conf
.freq
= chan
->freq
;
721 local
->hw
.conf
.phymode
= mode
->mode
;
722 local
->hw
.conf
.antenna_max
= chan
->antenna_max
;
723 local
->hw
.conf
.chan
= chan
;
724 local
->hw
.conf
.mode
= mode
;
726 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
727 printk(KERN_DEBUG
"HW CONFIG: channel=%d freq=%d "
728 "phymode=%d\n", local
->hw
.conf
.channel
, local
->hw
.conf
.freq
,
729 local
->hw
.conf
.phymode
);
730 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
732 if (local
->ops
->config
)
733 ret
= local
->ops
->config(local_to_hw(local
), &local
->hw
.conf
);
738 struct dev_mc_list
*ieee80211_get_mc_list_item(struct ieee80211_hw
*hw
,
739 struct dev_mc_list
*prev
,
742 struct ieee80211_local
*local
= hw_to_local(hw
);
743 struct ieee80211_sub_if_data
*sdata
= *ptr
;
744 struct dev_mc_list
*mc
;
750 if (!prev
|| !prev
->next
) {
752 sdata
= list_entry(sdata
->list
.next
,
753 struct ieee80211_sub_if_data
, list
);
755 sdata
= list_entry(local
->sub_if_list
.next
,
756 struct ieee80211_sub_if_data
, list
);
757 if (&sdata
->list
!= &local
->sub_if_list
)
758 mc
= sdata
->dev
->mc_list
;
767 EXPORT_SYMBOL(ieee80211_get_mc_list_item
);
769 static void ieee80211_stat_refresh(unsigned long data
)
771 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
772 struct sta_info
*sta
;
773 struct ieee80211_sub_if_data
*sdata
;
775 if (!local
->stat_time
)
778 /* go through all stations */
779 spin_lock_bh(&local
->sta_lock
);
780 list_for_each_entry(sta
, &local
->sta_list
, list
) {
781 sta
->channel_use
= (sta
->channel_use_raw
/ local
->stat_time
) /
783 sta
->channel_use_raw
= 0;
785 spin_unlock_bh(&local
->sta_lock
);
787 /* go through all subinterfaces */
788 read_lock(&local
->sub_if_lock
);
789 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
790 sdata
->channel_use
= (sdata
->channel_use_raw
/
791 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
792 sdata
->channel_use_raw
= 0;
794 read_unlock(&local
->sub_if_lock
);
796 /* hardware interface */
797 local
->channel_use
= (local
->channel_use_raw
/
798 local
->stat_time
) / CHAN_UTIL_PER_10MS
;
799 local
->channel_use_raw
= 0;
801 local
->stat_timer
.expires
= jiffies
+ HZ
* local
->stat_time
/ 100;
802 add_timer(&local
->stat_timer
);
805 void ieee80211_tx_status_irqsafe(struct ieee80211_hw
*hw
,
807 struct ieee80211_tx_status
*status
)
809 struct ieee80211_local
*local
= hw_to_local(hw
);
810 struct ieee80211_tx_status
*saved
;
813 skb
->dev
= local
->mdev
;
814 saved
= kmalloc(sizeof(struct ieee80211_tx_status
), GFP_ATOMIC
);
815 if (unlikely(!saved
)) {
817 printk(KERN_WARNING
"%s: Not enough memory, "
818 "dropping tx status", skb
->dev
->name
);
819 /* should be dev_kfree_skb_irq, but due to this function being
820 * named _irqsafe instead of just _irq we can't be sure that
821 * people won't call it from non-irq contexts */
822 dev_kfree_skb_any(skb
);
825 memcpy(saved
, status
, sizeof(struct ieee80211_tx_status
));
826 /* copy pointer to saved status into skb->cb for use by tasklet */
827 memcpy(skb
->cb
, &saved
, sizeof(saved
));
829 skb
->pkt_type
= IEEE80211_TX_STATUS_MSG
;
830 skb_queue_tail(status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
?
831 &local
->skb_queue
: &local
->skb_queue_unreliable
, skb
);
832 tmp
= skb_queue_len(&local
->skb_queue
) +
833 skb_queue_len(&local
->skb_queue_unreliable
);
834 while (tmp
> IEEE80211_IRQSAFE_QUEUE_LIMIT
&&
835 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
836 memcpy(&saved
, skb
->cb
, sizeof(saved
));
838 dev_kfree_skb_irq(skb
);
840 I802_DEBUG_INC(local
->tx_status_drop
);
842 tasklet_schedule(&local
->tasklet
);
844 EXPORT_SYMBOL(ieee80211_tx_status_irqsafe
);
846 static void ieee80211_tasklet_handler(unsigned long data
)
848 struct ieee80211_local
*local
= (struct ieee80211_local
*) data
;
850 struct ieee80211_rx_status rx_status
;
851 struct ieee80211_tx_status
*tx_status
;
853 while ((skb
= skb_dequeue(&local
->skb_queue
)) ||
854 (skb
= skb_dequeue(&local
->skb_queue_unreliable
))) {
855 switch (skb
->pkt_type
) {
856 case IEEE80211_RX_MSG
:
857 /* status is in skb->cb */
858 memcpy(&rx_status
, skb
->cb
, sizeof(rx_status
));
859 /* Clear skb->type in order to not confuse kernel
862 __ieee80211_rx(local_to_hw(local
), skb
, &rx_status
);
864 case IEEE80211_TX_STATUS_MSG
:
865 /* get pointer to saved status out of skb->cb */
866 memcpy(&tx_status
, skb
->cb
, sizeof(tx_status
));
868 ieee80211_tx_status(local_to_hw(local
),
872 default: /* should never get here! */
873 printk(KERN_ERR
"%s: Unknown message type (%d)\n",
874 local
->mdev
->name
, skb
->pkt_type
);
881 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
882 * make a prepared TX frame (one that has been given to hw) to look like brand
883 * new IEEE 802.11 frame that is ready to go through TX processing again.
884 * Also, tx_packet_data in cb is restored from tx_control. */
885 static void ieee80211_remove_tx_extra(struct ieee80211_local
*local
,
886 struct ieee80211_key
*key
,
888 struct ieee80211_tx_control
*control
)
890 int hdrlen
, iv_len
, mic_len
;
891 struct ieee80211_tx_packet_data
*pkt_data
;
893 pkt_data
= (struct ieee80211_tx_packet_data
*)skb
->cb
;
894 pkt_data
->ifindex
= control
->ifindex
;
895 pkt_data
->mgmt_iface
= (control
->type
== IEEE80211_IF_TYPE_MGMT
);
896 pkt_data
->req_tx_status
= !!(control
->flags
& IEEE80211_TXCTL_REQ_TX_STATUS
);
897 pkt_data
->do_not_encrypt
= !!(control
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
);
898 pkt_data
->requeue
= !!(control
->flags
& IEEE80211_TXCTL_REQUEUE
);
899 pkt_data
->queue
= control
->queue
;
901 hdrlen
= ieee80211_get_hdrlen_from_skb(skb
);
909 mic_len
= WEP_ICV_LEN
;
912 iv_len
= TKIP_IV_LEN
;
913 mic_len
= TKIP_ICV_LEN
;
916 iv_len
= CCMP_HDR_LEN
;
917 mic_len
= CCMP_MIC_LEN
;
923 if (skb
->len
>= mic_len
&& key
->force_sw_encrypt
)
924 skb_trim(skb
, skb
->len
- mic_len
);
925 if (skb
->len
>= iv_len
&& skb
->len
> hdrlen
) {
926 memmove(skb
->data
+ iv_len
, skb
->data
, hdrlen
);
927 skb_pull(skb
, iv_len
);
932 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
933 u16 fc
= le16_to_cpu(hdr
->frame_control
);
934 if ((fc
& 0x8C) == 0x88) /* QoS Control Field */ {
935 fc
&= ~IEEE80211_STYPE_QOS_DATA
;
936 hdr
->frame_control
= cpu_to_le16(fc
);
937 memmove(skb
->data
+ 2, skb
->data
, hdrlen
- 2);
943 void ieee80211_tx_status(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
944 struct ieee80211_tx_status
*status
)
946 struct sk_buff
*skb2
;
947 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
948 struct ieee80211_local
*local
= hw_to_local(hw
);
951 struct ieee80211_tx_status_rtap_hdr
*rthdr
;
952 struct ieee80211_sub_if_data
*sdata
;
957 "%s: ieee80211_tx_status called with NULL status\n",
963 if (status
->excessive_retries
) {
964 struct sta_info
*sta
;
965 sta
= sta_info_get(local
, hdr
->addr1
);
967 if (sta
->flags
& WLAN_STA_PS
) {
968 /* The STA is in power save mode, so assume
969 * that this TX packet failed because of that.
971 status
->excessive_retries
= 0;
972 status
->flags
|= IEEE80211_TX_STATUS_TX_FILTERED
;
978 if (status
->flags
& IEEE80211_TX_STATUS_TX_FILTERED
) {
979 struct sta_info
*sta
;
980 sta
= sta_info_get(local
, hdr
->addr1
);
982 sta
->tx_filtered_count
++;
984 /* Clear the TX filter mask for this STA when sending
985 * the next packet. If the STA went to power save mode,
986 * this will happen when it is waking up for the next
988 sta
->clear_dst_mask
= 1;
990 /* TODO: Is the WLAN_STA_PS flag always set here or is
991 * the race between RX and TX status causing some
992 * packets to be filtered out before 80211.o gets an
993 * update for PS status? This seems to be the case, so
994 * no changes are likely to be needed. */
995 if (sta
->flags
& WLAN_STA_PS
&&
996 skb_queue_len(&sta
->tx_filtered
) <
998 ieee80211_remove_tx_extra(local
, sta
->key
,
1001 skb_queue_tail(&sta
->tx_filtered
, skb
);
1002 } else if (!(sta
->flags
& WLAN_STA_PS
) &&
1003 !(status
->control
.flags
& IEEE80211_TXCTL_REQUEUE
)) {
1004 /* Software retry the packet once */
1005 status
->control
.flags
|= IEEE80211_TXCTL_REQUEUE
;
1006 ieee80211_remove_tx_extra(local
, sta
->key
,
1009 dev_queue_xmit(skb
);
1011 if (net_ratelimit()) {
1012 printk(KERN_DEBUG
"%s: dropped TX "
1013 "filtered frame queue_len=%d "
1018 !!(sta
->flags
& WLAN_STA_PS
),
1027 /* FIXME: STUPID to call this with both local and local->mdev */
1028 rate_control_tx_status(local
, local
->mdev
, skb
, status
);
1031 ieee80211_led_tx(local
, 0);
1034 * Fragments are passed to low-level drivers as separate skbs, so these
1035 * are actually fragments, not frames. Update frame counters only for
1036 * the first fragment of the frame. */
1038 frag
= le16_to_cpu(hdr
->seq_ctrl
) & IEEE80211_SCTL_FRAG
;
1039 type
= le16_to_cpu(hdr
->frame_control
) & IEEE80211_FCTL_FTYPE
;
1041 if (status
->flags
& IEEE80211_TX_STATUS_ACK
) {
1043 local
->dot11TransmittedFrameCount
++;
1044 if (is_multicast_ether_addr(hdr
->addr1
))
1045 local
->dot11MulticastTransmittedFrameCount
++;
1046 if (status
->retry_count
> 0)
1047 local
->dot11RetryCount
++;
1048 if (status
->retry_count
> 1)
1049 local
->dot11MultipleRetryCount
++;
1052 /* This counter shall be incremented for an acknowledged MPDU
1053 * with an individual address in the address 1 field or an MPDU
1054 * with a multicast address in the address 1 field of type Data
1056 if (!is_multicast_ether_addr(hdr
->addr1
) ||
1057 type
== IEEE80211_FTYPE_DATA
||
1058 type
== IEEE80211_FTYPE_MGMT
)
1059 local
->dot11TransmittedFragmentCount
++;
1062 local
->dot11FailedCount
++;
1065 msg_type
= (status
->flags
& IEEE80211_TX_STATUS_ACK
) ?
1066 ieee80211_msg_tx_callback_ack
: ieee80211_msg_tx_callback_fail
;
1068 /* this was a transmitted frame, but now we want to reuse it */
1071 if ((status
->control
.flags
& IEEE80211_TXCTL_REQ_TX_STATUS
) &&
1073 if (local
->monitors
) {
1074 skb2
= skb_clone(skb
, GFP_ATOMIC
);
1081 /* Send frame to hostapd */
1082 ieee80211_rx_mgmt(local
, skb2
, NULL
, msg_type
);
1088 if (!local
->monitors
) {
1093 /* send frame to monitor interfaces now */
1095 if (skb_headroom(skb
) < sizeof(*rthdr
)) {
1096 printk(KERN_ERR
"ieee80211_tx_status: headroom too small\n");
1101 rthdr
= (struct ieee80211_tx_status_rtap_hdr
*)
1102 skb_push(skb
, sizeof(*rthdr
));
1104 memset(rthdr
, 0, sizeof(*rthdr
));
1105 rthdr
->hdr
.it_len
= cpu_to_le16(sizeof(*rthdr
));
1106 rthdr
->hdr
.it_present
=
1107 cpu_to_le32((1 << IEEE80211_RADIOTAP_TX_FLAGS
) |
1108 (1 << IEEE80211_RADIOTAP_DATA_RETRIES
));
1110 if (!(status
->flags
& IEEE80211_TX_STATUS_ACK
) &&
1111 !is_multicast_ether_addr(hdr
->addr1
))
1112 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_FAIL
);
1114 if ((status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
) &&
1115 (status
->control
.flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
))
1116 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_CTS
);
1117 else if (status
->control
.flags
& IEEE80211_TXCTL_USE_RTS_CTS
)
1118 rthdr
->tx_flags
|= cpu_to_le16(IEEE80211_RADIOTAP_F_TX_RTS
);
1120 rthdr
->data_retries
= status
->retry_count
;
1122 read_lock(&local
->sub_if_lock
);
1123 monitors
= local
->monitors
;
1124 list_for_each_entry(sdata
, &local
->sub_if_list
, list
) {
1126 * Using the monitors counter is possibly racy, but
1127 * if the value is wrong we simply either clone the skb
1128 * once too much or forget sending it to one monitor iface
1129 * The latter case isn't nice but fixing the race is much
1132 if (!monitors
|| !skb
)
1135 if (sdata
->type
== IEEE80211_IF_TYPE_MNTR
) {
1136 if (!netif_running(sdata
->dev
))
1140 skb2
= skb_clone(skb
, GFP_KERNEL
);
1143 skb
->dev
= sdata
->dev
;
1144 /* XXX: is this sufficient for BPF? */
1145 skb_set_mac_header(skb
, 0);
1146 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1147 skb
->pkt_type
= PACKET_OTHERHOST
;
1148 skb
->protocol
= htons(ETH_P_802_2
);
1149 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1155 read_unlock(&local
->sub_if_lock
);
1159 EXPORT_SYMBOL(ieee80211_tx_status
);
1161 struct ieee80211_hw
*ieee80211_alloc_hw(size_t priv_data_len
,
1162 const struct ieee80211_ops
*ops
)
1164 struct net_device
*mdev
;
1165 struct ieee80211_local
*local
;
1166 struct ieee80211_sub_if_data
*sdata
;
1168 struct wiphy
*wiphy
;
1170 /* Ensure 32-byte alignment of our private data and hw private data.
1171 * We use the wiphy priv data for both our ieee80211_local and for
1172 * the driver's private data
1174 * In memory it'll be like this:
1176 * +-------------------------+
1178 * +-------------------------+
1179 * | struct ieee80211_local |
1180 * +-------------------------+
1181 * | driver's private data |
1182 * +-------------------------+
1185 priv_size
= ((sizeof(struct ieee80211_local
) +
1186 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
) +
1189 wiphy
= wiphy_new(&mac80211_config_ops
, priv_size
);
1194 wiphy
->privid
= mac80211_wiphy_privid
;
1196 local
= wiphy_priv(wiphy
);
1197 local
->hw
.wiphy
= wiphy
;
1199 local
->hw
.priv
= (char *)local
+
1200 ((sizeof(struct ieee80211_local
) +
1201 NETDEV_ALIGN_CONST
) & ~NETDEV_ALIGN_CONST
);
1204 BUG_ON(!ops
->config
);
1205 BUG_ON(!ops
->add_interface
);
1208 /* for now, mdev needs sub_if_data :/ */
1209 mdev
= alloc_netdev(sizeof(struct ieee80211_sub_if_data
),
1210 "wmaster%d", ether_setup
);
1216 sdata
= IEEE80211_DEV_TO_SUB_IF(mdev
);
1217 mdev
->ieee80211_ptr
= &sdata
->wdev
;
1218 sdata
->wdev
.wiphy
= wiphy
;
1220 local
->hw
.queues
= 1; /* default */
1223 local
->rx_pre_handlers
= ieee80211_rx_pre_handlers
;
1224 local
->rx_handlers
= ieee80211_rx_handlers
;
1225 local
->tx_handlers
= ieee80211_tx_handlers
;
1227 local
->bridge_packets
= 1;
1229 local
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
1230 local
->fragmentation_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
;
1231 local
->short_retry_limit
= 7;
1232 local
->long_retry_limit
= 4;
1233 local
->hw
.conf
.radio_enabled
= 1;
1235 local
->enabled_modes
= (unsigned int) -1;
1237 INIT_LIST_HEAD(&local
->modes_list
);
1239 rwlock_init(&local
->sub_if_lock
);
1240 INIT_LIST_HEAD(&local
->sub_if_list
);
1242 INIT_DELAYED_WORK(&local
->scan_work
, ieee80211_sta_scan_work
);
1243 init_timer(&local
->stat_timer
);
1244 local
->stat_timer
.function
= ieee80211_stat_refresh
;
1245 local
->stat_timer
.data
= (unsigned long) local
;
1246 ieee80211_rx_bss_list_init(mdev
);
1248 sta_info_init(local
);
1250 mdev
->hard_start_xmit
= ieee80211_master_start_xmit
;
1251 mdev
->open
= ieee80211_master_open
;
1252 mdev
->stop
= ieee80211_master_stop
;
1253 mdev
->type
= ARPHRD_IEEE80211
;
1254 mdev
->hard_header_parse
= header_parse_80211
;
1256 sdata
->type
= IEEE80211_IF_TYPE_AP
;
1258 sdata
->local
= local
;
1259 sdata
->u
.ap
.force_unicast_rateidx
= -1;
1260 sdata
->u
.ap
.max_ratectrl_rateidx
= -1;
1261 ieee80211_if_sdata_init(sdata
);
1262 list_add_tail(&sdata
->list
, &local
->sub_if_list
);
1264 tasklet_init(&local
->tx_pending_tasklet
, ieee80211_tx_pending
,
1265 (unsigned long)local
);
1266 tasklet_disable(&local
->tx_pending_tasklet
);
1268 tasklet_init(&local
->tasklet
,
1269 ieee80211_tasklet_handler
,
1270 (unsigned long) local
);
1271 tasklet_disable(&local
->tasklet
);
1273 skb_queue_head_init(&local
->skb_queue
);
1274 skb_queue_head_init(&local
->skb_queue_unreliable
);
1276 return local_to_hw(local
);
1278 EXPORT_SYMBOL(ieee80211_alloc_hw
);
1280 int ieee80211_register_hw(struct ieee80211_hw
*hw
)
1282 struct ieee80211_local
*local
= hw_to_local(hw
);
1286 result
= wiphy_register(local
->hw
.wiphy
);
1290 name
= wiphy_dev(local
->hw
.wiphy
)->driver
->name
;
1291 local
->hw
.workqueue
= create_singlethread_workqueue(name
);
1292 if (!local
->hw
.workqueue
) {
1294 goto fail_workqueue
;
1298 * The hardware needs headroom for sending the frame,
1299 * and we need some headroom for passing the frame to monitor
1300 * interfaces, but never both at the same time.
1302 local
->tx_headroom
= max_t(unsigned int , local
->hw
.extra_tx_headroom
,
1303 sizeof(struct ieee80211_tx_status_rtap_hdr
));
1305 debugfs_hw_add(local
);
1307 local
->hw
.conf
.beacon_int
= 1000;
1309 local
->wstats_flags
|= local
->hw
.max_rssi
?
1310 IW_QUAL_LEVEL_UPDATED
: IW_QUAL_LEVEL_INVALID
;
1311 local
->wstats_flags
|= local
->hw
.max_signal
?
1312 IW_QUAL_QUAL_UPDATED
: IW_QUAL_QUAL_INVALID
;
1313 local
->wstats_flags
|= local
->hw
.max_noise
?
1314 IW_QUAL_NOISE_UPDATED
: IW_QUAL_NOISE_INVALID
;
1315 if (local
->hw
.max_rssi
< 0 || local
->hw
.max_noise
< 0)
1316 local
->wstats_flags
|= IW_QUAL_DBM
;
1318 result
= sta_info_start(local
);
1323 result
= dev_alloc_name(local
->mdev
, local
->mdev
->name
);
1327 memcpy(local
->mdev
->dev_addr
, local
->hw
.wiphy
->perm_addr
, ETH_ALEN
);
1328 SET_NETDEV_DEV(local
->mdev
, wiphy_dev(local
->hw
.wiphy
));
1330 result
= register_netdevice(local
->mdev
);
1334 ieee80211_debugfs_add_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1336 result
= ieee80211_init_rate_ctrl_alg(local
, NULL
);
1338 printk(KERN_DEBUG
"%s: Failed to initialize rate control "
1339 "algorithm\n", local
->mdev
->name
);
1343 result
= ieee80211_wep_init(local
);
1346 printk(KERN_DEBUG
"%s: Failed to initialize wep\n",
1351 ieee80211_install_qdisc(local
->mdev
);
1353 /* add one default STA interface */
1354 result
= ieee80211_if_add(local
->mdev
, "wlan%d", NULL
,
1355 IEEE80211_IF_TYPE_STA
);
1357 printk(KERN_WARNING
"%s: Failed to add default virtual iface\n",
1360 local
->reg_state
= IEEE80211_DEV_REGISTERED
;
1363 ieee80211_led_init(local
);
1368 rate_control_deinitialize(local
);
1370 ieee80211_debugfs_remove_netdev(IEEE80211_DEV_TO_SUB_IF(local
->mdev
));
1371 unregister_netdevice(local
->mdev
);
1374 sta_info_stop(local
);
1376 debugfs_hw_del(local
);
1377 destroy_workqueue(local
->hw
.workqueue
);
1379 wiphy_unregister(local
->hw
.wiphy
);
1382 EXPORT_SYMBOL(ieee80211_register_hw
);
1384 int ieee80211_register_hwmode(struct ieee80211_hw
*hw
,
1385 struct ieee80211_hw_mode
*mode
)
1387 struct ieee80211_local
*local
= hw_to_local(hw
);
1388 struct ieee80211_rate
*rate
;
1391 INIT_LIST_HEAD(&mode
->list
);
1392 list_add_tail(&mode
->list
, &local
->modes_list
);
1394 local
->hw_modes
|= (1 << mode
->mode
);
1395 for (i
= 0; i
< mode
->num_rates
; i
++) {
1396 rate
= &(mode
->rates
[i
]);
1397 rate
->rate_inv
= CHAN_UTIL_RATE_LCM
/ rate
->rate
;
1399 ieee80211_prepare_rates(local
, mode
);
1401 if (!local
->oper_hw_mode
) {
1402 /* Default to this mode */
1403 local
->hw
.conf
.phymode
= mode
->mode
;
1404 local
->oper_hw_mode
= local
->scan_hw_mode
= mode
;
1405 local
->oper_channel
= local
->scan_channel
= &mode
->channels
[0];
1406 local
->hw
.conf
.mode
= local
->oper_hw_mode
;
1407 local
->hw
.conf
.chan
= local
->oper_channel
;
1410 if (!(hw
->flags
& IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
))
1411 ieee80211_set_default_regdomain(mode
);
1415 EXPORT_SYMBOL(ieee80211_register_hwmode
);
1417 void ieee80211_unregister_hw(struct ieee80211_hw
*hw
)
1419 struct ieee80211_local
*local
= hw_to_local(hw
);
1420 struct ieee80211_sub_if_data
*sdata
, *tmp
;
1421 struct list_head tmp_list
;
1424 tasklet_kill(&local
->tx_pending_tasklet
);
1425 tasklet_kill(&local
->tasklet
);
1429 BUG_ON(local
->reg_state
!= IEEE80211_DEV_REGISTERED
);
1431 local
->reg_state
= IEEE80211_DEV_UNREGISTERED
;
1433 ieee80211_if_del_mgmt(local
);
1435 write_lock_bh(&local
->sub_if_lock
);
1436 list_replace_init(&local
->sub_if_list
, &tmp_list
);
1437 write_unlock_bh(&local
->sub_if_lock
);
1439 list_for_each_entry_safe(sdata
, tmp
, &tmp_list
, list
)
1440 __ieee80211_if_del(local
, sdata
);
1444 if (local
->stat_time
)
1445 del_timer_sync(&local
->stat_timer
);
1447 ieee80211_rx_bss_list_deinit(local
->mdev
);
1448 ieee80211_clear_tx_pending(local
);
1449 sta_info_stop(local
);
1450 rate_control_deinitialize(local
);
1451 debugfs_hw_del(local
);
1453 for (i
= 0; i
< NUM_IEEE80211_MODES
; i
++) {
1454 kfree(local
->supp_rates
[i
]);
1455 kfree(local
->basic_rates
[i
]);
1458 if (skb_queue_len(&local
->skb_queue
)
1459 || skb_queue_len(&local
->skb_queue_unreliable
))
1460 printk(KERN_WARNING
"%s: skb_queue not empty\n",
1462 skb_queue_purge(&local
->skb_queue
);
1463 skb_queue_purge(&local
->skb_queue_unreliable
);
1465 destroy_workqueue(local
->hw
.workqueue
);
1466 wiphy_unregister(local
->hw
.wiphy
);
1467 ieee80211_wep_free(local
);
1468 ieee80211_led_exit(local
);
1470 EXPORT_SYMBOL(ieee80211_unregister_hw
);
1472 void ieee80211_free_hw(struct ieee80211_hw
*hw
)
1474 struct ieee80211_local
*local
= hw_to_local(hw
);
1476 ieee80211_if_free(local
->mdev
);
1477 wiphy_free(local
->hw
.wiphy
);
1479 EXPORT_SYMBOL(ieee80211_free_hw
);
1481 struct net_device_stats
*ieee80211_dev_stats(struct net_device
*dev
)
1483 struct ieee80211_sub_if_data
*sdata
;
1484 sdata
= IEEE80211_DEV_TO_SUB_IF(dev
);
1485 return &sdata
->stats
;
1488 static int __init
ieee80211_init(void)
1490 struct sk_buff
*skb
;
1493 BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data
) > sizeof(skb
->cb
));
1495 ret
= ieee80211_wme_register();
1497 printk(KERN_DEBUG
"ieee80211_init: failed to "
1498 "initialize WME (err=%d)\n", ret
);
1502 ieee80211_debugfs_netdev_init();
1503 ieee80211_regdomain_init();
1508 static void __exit
ieee80211_exit(void)
1510 ieee80211_wme_unregister();
1511 ieee80211_debugfs_netdev_exit();
1515 subsys_initcall(ieee80211_init
);
1516 module_exit(ieee80211_exit
);
1518 MODULE_DESCRIPTION("IEEE 802.11 subsystem");
1519 MODULE_LICENSE("GPL");