Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
acc1e7a3 JM |
2 | /* |
3 | * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211 | |
4 | * Copyright (c) 2008, Jouni Malinen <j@w1.fi> | |
7882513b | 5 | * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com> |
518ea3c5 | 6 | * Copyright (c) 2016 - 2017 Intel Deutschland GmbH |
358ddc7b | 7 | * Copyright (C) 2018 - 2024 Intel Corporation |
acc1e7a3 JM |
8 | */ |
9 | ||
10 | /* | |
11 | * TODO: | |
2b2d7795 JB |
12 | * - Add TSF sync and fix IBSS beacon transmission by adding |
13 | * competition for "air time" at TBTT | |
acc1e7a3 JM |
14 | * - RX filtering based on filter configuration (data->rx_filter) |
15 | */ | |
16 | ||
0e057d73 | 17 | #include <linux/list.h> |
5a0e3ad6 | 18 | #include <linux/slab.h> |
0e057d73 | 19 | #include <linux/spinlock.h> |
90e3012e JB |
20 | #include <net/dst.h> |
21 | #include <net/xfrm.h> | |
acc1e7a3 JM |
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> | |
9ea92774 | 27 | #include <linux/platform_device.h> |
fc6971d4 | 28 | #include <linux/debugfs.h> |
9d9779e7 | 29 | #include <linux/module.h> |
2f40b940 | 30 | #include <linux/ktime.h> |
7882513b | 31 | #include <net/genetlink.h> |
100cb9ff MW |
32 | #include <net/net_namespace.h> |
33 | #include <net/netns/generic.h> | |
c6509cc3 | 34 | #include <linux/rhashtable.h> |
3a2af7cc | 35 | #include <linux/nospec.h> |
5d44fe7c EG |
36 | #include <linux/virtio.h> |
37 | #include <linux/virtio_ids.h> | |
38 | #include <linux/virtio_config.h> | |
7882513b JL |
39 | #include "mac80211_hwsim.h" |
40 | ||
41 | #define WARN_QUEUE 100 | |
42 | #define MAX_QUEUE 200 | |
acc1e7a3 JM |
43 | |
44 | MODULE_AUTHOR("Jouni Malinen"); | |
45 | MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211"); | |
46 | MODULE_LICENSE("GPL"); | |
47 | ||
48 | static int radios = 2; | |
49 | module_param(radios, int, 0444); | |
50 | MODULE_PARM_DESC(radios, "Number of simulated radios"); | |
51 | ||
e8261171 JB |
52 | static int channels = 1; |
53 | module_param(channels, int, 0444); | |
54 | MODULE_PARM_DESC(channels, "Number of concurrent channels"); | |
69068036 | 55 | |
a357d7f9 JB |
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"); | |
59 | ||
1eb32179 KB |
60 | static bool rctbl = false; |
61 | module_param(rctbl, bool, 0444); | |
62 | MODULE_PARM_DESC(rctbl, "Handle rate control table"); | |
63 | ||
8c66a3d9 JB |
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"); | |
67 | ||
2fd0c671 JB |
68 | static bool mlo; |
69 | module_param(mlo, bool, 0444); | |
70 | MODULE_PARM_DESC(mlo, "Support MLO"); | |
71 | ||
4a5af9c2 LR |
72 | /** |
73 | * enum hwsim_regtest - the type of regulatory tests we offer | |
74 | * | |
4a5af9c2 LR |
75 | * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed, |
76 | * this is the default value. | |
77 | * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory | |
78 | * hint, only one driver regulatory hint will be sent as such the | |
79 | * secondary radios are expected to follow. | |
80 | * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory | |
81 | * request with all radios reporting the same regulatory domain. | |
82 | * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling | |
83 | * different regulatory domains requests. Expected behaviour is for | |
84 | * an intersection to occur but each device will still use their | |
85 | * respective regulatory requested domains. Subsequent radios will | |
86 | * use the resulting intersection. | |
25985edc | 87 | * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish |
4a5af9c2 LR |
88 | * this by using a custom beacon-capable regulatory domain for the first |
89 | * radio. All other device world roam. | |
90 | * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory | |
91 | * domain requests. All radios will adhere to this custom world regulatory | |
92 | * domain. | |
93 | * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory | |
94 | * domain requests. The first radio will adhere to the first custom world | |
95 | * regulatory domain, the second one to the second custom world regulatory | |
96 | * domain. All other devices will world roam. | |
e83adb18 | 97 | * @HWSIM_REGTEST_STRICT_FOLLOW: Used for testing strict regulatory domain |
4a5af9c2 LR |
98 | * settings, only the first radio will send a regulatory domain request |
99 | * and use strict settings. The rest of the radios are expected to follow. | |
100 | * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain | |
101 | * settings. All radios will adhere to this. | |
102 | * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory | |
103 | * domain settings, combined with secondary driver regulatory domain | |
104 | * settings. The first radio will get a strict regulatory domain setting | |
105 | * using the first driver regulatory request and the second radio will use | |
106 | * non-strict settings using the second driver regulatory request. All | |
107 | * other devices should follow the intersection created between the | |
108 | * first two. | |
109 | * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need | |
110 | * at least 6 radios for a complete test. We will test in this order: | |
111 | * 1 - driver custom world regulatory domain | |
112 | * 2 - second custom world regulatory domain | |
113 | * 3 - first driver regulatory domain request | |
114 | * 4 - second driver regulatory domain request | |
115 | * 5 - strict regulatory domain settings using the third driver regulatory | |
116 | * domain request | |
117 | * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio | |
118 | * regulatory requests. | |
c9394c82 JB |
119 | * |
120 | * These are the different values you can use for the regtest | |
121 | * module parameter. This is useful to help test world roaming | |
122 | * and the driver regulatory_hint() call and combinations of these. | |
123 | * If you want to do specific alpha2 regulatory domain tests simply | |
124 | * use the userspace regulatory request as that will be respected as | |
125 | * well without the need of this module parameter. This is designed | |
126 | * only for testing the driver regulatory request, world roaming | |
127 | * and all possible combinations. | |
4a5af9c2 LR |
128 | */ |
129 | enum hwsim_regtest { | |
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, | |
141 | }; | |
142 | ||
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"); | |
147 | ||
148 | static const char *hwsim_alpha2s[] = { | |
149 | "FI", | |
150 | "AL", | |
151 | "US", | |
152 | "DE", | |
153 | "JP", | |
154 | "AL", | |
155 | }; | |
156 | ||
157 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = { | |
b5764696 | 158 | .n_reg_rules = 5, |
4a5af9c2 LR |
159 | .alpha2 = "99", |
160 | .reg_rules = { | |
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), | |
b5764696 | 165 | REG_RULE(5855-10, 5925+10, 40, 0, 33, 0), |
4a5af9c2 LR |
166 | } |
167 | }; | |
168 | ||
169 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = { | |
b5764696 | 170 | .n_reg_rules = 3, |
4a5af9c2 LR |
171 | .alpha2 = "99", |
172 | .reg_rules = { | |
173 | REG_RULE(2412-10, 2462+10, 40, 0, 20, 0), | |
174 | REG_RULE(5725-10, 5850+10, 40, 0, 30, | |
8fe02e16 | 175 | NL80211_RRF_NO_IR), |
b5764696 | 176 | REG_RULE(5855-10, 5925+10, 40, 0, 33, 0), |
4a5af9c2 LR |
177 | } |
178 | }; | |
179 | ||
64e59429 IP |
180 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_03 = { |
181 | .n_reg_rules = 6, | |
182 | .alpha2 = "99", | |
183 | .reg_rules = { | |
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), | |
190 | } | |
191 | }; | |
192 | ||
99b6877d AO |
193 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_04 = { |
194 | .n_reg_rules = 6, | |
195 | .alpha2 = "99", | |
196 | .reg_rules = { | |
197 | REG_RULE(2412 - 10, 2462 + 10, 40, 0, 20, 0), | |
198 | REG_RULE(2484 - 10, 2484 + 10, 40, 0, 20, 0), | |
675516f5 | 199 | REG_RULE(5150 - 10, 5240 + 10, 80, 0, 30, NL80211_RRF_AUTO_BW), |
99b6877d | 200 | REG_RULE(5260 - 10, 5320 + 10, 80, 0, 30, |
675516f5 AO |
201 | NL80211_RRF_DFS_CONCURRENT | NL80211_RRF_DFS | |
202 | NL80211_RRF_AUTO_BW), | |
203 | REG_RULE(5500 - 10, 5720 + 10, 160, 0, 30, | |
99b6877d AO |
204 | NL80211_RRF_DFS_CONCURRENT | NL80211_RRF_DFS), |
205 | REG_RULE(5745 - 10, 5825 + 10, 80, 0, 30, 0), | |
206 | REG_RULE(5855 - 10, 5925 + 10, 80, 0, 33, 0), | |
207 | } | |
208 | }; | |
209 | ||
26b0e411 JB |
210 | static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = { |
211 | &hwsim_world_regdom_custom_01, | |
212 | &hwsim_world_regdom_custom_02, | |
64e59429 | 213 | &hwsim_world_regdom_custom_03, |
99b6877d | 214 | &hwsim_world_regdom_custom_04, |
26b0e411 JB |
215 | }; |
216 | ||
8aa21e6f JB |
217 | struct hwsim_vif_priv { |
218 | u32 magic; | |
7d366663 | 219 | u32 skip_beacons; |
fc6971d4 JM |
220 | u8 bssid[ETH_ALEN]; |
221 | bool assoc; | |
0bb861e6 | 222 | bool bcn_en; |
fc6971d4 | 223 | u16 aid; |
8aa21e6f JB |
224 | }; |
225 | ||
226 | #define HWSIM_VIF_MAGIC 0x69537748 | |
227 | ||
228 | static inline void hwsim_check_magic(struct ieee80211_vif *vif) | |
229 | { | |
230 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
e8261171 JB |
231 | WARN(vp->magic != HWSIM_VIF_MAGIC, |
232 | "Invalid VIF (%p) magic %#x, %pM, %d/%d\n", | |
233 | vif, vp->magic, vif->addr, vif->type, vif->p2p); | |
8aa21e6f JB |
234 | } |
235 | ||
236 | static inline void hwsim_set_magic(struct ieee80211_vif *vif) | |
237 | { | |
238 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
239 | vp->magic = HWSIM_VIF_MAGIC; | |
240 | } | |
241 | ||
242 | static inline void hwsim_clear_magic(struct ieee80211_vif *vif) | |
243 | { | |
244 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
245 | vp->magic = 0; | |
246 | } | |
acc1e7a3 | 247 | |
81c06523 JB |
248 | struct hwsim_sta_priv { |
249 | u32 magic; | |
af4f2aa3 | 250 | unsigned int last_link; |
e229f978 | 251 | u16 active_links_rx; |
81c06523 JB |
252 | }; |
253 | ||
e8261171 | 254 | #define HWSIM_STA_MAGIC 0x6d537749 |
81c06523 JB |
255 | |
256 | static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta) | |
257 | { | |
258 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
5d6924ea | 259 | WARN_ON(sp->magic != HWSIM_STA_MAGIC); |
81c06523 JB |
260 | } |
261 | ||
262 | static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta) | |
263 | { | |
264 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
5d6924ea | 265 | sp->magic = HWSIM_STA_MAGIC; |
81c06523 JB |
266 | } |
267 | ||
268 | static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta) | |
269 | { | |
270 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
271 | sp->magic = 0; | |
272 | } | |
273 | ||
e8261171 JB |
274 | struct hwsim_chanctx_priv { |
275 | u32 magic; | |
276 | }; | |
277 | ||
278 | #define HWSIM_CHANCTX_MAGIC 0x6d53774a | |
279 | ||
280 | static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
281 | { | |
282 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
283 | WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC); | |
284 | } | |
285 | ||
286 | static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
287 | { | |
288 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
289 | cp->magic = HWSIM_CHANCTX_MAGIC; | |
290 | } | |
291 | ||
292 | static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
293 | { | |
294 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
295 | cp->magic = 0; | |
296 | } | |
297 | ||
c7d03a00 | 298 | static unsigned int hwsim_net_id; |
100cb9ff | 299 | |
60a05271 | 300 | static DEFINE_IDA(hwsim_netgroup_ida); |
100cb9ff MW |
301 | |
302 | struct hwsim_net { | |
303 | int netgroup; | |
f21e4d8e | 304 | u32 wmediumd; |
100cb9ff MW |
305 | }; |
306 | ||
307 | static inline int hwsim_net_get_netgroup(struct net *net) | |
308 | { | |
309 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); | |
310 | ||
311 | return hwsim_net->netgroup; | |
312 | } | |
313 | ||
03695549 | 314 | static inline int hwsim_net_set_netgroup(struct net *net) |
100cb9ff MW |
315 | { |
316 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); | |
317 | ||
1449c24e | 318 | hwsim_net->netgroup = ida_alloc(&hwsim_netgroup_ida, GFP_KERNEL); |
03695549 | 319 | return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM; |
100cb9ff MW |
320 | } |
321 | ||
f21e4d8e MW |
322 | static inline u32 hwsim_net_get_wmediumd(struct net *net) |
323 | { | |
324 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); | |
325 | ||
326 | return hwsim_net->wmediumd; | |
327 | } | |
328 | ||
329 | static inline void hwsim_net_set_wmediumd(struct net *net, u32 portid) | |
330 | { | |
331 | struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id); | |
332 | ||
333 | hwsim_net->wmediumd = portid; | |
334 | } | |
335 | ||
acc1e7a3 JM |
336 | static struct class *hwsim_class; |
337 | ||
acc1e7a3 JM |
338 | static struct net_device *hwsim_mon; /* global monitor netdev */ |
339 | ||
22cad735 | 340 | #define CHAN2G(_freq) { \ |
57fbcce3 | 341 | .band = NL80211_BAND_2GHZ, \ |
22cad735 LR |
342 | .center_freq = (_freq), \ |
343 | .hw_value = (_freq), \ | |
22cad735 LR |
344 | } |
345 | ||
346 | #define CHAN5G(_freq) { \ | |
57fbcce3 | 347 | .band = NL80211_BAND_5GHZ, \ |
22cad735 LR |
348 | .center_freq = (_freq), \ |
349 | .hw_value = (_freq), \ | |
22cad735 LR |
350 | } |
351 | ||
28881922 RF |
352 | #define CHAN6G(_freq) { \ |
353 | .band = NL80211_BAND_6GHZ, \ | |
354 | .center_freq = (_freq), \ | |
355 | .hw_value = (_freq), \ | |
356 | } | |
357 | ||
22cad735 LR |
358 | static const struct ieee80211_channel hwsim_channels_2ghz[] = { |
359 | CHAN2G(2412), /* Channel 1 */ | |
360 | CHAN2G(2417), /* Channel 2 */ | |
361 | CHAN2G(2422), /* Channel 3 */ | |
362 | CHAN2G(2427), /* Channel 4 */ | |
363 | CHAN2G(2432), /* Channel 5 */ | |
364 | CHAN2G(2437), /* Channel 6 */ | |
365 | CHAN2G(2442), /* Channel 7 */ | |
366 | CHAN2G(2447), /* Channel 8 */ | |
367 | CHAN2G(2452), /* Channel 9 */ | |
368 | CHAN2G(2457), /* Channel 10 */ | |
369 | CHAN2G(2462), /* Channel 11 */ | |
370 | CHAN2G(2467), /* Channel 12 */ | |
371 | CHAN2G(2472), /* Channel 13 */ | |
372 | CHAN2G(2484), /* Channel 14 */ | |
373 | }; | |
acc1e7a3 | 374 | |
22cad735 LR |
375 | static const struct ieee80211_channel hwsim_channels_5ghz[] = { |
376 | CHAN5G(5180), /* Channel 36 */ | |
377 | CHAN5G(5200), /* Channel 40 */ | |
378 | CHAN5G(5220), /* Channel 44 */ | |
379 | CHAN5G(5240), /* Channel 48 */ | |
380 | ||
381 | CHAN5G(5260), /* Channel 52 */ | |
382 | CHAN5G(5280), /* Channel 56 */ | |
383 | CHAN5G(5300), /* Channel 60 */ | |
384 | CHAN5G(5320), /* Channel 64 */ | |
385 | ||
386 | CHAN5G(5500), /* Channel 100 */ | |
387 | CHAN5G(5520), /* Channel 104 */ | |
388 | CHAN5G(5540), /* Channel 108 */ | |
389 | CHAN5G(5560), /* Channel 112 */ | |
390 | CHAN5G(5580), /* Channel 116 */ | |
391 | CHAN5G(5600), /* Channel 120 */ | |
392 | CHAN5G(5620), /* Channel 124 */ | |
393 | CHAN5G(5640), /* Channel 128 */ | |
394 | CHAN5G(5660), /* Channel 132 */ | |
395 | CHAN5G(5680), /* Channel 136 */ | |
396 | CHAN5G(5700), /* Channel 140 */ | |
397 | ||
398 | CHAN5G(5745), /* Channel 149 */ | |
399 | CHAN5G(5765), /* Channel 153 */ | |
400 | CHAN5G(5785), /* Channel 157 */ | |
401 | CHAN5G(5805), /* Channel 161 */ | |
402 | CHAN5G(5825), /* Channel 165 */ | |
85bbd803 | 403 | CHAN5G(5845), /* Channel 169 */ |
b5764696 RF |
404 | |
405 | CHAN5G(5855), /* Channel 171 */ | |
406 | CHAN5G(5860), /* Channel 172 */ | |
407 | CHAN5G(5865), /* Channel 173 */ | |
408 | CHAN5G(5870), /* Channel 174 */ | |
409 | ||
410 | CHAN5G(5875), /* Channel 175 */ | |
411 | CHAN5G(5880), /* Channel 176 */ | |
412 | CHAN5G(5885), /* Channel 177 */ | |
413 | CHAN5G(5890), /* Channel 178 */ | |
414 | CHAN5G(5895), /* Channel 179 */ | |
415 | CHAN5G(5900), /* Channel 180 */ | |
416 | CHAN5G(5905), /* Channel 181 */ | |
417 | ||
418 | CHAN5G(5910), /* Channel 182 */ | |
419 | CHAN5G(5915), /* Channel 183 */ | |
420 | CHAN5G(5920), /* Channel 184 */ | |
421 | CHAN5G(5925), /* Channel 185 */ | |
acc1e7a3 JM |
422 | }; |
423 | ||
28881922 RF |
424 | static const struct ieee80211_channel hwsim_channels_6ghz[] = { |
425 | CHAN6G(5955), /* Channel 1 */ | |
426 | CHAN6G(5975), /* Channel 5 */ | |
427 | CHAN6G(5995), /* Channel 9 */ | |
428 | CHAN6G(6015), /* Channel 13 */ | |
429 | CHAN6G(6035), /* Channel 17 */ | |
430 | CHAN6G(6055), /* Channel 21 */ | |
431 | CHAN6G(6075), /* Channel 25 */ | |
432 | CHAN6G(6095), /* Channel 29 */ | |
433 | CHAN6G(6115), /* Channel 33 */ | |
434 | CHAN6G(6135), /* Channel 37 */ | |
435 | CHAN6G(6155), /* Channel 41 */ | |
436 | CHAN6G(6175), /* Channel 45 */ | |
437 | CHAN6G(6195), /* Channel 49 */ | |
438 | CHAN6G(6215), /* Channel 53 */ | |
439 | CHAN6G(6235), /* Channel 57 */ | |
440 | CHAN6G(6255), /* Channel 61 */ | |
441 | CHAN6G(6275), /* Channel 65 */ | |
442 | CHAN6G(6295), /* Channel 69 */ | |
443 | CHAN6G(6315), /* Channel 73 */ | |
444 | CHAN6G(6335), /* Channel 77 */ | |
445 | CHAN6G(6355), /* Channel 81 */ | |
446 | CHAN6G(6375), /* Channel 85 */ | |
447 | CHAN6G(6395), /* Channel 89 */ | |
448 | CHAN6G(6415), /* Channel 93 */ | |
449 | CHAN6G(6435), /* Channel 97 */ | |
450 | CHAN6G(6455), /* Channel 181 */ | |
451 | CHAN6G(6475), /* Channel 105 */ | |
452 | CHAN6G(6495), /* Channel 109 */ | |
453 | CHAN6G(6515), /* Channel 113 */ | |
454 | CHAN6G(6535), /* Channel 117 */ | |
455 | CHAN6G(6555), /* Channel 121 */ | |
456 | CHAN6G(6575), /* Channel 125 */ | |
457 | CHAN6G(6595), /* Channel 129 */ | |
458 | CHAN6G(6615), /* Channel 133 */ | |
459 | CHAN6G(6635), /* Channel 137 */ | |
460 | CHAN6G(6655), /* Channel 141 */ | |
461 | CHAN6G(6675), /* Channel 145 */ | |
462 | CHAN6G(6695), /* Channel 149 */ | |
463 | CHAN6G(6715), /* Channel 153 */ | |
464 | CHAN6G(6735), /* Channel 157 */ | |
465 | CHAN6G(6755), /* Channel 161 */ | |
466 | CHAN6G(6775), /* Channel 165 */ | |
467 | CHAN6G(6795), /* Channel 169 */ | |
468 | CHAN6G(6815), /* Channel 173 */ | |
469 | CHAN6G(6835), /* Channel 177 */ | |
470 | CHAN6G(6855), /* Channel 181 */ | |
471 | CHAN6G(6875), /* Channel 185 */ | |
472 | CHAN6G(6895), /* Channel 189 */ | |
473 | CHAN6G(6915), /* Channel 193 */ | |
474 | CHAN6G(6935), /* Channel 197 */ | |
475 | CHAN6G(6955), /* Channel 201 */ | |
476 | CHAN6G(6975), /* Channel 205 */ | |
477 | CHAN6G(6995), /* Channel 209 */ | |
478 | CHAN6G(7015), /* Channel 213 */ | |
479 | CHAN6G(7035), /* Channel 217 */ | |
480 | CHAN6G(7055), /* Channel 221 */ | |
481 | CHAN6G(7075), /* Channel 225 */ | |
482 | CHAN6G(7095), /* Channel 229 */ | |
483 | CHAN6G(7115), /* Channel 233 */ | |
484 | }; | |
485 | ||
148fe295 TP |
486 | #define NUM_S1G_CHANS_US 51 |
487 | static struct ieee80211_channel hwsim_channels_s1g[NUM_S1G_CHANS_US]; | |
488 | ||
489 | static const struct ieee80211_sta_s1g_cap hwsim_s1g_cap = { | |
490 | .s1g = true, | |
491 | .cap = { S1G_CAP0_SGI_1MHZ | S1G_CAP0_SGI_2MHZ, | |
492 | 0, | |
493 | 0, | |
494 | S1G_CAP3_MAX_MPDU_LEN, | |
495 | 0, | |
496 | S1G_CAP5_AMPDU, | |
497 | 0, | |
498 | S1G_CAP7_DUP_1MHZ, | |
499 | S1G_CAP8_TWT_RESPOND | S1G_CAP8_TWT_REQUEST, | |
500 | 0}, | |
501 | .nss_mcs = { 0xfc | 1, /* MCS 7 for 1 SS */ | |
502 | /* RX Highest Supported Long GI Data Rate 0:7 */ | |
503 | 0, | |
504 | /* RX Highest Supported Long GI Data Rate 0:7 */ | |
505 | /* TX S1G MCS Map 0:6 */ | |
506 | 0xfa, | |
507 | /* TX S1G MCS Map :7 */ | |
508 | /* TX Highest Supported Long GI Data Rate 0:6 */ | |
509 | 0x80, | |
510 | /* TX Highest Supported Long GI Data Rate 7:8 */ | |
511 | /* Rx Single spatial stream and S1G-MCS Map for 1MHz */ | |
512 | /* Tx Single spatial stream and S1G-MCS Map for 1MHz */ | |
513 | 0 }, | |
514 | }; | |
515 | ||
f68420e4 | 516 | static void hwsim_init_s1g_channels(struct ieee80211_channel *chans) |
148fe295 TP |
517 | { |
518 | int ch, freq; | |
519 | ||
520 | for (ch = 0; ch < NUM_S1G_CHANS_US; ch++) { | |
521 | freq = 902000 + (ch + 1) * 500; | |
f68420e4 JB |
522 | chans[ch].band = NL80211_BAND_S1GHZ; |
523 | chans[ch].center_freq = KHZ_TO_MHZ(freq); | |
524 | chans[ch].freq_offset = freq % 1000; | |
525 | chans[ch].hw_value = ch + 1; | |
148fe295 TP |
526 | } |
527 | } | |
528 | ||
acc1e7a3 JM |
529 | static const struct ieee80211_rate hwsim_rates[] = { |
530 | { .bitrate = 10 }, | |
531 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
532 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
533 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
534 | { .bitrate = 60 }, | |
535 | { .bitrate = 90 }, | |
536 | { .bitrate = 120 }, | |
537 | { .bitrate = 180 }, | |
538 | { .bitrate = 240 }, | |
539 | { .bitrate = 360 }, | |
540 | { .bitrate = 480 }, | |
541 | { .bitrate = 540 } | |
542 | }; | |
543 | ||
b59fb546 BL |
544 | #define DEFAULT_RX_RSSI -50 |
545 | ||
c0a0189d JP |
546 | static const u32 hwsim_ciphers[] = { |
547 | WLAN_CIPHER_SUITE_WEP40, | |
548 | WLAN_CIPHER_SUITE_WEP104, | |
549 | WLAN_CIPHER_SUITE_TKIP, | |
550 | WLAN_CIPHER_SUITE_CCMP, | |
551 | WLAN_CIPHER_SUITE_CCMP_256, | |
552 | WLAN_CIPHER_SUITE_GCMP, | |
553 | WLAN_CIPHER_SUITE_GCMP_256, | |
554 | WLAN_CIPHER_SUITE_AES_CMAC, | |
555 | WLAN_CIPHER_SUITE_BIP_CMAC_256, | |
556 | WLAN_CIPHER_SUITE_BIP_GMAC_128, | |
557 | WLAN_CIPHER_SUITE_BIP_GMAC_256, | |
558 | }; | |
559 | ||
d5d011b4 JM |
560 | #define OUI_QCA 0x001374 |
561 | #define QCA_NL80211_SUBCMD_TEST 1 | |
562 | enum qca_nl80211_vendor_subcmds { | |
563 | QCA_WLAN_VENDOR_ATTR_TEST = 8, | |
564 | QCA_WLAN_VENDOR_ATTR_MAX = QCA_WLAN_VENDOR_ATTR_TEST | |
565 | }; | |
566 | ||
567 | static const struct nla_policy | |
568 | hwsim_vendor_test_policy[QCA_WLAN_VENDOR_ATTR_MAX + 1] = { | |
569 | [QCA_WLAN_VENDOR_ATTR_MAX] = { .type = NLA_U32 }, | |
570 | }; | |
571 | ||
572 | static int mac80211_hwsim_vendor_cmd_test(struct wiphy *wiphy, | |
573 | struct wireless_dev *wdev, | |
574 | const void *data, int data_len) | |
575 | { | |
576 | struct sk_buff *skb; | |
577 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
578 | int err; | |
579 | u32 val; | |
580 | ||
8cb08174 JB |
581 | err = nla_parse_deprecated(tb, QCA_WLAN_VENDOR_ATTR_MAX, data, |
582 | data_len, hwsim_vendor_test_policy, NULL); | |
d5d011b4 JM |
583 | if (err) |
584 | return err; | |
585 | if (!tb[QCA_WLAN_VENDOR_ATTR_TEST]) | |
586 | return -EINVAL; | |
587 | val = nla_get_u32(tb[QCA_WLAN_VENDOR_ATTR_TEST]); | |
62b093b3 | 588 | wiphy_dbg(wiphy, "%s: test=%u\n", __func__, val); |
d5d011b4 JM |
589 | |
590 | /* Send a vendor event as a test. Note that this would not normally be | |
591 | * done within a command handler, but rather, based on some other | |
592 | * trigger. For simplicity, this command is used to trigger the event | |
593 | * here. | |
594 | * | |
595 | * event_idx = 0 (index in mac80211_hwsim_vendor_commands) | |
596 | */ | |
597 | skb = cfg80211_vendor_event_alloc(wiphy, wdev, 100, 0, GFP_KERNEL); | |
598 | if (skb) { | |
599 | /* skb_put() or nla_put() will fill up data within | |
600 | * NL80211_ATTR_VENDOR_DATA. | |
601 | */ | |
602 | ||
603 | /* Add vendor data */ | |
1b78dd34 JB |
604 | nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 1); |
605 | ||
d5d011b4 JM |
606 | /* Send the event - this will call nla_nest_end() */ |
607 | cfg80211_vendor_event(skb, GFP_KERNEL); | |
608 | } | |
609 | ||
610 | /* Send a response to the command */ | |
611 | skb = cfg80211_vendor_cmd_alloc_reply_skb(wiphy, 10); | |
612 | if (!skb) | |
613 | return -ENOMEM; | |
614 | ||
615 | /* skb_put() or nla_put() will fill up data within | |
616 | * NL80211_ATTR_VENDOR_DATA | |
617 | */ | |
618 | nla_put_u32(skb, QCA_WLAN_VENDOR_ATTR_TEST, val + 2); | |
619 | ||
620 | return cfg80211_vendor_cmd_reply(skb); | |
621 | } | |
622 | ||
623 | static struct wiphy_vendor_command mac80211_hwsim_vendor_commands[] = { | |
624 | { | |
625 | .info = { .vendor_id = OUI_QCA, | |
626 | .subcmd = QCA_NL80211_SUBCMD_TEST }, | |
627 | .flags = WIPHY_VENDOR_CMD_NEED_NETDEV, | |
628 | .doit = mac80211_hwsim_vendor_cmd_test, | |
901bb989 JB |
629 | .policy = hwsim_vendor_test_policy, |
630 | .maxattr = QCA_WLAN_VENDOR_ATTR_MAX, | |
d5d011b4 JM |
631 | } |
632 | }; | |
633 | ||
634 | /* Advertise support vendor specific events */ | |
635 | static const struct nl80211_vendor_cmd_info mac80211_hwsim_vendor_events[] = { | |
636 | { .vendor_id = OUI_QCA, .subcmd = 1 }, | |
637 | }; | |
638 | ||
30a70d18 | 639 | static DEFINE_SPINLOCK(hwsim_radio_lock); |
b59abfbe | 640 | static LIST_HEAD(hwsim_radios); |
c6509cc3 | 641 | static struct rhashtable hwsim_radios_rht; |
2d68992b | 642 | static int hwsim_radio_idx; |
6335698e | 643 | static int hwsim_radios_generation = 1; |
0e057d73 | 644 | |
de0421d5 JB |
645 | static struct platform_driver mac80211_hwsim_driver = { |
646 | .driver = { | |
647 | .name = "mac80211_hwsim", | |
de0421d5 JB |
648 | }, |
649 | }; | |
0e057d73 | 650 | |
e57f8a48 ST |
651 | struct mac80211_hwsim_link_data { |
652 | u32 link_id; | |
653 | u64 beacon_int /* beacon interval in us */; | |
654 | struct hrtimer beacon_timer; | |
655 | }; | |
656 | ||
acc1e7a3 | 657 | struct mac80211_hwsim_data { |
0e057d73 | 658 | struct list_head list; |
c6509cc3 | 659 | struct rhash_head rht; |
0e057d73 | 660 | struct ieee80211_hw *hw; |
acc1e7a3 | 661 | struct device *dev; |
57fbcce3 | 662 | struct ieee80211_supported_band bands[NUM_NL80211_BANDS]; |
22cad735 LR |
663 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)]; |
664 | struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)]; | |
28881922 | 665 | struct ieee80211_channel channels_6ghz[ARRAY_SIZE(hwsim_channels_6ghz)]; |
148fe295 | 666 | struct ieee80211_channel channels_s1g[ARRAY_SIZE(hwsim_channels_s1g)]; |
acc1e7a3 | 667 | struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; |
38ed5048 | 668 | struct ieee80211_iface_combination if_combination; |
99e3a44b JP |
669 | struct ieee80211_iface_limit if_limits[3]; |
670 | int n_if_limits; | |
acc1e7a3 | 671 | |
c0a0189d | 672 | u32 ciphers[ARRAY_SIZE(hwsim_ciphers)]; |
acc1e7a3 | 673 | |
ef15aac6 | 674 | struct mac_address addresses[2]; |
bc791098 | 675 | int channels, idx; |
361c3e04 | 676 | bool use_chanctx; |
e9ed49bf | 677 | bool destroy_on_close; |
e9ed49bf | 678 | u32 portid; |
93d638d4 PF |
679 | char alpha2[2]; |
680 | const struct ieee80211_regdomain *regd; | |
ef15aac6 | 681 | |
e8261171 | 682 | struct ieee80211_channel *tmp_chan; |
661ef475 JB |
683 | struct ieee80211_channel *roc_chan; |
684 | u32 roc_duration; | |
685 | struct delayed_work roc_start; | |
e8261171 JB |
686 | struct delayed_work roc_done; |
687 | struct delayed_work hw_scan; | |
688 | struct cfg80211_scan_request *hw_scan_request; | |
689 | struct ieee80211_vif *hw_scan_vif; | |
690 | int scan_chan_idx; | |
339467b9 | 691 | u8 scan_addr[ETH_ALEN]; |
7f813ce1 JB |
692 | struct { |
693 | struct ieee80211_channel *channel; | |
694 | unsigned long next_start, start, end; | |
695 | } survey_data[ARRAY_SIZE(hwsim_channels_2ghz) + | |
28881922 RF |
696 | ARRAY_SIZE(hwsim_channels_5ghz) + |
697 | ARRAY_SIZE(hwsim_channels_6ghz)]; | |
e8261171 | 698 | |
acc1e7a3 | 699 | struct ieee80211_channel *channel; |
585625c9 | 700 | enum nl80211_chan_width bw; |
acc1e7a3 | 701 | unsigned int rx_filter; |
f74cb0f7 LR |
702 | bool started, idle, scanning; |
703 | struct mutex mutex; | |
fc6971d4 JM |
704 | enum ps_mode { |
705 | PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL | |
706 | } ps; | |
707 | bool ps_poll_pending; | |
708 | struct dentry *debugfs; | |
73606d00 | 709 | |
cc5250cd | 710 | atomic_t pending_cookie; |
7882513b | 711 | struct sk_buff_head pending; /* packets pending */ |
73606d00 DW |
712 | /* |
713 | * Only radios in the same group can communicate together (the | |
714 | * channel has to match too). Each bit represents a group. A | |
9ebac15f | 715 | * radio can be in more than one group. |
73606d00 DW |
716 | */ |
717 | u64 group; | |
bdd7bd16 | 718 | |
100cb9ff MW |
719 | /* group shared by radios created in the same netns */ |
720 | int netgroup; | |
f21e4d8e MW |
721 | /* wmediumd portid responsible for netgroup of this radio */ |
722 | u32 wmediumd; | |
100cb9ff | 723 | |
2f40b940 | 724 | /* difference between this hw's clock and the real clock, in usecs */ |
45034bfb | 725 | s64 tsf_offset; |
c51f8783 | 726 | s64 bcn_delta; |
b66851c3 TP |
727 | /* absolute beacon transmission time. Used to cover up "tx" delay. */ |
728 | u64 abs_bcn_ts; | |
2155c3f8 BG |
729 | |
730 | /* Stats */ | |
731 | u64 tx_pkts; | |
732 | u64 rx_pkts; | |
733 | u64 tx_bytes; | |
734 | u64 rx_bytes; | |
735 | u64 tx_dropped; | |
736 | u64 tx_failed; | |
b59fb546 BL |
737 | |
738 | /* RSSI in rx status of the receiver */ | |
739 | int rx_rssi; | |
e57f8a48 | 740 | |
92d13386 JK |
741 | /* only used when pmsr capability is supplied */ |
742 | struct cfg80211_pmsr_capabilities pmsr_capa; | |
5530c04c JK |
743 | struct cfg80211_pmsr_request *pmsr_request; |
744 | struct wireless_dev *pmsr_request_wdev; | |
92d13386 | 745 | |
e57f8a48 | 746 | struct mac80211_hwsim_link_data link_data[IEEE80211_MLD_MAX_NUM_LINKS]; |
acc1e7a3 JM |
747 | }; |
748 | ||
c6509cc3 BB |
749 | static const struct rhashtable_params hwsim_rht_params = { |
750 | .nelem_hint = 2, | |
751 | .automatic_shrinking = true, | |
752 | .key_len = ETH_ALEN, | |
753 | .key_offset = offsetof(struct mac80211_hwsim_data, addresses[1]), | |
754 | .head_offset = offsetof(struct mac80211_hwsim_data, rht), | |
755 | }; | |
acc1e7a3 JM |
756 | |
757 | struct hwsim_radiotap_hdr { | |
758 | struct ieee80211_radiotap_header hdr; | |
2f40b940 | 759 | __le64 rt_tsft; |
acc1e7a3 JM |
760 | u8 rt_flags; |
761 | u8 rt_rate; | |
762 | __le16 rt_channel; | |
763 | __le16 rt_chbitmask; | |
ba2d3587 | 764 | } __packed; |
acc1e7a3 | 765 | |
76a56eb3 JM |
766 | struct hwsim_radiotap_ack_hdr { |
767 | struct ieee80211_radiotap_header hdr; | |
768 | u8 rt_flags; | |
769 | u8 pad; | |
770 | __le16 rt_channel; | |
771 | __le16 rt_chbitmask; | |
772 | } __packed; | |
773 | ||
2af3b2a6 JK |
774 | static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr) |
775 | { | |
776 | return rhashtable_lookup_fast(&hwsim_radios_rht, addr, hwsim_rht_params); | |
777 | } | |
778 | ||
489111e5 JB |
779 | /* MAC80211_HWSIM netlink family */ |
780 | static struct genl_family hwsim_genl_family; | |
7882513b | 781 | |
62759361 JR |
782 | enum hwsim_multicast_groups { |
783 | HWSIM_MCGRP_CONFIG, | |
784 | }; | |
785 | ||
786 | static const struct genl_multicast_group hwsim_mcgrps[] = { | |
787 | [HWSIM_MCGRP_CONFIG] = { .name = "config", }, | |
788 | }; | |
789 | ||
7882513b JL |
790 | /* MAC80211_HWSIM netlink policy */ |
791 | ||
2af3b2a6 JK |
792 | static const struct nla_policy |
793 | hwsim_rate_info_policy[HWSIM_RATE_INFO_ATTR_MAX + 1] = { | |
794 | [HWSIM_RATE_INFO_ATTR_FLAGS] = { .type = NLA_U8 }, | |
795 | [HWSIM_RATE_INFO_ATTR_MCS] = { .type = NLA_U8 }, | |
796 | [HWSIM_RATE_INFO_ATTR_LEGACY] = { .type = NLA_U16 }, | |
797 | [HWSIM_RATE_INFO_ATTR_NSS] = { .type = NLA_U8 }, | |
798 | [HWSIM_RATE_INFO_ATTR_BW] = { .type = NLA_U8 }, | |
799 | [HWSIM_RATE_INFO_ATTR_HE_GI] = { .type = NLA_U8 }, | |
800 | [HWSIM_RATE_INFO_ATTR_HE_DCM] = { .type = NLA_U8 }, | |
801 | [HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC] = { .type = NLA_U8 }, | |
802 | [HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH] = { .type = NLA_U8 }, | |
803 | [HWSIM_RATE_INFO_ATTR_EHT_GI] = { .type = NLA_U8 }, | |
804 | [HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC] = { .type = NLA_U8 }, | |
805 | }; | |
806 | ||
807 | static const struct nla_policy | |
808 | hwsim_ftm_result_policy[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1] = { | |
809 | [NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON] = { .type = NLA_U32 }, | |
810 | [NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX] = { .type = NLA_U16 }, | |
811 | [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS] = { .type = NLA_U32 }, | |
812 | [NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES] = { .type = NLA_U32 }, | |
813 | [NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME] = { .type = NLA_U8 }, | |
814 | [NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP] = { .type = NLA_U8 }, | |
815 | [NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION] = { .type = NLA_U8 }, | |
816 | [NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST] = { .type = NLA_U8 }, | |
817 | [NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG] = { .type = NLA_U32 }, | |
818 | [NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD] = { .type = NLA_U32 }, | |
819 | [NL80211_PMSR_FTM_RESP_ATTR_TX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy), | |
820 | [NL80211_PMSR_FTM_RESP_ATTR_RX_RATE] = NLA_POLICY_NESTED(hwsim_rate_info_policy), | |
821 | [NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG] = { .type = NLA_U64 }, | |
822 | [NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE] = { .type = NLA_U64 }, | |
823 | [NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD] = { .type = NLA_U64 }, | |
824 | [NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG] = { .type = NLA_U64 }, | |
825 | [NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE] = { .type = NLA_U64 }, | |
826 | [NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD] = { .type = NLA_U64 }, | |
827 | [NL80211_PMSR_FTM_RESP_ATTR_LCI] = { .type = NLA_STRING }, | |
828 | [NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_STRING }, | |
829 | }; | |
830 | ||
831 | static const struct nla_policy | |
832 | hwsim_pmsr_resp_type_policy[NL80211_PMSR_TYPE_MAX + 1] = { | |
833 | [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_result_policy), | |
834 | }; | |
835 | ||
836 | static const struct nla_policy | |
837 | hwsim_pmsr_resp_policy[NL80211_PMSR_RESP_ATTR_MAX + 1] = { | |
838 | [NL80211_PMSR_RESP_ATTR_STATUS] = { .type = NLA_U32 }, | |
839 | [NL80211_PMSR_RESP_ATTR_HOST_TIME] = { .type = NLA_U64 }, | |
840 | [NL80211_PMSR_RESP_ATTR_AP_TSF] = { .type = NLA_U64 }, | |
841 | [NL80211_PMSR_RESP_ATTR_FINAL] = { .type = NLA_FLAG }, | |
842 | [NL80211_PMSR_RESP_ATTR_DATA] = NLA_POLICY_NESTED(hwsim_pmsr_resp_type_policy), | |
843 | }; | |
844 | ||
845 | static const struct nla_policy | |
846 | hwsim_pmsr_peer_result_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { | |
847 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT, | |
848 | [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_REJECT }, | |
849 | [NL80211_PMSR_PEER_ATTR_REQ] = { .type = NLA_REJECT }, | |
850 | [NL80211_PMSR_PEER_ATTR_RESP] = NLA_POLICY_NESTED(hwsim_pmsr_resp_policy), | |
851 | }; | |
852 | ||
853 | static const struct nla_policy | |
854 | hwsim_pmsr_peers_result_policy[NL80211_PMSR_ATTR_MAX + 1] = { | |
855 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, | |
856 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, | |
857 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, | |
858 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, | |
859 | [NL80211_PMSR_ATTR_PEERS] = NLA_POLICY_NESTED_ARRAY(hwsim_pmsr_peer_result_policy), | |
860 | }; | |
861 | ||
92d13386 JK |
862 | static const struct nla_policy |
863 | hwsim_ftm_capa_policy[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1] = { | |
864 | [NL80211_PMSR_FTM_CAPA_ATTR_ASAP] = { .type = NLA_FLAG }, | |
865 | [NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP] = { .type = NLA_FLAG }, | |
866 | [NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI] = { .type = NLA_FLAG }, | |
867 | [NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC] = { .type = NLA_FLAG }, | |
868 | [NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES] = { .type = NLA_U32 }, | |
869 | [NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS] = { .type = NLA_U32 }, | |
870 | [NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT] = NLA_POLICY_MAX(NLA_U8, 15), | |
871 | [NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST] = NLA_POLICY_MAX(NLA_U8, 31), | |
872 | [NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, | |
873 | [NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, | |
874 | }; | |
875 | ||
876 | static const struct nla_policy | |
877 | hwsim_pmsr_capa_type_policy[NL80211_PMSR_TYPE_MAX + 1] = { | |
878 | [NL80211_PMSR_TYPE_FTM] = NLA_POLICY_NESTED(hwsim_ftm_capa_policy), | |
879 | }; | |
880 | ||
881 | static const struct nla_policy | |
882 | hwsim_pmsr_capa_policy[NL80211_PMSR_ATTR_MAX + 1] = { | |
883 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_U32 }, | |
884 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_FLAG }, | |
885 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_FLAG }, | |
886 | [NL80211_PMSR_ATTR_TYPE_CAPA] = NLA_POLICY_NESTED(hwsim_pmsr_capa_type_policy), | |
887 | [NL80211_PMSR_ATTR_PEERS] = { .type = NLA_REJECT }, // only for request. | |
888 | }; | |
889 | ||
205d2429 | 890 | static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { |
5d44fe7c EG |
891 | [HWSIM_ATTR_ADDR_RECEIVER] = NLA_POLICY_ETH_ADDR_COMPAT, |
892 | [HWSIM_ATTR_ADDR_TRANSMITTER] = NLA_POLICY_ETH_ADDR_COMPAT, | |
7882513b JL |
893 | [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, |
894 | .len = IEEE80211_MAX_DATA_LEN }, | |
895 | [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, | |
896 | [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, | |
897 | [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, | |
5d44fe7c | 898 | [HWSIM_ATTR_TX_INFO] = { .type = NLA_BINARY, |
9ddd12af JB |
899 | .len = IEEE80211_TX_MAX_RATES * |
900 | sizeof(struct hwsim_tx_rate)}, | |
7882513b | 901 | [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, |
bc791098 JB |
902 | [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 }, |
903 | [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 }, | |
26b0e411 JB |
904 | [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
905 | [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 }, | |
906 | [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG }, | |
8c66a3d9 | 907 | [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG }, |
5d44fe7c | 908 | [HWSIM_ATTR_USE_CHANCTX] = { .type = NLA_FLAG }, |
e9ed49bf | 909 | [HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE] = { .type = NLA_FLAG }, |
de29eda8 JB |
910 | [HWSIM_ATTR_RADIO_NAME] = { .type = NLA_STRING }, |
911 | [HWSIM_ATTR_NO_VIF] = { .type = NLA_FLAG }, | |
912 | [HWSIM_ATTR_FREQ] = { .type = NLA_U32 }, | |
5d44fe7c EG |
913 | [HWSIM_ATTR_TX_INFO_FLAGS] = { .type = NLA_BINARY }, |
914 | [HWSIM_ATTR_PERM_ADDR] = NLA_POLICY_ETH_ADDR_COMPAT, | |
99e3a44b | 915 | [HWSIM_ATTR_IFTYPE_SUPPORT] = { .type = NLA_U32 }, |
c0a0189d | 916 | [HWSIM_ATTR_CIPHER_SUPPORT] = { .type = NLA_BINARY }, |
2fd0c671 | 917 | [HWSIM_ATTR_MLO_SUPPORT] = { .type = NLA_FLAG }, |
92d13386 | 918 | [HWSIM_ATTR_PMSR_SUPPORT] = NLA_POLICY_NESTED(hwsim_pmsr_capa_policy), |
2af3b2a6 | 919 | [HWSIM_ATTR_PMSR_RESULT] = NLA_POLICY_NESTED(hwsim_pmsr_peers_result_policy), |
7882513b | 920 | }; |
acc1e7a3 | 921 | |
5d44fe7c EG |
922 | #if IS_REACHABLE(CONFIG_VIRTIO) |
923 | ||
924 | /* MAC80211_HWSIM virtio queues */ | |
925 | static struct virtqueue *hwsim_vqs[HWSIM_NUM_VQS]; | |
926 | static bool hwsim_virtio_enabled; | |
30a70d18 | 927 | static DEFINE_SPINLOCK(hwsim_virtio_lock); |
5d44fe7c EG |
928 | |
929 | static void hwsim_virtio_rx_work(struct work_struct *work); | |
930 | static DECLARE_WORK(hwsim_virtio_rx, hwsim_virtio_rx_work); | |
931 | ||
932 | static int hwsim_tx_virtio(struct mac80211_hwsim_data *data, | |
933 | struct sk_buff *skb) | |
934 | { | |
935 | struct scatterlist sg[1]; | |
936 | unsigned long flags; | |
937 | int err; | |
938 | ||
939 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
940 | if (!hwsim_virtio_enabled) { | |
941 | err = -ENODEV; | |
942 | goto out_free; | |
943 | } | |
944 | ||
945 | sg_init_one(sg, skb->head, skb_end_offset(skb)); | |
946 | err = virtqueue_add_outbuf(hwsim_vqs[HWSIM_VQ_TX], sg, 1, skb, | |
947 | GFP_ATOMIC); | |
948 | if (err) | |
949 | goto out_free; | |
950 | virtqueue_kick(hwsim_vqs[HWSIM_VQ_TX]); | |
951 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
952 | return 0; | |
953 | ||
954 | out_free: | |
955 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
956 | nlmsg_free(skb); | |
957 | return err; | |
958 | } | |
959 | #else | |
960 | /* cause a linker error if this ends up being needed */ | |
961 | extern int hwsim_tx_virtio(struct mac80211_hwsim_data *data, | |
962 | struct sk_buff *skb); | |
963 | #define hwsim_virtio_enabled false | |
964 | #endif | |
965 | ||
585625c9 JB |
966 | static int hwsim_get_chanwidth(enum nl80211_chan_width bw) |
967 | { | |
968 | switch (bw) { | |
969 | case NL80211_CHAN_WIDTH_20_NOHT: | |
970 | case NL80211_CHAN_WIDTH_20: | |
971 | return 20; | |
972 | case NL80211_CHAN_WIDTH_40: | |
973 | return 40; | |
974 | case NL80211_CHAN_WIDTH_80: | |
975 | return 80; | |
976 | case NL80211_CHAN_WIDTH_80P80: | |
977 | case NL80211_CHAN_WIDTH_160: | |
978 | return 160; | |
3743bec6 JD |
979 | case NL80211_CHAN_WIDTH_320: |
980 | return 320; | |
585625c9 JB |
981 | case NL80211_CHAN_WIDTH_5: |
982 | return 5; | |
983 | case NL80211_CHAN_WIDTH_10: | |
984 | return 10; | |
985 | case NL80211_CHAN_WIDTH_1: | |
986 | return 1; | |
987 | case NL80211_CHAN_WIDTH_2: | |
988 | return 2; | |
989 | case NL80211_CHAN_WIDTH_4: | |
990 | return 4; | |
991 | case NL80211_CHAN_WIDTH_8: | |
992 | return 8; | |
993 | case NL80211_CHAN_WIDTH_16: | |
994 | return 16; | |
995 | } | |
996 | ||
997 | return INT_MAX; | |
998 | } | |
999 | ||
de0421d5 JB |
1000 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
1001 | struct sk_buff *skb, | |
1002 | struct ieee80211_channel *chan); | |
1003 | ||
1004 | /* sysfs attributes */ | |
1005 | static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif) | |
1006 | { | |
1007 | struct mac80211_hwsim_data *data = dat; | |
1008 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
1009 | struct sk_buff *skb; | |
1010 | struct ieee80211_pspoll *pspoll; | |
1011 | ||
1012 | if (!vp->assoc) | |
1013 | return; | |
1014 | ||
62b093b3 LR |
1015 | wiphy_dbg(data->hw->wiphy, |
1016 | "%s: send PS-Poll to %pM for aid %d\n", | |
1017 | __func__, vp->bssid, vp->aid); | |
de0421d5 JB |
1018 | |
1019 | skb = dev_alloc_skb(sizeof(*pspoll)); | |
1020 | if (!skb) | |
1021 | return; | |
4df864c1 | 1022 | pspoll = skb_put(skb, sizeof(*pspoll)); |
de0421d5 JB |
1023 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
1024 | IEEE80211_STYPE_PSPOLL | | |
1025 | IEEE80211_FCTL_PM); | |
1026 | pspoll->aid = cpu_to_le16(0xc000 | vp->aid); | |
1027 | memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); | |
1028 | memcpy(pspoll->ta, mac, ETH_ALEN); | |
1029 | ||
1030 | rcu_read_lock(); | |
1031 | mac80211_hwsim_tx_frame(data->hw, skb, | |
d0a9123e | 1032 | rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan); |
de0421d5 JB |
1033 | rcu_read_unlock(); |
1034 | } | |
1035 | ||
1036 | static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac, | |
1037 | struct ieee80211_vif *vif, int ps) | |
1038 | { | |
1039 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
1040 | struct sk_buff *skb; | |
1041 | struct ieee80211_hdr *hdr; | |
69188df5 | 1042 | struct ieee80211_tx_info *cb; |
de0421d5 JB |
1043 | |
1044 | if (!vp->assoc) | |
1045 | return; | |
1046 | ||
62b093b3 LR |
1047 | wiphy_dbg(data->hw->wiphy, |
1048 | "%s: send data::nullfunc to %pM ps=%d\n", | |
1049 | __func__, vp->bssid, ps); | |
de0421d5 JB |
1050 | |
1051 | skb = dev_alloc_skb(sizeof(*hdr)); | |
1052 | if (!skb) | |
1053 | return; | |
4df864c1 | 1054 | hdr = skb_put(skb, sizeof(*hdr) - ETH_ALEN); |
de0421d5 JB |
1055 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
1056 | IEEE80211_STYPE_NULLFUNC | | |
b65c7b8a | 1057 | IEEE80211_FCTL_TODS | |
de0421d5 JB |
1058 | (ps ? IEEE80211_FCTL_PM : 0)); |
1059 | hdr->duration_id = cpu_to_le16(0); | |
1060 | memcpy(hdr->addr1, vp->bssid, ETH_ALEN); | |
1061 | memcpy(hdr->addr2, mac, ETH_ALEN); | |
1062 | memcpy(hdr->addr3, vp->bssid, ETH_ALEN); | |
1063 | ||
69188df5 JJ |
1064 | cb = IEEE80211_SKB_CB(skb); |
1065 | cb->control.rates[0].count = 1; | |
1066 | cb->control.rates[1].idx = -1; | |
1067 | ||
de0421d5 JB |
1068 | rcu_read_lock(); |
1069 | mac80211_hwsim_tx_frame(data->hw, skb, | |
d0a9123e | 1070 | rcu_dereference(vif->bss_conf.chanctx_conf)->def.chan); |
de0421d5 JB |
1071 | rcu_read_unlock(); |
1072 | } | |
1073 | ||
1074 | ||
1075 | static void hwsim_send_nullfunc_ps(void *dat, u8 *mac, | |
1076 | struct ieee80211_vif *vif) | |
1077 | { | |
1078 | struct mac80211_hwsim_data *data = dat; | |
1079 | hwsim_send_nullfunc(data, mac, vif, 1); | |
1080 | } | |
1081 | ||
1082 | static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac, | |
1083 | struct ieee80211_vif *vif) | |
1084 | { | |
1085 | struct mac80211_hwsim_data *data = dat; | |
1086 | hwsim_send_nullfunc(data, mac, vif, 0); | |
1087 | } | |
1088 | ||
1089 | static int hwsim_fops_ps_read(void *dat, u64 *val) | |
1090 | { | |
1091 | struct mac80211_hwsim_data *data = dat; | |
1092 | *val = data->ps; | |
1093 | return 0; | |
1094 | } | |
1095 | ||
1096 | static int hwsim_fops_ps_write(void *dat, u64 val) | |
1097 | { | |
1098 | struct mac80211_hwsim_data *data = dat; | |
1099 | enum ps_mode old_ps; | |
1100 | ||
1101 | if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL && | |
1102 | val != PS_MANUAL_POLL) | |
1103 | return -EINVAL; | |
1104 | ||
de0421d5 | 1105 | if (val == PS_MANUAL_POLL) { |
e16ea4bb AA |
1106 | if (data->ps != PS_ENABLED) |
1107 | return -EINVAL; | |
1108 | local_bh_disable(); | |
a809ca5e JB |
1109 | ieee80211_iterate_active_interfaces_atomic( |
1110 | data->hw, IEEE80211_IFACE_ITER_NORMAL, | |
1111 | hwsim_send_ps_poll, data); | |
e16ea4bb AA |
1112 | local_bh_enable(); |
1113 | return 0; | |
1114 | } | |
1115 | old_ps = data->ps; | |
1116 | data->ps = val; | |
1117 | ||
1118 | local_bh_disable(); | |
1119 | if (old_ps == PS_DISABLED && val != PS_DISABLED) { | |
a809ca5e JB |
1120 | ieee80211_iterate_active_interfaces_atomic( |
1121 | data->hw, IEEE80211_IFACE_ITER_NORMAL, | |
1122 | hwsim_send_nullfunc_ps, data); | |
de0421d5 | 1123 | } else if (old_ps != PS_DISABLED && val == PS_DISABLED) { |
a809ca5e JB |
1124 | ieee80211_iterate_active_interfaces_atomic( |
1125 | data->hw, IEEE80211_IFACE_ITER_NORMAL, | |
1126 | hwsim_send_nullfunc_no_ps, data); | |
de0421d5 | 1127 | } |
a809ca5e | 1128 | local_bh_enable(); |
de0421d5 JB |
1129 | |
1130 | return 0; | |
1131 | } | |
1132 | ||
7d13cf1e | 1133 | DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, |
1134 | "%llu\n"); | |
de0421d5 JB |
1135 | |
1136 | static int hwsim_write_simulate_radar(void *dat, u64 val) | |
1137 | { | |
1138 | struct mac80211_hwsim_data *data = dat; | |
1139 | ||
1140 | ieee80211_radar_detected(data->hw); | |
1141 | ||
1142 | return 0; | |
1143 | } | |
1144 | ||
7d13cf1e | 1145 | DEFINE_DEBUGFS_ATTRIBUTE(hwsim_simulate_radar, NULL, |
1146 | hwsim_write_simulate_radar, "%llu\n"); | |
de0421d5 JB |
1147 | |
1148 | static int hwsim_fops_group_read(void *dat, u64 *val) | |
1149 | { | |
1150 | struct mac80211_hwsim_data *data = dat; | |
1151 | *val = data->group; | |
1152 | return 0; | |
1153 | } | |
1154 | ||
1155 | static int hwsim_fops_group_write(void *dat, u64 val) | |
1156 | { | |
1157 | struct mac80211_hwsim_data *data = dat; | |
1158 | data->group = val; | |
1159 | return 0; | |
1160 | } | |
1161 | ||
7d13cf1e | 1162 | DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_group, |
1163 | hwsim_fops_group_read, hwsim_fops_group_write, | |
1164 | "%llx\n"); | |
de0421d5 | 1165 | |
b59fb546 BL |
1166 | static int hwsim_fops_rx_rssi_read(void *dat, u64 *val) |
1167 | { | |
1168 | struct mac80211_hwsim_data *data = dat; | |
1169 | *val = data->rx_rssi; | |
1170 | return 0; | |
1171 | } | |
1172 | ||
1173 | static int hwsim_fops_rx_rssi_write(void *dat, u64 val) | |
1174 | { | |
1175 | struct mac80211_hwsim_data *data = dat; | |
1176 | int rssi = (int)val; | |
1177 | ||
1178 | if (rssi >= 0 || rssi < -100) | |
1179 | return -EINVAL; | |
1180 | ||
1181 | data->rx_rssi = rssi; | |
1182 | return 0; | |
1183 | } | |
1184 | ||
3856f1b3 YH |
1185 | DEFINE_DEBUGFS_ATTRIBUTE(hwsim_fops_rx_rssi, |
1186 | hwsim_fops_rx_rssi_read, hwsim_fops_rx_rssi_write, | |
1187 | "%lld\n"); | |
b59fb546 | 1188 | |
d0cf9c0d SH |
1189 | static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, |
1190 | struct net_device *dev) | |
acc1e7a3 JM |
1191 | { |
1192 | /* TODO: allow packet injection */ | |
1193 | dev_kfree_skb(skb); | |
6ed10654 | 1194 | return NETDEV_TX_OK; |
acc1e7a3 JM |
1195 | } |
1196 | ||
b66851c3 TP |
1197 | static inline u64 mac80211_hwsim_get_tsf_raw(void) |
1198 | { | |
1199 | return ktime_to_us(ktime_get_real()); | |
1200 | } | |
1201 | ||
2f40b940 JC |
1202 | static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data) |
1203 | { | |
b66851c3 | 1204 | u64 now = mac80211_hwsim_get_tsf_raw(); |
2f40b940 JC |
1205 | return cpu_to_le64(now + data->tsf_offset); |
1206 | } | |
acc1e7a3 | 1207 | |
12ce8ba3 | 1208 | static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw, |
b66851c3 | 1209 | struct ieee80211_vif *vif) |
12ce8ba3 JC |
1210 | { |
1211 | struct mac80211_hwsim_data *data = hw->priv; | |
1212 | return le64_to_cpu(__mac80211_hwsim_get_tsf(data)); | |
1213 | } | |
1214 | ||
1215 | static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, | |
1216 | struct ieee80211_vif *vif, u64 tsf) | |
1217 | { | |
1218 | struct mac80211_hwsim_data *data = hw->priv; | |
45034bfb | 1219 | u64 now = mac80211_hwsim_get_tsf(hw, vif); |
e57f8a48 ST |
1220 | /* MLD not supported here */ |
1221 | u32 bcn_int = data->link_data[0].beacon_int; | |
79211c8e | 1222 | u64 delta = abs(tsf - now); |
45034bfb | 1223 | |
c51f8783 | 1224 | /* adjust after beaconing with new timestamp at old TBTT */ |
5d26b508 AB |
1225 | if (tsf > now) { |
1226 | data->tsf_offset += delta; | |
1227 | data->bcn_delta = do_div(delta, bcn_int); | |
1228 | } else { | |
1229 | data->tsf_offset -= delta; | |
4fb7f8af | 1230 | data->bcn_delta = -(s64)do_div(delta, bcn_int); |
5d26b508 | 1231 | } |
12ce8ba3 JC |
1232 | } |
1233 | ||
acc1e7a3 | 1234 | static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, |
e8261171 JB |
1235 | struct sk_buff *tx_skb, |
1236 | struct ieee80211_channel *chan) | |
acc1e7a3 JM |
1237 | { |
1238 | struct mac80211_hwsim_data *data = hw->priv; | |
1239 | struct sk_buff *skb; | |
1240 | struct hwsim_radiotap_hdr *hdr; | |
148fe295 | 1241 | u16 flags, bitrate; |
acc1e7a3 JM |
1242 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb); |
1243 | struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info); | |
1244 | ||
148fe295 TP |
1245 | if (!txrate) |
1246 | bitrate = 0; | |
1247 | else | |
1248 | bitrate = txrate->bitrate; | |
89f44d8c | 1249 | |
acc1e7a3 JM |
1250 | if (!netif_running(hwsim_mon)) |
1251 | return; | |
1252 | ||
1253 | skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); | |
1254 | if (skb == NULL) | |
1255 | return; | |
1256 | ||
d58ff351 | 1257 | hdr = skb_push(skb, sizeof(*hdr)); |
acc1e7a3 JM |
1258 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
1259 | hdr->hdr.it_pad = 0; | |
1260 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); | |
f248f105 JM |
1261 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
1262 | (1 << IEEE80211_RADIOTAP_RATE) | | |
2f40b940 | 1263 | (1 << IEEE80211_RADIOTAP_TSFT) | |
f248f105 | 1264 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
2f40b940 | 1265 | hdr->rt_tsft = __mac80211_hwsim_get_tsf(data); |
acc1e7a3 | 1266 | hdr->rt_flags = 0; |
148fe295 | 1267 | hdr->rt_rate = bitrate / 5; |
e8261171 | 1268 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
acc1e7a3 | 1269 | flags = IEEE80211_CHAN_2GHZ; |
148fe295 | 1270 | if (txrate && txrate->flags & IEEE80211_RATE_ERP_G) |
acc1e7a3 JM |
1271 | flags |= IEEE80211_CHAN_OFDM; |
1272 | else | |
1273 | flags |= IEEE80211_CHAN_CCK; | |
1274 | hdr->rt_chbitmask = cpu_to_le16(flags); | |
1275 | ||
1276 | skb->dev = hwsim_mon; | |
6b163a85 | 1277 | skb_reset_mac_header(skb); |
acc1e7a3 JM |
1278 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
1279 | skb->pkt_type = PACKET_OTHERHOST; | |
f248f105 | 1280 | skb->protocol = htons(ETH_P_802_2); |
acc1e7a3 JM |
1281 | memset(skb->cb, 0, sizeof(skb->cb)); |
1282 | netif_rx(skb); | |
1283 | } | |
1284 | ||
1285 | ||
e8261171 JB |
1286 | static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan, |
1287 | const u8 *addr) | |
6c085227 | 1288 | { |
6c085227 | 1289 | struct sk_buff *skb; |
76a56eb3 | 1290 | struct hwsim_radiotap_ack_hdr *hdr; |
6c085227 JM |
1291 | u16 flags; |
1292 | struct ieee80211_hdr *hdr11; | |
1293 | ||
1294 | if (!netif_running(hwsim_mon)) | |
1295 | return; | |
1296 | ||
1297 | skb = dev_alloc_skb(100); | |
1298 | if (skb == NULL) | |
1299 | return; | |
1300 | ||
4df864c1 | 1301 | hdr = skb_put(skb, sizeof(*hdr)); |
6c085227 JM |
1302 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
1303 | hdr->hdr.it_pad = 0; | |
1304 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); | |
1305 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | | |
1306 | (1 << IEEE80211_RADIOTAP_CHANNEL)); | |
1307 | hdr->rt_flags = 0; | |
76a56eb3 | 1308 | hdr->pad = 0; |
e8261171 | 1309 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
6c085227 JM |
1310 | flags = IEEE80211_CHAN_2GHZ; |
1311 | hdr->rt_chbitmask = cpu_to_le16(flags); | |
1312 | ||
4df864c1 | 1313 | hdr11 = skb_put(skb, 10); |
6c085227 JM |
1314 | hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
1315 | IEEE80211_STYPE_ACK); | |
1316 | hdr11->duration_id = cpu_to_le16(0); | |
1317 | memcpy(hdr11->addr1, addr, ETH_ALEN); | |
1318 | ||
1319 | skb->dev = hwsim_mon; | |
6b163a85 | 1320 | skb_reset_mac_header(skb); |
6c085227 JM |
1321 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
1322 | skb->pkt_type = PACKET_OTHERHOST; | |
1323 | skb->protocol = htons(ETH_P_802_2); | |
1324 | memset(skb->cb, 0, sizeof(skb->cb)); | |
1325 | netif_rx(skb); | |
1326 | } | |
1327 | ||
3283e286 JB |
1328 | struct mac80211_hwsim_addr_match_data { |
1329 | u8 addr[ETH_ALEN]; | |
1330 | bool ret; | |
1331 | }; | |
1332 | ||
1333 | static void mac80211_hwsim_addr_iter(void *data, u8 *mac, | |
1334 | struct ieee80211_vif *vif) | |
1335 | { | |
b8375cf1 | 1336 | int i; |
3283e286 JB |
1337 | struct mac80211_hwsim_addr_match_data *md = data; |
1338 | ||
b8375cf1 | 1339 | if (memcmp(mac, md->addr, ETH_ALEN) == 0) { |
3283e286 | 1340 | md->ret = true; |
b8375cf1 AO |
1341 | return; |
1342 | } | |
1343 | ||
1344 | /* Match the link address */ | |
1345 | for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) { | |
1346 | struct ieee80211_bss_conf *conf; | |
1347 | ||
1348 | conf = rcu_dereference(vif->link_conf[i]); | |
1349 | if (!conf) | |
1350 | continue; | |
1351 | ||
1352 | if (memcmp(conf->addr, md->addr, ETH_ALEN) == 0) { | |
1353 | md->ret = true; | |
1354 | return; | |
1355 | } | |
1356 | } | |
3283e286 JB |
1357 | } |
1358 | ||
1359 | static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data, | |
1360 | const u8 *addr) | |
1361 | { | |
1362 | struct mac80211_hwsim_addr_match_data md = { | |
1363 | .ret = false, | |
1364 | }; | |
1365 | ||
339467b9 JB |
1366 | if (data->scanning && memcmp(addr, data->scan_addr, ETH_ALEN) == 0) |
1367 | return true; | |
1368 | ||
3283e286 JB |
1369 | memcpy(md.addr, addr, ETH_ALEN); |
1370 | ||
1371 | ieee80211_iterate_active_interfaces_atomic(data->hw, | |
1372 | IEEE80211_IFACE_ITER_NORMAL, | |
1373 | mac80211_hwsim_addr_iter, | |
1374 | &md); | |
1375 | ||
1376 | return md.ret; | |
1377 | } | |
6c085227 | 1378 | |
fc6971d4 JM |
1379 | static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data, |
1380 | struct sk_buff *skb) | |
1381 | { | |
1382 | switch (data->ps) { | |
1383 | case PS_DISABLED: | |
1384 | return true; | |
1385 | case PS_ENABLED: | |
1386 | return false; | |
1387 | case PS_AUTO_POLL: | |
1388 | /* TODO: accept (some) Beacons by default and other frames only | |
1389 | * if pending PS-Poll has been sent */ | |
1390 | return true; | |
1391 | case PS_MANUAL_POLL: | |
1392 | /* Allow unicast frames to own address if there is a pending | |
1393 | * PS-Poll */ | |
1394 | if (data->ps_poll_pending && | |
3283e286 | 1395 | mac80211_hwsim_addr_match(data, skb->data + 4)) { |
fc6971d4 JM |
1396 | data->ps_poll_pending = false; |
1397 | return true; | |
1398 | } | |
1399 | return false; | |
1400 | } | |
1401 | ||
1402 | return true; | |
1403 | } | |
1404 | ||
f21e4d8e MW |
1405 | static int hwsim_unicast_netgroup(struct mac80211_hwsim_data *data, |
1406 | struct sk_buff *skb, int portid) | |
1407 | { | |
1408 | struct net *net; | |
1409 | bool found = false; | |
1410 | int res = -ENOENT; | |
1411 | ||
1412 | rcu_read_lock(); | |
1413 | for_each_net_rcu(net) { | |
1414 | if (data->netgroup == hwsim_net_get_netgroup(net)) { | |
1415 | res = genlmsg_unicast(net, skb, portid); | |
1416 | found = true; | |
1417 | break; | |
1418 | } | |
1419 | } | |
1420 | rcu_read_unlock(); | |
1421 | ||
1422 | if (!found) | |
1423 | nlmsg_free(skb); | |
1424 | ||
1425 | return res; | |
1426 | } | |
1427 | ||
5cc58a9e JB |
1428 | static void mac80211_hwsim_config_mac_nl(struct ieee80211_hw *hw, |
1429 | const u8 *addr, bool add) | |
1430 | { | |
1431 | struct mac80211_hwsim_data *data = hw->priv; | |
1432 | u32 _portid = READ_ONCE(data->wmediumd); | |
1433 | struct sk_buff *skb; | |
1434 | void *msg_head; | |
1435 | ||
419bd7a7 JB |
1436 | WARN_ON(!is_valid_ether_addr(addr)); |
1437 | ||
5cc58a9e JB |
1438 | if (!_portid && !hwsim_virtio_enabled) |
1439 | return; | |
1440 | ||
1441 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); | |
1442 | if (!skb) | |
1443 | return; | |
1444 | ||
1445 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, | |
1446 | add ? HWSIM_CMD_ADD_MAC_ADDR : | |
1447 | HWSIM_CMD_DEL_MAC_ADDR); | |
1448 | if (!msg_head) { | |
1449 | pr_debug("mac80211_hwsim: problem with msg_head\n"); | |
1450 | goto nla_put_failure; | |
1451 | } | |
1452 | ||
1453 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, | |
1454 | ETH_ALEN, data->addresses[1].addr)) | |
1455 | goto nla_put_failure; | |
1456 | ||
1457 | if (nla_put(skb, HWSIM_ATTR_ADDR_RECEIVER, ETH_ALEN, addr)) | |
1458 | goto nla_put_failure; | |
1459 | ||
1460 | genlmsg_end(skb, msg_head); | |
1461 | ||
1462 | if (hwsim_virtio_enabled) | |
1463 | hwsim_tx_virtio(data, skb); | |
1464 | else | |
1465 | hwsim_unicast_netgroup(data, skb, _portid); | |
1466 | return; | |
1467 | nla_put_failure: | |
1468 | nlmsg_free(skb); | |
1469 | } | |
1470 | ||
6e3d6ca1 BB |
1471 | static inline u16 trans_tx_rate_flags_ieee2hwsim(struct ieee80211_tx_rate *rate) |
1472 | { | |
1473 | u16 result = 0; | |
1474 | ||
1475 | if (rate->flags & IEEE80211_TX_RC_USE_RTS_CTS) | |
1476 | result |= MAC80211_HWSIM_TX_RC_USE_RTS_CTS; | |
1477 | if (rate->flags & IEEE80211_TX_RC_USE_CTS_PROTECT) | |
1478 | result |= MAC80211_HWSIM_TX_RC_USE_CTS_PROTECT; | |
1479 | if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) | |
1480 | result |= MAC80211_HWSIM_TX_RC_USE_SHORT_PREAMBLE; | |
1481 | if (rate->flags & IEEE80211_TX_RC_MCS) | |
1482 | result |= MAC80211_HWSIM_TX_RC_MCS; | |
1483 | if (rate->flags & IEEE80211_TX_RC_GREEN_FIELD) | |
1484 | result |= MAC80211_HWSIM_TX_RC_GREEN_FIELD; | |
1485 | if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
1486 | result |= MAC80211_HWSIM_TX_RC_40_MHZ_WIDTH; | |
1487 | if (rate->flags & IEEE80211_TX_RC_DUP_DATA) | |
1488 | result |= MAC80211_HWSIM_TX_RC_DUP_DATA; | |
1489 | if (rate->flags & IEEE80211_TX_RC_SHORT_GI) | |
1490 | result |= MAC80211_HWSIM_TX_RC_SHORT_GI; | |
1491 | if (rate->flags & IEEE80211_TX_RC_VHT_MCS) | |
1492 | result |= MAC80211_HWSIM_TX_RC_VHT_MCS; | |
1493 | if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) | |
1494 | result |= MAC80211_HWSIM_TX_RC_80_MHZ_WIDTH; | |
1495 | if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) | |
1496 | result |= MAC80211_HWSIM_TX_RC_160_MHZ_WIDTH; | |
1497 | ||
1498 | return result; | |
1499 | } | |
1500 | ||
7882513b JL |
1501 | static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, |
1502 | struct sk_buff *my_skb, | |
626c30f9 WD |
1503 | int dst_portid, |
1504 | struct ieee80211_channel *channel) | |
7882513b JL |
1505 | { |
1506 | struct sk_buff *skb; | |
1507 | struct mac80211_hwsim_data *data = hw->priv; | |
1508 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data; | |
1509 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb); | |
1510 | void *msg_head; | |
1511 | unsigned int hwsim_flags = 0; | |
1512 | int i; | |
1513 | struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES]; | |
6e3d6ca1 | 1514 | struct hwsim_tx_rate_flag tx_attempts_flags[IEEE80211_TX_MAX_RATES]; |
cc5250cd | 1515 | uintptr_t cookie; |
7882513b | 1516 | |
7882513b JL |
1517 | if (data->ps != PS_DISABLED) |
1518 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
1519 | /* If the queue contains MAX_QUEUE skb's drop some */ | |
1520 | if (skb_queue_len(&data->pending) >= MAX_QUEUE) { | |
f5d32a7b | 1521 | /* Dropping until WARN_QUEUE level */ |
2155c3f8 | 1522 | while (skb_queue_len(&data->pending) >= WARN_QUEUE) { |
b7bc9679 | 1523 | ieee80211_free_txskb(hw, skb_dequeue(&data->pending)); |
2155c3f8 BG |
1524 | data->tx_dropped++; |
1525 | } | |
7882513b JL |
1526 | } |
1527 | ||
58050fce | 1528 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
7882513b JL |
1529 | if (skb == NULL) |
1530 | goto nla_put_failure; | |
1531 | ||
1532 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, | |
1533 | HWSIM_CMD_FRAME); | |
1534 | if (msg_head == NULL) { | |
62b093b3 | 1535 | pr_debug("mac80211_hwsim: problem with msg_head\n"); |
7882513b JL |
1536 | goto nla_put_failure; |
1537 | } | |
1538 | ||
354210f8 BC |
1539 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, |
1540 | ETH_ALEN, data->addresses[1].addr)) | |
633c9389 | 1541 | goto nla_put_failure; |
265dc7f0 | 1542 | |
7882513b | 1543 | /* We get the skb->data */ |
633c9389 DM |
1544 | if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data)) |
1545 | goto nla_put_failure; | |
7882513b JL |
1546 | |
1547 | /* We get the flags for this transmission, and we translate them to | |
1548 | wmediumd flags */ | |
1549 | ||
1550 | if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) | |
1551 | hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS; | |
1552 | ||
1553 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) | |
1554 | hwsim_flags |= HWSIM_TX_CTL_NO_ACK; | |
1555 | ||
633c9389 DM |
1556 | if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags)) |
1557 | goto nla_put_failure; | |
7882513b | 1558 | |
626c30f9 | 1559 | if (nla_put_u32(skb, HWSIM_ATTR_FREQ, channel->center_freq)) |
4f86ed8f BG |
1560 | goto nla_put_failure; |
1561 | ||
7882513b JL |
1562 | /* We get the tx control (rate and retries) info*/ |
1563 | ||
1564 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { | |
1565 | tx_attempts[i].idx = info->status.rates[i].idx; | |
6e3d6ca1 | 1566 | tx_attempts_flags[i].idx = info->status.rates[i].idx; |
7882513b | 1567 | tx_attempts[i].count = info->status.rates[i].count; |
6e3d6ca1 BB |
1568 | tx_attempts_flags[i].flags = |
1569 | trans_tx_rate_flags_ieee2hwsim( | |
1570 | &info->status.rates[i]); | |
7882513b JL |
1571 | } |
1572 | ||
633c9389 DM |
1573 | if (nla_put(skb, HWSIM_ATTR_TX_INFO, |
1574 | sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES, | |
1575 | tx_attempts)) | |
1576 | goto nla_put_failure; | |
7882513b | 1577 | |
6e3d6ca1 BB |
1578 | if (nla_put(skb, HWSIM_ATTR_TX_INFO_FLAGS, |
1579 | sizeof(struct hwsim_tx_rate_flag) * IEEE80211_TX_MAX_RATES, | |
1580 | tx_attempts_flags)) | |
1581 | goto nla_put_failure; | |
1582 | ||
7882513b | 1583 | /* We create a cookie to identify this skb */ |
cc5250cd | 1584 | cookie = atomic_inc_return(&data->pending_cookie); |
959eb2fd | 1585 | info->rate_driver_data[0] = (void *)cookie; |
08f4cbb8 | 1586 | if (nla_put_u64_64bit(skb, HWSIM_ATTR_COOKIE, cookie, HWSIM_ATTR_PAD)) |
633c9389 | 1587 | goto nla_put_failure; |
7882513b JL |
1588 | |
1589 | genlmsg_end(skb, msg_head); | |
5d44fe7c EG |
1590 | |
1591 | if (hwsim_virtio_enabled) { | |
1592 | if (hwsim_tx_virtio(data, skb)) | |
1593 | goto err_free_txskb; | |
1594 | } else { | |
1595 | if (hwsim_unicast_netgroup(data, skb, dst_portid)) | |
1596 | goto err_free_txskb; | |
1597 | } | |
7882513b JL |
1598 | |
1599 | /* Enqueue the packet */ | |
1600 | skb_queue_tail(&data->pending, my_skb); | |
2155c3f8 BG |
1601 | data->tx_pkts++; |
1602 | data->tx_bytes += my_skb->len; | |
7882513b JL |
1603 | return; |
1604 | ||
1605 | nla_put_failure: | |
f2831e20 BC |
1606 | nlmsg_free(skb); |
1607 | err_free_txskb: | |
62b093b3 | 1608 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
b7bc9679 | 1609 | ieee80211_free_txskb(hw, my_skb); |
2155c3f8 | 1610 | data->tx_failed++; |
7882513b JL |
1611 | } |
1612 | ||
e8261171 JB |
1613 | static bool hwsim_chans_compat(struct ieee80211_channel *c1, |
1614 | struct ieee80211_channel *c2) | |
1615 | { | |
1616 | if (!c1 || !c2) | |
1617 | return false; | |
1618 | ||
1619 | return c1->center_freq == c2->center_freq; | |
1620 | } | |
1621 | ||
1622 | struct tx_iter_data { | |
1623 | struct ieee80211_channel *channel; | |
1624 | bool receive; | |
1625 | }; | |
1626 | ||
1627 | static void mac80211_hwsim_tx_iter(void *_data, u8 *addr, | |
1628 | struct ieee80211_vif *vif) | |
1629 | { | |
1630 | struct tx_iter_data *data = _data; | |
912fa56b | 1631 | int i; |
e8261171 | 1632 | |
912fa56b | 1633 | for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) { |
d8675a63 | 1634 | struct ieee80211_bss_conf *conf; |
912fa56b | 1635 | struct ieee80211_chanctx_conf *chanctx; |
e8261171 | 1636 | |
d8675a63 | 1637 | conf = rcu_dereference(vif->link_conf[i]); |
912fa56b AO |
1638 | if (!conf) |
1639 | continue; | |
1640 | ||
1641 | chanctx = rcu_dereference(conf->chanctx_conf); | |
1642 | if (!chanctx) | |
1643 | continue; | |
e8261171 | 1644 | |
912fa56b AO |
1645 | if (!hwsim_chans_compat(data->channel, chanctx->def.chan)) |
1646 | continue; | |
1647 | ||
1648 | data->receive = true; | |
1649 | return; | |
1650 | } | |
e8261171 JB |
1651 | } |
1652 | ||
1f7bba79 JB |
1653 | static void mac80211_hwsim_add_vendor_rtap(struct sk_buff *skb) |
1654 | { | |
1655 | /* | |
1656 | * To enable this code, #define the HWSIM_RADIOTAP_OUI, | |
1657 | * e.g. like this: | |
1658 | * #define HWSIM_RADIOTAP_OUI "\x02\x00\x00" | |
1659 | * (but you should use a valid OUI, not that) | |
1660 | * | |
1661 | * If anyone wants to 'donate' a radiotap OUI/subns code | |
1662 | * please send a patch removing this #ifdef and changing | |
1663 | * the values accordingly. | |
1664 | */ | |
1665 | #ifdef HWSIM_RADIOTAP_OUI | |
9179dff8 MG |
1666 | struct ieee80211_radiotap_vendor_tlv *rtap; |
1667 | static const char vendor_data[8] = "ABCDEFGH"; | |
1668 | ||
1669 | // Make sure no padding is needed | |
1670 | BUILD_BUG_ON(sizeof(vendor_data) % 4); | |
1671 | /* this is last radiotap info before the mac header, so | |
1672 | * skb_reset_mac_header for mac8022 to know the end of | |
1673 | * the radiotap TLV/beginning of the 802.11 header | |
1674 | */ | |
1675 | skb_reset_mac_header(skb); | |
1f7bba79 JB |
1676 | |
1677 | /* | |
1678 | * Note that this code requires the headroom in the SKB | |
1679 | * that was allocated earlier. | |
1680 | */ | |
9179dff8 MG |
1681 | rtap = skb_push(skb, sizeof(*rtap) + sizeof(vendor_data)); |
1682 | ||
1683 | rtap->len = cpu_to_le16(sizeof(*rtap) - | |
1684 | sizeof(struct ieee80211_radiotap_tlv) + | |
1685 | sizeof(vendor_data)); | |
1686 | rtap->type = cpu_to_le16(IEEE80211_RADIOTAP_VENDOR_NAMESPACE); | |
1687 | ||
11a2638d MG |
1688 | rtap->content.oui[0] = HWSIM_RADIOTAP_OUI[0]; |
1689 | rtap->content.oui[1] = HWSIM_RADIOTAP_OUI[1]; | |
1690 | rtap->content.oui[2] = HWSIM_RADIOTAP_OUI[2]; | |
1691 | rtap->content.oui_subtype = 127; | |
9179dff8 | 1692 | /* clear reserved field */ |
11a2638d MG |
1693 | rtap->content.reserved = 0; |
1694 | rtap->content.vendor_type = 0; | |
1695 | memcpy(rtap->content.data, vendor_data, sizeof(vendor_data)); | |
1f7bba79 | 1696 | |
9179dff8 | 1697 | IEEE80211_SKB_RXCB(skb)->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; |
1f7bba79 JB |
1698 | #endif |
1699 | } | |
1700 | ||
b1622ada JB |
1701 | static void mac80211_hwsim_rx(struct mac80211_hwsim_data *data, |
1702 | struct ieee80211_rx_status *rx_status, | |
1703 | struct sk_buff *skb) | |
1704 | { | |
e229f978 JB |
1705 | struct ieee80211_hdr *hdr = (void *)skb->data; |
1706 | ||
1707 | if (!ieee80211_has_morefrags(hdr->frame_control) && | |
1708 | !is_multicast_ether_addr(hdr->addr1) && | |
1709 | (ieee80211_is_mgmt(hdr->frame_control) || | |
1710 | ieee80211_is_data(hdr->frame_control))) { | |
1711 | struct ieee80211_sta *sta; | |
1712 | unsigned int link_id; | |
1713 | ||
1714 | rcu_read_lock(); | |
1715 | sta = ieee80211_find_sta_by_link_addrs(data->hw, hdr->addr2, | |
1716 | hdr->addr1, &link_id); | |
1717 | if (sta) { | |
1718 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
1719 | ||
1720 | if (ieee80211_has_pm(hdr->frame_control)) | |
1721 | sp->active_links_rx &= ~BIT(link_id); | |
1722 | else | |
1723 | sp->active_links_rx |= BIT(link_id); | |
1724 | } | |
1725 | rcu_read_unlock(); | |
1726 | } | |
1727 | ||
b1622ada JB |
1728 | memcpy(IEEE80211_SKB_RXCB(skb), rx_status, sizeof(*rx_status)); |
1729 | ||
1730 | mac80211_hwsim_add_vendor_rtap(skb); | |
1731 | ||
1732 | data->rx_pkts++; | |
1733 | data->rx_bytes += skb->len; | |
1734 | ieee80211_rx_irqsafe(data->hw, skb); | |
1735 | } | |
1736 | ||
7882513b | 1737 | static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, |
e8261171 JB |
1738 | struct sk_buff *skb, |
1739 | struct ieee80211_channel *chan) | |
acc1e7a3 | 1740 | { |
0e057d73 JB |
1741 | struct mac80211_hwsim_data *data = hw->priv, *data2; |
1742 | bool ack = false; | |
e36cfdc9 | 1743 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
acc1e7a3 | 1744 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e36cfdc9 | 1745 | struct ieee80211_rx_status rx_status; |
b66851c3 | 1746 | u64 now; |
acc1e7a3 JM |
1747 | |
1748 | memset(&rx_status, 0, sizeof(rx_status)); | |
f4bda337 | 1749 | rx_status.flag |= RX_FLAG_MACTIME_START; |
e8261171 | 1750 | rx_status.freq = chan->center_freq; |
148fe295 | 1751 | rx_status.freq_offset = chan->freq_offset ? 1 : 0; |
e8261171 | 1752 | rx_status.band = chan->band; |
dad6330d KB |
1753 | if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) { |
1754 | rx_status.rate_idx = | |
1755 | ieee80211_rate_get_vht_mcs(&info->control.rates[0]); | |
8613c948 | 1756 | rx_status.nss = |
dad6330d | 1757 | ieee80211_rate_get_vht_nss(&info->control.rates[0]); |
da6a4352 | 1758 | rx_status.encoding = RX_ENC_VHT; |
dad6330d KB |
1759 | } else { |
1760 | rx_status.rate_idx = info->control.rates[0].idx; | |
1761 | if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS) | |
da6a4352 | 1762 | rx_status.encoding = RX_ENC_HT; |
dad6330d | 1763 | } |
281ed297 | 1764 | if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
2f242bf4 JB |
1765 | rx_status.bw = RATE_INFO_BW_40; |
1766 | else if (info->control.rates[0].flags & IEEE80211_TX_RC_80_MHZ_WIDTH) | |
1767 | rx_status.bw = RATE_INFO_BW_80; | |
1768 | else if (info->control.rates[0].flags & IEEE80211_TX_RC_160_MHZ_WIDTH) | |
1769 | rx_status.bw = RATE_INFO_BW_160; | |
1770 | else | |
1771 | rx_status.bw = RATE_INFO_BW_20; | |
281ed297 | 1772 | if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI) |
7fdd69c5 | 1773 | rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI; |
b59fb546 BL |
1774 | /* TODO: simulate optional packet loss */ |
1775 | rx_status.signal = data->rx_rssi; | |
1d5e9f80 JB |
1776 | if (info->control.vif) |
1777 | rx_status.signal += info->control.vif->bss_conf.txpower; | |
acc1e7a3 | 1778 | |
fc6971d4 JM |
1779 | if (data->ps != PS_DISABLED) |
1780 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
1781 | ||
90e3012e JB |
1782 | /* release the skb's source info */ |
1783 | skb_orphan(skb); | |
c0acf38e | 1784 | skb_dst_drop(skb); |
90e3012e | 1785 | skb->mark = 0; |
895b5c9f FW |
1786 | skb_ext_reset(skb); |
1787 | nf_reset_ct(skb); | |
90e3012e | 1788 | |
b66851c3 TP |
1789 | /* |
1790 | * Get absolute mactime here so all HWs RX at the "same time", and | |
1791 | * absolute TX time for beacon mactime so the timestamp matches. | |
1792 | * Giving beacons a different mactime than non-beacons looks messy, but | |
1793 | * it helps the Toffset be exact and a ~10us mactime discrepancy | |
1794 | * probably doesn't really matter. | |
1795 | */ | |
1796 | if (ieee80211_is_beacon(hdr->frame_control) || | |
341203e7 | 1797 | ieee80211_is_probe_resp(hdr->frame_control)) { |
9285ec4c | 1798 | rx_status.boottime_ns = ktime_get_boottime_ns(); |
b66851c3 | 1799 | now = data->abs_bcn_ts; |
341203e7 | 1800 | } else { |
b66851c3 | 1801 | now = mac80211_hwsim_get_tsf_raw(); |
341203e7 | 1802 | } |
b66851c3 | 1803 | |
acc1e7a3 | 1804 | /* Copy skb to all enabled radios that are on the current frequency */ |
0e057d73 JB |
1805 | spin_lock(&hwsim_radio_lock); |
1806 | list_for_each_entry(data2, &hwsim_radios, list) { | |
acc1e7a3 | 1807 | struct sk_buff *nskb; |
e8261171 JB |
1808 | struct tx_iter_data tx_iter_data = { |
1809 | .receive = false, | |
1810 | .channel = chan, | |
1811 | }; | |
acc1e7a3 | 1812 | |
0e057d73 | 1813 | if (data == data2) |
acc1e7a3 | 1814 | continue; |
0e057d73 | 1815 | |
e8261171 JB |
1816 | if (!data2->started || (data2->idle && !data2->tmp_chan) || |
1817 | !hwsim_ps_rx_ok(data2, skb)) | |
acc1e7a3 JM |
1818 | continue; |
1819 | ||
e8261171 JB |
1820 | if (!(data->group & data2->group)) |
1821 | continue; | |
1822 | ||
100cb9ff MW |
1823 | if (data->netgroup != data2->netgroup) |
1824 | continue; | |
1825 | ||
e8261171 JB |
1826 | if (!hwsim_chans_compat(chan, data2->tmp_chan) && |
1827 | !hwsim_chans_compat(chan, data2->channel)) { | |
1828 | ieee80211_iterate_active_interfaces_atomic( | |
8b2c9824 JB |
1829 | data2->hw, IEEE80211_IFACE_ITER_NORMAL, |
1830 | mac80211_hwsim_tx_iter, &tx_iter_data); | |
e8261171 JB |
1831 | if (!tx_iter_data.receive) |
1832 | continue; | |
1833 | } | |
1834 | ||
90b9e446 JB |
1835 | /* |
1836 | * reserve some space for our vendor and the normal | |
1837 | * radiotap header, since we're copying anyway | |
1838 | */ | |
a357d7f9 JB |
1839 | if (skb->len < PAGE_SIZE && paged_rx) { |
1840 | struct page *page = alloc_page(GFP_ATOMIC); | |
1841 | ||
1842 | if (!page) | |
1843 | continue; | |
1844 | ||
1845 | nskb = dev_alloc_skb(128); | |
1846 | if (!nskb) { | |
1847 | __free_page(page); | |
1848 | continue; | |
1849 | } | |
1850 | ||
1851 | memcpy(page_address(page), skb->data, skb->len); | |
1852 | skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len); | |
1853 | } else { | |
1854 | nskb = skb_copy(skb, GFP_ATOMIC); | |
1855 | if (!nskb) | |
1856 | continue; | |
1857 | } | |
acc1e7a3 | 1858 | |
265dc7f0 | 1859 | if (mac80211_hwsim_addr_match(data2, hdr->addr1)) |
0e057d73 | 1860 | ack = true; |
f483ad25 | 1861 | |
b66851c3 | 1862 | rx_status.mactime = now + data2->tsf_offset; |
90b9e446 | 1863 | |
b1622ada | 1864 | mac80211_hwsim_rx(data2, &rx_status, nskb); |
acc1e7a3 | 1865 | } |
0e057d73 | 1866 | spin_unlock(&hwsim_radio_lock); |
acc1e7a3 | 1867 | |
e36cfdc9 JM |
1868 | return ack; |
1869 | } | |
1870 | ||
2ab60f49 AO |
1871 | static struct ieee80211_bss_conf * |
1872 | mac80211_hwsim_select_tx_link(struct mac80211_hwsim_data *data, | |
1873 | struct ieee80211_vif *vif, | |
1874 | struct ieee80211_sta *sta, | |
e4c9050a JB |
1875 | struct ieee80211_hdr *hdr, |
1876 | struct ieee80211_link_sta **link_sta) | |
2ab60f49 | 1877 | { |
af4f2aa3 | 1878 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
2ab60f49 AO |
1879 | int i; |
1880 | ||
01ae1209 | 1881 | if (!ieee80211_vif_is_mld(vif)) |
af4f2aa3 JB |
1882 | return &vif->bss_conf; |
1883 | ||
86e74a08 | 1884 | WARN_ON(is_multicast_ether_addr(hdr->addr1)); |
af4f2aa3 | 1885 | |
0cc80943 | 1886 | if (WARN_ON_ONCE(!sta || !sta->valid_links)) |
af4f2aa3 JB |
1887 | return &vif->bss_conf; |
1888 | ||
2ab60f49 | 1889 | for (i = 0; i < ARRAY_SIZE(vif->link_conf); i++) { |
2ab60f49 | 1890 | struct ieee80211_bss_conf *bss_conf; |
af4f2aa3 | 1891 | unsigned int link_id; |
2ab60f49 | 1892 | |
af4f2aa3 JB |
1893 | /* round-robin the available link IDs */ |
1894 | link_id = (sp->last_link + i + 1) % ARRAY_SIZE(vif->link_conf); | |
1895 | ||
6521ee74 JB |
1896 | if (!(vif->active_links & BIT(link_id))) |
1897 | continue; | |
1898 | ||
e229f978 JB |
1899 | if (!(sp->active_links_rx & BIT(link_id))) |
1900 | continue; | |
1901 | ||
e4c9050a JB |
1902 | *link_sta = rcu_dereference(sta->link[link_id]); |
1903 | if (!*link_sta) | |
2ab60f49 AO |
1904 | continue; |
1905 | ||
af4f2aa3 JB |
1906 | bss_conf = rcu_dereference(vif->link_conf[link_id]); |
1907 | if (WARN_ON_ONCE(!bss_conf)) | |
1908 | continue; | |
2ab60f49 | 1909 | |
6521ee74 JB |
1910 | /* can happen while switching links */ |
1911 | if (!rcu_access_pointer(bss_conf->chanctx_conf)) | |
1912 | continue; | |
1913 | ||
af4f2aa3 | 1914 | sp->last_link = link_id; |
2ab60f49 AO |
1915 | return bss_conf; |
1916 | } | |
1917 | ||
1918 | return NULL; | |
1919 | } | |
1920 | ||
36323f81 TH |
1921 | static void mac80211_hwsim_tx(struct ieee80211_hw *hw, |
1922 | struct ieee80211_tx_control *control, | |
1923 | struct sk_buff *skb) | |
e36cfdc9 | 1924 | { |
e8261171 JB |
1925 | struct mac80211_hwsim_data *data = hw->priv; |
1926 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); | |
732b5395 | 1927 | struct ieee80211_hdr *hdr = (void *)skb->data; |
e8261171 JB |
1928 | struct ieee80211_chanctx_conf *chanctx_conf; |
1929 | struct ieee80211_channel *channel; | |
0e057d73 | 1930 | bool ack; |
585625c9 JB |
1931 | enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT; |
1932 | u32 _portid, i; | |
e36cfdc9 | 1933 | |
e8261171 | 1934 | if (WARN_ON(skb->len < 10)) { |
e36cfdc9 | 1935 | /* Should not happen; just a sanity check for addr1 use */ |
fe0f3cd2 | 1936 | ieee80211_free_txskb(hw, skb); |
7bb45683 | 1937 | return; |
e36cfdc9 JM |
1938 | } |
1939 | ||
361c3e04 | 1940 | if (!data->use_chanctx) { |
e8261171 | 1941 | channel = data->channel; |
585625c9 | 1942 | confbw = data->bw; |
e8261171 JB |
1943 | } else if (txi->hw_queue == 4) { |
1944 | channel = data->tmp_chan; | |
1945 | } else { | |
2ab60f49 AO |
1946 | u8 link = u32_get_bits(IEEE80211_SKB_CB(skb)->control.flags, |
1947 | IEEE80211_TX_CTRL_MLO_LINK); | |
e4c9050a JB |
1948 | struct ieee80211_vif *vif = txi->control.vif; |
1949 | struct ieee80211_link_sta *link_sta = NULL; | |
1950 | struct ieee80211_sta *sta = control->sta; | |
1951 | struct ieee80211_bss_conf *bss_conf; | |
2ab60f49 | 1952 | |
e4c9050a | 1953 | if (link != IEEE80211_LINK_UNSPECIFIED) { |
2ab60f49 | 1954 | bss_conf = rcu_dereference(txi->control.vif->link_conf[link]); |
e4c9050a JB |
1955 | if (sta) |
1956 | link_sta = rcu_dereference(sta->link[link]); | |
1957 | } else { | |
1958 | bss_conf = mac80211_hwsim_select_tx_link(data, vif, sta, | |
1959 | hdr, &link_sta); | |
1960 | } | |
2ab60f49 | 1961 | |
2d22be01 JB |
1962 | if (unlikely(!bss_conf)) { |
1963 | /* if it's an MLO STA, it might have deactivated all | |
1964 | * links temporarily - but we don't handle real PS in | |
1965 | * this code yet, so just drop the frame in that case | |
1966 | */ | |
1967 | WARN(link != IEEE80211_LINK_UNSPECIFIED || !sta || !sta->mlo, | |
1968 | "link:%d, sta:%pM, sta->mlo:%d\n", | |
1969 | link, sta ? sta->addr : NULL, sta ? sta->mlo : -1); | |
2ab60f49 AO |
1970 | ieee80211_free_txskb(hw, skb); |
1971 | return; | |
1972 | } | |
d0a9123e | 1973 | |
e4c9050a JB |
1974 | if (sta && sta->mlo) { |
1975 | if (WARN_ON(!link_sta)) { | |
1976 | ieee80211_free_txskb(hw, skb); | |
1977 | return; | |
1978 | } | |
1979 | /* address translation to link addresses on TX */ | |
1980 | ether_addr_copy(hdr->addr1, link_sta->addr); | |
1981 | ether_addr_copy(hdr->addr2, bss_conf->addr); | |
1982 | /* translate A3 only if it's the BSSID */ | |
1983 | if (!ieee80211_has_tods(hdr->frame_control) && | |
1984 | !ieee80211_has_fromds(hdr->frame_control)) { | |
1985 | if (ether_addr_equal(hdr->addr3, sta->addr)) | |
1986 | ether_addr_copy(hdr->addr3, link_sta->addr); | |
1987 | else if (ether_addr_equal(hdr->addr3, vif->addr)) | |
1988 | ether_addr_copy(hdr->addr3, bss_conf->addr); | |
1989 | } | |
1990 | /* no need to look at A4, if present it's SA */ | |
1991 | } | |
1992 | ||
d0a9123e | 1993 | chanctx_conf = rcu_dereference(bss_conf->chanctx_conf); |
585625c9 | 1994 | if (chanctx_conf) { |
4bf88530 | 1995 | channel = chanctx_conf->def.chan; |
585625c9 JB |
1996 | confbw = chanctx_conf->def.width; |
1997 | } else { | |
e8261171 | 1998 | channel = NULL; |
585625c9 | 1999 | } |
e8261171 JB |
2000 | } |
2001 | ||
2002 | if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) { | |
fe0f3cd2 | 2003 | ieee80211_free_txskb(hw, skb); |
e8261171 JB |
2004 | return; |
2005 | } | |
2006 | ||
2007 | if (data->idle && !data->tmp_chan) { | |
62b093b3 | 2008 | wiphy_dbg(hw->wiphy, "Trying to TX when idle - reject\n"); |
fe0f3cd2 | 2009 | ieee80211_free_txskb(hw, skb); |
e8261171 JB |
2010 | return; |
2011 | } | |
2012 | ||
2013 | if (txi->control.vif) | |
2014 | hwsim_check_magic(txi->control.vif); | |
2015 | if (control->sta) | |
2016 | hwsim_check_sta_magic(control->sta); | |
2017 | ||
30686bf7 | 2018 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) |
1eb32179 KB |
2019 | ieee80211_get_tx_rates(txi->control.vif, control->sta, skb, |
2020 | txi->control.rates, | |
2021 | ARRAY_SIZE(txi->control.rates)); | |
e8261171 | 2022 | |
585625c9 JB |
2023 | for (i = 0; i < ARRAY_SIZE(txi->control.rates); i++) { |
2024 | u16 rflags = txi->control.rates[i].flags; | |
2025 | /* initialize to data->bw for 5/10 MHz handling */ | |
2026 | enum nl80211_chan_width bw = data->bw; | |
2027 | ||
2028 | if (txi->control.rates[i].idx == -1) | |
2029 | break; | |
2030 | ||
2031 | if (rflags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
2032 | bw = NL80211_CHAN_WIDTH_40; | |
2033 | else if (rflags & IEEE80211_TX_RC_80_MHZ_WIDTH) | |
2034 | bw = NL80211_CHAN_WIDTH_80; | |
2035 | else if (rflags & IEEE80211_TX_RC_160_MHZ_WIDTH) | |
2036 | bw = NL80211_CHAN_WIDTH_160; | |
2037 | ||
2038 | if (WARN_ON(hwsim_get_chanwidth(bw) > hwsim_get_chanwidth(confbw))) | |
2039 | return; | |
2040 | } | |
2041 | ||
732b5395 JM |
2042 | if (skb->len >= 24 + 8 && |
2043 | ieee80211_is_probe_resp(hdr->frame_control)) { | |
2044 | /* fake header transmission time */ | |
2045 | struct ieee80211_mgmt *mgmt; | |
2046 | struct ieee80211_rate *txrate; | |
148fe295 TP |
2047 | /* TODO: get MCS */ |
2048 | int bitrate = 100; | |
732b5395 JM |
2049 | u64 ts; |
2050 | ||
2051 | mgmt = (struct ieee80211_mgmt *)skb->data; | |
2052 | txrate = ieee80211_get_tx_rate(hw, txi); | |
148fe295 TP |
2053 | if (txrate) |
2054 | bitrate = txrate->bitrate; | |
732b5395 JM |
2055 | ts = mac80211_hwsim_get_tsf_raw(); |
2056 | mgmt->u.probe_resp.timestamp = | |
2057 | cpu_to_le64(ts + data->tsf_offset + | |
148fe295 | 2058 | 24 * 8 * 10 / bitrate); |
732b5395 JM |
2059 | } |
2060 | ||
e8261171 JB |
2061 | mac80211_hwsim_monitor_rx(hw, skb, channel); |
2062 | ||
7882513b | 2063 | /* wmediumd mode check */ |
6aa7de05 | 2064 | _portid = READ_ONCE(data->wmediumd); |
7882513b | 2065 | |
5d44fe7c | 2066 | if (_portid || hwsim_virtio_enabled) |
626c30f9 | 2067 | return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, channel); |
7882513b JL |
2068 | |
2069 | /* NO wmediumd detected, perfect medium simulation */ | |
2155c3f8 BG |
2070 | data->tx_pkts++; |
2071 | data->tx_bytes += skb->len; | |
e8261171 | 2072 | ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel); |
7882513b | 2073 | |
f06b7ab8 | 2074 | if (ack && skb->len >= 16) |
e8261171 | 2075 | mac80211_hwsim_monitor_ack(channel, hdr->addr2); |
e36cfdc9 | 2076 | |
e6a9854b | 2077 | ieee80211_tx_info_clear_status(txi); |
2a4ffa4c JC |
2078 | |
2079 | /* frame was transmitted at most favorable rate at first attempt */ | |
2080 | txi->control.rates[0].count = 1; | |
2081 | txi->control.rates[1].idx = -1; | |
2082 | ||
e6a9854b JB |
2083 | if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack) |
2084 | txi->flags |= IEEE80211_TX_STAT_ACK; | |
acc1e7a3 | 2085 | ieee80211_tx_status_irqsafe(hw, skb); |
acc1e7a3 JM |
2086 | } |
2087 | ||
2088 | ||
2089 | static int mac80211_hwsim_start(struct ieee80211_hw *hw) | |
2090 | { | |
2091 | struct mac80211_hwsim_data *data = hw->priv; | |
62b093b3 | 2092 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
3db1cd5c | 2093 | data->started = true; |
acc1e7a3 JM |
2094 | return 0; |
2095 | } | |
2096 | ||
2097 | ||
2098 | static void mac80211_hwsim_stop(struct ieee80211_hw *hw) | |
2099 | { | |
2100 | struct mac80211_hwsim_data *data = hw->priv; | |
e57f8a48 | 2101 | int i; |
bd18de51 | 2102 | |
3db1cd5c | 2103 | data->started = false; |
e57f8a48 ST |
2104 | |
2105 | for (i = 0; i < ARRAY_SIZE(data->link_data); i++) | |
2106 | hrtimer_cancel(&data->link_data[i].beacon_timer); | |
bd18de51 JB |
2107 | |
2108 | while (!skb_queue_empty(&data->pending)) | |
2109 | ieee80211_free_txskb(hw, skb_dequeue(&data->pending)); | |
2110 | ||
62b093b3 | 2111 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
acc1e7a3 JM |
2112 | } |
2113 | ||
2114 | ||
2115 | static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw, | |
1ed32e4f | 2116 | struct ieee80211_vif *vif) |
acc1e7a3 | 2117 | { |
62b093b3 LR |
2118 | wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
2119 | __func__, ieee80211_vif_type_p2p(vif), | |
2120 | vif->addr); | |
1ed32e4f | 2121 | hwsim_set_magic(vif); |
e8261171 | 2122 | |
5cc58a9e JB |
2123 | if (vif->type != NL80211_IFTYPE_MONITOR) |
2124 | mac80211_hwsim_config_mac_nl(hw, vif->addr, true); | |
2125 | ||
e8261171 JB |
2126 | vif->cab_queue = 0; |
2127 | vif->hw_queue[IEEE80211_AC_VO] = 0; | |
2128 | vif->hw_queue[IEEE80211_AC_VI] = 1; | |
2129 | vif->hw_queue[IEEE80211_AC_BE] = 2; | |
2130 | vif->hw_queue[IEEE80211_AC_BK] = 3; | |
2131 | ||
acc1e7a3 JM |
2132 | return 0; |
2133 | } | |
2134 | ||
7d366663 JB |
2135 | #ifdef CONFIG_MAC80211_DEBUGFS |
2136 | static void mac80211_hwsim_vif_add_debugfs(struct ieee80211_hw *hw, | |
2137 | struct ieee80211_vif *vif) | |
2138 | { | |
2139 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
2140 | ||
2141 | debugfs_create_u32("skip_beacons", 0600, vif->debugfs_dir, | |
2142 | &vp->skip_beacons); | |
2143 | } | |
2144 | #endif | |
acc1e7a3 | 2145 | |
c35d0270 JB |
2146 | static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw, |
2147 | struct ieee80211_vif *vif, | |
2ca27bcf JB |
2148 | enum nl80211_iftype newtype, |
2149 | bool newp2p) | |
c35d0270 | 2150 | { |
2ca27bcf | 2151 | newtype = ieee80211_iftype_p2p(newtype, newp2p); |
62b093b3 LR |
2152 | wiphy_dbg(hw->wiphy, |
2153 | "%s (old type=%d, new type=%d, mac_addr=%pM)\n", | |
2154 | __func__, ieee80211_vif_type_p2p(vif), | |
2ca27bcf | 2155 | newtype, vif->addr); |
c35d0270 JB |
2156 | hwsim_check_magic(vif); |
2157 | ||
3eb92f6a JB |
2158 | /* |
2159 | * interface may change from non-AP to AP in | |
2160 | * which case this needs to be set up again | |
2161 | */ | |
2162 | vif->cab_queue = 0; | |
2163 | ||
c35d0270 JB |
2164 | return 0; |
2165 | } | |
2166 | ||
acc1e7a3 | 2167 | static void mac80211_hwsim_remove_interface( |
1ed32e4f | 2168 | struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
acc1e7a3 | 2169 | { |
62b093b3 LR |
2170 | wiphy_dbg(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
2171 | __func__, ieee80211_vif_type_p2p(vif), | |
2172 | vif->addr); | |
1ed32e4f JB |
2173 | hwsim_check_magic(vif); |
2174 | hwsim_clear_magic(vif); | |
5cc58a9e JB |
2175 | if (vif->type != NL80211_IFTYPE_MONITOR) |
2176 | mac80211_hwsim_config_mac_nl(hw, vif->addr, false); | |
acc1e7a3 JM |
2177 | } |
2178 | ||
e8261171 JB |
2179 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
2180 | struct sk_buff *skb, | |
2181 | struct ieee80211_channel *chan) | |
2182 | { | |
f21e4d8e | 2183 | struct mac80211_hwsim_data *data = hw->priv; |
08b74776 | 2184 | u32 _portid = READ_ONCE(data->wmediumd); |
e8261171 | 2185 | |
30686bf7 | 2186 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) { |
1eb32179 KB |
2187 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); |
2188 | ieee80211_get_tx_rates(txi->control.vif, NULL, skb, | |
2189 | txi->control.rates, | |
2190 | ARRAY_SIZE(txi->control.rates)); | |
2191 | } | |
2192 | ||
e8261171 JB |
2193 | mac80211_hwsim_monitor_rx(hw, skb, chan); |
2194 | ||
08b74776 JK |
2195 | if (_portid || hwsim_virtio_enabled) |
2196 | return mac80211_hwsim_tx_frame_nl(hw, skb, _portid, chan); | |
e8261171 | 2197 | |
93efeeea NDP |
2198 | data->tx_pkts++; |
2199 | data->tx_bytes += skb->len; | |
e8261171 JB |
2200 | mac80211_hwsim_tx_frame_no_nl(hw, skb, chan); |
2201 | dev_kfree_skb(skb); | |
2202 | } | |
acc1e7a3 | 2203 | |
b3a912e3 AD |
2204 | static void __mac80211_hwsim_beacon_tx(struct ieee80211_bss_conf *link_conf, |
2205 | struct mac80211_hwsim_data *data, | |
2206 | struct ieee80211_hw *hw, | |
2207 | struct ieee80211_vif *vif, | |
2208 | struct sk_buff *skb) | |
acc1e7a3 | 2209 | { |
7d366663 | 2210 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
b66851c3 TP |
2211 | struct ieee80211_tx_info *info; |
2212 | struct ieee80211_rate *txrate; | |
2213 | struct ieee80211_mgmt *mgmt; | |
148fe295 TP |
2214 | /* TODO: get MCS */ |
2215 | int bitrate = 100; | |
acc1e7a3 | 2216 | |
7d366663 JB |
2217 | if (vp->skip_beacons) { |
2218 | vp->skip_beacons--; | |
2219 | dev_kfree_skb(skb); | |
2220 | return; | |
2221 | } | |
2222 | ||
b66851c3 | 2223 | info = IEEE80211_SKB_CB(skb); |
30686bf7 | 2224 | if (ieee80211_hw_check(hw, SUPPORTS_RC_TABLE)) |
1eb32179 KB |
2225 | ieee80211_get_tx_rates(vif, NULL, skb, |
2226 | info->control.rates, | |
2227 | ARRAY_SIZE(info->control.rates)); | |
2228 | ||
b66851c3 | 2229 | txrate = ieee80211_get_tx_rate(hw, info); |
148fe295 TP |
2230 | if (txrate) |
2231 | bitrate = txrate->bitrate; | |
b66851c3 TP |
2232 | |
2233 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
2234 | /* fake header transmission time */ | |
2235 | data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw(); | |
a3ffee47 TP |
2236 | if (ieee80211_is_s1g_beacon(mgmt->frame_control)) { |
2237 | struct ieee80211_ext *ext = (void *) mgmt; | |
2238 | ||
2239 | ext->u.s1g_beacon.timestamp = cpu_to_le32(data->abs_bcn_ts + | |
2240 | data->tsf_offset + | |
2241 | 10 * 8 * 10 / | |
148fe295 | 2242 | bitrate); |
a3ffee47 TP |
2243 | } else { |
2244 | mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts + | |
2245 | data->tsf_offset + | |
2246 | 24 * 8 * 10 / | |
148fe295 | 2247 | bitrate); |
a3ffee47 | 2248 | } |
7882513b | 2249 | |
e8261171 | 2250 | mac80211_hwsim_tx_frame(hw, skb, |
e57f8a48 | 2251 | rcu_dereference(link_conf->chanctx_conf)->def.chan); |
b3a912e3 AD |
2252 | } |
2253 | ||
2254 | static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac, | |
2255 | struct ieee80211_vif *vif) | |
2256 | { | |
2257 | struct mac80211_hwsim_link_data *link_data = arg; | |
2258 | u32 link_id = link_data->link_id; | |
2259 | struct ieee80211_bss_conf *link_conf; | |
2260 | struct mac80211_hwsim_data *data = | |
2261 | container_of(link_data, struct mac80211_hwsim_data, | |
2262 | link_data[link_id]); | |
2263 | struct ieee80211_hw *hw = data->hw; | |
2264 | struct sk_buff *skb; | |
2265 | ||
2266 | hwsim_check_magic(vif); | |
2267 | ||
2268 | link_conf = rcu_dereference(vif->link_conf[link_id]); | |
2269 | if (!link_conf) | |
2270 | return; | |
2271 | ||
2272 | if (vif->type != NL80211_IFTYPE_AP && | |
2273 | vif->type != NL80211_IFTYPE_MESH_POINT && | |
2274 | vif->type != NL80211_IFTYPE_ADHOC && | |
2275 | vif->type != NL80211_IFTYPE_OCB) | |
2276 | return; | |
2277 | ||
c4f4d9f7 AD |
2278 | if (vif->mbssid_tx_vif && vif->mbssid_tx_vif != vif) |
2279 | return; | |
2280 | ||
0dd45ebc AD |
2281 | if (vif->bss_conf.ema_ap) { |
2282 | struct ieee80211_ema_beacons *ema; | |
2283 | u8 i = 0; | |
2284 | ||
2285 | ema = ieee80211_beacon_get_template_ema_list(hw, vif, link_id); | |
2286 | if (!ema || !ema->cnt) | |
2287 | return; | |
2288 | ||
2289 | for (i = 0; i < ema->cnt; i++) { | |
2290 | __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif, | |
2291 | ema->bcn[i].skb); | |
2292 | ema->bcn[i].skb = NULL; /* Already freed */ | |
2293 | } | |
2294 | ieee80211_beacon_free_ema_list(ema); | |
2295 | } else { | |
2296 | skb = ieee80211_beacon_get(hw, vif, link_id); | |
2297 | if (!skb) | |
2298 | return; | |
b3a912e3 | 2299 | |
0dd45ebc AD |
2300 | __mac80211_hwsim_beacon_tx(link_conf, data, hw, vif, skb); |
2301 | } | |
0037db63 | 2302 | |
01afc6fe TP |
2303 | while ((skb = ieee80211_get_buffered_bc(hw, vif)) != NULL) { |
2304 | mac80211_hwsim_tx_frame(hw, skb, | |
e57f8a48 | 2305 | rcu_dereference(link_conf->chanctx_conf)->def.chan); |
01afc6fe TP |
2306 | } |
2307 | ||
6030b3a4 | 2308 | if (link_conf->csa_active && ieee80211_beacon_cntdwn_is_complete(vif, link_id)) |
04ada859 | 2309 | ieee80211_csa_finish(vif, link_id); |
acc1e7a3 JM |
2310 | } |
2311 | ||
01e59e46 TP |
2312 | static enum hrtimer_restart |
2313 | mac80211_hwsim_beacon(struct hrtimer *timer) | |
acc1e7a3 | 2314 | { |
e57f8a48 ST |
2315 | struct mac80211_hwsim_link_data *link_data = |
2316 | container_of(timer, struct mac80211_hwsim_link_data, beacon_timer); | |
01e59e46 | 2317 | struct mac80211_hwsim_data *data = |
e57f8a48 ST |
2318 | container_of(link_data, struct mac80211_hwsim_data, |
2319 | link_data[link_data->link_id]); | |
01e59e46 | 2320 | struct ieee80211_hw *hw = data->hw; |
e57f8a48 | 2321 | u64 bcn_int = link_data->beacon_int; |
acc1e7a3 | 2322 | |
4c4c671a | 2323 | if (!data->started) |
77dcc623 | 2324 | return HRTIMER_NORESTART; |
acc1e7a3 | 2325 | |
f248f105 | 2326 | ieee80211_iterate_active_interfaces_atomic( |
8b2c9824 | 2327 | hw, IEEE80211_IFACE_ITER_NORMAL, |
e57f8a48 | 2328 | mac80211_hwsim_beacon_tx, link_data); |
acc1e7a3 | 2329 | |
c51f8783 TP |
2330 | /* beacon at new TBTT + beacon interval */ |
2331 | if (data->bcn_delta) { | |
2332 | bcn_int -= data->bcn_delta; | |
2333 | data->bcn_delta = 0; | |
2334 | } | |
e57f8a48 | 2335 | hrtimer_forward_now(&link_data->beacon_timer, |
313bbd19 | 2336 | ns_to_ktime(bcn_int * NSEC_PER_USEC)); |
77dcc623 | 2337 | return HRTIMER_RESTART; |
acc1e7a3 JM |
2338 | } |
2339 | ||
675a0b04 | 2340 | static const char * const hwsim_chanwidths[] = { |
b5764696 RF |
2341 | [NL80211_CHAN_WIDTH_5] = "ht5", |
2342 | [NL80211_CHAN_WIDTH_10] = "ht10", | |
675a0b04 KB |
2343 | [NL80211_CHAN_WIDTH_20_NOHT] = "noht", |
2344 | [NL80211_CHAN_WIDTH_20] = "ht20", | |
2345 | [NL80211_CHAN_WIDTH_40] = "ht40", | |
2346 | [NL80211_CHAN_WIDTH_80] = "vht80", | |
2347 | [NL80211_CHAN_WIDTH_80P80] = "vht80p80", | |
2348 | [NL80211_CHAN_WIDTH_160] = "vht160", | |
148fe295 TP |
2349 | [NL80211_CHAN_WIDTH_1] = "1MHz", |
2350 | [NL80211_CHAN_WIDTH_2] = "2MHz", | |
2351 | [NL80211_CHAN_WIDTH_4] = "4MHz", | |
2352 | [NL80211_CHAN_WIDTH_8] = "8MHz", | |
2353 | [NL80211_CHAN_WIDTH_16] = "16MHz", | |
0aaffa9b | 2354 | }; |
acc1e7a3 | 2355 | |
e8975581 | 2356 | static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) |
acc1e7a3 JM |
2357 | { |
2358 | struct mac80211_hwsim_data *data = hw->priv; | |
e8975581 | 2359 | struct ieee80211_conf *conf = &hw->conf; |
0f78231b JB |
2360 | static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = { |
2361 | [IEEE80211_SMPS_AUTOMATIC] = "auto", | |
2362 | [IEEE80211_SMPS_OFF] = "off", | |
2363 | [IEEE80211_SMPS_STATIC] = "static", | |
2364 | [IEEE80211_SMPS_DYNAMIC] = "dynamic", | |
2365 | }; | |
7f813ce1 | 2366 | int idx; |
0f78231b | 2367 | |
675a0b04 | 2368 | if (conf->chandef.chan) |
62b093b3 LR |
2369 | wiphy_dbg(hw->wiphy, |
2370 | "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n", | |
2371 | __func__, | |
2372 | conf->chandef.chan->center_freq, | |
2373 | conf->chandef.center_freq1, | |
2374 | conf->chandef.center_freq2, | |
2375 | hwsim_chanwidths[conf->chandef.width], | |
2376 | !!(conf->flags & IEEE80211_CONF_IDLE), | |
2377 | !!(conf->flags & IEEE80211_CONF_PS), | |
2378 | smps_modes[conf->smps_mode]); | |
675a0b04 | 2379 | else |
62b093b3 LR |
2380 | wiphy_dbg(hw->wiphy, |
2381 | "%s (freq=0 idle=%d ps=%d smps=%s)\n", | |
2382 | __func__, | |
2383 | !!(conf->flags & IEEE80211_CONF_IDLE), | |
2384 | !!(conf->flags & IEEE80211_CONF_PS), | |
2385 | smps_modes[conf->smps_mode]); | |
acc1e7a3 | 2386 | |
70541839 JM |
2387 | data->idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
2388 | ||
7f813ce1 | 2389 | WARN_ON(conf->chandef.chan && data->use_chanctx); |
e8261171 | 2390 | |
7f813ce1 JB |
2391 | mutex_lock(&data->mutex); |
2392 | if (data->scanning && conf->chandef.chan) { | |
2393 | for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) { | |
2394 | if (data->survey_data[idx].channel == data->channel) { | |
2395 | data->survey_data[idx].start = | |
2396 | data->survey_data[idx].next_start; | |
2397 | data->survey_data[idx].end = jiffies; | |
2398 | break; | |
2399 | } | |
2400 | } | |
2401 | ||
2402 | data->channel = conf->chandef.chan; | |
585625c9 | 2403 | data->bw = conf->chandef.width; |
e8261171 | 2404 | |
7f813ce1 JB |
2405 | for (idx = 0; idx < ARRAY_SIZE(data->survey_data); idx++) { |
2406 | if (data->survey_data[idx].channel && | |
2407 | data->survey_data[idx].channel != data->channel) | |
2408 | continue; | |
2409 | data->survey_data[idx].channel = data->channel; | |
2410 | data->survey_data[idx].next_start = jiffies; | |
2411 | break; | |
2412 | } | |
2413 | } else { | |
2414 | data->channel = conf->chandef.chan; | |
585625c9 | 2415 | data->bw = conf->chandef.width; |
7f813ce1 JB |
2416 | } |
2417 | mutex_unlock(&data->mutex); | |
e8261171 | 2418 | |
e57f8a48 ST |
2419 | for (idx = 0; idx < ARRAY_SIZE(data->link_data); idx++) { |
2420 | struct mac80211_hwsim_link_data *link_data = | |
2421 | &data->link_data[idx]; | |
2422 | ||
2423 | if (!data->started || !link_data->beacon_int) { | |
2424 | hrtimer_cancel(&link_data->beacon_timer); | |
2425 | } else if (!hrtimer_is_queued(&link_data->beacon_timer)) { | |
2426 | u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); | |
2427 | u32 bcn_int = link_data->beacon_int; | |
2428 | u64 until_tbtt = bcn_int - do_div(tsf, bcn_int); | |
c51f8783 | 2429 | |
e57f8a48 ST |
2430 | hrtimer_start(&link_data->beacon_timer, |
2431 | ns_to_ktime(until_tbtt * NSEC_PER_USEC), | |
2432 | HRTIMER_MODE_REL_SOFT); | |
2433 | } | |
01e59e46 | 2434 | } |
acc1e7a3 JM |
2435 | |
2436 | return 0; | |
2437 | } | |
2438 | ||
2439 | ||
2440 | static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw, | |
2441 | unsigned int changed_flags, | |
3ac64bee | 2442 | unsigned int *total_flags,u64 multicast) |
acc1e7a3 JM |
2443 | { |
2444 | struct mac80211_hwsim_data *data = hw->priv; | |
2445 | ||
62b093b3 | 2446 | wiphy_dbg(hw->wiphy, "%s\n", __func__); |
acc1e7a3 JM |
2447 | |
2448 | data->rx_filter = 0; | |
acc1e7a3 JM |
2449 | if (*total_flags & FIF_ALLMULTI) |
2450 | data->rx_filter |= FIF_ALLMULTI; | |
bedd7904 JM |
2451 | if (*total_flags & FIF_MCAST_ACTION) |
2452 | data->rx_filter |= FIF_MCAST_ACTION; | |
acc1e7a3 JM |
2453 | |
2454 | *total_flags = data->rx_filter; | |
2455 | } | |
2456 | ||
0bb861e6 JM |
2457 | static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac, |
2458 | struct ieee80211_vif *vif) | |
2459 | { | |
2460 | unsigned int *count = data; | |
2461 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
2462 | ||
2463 | if (vp->bcn_en) | |
2464 | (*count)++; | |
2465 | } | |
2466 | ||
7a52107e | 2467 | static void mac80211_hwsim_vif_info_changed(struct ieee80211_hw *hw, |
8aa21e6f | 2468 | struct ieee80211_vif *vif, |
7b7090b4 | 2469 | u64 changed) |
8aa21e6f | 2470 | { |
fc6971d4 JM |
2471 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
2472 | ||
8aa21e6f | 2473 | hwsim_check_magic(vif); |
fe63bfa3 | 2474 | |
7b7090b4 | 2475 | wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM)\n", |
62b093b3 | 2476 | __func__, changed, vif->addr); |
fe63bfa3 JM |
2477 | |
2478 | if (changed & BSS_CHANGED_ASSOC) { | |
62b093b3 | 2479 | wiphy_dbg(hw->wiphy, " ASSOC: assoc=%d aid=%d\n", |
f276e20b JB |
2480 | vif->cfg.assoc, vif->cfg.aid); |
2481 | vp->assoc = vif->cfg.assoc; | |
2482 | vp->aid = vif->cfg.aid; | |
fe63bfa3 | 2483 | } |
f605d10a IP |
2484 | |
2485 | if (vif->type == NL80211_IFTYPE_STATION && | |
9362fabc | 2486 | changed & (BSS_CHANGED_MLD_VALID_LINKS | BSS_CHANGED_MLD_TTLM)) { |
f605d10a IP |
2487 | u16 usable_links = ieee80211_vif_usable_links(vif); |
2488 | ||
2489 | if (vif->active_links != usable_links) | |
2490 | ieee80211_set_active_links_async(vif, usable_links); | |
2491 | } | |
7a52107e ST |
2492 | } |
2493 | ||
2494 | static void mac80211_hwsim_link_info_changed(struct ieee80211_hw *hw, | |
2495 | struct ieee80211_vif *vif, | |
d8675a63 | 2496 | struct ieee80211_bss_conf *info, |
7840bd46 | 2497 | u64 changed) |
7a52107e ST |
2498 | { |
2499 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
2500 | struct mac80211_hwsim_data *data = hw->priv; | |
7840bd46 | 2501 | unsigned int link_id = info->link_id; |
e57f8a48 | 2502 | struct mac80211_hwsim_link_data *link_data = &data->link_data[link_id]; |
7a52107e ST |
2503 | |
2504 | hwsim_check_magic(vif); | |
2505 | ||
245e5ebc ST |
2506 | wiphy_dbg(hw->wiphy, "%s(changed=0x%llx vif->addr=%pM, link id %u)\n", |
2507 | __func__, (unsigned long long)changed, vif->addr, link_id); | |
7a52107e ST |
2508 | |
2509 | if (changed & BSS_CHANGED_BSSID) { | |
2510 | wiphy_dbg(hw->wiphy, "%s: BSSID changed: %pM\n", | |
2511 | __func__, info->bssid); | |
2512 | memcpy(vp->bssid, info->bssid, ETH_ALEN); | |
2513 | } | |
fe63bfa3 | 2514 | |
01e59e46 | 2515 | if (changed & BSS_CHANGED_BEACON_ENABLED) { |
62b093b3 LR |
2516 | wiphy_dbg(hw->wiphy, " BCN EN: %d (BI=%u)\n", |
2517 | info->enable_beacon, info->beacon_int); | |
0bb861e6 | 2518 | vp->bcn_en = info->enable_beacon; |
01e59e46 | 2519 | if (data->started && |
e57f8a48 | 2520 | !hrtimer_is_queued(&link_data->beacon_timer) && |
01e59e46 | 2521 | info->enable_beacon) { |
c51f8783 TP |
2522 | u64 tsf, until_tbtt; |
2523 | u32 bcn_int; | |
e57f8a48 | 2524 | link_data->beacon_int = info->beacon_int * 1024; |
c51f8783 | 2525 | tsf = mac80211_hwsim_get_tsf(hw, vif); |
e57f8a48 | 2526 | bcn_int = link_data->beacon_int; |
c51f8783 | 2527 | until_tbtt = bcn_int - do_div(tsf, bcn_int); |
77dcc623 | 2528 | |
e57f8a48 | 2529 | hrtimer_start(&link_data->beacon_timer, |
77dcc623 TG |
2530 | ns_to_ktime(until_tbtt * NSEC_PER_USEC), |
2531 | HRTIMER_MODE_REL_SOFT); | |
0bb861e6 JM |
2532 | } else if (!info->enable_beacon) { |
2533 | unsigned int count = 0; | |
cdb1b805 | 2534 | ieee80211_iterate_active_interfaces_atomic( |
0bb861e6 JM |
2535 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
2536 | mac80211_hwsim_bcn_en_iter, &count); | |
62b093b3 LR |
2537 | wiphy_dbg(hw->wiphy, " beaconing vifs remaining: %u", |
2538 | count); | |
56067628 | 2539 | if (count == 0) { |
e57f8a48 ST |
2540 | hrtimer_cancel(&link_data->beacon_timer); |
2541 | link_data->beacon_int = 0; | |
56067628 | 2542 | } |
0bb861e6 | 2543 | } |
57c4d7b4 JB |
2544 | } |
2545 | ||
fe63bfa3 | 2546 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
62b093b3 LR |
2547 | wiphy_dbg(hw->wiphy, " ERP_CTS_PROT: %d\n", |
2548 | info->use_cts_prot); | |
fe63bfa3 JM |
2549 | } |
2550 | ||
2551 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
62b093b3 LR |
2552 | wiphy_dbg(hw->wiphy, " ERP_PREAMBLE: %d\n", |
2553 | info->use_short_preamble); | |
fe63bfa3 JM |
2554 | } |
2555 | ||
2556 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
62b093b3 | 2557 | wiphy_dbg(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot); |
fe63bfa3 JM |
2558 | } |
2559 | ||
2560 | if (changed & BSS_CHANGED_HT) { | |
62b093b3 LR |
2561 | wiphy_dbg(hw->wiphy, " HT: op_mode=0x%x\n", |
2562 | info->ht_operation_mode); | |
fe63bfa3 JM |
2563 | } |
2564 | ||
2565 | if (changed & BSS_CHANGED_BASIC_RATES) { | |
62b093b3 LR |
2566 | wiphy_dbg(hw->wiphy, " BASIC_RATES: 0x%llx\n", |
2567 | (unsigned long long) info->basic_rates); | |
fe63bfa3 | 2568 | } |
cbc668a7 JB |
2569 | |
2570 | if (changed & BSS_CHANGED_TXPOWER) | |
62b093b3 | 2571 | wiphy_dbg(hw->wiphy, " TX Power: %d dBm\n", info->txpower); |
8aa21e6f JB |
2572 | } |
2573 | ||
585625c9 JB |
2574 | static void |
2575 | mac80211_hwsim_sta_rc_update(struct ieee80211_hw *hw, | |
2576 | struct ieee80211_vif *vif, | |
2577 | struct ieee80211_sta *sta, | |
2578 | u32 changed) | |
2579 | { | |
2580 | struct mac80211_hwsim_data *data = hw->priv; | |
2581 | u32 bw = U32_MAX; | |
aea9a608 AO |
2582 | int link_id; |
2583 | ||
2584 | rcu_read_lock(); | |
2585 | for (link_id = 0; | |
2586 | link_id < ARRAY_SIZE(vif->link_conf); | |
2587 | link_id++) { | |
2588 | enum nl80211_chan_width confbw = NL80211_CHAN_WIDTH_20_NOHT; | |
2589 | struct ieee80211_bss_conf *vif_conf; | |
2590 | struct ieee80211_link_sta *link_sta; | |
2591 | ||
2592 | link_sta = rcu_dereference(sta->link[link_id]); | |
2593 | ||
2594 | if (!link_sta) | |
2595 | continue; | |
585625c9 | 2596 | |
aea9a608 | 2597 | switch (link_sta->bandwidth) { |
585625c9 | 2598 | #define C(_bw) case IEEE80211_STA_RX_BW_##_bw: bw = _bw; break |
aea9a608 AO |
2599 | C(20); |
2600 | C(40); | |
2601 | C(80); | |
2602 | C(160); | |
2603 | C(320); | |
585625c9 | 2604 | #undef C |
aea9a608 | 2605 | } |
585625c9 | 2606 | |
aea9a608 AO |
2607 | if (!data->use_chanctx) { |
2608 | confbw = data->bw; | |
2609 | } else { | |
2610 | struct ieee80211_chanctx_conf *chanctx_conf; | |
2611 | ||
2612 | vif_conf = rcu_dereference(vif->link_conf[link_id]); | |
2613 | if (WARN_ON(!vif_conf)) | |
2614 | continue; | |
2615 | ||
2616 | chanctx_conf = rcu_dereference(vif_conf->chanctx_conf); | |
2617 | ||
2618 | if (!WARN_ON(!chanctx_conf)) | |
2619 | confbw = chanctx_conf->def.width; | |
2620 | } | |
2621 | ||
2622 | WARN(bw > hwsim_get_chanwidth(confbw), | |
2623 | "intf %pM [link=%d]: bad STA %pM bandwidth %d MHz (%d) > channel config %d MHz (%d)\n", | |
2624 | vif->addr, link_id, sta->addr, bw, sta->deflink.bandwidth, | |
2625 | hwsim_get_chanwidth(data->bw), data->bw); | |
a59d5556 | 2626 | |
585625c9 | 2627 | |
585625c9 | 2628 | } |
aea9a608 AO |
2629 | rcu_read_unlock(); |
2630 | ||
585625c9 | 2631 | |
585625c9 JB |
2632 | } |
2633 | ||
1d669cbf JB |
2634 | static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw, |
2635 | struct ieee80211_vif *vif, | |
2636 | struct ieee80211_sta *sta) | |
2637 | { | |
e229f978 JB |
2638 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
2639 | ||
1d669cbf JB |
2640 | hwsim_check_magic(vif); |
2641 | hwsim_set_sta_magic(sta); | |
585625c9 | 2642 | mac80211_hwsim_sta_rc_update(hw, vif, sta, 0); |
1d669cbf | 2643 | |
e229f978 JB |
2644 | if (sta->valid_links) { |
2645 | WARN(hweight16(sta->valid_links) > 1, | |
2646 | "expect to add STA with single link, have 0x%x\n", | |
2647 | sta->valid_links); | |
2648 | sp->active_links_rx = sta->valid_links; | |
2649 | } | |
2650 | ||
1d669cbf JB |
2651 | return 0; |
2652 | } | |
2653 | ||
2654 | static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw, | |
2655 | struct ieee80211_vif *vif, | |
2656 | struct ieee80211_sta *sta) | |
2657 | { | |
2658 | hwsim_check_magic(vif); | |
2659 | hwsim_clear_sta_magic(sta); | |
2660 | ||
2661 | return 0; | |
2662 | } | |
2663 | ||
d46ffecf JB |
2664 | static int mac80211_hwsim_sta_state(struct ieee80211_hw *hw, |
2665 | struct ieee80211_vif *vif, | |
2666 | struct ieee80211_sta *sta, | |
2667 | enum ieee80211_sta_state old_state, | |
2668 | enum ieee80211_sta_state new_state) | |
2669 | { | |
2670 | if (new_state == IEEE80211_STA_NOTEXIST) | |
2671 | return mac80211_hwsim_sta_remove(hw, vif, sta); | |
2672 | ||
2673 | if (old_state == IEEE80211_STA_NOTEXIST) | |
2674 | return mac80211_hwsim_sta_add(hw, vif, sta); | |
2675 | ||
8fb7e2ef | 2676 | /* |
358ddc7b MK |
2677 | * in an MLO connection, when client is authorized |
2678 | * (AP station marked as such), enable all links | |
8fb7e2ef | 2679 | */ |
358ddc7b MK |
2680 | if (ieee80211_vif_is_mld(vif) && |
2681 | vif->type == NL80211_IFTYPE_STATION && | |
8fb7e2ef | 2682 | new_state == IEEE80211_STA_AUTHORIZED && !sta->tdls) |
01ae1209 IP |
2683 | ieee80211_set_active_links_async(vif, |
2684 | ieee80211_vif_usable_links(vif)); | |
8fb7e2ef | 2685 | |
d46ffecf JB |
2686 | return 0; |
2687 | } | |
2688 | ||
8aa21e6f JB |
2689 | static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw, |
2690 | struct ieee80211_vif *vif, | |
17741cdc JB |
2691 | enum sta_notify_cmd cmd, |
2692 | struct ieee80211_sta *sta) | |
8aa21e6f JB |
2693 | { |
2694 | hwsim_check_magic(vif); | |
1d669cbf | 2695 | |
81c06523 | 2696 | switch (cmd) { |
89fad578 CL |
2697 | case STA_NOTIFY_SLEEP: |
2698 | case STA_NOTIFY_AWAKE: | |
2699 | /* TODO: make good use of these flags */ | |
2700 | break; | |
1d669cbf JB |
2701 | default: |
2702 | WARN(1, "Invalid sta notify: %d\n", cmd); | |
2703 | break; | |
81c06523 JB |
2704 | } |
2705 | } | |
2706 | ||
2707 | static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw, | |
2708 | struct ieee80211_sta *sta, | |
2709 | bool set) | |
2710 | { | |
2711 | hwsim_check_sta_magic(sta); | |
2712 | return 0; | |
8aa21e6f | 2713 | } |
acc1e7a3 | 2714 | |
b3e2130b JB |
2715 | static int mac80211_hwsim_conf_tx(struct ieee80211_hw *hw, |
2716 | struct ieee80211_vif *vif, | |
2717 | unsigned int link_id, u16 queue, | |
2718 | const struct ieee80211_tx_queue_params *params) | |
1e898ff8 | 2719 | { |
62b093b3 LR |
2720 | wiphy_dbg(hw->wiphy, |
2721 | "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n", | |
2722 | __func__, queue, | |
2723 | params->txop, params->cw_min, | |
2724 | params->cw_max, params->aifs); | |
1e898ff8 JM |
2725 | return 0; |
2726 | } | |
2727 | ||
7f813ce1 JB |
2728 | static int mac80211_hwsim_get_survey(struct ieee80211_hw *hw, int idx, |
2729 | struct survey_info *survey) | |
1289723e | 2730 | { |
7f813ce1 | 2731 | struct mac80211_hwsim_data *hwsim = hw->priv; |
1289723e | 2732 | |
7f813ce1 | 2733 | if (idx < 0 || idx >= ARRAY_SIZE(hwsim->survey_data)) |
1289723e HS |
2734 | return -ENOENT; |
2735 | ||
7f813ce1 JB |
2736 | mutex_lock(&hwsim->mutex); |
2737 | survey->channel = hwsim->survey_data[idx].channel; | |
2738 | if (!survey->channel) { | |
2739 | mutex_unlock(&hwsim->mutex); | |
2740 | return -ENOENT; | |
2741 | } | |
1289723e HS |
2742 | |
2743 | /* | |
7f813ce1 | 2744 | * Magically conjured dummy values --- this is only ok for simulated hardware. |
1289723e | 2745 | * |
7f813ce1 JB |
2746 | * A real driver which cannot determine real values noise MUST NOT |
2747 | * report any, especially not a magically conjured ones :-) | |
1289723e | 2748 | */ |
7f813ce1 JB |
2749 | survey->filled = SURVEY_INFO_NOISE_DBM | |
2750 | SURVEY_INFO_TIME | | |
2751 | SURVEY_INFO_TIME_BUSY; | |
1289723e | 2752 | survey->noise = -92; |
7f813ce1 JB |
2753 | survey->time = |
2754 | jiffies_to_msecs(hwsim->survey_data[idx].end - | |
2755 | hwsim->survey_data[idx].start); | |
2756 | /* report 12.5% of channel time is used */ | |
2757 | survey->time_busy = survey->time/8; | |
2758 | mutex_unlock(&hwsim->mutex); | |
1289723e HS |
2759 | |
2760 | return 0; | |
2761 | } | |
2762 | ||
03d51102 AB |
2763 | static enum ieee80211_neg_ttlm_res |
2764 | mac80211_hwsim_can_neg_ttlm(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | |
2765 | struct ieee80211_neg_ttlm *neg_ttlm) | |
2766 | { | |
2767 | u32 i; | |
2768 | ||
2769 | /* For testing purposes, accept if all TIDs are mapped to the same links | |
2770 | * set, otherwise reject. | |
2771 | */ | |
2772 | for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) { | |
2773 | if (neg_ttlm->downlink[i] != neg_ttlm->uplink[i] || | |
2774 | neg_ttlm->downlink[i] != neg_ttlm->downlink[0]) | |
2775 | return NEG_TTLM_RES_REJECT; | |
2776 | } | |
2777 | ||
2778 | return NEG_TTLM_RES_ACCEPT; | |
2779 | } | |
2780 | ||
aff89a9b JB |
2781 | #ifdef CONFIG_NL80211_TESTMODE |
2782 | /* | |
2783 | * This section contains example code for using netlink | |
2784 | * attributes with the testmode command in nl80211. | |
2785 | */ | |
2786 | ||
2787 | /* These enums need to be kept in sync with userspace */ | |
2788 | enum hwsim_testmode_attr { | |
2789 | __HWSIM_TM_ATTR_INVALID = 0, | |
2790 | HWSIM_TM_ATTR_CMD = 1, | |
2791 | HWSIM_TM_ATTR_PS = 2, | |
2792 | ||
2793 | /* keep last */ | |
2794 | __HWSIM_TM_ATTR_AFTER_LAST, | |
2795 | HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1 | |
2796 | }; | |
2797 | ||
2798 | enum hwsim_testmode_cmd { | |
2799 | HWSIM_TM_CMD_SET_PS = 0, | |
2800 | HWSIM_TM_CMD_GET_PS = 1, | |
4d6d0ae2 JB |
2801 | HWSIM_TM_CMD_STOP_QUEUES = 2, |
2802 | HWSIM_TM_CMD_WAKE_QUEUES = 3, | |
aff89a9b JB |
2803 | }; |
2804 | ||
2805 | static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = { | |
2806 | [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
2807 | [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 }, | |
2808 | }; | |
2809 | ||
5bc38193 | 2810 | static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, |
52981cd7 | 2811 | struct ieee80211_vif *vif, |
5bc38193 | 2812 | void *data, int len) |
aff89a9b JB |
2813 | { |
2814 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
2815 | struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1]; | |
2816 | struct sk_buff *skb; | |
2817 | int err, ps; | |
2818 | ||
8cb08174 JB |
2819 | err = nla_parse_deprecated(tb, HWSIM_TM_ATTR_MAX, data, len, |
2820 | hwsim_testmode_policy, NULL); | |
aff89a9b JB |
2821 | if (err) |
2822 | return err; | |
2823 | ||
2824 | if (!tb[HWSIM_TM_ATTR_CMD]) | |
2825 | return -EINVAL; | |
2826 | ||
2827 | switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) { | |
2828 | case HWSIM_TM_CMD_SET_PS: | |
2829 | if (!tb[HWSIM_TM_ATTR_PS]) | |
2830 | return -EINVAL; | |
2831 | ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]); | |
2832 | return hwsim_fops_ps_write(hwsim, ps); | |
2833 | case HWSIM_TM_CMD_GET_PS: | |
2834 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, | |
2835 | nla_total_size(sizeof(u32))); | |
2836 | if (!skb) | |
2837 | return -ENOMEM; | |
633c9389 DM |
2838 | if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps)) |
2839 | goto nla_put_failure; | |
aff89a9b | 2840 | return cfg80211_testmode_reply(skb); |
4d6d0ae2 JB |
2841 | case HWSIM_TM_CMD_STOP_QUEUES: |
2842 | ieee80211_stop_queues(hw); | |
2843 | return 0; | |
2844 | case HWSIM_TM_CMD_WAKE_QUEUES: | |
2845 | ieee80211_wake_queues(hw); | |
2846 | return 0; | |
aff89a9b JB |
2847 | default: |
2848 | return -EOPNOTSUPP; | |
2849 | } | |
2850 | ||
2851 | nla_put_failure: | |
2852 | kfree_skb(skb); | |
2853 | return -ENOBUFS; | |
2854 | } | |
2855 | #endif | |
2856 | ||
8b73d13a JB |
2857 | static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw, |
2858 | struct ieee80211_vif *vif, | |
50ea05ef | 2859 | struct ieee80211_ampdu_params *params) |
8b73d13a | 2860 | { |
50ea05ef SS |
2861 | struct ieee80211_sta *sta = params->sta; |
2862 | enum ieee80211_ampdu_mlme_action action = params->action; | |
2863 | u16 tid = params->tid; | |
2864 | ||
8b73d13a JB |
2865 | switch (action) { |
2866 | case IEEE80211_AMPDU_TX_START: | |
2ce113de | 2867 | return IEEE80211_AMPDU_TX_START_IMMEDIATE; |
18b559d5 JB |
2868 | case IEEE80211_AMPDU_TX_STOP_CONT: |
2869 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
2870 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
8b73d13a JB |
2871 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
2872 | break; | |
2873 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
2874 | break; | |
2875 | case IEEE80211_AMPDU_RX_START: | |
2876 | case IEEE80211_AMPDU_RX_STOP: | |
2877 | break; | |
2878 | default: | |
2879 | return -EOPNOTSUPP; | |
2880 | } | |
2881 | ||
2882 | return 0; | |
2883 | } | |
2884 | ||
77be2c54 EG |
2885 | static void mac80211_hwsim_flush(struct ieee80211_hw *hw, |
2886 | struct ieee80211_vif *vif, | |
2887 | u32 queues, bool drop) | |
a80f7c0b | 2888 | { |
7882513b | 2889 | /* Not implemented, queues only on kernel side */ |
a80f7c0b JB |
2890 | } |
2891 | ||
e8261171 | 2892 | static void hw_scan_work(struct work_struct *work) |
69068036 | 2893 | { |
e8261171 JB |
2894 | struct mac80211_hwsim_data *hwsim = |
2895 | container_of(work, struct mac80211_hwsim_data, hw_scan.work); | |
2896 | struct cfg80211_scan_request *req = hwsim->hw_scan_request; | |
2897 | int dwell, i; | |
69068036 | 2898 | |
e8261171 JB |
2899 | mutex_lock(&hwsim->mutex); |
2900 | if (hwsim->scan_chan_idx >= req->n_channels) { | |
7947d3e0 AS |
2901 | struct cfg80211_scan_info info = { |
2902 | .aborted = false, | |
2903 | }; | |
2904 | ||
62b093b3 | 2905 | wiphy_dbg(hwsim->hw->wiphy, "hw scan complete\n"); |
7947d3e0 | 2906 | ieee80211_scan_completed(hwsim->hw, &info); |
e8261171 JB |
2907 | hwsim->hw_scan_request = NULL; |
2908 | hwsim->hw_scan_vif = NULL; | |
2909 | hwsim->tmp_chan = NULL; | |
2910 | mutex_unlock(&hwsim->mutex); | |
5cc58a9e JB |
2911 | mac80211_hwsim_config_mac_nl(hwsim->hw, hwsim->scan_addr, |
2912 | false); | |
e8261171 JB |
2913 | return; |
2914 | } | |
2915 | ||
62b093b3 LR |
2916 | wiphy_dbg(hwsim->hw->wiphy, "hw scan %d MHz\n", |
2917 | req->channels[hwsim->scan_chan_idx]->center_freq); | |
e8261171 JB |
2918 | |
2919 | hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx]; | |
a8e828de JB |
2920 | if (hwsim->tmp_chan->flags & (IEEE80211_CHAN_NO_IR | |
2921 | IEEE80211_CHAN_RADAR) || | |
e8261171 JB |
2922 | !req->n_ssids) { |
2923 | dwell = 120; | |
2924 | } else { | |
2925 | dwell = 30; | |
2926 | /* send probes */ | |
2927 | for (i = 0; i < req->n_ssids; i++) { | |
2928 | struct sk_buff *probe; | |
12880d16 | 2929 | struct ieee80211_mgmt *mgmt; |
e8261171 JB |
2930 | |
2931 | probe = ieee80211_probereq_get(hwsim->hw, | |
339467b9 | 2932 | hwsim->scan_addr, |
e8261171 JB |
2933 | req->ssids[i].ssid, |
2934 | req->ssids[i].ssid_len, | |
b9a9ada1 | 2935 | req->ie_len); |
e8261171 JB |
2936 | if (!probe) |
2937 | continue; | |
b9a9ada1 | 2938 | |
12880d16 JM |
2939 | mgmt = (struct ieee80211_mgmt *) probe->data; |
2940 | memcpy(mgmt->da, req->bssid, ETH_ALEN); | |
2941 | memcpy(mgmt->bssid, req->bssid, ETH_ALEN); | |
2942 | ||
b9a9ada1 | 2943 | if (req->ie_len) |
59ae1d12 | 2944 | skb_put_data(probe, req->ie, req->ie_len); |
b9a9ada1 | 2945 | |
9e2db50f | 2946 | rcu_read_lock(); |
cacfddf8 JP |
2947 | if (!ieee80211_tx_prepare_skb(hwsim->hw, |
2948 | hwsim->hw_scan_vif, | |
2949 | probe, | |
2950 | hwsim->tmp_chan->band, | |
2951 | NULL)) { | |
9e2db50f | 2952 | rcu_read_unlock(); |
cacfddf8 JP |
2953 | kfree_skb(probe); |
2954 | continue; | |
2955 | } | |
2956 | ||
e8261171 JB |
2957 | local_bh_disable(); |
2958 | mac80211_hwsim_tx_frame(hwsim->hw, probe, | |
2959 | hwsim->tmp_chan); | |
9e2db50f | 2960 | rcu_read_unlock(); |
e8261171 JB |
2961 | local_bh_enable(); |
2962 | } | |
2963 | } | |
2964 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, | |
2965 | msecs_to_jiffies(dwell)); | |
7f813ce1 JB |
2966 | hwsim->survey_data[hwsim->scan_chan_idx].channel = hwsim->tmp_chan; |
2967 | hwsim->survey_data[hwsim->scan_chan_idx].start = jiffies; | |
2968 | hwsim->survey_data[hwsim->scan_chan_idx].end = | |
2969 | jiffies + msecs_to_jiffies(dwell); | |
e8261171 JB |
2970 | hwsim->scan_chan_idx++; |
2971 | mutex_unlock(&hwsim->mutex); | |
69068036 JB |
2972 | } |
2973 | ||
2974 | static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw, | |
a060bbfe | 2975 | struct ieee80211_vif *vif, |
c56ef672 | 2976 | struct ieee80211_scan_request *hw_req) |
69068036 | 2977 | { |
e8261171 | 2978 | struct mac80211_hwsim_data *hwsim = hw->priv; |
c56ef672 | 2979 | struct cfg80211_scan_request *req = &hw_req->req; |
69068036 | 2980 | |
e8261171 JB |
2981 | mutex_lock(&hwsim->mutex); |
2982 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { | |
2983 | mutex_unlock(&hwsim->mutex); | |
2984 | return -EBUSY; | |
2985 | } | |
2986 | hwsim->hw_scan_request = req; | |
2987 | hwsim->hw_scan_vif = vif; | |
2988 | hwsim->scan_chan_idx = 0; | |
339467b9 JB |
2989 | if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) |
2990 | get_random_mask_addr(hwsim->scan_addr, | |
2991 | hw_req->req.mac_addr, | |
2992 | hw_req->req.mac_addr_mask); | |
2993 | else | |
2994 | memcpy(hwsim->scan_addr, vif->addr, ETH_ALEN); | |
7f813ce1 | 2995 | memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data)); |
e8261171 | 2996 | mutex_unlock(&hwsim->mutex); |
69068036 | 2997 | |
5cc58a9e | 2998 | mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true); |
62b093b3 | 2999 | wiphy_dbg(hw->wiphy, "hwsim hw_scan request\n"); |
69068036 | 3000 | |
e8261171 | 3001 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0); |
69068036 JB |
3002 | |
3003 | return 0; | |
3004 | } | |
3005 | ||
e8261171 JB |
3006 | static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw, |
3007 | struct ieee80211_vif *vif) | |
3008 | { | |
3009 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
7947d3e0 AS |
3010 | struct cfg80211_scan_info info = { |
3011 | .aborted = true, | |
3012 | }; | |
e8261171 | 3013 | |
62b093b3 | 3014 | wiphy_dbg(hw->wiphy, "hwsim cancel_hw_scan\n"); |
e8261171 JB |
3015 | |
3016 | cancel_delayed_work_sync(&hwsim->hw_scan); | |
3017 | ||
3018 | mutex_lock(&hwsim->mutex); | |
7947d3e0 | 3019 | ieee80211_scan_completed(hwsim->hw, &info); |
e8261171 JB |
3020 | hwsim->tmp_chan = NULL; |
3021 | hwsim->hw_scan_request = NULL; | |
3022 | hwsim->hw_scan_vif = NULL; | |
3023 | mutex_unlock(&hwsim->mutex); | |
3024 | } | |
3025 | ||
a344d677 JB |
3026 | static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw, |
3027 | struct ieee80211_vif *vif, | |
3028 | const u8 *mac_addr) | |
f74cb0f7 LR |
3029 | { |
3030 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
3031 | ||
3032 | mutex_lock(&hwsim->mutex); | |
3033 | ||
3034 | if (hwsim->scanning) { | |
62b093b3 | 3035 | pr_debug("two hwsim sw_scans detected!\n"); |
f74cb0f7 LR |
3036 | goto out; |
3037 | } | |
3038 | ||
62b093b3 | 3039 | pr_debug("hwsim sw_scan request, prepping stuff\n"); |
339467b9 JB |
3040 | |
3041 | memcpy(hwsim->scan_addr, mac_addr, ETH_ALEN); | |
5cc58a9e | 3042 | mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, true); |
f74cb0f7 | 3043 | hwsim->scanning = true; |
7f813ce1 | 3044 | memset(hwsim->survey_data, 0, sizeof(hwsim->survey_data)); |
f74cb0f7 LR |
3045 | |
3046 | out: | |
3047 | mutex_unlock(&hwsim->mutex); | |
3048 | } | |
3049 | ||
a344d677 JB |
3050 | static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw, |
3051 | struct ieee80211_vif *vif) | |
f74cb0f7 LR |
3052 | { |
3053 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
3054 | ||
3055 | mutex_lock(&hwsim->mutex); | |
3056 | ||
62b093b3 | 3057 | pr_debug("hwsim sw_scan_complete\n"); |
23ff98fc | 3058 | hwsim->scanning = false; |
5cc58a9e | 3059 | mac80211_hwsim_config_mac_nl(hw, hwsim->scan_addr, false); |
93803b33 | 3060 | eth_zero_addr(hwsim->scan_addr); |
f74cb0f7 LR |
3061 | |
3062 | mutex_unlock(&hwsim->mutex); | |
3063 | } | |
3064 | ||
661ef475 JB |
3065 | static void hw_roc_start(struct work_struct *work) |
3066 | { | |
3067 | struct mac80211_hwsim_data *hwsim = | |
3068 | container_of(work, struct mac80211_hwsim_data, roc_start.work); | |
3069 | ||
3070 | mutex_lock(&hwsim->mutex); | |
3071 | ||
62b093b3 | 3072 | wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC begins\n"); |
661ef475 JB |
3073 | hwsim->tmp_chan = hwsim->roc_chan; |
3074 | ieee80211_ready_on_channel(hwsim->hw); | |
3075 | ||
3076 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->roc_done, | |
3077 | msecs_to_jiffies(hwsim->roc_duration)); | |
3078 | ||
3079 | mutex_unlock(&hwsim->mutex); | |
3080 | } | |
3081 | ||
e8261171 JB |
3082 | static void hw_roc_done(struct work_struct *work) |
3083 | { | |
3084 | struct mac80211_hwsim_data *hwsim = | |
3085 | container_of(work, struct mac80211_hwsim_data, roc_done.work); | |
3086 | ||
3087 | mutex_lock(&hwsim->mutex); | |
3088 | ieee80211_remain_on_channel_expired(hwsim->hw); | |
3089 | hwsim->tmp_chan = NULL; | |
3090 | mutex_unlock(&hwsim->mutex); | |
3091 | ||
62b093b3 | 3092 | wiphy_dbg(hwsim->hw->wiphy, "hwsim ROC expired\n"); |
e8261171 JB |
3093 | } |
3094 | ||
3095 | static int mac80211_hwsim_roc(struct ieee80211_hw *hw, | |
49884568 | 3096 | struct ieee80211_vif *vif, |
e8261171 | 3097 | struct ieee80211_channel *chan, |
d339d5ca IP |
3098 | int duration, |
3099 | enum ieee80211_roc_type type) | |
e8261171 JB |
3100 | { |
3101 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
3102 | ||
3103 | mutex_lock(&hwsim->mutex); | |
3104 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { | |
3105 | mutex_unlock(&hwsim->mutex); | |
3106 | return -EBUSY; | |
3107 | } | |
3108 | ||
661ef475 JB |
3109 | hwsim->roc_chan = chan; |
3110 | hwsim->roc_duration = duration; | |
e8261171 JB |
3111 | mutex_unlock(&hwsim->mutex); |
3112 | ||
62b093b3 LR |
3113 | wiphy_dbg(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n", |
3114 | chan->center_freq, duration); | |
661ef475 | 3115 | ieee80211_queue_delayed_work(hw, &hwsim->roc_start, HZ/50); |
e8261171 | 3116 | |
e8261171 JB |
3117 | return 0; |
3118 | } | |
3119 | ||
5db4c4b9 EG |
3120 | static int mac80211_hwsim_croc(struct ieee80211_hw *hw, |
3121 | struct ieee80211_vif *vif) | |
e8261171 JB |
3122 | { |
3123 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
3124 | ||
661ef475 | 3125 | cancel_delayed_work_sync(&hwsim->roc_start); |
e8261171 JB |
3126 | cancel_delayed_work_sync(&hwsim->roc_done); |
3127 | ||
3128 | mutex_lock(&hwsim->mutex); | |
3129 | hwsim->tmp_chan = NULL; | |
3130 | mutex_unlock(&hwsim->mutex); | |
3131 | ||
62b093b3 | 3132 | wiphy_dbg(hw->wiphy, "hwsim ROC canceled\n"); |
e8261171 JB |
3133 | |
3134 | return 0; | |
3135 | } | |
3136 | ||
3137 | static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw, | |
3138 | struct ieee80211_chanctx_conf *ctx) | |
3139 | { | |
3140 | hwsim_set_chanctx_magic(ctx); | |
62b093b3 LR |
3141 | wiphy_dbg(hw->wiphy, |
3142 | "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
3143 | ctx->def.chan->center_freq, ctx->def.width, | |
3144 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
3145 | return 0; |
3146 | } | |
3147 | ||
3148 | static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw, | |
3149 | struct ieee80211_chanctx_conf *ctx) | |
3150 | { | |
62b093b3 LR |
3151 | wiphy_dbg(hw->wiphy, |
3152 | "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
3153 | ctx->def.chan->center_freq, ctx->def.width, | |
3154 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
3155 | hwsim_check_chanctx_magic(ctx); |
3156 | hwsim_clear_chanctx_magic(ctx); | |
3157 | } | |
3158 | ||
3159 | static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw, | |
3160 | struct ieee80211_chanctx_conf *ctx, | |
3161 | u32 changed) | |
3162 | { | |
3163 | hwsim_check_chanctx_magic(ctx); | |
62b093b3 LR |
3164 | wiphy_dbg(hw->wiphy, |
3165 | "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
3166 | ctx->def.chan->center_freq, ctx->def.width, | |
3167 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
3168 | } |
3169 | ||
3170 | static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw, | |
3171 | struct ieee80211_vif *vif, | |
727eff4d | 3172 | struct ieee80211_bss_conf *link_conf, |
e8261171 JB |
3173 | struct ieee80211_chanctx_conf *ctx) |
3174 | { | |
3175 | hwsim_check_magic(vif); | |
3176 | hwsim_check_chanctx_magic(ctx); | |
3177 | ||
5fc8cea9 JB |
3178 | /* if we activate a link while already associated wake it up */ |
3179 | if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) { | |
3180 | struct sk_buff *skb; | |
3181 | ||
3182 | skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true); | |
3183 | if (skb) { | |
3184 | local_bh_disable(); | |
3185 | mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan); | |
3186 | local_bh_enable(); | |
3187 | } | |
3188 | } | |
3189 | ||
e8261171 JB |
3190 | return 0; |
3191 | } | |
3192 | ||
3193 | static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
3194 | struct ieee80211_vif *vif, | |
727eff4d | 3195 | struct ieee80211_bss_conf *link_conf, |
e8261171 JB |
3196 | struct ieee80211_chanctx_conf *ctx) |
3197 | { | |
3198 | hwsim_check_magic(vif); | |
3199 | hwsim_check_chanctx_magic(ctx); | |
5fc8cea9 JB |
3200 | |
3201 | /* if we deactivate a link while associated suspend it first */ | |
3202 | if (vif->type == NL80211_IFTYPE_STATION && vif->cfg.assoc) { | |
3203 | struct sk_buff *skb; | |
3204 | ||
3205 | skb = ieee80211_nullfunc_get(hw, vif, link_conf->link_id, true); | |
3206 | if (skb) { | |
3207 | struct ieee80211_hdr *hdr = (void *)skb->data; | |
3208 | ||
3209 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
3210 | ||
3211 | local_bh_disable(); | |
3212 | mac80211_hwsim_tx_frame(hw, skb, ctx->def.chan); | |
3213 | local_bh_enable(); | |
3214 | } | |
3215 | } | |
e8261171 JB |
3216 | } |
3217 | ||
7f501452 AKS |
3218 | static int mac80211_hwsim_switch_vif_chanctx(struct ieee80211_hw *hw, |
3219 | struct ieee80211_vif_chanctx_switch *vifs, | |
3220 | int n_vifs, | |
3221 | enum ieee80211_chanctx_switch_mode mode) | |
3222 | { | |
3223 | int i; | |
3224 | ||
3225 | if (n_vifs <= 0) | |
3226 | return -EINVAL; | |
3227 | ||
3228 | wiphy_dbg(hw->wiphy, | |
3229 | "switch vif channel context mode: %u\n", mode); | |
3230 | ||
3231 | for (i = 0; i < n_vifs; i++) { | |
3232 | hwsim_check_chanctx_magic(vifs[i].old_ctx); | |
3233 | wiphy_dbg(hw->wiphy, | |
3234 | "switch vif channel context: %d MHz/width: %d/cfreqs:%d/%d MHz -> %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
3235 | vifs[i].old_ctx->def.chan->center_freq, | |
3236 | vifs[i].old_ctx->def.width, | |
3237 | vifs[i].old_ctx->def.center_freq1, | |
3238 | vifs[i].old_ctx->def.center_freq2, | |
3239 | vifs[i].new_ctx->def.chan->center_freq, | |
3240 | vifs[i].new_ctx->def.width, | |
3241 | vifs[i].new_ctx->def.center_freq1, | |
3242 | vifs[i].new_ctx->def.center_freq2); | |
3243 | ||
3244 | switch (mode) { | |
3245 | case CHANCTX_SWMODE_REASSIGN_VIF: | |
3246 | hwsim_check_chanctx_magic(vifs[i].new_ctx); | |
3247 | break; | |
3248 | case CHANCTX_SWMODE_SWAP_CONTEXTS: | |
3249 | hwsim_set_chanctx_magic(vifs[i].new_ctx); | |
3250 | hwsim_clear_chanctx_magic(vifs[i].old_ctx); | |
3251 | break; | |
3252 | default: | |
3253 | WARN_ON("Invalid mode"); | |
3254 | } | |
3255 | } | |
3256 | return 0; | |
3257 | } | |
3258 | ||
2155c3f8 BG |
3259 | static const char mac80211_hwsim_gstrings_stats[][ETH_GSTRING_LEN] = { |
3260 | "tx_pkts_nic", | |
3261 | "tx_bytes_nic", | |
3262 | "rx_pkts_nic", | |
3263 | "rx_bytes_nic", | |
3264 | "d_tx_dropped", | |
3265 | "d_tx_failed", | |
3266 | "d_ps_mode", | |
3267 | "d_group", | |
2155c3f8 BG |
3268 | }; |
3269 | ||
3270 | #define MAC80211_HWSIM_SSTATS_LEN ARRAY_SIZE(mac80211_hwsim_gstrings_stats) | |
3271 | ||
3272 | static void mac80211_hwsim_get_et_strings(struct ieee80211_hw *hw, | |
3273 | struct ieee80211_vif *vif, | |
3274 | u32 sset, u8 *data) | |
3275 | { | |
3276 | if (sset == ETH_SS_STATS) | |
cbaccdc4 | 3277 | memcpy(data, mac80211_hwsim_gstrings_stats, |
2155c3f8 BG |
3278 | sizeof(mac80211_hwsim_gstrings_stats)); |
3279 | } | |
3280 | ||
3281 | static int mac80211_hwsim_get_et_sset_count(struct ieee80211_hw *hw, | |
3282 | struct ieee80211_vif *vif, int sset) | |
3283 | { | |
3284 | if (sset == ETH_SS_STATS) | |
3285 | return MAC80211_HWSIM_SSTATS_LEN; | |
3286 | return 0; | |
3287 | } | |
3288 | ||
3289 | static void mac80211_hwsim_get_et_stats(struct ieee80211_hw *hw, | |
3290 | struct ieee80211_vif *vif, | |
3291 | struct ethtool_stats *stats, u64 *data) | |
3292 | { | |
3293 | struct mac80211_hwsim_data *ar = hw->priv; | |
3294 | int i = 0; | |
3295 | ||
3296 | data[i++] = ar->tx_pkts; | |
3297 | data[i++] = ar->tx_bytes; | |
3298 | data[i++] = ar->rx_pkts; | |
3299 | data[i++] = ar->rx_bytes; | |
3300 | data[i++] = ar->tx_dropped; | |
3301 | data[i++] = ar->tx_failed; | |
3302 | data[i++] = ar->ps; | |
3303 | data[i++] = ar->group; | |
2155c3f8 BG |
3304 | |
3305 | WARN_ON(i != MAC80211_HWSIM_SSTATS_LEN); | |
3306 | } | |
3307 | ||
bdee75d2 JB |
3308 | static int mac80211_hwsim_tx_last_beacon(struct ieee80211_hw *hw) |
3309 | { | |
3310 | return 1; | |
3311 | } | |
3312 | ||
2fd0c671 JB |
3313 | static int mac80211_hwsim_set_rts_threshold(struct ieee80211_hw *hw, u32 value) |
3314 | { | |
3315 | return -EOPNOTSUPP; | |
3316 | } | |
3317 | ||
3318 | static int mac80211_hwsim_change_vif_links(struct ieee80211_hw *hw, | |
3319 | struct ieee80211_vif *vif, | |
3320 | u16 old_links, u16 new_links, | |
3321 | struct ieee80211_bss_conf *old[IEEE80211_MLD_MAX_NUM_LINKS]) | |
3322 | { | |
65f7052b | 3323 | unsigned long rem = old_links & ~new_links; |
c204d9df JB |
3324 | unsigned long add = new_links & ~old_links; |
3325 | int i; | |
3326 | ||
65f7052b JB |
3327 | if (!old_links) |
3328 | rem |= BIT(0); | |
3329 | if (!new_links) | |
3330 | add |= BIT(0); | |
3331 | ||
c204d9df JB |
3332 | for_each_set_bit(i, &rem, IEEE80211_MLD_MAX_NUM_LINKS) |
3333 | mac80211_hwsim_config_mac_nl(hw, old[i]->addr, false); | |
3334 | ||
3335 | for_each_set_bit(i, &add, IEEE80211_MLD_MAX_NUM_LINKS) { | |
3336 | struct ieee80211_bss_conf *link_conf; | |
3337 | ||
65fd846c | 3338 | link_conf = link_conf_dereference_protected(vif, i); |
c204d9df JB |
3339 | if (WARN_ON(!link_conf)) |
3340 | continue; | |
3341 | ||
3342 | mac80211_hwsim_config_mac_nl(hw, link_conf->addr, true); | |
3343 | } | |
3344 | ||
2fd0c671 JB |
3345 | return 0; |
3346 | } | |
3347 | ||
3348 | static int mac80211_hwsim_change_sta_links(struct ieee80211_hw *hw, | |
3349 | struct ieee80211_vif *vif, | |
3350 | struct ieee80211_sta *sta, | |
3351 | u16 old_links, u16 new_links) | |
3352 | { | |
e229f978 JB |
3353 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; |
3354 | ||
b2c4aa35 JB |
3355 | hwsim_check_sta_magic(sta); |
3356 | ||
e229f978 JB |
3357 | if (vif->type == NL80211_IFTYPE_STATION) |
3358 | sp->active_links_rx = new_links; | |
3359 | ||
2fd0c671 JB |
3360 | return 0; |
3361 | } | |
3362 | ||
5530c04c JK |
3363 | static int mac80211_hwsim_send_pmsr_ftm_request_peer(struct sk_buff *msg, |
3364 | struct cfg80211_pmsr_ftm_request_peer *request) | |
3365 | { | |
3366 | struct nlattr *ftm; | |
3367 | ||
3368 | if (!request->requested) | |
3369 | return -EINVAL; | |
3370 | ||
3371 | ftm = nla_nest_start(msg, NL80211_PMSR_TYPE_FTM); | |
3372 | if (!ftm) | |
3373 | return -ENOBUFS; | |
3374 | ||
3375 | if (nla_put_u32(msg, NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE, request->preamble)) | |
3376 | return -ENOBUFS; | |
3377 | ||
3378 | if (nla_put_u16(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD, request->burst_period)) | |
3379 | return -ENOBUFS; | |
3380 | ||
3381 | if (request->asap && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_ASAP)) | |
3382 | return -ENOBUFS; | |
3383 | ||
3384 | if (request->request_lci && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI)) | |
3385 | return -ENOBUFS; | |
3386 | ||
3387 | if (request->request_civicloc && | |
3388 | nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC)) | |
3389 | return -ENOBUFS; | |
3390 | ||
3391 | if (request->trigger_based && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED)) | |
3392 | return -ENOBUFS; | |
3393 | ||
3394 | if (request->non_trigger_based && | |
3395 | nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED)) | |
3396 | return -ENOBUFS; | |
3397 | ||
3398 | if (request->lmr_feedback && nla_put_flag(msg, NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK)) | |
3399 | return -ENOBUFS; | |
3400 | ||
3401 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP, request->num_bursts_exp)) | |
3402 | return -ENOBUFS; | |
3403 | ||
3404 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration)) | |
3405 | return -ENOBUFS; | |
3406 | ||
3407 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST, request->ftms_per_burst)) | |
3408 | return -ENOBUFS; | |
3409 | ||
3410 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES, request->ftmr_retries)) | |
3411 | return -ENOBUFS; | |
3412 | ||
3413 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION, request->burst_duration)) | |
3414 | return -ENOBUFS; | |
3415 | ||
3416 | if (nla_put_u8(msg, NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR, request->bss_color)) | |
3417 | return -ENOBUFS; | |
3418 | ||
3419 | nla_nest_end(msg, ftm); | |
3420 | ||
3421 | return 0; | |
3422 | } | |
3423 | ||
3424 | static int mac80211_hwsim_send_pmsr_request_peer(struct sk_buff *msg, | |
3425 | struct cfg80211_pmsr_request_peer *request) | |
3426 | { | |
3427 | struct nlattr *peer, *chandef, *req, *data; | |
3428 | int err; | |
3429 | ||
3430 | peer = nla_nest_start(msg, NL80211_PMSR_ATTR_PEERS); | |
3431 | if (!peer) | |
3432 | return -ENOBUFS; | |
3433 | ||
3434 | if (nla_put(msg, NL80211_PMSR_PEER_ATTR_ADDR, ETH_ALEN, | |
3435 | request->addr)) | |
3436 | return -ENOBUFS; | |
3437 | ||
3438 | chandef = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_CHAN); | |
3439 | if (!chandef) | |
3440 | return -ENOBUFS; | |
3441 | ||
3442 | err = nl80211_send_chandef(msg, &request->chandef); | |
3443 | if (err) | |
3444 | return err; | |
3445 | ||
3446 | nla_nest_end(msg, chandef); | |
3447 | ||
3448 | req = nla_nest_start(msg, NL80211_PMSR_PEER_ATTR_REQ); | |
3449 | if (!req) | |
3450 | return -ENOBUFS; | |
3451 | ||
3452 | if (request->report_ap_tsf && nla_put_flag(msg, NL80211_PMSR_REQ_ATTR_GET_AP_TSF)) | |
3453 | return -ENOBUFS; | |
3454 | ||
3455 | data = nla_nest_start(msg, NL80211_PMSR_REQ_ATTR_DATA); | |
3456 | if (!data) | |
3457 | return -ENOBUFS; | |
3458 | ||
3459 | err = mac80211_hwsim_send_pmsr_ftm_request_peer(msg, &request->ftm); | |
3460 | if (err) | |
3461 | return err; | |
3462 | ||
3463 | nla_nest_end(msg, data); | |
3464 | nla_nest_end(msg, req); | |
3465 | nla_nest_end(msg, peer); | |
3466 | ||
3467 | return 0; | |
3468 | } | |
3469 | ||
3470 | static int mac80211_hwsim_send_pmsr_request(struct sk_buff *msg, | |
3471 | struct cfg80211_pmsr_request *request) | |
3472 | { | |
3473 | struct nlattr *pmsr; | |
3474 | int err; | |
3475 | ||
3476 | pmsr = nla_nest_start(msg, NL80211_ATTR_PEER_MEASUREMENTS); | |
3477 | if (!pmsr) | |
3478 | return -ENOBUFS; | |
3479 | ||
3480 | if (nla_put_u32(msg, NL80211_ATTR_TIMEOUT, request->timeout)) | |
3481 | return -ENOBUFS; | |
3482 | ||
3483 | if (!is_zero_ether_addr(request->mac_addr)) { | |
3484 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, request->mac_addr)) | |
3485 | return -ENOBUFS; | |
3486 | if (nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, request->mac_addr_mask)) | |
3487 | return -ENOBUFS; | |
3488 | } | |
3489 | ||
3490 | for (int i = 0; i < request->n_peers; i++) { | |
3491 | err = mac80211_hwsim_send_pmsr_request_peer(msg, &request->peers[i]); | |
3492 | if (err) | |
3493 | return err; | |
3494 | } | |
3495 | ||
3496 | nla_nest_end(msg, pmsr); | |
3497 | ||
3498 | return 0; | |
3499 | } | |
3500 | ||
3501 | static int mac80211_hwsim_start_pmsr(struct ieee80211_hw *hw, | |
3502 | struct ieee80211_vif *vif, | |
3503 | struct cfg80211_pmsr_request *request) | |
3504 | { | |
3505 | struct mac80211_hwsim_data *data; | |
3506 | struct sk_buff *skb = NULL; | |
3507 | struct nlattr *pmsr; | |
3508 | void *msg_head; | |
3509 | u32 _portid; | |
3510 | int err = 0; | |
3511 | ||
3512 | data = hw->priv; | |
3513 | _portid = READ_ONCE(data->wmediumd); | |
3514 | if (!_portid && !hwsim_virtio_enabled) | |
3515 | return -EOPNOTSUPP; | |
3516 | ||
3517 | mutex_lock(&data->mutex); | |
3518 | ||
3519 | if (data->pmsr_request) { | |
3520 | err = -EBUSY; | |
3521 | goto out_free; | |
3522 | } | |
3523 | ||
3524 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
3525 | ||
3526 | if (!skb) { | |
3527 | err = -ENOMEM; | |
3528 | goto out_free; | |
3529 | } | |
3530 | ||
3531 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_START_PMSR); | |
3532 | ||
3533 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, | |
3534 | ETH_ALEN, data->addresses[1].addr)) { | |
3535 | err = -ENOMEM; | |
3536 | goto out_free; | |
3537 | } | |
3538 | ||
3539 | pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST); | |
3540 | if (!pmsr) { | |
3541 | err = -ENOMEM; | |
3542 | goto out_free; | |
3543 | } | |
3544 | ||
3545 | err = mac80211_hwsim_send_pmsr_request(skb, request); | |
3546 | if (err) | |
3547 | goto out_free; | |
3548 | ||
3549 | nla_nest_end(skb, pmsr); | |
3550 | ||
3551 | genlmsg_end(skb, msg_head); | |
3552 | if (hwsim_virtio_enabled) | |
3553 | hwsim_tx_virtio(data, skb); | |
3554 | else | |
3555 | hwsim_unicast_netgroup(data, skb, _portid); | |
3556 | ||
3557 | data->pmsr_request = request; | |
3558 | data->pmsr_request_wdev = ieee80211_vif_to_wdev(vif); | |
3559 | ||
3560 | out_free: | |
3561 | if (err && skb) | |
3562 | nlmsg_free(skb); | |
3563 | ||
3564 | mutex_unlock(&data->mutex); | |
3565 | return err; | |
3566 | } | |
3567 | ||
8ba1da95 JK |
3568 | static void mac80211_hwsim_abort_pmsr(struct ieee80211_hw *hw, |
3569 | struct ieee80211_vif *vif, | |
3570 | struct cfg80211_pmsr_request *request) | |
3571 | { | |
3572 | struct mac80211_hwsim_data *data; | |
3573 | struct sk_buff *skb = NULL; | |
3574 | struct nlattr *pmsr; | |
3575 | void *msg_head; | |
3576 | u32 _portid; | |
3577 | int err = 0; | |
3578 | ||
3579 | data = hw->priv; | |
3580 | _portid = READ_ONCE(data->wmediumd); | |
3581 | if (!_portid && !hwsim_virtio_enabled) | |
3582 | return; | |
3583 | ||
3584 | mutex_lock(&data->mutex); | |
3585 | ||
3586 | if (data->pmsr_request != request) { | |
3587 | err = -EINVAL; | |
3588 | goto out; | |
3589 | } | |
3590 | ||
3591 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
3592 | if (!skb) { | |
3593 | err = -ENOMEM; | |
3594 | goto out; | |
3595 | } | |
3596 | ||
3597 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, HWSIM_CMD_ABORT_PMSR); | |
3598 | ||
3599 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, ETH_ALEN, data->addresses[1].addr)) | |
3600 | goto out; | |
3601 | ||
3602 | pmsr = nla_nest_start(skb, HWSIM_ATTR_PMSR_REQUEST); | |
3603 | if (!pmsr) { | |
3604 | err = -ENOMEM; | |
3605 | goto out; | |
3606 | } | |
3607 | ||
3608 | err = mac80211_hwsim_send_pmsr_request(skb, request); | |
3609 | if (err) | |
3610 | goto out; | |
3611 | ||
3612 | err = nla_nest_end(skb, pmsr); | |
3613 | if (err) | |
3614 | goto out; | |
3615 | ||
3616 | genlmsg_end(skb, msg_head); | |
3617 | if (hwsim_virtio_enabled) | |
3618 | hwsim_tx_virtio(data, skb); | |
3619 | else | |
3620 | hwsim_unicast_netgroup(data, skb, _portid); | |
3621 | ||
3622 | out: | |
3623 | if (err && skb) | |
3624 | nlmsg_free(skb); | |
3625 | ||
3626 | mutex_unlock(&data->mutex); | |
3627 | } | |
3628 | ||
2af3b2a6 JK |
3629 | static int mac80211_hwsim_parse_rate_info(struct nlattr *rateattr, |
3630 | struct rate_info *rate_info, | |
3631 | struct genl_info *info) | |
3632 | { | |
3633 | struct nlattr *tb[HWSIM_RATE_INFO_ATTR_MAX + 1]; | |
3634 | int ret; | |
3635 | ||
3636 | ret = nla_parse_nested(tb, HWSIM_RATE_INFO_ATTR_MAX, | |
3637 | rateattr, hwsim_rate_info_policy, info->extack); | |
3638 | if (ret) | |
3639 | return ret; | |
3640 | ||
3641 | if (tb[HWSIM_RATE_INFO_ATTR_FLAGS]) | |
3642 | rate_info->flags = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_FLAGS]); | |
3643 | ||
3644 | if (tb[HWSIM_RATE_INFO_ATTR_MCS]) | |
3645 | rate_info->mcs = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_MCS]); | |
3646 | ||
3647 | if (tb[HWSIM_RATE_INFO_ATTR_LEGACY]) | |
3648 | rate_info->legacy = nla_get_u16(tb[HWSIM_RATE_INFO_ATTR_LEGACY]); | |
3649 | ||
3650 | if (tb[HWSIM_RATE_INFO_ATTR_NSS]) | |
3651 | rate_info->nss = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_NSS]); | |
3652 | ||
3653 | if (tb[HWSIM_RATE_INFO_ATTR_BW]) | |
3654 | rate_info->bw = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_BW]); | |
3655 | ||
3656 | if (tb[HWSIM_RATE_INFO_ATTR_HE_GI]) | |
3657 | rate_info->he_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_GI]); | |
3658 | ||
3659 | if (tb[HWSIM_RATE_INFO_ATTR_HE_DCM]) | |
3660 | rate_info->he_dcm = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_DCM]); | |
3661 | ||
3662 | if (tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC]) | |
3663 | rate_info->he_ru_alloc = | |
3664 | nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_HE_RU_ALLOC]); | |
3665 | ||
3666 | if (tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH]) | |
3667 | rate_info->n_bonded_ch = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_N_BOUNDED_CH]); | |
3668 | ||
3669 | if (tb[HWSIM_RATE_INFO_ATTR_EHT_GI]) | |
3670 | rate_info->eht_gi = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_GI]); | |
3671 | ||
3672 | if (tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC]) | |
3673 | rate_info->eht_ru_alloc = nla_get_u8(tb[HWSIM_RATE_INFO_ATTR_EHT_RU_ALLOC]); | |
3674 | ||
3675 | return 0; | |
3676 | } | |
3677 | ||
3678 | static int mac80211_hwsim_parse_ftm_result(struct nlattr *ftm, | |
3679 | struct cfg80211_pmsr_ftm_result *result, | |
3680 | struct genl_info *info) | |
3681 | { | |
3682 | struct nlattr *tb[NL80211_PMSR_FTM_RESP_ATTR_MAX + 1]; | |
3683 | int ret; | |
3684 | ||
3685 | ret = nla_parse_nested(tb, NL80211_PMSR_FTM_RESP_ATTR_MAX, | |
3686 | ftm, hwsim_ftm_result_policy, info->extack); | |
3687 | if (ret) | |
3688 | return ret; | |
3689 | ||
3690 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON]) | |
3691 | result->failure_reason = nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON]); | |
3692 | ||
3693 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX]) | |
3694 | result->burst_index = nla_get_u16(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX]); | |
3695 | ||
3696 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]) { | |
3697 | result->num_ftmr_attempts_valid = 1; | |
3698 | result->num_ftmr_attempts = | |
3699 | nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS]); | |
3700 | } | |
3701 | ||
3702 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]) { | |
3703 | result->num_ftmr_successes_valid = 1; | |
3704 | result->num_ftmr_successes = | |
3705 | nla_get_u32(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES]); | |
3706 | } | |
3707 | ||
3708 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME]) | |
3709 | result->busy_retry_time = | |
3710 | nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME]); | |
3711 | ||
3712 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP]) | |
3713 | result->num_bursts_exp = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP]); | |
3714 | ||
3715 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION]) | |
3716 | result->burst_duration = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION]); | |
3717 | ||
3718 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST]) | |
3719 | result->ftms_per_burst = nla_get_u8(tb[NL80211_PMSR_FTM_RESP_ATTR_FTMS_PER_BURST]); | |
3720 | ||
3721 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]) { | |
3722 | result->rssi_avg_valid = 1; | |
3723 | result->rssi_avg = nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG]); | |
3724 | } | |
3725 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]) { | |
3726 | result->rssi_spread_valid = 1; | |
3727 | result->rssi_spread = | |
3728 | nla_get_s32(tb[NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD]); | |
3729 | } | |
3730 | ||
3731 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE]) { | |
3732 | result->tx_rate_valid = 1; | |
3733 | ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_TX_RATE], | |
3734 | &result->tx_rate, info); | |
3735 | if (ret) | |
3736 | return ret; | |
3737 | } | |
3738 | ||
3739 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE]) { | |
3740 | result->rx_rate_valid = 1; | |
3741 | ret = mac80211_hwsim_parse_rate_info(tb[NL80211_PMSR_FTM_RESP_ATTR_RX_RATE], | |
3742 | &result->rx_rate, info); | |
3743 | if (ret) | |
3744 | return ret; | |
3745 | } | |
3746 | ||
3747 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]) { | |
3748 | result->rtt_avg_valid = 1; | |
3749 | result->rtt_avg = | |
3750 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG]); | |
3751 | } | |
3752 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]) { | |
3753 | result->rtt_variance_valid = 1; | |
3754 | result->rtt_variance = | |
3755 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE]); | |
3756 | } | |
3757 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]) { | |
3758 | result->rtt_spread_valid = 1; | |
3759 | result->rtt_spread = | |
3760 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD]); | |
3761 | } | |
3762 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]) { | |
3763 | result->dist_avg_valid = 1; | |
3764 | result->dist_avg = | |
3765 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG]); | |
3766 | } | |
3767 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]) { | |
3768 | result->dist_variance_valid = 1; | |
3769 | result->dist_variance = | |
3770 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE]); | |
3771 | } | |
3772 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]) { | |
3773 | result->dist_spread_valid = 1; | |
3774 | result->dist_spread = | |
3775 | nla_get_u64(tb[NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD]); | |
3776 | } | |
3777 | ||
3778 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]) { | |
3779 | result->lci = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]); | |
3780 | result->lci_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_LCI]); | |
3781 | } | |
3782 | ||
3783 | if (tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]) { | |
3784 | result->civicloc = nla_data(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]); | |
3785 | result->civicloc_len = nla_len(tb[NL80211_PMSR_FTM_RESP_ATTR_CIVICLOC]); | |
3786 | } | |
3787 | ||
3788 | return 0; | |
3789 | } | |
3790 | ||
3791 | static int mac80211_hwsim_parse_pmsr_resp(struct nlattr *resp, | |
3792 | struct cfg80211_pmsr_result *result, | |
3793 | struct genl_info *info) | |
3794 | { | |
3795 | struct nlattr *tb[NL80211_PMSR_RESP_ATTR_MAX + 1]; | |
3796 | struct nlattr *pmsr; | |
3797 | int rem; | |
3798 | int ret; | |
3799 | ||
3800 | ret = nla_parse_nested(tb, NL80211_PMSR_RESP_ATTR_MAX, resp, hwsim_pmsr_resp_policy, | |
3801 | info->extack); | |
3802 | if (ret) | |
3803 | return ret; | |
3804 | ||
3805 | if (tb[NL80211_PMSR_RESP_ATTR_STATUS]) | |
3806 | result->status = nla_get_u32(tb[NL80211_PMSR_RESP_ATTR_STATUS]); | |
3807 | ||
3808 | if (tb[NL80211_PMSR_RESP_ATTR_HOST_TIME]) | |
3809 | result->host_time = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_HOST_TIME]); | |
3810 | ||
3811 | if (tb[NL80211_PMSR_RESP_ATTR_AP_TSF]) { | |
3812 | result->ap_tsf_valid = 1; | |
3813 | result->ap_tsf = nla_get_u64(tb[NL80211_PMSR_RESP_ATTR_AP_TSF]); | |
3814 | } | |
3815 | ||
3816 | result->final = !!tb[NL80211_PMSR_RESP_ATTR_FINAL]; | |
3817 | ||
3818 | if (!tb[NL80211_PMSR_RESP_ATTR_DATA]) | |
3819 | return 0; | |
3820 | ||
3821 | nla_for_each_nested(pmsr, tb[NL80211_PMSR_RESP_ATTR_DATA], rem) { | |
3822 | switch (nla_type(pmsr)) { | |
3823 | case NL80211_PMSR_TYPE_FTM: | |
3824 | result->type = NL80211_PMSR_TYPE_FTM; | |
3825 | ret = mac80211_hwsim_parse_ftm_result(pmsr, &result->ftm, info); | |
3826 | if (ret) | |
3827 | return ret; | |
3828 | break; | |
3829 | default: | |
3830 | NL_SET_ERR_MSG_ATTR(info->extack, pmsr, "Unknown pmsr resp type"); | |
3831 | return -EINVAL; | |
3832 | } | |
3833 | } | |
3834 | ||
3835 | return 0; | |
3836 | } | |
3837 | ||
3838 | static int mac80211_hwsim_parse_pmsr_result(struct nlattr *peer, | |
3839 | struct cfg80211_pmsr_result *result, | |
3840 | struct genl_info *info) | |
3841 | { | |
3842 | struct nlattr *tb[NL80211_PMSR_PEER_ATTR_MAX + 1]; | |
3843 | int ret; | |
3844 | ||
3845 | if (!peer) | |
3846 | return -EINVAL; | |
3847 | ||
3848 | ret = nla_parse_nested(tb, NL80211_PMSR_PEER_ATTR_MAX, peer, | |
3849 | hwsim_pmsr_peer_result_policy, info->extack); | |
3850 | if (ret) | |
3851 | return ret; | |
3852 | ||
3853 | if (tb[NL80211_PMSR_PEER_ATTR_ADDR]) | |
3854 | memcpy(result->addr, nla_data(tb[NL80211_PMSR_PEER_ATTR_ADDR]), | |
3855 | ETH_ALEN); | |
3856 | ||
3857 | if (tb[NL80211_PMSR_PEER_ATTR_RESP]) { | |
3858 | ret = mac80211_hwsim_parse_pmsr_resp(tb[NL80211_PMSR_PEER_ATTR_RESP], result, info); | |
3859 | if (ret) | |
3860 | return ret; | |
3861 | } | |
3862 | ||
3863 | return 0; | |
3864 | }; | |
3865 | ||
3866 | static int hwsim_pmsr_report_nl(struct sk_buff *msg, struct genl_info *info) | |
3867 | { | |
3868 | struct mac80211_hwsim_data *data; | |
3869 | struct nlattr *peers, *peer; | |
3870 | struct nlattr *reqattr; | |
3871 | const u8 *src; | |
3872 | int err; | |
3873 | int rem; | |
3874 | ||
2bef4d1f ED |
3875 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]) |
3876 | return -EINVAL; | |
3877 | ||
2af3b2a6 JK |
3878 | src = nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); |
3879 | data = get_hwsim_data_ref_from_addr(src); | |
3880 | if (!data) | |
3881 | return -EINVAL; | |
3882 | ||
3883 | mutex_lock(&data->mutex); | |
3884 | if (!data->pmsr_request) { | |
3885 | err = -EINVAL; | |
3886 | goto out; | |
3887 | } | |
3888 | ||
3889 | reqattr = info->attrs[HWSIM_ATTR_PMSR_RESULT]; | |
3890 | if (!reqattr) { | |
3891 | err = -EINVAL; | |
3892 | goto out; | |
3893 | } | |
3894 | ||
3895 | peers = nla_find_nested(reqattr, NL80211_PMSR_ATTR_PEERS); | |
3896 | if (!peers) { | |
3897 | err = -EINVAL; | |
3898 | goto out; | |
3899 | } | |
3900 | ||
3901 | nla_for_each_nested(peer, peers, rem) { | |
2a4e01e5 | 3902 | struct cfg80211_pmsr_result result = {}; |
2af3b2a6 JK |
3903 | |
3904 | err = mac80211_hwsim_parse_pmsr_result(peer, &result, info); | |
3905 | if (err) | |
3906 | goto out; | |
3907 | ||
3908 | cfg80211_pmsr_report(data->pmsr_request_wdev, | |
3909 | data->pmsr_request, &result, GFP_KERNEL); | |
3910 | } | |
3911 | ||
3912 | cfg80211_pmsr_complete(data->pmsr_request_wdev, data->pmsr_request, GFP_KERNEL); | |
3913 | ||
3914 | err = 0; | |
3915 | out: | |
3916 | data->pmsr_request = NULL; | |
3917 | data->pmsr_request_wdev = NULL; | |
3918 | ||
3919 | mutex_unlock(&data->mutex); | |
3920 | return err; | |
3921 | } | |
3922 | ||
7d366663 JB |
3923 | #ifdef CONFIG_MAC80211_DEBUGFS |
3924 | #define HWSIM_DEBUGFS_OPS \ | |
3925 | .vif_add_debugfs = mac80211_hwsim_vif_add_debugfs, | |
3926 | #else | |
3927 | #define HWSIM_DEBUGFS_OPS | |
3928 | #endif | |
3929 | ||
246ad56e JB |
3930 | #define HWSIM_COMMON_OPS \ |
3931 | .tx = mac80211_hwsim_tx, \ | |
a790cc3a | 3932 | .wake_tx_queue = ieee80211_handle_wake_tx_queue, \ |
246ad56e JB |
3933 | .start = mac80211_hwsim_start, \ |
3934 | .stop = mac80211_hwsim_stop, \ | |
3935 | .add_interface = mac80211_hwsim_add_interface, \ | |
3936 | .change_interface = mac80211_hwsim_change_interface, \ | |
3937 | .remove_interface = mac80211_hwsim_remove_interface, \ | |
3938 | .config = mac80211_hwsim_config, \ | |
3939 | .configure_filter = mac80211_hwsim_configure_filter, \ | |
7a52107e ST |
3940 | .vif_cfg_changed = mac80211_hwsim_vif_info_changed, \ |
3941 | .link_info_changed = mac80211_hwsim_link_info_changed, \ | |
bdee75d2 | 3942 | .tx_last_beacon = mac80211_hwsim_tx_last_beacon, \ |
246ad56e | 3943 | .sta_notify = mac80211_hwsim_sta_notify, \ |
585625c9 | 3944 | .sta_rc_update = mac80211_hwsim_sta_rc_update, \ |
246ad56e JB |
3945 | .conf_tx = mac80211_hwsim_conf_tx, \ |
3946 | .get_survey = mac80211_hwsim_get_survey, \ | |
3947 | CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) \ | |
3948 | .ampdu_action = mac80211_hwsim_ampdu_action, \ | |
3949 | .flush = mac80211_hwsim_flush, \ | |
246ad56e JB |
3950 | .get_et_sset_count = mac80211_hwsim_get_et_sset_count, \ |
3951 | .get_et_stats = mac80211_hwsim_get_et_stats, \ | |
5530c04c JK |
3952 | .get_et_strings = mac80211_hwsim_get_et_strings, \ |
3953 | .start_pmsr = mac80211_hwsim_start_pmsr, \ | |
7d366663 JB |
3954 | .abort_pmsr = mac80211_hwsim_abort_pmsr, \ |
3955 | HWSIM_DEBUGFS_OPS | |
246ad56e | 3956 | |
2fd0c671 | 3957 | #define HWSIM_NON_MLO_OPS \ |
d46ffecf JB |
3958 | .sta_add = mac80211_hwsim_sta_add, \ |
3959 | .sta_remove = mac80211_hwsim_sta_remove, \ | |
2fd0c671 JB |
3960 | .set_tim = mac80211_hwsim_set_tim, \ |
3961 | .get_tsf = mac80211_hwsim_get_tsf, \ | |
3962 | .set_tsf = mac80211_hwsim_set_tsf, | |
3963 | ||
38ed5048 | 3964 | static const struct ieee80211_ops mac80211_hwsim_ops = { |
246ad56e | 3965 | HWSIM_COMMON_OPS |
2fd0c671 | 3966 | HWSIM_NON_MLO_OPS |
f74cb0f7 LR |
3967 | .sw_scan_start = mac80211_hwsim_sw_scan, |
3968 | .sw_scan_complete = mac80211_hwsim_sw_scan_complete, | |
0a44dfc0 JB |
3969 | .add_chanctx = ieee80211_emulate_add_chanctx, |
3970 | .remove_chanctx = ieee80211_emulate_remove_chanctx, | |
3971 | .change_chanctx = ieee80211_emulate_change_chanctx, | |
3972 | .switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx, | |
acc1e7a3 JM |
3973 | }; |
3974 | ||
2fd0c671 JB |
3975 | #define HWSIM_CHANCTX_OPS \ |
3976 | .hw_scan = mac80211_hwsim_hw_scan, \ | |
3977 | .cancel_hw_scan = mac80211_hwsim_cancel_hw_scan, \ | |
3978 | .remain_on_channel = mac80211_hwsim_roc, \ | |
3979 | .cancel_remain_on_channel = mac80211_hwsim_croc, \ | |
3980 | .add_chanctx = mac80211_hwsim_add_chanctx, \ | |
3981 | .remove_chanctx = mac80211_hwsim_remove_chanctx, \ | |
3982 | .change_chanctx = mac80211_hwsim_change_chanctx, \ | |
3983 | .assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx,\ | |
7f501452 AKS |
3984 | .unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx, \ |
3985 | .switch_vif_chanctx = mac80211_hwsim_switch_vif_chanctx, | |
2fd0c671 | 3986 | |
246ad56e JB |
3987 | static const struct ieee80211_ops mac80211_hwsim_mchan_ops = { |
3988 | HWSIM_COMMON_OPS | |
2fd0c671 JB |
3989 | HWSIM_NON_MLO_OPS |
3990 | HWSIM_CHANCTX_OPS | |
3991 | }; | |
3992 | ||
3993 | static const struct ieee80211_ops mac80211_hwsim_mlo_ops = { | |
3994 | HWSIM_COMMON_OPS | |
3995 | HWSIM_CHANCTX_OPS | |
3996 | .set_rts_threshold = mac80211_hwsim_set_rts_threshold, | |
3997 | .change_vif_links = mac80211_hwsim_change_vif_links, | |
3998 | .change_sta_links = mac80211_hwsim_change_sta_links, | |
d46ffecf | 3999 | .sta_state = mac80211_hwsim_sta_state, |
03d51102 | 4000 | .can_neg_ttlm = mac80211_hwsim_can_neg_ttlm, |
246ad56e | 4001 | }; |
acc1e7a3 | 4002 | |
62759361 JR |
4003 | struct hwsim_new_radio_params { |
4004 | unsigned int channels; | |
4005 | const char *reg_alpha2; | |
4006 | const struct ieee80211_regdomain *regd; | |
4007 | bool reg_strict; | |
4008 | bool p2p_device; | |
4009 | bool use_chanctx; | |
4010 | bool destroy_on_close; | |
4011 | const char *hwname; | |
4012 | bool no_vif; | |
cb1a5bae | 4013 | const u8 *perm_addr; |
99e3a44b | 4014 | u32 iftypes; |
c0a0189d JP |
4015 | u32 *ciphers; |
4016 | u8 n_ciphers; | |
2fd0c671 | 4017 | bool mlo; |
92d13386 | 4018 | const struct cfg80211_pmsr_capabilities *pmsr_capa; |
62759361 JR |
4019 | }; |
4020 | ||
4021 | static void hwsim_mcast_config_msg(struct sk_buff *mcast_skb, | |
4022 | struct genl_info *info) | |
4023 | { | |
4024 | if (info) | |
92c14d9b JB |
4025 | genl_notify(&hwsim_genl_family, mcast_skb, info, |
4026 | HWSIM_MCGRP_CONFIG, GFP_KERNEL); | |
62759361 JR |
4027 | else |
4028 | genlmsg_multicast(&hwsim_genl_family, mcast_skb, 0, | |
4029 | HWSIM_MCGRP_CONFIG, GFP_KERNEL); | |
4030 | } | |
4031 | ||
c449981c PF |
4032 | static int append_radio_msg(struct sk_buff *skb, int id, |
4033 | struct hwsim_new_radio_params *param) | |
62759361 | 4034 | { |
62759361 JR |
4035 | int ret; |
4036 | ||
62759361 JR |
4037 | ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id); |
4038 | if (ret < 0) | |
c449981c | 4039 | return ret; |
62759361 JR |
4040 | |
4041 | if (param->channels) { | |
4042 | ret = nla_put_u32(skb, HWSIM_ATTR_CHANNELS, param->channels); | |
4043 | if (ret < 0) | |
c449981c | 4044 | return ret; |
62759361 JR |
4045 | } |
4046 | ||
4047 | if (param->reg_alpha2) { | |
4048 | ret = nla_put(skb, HWSIM_ATTR_REG_HINT_ALPHA2, 2, | |
4049 | param->reg_alpha2); | |
4050 | if (ret < 0) | |
c449981c | 4051 | return ret; |
62759361 JR |
4052 | } |
4053 | ||
4054 | if (param->regd) { | |
4055 | int i; | |
4056 | ||
5875755c JB |
4057 | for (i = 0; i < ARRAY_SIZE(hwsim_world_regdom_custom); i++) { |
4058 | if (hwsim_world_regdom_custom[i] != param->regd) | |
4059 | continue; | |
62759361 | 4060 | |
62759361 JR |
4061 | ret = nla_put_u32(skb, HWSIM_ATTR_REG_CUSTOM_REG, i); |
4062 | if (ret < 0) | |
c449981c | 4063 | return ret; |
5875755c | 4064 | break; |
62759361 JR |
4065 | } |
4066 | } | |
4067 | ||
4068 | if (param->reg_strict) { | |
4069 | ret = nla_put_flag(skb, HWSIM_ATTR_REG_STRICT_REG); | |
4070 | if (ret < 0) | |
c449981c | 4071 | return ret; |
62759361 JR |
4072 | } |
4073 | ||
4074 | if (param->p2p_device) { | |
4075 | ret = nla_put_flag(skb, HWSIM_ATTR_SUPPORT_P2P_DEVICE); | |
4076 | if (ret < 0) | |
c449981c | 4077 | return ret; |
62759361 JR |
4078 | } |
4079 | ||
4080 | if (param->use_chanctx) { | |
4081 | ret = nla_put_flag(skb, HWSIM_ATTR_USE_CHANCTX); | |
4082 | if (ret < 0) | |
c449981c | 4083 | return ret; |
62759361 JR |
4084 | } |
4085 | ||
4086 | if (param->hwname) { | |
4087 | ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, | |
4088 | strlen(param->hwname), param->hwname); | |
4089 | if (ret < 0) | |
c449981c | 4090 | return ret; |
62759361 JR |
4091 | } |
4092 | ||
c449981c | 4093 | return 0; |
62759361 JR |
4094 | } |
4095 | ||
c449981c | 4096 | static void hwsim_mcast_new_radio(int id, struct genl_info *info, |
62759361 JR |
4097 | struct hwsim_new_radio_params *param) |
4098 | { | |
4099 | struct sk_buff *mcast_skb; | |
c449981c | 4100 | void *data; |
62759361 | 4101 | |
c449981c | 4102 | mcast_skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); |
62759361 JR |
4103 | if (!mcast_skb) |
4104 | return; | |
4105 | ||
c449981c PF |
4106 | data = genlmsg_put(mcast_skb, 0, 0, &hwsim_genl_family, 0, |
4107 | HWSIM_CMD_NEW_RADIO); | |
4108 | if (!data) | |
4109 | goto out_err; | |
4110 | ||
4111 | if (append_radio_msg(mcast_skb, id, param) < 0) | |
4112 | goto out_err; | |
4113 | ||
4114 | genlmsg_end(mcast_skb, data); | |
4115 | ||
62759361 | 4116 | hwsim_mcast_config_msg(mcast_skb, info); |
c449981c PF |
4117 | return; |
4118 | ||
4119 | out_err: | |
c449981c | 4120 | nlmsg_free(mcast_skb); |
62759361 JR |
4121 | } |
4122 | ||
ea0de861 | 4123 | static const struct ieee80211_sband_iftype_data sband_capa_2ghz[] = { |
b697746c | 4124 | { |
4992b360 JB |
4125 | .types_mask = BIT(NL80211_IFTYPE_STATION), |
4126 | .he_cap = { | |
4127 | .has_he = true, | |
4128 | .he_cap_elem = { | |
4129 | .mac_cap_info[0] = | |
4130 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4131 | .mac_cap_info[1] = | |
4132 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4133 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4134 | .mac_cap_info[2] = | |
4135 | IEEE80211_HE_MAC_CAP2_BSR | | |
4136 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4137 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4138 | .mac_cap_info[3] = | |
4139 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
4140 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, | |
4141 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, | |
ce10e865 MK |
4142 | .phy_cap_info[0] = |
4143 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G, | |
4992b360 JB |
4144 | .phy_cap_info[1] = |
4145 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4146 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4147 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4148 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4149 | .phy_cap_info[2] = | |
4150 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4151 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4152 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4153 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4154 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4155 | ||
4156 | /* Leave all the other PHY capability bytes | |
4157 | * unset, as DCM, beam forming, RU and PPE | |
4158 | * threshold information are not supported | |
4159 | */ | |
4160 | }, | |
4161 | .he_mcs_nss_supp = { | |
4162 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4163 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4164 | .rx_mcs_160 = cpu_to_le16(0xffff), | |
4165 | .tx_mcs_160 = cpu_to_le16(0xffff), | |
4166 | .rx_mcs_80p80 = cpu_to_le16(0xffff), | |
4167 | .tx_mcs_80p80 = cpu_to_le16(0xffff), | |
4168 | }, | |
4169 | }, | |
4170 | .eht_cap = { | |
4171 | .has_eht = true, | |
4172 | .eht_cap_elem = { | |
4173 | .mac_cap_info[0] = | |
4174 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | | |
4175 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | | |
4176 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4177 | .phy_cap_info[0] = | |
4178 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4179 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4180 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4181 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4182 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE, | |
4183 | .phy_cap_info[3] = | |
4184 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4185 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4186 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4187 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4188 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4189 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4190 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4191 | .phy_cap_info[4] = | |
4192 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4193 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4194 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4195 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4196 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4197 | .phy_cap_info[5] = | |
4198 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4199 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4200 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4201 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4202 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4203 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4204 | .phy_cap_info[6] = | |
4205 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4206 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK, | |
4207 | .phy_cap_info[7] = | |
4208 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW, | |
4209 | }, | |
4210 | ||
4211 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4212 | * Rx | |
4213 | */ | |
4214 | .eht_mcs_nss_supp = { | |
4215 | /* | |
4216 | * Since B0, B1, B2 and B3 are not set in | |
4217 | * the supported channel width set field in the | |
4218 | * HE PHY capabilities information field the | |
4219 | * device is a 20MHz only device on 2.4GHz band. | |
4220 | */ | |
4221 | .only_20mhz = { | |
4222 | .rx_tx_mcs7_max_nss = 0x88, | |
4223 | .rx_tx_mcs9_max_nss = 0x88, | |
4224 | .rx_tx_mcs11_max_nss = 0x88, | |
4225 | .rx_tx_mcs13_max_nss = 0x88, | |
4226 | }, | |
4227 | }, | |
4228 | /* PPE threshold information is not supported */ | |
4229 | }, | |
4230 | }, | |
4231 | { | |
4232 | .types_mask = BIT(NL80211_IFTYPE_AP), | |
b697746c SE |
4233 | .he_cap = { |
4234 | .has_he = true, | |
4235 | .he_cap_elem = { | |
4236 | .mac_cap_info[0] = | |
4237 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4238 | .mac_cap_info[1] = | |
4239 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4240 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4241 | .mac_cap_info[2] = | |
4242 | IEEE80211_HE_MAC_CAP2_BSR | | |
4243 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4244 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4245 | .mac_cap_info[3] = | |
4246 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
1f851b8d | 4247 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, |
2f516444 | 4248 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, |
ce10e865 MK |
4249 | .phy_cap_info[0] = |
4250 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G, | |
b697746c SE |
4251 | .phy_cap_info[1] = |
4252 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4253 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4254 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4255 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4256 | .phy_cap_info[2] = | |
4257 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4258 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4259 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4260 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4261 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4262 | ||
4263 | /* Leave all the other PHY capability bytes | |
4264 | * unset, as DCM, beam forming, RU and PPE | |
4265 | * threshold information are not supported | |
4266 | */ | |
4267 | }, | |
4268 | .he_mcs_nss_supp = { | |
4269 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4270 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4271 | .rx_mcs_160 = cpu_to_le16(0xffff), | |
4272 | .tx_mcs_160 = cpu_to_le16(0xffff), | |
4273 | .rx_mcs_80p80 = cpu_to_le16(0xffff), | |
4274 | .tx_mcs_80p80 = cpu_to_le16(0xffff), | |
4275 | }, | |
518ea3c5 | 4276 | }, |
ea0de861 IP |
4277 | .eht_cap = { |
4278 | .has_eht = true, | |
4279 | .eht_cap_elem = { | |
4280 | .mac_cap_info[0] = | |
062e8e02 | 4281 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | |
ea0de861 IP |
4282 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | |
4283 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4284 | .phy_cap_info[0] = | |
4285 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4286 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4287 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4288 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4289 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE, | |
4290 | .phy_cap_info[3] = | |
4291 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4292 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4293 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4294 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4295 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4296 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4297 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4298 | .phy_cap_info[4] = | |
4299 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4300 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4301 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4302 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4303 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4304 | .phy_cap_info[5] = | |
4305 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4306 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4307 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4308 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4309 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4310 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4311 | .phy_cap_info[6] = | |
4312 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4313 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK, | |
4314 | .phy_cap_info[7] = | |
4315 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW, | |
4316 | }, | |
4317 | ||
4318 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4319 | * Rx | |
4320 | */ | |
4321 | .eht_mcs_nss_supp = { | |
4322 | /* | |
4323 | * Since B0, B1, B2 and B3 are not set in | |
4324 | * the supported channel width set field in the | |
4325 | * HE PHY capabilities information field the | |
4326 | * device is a 20MHz only device on 2.4GHz band. | |
4327 | */ | |
4328 | .only_20mhz = { | |
4329 | .rx_tx_mcs7_max_nss = 0x88, | |
4330 | .rx_tx_mcs9_max_nss = 0x88, | |
4331 | .rx_tx_mcs11_max_nss = 0x88, | |
4332 | .rx_tx_mcs13_max_nss = 0x88, | |
4333 | }, | |
4334 | }, | |
4335 | /* PPE threshold information is not supported */ | |
4336 | }, | |
b697746c SE |
4337 | }, |
4338 | #ifdef CONFIG_MAC80211_MESH | |
4339 | { | |
b697746c SE |
4340 | .types_mask = BIT(NL80211_IFTYPE_MESH_POINT), |
4341 | .he_cap = { | |
4342 | .has_he = true, | |
4343 | .he_cap_elem = { | |
4344 | .mac_cap_info[0] = | |
4345 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4346 | .mac_cap_info[1] = | |
4347 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4348 | .mac_cap_info[2] = | |
4349 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4350 | .mac_cap_info[3] = | |
4351 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
1f851b8d | 4352 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, |
2f516444 | 4353 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, |
ce10e865 MK |
4354 | .phy_cap_info[0] = |
4355 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G, | |
b697746c SE |
4356 | .phy_cap_info[1] = |
4357 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4358 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4359 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4360 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4361 | .phy_cap_info[2] = 0, | |
4362 | ||
4363 | /* Leave all the other PHY capability bytes | |
4364 | * unset, as DCM, beam forming, RU and PPE | |
4365 | * threshold information are not supported | |
4366 | */ | |
4367 | }, | |
4368 | .he_mcs_nss_supp = { | |
4369 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4370 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4371 | .rx_mcs_160 = cpu_to_le16(0xffff), | |
4372 | .tx_mcs_160 = cpu_to_le16(0xffff), | |
4373 | .rx_mcs_80p80 = cpu_to_le16(0xffff), | |
4374 | .tx_mcs_80p80 = cpu_to_le16(0xffff), | |
4375 | }, | |
518ea3c5 IP |
4376 | }, |
4377 | }, | |
b697746c | 4378 | #endif |
518ea3c5 IP |
4379 | }; |
4380 | ||
ea0de861 | 4381 | static const struct ieee80211_sband_iftype_data sband_capa_5ghz[] = { |
b697746c | 4382 | { |
4992b360 JB |
4383 | /* TODO: should we support other types, e.g., P2P? */ |
4384 | .types_mask = BIT(NL80211_IFTYPE_STATION), | |
4385 | .he_cap = { | |
4386 | .has_he = true, | |
4387 | .he_cap_elem = { | |
4388 | .mac_cap_info[0] = | |
4389 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4390 | .mac_cap_info[1] = | |
4391 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4392 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4393 | .mac_cap_info[2] = | |
4394 | IEEE80211_HE_MAC_CAP2_BSR | | |
4395 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4396 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4397 | .mac_cap_info[3] = | |
4398 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
4399 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, | |
4400 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, | |
4401 | .phy_cap_info[0] = | |
4402 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4403 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4404 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4405 | .phy_cap_info[1] = | |
4406 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4407 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4408 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4409 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4410 | .phy_cap_info[2] = | |
4411 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4412 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4413 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4414 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4415 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4416 | ||
4417 | /* Leave all the other PHY capability bytes | |
4418 | * unset, as DCM, beam forming, RU and PPE | |
4419 | * threshold information are not supported | |
4420 | */ | |
4421 | }, | |
4422 | .he_mcs_nss_supp = { | |
4423 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4424 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4425 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
4426 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
4427 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4428 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4429 | }, | |
4430 | }, | |
4431 | .eht_cap = { | |
4432 | .has_eht = true, | |
4433 | .eht_cap_elem = { | |
4434 | .mac_cap_info[0] = | |
4435 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | | |
4436 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | | |
4437 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4438 | .phy_cap_info[0] = | |
4439 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4440 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4441 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4442 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4443 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE | | |
4444 | IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK, | |
4445 | .phy_cap_info[1] = | |
4446 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK | | |
4447 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK, | |
4448 | .phy_cap_info[2] = | |
4449 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK | | |
4450 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK, | |
4451 | .phy_cap_info[3] = | |
4452 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4453 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4454 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4455 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4456 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4457 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4458 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4459 | .phy_cap_info[4] = | |
4460 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4461 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4462 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4463 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4464 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4465 | .phy_cap_info[5] = | |
4466 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4467 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4468 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4469 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4470 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4471 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4472 | .phy_cap_info[6] = | |
4473 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4474 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK, | |
4475 | .phy_cap_info[7] = | |
4476 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW | | |
4477 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
4478 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
4479 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
4480 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ, | |
4481 | }, | |
4482 | ||
4483 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4484 | * Rx | |
4485 | */ | |
4486 | .eht_mcs_nss_supp = { | |
4487 | /* | |
4488 | * As B1 and B2 are set in the supported | |
4489 | * channel width set field in the HE PHY | |
4490 | * capabilities information field include all | |
4491 | * the following MCS/NSS. | |
4492 | */ | |
4493 | .bw._80 = { | |
4494 | .rx_tx_mcs9_max_nss = 0x88, | |
4495 | .rx_tx_mcs11_max_nss = 0x88, | |
4496 | .rx_tx_mcs13_max_nss = 0x88, | |
4497 | }, | |
4498 | .bw._160 = { | |
4499 | .rx_tx_mcs9_max_nss = 0x88, | |
4500 | .rx_tx_mcs11_max_nss = 0x88, | |
4501 | .rx_tx_mcs13_max_nss = 0x88, | |
4502 | }, | |
4503 | }, | |
4504 | /* PPE threshold information is not supported */ | |
4505 | }, | |
4506 | }, | |
4507 | { | |
4508 | .types_mask = BIT(NL80211_IFTYPE_AP), | |
b697746c SE |
4509 | .he_cap = { |
4510 | .has_he = true, | |
4511 | .he_cap_elem = { | |
4512 | .mac_cap_info[0] = | |
4513 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4514 | .mac_cap_info[1] = | |
4515 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4516 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4517 | .mac_cap_info[2] = | |
4518 | IEEE80211_HE_MAC_CAP2_BSR | | |
4519 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4520 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4521 | .mac_cap_info[3] = | |
4522 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
1f851b8d | 4523 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, |
2f516444 | 4524 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, |
b697746c SE |
4525 | .phy_cap_info[0] = |
4526 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4527 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4528 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4529 | .phy_cap_info[1] = | |
4530 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4531 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4532 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4533 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4534 | .phy_cap_info[2] = | |
4535 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4536 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4537 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4538 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4539 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4540 | ||
4541 | /* Leave all the other PHY capability bytes | |
4542 | * unset, as DCM, beam forming, RU and PPE | |
4543 | * threshold information are not supported | |
4544 | */ | |
4545 | }, | |
4546 | .he_mcs_nss_supp = { | |
4547 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4548 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4549 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
4550 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
4551 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4552 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4553 | }, | |
518ea3c5 | 4554 | }, |
ea0de861 IP |
4555 | .eht_cap = { |
4556 | .has_eht = true, | |
4557 | .eht_cap_elem = { | |
4558 | .mac_cap_info[0] = | |
062e8e02 | 4559 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | |
ea0de861 IP |
4560 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | |
4561 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4562 | .phy_cap_info[0] = | |
4563 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4564 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4565 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4566 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4567 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE | | |
4568 | IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK, | |
4569 | .phy_cap_info[1] = | |
4570 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK | | |
4571 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK, | |
4572 | .phy_cap_info[2] = | |
4573 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK | | |
4574 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK, | |
4575 | .phy_cap_info[3] = | |
4576 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4577 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4578 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4579 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4580 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4581 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4582 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4583 | .phy_cap_info[4] = | |
4584 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4585 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4586 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4587 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4588 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4589 | .phy_cap_info[5] = | |
4590 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4591 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4592 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4593 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4594 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4595 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4596 | .phy_cap_info[6] = | |
4597 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4598 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK, | |
4599 | .phy_cap_info[7] = | |
4600 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW | | |
4601 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
4602 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
4603 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
4604 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ, | |
4605 | }, | |
4606 | ||
4607 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4608 | * Rx | |
4609 | */ | |
4610 | .eht_mcs_nss_supp = { | |
4611 | /* | |
4612 | * As B1 and B2 are set in the supported | |
4613 | * channel width set field in the HE PHY | |
4614 | * capabilities information field include all | |
4615 | * the following MCS/NSS. | |
4616 | */ | |
4617 | .bw._80 = { | |
4618 | .rx_tx_mcs9_max_nss = 0x88, | |
4619 | .rx_tx_mcs11_max_nss = 0x88, | |
4620 | .rx_tx_mcs13_max_nss = 0x88, | |
4621 | }, | |
4622 | .bw._160 = { | |
4623 | .rx_tx_mcs9_max_nss = 0x88, | |
4624 | .rx_tx_mcs11_max_nss = 0x88, | |
4625 | .rx_tx_mcs13_max_nss = 0x88, | |
4626 | }, | |
4627 | }, | |
4628 | /* PPE threshold information is not supported */ | |
4629 | }, | |
b697746c SE |
4630 | }, |
4631 | #ifdef CONFIG_MAC80211_MESH | |
4632 | { | |
4633 | /* TODO: should we support other types, e.g., IBSS?*/ | |
4634 | .types_mask = BIT(NL80211_IFTYPE_MESH_POINT), | |
4635 | .he_cap = { | |
4636 | .has_he = true, | |
4637 | .he_cap_elem = { | |
4638 | .mac_cap_info[0] = | |
4639 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4640 | .mac_cap_info[1] = | |
4641 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4642 | .mac_cap_info[2] = | |
4643 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4644 | .mac_cap_info[3] = | |
4645 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
1f851b8d | 4646 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, |
2f516444 | 4647 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, |
b697746c SE |
4648 | .phy_cap_info[0] = |
4649 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4650 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4651 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4652 | .phy_cap_info[1] = | |
4653 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4654 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4655 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4656 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4657 | .phy_cap_info[2] = 0, | |
4658 | ||
4659 | /* Leave all the other PHY capability bytes | |
4660 | * unset, as DCM, beam forming, RU and PPE | |
4661 | * threshold information are not supported | |
4662 | */ | |
4663 | }, | |
4664 | .he_mcs_nss_supp = { | |
4665 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4666 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4667 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
4668 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
4669 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4670 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4671 | }, | |
518ea3c5 IP |
4672 | }, |
4673 | }, | |
b697746c | 4674 | #endif |
518ea3c5 IP |
4675 | }; |
4676 | ||
ea0de861 | 4677 | static const struct ieee80211_sband_iftype_data sband_capa_6ghz[] = { |
cd8793f9 | 4678 | { |
4992b360 JB |
4679 | /* TODO: should we support other types, e.g., P2P? */ |
4680 | .types_mask = BIT(NL80211_IFTYPE_STATION), | |
4681 | .he_6ghz_capa = { | |
4682 | .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START | | |
4683 | IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP | | |
4684 | IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN | | |
4685 | IEEE80211_HE_6GHZ_CAP_SM_PS | | |
4686 | IEEE80211_HE_6GHZ_CAP_RD_RESPONDER | | |
4687 | IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS | | |
4688 | IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS), | |
4689 | }, | |
4690 | .he_cap = { | |
4691 | .has_he = true, | |
4692 | .he_cap_elem = { | |
4693 | .mac_cap_info[0] = | |
4694 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4695 | .mac_cap_info[1] = | |
4696 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4697 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4698 | .mac_cap_info[2] = | |
4699 | IEEE80211_HE_MAC_CAP2_BSR | | |
4700 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4701 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4702 | .mac_cap_info[3] = | |
4703 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
4704 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, | |
4705 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, | |
4706 | .phy_cap_info[0] = | |
4707 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4708 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4709 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4710 | .phy_cap_info[1] = | |
4711 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4712 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4713 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4714 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4715 | .phy_cap_info[2] = | |
4716 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4717 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4718 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4719 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4720 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4721 | ||
4722 | /* Leave all the other PHY capability bytes | |
4723 | * unset, as DCM, beam forming, RU and PPE | |
4724 | * threshold information are not supported | |
4725 | */ | |
4726 | }, | |
4727 | .he_mcs_nss_supp = { | |
4728 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4729 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4730 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
4731 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
4732 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4733 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4734 | }, | |
4735 | }, | |
4736 | .eht_cap = { | |
4737 | .has_eht = true, | |
4738 | .eht_cap_elem = { | |
4739 | .mac_cap_info[0] = | |
4740 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | | |
4741 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | | |
4742 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4743 | .phy_cap_info[0] = | |
4744 | IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ | | |
4745 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4746 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4747 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4748 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4749 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE | | |
4750 | IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK, | |
4751 | .phy_cap_info[1] = | |
4752 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK | | |
4753 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK | | |
4754 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK, | |
4755 | .phy_cap_info[2] = | |
4756 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK | | |
4757 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK | | |
4758 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK, | |
4759 | .phy_cap_info[3] = | |
4760 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4761 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4762 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4763 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4764 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4765 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4766 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4767 | .phy_cap_info[4] = | |
4768 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4769 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4770 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4771 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4772 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4773 | .phy_cap_info[5] = | |
4774 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4775 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4776 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4777 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4778 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4779 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4780 | .phy_cap_info[6] = | |
4781 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4782 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK | | |
4783 | IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP, | |
4784 | .phy_cap_info[7] = | |
4785 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW | | |
4786 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
4787 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
4788 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ | | |
4789 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
4790 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
4791 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ, | |
4792 | }, | |
4793 | ||
4794 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4795 | * Rx | |
4796 | */ | |
4797 | .eht_mcs_nss_supp = { | |
4798 | /* | |
4799 | * As B1 and B2 are set in the supported | |
4800 | * channel width set field in the HE PHY | |
4801 | * capabilities information field and 320MHz in | |
4802 | * 6GHz is supported include all the following | |
4803 | * MCS/NSS. | |
4804 | */ | |
4805 | .bw._80 = { | |
4806 | .rx_tx_mcs9_max_nss = 0x88, | |
4807 | .rx_tx_mcs11_max_nss = 0x88, | |
4808 | .rx_tx_mcs13_max_nss = 0x88, | |
4809 | }, | |
4810 | .bw._160 = { | |
4811 | .rx_tx_mcs9_max_nss = 0x88, | |
4812 | .rx_tx_mcs11_max_nss = 0x88, | |
4813 | .rx_tx_mcs13_max_nss = 0x88, | |
4814 | }, | |
4815 | .bw._320 = { | |
4816 | .rx_tx_mcs9_max_nss = 0x88, | |
4817 | .rx_tx_mcs11_max_nss = 0x88, | |
4818 | .rx_tx_mcs13_max_nss = 0x88, | |
4819 | }, | |
4820 | }, | |
4821 | /* PPE threshold information is not supported */ | |
4822 | }, | |
4823 | }, | |
4824 | { | |
4825 | .types_mask = BIT(NL80211_IFTYPE_AP), | |
cd8793f9 RF |
4826 | .he_6ghz_capa = { |
4827 | .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START | | |
4828 | IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP | | |
4829 | IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN | | |
4830 | IEEE80211_HE_6GHZ_CAP_SM_PS | | |
4831 | IEEE80211_HE_6GHZ_CAP_RD_RESPONDER | | |
4832 | IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS | | |
4833 | IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS), | |
4834 | }, | |
4835 | .he_cap = { | |
4836 | .has_he = true, | |
4837 | .he_cap_elem = { | |
4838 | .mac_cap_info[0] = | |
4839 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4840 | .mac_cap_info[1] = | |
4841 | IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US | | |
4842 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4843 | .mac_cap_info[2] = | |
4844 | IEEE80211_HE_MAC_CAP2_BSR | | |
4845 | IEEE80211_HE_MAC_CAP2_MU_CASCADING | | |
4846 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4847 | .mac_cap_info[3] = | |
4848 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
4849 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, | |
4850 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, | |
4851 | .phy_cap_info[0] = | |
4852 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4853 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4854 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4855 | .phy_cap_info[1] = | |
4856 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
4857 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
4858 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
4859 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
4860 | .phy_cap_info[2] = | |
4861 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | | |
4862 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | | |
4863 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ | | |
4864 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | | |
4865 | IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO, | |
4866 | ||
4867 | /* Leave all the other PHY capability bytes | |
4868 | * unset, as DCM, beam forming, RU and PPE | |
4869 | * threshold information are not supported | |
4870 | */ | |
4871 | }, | |
4872 | .he_mcs_nss_supp = { | |
4873 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
4874 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
4875 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
4876 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
4877 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4878 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
4879 | }, | |
4880 | }, | |
ea0de861 IP |
4881 | .eht_cap = { |
4882 | .has_eht = true, | |
4883 | .eht_cap_elem = { | |
4884 | .mac_cap_info[0] = | |
062e8e02 | 4885 | IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS | |
ea0de861 IP |
4886 | IEEE80211_EHT_MAC_CAP0_OM_CONTROL | |
4887 | IEEE80211_EHT_MAC_CAP0_TRIG_TXOP_SHARING_MODE1, | |
4888 | .phy_cap_info[0] = | |
4889 | IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ | | |
4890 | IEEE80211_EHT_PHY_CAP0_242_TONE_RU_GT20MHZ | | |
4891 | IEEE80211_EHT_PHY_CAP0_NDP_4_EHT_LFT_32_GI | | |
4892 | IEEE80211_EHT_PHY_CAP0_PARTIAL_BW_UL_MU_MIMO | | |
4893 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER | | |
4894 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE | | |
4895 | IEEE80211_EHT_PHY_CAP0_BEAMFORMEE_SS_80MHZ_MASK, | |
4896 | .phy_cap_info[1] = | |
4897 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_80MHZ_MASK | | |
4898 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_160MHZ_MASK | | |
4899 | IEEE80211_EHT_PHY_CAP1_BEAMFORMEE_SS_320MHZ_MASK, | |
4900 | .phy_cap_info[2] = | |
4901 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_80MHZ_MASK | | |
4902 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_160MHZ_MASK | | |
4903 | IEEE80211_EHT_PHY_CAP2_SOUNDING_DIM_320MHZ_MASK, | |
4904 | .phy_cap_info[3] = | |
4905 | IEEE80211_EHT_PHY_CAP3_NG_16_SU_FEEDBACK | | |
4906 | IEEE80211_EHT_PHY_CAP3_NG_16_MU_FEEDBACK | | |
4907 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_4_2_SU_FDBK | | |
4908 | IEEE80211_EHT_PHY_CAP3_CODEBOOK_7_5_MU_FDBK | | |
4909 | IEEE80211_EHT_PHY_CAP3_TRIG_SU_BF_FDBK | | |
4910 | IEEE80211_EHT_PHY_CAP3_TRIG_MU_BF_PART_BW_FDBK | | |
4911 | IEEE80211_EHT_PHY_CAP3_TRIG_CQI_FDBK, | |
4912 | .phy_cap_info[4] = | |
4913 | IEEE80211_EHT_PHY_CAP4_PART_BW_DL_MU_MIMO | | |
4914 | IEEE80211_EHT_PHY_CAP4_PSR_SR_SUPP | | |
4915 | IEEE80211_EHT_PHY_CAP4_POWER_BOOST_FACT_SUPP | | |
4916 | IEEE80211_EHT_PHY_CAP4_EHT_MU_PPDU_4_EHT_LTF_08_GI | | |
4917 | IEEE80211_EHT_PHY_CAP4_MAX_NC_MASK, | |
4918 | .phy_cap_info[5] = | |
4919 | IEEE80211_EHT_PHY_CAP5_NON_TRIG_CQI_FEEDBACK | | |
4920 | IEEE80211_EHT_PHY_CAP5_TX_LESS_242_TONE_RU_SUPP | | |
4921 | IEEE80211_EHT_PHY_CAP5_RX_LESS_242_TONE_RU_SUPP | | |
4922 | IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT | | |
4923 | IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK | | |
4924 | IEEE80211_EHT_PHY_CAP5_MAX_NUM_SUPP_EHT_LTF_MASK, | |
4925 | .phy_cap_info[6] = | |
4926 | IEEE80211_EHT_PHY_CAP6_MAX_NUM_SUPP_EHT_LTF_MASK | | |
4927 | IEEE80211_EHT_PHY_CAP6_MCS15_SUPP_MASK | | |
4928 | IEEE80211_EHT_PHY_CAP6_EHT_DUP_6GHZ_SUPP, | |
4929 | .phy_cap_info[7] = | |
4930 | IEEE80211_EHT_PHY_CAP7_20MHZ_STA_RX_NDP_WIDER_BW | | |
4931 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_80MHZ | | |
4932 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_160MHZ | | |
4933 | IEEE80211_EHT_PHY_CAP7_NON_OFDMA_UL_MU_MIMO_320MHZ | | |
4934 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
4935 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
4936 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ, | |
4937 | }, | |
4938 | ||
4939 | /* For all MCS and bandwidth, set 8 NSS for both Tx and | |
4940 | * Rx | |
4941 | */ | |
4942 | .eht_mcs_nss_supp = { | |
4943 | /* | |
4944 | * As B1 and B2 are set in the supported | |
4945 | * channel width set field in the HE PHY | |
4946 | * capabilities information field and 320MHz in | |
4947 | * 6GHz is supported include all the following | |
4948 | * MCS/NSS. | |
4949 | */ | |
4950 | .bw._80 = { | |
4951 | .rx_tx_mcs9_max_nss = 0x88, | |
4952 | .rx_tx_mcs11_max_nss = 0x88, | |
4953 | .rx_tx_mcs13_max_nss = 0x88, | |
4954 | }, | |
4955 | .bw._160 = { | |
4956 | .rx_tx_mcs9_max_nss = 0x88, | |
4957 | .rx_tx_mcs11_max_nss = 0x88, | |
4958 | .rx_tx_mcs13_max_nss = 0x88, | |
4959 | }, | |
4960 | .bw._320 = { | |
4961 | .rx_tx_mcs9_max_nss = 0x88, | |
4962 | .rx_tx_mcs11_max_nss = 0x88, | |
4963 | .rx_tx_mcs13_max_nss = 0x88, | |
4964 | }, | |
4965 | }, | |
4966 | /* PPE threshold information is not supported */ | |
4967 | }, | |
cd8793f9 RF |
4968 | }, |
4969 | #ifdef CONFIG_MAC80211_MESH | |
4970 | { | |
4971 | /* TODO: should we support other types, e.g., IBSS?*/ | |
4972 | .types_mask = BIT(NL80211_IFTYPE_MESH_POINT), | |
4973 | .he_6ghz_capa = { | |
4974 | .capa = cpu_to_le16(IEEE80211_HE_6GHZ_CAP_MIN_MPDU_START | | |
4975 | IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP | | |
4976 | IEEE80211_HE_6GHZ_CAP_MAX_MPDU_LEN | | |
4977 | IEEE80211_HE_6GHZ_CAP_SM_PS | | |
4978 | IEEE80211_HE_6GHZ_CAP_RD_RESPONDER | | |
4979 | IEEE80211_HE_6GHZ_CAP_TX_ANTPAT_CONS | | |
4980 | IEEE80211_HE_6GHZ_CAP_RX_ANTPAT_CONS), | |
4981 | }, | |
4982 | .he_cap = { | |
4983 | .has_he = true, | |
4984 | .he_cap_elem = { | |
4985 | .mac_cap_info[0] = | |
4986 | IEEE80211_HE_MAC_CAP0_HTC_HE, | |
4987 | .mac_cap_info[1] = | |
4988 | IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8, | |
4989 | .mac_cap_info[2] = | |
4990 | IEEE80211_HE_MAC_CAP2_ACK_EN, | |
4991 | .mac_cap_info[3] = | |
4992 | IEEE80211_HE_MAC_CAP3_OMI_CONTROL | | |
4993 | IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_EXT_3, | |
4994 | .mac_cap_info[4] = IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU, | |
4995 | .phy_cap_info[0] = | |
4996 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | | |
4997 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | | |
4998 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G, | |
4999 | .phy_cap_info[1] = | |
5000 | IEEE80211_HE_PHY_CAP1_PREAMBLE_PUNC_RX_MASK | | |
5001 | IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | | |
5002 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD | | |
5003 | IEEE80211_HE_PHY_CAP1_MIDAMBLE_RX_TX_MAX_NSTS, | |
5004 | .phy_cap_info[2] = 0, | |
5005 | ||
5006 | /* Leave all the other PHY capability bytes | |
5007 | * unset, as DCM, beam forming, RU and PPE | |
5008 | * threshold information are not supported | |
5009 | */ | |
5010 | }, | |
5011 | .he_mcs_nss_supp = { | |
5012 | .rx_mcs_80 = cpu_to_le16(0xfffa), | |
5013 | .tx_mcs_80 = cpu_to_le16(0xfffa), | |
5014 | .rx_mcs_160 = cpu_to_le16(0xfffa), | |
5015 | .tx_mcs_160 = cpu_to_le16(0xfffa), | |
5016 | .rx_mcs_80p80 = cpu_to_le16(0xfffa), | |
5017 | .tx_mcs_80p80 = cpu_to_le16(0xfffa), | |
5018 | }, | |
5019 | }, | |
5020 | }, | |
5021 | #endif | |
5022 | }; | |
5023 | ||
ea0de861 | 5024 | static void mac80211_hwsim_sband_capab(struct ieee80211_supported_band *sband) |
518ea3c5 | 5025 | { |
e8c18412 JB |
5026 | switch (sband->band) { |
5027 | case NL80211_BAND_2GHZ: | |
5028 | ieee80211_set_sband_iftype_data(sband, sband_capa_2ghz); | |
5029 | break; | |
5030 | case NL80211_BAND_5GHZ: | |
5031 | ieee80211_set_sband_iftype_data(sband, sband_capa_5ghz); | |
5032 | break; | |
5033 | case NL80211_BAND_6GHZ: | |
5034 | ieee80211_set_sband_iftype_data(sband, sband_capa_6ghz); | |
5035 | break; | |
5036 | default: | |
5037 | break; | |
b697746c | 5038 | } |
518ea3c5 IP |
5039 | } |
5040 | ||
99e3a44b JP |
5041 | #ifdef CONFIG_MAC80211_MESH |
5042 | #define HWSIM_MESH_BIT BIT(NL80211_IFTYPE_MESH_POINT) | |
5043 | #else | |
5044 | #define HWSIM_MESH_BIT 0 | |
5045 | #endif | |
5046 | ||
5047 | #define HWSIM_DEFAULT_IF_LIMIT \ | |
5048 | (BIT(NL80211_IFTYPE_STATION) | \ | |
5049 | BIT(NL80211_IFTYPE_P2P_CLIENT) | \ | |
5050 | BIT(NL80211_IFTYPE_AP) | \ | |
5051 | BIT(NL80211_IFTYPE_P2P_GO) | \ | |
5052 | HWSIM_MESH_BIT) | |
5053 | ||
5054 | #define HWSIM_IFTYPE_SUPPORT_MASK \ | |
5055 | (BIT(NL80211_IFTYPE_STATION) | \ | |
5056 | BIT(NL80211_IFTYPE_AP) | \ | |
5057 | BIT(NL80211_IFTYPE_P2P_CLIENT) | \ | |
5058 | BIT(NL80211_IFTYPE_P2P_GO) | \ | |
5059 | BIT(NL80211_IFTYPE_ADHOC) | \ | |
7dfd8ac3 RF |
5060 | BIT(NL80211_IFTYPE_MESH_POINT) | \ |
5061 | BIT(NL80211_IFTYPE_OCB)) | |
99e3a44b | 5062 | |
34b5ff46 IP |
5063 | static const u8 iftypes_ext_capa_ap[] = { |
5064 | [0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING, | |
5065 | [2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT, | |
5066 | [7] = WLAN_EXT_CAPA8_OPMODE_NOTIF | | |
5067 | WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB, | |
5068 | [8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB, | |
5069 | [9] = WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT, | |
5070 | }; | |
5071 | ||
2b3e35d9 JB |
5072 | #define MAC80211_HWSIM_MLD_CAPA_OPS \ |
5073 | FIELD_PREP_CONST(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP, \ | |
5074 | IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP_SAME) | \ | |
5075 | FIELD_PREP_CONST(IEEE80211_MLD_CAP_OP_MAX_SIMUL_LINKS, \ | |
5076 | IEEE80211_MLD_MAX_NUM_LINKS - 1) | |
34b5ff46 IP |
5077 | |
5078 | static const struct wiphy_iftype_ext_capab mac80211_hwsim_iftypes_ext_capa[] = { | |
5079 | { | |
5080 | .iftype = NL80211_IFTYPE_AP, | |
5081 | .extended_capabilities = iftypes_ext_capa_ap, | |
5082 | .extended_capabilities_mask = iftypes_ext_capa_ap, | |
5083 | .extended_capabilities_len = sizeof(iftypes_ext_capa_ap), | |
6a19031d JB |
5084 | .eml_capabilities = IEEE80211_EML_CAP_EMLSR_SUPP | |
5085 | IEEE80211_EML_CAP_EMLMR_SUPPORT, | |
34b5ff46 IP |
5086 | .mld_capa_and_ops = MAC80211_HWSIM_MLD_CAPA_OPS, |
5087 | }, | |
5088 | }; | |
5089 | ||
62759361 JR |
5090 | static int mac80211_hwsim_new_radio(struct genl_info *info, |
5091 | struct hwsim_new_radio_params *param) | |
acc1e7a3 | 5092 | { |
de0421d5 JB |
5093 | int err; |
5094 | u8 addr[ETH_ALEN]; | |
e4afb603 | 5095 | struct mac80211_hwsim_data *data; |
de0421d5 | 5096 | struct ieee80211_hw *hw; |
57fbcce3 | 5097 | enum nl80211_band band; |
de0421d5 | 5098 | const struct ieee80211_ops *ops = &mac80211_hwsim_ops; |
100cb9ff | 5099 | struct net *net; |
45fcef8b | 5100 | int idx, i; |
99e3a44b | 5101 | int n_limits = 0; |
0e057d73 | 5102 | |
62759361 | 5103 | if (WARN_ON(param->channels > 1 && !param->use_chanctx)) |
361c3e04 LC |
5104 | return -EINVAL; |
5105 | ||
0e057d73 | 5106 | spin_lock_bh(&hwsim_radio_lock); |
de0421d5 | 5107 | idx = hwsim_radio_idx++; |
0e057d73 JB |
5108 | spin_unlock_bh(&hwsim_radio_lock); |
5109 | ||
2fd0c671 JB |
5110 | if (param->mlo) |
5111 | ops = &mac80211_hwsim_mlo_ops; | |
5112 | else if (param->use_chanctx) | |
de0421d5 | 5113 | ops = &mac80211_hwsim_mchan_ops; |
62759361 | 5114 | hw = ieee80211_alloc_hw_nm(sizeof(*data), ops, param->hwname); |
de0421d5 | 5115 | if (!hw) { |
62b093b3 | 5116 | pr_debug("mac80211_hwsim: ieee80211_alloc_hw failed\n"); |
de0421d5 JB |
5117 | err = -ENOMEM; |
5118 | goto failed; | |
5119 | } | |
100cb9ff | 5120 | |
f7d3b4f5 AZ |
5121 | /* ieee80211_alloc_hw_nm may have used a default name */ |
5122 | param->hwname = wiphy_name(hw->wiphy); | |
5123 | ||
100cb9ff MW |
5124 | if (info) |
5125 | net = genl_info_net(info); | |
5126 | else | |
5127 | net = &init_net; | |
5128 | wiphy_net_set(hw->wiphy, net); | |
5129 | ||
de0421d5 JB |
5130 | data = hw->priv; |
5131 | data->hw = hw; | |
acc1e7a3 | 5132 | |
de0421d5 JB |
5133 | data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx); |
5134 | if (IS_ERR(data->dev)) { | |
5135 | printk(KERN_DEBUG | |
5136 | "mac80211_hwsim: device_create failed (%ld)\n", | |
5137 | PTR_ERR(data->dev)); | |
5138 | err = -ENOMEM; | |
5139 | goto failed_drvdata; | |
5140 | } | |
5141 | data->dev->driver = &mac80211_hwsim_driver.driver; | |
5142 | err = device_bind_driver(data->dev); | |
5143 | if (err != 0) { | |
62b093b3 | 5144 | pr_debug("mac80211_hwsim: device_bind_driver failed (%d)\n", |
de0421d5 | 5145 | err); |
805dbe17 | 5146 | goto failed_bind; |
acc1e7a3 | 5147 | } |
acc1e7a3 | 5148 | |
de0421d5 | 5149 | skb_queue_head_init(&data->pending); |
acc1e7a3 | 5150 | |
de0421d5 | 5151 | SET_IEEE80211_DEV(hw, data->dev); |
cb1a5bae BB |
5152 | if (!param->perm_addr) { |
5153 | eth_zero_addr(addr); | |
5154 | addr[0] = 0x02; | |
5155 | addr[3] = idx >> 8; | |
5156 | addr[4] = idx; | |
5157 | memcpy(data->addresses[0].addr, addr, ETH_ALEN); | |
5158 | /* Why need here second address ? */ | |
cb1a5bae | 5159 | memcpy(data->addresses[1].addr, addr, ETH_ALEN); |
796e1112 | 5160 | data->addresses[1].addr[0] |= 0x40; |
cb1a5bae BB |
5161 | hw->wiphy->n_addresses = 2; |
5162 | hw->wiphy->addresses = data->addresses; | |
5163 | /* possible address clash is checked at hash table insertion */ | |
5164 | } else { | |
5165 | memcpy(data->addresses[0].addr, param->perm_addr, ETH_ALEN); | |
5166 | /* compatibility with automatically generated mac addr */ | |
5167 | memcpy(data->addresses[1].addr, param->perm_addr, ETH_ALEN); | |
5168 | hw->wiphy->n_addresses = 2; | |
5169 | hw->wiphy->addresses = data->addresses; | |
5170 | } | |
fc6971d4 | 5171 | |
62759361 JR |
5172 | data->channels = param->channels; |
5173 | data->use_chanctx = param->use_chanctx; | |
bc791098 | 5174 | data->idx = idx; |
62759361 JR |
5175 | data->destroy_on_close = param->destroy_on_close; |
5176 | if (info) | |
5177 | data->portid = info->snd_portid; | |
fc6971d4 | 5178 | |
99e3a44b JP |
5179 | /* setup interface limits, only on interface types we support */ |
5180 | if (param->iftypes & BIT(NL80211_IFTYPE_ADHOC)) { | |
5181 | data->if_limits[n_limits].max = 1; | |
5182 | data->if_limits[n_limits].types = BIT(NL80211_IFTYPE_ADHOC); | |
5183 | n_limits++; | |
5184 | } | |
5185 | ||
5186 | if (param->iftypes & HWSIM_DEFAULT_IF_LIMIT) { | |
5187 | data->if_limits[n_limits].max = 2048; | |
5188 | /* | |
5189 | * For this case, we may only support a subset of | |
5190 | * HWSIM_DEFAULT_IF_LIMIT, therefore we only want to add the | |
5191 | * bits that both param->iftype & HWSIM_DEFAULT_IF_LIMIT have. | |
5192 | */ | |
5193 | data->if_limits[n_limits].types = | |
5194 | HWSIM_DEFAULT_IF_LIMIT & param->iftypes; | |
5195 | n_limits++; | |
5196 | } | |
5197 | ||
5198 | if (param->iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) { | |
5199 | data->if_limits[n_limits].max = 1; | |
5200 | data->if_limits[n_limits].types = | |
5201 | BIT(NL80211_IFTYPE_P2P_DEVICE); | |
5202 | n_limits++; | |
5203 | } | |
5204 | ||
361c3e04 | 5205 | if (data->use_chanctx) { |
de0421d5 JB |
5206 | hw->wiphy->max_scan_ssids = 255; |
5207 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; | |
5208 | hw->wiphy->max_remain_on_channel_duration = 1000; | |
f7736f50 | 5209 | data->if_combination.radar_detect_widths = 0; |
b59ec8dd | 5210 | data->if_combination.num_different_channels = data->channels; |
de0421d5 | 5211 | } else { |
68406a98 JP |
5212 | data->if_combination.num_different_channels = 1; |
5213 | data->if_combination.radar_detect_widths = | |
b5764696 RF |
5214 | BIT(NL80211_CHAN_WIDTH_5) | |
5215 | BIT(NL80211_CHAN_WIDTH_10) | | |
99e3a44b JP |
5216 | BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
5217 | BIT(NL80211_CHAN_WIDTH_20) | | |
5218 | BIT(NL80211_CHAN_WIDTH_40) | | |
5219 | BIT(NL80211_CHAN_WIDTH_80) | | |
5220 | BIT(NL80211_CHAN_WIDTH_160); | |
68406a98 JP |
5221 | } |
5222 | ||
9c5d3afa JB |
5223 | if (!n_limits) { |
5224 | err = -EINVAL; | |
5225 | goto failed_hw; | |
5226 | } | |
5227 | ||
45fcef8b JB |
5228 | data->if_combination.max_interfaces = 0; |
5229 | for (i = 0; i < n_limits; i++) | |
5230 | data->if_combination.max_interfaces += | |
5231 | data->if_limits[i].max; | |
5232 | ||
68406a98 | 5233 | data->if_combination.n_limits = n_limits; |
99e3a44b JP |
5234 | data->if_combination.limits = data->if_limits; |
5235 | ||
45fcef8b JB |
5236 | /* |
5237 | * If we actually were asked to support combinations, | |
5238 | * advertise them - if there's only a single thing like | |
5239 | * only IBSS then don't advertise it as combinations. | |
5240 | */ | |
5241 | if (data->if_combination.max_interfaces > 1) { | |
5242 | hw->wiphy->iface_combinations = &data->if_combination; | |
5243 | hw->wiphy->n_iface_combinations = 1; | |
5244 | } | |
99e3a44b | 5245 | |
c0a0189d JP |
5246 | if (param->ciphers) { |
5247 | memcpy(data->ciphers, param->ciphers, | |
5248 | param->n_ciphers * sizeof(u32)); | |
5249 | hw->wiphy->cipher_suites = data->ciphers; | |
5250 | hw->wiphy->n_cipher_suites = param->n_ciphers; | |
de0421d5 | 5251 | } |
acc1e7a3 | 5252 | |
c4f4d9f7 | 5253 | hw->wiphy->mbssid_max_interfaces = 8; |
0dd45ebc | 5254 | hw->wiphy->ema_max_profile_periodicity = 3; |
c4f4d9f7 | 5255 | |
b59fb546 BL |
5256 | data->rx_rssi = DEFAULT_RX_RSSI; |
5257 | ||
661ef475 | 5258 | INIT_DELAYED_WORK(&data->roc_start, hw_roc_start); |
de0421d5 JB |
5259 | INIT_DELAYED_WORK(&data->roc_done, hw_roc_done); |
5260 | INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work); | |
7882513b | 5261 | |
de0421d5 JB |
5262 | hw->queues = 5; |
5263 | hw->offchannel_tx_hw_queue = 4; | |
fc6971d4 | 5264 | |
30686bf7 JB |
5265 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); |
5266 | ieee80211_hw_set(hw, CHANCTX_STA_CSA); | |
5267 | ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES); | |
5268 | ieee80211_hw_set(hw, QUEUE_CONTROL); | |
5269 | ieee80211_hw_set(hw, WANT_MONITOR_VIF); | |
5270 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); | |
5271 | ieee80211_hw_set(hw, MFP_CAPABLE); | |
5272 | ieee80211_hw_set(hw, SIGNAL_DBM); | |
e4a2eb89 | 5273 | ieee80211_hw_set(hw, SUPPORTS_PS); |
01afc6fe | 5274 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); |
33c2f538 | 5275 | ieee80211_hw_set(hw, TDLS_WIDER_BW); |
040bda85 | 5276 | ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID); |
fc6971d4 | 5277 | |
2fd0c671 JB |
5278 | if (param->mlo) { |
5279 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; | |
5280 | ieee80211_hw_set(hw, HAS_RATE_CONTROL); | |
5281 | ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); | |
5282 | ieee80211_hw_set(hw, CONNECTION_MONITOR); | |
5283 | ieee80211_hw_set(hw, AP_LINK_PS); | |
34b5ff46 IP |
5284 | |
5285 | hw->wiphy->iftype_ext_capab = mac80211_hwsim_iftypes_ext_capa; | |
5286 | hw->wiphy->num_iftype_ext_capab = | |
5287 | ARRAY_SIZE(mac80211_hwsim_iftypes_ext_capa); | |
2fd0c671 JB |
5288 | } else { |
5289 | ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING); | |
5290 | ieee80211_hw_set(hw, PS_NULLFUNC_STACK); | |
5291 | if (rctbl) | |
5292 | ieee80211_hw_set(hw, SUPPORTS_RC_TABLE); | |
5293 | } | |
5294 | ||
01afc6fe | 5295 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
de0421d5 JB |
5296 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | |
5297 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | |
0037db63 | 5298 | WIPHY_FLAG_AP_UAPSD | |
119aadf8 | 5299 | WIPHY_FLAG_SUPPORTS_5_10_MHZ | |
0037db63 | 5300 | WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
0d8614b4 EP |
5301 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR | |
5302 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | | |
5303 | NL80211_FEATURE_STATIC_SMPS | | |
339467b9 JB |
5304 | NL80211_FEATURE_DYNAMIC_SMPS | |
5305 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | |
00eeccc4 | 5306 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_VHT_IBSS); |
a483e29c | 5307 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_BEACON_PROTECTION); |
bedd7904 JM |
5308 | wiphy_ext_feature_set(hw->wiphy, |
5309 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS); | |
1512bc07 JM |
5310 | wiphy_ext_feature_set(hw->wiphy, |
5311 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY); | |
92d13386 | 5312 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER); |
fc6971d4 | 5313 | |
5cf10940 IP |
5314 | wiphy_ext_feature_set(hw->wiphy, |
5315 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT); | |
5316 | ||
99e3a44b JP |
5317 | hw->wiphy->interface_modes = param->iftypes; |
5318 | ||
de0421d5 JB |
5319 | /* ask mac80211 to reserve space for magic */ |
5320 | hw->vif_data_size = sizeof(struct hwsim_vif_priv); | |
5321 | hw->sta_data_size = sizeof(struct hwsim_sta_priv); | |
5322 | hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv); | |
fc6971d4 | 5323 | |
de0421d5 JB |
5324 | memcpy(data->channels_2ghz, hwsim_channels_2ghz, |
5325 | sizeof(hwsim_channels_2ghz)); | |
5326 | memcpy(data->channels_5ghz, hwsim_channels_5ghz, | |
5327 | sizeof(hwsim_channels_5ghz)); | |
28881922 RF |
5328 | memcpy(data->channels_6ghz, hwsim_channels_6ghz, |
5329 | sizeof(hwsim_channels_6ghz)); | |
148fe295 TP |
5330 | memcpy(data->channels_s1g, hwsim_channels_s1g, |
5331 | sizeof(hwsim_channels_s1g)); | |
de0421d5 | 5332 | memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates)); |
7882513b | 5333 | |
57fbcce3 | 5334 | for (band = NL80211_BAND_2GHZ; band < NUM_NL80211_BANDS; band++) { |
de0421d5 | 5335 | struct ieee80211_supported_band *sband = &data->bands[band]; |
518ea3c5 IP |
5336 | |
5337 | sband->band = band; | |
5338 | ||
de0421d5 | 5339 | switch (band) { |
57fbcce3 | 5340 | case NL80211_BAND_2GHZ: |
de0421d5 JB |
5341 | sband->channels = data->channels_2ghz; |
5342 | sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz); | |
5343 | sband->bitrates = data->rates; | |
5344 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates); | |
5345 | break; | |
57fbcce3 | 5346 | case NL80211_BAND_5GHZ: |
de0421d5 JB |
5347 | sband->channels = data->channels_5ghz; |
5348 | sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz); | |
5349 | sband->bitrates = data->rates + 4; | |
5350 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; | |
f33f8483 IP |
5351 | |
5352 | sband->vht_cap.vht_supported = true; | |
5353 | sband->vht_cap.cap = | |
5354 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | |
5355 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ | | |
5356 | IEEE80211_VHT_CAP_RXLDPC | | |
5357 | IEEE80211_VHT_CAP_SHORT_GI_80 | | |
5358 | IEEE80211_VHT_CAP_SHORT_GI_160 | | |
5359 | IEEE80211_VHT_CAP_TXSTBC | | |
f33f8483 IP |
5360 | IEEE80211_VHT_CAP_RXSTBC_4 | |
5361 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | |
5362 | sband->vht_cap.vht_mcs.rx_mcs_map = | |
8aca9b29 IP |
5363 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_9 << 0 | |
5364 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 2 | | |
f33f8483 | 5365 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 | |
8aca9b29 IP |
5366 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 6 | |
5367 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 8 | | |
f33f8483 IP |
5368 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 | |
5369 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 | | |
8aca9b29 | 5370 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 14); |
f33f8483 IP |
5371 | sband->vht_cap.vht_mcs.tx_mcs_map = |
5372 | sband->vht_cap.vht_mcs.rx_mcs_map; | |
de0421d5 | 5373 | break; |
cd8793f9 RF |
5374 | case NL80211_BAND_6GHZ: |
5375 | sband->channels = data->channels_6ghz; | |
5376 | sband->n_channels = ARRAY_SIZE(hwsim_channels_6ghz); | |
5377 | sband->bitrates = data->rates + 4; | |
5378 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; | |
5379 | break; | |
148fe295 TP |
5380 | case NL80211_BAND_S1GHZ: |
5381 | memcpy(&sband->s1g_cap, &hwsim_s1g_cap, | |
5382 | sizeof(sband->s1g_cap)); | |
5383 | sband->channels = data->channels_s1g; | |
5384 | sband->n_channels = ARRAY_SIZE(hwsim_channels_s1g); | |
5385 | break; | |
de0421d5 JB |
5386 | default: |
5387 | continue; | |
5388 | } | |
acc1e7a3 | 5389 | |
cd8793f9 RF |
5390 | if (band != NL80211_BAND_6GHZ){ |
5391 | sband->ht_cap.ht_supported = true; | |
5392 | sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | | |
5393 | IEEE80211_HT_CAP_GRN_FLD | | |
5394 | IEEE80211_HT_CAP_SGI_20 | | |
5395 | IEEE80211_HT_CAP_SGI_40 | | |
5396 | IEEE80211_HT_CAP_DSSSCCK40; | |
5397 | sband->ht_cap.ampdu_factor = 0x3; | |
5398 | sband->ht_cap.ampdu_density = 0x6; | |
5399 | memset(&sband->ht_cap.mcs, 0, | |
5400 | sizeof(sband->ht_cap.mcs)); | |
5401 | sband->ht_cap.mcs.rx_mask[0] = 0xff; | |
5402 | sband->ht_cap.mcs.rx_mask[1] = 0xff; | |
5403 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
5404 | } | |
fc6971d4 | 5405 | |
ea0de861 | 5406 | mac80211_hwsim_sband_capab(sband); |
518ea3c5 | 5407 | |
de0421d5 | 5408 | hw->wiphy->bands[band] = sband; |
de0421d5 | 5409 | } |
acc1e7a3 | 5410 | |
de0421d5 JB |
5411 | /* By default all radios belong to the first group */ |
5412 | data->group = 1; | |
5413 | mutex_init(&data->mutex); | |
fc6971d4 | 5414 | |
100cb9ff | 5415 | data->netgroup = hwsim_net_get_netgroup(net); |
4ea5aca2 | 5416 | data->wmediumd = hwsim_net_get_wmediumd(net); |
100cb9ff | 5417 | |
de0421d5 JB |
5418 | /* Enable frame retransmissions for lossy channels */ |
5419 | hw->max_rates = 4; | |
5420 | hw->max_rate_tries = 11; | |
fc6971d4 | 5421 | |
d5d011b4 JM |
5422 | hw->wiphy->vendor_commands = mac80211_hwsim_vendor_commands; |
5423 | hw->wiphy->n_vendor_commands = | |
5424 | ARRAY_SIZE(mac80211_hwsim_vendor_commands); | |
5425 | hw->wiphy->vendor_events = mac80211_hwsim_vendor_events; | |
5426 | hw->wiphy->n_vendor_events = ARRAY_SIZE(mac80211_hwsim_vendor_events); | |
5427 | ||
62759361 | 5428 | if (param->reg_strict) |
26b0e411 | 5429 | hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; |
62759361 | 5430 | if (param->regd) { |
93d638d4 | 5431 | data->regd = param->regd; |
26b0e411 | 5432 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
62759361 | 5433 | wiphy_apply_custom_regulatory(hw->wiphy, param->regd); |
26b0e411 JB |
5434 | /* give the regulatory workqueue a chance to run */ |
5435 | schedule_timeout_interruptible(1); | |
5436 | } | |
fc6971d4 | 5437 | |
99b6877d AO |
5438 | wiphy_ext_feature_set(hw->wiphy, |
5439 | NL80211_EXT_FEATURE_DFS_CONCURRENT); | |
5440 | ||
62759361 | 5441 | if (param->no_vif) |
30686bf7 | 5442 | ieee80211_hw_set(hw, NO_AUTO_VIF); |
9a0cb89a | 5443 | |
ae44b502 AZ |
5444 | wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST); |
5445 | ||
e57f8a48 ST |
5446 | for (i = 0; i < ARRAY_SIZE(data->link_data); i++) { |
5447 | hrtimer_init(&data->link_data[i].beacon_timer, CLOCK_MONOTONIC, | |
5448 | HRTIMER_MODE_ABS_SOFT); | |
5449 | data->link_data[i].beacon_timer.function = | |
5450 | mac80211_hwsim_beacon; | |
5451 | data->link_data[i].link_id = i; | |
5452 | } | |
a1881c9b | 5453 | |
de0421d5 JB |
5454 | err = ieee80211_register_hw(hw); |
5455 | if (err < 0) { | |
62b093b3 | 5456 | pr_debug("mac80211_hwsim: ieee80211_register_hw failed (%d)\n", |
de0421d5 JB |
5457 | err); |
5458 | goto failed_hw; | |
5459 | } | |
fc6971d4 | 5460 | |
62b093b3 | 5461 | wiphy_dbg(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr); |
fc6971d4 | 5462 | |
93d638d4 PF |
5463 | if (param->reg_alpha2) { |
5464 | data->alpha2[0] = param->reg_alpha2[0]; | |
5465 | data->alpha2[1] = param->reg_alpha2[1]; | |
62759361 | 5466 | regulatory_hint(hw->wiphy, param->reg_alpha2); |
93d638d4 | 5467 | } |
7882513b | 5468 | |
de0421d5 JB |
5469 | data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir); |
5470 | debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps); | |
5471 | debugfs_create_file("group", 0666, data->debugfs, data, | |
5472 | &hwsim_fops_group); | |
b59fb546 BL |
5473 | debugfs_create_file("rx_rssi", 0666, data->debugfs, data, |
5474 | &hwsim_fops_rx_rssi); | |
361c3e04 | 5475 | if (!data->use_chanctx) |
de0421d5 JB |
5476 | debugfs_create_file("dfs_simulate_radar", 0222, |
5477 | data->debugfs, | |
5478 | data, &hwsim_simulate_radar); | |
fc6971d4 | 5479 | |
92d13386 JK |
5480 | if (param->pmsr_capa) { |
5481 | data->pmsr_capa = *param->pmsr_capa; | |
5482 | hw->wiphy->pmsr_capa = &data->pmsr_capa; | |
5483 | } | |
5484 | ||
de0421d5 | 5485 | spin_lock_bh(&hwsim_radio_lock); |
c6509cc3 BB |
5486 | err = rhashtable_insert_fast(&hwsim_radios_rht, &data->rht, |
5487 | hwsim_rht_params); | |
5488 | if (err < 0) { | |
301b0404 BB |
5489 | if (info) { |
5490 | GENL_SET_ERR_MSG(info, "perm addr already present"); | |
5491 | NL_SET_BAD_ATTR(info->extack, | |
5492 | info->attrs[HWSIM_ATTR_PERM_ADDR]); | |
5493 | } | |
c6509cc3 BB |
5494 | spin_unlock_bh(&hwsim_radio_lock); |
5495 | goto failed_final_insert; | |
5496 | } | |
5497 | ||
de0421d5 | 5498 | list_add_tail(&data->list, &hwsim_radios); |
6335698e | 5499 | hwsim_radios_generation++; |
de0421d5 | 5500 | spin_unlock_bh(&hwsim_radio_lock); |
fc6971d4 | 5501 | |
28ef8b49 | 5502 | hwsim_mcast_new_radio(idx, info, param); |
62759361 | 5503 | |
bc791098 | 5504 | return idx; |
fc6971d4 | 5505 | |
c6509cc3 BB |
5506 | failed_final_insert: |
5507 | debugfs_remove_recursive(data->debugfs); | |
5508 | ieee80211_unregister_hw(data->hw); | |
de0421d5 | 5509 | failed_hw: |
805dbe17 JM |
5510 | device_release_driver(data->dev); |
5511 | failed_bind: | |
de0421d5 JB |
5512 | device_unregister(data->dev); |
5513 | failed_drvdata: | |
5514 | ieee80211_free_hw(hw); | |
5515 | failed: | |
5516 | return err; | |
fc6971d4 JM |
5517 | } |
5518 | ||
579a05f2 JR |
5519 | static void hwsim_mcast_del_radio(int id, const char *hwname, |
5520 | struct genl_info *info) | |
fc6971d4 | 5521 | { |
579a05f2 JR |
5522 | struct sk_buff *skb; |
5523 | void *data; | |
5524 | int ret; | |
5525 | ||
5526 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5527 | if (!skb) | |
5528 | return; | |
5529 | ||
5530 | data = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, | |
5531 | HWSIM_CMD_DEL_RADIO); | |
5532 | if (!data) | |
5533 | goto error; | |
5534 | ||
5535 | ret = nla_put_u32(skb, HWSIM_ATTR_RADIO_ID, id); | |
5536 | if (ret < 0) | |
5537 | goto error; | |
5538 | ||
b9995f83 JR |
5539 | ret = nla_put(skb, HWSIM_ATTR_RADIO_NAME, strlen(hwname), |
5540 | hwname); | |
5541 | if (ret < 0) | |
5542 | goto error; | |
579a05f2 JR |
5543 | |
5544 | genlmsg_end(skb, data); | |
5545 | ||
5546 | hwsim_mcast_config_msg(skb, info); | |
5547 | ||
5548 | return; | |
5549 | ||
5550 | error: | |
5551 | nlmsg_free(skb); | |
5552 | } | |
5553 | ||
5554 | static void mac80211_hwsim_del_radio(struct mac80211_hwsim_data *data, | |
5555 | const char *hwname, | |
5556 | struct genl_info *info) | |
5557 | { | |
5558 | hwsim_mcast_del_radio(data->idx, hwname, info); | |
de0421d5 JB |
5559 | debugfs_remove_recursive(data->debugfs); |
5560 | ieee80211_unregister_hw(data->hw); | |
5561 | device_release_driver(data->dev); | |
5562 | device_unregister(data->dev); | |
5563 | ieee80211_free_hw(data->hw); | |
fc6971d4 JM |
5564 | } |
5565 | ||
93d638d4 PF |
5566 | static int mac80211_hwsim_get_radio(struct sk_buff *skb, |
5567 | struct mac80211_hwsim_data *data, | |
5568 | u32 portid, u32 seq, | |
5569 | struct netlink_callback *cb, int flags) | |
5570 | { | |
5571 | void *hdr; | |
5572 | struct hwsim_new_radio_params param = { }; | |
5573 | int res = -EMSGSIZE; | |
5574 | ||
5575 | hdr = genlmsg_put(skb, portid, seq, &hwsim_genl_family, flags, | |
5576 | HWSIM_CMD_GET_RADIO); | |
5577 | if (!hdr) | |
5578 | return -EMSGSIZE; | |
5579 | ||
5580 | if (cb) | |
0a833c29 | 5581 | genl_dump_check_consistent(cb, hdr); |
93d638d4 | 5582 | |
b0ad5e8b PF |
5583 | if (data->alpha2[0] && data->alpha2[1]) |
5584 | param.reg_alpha2 = data->alpha2; | |
5585 | ||
93d638d4 PF |
5586 | param.reg_strict = !!(data->hw->wiphy->regulatory_flags & |
5587 | REGULATORY_STRICT_REG); | |
5588 | param.p2p_device = !!(data->hw->wiphy->interface_modes & | |
5589 | BIT(NL80211_IFTYPE_P2P_DEVICE)); | |
5590 | param.use_chanctx = data->use_chanctx; | |
5591 | param.regd = data->regd; | |
5592 | param.channels = data->channels; | |
5593 | param.hwname = wiphy_name(data->hw->wiphy); | |
92d13386 | 5594 | param.pmsr_capa = &data->pmsr_capa; |
93d638d4 PF |
5595 | |
5596 | res = append_radio_msg(skb, data->idx, ¶m); | |
5597 | if (res < 0) | |
5598 | goto out_err; | |
5599 | ||
053c095a JB |
5600 | genlmsg_end(skb, hdr); |
5601 | return 0; | |
93d638d4 PF |
5602 | |
5603 | out_err: | |
5604 | genlmsg_cancel(skb, hdr); | |
5605 | return res; | |
5606 | } | |
5607 | ||
de0421d5 | 5608 | static void mac80211_hwsim_free(void) |
fc6971d4 | 5609 | { |
de0421d5 | 5610 | struct mac80211_hwsim_data *data; |
fc6971d4 | 5611 | |
de0421d5 JB |
5612 | spin_lock_bh(&hwsim_radio_lock); |
5613 | while ((data = list_first_entry_or_null(&hwsim_radios, | |
5614 | struct mac80211_hwsim_data, | |
5615 | list))) { | |
5616 | list_del(&data->list); | |
5617 | spin_unlock_bh(&hwsim_radio_lock); | |
b9995f83 JR |
5618 | mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy), |
5619 | NULL); | |
de0421d5 | 5620 | spin_lock_bh(&hwsim_radio_lock); |
fc6971d4 | 5621 | } |
de0421d5 JB |
5622 | spin_unlock_bh(&hwsim_radio_lock); |
5623 | class_destroy(hwsim_class); | |
bba05e3d JD |
5624 | } |
5625 | ||
de0421d5 JB |
5626 | static const struct net_device_ops hwsim_netdev_ops = { |
5627 | .ndo_start_xmit = hwsim_mon_xmit, | |
de0421d5 JB |
5628 | .ndo_set_mac_address = eth_mac_addr, |
5629 | .ndo_validate_addr = eth_validate_addr, | |
5630 | }; | |
73606d00 | 5631 | |
de0421d5 | 5632 | static void hwsim_mon_setup(struct net_device *dev) |
73606d00 | 5633 | { |
e76219e6 JK |
5634 | u8 addr[ETH_ALEN]; |
5635 | ||
de0421d5 | 5636 | dev->netdev_ops = &hwsim_netdev_ops; |
cf124db5 | 5637 | dev->needs_free_netdev = true; |
de0421d5 | 5638 | ether_setup(dev); |
3db6da1f | 5639 | dev->priv_flags |= IFF_NO_QUEUE; |
de0421d5 | 5640 | dev->type = ARPHRD_IEEE80211_RADIOTAP; |
e76219e6 JK |
5641 | eth_zero_addr(addr); |
5642 | addr[0] = 0x12; | |
5643 | eth_hw_addr_set(dev, addr); | |
73606d00 DW |
5644 | } |
5645 | ||
f21e4d8e MW |
5646 | static void hwsim_register_wmediumd(struct net *net, u32 portid) |
5647 | { | |
5648 | struct mac80211_hwsim_data *data; | |
5649 | ||
5650 | hwsim_net_set_wmediumd(net, portid); | |
5651 | ||
5652 | spin_lock_bh(&hwsim_radio_lock); | |
5653 | list_for_each_entry(data, &hwsim_radios, list) { | |
5654 | if (data->netgroup == hwsim_net_get_netgroup(net)) | |
5655 | data->wmediumd = portid; | |
5656 | } | |
5657 | spin_unlock_bh(&hwsim_radio_lock); | |
5658 | } | |
5659 | ||
7882513b JL |
5660 | static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, |
5661 | struct genl_info *info) | |
5662 | { | |
5663 | ||
5664 | struct ieee80211_hdr *hdr; | |
5665 | struct mac80211_hwsim_data *data2; | |
5666 | struct ieee80211_tx_info *txi; | |
5667 | struct hwsim_tx_rate *tx_attempts; | |
959eb2fd | 5668 | u64 ret_skb_cookie; |
7882513b | 5669 | struct sk_buff *skb, *tmp; |
9ddd12af | 5670 | const u8 *src; |
7882513b | 5671 | unsigned int hwsim_flags; |
7882513b | 5672 | int i; |
4ee186fa | 5673 | unsigned long flags; |
7882513b JL |
5674 | bool found = false; |
5675 | ||
5676 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || | |
9ddd12af JB |
5677 | !info->attrs[HWSIM_ATTR_FLAGS] || |
5678 | !info->attrs[HWSIM_ATTR_COOKIE] || | |
62397da5 | 5679 | !info->attrs[HWSIM_ATTR_SIGNAL] || |
9ddd12af | 5680 | !info->attrs[HWSIM_ATTR_TX_INFO]) |
7882513b JL |
5681 | goto out; |
5682 | ||
9ddd12af | 5683 | src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); |
7882513b | 5684 | hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); |
959eb2fd | 5685 | ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); |
7882513b JL |
5686 | |
5687 | data2 = get_hwsim_data_ref_from_addr(src); | |
9ddd12af | 5688 | if (!data2) |
7882513b JL |
5689 | goto out; |
5690 | ||
5d44fe7c EG |
5691 | if (!hwsim_virtio_enabled) { |
5692 | if (hwsim_net_get_netgroup(genl_info_net(info)) != | |
5693 | data2->netgroup) | |
5694 | goto out; | |
f21e4d8e | 5695 | |
5d44fe7c EG |
5696 | if (info->snd_portid != data2->wmediumd) |
5697 | goto out; | |
5698 | } | |
f21e4d8e | 5699 | |
7882513b | 5700 | /* look for the skb matching the cookie passed back from user */ |
4ee186fa | 5701 | spin_lock_irqsave(&data2->pending.lock, flags); |
7882513b | 5702 | skb_queue_walk_safe(&data2->pending, skb, tmp) { |
cc5250cd | 5703 | uintptr_t skb_cookie; |
959eb2fd JB |
5704 | |
5705 | txi = IEEE80211_SKB_CB(skb); | |
cc5250cd | 5706 | skb_cookie = (uintptr_t)txi->rate_driver_data[0]; |
959eb2fd JB |
5707 | |
5708 | if (skb_cookie == ret_skb_cookie) { | |
4ee186fa | 5709 | __skb_unlink(skb, &data2->pending); |
7882513b JL |
5710 | found = true; |
5711 | break; | |
5712 | } | |
5713 | } | |
4ee186fa | 5714 | spin_unlock_irqrestore(&data2->pending.lock, flags); |
7882513b JL |
5715 | |
5716 | /* not found */ | |
5717 | if (!found) | |
5718 | goto out; | |
5719 | ||
5720 | /* Tx info received because the frame was broadcasted on user space, | |
5721 | so we get all the necessary info: tx attempts and skb control buff */ | |
5722 | ||
5723 | tx_attempts = (struct hwsim_tx_rate *)nla_data( | |
5724 | info->attrs[HWSIM_ATTR_TX_INFO]); | |
5725 | ||
5726 | /* now send back TX status */ | |
5727 | txi = IEEE80211_SKB_CB(skb); | |
5728 | ||
7882513b JL |
5729 | ieee80211_tx_info_clear_status(txi); |
5730 | ||
5731 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { | |
5732 | txi->status.rates[i].idx = tx_attempts[i].idx; | |
5733 | txi->status.rates[i].count = tx_attempts[i].count; | |
7882513b JL |
5734 | } |
5735 | ||
5736 | txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); | |
5737 | ||
5738 | if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) && | |
5739 | (hwsim_flags & HWSIM_TX_STAT_ACK)) { | |
5740 | if (skb->len >= 16) { | |
5741 | hdr = (struct ieee80211_hdr *) skb->data; | |
c0e30763 | 5742 | mac80211_hwsim_monitor_ack(data2->channel, |
e8261171 | 5743 | hdr->addr2); |
7882513b | 5744 | } |
06cf5c4c | 5745 | txi->flags |= IEEE80211_TX_STAT_ACK; |
7882513b | 5746 | } |
42a79960 BB |
5747 | |
5748 | if (hwsim_flags & HWSIM_TX_CTL_NO_ACK) | |
5749 | txi->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED; | |
5750 | ||
7882513b JL |
5751 | ieee80211_tx_status_irqsafe(data2->hw, skb); |
5752 | return 0; | |
5753 | out: | |
5754 | return -EINVAL; | |
5755 | ||
5756 | } | |
5757 | ||
5758 | static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, | |
5759 | struct genl_info *info) | |
5760 | { | |
e8261171 | 5761 | struct mac80211_hwsim_data *data2; |
7882513b | 5762 | struct ieee80211_rx_status rx_status; |
05d610af | 5763 | struct ieee80211_hdr *hdr; |
9ddd12af | 5764 | const u8 *dst; |
7882513b | 5765 | int frame_data_len; |
9ddd12af | 5766 | void *frame_data; |
7882513b | 5767 | struct sk_buff *skb = NULL; |
626c30f9 | 5768 | struct ieee80211_channel *channel = NULL; |
7882513b JL |
5769 | |
5770 | if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || | |
e8261171 JB |
5771 | !info->attrs[HWSIM_ATTR_FRAME] || |
5772 | !info->attrs[HWSIM_ATTR_RX_RATE] || | |
5773 | !info->attrs[HWSIM_ATTR_SIGNAL]) | |
7882513b JL |
5774 | goto out; |
5775 | ||
9ddd12af | 5776 | dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]); |
7882513b | 5777 | frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); |
9ddd12af | 5778 | frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); |
7882513b | 5779 | |
fba360a0 JB |
5780 | if (frame_data_len < sizeof(struct ieee80211_hdr_3addr) || |
5781 | frame_data_len > IEEE80211_MAX_DATA_LEN) | |
5782 | goto err; | |
5783 | ||
7882513b JL |
5784 | /* Allocate new skb here */ |
5785 | skb = alloc_skb(frame_data_len, GFP_KERNEL); | |
5786 | if (skb == NULL) | |
5787 | goto err; | |
5788 | ||
9ddd12af | 5789 | /* Copy the data */ |
59ae1d12 | 5790 | skb_put_data(skb, frame_data, frame_data_len); |
7882513b | 5791 | |
9ddd12af JB |
5792 | data2 = get_hwsim_data_ref_from_addr(dst); |
5793 | if (!data2) | |
7882513b JL |
5794 | goto out; |
5795 | ||
626c30f9 WD |
5796 | if (data2->use_chanctx) { |
5797 | if (data2->tmp_chan) | |
5798 | channel = data2->tmp_chan; | |
626c30f9 WD |
5799 | } else { |
5800 | channel = data2->channel; | |
5801 | } | |
626c30f9 | 5802 | |
5d44fe7c EG |
5803 | if (!hwsim_virtio_enabled) { |
5804 | if (hwsim_net_get_netgroup(genl_info_net(info)) != | |
5805 | data2->netgroup) | |
5806 | goto out; | |
f21e4d8e | 5807 | |
5d44fe7c EG |
5808 | if (info->snd_portid != data2->wmediumd) |
5809 | goto out; | |
5810 | } | |
f21e4d8e | 5811 | |
7882513b JL |
5812 | /* check if radio is configured properly */ |
5813 | ||
626c30f9 | 5814 | if ((data2->idle && !data2->tmp_chan) || !data2->started) |
7882513b JL |
5815 | goto out; |
5816 | ||
9ddd12af | 5817 | /* A frame is received from user space */ |
7882513b | 5818 | memset(&rx_status, 0, sizeof(rx_status)); |
641cf2a5 | 5819 | if (info->attrs[HWSIM_ATTR_FREQ]) { |
c204d9df JB |
5820 | struct tx_iter_data iter_data = {}; |
5821 | ||
641cf2a5 | 5822 | /* throw away off-channel packets, but allow both the temporary |
c204d9df JB |
5823 | * ("hw" scan/remain-on-channel), regular channels and links, |
5824 | * since the internal datapath also allows this | |
641cf2a5 | 5825 | */ |
641cf2a5 AW |
5826 | rx_status.freq = nla_get_u32(info->attrs[HWSIM_ATTR_FREQ]); |
5827 | ||
c204d9df JB |
5828 | iter_data.channel = ieee80211_get_channel(data2->hw->wiphy, |
5829 | rx_status.freq); | |
5830 | if (!iter_data.channel) | |
641cf2a5 | 5831 | goto out; |
c087f9fc | 5832 | rx_status.band = iter_data.channel->band; |
c204d9df JB |
5833 | |
5834 | mutex_lock(&data2->mutex); | |
5835 | if (!hwsim_chans_compat(iter_data.channel, channel)) { | |
5836 | ieee80211_iterate_active_interfaces_atomic( | |
5837 | data2->hw, IEEE80211_IFACE_ITER_NORMAL, | |
5838 | mac80211_hwsim_tx_iter, &iter_data); | |
5839 | if (!iter_data.receive) { | |
5840 | mutex_unlock(&data2->mutex); | |
5841 | goto out; | |
5842 | } | |
641cf2a5 AW |
5843 | } |
5844 | mutex_unlock(&data2->mutex); | |
c087f9fc JB |
5845 | } else if (!channel) { |
5846 | goto out; | |
641cf2a5 | 5847 | } else { |
626c30f9 | 5848 | rx_status.freq = channel->center_freq; |
c087f9fc | 5849 | rx_status.band = channel->band; |
641cf2a5 AW |
5850 | } |
5851 | ||
7882513b | 5852 | rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]); |
1833b6f4 JB |
5853 | if (rx_status.rate_idx >= data2->hw->wiphy->bands[rx_status.band]->n_bitrates) |
5854 | goto out; | |
7882513b JL |
5855 | rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); |
5856 | ||
05d610af JB |
5857 | hdr = (void *)skb->data; |
5858 | ||
5859 | if (ieee80211_is_beacon(hdr->frame_control) || | |
5860 | ieee80211_is_probe_resp(hdr->frame_control)) | |
5861 | rx_status.boottime_ns = ktime_get_boottime_ns(); | |
5862 | ||
b1622ada | 5863 | mac80211_hwsim_rx(data2, &rx_status, skb); |
7882513b JL |
5864 | |
5865 | return 0; | |
5866 | err: | |
62b093b3 | 5867 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
7882513b JL |
5868 | out: |
5869 | dev_kfree_skb(skb); | |
5870 | return -EINVAL; | |
5871 | } | |
5872 | ||
5873 | static int hwsim_register_received_nl(struct sk_buff *skb_2, | |
5874 | struct genl_info *info) | |
5875 | { | |
f21e4d8e | 5876 | struct net *net = genl_info_net(info); |
c5ac0854 JB |
5877 | struct mac80211_hwsim_data *data; |
5878 | int chans = 1; | |
5879 | ||
5880 | spin_lock_bh(&hwsim_radio_lock); | |
5881 | list_for_each_entry(data, &hwsim_radios, list) | |
5882 | chans = max(chans, data->channels); | |
5883 | spin_unlock_bh(&hwsim_radio_lock); | |
5884 | ||
5885 | /* In the future we should revise the userspace API and allow it | |
5886 | * to set a flag that it does support multi-channel, then we can | |
5887 | * let this pass conditionally on the flag. | |
5888 | * For current userspace, prohibit it since it won't work right. | |
5889 | */ | |
5890 | if (chans > 1) | |
5891 | return -EOPNOTSUPP; | |
5892 | ||
f21e4d8e | 5893 | if (hwsim_net_get_wmediumd(net)) |
85ca8fc7 | 5894 | return -EBUSY; |
7882513b | 5895 | |
f21e4d8e | 5896 | hwsim_register_wmediumd(net, info->snd_portid); |
7882513b | 5897 | |
62b093b3 | 5898 | pr_debug("mac80211_hwsim: received a REGISTER, " |
15e47304 | 5899 | "switching to wmediumd mode with pid %d\n", info->snd_portid); |
7882513b JL |
5900 | |
5901 | return 0; | |
7882513b JL |
5902 | } |
5903 | ||
c0a0189d JP |
5904 | /* ensures ciphers only include ciphers listed in 'hwsim_ciphers' array */ |
5905 | static bool hwsim_known_ciphers(const u32 *ciphers, int n_ciphers) | |
5906 | { | |
5907 | int i; | |
5908 | ||
5909 | for (i = 0; i < n_ciphers; i++) { | |
5910 | int j; | |
5911 | int found = 0; | |
5912 | ||
5913 | for (j = 0; j < ARRAY_SIZE(hwsim_ciphers); j++) { | |
5914 | if (ciphers[i] == hwsim_ciphers[j]) { | |
5915 | found = 1; | |
5916 | break; | |
5917 | } | |
5918 | } | |
5919 | ||
5920 | if (!found) | |
5921 | return false; | |
5922 | } | |
5923 | ||
5924 | return true; | |
5925 | } | |
5926 | ||
92d13386 JK |
5927 | static int parse_ftm_capa(const struct nlattr *ftm_capa, struct cfg80211_pmsr_capabilities *out, |
5928 | struct genl_info *info) | |
5929 | { | |
5930 | struct nlattr *tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX + 1]; | |
5931 | int ret; | |
5932 | ||
5933 | ret = nla_parse_nested(tb, NL80211_PMSR_FTM_CAPA_ATTR_MAX, ftm_capa, hwsim_ftm_capa_policy, | |
5934 | NULL); | |
5935 | if (ret) { | |
5936 | NL_SET_ERR_MSG_ATTR(info->extack, ftm_capa, "malformed FTM capability"); | |
5937 | return -EINVAL; | |
5938 | } | |
5939 | ||
5940 | out->ftm.supported = 1; | |
5941 | if (tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES]) | |
5942 | out->ftm.preambles = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES]); | |
5943 | if (tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS]) | |
5944 | out->ftm.bandwidths = nla_get_u32(tb[NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS]); | |
5945 | if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT]) | |
5946 | out->ftm.max_bursts_exponent = | |
5947 | nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT]); | |
5948 | if (tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST]) | |
5949 | out->ftm.max_ftms_per_burst = | |
5950 | nla_get_u8(tb[NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST]); | |
5951 | out->ftm.asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_ASAP]; | |
5952 | out->ftm.non_asap = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP]; | |
5953 | out->ftm.request_lci = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI]; | |
5954 | out->ftm.request_civicloc = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC]; | |
5955 | out->ftm.trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED]; | |
5956 | out->ftm.non_trigger_based = !!tb[NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED]; | |
5957 | ||
5958 | return 0; | |
5959 | } | |
5960 | ||
5961 | static int parse_pmsr_capa(const struct nlattr *pmsr_capa, struct cfg80211_pmsr_capabilities *out, | |
5962 | struct genl_info *info) | |
5963 | { | |
5964 | struct nlattr *tb[NL80211_PMSR_ATTR_MAX + 1]; | |
5965 | struct nlattr *nla; | |
5966 | int size; | |
5967 | int ret; | |
5968 | ||
5969 | ret = nla_parse_nested(tb, NL80211_PMSR_ATTR_MAX, pmsr_capa, hwsim_pmsr_capa_policy, NULL); | |
5970 | if (ret) { | |
5971 | NL_SET_ERR_MSG_ATTR(info->extack, pmsr_capa, "malformed PMSR capability"); | |
5972 | return -EINVAL; | |
5973 | } | |
5974 | ||
5975 | if (tb[NL80211_PMSR_ATTR_MAX_PEERS]) | |
5976 | out->max_peers = nla_get_u32(tb[NL80211_PMSR_ATTR_MAX_PEERS]); | |
5977 | out->report_ap_tsf = !!tb[NL80211_PMSR_ATTR_REPORT_AP_TSF]; | |
5978 | out->randomize_mac_addr = !!tb[NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR]; | |
5979 | ||
5980 | if (!tb[NL80211_PMSR_ATTR_TYPE_CAPA]) { | |
5981 | NL_SET_ERR_MSG_ATTR(info->extack, tb[NL80211_PMSR_ATTR_TYPE_CAPA], | |
5982 | "malformed PMSR type"); | |
5983 | return -EINVAL; | |
5984 | } | |
5985 | ||
5986 | nla_for_each_nested(nla, tb[NL80211_PMSR_ATTR_TYPE_CAPA], size) { | |
5987 | switch (nla_type(nla)) { | |
5988 | case NL80211_PMSR_TYPE_FTM: | |
5989 | parse_ftm_capa(nla, out, info); | |
5990 | break; | |
5991 | default: | |
5992 | NL_SET_ERR_MSG_ATTR(info->extack, nla, "unsupported measurement type"); | |
5993 | return -EINVAL; | |
5994 | } | |
5995 | } | |
5996 | ||
5997 | return 0; | |
5998 | } | |
5999 | ||
62759361 | 6000 | static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info) |
bc791098 | 6001 | { |
62759361 | 6002 | struct hwsim_new_radio_params param = { 0 }; |
ff4dd73d | 6003 | const char *hwname = NULL; |
67bd5238 | 6004 | int ret; |
62759361 JR |
6005 | |
6006 | param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG]; | |
6007 | param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; | |
6008 | param.channels = channels; | |
6009 | param.destroy_on_close = | |
6010 | info->attrs[HWSIM_ATTR_DESTROY_RADIO_ON_CLOSE]; | |
bc791098 JB |
6011 | |
6012 | if (info->attrs[HWSIM_ATTR_CHANNELS]) | |
62759361 | 6013 | param.channels = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); |
bc791098 | 6014 | |
48400433 JB |
6015 | if (param.channels < 1) { |
6016 | GENL_SET_ERR_MSG(info, "must have at least one channel"); | |
6017 | return -EINVAL; | |
6018 | } | |
6019 | ||
9a0cb89a | 6020 | if (info->attrs[HWSIM_ATTR_NO_VIF]) |
62759361 | 6021 | param.no_vif = true; |
9a0cb89a | 6022 | |
361c3e04 | 6023 | if (info->attrs[HWSIM_ATTR_USE_CHANCTX]) |
62759361 | 6024 | param.use_chanctx = true; |
361c3e04 | 6025 | else |
62759361 | 6026 | param.use_chanctx = (param.channels > 1); |
361c3e04 | 6027 | |
26b0e411 | 6028 | if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]) |
62759361 JR |
6029 | param.reg_alpha2 = |
6030 | nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]); | |
26b0e411 JB |
6031 | |
6032 | if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) { | |
6033 | u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]); | |
6034 | ||
2f98abb1 | 6035 | if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) |
26b0e411 | 6036 | return -EINVAL; |
3a2af7cc JP |
6037 | |
6038 | idx = array_index_nospec(idx, | |
6039 | ARRAY_SIZE(hwsim_world_regdom_custom)); | |
62759361 | 6040 | param.regd = hwsim_world_regdom_custom[idx]; |
26b0e411 JB |
6041 | } |
6042 | ||
cb1a5bae BB |
6043 | if (info->attrs[HWSIM_ATTR_PERM_ADDR]) { |
6044 | if (!is_valid_ether_addr( | |
6045 | nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]))) { | |
6046 | GENL_SET_ERR_MSG(info,"MAC is no valid source addr"); | |
6047 | NL_SET_BAD_ATTR(info->extack, | |
6048 | info->attrs[HWSIM_ATTR_PERM_ADDR]); | |
6049 | return -EINVAL; | |
6050 | } | |
6051 | ||
cb1a5bae BB |
6052 | param.perm_addr = nla_data(info->attrs[HWSIM_ATTR_PERM_ADDR]); |
6053 | } | |
6054 | ||
99e3a44b JP |
6055 | if (info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]) { |
6056 | param.iftypes = | |
6057 | nla_get_u32(info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT]); | |
6058 | ||
6059 | if (param.iftypes & ~HWSIM_IFTYPE_SUPPORT_MASK) { | |
6060 | NL_SET_ERR_MSG_ATTR(info->extack, | |
6061 | info->attrs[HWSIM_ATTR_IFTYPE_SUPPORT], | |
6062 | "cannot support more iftypes than kernel"); | |
6063 | return -EINVAL; | |
6064 | } | |
6065 | } else { | |
6066 | param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK; | |
6067 | } | |
6068 | ||
6069 | /* ensure both flag and iftype support is honored */ | |
6070 | if (param.p2p_device || | |
6071 | param.iftypes & BIT(NL80211_IFTYPE_P2P_DEVICE)) { | |
6072 | param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE); | |
6073 | param.p2p_device = true; | |
6074 | } | |
6075 | ||
c0a0189d JP |
6076 | if (info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]) { |
6077 | u32 len = nla_len(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]); | |
6078 | ||
6079 | param.ciphers = | |
6080 | nla_data(info->attrs[HWSIM_ATTR_CIPHER_SUPPORT]); | |
6081 | ||
6082 | if (len % sizeof(u32)) { | |
6083 | NL_SET_ERR_MSG_ATTR(info->extack, | |
6084 | info->attrs[HWSIM_ATTR_CIPHER_SUPPORT], | |
6085 | "bad cipher list length"); | |
6086 | return -EINVAL; | |
6087 | } | |
6088 | ||
6089 | param.n_ciphers = len / sizeof(u32); | |
6090 | ||
6091 | if (param.n_ciphers > ARRAY_SIZE(hwsim_ciphers)) { | |
6092 | NL_SET_ERR_MSG_ATTR(info->extack, | |
6093 | info->attrs[HWSIM_ATTR_CIPHER_SUPPORT], | |
6094 | "too many ciphers specified"); | |
6095 | return -EINVAL; | |
6096 | } | |
6097 | ||
6098 | if (!hwsim_known_ciphers(param.ciphers, param.n_ciphers)) { | |
6099 | NL_SET_ERR_MSG_ATTR(info->extack, | |
6100 | info->attrs[HWSIM_ATTR_CIPHER_SUPPORT], | |
6101 | "unsupported ciphers specified"); | |
6102 | return -EINVAL; | |
6103 | } | |
6104 | } | |
6105 | ||
2fd0c671 JB |
6106 | param.mlo = info->attrs[HWSIM_ATTR_MLO_SUPPORT]; |
6107 | ||
6108 | if (param.mlo) | |
6109 | param.use_chanctx = true; | |
6110 | ||
2f98abb1 | 6111 | if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { |
7ea86204 TT |
6112 | hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]), |
6113 | nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), | |
6114 | GFP_KERNEL); | |
2f98abb1 JB |
6115 | if (!hwname) |
6116 | return -ENOMEM; | |
6117 | param.hwname = hwname; | |
6118 | } | |
6119 | ||
92d13386 JK |
6120 | if (info->attrs[HWSIM_ATTR_PMSR_SUPPORT]) { |
6121 | struct cfg80211_pmsr_capabilities *pmsr_capa; | |
6122 | ||
6123 | pmsr_capa = kmalloc(sizeof(*pmsr_capa), GFP_KERNEL); | |
6124 | if (!pmsr_capa) { | |
6125 | ret = -ENOMEM; | |
6126 | goto out_free; | |
6127 | } | |
098abbd4 ZS |
6128 | param.pmsr_capa = pmsr_capa; |
6129 | ||
92d13386 JK |
6130 | ret = parse_pmsr_capa(info->attrs[HWSIM_ATTR_PMSR_SUPPORT], pmsr_capa, info); |
6131 | if (ret) | |
6132 | goto out_free; | |
92d13386 JK |
6133 | } |
6134 | ||
67bd5238 | 6135 | ret = mac80211_hwsim_new_radio(info, ¶m); |
92d13386 JK |
6136 | |
6137 | out_free: | |
67bd5238 | 6138 | kfree(hwname); |
92d13386 | 6139 | kfree(param.pmsr_capa); |
67bd5238 | 6140 | return ret; |
bc791098 JB |
6141 | } |
6142 | ||
579a05f2 | 6143 | static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info) |
bc791098 JB |
6144 | { |
6145 | struct mac80211_hwsim_data *data; | |
8cdd9e1c BG |
6146 | s64 idx = -1; |
6147 | const char *hwname = NULL; | |
bc791098 | 6148 | |
ff4dd73d | 6149 | if (info->attrs[HWSIM_ATTR_RADIO_ID]) { |
8cdd9e1c | 6150 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); |
ff4dd73d | 6151 | } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { |
7ea86204 TT |
6152 | hwname = kstrndup((char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]), |
6153 | nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), | |
6154 | GFP_KERNEL); | |
ff4dd73d JB |
6155 | if (!hwname) |
6156 | return -ENOMEM; | |
6157 | } else | |
bc791098 | 6158 | return -EINVAL; |
bc791098 JB |
6159 | |
6160 | spin_lock_bh(&hwsim_radio_lock); | |
6161 | list_for_each_entry(data, &hwsim_radios, list) { | |
8cdd9e1c BG |
6162 | if (idx >= 0) { |
6163 | if (data->idx != idx) | |
6164 | continue; | |
6165 | } else { | |
ff4dd73d JB |
6166 | if (!hwname || |
6167 | strcmp(hwname, wiphy_name(data->hw->wiphy))) | |
8cdd9e1c BG |
6168 | continue; |
6169 | } | |
6170 | ||
100cb9ff MW |
6171 | if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info))) |
6172 | continue; | |
6173 | ||
bc791098 | 6174 | list_del(&data->list); |
c6509cc3 BB |
6175 | rhashtable_remove_fast(&hwsim_radios_rht, &data->rht, |
6176 | hwsim_rht_params); | |
6335698e | 6177 | hwsim_radios_generation++; |
bc791098 | 6178 | spin_unlock_bh(&hwsim_radio_lock); |
b9995f83 JR |
6179 | mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy), |
6180 | info); | |
ff4dd73d | 6181 | kfree(hwname); |
bc791098 JB |
6182 | return 0; |
6183 | } | |
6184 | spin_unlock_bh(&hwsim_radio_lock); | |
6185 | ||
ff4dd73d | 6186 | kfree(hwname); |
bc791098 | 6187 | return -ENODEV; |
7882513b JL |
6188 | } |
6189 | ||
93d638d4 PF |
6190 | static int hwsim_get_radio_nl(struct sk_buff *msg, struct genl_info *info) |
6191 | { | |
6192 | struct mac80211_hwsim_data *data; | |
6193 | struct sk_buff *skb; | |
6194 | int idx, res = -ENODEV; | |
6195 | ||
6196 | if (!info->attrs[HWSIM_ATTR_RADIO_ID]) | |
6197 | return -EINVAL; | |
6198 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); | |
6199 | ||
6200 | spin_lock_bh(&hwsim_radio_lock); | |
6201 | list_for_each_entry(data, &hwsim_radios, list) { | |
6202 | if (data->idx != idx) | |
6203 | continue; | |
6204 | ||
100cb9ff MW |
6205 | if (!net_eq(wiphy_net(data->hw->wiphy), genl_info_net(info))) |
6206 | continue; | |
6207 | ||
162bd5e5 | 6208 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
93d638d4 PF |
6209 | if (!skb) { |
6210 | res = -ENOMEM; | |
6211 | goto out_err; | |
6212 | } | |
6213 | ||
6214 | res = mac80211_hwsim_get_radio(skb, data, info->snd_portid, | |
6215 | info->snd_seq, NULL, 0); | |
6216 | if (res < 0) { | |
6217 | nlmsg_free(skb); | |
6218 | goto out_err; | |
6219 | } | |
6220 | ||
17407715 | 6221 | res = genlmsg_reply(skb, info); |
93d638d4 PF |
6222 | break; |
6223 | } | |
6224 | ||
6225 | out_err: | |
6226 | spin_unlock_bh(&hwsim_radio_lock); | |
6227 | ||
6228 | return res; | |
6229 | } | |
6230 | ||
6231 | static int hwsim_dump_radio_nl(struct sk_buff *skb, | |
6232 | struct netlink_callback *cb) | |
6233 | { | |
fed48250 | 6234 | int last_idx = cb->args[0] - 1; |
93d638d4 | 6235 | struct mac80211_hwsim_data *data = NULL; |
6335698e BB |
6236 | int res = 0; |
6237 | void *hdr; | |
93d638d4 PF |
6238 | |
6239 | spin_lock_bh(&hwsim_radio_lock); | |
6335698e | 6240 | cb->seq = hwsim_radios_generation; |
93d638d4 | 6241 | |
6335698e | 6242 | if (last_idx >= hwsim_radio_idx-1) |
93d638d4 PF |
6243 | goto done; |
6244 | ||
6245 | list_for_each_entry(data, &hwsim_radios, list) { | |
6335698e | 6246 | if (data->idx <= last_idx) |
93d638d4 PF |
6247 | continue; |
6248 | ||
100cb9ff MW |
6249 | if (!net_eq(wiphy_net(data->hw->wiphy), sock_net(skb->sk))) |
6250 | continue; | |
6251 | ||
93d638d4 PF |
6252 | res = mac80211_hwsim_get_radio(skb, data, |
6253 | NETLINK_CB(cb->skb).portid, | |
6254 | cb->nlh->nlmsg_seq, cb, | |
6255 | NLM_F_MULTI); | |
6256 | if (res < 0) | |
6257 | break; | |
6258 | ||
6335698e | 6259 | last_idx = data->idx; |
93d638d4 PF |
6260 | } |
6261 | ||
fed48250 | 6262 | cb->args[0] = last_idx + 1; |
6335698e BB |
6263 | |
6264 | /* list changed, but no new element sent, set interrupted flag */ | |
6265 | if (skb->len == 0 && cb->prev_seq && cb->seq != cb->prev_seq) { | |
6266 | hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, | |
6267 | cb->nlh->nlmsg_seq, &hwsim_genl_family, | |
6268 | NLM_F_MULTI, HWSIM_CMD_GET_RADIO); | |
b55f3b84 JJB |
6269 | if (hdr) { |
6270 | genl_dump_check_consistent(cb, hdr); | |
6271 | genlmsg_end(skb, hdr); | |
6272 | } else { | |
6335698e | 6273 | res = -EMSGSIZE; |
b55f3b84 | 6274 | } |
6335698e | 6275 | } |
93d638d4 PF |
6276 | |
6277 | done: | |
6278 | spin_unlock_bh(&hwsim_radio_lock); | |
6335698e | 6279 | return res ?: skb->len; |
93d638d4 PF |
6280 | } |
6281 | ||
7882513b | 6282 | /* Generic Netlink operations array */ |
66a9b928 | 6283 | static const struct genl_small_ops hwsim_ops[] = { |
7882513b JL |
6284 | { |
6285 | .cmd = HWSIM_CMD_REGISTER, | |
ef6243ac | 6286 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
7882513b | 6287 | .doit = hwsim_register_received_nl, |
f21e4d8e | 6288 | .flags = GENL_UNS_ADMIN_PERM, |
7882513b JL |
6289 | }, |
6290 | { | |
6291 | .cmd = HWSIM_CMD_FRAME, | |
ef6243ac | 6292 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
7882513b JL |
6293 | .doit = hwsim_cloned_frame_received_nl, |
6294 | }, | |
6295 | { | |
6296 | .cmd = HWSIM_CMD_TX_INFO_FRAME, | |
ef6243ac | 6297 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
7882513b JL |
6298 | .doit = hwsim_tx_info_frame_received_nl, |
6299 | }, | |
bc791098 | 6300 | { |
62759361 | 6301 | .cmd = HWSIM_CMD_NEW_RADIO, |
ef6243ac | 6302 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
62759361 | 6303 | .doit = hwsim_new_radio_nl, |
100cb9ff | 6304 | .flags = GENL_UNS_ADMIN_PERM, |
bc791098 JB |
6305 | }, |
6306 | { | |
579a05f2 | 6307 | .cmd = HWSIM_CMD_DEL_RADIO, |
ef6243ac | 6308 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
579a05f2 | 6309 | .doit = hwsim_del_radio_nl, |
100cb9ff | 6310 | .flags = GENL_UNS_ADMIN_PERM, |
bc791098 | 6311 | }, |
93d638d4 PF |
6312 | { |
6313 | .cmd = HWSIM_CMD_GET_RADIO, | |
ef6243ac | 6314 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
93d638d4 PF |
6315 | .doit = hwsim_get_radio_nl, |
6316 | .dumpit = hwsim_dump_radio_nl, | |
6317 | }, | |
2af3b2a6 JK |
6318 | { |
6319 | .cmd = HWSIM_CMD_REPORT_PMSR, | |
6320 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, | |
6321 | .doit = hwsim_pmsr_report_nl, | |
6322 | }, | |
7882513b JL |
6323 | }; |
6324 | ||
56989f6d | 6325 | static struct genl_family hwsim_genl_family __ro_after_init = { |
489111e5 JB |
6326 | .name = "MAC80211_HWSIM", |
6327 | .version = 1, | |
6328 | .maxattr = HWSIM_ATTR_MAX, | |
3b0f31f2 | 6329 | .policy = hwsim_genl_policy, |
489111e5 JB |
6330 | .netnsok = true, |
6331 | .module = THIS_MODULE, | |
66a9b928 JK |
6332 | .small_ops = hwsim_ops, |
6333 | .n_small_ops = ARRAY_SIZE(hwsim_ops), | |
2af3b2a6 | 6334 | .resv_start_op = HWSIM_CMD_REPORT_PMSR + 1, // match with __HWSIM_CMD_MAX |
489111e5 JB |
6335 | .mcgrps = hwsim_mcgrps, |
6336 | .n_mcgrps = ARRAY_SIZE(hwsim_mcgrps), | |
6337 | }; | |
6338 | ||
e9ed49bf JR |
6339 | static void remove_user_radios(u32 portid) |
6340 | { | |
6341 | struct mac80211_hwsim_data *entry, *tmp; | |
f1c47eb6 | 6342 | LIST_HEAD(list); |
e9ed49bf JR |
6343 | |
6344 | spin_lock_bh(&hwsim_radio_lock); | |
6345 | list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) { | |
6346 | if (entry->destroy_on_close && entry->portid == portid) { | |
f1c47eb6 | 6347 | list_move(&entry->list, &list); |
c6509cc3 BB |
6348 | rhashtable_remove_fast(&hwsim_radios_rht, &entry->rht, |
6349 | hwsim_rht_params); | |
f1c47eb6 | 6350 | hwsim_radios_generation++; |
e9ed49bf JR |
6351 | } |
6352 | } | |
6353 | spin_unlock_bh(&hwsim_radio_lock); | |
f1c47eb6 MW |
6354 | |
6355 | list_for_each_entry_safe(entry, tmp, &list, list) { | |
6356 | list_del(&entry->list); | |
6357 | mac80211_hwsim_del_radio(entry, wiphy_name(entry->hw->wiphy), | |
6358 | NULL); | |
6359 | } | |
e9ed49bf JR |
6360 | } |
6361 | ||
7882513b JL |
6362 | static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, |
6363 | unsigned long state, | |
6364 | void *_notify) | |
6365 | { | |
6366 | struct netlink_notify *notify = _notify; | |
6367 | ||
6368 | if (state != NETLINK_URELEASE) | |
6369 | return NOTIFY_DONE; | |
6370 | ||
e9ed49bf JR |
6371 | remove_user_radios(notify->portid); |
6372 | ||
f21e4d8e | 6373 | if (notify->portid == hwsim_net_get_wmediumd(notify->net)) { |
7882513b JL |
6374 | printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink" |
6375 | " socket, switching to perfect channel medium\n"); | |
f21e4d8e | 6376 | hwsim_register_wmediumd(notify->net, 0); |
7882513b JL |
6377 | } |
6378 | return NOTIFY_DONE; | |
6379 | ||
6380 | } | |
6381 | ||
6382 | static struct notifier_block hwsim_netlink_notifier = { | |
6383 | .notifier_call = mac80211_hwsim_netlink_notify, | |
6384 | }; | |
6385 | ||
56989f6d | 6386 | static int __init hwsim_init_netlink(void) |
7882513b JL |
6387 | { |
6388 | int rc; | |
e8261171 | 6389 | |
7882513b JL |
6390 | printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); |
6391 | ||
489111e5 | 6392 | rc = genl_register_family(&hwsim_genl_family); |
7882513b JL |
6393 | if (rc) |
6394 | goto failure; | |
6395 | ||
6396 | rc = netlink_register_notifier(&hwsim_netlink_notifier); | |
2459cd87 SKY |
6397 | if (rc) { |
6398 | genl_unregister_family(&hwsim_genl_family); | |
7882513b | 6399 | goto failure; |
2459cd87 | 6400 | } |
7882513b JL |
6401 | |
6402 | return 0; | |
6403 | ||
6404 | failure: | |
62b093b3 | 6405 | pr_debug("mac80211_hwsim: error occurred in %s\n", __func__); |
7882513b JL |
6406 | return -EINVAL; |
6407 | } | |
6408 | ||
100cb9ff MW |
6409 | static __net_init int hwsim_init_net(struct net *net) |
6410 | { | |
03695549 | 6411 | return hwsim_net_set_netgroup(net); |
100cb9ff MW |
6412 | } |
6413 | ||
6414 | static void __net_exit hwsim_exit_net(struct net *net) | |
6415 | { | |
6416 | struct mac80211_hwsim_data *data, *tmp; | |
628980e5 | 6417 | LIST_HEAD(list); |
100cb9ff MW |
6418 | |
6419 | spin_lock_bh(&hwsim_radio_lock); | |
6420 | list_for_each_entry_safe(data, tmp, &hwsim_radios, list) { | |
6421 | if (!net_eq(wiphy_net(data->hw->wiphy), net)) | |
6422 | continue; | |
6423 | ||
6424 | /* Radios created in init_net are returned to init_net. */ | |
6425 | if (data->netgroup == hwsim_net_get_netgroup(&init_net)) | |
6426 | continue; | |
6427 | ||
628980e5 | 6428 | list_move(&data->list, &list); |
c6509cc3 BB |
6429 | rhashtable_remove_fast(&hwsim_radios_rht, &data->rht, |
6430 | hwsim_rht_params); | |
8cfd36a0 | 6431 | hwsim_radios_generation++; |
628980e5 MW |
6432 | } |
6433 | spin_unlock_bh(&hwsim_radio_lock); | |
6434 | ||
6435 | list_for_each_entry_safe(data, tmp, &list, list) { | |
6436 | list_del(&data->list); | |
8cfd36a0 BB |
6437 | mac80211_hwsim_del_radio(data, |
6438 | wiphy_name(data->hw->wiphy), | |
6439 | NULL); | |
100cb9ff | 6440 | } |
03695549 | 6441 | |
1449c24e | 6442 | ida_free(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net)); |
100cb9ff MW |
6443 | } |
6444 | ||
6445 | static struct pernet_operations hwsim_net_ops = { | |
6446 | .init = hwsim_init_net, | |
6447 | .exit = hwsim_exit_net, | |
6448 | .id = &hwsim_net_id, | |
6449 | .size = sizeof(struct hwsim_net), | |
6450 | }; | |
6451 | ||
7882513b JL |
6452 | static void hwsim_exit_netlink(void) |
6453 | { | |
7882513b JL |
6454 | /* unregister the notifier */ |
6455 | netlink_unregister_notifier(&hwsim_netlink_notifier); | |
6456 | /* unregister the family */ | |
cf7a6b2d | 6457 | genl_unregister_family(&hwsim_genl_family); |
7882513b JL |
6458 | } |
6459 | ||
5d44fe7c EG |
6460 | #if IS_REACHABLE(CONFIG_VIRTIO) |
6461 | static void hwsim_virtio_tx_done(struct virtqueue *vq) | |
6462 | { | |
6463 | unsigned int len; | |
6464 | struct sk_buff *skb; | |
6465 | unsigned long flags; | |
6466 | ||
6467 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
6468 | while ((skb = virtqueue_get_buf(vq, &len))) | |
d40de0ad | 6469 | dev_kfree_skb_irq(skb); |
5d44fe7c EG |
6470 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); |
6471 | } | |
6472 | ||
6473 | static int hwsim_virtio_handle_cmd(struct sk_buff *skb) | |
6474 | { | |
6475 | struct nlmsghdr *nlh; | |
6476 | struct genlmsghdr *gnlh; | |
6477 | struct nlattr *tb[HWSIM_ATTR_MAX + 1]; | |
6478 | struct genl_info info = {}; | |
6479 | int err; | |
6480 | ||
6481 | nlh = nlmsg_hdr(skb); | |
6482 | gnlh = nlmsg_data(nlh); | |
8c042784 SH |
6483 | |
6484 | if (skb->len < nlh->nlmsg_len) | |
6485 | return -EINVAL; | |
6486 | ||
5d44fe7c EG |
6487 | err = genlmsg_parse(nlh, &hwsim_genl_family, tb, HWSIM_ATTR_MAX, |
6488 | hwsim_genl_policy, NULL); | |
6489 | if (err) { | |
6490 | pr_err_ratelimited("hwsim: genlmsg_parse returned %d\n", err); | |
6491 | return err; | |
6492 | } | |
6493 | ||
6494 | info.attrs = tb; | |
6495 | ||
6496 | switch (gnlh->cmd) { | |
6497 | case HWSIM_CMD_FRAME: | |
6498 | hwsim_cloned_frame_received_nl(skb, &info); | |
6499 | break; | |
6500 | case HWSIM_CMD_TX_INFO_FRAME: | |
6501 | hwsim_tx_info_frame_received_nl(skb, &info); | |
6502 | break; | |
2af3b2a6 JK |
6503 | case HWSIM_CMD_REPORT_PMSR: |
6504 | hwsim_pmsr_report_nl(skb, &info); | |
6505 | break; | |
5d44fe7c EG |
6506 | default: |
6507 | pr_err_ratelimited("hwsim: invalid cmd: %d\n", gnlh->cmd); | |
6508 | return -EPROTO; | |
6509 | } | |
6510 | return 0; | |
6511 | } | |
6512 | ||
6513 | static void hwsim_virtio_rx_work(struct work_struct *work) | |
6514 | { | |
6515 | struct virtqueue *vq; | |
6516 | unsigned int len; | |
6517 | struct sk_buff *skb; | |
6518 | struct scatterlist sg[1]; | |
6519 | int err; | |
6520 | unsigned long flags; | |
6521 | ||
6522 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
6523 | if (!hwsim_virtio_enabled) | |
6524 | goto out_unlock; | |
6525 | ||
6526 | skb = virtqueue_get_buf(hwsim_vqs[HWSIM_VQ_RX], &len); | |
6527 | if (!skb) | |
6528 | goto out_unlock; | |
6529 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
6530 | ||
6531 | skb->data = skb->head; | |
8c042784 SH |
6532 | skb_reset_tail_pointer(skb); |
6533 | skb_put(skb, len); | |
5d44fe7c EG |
6534 | hwsim_virtio_handle_cmd(skb); |
6535 | ||
6536 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
6537 | if (!hwsim_virtio_enabled) { | |
d40de0ad | 6538 | dev_kfree_skb_irq(skb); |
5d44fe7c EG |
6539 | goto out_unlock; |
6540 | } | |
6541 | vq = hwsim_vqs[HWSIM_VQ_RX]; | |
6542 | sg_init_one(sg, skb->head, skb_end_offset(skb)); | |
03798612 | 6543 | err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_ATOMIC); |
5d44fe7c | 6544 | if (WARN(err, "virtqueue_add_inbuf returned %d\n", err)) |
d40de0ad | 6545 | dev_kfree_skb_irq(skb); |
5d44fe7c EG |
6546 | else |
6547 | virtqueue_kick(vq); | |
6548 | schedule_work(&hwsim_virtio_rx); | |
6549 | ||
6550 | out_unlock: | |
6551 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
6552 | } | |
6553 | ||
6554 | static void hwsim_virtio_rx_done(struct virtqueue *vq) | |
6555 | { | |
6556 | schedule_work(&hwsim_virtio_rx); | |
6557 | } | |
6558 | ||
6559 | static int init_vqs(struct virtio_device *vdev) | |
6560 | { | |
6561 | vq_callback_t *callbacks[HWSIM_NUM_VQS] = { | |
6562 | [HWSIM_VQ_TX] = hwsim_virtio_tx_done, | |
6563 | [HWSIM_VQ_RX] = hwsim_virtio_rx_done, | |
6564 | }; | |
6565 | const char *names[HWSIM_NUM_VQS] = { | |
6566 | [HWSIM_VQ_TX] = "tx", | |
6567 | [HWSIM_VQ_RX] = "rx", | |
6568 | }; | |
6569 | ||
6570 | return virtio_find_vqs(vdev, HWSIM_NUM_VQS, | |
6571 | hwsim_vqs, callbacks, names, NULL); | |
6572 | } | |
6573 | ||
6574 | static int fill_vq(struct virtqueue *vq) | |
6575 | { | |
6576 | int i, err; | |
6577 | struct sk_buff *skb; | |
6578 | struct scatterlist sg[1]; | |
6579 | ||
6580 | for (i = 0; i < virtqueue_get_vring_size(vq); i++) { | |
6581 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6582 | if (!skb) | |
6583 | return -ENOMEM; | |
6584 | ||
6585 | sg_init_one(sg, skb->head, skb_end_offset(skb)); | |
6586 | err = virtqueue_add_inbuf(vq, sg, 1, skb, GFP_KERNEL); | |
6587 | if (err) { | |
6588 | nlmsg_free(skb); | |
6589 | return err; | |
6590 | } | |
6591 | } | |
6592 | virtqueue_kick(vq); | |
6593 | return 0; | |
6594 | } | |
6595 | ||
6596 | static void remove_vqs(struct virtio_device *vdev) | |
6597 | { | |
6598 | int i; | |
6599 | ||
d9679d00 | 6600 | virtio_reset_device(vdev); |
5d44fe7c EG |
6601 | |
6602 | for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) { | |
6603 | struct virtqueue *vq = hwsim_vqs[i]; | |
6604 | struct sk_buff *skb; | |
6605 | ||
6606 | while ((skb = virtqueue_detach_unused_buf(vq))) | |
6607 | nlmsg_free(skb); | |
6608 | } | |
6609 | ||
6610 | vdev->config->del_vqs(vdev); | |
6611 | } | |
6612 | ||
6613 | static int hwsim_virtio_probe(struct virtio_device *vdev) | |
6614 | { | |
6615 | int err; | |
6616 | unsigned long flags; | |
6617 | ||
6618 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
6619 | if (hwsim_virtio_enabled) { | |
6620 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
6621 | return -EEXIST; | |
6622 | } | |
6623 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
6624 | ||
6625 | err = init_vqs(vdev); | |
6626 | if (err) | |
6627 | return err; | |
6628 | ||
3f3558c8 JB |
6629 | virtio_device_ready(vdev); |
6630 | ||
5d44fe7c EG |
6631 | err = fill_vq(hwsim_vqs[HWSIM_VQ_RX]); |
6632 | if (err) | |
6633 | goto out_remove; | |
6634 | ||
6635 | spin_lock_irqsave(&hwsim_virtio_lock, flags); | |
6636 | hwsim_virtio_enabled = true; | |
6637 | spin_unlock_irqrestore(&hwsim_virtio_lock, flags); | |
6638 | ||
6639 | schedule_work(&hwsim_virtio_rx); | |
6640 | return 0; | |
6641 | ||
6642 | out_remove: | |
6643 | remove_vqs(vdev); | |
6644 | return err; | |
6645 | } | |
6646 | ||
6647 | static void hwsim_virtio_remove(struct virtio_device *vdev) | |
6648 | { | |
6649 | hwsim_virtio_enabled = false; | |
6650 | ||
6651 | cancel_work_sync(&hwsim_virtio_rx); | |
6652 | ||
6653 | remove_vqs(vdev); | |
6654 | } | |
6655 | ||
6656 | /* MAC80211_HWSIM virtio device id table */ | |
6657 | static const struct virtio_device_id id_table[] = { | |
6658 | { VIRTIO_ID_MAC80211_HWSIM, VIRTIO_DEV_ANY_ID }, | |
6659 | { 0 } | |
6660 | }; | |
6661 | MODULE_DEVICE_TABLE(virtio, id_table); | |
6662 | ||
6663 | static struct virtio_driver virtio_hwsim = { | |
6664 | .driver.name = KBUILD_MODNAME, | |
5d44fe7c EG |
6665 | .id_table = id_table, |
6666 | .probe = hwsim_virtio_probe, | |
6667 | .remove = hwsim_virtio_remove, | |
6668 | }; | |
6669 | ||
6670 | static int hwsim_register_virtio_driver(void) | |
6671 | { | |
5d44fe7c EG |
6672 | return register_virtio_driver(&virtio_hwsim); |
6673 | } | |
6674 | ||
6675 | static void hwsim_unregister_virtio_driver(void) | |
6676 | { | |
6677 | unregister_virtio_driver(&virtio_hwsim); | |
6678 | } | |
6679 | #else | |
6680 | static inline int hwsim_register_virtio_driver(void) | |
6681 | { | |
6682 | return 0; | |
6683 | } | |
6684 | ||
6685 | static inline void hwsim_unregister_virtio_driver(void) | |
6686 | { | |
6687 | } | |
6688 | #endif | |
6689 | ||
acc1e7a3 JM |
6690 | static int __init init_mac80211_hwsim(void) |
6691 | { | |
f39c2bfa | 6692 | int i, err; |
acc1e7a3 | 6693 | |
bc791098 | 6694 | if (radios < 0 || radios > 100) |
acc1e7a3 JM |
6695 | return -EINVAL; |
6696 | ||
e8261171 JB |
6697 | if (channels < 1) |
6698 | return -EINVAL; | |
6699 | ||
3f61b7a3 JB |
6700 | err = rhashtable_init(&hwsim_radios_rht, &hwsim_rht_params); |
6701 | if (err) | |
1edcfc20 | 6702 | return err; |
b71d856a | 6703 | |
100cb9ff | 6704 | err = register_pernet_device(&hwsim_net_ops); |
9ea92774 | 6705 | if (err) |
3f61b7a3 | 6706 | goto out_free_rht; |
9ea92774 | 6707 | |
100cb9ff MW |
6708 | err = platform_driver_register(&mac80211_hwsim_driver); |
6709 | if (err) | |
6710 | goto out_unregister_pernet; | |
6711 | ||
05cc09de AK |
6712 | err = hwsim_init_netlink(); |
6713 | if (err) | |
6714 | goto out_unregister_driver; | |
6715 | ||
5d44fe7c EG |
6716 | err = hwsim_register_virtio_driver(); |
6717 | if (err) | |
6718 | goto out_exit_netlink; | |
6719 | ||
1aaba11d | 6720 | hwsim_class = class_create("mac80211_hwsim"); |
9ea92774 MP |
6721 | if (IS_ERR(hwsim_class)) { |
6722 | err = PTR_ERR(hwsim_class); | |
5d44fe7c | 6723 | goto out_exit_virtio; |
9ea92774 | 6724 | } |
acc1e7a3 | 6725 | |
148fe295 TP |
6726 | hwsim_init_s1g_channels(hwsim_channels_s1g); |
6727 | ||
0e057d73 | 6728 | for (i = 0; i < radios; i++) { |
62759361 JR |
6729 | struct hwsim_new_radio_params param = { 0 }; |
6730 | ||
6731 | param.channels = channels; | |
acc1e7a3 | 6732 | |
4a5af9c2 | 6733 | switch (regtest) { |
4a5af9c2 | 6734 | case HWSIM_REGTEST_DIFF_COUNTRY: |
26b0e411 | 6735 | if (i < ARRAY_SIZE(hwsim_alpha2s)) |
62759361 | 6736 | param.reg_alpha2 = hwsim_alpha2s[i]; |
4a5af9c2 LR |
6737 | break; |
6738 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: | |
6739 | if (!i) | |
62759361 | 6740 | param.reg_alpha2 = hwsim_alpha2s[0]; |
4a5af9c2 | 6741 | break; |
4a5af9c2 | 6742 | case HWSIM_REGTEST_STRICT_ALL: |
62759361 | 6743 | param.reg_strict = true; |
fc0561dc | 6744 | fallthrough; |
26b0e411 | 6745 | case HWSIM_REGTEST_DRIVER_REG_ALL: |
62759361 | 6746 | param.reg_alpha2 = hwsim_alpha2s[0]; |
4a5af9c2 | 6747 | break; |
26b0e411 JB |
6748 | case HWSIM_REGTEST_WORLD_ROAM: |
6749 | if (i == 0) | |
62759361 | 6750 | param.regd = &hwsim_world_regdom_custom_01; |
4a5af9c2 LR |
6751 | break; |
6752 | case HWSIM_REGTEST_CUSTOM_WORLD: | |
62759361 | 6753 | param.regd = &hwsim_world_regdom_custom_01; |
26b0e411 | 6754 | break; |
4a5af9c2 | 6755 | case HWSIM_REGTEST_CUSTOM_WORLD_2: |
26b0e411 | 6756 | if (i == 0) |
62759361 | 6757 | param.regd = &hwsim_world_regdom_custom_01; |
26b0e411 | 6758 | else if (i == 1) |
62759361 | 6759 | param.regd = &hwsim_world_regdom_custom_02; |
4a5af9c2 LR |
6760 | break; |
6761 | case HWSIM_REGTEST_STRICT_FOLLOW: | |
26b0e411 | 6762 | if (i == 0) { |
62759361 JR |
6763 | param.reg_strict = true; |
6764 | param.reg_alpha2 = hwsim_alpha2s[0]; | |
26b0e411 | 6765 | } |
4a5af9c2 LR |
6766 | break; |
6767 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: | |
26b0e411 | 6768 | if (i == 0) { |
62759361 JR |
6769 | param.reg_strict = true; |
6770 | param.reg_alpha2 = hwsim_alpha2s[0]; | |
26b0e411 | 6771 | } else if (i == 1) { |
62759361 | 6772 | param.reg_alpha2 = hwsim_alpha2s[1]; |
26b0e411 | 6773 | } |
4a5af9c2 LR |
6774 | break; |
6775 | case HWSIM_REGTEST_ALL: | |
26b0e411 JB |
6776 | switch (i) { |
6777 | case 0: | |
62759361 | 6778 | param.regd = &hwsim_world_regdom_custom_01; |
26b0e411 JB |
6779 | break; |
6780 | case 1: | |
62759361 | 6781 | param.regd = &hwsim_world_regdom_custom_02; |
26b0e411 JB |
6782 | break; |
6783 | case 2: | |
62759361 | 6784 | param.reg_alpha2 = hwsim_alpha2s[0]; |
26b0e411 JB |
6785 | break; |
6786 | case 3: | |
62759361 | 6787 | param.reg_alpha2 = hwsim_alpha2s[1]; |
26b0e411 JB |
6788 | break; |
6789 | case 4: | |
62759361 JR |
6790 | param.reg_strict = true; |
6791 | param.reg_alpha2 = hwsim_alpha2s[2]; | |
26b0e411 JB |
6792 | break; |
6793 | } | |
4a5af9c2 LR |
6794 | break; |
6795 | default: | |
6796 | break; | |
6797 | } | |
6798 | ||
62759361 | 6799 | param.p2p_device = support_p2p_device; |
2fd0c671 JB |
6800 | param.mlo = mlo; |
6801 | param.use_chanctx = channels > 1 || mlo; | |
082b12d4 | 6802 | param.iftypes = HWSIM_IFTYPE_SUPPORT_MASK; |
05383950 AS |
6803 | if (param.p2p_device) |
6804 | param.iftypes |= BIT(NL80211_IFTYPE_P2P_DEVICE); | |
62759361 JR |
6805 | |
6806 | err = mac80211_hwsim_new_radio(NULL, ¶m); | |
bc791098 | 6807 | if (err < 0) |
f39c2bfa | 6808 | goto out_free_radios; |
acc1e7a3 JM |
6809 | } |
6810 | ||
c835a677 TG |
6811 | hwsim_mon = alloc_netdev(0, "hwsim%d", NET_NAME_UNKNOWN, |
6812 | hwsim_mon_setup); | |
bcdd8220 WY |
6813 | if (hwsim_mon == NULL) { |
6814 | err = -ENOMEM; | |
f39c2bfa | 6815 | goto out_free_radios; |
bcdd8220 | 6816 | } |
acc1e7a3 | 6817 | |
7882513b | 6818 | rtnl_lock(); |
7882513b | 6819 | err = dev_alloc_name(hwsim_mon, hwsim_mon->name); |
f39c2bfa JB |
6820 | if (err < 0) { |
6821 | rtnl_unlock(); | |
313c3fe9 | 6822 | goto out_free_mon; |
f39c2bfa | 6823 | } |
7882513b JL |
6824 | |
6825 | err = register_netdevice(hwsim_mon); | |
f39c2bfa JB |
6826 | if (err < 0) { |
6827 | rtnl_unlock(); | |
6828 | goto out_free_mon; | |
6829 | } | |
7882513b JL |
6830 | rtnl_unlock(); |
6831 | ||
acc1e7a3 JM |
6832 | return 0; |
6833 | ||
f39c2bfa | 6834 | out_free_mon: |
acc1e7a3 | 6835 | free_netdev(hwsim_mon); |
f39c2bfa | 6836 | out_free_radios: |
3a33cc10 | 6837 | mac80211_hwsim_free(); |
5d44fe7c EG |
6838 | out_exit_virtio: |
6839 | hwsim_unregister_virtio_driver(); | |
05cc09de AK |
6840 | out_exit_netlink: |
6841 | hwsim_exit_netlink(); | |
f39c2bfa | 6842 | out_unregister_driver: |
c07fe5ae | 6843 | platform_driver_unregister(&mac80211_hwsim_driver); |
100cb9ff MW |
6844 | out_unregister_pernet: |
6845 | unregister_pernet_device(&hwsim_net_ops); | |
3f61b7a3 JB |
6846 | out_free_rht: |
6847 | rhashtable_destroy(&hwsim_radios_rht); | |
acc1e7a3 JM |
6848 | return err; |
6849 | } | |
f8fffc7e | 6850 | module_init(init_mac80211_hwsim); |
acc1e7a3 JM |
6851 | |
6852 | static void __exit exit_mac80211_hwsim(void) | |
6853 | { | |
62b093b3 | 6854 | pr_debug("mac80211_hwsim: unregister radios\n"); |
acc1e7a3 | 6855 | |
5d44fe7c | 6856 | hwsim_unregister_virtio_driver(); |
7882513b JL |
6857 | hwsim_exit_netlink(); |
6858 | ||
acc1e7a3 | 6859 | mac80211_hwsim_free(); |
b71d856a | 6860 | |
c6509cc3 | 6861 | rhashtable_destroy(&hwsim_radios_rht); |
5d416351 | 6862 | unregister_netdev(hwsim_mon); |
c07fe5ae | 6863 | platform_driver_unregister(&mac80211_hwsim_driver); |
100cb9ff | 6864 | unregister_pernet_device(&hwsim_net_ops); |
acc1e7a3 | 6865 | } |
acc1e7a3 | 6866 | module_exit(exit_mac80211_hwsim); |