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;
235 #define HWSIM_STA_MAGIC 0x6d537749
237 static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
239 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
240 WARN_ON(sp->magic != HWSIM_STA_MAGIC);
243 static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
245 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
246 sp->magic = HWSIM_STA_MAGIC;
249 static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
251 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
255 struct hwsim_chanctx_priv {
259 #define HWSIM_CHANCTX_MAGIC 0x6d53774a
261 static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c)
263 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
264 WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC);
267 static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c)
269 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
270 cp->magic = HWSIM_CHANCTX_MAGIC;
273 static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c)
275 struct hwsim_chanctx_priv *cp = (void *)c->drv_priv;
279 static unsigned int hwsim_net_id;
281 static DEFINE_IDA(hwsim_netgroup_ida);
288 static inline int hwsim_net_get_netgroup(struct net *net)
290 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
292 return hwsim_net->netgroup;
295 static inline int hwsim_net_set_netgroup(struct net *net)
297 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
299 hwsim_net->netgroup = ida_alloc(&hwsim_netgroup_ida, GFP_KERNEL);
300 return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM;
303 static inline u32 hwsim_net_get_wmediumd(struct net *net)
305 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
307 return hwsim_net->wmediumd;
310 static inline void hwsim_net_set_wmediumd(struct net *net, u32 portid)
312 struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
314 hwsim_net->wmediumd = portid;
317 static struct class *hwsim_class;
319 static struct net_device *hwsim_mon; /* global monitor netdev */
321 #define CHAN2G(_freq) { \
322 .band = NL80211_BAND_2GHZ, \
323 .center_freq = (_freq), \
324 .hw_value = (_freq), \
327 #define CHAN5G(_freq) { \
328 .band = NL80211_BAND_5GHZ, \
329 .center_freq = (_freq), \
330 .hw_value = (_freq), \
333 #define CHAN6G(_freq) { \
334 .band = NL80211_BAND_6GHZ, \
335 .center_freq = (_freq), \
336 .hw_value = (_freq), \
339 static const struct ieee80211_channel hwsim_channels_2ghz[] = {
340 CHAN2G(2412), /* Channel 1 */
341 CHAN2G(2417), /* Channel 2 */
342 CHAN2G(2422), /* Channel 3 */
343 CHAN2G(2427), /* Channel 4 */
344 CHAN2G(2432), /* Channel 5 */
345 CHAN2G(2437), /* Channel 6 */
346 CHAN2G(2442), /* Channel 7 */
347 CHAN2G(2447), /* Channel 8 */
348 CHAN2G(2452), /* Channel 9 */
349 CHAN2G(2457), /* Channel 10 */
350 CHAN2G(2462), /* Channel 11 */
351 CHAN2G(2467), /* Channel 12 */
352 CHAN2G(2472), /* Channel 13 */
353 CHAN2G(2484), /* Channel 14 */
356 static const struct ieee80211_channel hwsim_channels_5ghz[] = {
357 CHAN5G(5180), /* Channel 36 */
358 CHAN5G(5200), /* Channel 40 */
359 CHAN5G(5220), /* Channel 44 */
360 CHAN5G(5240), /* Channel 48 */
362 CHAN5G(5260), /* Channel 52 */
363 CHAN5G(5280), /* Channel 56 */
364 CHAN5G(5300), /* Channel 60 */
365 CHAN5G(5320), /* Channel 64 */
367 CHAN5G(5500), /* Channel 100 */
368 CHAN5G(5520), /* Channel 104 */
369 CHAN5G(5540), /* Channel 108 */
370 CHAN5G(5560), /* Channel 112 */
371 CHAN5G(5580), /* Channel 116 */
372 CHAN5G(5600), /* Channel 120 */
373 CHAN5G(5620), /* Channel 124 */
374 CHAN5G(5640), /* Channel 128 */
375 CHAN5G(5660), /* Channel 132 */
376 CHAN5G(5680), /* Channel 136 */
377 CHAN5G(5700), /* Channel 140 */
379 CHAN5G(5745), /* Channel 149 */
380 CHAN5G(5765), /* Channel 153 */
381 CHAN5G(5785), /* Channel 157 */
382 CHAN5G(5805), /* Channel 161 */
383 CHAN5G(5825), /* Channel 165 */
384 CHAN5G(5845), /* Channel 169 */
386 CHAN5G(5855), /* Channel 171 */
387 CHAN5G(5860), /* Channel 172 */
388 CHAN5G(5865), /* Channel 173 */
389 CHAN5G(5870), /* Channel 174 */
391 CHAN5G(5875), /* Channel 175 */
392 CHAN5G(5880), /* Channel 176 */
393 CHAN5G(5885), /* Channel 177 */
394 CHAN5G(5890), /* Channel 178 */
395 CHAN5G(5895), /* Channel 179 */
396 CHAN5G(5900), /* Channel 180 */
397 CHAN5G(5905), /* Channel 181 */
399 CHAN5G(5910), /* Channel 182 */
400 CHAN5G(5915), /* Channel 183 */
401 CHAN5G(5920), /* Channel 184 */
402 CHAN5G(5925), /* Channel 185 */
405 static const struct ieee80211_channel hwsim_channels_6ghz[] = {
406 CHAN6G(5955), /* Channel 1 */
407 CHAN6G(5975), /* Channel 5 */
408 CHAN6G(5995), /* Channel 9 */
409 CHAN6G(6015), /* Channel 13 */
410 CHAN6G(6035), /* Channel 17 */
411 CHAN6G(6055), /* Channel 21 */
412 CHAN6G(6075), /* Channel 25 */
413 CHAN6G(6095), /* Channel 29 */
414 CHAN6G(6115), /* Channel 33 */
415 CHAN6G(6135), /* Channel 37 */
416 CHAN6G(6155), /* Channel 41 */
417 CHAN6G(6175), /* Channel 45 */
418 CHAN6G(6195), /* Channel 49 */
419 CHAN6G(6215), /* Channel 53 */
420 CHAN6G(6235), /* Channel 57 */
421 CHAN6G(6255), /* Channel 61 */
422 CHAN6G(6275), /* Channel 65 */
423 CHAN6G(6295), /* Channel 69 */
424 CHAN6G(6315), /* Channel 73 */
425 CHAN6G(6335), /* Channel 77 */
426 CHAN6G(6355), /* Channel 81 */
427 CHAN6G(6375), /* Channel 85 */
428 CHAN6G(6395), /* Channel 89 */
429 CHAN6G(6415), /* Channel 93 */
430 CHAN6G(6435), /* Channel 97 */
431 CHAN6G(6455), /* Channel 181 */
432 CHAN6G(6475), /* Channel 105 */
433 CHAN6G(6495), /* Channel 109 */
434 CHAN6G(6515), /* Channel 113 */
435 CHAN6G(6535), /* Channel 117 */
436 CHAN6G(6555), /* Channel 121 */
437 CHAN6G(6575), /* Channel 125 */
438 CHAN6G(6595), /* Channel 129 */
439 CHAN6G(6615), /* Channel 133 */
440 CHAN6G(6635), /* Channel 137 */
441 CHAN6G(6655), /* Channel 141 */
442 CHAN6G(6675), /* Channel 145 */
443 CHAN6G(6695), /* Channel 149 */
444 CHAN6G(6715), /* Channel 153 */
445 CHAN6G(6735), /* Channel 157 */
446 CHAN6G(6755), /* Channel 161 */
447 CHAN6G(6775), /* Channel 165 */
448 CHAN6G(6795), /* Channel 169 */
449 CHAN6G(6815), /* Channel 173 */
450 CHAN6G(6835), /* Channel 177 */
451 CHAN6G(6855), /* Channel 181 */
452 CHAN6G(6875), /* Channel 185 */
453 CHAN6G(6895), /* Channel 189 */
454 CHAN6G(6915), /* Channel 193 */
455 CHAN6G(6935), /* Channel 197 */
456 CHAN6G(6955), /* Channel 201 */
457 CHAN6G(6975), /* Channel 205 */
458 CHAN6G(6995), /* Channel 209 */
459 CHAN6G(7015), /* Channel 213 */
460 CHAN6G(7035), /* Channel 217 */
461 CHAN6G(7055), /* Channel 221 */
462 CHAN6G(7075), /* Channel 225 */
463 CHAN6G(7095), /* Channel 229 */
464 CHAN6G(7115), /* Channel 233 */
467 #define NUM_S1G_CHANS_US 51
468 static struct ieee80211_channel hwsim_channels_s1g[NUM_S1G_CHANS_US];
470 static const struct ieee80211_sta_s1g_cap hwsim_s1g_cap = {
472 .cap = { S1G_CAP0_SGI_1MHZ | S1G_CAP0_SGI_2MHZ,
475 S1G_CAP3_MAX_MPDU_LEN,
480 S1G_CAP8_TWT_RESPOND | S1G_CAP8_TWT_REQUEST,
482 .nss_mcs = { 0xfc | 1, /* MCS 7 for 1 SS */
483 /* RX Highest Supported Long GI Data Rate 0:7 */
485 /* RX Highest Supported Long GI Data Rate 0:7 */
486 /* TX S1G MCS Map 0:6 */
488 /* TX S1G MCS Map :7 */
489 /* TX Highest Supported Long GI Data Rate 0:6 */
491 /* TX Highest Supported Long GI Data Rate 7:8 */
492 /* Rx Single spatial stream and S1G-MCS Map for 1MHz */
493 /* Tx Single spatial stream and S1G-MCS Map for 1MHz */
497 static void hwsim_init_s1g_channels(struct ieee80211_channel *chans)
501 for (ch = 0; ch < NUM_S1G_CHANS_US; ch++) {
502 freq = 902000 + (ch + 1) * 500;
503 chans[ch].band = NL80211_BAND_S1GHZ;
504 chans[ch].center_freq = KHZ_TO_MHZ(freq);
505 chans[ch].freq_offset = freq % 1000;
506 chans[ch].hw_value = ch + 1;
510 static const struct ieee80211_rate hwsim_rates[] = {
512 { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
513 { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
514 { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
525 #define DEFAULT_RX_RSSI -50
527 static const u32 hwsim_ciphers[] = {
528 WLAN_CIPHER_SUITE_WEP40,
529 WLAN_CIPHER_SUITE_WEP104,
530 WLAN_CIPHER_SUITE_TKIP,
531 WLAN_CIPHER_SUITE_CCMP,
532 WLAN_CIPHER_SUITE_CCMP_256,
533 WLAN_CIPHER_SUITE_GCMP,
534 WLAN_CIPHER_SUITE_GCMP_256,
535 WLAN_CIPHER_SUITE_AES_CMAC,
536 WLAN_CIPHER_SUITE_BIP_CMAC_256,
537 WLAN_CIPHER_SUITE_BIP_GMAC_128,
538 WLAN_CIPHER_SUITE_BIP_GMAC_256,
541 #define OUI_QCA 0x001374
542 #define QCA_NL80211_SUBCMD_TEST 1
543 enum qca_nl80211_vendor_subcmds {
544 QCA_WLAN_VENDOR_ATTR_TEST = 8,
545 QCA_WLAN_VENDOR_ATTR_MAX = QCA_WLAN_VENDOR_ATTR_TEST
548 static const struct nla_policy
549 hwsim_vendor_test_policy[QCA_WLAN_VENDOR_ATTR_MAX + 1] = {
550 [QCA_WLAN_VENDOR_ATTR_MAX] = { .type = NLA_U32 },
553 static int mac80211_hwsim_vendor_cmd_test(struct wiphy *wiphy,
554 struct wireless_dev *wdev,
555 const void *data, int data_len)
558 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1];
562 err = nla_parse_deprecated(tb, QCA_WLAN_VENDOR_ATTR_MAX, data,
563 data_len, hwsim_vendor_test_policy, NULL);
566 if (!tb[QCA_WLAN_VENDOR_ATTR_TEST])
568 val = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_TEST]);
569 wiphy_dbg(wiphy, "%s: test=%u\n", __func__, val);
571 /* Send a vendor event as a test. Note that this would not normally be
572 * done within a command handler, but rather, based on some other
573 * trigger. For simplicity, this command is used to trigger the event
576 * event_idx = 0 (index in mac80211_hwsim_vendor_commands)
578 skb = cfg80211_vendor_event_alloc(wiphy, wdev, 100, 0, GFP_KERNEL);
580 /* skb_put() or nla_put() will fill up data within
581 * NL80211_ATTR_VENDOR_DATA.
584 /* Add vendor data */
585 nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 1);
587 /* Send the event - this will call nla_nest_end() */
588 cfg80211_vendor_event(skb, GFP_KERNEL);
591 /* Send a response to the command */
592 skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, 10);
596 /* skb_put() or nla_put() will fill up data within
597 * NL80211_ATTR_VENDOR_DATA
599 nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 2);
601 return cfg80211_vendor_cmd_reply(skb);
604 static struct wiphy_vendor_command mac80211_hwsim_vendor_commands[] = {
606 .info = { .vendor_id = OUI_QCA,
607 .subcmd = QCA_NL80211_SUBCMD_TEST },
608 .flags = WIPHY_VENDOR_CMD_NEED_NETDEV,
609 .doit = mac80211_hwsim_vendor_cmd_test,
610 .policy = hwsim_vendor_test_policy,
611 .maxattr = QCA_WLAN_VENDOR_ATTR_MAX,
615 /* Advertise support vendor specific events */
616 static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events[] = {
617 { .vendor_id = OUI_QCA, .subcmd = 1 },
620 static DEFINE_SPINLOCK(hwsim_radio_lock);
621 static LIST_HEAD(hwsim_radios);
622 static struct rhashtable hwsim_radios_rht;
623 static int hwsim_radio_idx;
624 static int hwsim_radios_generation = 1;
626 static struct platform_driver mac80211_hwsim_driver = {
628 .name = "mac80211_hwsim",
632 struct mac80211_hwsim_link_data {
634 u64 beacon_int /* beacon interval in us */;
635 struct hrtimer beacon_timer;
638 struct mac80211_hwsim_data {
639 struct list_head list;
640 struct rhash_head rht;
641 struct ieee80211_hw *hw;
643 struct ieee80211_supported_band bands[NUM_NL80211_BANDS];
644 struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)];
645 struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)];
646 struct ieee80211_channel channels_6ghz[ARRAY_SIZE(hwsim_channels_6ghz)];
647 struct ieee80211_channel channels_s1g[ARRAY_SIZE(hwsim_channels_s1g)];
648 struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
649 struct ieee80211_iface_combination if_combination;
650 struct ieee80211_iface_limit if_limits[3];
653 u32 ciphers[ARRAY_SIZE(hwsim_ciphers)];
655 struct mac_address addresses[2];
658 bool destroy_on_close;
661 const struct ieee80211_regdomain *regd;
663 struct ieee80211_channel *tmp_chan;
664 struct ieee80211_channel *roc_chan;
666 struct delayed_work roc_start;
667 struct delayed_work roc_done;
668 struct delayed_work hw_scan;
669 struct cfg80211_scan_request *hw_scan_request;
670 struct ieee80211_vif *hw_scan_vif;
672 u8 scan_addr[ETH_ALEN];
674 struct ieee80211_channel *channel;
675 unsigned long next_start, start, end;
676 } survey_data[ARRAY_SIZE(hwsim_channels_2ghz) +
677 ARRAY_SIZE(hwsim_channels_5ghz) +
678 ARRAY_SIZE(hwsim_channels_6ghz)];
680 struct ieee80211_channel *channel;
681 enum nl80211_chan_width bw;
682 unsigned int rx_filter;
683 bool started, idle, scanning;
686 PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
688 bool ps_poll_pending;
689 struct dentry *debugfs;
691 atomic_t pending_cookie;
692 struct sk_buff_head pending; /* packets pending */
694 * Only radios in the same group can communicate together (the
695 * channel has to match too). Each bit represents a group. A
696 * radio can be in more than one group.
700 /* group shared by radios created in the same netns */
702 /* wmediumd portid responsible for netgroup of this radio */
705 /* difference between this hw's clock and the real clock, in usecs */
708 /* absolute beacon transmission time. Used to cover up "tx" delay. */
719 /* RSSI in rx status of the receiver */
722 /* only used when pmsr capability is supplied */
723 struct cfg80211_pmsr_capabilities pmsr_capa;
724 struct cfg80211_pmsr_request *pmsr_request;
725 struct wireless_dev *pmsr_request_wdev;
727 struct mac80211_hwsim_link_data link_data[IEEE80211_MLD_MAX_NUM_LINKS];
730 static const struct rhashtable_params hwsim_rht_params = {
732 .automatic_shrinking = true,
734 .key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]),
735 .head_offset = offsetof(struct mac80211_hwsim_data, rht),
738 struct hwsim_radiotap_hdr {
739 struct ieee80211_radiotap_header hdr;
747 struct hwsim_radiotap_ack_hdr {
748 struct ieee80211_radiotap_header hdr;
755 static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr)
757 return rhashtable_lookup_fast(&hwsim_radios_rht, addr, hwsim_rht_params);
760 /* MAC80211_HWSIM netlink family */
761 static struct genl_family hwsim_genl_family;
763 enum hwsim_multicast_groups {
767 static const struct genl_multicast_group hwsim_mcgrps[] = {
768 [HWSIM_MCGRP_CONFIG] = { .name = "config", },
771 /* MAC80211_HWSIM netlink policy */
773 static const struct nla_policy
774 hwsim_rate_info_policy[HWSIM_RATE_INFO_ATTR_MAX + 1] = {
775 [HWSIM_RATE_INFO_ATTR_FLAGS] = { .type = NLA_U8 },
776 [HWSIM_RATE_INFO_ATTR_MCS] = { .type = NLA_U8 },
777 [HWSIM_RATE_INFO_ATTR_LEGACY] = { .type = NLA_U16 },
778 [HWSIM_RATE_INFO_ATTR_NSS] = { .type = NLA_U8 },
779 [HWSIM_RATE_INFO_ATTR_BW] = { .type = NLA_U8 },
780 [HWSIM_RATE_INFO_ATTR_HE_GI] = { .type = NLA_U8 },
781 [HWSIM_RATE_INFO_ATTR_HE_DCM] = { .type = NLA_U8 },
782 [HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC] = { .type = NLA_U8 },
783 [HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH] = { .type = NLA_U8 },
784 [HWSIM_RATE_INFO_ATTR_EHT_GI] = { .type = NLA_U8 },
785 [HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC] = { .type = NLA_U8 },
788 static const struct nla_policy
789 hwsim_ftm_result_policy[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1] = {
790 [NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON] = { .type = NLA_U32 },
791 [NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX] = { .type = NLA_U16 },
792 [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS] = { .type = NLA_U32 },
793 [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES] = { .type = NLA_U32 },
794 [NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME] = { .type = NLA_U8 },
795 [NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP] = { .type = NLA_U8 },
796 [NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION] = { .type = NLA_U8 },
797 [NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST] = { .type = NLA_U8 },
798 [NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG] = { .type = NLA_U32 },
799 [NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD] = { .type = NLA_U32 },
800 [NL80211_PMSR_FTM_RESP_ATTR_TX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy),
801 [NL80211_PMSR_FTM_RESP_ATTR_RX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy),
802 [NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG] = { .type = NLA_U64 },
803 [NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE] = { .type = NLA_U64 },
804 [NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD] = { .type = NLA_U64 },
805 [NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG] = { .type = NLA_U64 },
806 [NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE] = { .type = NLA_U64 },
807 [NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD] = { .type = NLA_U64 },
808 [NL80211_PMSR_FTM_RESP_ATTR_LCI] = { .type = NLA_STRING },
809 [NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_STRING },
812 static const struct nla_policy
813 hwsim_pmsr_resp_type_policy[NL80211_PMSR_TYPE_MAX + 1] = {
814 [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_result_policy),
817 static const struct nla_policy
818 hwsim_pmsr_resp_policy[NL80211_PMSR_RESP_ATTR_MAX + 1] = {
819 [NL80211_PMSR_RESP_ATTR_STATUS] = { .type = NLA_U32 },
820 [NL80211_PMSR_RESP_ATTR_HOST_TIME] = { .type = NLA_U64 },
821 [NL80211_PMSR_RESP_ATTR_AP_TSF] = { .type = NLA_U64 },
822 [NL80211_PMSR_RESP_ATTR_FINAL] = { .type = NLA_FLAG },
823 [NL80211_PMSR_RESP_ATTR_DATA] = NLA_POLICY_NESTED(hwsim_pmsr_resp_type_policy),
826 static const struct nla_policy
827 hwsim_pmsr_peer_result_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
828 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT,
829 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_REJECT },
830 [NL80211_PMSR_PEER_ATTR_REQ] = { .type = NLA_REJECT },
831 [NL80211_PMSR_PEER_ATTR_RESP] = NLA_POLICY_NESTED(hwsim_pmsr_resp_policy),
834 static const struct nla_policy
835 hwsim_pmsr_peers_result_policy[NL80211_PMSR_ATTR_MAX + 1] = {
836 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
837 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
838 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
839 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
840 [NL80211_PMSR_ATTR_PEERS] = NLA_POLICY_NESTED_ARRAY(hwsim_pmsr_peer_result_policy),
843 static const struct nla_policy
844 hwsim_ftm_capa_policy[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1] = {
845 [NL80211_PMSR_FTM_CAPA_ATTR_ASAP] = { .type = NLA_FLAG },
846 [NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP] = { .type = NLA_FLAG },
847 [NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI] = { .type = NLA_FLAG },
848 [NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC] = { .type = NLA_FLAG },
849 [NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES] = { .type = NLA_U32 },
850 [NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS] = { .type = NLA_U32 },
851 [NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT] = NLA_POLICY_MAX(NLA_U8, 15),
852 [NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST] = NLA_POLICY_MAX(NLA_U8, 31),
853 [NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
854 [NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
857 static const struct nla_policy
858 hwsim_pmsr_capa_type_policy[NL80211_PMSR_TYPE_MAX + 1] = {
859 [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_capa_policy),
862 static const struct nla_policy
863 hwsim_pmsr_capa_policy[NL80211_PMSR_ATTR_MAX + 1] = {
864 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_U32 },
865 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_FLAG },
866 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_FLAG },
867 [NL80211_PMSR_ATTR_TYPE_CAPA] = NLA_POLICY_NESTED(hwsim_pmsr_capa_type_policy),
868 [NL80211_PMSR_ATTR_PEERS] = { .type = NLA_REJECT }, // only for request.
871 static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = {
872 [HWSIM_ATTR_ADDR_RECEIVER] = NLA_POLICY_ETH_ADDR_COMPAT,
873 [HWSIM_ATTR_ADDR_TRANSMITTER] = NLA_POLICY_ETH_ADDR_COMPAT,
874 [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY,
875 .len = IEEE80211_MAX_DATA_LEN },
876 [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 },
877 [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 },
878 [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 },
879 [HWSIM_ATTR_TX_INFO] = { .type = NLA_BINARY,
880 .len = IEEE80211_TX_MAX_RATES *
881 sizeof(struct hwsim_tx_rate)},
882 [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 },
883 [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 },
884 [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 },
885 [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 },
886 [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 },
887 [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG },
888 [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG },
889 [HWSIM_ATTR_USE_CHANCTX] = { .type = NLA_FLAG },
890 [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG },
891 [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING },
892 [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG },
893 [HWSIM_ATTR_FREQ] = { .type = NLA_U32 },
894 [HWSIM_ATTR_TX_INFO_FLAGS] = { .type = NLA_BINARY },
895 [HWSIM_ATTR_PERM_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT,
896 [HWSIM_ATTR_IFTYPE_SUPPORT] = { .type = NLA_U32 },
897 [HWSIM_ATTR_CIPHER_SUPPORT] = { .type = NLA_BINARY },
898 [HWSIM_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG },
899 [HWSIM_ATTR_PMSR_SUPPORT] = NLA_POLICY_NESTED(hwsim_pmsr_capa_policy),
900 [HWSIM_ATTR_PMSR_RESULT] = NLA_POLICY_NESTED(hwsim_pmsr_peers_result_policy),
903 #if IS_REACHABLE(CONFIG_VIRTIO)
905 /* MAC80211_HWSIM virtio queues */
906 static struct virtqueue *hwsim_vqs[HWSIM_NUM_VQS];
907 static bool hwsim_virtio_enabled;
908 static DEFINE_SPINLOCK(hwsim_virtio_lock);
910 static void hwsim_virtio_rx_work(struct work_struct *work);
911 static DECLARE_WORK(hwsim_virtio_rx, hwsim_virtio_rx_work);
913 static int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
916 struct scatterlist sg[1];
920 spin_lock_irqsave(&hwsim_virtio_lock, flags);
921 if (!hwsim_virtio_enabled) {
926 sg_init_one(sg, skb->head, skb_end_offset(skb));
927 err = virtqueue_add_outbuf(hwsim_vqs[HWSIM_VQ_TX], sg, 1, skb,
931 virtqueue_kick(hwsim_vqs[HWSIM_VQ_TX]);
932 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
936 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
941 /* cause a linker error if this ends up being needed */
942 extern int hwsim_tx_virtio(struct mac80211_hwsim_data *data,
943 struct sk_buff *skb);
944 #define hwsim_virtio_enabled false
947 static int hwsim_get_chanwidth(enum nl80211_chan_width bw)
950 case NL80211_CHAN_WIDTH_20_NOHT:
951 case NL80211_CHAN_WIDTH_20:
953 case NL80211_CHAN_WIDTH_40:
955 case NL80211_CHAN_WIDTH_80:
957 case NL80211_CHAN_WIDTH_80P80:
958 case NL80211_CHAN_WIDTH_160:
960 case NL80211_CHAN_WIDTH_320:
962 case NL80211_CHAN_WIDTH_5:
964 case NL80211_CHAN_WIDTH_10:
966 case NL80211_CHAN_WIDTH_1:
968 case NL80211_CHAN_WIDTH_2:
970 case NL80211_CHAN_WIDTH_4:
972 case NL80211_CHAN_WIDTH_8:
974 case NL80211_CHAN_WIDTH_16:
981 static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
983 struct ieee80211_channel *chan);
985 /* sysfs attributes */
986 static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
988 struct mac80211_hwsim_data *data = dat;
989 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
991 struct ieee80211_pspoll *pspoll;
996 wiphy_dbg(data->hw->wiphy,
997 "%s: send PS-Poll to %pM for aid %d\n",
998 __func__, vp->bssid, vp->aid);
1000 skb = dev_alloc_skb(sizeof(*pspoll));
1003 pspoll = skb_put(skb, sizeof(*pspoll));
1004 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
1005 IEEE80211_STYPE_PSPOLL |
1007 pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
1008 memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
1009 memcpy(pspoll->ta, mac, ETH_ALEN);
1012 mac80211_hwsim_tx_frame(data->hw, skb,
1013 rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
1017 static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
1018 struct ieee80211_vif *vif, int ps)
1020 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
1021 struct sk_buff *skb;
1022 struct ieee80211_hdr *hdr;
1023 struct ieee80211_tx_info *cb;
1028 wiphy_dbg(data->hw->wiphy,
1029 "%s: send data::nullfunc to %pM ps=%d\n",
1030 __func__, vp->bssid, ps);
1032 skb = dev_alloc_skb(sizeof(*hdr));
1035 hdr = skb_put(skb, sizeof(*hdr) - ETH_ALEN);
1036 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1037 IEEE80211_STYPE_NULLFUNC |
1038 IEEE80211_FCTL_TODS |
1039 (ps ? IEEE80211_FCTL_PM : 0));
1040 hdr->duration_id = cpu_to_le16(0);
1041 memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
1042 memcpy(hdr->addr2, mac, ETH_ALEN);
1043 memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
1045 cb = IEEE80211_SKB_CB(skb);
1046 cb->control.rates[0].count = 1;
1047 cb->control.rates[1].idx = -1;
1050 mac80211_hwsim_tx_frame(data->hw, skb,
1051 rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan);
1056 static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
1057 struct ieee80211_vif *vif)
1059 struct mac80211_hwsim_data *data = dat;
1060 hwsim_send_nullfunc(data, mac, vif, 1);
1063 static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
1064 struct ieee80211_vif *vif)
1066 struct mac80211_hwsim_data *data = dat;
1067 hwsim_send_nullfunc(data, mac, vif, 0);
1070 static int hwsim_fops_ps_read(void *dat, u64 *val)
1072 struct mac80211_hwsim_data *data = dat;
1077 static int hwsim_fops_ps_write(void *dat, u64 val)
1079 struct mac80211_hwsim_data *data = dat;
1080 enum ps_mode old_ps;
1082 if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
1083 val != PS_MANUAL_POLL)
1086 if (val == PS_MANUAL_POLL) {
1087 if (data->ps != PS_ENABLED)
1090 ieee80211_iterate_active_interfaces_atomic(
1091 data->hw, IEEE80211_IFACE_ITER_NORMAL,
1092 hwsim_send_ps_poll, data);
1100 if (old_ps == PS_DISABLED && val != PS_DISABLED) {
1101 ieee80211_iterate_active_interfaces_atomic(
1102 data->hw, IEEE80211_IFACE_ITER_NORMAL,
1103 hwsim_send_nullfunc_ps, data);
1104 } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
1105 ieee80211_iterate_active_interfaces_atomic(
1106 data->hw, IEEE80211_IFACE_ITER_NORMAL,
1107 hwsim_send_nullfunc_no_ps, data);
1114 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
1117 static int hwsim_write_simulate_radar(void *dat, u64 val)
1119 struct mac80211_hwsim_data *data = dat;
1121 ieee80211_radar_detected(data->hw);
1126 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_simulate_radar, NULL,
1127 hwsim_write_simulate_radar, "%llu\n");
1129 static int hwsim_fops_group_read(void *dat, u64 *val)
1131 struct mac80211_hwsim_data *data = dat;
1136 static int hwsim_fops_group_write(void *dat, u64 val)
1138 struct mac80211_hwsim_data *data = dat;
1143 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group,
1144 hwsim_fops_group_read, hwsim_fops_group_write,
1147 static int hwsim_fops_rx_rssi_read(void *dat, u64 *val)
1149 struct mac80211_hwsim_data *data = dat;
1150 *val = data->rx_rssi;
1154 static int hwsim_fops_rx_rssi_write(void *dat, u64 val)
1156 struct mac80211_hwsim_data *data = dat;
1157 int rssi = (int)val;
1159 if (rssi >= 0 || rssi < -100)
1162 data->rx_rssi = rssi;
1166 DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_rx_rssi,
1167 hwsim_fops_rx_rssi_read, hwsim_fops_rx_rssi_write,
1170 static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb,
1171 struct net_device *dev)
1173 /* TODO: allow packet injection */
1175 return NETDEV_TX_OK;
1178 static inline u64 mac80211_hwsim_get_tsf_raw(void)
1180 return ktime_to_us(ktime_get_real());
1183 static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data)
1185 u64 now = mac80211_hwsim_get_tsf_raw();
1186 return cpu_to_le64(now + data->tsf_offset);
1189 static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw,
1190 struct ieee80211_vif *vif)
1192 struct mac80211_hwsim_data *data = hw->priv;
1193 return le64_to_cpu(__mac80211_hwsim_get_tsf(data));
1196 static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw,
1197 struct ieee80211_vif *vif, u64 tsf)
1199 struct mac80211_hwsim_data *data = hw->priv;
1200 u64 now = mac80211_hwsim_get_tsf(hw, vif);
1201 /* MLD not supported here */
1202 u32 bcn_int = data->link_data[0].beacon_int;
1203 u64 delta = abs(tsf - now);
1205 /* adjust after beaconing with new timestamp at old TBTT */
1207 data->tsf_offset += delta;
1208 data->bcn_delta = do_div(delta, bcn_int);
1210 data->tsf_offset -= delta;
1211 data->bcn_delta = -(s64)do_div(delta, bcn_int);
1215 static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
1216 struct sk_buff *tx_skb,
1217 struct ieee80211_channel *chan)
1219 struct mac80211_hwsim_data *data = hw->priv;
1220 struct sk_buff *skb;
1221 struct hwsim_radiotap_hdr *hdr;
1223 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
1224 struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
1229 bitrate = txrate->bitrate;
1231 if (!netif_running(hwsim_mon))
1234 skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
1238 hdr = skb_push(skb, sizeof(*hdr));
1239 hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
1240 hdr->hdr.it_pad = 0;
1241 hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
1242 hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1243 (1 << IEEE80211_RADIOTAP_RATE) |
1244 (1 << IEEE80211_RADIOTAP_TSFT) |
1245 (1 << IEEE80211_RADIOTAP_CHANNEL));
1246 hdr->rt_tsft = __mac80211_hwsim_get_tsf(data);
1248 hdr->rt_rate = bitrate / 5;
1249 hdr->rt_channel = cpu_to_le16(chan->center_freq);
1250 flags = IEEE80211_CHAN_2GHZ;
1251 if (txrate && txrate->flags & IEEE80211_RATE_ERP_G)
1252 flags |= IEEE80211_CHAN_OFDM;
1254 flags |= IEEE80211_CHAN_CCK;
1255 hdr->rt_chbitmask = cpu_to_le16(flags);
1257 skb->dev = hwsim_mon;
1258 skb_reset_mac_header(skb);
1259 skb->ip_summed = CHECKSUM_UNNECESSARY;
1260 skb->pkt_type = PACKET_OTHERHOST;
1261 skb->protocol = htons(ETH_P_802_2);
1262 memset(skb->cb, 0, sizeof(skb->cb));
1267 static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan,
1270 struct sk_buff *skb;
1271 struct hwsim_radiotap_ack_hdr *hdr;
1273 struct ieee80211_hdr *hdr11;
1275 if (!netif_running(hwsim_mon))
1278 skb = dev_alloc_skb(100);
1282 hdr = skb_put(skb, sizeof(*hdr));
1283 hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
1284 hdr->hdr.it_pad = 0;
1285 hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
1286 hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
1287 (1 << IEEE80211_RADIOTAP_CHANNEL));
1290 hdr->rt_channel = cpu_to_le16(chan->center_freq);
1291 flags = IEEE80211_CHAN_2GHZ;
1292 hdr->rt_chbitmask = cpu_to_le16(flags);
1294 hdr11 = skb_put(skb, 10);
1295 hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
1296 IEEE80211_STYPE_ACK);
1297 hdr11->duration_id = cpu_to_le16(0);
1298 memcpy(hdr11->addr1, addr, ETH_ALEN);
1300 skb->dev = hwsim_mon;
1301 skb_reset_mac_header(skb);
1302 skb->ip_summed = CHECKSUM_UNNECESSARY;
1303 skb->pkt_type = PACKET_OTHERHOST;
1304 skb->protocol = htons(ETH_P_802_2);
1305 memset(skb->cb, 0, sizeof(skb->cb));
1309 struct mac80211_hwsim_addr_match_data {
1314 static void mac80211_hwsim_addr_iter(void *data, u8 *mac,
1315 struct ieee80211_vif *vif)
1318 struct mac80211_hwsim_addr_match_data *md = data;
1320 if (memcmp(mac, md->addr, ETH_ALEN) == 0) {
1325 /* Match the link address */
1326 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1327 struct ieee80211_bss_conf *conf;
1329 conf = rcu_dereference(vif->link_conf[i]);
1333 if (memcmp(conf->addr, md->addr, ETH_ALEN) == 0) {
1340 static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data,
1343 struct mac80211_hwsim_addr_match_data md = {
1347 if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0)
1350 memcpy(md.addr, addr, ETH_ALEN);
1352 ieee80211_iterate_active_interfaces_atomic(data->hw,
1353 IEEE80211_IFACE_ITER_NORMAL,
1354 mac80211_hwsim_addr_iter,
1360 static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
1361 struct sk_buff *skb)
1369 /* TODO: accept (some) Beacons by default and other frames only
1370 * if pending PS-Poll has been sent */
1372 case PS_MANUAL_POLL:
1373 /* Allow unicast frames to own address if there is a pending
1375 if (data->ps_poll_pending &&
1376 mac80211_hwsim_addr_match(data, skb->data + 4)) {
1377 data->ps_poll_pending = false;
1386 static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data,
1387 struct sk_buff *skb, int portid)
1394 for_each_net_rcu(net) {
1395 if (data->netgroup == hwsim_net_get_netgroup(net)) {
1396 res = genlmsg_unicast(net, skb, portid);
1409 static void mac80211_hwsim_config_mac_nl(struct ieee80211_hw *hw,
1410 const u8 *addr, bool add)
1412 struct mac80211_hwsim_data *data = hw->priv;
1413 u32 _portid = READ_ONCE(data->wmediumd);
1414 struct sk_buff *skb;
1417 WARN_ON(!is_valid_ether_addr(addr));
1419 if (!_portid && !hwsim_virtio_enabled)
1422 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1426 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
1427 add ? HWSIM_CMD_ADD_MAC_ADDR :
1428 HWSIM_CMD_DEL_MAC_ADDR);
1430 pr_debug("mac80211_hwsim: problem with msg_head\n");
1431 goto nla_put_failure;
1434 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
1435 ETH_ALEN, data->addresses[1].addr))
1436 goto nla_put_failure;
1438 if (nla_put(skb, HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, addr))
1439 goto nla_put_failure;
1441 genlmsg_end(skb, msg_head);
1443 if (hwsim_virtio_enabled)
1444 hwsim_tx_virtio(data, skb);
1446 hwsim_unicast_netgroup(data, skb, _portid);
1452 static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate)
1456 if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1457 result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS;
1458 if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT)
1459 result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT;
1460 if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
1461 result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE;
1462 if (rate->flags & IEEE80211_TX_RC_MCS)
1463 result |= MAC80211_HWSIM_TX_RC_MCS;
1464 if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD)
1465 result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD;
1466 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1467 result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH;
1468 if (rate->flags & IEEE80211_TX_RC_DUP_DATA)
1469 result |= MAC80211_HWSIM_TX_RC_DUP_DATA;
1470 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
1471 result |= MAC80211_HWSIM_TX_RC_SHORT_GI;
1472 if (rate->flags & IEEE80211_TX_RC_VHT_MCS)
1473 result |= MAC80211_HWSIM_TX_RC_VHT_MCS;
1474 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1475 result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH;
1476 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1477 result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH;
1482 static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
1483 struct sk_buff *my_skb,
1485 struct ieee80211_channel *channel)
1487 struct sk_buff *skb;
1488 struct mac80211_hwsim_data *data = hw->priv;
1489 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data;
1490 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb);
1492 unsigned int hwsim_flags = 0;
1494 struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
1495 struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES];
1498 if (data->ps != PS_DISABLED)
1499 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1500 /* If the queue contains MAX_QUEUE skb's drop some */
1501 if (skb_queue_len(&data->pending) >= MAX_QUEUE) {
1502 /* Dropping until WARN_QUEUE level */
1503 while (skb_queue_len(&data->pending) >= WARN_QUEUE) {
1504 ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
1509 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC);
1511 goto nla_put_failure;
1513 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
1515 if (msg_head == NULL) {
1516 pr_debug("mac80211_hwsim: problem with msg_head\n");
1517 goto nla_put_failure;
1520 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
1521 ETH_ALEN, data->addresses[1].addr))
1522 goto nla_put_failure;
1524 /* We get the skb->data */
1525 if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data))
1526 goto nla_put_failure;
1528 /* We get the flags for this transmission, and we translate them to
1531 if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS)
1532 hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS;
1534 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
1535 hwsim_flags |= HWSIM_TX_CTL_NO_ACK;
1537 if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags))
1538 goto nla_put_failure;
1540 if (nla_put_u32(skb, HWSIM_ATTR_FREQ, channel->center_freq))
1541 goto nla_put_failure;
1543 /* We get the tx control (rate and retries) info*/
1545 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
1546 tx_attempts[i].idx = info->status.rates[i].idx;
1547 tx_attempts_flags[i].idx = info->status.rates[i].idx;
1548 tx_attempts[i].count = info->status.rates[i].count;
1549 tx_attempts_flags[i].flags =
1550 trans_tx_rate_flags_ieee2hwsim(
1551 &info->status.rates[i]);
1554 if (nla_put(skb, HWSIM_ATTR_TX_INFO,
1555 sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES,
1557 goto nla_put_failure;
1559 if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS,
1560 sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES,
1562 goto nla_put_failure;
1564 /* We create a cookie to identify this skb */
1565 cookie = atomic_inc_return(&data->pending_cookie);
1566 info->rate_driver_data[0] = (void *)cookie;
1567 if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD))
1568 goto nla_put_failure;
1570 genlmsg_end(skb, msg_head);
1572 if (hwsim_virtio_enabled) {
1573 if (hwsim_tx_virtio(data, skb))
1574 goto err_free_txskb;
1576 if (hwsim_unicast_netgroup(data, skb, dst_portid))
1577 goto err_free_txskb;
1580 /* Enqueue the packet */
1581 skb_queue_tail(&data->pending, my_skb);
1583 data->tx_bytes += my_skb->len;
1589 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
1590 ieee80211_free_txskb(hw, my_skb);
1594 static bool hwsim_chans_compat(struct ieee80211_channel *c1,
1595 struct ieee80211_channel *c2)
1600 return c1->center_freq == c2->center_freq;
1603 struct tx_iter_data {
1604 struct ieee80211_channel *channel;
1608 static void mac80211_hwsim_tx_iter(void *_data, u8 *addr,
1609 struct ieee80211_vif *vif)
1611 struct tx_iter_data *data = _data;
1614 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1615 struct ieee80211_bss_conf *conf;
1616 struct ieee80211_chanctx_conf *chanctx;
1618 conf = rcu_dereference(vif->link_conf[i]);
1622 chanctx = rcu_dereference(conf->chanctx_conf);
1626 if (!hwsim_chans_compat(data->channel, chanctx->def.chan))
1629 data->receive = true;
1634 static void mac80211_hwsim_add_vendor_rtap(struct sk_buff *skb)
1637 * To enable this code, #define the HWSIM_RADIOTAP_OUI,
1639 * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00"
1640 * (but you should use a valid OUI, not that)
1642 * If anyone wants to 'donate' a radiotap OUI/subns code
1643 * please send a patch removing this #ifdef and changing
1644 * the values accordingly.
1646 #ifdef HWSIM_RADIOTAP_OUI
1647 struct ieee80211_radiotap_vendor_tlv *rtap;
1648 static const char vendor_data[8] = "ABCDEFGH";
1650 // Make sure no padding is needed
1651 BUILD_BUG_ON(sizeof(vendor_data) % 4);
1652 /* this is last radiotap info before the mac header, so
1653 * skb_reset_mac_header for mac8022 to know the end of
1654 * the radiotap TLV/beginning of the 802.11 header
1656 skb_reset_mac_header(skb);
1659 * Note that this code requires the headroom in the SKB
1660 * that was allocated earlier.
1662 rtap = skb_push(skb, sizeof(*rtap) + sizeof(vendor_data));
1664 rtap->len = cpu_to_le16(sizeof(*rtap) -
1665 sizeof(struct ieee80211_radiotap_tlv) +
1666 sizeof(vendor_data));
1667 rtap->type = cpu_to_le16(IEEE80211_RADIOTAP_VENDOR_NAMESPACE);
1669 rtap->content.oui[0] = HWSIM_RADIOTAP_OUI[0];
1670 rtap->content.oui[1] = HWSIM_RADIOTAP_OUI[1];
1671 rtap->content.oui[2] = HWSIM_RADIOTAP_OUI[2];
1672 rtap->content.oui_subtype = 127;
1673 /* clear reserved field */
1674 rtap->content.reserved = 0;
1675 rtap->content.vendor_type = 0;
1676 memcpy(rtap->content.data, vendor_data, sizeof(vendor_data));
1678 IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
1682 static void mac80211_hwsim_rx(struct mac80211_hwsim_data *data,
1683 struct ieee80211_rx_status *rx_status,
1684 struct sk_buff *skb)
1686 struct ieee80211_hdr *hdr = (void *)skb->data;
1688 if (!ieee80211_has_morefrags(hdr->frame_control) &&
1689 !is_multicast_ether_addr(hdr->addr1) &&
1690 (ieee80211_is_mgmt(hdr->frame_control) ||
1691 ieee80211_is_data(hdr->frame_control))) {
1692 struct ieee80211_sta *sta;
1693 unsigned int link_id;
1696 sta = ieee80211_find_sta_by_link_addrs(data->hw, hdr->addr2,
1697 hdr->addr1, &link_id);
1699 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
1701 if (ieee80211_has_pm(hdr->frame_control))
1702 sp->active_links_rx &= ~BIT(link_id);
1704 sp->active_links_rx |= BIT(link_id);
1709 memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status));
1711 mac80211_hwsim_add_vendor_rtap(skb);
1714 data->rx_bytes += skb->len;
1715 ieee80211_rx_irqsafe(data->hw, skb);
1718 static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
1719 struct sk_buff *skb,
1720 struct ieee80211_channel *chan)
1722 struct mac80211_hwsim_data *data = hw->priv, *data2;
1724 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1725 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1726 struct ieee80211_rx_status rx_status;
1729 memset(&rx_status, 0, sizeof(rx_status));
1730 rx_status.flag |= RX_FLAG_MACTIME_START;
1731 rx_status.freq = chan->center_freq;
1732 rx_status.freq_offset = chan->freq_offset ? 1 : 0;
1733 rx_status.band = chan->band;
1734 if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) {
1735 rx_status.rate_idx =
1736 ieee80211_rate_get_vht_mcs(&info->control.rates[0]);
1738 ieee80211_rate_get_vht_nss(&info->control.rates[0]);
1739 rx_status.encoding = RX_ENC_VHT;
1741 rx_status.rate_idx = info->control.rates[0].idx;
1742 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
1743 rx_status.encoding = RX_ENC_HT;
1745 if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
1746 rx_status.bw = RATE_INFO_BW_40;
1747 else if (info->control.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
1748 rx_status.bw = RATE_INFO_BW_80;
1749 else if (info->control.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
1750 rx_status.bw = RATE_INFO_BW_160;
1752 rx_status.bw = RATE_INFO_BW_20;
1753 if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI)
1754 rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI;
1755 /* TODO: simulate optional packet loss */
1756 rx_status.signal = data->rx_rssi;
1757 if (info->control.vif)
1758 rx_status.signal += info->control.vif->bss_conf.txpower;
1760 if (data->ps != PS_DISABLED)
1761 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
1763 /* release the skb's source info */
1771 * Get absolute mactime here so all HWs RX at the "same time", and
1772 * absolute TX time for beacon mactime so the timestamp matches.
1773 * Giving beacons a different mactime than non-beacons looks messy, but
1774 * it helps the Toffset be exact and a ~10us mactime discrepancy
1775 * probably doesn't really matter.
1777 if (ieee80211_is_beacon(hdr->frame_control) ||
1778 ieee80211_is_probe_resp(hdr->frame_control)) {
1779 rx_status.boottime_ns = ktime_get_boottime_ns();
1780 now = data->abs_bcn_ts;
1782 now = mac80211_hwsim_get_tsf_raw();
1785 /* Copy skb to all enabled radios that are on the current frequency */
1786 spin_lock(&hwsim_radio_lock);
1787 list_for_each_entry(data2, &hwsim_radios, list) {
1788 struct sk_buff *nskb;
1789 struct tx_iter_data tx_iter_data = {
1797 if (!data2->started || (data2->idle && !data2->tmp_chan) ||
1798 !hwsim_ps_rx_ok(data2, skb))
1801 if (!(data->group & data2->group))
1804 if (data->netgroup != data2->netgroup)
1807 if (!hwsim_chans_compat(chan, data2->tmp_chan) &&
1808 !hwsim_chans_compat(chan, data2->channel)) {
1809 ieee80211_iterate_active_interfaces_atomic(
1810 data2->hw, IEEE80211_IFACE_ITER_NORMAL,
1811 mac80211_hwsim_tx_iter, &tx_iter_data);
1812 if (!tx_iter_data.receive)
1817 * reserve some space for our vendor and the normal
1818 * radiotap header, since we're copying anyway
1820 if (skb->len < PAGE_SIZE && paged_rx) {
1821 struct page *page = alloc_page(GFP_ATOMIC);
1826 nskb = dev_alloc_skb(128);
1832 memcpy(page_address(page), skb->data, skb->len);
1833 skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len);
1835 nskb = skb_copy(skb, GFP_ATOMIC);
1840 if (mac80211_hwsim_addr_match(data2, hdr->addr1))
1843 rx_status.mactime = now + data2->tsf_offset;
1845 mac80211_hwsim_rx(data2, &rx_status, nskb);
1847 spin_unlock(&hwsim_radio_lock);
1852 static struct ieee80211_bss_conf *
1853 mac80211_hwsim_select_tx_link(struct mac80211_hwsim_data *data,
1854 struct ieee80211_vif *vif,
1855 struct ieee80211_sta *sta,
1856 struct ieee80211_hdr *hdr,
1857 struct ieee80211_link_sta **link_sta)
1859 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
1862 if (!vif->valid_links)
1863 return &vif->bss_conf;
1865 WARN_ON(is_multicast_ether_addr(hdr->addr1));
1867 if (WARN_ON_ONCE(!sta->valid_links))
1868 return &vif->bss_conf;
1870 for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) {
1871 struct ieee80211_bss_conf *bss_conf;
1872 unsigned int link_id;
1874 /* round-robin the available link IDs */
1875 link_id = (sp->last_link + i + 1) % ARRAY_SIZE(vif->link_conf);
1877 if (!(vif->active_links & BIT(link_id)))
1880 if (!(sp->active_links_rx & BIT(link_id)))
1883 *link_sta = rcu_dereference(sta->link[link_id]);
1887 bss_conf = rcu_dereference(vif->link_conf[link_id]);
1888 if (WARN_ON_ONCE(!bss_conf))
1891 /* can happen while switching links */
1892 if (!rcu_access_pointer(bss_conf->chanctx_conf))
1895 sp->last_link = link_id;
1902 static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
1903 struct ieee80211_tx_control *control,
1904 struct sk_buff *skb)
1906 struct mac80211_hwsim_data *data = hw->priv;
1907 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
1908 struct ieee80211_hdr *hdr = (void *)skb->data;
1909 struct ieee80211_chanctx_conf *chanctx_conf;
1910 struct ieee80211_channel *channel;
1912 enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
1915 if (WARN_ON(skb->len < 10)) {
1916 /* Should not happen; just a sanity check for addr1 use */
1917 ieee80211_free_txskb(hw, skb);
1921 if (!data->use_chanctx) {
1922 channel = data->channel;
1924 } else if (txi->hw_queue == 4) {
1925 channel = data->tmp_chan;
1927 u8 link = u32_get_bits(IEEE80211_SKB_CB(skb)->control.flags,
1928 IEEE80211_TX_CTRL_MLO_LINK);
1929 struct ieee80211_vif *vif = txi->control.vif;
1930 struct ieee80211_link_sta *link_sta = NULL;
1931 struct ieee80211_sta *sta = control->sta;
1932 struct ieee80211_bss_conf *bss_conf;
1934 if (link != IEEE80211_LINK_UNSPECIFIED) {
1935 bss_conf = rcu_dereference(txi->control.vif->link_conf[link]);
1937 link_sta = rcu_dereference(sta->link[link]);
1939 bss_conf = mac80211_hwsim_select_tx_link(data, vif, sta,
1943 if (WARN_ON(!bss_conf)) {
1944 ieee80211_free_txskb(hw, skb);
1948 if (sta && sta->mlo) {
1949 if (WARN_ON(!link_sta)) {
1950 ieee80211_free_txskb(hw, skb);
1953 /* address translation to link addresses on TX */
1954 ether_addr_copy(hdr->addr1, link_sta->addr);
1955 ether_addr_copy(hdr->addr2, bss_conf->addr);
1956 /* translate A3 only if it's the BSSID */
1957 if (!ieee80211_has_tods(hdr->frame_control) &&
1958 !ieee80211_has_fromds(hdr->frame_control)) {
1959 if (ether_addr_equal(hdr->addr3, sta->addr))
1960 ether_addr_copy(hdr->addr3, link_sta->addr);
1961 else if (ether_addr_equal(hdr->addr3, vif->addr))
1962 ether_addr_copy(hdr->addr3, bss_conf->addr);
1964 /* no need to look at A4, if present it's SA */
1967 chanctx_conf = rcu_dereference(bss_conf->chanctx_conf);
1969 channel = chanctx_conf->def.chan;
1970 confbw = chanctx_conf->def.width;
1976 if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) {
1977 ieee80211_free_txskb(hw, skb);
1981 if (data->idle && !data->tmp_chan) {
1982 wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n");
1983 ieee80211_free_txskb(hw, skb);
1987 if (txi->control.vif)
1988 hwsim_check_magic(txi->control.vif);
1990 hwsim_check_sta_magic(control->sta);
1992 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
1993 ieee80211_get_tx_rates(txi->control.vif, control->sta, skb,
1995 ARRAY_SIZE(txi->control.rates));
1997 for (i = 0; i < ARRAY_SIZE(txi->control.rates); i++) {
1998 u16 rflags = txi->control.rates[i].flags;
1999 /* initialize to data->bw for 5/10 MHz handling */
2000 enum nl80211_chan_width bw = data->bw;
2002 if (txi->control.rates[i].idx == -1)
2005 if (rflags & IEEE80211_TX_RC_40_MHZ_WIDTH)
2006 bw = NL80211_CHAN_WIDTH_40;
2007 else if (rflags & IEEE80211_TX_RC_80_MHZ_WIDTH)
2008 bw = NL80211_CHAN_WIDTH_80;
2009 else if (rflags & IEEE80211_TX_RC_160_MHZ_WIDTH)
2010 bw = NL80211_CHAN_WIDTH_160;
2012 if (WARN_ON(hwsim_get_chanwidth(bw) > hwsim_get_chanwidth(confbw)))
2016 if (skb->len >= 24 + 8 &&
2017 ieee80211_is_probe_resp(hdr->frame_control)) {
2018 /* fake header transmission time */
2019 struct ieee80211_mgmt *mgmt;
2020 struct ieee80211_rate *txrate;
2025 mgmt = (struct ieee80211_mgmt *)skb->data;
2026 txrate = ieee80211_get_tx_rate(hw, txi);
2028 bitrate = txrate->bitrate;
2029 ts = mac80211_hwsim_get_tsf_raw();
2030 mgmt->u.probe_resp.timestamp =
2031 cpu_to_le64(ts + data->tsf_offset +
2032 24 * 8 * 10 / bitrate);
2035 mac80211_hwsim_monitor_rx(hw, skb, channel);
2037 /* wmediumd mode check */
2038 _portid = READ_ONCE(data->wmediumd);
2040 if (_portid || hwsim_virtio_enabled)
2041 return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, channel);
2043 /* NO wmediumd detected, perfect medium simulation */
2045 data->tx_bytes += skb->len;
2046 ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel);
2048 if (ack && skb->len >= 16)
2049 mac80211_hwsim_monitor_ack(channel, hdr->addr2);
2051 ieee80211_tx_info_clear_status(txi);
2053 /* frame was transmitted at most favorable rate at first attempt */
2054 txi->control.rates[0].count = 1;
2055 txi->control.rates[1].idx = -1;
2057 if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
2058 txi->flags |= IEEE80211_TX_STAT_ACK;
2059 ieee80211_tx_status_irqsafe(hw, skb);
2063 static int mac80211_hwsim_start(struct ieee80211_hw *hw)
2065 struct mac80211_hwsim_data *data = hw->priv;
2066 wiphy_dbg(hw->wiphy, "%s\n", __func__);
2067 data->started = true;
2072 static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
2074 struct mac80211_hwsim_data *data = hw->priv;
2077 data->started = false;
2079 for (i = 0; i < ARRAY_SIZE(data->link_data); i++)
2080 hrtimer_cancel(&data->link_data[i].beacon_timer);
2082 while (!skb_queue_empty(&data->pending))
2083 ieee80211_free_txskb(hw, skb_dequeue(&data->pending));
2085 wiphy_dbg(hw->wiphy, "%s\n", __func__);
2089 static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
2090 struct ieee80211_vif *vif)
2092 wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
2093 __func__, ieee80211_vif_type_p2p(vif),
2095 hwsim_set_magic(vif);
2097 if (vif->type != NL80211_IFTYPE_MONITOR)
2098 mac80211_hwsim_config_mac_nl(hw, vif->addr, true);
2101 vif->hw_queue[IEEE80211_AC_VO] = 0;
2102 vif->hw_queue[IEEE80211_AC_VI] = 1;
2103 vif->hw_queue[IEEE80211_AC_BE] = 2;
2104 vif->hw_queue[IEEE80211_AC_BK] = 3;
2110 static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw,
2111 struct ieee80211_vif *vif,
2112 enum nl80211_iftype newtype,
2115 newtype = ieee80211_iftype_p2p(newtype, newp2p);
2116 wiphy_dbg(hw->wiphy,
2117 "%s (old type=%d, new type=%d, mac_addr=%pM)\n",
2118 __func__, ieee80211_vif_type_p2p(vif),
2119 newtype, vif->addr);
2120 hwsim_check_magic(vif);
2123 * interface may change from non-AP to AP in
2124 * which case this needs to be set up again
2131 static void mac80211_hwsim_remove_interface(
2132 struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2134 wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n",
2135 __func__, ieee80211_vif_type_p2p(vif),
2137 hwsim_check_magic(vif);
2138 hwsim_clear_magic(vif);
2139 if (vif->type != NL80211_IFTYPE_MONITOR)
2140 mac80211_hwsim_config_mac_nl(hw, vif->addr, false);
2143 static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
2144 struct sk_buff *skb,
2145 struct ieee80211_channel *chan)
2147 struct mac80211_hwsim_data *data = hw->priv;
2148 u32 _portid = READ_ONCE(data->wmediumd);
2150 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) {
2151 struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb);
2152 ieee80211_get_tx_rates(txi->control.vif, NULL, skb,
2154 ARRAY_SIZE(txi->control.rates));
2157 mac80211_hwsim_monitor_rx(hw, skb, chan);
2159 if (_portid || hwsim_virtio_enabled)
2160 return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, chan);
2163 data->tx_bytes += skb->len;
2164 mac80211_hwsim_tx_frame_no_nl(hw, skb, chan);
2168 static void __mac80211_hwsim_beacon_tx(struct ieee80211_bss_conf *link_conf,
2169 struct mac80211_hwsim_data *data,
2170 struct ieee80211_hw *hw,
2171 struct ieee80211_vif *vif,
2172 struct sk_buff *skb)
2174 struct ieee80211_tx_info *info;
2175 struct ieee80211_rate *txrate;
2176 struct ieee80211_mgmt *mgmt;
2180 info = IEEE80211_SKB_CB(skb);
2181 if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE))
2182 ieee80211_get_tx_rates(vif, NULL, skb,
2183 info->control.rates,
2184 ARRAY_SIZE(info->control.rates));
2186 txrate = ieee80211_get_tx_rate(hw, info);
2188 bitrate = txrate->bitrate;
2190 mgmt = (struct ieee80211_mgmt *) skb->data;
2191 /* fake header transmission time */
2192 data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw();
2193 if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
2194 struct ieee80211_ext *ext = (void *) mgmt;
2196 ext->u.s1g_beacon.timestamp = cpu_to_le32(data->abs_bcn_ts +
2201 mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts +
2207 mac80211_hwsim_tx_frame(hw, skb,
2208 rcu_dereference(link_conf->chanctx_conf)->def.chan);
2211 static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
2212 struct ieee80211_vif *vif)
2214 struct mac80211_hwsim_link_data *link_data = arg;
2215 u32 link_id = link_data->link_id;
2216 struct ieee80211_bss_conf *link_conf;
2217 struct mac80211_hwsim_data *data =
2218 container_of(link_data, struct mac80211_hwsim_data,
2219 link_data[link_id]);
2220 struct ieee80211_hw *hw = data->hw;
2221 struct sk_buff *skb;
2223 hwsim_check_magic(vif);
2225 link_conf = rcu_dereference(vif->link_conf[link_id]);
2229 if (vif->type != NL80211_IFTYPE_AP &&
2230 vif->type != NL80211_IFTYPE_MESH_POINT &&
2231 vif->type != NL80211_IFTYPE_ADHOC &&
2232 vif->type != NL80211_IFTYPE_OCB)
2235 if (vif->mbssid_tx_vif && vif->mbssid_tx_vif != vif)
2238 if (vif->bss_conf.ema_ap) {
2239 struct ieee80211_ema_beacons *ema;
2242 ema = ieee80211_beacon_get_template_ema_list(hw, vif, link_id);
2243 if (!ema || !ema->cnt)
2246 for (i = 0; i < ema->cnt; i++) {
2247 __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif,
2249 ema->bcn[i].skb = NULL; /* Already freed */
2251 ieee80211_beacon_free_ema_list(ema);
2253 skb = ieee80211_beacon_get(hw, vif, link_id);
2257 __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif, skb);
2260 while ((skb = ieee80211_get_buffered_bc(hw, vif)) != NULL) {
2261 mac80211_hwsim_tx_frame(hw, skb,
2262 rcu_dereference(link_conf->chanctx_conf)->def.chan);
2265 if (link_conf->csa_active && ieee80211_beacon_cntdwn_is_complete(vif))
2266 ieee80211_csa_finish(vif);
2269 static enum hrtimer_restart
2270 mac80211_hwsim_beacon(struct hrtimer *timer)
2272 struct mac80211_hwsim_link_data *link_data =
2273 container_of(timer, struct mac80211_hwsim_link_data, beacon_timer);
2274 struct mac80211_hwsim_data *data =
2275 container_of(link_data, struct mac80211_hwsim_data,
2276 link_data[link_data->link_id]);
2277 struct ieee80211_hw *hw = data->hw;
2278 u64 bcn_int = link_data->beacon_int;
2281 return HRTIMER_NORESTART;
2283 ieee80211_iterate_active_interfaces_atomic(
2284 hw, IEEE80211_IFACE_ITER_NORMAL,
2285 mac80211_hwsim_beacon_tx, link_data);
2287 /* beacon at new TBTT + beacon interval */
2288 if (data->bcn_delta) {
2289 bcn_int -= data->bcn_delta;
2290 data->bcn_delta = 0;
2292 hrtimer_forward_now(&link_data->beacon_timer,
2293 ns_to_ktime(bcn_int * NSEC_PER_USEC));
2294 return HRTIMER_RESTART;
2297 static const char * const hwsim_chanwidths[] = {
2298 [NL80211_CHAN_WIDTH_5] = "ht5",
2299 [NL80211_CHAN_WIDTH_10] = "ht10",
2300 [NL80211_CHAN_WIDTH_20_NOHT] = "noht",
2301 [NL80211_CHAN_WIDTH_20] = "ht20",
2302 [NL80211_CHAN_WIDTH_40] = "ht40",
2303 [NL80211_CHAN_WIDTH_80] = "vht80",
2304 [NL80211_CHAN_WIDTH_80P80] = "vht80p80",
2305 [NL80211_CHAN_WIDTH_160] = "vht160",
2306 [NL80211_CHAN_WIDTH_1] = "1MHz",
2307 [NL80211_CHAN_WIDTH_2] = "2MHz",
2308 [NL80211_CHAN_WIDTH_4] = "4MHz",
2309 [NL80211_CHAN_WIDTH_8] = "8MHz",
2310 [NL80211_CHAN_WIDTH_16] = "16MHz",
2313 static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
2315 struct mac80211_hwsim_data *data = hw->priv;
2316 struct ieee80211_conf *conf = &hw->conf;
2317 static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
2318 [IEEE80211_SMPS_AUTOMATIC] = "auto",
2319 [IEEE80211_SMPS_OFF] = "off",
2320 [IEEE80211_SMPS_STATIC] = "static",
2321 [IEEE80211_SMPS_DYNAMIC] = "dynamic",
2325 if (conf->chandef.chan)
2326 wiphy_dbg(hw->wiphy,
2327 "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n",
2329 conf->chandef.chan->center_freq,
2330 conf->chandef.center_freq1,
2331 conf->chandef.center_freq2,
2332 hwsim_chanwidths[conf->chandef.width],
2333 !!(conf->flags & IEEE80211_CONF_IDLE),
2334 !!(conf->flags & IEEE80211_CONF_PS),
2335 smps_modes[conf->smps_mode]);
2337 wiphy_dbg(hw->wiphy,
2338 "%s (freq=0 idle=%d ps=%d smps=%s)\n",
2340 !!(conf->flags & IEEE80211_CONF_IDLE),
2341 !!(conf->flags & IEEE80211_CONF_PS),
2342 smps_modes[conf->smps_mode]);
2344 data->idle = !!(conf->flags & IEEE80211_CONF_IDLE);
2346 WARN_ON(conf->chandef.chan && data->use_chanctx);
2348 mutex_lock(&data->mutex);
2349 if (data->scanning && conf->chandef.chan) {
2350 for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
2351 if (data->survey_data[idx].channel == data->channel) {
2352 data->survey_data[idx].start =
2353 data->survey_data[idx].next_start;
2354 data->survey_data[idx].end = jiffies;
2359 data->channel = conf->chandef.chan;
2360 data->bw = conf->chandef.width;
2362 for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) {
2363 if (data->survey_data[idx].channel &&
2364 data->survey_data[idx].channel != data->channel)
2366 data->survey_data[idx].channel = data->channel;
2367 data->survey_data[idx].next_start = jiffies;
2371 data->channel = conf->chandef.chan;
2372 data->bw = conf->chandef.width;
2374 mutex_unlock(&data->mutex);
2376 for (idx = 0; idx < ARRAY_SIZE(data->link_data); idx++) {
2377 struct mac80211_hwsim_link_data *link_data =
2378 &data->link_data[idx];
2380 if (!data->started || !link_data->beacon_int) {
2381 hrtimer_cancel(&link_data->beacon_timer);
2382 } else if (!hrtimer_is_queued(&link_data->beacon_timer)) {
2383 u64 tsf = mac80211_hwsim_get_tsf(hw, NULL);
2384 u32 bcn_int = link_data->beacon_int;
2385 u64 until_tbtt = bcn_int - do_div(tsf, bcn_int);
2387 hrtimer_start(&link_data->beacon_timer,
2388 ns_to_ktime(until_tbtt * NSEC_PER_USEC),
2389 HRTIMER_MODE_REL_SOFT);
2397 static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
2398 unsigned int changed_flags,
2399 unsigned int *total_flags,u64 multicast)
2401 struct mac80211_hwsim_data *data = hw->priv;
2403 wiphy_dbg(hw->wiphy, "%s\n", __func__);
2405 data->rx_filter = 0;
2406 if (*total_flags & FIF_ALLMULTI)
2407 data->rx_filter |= FIF_ALLMULTI;
2408 if (*total_flags & FIF_MCAST_ACTION)
2409 data->rx_filter |= FIF_MCAST_ACTION;
2411 *total_flags = data->rx_filter;
2414 static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac,
2415 struct ieee80211_vif *vif)
2417 unsigned int *count = data;
2418 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2424 static void mac80211_hwsim_vif_info_changed(struct ieee80211_hw *hw,
2425 struct ieee80211_vif *vif,
2428 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2430 hwsim_check_magic(vif);
2432 wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM)\n",
2433 __func__, changed, vif->addr);
2435 if (changed & BSS_CHANGED_ASSOC) {
2436 wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n",
2437 vif->cfg.assoc, vif->cfg.aid);
2438 vp->assoc = vif->cfg.assoc;
2439 vp->aid = vif->cfg.aid;
2443 static void mac80211_hwsim_link_info_changed(struct ieee80211_hw *hw,
2444 struct ieee80211_vif *vif,
2445 struct ieee80211_bss_conf *info,
2448 struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
2449 struct mac80211_hwsim_data *data = hw->priv;
2450 unsigned int link_id = info->link_id;
2451 struct mac80211_hwsim_link_data *link_data = &data->link_data[link_id];
2453 hwsim_check_magic(vif);
2455 wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM, link id %u)\n",
2456 __func__, (unsigned long long)changed, vif->addr, link_id);
2458 if (changed & BSS_CHANGED_BSSID) {
2459 wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n",
2460 __func__, info->bssid);
2461 memcpy(vp->bssid, info->bssid, ETH_ALEN);
2464 if (changed & BSS_CHANGED_BEACON_ENABLED) {
2465 wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n",
2466 info->enable_beacon, info->beacon_int);
2467 vp->bcn_en = info->enable_beacon;
2468 if (data->started &&
2469 !hrtimer_is_queued(&link_data->beacon_timer) &&
2470 info->enable_beacon) {
2471 u64 tsf, until_tbtt;
2473 link_data->beacon_int = info->beacon_int * 1024;
2474 tsf = mac80211_hwsim_get_tsf(hw, vif);
2475 bcn_int = link_data->beacon_int;
2476 until_tbtt = bcn_int - do_div(tsf, bcn_int);
2478 hrtimer_start(&link_data->beacon_timer,
2479 ns_to_ktime(until_tbtt * NSEC_PER_USEC),
2480 HRTIMER_MODE_REL_SOFT);
2481 } else if (!info->enable_beacon) {
2482 unsigned int count = 0;
2483 ieee80211_iterate_active_interfaces_atomic(
2484 data->hw, IEEE80211_IFACE_ITER_NORMAL,
2485 mac80211_hwsim_bcn_en_iter, &count);
2486 wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u",
2489 hrtimer_cancel(&link_data->beacon_timer);
2490 link_data->beacon_int = 0;
2495 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2496 wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n",
2497 info->use_cts_prot);
2500 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2501 wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n",
2502 info->use_short_preamble);
2505 if (changed & BSS_CHANGED_ERP_SLOT) {
2506 wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot);
2509 if (changed & BSS_CHANGED_HT) {
2510 wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n",
2511 info->ht_operation_mode);
2514 if (changed & BSS_CHANGED_BASIC_RATES) {
2515 wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n",
2516 (unsigned long long) info->basic_rates);
2519 if (changed & BSS_CHANGED_TXPOWER)
2520 wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower);
2524 mac80211_hwsim_sta_rc_update(struct ieee80211_hw *hw,
2525 struct ieee80211_vif *vif,
2526 struct ieee80211_sta *sta,
2529 struct mac80211_hwsim_data *data = hw->priv;
2535 link_id < ARRAY_SIZE(vif->link_conf);
2537 enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT;
2538 struct ieee80211_bss_conf *vif_conf;
2539 struct ieee80211_link_sta *link_sta;
2541 link_sta = rcu_dereference(sta->link[link_id]);
2546 switch (link_sta->bandwidth) {
2547 #define C(_bw) case IEEE80211_STA_RX_BW_##_bw: bw = _bw; break
2556 if (!data->use_chanctx) {
2559 struct ieee80211_chanctx_conf *chanctx_conf;
2561 vif_conf = rcu_dereference(vif->link_conf[link_id]);
2562 if (WARN_ON(!vif_conf))
2565 chanctx_conf = rcu_dereference(vif_conf->chanctx_conf);
2567 if (!WARN_ON(!chanctx_conf))
2568 confbw = chanctx_conf->def.width;
2571 WARN(bw > hwsim_get_chanwidth(confbw),
2572 "intf %pM [link=%d]: bad STA %pM bandwidth %d MHz (%d) > channel config %d MHz (%d)\n",
2573 vif->addr, link_id, sta->addr, bw, sta->deflink.bandwidth,
2574 hwsim_get_chanwidth(data->bw), data->bw);
2583 static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw,
2584 struct ieee80211_vif *vif,
2585 struct ieee80211_sta *sta)
2587 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
2589 hwsim_check_magic(vif);
2590 hwsim_set_sta_magic(sta);
2591 mac80211_hwsim_sta_rc_update(hw, vif, sta, 0);
2593 if (sta->valid_links) {
2594 WARN(hweight16(sta->valid_links) > 1,
2595 "expect to add STA with single link, have 0x%x\n",
2597 sp->active_links_rx = sta->valid_links;
2603 static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw,
2604 struct ieee80211_vif *vif,
2605 struct ieee80211_sta *sta)
2607 hwsim_check_magic(vif);
2608 hwsim_clear_sta_magic(sta);
2613 static int mac80211_hwsim_sta_state(struct ieee80211_hw *hw,
2614 struct ieee80211_vif *vif,
2615 struct ieee80211_sta *sta,
2616 enum ieee80211_sta_state old_state,
2617 enum ieee80211_sta_state new_state)
2619 if (new_state == IEEE80211_STA_NOTEXIST)
2620 return mac80211_hwsim_sta_remove(hw, vif, sta);
2622 if (old_state == IEEE80211_STA_NOTEXIST)
2623 return mac80211_hwsim_sta_add(hw, vif, sta);
2626 * when client is authorized (AP station marked as such),
2629 if (vif->type == NL80211_IFTYPE_STATION &&
2630 new_state == IEEE80211_STA_AUTHORIZED && !sta->tdls)
2631 ieee80211_set_active_links_async(vif, vif->valid_links);
2636 static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
2637 struct ieee80211_vif *vif,
2638 enum sta_notify_cmd cmd,
2639 struct ieee80211_sta *sta)
2641 hwsim_check_magic(vif);
2644 case STA_NOTIFY_SLEEP:
2645 case STA_NOTIFY_AWAKE:
2646 /* TODO: make good use of these flags */
2649 WARN(1, "Invalid sta notify: %d\n", cmd);
2654 static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
2655 struct ieee80211_sta *sta,
2658 hwsim_check_sta_magic(sta);
2662 static int mac80211_hwsim_conf_tx(struct ieee80211_hw *hw,
2663 struct ieee80211_vif *vif,
2664 unsigned int link_id, u16 queue,
2665 const struct ieee80211_tx_queue_params *params)
2667 wiphy_dbg(hw->wiphy,
2668 "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n",
2670 params->txop, params->cw_min,
2671 params->cw_max, params->aifs);
2675 static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx,
2676 struct survey_info *survey)
2678 struct mac80211_hwsim_data *hwsim = hw->priv;
2680 if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data))
2683 mutex_lock(&hwsim->mutex);
2684 survey->channel = hwsim->survey_data[idx].channel;
2685 if (!survey->channel) {
2686 mutex_unlock(&hwsim->mutex);
2691 * Magically conjured dummy values --- this is only ok for simulated hardware.
2693 * A real driver which cannot determine real values noise MUST NOT
2694 * report any, especially not a magically conjured ones :-)
2696 survey->filled = SURVEY_INFO_NOISE_DBM |
2698 SURVEY_INFO_TIME_BUSY;
2699 survey->noise = -92;
2701 jiffies_to_msecs(hwsim->survey_data[idx].end -
2702 hwsim->survey_data[idx].start);
2703 /* report 12.5% of channel time is used */
2704 survey->time_busy = survey->time/8;
2705 mutex_unlock(&hwsim->mutex);
2710 #ifdef CONFIG_NL80211_TESTMODE
2712 * This section contains example code for using netlink
2713 * attributes with the testmode command in nl80211.
2716 /* These enums need to be kept in sync with userspace */
2717 enum hwsim_testmode_attr {
2718 __HWSIM_TM_ATTR_INVALID = 0,
2719 HWSIM_TM_ATTR_CMD = 1,
2720 HWSIM_TM_ATTR_PS = 2,
2723 __HWSIM_TM_ATTR_AFTER_LAST,
2724 HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1
2727 enum hwsim_testmode_cmd {
2728 HWSIM_TM_CMD_SET_PS = 0,
2729 HWSIM_TM_CMD_GET_PS = 1,
2730 HWSIM_TM_CMD_STOP_QUEUES = 2,
2731 HWSIM_TM_CMD_WAKE_QUEUES = 3,
2734 static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = {
2735 [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 },
2736 [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 },
2739 static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw,
2740 struct ieee80211_vif *vif,
2741 void *data, int len)
2743 struct mac80211_hwsim_data *hwsim = hw->priv;
2744 struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1];
2745 struct sk_buff *skb;
2748 err = nla_parse_deprecated(tb, HWSIM_TM_ATTR_MAX, data, len,
2749 hwsim_testmode_policy, NULL);
2753 if (!tb[HWSIM_TM_ATTR_CMD])
2756 switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) {
2757 case HWSIM_TM_CMD_SET_PS:
2758 if (!tb[HWSIM_TM_ATTR_PS])
2760 ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]);
2761 return hwsim_fops_ps_write(hwsim, ps);
2762 case HWSIM_TM_CMD_GET_PS:
2763 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
2764 nla_total_size(sizeof(u32)));
2767 if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps))
2768 goto nla_put_failure;
2769 return cfg80211_testmode_reply(skb);
2770 case HWSIM_TM_CMD_STOP_QUEUES:
2771 ieee80211_stop_queues(hw);
2773 case HWSIM_TM_CMD_WAKE_QUEUES:
2774 ieee80211_wake_queues(hw);
2786 static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw,
2787 struct ieee80211_vif *vif,
2788 struct ieee80211_ampdu_params *params)
2790 struct ieee80211_sta *sta = params->sta;
2791 enum ieee80211_ampdu_mlme_action action = params->action;
2792 u16 tid = params->tid;
2795 case IEEE80211_AMPDU_TX_START:
2796 return IEEE80211_AMPDU_TX_START_IMMEDIATE;
2797 case IEEE80211_AMPDU_TX_STOP_CONT:
2798 case IEEE80211_AMPDU_TX_STOP_FLUSH:
2799 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
2800 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2802 case IEEE80211_AMPDU_TX_OPERATIONAL:
2804 case IEEE80211_AMPDU_RX_START:
2805 case IEEE80211_AMPDU_RX_STOP:
2814 static void mac80211_hwsim_flush(struct ieee80211_hw *hw,
2815 struct ieee80211_vif *vif,
2816 u32 queues, bool drop)
2818 /* Not implemented, queues only on kernel side */
2821 static void hw_scan_work(struct work_struct *work)
2823 struct mac80211_hwsim_data *hwsim =
2824 container_of(work, struct mac80211_hwsim_data, hw_scan.work);
2825 struct cfg80211_scan_request *req = hwsim->hw_scan_request;
2828 mutex_lock(&hwsim->mutex);
2829 if (hwsim->scan_chan_idx >= req->n_channels) {
2830 struct cfg80211_scan_info info = {
2834 wiphy_dbg(hwsim->hw->wiphy, "hw scan complete\n");
2835 ieee80211_scan_completed(hwsim->hw, &info);
2836 hwsim->hw_scan_request = NULL;
2837 hwsim->hw_scan_vif = NULL;
2838 hwsim->tmp_chan = NULL;
2839 mutex_unlock(&hwsim->mutex);
2840 mac80211_hwsim_config_mac_nl(hwsim->hw, hwsim->scan_addr,
2845 wiphy_dbg(hwsim->hw->wiphy, "hw scan %d MHz\n",
2846 req->channels[hwsim->scan_chan_idx]->center_freq);
2848 hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx];
2849 if (hwsim->tmp_chan->flags & (IEEE80211_CHAN_NO_IR |
2850 IEEE80211_CHAN_RADAR) ||
2856 for (i = 0; i < req->n_ssids; i++) {
2857 struct sk_buff *probe;
2858 struct ieee80211_mgmt *mgmt;
2860 probe = ieee80211_probereq_get(hwsim->hw,
2863 req->ssids[i].ssid_len,
2868 mgmt = (struct ieee80211_mgmt *) probe->data;
2869 memcpy(mgmt->da, req->bssid, ETH_ALEN);
2870 memcpy(mgmt->bssid, req->bssid, ETH_ALEN);
2873 skb_put_data(probe, req->ie, req->ie_len);
2876 if (!ieee80211_tx_prepare_skb(hwsim->hw,
2879 hwsim->tmp_chan->band,
2887 mac80211_hwsim_tx_frame(hwsim->hw, probe,
2893 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan,
2894 msecs_to_jiffies(dwell));
2895 hwsim->survey_data[hwsim->scan_chan_idx].channel = hwsim->tmp_chan;
2896 hwsim->survey_data[hwsim->scan_chan_idx].start = jiffies;
2897 hwsim->survey_data[hwsim->scan_chan_idx].end =
2898 jiffies + msecs_to_jiffies(dwell);
2899 hwsim->scan_chan_idx++;
2900 mutex_unlock(&hwsim->mutex);
2903 static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw,
2904 struct ieee80211_vif *vif,
2905 struct ieee80211_scan_request *hw_req)
2907 struct mac80211_hwsim_data *hwsim = hw->priv;
2908 struct cfg80211_scan_request *req = &hw_req->req;
2910 mutex_lock(&hwsim->mutex);
2911 if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
2912 mutex_unlock(&hwsim->mutex);
2915 hwsim->hw_scan_request = req;
2916 hwsim->hw_scan_vif = vif;
2917 hwsim->scan_chan_idx = 0;
2918 if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
2919 get_random_mask_addr(hwsim->scan_addr,
2920 hw_req->req.mac_addr,
2921 hw_req->req.mac_addr_mask);
2923 memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN);
2924 memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
2925 mutex_unlock(&hwsim->mutex);
2927 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
2928 wiphy_dbg(hw->wiphy, "hwsim hw_scan request\n");
2930 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0);
2935 static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw,
2936 struct ieee80211_vif *vif)
2938 struct mac80211_hwsim_data *hwsim = hw->priv;
2939 struct cfg80211_scan_info info = {
2943 wiphy_dbg(hw->wiphy, "hwsim cancel_hw_scan\n");
2945 cancel_delayed_work_sync(&hwsim->hw_scan);
2947 mutex_lock(&hwsim->mutex);
2948 ieee80211_scan_completed(hwsim->hw, &info);
2949 hwsim->tmp_chan = NULL;
2950 hwsim->hw_scan_request = NULL;
2951 hwsim->hw_scan_vif = NULL;
2952 mutex_unlock(&hwsim->mutex);
2955 static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw,
2956 struct ieee80211_vif *vif,
2959 struct mac80211_hwsim_data *hwsim = hw->priv;
2961 mutex_lock(&hwsim->mutex);
2963 if (hwsim->scanning) {
2964 pr_debug("two hwsim sw_scans detected!\n");
2968 pr_debug("hwsim sw_scan request, prepping stuff\n");
2970 memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN);
2971 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true);
2972 hwsim->scanning = true;
2973 memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data));
2976 mutex_unlock(&hwsim->mutex);
2979 static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw,
2980 struct ieee80211_vif *vif)
2982 struct mac80211_hwsim_data *hwsim = hw->priv;
2984 mutex_lock(&hwsim->mutex);
2986 pr_debug("hwsim sw_scan_complete\n");
2987 hwsim->scanning = false;
2988 mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, false);
2989 eth_zero_addr(hwsim->scan_addr);
2991 mutex_unlock(&hwsim->mutex);
2994 static void hw_roc_start(struct work_struct *work)
2996 struct mac80211_hwsim_data *hwsim =
2997 container_of(work, struct mac80211_hwsim_data, roc_start.work);
2999 mutex_lock(&hwsim->mutex);
3001 wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC begins\n");
3002 hwsim->tmp_chan = hwsim->roc_chan;
3003 ieee80211_ready_on_channel(hwsim->hw);
3005 ieee80211_queue_delayed_work(hwsim->hw, &hwsim->roc_done,
3006 msecs_to_jiffies(hwsim->roc_duration));
3008 mutex_unlock(&hwsim->mutex);
3011 static void hw_roc_done(struct work_struct *work)
3013 struct mac80211_hwsim_data *hwsim =
3014 container_of(work, struct mac80211_hwsim_data, roc_done.work);
3016 mutex_lock(&hwsim->mutex);
3017 ieee80211_remain_on_channel_expired(hwsim->hw);
3018 hwsim->tmp_chan = NULL;
3019 mutex_unlock(&hwsim->mutex);
3021 wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC expired\n");
3024 static int mac80211_hwsim_roc(struct ieee80211_hw *hw,
3025 struct ieee80211_vif *vif,
3026 struct ieee80211_channel *chan,
3028 enum ieee80211_roc_type type)
3030 struct mac80211_hwsim_data *hwsim = hw->priv;
3032 mutex_lock(&hwsim->mutex);
3033 if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) {
3034 mutex_unlock(&hwsim->mutex);
3038 hwsim->roc_chan = chan;
3039 hwsim->roc_duration = duration;
3040 mutex_unlock(&hwsim->mutex);
3042 wiphy_dbg(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n",
3043 chan->center_freq, duration);
3044 ieee80211_queue_delayed_work(hw, &hwsim->roc_start, HZ/50);
3049 static int mac80211_hwsim_croc(struct ieee80211_hw *hw,
3050 struct ieee80211_vif *vif)
3052 struct mac80211_hwsim_data *hwsim = hw->priv;
3054 cancel_delayed_work_sync(&hwsim->roc_start);
3055 cancel_delayed_work_sync(&hwsim->roc_done);
3057 mutex_lock(&hwsim->mutex);
3058 hwsim->tmp_chan = NULL;
3059 mutex_unlock(&hwsim->mutex);
3061 wiphy_dbg(hw->wiphy, "hwsim ROC canceled\n");
3066 static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw,
3067 struct ieee80211_chanctx_conf *ctx)
3069 hwsim_set_chanctx_magic(ctx);
3070 wiphy_dbg(hw->wiphy,
3071 "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
3072 ctx->def.chan->center_freq, ctx->def.width,
3073 ctx->def.center_freq1, ctx->def.center_freq2);
3077 static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw,
3078 struct ieee80211_chanctx_conf *ctx)
3080 wiphy_dbg(hw->wiphy,
3081 "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
3082 ctx->def.chan->center_freq, ctx->def.width,
3083 ctx->def.center_freq1, ctx->def.center_freq2);
3084 hwsim_check_chanctx_magic(ctx);
3085 hwsim_clear_chanctx_magic(ctx);
3088 static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw,
3089 struct ieee80211_chanctx_conf *ctx,
3092 hwsim_check_chanctx_magic(ctx);
3093 wiphy_dbg(hw->wiphy,
3094 "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n",
3095 ctx->def.chan->center_freq, ctx->def.width,
3096 ctx->def.center_freq1, ctx->def.center_freq2);
3099 static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw,
3100 struct ieee80211_vif *vif,
3101 struct ieee80211_bss_conf *link_conf,
3102 struct ieee80211_chanctx_conf *ctx)
3104 hwsim_check_magic(vif);
3105 hwsim_check_chanctx_magic(ctx);
3107 /* if we activate a link while already associated wake it up */
3108 if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) {
3109 struct sk_buff *skb;
3111 skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true);
3114 mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan);
3122 static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw,
3123 struct ieee80211_vif *vif,
3124 struct ieee80211_bss_conf *link_conf,
3125 struct ieee80211_chanctx_conf *ctx)
3127 hwsim_check_magic(vif);
3128 hwsim_check_chanctx_magic(ctx);
3130 /* if we deactivate a link while associated suspend it first */
3131 if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) {
3132 struct sk_buff *skb;
3134 skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true);
3136 struct ieee80211_hdr *hdr = (void *)skb->data;
3138 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
3141 mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan);
3147 static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = {
3158 #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats)
3160 static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw,
3161 struct ieee80211_vif *vif,
3164 if (sset == ETH_SS_STATS)
3165 memcpy(data, *mac80211_hwsim_gstrings_stats,
3166 sizeof(mac80211_hwsim_gstrings_stats));
3169 static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw,
3170 struct ieee80211_vif *vif, int sset)
3172 if (sset == ETH_SS_STATS)
3173 return MAC80211_HWSIM_SSTATS_LEN;
3177 static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw,
3178 struct ieee80211_vif *vif,
3179 struct ethtool_stats *stats, u64 *data)
3181 struct mac80211_hwsim_data *ar = hw->priv;
3184 data[i++] = ar->tx_pkts;
3185 data[i++] = ar->tx_bytes;
3186 data[i++] = ar->rx_pkts;
3187 data[i++] = ar->rx_bytes;
3188 data[i++] = ar->tx_dropped;
3189 data[i++] = ar->tx_failed;
3191 data[i++] = ar->group;
3193 WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN);
3196 static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw)
3201 static int mac80211_hwsim_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3206 static int mac80211_hwsim_change_vif_links(struct ieee80211_hw *hw,
3207 struct ieee80211_vif *vif,
3208 u16 old_links, u16 new_links,
3209 struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS])
3211 unsigned long rem = old_links & ~new_links;
3212 unsigned long add = new_links & ~old_links;
3220 for_each_set_bit(i, &rem, IEEE80211_MLD_MAX_NUM_LINKS)
3221 mac80211_hwsim_config_mac_nl(hw, old[i]->addr, false);
3223 for_each_set_bit(i, &add, IEEE80211_MLD_MAX_NUM_LINKS) {
3224 struct ieee80211_bss_conf *link_conf;
3226 link_conf = link_conf_dereference_protected(vif, i);
3227 if (WARN_ON(!link_conf))
3230 mac80211_hwsim_config_mac_nl(hw, link_conf->addr, true);
3236 static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw,
3237 struct ieee80211_vif *vif,
3238 struct ieee80211_sta *sta,
3239 u16 old_links, u16 new_links)
3241 struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
3243 hwsim_check_sta_magic(sta);
3245 if (vif->type == NL80211_IFTYPE_STATION)
3246 sp->active_links_rx = new_links;
3251 static int mac80211_hwsim_send_pmsr_ftm_request_peer(struct sk_buff *msg,
3252 struct cfg80211_pmsr_ftm_request_peer *request)
3256 if (!request->requested)
3259 ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM);
3263 if (nla_put_u32(msg, NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE, request->preamble))
3266 if (nla_put_u16(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD, request->burst_period))
3269 if (request->asap && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_ASAP))
3272 if (request->request_lci && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI))
3275 if (request->request_civicloc &&
3276 nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC))
3279 if (request->trigger_based && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED))
3282 if (request->non_trigger_based &&
3283 nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED))
3286 if (request->lmr_feedback && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK))
3289 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP, request->num_bursts_exp))
3292 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration))
3295 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST, request->ftms_per_burst))
3298 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES, request->ftmr_retries))
3301 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration))
3304 if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR, request->bss_color))
3307 nla_nest_end(msg, ftm);
3312 static int mac80211_hwsim_send_pmsr_request_peer(struct sk_buff *msg,
3313 struct cfg80211_pmsr_request_peer *request)
3315 struct nlattr *peer, *chandef, *req, *data;
3318 peer = nla_nest_start(msg, NL80211_PMSR_ATTR_PEERS);
3322 if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN,
3326 chandef = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_CHAN);
3330 err = nl80211_send_chandef(msg, &request->chandef);
3334 nla_nest_end(msg, chandef);
3336 req = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_REQ);
3340 if (request->report_ap_tsf && nla_put_flag(msg, NL80211_PMSR_REQ_ATTR_GET_AP_TSF))
3343 data = nla_nest_start(msg, NL80211_PMSR_REQ_ATTR_DATA);
3347 err = mac80211_hwsim_send_pmsr_ftm_request_peer(msg, &request->ftm);
3351 nla_nest_end(msg, data);
3352 nla_nest_end(msg, req);
3353 nla_nest_end(msg, peer);
3358 static int mac80211_hwsim_send_pmsr_request(struct sk_buff *msg,
3359 struct cfg80211_pmsr_request *request)
3361 struct nlattr *pmsr;
3364 pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS);
3368 if (nla_put_u32(msg, NL80211_ATTR_TIMEOUT, request->timeout))
3371 if (!is_zero_ether_addr(request->mac_addr)) {
3372 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, request->mac_addr))
3374 if (nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, request->mac_addr_mask))
3378 for (int i = 0; i < request->n_peers; i++) {
3379 err = mac80211_hwsim_send_pmsr_request_peer(msg, &request->peers[i]);
3384 nla_nest_end(msg, pmsr);
3389 static int mac80211_hwsim_start_pmsr(struct ieee80211_hw *hw,
3390 struct ieee80211_vif *vif,
3391 struct cfg80211_pmsr_request *request)
3393 struct mac80211_hwsim_data *data;
3394 struct sk_buff *skb = NULL;
3395 struct nlattr *pmsr;
3401 _portid = READ_ONCE(data->wmediumd);
3402 if (!_portid && !hwsim_virtio_enabled)
3405 mutex_lock(&data->mutex);
3407 if (data->pmsr_request) {
3412 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
3419 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_START_PMSR);
3421 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER,
3422 ETH_ALEN, data->addresses[1].addr)) {
3427 pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST);
3433 err = mac80211_hwsim_send_pmsr_request(skb, request);
3437 nla_nest_end(skb, pmsr);
3439 genlmsg_end(skb, msg_head);
3440 if (hwsim_virtio_enabled)
3441 hwsim_tx_virtio(data, skb);
3443 hwsim_unicast_netgroup(data, skb, _portid);
3445 data->pmsr_request = request;
3446 data->pmsr_request_wdev = ieee80211_vif_to_wdev(vif);
3452 mutex_unlock(&data->mutex);
3456 static void mac80211_hwsim_abort_pmsr(struct ieee80211_hw *hw,
3457 struct ieee80211_vif *vif,
3458 struct cfg80211_pmsr_request *request)
3460 struct mac80211_hwsim_data *data;
3461 struct sk_buff *skb = NULL;
3462 struct nlattr *pmsr;
3468 _portid = READ_ONCE(data->wmediumd);
3469 if (!_portid && !hwsim_virtio_enabled)
3472 mutex_lock(&data->mutex);
3474 if (data->pmsr_request != request) {
3479 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
3485 msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_ABORT_PMSR);
3487 if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, ETH_ALEN, data->addresses[1].addr))
3490 pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST);
3496 err = mac80211_hwsim_send_pmsr_request(skb, request);
3500 err = nla_nest_end(skb, pmsr);
3504 genlmsg_end(skb, msg_head);
3505 if (hwsim_virtio_enabled)
3506 hwsim_tx_virtio(data, skb);
3508 hwsim_unicast_netgroup(data, skb, _portid);
3514 mutex_unlock(&data->mutex);
3517 static int mac80211_hwsim_parse_rate_info(struct nlattr *rateattr,
3518 struct rate_info *rate_info,
3519 struct genl_info *info)
3521 struct nlattr *tb[HWSIM_RATE_INFO_ATTR_MAX + 1];
3524 ret = nla_parse_nested(tb, HWSIM_RATE_INFO_ATTR_MAX,
3525 rateattr, hwsim_rate_info_policy, info->extack);
3529 if (tb[HWSIM_RATE_INFO_ATTR_FLAGS])
3530 rate_info->flags = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_FLAGS]);
3532 if (tb[HWSIM_RATE_INFO_ATTR_MCS])
3533 rate_info->mcs = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_MCS]);
3535 if (tb[HWSIM_RATE_INFO_ATTR_LEGACY])
3536 rate_info->legacy = nla_get_u16(tb[HWSIM_RATE_INFO_ATTR_LEGACY]);
3538 if (tb[HWSIM_RATE_INFO_ATTR_NSS])
3539 rate_info->nss = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_NSS]);
3541 if (tb[HWSIM_RATE_INFO_ATTR_BW])
3542 rate_info->bw = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_BW]);
3544 if (tb[HWSIM_RATE_INFO_ATTR_HE_GI])
3545 rate_info->he_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_GI]);
3547 if (tb[HWSIM_RATE_INFO_ATTR_HE_DCM])
3548 rate_info->he_dcm = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_DCM]);
3550 if (tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC])
3551 rate_info->he_ru_alloc =
3552 nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC]);
3554 if (tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH])
3555 rate_info->n_bonded_ch = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH]);
3557 if (tb[HWSIM_RATE_INFO_ATTR_EHT_GI])
3558 rate_info->eht_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_GI]);
3560 if (tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC])
3561 rate_info->eht_ru_alloc = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC]);
3566 static int mac80211_hwsim_parse_ftm_result(struct nlattr *ftm,
3567 struct cfg80211_pmsr_ftm_result *result,
3568 struct genl_info *info)
3570 struct nlattr *tb[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1];
3573 ret = nla_parse_nested(tb, NL80211_PMSR_FTM_RESP_ATTR_MAX,
3574 ftm, hwsim_ftm_result_policy, info->extack);
3578 if (tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON])
3579 result->failure_reason = nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON]);
3581 if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX])
3582 result->burst_index = nla_get_u16(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX]);
3584 if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]) {
3585 result->num_ftmr_attempts_valid = 1;
3586 result->num_ftmr_attempts =
3587 nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]);
3590 if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]) {
3591 result->num_ftmr_successes_valid = 1;
3592 result->num_ftmr_successes =
3593 nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]);
3596 if (tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME])
3597 result->busy_retry_time =
3598 nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME]);
3600 if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP])
3601 result->num_bursts_exp = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP]);
3603 if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION])
3604 result->burst_duration = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION]);
3606 if (tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST])
3607 result->ftms_per_burst = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST]);
3609 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]) {
3610 result->rssi_avg_valid = 1;
3611 result->rssi_avg = nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]);
3613 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]) {
3614 result->rssi_spread_valid = 1;
3615 result->rssi_spread =
3616 nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]);
3619 if (tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE]) {
3620 result->tx_rate_valid = 1;
3621 ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE],
3622 &result->tx_rate, info);
3627 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE]) {
3628 result->rx_rate_valid = 1;
3629 ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE],
3630 &result->rx_rate, info);
3635 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]) {
3636 result->rtt_avg_valid = 1;
3638 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]);
3640 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]) {
3641 result->rtt_variance_valid = 1;
3642 result->rtt_variance =
3643 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]);
3645 if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]) {
3646 result->rtt_spread_valid = 1;
3647 result->rtt_spread =
3648 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]);
3650 if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]) {
3651 result->dist_avg_valid = 1;
3653 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]);
3655 if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]) {
3656 result->dist_variance_valid = 1;
3657 result->dist_variance =
3658 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]);
3660 if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]) {
3661 result->dist_spread_valid = 1;
3662 result->dist_spread =
3663 nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]);
3666 if (tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]) {
3667 result->lci = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]);
3668 result->lci_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]);
3671 if (tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]) {
3672 result->civicloc = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]);
3673 result->civicloc_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]);
3679 static int mac80211_hwsim_parse_pmsr_resp(struct nlattr *resp,
3680 struct cfg80211_pmsr_result *result,
3681 struct genl_info *info)
3683 struct nlattr *tb[NL80211_PMSR_RESP_ATTR_MAX + 1];
3684 struct nlattr *pmsr;
3688 ret = nla_parse_nested(tb, NL80211_PMSR_RESP_ATTR_MAX, resp, hwsim_pmsr_resp_policy,
3693 if (tb[NL80211_PMSR_RESP_ATTR_STATUS])
3694 result->status = nla_get_u32(tb[NL80211_PMSR_RESP_ATTR_STATUS]);
3696 if (tb[NL80211_PMSR_RESP_ATTR_HOST_TIME])
3697 result->host_time = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_HOST_TIME]);
3699 if (tb[NL80211_PMSR_RESP_ATTR_AP_TSF]) {
3700 result->ap_tsf_valid = 1;
3701 result->ap_tsf = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_AP_TSF]);
3704 result->final = !!tb[NL80211_PMSR_RESP_ATTR_FINAL];
3706 if (!tb[NL80211_PMSR_RESP_ATTR_DATA])
3709 nla_for_each_nested(pmsr, tb[NL80211_PMSR_RESP_ATTR_DATA], rem) {
3710 switch (nla_type(pmsr)) {
3711 case NL80211_PMSR_TYPE_FTM:
3712 result->type = NL80211_PMSR_TYPE_FTM;
3713 ret = mac80211_hwsim_parse_ftm_result(pmsr, &result->ftm, info);
3718 NL_SET_ERR_MSG_ATTR(info->extack, pmsr, "Unknown pmsr resp type");
3726 static int mac80211_hwsim_parse_pmsr_result(struct nlattr *peer,
3727 struct cfg80211_pmsr_result *result,
3728 struct genl_info *info)
3730 struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1];
3736 ret = nla_parse_nested(tb, NL80211_PMSR_PEER_ATTR_MAX, peer,
3737 hwsim_pmsr_peer_result_policy, info->extack);
3741 if (tb[NL80211_PMSR_PEER_ATTR_ADDR])
3742 memcpy(result->addr, nla_data(tb[NL80211_PMSR_PEER_ATTR_ADDR]),
3745 if (tb[NL80211_PMSR_PEER_ATTR_RESP]) {
3746 ret = mac80211_hwsim_parse_pmsr_resp(tb[NL80211_PMSR_PEER_ATTR_RESP], result, info);
3754 static int hwsim_pmsr_report_nl(struct sk_buff *msg, struct genl_info *info)
3756 struct mac80211_hwsim_data *data;
3757 struct nlattr *peers, *peer;
3758 struct nlattr *reqattr;
3763 if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER])
3766 src = nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
3767 data = get_hwsim_data_ref_from_addr(src);
3771 mutex_lock(&data->mutex);
3772 if (!data->pmsr_request) {
3777 reqattr = info->attrs[HWSIM_ATTR_PMSR_RESULT];
3783 peers = nla_find_nested(reqattr, NL80211_PMSR_ATTR_PEERS);
3789 nla_for_each_nested(peer, peers, rem) {
3790 struct cfg80211_pmsr_result result;
3792 err = mac80211_hwsim_parse_pmsr_result(peer, &result, info);
3796 cfg80211_pmsr_report(data->pmsr_request_wdev,
3797 data->pmsr_request, &result, GFP_KERNEL);
3800 cfg80211_pmsr_complete(data->pmsr_request_wdev, data->pmsr_request, GFP_KERNEL);
3804 data->pmsr_request = NULL;
3805 data->pmsr_request_wdev = NULL;
3807 mutex_unlock(&data->mutex);
3811 #define HWSIM_COMMON_OPS \
3812 .tx = mac80211_hwsim_tx, \
3813 .wake_tx_queue = ieee80211_handle_wake_tx_queue, \
3814 .start = mac80211_hwsim_start, \
3815 .stop = mac80211_hwsim_stop, \
3816 .add_interface = mac80211_hwsim_add_interface, \
3817 .change_interface = mac80211_hwsim_change_interface, \
3818 .remove_interface = mac80211_hwsim_remove_interface, \
3819 .config = mac80211_hwsim_config, \
3820 .configure_filter = mac80211_hwsim_configure_filter, \
3821 .vif_cfg_changed = mac80211_hwsim_vif_info_changed, \
3822 .link_info_changed = mac80211_hwsim_link_info_changed, \
3823 .tx_last_beacon = mac80211_hwsim_tx_last_beacon, \
3824 .sta_notify = mac80211_hwsim_sta_notify, \
3825 .sta_rc_update = mac80211_hwsim_sta_rc_update, \
3826 .conf_tx = mac80211_hwsim_conf_tx, \
3827 .get_survey = mac80211_hwsim_get_survey, \
3828 CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \
3829 .ampdu_action = mac80211_hwsim_ampdu_action, \
3830 .flush = mac80211_hwsim_flush, \
3831 .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \
3832 .get_et_stats = mac80211_hwsim_get_et_stats, \
3833 .get_et_strings = mac80211_hwsim_get_et_strings, \
3834 .start_pmsr = mac80211_hwsim_start_pmsr, \
3835 .abort_pmsr = mac80211_hwsim_abort_pmsr,
3837 #define HWSIM_NON_MLO_OPS \
3838 .sta_add = mac80211_hwsim_sta_add, \
3839 .sta_remove = mac80211_hwsim_sta_remove, \
3840 .set_tim = mac80211_hwsim_set_tim, \
3841 .get_tsf = mac80211_hwsim_get_tsf, \
3842 .set_tsf = mac80211_hwsim_set_tsf,
3844 static const struct ieee80211_ops mac80211_hwsim_ops = {
3847 .sw_scan_start = mac80211_hwsim_sw_scan,
3848 .sw_scan_complete = mac80211_hwsim_sw_scan_complete,
3851 #define HWSIM_CHANCTX_OPS \
3852 .hw_scan = mac80211_hwsim_hw_scan, \
3853 .cancel_hw_scan = mac80211_hwsim_cancel_hw_scan, \
3854 .remain_on_channel = mac80211_hwsim_roc, \
3855 .cancel_remain_on_channel = mac80211_hwsim_croc, \
3856 .add_chanctx = mac80211_hwsim_add_chanctx, \
3857 .remove_chanctx = mac80211_hwsim_remove_chanctx, \
3858 .change_chanctx = mac80211_hwsim_change_chanctx, \
3859 .assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx,\
3860 .unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx,
3862 static const struct ieee80211_ops mac80211_hwsim_mchan_ops = {
3868 static const struct ieee80211_ops mac80211_hwsim_mlo_ops = {
3871 .set_rts_threshold = mac80211_hwsim_set_rts_threshold,
3872 .change_vif_links = mac80211_hwsim_change_vif_links,
3873 .change_sta_links = mac80211_hwsim_change_sta_links,
3874 .sta_state = mac80211_hwsim_sta_state,
3877 struct hwsim_new_radio_params {
3878 unsigned int channels;
3879 const char *reg_alpha2;
3880 const struct ieee80211_regdomain *regd;
3884 bool destroy_on_close;
3887 const u8 *perm_addr;
3892 const struct cfg80211_pmsr_capabilities *pmsr_capa;
3895 static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb,
3896 struct genl_info *info)
3899 genl_notify(&hwsim_genl_family, mcast_skb, info,
3900 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
3902 genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0,
3903 HWSIM_MCGRP_CONFIG, GFP_KERNEL);
3906 static int append_radio_msg(struct sk_buff *skb, int id,
3907 struct hwsim_new_radio_params *param)
3911 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
3915 if (param->channels) {
3916 ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels);
3921 if (param->reg_alpha2) {
3922 ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2,
3931 for (i = 0; i < ARRAY_SIZE(hwsim_world_regdom_custom); i++) {
3932 if (hwsim_world_regdom_custom[i] != param->regd)
3935 ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i);
3942 if (param->reg_strict) {
3943 ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG);
3948 if (param->p2p_device) {
3949 ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE);
3954 if (param->use_chanctx) {
3955 ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX);
3960 if (param->hwname) {
3961 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME,
3962 strlen(param->hwname), param->hwname);
3970 static void hwsim_mcast_new_radio(int id, struct genl_info *info,
3971 struct hwsim_new_radio_params *param)
3973 struct sk_buff *mcast_skb;
3976 mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
3980 data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0,
3981 HWSIM_CMD_NEW_RADIO);
3985 if (append_radio_msg(mcast_skb, id, param) < 0)
3988 genlmsg_end(mcast_skb, data);
3990 hwsim_mcast_config_msg(mcast_skb, info);
3994 nlmsg_free(mcast_skb);
3997 static const struct ieee80211_sband_iftype_data sband_capa_2ghz[] = {
3999 .types_mask = BIT(NL80211_IFTYPE_STATION),
4004 IEEE80211_HE_MAC_CAP0_HTC_HE,
4006 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4007 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4009 IEEE80211_HE_MAC_CAP2_BSR |
4010 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4011 IEEE80211_HE_MAC_CAP2_ACK_EN,
4013 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4014 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4015 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4017 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4018 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4019 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4020 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4022 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4023 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4024 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4025 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4026 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4028 /* Leave all the other PHY capability bytes
4029 * unset, as DCM, beam forming, RU and PPE
4030 * threshold information are not supported
4033 .he_mcs_nss_supp = {
4034 .rx_mcs_80 = cpu_to_le16(0xfffa),
4035 .tx_mcs_80 = cpu_to_le16(0xfffa),
4036 .rx_mcs_160 = cpu_to_le16(0xffff),
4037 .tx_mcs_160 = cpu_to_le16(0xffff),
4038 .rx_mcs_80p80 = cpu_to_le16(0xffff),
4039 .tx_mcs_80p80 = cpu_to_le16(0xffff),
4046 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4047 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4048 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4050 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4051 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4052 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4053 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4054 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
4056 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4057 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4058 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4059 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4060 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4061 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4062 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4064 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4065 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4066 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4067 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4068 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4070 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4071 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4072 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4073 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4074 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4075 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4077 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4078 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
4080 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
4083 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4086 .eht_mcs_nss_supp = {
4088 * Since B0, B1, B2 and B3 are not set in
4089 * the supported channel width set field in the
4090 * HE PHY capabilities information field the
4091 * device is a 20MHz only device on 2.4GHz band.
4094 .rx_tx_mcs7_max_nss = 0x88,
4095 .rx_tx_mcs9_max_nss = 0x88,
4096 .rx_tx_mcs11_max_nss = 0x88,
4097 .rx_tx_mcs13_max_nss = 0x88,
4100 /* PPE threshold information is not supported */
4104 .types_mask = BIT(NL80211_IFTYPE_AP),
4109 IEEE80211_HE_MAC_CAP0_HTC_HE,
4111 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4112 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4114 IEEE80211_HE_MAC_CAP2_BSR |
4115 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4116 IEEE80211_HE_MAC_CAP2_ACK_EN,
4118 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4119 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4120 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4122 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4123 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4124 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4125 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4127 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4128 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4129 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4130 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4131 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4133 /* Leave all the other PHY capability bytes
4134 * unset, as DCM, beam forming, RU and PPE
4135 * threshold information are not supported
4138 .he_mcs_nss_supp = {
4139 .rx_mcs_80 = cpu_to_le16(0xfffa),
4140 .tx_mcs_80 = cpu_to_le16(0xfffa),
4141 .rx_mcs_160 = cpu_to_le16(0xffff),
4142 .tx_mcs_160 = cpu_to_le16(0xffff),
4143 .rx_mcs_80p80 = cpu_to_le16(0xffff),
4144 .tx_mcs_80p80 = cpu_to_le16(0xffff),
4151 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4152 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4153 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4155 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4156 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4157 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4158 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4159 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE,
4161 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4162 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4163 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4164 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4165 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4166 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4167 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4169 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4170 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4171 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4172 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4173 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4175 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4176 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4177 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4178 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4179 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4180 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4182 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4183 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
4185 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW,
4188 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4191 .eht_mcs_nss_supp = {
4193 * Since B0, B1, B2 and B3 are not set in
4194 * the supported channel width set field in the
4195 * HE PHY capabilities information field the
4196 * device is a 20MHz only device on 2.4GHz band.
4199 .rx_tx_mcs7_max_nss = 0x88,
4200 .rx_tx_mcs9_max_nss = 0x88,
4201 .rx_tx_mcs11_max_nss = 0x88,
4202 .rx_tx_mcs13_max_nss = 0x88,
4205 /* PPE threshold information is not supported */
4208 #ifdef CONFIG_MAC80211_MESH
4210 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
4215 IEEE80211_HE_MAC_CAP0_HTC_HE,
4217 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4219 IEEE80211_HE_MAC_CAP2_ACK_EN,
4221 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4222 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4223 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4225 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4226 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4227 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4228 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4229 .phy_cap_info[2] = 0,
4231 /* Leave all the other PHY capability bytes
4232 * unset, as DCM, beam forming, RU and PPE
4233 * threshold information are not supported
4236 .he_mcs_nss_supp = {
4237 .rx_mcs_80 = cpu_to_le16(0xfffa),
4238 .tx_mcs_80 = cpu_to_le16(0xfffa),
4239 .rx_mcs_160 = cpu_to_le16(0xffff),
4240 .tx_mcs_160 = cpu_to_le16(0xffff),
4241 .rx_mcs_80p80 = cpu_to_le16(0xffff),
4242 .tx_mcs_80p80 = cpu_to_le16(0xffff),
4249 static const struct ieee80211_sband_iftype_data sband_capa_5ghz[] = {
4251 /* TODO: should we support other types, e.g., P2P? */
4252 .types_mask = BIT(NL80211_IFTYPE_STATION),
4257 IEEE80211_HE_MAC_CAP0_HTC_HE,
4259 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4260 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4262 IEEE80211_HE_MAC_CAP2_BSR |
4263 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4264 IEEE80211_HE_MAC_CAP2_ACK_EN,
4266 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4267 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4268 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4270 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4271 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4272 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4274 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4275 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4276 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4277 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4279 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4280 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4281 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4282 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4283 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4285 /* Leave all the other PHY capability bytes
4286 * unset, as DCM, beam forming, RU and PPE
4287 * threshold information are not supported
4290 .he_mcs_nss_supp = {
4291 .rx_mcs_80 = cpu_to_le16(0xfffa),
4292 .tx_mcs_80 = cpu_to_le16(0xfffa),
4293 .rx_mcs_160 = cpu_to_le16(0xfffa),
4294 .tx_mcs_160 = cpu_to_le16(0xfffa),
4295 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4296 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4303 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4304 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4305 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4307 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4308 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4309 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4310 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4311 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
4312 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
4314 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
4315 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
4317 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
4318 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
4320 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4321 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4322 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4323 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4324 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4325 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4326 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4328 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4329 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4330 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4331 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4332 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4334 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4335 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4336 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4337 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4338 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4339 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4341 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4342 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
4344 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
4345 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
4346 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
4347 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
4348 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
4351 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4354 .eht_mcs_nss_supp = {
4356 * As B1 and B2 are set in the supported
4357 * channel width set field in the HE PHY
4358 * capabilities information field include all
4359 * the following MCS/NSS.
4362 .rx_tx_mcs9_max_nss = 0x88,
4363 .rx_tx_mcs11_max_nss = 0x88,
4364 .rx_tx_mcs13_max_nss = 0x88,
4367 .rx_tx_mcs9_max_nss = 0x88,
4368 .rx_tx_mcs11_max_nss = 0x88,
4369 .rx_tx_mcs13_max_nss = 0x88,
4372 /* PPE threshold information is not supported */
4376 .types_mask = BIT(NL80211_IFTYPE_AP),
4381 IEEE80211_HE_MAC_CAP0_HTC_HE,
4383 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4384 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4386 IEEE80211_HE_MAC_CAP2_BSR |
4387 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4388 IEEE80211_HE_MAC_CAP2_ACK_EN,
4390 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4391 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4392 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4394 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4395 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4396 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4398 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4399 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4400 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4401 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4403 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4404 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4405 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4406 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4407 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4409 /* Leave all the other PHY capability bytes
4410 * unset, as DCM, beam forming, RU and PPE
4411 * threshold information are not supported
4414 .he_mcs_nss_supp = {
4415 .rx_mcs_80 = cpu_to_le16(0xfffa),
4416 .tx_mcs_80 = cpu_to_le16(0xfffa),
4417 .rx_mcs_160 = cpu_to_le16(0xfffa),
4418 .tx_mcs_160 = cpu_to_le16(0xfffa),
4419 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4420 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4427 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4428 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4429 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4431 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4432 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4433 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4434 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4435 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
4436 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
4438 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
4439 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK,
4441 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
4442 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK,
4444 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4445 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4446 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4447 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4448 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4449 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4450 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4452 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4453 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4454 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4455 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4456 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4458 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4459 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4460 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4461 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4462 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4463 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4465 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4466 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK,
4468 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
4469 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
4470 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
4471 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
4472 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ,
4475 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4478 .eht_mcs_nss_supp = {
4480 * As B1 and B2 are set in the supported
4481 * channel width set field in the HE PHY
4482 * capabilities information field include all
4483 * the following MCS/NSS.
4486 .rx_tx_mcs9_max_nss = 0x88,
4487 .rx_tx_mcs11_max_nss = 0x88,
4488 .rx_tx_mcs13_max_nss = 0x88,
4491 .rx_tx_mcs9_max_nss = 0x88,
4492 .rx_tx_mcs11_max_nss = 0x88,
4493 .rx_tx_mcs13_max_nss = 0x88,
4496 /* PPE threshold information is not supported */
4499 #ifdef CONFIG_MAC80211_MESH
4501 /* TODO: should we support other types, e.g., IBSS?*/
4502 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
4507 IEEE80211_HE_MAC_CAP0_HTC_HE,
4509 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4511 IEEE80211_HE_MAC_CAP2_ACK_EN,
4513 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4514 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4515 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4517 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4518 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4519 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4521 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4522 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4523 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4524 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4525 .phy_cap_info[2] = 0,
4527 /* Leave all the other PHY capability bytes
4528 * unset, as DCM, beam forming, RU and PPE
4529 * threshold information are not supported
4532 .he_mcs_nss_supp = {
4533 .rx_mcs_80 = cpu_to_le16(0xfffa),
4534 .tx_mcs_80 = cpu_to_le16(0xfffa),
4535 .rx_mcs_160 = cpu_to_le16(0xfffa),
4536 .tx_mcs_160 = cpu_to_le16(0xfffa),
4537 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4538 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4545 static const struct ieee80211_sband_iftype_data sband_capa_6ghz[] = {
4547 /* TODO: should we support other types, e.g., P2P? */
4548 .types_mask = BIT(NL80211_IFTYPE_STATION),
4550 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
4551 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
4552 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
4553 IEEE80211_HE_6GHZ_CAP_SM_PS |
4554 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
4555 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
4556 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
4562 IEEE80211_HE_MAC_CAP0_HTC_HE,
4564 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4565 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4567 IEEE80211_HE_MAC_CAP2_BSR |
4568 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4569 IEEE80211_HE_MAC_CAP2_ACK_EN,
4571 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4572 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4573 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4575 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4576 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4577 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4579 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4580 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4581 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4582 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4584 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4585 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4586 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4587 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4588 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4590 /* Leave all the other PHY capability bytes
4591 * unset, as DCM, beam forming, RU and PPE
4592 * threshold information are not supported
4595 .he_mcs_nss_supp = {
4596 .rx_mcs_80 = cpu_to_le16(0xfffa),
4597 .tx_mcs_80 = cpu_to_le16(0xfffa),
4598 .rx_mcs_160 = cpu_to_le16(0xfffa),
4599 .tx_mcs_160 = cpu_to_le16(0xfffa),
4600 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4601 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4608 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4609 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4610 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4612 IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
4613 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4614 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4615 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4616 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4617 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
4618 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
4620 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
4621 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
4622 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
4624 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
4625 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
4626 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
4628 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4629 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4630 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4631 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4632 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4633 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4634 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4636 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4637 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4638 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4639 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4640 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4642 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4643 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4644 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4645 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4646 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4647 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4649 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4650 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
4651 IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
4653 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
4654 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
4655 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
4656 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
4657 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
4658 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
4659 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
4662 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4665 .eht_mcs_nss_supp = {
4667 * As B1 and B2 are set in the supported
4668 * channel width set field in the HE PHY
4669 * capabilities information field and 320MHz in
4670 * 6GHz is supported include all the following
4674 .rx_tx_mcs9_max_nss = 0x88,
4675 .rx_tx_mcs11_max_nss = 0x88,
4676 .rx_tx_mcs13_max_nss = 0x88,
4679 .rx_tx_mcs9_max_nss = 0x88,
4680 .rx_tx_mcs11_max_nss = 0x88,
4681 .rx_tx_mcs13_max_nss = 0x88,
4684 .rx_tx_mcs9_max_nss = 0x88,
4685 .rx_tx_mcs11_max_nss = 0x88,
4686 .rx_tx_mcs13_max_nss = 0x88,
4689 /* PPE threshold information is not supported */
4693 .types_mask = BIT(NL80211_IFTYPE_AP),
4695 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
4696 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
4697 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
4698 IEEE80211_HE_6GHZ_CAP_SM_PS |
4699 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
4700 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
4701 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
4707 IEEE80211_HE_MAC_CAP0_HTC_HE,
4709 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
4710 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4712 IEEE80211_HE_MAC_CAP2_BSR |
4713 IEEE80211_HE_MAC_CAP2_MU_CASCADING |
4714 IEEE80211_HE_MAC_CAP2_ACK_EN,
4716 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4717 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4718 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4720 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4721 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4722 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4724 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4725 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4726 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4727 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4729 IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
4730 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ |
4731 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ |
4732 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
4733 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO,
4735 /* Leave all the other PHY capability bytes
4736 * unset, as DCM, beam forming, RU and PPE
4737 * threshold information are not supported
4740 .he_mcs_nss_supp = {
4741 .rx_mcs_80 = cpu_to_le16(0xfffa),
4742 .tx_mcs_80 = cpu_to_le16(0xfffa),
4743 .rx_mcs_160 = cpu_to_le16(0xfffa),
4744 .tx_mcs_160 = cpu_to_le16(0xfffa),
4745 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4746 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4753 IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS |
4754 IEEE80211_EHT_MAC_CAP0_OM_CONTROL |
4755 IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1,
4757 IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ |
4758 IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ |
4759 IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI |
4760 IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO |
4761 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER |
4762 IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE |
4763 IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK,
4765 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK |
4766 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK |
4767 IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK,
4769 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK |
4770 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK |
4771 IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK,
4773 IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK |
4774 IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK |
4775 IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK |
4776 IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK |
4777 IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK |
4778 IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK |
4779 IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK,
4781 IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO |
4782 IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP |
4783 IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP |
4784 IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI |
4785 IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK,
4787 IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK |
4788 IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP |
4789 IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP |
4790 IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT |
4791 IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK |
4792 IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK,
4794 IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK |
4795 IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK |
4796 IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP,
4798 IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW |
4799 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ |
4800 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ |
4801 IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ |
4802 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ |
4803 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ |
4804 IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ,
4807 /* For all MCS and bandwidth, set 8 NSS for both Tx and
4810 .eht_mcs_nss_supp = {
4812 * As B1 and B2 are set in the supported
4813 * channel width set field in the HE PHY
4814 * capabilities information field and 320MHz in
4815 * 6GHz is supported include all the following
4819 .rx_tx_mcs9_max_nss = 0x88,
4820 .rx_tx_mcs11_max_nss = 0x88,
4821 .rx_tx_mcs13_max_nss = 0x88,
4824 .rx_tx_mcs9_max_nss = 0x88,
4825 .rx_tx_mcs11_max_nss = 0x88,
4826 .rx_tx_mcs13_max_nss = 0x88,
4829 .rx_tx_mcs9_max_nss = 0x88,
4830 .rx_tx_mcs11_max_nss = 0x88,
4831 .rx_tx_mcs13_max_nss = 0x88,
4834 /* PPE threshold information is not supported */
4837 #ifdef CONFIG_MAC80211_MESH
4839 /* TODO: should we support other types, e.g., IBSS?*/
4840 .types_mask = BIT(NL80211_IFTYPE_MESH_POINT),
4842 .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START |
4843 IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP |
4844 IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN |
4845 IEEE80211_HE_6GHZ_CAP_SM_PS |
4846 IEEE80211_HE_6GHZ_CAP_RD_RESPONDER |
4847 IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS |
4848 IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS),
4854 IEEE80211_HE_MAC_CAP0_HTC_HE,
4856 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
4858 IEEE80211_HE_MAC_CAP2_ACK_EN,
4860 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
4861 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3,
4862 .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU,
4864 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G |
4865 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
4866 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G,
4868 IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK |
4869 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A |
4870 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD |
4871 IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS,
4872 .phy_cap_info[2] = 0,
4874 /* Leave all the other PHY capability bytes
4875 * unset, as DCM, beam forming, RU and PPE
4876 * threshold information are not supported
4879 .he_mcs_nss_supp = {
4880 .rx_mcs_80 = cpu_to_le16(0xfffa),
4881 .tx_mcs_80 = cpu_to_le16(0xfffa),
4882 .rx_mcs_160 = cpu_to_le16(0xfffa),
4883 .tx_mcs_160 = cpu_to_le16(0xfffa),
4884 .rx_mcs_80p80 = cpu_to_le16(0xfffa),
4885 .tx_mcs_80p80 = cpu_to_le16(0xfffa),
4892 static void mac80211_hwsim_sband_capab(struct ieee80211_supported_band *sband)
4896 if (sband->band == NL80211_BAND_2GHZ) {
4897 n_iftype_data = ARRAY_SIZE(sband_capa_2ghz);
4898 sband->iftype_data =
4899 (struct ieee80211_sband_iftype_data *)sband_capa_2ghz;
4900 } else if (sband->band == NL80211_BAND_5GHZ) {
4901 n_iftype_data = ARRAY_SIZE(sband_capa_5ghz);
4902 sband->iftype_data =
4903 (struct ieee80211_sband_iftype_data *)sband_capa_5ghz;
4904 } else if (sband->band == NL80211_BAND_6GHZ) {
4905 n_iftype_data = ARRAY_SIZE(sband_capa_6ghz);
4906 sband->iftype_data =
4907 (struct ieee80211_sband_iftype_data *)sband_capa_6ghz;
4912 sband->n_iftype_data = n_iftype_data;
4915 #ifdef CONFIG_MAC80211_MESH
4916 #define HWSIM_MESH_BIT BIT(NL80211_IFTYPE_MESH_POINT)
4918 #define HWSIM_MESH_BIT 0
4921 #define HWSIM_DEFAULT_IF_LIMIT \
4922 (BIT(NL80211_IFTYPE_STATION) | \
4923 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
4924 BIT(NL80211_IFTYPE_AP) | \
4925 BIT(NL80211_IFTYPE_P2P_GO) | \
4928 #define HWSIM_IFTYPE_SUPPORT_MASK \
4929 (BIT(NL80211_IFTYPE_STATION) | \
4930 BIT(NL80211_IFTYPE_AP) | \
4931 BIT(NL80211_IFTYPE_P2P_CLIENT) | \
4932 BIT(NL80211_IFTYPE_P2P_GO) | \
4933 BIT(NL80211_IFTYPE_ADHOC) | \
4934 BIT(NL80211_IFTYPE_MESH_POINT) | \
4935 BIT(NL80211_IFTYPE_OCB))
4937 static int mac80211_hwsim_new_radio(struct genl_info *info,
4938 struct hwsim_new_radio_params *param)
4942 struct mac80211_hwsim_data *data;
4943 struct ieee80211_hw *hw;
4944 enum nl80211_band band;
4945 const struct ieee80211_ops *ops = &mac80211_hwsim_ops;
4950 if (WARN_ON(param->channels > 1 && !param->use_chanctx))
4953 spin_lock_bh(&hwsim_radio_lock);
4954 idx = hwsim_radio_idx++;
4955 spin_unlock_bh(&hwsim_radio_lock);
4958 ops = &mac80211_hwsim_mlo_ops;
4959 else if (param->use_chanctx)
4960 ops = &mac80211_hwsim_mchan_ops;
4961 hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname);
4963 pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n");
4968 /* ieee80211_alloc_hw_nm may have used a default name */
4969 param->hwname = wiphy_name(hw->wiphy);
4972 net = genl_info_net(info);
4975 wiphy_net_set(hw->wiphy, net);
4980 data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx);
4981 if (IS_ERR(data->dev)) {
4983 "mac80211_hwsim: device_create failed (%ld)\n",
4984 PTR_ERR(data->dev));
4986 goto failed_drvdata;
4988 data->dev->driver = &mac80211_hwsim_driver.driver;
4989 err = device_bind_driver(data->dev);
4991 pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n",
4996 skb_queue_head_init(&data->pending);
4998 SET_IEEE80211_DEV(hw, data->dev);
4999 if (!param->perm_addr) {
5000 eth_zero_addr(addr);
5004 memcpy(data->addresses[0].addr, addr, ETH_ALEN);
5005 /* Why need here second address ? */
5006 memcpy(data->addresses[1].addr, addr, ETH_ALEN);
5007 data->addresses[1].addr[0] |= 0x40;
5008 hw->wiphy->n_addresses = 2;
5009 hw->wiphy->addresses = data->addresses;
5010 /* possible address clash is checked at hash table insertion */
5012 memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN);
5013 /* compatibility with automatically generated mac addr */
5014 memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN);
5015 hw->wiphy->n_addresses = 2;
5016 hw->wiphy->addresses = data->addresses;
5019 data->channels = param->channels;
5020 data->use_chanctx = param->use_chanctx;
5022 data->destroy_on_close = param->destroy_on_close;
5024 data->portid = info->snd_portid;
5026 /* setup interface limits, only on interface types we support */
5027 if (param->iftypes & BIT(NL80211_IFTYPE_ADHOC)) {
5028 data->if_limits[n_limits].max = 1;
5029 data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_ADHOC);
5033 if (param->iftypes & HWSIM_DEFAULT_IF_LIMIT) {
5034 data->if_limits[n_limits].max = 2048;
5036 * For this case, we may only support a subset of
5037 * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the
5038 * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have.
5040 data->if_limits[n_limits].types =
5041 HWSIM_DEFAULT_IF_LIMIT & param->iftypes;
5045 if (param->iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
5046 data->if_limits[n_limits].max = 1;
5047 data->if_limits[n_limits].types =
5048 BIT(NL80211_IFTYPE_P2P_DEVICE);
5052 if (data->use_chanctx) {
5053 hw->wiphy->max_scan_ssids = 255;
5054 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
5055 hw->wiphy->max_remain_on_channel_duration = 1000;
5056 data->if_combination.radar_detect_widths = 0;
5057 data->if_combination.num_different_channels = data->channels;
5059 data->if_combination.num_different_channels = 1;
5060 data->if_combination.radar_detect_widths =
5061 BIT(NL80211_CHAN_WIDTH_5) |
5062 BIT(NL80211_CHAN_WIDTH_10) |
5063 BIT(NL80211_CHAN_WIDTH_20_NOHT) |
5064 BIT(NL80211_CHAN_WIDTH_20) |
5065 BIT(NL80211_CHAN_WIDTH_40) |
5066 BIT(NL80211_CHAN_WIDTH_80) |
5067 BIT(NL80211_CHAN_WIDTH_160);
5075 data->if_combination.max_interfaces = 0;
5076 for (i = 0; i < n_limits; i++)
5077 data->if_combination.max_interfaces +=
5078 data->if_limits[i].max;
5080 data->if_combination.n_limits = n_limits;
5081 data->if_combination.limits = data->if_limits;
5084 * If we actually were asked to support combinations,
5085 * advertise them - if there's only a single thing like
5086 * only IBSS then don't advertise it as combinations.
5088 if (data->if_combination.max_interfaces > 1) {
5089 hw->wiphy->iface_combinations = &data->if_combination;
5090 hw->wiphy->n_iface_combinations = 1;
5093 if (param->ciphers) {
5094 memcpy(data->ciphers, param->ciphers,
5095 param->n_ciphers * sizeof(u32));
5096 hw->wiphy->cipher_suites = data->ciphers;
5097 hw->wiphy->n_cipher_suites = param->n_ciphers;
5100 hw->wiphy->mbssid_max_interfaces = 8;
5101 hw->wiphy->ema_max_profile_periodicity = 3;
5103 data->rx_rssi = DEFAULT_RX_RSSI;
5105 INIT_DELAYED_WORK(&data->roc_start, hw_roc_start);
5106 INIT_DELAYED_WORK(&data->roc_done, hw_roc_done);
5107 INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work);
5110 hw->offchannel_tx_hw_queue = 4;
5112 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
5113 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
5114 ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
5115 ieee80211_hw_set(hw, QUEUE_CONTROL);
5116 ieee80211_hw_set(hw, WANT_MONITOR_VIF);
5117 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
5118 ieee80211_hw_set(hw, MFP_CAPABLE);
5119 ieee80211_hw_set(hw, SIGNAL_DBM);
5120 ieee80211_hw_set(hw, SUPPORTS_PS);
5121 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
5122 ieee80211_hw_set(hw, TDLS_WIDER_BW);
5123 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
5126 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO;
5127 ieee80211_hw_set(hw, HAS_RATE_CONTROL);
5128 ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS);
5129 ieee80211_hw_set(hw, CONNECTION_MONITOR);
5130 ieee80211_hw_set(hw, AP_LINK_PS);
5132 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
5133 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
5135 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
5138 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
5139 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS |
5140 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
5141 WIPHY_FLAG_AP_UAPSD |
5142 WIPHY_FLAG_SUPPORTS_5_10_MHZ |
5143 WIPHY_FLAG_HAS_CHANNEL_SWITCH;
5144 hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
5145 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
5146 NL80211_FEATURE_STATIC_SMPS |
5147 NL80211_FEATURE_DYNAMIC_SMPS |
5148 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
5149 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
5150 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION);
5151 wiphy_ext_feature_set(hw->wiphy,
5152 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
5153 wiphy_ext_feature_set(hw->wiphy,
5154 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY);
5155 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
5157 wiphy_ext_feature_set(hw->wiphy,
5158 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
5160 hw->wiphy->interface_modes = param->iftypes;
5162 /* ask mac80211 to reserve space for magic */
5163 hw->vif_data_size = sizeof(struct hwsim_vif_priv);
5164 hw->sta_data_size = sizeof(struct hwsim_sta_priv);
5165 hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv);
5167 memcpy(data->channels_2ghz, hwsim_channels_2ghz,
5168 sizeof(hwsim_channels_2ghz));
5169 memcpy(data->channels_5ghz, hwsim_channels_5ghz,
5170 sizeof(hwsim_channels_5ghz));
5171 memcpy(data->channels_6ghz, hwsim_channels_6ghz,
5172 sizeof(hwsim_channels_6ghz));
5173 memcpy(data->channels_s1g, hwsim_channels_s1g,
5174 sizeof(hwsim_channels_s1g));
5175 memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
5177 for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) {
5178 struct ieee80211_supported_band *sband = &data->bands[band];
5183 case NL80211_BAND_2GHZ:
5184 sband->channels = data->channels_2ghz;
5185 sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz);
5186 sband->bitrates = data->rates;
5187 sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
5189 case NL80211_BAND_5GHZ:
5190 sband->channels = data->channels_5ghz;
5191 sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz);
5192 sband->bitrates = data->rates + 4;
5193 sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
5195 sband->vht_cap.vht_supported = true;
5196 sband->vht_cap.cap =
5197 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
5198 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ |
5199 IEEE80211_VHT_CAP_RXLDPC |
5200 IEEE80211_VHT_CAP_SHORT_GI_80 |
5201 IEEE80211_VHT_CAP_SHORT_GI_160 |
5202 IEEE80211_VHT_CAP_TXSTBC |
5203 IEEE80211_VHT_CAP_RXSTBC_4 |
5204 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
5205 sband->vht_cap.vht_mcs.rx_mcs_map =
5206 cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 |
5207 IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 |
5208 IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 |
5209 IEEE80211_VHT_MCS_SUPPORT_0_9 << 6 |
5210 IEEE80211_VHT_MCS_SUPPORT_0_9 << 8 |
5211 IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 |
5212 IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 |
5213 IEEE80211_VHT_MCS_SUPPORT_0_9 << 14);
5214 sband->vht_cap.vht_mcs.tx_mcs_map =
5215 sband->vht_cap.vht_mcs.rx_mcs_map;
5217 case NL80211_BAND_6GHZ:
5218 sband->channels = data->channels_6ghz;
5219 sband->n_channels = ARRAY_SIZE(hwsim_channels_6ghz);
5220 sband->bitrates = data->rates + 4;
5221 sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4;
5223 case NL80211_BAND_S1GHZ:
5224 memcpy(&sband->s1g_cap, &hwsim_s1g_cap,
5225 sizeof(sband->s1g_cap));
5226 sband->channels = data->channels_s1g;
5227 sband->n_channels = ARRAY_SIZE(hwsim_channels_s1g);
5233 if (band != NL80211_BAND_6GHZ){
5234 sband->ht_cap.ht_supported = true;
5235 sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
5236 IEEE80211_HT_CAP_GRN_FLD |
5237 IEEE80211_HT_CAP_SGI_20 |
5238 IEEE80211_HT_CAP_SGI_40 |
5239 IEEE80211_HT_CAP_DSSSCCK40;
5240 sband->ht_cap.ampdu_factor = 0x3;
5241 sband->ht_cap.ampdu_density = 0x6;
5242 memset(&sband->ht_cap.mcs, 0,
5243 sizeof(sband->ht_cap.mcs));
5244 sband->ht_cap.mcs.rx_mask[0] = 0xff;
5245 sband->ht_cap.mcs.rx_mask[1] = 0xff;
5246 sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
5249 mac80211_hwsim_sband_capab(sband);
5251 hw->wiphy->bands[band] = sband;
5254 /* By default all radios belong to the first group */
5256 mutex_init(&data->mutex);
5258 data->netgroup = hwsim_net_get_netgroup(net);
5259 data->wmediumd = hwsim_net_get_wmediumd(net);
5261 /* Enable frame retransmissions for lossy channels */
5263 hw->max_rate_tries = 11;
5265 hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands;
5266 hw->wiphy->n_vendor_commands =
5267 ARRAY_SIZE(mac80211_hwsim_vendor_commands);
5268 hw->wiphy->vendor_events = mac80211_hwsim_vendor_events;
5269 hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events);
5271 if (param->reg_strict)
5272 hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
5274 data->regd = param->regd;
5275 hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
5276 wiphy_apply_custom_regulatory(hw->wiphy, param->regd);
5277 /* give the regulatory workqueue a chance to run */
5278 schedule_timeout_interruptible(1);
5282 ieee80211_hw_set(hw, NO_AUTO_VIF);
5284 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
5286 for (i = 0; i < ARRAY_SIZE(data->link_data); i++) {
5287 hrtimer_init(&data->link_data[i].beacon_timer, CLOCK_MONOTONIC,
5288 HRTIMER_MODE_ABS_SOFT);
5289 data->link_data[i].beacon_timer.function =
5290 mac80211_hwsim_beacon;
5291 data->link_data[i].link_id = i;
5294 err = ieee80211_register_hw(hw);
5296 pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n",
5301 wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr);
5303 if (param->reg_alpha2) {
5304 data->alpha2[0] = param->reg_alpha2[0];
5305 data->alpha2[1] = param->reg_alpha2[1];
5306 regulatory_hint(hw->wiphy, param->reg_alpha2);
5309 data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir);
5310 debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps);
5311 debugfs_create_file("group", 0666, data->debugfs, data,
5313 debugfs_create_file("rx_rssi", 0666, data->debugfs, data,
5314 &hwsim_fops_rx_rssi);
5315 if (!data->use_chanctx)
5316 debugfs_create_file("dfs_simulate_radar", 0222,
5318 data, &hwsim_simulate_radar);
5320 if (param->pmsr_capa) {
5321 data->pmsr_capa = *param->pmsr_capa;
5322 hw->wiphy->pmsr_capa = &data->pmsr_capa;
5325 spin_lock_bh(&hwsim_radio_lock);
5326 err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht,
5330 GENL_SET_ERR_MSG(info, "perm addr already present");
5331 NL_SET_BAD_ATTR(info->extack,
5332 info->attrs[HWSIM_ATTR_PERM_ADDR]);
5334 spin_unlock_bh(&hwsim_radio_lock);
5335 goto failed_final_insert;
5338 list_add_tail(&data->list, &hwsim_radios);
5339 hwsim_radios_generation++;
5340 spin_unlock_bh(&hwsim_radio_lock);
5342 hwsim_mcast_new_radio(idx, info, param);
5346 failed_final_insert:
5347 debugfs_remove_recursive(data->debugfs);
5348 ieee80211_unregister_hw(data->hw);
5350 device_release_driver(data->dev);
5352 device_unregister(data->dev);
5354 ieee80211_free_hw(hw);
5359 static void hwsim_mcast_del_radio(int id, const char *hwname,
5360 struct genl_info *info)
5362 struct sk_buff *skb;
5366 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
5370 data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0,
5371 HWSIM_CMD_DEL_RADIO);
5375 ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id);
5379 ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname),
5384 genlmsg_end(skb, data);
5386 hwsim_mcast_config_msg(skb, info);
5394 static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data,
5396 struct genl_info *info)
5398 hwsim_mcast_del_radio(data->idx, hwname, info);
5399 debugfs_remove_recursive(data->debugfs);
5400 ieee80211_unregister_hw(data->hw);
5401 device_release_driver(data->dev);
5402 device_unregister(data->dev);
5403 ieee80211_free_hw(data->hw);
5406 static int mac80211_hwsim_get_radio(struct sk_buff *skb,
5407 struct mac80211_hwsim_data *data,
5408 u32 portid, u32 seq,
5409 struct netlink_callback *cb, int flags)
5412 struct hwsim_new_radio_params param = { };
5413 int res = -EMSGSIZE;
5415 hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags,
5416 HWSIM_CMD_GET_RADIO);
5421 genl_dump_check_consistent(cb, hdr);
5423 if (data->alpha2[0] && data->alpha2[1])
5424 param.reg_alpha2 = data->alpha2;
5426 param.reg_strict = !!(data->hw->wiphy->regulatory_flags &
5427 REGULATORY_STRICT_REG);
5428 param.p2p_device = !!(data->hw->wiphy->interface_modes &
5429 BIT(NL80211_IFTYPE_P2P_DEVICE));
5430 param.use_chanctx = data->use_chanctx;
5431 param.regd = data->regd;
5432 param.channels = data->channels;
5433 param.hwname = wiphy_name(data->hw->wiphy);
5434 param.pmsr_capa = &data->pmsr_capa;
5436 res = append_radio_msg(skb, data->idx, ¶m);
5440 genlmsg_end(skb, hdr);
5444 genlmsg_cancel(skb, hdr);
5448 static void mac80211_hwsim_free(void)
5450 struct mac80211_hwsim_data *data;
5452 spin_lock_bh(&hwsim_radio_lock);
5453 while ((data = list_first_entry_or_null(&hwsim_radios,
5454 struct mac80211_hwsim_data,
5456 list_del(&data->list);
5457 spin_unlock_bh(&hwsim_radio_lock);
5458 mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
5460 spin_lock_bh(&hwsim_radio_lock);
5462 spin_unlock_bh(&hwsim_radio_lock);
5463 class_destroy(hwsim_class);
5466 static const struct net_device_ops hwsim_netdev_ops = {
5467 .ndo_start_xmit = hwsim_mon_xmit,
5468 .ndo_set_mac_address = eth_mac_addr,
5469 .ndo_validate_addr = eth_validate_addr,
5472 static void hwsim_mon_setup(struct net_device *dev)
5476 dev->netdev_ops = &hwsim_netdev_ops;
5477 dev->needs_free_netdev = true;
5479 dev->priv_flags |= IFF_NO_QUEUE;
5480 dev->type = ARPHRD_IEEE80211_RADIOTAP;
5481 eth_zero_addr(addr);
5483 eth_hw_addr_set(dev, addr);
5486 static void hwsim_register_wmediumd(struct net *net, u32 portid)
5488 struct mac80211_hwsim_data *data;
5490 hwsim_net_set_wmediumd(net, portid);
5492 spin_lock_bh(&hwsim_radio_lock);
5493 list_for_each_entry(data, &hwsim_radios, list) {
5494 if (data->netgroup == hwsim_net_get_netgroup(net))
5495 data->wmediumd = portid;
5497 spin_unlock_bh(&hwsim_radio_lock);
5500 static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
5501 struct genl_info *info)
5504 struct ieee80211_hdr *hdr;
5505 struct mac80211_hwsim_data *data2;
5506 struct ieee80211_tx_info *txi;
5507 struct hwsim_tx_rate *tx_attempts;
5509 struct sk_buff *skb, *tmp;
5511 unsigned int hwsim_flags;
5513 unsigned long flags;
5516 if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] ||
5517 !info->attrs[HWSIM_ATTR_FLAGS] ||
5518 !info->attrs[HWSIM_ATTR_COOKIE] ||
5519 !info->attrs[HWSIM_ATTR_SIGNAL] ||
5520 !info->attrs[HWSIM_ATTR_TX_INFO])
5523 src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
5524 hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
5525 ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
5527 data2 = get_hwsim_data_ref_from_addr(src);
5531 if (!hwsim_virtio_enabled) {
5532 if (hwsim_net_get_netgroup(genl_info_net(info)) !=
5536 if (info->snd_portid != data2->wmediumd)
5540 /* look for the skb matching the cookie passed back from user */
5541 spin_lock_irqsave(&data2->pending.lock, flags);
5542 skb_queue_walk_safe(&data2->pending, skb, tmp) {
5543 uintptr_t skb_cookie;
5545 txi = IEEE80211_SKB_CB(skb);
5546 skb_cookie = (uintptr_t)txi->rate_driver_data[0];
5548 if (skb_cookie == ret_skb_cookie) {
5549 __skb_unlink(skb, &data2->pending);
5554 spin_unlock_irqrestore(&data2->pending.lock, flags);
5560 /* Tx info received because the frame was broadcasted on user space,
5561 so we get all the necessary info: tx attempts and skb control buff */
5563 tx_attempts = (struct hwsim_tx_rate *)nla_data(
5564 info->attrs[HWSIM_ATTR_TX_INFO]);
5566 /* now send back TX status */
5567 txi = IEEE80211_SKB_CB(skb);
5569 ieee80211_tx_info_clear_status(txi);
5571 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
5572 txi->status.rates[i].idx = tx_attempts[i].idx;
5573 txi->status.rates[i].count = tx_attempts[i].count;
5576 txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
5578 if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) &&
5579 (hwsim_flags & HWSIM_TX_STAT_ACK)) {
5580 if (skb->len >= 16) {
5581 hdr = (struct ieee80211_hdr *) skb->data;
5582 mac80211_hwsim_monitor_ack(data2->channel,
5585 txi->flags |= IEEE80211_TX_STAT_ACK;
5588 if (hwsim_flags & HWSIM_TX_CTL_NO_ACK)
5589 txi->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
5591 ieee80211_tx_status_irqsafe(data2->hw, skb);
5598 static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
5599 struct genl_info *info)
5601 struct mac80211_hwsim_data *data2;
5602 struct ieee80211_rx_status rx_status;
5603 struct ieee80211_hdr *hdr;
5607 struct sk_buff *skb = NULL;
5608 struct ieee80211_channel *channel = NULL;
5610 if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] ||
5611 !info->attrs[HWSIM_ATTR_FRAME] ||
5612 !info->attrs[HWSIM_ATTR_RX_RATE] ||
5613 !info->attrs[HWSIM_ATTR_SIGNAL])
5616 dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]);
5617 frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]);
5618 frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]);
5620 /* Allocate new skb here */
5621 skb = alloc_skb(frame_data_len, GFP_KERNEL);
5625 if (frame_data_len > IEEE80211_MAX_DATA_LEN)
5629 skb_put_data(skb, frame_data, frame_data_len);
5631 data2 = get_hwsim_data_ref_from_addr(dst);
5635 if (data2->use_chanctx) {
5636 if (data2->tmp_chan)
5637 channel = data2->tmp_chan;
5639 channel = data2->channel;
5642 if (!hwsim_virtio_enabled) {
5643 if (hwsim_net_get_netgroup(genl_info_net(info)) !=
5647 if (info->snd_portid != data2->wmediumd)
5651 /* check if radio is configured properly */
5653 if ((data2->idle && !data2->tmp_chan) || !data2->started)
5656 /* A frame is received from user space */
5657 memset(&rx_status, 0, sizeof(rx_status));
5658 if (info->attrs[HWSIM_ATTR_FREQ]) {
5659 struct tx_iter_data iter_data = {};
5661 /* throw away off-channel packets, but allow both the temporary
5662 * ("hw" scan/remain-on-channel), regular channels and links,
5663 * since the internal datapath also allows this
5665 rx_status.freq = nla_get_u32(info->attrs[HWSIM_ATTR_FREQ]);
5667 iter_data.channel = ieee80211_get_channel(data2->hw->wiphy,
5669 if (!iter_data.channel)
5671 rx_status.band = iter_data.channel->band;
5673 mutex_lock(&data2->mutex);
5674 if (!hwsim_chans_compat(iter_data.channel, channel)) {
5675 ieee80211_iterate_active_interfaces_atomic(
5676 data2->hw, IEEE80211_IFACE_ITER_NORMAL,
5677 mac80211_hwsim_tx_iter, &iter_data);
5678 if (!iter_data.receive) {
5679 mutex_unlock(&data2->mutex);
5683 mutex_unlock(&data2->mutex);
5684 } else if (!channel) {
5687 rx_status.freq = channel->center_freq;
5688 rx_status.band = channel->band;
5691 rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]);
5692 if (rx_status.rate_idx >= data2->hw->wiphy->bands[rx_status.band]->n_bitrates)
5694 rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]);
5696 hdr = (void *)skb->data;
5698 if (ieee80211_is_beacon(hdr->frame_control) ||
5699 ieee80211_is_probe_resp(hdr->frame_control))
5700 rx_status.boottime_ns = ktime_get_boottime_ns();
5702 mac80211_hwsim_rx(data2, &rx_status, skb);
5706 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
5712 static int hwsim_register_received_nl(struct sk_buff *skb_2,
5713 struct genl_info *info)
5715 struct net *net = genl_info_net(info);
5716 struct mac80211_hwsim_data *data;
5719 spin_lock_bh(&hwsim_radio_lock);
5720 list_for_each_entry(data, &hwsim_radios, list)
5721 chans = max(chans, data->channels);
5722 spin_unlock_bh(&hwsim_radio_lock);
5724 /* In the future we should revise the userspace API and allow it
5725 * to set a flag that it does support multi-channel, then we can
5726 * let this pass conditionally on the flag.
5727 * For current userspace, prohibit it since it won't work right.
5732 if (hwsim_net_get_wmediumd(net))
5735 hwsim_register_wmediumd(net, info->snd_portid);
5737 pr_debug("mac80211_hwsim: received a REGISTER, "
5738 "switching to wmediumd mode with pid %d\n", info->snd_portid);
5743 /* ensures ciphers only include ciphers listed in 'hwsim_ciphers' array */
5744 static bool hwsim_known_ciphers(const u32 *ciphers, int n_ciphers)
5748 for (i = 0; i < n_ciphers; i++) {
5752 for (j = 0; j < ARRAY_SIZE(hwsim_ciphers); j++) {
5753 if (ciphers[i] == hwsim_ciphers[j]) {
5766 static int parse_ftm_capa(const struct nlattr *ftm_capa, struct cfg80211_pmsr_capabilities *out,
5767 struct genl_info *info)
5769 struct nlattr *tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1];
5772 ret = nla_parse_nested(tb, NL80211_PMSR_FTM_CAPA_ATTR_MAX, ftm_capa, hwsim_ftm_capa_policy,
5775 NL_SET_ERR_MSG_ATTR(info->extack, ftm_capa, "malformed FTM capability");
5779 out->ftm.supported = 1;
5780 if (tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES])
5781 out->ftm.preambles = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES]);
5782 if (tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS])
5783 out->ftm.bandwidths = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS]);
5784 if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT])
5785 out->ftm.max_bursts_exponent =
5786 nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT]);
5787 if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST])
5788 out->ftm.max_ftms_per_burst =
5789 nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST]);
5790 out->ftm.asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_ASAP];
5791 out->ftm.non_asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP];
5792 out->ftm.request_lci = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI];
5793 out->ftm.request_civicloc = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC];
5794 out->ftm.trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED];
5795 out->ftm.non_trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED];
5800 static int parse_pmsr_capa(const struct nlattr *pmsr_capa, struct cfg80211_pmsr_capabilities *out,
5801 struct genl_info *info)
5803 struct nlattr *tb[NL80211_PMSR_ATTR_MAX + 1];
5808 ret = nla_parse_nested(tb, NL80211_PMSR_ATTR_MAX, pmsr_capa, hwsim_pmsr_capa_policy, NULL);
5810 NL_SET_ERR_MSG_ATTR(info->extack, pmsr_capa, "malformed PMSR capability");
5814 if (tb[NL80211_PMSR_ATTR_MAX_PEERS])
5815 out->max_peers = nla_get_u32(tb[NL80211_PMSR_ATTR_MAX_PEERS]);
5816 out->report_ap_tsf = !!tb[NL80211_PMSR_ATTR_REPORT_AP_TSF];
5817 out->randomize_mac_addr = !!tb[NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR];
5819 if (!tb[NL80211_PMSR_ATTR_TYPE_CAPA]) {
5820 NL_SET_ERR_MSG_ATTR(info->extack, tb[NL80211_PMSR_ATTR_TYPE_CAPA],
5821 "malformed PMSR type");
5825 nla_for_each_nested(nla, tb[NL80211_PMSR_ATTR_TYPE_CAPA], size) {
5826 switch (nla_type(nla)) {
5827 case NL80211_PMSR_TYPE_FTM:
5828 parse_ftm_capa(nla, out, info);
5831 NL_SET_ERR_MSG_ATTR(info->extack, nla, "unsupported measurement type");
5839 static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
5841 struct hwsim_new_radio_params param = { 0 };
5842 const char *hwname = NULL;
5845 param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
5846 param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
5847 param.channels = channels;
5848 param.destroy_on_close =
5849 info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE];
5851 if (info->attrs[HWSIM_ATTR_CHANNELS])
5852 param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]);
5854 if (param.channels < 1) {
5855 GENL_SET_ERR_MSG(info, "must have at least one channel");
5859 if (info->attrs[HWSIM_ATTR_NO_VIF])
5860 param.no_vif = true;
5862 if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
5863 param.use_chanctx = true;
5865 param.use_chanctx = (param.channels > 1);
5867 if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2])
5869 nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]);
5871 if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) {
5872 u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]);
5874 if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom))
5877 idx = array_index_nospec(idx,
5878 ARRAY_SIZE(hwsim_world_regdom_custom));
5879 param.regd = hwsim_world_regdom_custom[idx];
5882 if (info->attrs[HWSIM_ATTR_PERM_ADDR]) {
5883 if (!is_valid_ether_addr(
5884 nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) {
5885 GENL_SET_ERR_MSG(info,"MAC is no valid source addr");
5886 NL_SET_BAD_ATTR(info->extack,
5887 info->attrs[HWSIM_ATTR_PERM_ADDR]);
5891 param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]);
5894 if (info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]) {
5896 nla_get_u32(info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]);
5898 if (param.iftypes & ~HWSIM_IFTYPE_SUPPORT_MASK) {
5899 NL_SET_ERR_MSG_ATTR(info->extack,
5900 info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT],
5901 "cannot support more iftypes than kernel");
5905 param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
5908 /* ensure both flag and iftype support is honored */
5909 if (param.p2p_device ||
5910 param.iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) {
5911 param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
5912 param.p2p_device = true;
5915 if (info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]) {
5916 u32 len = nla_len(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
5919 nla_data(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]);
5921 if (len % sizeof(u32)) {
5922 NL_SET_ERR_MSG_ATTR(info->extack,
5923 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5924 "bad cipher list length");
5928 param.n_ciphers = len / sizeof(u32);
5930 if (param.n_ciphers > ARRAY_SIZE(hwsim_ciphers)) {
5931 NL_SET_ERR_MSG_ATTR(info->extack,
5932 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5933 "too many ciphers specified");
5937 if (!hwsim_known_ciphers(param.ciphers, param.n_ciphers)) {
5938 NL_SET_ERR_MSG_ATTR(info->extack,
5939 info->attrs[HWSIM_ATTR_CIPHER_SUPPORT],
5940 "unsupported ciphers specified");
5945 param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT];
5948 param.use_chanctx = true;
5950 if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
5951 hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5952 nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5956 param.hwname = hwname;
5959 if (info->attrs[HWSIM_ATTR_PMSR_SUPPORT]) {
5960 struct cfg80211_pmsr_capabilities *pmsr_capa;
5962 pmsr_capa = kmalloc(sizeof(*pmsr_capa), GFP_KERNEL);
5967 param.pmsr_capa = pmsr_capa;
5969 ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT], pmsr_capa, info);
5974 ret = mac80211_hwsim_new_radio(info, ¶m);
5978 kfree(param.pmsr_capa);
5982 static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
5984 struct mac80211_hwsim_data *data;
5986 const char *hwname = NULL;
5988 if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
5989 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
5990 } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
5991 hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5992 nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
5999 spin_lock_bh(&hwsim_radio_lock);
6000 list_for_each_entry(data, &hwsim_radios, list) {
6002 if (data->idx != idx)
6006 strcmp(hwname, wiphy_name(data->hw->wiphy)))
6010 if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
6013 list_del(&data->list);
6014 rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
6016 hwsim_radios_generation++;
6017 spin_unlock_bh(&hwsim_radio_lock);
6018 mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
6023 spin_unlock_bh(&hwsim_radio_lock);
6029 static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info)
6031 struct mac80211_hwsim_data *data;
6032 struct sk_buff *skb;
6033 int idx, res = -ENODEV;
6035 if (!info->attrs[HWSIM_ATTR_RADIO_ID])
6037 idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
6039 spin_lock_bh(&hwsim_radio_lock);
6040 list_for_each_entry(data, &hwsim_radios, list) {
6041 if (data->idx != idx)
6044 if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info)))
6047 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
6053 res = mac80211_hwsim_get_radio(skb, data, info->snd_portid,
6054 info->snd_seq, NULL, 0);
6060 res = genlmsg_reply(skb, info);
6065 spin_unlock_bh(&hwsim_radio_lock);
6070 static int hwsim_dump_radio_nl(struct sk_buff *skb,
6071 struct netlink_callback *cb)
6073 int last_idx = cb->args[0] - 1;
6074 struct mac80211_hwsim_data *data = NULL;
6078 spin_lock_bh(&hwsim_radio_lock);
6079 cb->seq = hwsim_radios_generation;
6081 if (last_idx >= hwsim_radio_idx-1)
6084 list_for_each_entry(data, &hwsim_radios, list) {
6085 if (data->idx <= last_idx)
6088 if (!net_eq(wiphy_net(data->hw->wiphy), sock_net(skb->sk)))
6091 res = mac80211_hwsim_get_radio(skb, data,
6092 NETLINK_CB(cb->skb).portid,
6093 cb->nlh->nlmsg_seq, cb,
6098 last_idx = data->idx;
6101 cb->args[0] = last_idx + 1;
6103 /* list changed, but no new element sent, set interrupted flag */
6104 if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) {
6105 hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
6106 cb->nlh->nlmsg_seq, &hwsim_genl_family,
6107 NLM_F_MULTI, HWSIM_CMD_GET_RADIO);
6109 genl_dump_check_consistent(cb, hdr);
6110 genlmsg_end(skb, hdr);
6117 spin_unlock_bh(&hwsim_radio_lock);
6118 return res ?: skb->len;
6121 /* Generic Netlink operations array */
6122 static const struct genl_small_ops hwsim_ops[] = {
6124 .cmd = HWSIM_CMD_REGISTER,
6125 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6126 .doit = hwsim_register_received_nl,
6127 .flags = GENL_UNS_ADMIN_PERM,
6130 .cmd = HWSIM_CMD_FRAME,
6131 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6132 .doit = hwsim_cloned_frame_received_nl,
6135 .cmd = HWSIM_CMD_TX_INFO_FRAME,
6136 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6137 .doit = hwsim_tx_info_frame_received_nl,
6140 .cmd = HWSIM_CMD_NEW_RADIO,
6141 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6142 .doit = hwsim_new_radio_nl,
6143 .flags = GENL_UNS_ADMIN_PERM,
6146 .cmd = HWSIM_CMD_DEL_RADIO,
6147 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6148 .doit = hwsim_del_radio_nl,
6149 .flags = GENL_UNS_ADMIN_PERM,
6152 .cmd = HWSIM_CMD_GET_RADIO,
6153 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6154 .doit = hwsim_get_radio_nl,
6155 .dumpit = hwsim_dump_radio_nl,
6158 .cmd = HWSIM_CMD_REPORT_PMSR,
6159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
6160 .doit = hwsim_pmsr_report_nl,
6164 static struct genl_family hwsim_genl_family __ro_after_init = {
6165 .name = "MAC80211_HWSIM",
6167 .maxattr = HWSIM_ATTR_MAX,
6168 .policy = hwsim_genl_policy,
6170 .module = THIS_MODULE,
6171 .small_ops = hwsim_ops,
6172 .n_small_ops = ARRAY_SIZE(hwsim_ops),
6173 .resv_start_op = HWSIM_CMD_REPORT_PMSR + 1, // match with __HWSIM_CMD_MAX
6174 .mcgrps = hwsim_mcgrps,
6175 .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps),
6178 static void remove_user_radios(u32 portid)
6180 struct mac80211_hwsim_data *entry, *tmp;
6183 spin_lock_bh(&hwsim_radio_lock);
6184 list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
6185 if (entry->destroy_on_close && entry->portid == portid) {
6186 list_move(&entry->list, &list);
6187 rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht,
6189 hwsim_radios_generation++;
6192 spin_unlock_bh(&hwsim_radio_lock);
6194 list_for_each_entry_safe(entry, tmp, &list, list) {
6195 list_del(&entry->list);
6196 mac80211_hwsim_del_radio(entry, wiphy_name(entry->hw->wiphy),
6201 static int mac80211_hwsim_netlink_notify(struct notifier_block *nb,
6202 unsigned long state,
6205 struct netlink_notify *notify = _notify;
6207 if (state != NETLINK_URELEASE)
6210 remove_user_radios(notify->portid);
6212 if (notify->portid == hwsim_net_get_wmediumd(notify->net)) {
6213 printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink"
6214 " socket, switching to perfect channel medium\n");
6215 hwsim_register_wmediumd(notify->net, 0);
6221 static struct notifier_block hwsim_netlink_notifier = {
6222 .notifier_call = mac80211_hwsim_netlink_notify,
6225 static int __init hwsim_init_netlink(void)
6229 printk(KERN_INFO "mac80211_hwsim: initializing netlink\n");
6231 rc = genl_register_family(&hwsim_genl_family);
6235 rc = netlink_register_notifier(&hwsim_netlink_notifier);
6237 genl_unregister_family(&hwsim_genl_family);
6244 pr_debug("mac80211_hwsim: error occurred in %s\n", __func__);
6248 static __net_init int hwsim_init_net(struct net *net)
6250 return hwsim_net_set_netgroup(net);
6253 static void __net_exit hwsim_exit_net(struct net *net)
6255 struct mac80211_hwsim_data *data, *tmp;
6258 spin_lock_bh(&hwsim_radio_lock);
6259 list_for_each_entry_safe(data, tmp, &hwsim_radios, list) {
6260 if (!net_eq(wiphy_net(data->hw->wiphy), net))
6263 /* Radios created in init_net are returned to init_net. */
6264 if (data->netgroup == hwsim_net_get_netgroup(&init_net))
6267 list_move(&data->list, &list);
6268 rhashtable_remove_fast(&hwsim_radios_rht, &data->rht,
6270 hwsim_radios_generation++;
6272 spin_unlock_bh(&hwsim_radio_lock);
6274 list_for_each_entry_safe(data, tmp, &list, list) {
6275 list_del(&data->list);
6276 mac80211_hwsim_del_radio(data,
6277 wiphy_name(data->hw->wiphy),
6281 ida_free(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
6284 static struct pernet_operations hwsim_net_ops = {
6285 .init = hwsim_init_net,
6286 .exit = hwsim_exit_net,
6287 .id = &hwsim_net_id,
6288 .size = sizeof(struct hwsim_net),
6291 static void hwsim_exit_netlink(void)
6293 /* unregister the notifier */
6294 netlink_unregister_notifier(&hwsim_netlink_notifier);
6295 /* unregister the family */
6296 genl_unregister_family(&hwsim_genl_family);
6299 #if IS_REACHABLE(CONFIG_VIRTIO)
6300 static void hwsim_virtio_tx_done(struct virtqueue *vq)
6303 struct sk_buff *skb;
6304 unsigned long flags;
6306 spin_lock_irqsave(&hwsim_virtio_lock, flags);
6307 while ((skb = virtqueue_get_buf(vq, &len)))
6309 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6312 static int hwsim_virtio_handle_cmd(struct sk_buff *skb)
6314 struct nlmsghdr *nlh;
6315 struct genlmsghdr *gnlh;
6316 struct nlattr *tb[HWSIM_ATTR_MAX + 1];
6317 struct genl_info info = {};
6320 nlh = nlmsg_hdr(skb);
6321 gnlh = nlmsg_data(nlh);
6323 if (skb->len < nlh->nlmsg_len)
6326 err = genlmsg_parse(nlh, &hwsim_genl_family, tb, HWSIM_ATTR_MAX,
6327 hwsim_genl_policy, NULL);
6329 pr_err_ratelimited("hwsim: genlmsg_parse returned %d\n", err);
6335 switch (gnlh->cmd) {
6336 case HWSIM_CMD_FRAME:
6337 hwsim_cloned_frame_received_nl(skb, &info);
6339 case HWSIM_CMD_TX_INFO_FRAME:
6340 hwsim_tx_info_frame_received_nl(skb, &info);
6342 case HWSIM_CMD_REPORT_PMSR:
6343 hwsim_pmsr_report_nl(skb, &info);
6346 pr_err_ratelimited("hwsim: invalid cmd: %d\n", gnlh->cmd);
6352 static void hwsim_virtio_rx_work(struct work_struct *work)
6354 struct virtqueue *vq;
6356 struct sk_buff *skb;
6357 struct scatterlist sg[1];
6359 unsigned long flags;
6361 spin_lock_irqsave(&hwsim_virtio_lock, flags);
6362 if (!hwsim_virtio_enabled)
6365 skb = virtqueue_get_buf(hwsim_vqs[HWSIM_VQ_RX], &len);
6368 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6370 skb->data = skb->head;
6371 skb_reset_tail_pointer(skb);
6373 hwsim_virtio_handle_cmd(skb);
6375 spin_lock_irqsave(&hwsim_virtio_lock, flags);
6376 if (!hwsim_virtio_enabled) {
6380 vq = hwsim_vqs[HWSIM_VQ_RX];
6381 sg_init_one(sg, skb->head, skb_end_offset(skb));
6382 err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_ATOMIC);
6383 if (WARN(err, "virtqueue_add_inbuf returned %d\n", err))
6387 schedule_work(&hwsim_virtio_rx);
6390 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6393 static void hwsim_virtio_rx_done(struct virtqueue *vq)
6395 schedule_work(&hwsim_virtio_rx);
6398 static int init_vqs(struct virtio_device *vdev)
6400 vq_callback_t *callbacks[HWSIM_NUM_VQS] = {
6401 [HWSIM_VQ_TX] = hwsim_virtio_tx_done,
6402 [HWSIM_VQ_RX] = hwsim_virtio_rx_done,
6404 const char *names[HWSIM_NUM_VQS] = {
6405 [HWSIM_VQ_TX] = "tx",
6406 [HWSIM_VQ_RX] = "rx",
6409 return virtio_find_vqs(vdev, HWSIM_NUM_VQS,
6410 hwsim_vqs, callbacks, names, NULL);
6413 static int fill_vq(struct virtqueue *vq)
6416 struct sk_buff *skb;
6417 struct scatterlist sg[1];
6419 for (i = 0; i < virtqueue_get_vring_size(vq); i++) {
6420 skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
6424 sg_init_one(sg, skb->head, skb_end_offset(skb));
6425 err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_KERNEL);
6435 static void remove_vqs(struct virtio_device *vdev)
6439 virtio_reset_device(vdev);
6441 for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) {
6442 struct virtqueue *vq = hwsim_vqs[i];
6443 struct sk_buff *skb;
6445 while ((skb = virtqueue_detach_unused_buf(vq)))
6449 vdev->config->del_vqs(vdev);
6452 static int hwsim_virtio_probe(struct virtio_device *vdev)
6455 unsigned long flags;
6457 spin_lock_irqsave(&hwsim_virtio_lock, flags);
6458 if (hwsim_virtio_enabled) {
6459 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6462 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6464 err = init_vqs(vdev);
6468 virtio_device_ready(vdev);
6470 err = fill_vq(hwsim_vqs[HWSIM_VQ_RX]);
6474 spin_lock_irqsave(&hwsim_virtio_lock, flags);
6475 hwsim_virtio_enabled = true;
6476 spin_unlock_irqrestore(&hwsim_virtio_lock, flags);
6478 schedule_work(&hwsim_virtio_rx);
6486 static void hwsim_virtio_remove(struct virtio_device *vdev)
6488 hwsim_virtio_enabled = false;
6490 cancel_work_sync(&hwsim_virtio_rx);
6495 /* MAC80211_HWSIM virtio device id table */
6496 static const struct virtio_device_id id_table[] = {
6497 { VIRTIO_ID_MAC80211_HWSIM, VIRTIO_DEV_ANY_ID },
6500 MODULE_DEVICE_TABLE(virtio, id_table);
6502 static struct virtio_driver virtio_hwsim = {
6503 .driver.name = KBUILD_MODNAME,
6504 .driver.owner = THIS_MODULE,
6505 .id_table = id_table,
6506 .probe = hwsim_virtio_probe,
6507 .remove = hwsim_virtio_remove,
6510 static int hwsim_register_virtio_driver(void)
6512 return register_virtio_driver(&virtio_hwsim);
6515 static void hwsim_unregister_virtio_driver(void)
6517 unregister_virtio_driver(&virtio_hwsim);
6520 static inline int hwsim_register_virtio_driver(void)
6525 static inline void hwsim_unregister_virtio_driver(void)
6530 static int __init init_mac80211_hwsim(void)
6534 if (radios < 0 || radios > 100)
6540 err = rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params);
6544 err = register_pernet_device(&hwsim_net_ops);
6548 err = platform_driver_register(&mac80211_hwsim_driver);
6550 goto out_unregister_pernet;
6552 err = hwsim_init_netlink();
6554 goto out_unregister_driver;
6556 err = hwsim_register_virtio_driver();
6558 goto out_exit_netlink;
6560 hwsim_class = class_create("mac80211_hwsim");
6561 if (IS_ERR(hwsim_class)) {
6562 err = PTR_ERR(hwsim_class);
6563 goto out_exit_virtio;
6566 hwsim_init_s1g_channels(hwsim_channels_s1g);
6568 for (i = 0; i < radios; i++) {
6569 struct hwsim_new_radio_params param = { 0 };
6571 param.channels = channels;
6574 case HWSIM_REGTEST_DIFF_COUNTRY:
6575 if (i < ARRAY_SIZE(hwsim_alpha2s))
6576 param.reg_alpha2 = hwsim_alpha2s[i];
6578 case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
6580 param.reg_alpha2 = hwsim_alpha2s[0];
6582 case HWSIM_REGTEST_STRICT_ALL:
6583 param.reg_strict = true;
6585 case HWSIM_REGTEST_DRIVER_REG_ALL:
6586 param.reg_alpha2 = hwsim_alpha2s[0];
6588 case HWSIM_REGTEST_WORLD_ROAM:
6590 param.regd = &hwsim_world_regdom_custom_01;
6592 case HWSIM_REGTEST_CUSTOM_WORLD:
6593 param.regd = &hwsim_world_regdom_custom_01;
6595 case HWSIM_REGTEST_CUSTOM_WORLD_2:
6597 param.regd = &hwsim_world_regdom_custom_01;
6599 param.regd = &hwsim_world_regdom_custom_02;
6601 case HWSIM_REGTEST_STRICT_FOLLOW:
6603 param.reg_strict = true;
6604 param.reg_alpha2 = hwsim_alpha2s[0];
6607 case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
6609 param.reg_strict = true;
6610 param.reg_alpha2 = hwsim_alpha2s[0];
6611 } else if (i == 1) {
6612 param.reg_alpha2 = hwsim_alpha2s[1];
6615 case HWSIM_REGTEST_ALL:
6618 param.regd = &hwsim_world_regdom_custom_01;
6621 param.regd = &hwsim_world_regdom_custom_02;
6624 param.reg_alpha2 = hwsim_alpha2s[0];
6627 param.reg_alpha2 = hwsim_alpha2s[1];
6630 param.reg_strict = true;
6631 param.reg_alpha2 = hwsim_alpha2s[2];
6639 param.p2p_device = support_p2p_device;
6641 param.use_chanctx = channels > 1 || mlo;
6642 param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK;
6643 if (param.p2p_device)
6644 param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE);
6646 err = mac80211_hwsim_new_radio(NULL, ¶m);
6648 goto out_free_radios;
6651 hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN,
6653 if (hwsim_mon == NULL) {
6655 goto out_free_radios;
6659 err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
6665 err = register_netdevice(hwsim_mon);
6675 free_netdev(hwsim_mon);
6677 mac80211_hwsim_free();
6679 hwsim_unregister_virtio_driver();
6681 hwsim_exit_netlink();
6682 out_unregister_driver:
6683 platform_driver_unregister(&mac80211_hwsim_driver);
6684 out_unregister_pernet:
6685 unregister_pernet_device(&hwsim_net_ops);
6687 rhashtable_destroy(&hwsim_radios_rht);
6690 module_init(init_mac80211_hwsim);
6692 static void __exit exit_mac80211_hwsim(void)
6694 pr_debug("mac80211_hwsim: unregister radios\n");
6696 hwsim_unregister_virtio_driver();
6697 hwsim_exit_netlink();
6699 mac80211_hwsim_free();
6701 rhashtable_destroy(&hwsim_radios_rht);
6702 unregister_netdev(hwsim_mon);
6703 platform_driver_unregister(&mac80211_hwsim_driver);
6704 unregister_pernet_device(&hwsim_net_ops);
6706 module_exit(exit_mac80211_hwsim);