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 - 2022 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 module_param(mlo, bool, 0444);
70 MODULE_PARM_DESC(mlo, "Support MLO");
73 * enum hwsim_regtest - the type of regulatory tests we offer
75 * These are the different values you can use for the regtest
76 * module parameter. This is useful to help test world roaming
77 * and the driver regulatory_hint() call and combinations of these.
78 * If you want to do specific alpha2 regulatory domain tests simply
79 * use the userspace regulatory request as that will be respected as
80 * well without the need of this module parameter. This is designed
81 * only for testing the driver regulatory request, world roaming
82 * and all possible combinations.
84 * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed,
85 * this is the default value.
86 * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory
87 * hint, only one driver regulatory hint will be sent as such the
88 * secondary radios are expected to follow.
89 * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory
90 * request with all radios reporting the same regulatory domain.
91 * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling
92 * different regulatory domains requests. Expected behaviour is for
93 * an intersection to occur but each device will still use their
94 * respective regulatory requested domains. Subsequent radios will
95 * use the resulting intersection.
96 * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish
97 * this by using a custom beacon-capable regulatory domain for the first
98 * radio. All other device world roam.
99 * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory
100 * domain requests. All radios will adhere to this custom world regulatory
102 * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory
103 * domain requests. The first radio will adhere to the first custom world
104 * regulatory domain, the second one to the second custom world regulatory
105 * domain. All other devices will world roam.
106 * @HWSIM_REGTEST_STRICT_FOLLOW: Used for testing strict regulatory domain
107 * settings, only the first radio will send a regulatory domain request
108 * and use strict settings. The rest of the radios are expected to follow.
109 * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain
110 * settings. All radios will adhere to this.
111 * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory
112 * domain settings, combined with secondary driver regulatory domain
113 * settings. The first radio will get a strict regulatory domain setting
114 * using the first driver regulatory request and the second radio will use
115 * non-strict settings using the second driver regulatory request. All
116 * other devices should follow the intersection created between the
118 * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need
119 * at least 6 radios for a complete test. We will test in this order:
120 * 1 - driver custom world regulatory domain
121 * 2 - second custom world regulatory domain
122 * 3 - first driver regulatory domain request
123 * 4 - second driver regulatory domain request
124 * 5 - strict regulatory domain settings using the third driver regulatory
126 * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio
127 * regulatory requests.
130 HWSIM_REGTEST_DISABLED = 0,
131 HWSIM_REGTEST_DRIVER_REG_FOLLOW = 1,
132 HWSIM_REGTEST_DRIVER_REG_ALL = 2,
133 HWSIM_REGTEST_DIFF_COUNTRY = 3,
134 HWSIM_REGTEST_WORLD_ROAM = 4,
135 HWSIM_REGTEST_CUSTOM_WORLD = 5,
136 HWSIM_REGTEST_CUSTOM_WORLD_2 = 6,
137 HWSIM_REGTEST_STRICT_FOLLOW = 7,
138 HWSIM_REGTEST_STRICT_ALL = 8,
139 HWSIM_REGTEST_STRICT_AND_DRIVER_REG = 9,
140 HWSIM_REGTEST_ALL = 10,
143 /* Set to one of the HWSIM_REGTEST_* values above */
144 static int regtest = HWSIM_REGTEST_DISABLED;
145 module_param(regtest, int, 0444);
146 MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run");
148 static const char *hwsim_alpha2s[] = {
157 static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = {
161 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
162 REG_RULE(2484-10, 2484+10, 40, 0, 20, 0),
163 REG_RULE(5150-10, 5240+10, 40, 0, 30, 0),
164 REG_RULE(5745-10, 5825+10, 40, 0, 30, 0),
165 REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
169 static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = {
173 REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
174 REG_RULE(5725-10, 5850+10, 40, 0, 30,
176 REG_RULE(5855-10, 5925+10, 40, 0, 33, 0),
180 static const struct ieee80211_regdomain hwsim_world_regdom_custom_03 = {
184 REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0),
185 REG_RULE(2484 - 10, 2484 + 10, 40, 0, 20, 0),
186 REG_RULE(5150 - 10, 5240 + 10, 40, 0, 30, 0),
187 REG_RULE(5745 - 10, 5825 + 10, 40, 0, 30, 0),
188 REG_RULE(5855 - 10, 5925 + 10, 40, 0, 33, 0),
189 REG_RULE(5955 - 10, 7125 + 10, 320, 0, 33, 0),
193 static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = {
194 &hwsim_world_regdom_custom_01,
195 &hwsim_world_regdom_custom_02,
196 &hwsim_world_regdom_custom_03,
199 struct hwsim_vif_priv {
207 #define HWSIM_VIF_MAGIC 0x69537748
209 static inline void hwsim_check_magic(struct ieee80211_vif *vif)
211 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
212 WARN(vp->magic != HWSIM_VIF_MAGIC,
213 "Invalid VIF (%p) magic %#x, %pM, %d/%d\n",
214 vif, vp->magic, vif->addr, vif->type, vif->p2p);
217 static inline void hwsim_set_magic(struct ieee80211_vif *vif)
219 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
220 vp->magic = HWSIM_VIF_MAGIC;
223 static inline void hwsim_clear_magic(struct ieee80211_vif *vif)
225 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
229 struct hwsim_sta_priv {
231 unsigned int last_link;
234 #define HWSIM_STA_MAGIC 0x6d537749
236 static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
238 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
239 WARN_ON(sp->magic != HWSIM_STA_MAGIC);
242 static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
244 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
245 sp->magic = HWSIM_STA_MAGIC;
248 static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
250 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
254 struct hwsim_chanctx_priv {
258 #define HWSIM_CHANCTX_MAGIC 0x6d53774a
260 static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c)
262 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
263 WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC);
266 static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c)
268 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
269 cp->magic = HWSIM_CHANCTX_MAGIC;
272 static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c)
274 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
278 static unsigned int hwsim_net_id;
280 static DEFINE_IDA(hwsim_netgroup_ida);
287 static inline int hwsim_net_get_netgroup(struct net *net)
289 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
291 return hwsim_net->netgroup;
294 static inline int hwsim_net_set_netgroup(struct net *net)
296 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
298 hwsim_net->netgroup = ida_alloc(&hwsim_netgroup_ida, GFP_KERNEL);
299 return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM;
302 static inline u32 hwsim_net_get_wmediumd(struct net *net)
304 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
306 return hwsim_net->wmediumd;
309 static inline void hwsim_net_set_wmediumd(struct net *net, u32 portid)
311 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
313 hwsim_net->wmediumd = portid;
316 static struct class *hwsim_class;
318 static struct net_device *hwsim_mon; /* global monitor netdev */
320 #define CHAN2G(_freq) { \
321 .band = NL80211_BAND_2GHZ, \
322 .center_freq = (_freq), \
323 .hw_value = (_freq), \
326 #define CHAN5G(_freq) { \
327 .band = NL80211_BAND_5GHZ, \
328 .center_freq = (_freq), \
329 .hw_value = (_freq), \
332 #define CHAN6G(_freq) { \
333 .band = NL80211_BAND_6GHZ, \
334 .center_freq = (_freq), \
335 .hw_value = (_freq), \
338 static const struct ieee80211_channel hwsim_channels_2ghz[] = {
339 CHAN2G(2412), /* Channel 1 */
340 CHAN2G(2417), /* Channel 2 */
341 CHAN2G(2422), /* Channel 3 */
342 CHAN2G(2427), /* Channel 4 */
343 CHAN2G(2432), /* Channel 5 */
344 CHAN2G(2437), /* Channel 6 */
345 CHAN2G(2442), /* Channel 7 */
346 CHAN2G(2447), /* Channel 8 */
347 CHAN2G(2452), /* Channel 9 */
348 CHAN2G(2457), /* Channel 10 */
349 CHAN2G(2462), /* Channel 11 */
350 CHAN2G(2467), /* Channel 12 */
351 CHAN2G(2472), /* Channel 13 */
352 CHAN2G(2484), /* Channel 14 */
355 static const struct ieee80211_channel hwsim_channels_5ghz[] = {
356 CHAN5G(5180), /* Channel 36 */
357 CHAN5G(5200), /* Channel 40 */
358 CHAN5G(5220), /* Channel 44 */
359 CHAN5G(5240), /* Channel 48 */
361 CHAN5G(5260), /* Channel 52 */
362 CHAN5G(5280), /* Channel 56 */
363 CHAN5G(5300), /* Channel 60 */
364 CHAN5G(5320), /* Channel 64 */
366 CHAN5G(5500), /* Channel 100 */
367 CHAN5G(5520), /* Channel 104 */
368 CHAN5G(5540), /* Channel 108 */
369 CHAN5G(5560), /* Channel 112 */
370 CHAN5G(5580), /* Channel 116 */
371 CHAN5G(5600), /* Channel 120 */
372 CHAN5G(5620), /* Channel 124 */
373 CHAN5G(5640), /* Channel 128 */
374 CHAN5G(5660), /* Channel 132 */
375 CHAN5G(5680), /* Channel 136 */
376 CHAN5G(5700), /* Channel 140 */
378 CHAN5G(5745), /* Channel 149 */
379 CHAN5G(5765), /* Channel 153 */
380 CHAN5G(5785), /* Channel 157 */
381 CHAN5G(5805), /* Channel 161 */
382 CHAN5G(5825), /* Channel 165 */
383 CHAN5G(5845), /* Channel 169 */
385 CHAN5G(5855), /* Channel 171 */
386 CHAN5G(5860), /* Channel 172 */
387 CHAN5G(5865), /* Channel 173 */
388 CHAN5G(5870), /* Channel 174 */
390 CHAN5G(5875), /* Channel 175 */
391 CHAN5G(5880), /* Channel 176 */
392 CHAN5G(5885), /* Channel 177 */
393 CHAN5G(5890), /* Channel 178 */
394 CHAN5G(5895), /* Channel 179 */
395 CHAN5G(5900), /* Channel 180 */
396 CHAN5G(5905), /* Channel 181 */
398 CHAN5G(5910), /* Channel 182 */
399 CHAN5G(5915), /* Channel 183 */
400 CHAN5G(5920), /* Channel 184 */
401 CHAN5G(5925), /* Channel 185 */
404 static const struct ieee80211_channel hwsim_channels_6ghz[] = {
405 CHAN6G(5955), /* Channel 1 */
406 CHAN6G(5975), /* Channel 5 */
407 CHAN6G(5995), /* Channel 9 */
408 CHAN6G(6015), /* Channel 13 */
409 CHAN6G(6035), /* Channel 17 */
410 CHAN6G(6055), /* Channel 21 */
411 CHAN6G(6075), /* Channel 25 */
412 CHAN6G(6095), /* Channel 29 */
413 CHAN6G(6115), /* Channel 33 */
414 CHAN6G(6135), /* Channel 37 */
415 CHAN6G(6155), /* Channel 41 */
416 CHAN6G(6175), /* Channel 45 */
417 CHAN6G(6195), /* Channel 49 */
418 CHAN6G(6215), /* Channel 53 */
419 CHAN6G(6235), /* Channel 57 */
420 CHAN6G(6255), /* Channel 61 */
421 CHAN6G(6275), /* Channel 65 */
422 CHAN6G(6295), /* Channel 69 */
423 CHAN6G(6315), /* Channel 73 */
424 CHAN6G(6335), /* Channel 77 */
425 CHAN6G(6355), /* Channel 81 */
426 CHAN6G(6375), /* Channel 85 */
427 CHAN6G(6395), /* Channel 89 */
428 CHAN6G(6415), /* Channel 93 */
429 CHAN6G(6435), /* Channel 97 */
430 CHAN6G(6455), /* Channel 181 */
431 CHAN6G(6475), /* Channel 105 */
432 CHAN6G(6495), /* Channel 109 */
433 CHAN6G(6515), /* Channel 113 */
434 CHAN6G(6535), /* Channel 117 */
435 CHAN6G(6555), /* Channel 121 */
436 CHAN6G(6575), /* Channel 125 */
437 CHAN6G(6595), /* Channel 129 */
438 CHAN6G(6615), /* Channel 133 */
439 CHAN6G(6635), /* Channel 137 */
440 CHAN6G(6655), /* Channel 141 */
441 CHAN6G(6675), /* Channel 145 */
442 CHAN6G(6695), /* Channel 149 */
443 CHAN6G(6715), /* Channel 153 */
444 CHAN6G(6735), /* Channel 157 */
445 CHAN6G(6755), /* Channel 161 */
446 CHAN6G(6775), /* Channel 165 */
447 CHAN6G(6795), /* Channel 169 */
448 CHAN6G(6815), /* Channel 173 */
449 CHAN6G(6835), /* Channel 177 */
450 CHAN6G(6855), /* Channel 181 */
451 CHAN6G(6875), /* Channel 185 */
452 CHAN6G(6895), /* Channel 189 */
453 CHAN6G(6915), /* Channel 193 */
454 CHAN6G(6935), /* Channel 197 */
455 CHAN6G(6955), /* Channel 201 */
456 CHAN6G(6975), /* Channel 205 */
457 CHAN6G(6995), /* Channel 209 */
458 CHAN6G(7015), /* Channel 213 */
459 CHAN6G(7035), /* Channel 217 */
460 CHAN6G(7055), /* Channel 221 */
461 CHAN6G(7075), /* Channel 225 */
462 CHAN6G(7095), /* Channel 229 */
463 CHAN6G(7115), /* Channel 233 */
466 #define NUM_S1G_CHANS_US 51
467 static struct ieee80211_channel hwsim_channels_s1g[NUM_S1G_CHANS_US];
469 static const struct ieee80211_sta_s1g_cap hwsim_s1g_cap = {
471 .cap = { S1G_CAP0_SGI_1MHZ | S1G_CAP0_SGI_2MHZ,
474 S1G_CAP3_MAX_MPDU_LEN,
479 S1G_CAP8_TWT_RESPOND | S1G_CAP8_TWT_REQUEST,
481 .nss_mcs = { 0xfc | 1, /* MCS 7 for 1 SS */
482 /* RX Highest Supported Long GI Data Rate 0:7 */
484 /* RX Highest Supported Long GI Data Rate 0:7 */
485 /* TX S1G MCS Map 0:6 */
487 /* TX S1G MCS Map :7 */
488 /* TX Highest Supported Long GI Data Rate 0:6 */
490 /* TX Highest Supported Long GI Data Rate 7:8 */
491 /* Rx Single spatial stream and S1G-MCS Map for 1MHz */
492 /* Tx Single spatial stream and S1G-MCS Map for 1MHz */
496 static void hwsim_init_s1g_channels(struct ieee80211_channel *chans)
500 for (ch = 0; ch < NUM_S1G_CHANS_US; ch++) {
501 freq = 902000 + (ch + 1) * 500;
502 chans[ch].band = NL80211_BAND_S1GHZ;
503 chans[ch].center_freq = KHZ_TO_MHZ(freq);
504 chans[ch].freq_offset = freq % 1000;
505 chans[ch].hw_value = ch + 1;
509 static const struct ieee80211_rate hwsim_rates[] = {
511 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
512 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
513 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
524 #define DEFAULT_RX_RSSI -50
526 static const u32 hwsim_ciphers[] = {
527 WLAN_CIPHER_SUITE_WEP40,
528 WLAN_CIPHER_SUITE_WEP104,
529 WLAN_CIPHER_SUITE_TKIP,
530 WLAN_CIPHER_SUITE_CCMP,
531 WLAN_CIPHER_SUITE_CCMP_256,
532 WLAN_CIPHER_SUITE_GCMP,
533 WLAN_CIPHER_SUITE_GCMP_256,
534 WLAN_CIPHER_SUITE_AES_CMAC,
535 WLAN_CIPHER_SUITE_BIP_CMAC_256,
536 WLAN_CIPHER_SUITE_BIP_GMAC_128,
537 WLAN_CIPHER_SUITE_BIP_GMAC_256,
540 #define OUI_QCA 0x001374
541 #define QCA_NL80211_SUBCMD_TEST 1
542 enum qca_nl80211_vendor_subcmds {
543 QCA_WLAN_VENDOR_ATTR_TEST = 8,
544 QCA_WLAN_VENDOR_ATTR_MAX = QCA_WLAN_VENDOR_ATTR_TEST
547 static const struct nla_policy
548 hwsim_vendor_test_policy[QCA_WLAN_VENDOR_ATTR_MAX + 1] = {
549 [QCA_WLAN_VENDOR_ATTR_MAX] = { .type = NLA_U32 },
552 static int mac80211_hwsim_vendor_cmd_test(struct wiphy *wiphy,
553 struct wireless_dev *wdev,
554 const void *data, int data_len)
557 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
561 err = nla_parse_deprecated(tb, QCA_WLAN_VENDOR_ATTR_MAX, data,
562 data_len, hwsim_vendor_test_policy, NULL);
565 if (!tb[QCA_WLAN_VENDOR_ATTR_TEST])
567 val = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_TEST]);
568 wiphy_dbg(wiphy, "%s: test=%u\n", __func__, val);
570 /* Send a vendor event as a test. Note that this would not normally be
571 * done within a command handler, but rather, based on some other
572 * trigger. For simplicity, this command is used to trigger the event
575 * event_idx = 0 (index in mac80211_hwsim_vendor_commands)
577 skb = cfg80211_vendor_event_alloc(wiphy, wdev, 100, 0, GFP_KERNEL);
579 /* skb_put() or nla_put() will fill up data within
580 * NL80211_ATTR_VENDOR_DATA.
583 /* Add vendor data */
584 nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 1);
586 /* Send the event - this will call nla_nest_end() */
587 cfg80211_vendor_event(skb, GFP_KERNEL);
590 /* Send a response to the command */
591 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, 10);
595 /* skb_put() or nla_put() will fill up data within
596 * NL80211_ATTR_VENDOR_DATA
598 nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 2);
600 return cfg80211_vendor_cmd_reply(skb);
603 static struct wiphy_vendor_command mac80211_hwsim_vendor_commands[] = {
605 .info = { .vendor_id = OUI_QCA,
606 .subcmd = QCA_NL80211_SUBCMD_TEST },
607 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV,
608 .doit = mac80211_hwsim_vendor_cmd_test,
609 .policy = hwsim_vendor_test_policy,
610 .maxattr = QCA_WLAN_VENDOR_ATTR_MAX,
614 /* Advertise support vendor specific events */
615 static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events[] = {
616 { .vendor_id = OUI_QCA, .subcmd = 1 },
619 static DEFINE_SPINLOCK(hwsim_radio_lock);
620 static LIST_HEAD(hwsim_radios);
621 static struct rhashtable hwsim_radios_rht;
622 static int hwsim_radio_idx;
623 static int hwsim_radios_generation = 1;
625 static struct platform_driver mac80211_hwsim_driver = {
627 .name = "mac80211_hwsim",
631 struct mac80211_hwsim_link_data {
633 u64 beacon_int /* beacon interval in us */;
634 struct hrtimer beacon_timer;
637 struct mac80211_hwsim_data {
638 struct list_head list;
639 struct rhash_head rht;
640 struct ieee80211_hw *hw;
642 struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
643 struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)];
644 struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)];
645 struct ieee80211_channel channels_6ghz[ARRAY_SIZE(hwsim_channels_6ghz)];
646 struct ieee80211_channel channels_s1g[ARRAY_SIZE(hwsim_channels_s1g)];
647 struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
648 struct ieee80211_iface_combination if_combination;
649 struct ieee80211_iface_limit if_limits[3];
652 u32 ciphers[ARRAY_SIZE(hwsim_ciphers)];
654 struct mac_address addresses[2];
657 bool destroy_on_close;
660 const struct ieee80211_regdomain *regd;
662 struct ieee80211_channel *tmp_chan;
663 struct ieee80211_channel *roc_chan;
665 struct delayed_work roc_start;
666 struct delayed_work roc_done;
667 struct delayed_work hw_scan;
668 struct cfg80211_scan_request *hw_scan_request;
669 struct ieee80211_vif *hw_scan_vif;
671 u8 scan_addr[ETH_ALEN];
673 struct ieee80211_channel *channel;
674 unsigned long next_start, start, end;
675 } survey_data[ARRAY_SIZE(hwsim_channels_2ghz) +
676 ARRAY_SIZE(hwsim_channels_5ghz) +
677 ARRAY_SIZE(hwsim_channels_6ghz)];
679 struct ieee80211_channel *channel;
680 enum nl80211_chan_width bw;
681 unsigned int rx_filter;
682 bool started, idle, scanning;
685 PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
687 bool ps_poll_pending;
688 struct dentry *debugfs;
690 atomic_t pending_cookie;
691 struct sk_buff_head pending; /* packets pending */
693 * Only radios in the same group can communicate together (the
694 * channel has to match too). Each bit represents a group. A
695 * radio can be in more than one group.
699 /* group shared by radios created in the same netns */
701 /* wmediumd portid responsible for netgroup of this radio */
704 /* difference between this hw's clock and the real clock, in usecs */
707 /* absolute beacon transmission time. Used to cover up "tx" delay. */
718 /* RSSI in rx status of the receiver */
721 struct mac80211_hwsim_link_data link_data[IEEE80211_MLD_MAX_NUM_LINKS];
724 static const struct rhashtable_params hwsim_rht_params = {
726 .automatic_shrinking = true,
728 .key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]),
729 .head_offset = offsetof(struct mac80211_hwsim_data, rht),
732 struct hwsim_radiotap_hdr {
733 struct ieee80211_radiotap_header hdr;
741 struct hwsim_radiotap_ack_hdr {
742 struct ieee80211_radiotap_header hdr;
749 /* MAC80211_HWSIM netlink family */
750 static struct genl_family hwsim_genl_family;
752 enum hwsim_multicast_groups {
756 static const struct genl_multicast_group hwsim_mcgrps[] = {
757 [HWSIM_MCGRP_CONFIG] = { .name = "config", },
760 /* MAC80211_HWSIM netlink policy */
762 static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
763 [HWSIM_ATTR_ADDR_RECEIVER] = NLA_POLICY_ETH_ADDR_COMPAT,
764 [HWSIM_ATTR_ADDR_TRANSMITTER] = NLA_POLICY_ETH_ADDR_COMPAT,
765 [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY,
766 .len = IEEE80211_MAX_DATA_LEN },
767 [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 },
768 [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 },
769 [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 },
770 [HWSIM_ATTR_TX_INFO] = { .type = NLA_BINARY,
771 .len = IEEE80211_TX_MAX_RATES *
772 sizeof(struct hwsim_tx_rate)},
773 [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 },
774 [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 },
775 [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 },
776 [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 },
777 [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 },
778 [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG },
779 [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG },
780 [HWSIM_ATTR_USE_CHANCTX] = { .type = NLA_FLAG },
781 [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG },
782 [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING },
783 [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG },
784 [HWSIM_ATTR_FREQ] = { .type = NLA_U32 },
785 [HWSIM_ATTR_TX_INFO_FLAGS] = { .type = NLA_BINARY },
786 [HWSIM_ATTR_PERM_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT,
787 [HWSIM_ATTR_IFTYPE_SUPPORT] = { .type = NLA_U32 },
788 [HWSIM_ATTR_CIPHER_SUPPORT] = { .type = NLA_BINARY },
789 [HWSIM_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
792 #if IS_REACHABLE(CONFIG_VIRTIO)
794 /* MAC80211_HWSIM virtio queues */
795 static struct virtqueue *hwsim_vqs[HWSIM_NUM_VQS];
796 static bool hwsim_virtio_enabled;
797 static DEFINE_SPINLOCK(hwsim_virtio_lock);
799 static void hwsim_virtio_rx_work(struct work_struct *work);
800 static DECLARE_WORK(hwsim_virtio_rx, hwsim_virtio_rx_work);
802 static int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
805 struct scatterlist sg[1];
809 spin_lock_irqsave(&hwsim_virtio_lock, flags);
810 if (!hwsim_virtio_enabled) {
815 sg_init_one(sg, skb->head, skb_end_offset(skb));
816 err = virtqueue_add_outbuf(hwsim_vqs[HWSIM_VQ_TX], sg, 1, skb,
820 virtqueue_kick(hwsim_vqs[HWSIM_VQ_TX]);
821 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
825 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
830 /* cause a linker error if this ends up being needed */
831 extern int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
832 struct sk_buff *skb);
833 #define hwsim_virtio_enabled false
836 static int hwsim_get_chanwidth(enum nl80211_chan_width bw)
839 case NL80211_CHAN_WIDTH_20_NOHT:
840 case NL80211_CHAN_WIDTH_20:
842 case NL80211_CHAN_WIDTH_40:
844 case NL80211_CHAN_WIDTH_80:
846 case NL80211_CHAN_WIDTH_80P80:
847 case NL80211_CHAN_WIDTH_160:
849 case NL80211_CHAN_WIDTH_320:
851 case NL80211_CHAN_WIDTH_5:
853 case NL80211_CHAN_WIDTH_10:
855 case NL80211_CHAN_WIDTH_1:
857 case NL80211_CHAN_WIDTH_2:
859 case NL80211_CHAN_WIDTH_4:
861 case NL80211_CHAN_WIDTH_8:
863 case NL80211_CHAN_WIDTH_16:
870 static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
872 struct ieee80211_channel *chan);
874 /* sysfs attributes */
875 static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
877 struct mac80211_hwsim_data *data = dat;
878 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
880 struct ieee80211_pspoll *pspoll;
885 wiphy_dbg(data->hw->wiphy,
886 "%s: send PS-Poll to %pM for aid %d\n",
887 __func__, vp->bssid, vp->aid);
889 skb = dev_alloc_skb(sizeof(*pspoll));
892 pspoll = skb_put(skb, sizeof(*pspoll));
893 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
894 IEEE80211_STYPE_PSPOLL |
896 pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
897 memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
898 memcpy(pspoll->ta, mac, ETH_ALEN);
901 mac80211_hwsim_tx_frame(data->hw, skb,
902 rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
906 static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
907 struct ieee80211_vif *vif, int ps)
909 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
911 struct ieee80211_hdr *hdr;
916 wiphy_dbg(data->hw->wiphy,
917 "%s: send data::nullfunc to %pM ps=%d\n",
918 __func__, vp->bssid, ps);
920 skb = dev_alloc_skb(sizeof(*hdr));
923 hdr = skb_put(skb, sizeof(*hdr) - ETH_ALEN);
924 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
925 IEEE80211_STYPE_NULLFUNC |
926 IEEE80211_FCTL_TODS |
927 (ps ? IEEE80211_FCTL_PM : 0));
928 hdr->duration_id = cpu_to_le16(0);
929 memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
930 memcpy(hdr->addr2, mac, ETH_ALEN);
931 memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
934 mac80211_hwsim_tx_frame(data->hw, skb,
935 rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
940 static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
941 struct ieee80211_vif *vif)
943 struct mac80211_hwsim_data *data = dat;
944 hwsim_send_nullfunc(data, mac, vif, 1);
947 static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
948 struct ieee80211_vif *vif)
950 struct mac80211_hwsim_data *data = dat;
951 hwsim_send_nullfunc(data, mac, vif, 0);
954 static int hwsim_fops_ps_read(void *dat, u64 *val)
956 struct mac80211_hwsim_data *data = dat;
961 static int hwsim_fops_ps_write(void *dat, u64 val)
963 struct mac80211_hwsim_data *data = dat;
966 if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
967 val != PS_MANUAL_POLL)
970 if (val == PS_MANUAL_POLL) {
971 if (data->ps != PS_ENABLED)
974 ieee80211_iterate_active_interfaces_atomic(
975 data->hw, IEEE80211_IFACE_ITER_NORMAL,
976 hwsim_send_ps_poll, data);
984 if (old_ps == PS_DISABLED && val != PS_DISABLED) {
985 ieee80211_iterate_active_interfaces_atomic(
986 data->hw, IEEE80211_IFACE_ITER_NORMAL,
987 hwsim_send_nullfunc_ps, data);
988 } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
989 ieee80211_iterate_active_interfaces_atomic(
990 data->hw, IEEE80211_IFACE_ITER_NORMAL,
991 hwsim_send_nullfunc_no_ps, data);
998 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
1001 static int hwsim_write_simulate_radar(void *dat, u64 val)
1003 struct mac80211_hwsim_data *data = dat;
1005 ieee80211_radar_detected(data->hw);
1010 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_simulate_radar, NULL,
1011 hwsim_write_simulate_radar, "%llu\n");
1013 static int hwsim_fops_group_read(void *dat, u64 *val)
1015 struct mac80211_hwsim_data *data = dat;
1020 static int hwsim_fops_group_write(void *dat, u64 val)
1022 struct mac80211_hwsim_data *data = dat;
1027 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group,
1028 hwsim_fops_group_read, hwsim_fops_group_write,
1031 static int hwsim_fops_rx_rssi_read(void *dat, u64 *val)
1033 struct mac80211_hwsim_data *data = dat;
1034 *val = data->rx_rssi;
1038 static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
1040 struct mac80211_hwsim_data *data = dat;
1041 int rssi = (int)val;
1043 if (rssi >= 0 || rssi < -100)
1046 data->rx_rssi = rssi;
1050 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_rx_rssi,
1051 hwsim_fops_rx_rssi_read, hwsim_fops_rx_rssi_write,
1054 static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb,
1055 struct net_device *dev)
1057 /* TODO: allow packet injection */
1059 return NETDEV_TX_OK;
1062 static inline u64 mac80211_hwsim_get_tsf_raw(void)
1064 return ktime_to_us(ktime_get_real());
1067 static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
1069 u64 now = mac80211_hwsim_get_tsf_raw();
1070 return cpu_to_le64(now + data->tsf_offset);
1073 static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw,
1074 struct ieee80211_vif *vif)
1076 struct mac80211_hwsim_data *data = hw->priv;
1077 return le64_to_cpu(__mac80211_hwsim_get_tsf(data));
1080 static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw,
1081 struct ieee80211_vif *vif, u64 tsf)
1083 struct mac80211_hwsim_data *data = hw->priv;
1084 u64 now = mac80211_hwsim_get_tsf(hw, vif);
1085 /* MLD not supported here */
1086 u32 bcn_int = data->link_data[0].beacon_int;
1087 u64 delta = abs(tsf - now);
1089 /* adjust after beaconing with new timestamp at old TBTT */
1091 data->tsf_offset += delta;
1092 data->bcn_delta = do_div(delta, bcn_int);
1094 data->tsf_offset -= delta;
1095 data->bcn_delta = -(s64)do_div(delta, bcn_int);
1099 static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
1100 struct sk_buff *tx_skb,
1101 struct ieee80211_channel *chan)
1103 struct mac80211_hwsim_data *data = hw->priv;
1104 struct sk_buff *skb;
1105 struct hwsim_radiotap_hdr *hdr;
1107 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
1108 struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
1113 bitrate = txrate->bitrate;
1115 if (!netif_running(hwsim_mon))
1118 skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
1122 hdr = skb_push(skb, sizeof(*hdr));
1123 hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
1124 hdr->hdr.it_pad = 0;
1125 hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
1126 hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1127 (1 << IEEE80211_RADIOTAP_RATE) |
1128 (1 << IEEE80211_RADIOTAP_TSFT) |
1129 (1 << IEEE80211_RADIOTAP_CHANNEL));
1130 hdr->rt_tsft = __mac80211_hwsim_get_tsf(data);
1132 hdr->rt_rate = bitrate / 5;
1133 hdr->rt_channel = cpu_to_le16(chan->center_freq);
1134 flags = IEEE80211_CHAN_2GHZ;
1135 if (txrate && txrate->flags & IEEE80211_RATE_ERP_G)
1136 flags |= IEEE80211_CHAN_OFDM;
1138 flags |= IEEE80211_CHAN_CCK;
1139 hdr->rt_chbitmask = cpu_to_le16(flags);
1141 skb->dev = hwsim_mon;
1142 skb_reset_mac_header(skb);
1143 skb->ip_summed = CHECKSUM_UNNECESSARY;
1144 skb->pkt_type = PACKET_OTHERHOST;
1145 skb->protocol = htons(ETH_P_802_2);
1146 memset(skb->cb, 0, sizeof(skb->cb));
1151 static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan,
1154 struct sk_buff *skb;
1155 struct hwsim_radiotap_ack_hdr *hdr;
1157 struct ieee80211_hdr *hdr11;
1159 if (!netif_running(hwsim_mon))
1162 skb = dev_alloc_skb(100);
1166 hdr = skb_put(skb, sizeof(*hdr));
1167 hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
1168 hdr->hdr.it_pad = 0;
1169 hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
1170 hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1171 (1 << IEEE80211_RADIOTAP_CHANNEL));
1174 hdr->rt_channel = cpu_to_le16(chan->center_freq);
1175 flags = IEEE80211_CHAN_2GHZ;
1176 hdr->rt_chbitmask = cpu_to_le16(flags);
1178 hdr11 = skb_put(skb, 10);
1179 hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
1180 IEEE80211_STYPE_ACK);
1181 hdr11->duration_id = cpu_to_le16(0);
1182 memcpy(hdr11->addr1, addr, ETH_ALEN);
1184 skb->dev = hwsim_mon;
1185 skb_reset_mac_header(skb);
1186 skb->ip_summed = CHECKSUM_UNNECESSARY;
1187 skb->pkt_type = PACKET_OTHERHOST;
1188 skb->protocol = htons(ETH_P_802_2);
1189 memset(skb->cb, 0, sizeof(skb->cb));
1193 struct mac80211_hwsim_addr_match_data {
1198 static void mac80211_hwsim_addr_iter(void *data, u8 *mac,
1199 struct ieee80211_vif *vif)
1202 struct mac80211_hwsim_addr_match_data *md = data;
1204 if (memcmp(mac, md->addr, ETH_ALEN) == 0) {
1209 /* Match the link address */
1210 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1211 struct ieee80211_bss_conf *conf;
1213 conf = rcu_dereference(vif->link_conf[i]);
1217 if (memcmp(conf->addr, md->addr, ETH_ALEN) == 0) {
1224 static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
1227 struct mac80211_hwsim_addr_match_data md = {
1231 if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
1234 memcpy(md.addr, addr, ETH_ALEN);
1236 ieee80211_iterate_active_interfaces_atomic(data->hw,
1237 IEEE80211_IFACE_ITER_NORMAL,
1238 mac80211_hwsim_addr_iter,
1244 static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
1245 struct sk_buff *skb)
1253 /* TODO: accept (some) Beacons by default and other frames only
1254 * if pending PS-Poll has been sent */
1256 case PS_MANUAL_POLL:
1257 /* Allow unicast frames to own address if there is a pending
1259 if (data->ps_poll_pending &&
1260 mac80211_hwsim_addr_match(data, skb->data + 4)) {
1261 data->ps_poll_pending = false;
1270 static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
1271 struct sk_buff *skb, int portid)
1278 for_each_net_rcu(net) {
1279 if (data->netgroup == hwsim_net_get_netgroup(net)) {
1280 res = genlmsg_unicast(net, skb, portid);
1293 static void mac80211_hwsim_config_mac_nl(struct ieee80211_hw *hw,
1294 const u8 *addr, bool add)
1296 struct mac80211_hwsim_data *data = hw->priv;
1297 u32 _portid = READ_ONCE(data->wmediumd);
1298 struct sk_buff *skb;
1301 WARN_ON(!is_valid_ether_addr(addr));
1303 if (!_portid && !hwsim_virtio_enabled)
1306 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1310 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
1311 add ? HWSIM_CMD_ADD_MAC_ADDR :
1312 HWSIM_CMD_DEL_MAC_ADDR);
1314 pr_debug("mac80211_hwsim: problem with msg_head\n");
1315 goto nla_put_failure;
1318 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
1319 ETH_ALEN, data->addresses[1].addr))
1320 goto nla_put_failure;
1322 if (nla_put(skb, HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, addr))
1323 goto nla_put_failure;
1325 genlmsg_end(skb, msg_head);
1327 if (hwsim_virtio_enabled)
1328 hwsim_tx_virtio(data, skb);
1330 hwsim_unicast_netgroup(data, skb, _portid);
1336 static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate)
1340 if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1341 result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS;
1342 if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1343 result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT;
1344 if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1345 result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE;
1346 if (rate->flags & IEEE80211_TX_RC_MCS)
1347 result |= MAC80211_HWSIM_TX_RC_MCS;
1348 if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD)
1349 result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD;
1350 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1351 result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH;
1352 if (rate->flags & IEEE80211_TX_RC_DUP_DATA)
1353 result |= MAC80211_HWSIM_TX_RC_DUP_DATA;
1354 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
1355 result |= MAC80211_HWSIM_TX_RC_SHORT_GI;
1356 if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
1357 result |= MAC80211_HWSIM_TX_RC_VHT_MCS;
1358 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1359 result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH;
1360 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1361 result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH;
1366 static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
1367 struct sk_buff *my_skb,
1369 struct ieee80211_channel *channel)
1371 struct sk_buff *skb;
1372 struct mac80211_hwsim_data *data = hw->priv;
1373 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data;
1374 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb);
1376 unsigned int hwsim_flags = 0;
1378 struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
1379 struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
1382 if (data->ps != PS_DISABLED)
1383 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1384 /* If the queue contains MAX_QUEUE skb's drop some */
1385 if (skb_queue_len(&data->pending) >= MAX_QUEUE) {
1386 /* Dropping until WARN_QUEUE level */
1387 while (skb_queue_len(&data->pending) >= WARN_QUEUE) {
1388 ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
1393 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1395 goto nla_put_failure;
1397 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
1399 if (msg_head == NULL) {
1400 pr_debug("mac80211_hwsim: problem with msg_head\n");
1401 goto nla_put_failure;
1404 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
1405 ETH_ALEN, data->addresses[1].addr))
1406 goto nla_put_failure;
1408 /* We get the skb->data */
1409 if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data))
1410 goto nla_put_failure;
1412 /* We get the flags for this transmission, and we translate them to
1415 if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
1416 hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS;
1418 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
1419 hwsim_flags |= HWSIM_TX_CTL_NO_ACK;
1421 if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags))
1422 goto nla_put_failure;
1424 if (nla_put_u32(skb, HWSIM_ATTR_FREQ, channel->center_freq))
1425 goto nla_put_failure;
1427 /* We get the tx control (rate and retries) info*/
1429 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
1430 tx_attempts[i].idx = info->status.rates[i].idx;
1431 tx_attempts_flags[i].idx = info->status.rates[i].idx;
1432 tx_attempts[i].count = info->status.rates[i].count;
1433 tx_attempts_flags[i].flags =
1434 trans_tx_rate_flags_ieee2hwsim(
1435 &info->status.rates[i]);
1438 if (nla_put(skb, HWSIM_ATTR_TX_INFO,
1439 sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES,
1441 goto nla_put_failure;
1443 if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS,
1444 sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES,
1446 goto nla_put_failure;
1448 /* We create a cookie to identify this skb */
1449 cookie = atomic_inc_return(&data->pending_cookie);
1450 info->rate_driver_data[0] = (void *)cookie;
1451 if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD))
1452 goto nla_put_failure;
1454 genlmsg_end(skb, msg_head);
1456 if (hwsim_virtio_enabled) {
1457 if (hwsim_tx_virtio(data, skb))
1458 goto err_free_txskb;
1460 if (hwsim_unicast_netgroup(data, skb, dst_portid))
1461 goto err_free_txskb;
1464 /* Enqueue the packet */
1465 skb_queue_tail(&data->pending, my_skb);
1467 data->tx_bytes += my_skb->len;
1473 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
1474 ieee80211_free_txskb(hw, my_skb);
1478 static bool hwsim_chans_compat(struct ieee80211_channel *c1,
1479 struct ieee80211_channel *c2)
1484 return c1->center_freq == c2->center_freq;
1487 struct tx_iter_data {
1488 struct ieee80211_channel *channel;
1492 static void mac80211_hwsim_tx_iter(void *_data, u8 *addr,
1493 struct ieee80211_vif *vif)
1495 struct tx_iter_data *data = _data;
1498 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1499 struct ieee80211_bss_conf *conf;
1500 struct ieee80211_chanctx_conf *chanctx;
1502 conf = rcu_dereference(vif->link_conf[i]);
1506 chanctx = rcu_dereference(conf->chanctx_conf);
1510 if (!hwsim_chans_compat(data->channel, chanctx->def.chan))
1513 data->receive = true;
1518 static void mac80211_hwsim_add_vendor_rtap(struct sk_buff *skb)
1521 * To enable this code, #define the HWSIM_RADIOTAP_OUI,
1523 * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00"
1524 * (but you should use a valid OUI, not that)
1526 * If anyone wants to 'donate' a radiotap OUI/subns code
1527 * please send a patch removing this #ifdef and changing
1528 * the values accordingly.
1530 #ifdef HWSIM_RADIOTAP_OUI
1531 struct ieee80211_vendor_radiotap *rtap;
1534 * Note that this code requires the headroom in the SKB
1535 * that was allocated earlier.
1537 rtap = skb_push(skb, sizeof(*rtap) + 8 + 4);
1538 rtap->oui[0] = HWSIM_RADIOTAP_OUI[0];
1539 rtap->oui[1] = HWSIM_RADIOTAP_OUI[1];
1540 rtap->oui[2] = HWSIM_RADIOTAP_OUI[2];
1544 * Radiotap vendor namespaces can (and should) also be
1545 * split into fields by using the standard radiotap
1546 * presence bitmap mechanism. Use just BIT(0) here for
1547 * the presence bitmap.
1549 rtap->present = BIT(0);
1550 /* We have 8 bytes of (dummy) data */
1552 /* For testing, also require it to be aligned */
1554 /* And also test that padding works, 4 bytes */
1557 memcpy(rtap->data, "ABCDEFGH", 8);
1558 /* make sure to clear padding, mac80211 doesn't */
1559 memset(rtap->data + 8, 0, 4);
1561 IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_RADIOTAP_VENDOR_DATA;
1565 static void mac80211_hwsim_rx(struct mac80211_hwsim_data *data,
1566 struct ieee80211_rx_status *rx_status,
1567 struct sk_buff *skb)
1569 memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status));
1571 mac80211_hwsim_add_vendor_rtap(skb);
1574 data->rx_bytes += skb->len;
1575 ieee80211_rx_irqsafe(data->hw, skb);
1578 static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
1579 struct sk_buff *skb,
1580 struct ieee80211_channel *chan)
1582 struct mac80211_hwsim_data *data = hw->priv, *data2;
1584 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1585 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1586 struct ieee80211_rx_status rx_status;
1589 memset(&rx_status, 0, sizeof(rx_status));
1590 rx_status.flag |= RX_FLAG_MACTIME_START;
1591 rx_status.freq = chan->center_freq;
1592 rx_status.freq_offset = chan->freq_offset ? 1 : 0;
1593 rx_status.band = chan->band;
1594 if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
1595 rx_status.rate_idx =
1596 ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
1598 ieee80211_rate_get_vht_nss(&info->control.rates[0]);
1599 rx_status.encoding = RX_ENC_VHT;
1601 rx_status.rate_idx = info->control.rates[0].idx;
1602 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
1603 rx_status.encoding = RX_ENC_HT;
1605 if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1606 rx_status.bw = RATE_INFO_BW_40;
1607 else if (info->control.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1608 rx_status.bw = RATE_INFO_BW_80;
1609 else if (info->control.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1610 rx_status.bw = RATE_INFO_BW_160;
1612 rx_status.bw = RATE_INFO_BW_20;
1613 if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
1614 rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI;
1615 /* TODO: simulate optional packet loss */
1616 rx_status.signal = data->rx_rssi;
1617 if (info->control.vif)
1618 rx_status.signal += info->control.vif->bss_conf.txpower;
1620 if (data->ps != PS_DISABLED)
1621 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1623 /* release the skb's source info */
1631 * Get absolute mactime here so all HWs RX at the "same time", and
1632 * absolute TX time for beacon mactime so the timestamp matches.
1633 * Giving beacons a different mactime than non-beacons looks messy, but
1634 * it helps the Toffset be exact and a ~10us mactime discrepancy
1635 * probably doesn't really matter.
1637 if (ieee80211_is_beacon(hdr->frame_control) ||
1638 ieee80211_is_probe_resp(hdr->frame_control)) {
1639 rx_status.boottime_ns = ktime_get_boottime_ns();
1640 now = data->abs_bcn_ts;
1642 now = mac80211_hwsim_get_tsf_raw();
1645 /* Copy skb to all enabled radios that are on the current frequency */
1646 spin_lock(&hwsim_radio_lock);
1647 list_for_each_entry(data2, &hwsim_radios, list) {
1648 struct sk_buff *nskb;
1649 struct tx_iter_data tx_iter_data = {
1657 if (!data2->started || (data2->idle && !data2->tmp_chan) ||
1658 !hwsim_ps_rx_ok(data2, skb))
1661 if (!(data->group & data2->group))
1664 if (data->netgroup != data2->netgroup)
1667 if (!hwsim_chans_compat(chan, data2->tmp_chan) &&
1668 !hwsim_chans_compat(chan, data2->channel)) {
1669 ieee80211_iterate_active_interfaces_atomic(
1670 data2->hw, IEEE80211_IFACE_ITER_NORMAL,
1671 mac80211_hwsim_tx_iter, &tx_iter_data);
1672 if (!tx_iter_data.receive)
1677 * reserve some space for our vendor and the normal
1678 * radiotap header, since we're copying anyway
1680 if (skb->len < PAGE_SIZE && paged_rx) {
1681 struct page *page = alloc_page(GFP_ATOMIC);
1686 nskb = dev_alloc_skb(128);
1692 memcpy(page_address(page), skb->data, skb->len);
1693 skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len);
1695 nskb = skb_copy(skb, GFP_ATOMIC);
1700 if (mac80211_hwsim_addr_match(data2, hdr->addr1))
1703 rx_status.mactime = now + data2->tsf_offset;
1705 mac80211_hwsim_rx(data2, &rx_status, nskb);
1707 spin_unlock(&hwsim_radio_lock);
1712 static struct ieee80211_bss_conf *
1713 mac80211_hwsim_select_tx_link(struct mac80211_hwsim_data *data,
1714 struct ieee80211_vif *vif,
1715 struct ieee80211_sta *sta,
1716 struct ieee80211_hdr *hdr,
1717 struct ieee80211_link_sta **link_sta)
1719 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
1722 if (!vif->valid_links)
1723 return &vif->bss_conf;
1725 WARN_ON(is_multicast_ether_addr(hdr->addr1));
1727 if (WARN_ON_ONCE(!sta->valid_links))
1728 return &vif->bss_conf;
1730 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1731 struct ieee80211_bss_conf *bss_conf;
1732 unsigned int link_id;
1734 /* round-robin the available link IDs */
1735 link_id = (sp->last_link + i + 1) % ARRAY_SIZE(vif->link_conf);
1737 *link_sta = rcu_dereference(sta->link[link_id]);
1741 bss_conf = rcu_dereference(vif->link_conf[link_id]);
1742 if (WARN_ON_ONCE(!bss_conf))
1745 sp->last_link = link_id;
1752 static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
1753 struct ieee80211_tx_control *control,
1754 struct sk_buff *skb)
1756 struct mac80211_hwsim_data *data = hw->priv;
1757 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
1758 struct ieee80211_hdr *hdr = (void *)skb->data;
1759 struct ieee80211_chanctx_conf *chanctx_conf;
1760 struct ieee80211_channel *channel;
1762 enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
1765 if (WARN_ON(skb->len < 10)) {
1766 /* Should not happen; just a sanity check for addr1 use */
1767 ieee80211_free_txskb(hw, skb);
1771 if (!data->use_chanctx) {
1772 channel = data->channel;
1774 } else if (txi->hw_queue == 4) {
1775 channel = data->tmp_chan;
1777 u8 link = u32_get_bits(IEEE80211_SKB_CB(skb)->control.flags,
1778 IEEE80211_TX_CTRL_MLO_LINK);
1779 struct ieee80211_vif *vif = txi->control.vif;
1780 struct ieee80211_link_sta *link_sta = NULL;
1781 struct ieee80211_sta *sta = control->sta;
1782 struct ieee80211_bss_conf *bss_conf;
1784 if (link != IEEE80211_LINK_UNSPECIFIED) {
1785 bss_conf = rcu_dereference(txi->control.vif->link_conf[link]);
1787 link_sta = rcu_dereference(sta->link[link]);
1789 bss_conf = mac80211_hwsim_select_tx_link(data, vif, sta,
1793 if (WARN_ON(!bss_conf)) {
1794 ieee80211_free_txskb(hw, skb);
1798 if (sta && sta->mlo) {
1799 if (WARN_ON(!link_sta)) {
1800 ieee80211_free_txskb(hw, skb);
1803 /* address translation to link addresses on TX */
1804 ether_addr_copy(hdr->addr1, link_sta->addr);
1805 ether_addr_copy(hdr->addr2, bss_conf->addr);
1806 /* translate A3 only if it's the BSSID */
1807 if (!ieee80211_has_tods(hdr->frame_control) &&
1808 !ieee80211_has_fromds(hdr->frame_control)) {
1809 if (ether_addr_equal(hdr->addr3, sta->addr))
1810 ether_addr_copy(hdr->addr3, link_sta->addr);
1811 else if (ether_addr_equal(hdr->addr3, vif->addr))
1812 ether_addr_copy(hdr->addr3, bss_conf->addr);
1814 /* no need to look at A4, if present it's SA */
1817 chanctx_conf = rcu_dereference(bss_conf->chanctx_conf);
1819 channel = chanctx_conf->def.chan;
1820 confbw = chanctx_conf->def.width;
1826 if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) {
1827 ieee80211_free_txskb(hw, skb);
1831 if (data->idle && !data->tmp_chan) {
1832 wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n");
1833 ieee80211_free_txskb(hw, skb);
1837 if (txi->control.vif)
1838 hwsim_check_magic(txi->control.vif);
1840 hwsim_check_sta_magic(control->sta);
1842 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
1843 ieee80211_get_tx_rates(txi->control.vif, control->sta, skb,
1845 ARRAY_SIZE(txi->control.rates));
1847 for (i = 0; i < ARRAY_SIZE(txi->control.rates); i++) {
1848 u16 rflags = txi->control.rates[i].flags;
1849 /* initialize to data->bw for 5/10 MHz handling */
1850 enum nl80211_chan_width bw = data->bw;
1852 if (txi->control.rates[i].idx == -1)
1855 if (rflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1856 bw = NL80211_CHAN_WIDTH_40;
1857 else if (rflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1858 bw = NL80211_CHAN_WIDTH_80;
1859 else if (rflags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1860 bw = NL80211_CHAN_WIDTH_160;
1862 if (WARN_ON(hwsim_get_chanwidth(bw) > hwsim_get_chanwidth(confbw)))
1866 if (skb->len >= 24 + 8 &&
1867 ieee80211_is_probe_resp(hdr->frame_control)) {
1868 /* fake header transmission time */
1869 struct ieee80211_mgmt *mgmt;
1870 struct ieee80211_rate *txrate;
1875 mgmt = (struct ieee80211_mgmt *)skb->data;
1876 txrate = ieee80211_get_tx_rate(hw, txi);
1878 bitrate = txrate->bitrate;
1879 ts = mac80211_hwsim_get_tsf_raw();
1880 mgmt->u.probe_resp.timestamp =
1881 cpu_to_le64(ts + data->tsf_offset +
1882 24 * 8 * 10 / bitrate);
1885 mac80211_hwsim_monitor_rx(hw, skb, channel);
1887 /* wmediumd mode check */
1888 _portid = READ_ONCE(data->wmediumd);
1890 if (_portid || hwsim_virtio_enabled)
1891 return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, channel);
1893 /* NO wmediumd detected, perfect medium simulation */
1895 data->tx_bytes += skb->len;
1896 ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel);
1898 if (ack && skb->len >= 16)
1899 mac80211_hwsim_monitor_ack(channel, hdr->addr2);
1901 ieee80211_tx_info_clear_status(txi);
1903 /* frame was transmitted at most favorable rate at first attempt */
1904 txi->control.rates[0].count = 1;
1905 txi->control.rates[1].idx = -1;
1907 if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
1908 txi->flags |= IEEE80211_TX_STAT_ACK;
1909 ieee80211_tx_status_irqsafe(hw, skb);
1913 static int mac80211_hwsim_start(struct ieee80211_hw *hw)
1915 struct mac80211_hwsim_data *data = hw->priv;
1916 wiphy_dbg(hw->wiphy, "%s\n", __func__);
1917 data->started = true;
1922 static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
1924 struct mac80211_hwsim_data *data = hw->priv;
1927 data->started = false;
1929 for (i = 0; i < ARRAY_SIZE(data->link_data); i++)
1930 hrtimer_cancel(&data->link_data[i].beacon_timer);
1932 while (!skb_queue_empty(&data->pending))
1933 ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
1935 wiphy_dbg(hw->wiphy, "%s\n", __func__);
1939 static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
1940 struct ieee80211_vif *vif)
1942 wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
1943 __func__, ieee80211_vif_type_p2p(vif),
1945 hwsim_set_magic(vif);
1947 if (vif->type != NL80211_IFTYPE_MONITOR)
1948 mac80211_hwsim_config_mac_nl(hw, vif->addr, true);
1951 vif->hw_queue[IEEE80211_AC_VO] = 0;
1952 vif->hw_queue[IEEE80211_AC_VI] = 1;
1953 vif->hw_queue[IEEE80211_AC_BE] = 2;
1954 vif->hw_queue[IEEE80211_AC_BK] = 3;
1960 static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw,
1961 struct ieee80211_vif *vif,
1962 enum nl80211_iftype newtype,
1965 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1966 wiphy_dbg(hw->wiphy,
1967 "%s (old type=%d, new type=%d, mac_addr=%pM)\n",
1968 __func__, ieee80211_vif_type_p2p(vif),
1969 newtype, vif->addr);
1970 hwsim_check_magic(vif);
1973 * interface may change from non-AP to AP in
1974 * which case this needs to be set up again
1981 static void mac80211_hwsim_remove_interface(
1982 struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1984 wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
1985 __func__, ieee80211_vif_type_p2p(vif),
1987 hwsim_check_magic(vif);
1988 hwsim_clear_magic(vif);
1989 if (vif->type != NL80211_IFTYPE_MONITOR)
1990 mac80211_hwsim_config_mac_nl(hw, vif->addr, false);
1993 static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
1994 struct sk_buff *skb,
1995 struct ieee80211_channel *chan)
1997 struct mac80211_hwsim_data *data = hw->priv;
1998 u32 _pid = READ_ONCE(data->wmediumd);
2000 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) {
2001 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
2002 ieee80211_get_tx_rates(txi->control.vif, NULL, skb,
2004 ARRAY_SIZE(txi->control.rates));
2007 mac80211_hwsim_monitor_rx(hw, skb, chan);
2009 if (_pid || hwsim_virtio_enabled)
2010 return mac80211_hwsim_tx_frame_nl(hw, skb, _pid, chan);
2013 data->tx_bytes += skb->len;
2014 mac80211_hwsim_tx_frame_no_nl(hw, skb, chan);
2018 static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
2019 struct ieee80211_vif *vif)
2021 struct mac80211_hwsim_link_data *link_data = arg;
2022 u32 link_id = link_data->link_id;
2023 struct ieee80211_bss_conf *link_conf;
2024 struct mac80211_hwsim_data *data =
2025 container_of(link_data, struct mac80211_hwsim_data,
2026 link_data[link_id]);
2027 struct ieee80211_hw *hw = data->hw;
2028 struct ieee80211_tx_info *info;
2029 struct ieee80211_rate *txrate;
2030 struct ieee80211_mgmt *mgmt;
2031 struct sk_buff *skb;
2035 hwsim_check_magic(vif);
2037 link_conf = rcu_dereference(vif->link_conf[link_id]);
2041 if (vif->type != NL80211_IFTYPE_AP &&
2042 vif->type != NL80211_IFTYPE_MESH_POINT &&
2043 vif->type != NL80211_IFTYPE_ADHOC &&
2044 vif->type != NL80211_IFTYPE_OCB)
2047 skb = ieee80211_beacon_get(hw, vif, link_data->link_id);
2050 info = IEEE80211_SKB_CB(skb);
2051 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
2052 ieee80211_get_tx_rates(vif, NULL, skb,
2053 info->control.rates,
2054 ARRAY_SIZE(info->control.rates));
2056 txrate = ieee80211_get_tx_rate(hw, info);
2058 bitrate = txrate->bitrate;
2060 mgmt = (struct ieee80211_mgmt *) skb->data;
2061 /* fake header transmission time */
2062 data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw();
2063 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
2064 struct ieee80211_ext *ext = (void *) mgmt;
2066 ext->u.s1g_beacon.timestamp = cpu_to_le32(data->abs_bcn_ts +
2071 mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts +
2077 mac80211_hwsim_tx_frame(hw, skb,
2078 rcu_dereference(link_conf->chanctx_conf)->def.chan);
2080 while ((skb = ieee80211_get_buffered_bc(hw, vif)) != NULL) {
2081 mac80211_hwsim_tx_frame(hw, skb,
2082 rcu_dereference(link_conf->chanctx_conf)->def.chan);
2085 if (link_conf->csa_active && ieee80211_beacon_cntdwn_is_complete(vif))
2086 ieee80211_csa_finish(vif);
2089 static enum hrtimer_restart
2090 mac80211_hwsim_beacon(struct hrtimer *timer)
2092 struct mac80211_hwsim_link_data *link_data =
2093 container_of(timer, struct mac80211_hwsim_link_data, beacon_timer);
2094 struct mac80211_hwsim_data *data =
2095 container_of(link_data, struct mac80211_hwsim_data,
2096 link_data[link_data->link_id]);
2097 struct ieee80211_hw *hw = data->hw;
2098 u64 bcn_int = link_data->beacon_int;
2101 return HRTIMER_NORESTART;
2103 ieee80211_iterate_active_interfaces_atomic(
2104 hw, IEEE80211_IFACE_ITER_NORMAL,
2105 mac80211_hwsim_beacon_tx, link_data);
2107 /* beacon at new TBTT + beacon interval */
2108 if (data->bcn_delta) {
2109 bcn_int -= data->bcn_delta;
2110 data->bcn_delta = 0;
2112 hrtimer_forward_now(&link_data->beacon_timer,
2113 ns_to_ktime(bcn_int * NSEC_PER_USEC));
2114 return HRTIMER_RESTART;
2117 static const char * const hwsim_chanwidths[] = {
2118 [NL80211_CHAN_WIDTH_5] = "ht5",
2119 [NL80211_CHAN_WIDTH_10] = "ht10",
2120 [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
2121 [NL80211_CHAN_WIDTH_20] = "ht20",
2122 [NL80211_CHAN_WIDTH_40] = "ht40",
2123 [NL80211_CHAN_WIDTH_80] = "vht80",
2124 [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
2125 [NL80211_CHAN_WIDTH_160] = "vht160",
2126 [NL80211_CHAN_WIDTH_1] = "1MHz",
2127 [NL80211_CHAN_WIDTH_2] = "2MHz",
2128 [NL80211_CHAN_WIDTH_4] = "4MHz",
2129 [NL80211_CHAN_WIDTH_8] = "8MHz",
2130 [NL80211_CHAN_WIDTH_16] = "16MHz",
2133 static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
2135 struct mac80211_hwsim_data *data = hw->priv;
2136 struct ieee80211_conf *conf = &hw->conf;
2137 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
2138 [IEEE80211_SMPS_AUTOMATIC] = "auto",
2139 [IEEE80211_SMPS_OFF] = "off",
2140 [IEEE80211_SMPS_STATIC] = "static",
2141 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
2145 if (conf->chandef.chan)
2146 wiphy_dbg(hw->wiphy,
2147 "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
2149 conf->chandef.chan->center_freq,
2150 conf->chandef.center_freq1,
2151 conf->chandef.center_freq2,
2152 hwsim_chanwidths[conf->chandef.width],
2153 !!(conf->flags & IEEE80211_CONF_IDLE),
2154 !!(conf->flags & IEEE80211_CONF_PS),
2155 smps_modes[conf->smps_mode]);
2157 wiphy_dbg(hw->wiphy,
2158 "%s (freq=0 idle=%d ps=%d smps=%s)\n",
2160 !!(conf->flags & IEEE80211_CONF_IDLE),
2161 !!(conf->flags & IEEE80211_CONF_PS),
2162 smps_modes[conf->smps_mode]);
2164 data->idle = !!(conf->flags & IEEE80211_CONF_IDLE);
2166 WARN_ON(conf->chandef.chan && data->use_chanctx);
2168 mutex_lock(&data->mutex);
2169 if (data->scanning && conf->chandef.chan) {
2170 for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
2171 if (data->survey_data[idx].channel == data->channel) {
2172 data->survey_data[idx].start =
2173 data->survey_data[idx].next_start;
2174 data->survey_data[idx].end = jiffies;
2179 data->channel = conf->chandef.chan;
2180 data->bw = conf->chandef.width;
2182 for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
2183 if (data->survey_data[idx].channel &&
2184 data->survey_data[idx].channel != data->channel)
2186 data->survey_data[idx].channel = data->channel;
2187 data->survey_data[idx].next_start = jiffies;
2191 data->channel = conf->chandef.chan;
2192 data->bw = conf->chandef.width;
2194 mutex_unlock(&data->mutex);
2196 for (idx = 0; idx < ARRAY_SIZE(data->link_data); idx++) {
2197 struct mac80211_hwsim_link_data *link_data =
2198 &data->link_data[idx];
2200 if (!data->started || !link_data->beacon_int) {
2201 hrtimer_cancel(&link_data->beacon_timer);
2202 } else if (!hrtimer_is_queued(&link_data->beacon_timer)) {
2203 u64 tsf = mac80211_hwsim_get_tsf(hw, NULL);
2204 u32 bcn_int = link_data->beacon_int;
2205 u64 until_tbtt = bcn_int - do_div(tsf, bcn_int);
2207 hrtimer_start(&link_data->beacon_timer,
2208 ns_to_ktime(until_tbtt * NSEC_PER_USEC),
2209 HRTIMER_MODE_REL_SOFT);
2217 static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
2218 unsigned int changed_flags,
2219 unsigned int *total_flags,u64 multicast)
2221 struct mac80211_hwsim_data *data = hw->priv;
2223 wiphy_dbg(hw->wiphy, "%s\n", __func__);
2225 data->rx_filter = 0;
2226 if (*total_flags & FIF_ALLMULTI)
2227 data->rx_filter |= FIF_ALLMULTI;
2228 if (*total_flags & FIF_MCAST_ACTION)
2229 data->rx_filter |= FIF_MCAST_ACTION;
2231 *total_flags = data->rx_filter;
2234 static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac,
2235 struct ieee80211_vif *vif)
2237 unsigned int *count = data;
2238 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2244 static void mac80211_hwsim_vif_info_changed(struct ieee80211_hw *hw,
2245 struct ieee80211_vif *vif,
2248 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2250 hwsim_check_magic(vif);
2252 wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM)\n",
2253 __func__, changed, vif->addr);
2255 if (changed & BSS_CHANGED_ASSOC) {
2256 wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n",
2257 vif->cfg.assoc, vif->cfg.aid);
2258 vp->assoc = vif->cfg.assoc;
2259 vp->aid = vif->cfg.aid;
2263 static void mac80211_hwsim_link_info_changed(struct ieee80211_hw *hw,
2264 struct ieee80211_vif *vif,
2265 struct ieee80211_bss_conf *info,
2268 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2269 struct mac80211_hwsim_data *data = hw->priv;
2270 unsigned int link_id = info->link_id;
2271 struct mac80211_hwsim_link_data *link_data = &data->link_data[link_id];
2273 hwsim_check_magic(vif);
2275 wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM, link id %u)\n",
2276 __func__, (unsigned long long)changed, vif->addr, link_id);
2278 if (changed & BSS_CHANGED_BSSID) {
2279 wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n",
2280 __func__, info->bssid);
2281 memcpy(vp->bssid, info->bssid, ETH_ALEN);
2284 if (changed & BSS_CHANGED_BEACON_ENABLED) {
2285 wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n",
2286 info->enable_beacon, info->beacon_int);
2287 vp->bcn_en = info->enable_beacon;
2288 if (data->started &&
2289 !hrtimer_is_queued(&link_data->beacon_timer) &&
2290 info->enable_beacon) {
2291 u64 tsf, until_tbtt;
2293 link_data->beacon_int = info->beacon_int * 1024;
2294 tsf = mac80211_hwsim_get_tsf(hw, vif);
2295 bcn_int = link_data->beacon_int;
2296 until_tbtt = bcn_int - do_div(tsf, bcn_int);
2298 hrtimer_start(&link_data->beacon_timer,
2299 ns_to_ktime(until_tbtt * NSEC_PER_USEC),
2300 HRTIMER_MODE_REL_SOFT);
2301 } else if (!info->enable_beacon) {
2302 unsigned int count = 0;
2303 ieee80211_iterate_active_interfaces_atomic(
2304 data->hw, IEEE80211_IFACE_ITER_NORMAL,
2305 mac80211_hwsim_bcn_en_iter, &count);
2306 wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u",
2309 hrtimer_cancel(&link_data->beacon_timer);
2310 link_data->beacon_int = 0;
2315 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2316 wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n",
2317 info->use_cts_prot);
2320 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2321 wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n",
2322 info->use_short_preamble);
2325 if (changed & BSS_CHANGED_ERP_SLOT) {
2326 wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot);
2329 if (changed & BSS_CHANGED_HT) {
2330 wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n",
2331 info->ht_operation_mode);
2334 if (changed & BSS_CHANGED_BASIC_RATES) {
2335 wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n",
2336 (unsigned long long) info->basic_rates);
2339 if (changed & BSS_CHANGED_TXPOWER)
2340 wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower);
2344 mac80211_hwsim_sta_rc_update(struct ieee80211_hw *hw,
2345 struct ieee80211_vif *vif,
2346 struct ieee80211_sta *sta,
2349 struct mac80211_hwsim_data *data = hw->priv;
2355 link_id < ARRAY_SIZE(vif->link_conf);
2357 enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
2358 struct ieee80211_bss_conf *vif_conf;
2359 struct ieee80211_link_sta *link_sta;
2361 link_sta = rcu_dereference(sta->link[link_id]);
2366 switch (link_sta->bandwidth) {
2367 #define C(_bw) case IEEE80211_STA_RX_BW_##_bw: bw = _bw; break
2376 if (!data->use_chanctx) {
2379 struct ieee80211_chanctx_conf *chanctx_conf;
2381 vif_conf = rcu_dereference(vif->link_conf[link_id]);
2382 if (WARN_ON(!vif_conf))
2385 chanctx_conf = rcu_dereference(vif_conf->chanctx_conf);
2387 if (!WARN_ON(!chanctx_conf))
2388 confbw = chanctx_conf->def.width;
2391 WARN(bw > hwsim_get_chanwidth(confbw),
2392 "intf %pM [link=%d]: bad STA %pM bandwidth %d MHz (%d) > channel config %d MHz (%d)\n",
2393 vif->addr, link_id, sta->addr, bw, sta->deflink.bandwidth,
2394 hwsim_get_chanwidth(data->bw), data->bw);
2403 static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw,
2404 struct ieee80211_vif *vif,
2405 struct ieee80211_sta *sta)
2407 hwsim_check_magic(vif);
2408 hwsim_set_sta_magic(sta);
2409 mac80211_hwsim_sta_rc_update(hw, vif, sta, 0);
2414 static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw,
2415 struct ieee80211_vif *vif,
2416 struct ieee80211_sta *sta)
2418 hwsim_check_magic(vif);
2419 hwsim_clear_sta_magic(sta);
2424 static int mac80211_hwsim_sta_state(struct ieee80211_hw *hw,
2425 struct ieee80211_vif *vif,
2426 struct ieee80211_sta *sta,
2427 enum ieee80211_sta_state old_state,
2428 enum ieee80211_sta_state new_state)
2430 if (new_state == IEEE80211_STA_NOTEXIST)
2431 return mac80211_hwsim_sta_remove(hw, vif, sta);
2433 if (old_state == IEEE80211_STA_NOTEXIST)
2434 return mac80211_hwsim_sta_add(hw, vif, sta);
2439 static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
2440 struct ieee80211_vif *vif,
2441 enum sta_notify_cmd cmd,
2442 struct ieee80211_sta *sta)
2444 hwsim_check_magic(vif);
2447 case STA_NOTIFY_SLEEP:
2448 case STA_NOTIFY_AWAKE:
2449 /* TODO: make good use of these flags */
2452 WARN(1, "Invalid sta notify: %d\n", cmd);
2457 static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
2458 struct ieee80211_sta *sta,
2461 hwsim_check_sta_magic(sta);
2465 static int mac80211_hwsim_conf_tx(struct ieee80211_hw *hw,
2466 struct ieee80211_vif *vif,
2467 unsigned int link_id, u16 queue,
2468 const struct ieee80211_tx_queue_params *params)
2470 wiphy_dbg(hw->wiphy,
2471 "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n",
2473 params->txop, params->cw_min,
2474 params->cw_max, params->aifs);
2478 static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx,
2479 struct survey_info *survey)
2481 struct mac80211_hwsim_data *hwsim = hw->priv;
2483 if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data))
2486 mutex_lock(&hwsim->mutex);
2487 survey->channel = hwsim->survey_data[idx].channel;
2488 if (!survey->channel) {
2489 mutex_unlock(&hwsim->mutex);
2494 * Magically conjured dummy values --- this is only ok for simulated hardware.
2496 * A real driver which cannot determine real values noise MUST NOT
2497 * report any, especially not a magically conjured ones :-)
2499 survey->filled = SURVEY_INFO_NOISE_DBM |
2501 SURVEY_INFO_TIME_BUSY;
2502 survey->noise = -92;
2504 jiffies_to_msecs(hwsim->survey_data[idx].end -
2505 hwsim->survey_data[idx].start);
2506 /* report 12.5% of channel time is used */
2507 survey->time_busy = survey->time/8;
2508 mutex_unlock(&hwsim->mutex);
2513 #ifdef CONFIG_NL80211_TESTMODE
2515 * This section contains example code for using netlink
2516 * attributes with the testmode command in nl80211.
2519 /* These enums need to be kept in sync with userspace */
2520 enum hwsim_testmode_attr {
2521 __HWSIM_TM_ATTR_INVALID = 0,
2522 HWSIM_TM_ATTR_CMD = 1,
2523 HWSIM_TM_ATTR_PS = 2,
2526 __HWSIM_TM_ATTR_AFTER_LAST,
2527 HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1
2530 enum hwsim_testmode_cmd {
2531 HWSIM_TM_CMD_SET_PS = 0,
2532 HWSIM_TM_CMD_GET_PS = 1,
2533 HWSIM_TM_CMD_STOP_QUEUES = 2,
2534 HWSIM_TM_CMD_WAKE_QUEUES = 3,
2537 static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = {
2538 [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 },
2539 [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 },
2542 static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw,
2543 struct ieee80211_vif *vif,
2544 void *data, int len)
2546 struct mac80211_hwsim_data *hwsim = hw->priv;
2547 struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1];
2548 struct sk_buff *skb;
2551 err = nla_parse_deprecated(tb, HWSIM_TM_ATTR_MAX, data, len,
2552 hwsim_testmode_policy, NULL);
2556 if (!tb[HWSIM_TM_ATTR_CMD])
2559 switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) {
2560 case HWSIM_TM_CMD_SET_PS:
2561 if (!tb[HWSIM_TM_ATTR_PS])
2563 ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]);
2564 return hwsim_fops_ps_write(hwsim, ps);
2565 case HWSIM_TM_CMD_GET_PS:
2566 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
2567 nla_total_size(sizeof(u32)));
2570 if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps))
2571 goto nla_put_failure;
2572 return cfg80211_testmode_reply(skb);
2573 case HWSIM_TM_CMD_STOP_QUEUES:
2574 ieee80211_stop_queues(hw);
2576 case HWSIM_TM_CMD_WAKE_QUEUES:
2577 ieee80211_wake_queues(hw);
2589 static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw,
2590 struct ieee80211_vif *vif,
2591 struct ieee80211_ampdu_params *params)
2593 struct ieee80211_sta *sta = params->sta;
2594 enum ieee80211_ampdu_mlme_action action = params->action;
2595 u16 tid = params->tid;
2598 case IEEE80211_AMPDU_TX_START:
2599 return IEEE80211_AMPDU_TX_START_IMMEDIATE;
2600 case IEEE80211_AMPDU_TX_STOP_CONT:
2601 case IEEE80211_AMPDU_TX_STOP_FLUSH:
2602 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
2603 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2605 case IEEE80211_AMPDU_TX_OPERATIONAL:
2607 case IEEE80211_AMPDU_RX_START:
2608 case IEEE80211_AMPDU_RX_STOP:
2617 static void mac80211_hwsim_flush(struct ieee80211_hw *hw,
2618 struct ieee80211_vif *vif,
2619 u32 queues, bool drop)
2621 /* Not implemented, queues only on kernel side */
2624 static void hw_scan_work(struct work_struct *work)
2626 struct mac80211_hwsim_data *hwsim =
2627 container_of(work, struct mac80211_hwsim_data, hw_scan.work);
2628 struct cfg80211_scan_request *req = hwsim->hw_scan_request;
2631 mutex_lock(&hwsim->mutex);
2632 if (hwsim->scan_chan_idx >= req->n_channels) {
2633 struct cfg80211_scan_info info = {
2637 wiphy_dbg(hwsim->hw->wiphy, "hw scan complete\n");
2638 ieee80211_scan_completed(hwsim->hw, &info);
2639 hwsim->hw_scan_request = NULL;
2640 hwsim->hw_scan_vif = NULL;
2641 hwsim->tmp_chan = NULL;
2642 mutex_unlock(&hwsim->mutex);
2643 mac80211_hwsim_config_mac_nl(hwsim->hw, hwsim->scan_addr,
2648 wiphy_dbg(hwsim->hw->wiphy, "hw scan %d MHz\n",
2649 req->channels[hwsim->scan_chan_idx]->center_freq);
2651 hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx];
2652 if (hwsim->tmp_chan->flags & (IEEE80211_CHAN_NO_IR |
2653 IEEE80211_CHAN_RADAR) ||
2659 for (i = 0; i < req->n_ssids; i++) {
2660 struct sk_buff *probe;
2661 struct ieee80211_mgmt *mgmt;
2663 probe = ieee80211_probereq_get(hwsim->hw,
2666 req->ssids[i].ssid_len,
2671 mgmt = (struct ieee80211_mgmt *) probe->data;
2672 memcpy(mgmt->da, req->bssid, ETH_ALEN);
2673 memcpy(mgmt->bssid, req->bssid, ETH_ALEN);
2676 skb_put_data(probe, req->ie, req->ie_len);
2679 if (!ieee80211_tx_prepare_skb(hwsim->hw,
2682 hwsim->tmp_chan->band,
2690 mac80211_hwsim_tx_frame(hwsim->hw, probe,
2696 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan,
2697 msecs_to_jiffies(dwell));
2698 hwsim->survey_data[hwsim->scan_chan_idx].channel = hwsim->tmp_chan;
2699 hwsim->survey_data[hwsim->scan_chan_idx].start = jiffies;
2700 hwsim->survey_data[hwsim->scan_chan_idx].end =
2701 jiffies + msecs_to_jiffies(dwell);
2702 hwsim->scan_chan_idx++;
2703 mutex_unlock(&hwsim->mutex);
2706 static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw,
2707 struct ieee80211_vif *vif,
2708 struct ieee80211_scan_request *hw_req)
2710 struct mac80211_hwsim_data *hwsim = hw->priv;
2711 struct cfg80211_scan_request *req = &hw_req->req;
2713 mutex_lock(&hwsim->mutex);
2714 if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
2715 mutex_unlock(&hwsim->mutex);
2718 hwsim->hw_scan_request = req;
2719 hwsim->hw_scan_vif = vif;
2720 hwsim->scan_chan_idx = 0;
2721 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
2722 get_random_mask_addr(hwsim->scan_addr,
2723 hw_req->req.mac_addr,
2724 hw_req->req.mac_addr_mask);
2726 memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN);
2727 memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
2728 mutex_unlock(&hwsim->mutex);
2730 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
2731 wiphy_dbg(hw->wiphy, "hwsim hw_scan request\n");
2733 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0);
2738 static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw,
2739 struct ieee80211_vif *vif)
2741 struct mac80211_hwsim_data *hwsim = hw->priv;
2742 struct cfg80211_scan_info info = {
2746 wiphy_dbg(hw->wiphy, "hwsim cancel_hw_scan\n");
2748 cancel_delayed_work_sync(&hwsim->hw_scan);
2750 mutex_lock(&hwsim->mutex);
2751 ieee80211_scan_completed(hwsim->hw, &info);
2752 hwsim->tmp_chan = NULL;
2753 hwsim->hw_scan_request = NULL;
2754 hwsim->hw_scan_vif = NULL;
2755 mutex_unlock(&hwsim->mutex);
2758 static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw,
2759 struct ieee80211_vif *vif,
2762 struct mac80211_hwsim_data *hwsim = hw->priv;
2764 mutex_lock(&hwsim->mutex);
2766 if (hwsim->scanning) {
2767 pr_debug("two hwsim sw_scans detected!\n");
2771 pr_debug("hwsim sw_scan request, prepping stuff\n");
2773 memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN);
2774 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
2775 hwsim->scanning = true;
2776 memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
2779 mutex_unlock(&hwsim->mutex);
2782 static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw,
2783 struct ieee80211_vif *vif)
2785 struct mac80211_hwsim_data *hwsim = hw->priv;
2787 mutex_lock(&hwsim->mutex);
2789 pr_debug("hwsim sw_scan_complete\n");
2790 hwsim->scanning = false;
2791 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, false);
2792 eth_zero_addr(hwsim->scan_addr);
2794 mutex_unlock(&hwsim->mutex);
2797 static void hw_roc_start(struct work_struct *work)
2799 struct mac80211_hwsim_data *hwsim =
2800 container_of(work, struct mac80211_hwsim_data, roc_start.work);
2802 mutex_lock(&hwsim->mutex);
2804 wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC begins\n");
2805 hwsim->tmp_chan = hwsim->roc_chan;
2806 ieee80211_ready_on_channel(hwsim->hw);
2808 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->roc_done,
2809 msecs_to_jiffies(hwsim->roc_duration));
2811 mutex_unlock(&hwsim->mutex);
2814 static void hw_roc_done(struct work_struct *work)
2816 struct mac80211_hwsim_data *hwsim =
2817 container_of(work, struct mac80211_hwsim_data, roc_done.work);
2819 mutex_lock(&hwsim->mutex);
2820 ieee80211_remain_on_channel_expired(hwsim->hw);
2821 hwsim->tmp_chan = NULL;
2822 mutex_unlock(&hwsim->mutex);
2824 wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC expired\n");
2827 static int mac80211_hwsim_roc(struct ieee80211_hw *hw,
2828 struct ieee80211_vif *vif,
2829 struct ieee80211_channel *chan,
2831 enum ieee80211_roc_type type)
2833 struct mac80211_hwsim_data *hwsim = hw->priv;
2835 mutex_lock(&hwsim->mutex);
2836 if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
2837 mutex_unlock(&hwsim->mutex);
2841 hwsim->roc_chan = chan;
2842 hwsim->roc_duration = duration;
2843 mutex_unlock(&hwsim->mutex);
2845 wiphy_dbg(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n",
2846 chan->center_freq, duration);
2847 ieee80211_queue_delayed_work(hw, &hwsim->roc_start, HZ/50);
2852 static int mac80211_hwsim_croc(struct ieee80211_hw *hw,
2853 struct ieee80211_vif *vif)
2855 struct mac80211_hwsim_data *hwsim = hw->priv;
2857 cancel_delayed_work_sync(&hwsim->roc_start);
2858 cancel_delayed_work_sync(&hwsim->roc_done);
2860 mutex_lock(&hwsim->mutex);
2861 hwsim->tmp_chan = NULL;
2862 mutex_unlock(&hwsim->mutex);
2864 wiphy_dbg(hw->wiphy, "hwsim ROC canceled\n");
2869 static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw,
2870 struct ieee80211_chanctx_conf *ctx)
2872 hwsim_set_chanctx_magic(ctx);
2873 wiphy_dbg(hw->wiphy,
2874 "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2875 ctx->def.chan->center_freq, ctx->def.width,
2876 ctx->def.center_freq1, ctx->def.center_freq2);
2880 static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw,
2881 struct ieee80211_chanctx_conf *ctx)
2883 wiphy_dbg(hw->wiphy,
2884 "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2885 ctx->def.chan->center_freq, ctx->def.width,
2886 ctx->def.center_freq1, ctx->def.center_freq2);
2887 hwsim_check_chanctx_magic(ctx);
2888 hwsim_clear_chanctx_magic(ctx);
2891 static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw,
2892 struct ieee80211_chanctx_conf *ctx,
2895 hwsim_check_chanctx_magic(ctx);
2896 wiphy_dbg(hw->wiphy,
2897 "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
2898 ctx->def.chan->center_freq, ctx->def.width,
2899 ctx->def.center_freq1, ctx->def.center_freq2);
2902 static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw,
2903 struct ieee80211_vif *vif,
2904 struct ieee80211_bss_conf *link_conf,
2905 struct ieee80211_chanctx_conf *ctx)
2907 hwsim_check_magic(vif);
2908 hwsim_check_chanctx_magic(ctx);
2913 static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw,
2914 struct ieee80211_vif *vif,
2915 struct ieee80211_bss_conf *link_conf,
2916 struct ieee80211_chanctx_conf *ctx)
2918 hwsim_check_magic(vif);
2919 hwsim_check_chanctx_magic(ctx);
2922 static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = {
2933 #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats)
2935 static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw,
2936 struct ieee80211_vif *vif,
2939 if (sset == ETH_SS_STATS)
2940 memcpy(data, *mac80211_hwsim_gstrings_stats,
2941 sizeof(mac80211_hwsim_gstrings_stats));
2944 static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw,
2945 struct ieee80211_vif *vif, int sset)
2947 if (sset == ETH_SS_STATS)
2948 return MAC80211_HWSIM_SSTATS_LEN;
2952 static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw,
2953 struct ieee80211_vif *vif,
2954 struct ethtool_stats *stats, u64 *data)
2956 struct mac80211_hwsim_data *ar = hw->priv;
2959 data[i++] = ar->tx_pkts;
2960 data[i++] = ar->tx_bytes;
2961 data[i++] = ar->rx_pkts;
2962 data[i++] = ar->rx_bytes;
2963 data[i++] = ar->tx_dropped;
2964 data[i++] = ar->tx_failed;
2966 data[i++] = ar->group;
2968 WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN);
2971 static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
2976 static int mac80211_hwsim_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2981 static int mac80211_hwsim_change_vif_links(struct ieee80211_hw *hw,
2982 struct ieee80211_vif *vif,
2983 u16 old_links, u16 new_links,
2984 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
2986 unsigned long rem = old_links & ~new_links;
2987 unsigned long add = new_links & ~old_links;
2995 for_each_set_bit(i, &rem, IEEE80211_MLD_MAX_NUM_LINKS)
2996 mac80211_hwsim_config_mac_nl(hw, old[i]->addr, false);
2998 for_each_set_bit(i, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
2999 struct ieee80211_bss_conf *link_conf;
3001 /* FIXME: figure out how to get the locking here */
3002 link_conf = rcu_dereference_protected(vif->link_conf[i], 1);
3003 if (WARN_ON(!link_conf))
3006 mac80211_hwsim_config_mac_nl(hw, link_conf->addr, true);
3012 static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw,
3013 struct ieee80211_vif *vif,
3014 struct ieee80211_sta *sta,
3015 u16 old_links, u16 new_links)
3017 hwsim_check_sta_magic(sta);
3022 #define HWSIM_COMMON_OPS \
3023 .tx = mac80211_hwsim_tx, \
3024 .start = mac80211_hwsim_start, \
3025 .stop = mac80211_hwsim_stop, \
3026 .add_interface = mac80211_hwsim_add_interface, \
3027 .change_interface = mac80211_hwsim_change_interface, \
3028 .remove_interface = mac80211_hwsim_remove_interface, \
3029 .config = mac80211_hwsim_config, \
3030 .configure_filter = mac80211_hwsim_configure_filter, \
3031 .vif_cfg_changed = mac80211_hwsim_vif_info_changed, \
3032 .link_info_changed = mac80211_hwsim_link_info_changed, \
3033 .tx_last_beacon = mac80211_hwsim_tx_last_beacon, \
3034 .sta_notify = mac80211_hwsim_sta_notify, \
3035 .sta_rc_update = mac80211_hwsim_sta_rc_update, \
3036 .conf_tx = mac80211_hwsim_conf_tx, \
3037 .get_survey = mac80211_hwsim_get_survey, \
3038 CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \
3039 .ampdu_action = mac80211_hwsim_ampdu_action, \
3040 .flush = mac80211_hwsim_flush, \
3041 .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \
3042 .get_et_stats = mac80211_hwsim_get_et_stats, \
3043 .get_et_strings = mac80211_hwsim_get_et_strings,
3045 #define HWSIM_NON_MLO_OPS \
3046 .sta_add = mac80211_hwsim_sta_add, \
3047 .sta_remove = mac80211_hwsim_sta_remove, \
3048 .set_tim = mac80211_hwsim_set_tim, \
3049 .get_tsf = mac80211_hwsim_get_tsf, \
3050 .set_tsf = mac80211_hwsim_set_tsf,
3052 static const struct ieee80211_ops mac80211_hwsim_ops = {
3055 .sw_scan_start = mac80211_hwsim_sw_scan,
3056 .sw_scan_complete = mac80211_hwsim_sw_scan_complete,
3059 #define HWSIM_CHANCTX_OPS \
3060 .hw_scan = mac80211_hwsim_hw_scan, \
3061 .cancel_hw_scan = mac80211_hwsim_cancel_hw_scan, \
3062 .remain_on_channel = mac80211_hwsim_roc, \
3063 .cancel_remain_on_channel = mac80211_hwsim_croc, \
3064 .add_chanctx = mac80211_hwsim_add_chanctx, \
3065 .remove_chanctx = mac80211_hwsim_remove_chanctx, \
3066 .change_chanctx = mac80211_hwsim_change_chanctx, \
3067 .assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx,\
3068 .unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx,
3070 static const struct ieee80211_ops mac80211_hwsim_mchan_ops = {
3076 static const struct ieee80211_ops mac80211_hwsim_mlo_ops = {
3079 .set_rts_threshold = mac80211_hwsim_set_rts_threshold,
3080 .change_vif_links = mac80211_hwsim_change_vif_links,
3081 .change_sta_links = mac80211_hwsim_change_sta_links,
3082 .sta_state = mac80211_hwsim_sta_state,
3085 struct hwsim_new_radio_params {
3086 unsigned int channels;
3087 const char *reg_alpha2;
3088 const struct ieee80211_regdomain *regd;
3092 bool destroy_on_close;
3095 const u8 *perm_addr;
3102 static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
3103 struct genl_info *info)
3106 genl_notify(&hwsim_genl_family, mcast_skb, info,
3107 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
3109 genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0,
3110 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
3113 static int append_radio_msg(struct sk_buff *skb, int id,
3114 struct hwsim_new_radio_params *param)
3118 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
3122 if (param->channels) {
3123 ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
3128 if (param->reg_alpha2) {
3129 ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
3138 for (i = 0; i < ARRAY_SIZE(hwsim_world_regdom_custom); i++) {
3139 if (hwsim_world_regdom_custom[i] != param->regd)
3142 ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
3149 if (param->reg_strict) {
3150 ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
3155 if (param->p2p_device) {
3156 ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
3161 if (param->use_chanctx) {
3162 ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
3167 if (param->hwname) {
3168 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
3169 strlen(param->hwname), param->hwname);
3177 static void hwsim_mcast_new_radio(int id, struct genl_info *info,
3178 struct hwsim_new_radio_params *param)
3180 struct sk_buff *mcast_skb;
3183 mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
3187 data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
3188 HWSIM_CMD_NEW_RADIO);
3192 if (append_radio_msg(mcast_skb, id, param) < 0)
3195 genlmsg_end(mcast_skb, data);
3197 hwsim_mcast_config_msg(mcast_skb, info);
3201 nlmsg_free(mcast_skb);
3204 static const struct ieee80211_sband_iftype_data sband_capa_2ghz[] = {
3206 .types_mask = BIT(NL80211_IFTYPE_STATION),
3211 IEEE80211_HE_MAC_CAP0_HTC_HE,
3213 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3214 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3216 IEEE80211_HE_MAC_CAP2_BSR |
3217 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3218 IEEE80211_HE_MAC_CAP2_ACK_EN,
3220 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3221 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3222 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3224 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3225 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3226 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3227 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3229 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3230 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3231 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3232 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3233 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3235 /* Leave all the other PHY capability bytes
3236 * unset, as DCM, beam forming, RU and PPE
3237 * threshold information are not supported
3240 .he_mcs_nss_supp = {
3241 .rx_mcs_80 = cpu_to_le16(0xfffa),
3242 .tx_mcs_80 = cpu_to_le16(0xfffa),
3243 .rx_mcs_160 = cpu_to_le16(0xffff),
3244 .tx_mcs_160 = cpu_to_le16(0xffff),
3245 .rx_mcs_80p80 = cpu_to_le16(0xffff),
3246 .tx_mcs_80p80 = cpu_to_le16(0xffff),
3253 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3254 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3255 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3257 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3258 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3259 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3260 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3261 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
3263 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3264 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3265 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3266 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3267 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3268 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3269 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3271 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3272 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3273 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3274 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3275 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3277 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3278 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3279 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3280 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3281 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3282 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
3284 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
3285 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
3287 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
3290 /* For all MCS and bandwidth, set 8 NSS for both Tx and
3293 .eht_mcs_nss_supp = {
3295 * Since B0, B1, B2 and B3 are not set in
3296 * the supported channel width set field in the
3297 * HE PHY capabilities information field the
3298 * device is a 20MHz only device on 2.4GHz band.
3301 .rx_tx_mcs7_max_nss = 0x88,
3302 .rx_tx_mcs9_max_nss = 0x88,
3303 .rx_tx_mcs11_max_nss = 0x88,
3304 .rx_tx_mcs13_max_nss = 0x88,
3307 /* PPE threshold information is not supported */
3311 .types_mask = BIT(NL80211_IFTYPE_AP),
3316 IEEE80211_HE_MAC_CAP0_HTC_HE,
3318 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3319 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3321 IEEE80211_HE_MAC_CAP2_BSR |
3322 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3323 IEEE80211_HE_MAC_CAP2_ACK_EN,
3325 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3326 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3327 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3329 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3330 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3331 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3332 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3334 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3335 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3336 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3337 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3338 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3340 /* Leave all the other PHY capability bytes
3341 * unset, as DCM, beam forming, RU and PPE
3342 * threshold information are not supported
3345 .he_mcs_nss_supp = {
3346 .rx_mcs_80 = cpu_to_le16(0xfffa),
3347 .tx_mcs_80 = cpu_to_le16(0xfffa),
3348 .rx_mcs_160 = cpu_to_le16(0xffff),
3349 .tx_mcs_160 = cpu_to_le16(0xffff),
3350 .rx_mcs_80p80 = cpu_to_le16(0xffff),
3351 .tx_mcs_80p80 = cpu_to_le16(0xffff),
3358 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3359 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3360 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3362 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3363 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3364 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3365 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3366 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
3368 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3369 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3370 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3371 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3372 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3373 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3374 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3376 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3377 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3378 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3379 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3380 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3382 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3383 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3384 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3385 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3386 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3387 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
3389 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
3390 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
3392 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
3395 /* For all MCS and bandwidth, set 8 NSS for both Tx and
3398 .eht_mcs_nss_supp = {
3400 * Since B0, B1, B2 and B3 are not set in
3401 * the supported channel width set field in the
3402 * HE PHY capabilities information field the
3403 * device is a 20MHz only device on 2.4GHz band.
3406 .rx_tx_mcs7_max_nss = 0x88,
3407 .rx_tx_mcs9_max_nss = 0x88,
3408 .rx_tx_mcs11_max_nss = 0x88,
3409 .rx_tx_mcs13_max_nss = 0x88,
3412 /* PPE threshold information is not supported */
3415 #ifdef CONFIG_MAC80211_MESH
3417 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
3422 IEEE80211_HE_MAC_CAP0_HTC_HE,
3424 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3426 IEEE80211_HE_MAC_CAP2_ACK_EN,
3428 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3429 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3430 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3432 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3433 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3434 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3435 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3436 .phy_cap_info[2] = 0,
3438 /* Leave all the other PHY capability bytes
3439 * unset, as DCM, beam forming, RU and PPE
3440 * threshold information are not supported
3443 .he_mcs_nss_supp = {
3444 .rx_mcs_80 = cpu_to_le16(0xfffa),
3445 .tx_mcs_80 = cpu_to_le16(0xfffa),
3446 .rx_mcs_160 = cpu_to_le16(0xffff),
3447 .tx_mcs_160 = cpu_to_le16(0xffff),
3448 .rx_mcs_80p80 = cpu_to_le16(0xffff),
3449 .tx_mcs_80p80 = cpu_to_le16(0xffff),
3456 static const struct ieee80211_sband_iftype_data sband_capa_5ghz[] = {
3458 /* TODO: should we support other types, e.g., P2P? */
3459 .types_mask = BIT(NL80211_IFTYPE_STATION),
3464 IEEE80211_HE_MAC_CAP0_HTC_HE,
3466 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3467 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3469 IEEE80211_HE_MAC_CAP2_BSR |
3470 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3471 IEEE80211_HE_MAC_CAP2_ACK_EN,
3473 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3474 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3475 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3477 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
3478 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
3479 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
3481 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3482 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3483 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3484 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3486 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3487 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3488 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3489 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3490 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3492 /* Leave all the other PHY capability bytes
3493 * unset, as DCM, beam forming, RU and PPE
3494 * threshold information are not supported
3497 .he_mcs_nss_supp = {
3498 .rx_mcs_80 = cpu_to_le16(0xfffa),
3499 .tx_mcs_80 = cpu_to_le16(0xfffa),
3500 .rx_mcs_160 = cpu_to_le16(0xfffa),
3501 .tx_mcs_160 = cpu_to_le16(0xfffa),
3502 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
3503 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
3510 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3511 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3512 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3514 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3515 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3516 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3517 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3518 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
3519 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
3521 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
3522 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
3524 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
3525 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
3527 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3528 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3529 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3530 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3531 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3532 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3533 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3535 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3536 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3537 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3538 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3539 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3541 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3542 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3543 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3544 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3545 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3546 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
3548 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
3549 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
3551 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
3552 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
3553 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
3554 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
3555 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
3558 /* For all MCS and bandwidth, set 8 NSS for both Tx and
3561 .eht_mcs_nss_supp = {
3563 * As B1 and B2 are set in the supported
3564 * channel width set field in the HE PHY
3565 * capabilities information field include all
3566 * the following MCS/NSS.
3569 .rx_tx_mcs9_max_nss = 0x88,
3570 .rx_tx_mcs11_max_nss = 0x88,
3571 .rx_tx_mcs13_max_nss = 0x88,
3574 .rx_tx_mcs9_max_nss = 0x88,
3575 .rx_tx_mcs11_max_nss = 0x88,
3576 .rx_tx_mcs13_max_nss = 0x88,
3579 /* PPE threshold information is not supported */
3583 .types_mask = BIT(NL80211_IFTYPE_AP),
3588 IEEE80211_HE_MAC_CAP0_HTC_HE,
3590 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3591 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3593 IEEE80211_HE_MAC_CAP2_BSR |
3594 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3595 IEEE80211_HE_MAC_CAP2_ACK_EN,
3597 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3598 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3599 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3601 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
3602 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
3603 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
3605 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3606 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3607 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3608 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3610 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3611 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3612 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3613 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3614 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3616 /* Leave all the other PHY capability bytes
3617 * unset, as DCM, beam forming, RU and PPE
3618 * threshold information are not supported
3621 .he_mcs_nss_supp = {
3622 .rx_mcs_80 = cpu_to_le16(0xfffa),
3623 .tx_mcs_80 = cpu_to_le16(0xfffa),
3624 .rx_mcs_160 = cpu_to_le16(0xfffa),
3625 .tx_mcs_160 = cpu_to_le16(0xfffa),
3626 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
3627 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
3634 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3635 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3636 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3638 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3639 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3640 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3641 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3642 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
3643 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
3645 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
3646 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
3648 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
3649 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
3651 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3652 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3653 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3654 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3655 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3656 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3657 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3659 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3660 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3661 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3662 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3663 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3665 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3666 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3667 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3668 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3669 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3670 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
3672 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
3673 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
3675 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
3676 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
3677 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
3678 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
3679 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
3682 /* For all MCS and bandwidth, set 8 NSS for both Tx and
3685 .eht_mcs_nss_supp = {
3687 * As B1 and B2 are set in the supported
3688 * channel width set field in the HE PHY
3689 * capabilities information field include all
3690 * the following MCS/NSS.
3693 .rx_tx_mcs9_max_nss = 0x88,
3694 .rx_tx_mcs11_max_nss = 0x88,
3695 .rx_tx_mcs13_max_nss = 0x88,
3698 .rx_tx_mcs9_max_nss = 0x88,
3699 .rx_tx_mcs11_max_nss = 0x88,
3700 .rx_tx_mcs13_max_nss = 0x88,
3703 /* PPE threshold information is not supported */
3706 #ifdef CONFIG_MAC80211_MESH
3708 /* TODO: should we support other types, e.g., IBSS?*/
3709 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
3714 IEEE80211_HE_MAC_CAP0_HTC_HE,
3716 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3718 IEEE80211_HE_MAC_CAP2_ACK_EN,
3720 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3721 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3722 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3724 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
3725 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
3726 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
3728 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3729 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3730 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3731 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3732 .phy_cap_info[2] = 0,
3734 /* Leave all the other PHY capability bytes
3735 * unset, as DCM, beam forming, RU and PPE
3736 * threshold information are not supported
3739 .he_mcs_nss_supp = {
3740 .rx_mcs_80 = cpu_to_le16(0xfffa),
3741 .tx_mcs_80 = cpu_to_le16(0xfffa),
3742 .rx_mcs_160 = cpu_to_le16(0xfffa),
3743 .tx_mcs_160 = cpu_to_le16(0xfffa),
3744 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
3745 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
3752 static const struct ieee80211_sband_iftype_data sband_capa_6ghz[] = {
3754 /* TODO: should we support other types, e.g., P2P? */
3755 .types_mask = BIT(NL80211_IFTYPE_STATION),
3757 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
3758 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
3759 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
3760 IEEE80211_HE_6GHZ_CAP_SM_PS |
3761 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
3762 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
3763 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
3769 IEEE80211_HE_MAC_CAP0_HTC_HE,
3771 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3772 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3774 IEEE80211_HE_MAC_CAP2_BSR |
3775 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3776 IEEE80211_HE_MAC_CAP2_ACK_EN,
3778 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3779 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3780 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3782 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
3783 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
3784 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
3786 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3787 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3788 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3789 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3791 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3792 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3793 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3794 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3795 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3797 /* Leave all the other PHY capability bytes
3798 * unset, as DCM, beam forming, RU and PPE
3799 * threshold information are not supported
3802 .he_mcs_nss_supp = {
3803 .rx_mcs_80 = cpu_to_le16(0xfffa),
3804 .tx_mcs_80 = cpu_to_le16(0xfffa),
3805 .rx_mcs_160 = cpu_to_le16(0xfffa),
3806 .tx_mcs_160 = cpu_to_le16(0xfffa),
3807 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
3808 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
3815 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3816 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3817 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3819 IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
3820 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3821 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3822 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3823 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3824 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
3825 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
3827 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
3828 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
3829 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
3831 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
3832 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
3833 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
3835 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3836 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3837 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3838 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3839 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3840 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3841 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3843 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3844 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3845 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3846 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3847 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3849 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3850 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3851 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3852 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3853 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3854 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
3856 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
3857 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
3858 IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
3860 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
3861 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
3862 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
3863 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
3864 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
3865 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
3866 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
3869 /* For all MCS and bandwidth, set 8 NSS for both Tx and
3872 .eht_mcs_nss_supp = {
3874 * As B1 and B2 are set in the supported
3875 * channel width set field in the HE PHY
3876 * capabilities information field and 320MHz in
3877 * 6GHz is supported include all the following
3881 .rx_tx_mcs9_max_nss = 0x88,
3882 .rx_tx_mcs11_max_nss = 0x88,
3883 .rx_tx_mcs13_max_nss = 0x88,
3886 .rx_tx_mcs9_max_nss = 0x88,
3887 .rx_tx_mcs11_max_nss = 0x88,
3888 .rx_tx_mcs13_max_nss = 0x88,
3891 .rx_tx_mcs9_max_nss = 0x88,
3892 .rx_tx_mcs11_max_nss = 0x88,
3893 .rx_tx_mcs13_max_nss = 0x88,
3896 /* PPE threshold information is not supported */
3900 .types_mask = BIT(NL80211_IFTYPE_AP),
3902 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
3903 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
3904 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
3905 IEEE80211_HE_6GHZ_CAP_SM_PS |
3906 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
3907 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
3908 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
3914 IEEE80211_HE_MAC_CAP0_HTC_HE,
3916 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
3917 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
3919 IEEE80211_HE_MAC_CAP2_BSR |
3920 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
3921 IEEE80211_HE_MAC_CAP2_ACK_EN,
3923 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
3924 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
3925 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
3927 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
3928 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
3929 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
3931 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
3932 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
3933 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
3934 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
3936 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
3937 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
3938 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
3939 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
3940 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
3942 /* Leave all the other PHY capability bytes
3943 * unset, as DCM, beam forming, RU and PPE
3944 * threshold information are not supported
3947 .he_mcs_nss_supp = {
3948 .rx_mcs_80 = cpu_to_le16(0xfffa),
3949 .tx_mcs_80 = cpu_to_le16(0xfffa),
3950 .rx_mcs_160 = cpu_to_le16(0xfffa),
3951 .tx_mcs_160 = cpu_to_le16(0xfffa),
3952 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
3953 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
3960 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
3961 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
3962 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
3964 IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
3965 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
3966 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
3967 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
3968 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
3969 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
3970 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
3972 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
3973 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
3974 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
3976 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
3977 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
3978 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
3980 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
3981 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
3982 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
3983 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
3984 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
3985 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
3986 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
3988 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
3989 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
3990 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
3991 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
3992 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
3994 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
3995 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
3996 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
3997 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
3998 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
3999 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4001 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4002 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
4003 IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
4005 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
4006 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
4007 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
4008 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
4009 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
4010 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
4011 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
4014 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4017 .eht_mcs_nss_supp = {
4019 * As B1 and B2 are set in the supported
4020 * channel width set field in the HE PHY
4021 * capabilities information field and 320MHz in
4022 * 6GHz is supported include all the following
4026 .rx_tx_mcs9_max_nss = 0x88,
4027 .rx_tx_mcs11_max_nss = 0x88,
4028 .rx_tx_mcs13_max_nss = 0x88,
4031 .rx_tx_mcs9_max_nss = 0x88,
4032 .rx_tx_mcs11_max_nss = 0x88,
4033 .rx_tx_mcs13_max_nss = 0x88,
4036 .rx_tx_mcs9_max_nss = 0x88,
4037 .rx_tx_mcs11_max_nss = 0x88,
4038 .rx_tx_mcs13_max_nss = 0x88,
4041 /* PPE threshold information is not supported */
4044 #ifdef CONFIG_MAC80211_MESH
4046 /* TODO: should we support other types, e.g., IBSS?*/
4047 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
4049 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
4050 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
4051 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
4052 IEEE80211_HE_6GHZ_CAP_SM_PS |
4053 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
4054 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
4055 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
4061 IEEE80211_HE_MAC_CAP0_HTC_HE,
4063 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4065 IEEE80211_HE_MAC_CAP2_ACK_EN,
4067 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4068 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4069 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4071 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4072 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4073 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4075 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4076 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4077 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4078 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4079 .phy_cap_info[2] = 0,
4081 /* Leave all the other PHY capability bytes
4082 * unset, as DCM, beam forming, RU and PPE
4083 * threshold information are not supported
4086 .he_mcs_nss_supp = {
4087 .rx_mcs_80 = cpu_to_le16(0xfffa),
4088 .tx_mcs_80 = cpu_to_le16(0xfffa),
4089 .rx_mcs_160 = cpu_to_le16(0xfffa),
4090 .tx_mcs_160 = cpu_to_le16(0xfffa),
4091 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4092 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4099 static void mac80211_hwsim_sband_capab(struct ieee80211_supported_band *sband)
4103 if (sband->band == NL80211_BAND_2GHZ) {
4104 n_iftype_data = ARRAY_SIZE(sband_capa_2ghz);
4105 sband->iftype_data =
4106 (struct ieee80211_sband_iftype_data *)sband_capa_2ghz;
4107 } else if (sband->band == NL80211_BAND_5GHZ) {
4108 n_iftype_data = ARRAY_SIZE(sband_capa_5ghz);
4109 sband->iftype_data =
4110 (struct ieee80211_sband_iftype_data *)sband_capa_5ghz;
4111 } else if (sband->band == NL80211_BAND_6GHZ) {
4112 n_iftype_data = ARRAY_SIZE(sband_capa_6ghz);
4113 sband->iftype_data =
4114 (struct ieee80211_sband_iftype_data *)sband_capa_6ghz;
4119 sband->n_iftype_data = n_iftype_data;
4122 #ifdef CONFIG_MAC80211_MESH
4123 #define HWSIM_MESH_BIT BIT(NL80211_IFTYPE_MESH_POINT)
4125 #define HWSIM_MESH_BIT 0
4128 #define HWSIM_DEFAULT_IF_LIMIT \
4129 (BIT(NL80211_IFTYPE_STATION) | \
4130 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
4131 BIT(NL80211_IFTYPE_AP) | \
4132 BIT(NL80211_IFTYPE_P2P_GO) | \
4135 #define HWSIM_IFTYPE_SUPPORT_MASK \
4136 (BIT(NL80211_IFTYPE_STATION) | \
4137 BIT(NL80211_IFTYPE_AP) | \
4138 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
4139 BIT(NL80211_IFTYPE_P2P_GO) | \
4140 BIT(NL80211_IFTYPE_ADHOC) | \
4141 BIT(NL80211_IFTYPE_MESH_POINT) | \
4142 BIT(NL80211_IFTYPE_OCB))
4144 static int mac80211_hwsim_new_radio(struct genl_info *info,
4145 struct hwsim_new_radio_params *param)
4149 struct mac80211_hwsim_data *data;
4150 struct ieee80211_hw *hw;
4151 enum nl80211_band band;
4152 const struct ieee80211_ops *ops = &mac80211_hwsim_ops;
4157 if (WARN_ON(param->channels > 1 && !param->use_chanctx))
4160 spin_lock_bh(&hwsim_radio_lock);
4161 idx = hwsim_radio_idx++;
4162 spin_unlock_bh(&hwsim_radio_lock);
4165 ops = &mac80211_hwsim_mlo_ops;
4166 else if (param->use_chanctx)
4167 ops = &mac80211_hwsim_mchan_ops;
4168 hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname);
4170 pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n");
4175 /* ieee80211_alloc_hw_nm may have used a default name */
4176 param->hwname = wiphy_name(hw->wiphy);
4179 net = genl_info_net(info);
4182 wiphy_net_set(hw->wiphy, net);
4187 data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx);
4188 if (IS_ERR(data->dev)) {
4190 "mac80211_hwsim: device_create failed (%ld)\n",
4191 PTR_ERR(data->dev));
4193 goto failed_drvdata;
4195 data->dev->driver = &mac80211_hwsim_driver.driver;
4196 err = device_bind_driver(data->dev);
4198 pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n",
4203 skb_queue_head_init(&data->pending);
4205 SET_IEEE80211_DEV(hw, data->dev);
4206 if (!param->perm_addr) {
4207 eth_zero_addr(addr);
4211 memcpy(data->addresses[0].addr, addr, ETH_ALEN);
4212 /* Why need here second address ? */
4213 memcpy(data->addresses[1].addr, addr, ETH_ALEN);
4214 data->addresses[1].addr[0] |= 0x40;
4215 hw->wiphy->n_addresses = 2;
4216 hw->wiphy->addresses = data->addresses;
4217 /* possible address clash is checked at hash table insertion */
4219 memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN);
4220 /* compatibility with automatically generated mac addr */
4221 memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN);
4222 hw->wiphy->n_addresses = 2;
4223 hw->wiphy->addresses = data->addresses;
4226 data->channels = param->channels;
4227 data->use_chanctx = param->use_chanctx;
4229 data->destroy_on_close = param->destroy_on_close;
4231 data->portid = info->snd_portid;
4233 /* setup interface limits, only on interface types we support */
4234 if (param->iftypes & BIT(NL80211_IFTYPE_ADHOC)) {
4235 data->if_limits[n_limits].max = 1;
4236 data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_ADHOC);
4240 if (param->iftypes & HWSIM_DEFAULT_IF_LIMIT) {
4241 data->if_limits[n_limits].max = 2048;
4243 * For this case, we may only support a subset of
4244 * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the
4245 * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have.
4247 data->if_limits[n_limits].types =
4248 HWSIM_DEFAULT_IF_LIMIT & param->iftypes;
4252 if (param->iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
4253 data->if_limits[n_limits].max = 1;
4254 data->if_limits[n_limits].types =
4255 BIT(NL80211_IFTYPE_P2P_DEVICE);
4259 if (data->use_chanctx) {
4260 hw->wiphy->max_scan_ssids = 255;
4261 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
4262 hw->wiphy->max_remain_on_channel_duration = 1000;
4263 data->if_combination.radar_detect_widths = 0;
4264 data->if_combination.num_different_channels = data->channels;
4266 data->if_combination.num_different_channels = 1;
4267 data->if_combination.radar_detect_widths =
4268 BIT(NL80211_CHAN_WIDTH_5) |
4269 BIT(NL80211_CHAN_WIDTH_10) |
4270 BIT(NL80211_CHAN_WIDTH_20_NOHT) |
4271 BIT(NL80211_CHAN_WIDTH_20) |
4272 BIT(NL80211_CHAN_WIDTH_40) |
4273 BIT(NL80211_CHAN_WIDTH_80) |
4274 BIT(NL80211_CHAN_WIDTH_160);
4282 data->if_combination.max_interfaces = 0;
4283 for (i = 0; i < n_limits; i++)
4284 data->if_combination.max_interfaces +=
4285 data->if_limits[i].max;
4287 data->if_combination.n_limits = n_limits;
4288 data->if_combination.limits = data->if_limits;
4291 * If we actually were asked to support combinations,
4292 * advertise them - if there's only a single thing like
4293 * only IBSS then don't advertise it as combinations.
4295 if (data->if_combination.max_interfaces > 1) {
4296 hw->wiphy->iface_combinations = &data->if_combination;
4297 hw->wiphy->n_iface_combinations = 1;
4300 if (param->ciphers) {
4301 memcpy(data->ciphers, param->ciphers,
4302 param->n_ciphers * sizeof(u32));
4303 hw->wiphy->cipher_suites = data->ciphers;
4304 hw->wiphy->n_cipher_suites = param->n_ciphers;
4307 data->rx_rssi = DEFAULT_RX_RSSI;
4309 INIT_DELAYED_WORK(&data->roc_start, hw_roc_start);
4310 INIT_DELAYED_WORK(&data->roc_done, hw_roc_done);
4311 INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work);
4314 hw->offchannel_tx_hw_queue = 4;
4316 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
4317 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
4318 ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
4319 ieee80211_hw_set(hw, QUEUE_CONTROL);
4320 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
4321 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
4322 ieee80211_hw_set(hw, MFP_CAPABLE);
4323 ieee80211_hw_set(hw, SIGNAL_DBM);
4324 ieee80211_hw_set(hw, SUPPORTS_PS);
4325 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
4326 ieee80211_hw_set(hw, TDLS_WIDER_BW);
4327 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
4330 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
4331 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
4332 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
4333 ieee80211_hw_set(hw, CONNECTION_MONITOR);
4334 ieee80211_hw_set(hw, AP_LINK_PS);
4336 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
4337 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
4339 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
4342 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
4343 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
4344 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
4345 WIPHY_FLAG_AP_UAPSD |
4346 WIPHY_FLAG_SUPPORTS_5_10_MHZ |
4347 WIPHY_FLAG_HAS_CHANNEL_SWITCH;
4348 hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
4349 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
4350 NL80211_FEATURE_STATIC_SMPS |
4351 NL80211_FEATURE_DYNAMIC_SMPS |
4352 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
4353 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
4354 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
4355 wiphy_ext_feature_set(hw->wiphy,
4356 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
4357 wiphy_ext_feature_set(hw->wiphy,
4358 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
4360 hw->wiphy->interface_modes = param->iftypes;
4362 /* ask mac80211 to reserve space for magic */
4363 hw->vif_data_size = sizeof(struct hwsim_vif_priv);
4364 hw->sta_data_size = sizeof(struct hwsim_sta_priv);
4365 hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv);
4367 memcpy(data->channels_2ghz, hwsim_channels_2ghz,
4368 sizeof(hwsim_channels_2ghz));
4369 memcpy(data->channels_5ghz, hwsim_channels_5ghz,
4370 sizeof(hwsim_channels_5ghz));
4371 memcpy(data->channels_6ghz, hwsim_channels_6ghz,
4372 sizeof(hwsim_channels_6ghz));
4373 memcpy(data->channels_s1g, hwsim_channels_s1g,
4374 sizeof(hwsim_channels_s1g));
4375 memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
4377 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
4378 struct ieee80211_supported_band *sband = &data->bands[band];
4383 case NL80211_BAND_2GHZ:
4384 sband->channels = data->channels_2ghz;
4385 sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz);
4386 sband->bitrates = data->rates;
4387 sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
4389 case NL80211_BAND_5GHZ:
4390 sband->channels = data->channels_5ghz;
4391 sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz);
4392 sband->bitrates = data->rates + 4;
4393 sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
4395 sband->vht_cap.vht_supported = true;
4396 sband->vht_cap.cap =
4397 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
4398 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ |
4399 IEEE80211_VHT_CAP_RXLDPC |
4400 IEEE80211_VHT_CAP_SHORT_GI_80 |
4401 IEEE80211_VHT_CAP_SHORT_GI_160 |
4402 IEEE80211_VHT_CAP_TXSTBC |
4403 IEEE80211_VHT_CAP_RXSTBC_4 |
4404 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
4405 sband->vht_cap.vht_mcs.rx_mcs_map =
4406 cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
4407 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
4408 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
4409 IEEE80211_VHT_MCS_SUPPORT_0_9 << 6 |
4410 IEEE80211_VHT_MCS_SUPPORT_0_9 << 8 |
4411 IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 |
4412 IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 |
4413 IEEE80211_VHT_MCS_SUPPORT_0_9 << 14);
4414 sband->vht_cap.vht_mcs.tx_mcs_map =
4415 sband->vht_cap.vht_mcs.rx_mcs_map;
4417 case NL80211_BAND_6GHZ:
4418 sband->channels = data->channels_6ghz;
4419 sband->n_channels = ARRAY_SIZE(hwsim_channels_6ghz);
4420 sband->bitrates = data->rates + 4;
4421 sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
4423 case NL80211_BAND_S1GHZ:
4424 memcpy(&sband->s1g_cap, &hwsim_s1g_cap,
4425 sizeof(sband->s1g_cap));
4426 sband->channels = data->channels_s1g;
4427 sband->n_channels = ARRAY_SIZE(hwsim_channels_s1g);
4433 if (band != NL80211_BAND_6GHZ){
4434 sband->ht_cap.ht_supported = true;
4435 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
4436 IEEE80211_HT_CAP_GRN_FLD |
4437 IEEE80211_HT_CAP_SGI_20 |
4438 IEEE80211_HT_CAP_SGI_40 |
4439 IEEE80211_HT_CAP_DSSSCCK40;
4440 sband->ht_cap.ampdu_factor = 0x3;
4441 sband->ht_cap.ampdu_density = 0x6;
4442 memset(&sband->ht_cap.mcs, 0,
4443 sizeof(sband->ht_cap.mcs));
4444 sband->ht_cap.mcs.rx_mask[0] = 0xff;
4445 sband->ht_cap.mcs.rx_mask[1] = 0xff;
4446 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
4449 mac80211_hwsim_sband_capab(sband);
4451 hw->wiphy->bands[band] = sband;
4454 /* By default all radios belong to the first group */
4456 mutex_init(&data->mutex);
4458 data->netgroup = hwsim_net_get_netgroup(net);
4459 data->wmediumd = hwsim_net_get_wmediumd(net);
4461 /* Enable frame retransmissions for lossy channels */
4463 hw->max_rate_tries = 11;
4465 hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands;
4466 hw->wiphy->n_vendor_commands =
4467 ARRAY_SIZE(mac80211_hwsim_vendor_commands);
4468 hw->wiphy->vendor_events = mac80211_hwsim_vendor_events;
4469 hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events);
4471 if (param->reg_strict)
4472 hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
4474 data->regd = param->regd;
4475 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
4476 wiphy_apply_custom_regulatory(hw->wiphy, param->regd);
4477 /* give the regulatory workqueue a chance to run */
4478 schedule_timeout_interruptible(1);
4482 ieee80211_hw_set(hw, NO_AUTO_VIF);
4484 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
4486 for (i = 0; i < ARRAY_SIZE(data->link_data); i++) {
4487 hrtimer_init(&data->link_data[i].beacon_timer, CLOCK_MONOTONIC,
4488 HRTIMER_MODE_ABS_SOFT);
4489 data->link_data[i].beacon_timer.function =
4490 mac80211_hwsim_beacon;
4491 data->link_data[i].link_id = i;
4494 err = ieee80211_register_hw(hw);
4496 pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
4501 wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr);
4503 if (param->reg_alpha2) {
4504 data->alpha2[0] = param->reg_alpha2[0];
4505 data->alpha2[1] = param->reg_alpha2[1];
4506 regulatory_hint(hw->wiphy, param->reg_alpha2);
4509 data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir);
4510 debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
4511 debugfs_create_file("group", 0666, data->debugfs, data,
4513 debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
4514 &hwsim_fops_rx_rssi);
4515 if (!data->use_chanctx)
4516 debugfs_create_file("dfs_simulate_radar", 0222,
4518 data, &hwsim_simulate_radar);
4520 spin_lock_bh(&hwsim_radio_lock);
4521 err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht,
4525 GENL_SET_ERR_MSG(info, "perm addr already present");
4526 NL_SET_BAD_ATTR(info->extack,
4527 info->attrs[HWSIM_ATTR_PERM_ADDR]);
4529 spin_unlock_bh(&hwsim_radio_lock);
4530 goto failed_final_insert;
4533 list_add_tail(&data->list, &hwsim_radios);
4534 hwsim_radios_generation++;
4535 spin_unlock_bh(&hwsim_radio_lock);
4537 hwsim_mcast_new_radio(idx, info, param);
4541 failed_final_insert:
4542 debugfs_remove_recursive(data->debugfs);
4543 ieee80211_unregister_hw(data->hw);
4545 device_release_driver(data->dev);
4547 device_unregister(data->dev);
4549 ieee80211_free_hw(hw);
4554 static void hwsim_mcast_del_radio(int id, const char *hwname,
4555 struct genl_info *info)
4557 struct sk_buff *skb;
4561 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
4565 data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
4566 HWSIM_CMD_DEL_RADIO);
4570 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
4574 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname),
4579 genlmsg_end(skb, data);
4581 hwsim_mcast_config_msg(skb, info);
4589 static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
4591 struct genl_info *info)
4593 hwsim_mcast_del_radio(data->idx, hwname, info);
4594 debugfs_remove_recursive(data->debugfs);
4595 ieee80211_unregister_hw(data->hw);
4596 device_release_driver(data->dev);
4597 device_unregister(data->dev);
4598 ieee80211_free_hw(data->hw);
4601 static int mac80211_hwsim_get_radio(struct sk_buff *skb,
4602 struct mac80211_hwsim_data *data,
4603 u32 portid, u32 seq,
4604 struct netlink_callback *cb, int flags)
4607 struct hwsim_new_radio_params param = { };
4608 int res = -EMSGSIZE;
4610 hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags,
4611 HWSIM_CMD_GET_RADIO);
4616 genl_dump_check_consistent(cb, hdr);
4618 if (data->alpha2[0] && data->alpha2[1])
4619 param.reg_alpha2 = data->alpha2;
4621 param.reg_strict = !!(data->hw->wiphy->regulatory_flags &
4622 REGULATORY_STRICT_REG);
4623 param.p2p_device = !!(data->hw->wiphy->interface_modes &
4624 BIT(NL80211_IFTYPE_P2P_DEVICE));
4625 param.use_chanctx = data->use_chanctx;
4626 param.regd = data->regd;
4627 param.channels = data->channels;
4628 param.hwname = wiphy_name(data->hw->wiphy);
4630 res = append_radio_msg(skb, data->idx, ¶m);
4634 genlmsg_end(skb, hdr);
4638 genlmsg_cancel(skb, hdr);
4642 static void mac80211_hwsim_free(void)
4644 struct mac80211_hwsim_data *data;
4646 spin_lock_bh(&hwsim_radio_lock);
4647 while ((data = list_first_entry_or_null(&hwsim_radios,
4648 struct mac80211_hwsim_data,
4650 list_del(&data->list);
4651 spin_unlock_bh(&hwsim_radio_lock);
4652 mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
4654 spin_lock_bh(&hwsim_radio_lock);
4656 spin_unlock_bh(&hwsim_radio_lock);
4657 class_destroy(hwsim_class);
4660 static const struct net_device_ops hwsim_netdev_ops = {
4661 .ndo_start_xmit = hwsim_mon_xmit,
4662 .ndo_set_mac_address = eth_mac_addr,
4663 .ndo_validate_addr = eth_validate_addr,
4666 static void hwsim_mon_setup(struct net_device *dev)
4670 dev->netdev_ops = &hwsim_netdev_ops;
4671 dev->needs_free_netdev = true;
4673 dev->priv_flags |= IFF_NO_QUEUE;
4674 dev->type = ARPHRD_IEEE80211_RADIOTAP;
4675 eth_zero_addr(addr);
4677 eth_hw_addr_set(dev, addr);
4680 static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr)
4682 return rhashtable_lookup_fast(&hwsim_radios_rht,
4687 static void hwsim_register_wmediumd(struct net *net, u32 portid)
4689 struct mac80211_hwsim_data *data;
4691 hwsim_net_set_wmediumd(net, portid);
4693 spin_lock_bh(&hwsim_radio_lock);
4694 list_for_each_entry(data, &hwsim_radios, list) {
4695 if (data->netgroup == hwsim_net_get_netgroup(net))
4696 data->wmediumd = portid;
4698 spin_unlock_bh(&hwsim_radio_lock);
4701 static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
4702 struct genl_info *info)
4705 struct ieee80211_hdr *hdr;
4706 struct mac80211_hwsim_data *data2;
4707 struct ieee80211_tx_info *txi;
4708 struct hwsim_tx_rate *tx_attempts;
4710 struct sk_buff *skb, *tmp;
4712 unsigned int hwsim_flags;
4714 unsigned long flags;
4717 if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] ||
4718 !info->attrs[HWSIM_ATTR_FLAGS] ||
4719 !info->attrs[HWSIM_ATTR_COOKIE] ||
4720 !info->attrs[HWSIM_ATTR_SIGNAL] ||
4721 !info->attrs[HWSIM_ATTR_TX_INFO])
4724 src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
4725 hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
4726 ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
4728 data2 = get_hwsim_data_ref_from_addr(src);
4732 if (!hwsim_virtio_enabled) {
4733 if (hwsim_net_get_netgroup(genl_info_net(info)) !=
4737 if (info->snd_portid != data2->wmediumd)
4741 /* look for the skb matching the cookie passed back from user */
4742 spin_lock_irqsave(&data2->pending.lock, flags);
4743 skb_queue_walk_safe(&data2->pending, skb, tmp) {
4744 uintptr_t skb_cookie;
4746 txi = IEEE80211_SKB_CB(skb);
4747 skb_cookie = (uintptr_t)txi->rate_driver_data[0];
4749 if (skb_cookie == ret_skb_cookie) {
4750 __skb_unlink(skb, &data2->pending);
4755 spin_unlock_irqrestore(&data2->pending.lock, flags);
4761 /* Tx info received because the frame was broadcasted on user space,
4762 so we get all the necessary info: tx attempts and skb control buff */
4764 tx_attempts = (struct hwsim_tx_rate *)nla_data(
4765 info->attrs[HWSIM_ATTR_TX_INFO]);
4767 /* now send back TX status */
4768 txi = IEEE80211_SKB_CB(skb);
4770 ieee80211_tx_info_clear_status(txi);
4772 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
4773 txi->status.rates[i].idx = tx_attempts[i].idx;
4774 txi->status.rates[i].count = tx_attempts[i].count;
4777 txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
4779 if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) &&
4780 (hwsim_flags & HWSIM_TX_STAT_ACK)) {
4781 if (skb->len >= 16) {
4782 hdr = (struct ieee80211_hdr *) skb->data;
4783 mac80211_hwsim_monitor_ack(data2->channel,
4786 txi->flags |= IEEE80211_TX_STAT_ACK;
4789 if (hwsim_flags & HWSIM_TX_CTL_NO_ACK)
4790 txi->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
4792 ieee80211_tx_status_irqsafe(data2->hw, skb);
4799 static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
4800 struct genl_info *info)
4802 struct mac80211_hwsim_data *data2;
4803 struct ieee80211_rx_status rx_status;
4804 struct ieee80211_hdr *hdr;
4808 struct sk_buff *skb = NULL;
4809 struct ieee80211_channel *channel = NULL;
4811 if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
4812 !info->attrs[HWSIM_ATTR_FRAME] ||
4813 !info->attrs[HWSIM_ATTR_RX_RATE] ||
4814 !info->attrs[HWSIM_ATTR_SIGNAL])
4817 dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
4818 frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
4819 frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]);
4821 /* Allocate new skb here */
4822 skb = alloc_skb(frame_data_len, GFP_KERNEL);
4826 if (frame_data_len > IEEE80211_MAX_DATA_LEN)
4830 skb_put_data(skb, frame_data, frame_data_len);
4832 data2 = get_hwsim_data_ref_from_addr(dst);
4836 if (data2->use_chanctx) {
4837 if (data2->tmp_chan)
4838 channel = data2->tmp_chan;
4840 channel = data2->channel;
4843 if (!hwsim_virtio_enabled) {
4844 if (hwsim_net_get_netgroup(genl_info_net(info)) !=
4848 if (info->snd_portid != data2->wmediumd)
4852 /* check if radio is configured properly */
4854 if ((data2->idle && !data2->tmp_chan) || !data2->started)
4857 /* A frame is received from user space */
4858 memset(&rx_status, 0, sizeof(rx_status));
4859 if (info->attrs[HWSIM_ATTR_FREQ]) {
4860 struct tx_iter_data iter_data = {};
4862 /* throw away off-channel packets, but allow both the temporary
4863 * ("hw" scan/remain-on-channel), regular channels and links,
4864 * since the internal datapath also allows this
4866 rx_status.freq = nla_get_u32(info->attrs[HWSIM_ATTR_FREQ]);
4868 iter_data.channel = ieee80211_get_channel(data2->hw->wiphy,
4870 if (!iter_data.channel)
4872 rx_status.band = iter_data.channel->band;
4874 mutex_lock(&data2->mutex);
4875 if (!hwsim_chans_compat(iter_data.channel, channel)) {
4876 ieee80211_iterate_active_interfaces_atomic(
4877 data2->hw, IEEE80211_IFACE_ITER_NORMAL,
4878 mac80211_hwsim_tx_iter, &iter_data);
4879 if (!iter_data.receive) {
4880 mutex_unlock(&data2->mutex);
4884 mutex_unlock(&data2->mutex);
4885 } else if (!channel) {
4888 rx_status.freq = channel->center_freq;
4889 rx_status.band = channel->band;
4892 rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]);
4893 rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
4895 hdr = (void *)skb->data;
4897 if (ieee80211_is_beacon(hdr->frame_control) ||
4898 ieee80211_is_probe_resp(hdr->frame_control))
4899 rx_status.boottime_ns = ktime_get_boottime_ns();
4901 mac80211_hwsim_rx(data2, &rx_status, skb);
4905 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
4911 static int hwsim_register_received_nl(struct sk_buff *skb_2,
4912 struct genl_info *info)
4914 struct net *net = genl_info_net(info);
4915 struct mac80211_hwsim_data *data;
4918 spin_lock_bh(&hwsim_radio_lock);
4919 list_for_each_entry(data, &hwsim_radios, list)
4920 chans = max(chans, data->channels);
4921 spin_unlock_bh(&hwsim_radio_lock);
4923 /* In the future we should revise the userspace API and allow it
4924 * to set a flag that it does support multi-channel, then we can
4925 * let this pass conditionally on the flag.
4926 * For current userspace, prohibit it since it won't work right.
4931 if (hwsim_net_get_wmediumd(net))
4934 hwsim_register_wmediumd(net, info->snd_portid);
4936 pr_debug("mac80211_hwsim: received a REGISTER, "
4937 "switching to wmediumd mode with pid %d\n", info->snd_portid);
4942 /* ensures ciphers only include ciphers listed in 'hwsim_ciphers' array */
4943 static bool hwsim_known_ciphers(const u32 *ciphers, int n_ciphers)
4947 for (i = 0; i < n_ciphers; i++) {
4951 for (j = 0; j < ARRAY_SIZE(hwsim_ciphers); j++) {
4952 if (ciphers[i] == hwsim_ciphers[j]) {
4965 static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
4967 struct hwsim_new_radio_params param = { 0 };
4968 const char *hwname = NULL;
4971 param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
4972 param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
4973 param.channels = channels;
4974 param.destroy_on_close =
4975 info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE];
4977 if (info->attrs[HWSIM_ATTR_CHANNELS])
4978 param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
4980 if (param.channels < 1) {
4981 GENL_SET_ERR_MSG(info, "must have at least one channel");
4985 if (info->attrs[HWSIM_ATTR_NO_VIF])
4986 param.no_vif = true;
4988 if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
4989 param.use_chanctx = true;
4991 param.use_chanctx = (param.channels > 1);
4993 if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
4995 nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
4997 if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
4998 u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
5000 if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
5003 idx = array_index_nospec(idx,
5004 ARRAY_SIZE(hwsim_world_regdom_custom));
5005 param.regd = hwsim_world_regdom_custom[idx];
5008 if (info->attrs[HWSIM_ATTR_PERM_ADDR]) {
5009 if (!is_valid_ether_addr(
5010 nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) {
5011 GENL_SET_ERR_MSG(info,"MAC is no valid source addr");
5012 NL_SET_BAD_ATTR(info->extack,
5013 info->attrs[HWSIM_ATTR_PERM_ADDR]);
5017 param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]);
5020 if (info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]) {
5022 nla_get_u32(info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]);
5024 if (param.iftypes & ~HWSIM_IFTYPE_SUPPORT_MASK) {
5025 NL_SET_ERR_MSG_ATTR(info->extack,
5026 info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT],
5027 "cannot support more iftypes than kernel");
5031 param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
5034 /* ensure both flag and iftype support is honored */
5035 if (param.p2p_device ||
5036 param.iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
5037 param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
5038 param.p2p_device = true;
5041 if (info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]) {
5042 u32 len = nla_len(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
5045 nla_data(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
5047 if (len % sizeof(u32)) {
5048 NL_SET_ERR_MSG_ATTR(info->extack,
5049 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5050 "bad cipher list length");
5054 param.n_ciphers = len / sizeof(u32);
5056 if (param.n_ciphers > ARRAY_SIZE(hwsim_ciphers)) {
5057 NL_SET_ERR_MSG_ATTR(info->extack,
5058 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5059 "too many ciphers specified");
5063 if (!hwsim_known_ciphers(param.ciphers, param.n_ciphers)) {
5064 NL_SET_ERR_MSG_ATTR(info->extack,
5065 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5066 "unsupported ciphers specified");
5071 param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT];
5074 param.use_chanctx = true;
5076 if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
5077 hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5078 nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5082 param.hwname = hwname;
5085 ret = mac80211_hwsim_new_radio(info, ¶m);
5090 static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
5092 struct mac80211_hwsim_data *data;
5094 const char *hwname = NULL;
5096 if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
5097 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
5098 } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
5099 hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5100 nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5107 spin_lock_bh(&hwsim_radio_lock);
5108 list_for_each_entry(data, &hwsim_radios, list) {
5110 if (data->idx != idx)
5114 strcmp(hwname, wiphy_name(data->hw->wiphy)))
5118 if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
5121 list_del(&data->list);
5122 rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
5124 hwsim_radios_generation++;
5125 spin_unlock_bh(&hwsim_radio_lock);
5126 mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
5131 spin_unlock_bh(&hwsim_radio_lock);
5137 static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info)
5139 struct mac80211_hwsim_data *data;
5140 struct sk_buff *skb;
5141 int idx, res = -ENODEV;
5143 if (!info->attrs[HWSIM_ATTR_RADIO_ID])
5145 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
5147 spin_lock_bh(&hwsim_radio_lock);
5148 list_for_each_entry(data, &hwsim_radios, list) {
5149 if (data->idx != idx)
5152 if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
5155 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
5161 res = mac80211_hwsim_get_radio(skb, data, info->snd_portid,
5162 info->snd_seq, NULL, 0);
5168 res = genlmsg_reply(skb, info);
5173 spin_unlock_bh(&hwsim_radio_lock);
5178 static int hwsim_dump_radio_nl(struct sk_buff *skb,
5179 struct netlink_callback *cb)
5181 int last_idx = cb->args[0] - 1;
5182 struct mac80211_hwsim_data *data = NULL;
5186 spin_lock_bh(&hwsim_radio_lock);
5187 cb->seq = hwsim_radios_generation;
5189 if (last_idx >= hwsim_radio_idx-1)
5192 list_for_each_entry(data, &hwsim_radios, list) {
5193 if (data->idx <= last_idx)
5196 if (!net_eq(wiphy_net(data->hw->wiphy), sock_net(skb->sk)))
5199 res = mac80211_hwsim_get_radio(skb, data,
5200 NETLINK_CB(cb->skb).portid,
5201 cb->nlh->nlmsg_seq, cb,
5206 last_idx = data->idx;
5209 cb->args[0] = last_idx + 1;
5211 /* list changed, but no new element sent, set interrupted flag */
5212 if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) {
5213 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
5214 cb->nlh->nlmsg_seq, &hwsim_genl_family,
5215 NLM_F_MULTI, HWSIM_CMD_GET_RADIO);
5217 genl_dump_check_consistent(cb, hdr);
5218 genlmsg_end(skb, hdr);
5225 spin_unlock_bh(&hwsim_radio_lock);
5226 return res ?: skb->len;
5229 /* Generic Netlink operations array */
5230 static const struct genl_small_ops hwsim_ops[] = {
5232 .cmd = HWSIM_CMD_REGISTER,
5233 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5234 .doit = hwsim_register_received_nl,
5235 .flags = GENL_UNS_ADMIN_PERM,
5238 .cmd = HWSIM_CMD_FRAME,
5239 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5240 .doit = hwsim_cloned_frame_received_nl,
5243 .cmd = HWSIM_CMD_TX_INFO_FRAME,
5244 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5245 .doit = hwsim_tx_info_frame_received_nl,
5248 .cmd = HWSIM_CMD_NEW_RADIO,
5249 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5250 .doit = hwsim_new_radio_nl,
5251 .flags = GENL_UNS_ADMIN_PERM,
5254 .cmd = HWSIM_CMD_DEL_RADIO,
5255 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5256 .doit = hwsim_del_radio_nl,
5257 .flags = GENL_UNS_ADMIN_PERM,
5260 .cmd = HWSIM_CMD_GET_RADIO,
5261 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
5262 .doit = hwsim_get_radio_nl,
5263 .dumpit = hwsim_dump_radio_nl,
5267 static struct genl_family hwsim_genl_family __ro_after_init = {
5268 .name = "MAC80211_HWSIM",
5270 .maxattr = HWSIM_ATTR_MAX,
5271 .policy = hwsim_genl_policy,
5273 .module = THIS_MODULE,
5274 .small_ops = hwsim_ops,
5275 .n_small_ops = ARRAY_SIZE(hwsim_ops),
5276 .resv_start_op = HWSIM_CMD_DEL_MAC_ADDR + 1,
5277 .mcgrps = hwsim_mcgrps,
5278 .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
5281 static void remove_user_radios(u32 portid)
5283 struct mac80211_hwsim_data *entry, *tmp;
5286 spin_lock_bh(&hwsim_radio_lock);
5287 list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
5288 if (entry->destroy_on_close && entry->portid == portid) {
5289 list_move(&entry->list, &list);
5290 rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht,
5292 hwsim_radios_generation++;
5295 spin_unlock_bh(&hwsim_radio_lock);
5297 list_for_each_entry_safe(entry, tmp, &list, list) {
5298 list_del(&entry->list);
5299 mac80211_hwsim_del_radio(entry, wiphy_name(entry->hw->wiphy),
5304 static int mac80211_hwsim_netlink_notify(struct notifier_block *nb,
5305 unsigned long state,
5308 struct netlink_notify *notify = _notify;
5310 if (state != NETLINK_URELEASE)
5313 remove_user_radios(notify->portid);
5315 if (notify->portid == hwsim_net_get_wmediumd(notify->net)) {
5316 printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink"
5317 " socket, switching to perfect channel medium\n");
5318 hwsim_register_wmediumd(notify->net, 0);
5324 static struct notifier_block hwsim_netlink_notifier = {
5325 .notifier_call = mac80211_hwsim_netlink_notify,
5328 static int __init hwsim_init_netlink(void)
5332 printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");
5334 rc = genl_register_family(&hwsim_genl_family);
5338 rc = netlink_register_notifier(&hwsim_netlink_notifier);
5340 genl_unregister_family(&hwsim_genl_family);
5347 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
5351 static __net_init int hwsim_init_net(struct net *net)
5353 return hwsim_net_set_netgroup(net);
5356 static void __net_exit hwsim_exit_net(struct net *net)
5358 struct mac80211_hwsim_data *data, *tmp;
5361 spin_lock_bh(&hwsim_radio_lock);
5362 list_for_each_entry_safe(data, tmp, &hwsim_radios, list) {
5363 if (!net_eq(wiphy_net(data->hw->wiphy), net))
5366 /* Radios created in init_net are returned to init_net. */
5367 if (data->netgroup == hwsim_net_get_netgroup(&init_net))
5370 list_move(&data->list, &list);
5371 rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
5373 hwsim_radios_generation++;
5375 spin_unlock_bh(&hwsim_radio_lock);
5377 list_for_each_entry_safe(data, tmp, &list, list) {
5378 list_del(&data->list);
5379 mac80211_hwsim_del_radio(data,
5380 wiphy_name(data->hw->wiphy),
5384 ida_free(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
5387 static struct pernet_operations hwsim_net_ops = {
5388 .init = hwsim_init_net,
5389 .exit = hwsim_exit_net,
5390 .id = &hwsim_net_id,
5391 .size = sizeof(struct hwsim_net),
5394 static void hwsim_exit_netlink(void)
5396 /* unregister the notifier */
5397 netlink_unregister_notifier(&hwsim_netlink_notifier);
5398 /* unregister the family */
5399 genl_unregister_family(&hwsim_genl_family);
5402 #if IS_REACHABLE(CONFIG_VIRTIO)
5403 static void hwsim_virtio_tx_done(struct virtqueue *vq)
5406 struct sk_buff *skb;
5407 unsigned long flags;
5409 spin_lock_irqsave(&hwsim_virtio_lock, flags);
5410 while ((skb = virtqueue_get_buf(vq, &len)))
5412 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5415 static int hwsim_virtio_handle_cmd(struct sk_buff *skb)
5417 struct nlmsghdr *nlh;
5418 struct genlmsghdr *gnlh;
5419 struct nlattr *tb[HWSIM_ATTR_MAX + 1];
5420 struct genl_info info = {};
5423 nlh = nlmsg_hdr(skb);
5424 gnlh = nlmsg_data(nlh);
5426 if (skb->len < nlh->nlmsg_len)
5429 err = genlmsg_parse(nlh, &hwsim_genl_family, tb, HWSIM_ATTR_MAX,
5430 hwsim_genl_policy, NULL);
5432 pr_err_ratelimited("hwsim: genlmsg_parse returned %d\n", err);
5438 switch (gnlh->cmd) {
5439 case HWSIM_CMD_FRAME:
5440 hwsim_cloned_frame_received_nl(skb, &info);
5442 case HWSIM_CMD_TX_INFO_FRAME:
5443 hwsim_tx_info_frame_received_nl(skb, &info);
5446 pr_err_ratelimited("hwsim: invalid cmd: %d\n", gnlh->cmd);
5452 static void hwsim_virtio_rx_work(struct work_struct *work)
5454 struct virtqueue *vq;
5456 struct sk_buff *skb;
5457 struct scatterlist sg[1];
5459 unsigned long flags;
5461 spin_lock_irqsave(&hwsim_virtio_lock, flags);
5462 if (!hwsim_virtio_enabled)
5465 skb = virtqueue_get_buf(hwsim_vqs[HWSIM_VQ_RX], &len);
5468 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5470 skb->data = skb->head;
5471 skb_reset_tail_pointer(skb);
5473 hwsim_virtio_handle_cmd(skb);
5475 spin_lock_irqsave(&hwsim_virtio_lock, flags);
5476 if (!hwsim_virtio_enabled) {
5480 vq = hwsim_vqs[HWSIM_VQ_RX];
5481 sg_init_one(sg, skb->head, skb_end_offset(skb));
5482 err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_ATOMIC);
5483 if (WARN(err, "virtqueue_add_inbuf returned %d\n", err))
5487 schedule_work(&hwsim_virtio_rx);
5490 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5493 static void hwsim_virtio_rx_done(struct virtqueue *vq)
5495 schedule_work(&hwsim_virtio_rx);
5498 static int init_vqs(struct virtio_device *vdev)
5500 vq_callback_t *callbacks[HWSIM_NUM_VQS] = {
5501 [HWSIM_VQ_TX] = hwsim_virtio_tx_done,
5502 [HWSIM_VQ_RX] = hwsim_virtio_rx_done,
5504 const char *names[HWSIM_NUM_VQS] = {
5505 [HWSIM_VQ_TX] = "tx",
5506 [HWSIM_VQ_RX] = "rx",
5509 return virtio_find_vqs(vdev, HWSIM_NUM_VQS,
5510 hwsim_vqs, callbacks, names, NULL);
5513 static int fill_vq(struct virtqueue *vq)
5516 struct sk_buff *skb;
5517 struct scatterlist sg[1];
5519 for (i = 0; i < virtqueue_get_vring_size(vq); i++) {
5520 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
5524 sg_init_one(sg, skb->head, skb_end_offset(skb));
5525 err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_KERNEL);
5535 static void remove_vqs(struct virtio_device *vdev)
5539 virtio_reset_device(vdev);
5541 for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) {
5542 struct virtqueue *vq = hwsim_vqs[i];
5543 struct sk_buff *skb;
5545 while ((skb = virtqueue_detach_unused_buf(vq)))
5549 vdev->config->del_vqs(vdev);
5552 static int hwsim_virtio_probe(struct virtio_device *vdev)
5555 unsigned long flags;
5557 spin_lock_irqsave(&hwsim_virtio_lock, flags);
5558 if (hwsim_virtio_enabled) {
5559 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5562 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5564 err = init_vqs(vdev);
5568 virtio_device_ready(vdev);
5570 err = fill_vq(hwsim_vqs[HWSIM_VQ_RX]);
5574 spin_lock_irqsave(&hwsim_virtio_lock, flags);
5575 hwsim_virtio_enabled = true;
5576 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
5578 schedule_work(&hwsim_virtio_rx);
5586 static void hwsim_virtio_remove(struct virtio_device *vdev)
5588 hwsim_virtio_enabled = false;
5590 cancel_work_sync(&hwsim_virtio_rx);
5595 /* MAC80211_HWSIM virtio device id table */
5596 static const struct virtio_device_id id_table[] = {
5597 { VIRTIO_ID_MAC80211_HWSIM, VIRTIO_DEV_ANY_ID },
5600 MODULE_DEVICE_TABLE(virtio, id_table);
5602 static struct virtio_driver virtio_hwsim = {
5603 .driver.name = KBUILD_MODNAME,
5604 .driver.owner = THIS_MODULE,
5605 .id_table = id_table,
5606 .probe = hwsim_virtio_probe,
5607 .remove = hwsim_virtio_remove,
5610 static int hwsim_register_virtio_driver(void)
5612 return register_virtio_driver(&virtio_hwsim);
5615 static void hwsim_unregister_virtio_driver(void)
5617 unregister_virtio_driver(&virtio_hwsim);
5620 static inline int hwsim_register_virtio_driver(void)
5625 static inline void hwsim_unregister_virtio_driver(void)
5630 static int __init init_mac80211_hwsim(void)
5634 if (radios < 0 || radios > 100)
5640 err = rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params);
5644 err = register_pernet_device(&hwsim_net_ops);
5648 err = platform_driver_register(&mac80211_hwsim_driver);
5650 goto out_unregister_pernet;
5652 err = hwsim_init_netlink();
5654 goto out_unregister_driver;
5656 err = hwsim_register_virtio_driver();
5658 goto out_exit_netlink;
5660 hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
5661 if (IS_ERR(hwsim_class)) {
5662 err = PTR_ERR(hwsim_class);
5663 goto out_exit_virtio;
5666 hwsim_init_s1g_channels(hwsim_channels_s1g);
5668 for (i = 0; i < radios; i++) {
5669 struct hwsim_new_radio_params param = { 0 };
5671 param.channels = channels;
5674 case HWSIM_REGTEST_DIFF_COUNTRY:
5675 if (i < ARRAY_SIZE(hwsim_alpha2s))
5676 param.reg_alpha2 = hwsim_alpha2s[i];
5678 case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
5680 param.reg_alpha2 = hwsim_alpha2s[0];
5682 case HWSIM_REGTEST_STRICT_ALL:
5683 param.reg_strict = true;
5685 case HWSIM_REGTEST_DRIVER_REG_ALL:
5686 param.reg_alpha2 = hwsim_alpha2s[0];
5688 case HWSIM_REGTEST_WORLD_ROAM:
5690 param.regd = &hwsim_world_regdom_custom_01;
5692 case HWSIM_REGTEST_CUSTOM_WORLD:
5693 param.regd = &hwsim_world_regdom_custom_01;
5695 case HWSIM_REGTEST_CUSTOM_WORLD_2:
5697 param.regd = &hwsim_world_regdom_custom_01;
5699 param.regd = &hwsim_world_regdom_custom_02;
5701 case HWSIM_REGTEST_STRICT_FOLLOW:
5703 param.reg_strict = true;
5704 param.reg_alpha2 = hwsim_alpha2s[0];
5707 case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
5709 param.reg_strict = true;
5710 param.reg_alpha2 = hwsim_alpha2s[0];
5711 } else if (i == 1) {
5712 param.reg_alpha2 = hwsim_alpha2s[1];
5715 case HWSIM_REGTEST_ALL:
5718 param.regd = &hwsim_world_regdom_custom_01;
5721 param.regd = &hwsim_world_regdom_custom_02;
5724 param.reg_alpha2 = hwsim_alpha2s[0];
5727 param.reg_alpha2 = hwsim_alpha2s[1];
5730 param.reg_strict = true;
5731 param.reg_alpha2 = hwsim_alpha2s[2];
5739 param.p2p_device = support_p2p_device;
5741 param.use_chanctx = channels > 1 || mlo;
5742 param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
5743 if (param.p2p_device)
5744 param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
5746 err = mac80211_hwsim_new_radio(NULL, ¶m);
5748 goto out_free_radios;
5751 hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN,
5753 if (hwsim_mon == NULL) {
5755 goto out_free_radios;
5759 err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
5765 err = register_netdevice(hwsim_mon);
5775 free_netdev(hwsim_mon);
5777 mac80211_hwsim_free();
5779 hwsim_unregister_virtio_driver();
5781 hwsim_exit_netlink();
5782 out_unregister_driver:
5783 platform_driver_unregister(&mac80211_hwsim_driver);
5784 out_unregister_pernet:
5785 unregister_pernet_device(&hwsim_net_ops);
5787 rhashtable_destroy(&hwsim_radios_rht);
5790 module_init(init_mac80211_hwsim);
5792 static void __exit exit_mac80211_hwsim(void)
5794 pr_debug("mac80211_hwsim: unregister radios\n");
5796 hwsim_unregister_virtio_driver();
5797 hwsim_exit_netlink();
5799 mac80211_hwsim_free();
5801 rhashtable_destroy(&hwsim_radios_rht);
5802 unregister_netdev(hwsim_mon);
5803 platform_driver_unregister(&mac80211_hwsim_driver);
5804 unregister_pernet_device(&hwsim_net_ops);
5806 module_exit(exit_mac80211_hwsim);