1 // SPDX-License-Identifier: GPL-2.0-only
3 * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
4 * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
5 * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com>
6 * Copyright (c) 2016 - 2017 Intel Deutschland GmbH
7 * Copyright (C) 2018 - 2020 Intel Corporation
12 * - Add TSF sync and fix IBSS beacon transmission by adding
13 * competition for "air time" at TBTT
14 * - RX filtering based on filter configuration (data->rx_filter)
17 #include <linux/list.h>
18 #include <linux/slab.h>
19 #include <linux/spinlock.h>
22 #include <net/mac80211.h>
23 #include <net/ieee80211_radiotap.h>
24 #include <linux/if_arp.h>
25 #include <linux/rtnetlink.h>
26 #include <linux/etherdevice.h>
27 #include <linux/platform_device.h>
28 #include <linux/debugfs.h>
29 #include <linux/module.h>
30 #include <linux/ktime.h>
31 #include <net/genetlink.h>
32 #include <net/net_namespace.h>
33 #include <net/netns/generic.h>
34 #include <linux/rhashtable.h>
35 #include <linux/nospec.h>
36 #include <linux/virtio.h>
37 #include <linux/virtio_ids.h>
38 #include <linux/virtio_config.h>
39 #include "mac80211_hwsim.h"
41 #define WARN_QUEUE 100
44 MODULE_AUTHOR("Jouni Malinen");
45 MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
46 MODULE_LICENSE("GPL");
48 static int radios
= 2;
49 module_param(radios
, int, 0444);
50 MODULE_PARM_DESC(radios
, "Number of simulated radios");
52 static int channels
= 1;
53 module_param(channels
, int, 0444);
54 MODULE_PARM_DESC(channels
, "Number of concurrent channels");
56 static bool paged_rx
= false;
57 module_param(paged_rx
, bool, 0644);
58 MODULE_PARM_DESC(paged_rx
, "Use paged SKBs for RX instead of linear ones");
60 static bool rctbl
= false;
61 module_param(rctbl
, bool, 0444);
62 MODULE_PARM_DESC(rctbl
, "Handle rate control table");
64 static bool support_p2p_device
= true;
65 module_param(support_p2p_device
, bool, 0444);
66 MODULE_PARM_DESC(support_p2p_device
, "Support P2P-Device interface type");
69 * enum hwsim_regtest - the type of regulatory tests we offer
71 * These are the different values you can use for the regtest
72 * module parameter. This is useful to help test world roaming
73 * and the driver regulatory_hint() call and combinations of these.
74 * If you want to do specific alpha2 regulatory domain tests simply
75 * use the userspace regulatory request as that will be respected as
76 * well without the need of this module parameter. This is designed
77 * only for testing the driver regulatory request, world roaming
78 * and all possible combinations.
80 * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed,
81 * this is the default value.
82 * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory
83 * hint, only one driver regulatory hint will be sent as such the
84 * secondary radios are expected to follow.
85 * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory
86 * request with all radios reporting the same regulatory domain.
87 * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling
88 * different regulatory domains requests. Expected behaviour is for
89 * an intersection to occur but each device will still use their
90 * respective regulatory requested domains. Subsequent radios will
91 * use the resulting intersection.
92 * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish
93 * this by using a custom beacon-capable regulatory domain for the first
94 * radio. All other device world roam.
95 * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory
96 * domain requests. All radios will adhere to this custom world regulatory
98 * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory
99 * domain requests. The first radio will adhere to the first custom world
100 * regulatory domain, the second one to the second custom world regulatory
101 * domain. All other devices will world roam.
102 * @HWSIM_REGTEST_STRICT_FOLLOW: Used for testing strict regulatory domain
103 * settings, only the first radio will send a regulatory domain request
104 * and use strict settings. The rest of the radios are expected to follow.
105 * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain
106 * settings. All radios will adhere to this.
107 * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory
108 * domain settings, combined with secondary driver regulatory domain
109 * settings. The first radio will get a strict regulatory domain setting
110 * using the first driver regulatory request and the second radio will use
111 * non-strict settings using the second driver regulatory request. All
112 * other devices should follow the intersection created between the
114 * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need
115 * at least 6 radios for a complete test. We will test in this order:
116 * 1 - driver custom world regulatory domain
117 * 2 - second custom world regulatory domain
118 * 3 - first driver regulatory domain request
119 * 4 - second driver regulatory domain request
120 * 5 - strict regulatory domain settings using the third driver regulatory
122 * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio
123 * regulatory requests.
126 HWSIM_REGTEST_DISABLED
= 0,
127 HWSIM_REGTEST_DRIVER_REG_FOLLOW
= 1,
128 HWSIM_REGTEST_DRIVER_REG_ALL
= 2,
129 HWSIM_REGTEST_DIFF_COUNTRY
= 3,
130 HWSIM_REGTEST_WORLD_ROAM
= 4,
131 HWSIM_REGTEST_CUSTOM_WORLD
= 5,
132 HWSIM_REGTEST_CUSTOM_WORLD_2
= 6,
133 HWSIM_REGTEST_STRICT_FOLLOW
= 7,
134 HWSIM_REGTEST_STRICT_ALL
= 8,
135 HWSIM_REGTEST_STRICT_AND_DRIVER_REG
= 9,
136 HWSIM_REGTEST_ALL
= 10,
139 /* Set to one of the HWSIM_REGTEST_* values above */
140 static int regtest
= HWSIM_REGTEST_DISABLED
;
141 module_param(regtest
, int, 0444);
142 MODULE_PARM_DESC(regtest
, "The type of regulatory test we want to run");
144 static const char *hwsim_alpha2s
[] = {
153 static const struct ieee80211_regdomain hwsim_world_regdom_custom_01
= {
157 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
158 REG_RULE(2484-10, 2484+10, 40, 0, 20, 0),
159 REG_RULE(5150-10, 5240+10, 40, 0, 30, 0),
160 REG_RULE(5745-10, 5825+10, 40, 0, 30, 0),
161 REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
165 static const struct ieee80211_regdomain hwsim_world_regdom_custom_02
= {
169 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
170 REG_RULE(5725-10, 5850+10, 40, 0, 30,
172 REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
176 static const struct ieee80211_regdomain
*hwsim_world_regdom_custom
[] = {
177 &hwsim_world_regdom_custom_01
,
178 &hwsim_world_regdom_custom_02
,
181 struct hwsim_vif_priv
{
189 #define HWSIM_VIF_MAGIC 0x69537748
191 static inline void hwsim_check_magic(struct ieee80211_vif
*vif
)
193 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
194 WARN(vp
->magic
!= HWSIM_VIF_MAGIC
,
195 "Invalid VIF (%p) magic %#x, %pM, %d/%d\n",
196 vif
, vp
->magic
, vif
->addr
, vif
->type
, vif
->p2p
);
199 static inline void hwsim_set_magic(struct ieee80211_vif
*vif
)
201 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
202 vp
->magic
= HWSIM_VIF_MAGIC
;
205 static inline void hwsim_clear_magic(struct ieee80211_vif
*vif
)
207 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
211 struct hwsim_sta_priv
{
215 #define HWSIM_STA_MAGIC 0x6d537749
217 static inline void hwsim_check_sta_magic(struct ieee80211_sta
*sta
)
219 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
220 WARN_ON(sp
->magic
!= HWSIM_STA_MAGIC
);
223 static inline void hwsim_set_sta_magic(struct ieee80211_sta
*sta
)
225 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
226 sp
->magic
= HWSIM_STA_MAGIC
;
229 static inline void hwsim_clear_sta_magic(struct ieee80211_sta
*sta
)
231 struct hwsim_sta_priv
*sp
= (void *)sta
->drv_priv
;
235 struct hwsim_chanctx_priv
{
239 #define HWSIM_CHANCTX_MAGIC 0x6d53774a
241 static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf
*c
)
243 struct hwsim_chanctx_priv
*cp
= (void *)c
->drv_priv
;
244 WARN_ON(cp
->magic
!= HWSIM_CHANCTX_MAGIC
);
247 static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf
*c
)
249 struct hwsim_chanctx_priv
*cp
= (void *)c
->drv_priv
;
250 cp
->magic
= HWSIM_CHANCTX_MAGIC
;
253 static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf
*c
)
255 struct hwsim_chanctx_priv
*cp
= (void *)c
->drv_priv
;
259 static unsigned int hwsim_net_id
;
261 static DEFINE_IDA(hwsim_netgroup_ida
);
268 static inline int hwsim_net_get_netgroup(struct net
*net
)
270 struct hwsim_net
*hwsim_net
= net_generic(net
, hwsim_net_id
);
272 return hwsim_net
->netgroup
;
275 static inline int hwsim_net_set_netgroup(struct net
*net
)
277 struct hwsim_net
*hwsim_net
= net_generic(net
, hwsim_net_id
);
279 hwsim_net
->netgroup
= ida_simple_get(&hwsim_netgroup_ida
,
281 return hwsim_net
->netgroup
>= 0 ? 0 : -ENOMEM
;
284 static inline u32
hwsim_net_get_wmediumd(struct net
*net
)
286 struct hwsim_net
*hwsim_net
= net_generic(net
, hwsim_net_id
);
288 return hwsim_net
->wmediumd
;
291 static inline void hwsim_net_set_wmediumd(struct net
*net
, u32 portid
)
293 struct hwsim_net
*hwsim_net
= net_generic(net
, hwsim_net_id
);
295 hwsim_net
->wmediumd
= portid
;
298 static struct class *hwsim_class
;
300 static struct net_device
*hwsim_mon
; /* global monitor netdev */
302 #define CHAN2G(_freq) { \
303 .band = NL80211_BAND_2GHZ, \
304 .center_freq = (_freq), \
305 .hw_value = (_freq), \
308 #define CHAN5G(_freq) { \
309 .band = NL80211_BAND_5GHZ, \
310 .center_freq = (_freq), \
311 .hw_value = (_freq), \
314 static const struct ieee80211_channel hwsim_channels_2ghz
[] = {
315 CHAN2G(2412), /* Channel 1 */
316 CHAN2G(2417), /* Channel 2 */
317 CHAN2G(2422), /* Channel 3 */
318 CHAN2G(2427), /* Channel 4 */
319 CHAN2G(2432), /* Channel 5 */
320 CHAN2G(2437), /* Channel 6 */
321 CHAN2G(2442), /* Channel 7 */
322 CHAN2G(2447), /* Channel 8 */
323 CHAN2G(2452), /* Channel 9 */
324 CHAN2G(2457), /* Channel 10 */
325 CHAN2G(2462), /* Channel 11 */
326 CHAN2G(2467), /* Channel 12 */
327 CHAN2G(2472), /* Channel 13 */
328 CHAN2G(2484), /* Channel 14 */
331 static const struct ieee80211_channel hwsim_channels_5ghz
[] = {
332 CHAN5G(5180), /* Channel 36 */
333 CHAN5G(5200), /* Channel 40 */
334 CHAN5G(5220), /* Channel 44 */
335 CHAN5G(5240), /* Channel 48 */
337 CHAN5G(5260), /* Channel 52 */
338 CHAN5G(5280), /* Channel 56 */
339 CHAN5G(5300), /* Channel 60 */
340 CHAN5G(5320), /* Channel 64 */
342 CHAN5G(5500), /* Channel 100 */
343 CHAN5G(5520), /* Channel 104 */
344 CHAN5G(5540), /* Channel 108 */
345 CHAN5G(5560), /* Channel 112 */
346 CHAN5G(5580), /* Channel 116 */
347 CHAN5G(5600), /* Channel 120 */
348 CHAN5G(5620), /* Channel 124 */
349 CHAN5G(5640), /* Channel 128 */
350 CHAN5G(5660), /* Channel 132 */
351 CHAN5G(5680), /* Channel 136 */
352 CHAN5G(5700), /* Channel 140 */
354 CHAN5G(5745), /* Channel 149 */
355 CHAN5G(5765), /* Channel 153 */
356 CHAN5G(5785), /* Channel 157 */
357 CHAN5G(5805), /* Channel 161 */
358 CHAN5G(5825), /* Channel 165 */
359 CHAN5G(5845), /* Channel 169 */
361 CHAN5G(5855), /* Channel 171 */
362 CHAN5G(5860), /* Channel 172 */
363 CHAN5G(5865), /* Channel 173 */
364 CHAN5G(5870), /* Channel 174 */
366 CHAN5G(5875), /* Channel 175 */
367 CHAN5G(5880), /* Channel 176 */
368 CHAN5G(5885), /* Channel 177 */
369 CHAN5G(5890), /* Channel 178 */
370 CHAN5G(5895), /* Channel 179 */
371 CHAN5G(5900), /* Channel 180 */
372 CHAN5G(5905), /* Channel 181 */
374 CHAN5G(5910), /* Channel 182 */
375 CHAN5G(5915), /* Channel 183 */
376 CHAN5G(5920), /* Channel 184 */
377 CHAN5G(5925), /* Channel 185 */
380 #define NUM_S1G_CHANS_US 51
381 static struct ieee80211_channel hwsim_channels_s1g
[NUM_S1G_CHANS_US
];
383 static const struct ieee80211_sta_s1g_cap hwsim_s1g_cap
= {
385 .cap
= { S1G_CAP0_SGI_1MHZ
| S1G_CAP0_SGI_2MHZ
,
388 S1G_CAP3_MAX_MPDU_LEN
,
393 S1G_CAP8_TWT_RESPOND
| S1G_CAP8_TWT_REQUEST
,
395 .nss_mcs
= { 0xfc | 1, /* MCS 7 for 1 SS */
396 /* RX Highest Supported Long GI Data Rate 0:7 */
398 /* RX Highest Supported Long GI Data Rate 0:7 */
399 /* TX S1G MCS Map 0:6 */
401 /* TX S1G MCS Map :7 */
402 /* TX Highest Supported Long GI Data Rate 0:6 */
404 /* TX Highest Supported Long GI Data Rate 7:8 */
405 /* Rx Single spatial stream and S1G-MCS Map for 1MHz */
406 /* Tx Single spatial stream and S1G-MCS Map for 1MHz */
410 static void hwsim_init_s1g_channels(struct ieee80211_channel
*channels
)
414 for (ch
= 0; ch
< NUM_S1G_CHANS_US
; ch
++) {
415 freq
= 902000 + (ch
+ 1) * 500;
416 channels
[ch
].band
= NL80211_BAND_S1GHZ
;
417 channels
[ch
].center_freq
= KHZ_TO_MHZ(freq
);
418 channels
[ch
].freq_offset
= freq
% 1000;
419 channels
[ch
].hw_value
= ch
+ 1;
423 static const struct ieee80211_rate hwsim_rates
[] = {
425 { .bitrate
= 20, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
426 { .bitrate
= 55, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
427 { .bitrate
= 110, .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
438 static const u32 hwsim_ciphers
[] = {
439 WLAN_CIPHER_SUITE_WEP40
,
440 WLAN_CIPHER_SUITE_WEP104
,
441 WLAN_CIPHER_SUITE_TKIP
,
442 WLAN_CIPHER_SUITE_CCMP
,
443 WLAN_CIPHER_SUITE_CCMP_256
,
444 WLAN_CIPHER_SUITE_GCMP
,
445 WLAN_CIPHER_SUITE_GCMP_256
,
446 WLAN_CIPHER_SUITE_AES_CMAC
,
447 WLAN_CIPHER_SUITE_BIP_CMAC_256
,
448 WLAN_CIPHER_SUITE_BIP_GMAC_128
,
449 WLAN_CIPHER_SUITE_BIP_GMAC_256
,
452 #define OUI_QCA 0x001374
453 #define QCA_NL80211_SUBCMD_TEST 1
454 enum qca_nl80211_vendor_subcmds
{
455 QCA_WLAN_VENDOR_ATTR_TEST
= 8,
456 QCA_WLAN_VENDOR_ATTR_MAX
= QCA_WLAN_VENDOR_ATTR_TEST
459 static const struct nla_policy
460 hwsim_vendor_test_policy
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1] = {
461 [QCA_WLAN_VENDOR_ATTR_MAX
] = { .type
= NLA_U32
},
464 static int mac80211_hwsim_vendor_cmd_test(struct wiphy
*wiphy
,
465 struct wireless_dev
*wdev
,
466 const void *data
, int data_len
)
469 struct nlattr
*tb
[QCA_WLAN_VENDOR_ATTR_MAX
+ 1];
473 err
= nla_parse_deprecated(tb
, QCA_WLAN_VENDOR_ATTR_MAX
, data
,
474 data_len
, hwsim_vendor_test_policy
, NULL
);
477 if (!tb
[QCA_WLAN_VENDOR_ATTR_TEST
])
479 val
= nla_get_u32(tb
[QCA_WLAN_VENDOR_ATTR_TEST
]);
480 wiphy_dbg(wiphy
, "%s: test=%u\n", __func__
, val
);
482 /* Send a vendor event as a test. Note that this would not normally be
483 * done within a command handler, but rather, based on some other
484 * trigger. For simplicity, this command is used to trigger the event
487 * event_idx = 0 (index in mac80211_hwsim_vendor_commands)
489 skb
= cfg80211_vendor_event_alloc(wiphy
, wdev
, 100, 0, GFP_KERNEL
);
491 /* skb_put() or nla_put() will fill up data within
492 * NL80211_ATTR_VENDOR_DATA.
495 /* Add vendor data */
496 nla_put_u32(skb
, QCA_WLAN_VENDOR_ATTR_TEST
, val
+ 1);
498 /* Send the event - this will call nla_nest_end() */
499 cfg80211_vendor_event(skb
, GFP_KERNEL
);
502 /* Send a response to the command */
503 skb
= cfg80211_vendor_cmd_alloc_reply_skb(wiphy
, 10);
507 /* skb_put() or nla_put() will fill up data within
508 * NL80211_ATTR_VENDOR_DATA
510 nla_put_u32(skb
, QCA_WLAN_VENDOR_ATTR_TEST
, val
+ 2);
512 return cfg80211_vendor_cmd_reply(skb
);
515 static struct wiphy_vendor_command mac80211_hwsim_vendor_commands
[] = {
517 .info
= { .vendor_id
= OUI_QCA
,
518 .subcmd
= QCA_NL80211_SUBCMD_TEST
},
519 .flags
= WIPHY_VENDOR_CMD_NEED_NETDEV
,
520 .doit
= mac80211_hwsim_vendor_cmd_test
,
521 .policy
= hwsim_vendor_test_policy
,
522 .maxattr
= QCA_WLAN_VENDOR_ATTR_MAX
,
526 /* Advertise support vendor specific events */
527 static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events
[] = {
528 { .vendor_id
= OUI_QCA
, .subcmd
= 1 },
531 static spinlock_t hwsim_radio_lock
;
532 static LIST_HEAD(hwsim_radios
);
533 static struct rhashtable hwsim_radios_rht
;
534 static int hwsim_radio_idx
;
535 static int hwsim_radios_generation
= 1;
537 static struct platform_driver mac80211_hwsim_driver
= {
539 .name
= "mac80211_hwsim",
543 struct mac80211_hwsim_data
{
544 struct list_head list
;
545 struct rhash_head rht
;
546 struct ieee80211_hw
*hw
;
548 struct ieee80211_supported_band bands
[NUM_NL80211_BANDS
];
549 struct ieee80211_channel channels_2ghz
[ARRAY_SIZE(hwsim_channels_2ghz
)];
550 struct ieee80211_channel channels_5ghz
[ARRAY_SIZE(hwsim_channels_5ghz
)];
551 struct ieee80211_channel channels_s1g
[ARRAY_SIZE(hwsim_channels_s1g
)];
552 struct ieee80211_rate rates
[ARRAY_SIZE(hwsim_rates
)];
553 struct ieee80211_iface_combination if_combination
;
554 struct ieee80211_iface_limit if_limits
[3];
557 u32 ciphers
[ARRAY_SIZE(hwsim_ciphers
)];
559 struct mac_address addresses
[2];
562 bool destroy_on_close
;
565 const struct ieee80211_regdomain
*regd
;
567 struct ieee80211_channel
*tmp_chan
;
568 struct ieee80211_channel
*roc_chan
;
570 struct delayed_work roc_start
;
571 struct delayed_work roc_done
;
572 struct delayed_work hw_scan
;
573 struct cfg80211_scan_request
*hw_scan_request
;
574 struct ieee80211_vif
*hw_scan_vif
;
576 u8 scan_addr
[ETH_ALEN
];
578 struct ieee80211_channel
*channel
;
579 unsigned long next_start
, start
, end
;
580 } survey_data
[ARRAY_SIZE(hwsim_channels_2ghz
) +
581 ARRAY_SIZE(hwsim_channels_5ghz
)];
583 struct ieee80211_channel
*channel
;
584 u64 beacon_int
/* beacon interval in us */;
585 unsigned int rx_filter
;
586 bool started
, idle
, scanning
;
588 struct hrtimer beacon_timer
;
590 PS_DISABLED
, PS_ENABLED
, PS_AUTO_POLL
, PS_MANUAL_POLL
592 bool ps_poll_pending
;
593 struct dentry
*debugfs
;
595 uintptr_t pending_cookie
;
596 struct sk_buff_head pending
; /* packets pending */
598 * Only radios in the same group can communicate together (the
599 * channel has to match too). Each bit represents a group. A
600 * radio can be in more than one group.
604 /* group shared by radios created in the same netns */
606 /* wmediumd portid responsible for netgroup of this radio */
609 /* difference between this hw's clock and the real clock, in usecs */
612 /* absolute beacon transmission time. Used to cover up "tx" delay. */
624 static const struct rhashtable_params hwsim_rht_params
= {
626 .automatic_shrinking
= true,
628 .key_offset
= offsetof(struct mac80211_hwsim_data
, addresses
[1]),
629 .head_offset
= offsetof(struct mac80211_hwsim_data
, rht
),
632 struct hwsim_radiotap_hdr
{
633 struct ieee80211_radiotap_header hdr
;
641 struct hwsim_radiotap_ack_hdr
{
642 struct ieee80211_radiotap_header hdr
;
649 /* MAC80211_HWSIM netlink family */
650 static struct genl_family hwsim_genl_family
;
652 enum hwsim_multicast_groups
{
656 static const struct genl_multicast_group hwsim_mcgrps
[] = {
657 [HWSIM_MCGRP_CONFIG
] = { .name
= "config", },
660 /* MAC80211_HWSIM netlink policy */
662 static const struct nla_policy hwsim_genl_policy
[HWSIM_ATTR_MAX
+ 1] = {
663 [HWSIM_ATTR_ADDR_RECEIVER
] = NLA_POLICY_ETH_ADDR_COMPAT
,
664 [HWSIM_ATTR_ADDR_TRANSMITTER
] = NLA_POLICY_ETH_ADDR_COMPAT
,
665 [HWSIM_ATTR_FRAME
] = { .type
= NLA_BINARY
,
666 .len
= IEEE80211_MAX_DATA_LEN
},
667 [HWSIM_ATTR_FLAGS
] = { .type
= NLA_U32
},
668 [HWSIM_ATTR_RX_RATE
] = { .type
= NLA_U32
},
669 [HWSIM_ATTR_SIGNAL
] = { .type
= NLA_U32
},
670 [HWSIM_ATTR_TX_INFO
] = { .type
= NLA_BINARY
,
671 .len
= IEEE80211_TX_MAX_RATES
*
672 sizeof(struct hwsim_tx_rate
)},
673 [HWSIM_ATTR_COOKIE
] = { .type
= NLA_U64
},
674 [HWSIM_ATTR_CHANNELS
] = { .type
= NLA_U32
},
675 [HWSIM_ATTR_RADIO_ID
] = { .type
= NLA_U32
},
676 [HWSIM_ATTR_REG_HINT_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
677 [HWSIM_ATTR_REG_CUSTOM_REG
] = { .type
= NLA_U32
},
678 [HWSIM_ATTR_REG_STRICT_REG
] = { .type
= NLA_FLAG
},
679 [HWSIM_ATTR_SUPPORT_P2P_DEVICE
] = { .type
= NLA_FLAG
},
680 [HWSIM_ATTR_USE_CHANCTX
] = { .type
= NLA_FLAG
},
681 [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE
] = { .type
= NLA_FLAG
},
682 [HWSIM_ATTR_RADIO_NAME
] = { .type
= NLA_STRING
},
683 [HWSIM_ATTR_NO_VIF
] = { .type
= NLA_FLAG
},
684 [HWSIM_ATTR_FREQ
] = { .type
= NLA_U32
},
685 [HWSIM_ATTR_TX_INFO_FLAGS
] = { .type
= NLA_BINARY
},
686 [HWSIM_ATTR_PERM_ADDR
] = NLA_POLICY_ETH_ADDR_COMPAT
,
687 [HWSIM_ATTR_IFTYPE_SUPPORT
] = { .type
= NLA_U32
},
688 [HWSIM_ATTR_CIPHER_SUPPORT
] = { .type
= NLA_BINARY
},
691 #if IS_REACHABLE(CONFIG_VIRTIO)
693 /* MAC80211_HWSIM virtio queues */
694 static struct virtqueue
*hwsim_vqs
[HWSIM_NUM_VQS
];
695 static bool hwsim_virtio_enabled
;
696 static spinlock_t hwsim_virtio_lock
;
698 static void hwsim_virtio_rx_work(struct work_struct
*work
);
699 static DECLARE_WORK(hwsim_virtio_rx
, hwsim_virtio_rx_work
);
701 static int hwsim_tx_virtio(struct mac80211_hwsim_data
*data
,
704 struct scatterlist sg
[1];
708 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
709 if (!hwsim_virtio_enabled
) {
714 sg_init_one(sg
, skb
->head
, skb_end_offset(skb
));
715 err
= virtqueue_add_outbuf(hwsim_vqs
[HWSIM_VQ_TX
], sg
, 1, skb
,
719 virtqueue_kick(hwsim_vqs
[HWSIM_VQ_TX
]);
720 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
724 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
729 /* cause a linker error if this ends up being needed */
730 extern int hwsim_tx_virtio(struct mac80211_hwsim_data
*data
,
731 struct sk_buff
*skb
);
732 #define hwsim_virtio_enabled false
735 static void mac80211_hwsim_tx_frame(struct ieee80211_hw
*hw
,
737 struct ieee80211_channel
*chan
);
739 /* sysfs attributes */
740 static void hwsim_send_ps_poll(void *dat
, u8
*mac
, struct ieee80211_vif
*vif
)
742 struct mac80211_hwsim_data
*data
= dat
;
743 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
745 struct ieee80211_pspoll
*pspoll
;
750 wiphy_dbg(data
->hw
->wiphy
,
751 "%s: send PS-Poll to %pM for aid %d\n",
752 __func__
, vp
->bssid
, vp
->aid
);
754 skb
= dev_alloc_skb(sizeof(*pspoll
));
757 pspoll
= skb_put(skb
, sizeof(*pspoll
));
758 pspoll
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
759 IEEE80211_STYPE_PSPOLL
|
761 pspoll
->aid
= cpu_to_le16(0xc000 | vp
->aid
);
762 memcpy(pspoll
->bssid
, vp
->bssid
, ETH_ALEN
);
763 memcpy(pspoll
->ta
, mac
, ETH_ALEN
);
766 mac80211_hwsim_tx_frame(data
->hw
, skb
,
767 rcu_dereference(vif
->chanctx_conf
)->def
.chan
);
771 static void hwsim_send_nullfunc(struct mac80211_hwsim_data
*data
, u8
*mac
,
772 struct ieee80211_vif
*vif
, int ps
)
774 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
776 struct ieee80211_hdr
*hdr
;
781 wiphy_dbg(data
->hw
->wiphy
,
782 "%s: send data::nullfunc to %pM ps=%d\n",
783 __func__
, vp
->bssid
, ps
);
785 skb
= dev_alloc_skb(sizeof(*hdr
));
788 hdr
= skb_put(skb
, sizeof(*hdr
) - ETH_ALEN
);
789 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
790 IEEE80211_STYPE_NULLFUNC
|
791 IEEE80211_FCTL_TODS
|
792 (ps
? IEEE80211_FCTL_PM
: 0));
793 hdr
->duration_id
= cpu_to_le16(0);
794 memcpy(hdr
->addr1
, vp
->bssid
, ETH_ALEN
);
795 memcpy(hdr
->addr2
, mac
, ETH_ALEN
);
796 memcpy(hdr
->addr3
, vp
->bssid
, ETH_ALEN
);
799 mac80211_hwsim_tx_frame(data
->hw
, skb
,
800 rcu_dereference(vif
->chanctx_conf
)->def
.chan
);
805 static void hwsim_send_nullfunc_ps(void *dat
, u8
*mac
,
806 struct ieee80211_vif
*vif
)
808 struct mac80211_hwsim_data
*data
= dat
;
809 hwsim_send_nullfunc(data
, mac
, vif
, 1);
812 static void hwsim_send_nullfunc_no_ps(void *dat
, u8
*mac
,
813 struct ieee80211_vif
*vif
)
815 struct mac80211_hwsim_data
*data
= dat
;
816 hwsim_send_nullfunc(data
, mac
, vif
, 0);
819 static int hwsim_fops_ps_read(void *dat
, u64
*val
)
821 struct mac80211_hwsim_data
*data
= dat
;
826 static int hwsim_fops_ps_write(void *dat
, u64 val
)
828 struct mac80211_hwsim_data
*data
= dat
;
831 if (val
!= PS_DISABLED
&& val
!= PS_ENABLED
&& val
!= PS_AUTO_POLL
&&
832 val
!= PS_MANUAL_POLL
)
835 if (val
== PS_MANUAL_POLL
) {
836 if (data
->ps
!= PS_ENABLED
)
839 ieee80211_iterate_active_interfaces_atomic(
840 data
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
841 hwsim_send_ps_poll
, data
);
849 if (old_ps
== PS_DISABLED
&& val
!= PS_DISABLED
) {
850 ieee80211_iterate_active_interfaces_atomic(
851 data
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
852 hwsim_send_nullfunc_ps
, data
);
853 } else if (old_ps
!= PS_DISABLED
&& val
== PS_DISABLED
) {
854 ieee80211_iterate_active_interfaces_atomic(
855 data
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
856 hwsim_send_nullfunc_no_ps
, data
);
863 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_ps
, hwsim_fops_ps_read
, hwsim_fops_ps_write
,
866 static int hwsim_write_simulate_radar(void *dat
, u64 val
)
868 struct mac80211_hwsim_data
*data
= dat
;
870 ieee80211_radar_detected(data
->hw
);
875 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_simulate_radar
, NULL
,
876 hwsim_write_simulate_radar
, "%llu\n");
878 static int hwsim_fops_group_read(void *dat
, u64
*val
)
880 struct mac80211_hwsim_data
*data
= dat
;
885 static int hwsim_fops_group_write(void *dat
, u64 val
)
887 struct mac80211_hwsim_data
*data
= dat
;
892 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group
,
893 hwsim_fops_group_read
, hwsim_fops_group_write
,
896 static netdev_tx_t
hwsim_mon_xmit(struct sk_buff
*skb
,
897 struct net_device
*dev
)
899 /* TODO: allow packet injection */
904 static inline u64
mac80211_hwsim_get_tsf_raw(void)
906 return ktime_to_us(ktime_get_real());
909 static __le64
__mac80211_hwsim_get_tsf(struct mac80211_hwsim_data
*data
)
911 u64 now
= mac80211_hwsim_get_tsf_raw();
912 return cpu_to_le64(now
+ data
->tsf_offset
);
915 static u64
mac80211_hwsim_get_tsf(struct ieee80211_hw
*hw
,
916 struct ieee80211_vif
*vif
)
918 struct mac80211_hwsim_data
*data
= hw
->priv
;
919 return le64_to_cpu(__mac80211_hwsim_get_tsf(data
));
922 static void mac80211_hwsim_set_tsf(struct ieee80211_hw
*hw
,
923 struct ieee80211_vif
*vif
, u64 tsf
)
925 struct mac80211_hwsim_data
*data
= hw
->priv
;
926 u64 now
= mac80211_hwsim_get_tsf(hw
, vif
);
927 u32 bcn_int
= data
->beacon_int
;
928 u64 delta
= abs(tsf
- now
);
930 /* adjust after beaconing with new timestamp at old TBTT */
932 data
->tsf_offset
+= delta
;
933 data
->bcn_delta
= do_div(delta
, bcn_int
);
935 data
->tsf_offset
-= delta
;
936 data
->bcn_delta
= -(s64
)do_div(delta
, bcn_int
);
940 static void mac80211_hwsim_monitor_rx(struct ieee80211_hw
*hw
,
941 struct sk_buff
*tx_skb
,
942 struct ieee80211_channel
*chan
)
944 struct mac80211_hwsim_data
*data
= hw
->priv
;
946 struct hwsim_radiotap_hdr
*hdr
;
948 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(tx_skb
);
949 struct ieee80211_rate
*txrate
= ieee80211_get_tx_rate(hw
, info
);
954 bitrate
= txrate
->bitrate
;
956 if (!netif_running(hwsim_mon
))
959 skb
= skb_copy_expand(tx_skb
, sizeof(*hdr
), 0, GFP_ATOMIC
);
963 hdr
= skb_push(skb
, sizeof(*hdr
));
964 hdr
->hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
966 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(*hdr
));
967 hdr
->hdr
.it_present
= cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
968 (1 << IEEE80211_RADIOTAP_RATE
) |
969 (1 << IEEE80211_RADIOTAP_TSFT
) |
970 (1 << IEEE80211_RADIOTAP_CHANNEL
));
971 hdr
->rt_tsft
= __mac80211_hwsim_get_tsf(data
);
973 hdr
->rt_rate
= bitrate
/ 5;
974 hdr
->rt_channel
= cpu_to_le16(chan
->center_freq
);
975 flags
= IEEE80211_CHAN_2GHZ
;
976 if (txrate
&& txrate
->flags
& IEEE80211_RATE_ERP_G
)
977 flags
|= IEEE80211_CHAN_OFDM
;
979 flags
|= IEEE80211_CHAN_CCK
;
980 hdr
->rt_chbitmask
= cpu_to_le16(flags
);
982 skb
->dev
= hwsim_mon
;
983 skb_reset_mac_header(skb
);
984 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
985 skb
->pkt_type
= PACKET_OTHERHOST
;
986 skb
->protocol
= htons(ETH_P_802_2
);
987 memset(skb
->cb
, 0, sizeof(skb
->cb
));
992 static void mac80211_hwsim_monitor_ack(struct ieee80211_channel
*chan
,
996 struct hwsim_radiotap_ack_hdr
*hdr
;
998 struct ieee80211_hdr
*hdr11
;
1000 if (!netif_running(hwsim_mon
))
1003 skb
= dev_alloc_skb(100);
1007 hdr
= skb_put(skb
, sizeof(*hdr
));
1008 hdr
->hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
1009 hdr
->hdr
.it_pad
= 0;
1010 hdr
->hdr
.it_len
= cpu_to_le16(sizeof(*hdr
));
1011 hdr
->hdr
.it_present
= cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS
) |
1012 (1 << IEEE80211_RADIOTAP_CHANNEL
));
1015 hdr
->rt_channel
= cpu_to_le16(chan
->center_freq
);
1016 flags
= IEEE80211_CHAN_2GHZ
;
1017 hdr
->rt_chbitmask
= cpu_to_le16(flags
);
1019 hdr11
= skb_put(skb
, 10);
1020 hdr11
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_CTL
|
1021 IEEE80211_STYPE_ACK
);
1022 hdr11
->duration_id
= cpu_to_le16(0);
1023 memcpy(hdr11
->addr1
, addr
, ETH_ALEN
);
1025 skb
->dev
= hwsim_mon
;
1026 skb_reset_mac_header(skb
);
1027 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1028 skb
->pkt_type
= PACKET_OTHERHOST
;
1029 skb
->protocol
= htons(ETH_P_802_2
);
1030 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1034 struct mac80211_hwsim_addr_match_data
{
1039 static void mac80211_hwsim_addr_iter(void *data
, u8
*mac
,
1040 struct ieee80211_vif
*vif
)
1042 struct mac80211_hwsim_addr_match_data
*md
= data
;
1044 if (memcmp(mac
, md
->addr
, ETH_ALEN
) == 0)
1048 static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data
*data
,
1051 struct mac80211_hwsim_addr_match_data md
= {
1055 if (data
->scanning
&& memcmp(addr
, data
->scan_addr
, ETH_ALEN
) == 0)
1058 memcpy(md
.addr
, addr
, ETH_ALEN
);
1060 ieee80211_iterate_active_interfaces_atomic(data
->hw
,
1061 IEEE80211_IFACE_ITER_NORMAL
,
1062 mac80211_hwsim_addr_iter
,
1068 static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data
*data
,
1069 struct sk_buff
*skb
)
1077 /* TODO: accept (some) Beacons by default and other frames only
1078 * if pending PS-Poll has been sent */
1080 case PS_MANUAL_POLL
:
1081 /* Allow unicast frames to own address if there is a pending
1083 if (data
->ps_poll_pending
&&
1084 mac80211_hwsim_addr_match(data
, skb
->data
+ 4)) {
1085 data
->ps_poll_pending
= false;
1094 static int hwsim_unicast_netgroup(struct mac80211_hwsim_data
*data
,
1095 struct sk_buff
*skb
, int portid
)
1102 for_each_net_rcu(net
) {
1103 if (data
->netgroup
== hwsim_net_get_netgroup(net
)) {
1104 res
= genlmsg_unicast(net
, skb
, portid
);
1117 static void mac80211_hwsim_config_mac_nl(struct ieee80211_hw
*hw
,
1118 const u8
*addr
, bool add
)
1120 struct mac80211_hwsim_data
*data
= hw
->priv
;
1121 u32 _portid
= READ_ONCE(data
->wmediumd
);
1122 struct sk_buff
*skb
;
1125 if (!_portid
&& !hwsim_virtio_enabled
)
1128 skb
= genlmsg_new(GENLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
1132 msg_head
= genlmsg_put(skb
, 0, 0, &hwsim_genl_family
, 0,
1133 add
? HWSIM_CMD_ADD_MAC_ADDR
:
1134 HWSIM_CMD_DEL_MAC_ADDR
);
1136 pr_debug("mac80211_hwsim: problem with msg_head\n");
1137 goto nla_put_failure
;
1140 if (nla_put(skb
, HWSIM_ATTR_ADDR_TRANSMITTER
,
1141 ETH_ALEN
, data
->addresses
[1].addr
))
1142 goto nla_put_failure
;
1144 if (nla_put(skb
, HWSIM_ATTR_ADDR_RECEIVER
, ETH_ALEN
, addr
))
1145 goto nla_put_failure
;
1147 genlmsg_end(skb
, msg_head
);
1149 if (hwsim_virtio_enabled
)
1150 hwsim_tx_virtio(data
, skb
);
1152 hwsim_unicast_netgroup(data
, skb
, _portid
);
1158 static inline u16
trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate
*rate
)
1162 if (rate
->flags
& IEEE80211_TX_RC_USE_RTS_CTS
)
1163 result
|= MAC80211_HWSIM_TX_RC_USE_RTS_CTS
;
1164 if (rate
->flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
)
1165 result
|= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT
;
1166 if (rate
->flags
& IEEE80211_TX_RC_USE_SHORT_PREAMBLE
)
1167 result
|= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE
;
1168 if (rate
->flags
& IEEE80211_TX_RC_MCS
)
1169 result
|= MAC80211_HWSIM_TX_RC_MCS
;
1170 if (rate
->flags
& IEEE80211_TX_RC_GREEN_FIELD
)
1171 result
|= MAC80211_HWSIM_TX_RC_GREEN_FIELD
;
1172 if (rate
->flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
1173 result
|= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH
;
1174 if (rate
->flags
& IEEE80211_TX_RC_DUP_DATA
)
1175 result
|= MAC80211_HWSIM_TX_RC_DUP_DATA
;
1176 if (rate
->flags
& IEEE80211_TX_RC_SHORT_GI
)
1177 result
|= MAC80211_HWSIM_TX_RC_SHORT_GI
;
1178 if (rate
->flags
& IEEE80211_TX_RC_VHT_MCS
)
1179 result
|= MAC80211_HWSIM_TX_RC_VHT_MCS
;
1180 if (rate
->flags
& IEEE80211_TX_RC_80_MHZ_WIDTH
)
1181 result
|= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH
;
1182 if (rate
->flags
& IEEE80211_TX_RC_160_MHZ_WIDTH
)
1183 result
|= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH
;
1188 static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw
*hw
,
1189 struct sk_buff
*my_skb
,
1192 struct sk_buff
*skb
;
1193 struct mac80211_hwsim_data
*data
= hw
->priv
;
1194 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) my_skb
->data
;
1195 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(my_skb
);
1197 unsigned int hwsim_flags
= 0;
1199 struct hwsim_tx_rate tx_attempts
[IEEE80211_TX_MAX_RATES
];
1200 struct hwsim_tx_rate_flag tx_attempts_flags
[IEEE80211_TX_MAX_RATES
];
1203 if (data
->ps
!= PS_DISABLED
)
1204 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1205 /* If the queue contains MAX_QUEUE skb's drop some */
1206 if (skb_queue_len(&data
->pending
) >= MAX_QUEUE
) {
1207 /* Droping until WARN_QUEUE level */
1208 while (skb_queue_len(&data
->pending
) >= WARN_QUEUE
) {
1209 ieee80211_free_txskb(hw
, skb_dequeue(&data
->pending
));
1214 skb
= genlmsg_new(GENLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
1216 goto nla_put_failure
;
1218 msg_head
= genlmsg_put(skb
, 0, 0, &hwsim_genl_family
, 0,
1220 if (msg_head
== NULL
) {
1221 pr_debug("mac80211_hwsim: problem with msg_head\n");
1222 goto nla_put_failure
;
1225 if (nla_put(skb
, HWSIM_ATTR_ADDR_TRANSMITTER
,
1226 ETH_ALEN
, data
->addresses
[1].addr
))
1227 goto nla_put_failure
;
1229 /* We get the skb->data */
1230 if (nla_put(skb
, HWSIM_ATTR_FRAME
, my_skb
->len
, my_skb
->data
))
1231 goto nla_put_failure
;
1233 /* We get the flags for this transmission, and we translate them to
1236 if (info
->flags
& IEEE80211_TX_CTL_REQ_TX_STATUS
)
1237 hwsim_flags
|= HWSIM_TX_CTL_REQ_TX_STATUS
;
1239 if (info
->flags
& IEEE80211_TX_CTL_NO_ACK
)
1240 hwsim_flags
|= HWSIM_TX_CTL_NO_ACK
;
1242 if (nla_put_u32(skb
, HWSIM_ATTR_FLAGS
, hwsim_flags
))
1243 goto nla_put_failure
;
1245 if (nla_put_u32(skb
, HWSIM_ATTR_FREQ
, data
->channel
->center_freq
))
1246 goto nla_put_failure
;
1248 /* We get the tx control (rate and retries) info*/
1250 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++) {
1251 tx_attempts
[i
].idx
= info
->status
.rates
[i
].idx
;
1252 tx_attempts_flags
[i
].idx
= info
->status
.rates
[i
].idx
;
1253 tx_attempts
[i
].count
= info
->status
.rates
[i
].count
;
1254 tx_attempts_flags
[i
].flags
=
1255 trans_tx_rate_flags_ieee2hwsim(
1256 &info
->status
.rates
[i
]);
1259 if (nla_put(skb
, HWSIM_ATTR_TX_INFO
,
1260 sizeof(struct hwsim_tx_rate
)*IEEE80211_TX_MAX_RATES
,
1262 goto nla_put_failure
;
1264 if (nla_put(skb
, HWSIM_ATTR_TX_INFO_FLAGS
,
1265 sizeof(struct hwsim_tx_rate_flag
) * IEEE80211_TX_MAX_RATES
,
1267 goto nla_put_failure
;
1269 /* We create a cookie to identify this skb */
1270 data
->pending_cookie
++;
1271 cookie
= data
->pending_cookie
;
1272 info
->rate_driver_data
[0] = (void *)cookie
;
1273 if (nla_put_u64_64bit(skb
, HWSIM_ATTR_COOKIE
, cookie
, HWSIM_ATTR_PAD
))
1274 goto nla_put_failure
;
1276 genlmsg_end(skb
, msg_head
);
1278 if (hwsim_virtio_enabled
) {
1279 if (hwsim_tx_virtio(data
, skb
))
1280 goto err_free_txskb
;
1282 if (hwsim_unicast_netgroup(data
, skb
, dst_portid
))
1283 goto err_free_txskb
;
1286 /* Enqueue the packet */
1287 skb_queue_tail(&data
->pending
, my_skb
);
1289 data
->tx_bytes
+= my_skb
->len
;
1295 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__
);
1296 ieee80211_free_txskb(hw
, my_skb
);
1300 static bool hwsim_chans_compat(struct ieee80211_channel
*c1
,
1301 struct ieee80211_channel
*c2
)
1306 return c1
->center_freq
== c2
->center_freq
;
1309 struct tx_iter_data
{
1310 struct ieee80211_channel
*channel
;
1314 static void mac80211_hwsim_tx_iter(void *_data
, u8
*addr
,
1315 struct ieee80211_vif
*vif
)
1317 struct tx_iter_data
*data
= _data
;
1319 if (!vif
->chanctx_conf
)
1322 if (!hwsim_chans_compat(data
->channel
,
1323 rcu_dereference(vif
->chanctx_conf
)->def
.chan
))
1326 data
->receive
= true;
1329 static void mac80211_hwsim_add_vendor_rtap(struct sk_buff
*skb
)
1332 * To enable this code, #define the HWSIM_RADIOTAP_OUI,
1334 * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00"
1335 * (but you should use a valid OUI, not that)
1337 * If anyone wants to 'donate' a radiotap OUI/subns code
1338 * please send a patch removing this #ifdef and changing
1339 * the values accordingly.
1341 #ifdef HWSIM_RADIOTAP_OUI
1342 struct ieee80211_vendor_radiotap
*rtap
;
1345 * Note that this code requires the headroom in the SKB
1346 * that was allocated earlier.
1348 rtap
= skb_push(skb
, sizeof(*rtap
) + 8 + 4);
1349 rtap
->oui
[0] = HWSIM_RADIOTAP_OUI
[0];
1350 rtap
->oui
[1] = HWSIM_RADIOTAP_OUI
[1];
1351 rtap
->oui
[2] = HWSIM_RADIOTAP_OUI
[2];
1355 * Radiotap vendor namespaces can (and should) also be
1356 * split into fields by using the standard radiotap
1357 * presence bitmap mechanism. Use just BIT(0) here for
1358 * the presence bitmap.
1360 rtap
->present
= BIT(0);
1361 /* We have 8 bytes of (dummy) data */
1363 /* For testing, also require it to be aligned */
1365 /* And also test that padding works, 4 bytes */
1368 memcpy(rtap
->data
, "ABCDEFGH", 8);
1369 /* make sure to clear padding, mac80211 doesn't */
1370 memset(rtap
->data
+ 8, 0, 4);
1372 IEEE80211_SKB_RXCB(skb
)->flag
|= RX_FLAG_RADIOTAP_VENDOR_DATA
;
1376 static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw
*hw
,
1377 struct sk_buff
*skb
,
1378 struct ieee80211_channel
*chan
)
1380 struct mac80211_hwsim_data
*data
= hw
->priv
, *data2
;
1382 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*) skb
->data
;
1383 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1384 struct ieee80211_rx_status rx_status
;
1387 memset(&rx_status
, 0, sizeof(rx_status
));
1388 rx_status
.flag
|= RX_FLAG_MACTIME_START
;
1389 rx_status
.freq
= chan
->center_freq
;
1390 rx_status
.freq_offset
= chan
->freq_offset
? 1 : 0;
1391 rx_status
.band
= chan
->band
;
1392 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_VHT_MCS
) {
1393 rx_status
.rate_idx
=
1394 ieee80211_rate_get_vht_mcs(&info
->control
.rates
[0]);
1396 ieee80211_rate_get_vht_nss(&info
->control
.rates
[0]);
1397 rx_status
.encoding
= RX_ENC_VHT
;
1399 rx_status
.rate_idx
= info
->control
.rates
[0].idx
;
1400 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_MCS
)
1401 rx_status
.encoding
= RX_ENC_HT
;
1403 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_40_MHZ_WIDTH
)
1404 rx_status
.bw
= RATE_INFO_BW_40
;
1405 else if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_80_MHZ_WIDTH
)
1406 rx_status
.bw
= RATE_INFO_BW_80
;
1407 else if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_160_MHZ_WIDTH
)
1408 rx_status
.bw
= RATE_INFO_BW_160
;
1410 rx_status
.bw
= RATE_INFO_BW_20
;
1411 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_SHORT_GI
)
1412 rx_status
.enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
1413 /* TODO: simulate real signal strength (and optional packet loss) */
1414 rx_status
.signal
= -50;
1415 if (info
->control
.vif
)
1416 rx_status
.signal
+= info
->control
.vif
->bss_conf
.txpower
;
1418 if (data
->ps
!= PS_DISABLED
)
1419 hdr
->frame_control
|= cpu_to_le16(IEEE80211_FCTL_PM
);
1421 /* release the skb's source info */
1429 * Get absolute mactime here so all HWs RX at the "same time", and
1430 * absolute TX time for beacon mactime so the timestamp matches.
1431 * Giving beacons a different mactime than non-beacons looks messy, but
1432 * it helps the Toffset be exact and a ~10us mactime discrepancy
1433 * probably doesn't really matter.
1435 if (ieee80211_is_beacon(hdr
->frame_control
) ||
1436 ieee80211_is_probe_resp(hdr
->frame_control
)) {
1437 rx_status
.boottime_ns
= ktime_get_boottime_ns();
1438 now
= data
->abs_bcn_ts
;
1440 now
= mac80211_hwsim_get_tsf_raw();
1443 /* Copy skb to all enabled radios that are on the current frequency */
1444 spin_lock(&hwsim_radio_lock
);
1445 list_for_each_entry(data2
, &hwsim_radios
, list
) {
1446 struct sk_buff
*nskb
;
1447 struct tx_iter_data tx_iter_data
= {
1455 if (!data2
->started
|| (data2
->idle
&& !data2
->tmp_chan
) ||
1456 !hwsim_ps_rx_ok(data2
, skb
))
1459 if (!(data
->group
& data2
->group
))
1462 if (data
->netgroup
!= data2
->netgroup
)
1465 if (!hwsim_chans_compat(chan
, data2
->tmp_chan
) &&
1466 !hwsim_chans_compat(chan
, data2
->channel
)) {
1467 ieee80211_iterate_active_interfaces_atomic(
1468 data2
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1469 mac80211_hwsim_tx_iter
, &tx_iter_data
);
1470 if (!tx_iter_data
.receive
)
1475 * reserve some space for our vendor and the normal
1476 * radiotap header, since we're copying anyway
1478 if (skb
->len
< PAGE_SIZE
&& paged_rx
) {
1479 struct page
*page
= alloc_page(GFP_ATOMIC
);
1484 nskb
= dev_alloc_skb(128);
1490 memcpy(page_address(page
), skb
->data
, skb
->len
);
1491 skb_add_rx_frag(nskb
, 0, page
, 0, skb
->len
, skb
->len
);
1493 nskb
= skb_copy(skb
, GFP_ATOMIC
);
1498 if (mac80211_hwsim_addr_match(data2
, hdr
->addr1
))
1501 rx_status
.mactime
= now
+ data2
->tsf_offset
;
1503 memcpy(IEEE80211_SKB_RXCB(nskb
), &rx_status
, sizeof(rx_status
));
1505 mac80211_hwsim_add_vendor_rtap(nskb
);
1508 data2
->rx_bytes
+= nskb
->len
;
1509 ieee80211_rx_irqsafe(data2
->hw
, nskb
);
1511 spin_unlock(&hwsim_radio_lock
);
1516 static void mac80211_hwsim_tx(struct ieee80211_hw
*hw
,
1517 struct ieee80211_tx_control
*control
,
1518 struct sk_buff
*skb
)
1520 struct mac80211_hwsim_data
*data
= hw
->priv
;
1521 struct ieee80211_tx_info
*txi
= IEEE80211_SKB_CB(skb
);
1522 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
1523 struct ieee80211_chanctx_conf
*chanctx_conf
;
1524 struct ieee80211_channel
*channel
;
1528 if (WARN_ON(skb
->len
< 10)) {
1529 /* Should not happen; just a sanity check for addr1 use */
1530 ieee80211_free_txskb(hw
, skb
);
1534 if (!data
->use_chanctx
) {
1535 channel
= data
->channel
;
1536 } else if (txi
->hw_queue
== 4) {
1537 channel
= data
->tmp_chan
;
1539 chanctx_conf
= rcu_dereference(txi
->control
.vif
->chanctx_conf
);
1541 channel
= chanctx_conf
->def
.chan
;
1546 if (WARN(!channel
, "TX w/o channel - queue = %d\n", txi
->hw_queue
)) {
1547 ieee80211_free_txskb(hw
, skb
);
1551 if (data
->idle
&& !data
->tmp_chan
) {
1552 wiphy_dbg(hw
->wiphy
, "Trying to TX when idle - reject\n");
1553 ieee80211_free_txskb(hw
, skb
);
1557 if (txi
->control
.vif
)
1558 hwsim_check_magic(txi
->control
.vif
);
1560 hwsim_check_sta_magic(control
->sta
);
1562 if (ieee80211_hw_check(hw
, SUPPORTS_RC_TABLE
))
1563 ieee80211_get_tx_rates(txi
->control
.vif
, control
->sta
, skb
,
1565 ARRAY_SIZE(txi
->control
.rates
));
1567 if (skb
->len
>= 24 + 8 &&
1568 ieee80211_is_probe_resp(hdr
->frame_control
)) {
1569 /* fake header transmission time */
1570 struct ieee80211_mgmt
*mgmt
;
1571 struct ieee80211_rate
*txrate
;
1576 mgmt
= (struct ieee80211_mgmt
*)skb
->data
;
1577 txrate
= ieee80211_get_tx_rate(hw
, txi
);
1579 bitrate
= txrate
->bitrate
;
1580 ts
= mac80211_hwsim_get_tsf_raw();
1581 mgmt
->u
.probe_resp
.timestamp
=
1582 cpu_to_le64(ts
+ data
->tsf_offset
+
1583 24 * 8 * 10 / bitrate
);
1586 mac80211_hwsim_monitor_rx(hw
, skb
, channel
);
1588 /* wmediumd mode check */
1589 _portid
= READ_ONCE(data
->wmediumd
);
1591 if (_portid
|| hwsim_virtio_enabled
)
1592 return mac80211_hwsim_tx_frame_nl(hw
, skb
, _portid
);
1594 /* NO wmediumd detected, perfect medium simulation */
1596 data
->tx_bytes
+= skb
->len
;
1597 ack
= mac80211_hwsim_tx_frame_no_nl(hw
, skb
, channel
);
1599 if (ack
&& skb
->len
>= 16)
1600 mac80211_hwsim_monitor_ack(channel
, hdr
->addr2
);
1602 ieee80211_tx_info_clear_status(txi
);
1604 /* frame was transmitted at most favorable rate at first attempt */
1605 txi
->control
.rates
[0].count
= 1;
1606 txi
->control
.rates
[1].idx
= -1;
1608 if (!(txi
->flags
& IEEE80211_TX_CTL_NO_ACK
) && ack
)
1609 txi
->flags
|= IEEE80211_TX_STAT_ACK
;
1610 ieee80211_tx_status_irqsafe(hw
, skb
);
1614 static int mac80211_hwsim_start(struct ieee80211_hw
*hw
)
1616 struct mac80211_hwsim_data
*data
= hw
->priv
;
1617 wiphy_dbg(hw
->wiphy
, "%s\n", __func__
);
1618 data
->started
= true;
1623 static void mac80211_hwsim_stop(struct ieee80211_hw
*hw
)
1625 struct mac80211_hwsim_data
*data
= hw
->priv
;
1626 data
->started
= false;
1627 hrtimer_cancel(&data
->beacon_timer
);
1628 wiphy_dbg(hw
->wiphy
, "%s\n", __func__
);
1632 static int mac80211_hwsim_add_interface(struct ieee80211_hw
*hw
,
1633 struct ieee80211_vif
*vif
)
1635 wiphy_dbg(hw
->wiphy
, "%s (type=%d mac_addr=%pM)\n",
1636 __func__
, ieee80211_vif_type_p2p(vif
),
1638 hwsim_set_magic(vif
);
1640 if (vif
->type
!= NL80211_IFTYPE_MONITOR
)
1641 mac80211_hwsim_config_mac_nl(hw
, vif
->addr
, true);
1644 vif
->hw_queue
[IEEE80211_AC_VO
] = 0;
1645 vif
->hw_queue
[IEEE80211_AC_VI
] = 1;
1646 vif
->hw_queue
[IEEE80211_AC_BE
] = 2;
1647 vif
->hw_queue
[IEEE80211_AC_BK
] = 3;
1653 static int mac80211_hwsim_change_interface(struct ieee80211_hw
*hw
,
1654 struct ieee80211_vif
*vif
,
1655 enum nl80211_iftype newtype
,
1658 newtype
= ieee80211_iftype_p2p(newtype
, newp2p
);
1659 wiphy_dbg(hw
->wiphy
,
1660 "%s (old type=%d, new type=%d, mac_addr=%pM)\n",
1661 __func__
, ieee80211_vif_type_p2p(vif
),
1662 newtype
, vif
->addr
);
1663 hwsim_check_magic(vif
);
1666 * interface may change from non-AP to AP in
1667 * which case this needs to be set up again
1674 static void mac80211_hwsim_remove_interface(
1675 struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1677 wiphy_dbg(hw
->wiphy
, "%s (type=%d mac_addr=%pM)\n",
1678 __func__
, ieee80211_vif_type_p2p(vif
),
1680 hwsim_check_magic(vif
);
1681 hwsim_clear_magic(vif
);
1682 if (vif
->type
!= NL80211_IFTYPE_MONITOR
)
1683 mac80211_hwsim_config_mac_nl(hw
, vif
->addr
, false);
1686 static void mac80211_hwsim_tx_frame(struct ieee80211_hw
*hw
,
1687 struct sk_buff
*skb
,
1688 struct ieee80211_channel
*chan
)
1690 struct mac80211_hwsim_data
*data
= hw
->priv
;
1691 u32 _pid
= READ_ONCE(data
->wmediumd
);
1693 if (ieee80211_hw_check(hw
, SUPPORTS_RC_TABLE
)) {
1694 struct ieee80211_tx_info
*txi
= IEEE80211_SKB_CB(skb
);
1695 ieee80211_get_tx_rates(txi
->control
.vif
, NULL
, skb
,
1697 ARRAY_SIZE(txi
->control
.rates
));
1700 mac80211_hwsim_monitor_rx(hw
, skb
, chan
);
1702 if (_pid
|| hwsim_virtio_enabled
)
1703 return mac80211_hwsim_tx_frame_nl(hw
, skb
, _pid
);
1705 mac80211_hwsim_tx_frame_no_nl(hw
, skb
, chan
);
1709 static void mac80211_hwsim_beacon_tx(void *arg
, u8
*mac
,
1710 struct ieee80211_vif
*vif
)
1712 struct mac80211_hwsim_data
*data
= arg
;
1713 struct ieee80211_hw
*hw
= data
->hw
;
1714 struct ieee80211_tx_info
*info
;
1715 struct ieee80211_rate
*txrate
;
1716 struct ieee80211_mgmt
*mgmt
;
1717 struct sk_buff
*skb
;
1721 hwsim_check_magic(vif
);
1723 if (vif
->type
!= NL80211_IFTYPE_AP
&&
1724 vif
->type
!= NL80211_IFTYPE_MESH_POINT
&&
1725 vif
->type
!= NL80211_IFTYPE_ADHOC
&&
1726 vif
->type
!= NL80211_IFTYPE_OCB
)
1729 skb
= ieee80211_beacon_get(hw
, vif
);
1732 info
= IEEE80211_SKB_CB(skb
);
1733 if (ieee80211_hw_check(hw
, SUPPORTS_RC_TABLE
))
1734 ieee80211_get_tx_rates(vif
, NULL
, skb
,
1735 info
->control
.rates
,
1736 ARRAY_SIZE(info
->control
.rates
));
1738 txrate
= ieee80211_get_tx_rate(hw
, info
);
1740 bitrate
= txrate
->bitrate
;
1742 mgmt
= (struct ieee80211_mgmt
*) skb
->data
;
1743 /* fake header transmission time */
1744 data
->abs_bcn_ts
= mac80211_hwsim_get_tsf_raw();
1745 if (ieee80211_is_s1g_beacon(mgmt
->frame_control
)) {
1746 struct ieee80211_ext
*ext
= (void *) mgmt
;
1748 ext
->u
.s1g_beacon
.timestamp
= cpu_to_le32(data
->abs_bcn_ts
+
1753 mgmt
->u
.beacon
.timestamp
= cpu_to_le64(data
->abs_bcn_ts
+
1759 mac80211_hwsim_tx_frame(hw
, skb
,
1760 rcu_dereference(vif
->chanctx_conf
)->def
.chan
);
1762 while ((skb
= ieee80211_get_buffered_bc(hw
, vif
)) != NULL
) {
1763 mac80211_hwsim_tx_frame(hw
, skb
,
1764 rcu_dereference(vif
->chanctx_conf
)->def
.chan
);
1767 if (vif
->csa_active
&& ieee80211_beacon_cntdwn_is_complete(vif
))
1768 ieee80211_csa_finish(vif
);
1771 static enum hrtimer_restart
1772 mac80211_hwsim_beacon(struct hrtimer
*timer
)
1774 struct mac80211_hwsim_data
*data
=
1775 container_of(timer
, struct mac80211_hwsim_data
, beacon_timer
);
1776 struct ieee80211_hw
*hw
= data
->hw
;
1777 u64 bcn_int
= data
->beacon_int
;
1780 return HRTIMER_NORESTART
;
1782 ieee80211_iterate_active_interfaces_atomic(
1783 hw
, IEEE80211_IFACE_ITER_NORMAL
,
1784 mac80211_hwsim_beacon_tx
, data
);
1786 /* beacon at new TBTT + beacon interval */
1787 if (data
->bcn_delta
) {
1788 bcn_int
-= data
->bcn_delta
;
1789 data
->bcn_delta
= 0;
1791 hrtimer_forward(&data
->beacon_timer
, hrtimer_get_expires(timer
),
1792 ns_to_ktime(bcn_int
* NSEC_PER_USEC
));
1793 return HRTIMER_RESTART
;
1796 static const char * const hwsim_chanwidths
[] = {
1797 [NL80211_CHAN_WIDTH_5
] = "ht5",
1798 [NL80211_CHAN_WIDTH_10
] = "ht10",
1799 [NL80211_CHAN_WIDTH_20_NOHT
] = "noht",
1800 [NL80211_CHAN_WIDTH_20
] = "ht20",
1801 [NL80211_CHAN_WIDTH_40
] = "ht40",
1802 [NL80211_CHAN_WIDTH_80
] = "vht80",
1803 [NL80211_CHAN_WIDTH_80P80
] = "vht80p80",
1804 [NL80211_CHAN_WIDTH_160
] = "vht160",
1805 [NL80211_CHAN_WIDTH_1
] = "1MHz",
1806 [NL80211_CHAN_WIDTH_2
] = "2MHz",
1807 [NL80211_CHAN_WIDTH_4
] = "4MHz",
1808 [NL80211_CHAN_WIDTH_8
] = "8MHz",
1809 [NL80211_CHAN_WIDTH_16
] = "16MHz",
1812 static int mac80211_hwsim_config(struct ieee80211_hw
*hw
, u32 changed
)
1814 struct mac80211_hwsim_data
*data
= hw
->priv
;
1815 struct ieee80211_conf
*conf
= &hw
->conf
;
1816 static const char *smps_modes
[IEEE80211_SMPS_NUM_MODES
] = {
1817 [IEEE80211_SMPS_AUTOMATIC
] = "auto",
1818 [IEEE80211_SMPS_OFF
] = "off",
1819 [IEEE80211_SMPS_STATIC
] = "static",
1820 [IEEE80211_SMPS_DYNAMIC
] = "dynamic",
1824 if (conf
->chandef
.chan
)
1825 wiphy_dbg(hw
->wiphy
,
1826 "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
1828 conf
->chandef
.chan
->center_freq
,
1829 conf
->chandef
.center_freq1
,
1830 conf
->chandef
.center_freq2
,
1831 hwsim_chanwidths
[conf
->chandef
.width
],
1832 !!(conf
->flags
& IEEE80211_CONF_IDLE
),
1833 !!(conf
->flags
& IEEE80211_CONF_PS
),
1834 smps_modes
[conf
->smps_mode
]);
1836 wiphy_dbg(hw
->wiphy
,
1837 "%s (freq=0 idle=%d ps=%d smps=%s)\n",
1839 !!(conf
->flags
& IEEE80211_CONF_IDLE
),
1840 !!(conf
->flags
& IEEE80211_CONF_PS
),
1841 smps_modes
[conf
->smps_mode
]);
1843 data
->idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1845 WARN_ON(conf
->chandef
.chan
&& data
->use_chanctx
);
1847 mutex_lock(&data
->mutex
);
1848 if (data
->scanning
&& conf
->chandef
.chan
) {
1849 for (idx
= 0; idx
< ARRAY_SIZE(data
->survey_data
); idx
++) {
1850 if (data
->survey_data
[idx
].channel
== data
->channel
) {
1851 data
->survey_data
[idx
].start
=
1852 data
->survey_data
[idx
].next_start
;
1853 data
->survey_data
[idx
].end
= jiffies
;
1858 data
->channel
= conf
->chandef
.chan
;
1860 for (idx
= 0; idx
< ARRAY_SIZE(data
->survey_data
); idx
++) {
1861 if (data
->survey_data
[idx
].channel
&&
1862 data
->survey_data
[idx
].channel
!= data
->channel
)
1864 data
->survey_data
[idx
].channel
= data
->channel
;
1865 data
->survey_data
[idx
].next_start
= jiffies
;
1869 data
->channel
= conf
->chandef
.chan
;
1871 mutex_unlock(&data
->mutex
);
1873 if (!data
->started
|| !data
->beacon_int
)
1874 hrtimer_cancel(&data
->beacon_timer
);
1875 else if (!hrtimer_is_queued(&data
->beacon_timer
)) {
1876 u64 tsf
= mac80211_hwsim_get_tsf(hw
, NULL
);
1877 u32 bcn_int
= data
->beacon_int
;
1878 u64 until_tbtt
= bcn_int
- do_div(tsf
, bcn_int
);
1880 hrtimer_start(&data
->beacon_timer
,
1881 ns_to_ktime(until_tbtt
* NSEC_PER_USEC
),
1882 HRTIMER_MODE_REL_SOFT
);
1889 static void mac80211_hwsim_configure_filter(struct ieee80211_hw
*hw
,
1890 unsigned int changed_flags
,
1891 unsigned int *total_flags
,u64 multicast
)
1893 struct mac80211_hwsim_data
*data
= hw
->priv
;
1895 wiphy_dbg(hw
->wiphy
, "%s\n", __func__
);
1897 data
->rx_filter
= 0;
1898 if (*total_flags
& FIF_ALLMULTI
)
1899 data
->rx_filter
|= FIF_ALLMULTI
;
1900 if (*total_flags
& FIF_MCAST_ACTION
)
1901 data
->rx_filter
|= FIF_MCAST_ACTION
;
1903 *total_flags
= data
->rx_filter
;
1906 static void mac80211_hwsim_bcn_en_iter(void *data
, u8
*mac
,
1907 struct ieee80211_vif
*vif
)
1909 unsigned int *count
= data
;
1910 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
1916 static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw
*hw
,
1917 struct ieee80211_vif
*vif
,
1918 struct ieee80211_bss_conf
*info
,
1921 struct hwsim_vif_priv
*vp
= (void *)vif
->drv_priv
;
1922 struct mac80211_hwsim_data
*data
= hw
->priv
;
1924 hwsim_check_magic(vif
);
1926 wiphy_dbg(hw
->wiphy
, "%s(changed=0x%x vif->addr=%pM)\n",
1927 __func__
, changed
, vif
->addr
);
1929 if (changed
& BSS_CHANGED_BSSID
) {
1930 wiphy_dbg(hw
->wiphy
, "%s: BSSID changed: %pM\n",
1931 __func__
, info
->bssid
);
1932 memcpy(vp
->bssid
, info
->bssid
, ETH_ALEN
);
1935 if (changed
& BSS_CHANGED_ASSOC
) {
1936 wiphy_dbg(hw
->wiphy
, " ASSOC: assoc=%d aid=%d\n",
1937 info
->assoc
, info
->aid
);
1938 vp
->assoc
= info
->assoc
;
1939 vp
->aid
= info
->aid
;
1942 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
1943 wiphy_dbg(hw
->wiphy
, " BCN EN: %d (BI=%u)\n",
1944 info
->enable_beacon
, info
->beacon_int
);
1945 vp
->bcn_en
= info
->enable_beacon
;
1946 if (data
->started
&&
1947 !hrtimer_is_queued(&data
->beacon_timer
) &&
1948 info
->enable_beacon
) {
1949 u64 tsf
, until_tbtt
;
1951 data
->beacon_int
= info
->beacon_int
* 1024;
1952 tsf
= mac80211_hwsim_get_tsf(hw
, vif
);
1953 bcn_int
= data
->beacon_int
;
1954 until_tbtt
= bcn_int
- do_div(tsf
, bcn_int
);
1956 hrtimer_start(&data
->beacon_timer
,
1957 ns_to_ktime(until_tbtt
* NSEC_PER_USEC
),
1958 HRTIMER_MODE_REL_SOFT
);
1959 } else if (!info
->enable_beacon
) {
1960 unsigned int count
= 0;
1961 ieee80211_iterate_active_interfaces_atomic(
1962 data
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1963 mac80211_hwsim_bcn_en_iter
, &count
);
1964 wiphy_dbg(hw
->wiphy
, " beaconing vifs remaining: %u",
1967 hrtimer_cancel(&data
->beacon_timer
);
1968 data
->beacon_int
= 0;
1973 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1974 wiphy_dbg(hw
->wiphy
, " ERP_CTS_PROT: %d\n",
1975 info
->use_cts_prot
);
1978 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1979 wiphy_dbg(hw
->wiphy
, " ERP_PREAMBLE: %d\n",
1980 info
->use_short_preamble
);
1983 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1984 wiphy_dbg(hw
->wiphy
, " ERP_SLOT: %d\n", info
->use_short_slot
);
1987 if (changed
& BSS_CHANGED_HT
) {
1988 wiphy_dbg(hw
->wiphy
, " HT: op_mode=0x%x\n",
1989 info
->ht_operation_mode
);
1992 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1993 wiphy_dbg(hw
->wiphy
, " BASIC_RATES: 0x%llx\n",
1994 (unsigned long long) info
->basic_rates
);
1997 if (changed
& BSS_CHANGED_TXPOWER
)
1998 wiphy_dbg(hw
->wiphy
, " TX Power: %d dBm\n", info
->txpower
);
2001 static int mac80211_hwsim_sta_add(struct ieee80211_hw
*hw
,
2002 struct ieee80211_vif
*vif
,
2003 struct ieee80211_sta
*sta
)
2005 hwsim_check_magic(vif
);
2006 hwsim_set_sta_magic(sta
);
2011 static int mac80211_hwsim_sta_remove(struct ieee80211_hw
*hw
,
2012 struct ieee80211_vif
*vif
,
2013 struct ieee80211_sta
*sta
)
2015 hwsim_check_magic(vif
);
2016 hwsim_clear_sta_magic(sta
);
2021 static void mac80211_hwsim_sta_notify(struct ieee80211_hw
*hw
,
2022 struct ieee80211_vif
*vif
,
2023 enum sta_notify_cmd cmd
,
2024 struct ieee80211_sta
*sta
)
2026 hwsim_check_magic(vif
);
2029 case STA_NOTIFY_SLEEP
:
2030 case STA_NOTIFY_AWAKE
:
2031 /* TODO: make good use of these flags */
2034 WARN(1, "Invalid sta notify: %d\n", cmd
);
2039 static int mac80211_hwsim_set_tim(struct ieee80211_hw
*hw
,
2040 struct ieee80211_sta
*sta
,
2043 hwsim_check_sta_magic(sta
);
2047 static int mac80211_hwsim_conf_tx(
2048 struct ieee80211_hw
*hw
,
2049 struct ieee80211_vif
*vif
, u16 queue
,
2050 const struct ieee80211_tx_queue_params
*params
)
2052 wiphy_dbg(hw
->wiphy
,
2053 "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n",
2055 params
->txop
, params
->cw_min
,
2056 params
->cw_max
, params
->aifs
);
2060 static int mac80211_hwsim_get_survey(struct ieee80211_hw
*hw
, int idx
,
2061 struct survey_info
*survey
)
2063 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2065 if (idx
< 0 || idx
>= ARRAY_SIZE(hwsim
->survey_data
))
2068 mutex_lock(&hwsim
->mutex
);
2069 survey
->channel
= hwsim
->survey_data
[idx
].channel
;
2070 if (!survey
->channel
) {
2071 mutex_unlock(&hwsim
->mutex
);
2076 * Magically conjured dummy values --- this is only ok for simulated hardware.
2078 * A real driver which cannot determine real values noise MUST NOT
2079 * report any, especially not a magically conjured ones :-)
2081 survey
->filled
= SURVEY_INFO_NOISE_DBM
|
2083 SURVEY_INFO_TIME_BUSY
;
2084 survey
->noise
= -92;
2086 jiffies_to_msecs(hwsim
->survey_data
[idx
].end
-
2087 hwsim
->survey_data
[idx
].start
);
2088 /* report 12.5% of channel time is used */
2089 survey
->time_busy
= survey
->time
/8;
2090 mutex_unlock(&hwsim
->mutex
);
2095 #ifdef CONFIG_NL80211_TESTMODE
2097 * This section contains example code for using netlink
2098 * attributes with the testmode command in nl80211.
2101 /* These enums need to be kept in sync with userspace */
2102 enum hwsim_testmode_attr
{
2103 __HWSIM_TM_ATTR_INVALID
= 0,
2104 HWSIM_TM_ATTR_CMD
= 1,
2105 HWSIM_TM_ATTR_PS
= 2,
2108 __HWSIM_TM_ATTR_AFTER_LAST
,
2109 HWSIM_TM_ATTR_MAX
= __HWSIM_TM_ATTR_AFTER_LAST
- 1
2112 enum hwsim_testmode_cmd
{
2113 HWSIM_TM_CMD_SET_PS
= 0,
2114 HWSIM_TM_CMD_GET_PS
= 1,
2115 HWSIM_TM_CMD_STOP_QUEUES
= 2,
2116 HWSIM_TM_CMD_WAKE_QUEUES
= 3,
2119 static const struct nla_policy hwsim_testmode_policy
[HWSIM_TM_ATTR_MAX
+ 1] = {
2120 [HWSIM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
2121 [HWSIM_TM_ATTR_PS
] = { .type
= NLA_U32
},
2124 static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw
*hw
,
2125 struct ieee80211_vif
*vif
,
2126 void *data
, int len
)
2128 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2129 struct nlattr
*tb
[HWSIM_TM_ATTR_MAX
+ 1];
2130 struct sk_buff
*skb
;
2133 err
= nla_parse_deprecated(tb
, HWSIM_TM_ATTR_MAX
, data
, len
,
2134 hwsim_testmode_policy
, NULL
);
2138 if (!tb
[HWSIM_TM_ATTR_CMD
])
2141 switch (nla_get_u32(tb
[HWSIM_TM_ATTR_CMD
])) {
2142 case HWSIM_TM_CMD_SET_PS
:
2143 if (!tb
[HWSIM_TM_ATTR_PS
])
2145 ps
= nla_get_u32(tb
[HWSIM_TM_ATTR_PS
]);
2146 return hwsim_fops_ps_write(hwsim
, ps
);
2147 case HWSIM_TM_CMD_GET_PS
:
2148 skb
= cfg80211_testmode_alloc_reply_skb(hw
->wiphy
,
2149 nla_total_size(sizeof(u32
)));
2152 if (nla_put_u32(skb
, HWSIM_TM_ATTR_PS
, hwsim
->ps
))
2153 goto nla_put_failure
;
2154 return cfg80211_testmode_reply(skb
);
2155 case HWSIM_TM_CMD_STOP_QUEUES
:
2156 ieee80211_stop_queues(hw
);
2158 case HWSIM_TM_CMD_WAKE_QUEUES
:
2159 ieee80211_wake_queues(hw
);
2171 static int mac80211_hwsim_ampdu_action(struct ieee80211_hw
*hw
,
2172 struct ieee80211_vif
*vif
,
2173 struct ieee80211_ampdu_params
*params
)
2175 struct ieee80211_sta
*sta
= params
->sta
;
2176 enum ieee80211_ampdu_mlme_action action
= params
->action
;
2177 u16 tid
= params
->tid
;
2180 case IEEE80211_AMPDU_TX_START
:
2181 return IEEE80211_AMPDU_TX_START_IMMEDIATE
;
2182 case IEEE80211_AMPDU_TX_STOP_CONT
:
2183 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
2184 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
2185 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
2187 case IEEE80211_AMPDU_TX_OPERATIONAL
:
2189 case IEEE80211_AMPDU_RX_START
:
2190 case IEEE80211_AMPDU_RX_STOP
:
2199 static void mac80211_hwsim_flush(struct ieee80211_hw
*hw
,
2200 struct ieee80211_vif
*vif
,
2201 u32 queues
, bool drop
)
2203 /* Not implemented, queues only on kernel side */
2206 static void hw_scan_work(struct work_struct
*work
)
2208 struct mac80211_hwsim_data
*hwsim
=
2209 container_of(work
, struct mac80211_hwsim_data
, hw_scan
.work
);
2210 struct cfg80211_scan_request
*req
= hwsim
->hw_scan_request
;
2213 mutex_lock(&hwsim
->mutex
);
2214 if (hwsim
->scan_chan_idx
>= req
->n_channels
) {
2215 struct cfg80211_scan_info info
= {
2219 wiphy_dbg(hwsim
->hw
->wiphy
, "hw scan complete\n");
2220 ieee80211_scan_completed(hwsim
->hw
, &info
);
2221 hwsim
->hw_scan_request
= NULL
;
2222 hwsim
->hw_scan_vif
= NULL
;
2223 hwsim
->tmp_chan
= NULL
;
2224 mutex_unlock(&hwsim
->mutex
);
2225 mac80211_hwsim_config_mac_nl(hwsim
->hw
, hwsim
->scan_addr
,
2230 wiphy_dbg(hwsim
->hw
->wiphy
, "hw scan %d MHz\n",
2231 req
->channels
[hwsim
->scan_chan_idx
]->center_freq
);
2233 hwsim
->tmp_chan
= req
->channels
[hwsim
->scan_chan_idx
];
2234 if (hwsim
->tmp_chan
->flags
& (IEEE80211_CHAN_NO_IR
|
2235 IEEE80211_CHAN_RADAR
) ||
2241 for (i
= 0; i
< req
->n_ssids
; i
++) {
2242 struct sk_buff
*probe
;
2243 struct ieee80211_mgmt
*mgmt
;
2245 probe
= ieee80211_probereq_get(hwsim
->hw
,
2248 req
->ssids
[i
].ssid_len
,
2253 mgmt
= (struct ieee80211_mgmt
*) probe
->data
;
2254 memcpy(mgmt
->da
, req
->bssid
, ETH_ALEN
);
2255 memcpy(mgmt
->bssid
, req
->bssid
, ETH_ALEN
);
2258 skb_put_data(probe
, req
->ie
, req
->ie_len
);
2261 mac80211_hwsim_tx_frame(hwsim
->hw
, probe
,
2266 ieee80211_queue_delayed_work(hwsim
->hw
, &hwsim
->hw_scan
,
2267 msecs_to_jiffies(dwell
));
2268 hwsim
->survey_data
[hwsim
->scan_chan_idx
].channel
= hwsim
->tmp_chan
;
2269 hwsim
->survey_data
[hwsim
->scan_chan_idx
].start
= jiffies
;
2270 hwsim
->survey_data
[hwsim
->scan_chan_idx
].end
=
2271 jiffies
+ msecs_to_jiffies(dwell
);
2272 hwsim
->scan_chan_idx
++;
2273 mutex_unlock(&hwsim
->mutex
);
2276 static int mac80211_hwsim_hw_scan(struct ieee80211_hw
*hw
,
2277 struct ieee80211_vif
*vif
,
2278 struct ieee80211_scan_request
*hw_req
)
2280 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2281 struct cfg80211_scan_request
*req
= &hw_req
->req
;
2283 mutex_lock(&hwsim
->mutex
);
2284 if (WARN_ON(hwsim
->tmp_chan
|| hwsim
->hw_scan_request
)) {
2285 mutex_unlock(&hwsim
->mutex
);
2288 hwsim
->hw_scan_request
= req
;
2289 hwsim
->hw_scan_vif
= vif
;
2290 hwsim
->scan_chan_idx
= 0;
2291 if (req
->flags
& NL80211_SCAN_FLAG_RANDOM_ADDR
)
2292 get_random_mask_addr(hwsim
->scan_addr
,
2293 hw_req
->req
.mac_addr
,
2294 hw_req
->req
.mac_addr_mask
);
2296 memcpy(hwsim
->scan_addr
, vif
->addr
, ETH_ALEN
);
2297 memset(hwsim
->survey_data
, 0, sizeof(hwsim
->survey_data
));
2298 mutex_unlock(&hwsim
->mutex
);
2300 mac80211_hwsim_config_mac_nl(hw
, hwsim
->scan_addr
, true);
2301 wiphy_dbg(hw
->wiphy
, "hwsim hw_scan request\n");
2303 ieee80211_queue_delayed_work(hwsim
->hw
, &hwsim
->hw_scan
, 0);
2308 static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw
*hw
,
2309 struct ieee80211_vif
*vif
)
2311 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2312 struct cfg80211_scan_info info
= {
2316 wiphy_dbg(hw
->wiphy
, "hwsim cancel_hw_scan\n");
2318 cancel_delayed_work_sync(&hwsim
->hw_scan
);
2320 mutex_lock(&hwsim
->mutex
);
2321 ieee80211_scan_completed(hwsim
->hw
, &info
);
2322 hwsim
->tmp_chan
= NULL
;
2323 hwsim
->hw_scan_request
= NULL
;
2324 hwsim
->hw_scan_vif
= NULL
;
2325 mutex_unlock(&hwsim
->mutex
);
2328 static void mac80211_hwsim_sw_scan(struct ieee80211_hw
*hw
,
2329 struct ieee80211_vif
*vif
,
2332 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2334 mutex_lock(&hwsim
->mutex
);
2336 if (hwsim
->scanning
) {
2337 pr_debug("two hwsim sw_scans detected!\n");
2341 pr_debug("hwsim sw_scan request, prepping stuff\n");
2343 memcpy(hwsim
->scan_addr
, mac_addr
, ETH_ALEN
);
2344 mac80211_hwsim_config_mac_nl(hw
, hwsim
->scan_addr
, true);
2345 hwsim
->scanning
= true;
2346 memset(hwsim
->survey_data
, 0, sizeof(hwsim
->survey_data
));
2349 mutex_unlock(&hwsim
->mutex
);
2352 static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw
*hw
,
2353 struct ieee80211_vif
*vif
)
2355 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2357 mutex_lock(&hwsim
->mutex
);
2359 pr_debug("hwsim sw_scan_complete\n");
2360 hwsim
->scanning
= false;
2361 mac80211_hwsim_config_mac_nl(hw
, hwsim
->scan_addr
, false);
2362 eth_zero_addr(hwsim
->scan_addr
);
2364 mutex_unlock(&hwsim
->mutex
);
2367 static void hw_roc_start(struct work_struct
*work
)
2369 struct mac80211_hwsim_data
*hwsim
=
2370 container_of(work
, struct mac80211_hwsim_data
, roc_start
.work
);
2372 mutex_lock(&hwsim
->mutex
);
2374 wiphy_dbg(hwsim
->hw
->wiphy
, "hwsim ROC begins\n");
2375 hwsim
->tmp_chan
= hwsim
->roc_chan
;
2376 ieee80211_ready_on_channel(hwsim
->hw
);
2378 ieee80211_queue_delayed_work(hwsim
->hw
, &hwsim
->roc_done
,
2379 msecs_to_jiffies(hwsim
->roc_duration
));
2381 mutex_unlock(&hwsim
->mutex
);
2384 static void hw_roc_done(struct work_struct
*work
)
2386 struct mac80211_hwsim_data
*hwsim
=
2387 container_of(work
, struct mac80211_hwsim_data
, roc_done
.work
);
2389 mutex_lock(&hwsim
->mutex
);
2390 ieee80211_remain_on_channel_expired(hwsim
->hw
);
2391 hwsim
->tmp_chan
= NULL
;
2392 mutex_unlock(&hwsim
->mutex
);
2394 wiphy_dbg(hwsim
->hw
->wiphy
, "hwsim ROC expired\n");
2397 static int mac80211_hwsim_roc(struct ieee80211_hw
*hw
,
2398 struct ieee80211_vif
*vif
,
2399 struct ieee80211_channel
*chan
,
2401 enum ieee80211_roc_type type
)
2403 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2405 mutex_lock(&hwsim
->mutex
);
2406 if (WARN_ON(hwsim
->tmp_chan
|| hwsim
->hw_scan_request
)) {
2407 mutex_unlock(&hwsim
->mutex
);
2411 hwsim
->roc_chan
= chan
;
2412 hwsim
->roc_duration
= duration
;
2413 mutex_unlock(&hwsim
->mutex
);
2415 wiphy_dbg(hw
->wiphy
, "hwsim ROC (%d MHz, %d ms)\n",
2416 chan
->center_freq
, duration
);
2417 ieee80211_queue_delayed_work(hw
, &hwsim
->roc_start
, HZ
/50);
2422 static int mac80211_hwsim_croc(struct ieee80211_hw
*hw
,
2423 struct ieee80211_vif
*vif
)
2425 struct mac80211_hwsim_data
*hwsim
= hw
->priv
;
2427 cancel_delayed_work_sync(&hwsim
->roc_start
);
2428 cancel_delayed_work_sync(&hwsim
->roc_done
);
2430 mutex_lock(&hwsim
->mutex
);
2431 hwsim
->tmp_chan
= NULL
;
2432 mutex_unlock(&hwsim
->mutex
);
2434 wiphy_dbg(hw
->wiphy
, "hwsim ROC canceled\n");
2439 static int mac80211_hwsim_add_chanctx(struct ieee80211_hw
*hw
,
2440 struct ieee80211_chanctx_conf
*ctx
)
2442 hwsim_set_chanctx_magic(ctx
);
2443 wiphy_dbg(hw
->wiphy
,
2444 "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2445 ctx
->def
.chan
->center_freq
, ctx
->def
.width
,
2446 ctx
->def
.center_freq1
, ctx
->def
.center_freq2
);
2450 static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw
*hw
,
2451 struct ieee80211_chanctx_conf
*ctx
)
2453 wiphy_dbg(hw
->wiphy
,
2454 "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2455 ctx
->def
.chan
->center_freq
, ctx
->def
.width
,
2456 ctx
->def
.center_freq1
, ctx
->def
.center_freq2
);
2457 hwsim_check_chanctx_magic(ctx
);
2458 hwsim_clear_chanctx_magic(ctx
);
2461 static void mac80211_hwsim_change_chanctx(struct ieee80211_hw
*hw
,
2462 struct ieee80211_chanctx_conf
*ctx
,
2465 hwsim_check_chanctx_magic(ctx
);
2466 wiphy_dbg(hw
->wiphy
,
2467 "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2468 ctx
->def
.chan
->center_freq
, ctx
->def
.width
,
2469 ctx
->def
.center_freq1
, ctx
->def
.center_freq2
);
2472 static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2473 struct ieee80211_vif
*vif
,
2474 struct ieee80211_chanctx_conf
*ctx
)
2476 hwsim_check_magic(vif
);
2477 hwsim_check_chanctx_magic(ctx
);
2482 static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2483 struct ieee80211_vif
*vif
,
2484 struct ieee80211_chanctx_conf
*ctx
)
2486 hwsim_check_magic(vif
);
2487 hwsim_check_chanctx_magic(ctx
);
2490 static const char mac80211_hwsim_gstrings_stats
[][ETH_GSTRING_LEN
] = {
2501 #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats)
2503 static void mac80211_hwsim_get_et_strings(struct ieee80211_hw
*hw
,
2504 struct ieee80211_vif
*vif
,
2507 if (sset
== ETH_SS_STATS
)
2508 memcpy(data
, *mac80211_hwsim_gstrings_stats
,
2509 sizeof(mac80211_hwsim_gstrings_stats
));
2512 static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw
*hw
,
2513 struct ieee80211_vif
*vif
, int sset
)
2515 if (sset
== ETH_SS_STATS
)
2516 return MAC80211_HWSIM_SSTATS_LEN
;
2520 static void mac80211_hwsim_get_et_stats(struct ieee80211_hw
*hw
,
2521 struct ieee80211_vif
*vif
,
2522 struct ethtool_stats
*stats
, u64
*data
)
2524 struct mac80211_hwsim_data
*ar
= hw
->priv
;
2527 data
[i
++] = ar
->tx_pkts
;
2528 data
[i
++] = ar
->tx_bytes
;
2529 data
[i
++] = ar
->rx_pkts
;
2530 data
[i
++] = ar
->rx_bytes
;
2531 data
[i
++] = ar
->tx_dropped
;
2532 data
[i
++] = ar
->tx_failed
;
2534 data
[i
++] = ar
->group
;
2536 WARN_ON(i
!= MAC80211_HWSIM_SSTATS_LEN
);
2539 static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw
*hw
)
2544 #define HWSIM_COMMON_OPS \
2545 .tx = mac80211_hwsim_tx, \
2546 .start = mac80211_hwsim_start, \
2547 .stop = mac80211_hwsim_stop, \
2548 .add_interface = mac80211_hwsim_add_interface, \
2549 .change_interface = mac80211_hwsim_change_interface, \
2550 .remove_interface = mac80211_hwsim_remove_interface, \
2551 .config = mac80211_hwsim_config, \
2552 .configure_filter = mac80211_hwsim_configure_filter, \
2553 .bss_info_changed = mac80211_hwsim_bss_info_changed, \
2554 .tx_last_beacon = mac80211_hwsim_tx_last_beacon, \
2555 .sta_add = mac80211_hwsim_sta_add, \
2556 .sta_remove = mac80211_hwsim_sta_remove, \
2557 .sta_notify = mac80211_hwsim_sta_notify, \
2558 .set_tim = mac80211_hwsim_set_tim, \
2559 .conf_tx = mac80211_hwsim_conf_tx, \
2560 .get_survey = mac80211_hwsim_get_survey, \
2561 CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \
2562 .ampdu_action = mac80211_hwsim_ampdu_action, \
2563 .flush = mac80211_hwsim_flush, \
2564 .get_tsf = mac80211_hwsim_get_tsf, \
2565 .set_tsf = mac80211_hwsim_set_tsf, \
2566 .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \
2567 .get_et_stats = mac80211_hwsim_get_et_stats, \
2568 .get_et_strings = mac80211_hwsim_get_et_strings,
2570 static const struct ieee80211_ops mac80211_hwsim_ops
= {
2572 .sw_scan_start
= mac80211_hwsim_sw_scan
,
2573 .sw_scan_complete
= mac80211_hwsim_sw_scan_complete
,
2576 static const struct ieee80211_ops mac80211_hwsim_mchan_ops
= {
2578 .hw_scan
= mac80211_hwsim_hw_scan
,
2579 .cancel_hw_scan
= mac80211_hwsim_cancel_hw_scan
,
2580 .sw_scan_start
= NULL
,
2581 .sw_scan_complete
= NULL
,
2582 .remain_on_channel
= mac80211_hwsim_roc
,
2583 .cancel_remain_on_channel
= mac80211_hwsim_croc
,
2584 .add_chanctx
= mac80211_hwsim_add_chanctx
,
2585 .remove_chanctx
= mac80211_hwsim_remove_chanctx
,
2586 .change_chanctx
= mac80211_hwsim_change_chanctx
,
2587 .assign_vif_chanctx
= mac80211_hwsim_assign_vif_chanctx
,
2588 .unassign_vif_chanctx
= mac80211_hwsim_unassign_vif_chanctx
,
2591 struct hwsim_new_radio_params
{
2592 unsigned int channels
;
2593 const char *reg_alpha2
;
2594 const struct ieee80211_regdomain
*regd
;
2598 bool destroy_on_close
;
2601 const u8
*perm_addr
;
2607 static void hwsim_mcast_config_msg(struct sk_buff
*mcast_skb
,
2608 struct genl_info
*info
)
2611 genl_notify(&hwsim_genl_family
, mcast_skb
, info
,
2612 HWSIM_MCGRP_CONFIG
, GFP_KERNEL
);
2614 genlmsg_multicast(&hwsim_genl_family
, mcast_skb
, 0,
2615 HWSIM_MCGRP_CONFIG
, GFP_KERNEL
);
2618 static int append_radio_msg(struct sk_buff
*skb
, int id
,
2619 struct hwsim_new_radio_params
*param
)
2623 ret
= nla_put_u32(skb
, HWSIM_ATTR_RADIO_ID
, id
);
2627 if (param
->channels
) {
2628 ret
= nla_put_u32(skb
, HWSIM_ATTR_CHANNELS
, param
->channels
);
2633 if (param
->reg_alpha2
) {
2634 ret
= nla_put(skb
, HWSIM_ATTR_REG_HINT_ALPHA2
, 2,
2643 for (i
= 0; i
< ARRAY_SIZE(hwsim_world_regdom_custom
); i
++) {
2644 if (hwsim_world_regdom_custom
[i
] != param
->regd
)
2647 ret
= nla_put_u32(skb
, HWSIM_ATTR_REG_CUSTOM_REG
, i
);
2654 if (param
->reg_strict
) {
2655 ret
= nla_put_flag(skb
, HWSIM_ATTR_REG_STRICT_REG
);
2660 if (param
->p2p_device
) {
2661 ret
= nla_put_flag(skb
, HWSIM_ATTR_SUPPORT_P2P_DEVICE
);
2666 if (param
->use_chanctx
) {
2667 ret
= nla_put_flag(skb
, HWSIM_ATTR_USE_CHANCTX
);
2672 if (param
->hwname
) {
2673 ret
= nla_put(skb
, HWSIM_ATTR_RADIO_NAME
,
2674 strlen(param
->hwname
), param
->hwname
);
2682 static void hwsim_mcast_new_radio(int id
, struct genl_info
*info
,
2683 struct hwsim_new_radio_params
*param
)
2685 struct sk_buff
*mcast_skb
;
2688 mcast_skb
= genlmsg_new(GENLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2692 data
= genlmsg_put(mcast_skb
, 0, 0, &hwsim_genl_family
, 0,
2693 HWSIM_CMD_NEW_RADIO
);
2697 if (append_radio_msg(mcast_skb
, id
, param
) < 0)
2700 genlmsg_end(mcast_skb
, data
);
2702 hwsim_mcast_config_msg(mcast_skb
, info
);
2706 nlmsg_free(mcast_skb
);
2709 static const struct ieee80211_sband_iftype_data he_capa_2ghz
[] = {
2711 /* TODO: should we support other types, e.g., P2P?*/
2712 .types_mask
= BIT(NL80211_IFTYPE_STATION
) |
2713 BIT(NL80211_IFTYPE_AP
),
2718 IEEE80211_HE_MAC_CAP0_HTC_HE
,
2720 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US
|
2721 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8
,
2723 IEEE80211_HE_MAC_CAP2_BSR
|
2724 IEEE80211_HE_MAC_CAP2_MU_CASCADING
|
2725 IEEE80211_HE_MAC_CAP2_ACK_EN
,
2727 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
|
2728 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2
,
2729 .mac_cap_info
[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU
,
2731 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK
|
2732 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A
|
2733 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
|
2734 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS
,
2736 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US
|
2737 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ
|
2738 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ
|
2739 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO
|
2740 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO
,
2742 /* Leave all the other PHY capability bytes
2743 * unset, as DCM, beam forming, RU and PPE
2744 * threshold information are not supported
2747 .he_mcs_nss_supp
= {
2748 .rx_mcs_80
= cpu_to_le16(0xfffa),
2749 .tx_mcs_80
= cpu_to_le16(0xfffa),
2750 .rx_mcs_160
= cpu_to_le16(0xffff),
2751 .tx_mcs_160
= cpu_to_le16(0xffff),
2752 .rx_mcs_80p80
= cpu_to_le16(0xffff),
2753 .tx_mcs_80p80
= cpu_to_le16(0xffff),
2757 #ifdef CONFIG_MAC80211_MESH
2759 /* TODO: should we support other types, e.g., IBSS?*/
2760 .types_mask
= BIT(NL80211_IFTYPE_MESH_POINT
),
2765 IEEE80211_HE_MAC_CAP0_HTC_HE
,
2767 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8
,
2769 IEEE80211_HE_MAC_CAP2_ACK_EN
,
2771 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
|
2772 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2
,
2773 .mac_cap_info
[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU
,
2775 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK
|
2776 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A
|
2777 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
|
2778 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS
,
2779 .phy_cap_info
[2] = 0,
2781 /* Leave all the other PHY capability bytes
2782 * unset, as DCM, beam forming, RU and PPE
2783 * threshold information are not supported
2786 .he_mcs_nss_supp
= {
2787 .rx_mcs_80
= cpu_to_le16(0xfffa),
2788 .tx_mcs_80
= cpu_to_le16(0xfffa),
2789 .rx_mcs_160
= cpu_to_le16(0xffff),
2790 .tx_mcs_160
= cpu_to_le16(0xffff),
2791 .rx_mcs_80p80
= cpu_to_le16(0xffff),
2792 .tx_mcs_80p80
= cpu_to_le16(0xffff),
2799 static const struct ieee80211_sband_iftype_data he_capa_5ghz
[] = {
2801 /* TODO: should we support other types, e.g., P2P?*/
2802 .types_mask
= BIT(NL80211_IFTYPE_STATION
) |
2803 BIT(NL80211_IFTYPE_AP
),
2808 IEEE80211_HE_MAC_CAP0_HTC_HE
,
2810 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US
|
2811 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8
,
2813 IEEE80211_HE_MAC_CAP2_BSR
|
2814 IEEE80211_HE_MAC_CAP2_MU_CASCADING
|
2815 IEEE80211_HE_MAC_CAP2_ACK_EN
,
2817 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
|
2818 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2
,
2819 .mac_cap_info
[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU
,
2821 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G
|
2822 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G
|
2823 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G
,
2825 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK
|
2826 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A
|
2827 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
|
2828 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS
,
2830 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US
|
2831 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ
|
2832 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ
|
2833 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO
|
2834 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO
,
2836 /* Leave all the other PHY capability bytes
2837 * unset, as DCM, beam forming, RU and PPE
2838 * threshold information are not supported
2841 .he_mcs_nss_supp
= {
2842 .rx_mcs_80
= cpu_to_le16(0xfffa),
2843 .tx_mcs_80
= cpu_to_le16(0xfffa),
2844 .rx_mcs_160
= cpu_to_le16(0xfffa),
2845 .tx_mcs_160
= cpu_to_le16(0xfffa),
2846 .rx_mcs_80p80
= cpu_to_le16(0xfffa),
2847 .tx_mcs_80p80
= cpu_to_le16(0xfffa),
2851 #ifdef CONFIG_MAC80211_MESH
2853 /* TODO: should we support other types, e.g., IBSS?*/
2854 .types_mask
= BIT(NL80211_IFTYPE_MESH_POINT
),
2859 IEEE80211_HE_MAC_CAP0_HTC_HE
,
2861 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8
,
2863 IEEE80211_HE_MAC_CAP2_ACK_EN
,
2865 IEEE80211_HE_MAC_CAP3_OMI_CONTROL
|
2866 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2
,
2867 .mac_cap_info
[4] = IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU
,
2869 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G
|
2870 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G
|
2871 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G
,
2873 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK
|
2874 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A
|
2875 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD
|
2876 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS
,
2877 .phy_cap_info
[2] = 0,
2879 /* Leave all the other PHY capability bytes
2880 * unset, as DCM, beam forming, RU and PPE
2881 * threshold information are not supported
2884 .he_mcs_nss_supp
= {
2885 .rx_mcs_80
= cpu_to_le16(0xfffa),
2886 .tx_mcs_80
= cpu_to_le16(0xfffa),
2887 .rx_mcs_160
= cpu_to_le16(0xfffa),
2888 .tx_mcs_160
= cpu_to_le16(0xfffa),
2889 .rx_mcs_80p80
= cpu_to_le16(0xfffa),
2890 .tx_mcs_80p80
= cpu_to_le16(0xfffa),
2897 static void mac80211_hwsim_he_capab(struct ieee80211_supported_band
*sband
)
2901 if (sband
->band
== NL80211_BAND_2GHZ
) {
2902 n_iftype_data
= ARRAY_SIZE(he_capa_2ghz
);
2903 sband
->iftype_data
=
2904 (struct ieee80211_sband_iftype_data
*)he_capa_2ghz
;
2905 } else if (sband
->band
== NL80211_BAND_5GHZ
) {
2906 n_iftype_data
= ARRAY_SIZE(he_capa_5ghz
);
2907 sband
->iftype_data
=
2908 (struct ieee80211_sband_iftype_data
*)he_capa_5ghz
;
2913 sband
->n_iftype_data
= n_iftype_data
;
2916 #ifdef CONFIG_MAC80211_MESH
2917 #define HWSIM_MESH_BIT BIT(NL80211_IFTYPE_MESH_POINT)
2919 #define HWSIM_MESH_BIT 0
2922 #define HWSIM_DEFAULT_IF_LIMIT \
2923 (BIT(NL80211_IFTYPE_STATION) | \
2924 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
2925 BIT(NL80211_IFTYPE_AP) | \
2926 BIT(NL80211_IFTYPE_P2P_GO) | \
2929 #define HWSIM_IFTYPE_SUPPORT_MASK \
2930 (BIT(NL80211_IFTYPE_STATION) | \
2931 BIT(NL80211_IFTYPE_AP) | \
2932 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
2933 BIT(NL80211_IFTYPE_P2P_GO) | \
2934 BIT(NL80211_IFTYPE_ADHOC) | \
2935 BIT(NL80211_IFTYPE_MESH_POINT) | \
2936 BIT(NL80211_IFTYPE_OCB))
2938 static int mac80211_hwsim_new_radio(struct genl_info
*info
,
2939 struct hwsim_new_radio_params
*param
)
2943 struct mac80211_hwsim_data
*data
;
2944 struct ieee80211_hw
*hw
;
2945 enum nl80211_band band
;
2946 const struct ieee80211_ops
*ops
= &mac80211_hwsim_ops
;
2951 if (WARN_ON(param
->channels
> 1 && !param
->use_chanctx
))
2954 spin_lock_bh(&hwsim_radio_lock
);
2955 idx
= hwsim_radio_idx
++;
2956 spin_unlock_bh(&hwsim_radio_lock
);
2958 if (param
->use_chanctx
)
2959 ops
= &mac80211_hwsim_mchan_ops
;
2960 hw
= ieee80211_alloc_hw_nm(sizeof(*data
), ops
, param
->hwname
);
2962 pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n");
2967 /* ieee80211_alloc_hw_nm may have used a default name */
2968 param
->hwname
= wiphy_name(hw
->wiphy
);
2971 net
= genl_info_net(info
);
2974 wiphy_net_set(hw
->wiphy
, net
);
2979 data
->dev
= device_create(hwsim_class
, NULL
, 0, hw
, "hwsim%d", idx
);
2980 if (IS_ERR(data
->dev
)) {
2982 "mac80211_hwsim: device_create failed (%ld)\n",
2983 PTR_ERR(data
->dev
));
2985 goto failed_drvdata
;
2987 data
->dev
->driver
= &mac80211_hwsim_driver
.driver
;
2988 err
= device_bind_driver(data
->dev
);
2990 pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n",
2995 skb_queue_head_init(&data
->pending
);
2997 SET_IEEE80211_DEV(hw
, data
->dev
);
2998 if (!param
->perm_addr
) {
2999 eth_zero_addr(addr
);
3003 memcpy(data
->addresses
[0].addr
, addr
, ETH_ALEN
);
3004 /* Why need here second address ? */
3005 memcpy(data
->addresses
[1].addr
, addr
, ETH_ALEN
);
3006 data
->addresses
[1].addr
[0] |= 0x40;
3007 hw
->wiphy
->n_addresses
= 2;
3008 hw
->wiphy
->addresses
= data
->addresses
;
3009 /* possible address clash is checked at hash table insertion */
3011 memcpy(data
->addresses
[0].addr
, param
->perm_addr
, ETH_ALEN
);
3012 /* compatibility with automatically generated mac addr */
3013 memcpy(data
->addresses
[1].addr
, param
->perm_addr
, ETH_ALEN
);
3014 hw
->wiphy
->n_addresses
= 2;
3015 hw
->wiphy
->addresses
= data
->addresses
;
3018 data
->channels
= param
->channels
;
3019 data
->use_chanctx
= param
->use_chanctx
;
3021 data
->destroy_on_close
= param
->destroy_on_close
;
3023 data
->portid
= info
->snd_portid
;
3025 /* setup interface limits, only on interface types we support */
3026 if (param
->iftypes
& BIT(NL80211_IFTYPE_ADHOC
)) {
3027 data
->if_limits
[n_limits
].max
= 1;
3028 data
->if_limits
[n_limits
].types
= BIT(NL80211_IFTYPE_ADHOC
);
3032 if (param
->iftypes
& HWSIM_DEFAULT_IF_LIMIT
) {
3033 data
->if_limits
[n_limits
].max
= 2048;
3035 * For this case, we may only support a subset of
3036 * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the
3037 * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have.
3039 data
->if_limits
[n_limits
].types
=
3040 HWSIM_DEFAULT_IF_LIMIT
& param
->iftypes
;
3044 if (param
->iftypes
& BIT(NL80211_IFTYPE_P2P_DEVICE
)) {
3045 data
->if_limits
[n_limits
].max
= 1;
3046 data
->if_limits
[n_limits
].types
=
3047 BIT(NL80211_IFTYPE_P2P_DEVICE
);
3051 if (data
->use_chanctx
) {
3052 hw
->wiphy
->max_scan_ssids
= 255;
3053 hw
->wiphy
->max_scan_ie_len
= IEEE80211_MAX_DATA_LEN
;
3054 hw
->wiphy
->max_remain_on_channel_duration
= 1000;
3055 data
->if_combination
.radar_detect_widths
= 0;
3056 data
->if_combination
.num_different_channels
= data
->channels
;
3058 data
->if_combination
.num_different_channels
= 1;
3059 data
->if_combination
.radar_detect_widths
=
3060 BIT(NL80211_CHAN_WIDTH_5
) |
3061 BIT(NL80211_CHAN_WIDTH_10
) |
3062 BIT(NL80211_CHAN_WIDTH_20_NOHT
) |
3063 BIT(NL80211_CHAN_WIDTH_20
) |
3064 BIT(NL80211_CHAN_WIDTH_40
) |
3065 BIT(NL80211_CHAN_WIDTH_80
) |
3066 BIT(NL80211_CHAN_WIDTH_160
);
3074 data
->if_combination
.max_interfaces
= 0;
3075 for (i
= 0; i
< n_limits
; i
++)
3076 data
->if_combination
.max_interfaces
+=
3077 data
->if_limits
[i
].max
;
3079 data
->if_combination
.n_limits
= n_limits
;
3080 data
->if_combination
.limits
= data
->if_limits
;
3083 * If we actually were asked to support combinations,
3084 * advertise them - if there's only a single thing like
3085 * only IBSS then don't advertise it as combinations.
3087 if (data
->if_combination
.max_interfaces
> 1) {
3088 hw
->wiphy
->iface_combinations
= &data
->if_combination
;
3089 hw
->wiphy
->n_iface_combinations
= 1;
3092 if (param
->ciphers
) {
3093 memcpy(data
->ciphers
, param
->ciphers
,
3094 param
->n_ciphers
* sizeof(u32
));
3095 hw
->wiphy
->cipher_suites
= data
->ciphers
;
3096 hw
->wiphy
->n_cipher_suites
= param
->n_ciphers
;
3099 INIT_DELAYED_WORK(&data
->roc_start
, hw_roc_start
);
3100 INIT_DELAYED_WORK(&data
->roc_done
, hw_roc_done
);
3101 INIT_DELAYED_WORK(&data
->hw_scan
, hw_scan_work
);
3104 hw
->offchannel_tx_hw_queue
= 4;
3106 ieee80211_hw_set(hw
, SUPPORT_FAST_XMIT
);
3107 ieee80211_hw_set(hw
, CHANCTX_STA_CSA
);
3108 ieee80211_hw_set(hw
, SUPPORTS_HT_CCK_RATES
);
3109 ieee80211_hw_set(hw
, QUEUE_CONTROL
);
3110 ieee80211_hw_set(hw
, WANT_MONITOR_VIF
);
3111 ieee80211_hw_set(hw
, AMPDU_AGGREGATION
);
3112 ieee80211_hw_set(hw
, MFP_CAPABLE
);
3113 ieee80211_hw_set(hw
, SIGNAL_DBM
);
3114 ieee80211_hw_set(hw
, SUPPORTS_PS
);
3115 ieee80211_hw_set(hw
, REPORTS_TX_ACK_STATUS
);
3116 ieee80211_hw_set(hw
, HOST_BROADCAST_PS_BUFFERING
);
3117 ieee80211_hw_set(hw
, PS_NULLFUNC_STACK
);
3118 ieee80211_hw_set(hw
, TDLS_WIDER_BW
);
3120 ieee80211_hw_set(hw
, SUPPORTS_RC_TABLE
);
3121 ieee80211_hw_set(hw
, SUPPORTS_MULTI_BSSID
);
3123 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
3124 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_TDLS
|
3125 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
|
3126 WIPHY_FLAG_AP_UAPSD
|
3127 WIPHY_FLAG_SUPPORTS_5_10_MHZ
|
3128 WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
3129 hw
->wiphy
->features
|= NL80211_FEATURE_ACTIVE_MONITOR
|
3130 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE
|
3131 NL80211_FEATURE_STATIC_SMPS
|
3132 NL80211_FEATURE_DYNAMIC_SMPS
|
3133 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR
;
3134 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_VHT_IBSS
);
3135 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_BEACON_PROTECTION
);
3136 wiphy_ext_feature_set(hw
->wiphy
,
3137 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS
);
3138 wiphy_ext_feature_set(hw
->wiphy
,
3139 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY
);
3141 hw
->wiphy
->interface_modes
= param
->iftypes
;
3143 /* ask mac80211 to reserve space for magic */
3144 hw
->vif_data_size
= sizeof(struct hwsim_vif_priv
);
3145 hw
->sta_data_size
= sizeof(struct hwsim_sta_priv
);
3146 hw
->chanctx_data_size
= sizeof(struct hwsim_chanctx_priv
);
3148 memcpy(data
->channels_2ghz
, hwsim_channels_2ghz
,
3149 sizeof(hwsim_channels_2ghz
));
3150 memcpy(data
->channels_5ghz
, hwsim_channels_5ghz
,
3151 sizeof(hwsim_channels_5ghz
));
3152 memcpy(data
->channels_s1g
, hwsim_channels_s1g
,
3153 sizeof(hwsim_channels_s1g
));
3154 memcpy(data
->rates
, hwsim_rates
, sizeof(hwsim_rates
));
3156 for (band
= NL80211_BAND_2GHZ
; band
< NUM_NL80211_BANDS
; band
++) {
3157 struct ieee80211_supported_band
*sband
= &data
->bands
[band
];
3162 case NL80211_BAND_2GHZ
:
3163 sband
->channels
= data
->channels_2ghz
;
3164 sband
->n_channels
= ARRAY_SIZE(hwsim_channels_2ghz
);
3165 sband
->bitrates
= data
->rates
;
3166 sband
->n_bitrates
= ARRAY_SIZE(hwsim_rates
);
3168 case NL80211_BAND_5GHZ
:
3169 sband
->channels
= data
->channels_5ghz
;
3170 sband
->n_channels
= ARRAY_SIZE(hwsim_channels_5ghz
);
3171 sband
->bitrates
= data
->rates
+ 4;
3172 sband
->n_bitrates
= ARRAY_SIZE(hwsim_rates
) - 4;
3174 sband
->vht_cap
.vht_supported
= true;
3175 sband
->vht_cap
.cap
=
3176 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454
|
3177 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ
|
3178 IEEE80211_VHT_CAP_RXLDPC
|
3179 IEEE80211_VHT_CAP_SHORT_GI_80
|
3180 IEEE80211_VHT_CAP_SHORT_GI_160
|
3181 IEEE80211_VHT_CAP_TXSTBC
|
3182 IEEE80211_VHT_CAP_RXSTBC_4
|
3183 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
3184 sband
->vht_cap
.vht_mcs
.rx_mcs_map
=
3185 cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9
<< 0 |
3186 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 2 |
3187 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 4 |
3188 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 6 |
3189 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 8 |
3190 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 10 |
3191 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 12 |
3192 IEEE80211_VHT_MCS_SUPPORT_0_9
<< 14);
3193 sband
->vht_cap
.vht_mcs
.tx_mcs_map
=
3194 sband
->vht_cap
.vht_mcs
.rx_mcs_map
;
3196 case NL80211_BAND_S1GHZ
:
3197 memcpy(&sband
->s1g_cap
, &hwsim_s1g_cap
,
3198 sizeof(sband
->s1g_cap
));
3199 sband
->channels
= data
->channels_s1g
;
3200 sband
->n_channels
= ARRAY_SIZE(hwsim_channels_s1g
);
3206 sband
->ht_cap
.ht_supported
= true;
3207 sband
->ht_cap
.cap
= IEEE80211_HT_CAP_SUP_WIDTH_20_40
|
3208 IEEE80211_HT_CAP_GRN_FLD
|
3209 IEEE80211_HT_CAP_SGI_20
|
3210 IEEE80211_HT_CAP_SGI_40
|
3211 IEEE80211_HT_CAP_DSSSCCK40
;
3212 sband
->ht_cap
.ampdu_factor
= 0x3;
3213 sband
->ht_cap
.ampdu_density
= 0x6;
3214 memset(&sband
->ht_cap
.mcs
, 0,
3215 sizeof(sband
->ht_cap
.mcs
));
3216 sband
->ht_cap
.mcs
.rx_mask
[0] = 0xff;
3217 sband
->ht_cap
.mcs
.rx_mask
[1] = 0xff;
3218 sband
->ht_cap
.mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
3220 mac80211_hwsim_he_capab(sband
);
3222 hw
->wiphy
->bands
[band
] = sband
;
3225 /* By default all radios belong to the first group */
3227 mutex_init(&data
->mutex
);
3229 data
->netgroup
= hwsim_net_get_netgroup(net
);
3230 data
->wmediumd
= hwsim_net_get_wmediumd(net
);
3232 /* Enable frame retransmissions for lossy channels */
3234 hw
->max_rate_tries
= 11;
3236 hw
->wiphy
->vendor_commands
= mac80211_hwsim_vendor_commands
;
3237 hw
->wiphy
->n_vendor_commands
=
3238 ARRAY_SIZE(mac80211_hwsim_vendor_commands
);
3239 hw
->wiphy
->vendor_events
= mac80211_hwsim_vendor_events
;
3240 hw
->wiphy
->n_vendor_events
= ARRAY_SIZE(mac80211_hwsim_vendor_events
);
3242 if (param
->reg_strict
)
3243 hw
->wiphy
->regulatory_flags
|= REGULATORY_STRICT_REG
;
3245 data
->regd
= param
->regd
;
3246 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
;
3247 wiphy_apply_custom_regulatory(hw
->wiphy
, param
->regd
);
3248 /* give the regulatory workqueue a chance to run */
3249 schedule_timeout_interruptible(1);
3253 ieee80211_hw_set(hw
, NO_AUTO_VIF
);
3255 wiphy_ext_feature_set(hw
->wiphy
, NL80211_EXT_FEATURE_CQM_RSSI_LIST
);
3257 hrtimer_init(&data
->beacon_timer
, CLOCK_MONOTONIC
,
3258 HRTIMER_MODE_ABS_SOFT
);
3259 data
->beacon_timer
.function
= mac80211_hwsim_beacon
;
3261 err
= ieee80211_register_hw(hw
);
3263 pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
3268 wiphy_dbg(hw
->wiphy
, "hwaddr %pM registered\n", hw
->wiphy
->perm_addr
);
3270 if (param
->reg_alpha2
) {
3271 data
->alpha2
[0] = param
->reg_alpha2
[0];
3272 data
->alpha2
[1] = param
->reg_alpha2
[1];
3273 regulatory_hint(hw
->wiphy
, param
->reg_alpha2
);
3276 data
->debugfs
= debugfs_create_dir("hwsim", hw
->wiphy
->debugfsdir
);
3277 debugfs_create_file("ps", 0666, data
->debugfs
, data
, &hwsim_fops_ps
);
3278 debugfs_create_file("group", 0666, data
->debugfs
, data
,
3280 if (!data
->use_chanctx
)
3281 debugfs_create_file("dfs_simulate_radar", 0222,
3283 data
, &hwsim_simulate_radar
);
3285 spin_lock_bh(&hwsim_radio_lock
);
3286 err
= rhashtable_insert_fast(&hwsim_radios_rht
, &data
->rht
,
3290 GENL_SET_ERR_MSG(info
, "perm addr already present");
3291 NL_SET_BAD_ATTR(info
->extack
,
3292 info
->attrs
[HWSIM_ATTR_PERM_ADDR
]);
3294 spin_unlock_bh(&hwsim_radio_lock
);
3295 goto failed_final_insert
;
3298 list_add_tail(&data
->list
, &hwsim_radios
);
3299 hwsim_radios_generation
++;
3300 spin_unlock_bh(&hwsim_radio_lock
);
3302 hwsim_mcast_new_radio(idx
, info
, param
);
3306 failed_final_insert
:
3307 debugfs_remove_recursive(data
->debugfs
);
3308 ieee80211_unregister_hw(data
->hw
);
3310 device_release_driver(data
->dev
);
3312 device_unregister(data
->dev
);
3314 ieee80211_free_hw(hw
);
3319 static void hwsim_mcast_del_radio(int id
, const char *hwname
,
3320 struct genl_info
*info
)
3322 struct sk_buff
*skb
;
3326 skb
= genlmsg_new(GENLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3330 data
= genlmsg_put(skb
, 0, 0, &hwsim_genl_family
, 0,
3331 HWSIM_CMD_DEL_RADIO
);
3335 ret
= nla_put_u32(skb
, HWSIM_ATTR_RADIO_ID
, id
);
3339 ret
= nla_put(skb
, HWSIM_ATTR_RADIO_NAME
, strlen(hwname
),
3344 genlmsg_end(skb
, data
);
3346 hwsim_mcast_config_msg(skb
, info
);
3354 static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data
*data
,
3356 struct genl_info
*info
)
3358 hwsim_mcast_del_radio(data
->idx
, hwname
, info
);
3359 debugfs_remove_recursive(data
->debugfs
);
3360 ieee80211_unregister_hw(data
->hw
);
3361 device_release_driver(data
->dev
);
3362 device_unregister(data
->dev
);
3363 ieee80211_free_hw(data
->hw
);
3366 static int mac80211_hwsim_get_radio(struct sk_buff
*skb
,
3367 struct mac80211_hwsim_data
*data
,
3368 u32 portid
, u32 seq
,
3369 struct netlink_callback
*cb
, int flags
)
3372 struct hwsim_new_radio_params param
= { };
3373 int res
= -EMSGSIZE
;
3375 hdr
= genlmsg_put(skb
, portid
, seq
, &hwsim_genl_family
, flags
,
3376 HWSIM_CMD_GET_RADIO
);
3381 genl_dump_check_consistent(cb
, hdr
);
3383 if (data
->alpha2
[0] && data
->alpha2
[1])
3384 param
.reg_alpha2
= data
->alpha2
;
3386 param
.reg_strict
= !!(data
->hw
->wiphy
->regulatory_flags
&
3387 REGULATORY_STRICT_REG
);
3388 param
.p2p_device
= !!(data
->hw
->wiphy
->interface_modes
&
3389 BIT(NL80211_IFTYPE_P2P_DEVICE
));
3390 param
.use_chanctx
= data
->use_chanctx
;
3391 param
.regd
= data
->regd
;
3392 param
.channels
= data
->channels
;
3393 param
.hwname
= wiphy_name(data
->hw
->wiphy
);
3395 res
= append_radio_msg(skb
, data
->idx
, ¶m
);
3399 genlmsg_end(skb
, hdr
);
3403 genlmsg_cancel(skb
, hdr
);
3407 static void mac80211_hwsim_free(void)
3409 struct mac80211_hwsim_data
*data
;
3411 spin_lock_bh(&hwsim_radio_lock
);
3412 while ((data
= list_first_entry_or_null(&hwsim_radios
,
3413 struct mac80211_hwsim_data
,
3415 list_del(&data
->list
);
3416 spin_unlock_bh(&hwsim_radio_lock
);
3417 mac80211_hwsim_del_radio(data
, wiphy_name(data
->hw
->wiphy
),
3419 spin_lock_bh(&hwsim_radio_lock
);
3421 spin_unlock_bh(&hwsim_radio_lock
);
3422 class_destroy(hwsim_class
);
3425 static const struct net_device_ops hwsim_netdev_ops
= {
3426 .ndo_start_xmit
= hwsim_mon_xmit
,
3427 .ndo_set_mac_address
= eth_mac_addr
,
3428 .ndo_validate_addr
= eth_validate_addr
,
3431 static void hwsim_mon_setup(struct net_device
*dev
)
3433 dev
->netdev_ops
= &hwsim_netdev_ops
;
3434 dev
->needs_free_netdev
= true;
3436 dev
->priv_flags
|= IFF_NO_QUEUE
;
3437 dev
->type
= ARPHRD_IEEE80211_RADIOTAP
;
3438 eth_zero_addr(dev
->dev_addr
);
3439 dev
->dev_addr
[0] = 0x12;
3442 static struct mac80211_hwsim_data
*get_hwsim_data_ref_from_addr(const u8
*addr
)
3444 return rhashtable_lookup_fast(&hwsim_radios_rht
,
3449 static void hwsim_register_wmediumd(struct net
*net
, u32 portid
)
3451 struct mac80211_hwsim_data
*data
;
3453 hwsim_net_set_wmediumd(net
, portid
);
3455 spin_lock_bh(&hwsim_radio_lock
);
3456 list_for_each_entry(data
, &hwsim_radios
, list
) {
3457 if (data
->netgroup
== hwsim_net_get_netgroup(net
))
3458 data
->wmediumd
= portid
;
3460 spin_unlock_bh(&hwsim_radio_lock
);
3463 static int hwsim_tx_info_frame_received_nl(struct sk_buff
*skb_2
,
3464 struct genl_info
*info
)
3467 struct ieee80211_hdr
*hdr
;
3468 struct mac80211_hwsim_data
*data2
;
3469 struct ieee80211_tx_info
*txi
;
3470 struct hwsim_tx_rate
*tx_attempts
;
3472 struct sk_buff
*skb
, *tmp
;
3474 unsigned int hwsim_flags
;
3478 if (!info
->attrs
[HWSIM_ATTR_ADDR_TRANSMITTER
] ||
3479 !info
->attrs
[HWSIM_ATTR_FLAGS
] ||
3480 !info
->attrs
[HWSIM_ATTR_COOKIE
] ||
3481 !info
->attrs
[HWSIM_ATTR_SIGNAL
] ||
3482 !info
->attrs
[HWSIM_ATTR_TX_INFO
])
3485 src
= (void *)nla_data(info
->attrs
[HWSIM_ATTR_ADDR_TRANSMITTER
]);
3486 hwsim_flags
= nla_get_u32(info
->attrs
[HWSIM_ATTR_FLAGS
]);
3487 ret_skb_cookie
= nla_get_u64(info
->attrs
[HWSIM_ATTR_COOKIE
]);
3489 data2
= get_hwsim_data_ref_from_addr(src
);
3493 if (!hwsim_virtio_enabled
) {
3494 if (hwsim_net_get_netgroup(genl_info_net(info
)) !=
3498 if (info
->snd_portid
!= data2
->wmediumd
)
3502 /* look for the skb matching the cookie passed back from user */
3503 skb_queue_walk_safe(&data2
->pending
, skb
, tmp
) {
3506 txi
= IEEE80211_SKB_CB(skb
);
3507 skb_cookie
= (u64
)(uintptr_t)txi
->rate_driver_data
[0];
3509 if (skb_cookie
== ret_skb_cookie
) {
3510 skb_unlink(skb
, &data2
->pending
);
3520 /* Tx info received because the frame was broadcasted on user space,
3521 so we get all the necessary info: tx attempts and skb control buff */
3523 tx_attempts
= (struct hwsim_tx_rate
*)nla_data(
3524 info
->attrs
[HWSIM_ATTR_TX_INFO
]);
3526 /* now send back TX status */
3527 txi
= IEEE80211_SKB_CB(skb
);
3529 ieee80211_tx_info_clear_status(txi
);
3531 for (i
= 0; i
< IEEE80211_TX_MAX_RATES
; i
++) {
3532 txi
->status
.rates
[i
].idx
= tx_attempts
[i
].idx
;
3533 txi
->status
.rates
[i
].count
= tx_attempts
[i
].count
;
3536 txi
->status
.ack_signal
= nla_get_u32(info
->attrs
[HWSIM_ATTR_SIGNAL
]);
3538 if (!(hwsim_flags
& HWSIM_TX_CTL_NO_ACK
) &&
3539 (hwsim_flags
& HWSIM_TX_STAT_ACK
)) {
3540 if (skb
->len
>= 16) {
3541 hdr
= (struct ieee80211_hdr
*) skb
->data
;
3542 mac80211_hwsim_monitor_ack(data2
->channel
,
3545 txi
->flags
|= IEEE80211_TX_STAT_ACK
;
3547 ieee80211_tx_status_irqsafe(data2
->hw
, skb
);
3554 static int hwsim_cloned_frame_received_nl(struct sk_buff
*skb_2
,
3555 struct genl_info
*info
)
3557 struct mac80211_hwsim_data
*data2
;
3558 struct ieee80211_rx_status rx_status
;
3559 struct ieee80211_hdr
*hdr
;
3563 struct sk_buff
*skb
= NULL
;
3565 if (!info
->attrs
[HWSIM_ATTR_ADDR_RECEIVER
] ||
3566 !info
->attrs
[HWSIM_ATTR_FRAME
] ||
3567 !info
->attrs
[HWSIM_ATTR_RX_RATE
] ||
3568 !info
->attrs
[HWSIM_ATTR_SIGNAL
])
3571 dst
= (void *)nla_data(info
->attrs
[HWSIM_ATTR_ADDR_RECEIVER
]);
3572 frame_data_len
= nla_len(info
->attrs
[HWSIM_ATTR_FRAME
]);
3573 frame_data
= (void *)nla_data(info
->attrs
[HWSIM_ATTR_FRAME
]);
3575 /* Allocate new skb here */
3576 skb
= alloc_skb(frame_data_len
, GFP_KERNEL
);
3580 if (frame_data_len
> IEEE80211_MAX_DATA_LEN
)
3584 skb_put_data(skb
, frame_data
, frame_data_len
);
3586 data2
= get_hwsim_data_ref_from_addr(dst
);
3590 if (!hwsim_virtio_enabled
) {
3591 if (hwsim_net_get_netgroup(genl_info_net(info
)) !=
3595 if (info
->snd_portid
!= data2
->wmediumd
)
3599 /* check if radio is configured properly */
3601 if (data2
->idle
|| !data2
->started
)
3604 /* A frame is received from user space */
3605 memset(&rx_status
, 0, sizeof(rx_status
));
3606 if (info
->attrs
[HWSIM_ATTR_FREQ
]) {
3607 /* throw away off-channel packets, but allow both the temporary
3608 * ("hw" scan/remain-on-channel) and regular channel, since the
3609 * internal datapath also allows this
3611 mutex_lock(&data2
->mutex
);
3612 rx_status
.freq
= nla_get_u32(info
->attrs
[HWSIM_ATTR_FREQ
]);
3614 if (rx_status
.freq
!= data2
->channel
->center_freq
&&
3615 (!data2
->tmp_chan
||
3616 rx_status
.freq
!= data2
->tmp_chan
->center_freq
)) {
3617 mutex_unlock(&data2
->mutex
);
3620 mutex_unlock(&data2
->mutex
);
3622 rx_status
.freq
= data2
->channel
->center_freq
;
3625 rx_status
.band
= data2
->channel
->band
;
3626 rx_status
.rate_idx
= nla_get_u32(info
->attrs
[HWSIM_ATTR_RX_RATE
]);
3627 rx_status
.signal
= nla_get_u32(info
->attrs
[HWSIM_ATTR_SIGNAL
]);
3629 hdr
= (void *)skb
->data
;
3631 if (ieee80211_is_beacon(hdr
->frame_control
) ||
3632 ieee80211_is_probe_resp(hdr
->frame_control
))
3633 rx_status
.boottime_ns
= ktime_get_boottime_ns();
3635 memcpy(IEEE80211_SKB_RXCB(skb
), &rx_status
, sizeof(rx_status
));
3637 data2
->rx_bytes
+= skb
->len
;
3638 ieee80211_rx_irqsafe(data2
->hw
, skb
);
3642 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__
);
3648 static int hwsim_register_received_nl(struct sk_buff
*skb_2
,
3649 struct genl_info
*info
)
3651 struct net
*net
= genl_info_net(info
);
3652 struct mac80211_hwsim_data
*data
;
3655 spin_lock_bh(&hwsim_radio_lock
);
3656 list_for_each_entry(data
, &hwsim_radios
, list
)
3657 chans
= max(chans
, data
->channels
);
3658 spin_unlock_bh(&hwsim_radio_lock
);
3660 /* In the future we should revise the userspace API and allow it
3661 * to set a flag that it does support multi-channel, then we can
3662 * let this pass conditionally on the flag.
3663 * For current userspace, prohibit it since it won't work right.
3668 if (hwsim_net_get_wmediumd(net
))
3671 hwsim_register_wmediumd(net
, info
->snd_portid
);
3673 pr_debug("mac80211_hwsim: received a REGISTER, "
3674 "switching to wmediumd mode with pid %d\n", info
->snd_portid
);
3679 /* ensures ciphers only include ciphers listed in 'hwsim_ciphers' array */
3680 static bool hwsim_known_ciphers(const u32
*ciphers
, int n_ciphers
)
3684 for (i
= 0; i
< n_ciphers
; i
++) {
3688 for (j
= 0; j
< ARRAY_SIZE(hwsim_ciphers
); j
++) {
3689 if (ciphers
[i
] == hwsim_ciphers
[j
]) {
3702 static int hwsim_new_radio_nl(struct sk_buff
*msg
, struct genl_info
*info
)
3704 struct hwsim_new_radio_params param
= { 0 };
3705 const char *hwname
= NULL
;
3708 param
.reg_strict
= info
->attrs
[HWSIM_ATTR_REG_STRICT_REG
];
3709 param
.p2p_device
= info
->attrs
[HWSIM_ATTR_SUPPORT_P2P_DEVICE
];
3710 param
.channels
= channels
;
3711 param
.destroy_on_close
=
3712 info
->attrs
[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE
];
3714 if (info
->attrs
[HWSIM_ATTR_CHANNELS
])
3715 param
.channels
= nla_get_u32(info
->attrs
[HWSIM_ATTR_CHANNELS
]);
3717 if (param
.channels
< 1) {
3718 GENL_SET_ERR_MSG(info
, "must have at least one channel");
3722 if (param
.channels
> CFG80211_MAX_NUM_DIFFERENT_CHANNELS
) {
3723 GENL_SET_ERR_MSG(info
, "too many channels specified");
3727 if (info
->attrs
[HWSIM_ATTR_NO_VIF
])
3728 param
.no_vif
= true;
3730 if (info
->attrs
[HWSIM_ATTR_USE_CHANCTX
])
3731 param
.use_chanctx
= true;
3733 param
.use_chanctx
= (param
.channels
> 1);
3735 if (info
->attrs
[HWSIM_ATTR_REG_HINT_ALPHA2
])
3737 nla_data(info
->attrs
[HWSIM_ATTR_REG_HINT_ALPHA2
]);
3739 if (info
->attrs
[HWSIM_ATTR_REG_CUSTOM_REG
]) {
3740 u32 idx
= nla_get_u32(info
->attrs
[HWSIM_ATTR_REG_CUSTOM_REG
]);
3742 if (idx
>= ARRAY_SIZE(hwsim_world_regdom_custom
))
3745 idx
= array_index_nospec(idx
,
3746 ARRAY_SIZE(hwsim_world_regdom_custom
));
3747 param
.regd
= hwsim_world_regdom_custom
[idx
];
3750 if (info
->attrs
[HWSIM_ATTR_PERM_ADDR
]) {
3751 if (!is_valid_ether_addr(
3752 nla_data(info
->attrs
[HWSIM_ATTR_PERM_ADDR
]))) {
3753 GENL_SET_ERR_MSG(info
,"MAC is no valid source addr");
3754 NL_SET_BAD_ATTR(info
->extack
,
3755 info
->attrs
[HWSIM_ATTR_PERM_ADDR
]);
3759 param
.perm_addr
= nla_data(info
->attrs
[HWSIM_ATTR_PERM_ADDR
]);
3762 if (info
->attrs
[HWSIM_ATTR_IFTYPE_SUPPORT
]) {
3764 nla_get_u32(info
->attrs
[HWSIM_ATTR_IFTYPE_SUPPORT
]);
3766 if (param
.iftypes
& ~HWSIM_IFTYPE_SUPPORT_MASK
) {
3767 NL_SET_ERR_MSG_ATTR(info
->extack
,
3768 info
->attrs
[HWSIM_ATTR_IFTYPE_SUPPORT
],
3769 "cannot support more iftypes than kernel");
3773 param
.iftypes
= HWSIM_IFTYPE_SUPPORT_MASK
;
3776 /* ensure both flag and iftype support is honored */
3777 if (param
.p2p_device
||
3778 param
.iftypes
& BIT(NL80211_IFTYPE_P2P_DEVICE
)) {
3779 param
.iftypes
|= BIT(NL80211_IFTYPE_P2P_DEVICE
);
3780 param
.p2p_device
= true;
3783 if (info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
]) {
3784 u32 len
= nla_len(info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
]);
3787 nla_data(info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
]);
3789 if (len
% sizeof(u32
)) {
3790 NL_SET_ERR_MSG_ATTR(info
->extack
,
3791 info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
],
3792 "bad cipher list length");
3796 param
.n_ciphers
= len
/ sizeof(u32
);
3798 if (param
.n_ciphers
> ARRAY_SIZE(hwsim_ciphers
)) {
3799 NL_SET_ERR_MSG_ATTR(info
->extack
,
3800 info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
],
3801 "too many ciphers specified");
3805 if (!hwsim_known_ciphers(param
.ciphers
, param
.n_ciphers
)) {
3806 NL_SET_ERR_MSG_ATTR(info
->extack
,
3807 info
->attrs
[HWSIM_ATTR_CIPHER_SUPPORT
],
3808 "unsupported ciphers specified");
3813 if (info
->attrs
[HWSIM_ATTR_RADIO_NAME
]) {
3814 hwname
= kstrndup((char *)nla_data(info
->attrs
[HWSIM_ATTR_RADIO_NAME
]),
3815 nla_len(info
->attrs
[HWSIM_ATTR_RADIO_NAME
]),
3819 param
.hwname
= hwname
;
3822 ret
= mac80211_hwsim_new_radio(info
, ¶m
);
3827 static int hwsim_del_radio_nl(struct sk_buff
*msg
, struct genl_info
*info
)
3829 struct mac80211_hwsim_data
*data
;
3831 const char *hwname
= NULL
;
3833 if (info
->attrs
[HWSIM_ATTR_RADIO_ID
]) {
3834 idx
= nla_get_u32(info
->attrs
[HWSIM_ATTR_RADIO_ID
]);
3835 } else if (info
->attrs
[HWSIM_ATTR_RADIO_NAME
]) {
3836 hwname
= kstrndup((char *)nla_data(info
->attrs
[HWSIM_ATTR_RADIO_NAME
]),
3837 nla_len(info
->attrs
[HWSIM_ATTR_RADIO_NAME
]),
3844 spin_lock_bh(&hwsim_radio_lock
);
3845 list_for_each_entry(data
, &hwsim_radios
, list
) {
3847 if (data
->idx
!= idx
)
3851 strcmp(hwname
, wiphy_name(data
->hw
->wiphy
)))
3855 if (!net_eq(wiphy_net(data
->hw
->wiphy
), genl_info_net(info
)))
3858 list_del(&data
->list
);
3859 rhashtable_remove_fast(&hwsim_radios_rht
, &data
->rht
,
3861 hwsim_radios_generation
++;
3862 spin_unlock_bh(&hwsim_radio_lock
);
3863 mac80211_hwsim_del_radio(data
, wiphy_name(data
->hw
->wiphy
),
3868 spin_unlock_bh(&hwsim_radio_lock
);
3874 static int hwsim_get_radio_nl(struct sk_buff
*msg
, struct genl_info
*info
)
3876 struct mac80211_hwsim_data
*data
;
3877 struct sk_buff
*skb
;
3878 int idx
, res
= -ENODEV
;
3880 if (!info
->attrs
[HWSIM_ATTR_RADIO_ID
])
3882 idx
= nla_get_u32(info
->attrs
[HWSIM_ATTR_RADIO_ID
]);
3884 spin_lock_bh(&hwsim_radio_lock
);
3885 list_for_each_entry(data
, &hwsim_radios
, list
) {
3886 if (data
->idx
!= idx
)
3889 if (!net_eq(wiphy_net(data
->hw
->wiphy
), genl_info_net(info
)))
3892 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3898 res
= mac80211_hwsim_get_radio(skb
, data
, info
->snd_portid
,
3899 info
->snd_seq
, NULL
, 0);
3905 res
= genlmsg_reply(skb
, info
);
3910 spin_unlock_bh(&hwsim_radio_lock
);
3915 static int hwsim_dump_radio_nl(struct sk_buff
*skb
,
3916 struct netlink_callback
*cb
)
3918 int last_idx
= cb
->args
[0] - 1;
3919 struct mac80211_hwsim_data
*data
= NULL
;
3923 spin_lock_bh(&hwsim_radio_lock
);
3924 cb
->seq
= hwsim_radios_generation
;
3926 if (last_idx
>= hwsim_radio_idx
-1)
3929 list_for_each_entry(data
, &hwsim_radios
, list
) {
3930 if (data
->idx
<= last_idx
)
3933 if (!net_eq(wiphy_net(data
->hw
->wiphy
), sock_net(skb
->sk
)))
3936 res
= mac80211_hwsim_get_radio(skb
, data
,
3937 NETLINK_CB(cb
->skb
).portid
,
3938 cb
->nlh
->nlmsg_seq
, cb
,
3943 last_idx
= data
->idx
;
3946 cb
->args
[0] = last_idx
+ 1;
3948 /* list changed, but no new element sent, set interrupted flag */
3949 if (skb
->len
== 0 && cb
->prev_seq
&& cb
->seq
!= cb
->prev_seq
) {
3950 hdr
= genlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
,
3951 cb
->nlh
->nlmsg_seq
, &hwsim_genl_family
,
3952 NLM_F_MULTI
, HWSIM_CMD_GET_RADIO
);
3954 genl_dump_check_consistent(cb
, hdr
);
3955 genlmsg_end(skb
, hdr
);
3962 spin_unlock_bh(&hwsim_radio_lock
);
3963 return res
?: skb
->len
;
3966 /* Generic Netlink operations array */
3967 static const struct genl_small_ops hwsim_ops
[] = {
3969 .cmd
= HWSIM_CMD_REGISTER
,
3970 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3971 .doit
= hwsim_register_received_nl
,
3972 .flags
= GENL_UNS_ADMIN_PERM
,
3975 .cmd
= HWSIM_CMD_FRAME
,
3976 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3977 .doit
= hwsim_cloned_frame_received_nl
,
3980 .cmd
= HWSIM_CMD_TX_INFO_FRAME
,
3981 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3982 .doit
= hwsim_tx_info_frame_received_nl
,
3985 .cmd
= HWSIM_CMD_NEW_RADIO
,
3986 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3987 .doit
= hwsim_new_radio_nl
,
3988 .flags
= GENL_UNS_ADMIN_PERM
,
3991 .cmd
= HWSIM_CMD_DEL_RADIO
,
3992 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3993 .doit
= hwsim_del_radio_nl
,
3994 .flags
= GENL_UNS_ADMIN_PERM
,
3997 .cmd
= HWSIM_CMD_GET_RADIO
,
3998 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
3999 .doit
= hwsim_get_radio_nl
,
4000 .dumpit
= hwsim_dump_radio_nl
,
4004 static struct genl_family hwsim_genl_family __ro_after_init
= {
4005 .name
= "MAC80211_HWSIM",
4007 .maxattr
= HWSIM_ATTR_MAX
,
4008 .policy
= hwsim_genl_policy
,
4010 .module
= THIS_MODULE
,
4011 .small_ops
= hwsim_ops
,
4012 .n_small_ops
= ARRAY_SIZE(hwsim_ops
),
4013 .mcgrps
= hwsim_mcgrps
,
4014 .n_mcgrps
= ARRAY_SIZE(hwsim_mcgrps
),
4017 static void remove_user_radios(u32 portid
)
4019 struct mac80211_hwsim_data
*entry
, *tmp
;
4022 spin_lock_bh(&hwsim_radio_lock
);
4023 list_for_each_entry_safe(entry
, tmp
, &hwsim_radios
, list
) {
4024 if (entry
->destroy_on_close
&& entry
->portid
== portid
) {
4025 list_move(&entry
->list
, &list
);
4026 rhashtable_remove_fast(&hwsim_radios_rht
, &entry
->rht
,
4028 hwsim_radios_generation
++;
4031 spin_unlock_bh(&hwsim_radio_lock
);
4033 list_for_each_entry_safe(entry
, tmp
, &list
, list
) {
4034 list_del(&entry
->list
);
4035 mac80211_hwsim_del_radio(entry
, wiphy_name(entry
->hw
->wiphy
),
4040 static int mac80211_hwsim_netlink_notify(struct notifier_block
*nb
,
4041 unsigned long state
,
4044 struct netlink_notify
*notify
= _notify
;
4046 if (state
!= NETLINK_URELEASE
)
4049 remove_user_radios(notify
->portid
);
4051 if (notify
->portid
== hwsim_net_get_wmediumd(notify
->net
)) {
4052 printk(KERN_INFO
"mac80211_hwsim: wmediumd released netlink"
4053 " socket, switching to perfect channel medium\n");
4054 hwsim_register_wmediumd(notify
->net
, 0);
4060 static struct notifier_block hwsim_netlink_notifier
= {
4061 .notifier_call
= mac80211_hwsim_netlink_notify
,
4064 static int __init
hwsim_init_netlink(void)
4068 printk(KERN_INFO
"mac80211_hwsim: initializing netlink\n");
4070 rc
= genl_register_family(&hwsim_genl_family
);
4074 rc
= netlink_register_notifier(&hwsim_netlink_notifier
);
4076 genl_unregister_family(&hwsim_genl_family
);
4083 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__
);
4087 static __net_init
int hwsim_init_net(struct net
*net
)
4089 return hwsim_net_set_netgroup(net
);
4092 static void __net_exit
hwsim_exit_net(struct net
*net
)
4094 struct mac80211_hwsim_data
*data
, *tmp
;
4097 spin_lock_bh(&hwsim_radio_lock
);
4098 list_for_each_entry_safe(data
, tmp
, &hwsim_radios
, list
) {
4099 if (!net_eq(wiphy_net(data
->hw
->wiphy
), net
))
4102 /* Radios created in init_net are returned to init_net. */
4103 if (data
->netgroup
== hwsim_net_get_netgroup(&init_net
))
4106 list_move(&data
->list
, &list
);
4107 rhashtable_remove_fast(&hwsim_radios_rht
, &data
->rht
,
4109 hwsim_radios_generation
++;
4111 spin_unlock_bh(&hwsim_radio_lock
);
4113 list_for_each_entry_safe(data
, tmp
, &list
, list
) {
4114 list_del(&data
->list
);
4115 mac80211_hwsim_del_radio(data
,
4116 wiphy_name(data
->hw
->wiphy
),
4120 ida_simple_remove(&hwsim_netgroup_ida
, hwsim_net_get_netgroup(net
));
4123 static struct pernet_operations hwsim_net_ops
= {
4124 .init
= hwsim_init_net
,
4125 .exit
= hwsim_exit_net
,
4126 .id
= &hwsim_net_id
,
4127 .size
= sizeof(struct hwsim_net
),
4130 static void hwsim_exit_netlink(void)
4132 /* unregister the notifier */
4133 netlink_unregister_notifier(&hwsim_netlink_notifier
);
4134 /* unregister the family */
4135 genl_unregister_family(&hwsim_genl_family
);
4138 #if IS_REACHABLE(CONFIG_VIRTIO)
4139 static void hwsim_virtio_tx_done(struct virtqueue
*vq
)
4142 struct sk_buff
*skb
;
4143 unsigned long flags
;
4145 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
4146 while ((skb
= virtqueue_get_buf(vq
, &len
)))
4148 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4151 static int hwsim_virtio_handle_cmd(struct sk_buff
*skb
)
4153 struct nlmsghdr
*nlh
;
4154 struct genlmsghdr
*gnlh
;
4155 struct nlattr
*tb
[HWSIM_ATTR_MAX
+ 1];
4156 struct genl_info info
= {};
4159 nlh
= nlmsg_hdr(skb
);
4160 gnlh
= nlmsg_data(nlh
);
4161 err
= genlmsg_parse(nlh
, &hwsim_genl_family
, tb
, HWSIM_ATTR_MAX
,
4162 hwsim_genl_policy
, NULL
);
4164 pr_err_ratelimited("hwsim: genlmsg_parse returned %d\n", err
);
4170 switch (gnlh
->cmd
) {
4171 case HWSIM_CMD_FRAME
:
4172 hwsim_cloned_frame_received_nl(skb
, &info
);
4174 case HWSIM_CMD_TX_INFO_FRAME
:
4175 hwsim_tx_info_frame_received_nl(skb
, &info
);
4178 pr_err_ratelimited("hwsim: invalid cmd: %d\n", gnlh
->cmd
);
4184 static void hwsim_virtio_rx_work(struct work_struct
*work
)
4186 struct virtqueue
*vq
;
4188 struct sk_buff
*skb
;
4189 struct scatterlist sg
[1];
4191 unsigned long flags
;
4193 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
4194 if (!hwsim_virtio_enabled
)
4197 skb
= virtqueue_get_buf(hwsim_vqs
[HWSIM_VQ_RX
], &len
);
4200 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4202 skb
->data
= skb
->head
;
4203 skb_set_tail_pointer(skb
, len
);
4204 hwsim_virtio_handle_cmd(skb
);
4206 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
4207 if (!hwsim_virtio_enabled
) {
4211 vq
= hwsim_vqs
[HWSIM_VQ_RX
];
4212 sg_init_one(sg
, skb
->head
, skb_end_offset(skb
));
4213 err
= virtqueue_add_inbuf(vq
, sg
, 1, skb
, GFP_ATOMIC
);
4214 if (WARN(err
, "virtqueue_add_inbuf returned %d\n", err
))
4218 schedule_work(&hwsim_virtio_rx
);
4221 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4224 static void hwsim_virtio_rx_done(struct virtqueue
*vq
)
4226 schedule_work(&hwsim_virtio_rx
);
4229 static int init_vqs(struct virtio_device
*vdev
)
4231 vq_callback_t
*callbacks
[HWSIM_NUM_VQS
] = {
4232 [HWSIM_VQ_TX
] = hwsim_virtio_tx_done
,
4233 [HWSIM_VQ_RX
] = hwsim_virtio_rx_done
,
4235 const char *names
[HWSIM_NUM_VQS
] = {
4236 [HWSIM_VQ_TX
] = "tx",
4237 [HWSIM_VQ_RX
] = "rx",
4240 return virtio_find_vqs(vdev
, HWSIM_NUM_VQS
,
4241 hwsim_vqs
, callbacks
, names
, NULL
);
4244 static int fill_vq(struct virtqueue
*vq
)
4247 struct sk_buff
*skb
;
4248 struct scatterlist sg
[1];
4250 for (i
= 0; i
< virtqueue_get_vring_size(vq
); i
++) {
4251 skb
= genlmsg_new(GENLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4255 sg_init_one(sg
, skb
->head
, skb_end_offset(skb
));
4256 err
= virtqueue_add_inbuf(vq
, sg
, 1, skb
, GFP_KERNEL
);
4266 static void remove_vqs(struct virtio_device
*vdev
)
4270 vdev
->config
->reset(vdev
);
4272 for (i
= 0; i
< ARRAY_SIZE(hwsim_vqs
); i
++) {
4273 struct virtqueue
*vq
= hwsim_vqs
[i
];
4274 struct sk_buff
*skb
;
4276 while ((skb
= virtqueue_detach_unused_buf(vq
)))
4280 vdev
->config
->del_vqs(vdev
);
4283 static int hwsim_virtio_probe(struct virtio_device
*vdev
)
4286 unsigned long flags
;
4288 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
4289 if (hwsim_virtio_enabled
) {
4290 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4293 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4295 err
= init_vqs(vdev
);
4299 err
= fill_vq(hwsim_vqs
[HWSIM_VQ_RX
]);
4303 spin_lock_irqsave(&hwsim_virtio_lock
, flags
);
4304 hwsim_virtio_enabled
= true;
4305 spin_unlock_irqrestore(&hwsim_virtio_lock
, flags
);
4307 schedule_work(&hwsim_virtio_rx
);
4315 static void hwsim_virtio_remove(struct virtio_device
*vdev
)
4317 hwsim_virtio_enabled
= false;
4319 cancel_work_sync(&hwsim_virtio_rx
);
4324 /* MAC80211_HWSIM virtio device id table */
4325 static const struct virtio_device_id id_table
[] = {
4326 { VIRTIO_ID_MAC80211_HWSIM
, VIRTIO_DEV_ANY_ID
},
4329 MODULE_DEVICE_TABLE(virtio
, id_table
);
4331 static struct virtio_driver virtio_hwsim
= {
4332 .driver
.name
= KBUILD_MODNAME
,
4333 .driver
.owner
= THIS_MODULE
,
4334 .id_table
= id_table
,
4335 .probe
= hwsim_virtio_probe
,
4336 .remove
= hwsim_virtio_remove
,
4339 static int hwsim_register_virtio_driver(void)
4341 spin_lock_init(&hwsim_virtio_lock
);
4343 return register_virtio_driver(&virtio_hwsim
);
4346 static void hwsim_unregister_virtio_driver(void)
4348 unregister_virtio_driver(&virtio_hwsim
);
4351 static inline int hwsim_register_virtio_driver(void)
4356 static inline void hwsim_unregister_virtio_driver(void)
4361 static int __init
init_mac80211_hwsim(void)
4365 if (radios
< 0 || radios
> 100)
4371 spin_lock_init(&hwsim_radio_lock
);
4373 err
= rhashtable_init(&hwsim_radios_rht
, &hwsim_rht_params
);
4377 err
= register_pernet_device(&hwsim_net_ops
);
4381 err
= platform_driver_register(&mac80211_hwsim_driver
);
4383 goto out_unregister_pernet
;
4385 err
= hwsim_init_netlink();
4387 goto out_unregister_driver
;
4389 err
= hwsim_register_virtio_driver();
4391 goto out_exit_netlink
;
4393 hwsim_class
= class_create(THIS_MODULE
, "mac80211_hwsim");
4394 if (IS_ERR(hwsim_class
)) {
4395 err
= PTR_ERR(hwsim_class
);
4396 goto out_exit_virtio
;
4399 hwsim_init_s1g_channels(hwsim_channels_s1g
);
4401 for (i
= 0; i
< radios
; i
++) {
4402 struct hwsim_new_radio_params param
= { 0 };
4404 param
.channels
= channels
;
4407 case HWSIM_REGTEST_DIFF_COUNTRY
:
4408 if (i
< ARRAY_SIZE(hwsim_alpha2s
))
4409 param
.reg_alpha2
= hwsim_alpha2s
[i
];
4411 case HWSIM_REGTEST_DRIVER_REG_FOLLOW
:
4413 param
.reg_alpha2
= hwsim_alpha2s
[0];
4415 case HWSIM_REGTEST_STRICT_ALL
:
4416 param
.reg_strict
= true;
4418 case HWSIM_REGTEST_DRIVER_REG_ALL
:
4419 param
.reg_alpha2
= hwsim_alpha2s
[0];
4421 case HWSIM_REGTEST_WORLD_ROAM
:
4423 param
.regd
= &hwsim_world_regdom_custom_01
;
4425 case HWSIM_REGTEST_CUSTOM_WORLD
:
4426 param
.regd
= &hwsim_world_regdom_custom_01
;
4428 case HWSIM_REGTEST_CUSTOM_WORLD_2
:
4430 param
.regd
= &hwsim_world_regdom_custom_01
;
4432 param
.regd
= &hwsim_world_regdom_custom_02
;
4434 case HWSIM_REGTEST_STRICT_FOLLOW
:
4436 param
.reg_strict
= true;
4437 param
.reg_alpha2
= hwsim_alpha2s
[0];
4440 case HWSIM_REGTEST_STRICT_AND_DRIVER_REG
:
4442 param
.reg_strict
= true;
4443 param
.reg_alpha2
= hwsim_alpha2s
[0];
4444 } else if (i
== 1) {
4445 param
.reg_alpha2
= hwsim_alpha2s
[1];
4448 case HWSIM_REGTEST_ALL
:
4451 param
.regd
= &hwsim_world_regdom_custom_01
;
4454 param
.regd
= &hwsim_world_regdom_custom_02
;
4457 param
.reg_alpha2
= hwsim_alpha2s
[0];
4460 param
.reg_alpha2
= hwsim_alpha2s
[1];
4463 param
.reg_strict
= true;
4464 param
.reg_alpha2
= hwsim_alpha2s
[2];
4472 param
.p2p_device
= support_p2p_device
;
4473 param
.use_chanctx
= channels
> 1;
4474 param
.iftypes
= HWSIM_IFTYPE_SUPPORT_MASK
;
4475 if (param
.p2p_device
)
4476 param
.iftypes
|= BIT(NL80211_IFTYPE_P2P_DEVICE
);
4478 err
= mac80211_hwsim_new_radio(NULL
, ¶m
);
4480 goto out_free_radios
;
4483 hwsim_mon
= alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN
,
4485 if (hwsim_mon
== NULL
) {
4487 goto out_free_radios
;
4491 err
= dev_alloc_name(hwsim_mon
, hwsim_mon
->name
);
4497 err
= register_netdevice(hwsim_mon
);
4507 free_netdev(hwsim_mon
);
4509 mac80211_hwsim_free();
4511 hwsim_unregister_virtio_driver();
4513 hwsim_exit_netlink();
4514 out_unregister_driver
:
4515 platform_driver_unregister(&mac80211_hwsim_driver
);
4516 out_unregister_pernet
:
4517 unregister_pernet_device(&hwsim_net_ops
);
4519 rhashtable_destroy(&hwsim_radios_rht
);
4522 module_init(init_mac80211_hwsim
);
4524 static void __exit
exit_mac80211_hwsim(void)
4526 pr_debug("mac80211_hwsim: unregister radios\n");
4528 hwsim_unregister_virtio_driver();
4529 hwsim_exit_netlink();
4531 mac80211_hwsim_free();
4533 rhashtable_destroy(&hwsim_radios_rht
);
4534 unregister_netdev(hwsim_mon
);
4535 platform_driver_unregister(&mac80211_hwsim_driver
);
4536 unregister_pernet_device(&hwsim_net_ops
);
4538 module_exit(exit_mac80211_hwsim
);