]>
Commit | Line | Data |
---|---|---|
acc1e7a3 JM |
1 | /* |
2 | * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211 | |
3 | * Copyright (c) 2008, Jouni Malinen <j@w1.fi> | |
7882513b | 4 | * Copyright (c) 2011, Javier Lopez <jlopex@gmail.com> |
acc1e7a3 JM |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | */ | |
10 | ||
11 | /* | |
12 | * TODO: | |
2b2d7795 JB |
13 | * - Add TSF sync and fix IBSS beacon transmission by adding |
14 | * competition for "air time" at TBTT | |
acc1e7a3 JM |
15 | * - RX filtering based on filter configuration (data->rx_filter) |
16 | */ | |
17 | ||
0e057d73 | 18 | #include <linux/list.h> |
5a0e3ad6 | 19 | #include <linux/slab.h> |
0e057d73 | 20 | #include <linux/spinlock.h> |
90e3012e JB |
21 | #include <net/dst.h> |
22 | #include <net/xfrm.h> | |
acc1e7a3 JM |
23 | #include <net/mac80211.h> |
24 | #include <net/ieee80211_radiotap.h> | |
25 | #include <linux/if_arp.h> | |
26 | #include <linux/rtnetlink.h> | |
27 | #include <linux/etherdevice.h> | |
9ea92774 | 28 | #include <linux/platform_device.h> |
fc6971d4 | 29 | #include <linux/debugfs.h> |
9d9779e7 | 30 | #include <linux/module.h> |
2f40b940 | 31 | #include <linux/ktime.h> |
7882513b JL |
32 | #include <net/genetlink.h> |
33 | #include "mac80211_hwsim.h" | |
34 | ||
35 | #define WARN_QUEUE 100 | |
36 | #define MAX_QUEUE 200 | |
acc1e7a3 JM |
37 | |
38 | MODULE_AUTHOR("Jouni Malinen"); | |
39 | MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211"); | |
40 | MODULE_LICENSE("GPL"); | |
41 | ||
15e47304 | 42 | static u32 wmediumd_portid; |
a1910f9c | 43 | |
acc1e7a3 JM |
44 | static int radios = 2; |
45 | module_param(radios, int, 0444); | |
46 | MODULE_PARM_DESC(radios, "Number of simulated radios"); | |
47 | ||
e8261171 JB |
48 | static int channels = 1; |
49 | module_param(channels, int, 0444); | |
50 | MODULE_PARM_DESC(channels, "Number of concurrent channels"); | |
69068036 | 51 | |
a357d7f9 JB |
52 | static bool paged_rx = false; |
53 | module_param(paged_rx, bool, 0644); | |
54 | MODULE_PARM_DESC(paged_rx, "Use paged SKBs for RX instead of linear ones"); | |
55 | ||
1eb32179 KB |
56 | static bool rctbl = false; |
57 | module_param(rctbl, bool, 0444); | |
58 | MODULE_PARM_DESC(rctbl, "Handle rate control table"); | |
59 | ||
8c66a3d9 JB |
60 | static bool support_p2p_device = true; |
61 | module_param(support_p2p_device, bool, 0444); | |
62 | MODULE_PARM_DESC(support_p2p_device, "Support P2P-Device interface type"); | |
63 | ||
4a5af9c2 LR |
64 | /** |
65 | * enum hwsim_regtest - the type of regulatory tests we offer | |
66 | * | |
67 | * These are the different values you can use for the regtest | |
68 | * module parameter. This is useful to help test world roaming | |
69 | * and the driver regulatory_hint() call and combinations of these. | |
70 | * If you want to do specific alpha2 regulatory domain tests simply | |
71 | * use the userspace regulatory request as that will be respected as | |
72 | * well without the need of this module parameter. This is designed | |
73 | * only for testing the driver regulatory request, world roaming | |
74 | * and all possible combinations. | |
75 | * | |
76 | * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed, | |
77 | * this is the default value. | |
78 | * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory | |
79 | * hint, only one driver regulatory hint will be sent as such the | |
80 | * secondary radios are expected to follow. | |
81 | * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory | |
82 | * request with all radios reporting the same regulatory domain. | |
83 | * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling | |
84 | * different regulatory domains requests. Expected behaviour is for | |
85 | * an intersection to occur but each device will still use their | |
86 | * respective regulatory requested domains. Subsequent radios will | |
87 | * use the resulting intersection. | |
25985edc | 88 | * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We accomplish |
4a5af9c2 LR |
89 | * this by using a custom beacon-capable regulatory domain for the first |
90 | * radio. All other device world roam. | |
91 | * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory | |
92 | * domain requests. All radios will adhere to this custom world regulatory | |
93 | * domain. | |
94 | * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory | |
95 | * domain requests. The first radio will adhere to the first custom world | |
96 | * regulatory domain, the second one to the second custom world regulatory | |
97 | * domain. All other devices will world roam. | |
98 | * @HWSIM_REGTEST_STRICT_FOLLOW_: Used for testing strict regulatory domain | |
99 | * settings, only the first radio will send a regulatory domain request | |
100 | * and use strict settings. The rest of the radios are expected to follow. | |
101 | * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain | |
102 | * settings. All radios will adhere to this. | |
103 | * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory | |
104 | * domain settings, combined with secondary driver regulatory domain | |
105 | * settings. The first radio will get a strict regulatory domain setting | |
106 | * using the first driver regulatory request and the second radio will use | |
107 | * non-strict settings using the second driver regulatory request. All | |
108 | * other devices should follow the intersection created between the | |
109 | * first two. | |
110 | * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need | |
111 | * at least 6 radios for a complete test. We will test in this order: | |
112 | * 1 - driver custom world regulatory domain | |
113 | * 2 - second custom world regulatory domain | |
114 | * 3 - first driver regulatory domain request | |
115 | * 4 - second driver regulatory domain request | |
116 | * 5 - strict regulatory domain settings using the third driver regulatory | |
117 | * domain request | |
118 | * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio | |
119 | * regulatory requests. | |
120 | */ | |
121 | enum hwsim_regtest { | |
122 | HWSIM_REGTEST_DISABLED = 0, | |
123 | HWSIM_REGTEST_DRIVER_REG_FOLLOW = 1, | |
124 | HWSIM_REGTEST_DRIVER_REG_ALL = 2, | |
125 | HWSIM_REGTEST_DIFF_COUNTRY = 3, | |
126 | HWSIM_REGTEST_WORLD_ROAM = 4, | |
127 | HWSIM_REGTEST_CUSTOM_WORLD = 5, | |
128 | HWSIM_REGTEST_CUSTOM_WORLD_2 = 6, | |
129 | HWSIM_REGTEST_STRICT_FOLLOW = 7, | |
130 | HWSIM_REGTEST_STRICT_ALL = 8, | |
131 | HWSIM_REGTEST_STRICT_AND_DRIVER_REG = 9, | |
132 | HWSIM_REGTEST_ALL = 10, | |
133 | }; | |
134 | ||
135 | /* Set to one of the HWSIM_REGTEST_* values above */ | |
136 | static int regtest = HWSIM_REGTEST_DISABLED; | |
137 | module_param(regtest, int, 0444); | |
138 | MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run"); | |
139 | ||
140 | static const char *hwsim_alpha2s[] = { | |
141 | "FI", | |
142 | "AL", | |
143 | "US", | |
144 | "DE", | |
145 | "JP", | |
146 | "AL", | |
147 | }; | |
148 | ||
149 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = { | |
150 | .n_reg_rules = 4, | |
151 | .alpha2 = "99", | |
152 | .reg_rules = { | |
153 | REG_RULE(2412-10, 2462+10, 40, 0, 20, 0), | |
154 | REG_RULE(2484-10, 2484+10, 40, 0, 20, 0), | |
155 | REG_RULE(5150-10, 5240+10, 40, 0, 30, 0), | |
156 | REG_RULE(5745-10, 5825+10, 40, 0, 30, 0), | |
157 | } | |
158 | }; | |
159 | ||
160 | static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = { | |
161 | .n_reg_rules = 2, | |
162 | .alpha2 = "99", | |
163 | .reg_rules = { | |
164 | REG_RULE(2412-10, 2462+10, 40, 0, 20, 0), | |
165 | REG_RULE(5725-10, 5850+10, 40, 0, 30, | |
8fe02e16 | 166 | NL80211_RRF_NO_IR), |
4a5af9c2 LR |
167 | } |
168 | }; | |
169 | ||
26b0e411 JB |
170 | static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = { |
171 | &hwsim_world_regdom_custom_01, | |
172 | &hwsim_world_regdom_custom_02, | |
173 | }; | |
174 | ||
8aa21e6f JB |
175 | struct hwsim_vif_priv { |
176 | u32 magic; | |
fc6971d4 JM |
177 | u8 bssid[ETH_ALEN]; |
178 | bool assoc; | |
0bb861e6 | 179 | bool bcn_en; |
fc6971d4 | 180 | u16 aid; |
8aa21e6f JB |
181 | }; |
182 | ||
183 | #define HWSIM_VIF_MAGIC 0x69537748 | |
184 | ||
185 | static inline void hwsim_check_magic(struct ieee80211_vif *vif) | |
186 | { | |
187 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
e8261171 JB |
188 | WARN(vp->magic != HWSIM_VIF_MAGIC, |
189 | "Invalid VIF (%p) magic %#x, %pM, %d/%d\n", | |
190 | vif, vp->magic, vif->addr, vif->type, vif->p2p); | |
8aa21e6f JB |
191 | } |
192 | ||
193 | static inline void hwsim_set_magic(struct ieee80211_vif *vif) | |
194 | { | |
195 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
196 | vp->magic = HWSIM_VIF_MAGIC; | |
197 | } | |
198 | ||
199 | static inline void hwsim_clear_magic(struct ieee80211_vif *vif) | |
200 | { | |
201 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
202 | vp->magic = 0; | |
203 | } | |
acc1e7a3 | 204 | |
81c06523 JB |
205 | struct hwsim_sta_priv { |
206 | u32 magic; | |
207 | }; | |
208 | ||
e8261171 | 209 | #define HWSIM_STA_MAGIC 0x6d537749 |
81c06523 JB |
210 | |
211 | static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta) | |
212 | { | |
213 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
5d6924ea | 214 | WARN_ON(sp->magic != HWSIM_STA_MAGIC); |
81c06523 JB |
215 | } |
216 | ||
217 | static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta) | |
218 | { | |
219 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
5d6924ea | 220 | sp->magic = HWSIM_STA_MAGIC; |
81c06523 JB |
221 | } |
222 | ||
223 | static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta) | |
224 | { | |
225 | struct hwsim_sta_priv *sp = (void *)sta->drv_priv; | |
226 | sp->magic = 0; | |
227 | } | |
228 | ||
e8261171 JB |
229 | struct hwsim_chanctx_priv { |
230 | u32 magic; | |
231 | }; | |
232 | ||
233 | #define HWSIM_CHANCTX_MAGIC 0x6d53774a | |
234 | ||
235 | static inline void hwsim_check_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
236 | { | |
237 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
238 | WARN_ON(cp->magic != HWSIM_CHANCTX_MAGIC); | |
239 | } | |
240 | ||
241 | static inline void hwsim_set_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
242 | { | |
243 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
244 | cp->magic = HWSIM_CHANCTX_MAGIC; | |
245 | } | |
246 | ||
247 | static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c) | |
248 | { | |
249 | struct hwsim_chanctx_priv *cp = (void *)c->drv_priv; | |
250 | cp->magic = 0; | |
251 | } | |
252 | ||
acc1e7a3 JM |
253 | static struct class *hwsim_class; |
254 | ||
acc1e7a3 JM |
255 | static struct net_device *hwsim_mon; /* global monitor netdev */ |
256 | ||
22cad735 LR |
257 | #define CHAN2G(_freq) { \ |
258 | .band = IEEE80211_BAND_2GHZ, \ | |
259 | .center_freq = (_freq), \ | |
260 | .hw_value = (_freq), \ | |
261 | .max_power = 20, \ | |
262 | } | |
263 | ||
264 | #define CHAN5G(_freq) { \ | |
265 | .band = IEEE80211_BAND_5GHZ, \ | |
266 | .center_freq = (_freq), \ | |
267 | .hw_value = (_freq), \ | |
268 | .max_power = 20, \ | |
269 | } | |
270 | ||
271 | static const struct ieee80211_channel hwsim_channels_2ghz[] = { | |
272 | CHAN2G(2412), /* Channel 1 */ | |
273 | CHAN2G(2417), /* Channel 2 */ | |
274 | CHAN2G(2422), /* Channel 3 */ | |
275 | CHAN2G(2427), /* Channel 4 */ | |
276 | CHAN2G(2432), /* Channel 5 */ | |
277 | CHAN2G(2437), /* Channel 6 */ | |
278 | CHAN2G(2442), /* Channel 7 */ | |
279 | CHAN2G(2447), /* Channel 8 */ | |
280 | CHAN2G(2452), /* Channel 9 */ | |
281 | CHAN2G(2457), /* Channel 10 */ | |
282 | CHAN2G(2462), /* Channel 11 */ | |
283 | CHAN2G(2467), /* Channel 12 */ | |
284 | CHAN2G(2472), /* Channel 13 */ | |
285 | CHAN2G(2484), /* Channel 14 */ | |
286 | }; | |
acc1e7a3 | 287 | |
22cad735 LR |
288 | static const struct ieee80211_channel hwsim_channels_5ghz[] = { |
289 | CHAN5G(5180), /* Channel 36 */ | |
290 | CHAN5G(5200), /* Channel 40 */ | |
291 | CHAN5G(5220), /* Channel 44 */ | |
292 | CHAN5G(5240), /* Channel 48 */ | |
293 | ||
294 | CHAN5G(5260), /* Channel 52 */ | |
295 | CHAN5G(5280), /* Channel 56 */ | |
296 | CHAN5G(5300), /* Channel 60 */ | |
297 | CHAN5G(5320), /* Channel 64 */ | |
298 | ||
299 | CHAN5G(5500), /* Channel 100 */ | |
300 | CHAN5G(5520), /* Channel 104 */ | |
301 | CHAN5G(5540), /* Channel 108 */ | |
302 | CHAN5G(5560), /* Channel 112 */ | |
303 | CHAN5G(5580), /* Channel 116 */ | |
304 | CHAN5G(5600), /* Channel 120 */ | |
305 | CHAN5G(5620), /* Channel 124 */ | |
306 | CHAN5G(5640), /* Channel 128 */ | |
307 | CHAN5G(5660), /* Channel 132 */ | |
308 | CHAN5G(5680), /* Channel 136 */ | |
309 | CHAN5G(5700), /* Channel 140 */ | |
310 | ||
311 | CHAN5G(5745), /* Channel 149 */ | |
312 | CHAN5G(5765), /* Channel 153 */ | |
313 | CHAN5G(5785), /* Channel 157 */ | |
314 | CHAN5G(5805), /* Channel 161 */ | |
315 | CHAN5G(5825), /* Channel 165 */ | |
acc1e7a3 JM |
316 | }; |
317 | ||
318 | static const struct ieee80211_rate hwsim_rates[] = { | |
319 | { .bitrate = 10 }, | |
320 | { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
321 | { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
322 | { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, | |
323 | { .bitrate = 60 }, | |
324 | { .bitrate = 90 }, | |
325 | { .bitrate = 120 }, | |
326 | { .bitrate = 180 }, | |
327 | { .bitrate = 240 }, | |
328 | { .bitrate = 360 }, | |
329 | { .bitrate = 480 }, | |
330 | { .bitrate = 540 } | |
331 | }; | |
332 | ||
de0421d5 JB |
333 | static const struct ieee80211_iface_limit hwsim_if_limits[] = { |
334 | { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) }, | |
335 | { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) | | |
336 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
337 | #ifdef CONFIG_MAC80211_MESH | |
338 | BIT(NL80211_IFTYPE_MESH_POINT) | | |
339 | #endif | |
340 | BIT(NL80211_IFTYPE_AP) | | |
341 | BIT(NL80211_IFTYPE_P2P_GO) }, | |
8c66a3d9 JB |
342 | /* must be last, see hwsim_if_comb */ |
343 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) } | |
de0421d5 JB |
344 | }; |
345 | ||
346 | static const struct ieee80211_iface_limit hwsim_if_dfs_limits[] = { | |
347 | { .max = 8, .types = BIT(NL80211_IFTYPE_AP) }, | |
348 | }; | |
349 | ||
350 | static const struct ieee80211_iface_combination hwsim_if_comb[] = { | |
8c66a3d9 JB |
351 | { |
352 | .limits = hwsim_if_limits, | |
353 | /* remove the last entry which is P2P_DEVICE */ | |
354 | .n_limits = ARRAY_SIZE(hwsim_if_limits) - 1, | |
355 | .max_interfaces = 2048, | |
356 | .num_different_channels = 1, | |
357 | }, | |
358 | { | |
359 | .limits = hwsim_if_dfs_limits, | |
360 | .n_limits = ARRAY_SIZE(hwsim_if_dfs_limits), | |
361 | .max_interfaces = 8, | |
362 | .num_different_channels = 1, | |
363 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
364 | BIT(NL80211_CHAN_WIDTH_20) | | |
365 | BIT(NL80211_CHAN_WIDTH_40) | | |
366 | BIT(NL80211_CHAN_WIDTH_80) | | |
367 | BIT(NL80211_CHAN_WIDTH_160), | |
368 | } | |
369 | }; | |
370 | ||
371 | static const struct ieee80211_iface_combination hwsim_if_comb_p2p_dev[] = { | |
de0421d5 JB |
372 | { |
373 | .limits = hwsim_if_limits, | |
374 | .n_limits = ARRAY_SIZE(hwsim_if_limits), | |
375 | .max_interfaces = 2048, | |
376 | .num_different_channels = 1, | |
377 | }, | |
378 | { | |
379 | .limits = hwsim_if_dfs_limits, | |
380 | .n_limits = ARRAY_SIZE(hwsim_if_dfs_limits), | |
381 | .max_interfaces = 8, | |
382 | .num_different_channels = 1, | |
383 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | |
384 | BIT(NL80211_CHAN_WIDTH_20) | | |
385 | BIT(NL80211_CHAN_WIDTH_40) | | |
386 | BIT(NL80211_CHAN_WIDTH_80) | | |
387 | BIT(NL80211_CHAN_WIDTH_160), | |
388 | } | |
389 | }; | |
390 | ||
0e057d73 JB |
391 | static spinlock_t hwsim_radio_lock; |
392 | static struct list_head hwsim_radios; | |
2d68992b | 393 | static int hwsim_radio_idx; |
0e057d73 | 394 | |
de0421d5 JB |
395 | static struct platform_driver mac80211_hwsim_driver = { |
396 | .driver = { | |
397 | .name = "mac80211_hwsim", | |
398 | .owner = THIS_MODULE, | |
399 | }, | |
400 | }; | |
0e057d73 | 401 | |
acc1e7a3 | 402 | struct mac80211_hwsim_data { |
0e057d73 JB |
403 | struct list_head list; |
404 | struct ieee80211_hw *hw; | |
acc1e7a3 | 405 | struct device *dev; |
1b083ea4 | 406 | struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; |
22cad735 LR |
407 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)]; |
408 | struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)]; | |
acc1e7a3 | 409 | struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; |
38ed5048 | 410 | struct ieee80211_iface_combination if_combination; |
acc1e7a3 | 411 | |
ef15aac6 | 412 | struct mac_address addresses[2]; |
bc791098 | 413 | int channels, idx; |
ef15aac6 | 414 | |
e8261171 JB |
415 | struct ieee80211_channel *tmp_chan; |
416 | struct delayed_work roc_done; | |
417 | struct delayed_work hw_scan; | |
418 | struct cfg80211_scan_request *hw_scan_request; | |
419 | struct ieee80211_vif *hw_scan_vif; | |
420 | int scan_chan_idx; | |
421 | ||
acc1e7a3 | 422 | struct ieee80211_channel *channel; |
01e59e46 | 423 | u64 beacon_int /* beacon interval in us */; |
acc1e7a3 | 424 | unsigned int rx_filter; |
f74cb0f7 LR |
425 | bool started, idle, scanning; |
426 | struct mutex mutex; | |
01e59e46 | 427 | struct tasklet_hrtimer beacon_timer; |
fc6971d4 JM |
428 | enum ps_mode { |
429 | PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL | |
430 | } ps; | |
431 | bool ps_poll_pending; | |
432 | struct dentry *debugfs; | |
73606d00 | 433 | |
7882513b | 434 | struct sk_buff_head pending; /* packets pending */ |
73606d00 DW |
435 | /* |
436 | * Only radios in the same group can communicate together (the | |
437 | * channel has to match too). Each bit represents a group. A | |
438 | * radio can be in more then one group. | |
439 | */ | |
440 | u64 group; | |
bdd7bd16 BG |
441 | |
442 | int power_level; | |
2f40b940 JC |
443 | |
444 | /* difference between this hw's clock and the real clock, in usecs */ | |
45034bfb | 445 | s64 tsf_offset; |
c51f8783 | 446 | s64 bcn_delta; |
b66851c3 TP |
447 | /* absolute beacon transmission time. Used to cover up "tx" delay. */ |
448 | u64 abs_bcn_ts; | |
acc1e7a3 JM |
449 | }; |
450 | ||
451 | ||
452 | struct hwsim_radiotap_hdr { | |
453 | struct ieee80211_radiotap_header hdr; | |
2f40b940 | 454 | __le64 rt_tsft; |
acc1e7a3 JM |
455 | u8 rt_flags; |
456 | u8 rt_rate; | |
457 | __le16 rt_channel; | |
458 | __le16 rt_chbitmask; | |
ba2d3587 | 459 | } __packed; |
acc1e7a3 | 460 | |
76a56eb3 JM |
461 | struct hwsim_radiotap_ack_hdr { |
462 | struct ieee80211_radiotap_header hdr; | |
463 | u8 rt_flags; | |
464 | u8 pad; | |
465 | __le16 rt_channel; | |
466 | __le16 rt_chbitmask; | |
467 | } __packed; | |
468 | ||
7882513b JL |
469 | /* MAC80211_HWSIM netlinf family */ |
470 | static struct genl_family hwsim_genl_family = { | |
471 | .id = GENL_ID_GENERATE, | |
472 | .hdrsize = 0, | |
473 | .name = "MAC80211_HWSIM", | |
474 | .version = 1, | |
475 | .maxattr = HWSIM_ATTR_MAX, | |
476 | }; | |
477 | ||
478 | /* MAC80211_HWSIM netlink policy */ | |
479 | ||
205d2429 | 480 | static const struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { |
9ddd12af JB |
481 | [HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
482 | [HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, | |
7882513b JL |
483 | [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, |
484 | .len = IEEE80211_MAX_DATA_LEN }, | |
485 | [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, | |
486 | [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, | |
487 | [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, | |
488 | [HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC, | |
9ddd12af JB |
489 | .len = IEEE80211_TX_MAX_RATES * |
490 | sizeof(struct hwsim_tx_rate)}, | |
7882513b | 491 | [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, |
bc791098 JB |
492 | [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 }, |
493 | [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 }, | |
26b0e411 JB |
494 | [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
495 | [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 }, | |
496 | [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG }, | |
8c66a3d9 | 497 | [HWSIM_ATTR_SUPPORT_P2P_DEVICE] = { .type = NLA_FLAG }, |
7882513b | 498 | }; |
acc1e7a3 | 499 | |
de0421d5 JB |
500 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
501 | struct sk_buff *skb, | |
502 | struct ieee80211_channel *chan); | |
503 | ||
504 | /* sysfs attributes */ | |
505 | static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif) | |
506 | { | |
507 | struct mac80211_hwsim_data *data = dat; | |
508 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
509 | struct sk_buff *skb; | |
510 | struct ieee80211_pspoll *pspoll; | |
511 | ||
512 | if (!vp->assoc) | |
513 | return; | |
514 | ||
515 | wiphy_debug(data->hw->wiphy, | |
516 | "%s: send PS-Poll to %pM for aid %d\n", | |
517 | __func__, vp->bssid, vp->aid); | |
518 | ||
519 | skb = dev_alloc_skb(sizeof(*pspoll)); | |
520 | if (!skb) | |
521 | return; | |
522 | pspoll = (void *) skb_put(skb, sizeof(*pspoll)); | |
523 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | |
524 | IEEE80211_STYPE_PSPOLL | | |
525 | IEEE80211_FCTL_PM); | |
526 | pspoll->aid = cpu_to_le16(0xc000 | vp->aid); | |
527 | memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); | |
528 | memcpy(pspoll->ta, mac, ETH_ALEN); | |
529 | ||
530 | rcu_read_lock(); | |
531 | mac80211_hwsim_tx_frame(data->hw, skb, | |
532 | rcu_dereference(vif->chanctx_conf)->def.chan); | |
533 | rcu_read_unlock(); | |
534 | } | |
535 | ||
536 | static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac, | |
537 | struct ieee80211_vif *vif, int ps) | |
538 | { | |
539 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
540 | struct sk_buff *skb; | |
541 | struct ieee80211_hdr *hdr; | |
542 | ||
543 | if (!vp->assoc) | |
544 | return; | |
545 | ||
546 | wiphy_debug(data->hw->wiphy, | |
547 | "%s: send data::nullfunc to %pM ps=%d\n", | |
548 | __func__, vp->bssid, ps); | |
549 | ||
550 | skb = dev_alloc_skb(sizeof(*hdr)); | |
551 | if (!skb) | |
552 | return; | |
553 | hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN); | |
554 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
555 | IEEE80211_STYPE_NULLFUNC | | |
556 | (ps ? IEEE80211_FCTL_PM : 0)); | |
557 | hdr->duration_id = cpu_to_le16(0); | |
558 | memcpy(hdr->addr1, vp->bssid, ETH_ALEN); | |
559 | memcpy(hdr->addr2, mac, ETH_ALEN); | |
560 | memcpy(hdr->addr3, vp->bssid, ETH_ALEN); | |
561 | ||
562 | rcu_read_lock(); | |
563 | mac80211_hwsim_tx_frame(data->hw, skb, | |
564 | rcu_dereference(vif->chanctx_conf)->def.chan); | |
565 | rcu_read_unlock(); | |
566 | } | |
567 | ||
568 | ||
569 | static void hwsim_send_nullfunc_ps(void *dat, u8 *mac, | |
570 | struct ieee80211_vif *vif) | |
571 | { | |
572 | struct mac80211_hwsim_data *data = dat; | |
573 | hwsim_send_nullfunc(data, mac, vif, 1); | |
574 | } | |
575 | ||
576 | static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac, | |
577 | struct ieee80211_vif *vif) | |
578 | { | |
579 | struct mac80211_hwsim_data *data = dat; | |
580 | hwsim_send_nullfunc(data, mac, vif, 0); | |
581 | } | |
582 | ||
583 | static int hwsim_fops_ps_read(void *dat, u64 *val) | |
584 | { | |
585 | struct mac80211_hwsim_data *data = dat; | |
586 | *val = data->ps; | |
587 | return 0; | |
588 | } | |
589 | ||
590 | static int hwsim_fops_ps_write(void *dat, u64 val) | |
591 | { | |
592 | struct mac80211_hwsim_data *data = dat; | |
593 | enum ps_mode old_ps; | |
594 | ||
595 | if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL && | |
596 | val != PS_MANUAL_POLL) | |
597 | return -EINVAL; | |
598 | ||
599 | old_ps = data->ps; | |
600 | data->ps = val; | |
601 | ||
602 | if (val == PS_MANUAL_POLL) { | |
603 | ieee80211_iterate_active_interfaces(data->hw, | |
604 | IEEE80211_IFACE_ITER_NORMAL, | |
605 | hwsim_send_ps_poll, data); | |
606 | data->ps_poll_pending = true; | |
607 | } else if (old_ps == PS_DISABLED && val != PS_DISABLED) { | |
608 | ieee80211_iterate_active_interfaces(data->hw, | |
609 | IEEE80211_IFACE_ITER_NORMAL, | |
610 | hwsim_send_nullfunc_ps, | |
611 | data); | |
612 | } else if (old_ps != PS_DISABLED && val == PS_DISABLED) { | |
613 | ieee80211_iterate_active_interfaces(data->hw, | |
614 | IEEE80211_IFACE_ITER_NORMAL, | |
615 | hwsim_send_nullfunc_no_ps, | |
616 | data); | |
617 | } | |
618 | ||
619 | return 0; | |
620 | } | |
621 | ||
622 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, | |
623 | "%llu\n"); | |
624 | ||
625 | static int hwsim_write_simulate_radar(void *dat, u64 val) | |
626 | { | |
627 | struct mac80211_hwsim_data *data = dat; | |
628 | ||
629 | ieee80211_radar_detected(data->hw); | |
630 | ||
631 | return 0; | |
632 | } | |
633 | ||
634 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_simulate_radar, NULL, | |
635 | hwsim_write_simulate_radar, "%llu\n"); | |
636 | ||
637 | static int hwsim_fops_group_read(void *dat, u64 *val) | |
638 | { | |
639 | struct mac80211_hwsim_data *data = dat; | |
640 | *val = data->group; | |
641 | return 0; | |
642 | } | |
643 | ||
644 | static int hwsim_fops_group_write(void *dat, u64 val) | |
645 | { | |
646 | struct mac80211_hwsim_data *data = dat; | |
647 | data->group = val; | |
648 | return 0; | |
649 | } | |
650 | ||
651 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group, | |
652 | hwsim_fops_group_read, hwsim_fops_group_write, | |
653 | "%llx\n"); | |
654 | ||
d0cf9c0d SH |
655 | static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, |
656 | struct net_device *dev) | |
acc1e7a3 JM |
657 | { |
658 | /* TODO: allow packet injection */ | |
659 | dev_kfree_skb(skb); | |
6ed10654 | 660 | return NETDEV_TX_OK; |
acc1e7a3 JM |
661 | } |
662 | ||
b66851c3 TP |
663 | static inline u64 mac80211_hwsim_get_tsf_raw(void) |
664 | { | |
665 | return ktime_to_us(ktime_get_real()); | |
666 | } | |
667 | ||
2f40b940 JC |
668 | static __le64 __mac80211_hwsim_get_tsf(struct mac80211_hwsim_data *data) |
669 | { | |
b66851c3 | 670 | u64 now = mac80211_hwsim_get_tsf_raw(); |
2f40b940 JC |
671 | return cpu_to_le64(now + data->tsf_offset); |
672 | } | |
acc1e7a3 | 673 | |
12ce8ba3 | 674 | static u64 mac80211_hwsim_get_tsf(struct ieee80211_hw *hw, |
b66851c3 | 675 | struct ieee80211_vif *vif) |
12ce8ba3 JC |
676 | { |
677 | struct mac80211_hwsim_data *data = hw->priv; | |
678 | return le64_to_cpu(__mac80211_hwsim_get_tsf(data)); | |
679 | } | |
680 | ||
681 | static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, | |
682 | struct ieee80211_vif *vif, u64 tsf) | |
683 | { | |
684 | struct mac80211_hwsim_data *data = hw->priv; | |
45034bfb | 685 | u64 now = mac80211_hwsim_get_tsf(hw, vif); |
c51f8783 | 686 | u32 bcn_int = data->beacon_int; |
45034bfb TP |
687 | s64 delta = tsf - now; |
688 | ||
689 | data->tsf_offset += delta; | |
c51f8783 TP |
690 | /* adjust after beaconing with new timestamp at old TBTT */ |
691 | data->bcn_delta = do_div(delta, bcn_int); | |
12ce8ba3 JC |
692 | } |
693 | ||
acc1e7a3 | 694 | static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw, |
e8261171 JB |
695 | struct sk_buff *tx_skb, |
696 | struct ieee80211_channel *chan) | |
acc1e7a3 JM |
697 | { |
698 | struct mac80211_hwsim_data *data = hw->priv; | |
699 | struct sk_buff *skb; | |
700 | struct hwsim_radiotap_hdr *hdr; | |
701 | u16 flags; | |
702 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb); | |
703 | struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info); | |
704 | ||
705 | if (!netif_running(hwsim_mon)) | |
706 | return; | |
707 | ||
708 | skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC); | |
709 | if (skb == NULL) | |
710 | return; | |
711 | ||
712 | hdr = (struct hwsim_radiotap_hdr *) skb_push(skb, sizeof(*hdr)); | |
713 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; | |
714 | hdr->hdr.it_pad = 0; | |
715 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); | |
f248f105 JM |
716 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | |
717 | (1 << IEEE80211_RADIOTAP_RATE) | | |
2f40b940 | 718 | (1 << IEEE80211_RADIOTAP_TSFT) | |
f248f105 | 719 | (1 << IEEE80211_RADIOTAP_CHANNEL)); |
2f40b940 | 720 | hdr->rt_tsft = __mac80211_hwsim_get_tsf(data); |
acc1e7a3 JM |
721 | hdr->rt_flags = 0; |
722 | hdr->rt_rate = txrate->bitrate / 5; | |
e8261171 | 723 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
acc1e7a3 JM |
724 | flags = IEEE80211_CHAN_2GHZ; |
725 | if (txrate->flags & IEEE80211_RATE_ERP_G) | |
726 | flags |= IEEE80211_CHAN_OFDM; | |
727 | else | |
728 | flags |= IEEE80211_CHAN_CCK; | |
729 | hdr->rt_chbitmask = cpu_to_le16(flags); | |
730 | ||
731 | skb->dev = hwsim_mon; | |
732 | skb_set_mac_header(skb, 0); | |
733 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
734 | skb->pkt_type = PACKET_OTHERHOST; | |
f248f105 | 735 | skb->protocol = htons(ETH_P_802_2); |
acc1e7a3 JM |
736 | memset(skb->cb, 0, sizeof(skb->cb)); |
737 | netif_rx(skb); | |
738 | } | |
739 | ||
740 | ||
e8261171 JB |
741 | static void mac80211_hwsim_monitor_ack(struct ieee80211_channel *chan, |
742 | const u8 *addr) | |
6c085227 | 743 | { |
6c085227 | 744 | struct sk_buff *skb; |
76a56eb3 | 745 | struct hwsim_radiotap_ack_hdr *hdr; |
6c085227 JM |
746 | u16 flags; |
747 | struct ieee80211_hdr *hdr11; | |
748 | ||
749 | if (!netif_running(hwsim_mon)) | |
750 | return; | |
751 | ||
752 | skb = dev_alloc_skb(100); | |
753 | if (skb == NULL) | |
754 | return; | |
755 | ||
76a56eb3 | 756 | hdr = (struct hwsim_radiotap_ack_hdr *) skb_put(skb, sizeof(*hdr)); |
6c085227 JM |
757 | hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
758 | hdr->hdr.it_pad = 0; | |
759 | hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr)); | |
760 | hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) | | |
761 | (1 << IEEE80211_RADIOTAP_CHANNEL)); | |
762 | hdr->rt_flags = 0; | |
76a56eb3 | 763 | hdr->pad = 0; |
e8261171 | 764 | hdr->rt_channel = cpu_to_le16(chan->center_freq); |
6c085227 JM |
765 | flags = IEEE80211_CHAN_2GHZ; |
766 | hdr->rt_chbitmask = cpu_to_le16(flags); | |
767 | ||
768 | hdr11 = (struct ieee80211_hdr *) skb_put(skb, 10); | |
769 | hdr11->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | |
770 | IEEE80211_STYPE_ACK); | |
771 | hdr11->duration_id = cpu_to_le16(0); | |
772 | memcpy(hdr11->addr1, addr, ETH_ALEN); | |
773 | ||
774 | skb->dev = hwsim_mon; | |
775 | skb_set_mac_header(skb, 0); | |
776 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
777 | skb->pkt_type = PACKET_OTHERHOST; | |
778 | skb->protocol = htons(ETH_P_802_2); | |
779 | memset(skb->cb, 0, sizeof(skb->cb)); | |
780 | netif_rx(skb); | |
781 | } | |
782 | ||
783 | ||
fc6971d4 JM |
784 | static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data, |
785 | struct sk_buff *skb) | |
786 | { | |
787 | switch (data->ps) { | |
788 | case PS_DISABLED: | |
789 | return true; | |
790 | case PS_ENABLED: | |
791 | return false; | |
792 | case PS_AUTO_POLL: | |
793 | /* TODO: accept (some) Beacons by default and other frames only | |
794 | * if pending PS-Poll has been sent */ | |
795 | return true; | |
796 | case PS_MANUAL_POLL: | |
797 | /* Allow unicast frames to own address if there is a pending | |
798 | * PS-Poll */ | |
799 | if (data->ps_poll_pending && | |
800 | memcmp(data->hw->wiphy->perm_addr, skb->data + 4, | |
801 | ETH_ALEN) == 0) { | |
802 | data->ps_poll_pending = false; | |
803 | return true; | |
804 | } | |
805 | return false; | |
806 | } | |
807 | ||
808 | return true; | |
809 | } | |
810 | ||
811 | ||
265dc7f0 JM |
812 | struct mac80211_hwsim_addr_match_data { |
813 | bool ret; | |
814 | const u8 *addr; | |
815 | }; | |
816 | ||
817 | static void mac80211_hwsim_addr_iter(void *data, u8 *mac, | |
818 | struct ieee80211_vif *vif) | |
819 | { | |
820 | struct mac80211_hwsim_addr_match_data *md = data; | |
821 | if (memcmp(mac, md->addr, ETH_ALEN) == 0) | |
822 | md->ret = true; | |
823 | } | |
824 | ||
825 | ||
826 | static bool mac80211_hwsim_addr_match(struct mac80211_hwsim_data *data, | |
827 | const u8 *addr) | |
828 | { | |
829 | struct mac80211_hwsim_addr_match_data md; | |
830 | ||
831 | if (memcmp(addr, data->hw->wiphy->perm_addr, ETH_ALEN) == 0) | |
832 | return true; | |
833 | ||
834 | md.ret = false; | |
835 | md.addr = addr; | |
836 | ieee80211_iterate_active_interfaces_atomic(data->hw, | |
8b2c9824 | 837 | IEEE80211_IFACE_ITER_NORMAL, |
265dc7f0 JM |
838 | mac80211_hwsim_addr_iter, |
839 | &md); | |
840 | ||
841 | return md.ret; | |
842 | } | |
843 | ||
7882513b JL |
844 | static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, |
845 | struct sk_buff *my_skb, | |
15e47304 | 846 | int dst_portid) |
7882513b JL |
847 | { |
848 | struct sk_buff *skb; | |
849 | struct mac80211_hwsim_data *data = hw->priv; | |
850 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) my_skb->data; | |
851 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(my_skb); | |
852 | void *msg_head; | |
853 | unsigned int hwsim_flags = 0; | |
854 | int i; | |
855 | struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES]; | |
856 | ||
7882513b JL |
857 | if (data->ps != PS_DISABLED) |
858 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
859 | /* If the queue contains MAX_QUEUE skb's drop some */ | |
860 | if (skb_queue_len(&data->pending) >= MAX_QUEUE) { | |
861 | /* Droping until WARN_QUEUE level */ | |
862 | while (skb_queue_len(&data->pending) >= WARN_QUEUE) | |
863 | skb_dequeue(&data->pending); | |
864 | } | |
865 | ||
58050fce | 866 | skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
7882513b JL |
867 | if (skb == NULL) |
868 | goto nla_put_failure; | |
869 | ||
870 | msg_head = genlmsg_put(skb, 0, 0, &hwsim_genl_family, 0, | |
871 | HWSIM_CMD_FRAME); | |
872 | if (msg_head == NULL) { | |
873 | printk(KERN_DEBUG "mac80211_hwsim: problem with msg_head\n"); | |
874 | goto nla_put_failure; | |
875 | } | |
876 | ||
633c9389 | 877 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, |
9ddd12af | 878 | ETH_ALEN, data->addresses[1].addr)) |
633c9389 | 879 | goto nla_put_failure; |
265dc7f0 | 880 | |
7882513b | 881 | /* We get the skb->data */ |
633c9389 DM |
882 | if (nla_put(skb, HWSIM_ATTR_FRAME, my_skb->len, my_skb->data)) |
883 | goto nla_put_failure; | |
7882513b JL |
884 | |
885 | /* We get the flags for this transmission, and we translate them to | |
886 | wmediumd flags */ | |
887 | ||
888 | if (info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS) | |
889 | hwsim_flags |= HWSIM_TX_CTL_REQ_TX_STATUS; | |
890 | ||
891 | if (info->flags & IEEE80211_TX_CTL_NO_ACK) | |
892 | hwsim_flags |= HWSIM_TX_CTL_NO_ACK; | |
893 | ||
633c9389 DM |
894 | if (nla_put_u32(skb, HWSIM_ATTR_FLAGS, hwsim_flags)) |
895 | goto nla_put_failure; | |
7882513b JL |
896 | |
897 | /* We get the tx control (rate and retries) info*/ | |
898 | ||
899 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { | |
900 | tx_attempts[i].idx = info->status.rates[i].idx; | |
901 | tx_attempts[i].count = info->status.rates[i].count; | |
902 | } | |
903 | ||
633c9389 DM |
904 | if (nla_put(skb, HWSIM_ATTR_TX_INFO, |
905 | sizeof(struct hwsim_tx_rate)*IEEE80211_TX_MAX_RATES, | |
906 | tx_attempts)) | |
907 | goto nla_put_failure; | |
7882513b JL |
908 | |
909 | /* We create a cookie to identify this skb */ | |
633c9389 DM |
910 | if (nla_put_u64(skb, HWSIM_ATTR_COOKIE, (unsigned long) my_skb)) |
911 | goto nla_put_failure; | |
7882513b JL |
912 | |
913 | genlmsg_end(skb, msg_head); | |
15e47304 | 914 | genlmsg_unicast(&init_net, skb, dst_portid); |
7882513b JL |
915 | |
916 | /* Enqueue the packet */ | |
917 | skb_queue_tail(&data->pending, my_skb); | |
918 | return; | |
919 | ||
920 | nla_put_failure: | |
c393862f | 921 | printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); |
7882513b JL |
922 | } |
923 | ||
e8261171 JB |
924 | static bool hwsim_chans_compat(struct ieee80211_channel *c1, |
925 | struct ieee80211_channel *c2) | |
926 | { | |
927 | if (!c1 || !c2) | |
928 | return false; | |
929 | ||
930 | return c1->center_freq == c2->center_freq; | |
931 | } | |
932 | ||
933 | struct tx_iter_data { | |
934 | struct ieee80211_channel *channel; | |
935 | bool receive; | |
936 | }; | |
937 | ||
938 | static void mac80211_hwsim_tx_iter(void *_data, u8 *addr, | |
939 | struct ieee80211_vif *vif) | |
940 | { | |
941 | struct tx_iter_data *data = _data; | |
942 | ||
943 | if (!vif->chanctx_conf) | |
944 | return; | |
945 | ||
946 | if (!hwsim_chans_compat(data->channel, | |
4bf88530 | 947 | rcu_dereference(vif->chanctx_conf)->def.chan)) |
e8261171 JB |
948 | return; |
949 | ||
950 | data->receive = true; | |
951 | } | |
952 | ||
7882513b | 953 | static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw, |
e8261171 JB |
954 | struct sk_buff *skb, |
955 | struct ieee80211_channel *chan) | |
acc1e7a3 | 956 | { |
0e057d73 JB |
957 | struct mac80211_hwsim_data *data = hw->priv, *data2; |
958 | bool ack = false; | |
e36cfdc9 | 959 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
acc1e7a3 | 960 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e36cfdc9 | 961 | struct ieee80211_rx_status rx_status; |
b66851c3 | 962 | u64 now; |
acc1e7a3 JM |
963 | |
964 | memset(&rx_status, 0, sizeof(rx_status)); | |
f4bda337 | 965 | rx_status.flag |= RX_FLAG_MACTIME_START; |
e8261171 JB |
966 | rx_status.freq = chan->center_freq; |
967 | rx_status.band = chan->band; | |
dad6330d KB |
968 | if (info->control.rates[0].flags & IEEE80211_TX_RC_VHT_MCS) { |
969 | rx_status.rate_idx = | |
970 | ieee80211_rate_get_vht_mcs(&info->control.rates[0]); | |
971 | rx_status.vht_nss = | |
972 | ieee80211_rate_get_vht_nss(&info->control.rates[0]); | |
973 | rx_status.flag |= RX_FLAG_VHT; | |
974 | } else { | |
975 | rx_status.rate_idx = info->control.rates[0].idx; | |
976 | if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS) | |
977 | rx_status.flag |= RX_FLAG_HT; | |
978 | } | |
281ed297 JM |
979 | if (info->control.rates[0].flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
980 | rx_status.flag |= RX_FLAG_40MHZ; | |
981 | if (info->control.rates[0].flags & IEEE80211_TX_RC_SHORT_GI) | |
982 | rx_status.flag |= RX_FLAG_SHORT_GI; | |
4b14c96d | 983 | /* TODO: simulate real signal strength (and optional packet loss) */ |
bdd7bd16 | 984 | rx_status.signal = data->power_level - 50; |
acc1e7a3 | 985 | |
fc6971d4 JM |
986 | if (data->ps != PS_DISABLED) |
987 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); | |
988 | ||
90e3012e JB |
989 | /* release the skb's source info */ |
990 | skb_orphan(skb); | |
c0acf38e | 991 | skb_dst_drop(skb); |
90e3012e JB |
992 | skb->mark = 0; |
993 | secpath_reset(skb); | |
994 | nf_reset(skb); | |
995 | ||
b66851c3 TP |
996 | /* |
997 | * Get absolute mactime here so all HWs RX at the "same time", and | |
998 | * absolute TX time for beacon mactime so the timestamp matches. | |
999 | * Giving beacons a different mactime than non-beacons looks messy, but | |
1000 | * it helps the Toffset be exact and a ~10us mactime discrepancy | |
1001 | * probably doesn't really matter. | |
1002 | */ | |
1003 | if (ieee80211_is_beacon(hdr->frame_control) || | |
1004 | ieee80211_is_probe_resp(hdr->frame_control)) | |
1005 | now = data->abs_bcn_ts; | |
1006 | else | |
1007 | now = mac80211_hwsim_get_tsf_raw(); | |
1008 | ||
acc1e7a3 | 1009 | /* Copy skb to all enabled radios that are on the current frequency */ |
0e057d73 JB |
1010 | spin_lock(&hwsim_radio_lock); |
1011 | list_for_each_entry(data2, &hwsim_radios, list) { | |
acc1e7a3 | 1012 | struct sk_buff *nskb; |
e8261171 JB |
1013 | struct tx_iter_data tx_iter_data = { |
1014 | .receive = false, | |
1015 | .channel = chan, | |
1016 | }; | |
acc1e7a3 | 1017 | |
0e057d73 | 1018 | if (data == data2) |
acc1e7a3 | 1019 | continue; |
0e057d73 | 1020 | |
e8261171 JB |
1021 | if (!data2->started || (data2->idle && !data2->tmp_chan) || |
1022 | !hwsim_ps_rx_ok(data2, skb)) | |
acc1e7a3 JM |
1023 | continue; |
1024 | ||
e8261171 JB |
1025 | if (!(data->group & data2->group)) |
1026 | continue; | |
1027 | ||
1028 | if (!hwsim_chans_compat(chan, data2->tmp_chan) && | |
1029 | !hwsim_chans_compat(chan, data2->channel)) { | |
1030 | ieee80211_iterate_active_interfaces_atomic( | |
8b2c9824 JB |
1031 | data2->hw, IEEE80211_IFACE_ITER_NORMAL, |
1032 | mac80211_hwsim_tx_iter, &tx_iter_data); | |
e8261171 JB |
1033 | if (!tx_iter_data.receive) |
1034 | continue; | |
1035 | } | |
1036 | ||
90b9e446 JB |
1037 | /* |
1038 | * reserve some space for our vendor and the normal | |
1039 | * radiotap header, since we're copying anyway | |
1040 | */ | |
a357d7f9 JB |
1041 | if (skb->len < PAGE_SIZE && paged_rx) { |
1042 | struct page *page = alloc_page(GFP_ATOMIC); | |
1043 | ||
1044 | if (!page) | |
1045 | continue; | |
1046 | ||
1047 | nskb = dev_alloc_skb(128); | |
1048 | if (!nskb) { | |
1049 | __free_page(page); | |
1050 | continue; | |
1051 | } | |
1052 | ||
1053 | memcpy(page_address(page), skb->data, skb->len); | |
1054 | skb_add_rx_frag(nskb, 0, page, 0, skb->len, skb->len); | |
1055 | } else { | |
1056 | nskb = skb_copy(skb, GFP_ATOMIC); | |
1057 | if (!nskb) | |
1058 | continue; | |
1059 | } | |
acc1e7a3 | 1060 | |
265dc7f0 | 1061 | if (mac80211_hwsim_addr_match(data2, hdr->addr1)) |
0e057d73 | 1062 | ack = true; |
f483ad25 | 1063 | |
b66851c3 | 1064 | rx_status.mactime = now + data2->tsf_offset; |
90b9e446 | 1065 | |
f1d58c25 JB |
1066 | memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status)); |
1067 | ieee80211_rx_irqsafe(data2->hw, nskb); | |
acc1e7a3 | 1068 | } |
0e057d73 | 1069 | spin_unlock(&hwsim_radio_lock); |
acc1e7a3 | 1070 | |
e36cfdc9 JM |
1071 | return ack; |
1072 | } | |
1073 | ||
36323f81 TH |
1074 | static void mac80211_hwsim_tx(struct ieee80211_hw *hw, |
1075 | struct ieee80211_tx_control *control, | |
1076 | struct sk_buff *skb) | |
e36cfdc9 | 1077 | { |
e8261171 JB |
1078 | struct mac80211_hwsim_data *data = hw->priv; |
1079 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); | |
1080 | struct ieee80211_chanctx_conf *chanctx_conf; | |
1081 | struct ieee80211_channel *channel; | |
0e057d73 | 1082 | bool ack; |
15e47304 | 1083 | u32 _portid; |
e36cfdc9 | 1084 | |
e8261171 | 1085 | if (WARN_ON(skb->len < 10)) { |
e36cfdc9 | 1086 | /* Should not happen; just a sanity check for addr1 use */ |
fe0f3cd2 | 1087 | ieee80211_free_txskb(hw, skb); |
7bb45683 | 1088 | return; |
e36cfdc9 JM |
1089 | } |
1090 | ||
38ed5048 | 1091 | if (data->channels == 1) { |
e8261171 JB |
1092 | channel = data->channel; |
1093 | } else if (txi->hw_queue == 4) { | |
1094 | channel = data->tmp_chan; | |
1095 | } else { | |
1096 | chanctx_conf = rcu_dereference(txi->control.vif->chanctx_conf); | |
1097 | if (chanctx_conf) | |
4bf88530 | 1098 | channel = chanctx_conf->def.chan; |
e8261171 JB |
1099 | else |
1100 | channel = NULL; | |
1101 | } | |
1102 | ||
1103 | if (WARN(!channel, "TX w/o channel - queue = %d\n", txi->hw_queue)) { | |
fe0f3cd2 | 1104 | ieee80211_free_txskb(hw, skb); |
e8261171 JB |
1105 | return; |
1106 | } | |
1107 | ||
1108 | if (data->idle && !data->tmp_chan) { | |
1109 | wiphy_debug(hw->wiphy, "Trying to TX when idle - reject\n"); | |
fe0f3cd2 | 1110 | ieee80211_free_txskb(hw, skb); |
e8261171 JB |
1111 | return; |
1112 | } | |
1113 | ||
1114 | if (txi->control.vif) | |
1115 | hwsim_check_magic(txi->control.vif); | |
1116 | if (control->sta) | |
1117 | hwsim_check_sta_magic(control->sta); | |
1118 | ||
81338410 | 1119 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) |
1eb32179 KB |
1120 | ieee80211_get_tx_rates(txi->control.vif, control->sta, skb, |
1121 | txi->control.rates, | |
1122 | ARRAY_SIZE(txi->control.rates)); | |
e8261171 | 1123 | |
1eb32179 | 1124 | txi->rate_driver_data[0] = channel; |
e8261171 JB |
1125 | mac80211_hwsim_monitor_rx(hw, skb, channel); |
1126 | ||
7882513b | 1127 | /* wmediumd mode check */ |
15e47304 | 1128 | _portid = ACCESS_ONCE(wmediumd_portid); |
7882513b | 1129 | |
15e47304 EB |
1130 | if (_portid) |
1131 | return mac80211_hwsim_tx_frame_nl(hw, skb, _portid); | |
7882513b JL |
1132 | |
1133 | /* NO wmediumd detected, perfect medium simulation */ | |
e8261171 | 1134 | ack = mac80211_hwsim_tx_frame_no_nl(hw, skb, channel); |
7882513b | 1135 | |
6c085227 JM |
1136 | if (ack && skb->len >= 16) { |
1137 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
e8261171 | 1138 | mac80211_hwsim_monitor_ack(channel, hdr->addr2); |
6c085227 | 1139 | } |
e36cfdc9 | 1140 | |
e6a9854b | 1141 | ieee80211_tx_info_clear_status(txi); |
2a4ffa4c JC |
1142 | |
1143 | /* frame was transmitted at most favorable rate at first attempt */ | |
1144 | txi->control.rates[0].count = 1; | |
1145 | txi->control.rates[1].idx = -1; | |
1146 | ||
e6a9854b JB |
1147 | if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack) |
1148 | txi->flags |= IEEE80211_TX_STAT_ACK; | |
acc1e7a3 | 1149 | ieee80211_tx_status_irqsafe(hw, skb); |
acc1e7a3 JM |
1150 | } |
1151 | ||
1152 | ||
1153 | static int mac80211_hwsim_start(struct ieee80211_hw *hw) | |
1154 | { | |
1155 | struct mac80211_hwsim_data *data = hw->priv; | |
c96c31e4 | 1156 | wiphy_debug(hw->wiphy, "%s\n", __func__); |
3db1cd5c | 1157 | data->started = true; |
acc1e7a3 JM |
1158 | return 0; |
1159 | } | |
1160 | ||
1161 | ||
1162 | static void mac80211_hwsim_stop(struct ieee80211_hw *hw) | |
1163 | { | |
1164 | struct mac80211_hwsim_data *data = hw->priv; | |
3db1cd5c | 1165 | data->started = false; |
01e59e46 | 1166 | tasklet_hrtimer_cancel(&data->beacon_timer); |
c96c31e4 | 1167 | wiphy_debug(hw->wiphy, "%s\n", __func__); |
acc1e7a3 JM |
1168 | } |
1169 | ||
1170 | ||
1171 | static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw, | |
1ed32e4f | 1172 | struct ieee80211_vif *vif) |
acc1e7a3 | 1173 | { |
c96c31e4 | 1174 | wiphy_debug(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
2ca27bcf JB |
1175 | __func__, ieee80211_vif_type_p2p(vif), |
1176 | vif->addr); | |
1ed32e4f | 1177 | hwsim_set_magic(vif); |
e8261171 JB |
1178 | |
1179 | vif->cab_queue = 0; | |
1180 | vif->hw_queue[IEEE80211_AC_VO] = 0; | |
1181 | vif->hw_queue[IEEE80211_AC_VI] = 1; | |
1182 | vif->hw_queue[IEEE80211_AC_BE] = 2; | |
1183 | vif->hw_queue[IEEE80211_AC_BK] = 3; | |
1184 | ||
acc1e7a3 JM |
1185 | return 0; |
1186 | } | |
1187 | ||
1188 | ||
c35d0270 JB |
1189 | static int mac80211_hwsim_change_interface(struct ieee80211_hw *hw, |
1190 | struct ieee80211_vif *vif, | |
2ca27bcf JB |
1191 | enum nl80211_iftype newtype, |
1192 | bool newp2p) | |
c35d0270 | 1193 | { |
2ca27bcf | 1194 | newtype = ieee80211_iftype_p2p(newtype, newp2p); |
c35d0270 JB |
1195 | wiphy_debug(hw->wiphy, |
1196 | "%s (old type=%d, new type=%d, mac_addr=%pM)\n", | |
2ca27bcf JB |
1197 | __func__, ieee80211_vif_type_p2p(vif), |
1198 | newtype, vif->addr); | |
c35d0270 JB |
1199 | hwsim_check_magic(vif); |
1200 | ||
3eb92f6a JB |
1201 | /* |
1202 | * interface may change from non-AP to AP in | |
1203 | * which case this needs to be set up again | |
1204 | */ | |
1205 | vif->cab_queue = 0; | |
1206 | ||
c35d0270 JB |
1207 | return 0; |
1208 | } | |
1209 | ||
acc1e7a3 | 1210 | static void mac80211_hwsim_remove_interface( |
1ed32e4f | 1211 | struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
acc1e7a3 | 1212 | { |
c96c31e4 | 1213 | wiphy_debug(hw->wiphy, "%s (type=%d mac_addr=%pM)\n", |
2ca27bcf JB |
1214 | __func__, ieee80211_vif_type_p2p(vif), |
1215 | vif->addr); | |
1ed32e4f JB |
1216 | hwsim_check_magic(vif); |
1217 | hwsim_clear_magic(vif); | |
acc1e7a3 JM |
1218 | } |
1219 | ||
e8261171 JB |
1220 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, |
1221 | struct sk_buff *skb, | |
1222 | struct ieee80211_channel *chan) | |
1223 | { | |
1224 | u32 _pid = ACCESS_ONCE(wmediumd_portid); | |
1225 | ||
81338410 | 1226 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) { |
1eb32179 KB |
1227 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); |
1228 | ieee80211_get_tx_rates(txi->control.vif, NULL, skb, | |
1229 | txi->control.rates, | |
1230 | ARRAY_SIZE(txi->control.rates)); | |
1231 | } | |
1232 | ||
e8261171 JB |
1233 | mac80211_hwsim_monitor_rx(hw, skb, chan); |
1234 | ||
1235 | if (_pid) | |
1236 | return mac80211_hwsim_tx_frame_nl(hw, skb, _pid); | |
1237 | ||
1238 | mac80211_hwsim_tx_frame_no_nl(hw, skb, chan); | |
1239 | dev_kfree_skb(skb); | |
1240 | } | |
acc1e7a3 JM |
1241 | |
1242 | static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac, | |
1243 | struct ieee80211_vif *vif) | |
1244 | { | |
b66851c3 TP |
1245 | struct mac80211_hwsim_data *data = arg; |
1246 | struct ieee80211_hw *hw = data->hw; | |
1247 | struct ieee80211_tx_info *info; | |
1248 | struct ieee80211_rate *txrate; | |
1249 | struct ieee80211_mgmt *mgmt; | |
acc1e7a3 | 1250 | struct sk_buff *skb; |
acc1e7a3 | 1251 | |
8aa21e6f JB |
1252 | hwsim_check_magic(vif); |
1253 | ||
55b39619 | 1254 | if (vif->type != NL80211_IFTYPE_AP && |
2b2d7795 JB |
1255 | vif->type != NL80211_IFTYPE_MESH_POINT && |
1256 | vif->type != NL80211_IFTYPE_ADHOC) | |
acc1e7a3 JM |
1257 | return; |
1258 | ||
1259 | skb = ieee80211_beacon_get(hw, vif); | |
1260 | if (skb == NULL) | |
1261 | return; | |
b66851c3 | 1262 | info = IEEE80211_SKB_CB(skb); |
81338410 | 1263 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) |
1eb32179 KB |
1264 | ieee80211_get_tx_rates(vif, NULL, skb, |
1265 | info->control.rates, | |
1266 | ARRAY_SIZE(info->control.rates)); | |
1267 | ||
b66851c3 TP |
1268 | txrate = ieee80211_get_tx_rate(hw, info); |
1269 | ||
1270 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
1271 | /* fake header transmission time */ | |
1272 | data->abs_bcn_ts = mac80211_hwsim_get_tsf_raw(); | |
1273 | mgmt->u.beacon.timestamp = cpu_to_le64(data->abs_bcn_ts + | |
1274 | data->tsf_offset + | |
1275 | 24 * 8 * 10 / txrate->bitrate); | |
7882513b | 1276 | |
e8261171 | 1277 | mac80211_hwsim_tx_frame(hw, skb, |
4bf88530 | 1278 | rcu_dereference(vif->chanctx_conf)->def.chan); |
0037db63 AO |
1279 | |
1280 | if (vif->csa_active && ieee80211_csa_is_complete(vif)) | |
1281 | ieee80211_csa_finish(vif); | |
acc1e7a3 JM |
1282 | } |
1283 | ||
01e59e46 TP |
1284 | static enum hrtimer_restart |
1285 | mac80211_hwsim_beacon(struct hrtimer *timer) | |
acc1e7a3 | 1286 | { |
01e59e46 TP |
1287 | struct mac80211_hwsim_data *data = |
1288 | container_of(timer, struct mac80211_hwsim_data, | |
1289 | beacon_timer.timer); | |
1290 | struct ieee80211_hw *hw = data->hw; | |
1291 | u64 bcn_int = data->beacon_int; | |
1292 | ktime_t next_bcn; | |
acc1e7a3 | 1293 | |
4c4c671a | 1294 | if (!data->started) |
01e59e46 | 1295 | goto out; |
acc1e7a3 | 1296 | |
f248f105 | 1297 | ieee80211_iterate_active_interfaces_atomic( |
8b2c9824 | 1298 | hw, IEEE80211_IFACE_ITER_NORMAL, |
b66851c3 | 1299 | mac80211_hwsim_beacon_tx, data); |
acc1e7a3 | 1300 | |
c51f8783 TP |
1301 | /* beacon at new TBTT + beacon interval */ |
1302 | if (data->bcn_delta) { | |
1303 | bcn_int -= data->bcn_delta; | |
1304 | data->bcn_delta = 0; | |
1305 | } | |
1306 | ||
01e59e46 TP |
1307 | next_bcn = ktime_add(hrtimer_get_expires(timer), |
1308 | ns_to_ktime(bcn_int * 1000)); | |
1309 | tasklet_hrtimer_start(&data->beacon_timer, next_bcn, HRTIMER_MODE_ABS); | |
1310 | out: | |
1311 | return HRTIMER_NORESTART; | |
acc1e7a3 JM |
1312 | } |
1313 | ||
675a0b04 KB |
1314 | static const char * const hwsim_chanwidths[] = { |
1315 | [NL80211_CHAN_WIDTH_20_NOHT] = "noht", | |
1316 | [NL80211_CHAN_WIDTH_20] = "ht20", | |
1317 | [NL80211_CHAN_WIDTH_40] = "ht40", | |
1318 | [NL80211_CHAN_WIDTH_80] = "vht80", | |
1319 | [NL80211_CHAN_WIDTH_80P80] = "vht80p80", | |
1320 | [NL80211_CHAN_WIDTH_160] = "vht160", | |
0aaffa9b | 1321 | }; |
acc1e7a3 | 1322 | |
e8975581 | 1323 | static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) |
acc1e7a3 JM |
1324 | { |
1325 | struct mac80211_hwsim_data *data = hw->priv; | |
e8975581 | 1326 | struct ieee80211_conf *conf = &hw->conf; |
0f78231b JB |
1327 | static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = { |
1328 | [IEEE80211_SMPS_AUTOMATIC] = "auto", | |
1329 | [IEEE80211_SMPS_OFF] = "off", | |
1330 | [IEEE80211_SMPS_STATIC] = "static", | |
1331 | [IEEE80211_SMPS_DYNAMIC] = "dynamic", | |
1332 | }; | |
1333 | ||
675a0b04 KB |
1334 | if (conf->chandef.chan) |
1335 | wiphy_debug(hw->wiphy, | |
1336 | "%s (freq=%d(%d - %d)/%s idle=%d ps=%d smps=%s)\n", | |
1337 | __func__, | |
1338 | conf->chandef.chan->center_freq, | |
1339 | conf->chandef.center_freq1, | |
1340 | conf->chandef.center_freq2, | |
1341 | hwsim_chanwidths[conf->chandef.width], | |
1342 | !!(conf->flags & IEEE80211_CONF_IDLE), | |
1343 | !!(conf->flags & IEEE80211_CONF_PS), | |
1344 | smps_modes[conf->smps_mode]); | |
1345 | else | |
1346 | wiphy_debug(hw->wiphy, | |
1347 | "%s (freq=0 idle=%d ps=%d smps=%s)\n", | |
1348 | __func__, | |
1349 | !!(conf->flags & IEEE80211_CONF_IDLE), | |
1350 | !!(conf->flags & IEEE80211_CONF_PS), | |
1351 | smps_modes[conf->smps_mode]); | |
acc1e7a3 | 1352 | |
70541839 JM |
1353 | data->idle = !!(conf->flags & IEEE80211_CONF_IDLE); |
1354 | ||
675a0b04 | 1355 | data->channel = conf->chandef.chan; |
e8261171 | 1356 | |
38ed5048 | 1357 | WARN_ON(data->channel && data->channels > 1); |
e8261171 | 1358 | |
bdd7bd16 | 1359 | data->power_level = conf->power_level; |
4c4c671a | 1360 | if (!data->started || !data->beacon_int) |
01e59e46 TP |
1361 | tasklet_hrtimer_cancel(&data->beacon_timer); |
1362 | else if (!hrtimer_is_queued(&data->beacon_timer.timer)) { | |
c51f8783 TP |
1363 | u64 tsf = mac80211_hwsim_get_tsf(hw, NULL); |
1364 | u32 bcn_int = data->beacon_int; | |
1365 | u64 until_tbtt = bcn_int - do_div(tsf, bcn_int); | |
1366 | ||
01e59e46 | 1367 | tasklet_hrtimer_start(&data->beacon_timer, |
c51f8783 | 1368 | ns_to_ktime(until_tbtt * 1000), |
01e59e46 TP |
1369 | HRTIMER_MODE_REL); |
1370 | } | |
acc1e7a3 JM |
1371 | |
1372 | return 0; | |
1373 | } | |
1374 | ||
1375 | ||
1376 | static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw, | |
1377 | unsigned int changed_flags, | |
3ac64bee | 1378 | unsigned int *total_flags,u64 multicast) |
acc1e7a3 JM |
1379 | { |
1380 | struct mac80211_hwsim_data *data = hw->priv; | |
1381 | ||
c96c31e4 | 1382 | wiphy_debug(hw->wiphy, "%s\n", __func__); |
acc1e7a3 JM |
1383 | |
1384 | data->rx_filter = 0; | |
1385 | if (*total_flags & FIF_PROMISC_IN_BSS) | |
1386 | data->rx_filter |= FIF_PROMISC_IN_BSS; | |
1387 | if (*total_flags & FIF_ALLMULTI) | |
1388 | data->rx_filter |= FIF_ALLMULTI; | |
1389 | ||
1390 | *total_flags = data->rx_filter; | |
1391 | } | |
1392 | ||
0bb861e6 JM |
1393 | static void mac80211_hwsim_bcn_en_iter(void *data, u8 *mac, |
1394 | struct ieee80211_vif *vif) | |
1395 | { | |
1396 | unsigned int *count = data; | |
1397 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | |
1398 | ||
1399 | if (vp->bcn_en) | |
1400 | (*count)++; | |
1401 | } | |
1402 | ||
8aa21e6f JB |
1403 | static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw, |
1404 | struct ieee80211_vif *vif, | |
1405 | struct ieee80211_bss_conf *info, | |
1406 | u32 changed) | |
1407 | { | |
fc6971d4 | 1408 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; |
57c4d7b4 | 1409 | struct mac80211_hwsim_data *data = hw->priv; |
fc6971d4 | 1410 | |
8aa21e6f | 1411 | hwsim_check_magic(vif); |
fe63bfa3 | 1412 | |
0bb861e6 JM |
1413 | wiphy_debug(hw->wiphy, "%s(changed=0x%x vif->addr=%pM)\n", |
1414 | __func__, changed, vif->addr); | |
fe63bfa3 | 1415 | |
2d0ddec5 | 1416 | if (changed & BSS_CHANGED_BSSID) { |
c96c31e4 JP |
1417 | wiphy_debug(hw->wiphy, "%s: BSSID changed: %pM\n", |
1418 | __func__, info->bssid); | |
2d0ddec5 JB |
1419 | memcpy(vp->bssid, info->bssid, ETH_ALEN); |
1420 | } | |
1421 | ||
fe63bfa3 | 1422 | if (changed & BSS_CHANGED_ASSOC) { |
c96c31e4 JP |
1423 | wiphy_debug(hw->wiphy, " ASSOC: assoc=%d aid=%d\n", |
1424 | info->assoc, info->aid); | |
fc6971d4 JM |
1425 | vp->assoc = info->assoc; |
1426 | vp->aid = info->aid; | |
fe63bfa3 JM |
1427 | } |
1428 | ||
57c4d7b4 | 1429 | if (changed & BSS_CHANGED_BEACON_INT) { |
c96c31e4 | 1430 | wiphy_debug(hw->wiphy, " BCNINT: %d\n", info->beacon_int); |
01e59e46 TP |
1431 | data->beacon_int = info->beacon_int * 1024; |
1432 | } | |
1433 | ||
1434 | if (changed & BSS_CHANGED_BEACON_ENABLED) { | |
1435 | wiphy_debug(hw->wiphy, " BCN EN: %d\n", info->enable_beacon); | |
0bb861e6 | 1436 | vp->bcn_en = info->enable_beacon; |
01e59e46 TP |
1437 | if (data->started && |
1438 | !hrtimer_is_queued(&data->beacon_timer.timer) && | |
1439 | info->enable_beacon) { | |
c51f8783 TP |
1440 | u64 tsf, until_tbtt; |
1441 | u32 bcn_int; | |
01e59e46 TP |
1442 | if (WARN_ON(!data->beacon_int)) |
1443 | data->beacon_int = 1000 * 1024; | |
c51f8783 TP |
1444 | tsf = mac80211_hwsim_get_tsf(hw, vif); |
1445 | bcn_int = data->beacon_int; | |
1446 | until_tbtt = bcn_int - do_div(tsf, bcn_int); | |
01e59e46 | 1447 | tasklet_hrtimer_start(&data->beacon_timer, |
c51f8783 | 1448 | ns_to_ktime(until_tbtt * 1000), |
01e59e46 | 1449 | HRTIMER_MODE_REL); |
0bb861e6 JM |
1450 | } else if (!info->enable_beacon) { |
1451 | unsigned int count = 0; | |
cdb1b805 | 1452 | ieee80211_iterate_active_interfaces_atomic( |
0bb861e6 JM |
1453 | data->hw, IEEE80211_IFACE_ITER_NORMAL, |
1454 | mac80211_hwsim_bcn_en_iter, &count); | |
1455 | wiphy_debug(hw->wiphy, " beaconing vifs remaining: %u", | |
1456 | count); | |
1457 | if (count == 0) | |
1458 | tasklet_hrtimer_cancel(&data->beacon_timer); | |
1459 | } | |
57c4d7b4 JB |
1460 | } |
1461 | ||
fe63bfa3 | 1462 | if (changed & BSS_CHANGED_ERP_CTS_PROT) { |
c96c31e4 JP |
1463 | wiphy_debug(hw->wiphy, " ERP_CTS_PROT: %d\n", |
1464 | info->use_cts_prot); | |
fe63bfa3 JM |
1465 | } |
1466 | ||
1467 | if (changed & BSS_CHANGED_ERP_PREAMBLE) { | |
c96c31e4 JP |
1468 | wiphy_debug(hw->wiphy, " ERP_PREAMBLE: %d\n", |
1469 | info->use_short_preamble); | |
fe63bfa3 JM |
1470 | } |
1471 | ||
1472 | if (changed & BSS_CHANGED_ERP_SLOT) { | |
c96c31e4 | 1473 | wiphy_debug(hw->wiphy, " ERP_SLOT: %d\n", info->use_short_slot); |
fe63bfa3 JM |
1474 | } |
1475 | ||
1476 | if (changed & BSS_CHANGED_HT) { | |
4bf88530 JB |
1477 | wiphy_debug(hw->wiphy, " HT: op_mode=0x%x\n", |
1478 | info->ht_operation_mode); | |
fe63bfa3 JM |
1479 | } |
1480 | ||
1481 | if (changed & BSS_CHANGED_BASIC_RATES) { | |
c96c31e4 JP |
1482 | wiphy_debug(hw->wiphy, " BASIC_RATES: 0x%llx\n", |
1483 | (unsigned long long) info->basic_rates); | |
fe63bfa3 | 1484 | } |
cbc668a7 JB |
1485 | |
1486 | if (changed & BSS_CHANGED_TXPOWER) | |
1487 | wiphy_debug(hw->wiphy, " TX Power: %d dBm\n", info->txpower); | |
8aa21e6f JB |
1488 | } |
1489 | ||
1d669cbf JB |
1490 | static int mac80211_hwsim_sta_add(struct ieee80211_hw *hw, |
1491 | struct ieee80211_vif *vif, | |
1492 | struct ieee80211_sta *sta) | |
1493 | { | |
1494 | hwsim_check_magic(vif); | |
1495 | hwsim_set_sta_magic(sta); | |
1496 | ||
1497 | return 0; | |
1498 | } | |
1499 | ||
1500 | static int mac80211_hwsim_sta_remove(struct ieee80211_hw *hw, | |
1501 | struct ieee80211_vif *vif, | |
1502 | struct ieee80211_sta *sta) | |
1503 | { | |
1504 | hwsim_check_magic(vif); | |
1505 | hwsim_clear_sta_magic(sta); | |
1506 | ||
1507 | return 0; | |
1508 | } | |
1509 | ||
8aa21e6f JB |
1510 | static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw, |
1511 | struct ieee80211_vif *vif, | |
17741cdc JB |
1512 | enum sta_notify_cmd cmd, |
1513 | struct ieee80211_sta *sta) | |
8aa21e6f JB |
1514 | { |
1515 | hwsim_check_magic(vif); | |
1d669cbf | 1516 | |
81c06523 | 1517 | switch (cmd) { |
89fad578 CL |
1518 | case STA_NOTIFY_SLEEP: |
1519 | case STA_NOTIFY_AWAKE: | |
1520 | /* TODO: make good use of these flags */ | |
1521 | break; | |
1d669cbf JB |
1522 | default: |
1523 | WARN(1, "Invalid sta notify: %d\n", cmd); | |
1524 | break; | |
81c06523 JB |
1525 | } |
1526 | } | |
1527 | ||
1528 | static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw, | |
1529 | struct ieee80211_sta *sta, | |
1530 | bool set) | |
1531 | { | |
1532 | hwsim_check_sta_magic(sta); | |
1533 | return 0; | |
8aa21e6f | 1534 | } |
acc1e7a3 | 1535 | |
1e898ff8 | 1536 | static int mac80211_hwsim_conf_tx( |
8a3a3c85 EP |
1537 | struct ieee80211_hw *hw, |
1538 | struct ieee80211_vif *vif, u16 queue, | |
1e898ff8 JM |
1539 | const struct ieee80211_tx_queue_params *params) |
1540 | { | |
c96c31e4 JP |
1541 | wiphy_debug(hw->wiphy, |
1542 | "%s (queue=%d txop=%d cw_min=%d cw_max=%d aifs=%d)\n", | |
1543 | __func__, queue, | |
1544 | params->txop, params->cw_min, | |
1545 | params->cw_max, params->aifs); | |
1e898ff8 JM |
1546 | return 0; |
1547 | } | |
1548 | ||
1289723e HS |
1549 | static int mac80211_hwsim_get_survey( |
1550 | struct ieee80211_hw *hw, int idx, | |
1551 | struct survey_info *survey) | |
1552 | { | |
1553 | struct ieee80211_conf *conf = &hw->conf; | |
1554 | ||
c96c31e4 | 1555 | wiphy_debug(hw->wiphy, "%s (idx=%d)\n", __func__, idx); |
1289723e HS |
1556 | |
1557 | if (idx != 0) | |
1558 | return -ENOENT; | |
1559 | ||
1560 | /* Current channel */ | |
675a0b04 | 1561 | survey->channel = conf->chandef.chan; |
1289723e HS |
1562 | |
1563 | /* | |
1564 | * Magically conjured noise level --- this is only ok for simulated hardware. | |
1565 | * | |
1566 | * A real driver which cannot determine the real channel noise MUST NOT | |
1567 | * report any noise, especially not a magically conjured one :-) | |
1568 | */ | |
1569 | survey->filled = SURVEY_INFO_NOISE_DBM; | |
1570 | survey->noise = -92; | |
1571 | ||
1572 | return 0; | |
1573 | } | |
1574 | ||
aff89a9b JB |
1575 | #ifdef CONFIG_NL80211_TESTMODE |
1576 | /* | |
1577 | * This section contains example code for using netlink | |
1578 | * attributes with the testmode command in nl80211. | |
1579 | */ | |
1580 | ||
1581 | /* These enums need to be kept in sync with userspace */ | |
1582 | enum hwsim_testmode_attr { | |
1583 | __HWSIM_TM_ATTR_INVALID = 0, | |
1584 | HWSIM_TM_ATTR_CMD = 1, | |
1585 | HWSIM_TM_ATTR_PS = 2, | |
1586 | ||
1587 | /* keep last */ | |
1588 | __HWSIM_TM_ATTR_AFTER_LAST, | |
1589 | HWSIM_TM_ATTR_MAX = __HWSIM_TM_ATTR_AFTER_LAST - 1 | |
1590 | }; | |
1591 | ||
1592 | enum hwsim_testmode_cmd { | |
1593 | HWSIM_TM_CMD_SET_PS = 0, | |
1594 | HWSIM_TM_CMD_GET_PS = 1, | |
4d6d0ae2 JB |
1595 | HWSIM_TM_CMD_STOP_QUEUES = 2, |
1596 | HWSIM_TM_CMD_WAKE_QUEUES = 3, | |
aff89a9b JB |
1597 | }; |
1598 | ||
1599 | static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = { | |
1600 | [HWSIM_TM_ATTR_CMD] = { .type = NLA_U32 }, | |
1601 | [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 }, | |
1602 | }; | |
1603 | ||
5bc38193 | 1604 | static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, |
52981cd7 | 1605 | struct ieee80211_vif *vif, |
5bc38193 | 1606 | void *data, int len) |
aff89a9b JB |
1607 | { |
1608 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1609 | struct nlattr *tb[HWSIM_TM_ATTR_MAX + 1]; | |
1610 | struct sk_buff *skb; | |
1611 | int err, ps; | |
1612 | ||
1613 | err = nla_parse(tb, HWSIM_TM_ATTR_MAX, data, len, | |
1614 | hwsim_testmode_policy); | |
1615 | if (err) | |
1616 | return err; | |
1617 | ||
1618 | if (!tb[HWSIM_TM_ATTR_CMD]) | |
1619 | return -EINVAL; | |
1620 | ||
1621 | switch (nla_get_u32(tb[HWSIM_TM_ATTR_CMD])) { | |
1622 | case HWSIM_TM_CMD_SET_PS: | |
1623 | if (!tb[HWSIM_TM_ATTR_PS]) | |
1624 | return -EINVAL; | |
1625 | ps = nla_get_u32(tb[HWSIM_TM_ATTR_PS]); | |
1626 | return hwsim_fops_ps_write(hwsim, ps); | |
1627 | case HWSIM_TM_CMD_GET_PS: | |
1628 | skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, | |
1629 | nla_total_size(sizeof(u32))); | |
1630 | if (!skb) | |
1631 | return -ENOMEM; | |
633c9389 DM |
1632 | if (nla_put_u32(skb, HWSIM_TM_ATTR_PS, hwsim->ps)) |
1633 | goto nla_put_failure; | |
aff89a9b | 1634 | return cfg80211_testmode_reply(skb); |
4d6d0ae2 JB |
1635 | case HWSIM_TM_CMD_STOP_QUEUES: |
1636 | ieee80211_stop_queues(hw); | |
1637 | return 0; | |
1638 | case HWSIM_TM_CMD_WAKE_QUEUES: | |
1639 | ieee80211_wake_queues(hw); | |
1640 | return 0; | |
aff89a9b JB |
1641 | default: |
1642 | return -EOPNOTSUPP; | |
1643 | } | |
1644 | ||
1645 | nla_put_failure: | |
1646 | kfree_skb(skb); | |
1647 | return -ENOBUFS; | |
1648 | } | |
1649 | #endif | |
1650 | ||
8b73d13a JB |
1651 | static int mac80211_hwsim_ampdu_action(struct ieee80211_hw *hw, |
1652 | struct ieee80211_vif *vif, | |
1653 | enum ieee80211_ampdu_mlme_action action, | |
0b01f030 JB |
1654 | struct ieee80211_sta *sta, u16 tid, u16 *ssn, |
1655 | u8 buf_size) | |
8b73d13a JB |
1656 | { |
1657 | switch (action) { | |
1658 | case IEEE80211_AMPDU_TX_START: | |
1659 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
1660 | break; | |
18b559d5 JB |
1661 | case IEEE80211_AMPDU_TX_STOP_CONT: |
1662 | case IEEE80211_AMPDU_TX_STOP_FLUSH: | |
1663 | case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT: | |
8b73d13a JB |
1664 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
1665 | break; | |
1666 | case IEEE80211_AMPDU_TX_OPERATIONAL: | |
1667 | break; | |
1668 | case IEEE80211_AMPDU_RX_START: | |
1669 | case IEEE80211_AMPDU_RX_STOP: | |
1670 | break; | |
1671 | default: | |
1672 | return -EOPNOTSUPP; | |
1673 | } | |
1674 | ||
1675 | return 0; | |
1676 | } | |
1677 | ||
39ecc01d | 1678 | static void mac80211_hwsim_flush(struct ieee80211_hw *hw, u32 queues, bool drop) |
a80f7c0b | 1679 | { |
7882513b | 1680 | /* Not implemented, queues only on kernel side */ |
a80f7c0b JB |
1681 | } |
1682 | ||
e8261171 | 1683 | static void hw_scan_work(struct work_struct *work) |
69068036 | 1684 | { |
e8261171 JB |
1685 | struct mac80211_hwsim_data *hwsim = |
1686 | container_of(work, struct mac80211_hwsim_data, hw_scan.work); | |
1687 | struct cfg80211_scan_request *req = hwsim->hw_scan_request; | |
1688 | int dwell, i; | |
69068036 | 1689 | |
e8261171 JB |
1690 | mutex_lock(&hwsim->mutex); |
1691 | if (hwsim->scan_chan_idx >= req->n_channels) { | |
1692 | wiphy_debug(hwsim->hw->wiphy, "hw scan complete\n"); | |
1693 | ieee80211_scan_completed(hwsim->hw, false); | |
1694 | hwsim->hw_scan_request = NULL; | |
1695 | hwsim->hw_scan_vif = NULL; | |
1696 | hwsim->tmp_chan = NULL; | |
1697 | mutex_unlock(&hwsim->mutex); | |
1698 | return; | |
1699 | } | |
1700 | ||
1701 | wiphy_debug(hwsim->hw->wiphy, "hw scan %d MHz\n", | |
1702 | req->channels[hwsim->scan_chan_idx]->center_freq); | |
1703 | ||
1704 | hwsim->tmp_chan = req->channels[hwsim->scan_chan_idx]; | |
8fe02e16 | 1705 | if (hwsim->tmp_chan->flags & IEEE80211_CHAN_NO_IR || |
e8261171 JB |
1706 | !req->n_ssids) { |
1707 | dwell = 120; | |
1708 | } else { | |
1709 | dwell = 30; | |
1710 | /* send probes */ | |
1711 | for (i = 0; i < req->n_ssids; i++) { | |
1712 | struct sk_buff *probe; | |
1713 | ||
1714 | probe = ieee80211_probereq_get(hwsim->hw, | |
1715 | hwsim->hw_scan_vif, | |
1716 | req->ssids[i].ssid, | |
1717 | req->ssids[i].ssid_len, | |
b9a9ada1 | 1718 | req->ie_len); |
e8261171 JB |
1719 | if (!probe) |
1720 | continue; | |
b9a9ada1 JB |
1721 | |
1722 | if (req->ie_len) | |
1723 | memcpy(skb_put(probe, req->ie_len), req->ie, | |
1724 | req->ie_len); | |
1725 | ||
e8261171 JB |
1726 | local_bh_disable(); |
1727 | mac80211_hwsim_tx_frame(hwsim->hw, probe, | |
1728 | hwsim->tmp_chan); | |
1729 | local_bh_enable(); | |
1730 | } | |
1731 | } | |
1732 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, | |
1733 | msecs_to_jiffies(dwell)); | |
1734 | hwsim->scan_chan_idx++; | |
1735 | mutex_unlock(&hwsim->mutex); | |
69068036 JB |
1736 | } |
1737 | ||
1738 | static int mac80211_hwsim_hw_scan(struct ieee80211_hw *hw, | |
a060bbfe | 1739 | struct ieee80211_vif *vif, |
69068036 JB |
1740 | struct cfg80211_scan_request *req) |
1741 | { | |
e8261171 | 1742 | struct mac80211_hwsim_data *hwsim = hw->priv; |
69068036 | 1743 | |
e8261171 JB |
1744 | mutex_lock(&hwsim->mutex); |
1745 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { | |
1746 | mutex_unlock(&hwsim->mutex); | |
1747 | return -EBUSY; | |
1748 | } | |
1749 | hwsim->hw_scan_request = req; | |
1750 | hwsim->hw_scan_vif = vif; | |
1751 | hwsim->scan_chan_idx = 0; | |
1752 | mutex_unlock(&hwsim->mutex); | |
69068036 | 1753 | |
e8261171 | 1754 | wiphy_debug(hw->wiphy, "hwsim hw_scan request\n"); |
69068036 | 1755 | |
e8261171 | 1756 | ieee80211_queue_delayed_work(hwsim->hw, &hwsim->hw_scan, 0); |
69068036 JB |
1757 | |
1758 | return 0; | |
1759 | } | |
1760 | ||
e8261171 JB |
1761 | static void mac80211_hwsim_cancel_hw_scan(struct ieee80211_hw *hw, |
1762 | struct ieee80211_vif *vif) | |
1763 | { | |
1764 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1765 | ||
1766 | wiphy_debug(hw->wiphy, "hwsim cancel_hw_scan\n"); | |
1767 | ||
1768 | cancel_delayed_work_sync(&hwsim->hw_scan); | |
1769 | ||
1770 | mutex_lock(&hwsim->mutex); | |
1771 | ieee80211_scan_completed(hwsim->hw, true); | |
1772 | hwsim->tmp_chan = NULL; | |
1773 | hwsim->hw_scan_request = NULL; | |
1774 | hwsim->hw_scan_vif = NULL; | |
1775 | mutex_unlock(&hwsim->mutex); | |
1776 | } | |
1777 | ||
f74cb0f7 LR |
1778 | static void mac80211_hwsim_sw_scan(struct ieee80211_hw *hw) |
1779 | { | |
1780 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1781 | ||
1782 | mutex_lock(&hwsim->mutex); | |
1783 | ||
1784 | if (hwsim->scanning) { | |
1785 | printk(KERN_DEBUG "two hwsim sw_scans detected!\n"); | |
1786 | goto out; | |
1787 | } | |
1788 | ||
1789 | printk(KERN_DEBUG "hwsim sw_scan request, prepping stuff\n"); | |
1790 | hwsim->scanning = true; | |
1791 | ||
1792 | out: | |
1793 | mutex_unlock(&hwsim->mutex); | |
1794 | } | |
1795 | ||
1796 | static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw) | |
1797 | { | |
1798 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1799 | ||
1800 | mutex_lock(&hwsim->mutex); | |
1801 | ||
1802 | printk(KERN_DEBUG "hwsim sw_scan_complete\n"); | |
23ff98fc | 1803 | hwsim->scanning = false; |
f74cb0f7 LR |
1804 | |
1805 | mutex_unlock(&hwsim->mutex); | |
1806 | } | |
1807 | ||
e8261171 JB |
1808 | static void hw_roc_done(struct work_struct *work) |
1809 | { | |
1810 | struct mac80211_hwsim_data *hwsim = | |
1811 | container_of(work, struct mac80211_hwsim_data, roc_done.work); | |
1812 | ||
1813 | mutex_lock(&hwsim->mutex); | |
1814 | ieee80211_remain_on_channel_expired(hwsim->hw); | |
1815 | hwsim->tmp_chan = NULL; | |
1816 | mutex_unlock(&hwsim->mutex); | |
1817 | ||
1818 | wiphy_debug(hwsim->hw->wiphy, "hwsim ROC expired\n"); | |
1819 | } | |
1820 | ||
1821 | static int mac80211_hwsim_roc(struct ieee80211_hw *hw, | |
49884568 | 1822 | struct ieee80211_vif *vif, |
e8261171 | 1823 | struct ieee80211_channel *chan, |
d339d5ca IP |
1824 | int duration, |
1825 | enum ieee80211_roc_type type) | |
e8261171 JB |
1826 | { |
1827 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1828 | ||
1829 | mutex_lock(&hwsim->mutex); | |
1830 | if (WARN_ON(hwsim->tmp_chan || hwsim->hw_scan_request)) { | |
1831 | mutex_unlock(&hwsim->mutex); | |
1832 | return -EBUSY; | |
1833 | } | |
1834 | ||
1835 | hwsim->tmp_chan = chan; | |
1836 | mutex_unlock(&hwsim->mutex); | |
1837 | ||
1838 | wiphy_debug(hw->wiphy, "hwsim ROC (%d MHz, %d ms)\n", | |
1839 | chan->center_freq, duration); | |
1840 | ||
1841 | ieee80211_ready_on_channel(hw); | |
1842 | ||
1843 | ieee80211_queue_delayed_work(hw, &hwsim->roc_done, | |
1844 | msecs_to_jiffies(duration)); | |
1845 | return 0; | |
1846 | } | |
1847 | ||
1848 | static int mac80211_hwsim_croc(struct ieee80211_hw *hw) | |
1849 | { | |
1850 | struct mac80211_hwsim_data *hwsim = hw->priv; | |
1851 | ||
1852 | cancel_delayed_work_sync(&hwsim->roc_done); | |
1853 | ||
1854 | mutex_lock(&hwsim->mutex); | |
1855 | hwsim->tmp_chan = NULL; | |
1856 | mutex_unlock(&hwsim->mutex); | |
1857 | ||
1858 | wiphy_debug(hw->wiphy, "hwsim ROC canceled\n"); | |
1859 | ||
1860 | return 0; | |
1861 | } | |
1862 | ||
1863 | static int mac80211_hwsim_add_chanctx(struct ieee80211_hw *hw, | |
1864 | struct ieee80211_chanctx_conf *ctx) | |
1865 | { | |
1866 | hwsim_set_chanctx_magic(ctx); | |
4bf88530 JB |
1867 | wiphy_debug(hw->wiphy, |
1868 | "add channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
1869 | ctx->def.chan->center_freq, ctx->def.width, | |
1870 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
1871 | return 0; |
1872 | } | |
1873 | ||
1874 | static void mac80211_hwsim_remove_chanctx(struct ieee80211_hw *hw, | |
1875 | struct ieee80211_chanctx_conf *ctx) | |
1876 | { | |
4bf88530 JB |
1877 | wiphy_debug(hw->wiphy, |
1878 | "remove channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
1879 | ctx->def.chan->center_freq, ctx->def.width, | |
1880 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
1881 | hwsim_check_chanctx_magic(ctx); |
1882 | hwsim_clear_chanctx_magic(ctx); | |
1883 | } | |
1884 | ||
1885 | static void mac80211_hwsim_change_chanctx(struct ieee80211_hw *hw, | |
1886 | struct ieee80211_chanctx_conf *ctx, | |
1887 | u32 changed) | |
1888 | { | |
1889 | hwsim_check_chanctx_magic(ctx); | |
4bf88530 JB |
1890 | wiphy_debug(hw->wiphy, |
1891 | "change channel context control: %d MHz/width: %d/cfreqs:%d/%d MHz\n", | |
1892 | ctx->def.chan->center_freq, ctx->def.width, | |
1893 | ctx->def.center_freq1, ctx->def.center_freq2); | |
e8261171 JB |
1894 | } |
1895 | ||
1896 | static int mac80211_hwsim_assign_vif_chanctx(struct ieee80211_hw *hw, | |
1897 | struct ieee80211_vif *vif, | |
1898 | struct ieee80211_chanctx_conf *ctx) | |
1899 | { | |
1900 | hwsim_check_magic(vif); | |
1901 | hwsim_check_chanctx_magic(ctx); | |
1902 | ||
1903 | return 0; | |
1904 | } | |
1905 | ||
1906 | static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw, | |
1907 | struct ieee80211_vif *vif, | |
1908 | struct ieee80211_chanctx_conf *ctx) | |
1909 | { | |
1910 | hwsim_check_magic(vif); | |
1911 | hwsim_check_chanctx_magic(ctx); | |
1912 | } | |
1913 | ||
38ed5048 | 1914 | static const struct ieee80211_ops mac80211_hwsim_ops = { |
acc1e7a3 JM |
1915 | .tx = mac80211_hwsim_tx, |
1916 | .start = mac80211_hwsim_start, | |
1917 | .stop = mac80211_hwsim_stop, | |
1918 | .add_interface = mac80211_hwsim_add_interface, | |
c35d0270 | 1919 | .change_interface = mac80211_hwsim_change_interface, |
acc1e7a3 JM |
1920 | .remove_interface = mac80211_hwsim_remove_interface, |
1921 | .config = mac80211_hwsim_config, | |
1922 | .configure_filter = mac80211_hwsim_configure_filter, | |
8aa21e6f | 1923 | .bss_info_changed = mac80211_hwsim_bss_info_changed, |
1d669cbf JB |
1924 | .sta_add = mac80211_hwsim_sta_add, |
1925 | .sta_remove = mac80211_hwsim_sta_remove, | |
8aa21e6f | 1926 | .sta_notify = mac80211_hwsim_sta_notify, |
81c06523 | 1927 | .set_tim = mac80211_hwsim_set_tim, |
1e898ff8 | 1928 | .conf_tx = mac80211_hwsim_conf_tx, |
1289723e | 1929 | .get_survey = mac80211_hwsim_get_survey, |
aff89a9b | 1930 | CFG80211_TESTMODE_CMD(mac80211_hwsim_testmode_cmd) |
8b73d13a | 1931 | .ampdu_action = mac80211_hwsim_ampdu_action, |
f74cb0f7 LR |
1932 | .sw_scan_start = mac80211_hwsim_sw_scan, |
1933 | .sw_scan_complete = mac80211_hwsim_sw_scan_complete, | |
a80f7c0b | 1934 | .flush = mac80211_hwsim_flush, |
12ce8ba3 JC |
1935 | .get_tsf = mac80211_hwsim_get_tsf, |
1936 | .set_tsf = mac80211_hwsim_set_tsf, | |
acc1e7a3 JM |
1937 | }; |
1938 | ||
38ed5048 | 1939 | static struct ieee80211_ops mac80211_hwsim_mchan_ops; |
acc1e7a3 | 1940 | |
26b0e411 JB |
1941 | static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2, |
1942 | const struct ieee80211_regdomain *regd, | |
8c66a3d9 | 1943 | bool reg_strict, bool p2p_device) |
acc1e7a3 | 1944 | { |
de0421d5 JB |
1945 | int err; |
1946 | u8 addr[ETH_ALEN]; | |
e4afb603 | 1947 | struct mac80211_hwsim_data *data; |
de0421d5 JB |
1948 | struct ieee80211_hw *hw; |
1949 | enum ieee80211_band band; | |
1950 | const struct ieee80211_ops *ops = &mac80211_hwsim_ops; | |
1951 | int idx; | |
0e057d73 JB |
1952 | |
1953 | spin_lock_bh(&hwsim_radio_lock); | |
de0421d5 | 1954 | idx = hwsim_radio_idx++; |
0e057d73 JB |
1955 | spin_unlock_bh(&hwsim_radio_lock); |
1956 | ||
de0421d5 JB |
1957 | if (channels > 1) |
1958 | ops = &mac80211_hwsim_mchan_ops; | |
1959 | hw = ieee80211_alloc_hw(sizeof(*data), ops); | |
1960 | if (!hw) { | |
1961 | printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw failed\n"); | |
1962 | err = -ENOMEM; | |
1963 | goto failed; | |
1964 | } | |
1965 | data = hw->priv; | |
1966 | data->hw = hw; | |
acc1e7a3 | 1967 | |
de0421d5 JB |
1968 | data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx); |
1969 | if (IS_ERR(data->dev)) { | |
1970 | printk(KERN_DEBUG | |
1971 | "mac80211_hwsim: device_create failed (%ld)\n", | |
1972 | PTR_ERR(data->dev)); | |
1973 | err = -ENOMEM; | |
1974 | goto failed_drvdata; | |
1975 | } | |
1976 | data->dev->driver = &mac80211_hwsim_driver.driver; | |
1977 | err = device_bind_driver(data->dev); | |
1978 | if (err != 0) { | |
1979 | printk(KERN_DEBUG "mac80211_hwsim: device_bind_driver failed (%d)\n", | |
1980 | err); | |
1981 | goto failed_hw; | |
acc1e7a3 | 1982 | } |
acc1e7a3 | 1983 | |
de0421d5 | 1984 | skb_queue_head_init(&data->pending); |
acc1e7a3 | 1985 | |
de0421d5 JB |
1986 | SET_IEEE80211_DEV(hw, data->dev); |
1987 | memset(addr, 0, ETH_ALEN); | |
1988 | addr[0] = 0x02; | |
1989 | addr[3] = idx >> 8; | |
1990 | addr[4] = idx; | |
1991 | memcpy(data->addresses[0].addr, addr, ETH_ALEN); | |
1992 | memcpy(data->addresses[1].addr, addr, ETH_ALEN); | |
1993 | data->addresses[1].addr[0] |= 0x40; | |
1994 | hw->wiphy->n_addresses = 2; | |
1995 | hw->wiphy->addresses = data->addresses; | |
fc6971d4 | 1996 | |
de0421d5 | 1997 | data->channels = channels; |
bc791098 | 1998 | data->idx = idx; |
fc6971d4 | 1999 | |
de0421d5 JB |
2000 | if (data->channels > 1) { |
2001 | hw->wiphy->max_scan_ssids = 255; | |
2002 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; | |
2003 | hw->wiphy->max_remain_on_channel_duration = 1000; | |
2004 | /* For channels > 1 DFS is not allowed */ | |
2005 | hw->wiphy->n_iface_combinations = 1; | |
2006 | hw->wiphy->iface_combinations = &data->if_combination; | |
8c66a3d9 JB |
2007 | if (p2p_device) |
2008 | data->if_combination = hwsim_if_comb_p2p_dev[0]; | |
2009 | else | |
2010 | data->if_combination = hwsim_if_comb[0]; | |
b59ec8dd | 2011 | data->if_combination.num_different_channels = data->channels; |
8c66a3d9 JB |
2012 | } else if (p2p_device) { |
2013 | hw->wiphy->iface_combinations = hwsim_if_comb_p2p_dev; | |
2014 | hw->wiphy->n_iface_combinations = | |
2015 | ARRAY_SIZE(hwsim_if_comb_p2p_dev); | |
de0421d5 JB |
2016 | } else { |
2017 | hw->wiphy->iface_combinations = hwsim_if_comb; | |
2018 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(hwsim_if_comb); | |
2019 | } | |
acc1e7a3 | 2020 | |
de0421d5 JB |
2021 | INIT_DELAYED_WORK(&data->roc_done, hw_roc_done); |
2022 | INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work); | |
7882513b | 2023 | |
de0421d5 JB |
2024 | hw->queues = 5; |
2025 | hw->offchannel_tx_hw_queue = 4; | |
2026 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | |
2027 | BIT(NL80211_IFTYPE_AP) | | |
2028 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | |
2029 | BIT(NL80211_IFTYPE_P2P_GO) | | |
2030 | BIT(NL80211_IFTYPE_ADHOC) | | |
8c66a3d9 JB |
2031 | BIT(NL80211_IFTYPE_MESH_POINT); |
2032 | ||
2033 | if (p2p_device) | |
2034 | hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_P2P_DEVICE); | |
fc6971d4 | 2035 | |
de0421d5 JB |
2036 | hw->flags = IEEE80211_HW_MFP_CAPABLE | |
2037 | IEEE80211_HW_SIGNAL_DBM | | |
2038 | IEEE80211_HW_SUPPORTS_STATIC_SMPS | | |
2039 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | | |
2040 | IEEE80211_HW_AMPDU_AGGREGATION | | |
2041 | IEEE80211_HW_WANT_MONITOR_VIF | | |
2042 | IEEE80211_HW_QUEUE_CONTROL | | |
0037db63 AO |
2043 | IEEE80211_HW_SUPPORTS_HT_CCK_RATES | |
2044 | IEEE80211_HW_CHANCTX_STA_CSA; | |
de0421d5 JB |
2045 | if (rctbl) |
2046 | hw->flags |= IEEE80211_HW_SUPPORTS_RC_TABLE; | |
fc6971d4 | 2047 | |
de0421d5 JB |
2048 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | |
2049 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | |
0037db63 AO |
2050 | WIPHY_FLAG_AP_UAPSD | |
2051 | WIPHY_FLAG_HAS_CHANNEL_SWITCH; | |
de0421d5 | 2052 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR; |
fc6971d4 | 2053 | |
de0421d5 JB |
2054 | /* ask mac80211 to reserve space for magic */ |
2055 | hw->vif_data_size = sizeof(struct hwsim_vif_priv); | |
2056 | hw->sta_data_size = sizeof(struct hwsim_sta_priv); | |
2057 | hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv); | |
fc6971d4 | 2058 | |
de0421d5 JB |
2059 | memcpy(data->channels_2ghz, hwsim_channels_2ghz, |
2060 | sizeof(hwsim_channels_2ghz)); | |
2061 | memcpy(data->channels_5ghz, hwsim_channels_5ghz, | |
2062 | sizeof(hwsim_channels_5ghz)); | |
2063 | memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates)); | |
7882513b | 2064 | |
de0421d5 JB |
2065 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { |
2066 | struct ieee80211_supported_band *sband = &data->bands[band]; | |
2067 | switch (band) { | |
2068 | case IEEE80211_BAND_2GHZ: | |
2069 | sband->channels = data->channels_2ghz; | |
2070 | sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz); | |
2071 | sband->bitrates = data->rates; | |
2072 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates); | |
2073 | break; | |
2074 | case IEEE80211_BAND_5GHZ: | |
2075 | sband->channels = data->channels_5ghz; | |
2076 | sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz); | |
2077 | sband->bitrates = data->rates + 4; | |
2078 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; | |
2079 | break; | |
2080 | default: | |
2081 | continue; | |
2082 | } | |
acc1e7a3 | 2083 | |
de0421d5 JB |
2084 | sband->ht_cap.ht_supported = true; |
2085 | sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | | |
2086 | IEEE80211_HT_CAP_GRN_FLD | | |
2087 | IEEE80211_HT_CAP_SGI_40 | | |
2088 | IEEE80211_HT_CAP_DSSSCCK40; | |
2089 | sband->ht_cap.ampdu_factor = 0x3; | |
2090 | sband->ht_cap.ampdu_density = 0x6; | |
2091 | memset(&sband->ht_cap.mcs, 0, | |
2092 | sizeof(sband->ht_cap.mcs)); | |
2093 | sband->ht_cap.mcs.rx_mask[0] = 0xff; | |
2094 | sband->ht_cap.mcs.rx_mask[1] = 0xff; | |
2095 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | |
fc6971d4 | 2096 | |
de0421d5 | 2097 | hw->wiphy->bands[band] = sband; |
fc6971d4 | 2098 | |
de0421d5 JB |
2099 | sband->vht_cap.vht_supported = true; |
2100 | sband->vht_cap.cap = | |
2101 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | |
2102 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ | | |
2103 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | | |
2104 | IEEE80211_VHT_CAP_RXLDPC | | |
2105 | IEEE80211_VHT_CAP_SHORT_GI_80 | | |
2106 | IEEE80211_VHT_CAP_SHORT_GI_160 | | |
2107 | IEEE80211_VHT_CAP_TXSTBC | | |
2108 | IEEE80211_VHT_CAP_RXSTBC_1 | | |
2109 | IEEE80211_VHT_CAP_RXSTBC_2 | | |
2110 | IEEE80211_VHT_CAP_RXSTBC_3 | | |
2111 | IEEE80211_VHT_CAP_RXSTBC_4 | | |
2112 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | |
2113 | sband->vht_cap.vht_mcs.rx_mcs_map = | |
2114 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_8 << 0 | | |
2115 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 2 | | |
2116 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 | | |
2117 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 6 | | |
2118 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 8 | | |
2119 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 | | |
2120 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 | | |
2121 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 14); | |
2122 | sband->vht_cap.vht_mcs.tx_mcs_map = | |
2123 | sband->vht_cap.vht_mcs.rx_mcs_map; | |
2124 | } | |
acc1e7a3 | 2125 | |
de0421d5 JB |
2126 | /* By default all radios belong to the first group */ |
2127 | data->group = 1; | |
2128 | mutex_init(&data->mutex); | |
fc6971d4 | 2129 | |
de0421d5 JB |
2130 | /* Enable frame retransmissions for lossy channels */ |
2131 | hw->max_rates = 4; | |
2132 | hw->max_rate_tries = 11; | |
fc6971d4 | 2133 | |
26b0e411 JB |
2134 | if (reg_strict) |
2135 | hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; | |
2136 | if (regd) { | |
2137 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; | |
2138 | wiphy_apply_custom_regulatory(hw->wiphy, regd); | |
2139 | /* give the regulatory workqueue a chance to run */ | |
2140 | schedule_timeout_interruptible(1); | |
2141 | } | |
fc6971d4 | 2142 | |
de0421d5 JB |
2143 | err = ieee80211_register_hw(hw); |
2144 | if (err < 0) { | |
2145 | printk(KERN_DEBUG "mac80211_hwsim: ieee80211_register_hw failed (%d)\n", | |
2146 | err); | |
2147 | goto failed_hw; | |
2148 | } | |
fc6971d4 | 2149 | |
de0421d5 | 2150 | wiphy_debug(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr); |
fc6971d4 | 2151 | |
26b0e411 JB |
2152 | if (reg_alpha2) |
2153 | regulatory_hint(hw->wiphy, reg_alpha2); | |
7882513b | 2154 | |
de0421d5 JB |
2155 | data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir); |
2156 | debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps); | |
2157 | debugfs_create_file("group", 0666, data->debugfs, data, | |
2158 | &hwsim_fops_group); | |
2159 | if (data->channels == 1) | |
2160 | debugfs_create_file("dfs_simulate_radar", 0222, | |
2161 | data->debugfs, | |
2162 | data, &hwsim_simulate_radar); | |
fc6971d4 | 2163 | |
de0421d5 JB |
2164 | tasklet_hrtimer_init(&data->beacon_timer, |
2165 | mac80211_hwsim_beacon, | |
2166 | CLOCK_MONOTONIC_RAW, HRTIMER_MODE_ABS); | |
fc6971d4 | 2167 | |
de0421d5 JB |
2168 | spin_lock_bh(&hwsim_radio_lock); |
2169 | list_add_tail(&data->list, &hwsim_radios); | |
2170 | spin_unlock_bh(&hwsim_radio_lock); | |
fc6971d4 | 2171 | |
bc791098 | 2172 | return idx; |
fc6971d4 | 2173 | |
de0421d5 JB |
2174 | failed_hw: |
2175 | device_unregister(data->dev); | |
2176 | failed_drvdata: | |
2177 | ieee80211_free_hw(hw); | |
2178 | failed: | |
2179 | return err; | |
fc6971d4 JM |
2180 | } |
2181 | ||
de0421d5 | 2182 | static void mac80211_hwsim_destroy_radio(struct mac80211_hwsim_data *data) |
fc6971d4 | 2183 | { |
de0421d5 JB |
2184 | debugfs_remove_recursive(data->debugfs); |
2185 | ieee80211_unregister_hw(data->hw); | |
2186 | device_release_driver(data->dev); | |
2187 | device_unregister(data->dev); | |
2188 | ieee80211_free_hw(data->hw); | |
fc6971d4 JM |
2189 | } |
2190 | ||
de0421d5 | 2191 | static void mac80211_hwsim_free(void) |
fc6971d4 | 2192 | { |
de0421d5 | 2193 | struct mac80211_hwsim_data *data; |
fc6971d4 | 2194 | |
de0421d5 JB |
2195 | spin_lock_bh(&hwsim_radio_lock); |
2196 | while ((data = list_first_entry_or_null(&hwsim_radios, | |
2197 | struct mac80211_hwsim_data, | |
2198 | list))) { | |
2199 | list_del(&data->list); | |
2200 | spin_unlock_bh(&hwsim_radio_lock); | |
2201 | mac80211_hwsim_destroy_radio(data); | |
2202 | spin_lock_bh(&hwsim_radio_lock); | |
fc6971d4 | 2203 | } |
de0421d5 JB |
2204 | spin_unlock_bh(&hwsim_radio_lock); |
2205 | class_destroy(hwsim_class); | |
bba05e3d JD |
2206 | } |
2207 | ||
de0421d5 JB |
2208 | static const struct net_device_ops hwsim_netdev_ops = { |
2209 | .ndo_start_xmit = hwsim_mon_xmit, | |
2210 | .ndo_change_mtu = eth_change_mtu, | |
2211 | .ndo_set_mac_address = eth_mac_addr, | |
2212 | .ndo_validate_addr = eth_validate_addr, | |
2213 | }; | |
73606d00 | 2214 | |
de0421d5 | 2215 | static void hwsim_mon_setup(struct net_device *dev) |
73606d00 | 2216 | { |
de0421d5 JB |
2217 | dev->netdev_ops = &hwsim_netdev_ops; |
2218 | dev->destructor = free_netdev; | |
2219 | ether_setup(dev); | |
2220 | dev->tx_queue_len = 0; | |
2221 | dev->type = ARPHRD_IEEE80211_RADIOTAP; | |
2222 | memset(dev->dev_addr, 0, ETH_ALEN); | |
2223 | dev->dev_addr[0] = 0x12; | |
73606d00 DW |
2224 | } |
2225 | ||
9ddd12af | 2226 | static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr) |
7882513b JL |
2227 | { |
2228 | struct mac80211_hwsim_data *data; | |
2229 | bool _found = false; | |
2230 | ||
2231 | spin_lock_bh(&hwsim_radio_lock); | |
2232 | list_for_each_entry(data, &hwsim_radios, list) { | |
9ddd12af | 2233 | if (memcmp(data->addresses[1].addr, addr, ETH_ALEN) == 0) { |
7882513b JL |
2234 | _found = true; |
2235 | break; | |
2236 | } | |
2237 | } | |
2238 | spin_unlock_bh(&hwsim_radio_lock); | |
2239 | ||
2240 | if (!_found) | |
2241 | return NULL; | |
2242 | ||
2243 | return data; | |
2244 | } | |
2245 | ||
2246 | static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, | |
2247 | struct genl_info *info) | |
2248 | { | |
2249 | ||
2250 | struct ieee80211_hdr *hdr; | |
2251 | struct mac80211_hwsim_data *data2; | |
2252 | struct ieee80211_tx_info *txi; | |
2253 | struct hwsim_tx_rate *tx_attempts; | |
d0f718c1 | 2254 | unsigned long ret_skb_ptr; |
7882513b | 2255 | struct sk_buff *skb, *tmp; |
9ddd12af | 2256 | const u8 *src; |
7882513b | 2257 | unsigned int hwsim_flags; |
7882513b JL |
2258 | int i; |
2259 | bool found = false; | |
2260 | ||
85ca8fc7 JB |
2261 | if (info->snd_portid != wmediumd_portid) |
2262 | return -EINVAL; | |
2263 | ||
7882513b | 2264 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || |
9ddd12af JB |
2265 | !info->attrs[HWSIM_ATTR_FLAGS] || |
2266 | !info->attrs[HWSIM_ATTR_COOKIE] || | |
2267 | !info->attrs[HWSIM_ATTR_TX_INFO]) | |
7882513b JL |
2268 | goto out; |
2269 | ||
9ddd12af | 2270 | src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); |
7882513b | 2271 | hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); |
d0f718c1 | 2272 | ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); |
7882513b JL |
2273 | |
2274 | data2 = get_hwsim_data_ref_from_addr(src); | |
9ddd12af | 2275 | if (!data2) |
7882513b JL |
2276 | goto out; |
2277 | ||
2278 | /* look for the skb matching the cookie passed back from user */ | |
2279 | skb_queue_walk_safe(&data2->pending, skb, tmp) { | |
d0f718c1 | 2280 | if ((unsigned long)skb == ret_skb_ptr) { |
7882513b JL |
2281 | skb_unlink(skb, &data2->pending); |
2282 | found = true; | |
2283 | break; | |
2284 | } | |
2285 | } | |
2286 | ||
2287 | /* not found */ | |
2288 | if (!found) | |
2289 | goto out; | |
2290 | ||
2291 | /* Tx info received because the frame was broadcasted on user space, | |
2292 | so we get all the necessary info: tx attempts and skb control buff */ | |
2293 | ||
2294 | tx_attempts = (struct hwsim_tx_rate *)nla_data( | |
2295 | info->attrs[HWSIM_ATTR_TX_INFO]); | |
2296 | ||
2297 | /* now send back TX status */ | |
2298 | txi = IEEE80211_SKB_CB(skb); | |
2299 | ||
7882513b JL |
2300 | ieee80211_tx_info_clear_status(txi); |
2301 | ||
2302 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { | |
2303 | txi->status.rates[i].idx = tx_attempts[i].idx; | |
2304 | txi->status.rates[i].count = tx_attempts[i].count; | |
2305 | /*txi->status.rates[i].flags = 0;*/ | |
2306 | } | |
2307 | ||
2308 | txi->status.ack_signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); | |
2309 | ||
2310 | if (!(hwsim_flags & HWSIM_TX_CTL_NO_ACK) && | |
2311 | (hwsim_flags & HWSIM_TX_STAT_ACK)) { | |
2312 | if (skb->len >= 16) { | |
2313 | hdr = (struct ieee80211_hdr *) skb->data; | |
c0e30763 | 2314 | mac80211_hwsim_monitor_ack(data2->channel, |
e8261171 | 2315 | hdr->addr2); |
7882513b | 2316 | } |
06cf5c4c | 2317 | txi->flags |= IEEE80211_TX_STAT_ACK; |
7882513b JL |
2318 | } |
2319 | ieee80211_tx_status_irqsafe(data2->hw, skb); | |
2320 | return 0; | |
2321 | out: | |
2322 | return -EINVAL; | |
2323 | ||
2324 | } | |
2325 | ||
2326 | static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, | |
2327 | struct genl_info *info) | |
2328 | { | |
2329 | ||
e8261171 | 2330 | struct mac80211_hwsim_data *data2; |
7882513b | 2331 | struct ieee80211_rx_status rx_status; |
9ddd12af | 2332 | const u8 *dst; |
7882513b | 2333 | int frame_data_len; |
9ddd12af | 2334 | void *frame_data; |
7882513b JL |
2335 | struct sk_buff *skb = NULL; |
2336 | ||
85ca8fc7 JB |
2337 | if (info->snd_portid != wmediumd_portid) |
2338 | return -EINVAL; | |
2339 | ||
7882513b | 2340 | if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || |
e8261171 JB |
2341 | !info->attrs[HWSIM_ATTR_FRAME] || |
2342 | !info->attrs[HWSIM_ATTR_RX_RATE] || | |
2343 | !info->attrs[HWSIM_ATTR_SIGNAL]) | |
7882513b JL |
2344 | goto out; |
2345 | ||
9ddd12af | 2346 | dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]); |
7882513b | 2347 | frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); |
9ddd12af | 2348 | frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); |
7882513b JL |
2349 | |
2350 | /* Allocate new skb here */ | |
2351 | skb = alloc_skb(frame_data_len, GFP_KERNEL); | |
2352 | if (skb == NULL) | |
2353 | goto err; | |
2354 | ||
9ddd12af | 2355 | if (frame_data_len > IEEE80211_MAX_DATA_LEN) |
7882513b JL |
2356 | goto err; |
2357 | ||
9ddd12af JB |
2358 | /* Copy the data */ |
2359 | memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len); | |
7882513b | 2360 | |
9ddd12af JB |
2361 | data2 = get_hwsim_data_ref_from_addr(dst); |
2362 | if (!data2) | |
7882513b JL |
2363 | goto out; |
2364 | ||
2365 | /* check if radio is configured properly */ | |
2366 | ||
e8261171 | 2367 | if (data2->idle || !data2->started) |
7882513b JL |
2368 | goto out; |
2369 | ||
9ddd12af | 2370 | /* A frame is received from user space */ |
7882513b JL |
2371 | memset(&rx_status, 0, sizeof(rx_status)); |
2372 | rx_status.freq = data2->channel->center_freq; | |
2373 | rx_status.band = data2->channel->band; | |
2374 | rx_status.rate_idx = nla_get_u32(info->attrs[HWSIM_ATTR_RX_RATE]); | |
2375 | rx_status.signal = nla_get_u32(info->attrs[HWSIM_ATTR_SIGNAL]); | |
2376 | ||
2377 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status)); | |
2378 | ieee80211_rx_irqsafe(data2->hw, skb); | |
2379 | ||
2380 | return 0; | |
2381 | err: | |
c393862f | 2382 | printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); |
7882513b JL |
2383 | goto out; |
2384 | out: | |
2385 | dev_kfree_skb(skb); | |
2386 | return -EINVAL; | |
2387 | } | |
2388 | ||
2389 | static int hwsim_register_received_nl(struct sk_buff *skb_2, | |
2390 | struct genl_info *info) | |
2391 | { | |
c5ac0854 JB |
2392 | struct mac80211_hwsim_data *data; |
2393 | int chans = 1; | |
2394 | ||
2395 | spin_lock_bh(&hwsim_radio_lock); | |
2396 | list_for_each_entry(data, &hwsim_radios, list) | |
2397 | chans = max(chans, data->channels); | |
2398 | spin_unlock_bh(&hwsim_radio_lock); | |
2399 | ||
2400 | /* In the future we should revise the userspace API and allow it | |
2401 | * to set a flag that it does support multi-channel, then we can | |
2402 | * let this pass conditionally on the flag. | |
2403 | * For current userspace, prohibit it since it won't work right. | |
2404 | */ | |
2405 | if (chans > 1) | |
2406 | return -EOPNOTSUPP; | |
2407 | ||
85ca8fc7 JB |
2408 | if (wmediumd_portid) |
2409 | return -EBUSY; | |
7882513b | 2410 | |
15e47304 | 2411 | wmediumd_portid = info->snd_portid; |
7882513b JL |
2412 | |
2413 | printk(KERN_DEBUG "mac80211_hwsim: received a REGISTER, " | |
15e47304 | 2414 | "switching to wmediumd mode with pid %d\n", info->snd_portid); |
7882513b JL |
2415 | |
2416 | return 0; | |
7882513b JL |
2417 | } |
2418 | ||
bc791098 JB |
2419 | static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info) |
2420 | { | |
2421 | unsigned int chans = channels; | |
26b0e411 JB |
2422 | const char *alpha2 = NULL; |
2423 | const struct ieee80211_regdomain *regd = NULL; | |
2424 | bool reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG]; | |
8c66a3d9 | 2425 | bool p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; |
bc791098 JB |
2426 | |
2427 | if (info->attrs[HWSIM_ATTR_CHANNELS]) | |
2428 | chans = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); | |
2429 | ||
26b0e411 JB |
2430 | if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]) |
2431 | alpha2 = nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]); | |
2432 | ||
2433 | if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) { | |
2434 | u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]); | |
2435 | ||
2436 | if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) | |
2437 | return -EINVAL; | |
2438 | regd = hwsim_world_regdom_custom[idx]; | |
2439 | } | |
2440 | ||
8c66a3d9 JB |
2441 | return mac80211_hwsim_create_radio(chans, alpha2, regd, reg_strict, |
2442 | p2p_device); | |
bc791098 JB |
2443 | } |
2444 | ||
2445 | static int hwsim_destroy_radio_nl(struct sk_buff *msg, struct genl_info *info) | |
2446 | { | |
2447 | struct mac80211_hwsim_data *data; | |
2448 | int idx; | |
2449 | ||
2450 | if (!info->attrs[HWSIM_ATTR_RADIO_ID]) | |
2451 | return -EINVAL; | |
2452 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); | |
2453 | ||
2454 | spin_lock_bh(&hwsim_radio_lock); | |
2455 | list_for_each_entry(data, &hwsim_radios, list) { | |
2456 | if (data->idx != idx) | |
2457 | continue; | |
2458 | list_del(&data->list); | |
2459 | spin_unlock_bh(&hwsim_radio_lock); | |
2460 | mac80211_hwsim_destroy_radio(data); | |
2461 | return 0; | |
2462 | } | |
2463 | spin_unlock_bh(&hwsim_radio_lock); | |
2464 | ||
2465 | return -ENODEV; | |
7882513b JL |
2466 | } |
2467 | ||
2468 | /* Generic Netlink operations array */ | |
4534de83 | 2469 | static const struct genl_ops hwsim_ops[] = { |
7882513b JL |
2470 | { |
2471 | .cmd = HWSIM_CMD_REGISTER, | |
2472 | .policy = hwsim_genl_policy, | |
2473 | .doit = hwsim_register_received_nl, | |
2474 | .flags = GENL_ADMIN_PERM, | |
2475 | }, | |
2476 | { | |
2477 | .cmd = HWSIM_CMD_FRAME, | |
2478 | .policy = hwsim_genl_policy, | |
2479 | .doit = hwsim_cloned_frame_received_nl, | |
2480 | }, | |
2481 | { | |
2482 | .cmd = HWSIM_CMD_TX_INFO_FRAME, | |
2483 | .policy = hwsim_genl_policy, | |
2484 | .doit = hwsim_tx_info_frame_received_nl, | |
2485 | }, | |
bc791098 JB |
2486 | { |
2487 | .cmd = HWSIM_CMD_CREATE_RADIO, | |
2488 | .policy = hwsim_genl_policy, | |
2489 | .doit = hwsim_create_radio_nl, | |
2490 | .flags = GENL_ADMIN_PERM, | |
2491 | }, | |
2492 | { | |
2493 | .cmd = HWSIM_CMD_DESTROY_RADIO, | |
2494 | .policy = hwsim_genl_policy, | |
2495 | .doit = hwsim_destroy_radio_nl, | |
2496 | .flags = GENL_ADMIN_PERM, | |
2497 | }, | |
7882513b JL |
2498 | }; |
2499 | ||
2500 | static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, | |
2501 | unsigned long state, | |
2502 | void *_notify) | |
2503 | { | |
2504 | struct netlink_notify *notify = _notify; | |
2505 | ||
2506 | if (state != NETLINK_URELEASE) | |
2507 | return NOTIFY_DONE; | |
2508 | ||
15e47304 | 2509 | if (notify->portid == wmediumd_portid) { |
7882513b JL |
2510 | printk(KERN_INFO "mac80211_hwsim: wmediumd released netlink" |
2511 | " socket, switching to perfect channel medium\n"); | |
15e47304 | 2512 | wmediumd_portid = 0; |
7882513b JL |
2513 | } |
2514 | return NOTIFY_DONE; | |
2515 | ||
2516 | } | |
2517 | ||
2518 | static struct notifier_block hwsim_netlink_notifier = { | |
2519 | .notifier_call = mac80211_hwsim_netlink_notify, | |
2520 | }; | |
2521 | ||
2522 | static int hwsim_init_netlink(void) | |
2523 | { | |
2524 | int rc; | |
e8261171 | 2525 | |
7882513b JL |
2526 | printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); |
2527 | ||
c53ed742 | 2528 | rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops); |
7882513b JL |
2529 | if (rc) |
2530 | goto failure; | |
2531 | ||
2532 | rc = netlink_register_notifier(&hwsim_netlink_notifier); | |
2533 | if (rc) | |
2534 | goto failure; | |
2535 | ||
2536 | return 0; | |
2537 | ||
2538 | failure: | |
c393862f | 2539 | printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); |
7882513b JL |
2540 | return -EINVAL; |
2541 | } | |
2542 | ||
2543 | static void hwsim_exit_netlink(void) | |
2544 | { | |
7882513b JL |
2545 | /* unregister the notifier */ |
2546 | netlink_unregister_notifier(&hwsim_netlink_notifier); | |
2547 | /* unregister the family */ | |
cf7a6b2d | 2548 | genl_unregister_family(&hwsim_genl_family); |
7882513b JL |
2549 | } |
2550 | ||
acc1e7a3 JM |
2551 | static int __init init_mac80211_hwsim(void) |
2552 | { | |
f39c2bfa | 2553 | int i, err; |
acc1e7a3 | 2554 | |
bc791098 | 2555 | if (radios < 0 || radios > 100) |
acc1e7a3 JM |
2556 | return -EINVAL; |
2557 | ||
e8261171 JB |
2558 | if (channels < 1) |
2559 | return -EINVAL; | |
2560 | ||
38ed5048 JB |
2561 | mac80211_hwsim_mchan_ops = mac80211_hwsim_ops; |
2562 | mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan; | |
2563 | mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan; | |
2564 | mac80211_hwsim_mchan_ops.sw_scan_start = NULL; | |
2565 | mac80211_hwsim_mchan_ops.sw_scan_complete = NULL; | |
2566 | mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc; | |
2567 | mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc; | |
2568 | mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx; | |
2569 | mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx; | |
2570 | mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx; | |
2571 | mac80211_hwsim_mchan_ops.assign_vif_chanctx = | |
2572 | mac80211_hwsim_assign_vif_chanctx; | |
2573 | mac80211_hwsim_mchan_ops.unassign_vif_chanctx = | |
2574 | mac80211_hwsim_unassign_vif_chanctx; | |
69068036 | 2575 | |
0e057d73 JB |
2576 | spin_lock_init(&hwsim_radio_lock); |
2577 | INIT_LIST_HEAD(&hwsim_radios); | |
acc1e7a3 | 2578 | |
c07fe5ae | 2579 | err = platform_driver_register(&mac80211_hwsim_driver); |
9ea92774 MP |
2580 | if (err) |
2581 | return err; | |
2582 | ||
acc1e7a3 | 2583 | hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim"); |
9ea92774 MP |
2584 | if (IS_ERR(hwsim_class)) { |
2585 | err = PTR_ERR(hwsim_class); | |
f39c2bfa | 2586 | goto out_unregister_driver; |
9ea92774 | 2587 | } |
acc1e7a3 | 2588 | |
0e057d73 | 2589 | for (i = 0; i < radios; i++) { |
26b0e411 JB |
2590 | const char *reg_alpha2 = NULL; |
2591 | const struct ieee80211_regdomain *regd = NULL; | |
2592 | bool reg_strict = false; | |
acc1e7a3 | 2593 | |
4a5af9c2 | 2594 | switch (regtest) { |
4a5af9c2 | 2595 | case HWSIM_REGTEST_DIFF_COUNTRY: |
26b0e411 JB |
2596 | if (i < ARRAY_SIZE(hwsim_alpha2s)) |
2597 | reg_alpha2 = hwsim_alpha2s[i]; | |
4a5af9c2 LR |
2598 | break; |
2599 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: | |
2600 | if (!i) | |
26b0e411 | 2601 | reg_alpha2 = hwsim_alpha2s[0]; |
4a5af9c2 | 2602 | break; |
4a5af9c2 | 2603 | case HWSIM_REGTEST_STRICT_ALL: |
26b0e411 JB |
2604 | reg_strict = true; |
2605 | case HWSIM_REGTEST_DRIVER_REG_ALL: | |
2606 | reg_alpha2 = hwsim_alpha2s[0]; | |
4a5af9c2 | 2607 | break; |
26b0e411 JB |
2608 | case HWSIM_REGTEST_WORLD_ROAM: |
2609 | if (i == 0) | |
2610 | regd = &hwsim_world_regdom_custom_01; | |
4a5af9c2 LR |
2611 | break; |
2612 | case HWSIM_REGTEST_CUSTOM_WORLD: | |
26b0e411 JB |
2613 | regd = &hwsim_world_regdom_custom_01; |
2614 | break; | |
4a5af9c2 | 2615 | case HWSIM_REGTEST_CUSTOM_WORLD_2: |
26b0e411 JB |
2616 | if (i == 0) |
2617 | regd = &hwsim_world_regdom_custom_01; | |
2618 | else if (i == 1) | |
2619 | regd = &hwsim_world_regdom_custom_02; | |
4a5af9c2 LR |
2620 | break; |
2621 | case HWSIM_REGTEST_STRICT_FOLLOW: | |
26b0e411 JB |
2622 | if (i == 0) { |
2623 | reg_strict = true; | |
2624 | reg_alpha2 = hwsim_alpha2s[0]; | |
2625 | } | |
4a5af9c2 LR |
2626 | break; |
2627 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: | |
26b0e411 JB |
2628 | if (i == 0) { |
2629 | reg_strict = true; | |
2630 | reg_alpha2 = hwsim_alpha2s[0]; | |
2631 | } else if (i == 1) { | |
2632 | reg_alpha2 = hwsim_alpha2s[1]; | |
2633 | } | |
4a5af9c2 LR |
2634 | break; |
2635 | case HWSIM_REGTEST_ALL: | |
26b0e411 JB |
2636 | switch (i) { |
2637 | case 0: | |
2638 | regd = &hwsim_world_regdom_custom_01; | |
2639 | break; | |
2640 | case 1: | |
2641 | regd = &hwsim_world_regdom_custom_02; | |
2642 | break; | |
2643 | case 2: | |
2644 | reg_alpha2 = hwsim_alpha2s[0]; | |
2645 | break; | |
2646 | case 3: | |
2647 | reg_alpha2 = hwsim_alpha2s[1]; | |
2648 | break; | |
2649 | case 4: | |
2650 | reg_strict = true; | |
2651 | reg_alpha2 = hwsim_alpha2s[2]; | |
2652 | break; | |
2653 | } | |
4a5af9c2 LR |
2654 | break; |
2655 | default: | |
2656 | break; | |
2657 | } | |
2658 | ||
26b0e411 | 2659 | err = mac80211_hwsim_create_radio(channels, reg_alpha2, |
8c66a3d9 JB |
2660 | regd, reg_strict, |
2661 | support_p2p_device); | |
bc791098 | 2662 | if (err < 0) |
f39c2bfa | 2663 | goto out_free_radios; |
acc1e7a3 JM |
2664 | } |
2665 | ||
2666 | hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup); | |
bcdd8220 WY |
2667 | if (hwsim_mon == NULL) { |
2668 | err = -ENOMEM; | |
f39c2bfa | 2669 | goto out_free_radios; |
bcdd8220 | 2670 | } |
acc1e7a3 | 2671 | |
7882513b | 2672 | rtnl_lock(); |
7882513b | 2673 | err = dev_alloc_name(hwsim_mon, hwsim_mon->name); |
f39c2bfa JB |
2674 | if (err < 0) { |
2675 | rtnl_unlock(); | |
2676 | goto out_free_radios; | |
2677 | } | |
7882513b JL |
2678 | |
2679 | err = register_netdevice(hwsim_mon); | |
f39c2bfa JB |
2680 | if (err < 0) { |
2681 | rtnl_unlock(); | |
2682 | goto out_free_mon; | |
2683 | } | |
7882513b JL |
2684 | rtnl_unlock(); |
2685 | ||
2686 | err = hwsim_init_netlink(); | |
2687 | if (err < 0) | |
f39c2bfa | 2688 | goto out_free_mon; |
7882513b | 2689 | |
acc1e7a3 JM |
2690 | return 0; |
2691 | ||
f39c2bfa | 2692 | out_free_mon: |
acc1e7a3 | 2693 | free_netdev(hwsim_mon); |
f39c2bfa | 2694 | out_free_radios: |
3a33cc10 | 2695 | mac80211_hwsim_free(); |
f39c2bfa | 2696 | out_unregister_driver: |
c07fe5ae | 2697 | platform_driver_unregister(&mac80211_hwsim_driver); |
acc1e7a3 JM |
2698 | return err; |
2699 | } | |
f8fffc7e | 2700 | module_init(init_mac80211_hwsim); |
acc1e7a3 JM |
2701 | |
2702 | static void __exit exit_mac80211_hwsim(void) | |
2703 | { | |
0e057d73 | 2704 | printk(KERN_DEBUG "mac80211_hwsim: unregister radios\n"); |
acc1e7a3 | 2705 | |
7882513b JL |
2706 | hwsim_exit_netlink(); |
2707 | ||
acc1e7a3 | 2708 | mac80211_hwsim_free(); |
5d416351 | 2709 | unregister_netdev(hwsim_mon); |
c07fe5ae | 2710 | platform_driver_unregister(&mac80211_hwsim_driver); |
acc1e7a3 | 2711 | } |
acc1e7a3 | 2712 | module_exit(exit_mac80211_hwsim); |