2 * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
3 * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
12 * - IBSS mode simulation (Beacon transmission with competition for "air time")
13 * - IEEE 802.11a and 802.11n modes
14 * - RX filtering based on filter configuration (data->rx_filter)
17 #include <linux/list.h>
18 #include <linux/spinlock.h>
19 #include <net/mac80211.h>
20 #include <net/ieee80211_radiotap.h>
21 #include <linux/if_arp.h>
22 #include <linux/rtnetlink.h>
23 #include <linux/etherdevice.h>
24 #include <linux/debugfs.h>
26 MODULE_AUTHOR("Jouni Malinen");
27 MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
28 MODULE_LICENSE("GPL");
30 static int radios
= 2;
31 module_param(radios
, int, 0444);
32 MODULE_PARM_DESC(radios
, "Number of simulated radios");
34 struct hwsim_vif_priv
{
41 #define HWSIM_VIF_MAGIC 0x69537748
43 static inline void hwsim_check_magic(struct ieee80211_vif
*vif
)
45 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
46 WARN_ON(vp
->magic
!= HWSIM_VIF_MAGIC
);
49 static inline void hwsim_set_magic(struct ieee80211_vif
*vif
)
51 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
52 vp
->magic
= HWSIM_VIF_MAGIC
;
55 static inline void hwsim_clear_magic(struct ieee80211_vif
*vif
)
57 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
61 struct hwsim_sta_priv
{
65 #define HWSIM_STA_MAGIC 0x6d537748
67 static inline void hwsim_check_sta_magic(struct ieee80211_sta
*sta
)
69 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
70 WARN_ON(sp
->magic
!= HWSIM_STA_MAGIC
);
73 static inline void hwsim_set_sta_magic(struct ieee80211_sta
*sta
)
75 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
76 sp
->magic
= HWSIM_STA_MAGIC
;
79 static inline void hwsim_clear_sta_magic(struct ieee80211_sta
*sta
)
81 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
85 static struct class *hwsim_class
;
87 static struct net_device
*hwsim_mon
; /* global monitor netdev */
90 static const struct ieee80211_channel hwsim_channels
[] = {
91 { .center_freq
= 2412 },
92 { .center_freq
= 2417 },
93 { .center_freq
= 2422 },
94 { .center_freq
= 2427 },
95 { .center_freq
= 2432 },
96 { .center_freq
= 2437 },
97 { .center_freq
= 2442 },
98 { .center_freq
= 2447 },
99 { .center_freq
= 2452 },
100 { .center_freq
= 2457 },
101 { .center_freq
= 2462 },
102 { .center_freq
= 2467 },
103 { .center_freq
= 2472 },
104 { .center_freq
= 2484 },
107 static const struct ieee80211_rate hwsim_rates
[] = {
109 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
110 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
111 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
122 static spinlock_t hwsim_radio_lock
;
123 static struct list_head hwsim_radios
;
125 struct mac80211_hwsim_data
{
126 struct list_head list
;
127 struct ieee80211_hw
*hw
;
129 struct ieee80211_supported_band band
;
130 struct ieee80211_channel channels
[ARRAY_SIZE(hwsim_channels
)];
131 struct ieee80211_rate rates
[ARRAY_SIZE(hwsim_rates
)];
133 struct ieee80211_channel
*channel
;
135 unsigned long beacon_int
; /* in jiffies unit */
136 unsigned int rx_filter
;
138 struct timer_list beacon_timer
;
140 PS_DISABLED
, PS_ENABLED
, PS_AUTO_POLL
, PS_MANUAL_POLL
142 bool ps_poll_pending
;
143 struct dentry
*debugfs
;
144 struct dentry
*debugfs_ps
;
148 struct hwsim_radiotap_hdr
{
149 struct ieee80211_radiotap_header hdr
;
154 } __attribute__ ((packed
));
157 static int hwsim_mon_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
159 /* TODO: allow packet injection */
165 static void mac80211_hwsim_monitor_rx(struct ieee80211_hw
*hw
,
166 struct sk_buff
*tx_skb
)
168 struct mac80211_hwsim_data
*data
= hw
->priv
;
170 struct hwsim_radiotap_hdr
*hdr
;
172 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx_skb
);
173 struct ieee80211_rate
*txrate
= ieee80211_get_tx_rate(hw
, info
);
175 if (!netif_running(hwsim_mon
))
178 skb
= skb_copy_expand(tx_skb
, sizeof(*hdr
), 0, GFP_ATOMIC
);
182 hdr
= (struct hwsim_radiotap_hdr
*) skb_push(skb
, sizeof(*hdr
));
183 hdr
->hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
185 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(*hdr
));
186 hdr
->hdr
.it_present
= cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
187 (1 << IEEE80211_RADIOTAP_RATE
) |
188 (1 << IEEE80211_RADIOTAP_CHANNEL
));
190 hdr
->rt_rate
= txrate
->bitrate
/ 5;
191 hdr
->rt_channel
= cpu_to_le16(data
->channel
->center_freq
);
192 flags
= IEEE80211_CHAN_2GHZ
;
193 if (txrate
->flags
& IEEE80211_RATE_ERP_G
)
194 flags
|= IEEE80211_CHAN_OFDM
;
196 flags
|= IEEE80211_CHAN_CCK
;
197 hdr
->rt_chbitmask
= cpu_to_le16(flags
);
199 skb
->dev
= hwsim_mon
;
200 skb_set_mac_header(skb
, 0);
201 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
202 skb
->pkt_type
= PACKET_OTHERHOST
;
203 skb
->protocol
= htons(ETH_P_802_2
);
204 memset(skb
->cb
, 0, sizeof(skb
->cb
));
209 static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data
*data
,
218 /* TODO: accept (some) Beacons by default and other frames only
219 * if pending PS-Poll has been sent */
222 /* Allow unicast frames to own address if there is a pending
224 if (data
->ps_poll_pending
&&
225 memcmp(data
->hw
->wiphy
->perm_addr
, skb
->data
+ 4,
227 data
->ps_poll_pending
= false;
237 static bool mac80211_hwsim_tx_frame(struct ieee80211_hw
*hw
,
240 struct mac80211_hwsim_data
*data
= hw
->priv
, *data2
;
242 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
243 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
244 struct ieee80211_rx_status rx_status
;
246 memset(&rx_status
, 0, sizeof(rx_status
));
247 /* TODO: set mactime */
248 rx_status
.freq
= data
->channel
->center_freq
;
249 rx_status
.band
= data
->channel
->band
;
250 rx_status
.rate_idx
= info
->control
.rates
[0].idx
;
251 /* TODO: simulate signal strength (and optional packet drop) */
253 if (data
->ps
!= PS_DISABLED
)
254 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
256 /* Copy skb to all enabled radios that are on the current frequency */
257 spin_lock(&hwsim_radio_lock
);
258 list_for_each_entry(data2
, &hwsim_radios
, list
) {
259 struct sk_buff
*nskb
;
264 if (!data2
->started
|| !data2
->radio_enabled
||
265 !hwsim_ps_rx_ok(data2
, skb
) ||
266 data
->channel
->center_freq
!= data2
->channel
->center_freq
)
269 nskb
= skb_copy(skb
, GFP_ATOMIC
);
273 if (memcmp(hdr
->addr1
, data2
->hw
->wiphy
->perm_addr
,
276 ieee80211_rx_irqsafe(data2
->hw
, nskb
, &rx_status
);
278 spin_unlock(&hwsim_radio_lock
);
284 static int mac80211_hwsim_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
286 struct mac80211_hwsim_data
*data
= hw
->priv
;
288 struct ieee80211_tx_info
*txi
;
290 mac80211_hwsim_monitor_rx(hw
, skb
);
293 /* Should not happen; just a sanity check for addr1 use */
298 if (!data
->radio_enabled
) {
299 printk(KERN_DEBUG
"%s: dropped TX frame since radio "
300 "disabled\n", wiphy_name(hw
->wiphy
));
305 ack
= mac80211_hwsim_tx_frame(hw
, skb
);
307 txi
= IEEE80211_SKB_CB(skb
);
309 if (txi
->control
.vif
)
310 hwsim_check_magic(txi
->control
.vif
);
311 if (txi
->control
.sta
)
312 hwsim_check_sta_magic(txi
->control
.sta
);
314 ieee80211_tx_info_clear_status(txi
);
315 if (!(txi
->flags
& IEEE80211_TX_CTL_NO_ACK
) && ack
)
316 txi
->flags
|= IEEE80211_TX_STAT_ACK
;
317 ieee80211_tx_status_irqsafe(hw
, skb
);
322 static int mac80211_hwsim_start(struct ieee80211_hw
*hw
)
324 struct mac80211_hwsim_data
*data
= hw
->priv
;
325 printk(KERN_DEBUG
"%s:%s\n", wiphy_name(hw
->wiphy
), __func__
);
331 static void mac80211_hwsim_stop(struct ieee80211_hw
*hw
)
333 struct mac80211_hwsim_data
*data
= hw
->priv
;
335 del_timer(&data
->beacon_timer
);
336 printk(KERN_DEBUG
"%s:%s\n", wiphy_name(hw
->wiphy
), __func__
);
340 static int mac80211_hwsim_add_interface(struct ieee80211_hw
*hw
,
341 struct ieee80211_if_init_conf
*conf
)
343 printk(KERN_DEBUG
"%s:%s (type=%d mac_addr=%pM)\n",
344 wiphy_name(hw
->wiphy
), __func__
, conf
->type
,
346 hwsim_set_magic(conf
->vif
);
351 static void mac80211_hwsim_remove_interface(
352 struct ieee80211_hw
*hw
, struct ieee80211_if_init_conf
*conf
)
354 printk(KERN_DEBUG
"%s:%s (type=%d mac_addr=%pM)\n",
355 wiphy_name(hw
->wiphy
), __func__
, conf
->type
,
357 hwsim_check_magic(conf
->vif
);
358 hwsim_clear_magic(conf
->vif
);
362 static void mac80211_hwsim_beacon_tx(void *arg
, u8
*mac
,
363 struct ieee80211_vif
*vif
)
365 struct ieee80211_hw
*hw
= arg
;
367 struct ieee80211_tx_info
*info
;
369 hwsim_check_magic(vif
);
371 if (vif
->type
!= NL80211_IFTYPE_AP
&&
372 vif
->type
!= NL80211_IFTYPE_MESH_POINT
)
375 skb
= ieee80211_beacon_get(hw
, vif
);
378 info
= IEEE80211_SKB_CB(skb
);
380 mac80211_hwsim_monitor_rx(hw
, skb
);
381 mac80211_hwsim_tx_frame(hw
, skb
);
386 static void mac80211_hwsim_beacon(unsigned long arg
)
388 struct ieee80211_hw
*hw
= (struct ieee80211_hw
*) arg
;
389 struct mac80211_hwsim_data
*data
= hw
->priv
;
391 if (!data
->started
|| !data
->radio_enabled
)
394 ieee80211_iterate_active_interfaces_atomic(
395 hw
, mac80211_hwsim_beacon_tx
, hw
);
397 data
->beacon_timer
.expires
= jiffies
+ data
->beacon_int
;
398 add_timer(&data
->beacon_timer
);
402 static int mac80211_hwsim_config(struct ieee80211_hw
*hw
, u32 changed
)
404 struct mac80211_hwsim_data
*data
= hw
->priv
;
405 struct ieee80211_conf
*conf
= &hw
->conf
;
407 printk(KERN_DEBUG
"%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n",
408 wiphy_name(hw
->wiphy
), __func__
,
409 conf
->channel
->center_freq
, conf
->radio_enabled
,
412 data
->channel
= conf
->channel
;
413 data
->radio_enabled
= conf
->radio_enabled
;
414 data
->beacon_int
= 1024 * conf
->beacon_int
/ 1000 * HZ
/ 1000;
415 if (data
->beacon_int
< 1)
416 data
->beacon_int
= 1;
418 if (!data
->started
|| !data
->radio_enabled
)
419 del_timer(&data
->beacon_timer
);
421 mod_timer(&data
->beacon_timer
, jiffies
+ data
->beacon_int
);
427 static void mac80211_hwsim_configure_filter(struct ieee80211_hw
*hw
,
428 unsigned int changed_flags
,
429 unsigned int *total_flags
,
431 struct dev_addr_list
*mc_list
)
433 struct mac80211_hwsim_data
*data
= hw
->priv
;
435 printk(KERN_DEBUG
"%s:%s\n", wiphy_name(hw
->wiphy
), __func__
);
438 if (*total_flags
& FIF_PROMISC_IN_BSS
)
439 data
->rx_filter
|= FIF_PROMISC_IN_BSS
;
440 if (*total_flags
& FIF_ALLMULTI
)
441 data
->rx_filter
|= FIF_ALLMULTI
;
443 *total_flags
= data
->rx_filter
;
446 static int mac80211_hwsim_config_interface(struct ieee80211_hw
*hw
,
447 struct ieee80211_vif
*vif
,
448 struct ieee80211_if_conf
*conf
)
450 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
452 hwsim_check_magic(vif
);
453 if (conf
->changed
& IEEE80211_IFCC_BSSID
) {
454 DECLARE_MAC_BUF(mac
);
455 printk(KERN_DEBUG
"%s:%s: BSSID changed: %pM\n",
456 wiphy_name(hw
->wiphy
), __func__
,
458 memcpy(vp
->bssid
, conf
->bssid
, ETH_ALEN
);
463 static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw
*hw
,
464 struct ieee80211_vif
*vif
,
465 struct ieee80211_bss_conf
*info
,
468 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
470 hwsim_check_magic(vif
);
472 printk(KERN_DEBUG
"%s:%s(changed=0x%x)\n",
473 wiphy_name(hw
->wiphy
), __func__
, changed
);
475 if (changed
& BSS_CHANGED_ASSOC
) {
476 printk(KERN_DEBUG
" %s: ASSOC: assoc=%d aid=%d\n",
477 wiphy_name(hw
->wiphy
), info
->assoc
, info
->aid
);
478 vp
->assoc
= info
->assoc
;
482 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
483 printk(KERN_DEBUG
" %s: ERP_CTS_PROT: %d\n",
484 wiphy_name(hw
->wiphy
), info
->use_cts_prot
);
487 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
488 printk(KERN_DEBUG
" %s: ERP_PREAMBLE: %d\n",
489 wiphy_name(hw
->wiphy
), info
->use_short_preamble
);
492 if (changed
& BSS_CHANGED_ERP_SLOT
) {
493 printk(KERN_DEBUG
" %s: ERP_SLOT: %d\n",
494 wiphy_name(hw
->wiphy
), info
->use_short_slot
);
497 if (changed
& BSS_CHANGED_HT
) {
498 printk(KERN_DEBUG
" %s: HT: sec_ch_offs=%d width_40_ok=%d "
500 wiphy_name(hw
->wiphy
),
501 info
->ht
.secondary_channel_offset
,
502 info
->ht
.width_40_ok
, info
->ht
.operation_mode
);
505 if (changed
& BSS_CHANGED_BASIC_RATES
) {
506 printk(KERN_DEBUG
" %s: BASIC_RATES: 0x%llx\n",
507 wiphy_name(hw
->wiphy
),
508 (unsigned long long) info
->basic_rates
);
512 static void mac80211_hwsim_sta_notify(struct ieee80211_hw
*hw
,
513 struct ieee80211_vif
*vif
,
514 enum sta_notify_cmd cmd
,
515 struct ieee80211_sta
*sta
)
517 hwsim_check_magic(vif
);
520 hwsim_set_sta_magic(sta
);
522 case STA_NOTIFY_REMOVE
:
523 hwsim_clear_sta_magic(sta
);
528 static int mac80211_hwsim_set_tim(struct ieee80211_hw
*hw
,
529 struct ieee80211_sta
*sta
,
532 hwsim_check_sta_magic(sta
);
536 static int mac80211_hwsim_conf_tx(
537 struct ieee80211_hw
*hw
, u16 queue
,
538 const struct ieee80211_tx_queue_params
*params
)
540 printk(KERN_DEBUG
"%s:%s (queue=%d txop=%d cw_min=%d cw_max=%d "
542 wiphy_name(hw
->wiphy
), __func__
, queue
,
543 params
->txop
, params
->cw_min
, params
->cw_max
, params
->aifs
);
547 static const struct ieee80211_ops mac80211_hwsim_ops
=
549 .tx
= mac80211_hwsim_tx
,
550 .start
= mac80211_hwsim_start
,
551 .stop
= mac80211_hwsim_stop
,
552 .add_interface
= mac80211_hwsim_add_interface
,
553 .remove_interface
= mac80211_hwsim_remove_interface
,
554 .config
= mac80211_hwsim_config
,
555 .configure_filter
= mac80211_hwsim_configure_filter
,
556 .config_interface
= mac80211_hwsim_config_interface
,
557 .bss_info_changed
= mac80211_hwsim_bss_info_changed
,
558 .sta_notify
= mac80211_hwsim_sta_notify
,
559 .set_tim
= mac80211_hwsim_set_tim
,
560 .conf_tx
= mac80211_hwsim_conf_tx
,
564 static void mac80211_hwsim_free(void)
566 struct list_head tmplist
, *i
, *tmp
;
567 struct mac80211_hwsim_data
*data
;
569 INIT_LIST_HEAD(&tmplist
);
571 spin_lock_bh(&hwsim_radio_lock
);
572 list_for_each_safe(i
, tmp
, &hwsim_radios
)
573 list_move(i
, &tmplist
);
574 spin_unlock_bh(&hwsim_radio_lock
);
576 list_for_each_entry(data
, &tmplist
, list
) {
577 debugfs_remove(data
->debugfs_ps
);
578 debugfs_remove(data
->debugfs
);
579 ieee80211_unregister_hw(data
->hw
);
580 device_unregister(data
->dev
);
581 ieee80211_free_hw(data
->hw
);
583 class_destroy(hwsim_class
);
587 static struct device_driver mac80211_hwsim_driver
= {
588 .name
= "mac80211_hwsim"
592 static void hwsim_mon_setup(struct net_device
*dev
)
594 dev
->hard_start_xmit
= hwsim_mon_xmit
;
595 dev
->destructor
= free_netdev
;
597 dev
->tx_queue_len
= 0;
598 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
599 memset(dev
->dev_addr
, 0, ETH_ALEN
);
600 dev
->dev_addr
[0] = 0x12;
604 static void hwsim_send_ps_poll(void *dat
, u8
*mac
, struct ieee80211_vif
*vif
)
606 struct mac80211_hwsim_data
*data
= dat
;
607 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
608 DECLARE_MAC_BUF(buf
);
610 struct ieee80211_pspoll
*pspoll
;
615 printk(KERN_DEBUG
"%s:%s: send PS-Poll to %pM for aid %d\n",
616 wiphy_name(data
->hw
->wiphy
), __func__
, vp
->bssid
, vp
->aid
);
618 skb
= dev_alloc_skb(sizeof(*pspoll
));
621 pspoll
= (void *) skb_put(skb
, sizeof(*pspoll
));
622 pspoll
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
623 IEEE80211_STYPE_PSPOLL
|
625 pspoll
->aid
= cpu_to_le16(0xc000 | vp
->aid
);
626 memcpy(pspoll
->bssid
, vp
->bssid
, ETH_ALEN
);
627 memcpy(pspoll
->ta
, mac
, ETH_ALEN
);
628 if (data
->radio_enabled
&&
629 !mac80211_hwsim_tx_frame(data
->hw
, skb
))
630 printk(KERN_DEBUG
"%s: PS-Poll frame not ack'ed\n", __func__
);
635 static void hwsim_send_nullfunc(struct mac80211_hwsim_data
*data
, u8
*mac
,
636 struct ieee80211_vif
*vif
, int ps
)
638 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
639 DECLARE_MAC_BUF(buf
);
641 struct ieee80211_hdr
*hdr
;
646 printk(KERN_DEBUG
"%s:%s: send data::nullfunc to %pM ps=%d\n",
647 wiphy_name(data
->hw
->wiphy
), __func__
, vp
->bssid
, ps
);
649 skb
= dev_alloc_skb(sizeof(*hdr
));
652 hdr
= (void *) skb_put(skb
, sizeof(*hdr
) - ETH_ALEN
);
653 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
654 IEEE80211_STYPE_NULLFUNC
|
655 (ps
? IEEE80211_FCTL_PM
: 0));
656 hdr
->duration_id
= cpu_to_le16(0);
657 memcpy(hdr
->addr1
, vp
->bssid
, ETH_ALEN
);
658 memcpy(hdr
->addr2
, mac
, ETH_ALEN
);
659 memcpy(hdr
->addr3
, vp
->bssid
, ETH_ALEN
);
660 if (data
->radio_enabled
&&
661 !mac80211_hwsim_tx_frame(data
->hw
, skb
))
662 printk(KERN_DEBUG
"%s: nullfunc frame not ack'ed\n", __func__
);
667 static void hwsim_send_nullfunc_ps(void *dat
, u8
*mac
,
668 struct ieee80211_vif
*vif
)
670 struct mac80211_hwsim_data
*data
= dat
;
671 hwsim_send_nullfunc(data
, mac
, vif
, 1);
675 static void hwsim_send_nullfunc_no_ps(void *dat
, u8
*mac
,
676 struct ieee80211_vif
*vif
)
678 struct mac80211_hwsim_data
*data
= dat
;
679 hwsim_send_nullfunc(data
, mac
, vif
, 0);
683 static int hwsim_fops_ps_read(void *dat
, u64
*val
)
685 struct mac80211_hwsim_data
*data
= dat
;
690 static int hwsim_fops_ps_write(void *dat
, u64 val
)
692 struct mac80211_hwsim_data
*data
= dat
;
695 if (val
!= PS_DISABLED
&& val
!= PS_ENABLED
&& val
!= PS_AUTO_POLL
&&
696 val
!= PS_MANUAL_POLL
)
702 if (val
== PS_MANUAL_POLL
) {
703 ieee80211_iterate_active_interfaces(data
->hw
,
704 hwsim_send_ps_poll
, data
);
705 data
->ps_poll_pending
= true;
706 } else if (old_ps
== PS_DISABLED
&& val
!= PS_DISABLED
) {
707 ieee80211_iterate_active_interfaces(data
->hw
,
708 hwsim_send_nullfunc_ps
,
710 } else if (old_ps
!= PS_DISABLED
&& val
== PS_DISABLED
) {
711 ieee80211_iterate_active_interfaces(data
->hw
,
712 hwsim_send_nullfunc_no_ps
,
719 DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps
, hwsim_fops_ps_read
, hwsim_fops_ps_write
,
723 static int __init
init_mac80211_hwsim(void)
727 struct mac80211_hwsim_data
*data
;
728 struct ieee80211_hw
*hw
;
730 if (radios
< 1 || radios
> 100)
733 spin_lock_init(&hwsim_radio_lock
);
734 INIT_LIST_HEAD(&hwsim_radios
);
736 hwsim_class
= class_create(THIS_MODULE
, "mac80211_hwsim");
737 if (IS_ERR(hwsim_class
))
738 return PTR_ERR(hwsim_class
);
740 memset(addr
, 0, ETH_ALEN
);
743 for (i
= 0; i
< radios
; i
++) {
744 printk(KERN_DEBUG
"mac80211_hwsim: Initializing radio %d\n",
746 hw
= ieee80211_alloc_hw(sizeof(*data
), &mac80211_hwsim_ops
);
748 printk(KERN_DEBUG
"mac80211_hwsim: ieee80211_alloc_hw "
756 data
->dev
= device_create(hwsim_class
, NULL
, 0, hw
,
758 if (IS_ERR(data
->dev
)) {
760 "mac80211_hwsim: device_create "
761 "failed (%ld)\n", PTR_ERR(data
->dev
));
765 data
->dev
->driver
= &mac80211_hwsim_driver
;
767 SET_IEEE80211_DEV(hw
, data
->dev
);
770 SET_IEEE80211_PERM_ADDR(hw
, addr
);
772 hw
->channel_change_time
= 1;
774 hw
->wiphy
->interface_modes
=
775 BIT(NL80211_IFTYPE_STATION
) |
776 BIT(NL80211_IFTYPE_AP
) |
777 BIT(NL80211_IFTYPE_MESH_POINT
);
778 hw
->ampdu_queues
= 1;
780 /* ask mac80211 to reserve space for magic */
781 hw
->vif_data_size
= sizeof(struct hwsim_vif_priv
);
782 hw
->sta_data_size
= sizeof(struct hwsim_sta_priv
);
784 memcpy(data
->channels
, hwsim_channels
, sizeof(hwsim_channels
));
785 memcpy(data
->rates
, hwsim_rates
, sizeof(hwsim_rates
));
786 data
->band
.channels
= data
->channels
;
787 data
->band
.n_channels
= ARRAY_SIZE(hwsim_channels
);
788 data
->band
.bitrates
= data
->rates
;
789 data
->band
.n_bitrates
= ARRAY_SIZE(hwsim_rates
);
790 data
->band
.ht_cap
.ht_supported
= true;
791 data
->band
.ht_cap
.cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
792 IEEE80211_HT_CAP_GRN_FLD
|
793 IEEE80211_HT_CAP_SGI_40
|
794 IEEE80211_HT_CAP_DSSSCCK40
;
795 data
->band
.ht_cap
.ampdu_factor
= 0x3;
796 data
->band
.ht_cap
.ampdu_density
= 0x6;
797 memset(&data
->band
.ht_cap
.mcs
, 0,
798 sizeof(data
->band
.ht_cap
.mcs
));
799 data
->band
.ht_cap
.mcs
.rx_mask
[0] = 0xff;
800 data
->band
.ht_cap
.mcs
.rx_mask
[1] = 0xff;
801 data
->band
.ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
802 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] = &data
->band
;
804 err
= ieee80211_register_hw(hw
);
806 printk(KERN_DEBUG
"mac80211_hwsim: "
807 "ieee80211_register_hw failed (%d)\n", err
);
811 printk(KERN_DEBUG
"%s: hwaddr %pM registered\n",
812 wiphy_name(hw
->wiphy
),
813 hw
->wiphy
->perm_addr
);
815 data
->debugfs
= debugfs_create_dir("hwsim",
816 hw
->wiphy
->debugfsdir
);
817 data
->debugfs_ps
= debugfs_create_file("ps", 0666,
821 setup_timer(&data
->beacon_timer
, mac80211_hwsim_beacon
,
824 list_add_tail(&data
->list
, &hwsim_radios
);
827 hwsim_mon
= alloc_netdev(0, "hwsim%d", hwsim_mon_setup
);
828 if (hwsim_mon
== NULL
)
833 err
= dev_alloc_name(hwsim_mon
, hwsim_mon
->name
);
838 err
= register_netdevice(hwsim_mon
);
848 free_netdev(hwsim_mon
);
849 mac80211_hwsim_free();
853 device_unregister(data
->dev
);
855 ieee80211_free_hw(hw
);
857 mac80211_hwsim_free();
862 static void __exit
exit_mac80211_hwsim(void)
864 printk(KERN_DEBUG
"mac80211_hwsim: unregister radios\n");
866 unregister_netdev(hwsim_mon
);
867 mac80211_hwsim_free();
871 module_init(init_mac80211_hwsim
);
872 module_exit(exit_mac80211_hwsim
);