Commit | Line | Data |
---|---|---|
28c61a66 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
f0706e82 JB |
2 | /* |
3 | * mac80211 configuration hooks for cfg80211 | |
4 | * | |
026331c4 | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
b2eb0ee6 | 6 | * Copyright 2013-2015 Intel Mobile Communications GmbH |
e8e4f528 | 7 | * Copyright (C) 2015-2017 Intel Deutschland GmbH |
178e9d6a | 8 | * Copyright (C) 2018-2024 Intel Corporation |
f0706e82 JB |
9 | */ |
10 | ||
e8cbb4cb | 11 | #include <linux/ieee80211.h> |
f0706e82 JB |
12 | #include <linux/nl80211.h> |
13 | #include <linux/rtnetlink.h> | |
5a0e3ad6 | 14 | #include <linux/slab.h> |
881d966b | 15 | #include <net/net_namespace.h> |
5dfdaf58 | 16 | #include <linux/rcupdate.h> |
5fdb3735 | 17 | #include <linux/fips.h> |
dfe018bf | 18 | #include <linux/if_ether.h> |
f0706e82 JB |
19 | #include <net/cfg80211.h> |
20 | #include "ieee80211_i.h" | |
24487981 | 21 | #include "driver-ops.h" |
2c8dccc7 | 22 | #include "rate.h" |
c5dd9c2b | 23 | #include "mesh.h" |
02219b3a | 24 | #include "wme.h" |
c5dd9c2b | 25 | |
c88f1542 | 26 | static struct ieee80211_link_data * |
ccdde7c7 JB |
27 | ieee80211_link_or_deflink(struct ieee80211_sub_if_data *sdata, int link_id, |
28 | bool require_valid) | |
c88f1542 ST |
29 | { |
30 | struct ieee80211_link_data *link; | |
31 | ||
32 | if (link_id < 0) { | |
ccdde7c7 JB |
33 | /* |
34 | * For keys, if sdata is not an MLD, we might not use | |
35 | * the return value at all (if it's not a pairwise key), | |
36 | * so in that case (require_valid==false) don't error. | |
37 | */ | |
f1871abd | 38 | if (require_valid && ieee80211_vif_is_mld(&sdata->vif)) |
c88f1542 ST |
39 | return ERR_PTR(-EINVAL); |
40 | ||
41 | return &sdata->deflink; | |
42 | } | |
43 | ||
44 | link = sdata_dereference(sdata->link[link_id], sdata); | |
45 | if (!link) | |
46 | return ERR_PTR(-ENOLINK); | |
47 | return link; | |
48 | } | |
49 | ||
65f1d600 JB |
50 | static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata, |
51 | struct vif_params *params) | |
8c5e6889 | 52 | { |
8c5e6889 JB |
53 | bool mu_mimo_groups = false; |
54 | bool mu_mimo_follow = false; | |
55 | ||
8c5e6889 JB |
56 | if (params->vht_mumimo_groups) { |
57 | u64 membership; | |
58 | ||
59 | BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN); | |
60 | ||
65f1d600 | 61 | memcpy(sdata->vif.bss_conf.mu_group.membership, |
8c5e6889 | 62 | params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN); |
65f1d600 | 63 | memcpy(sdata->vif.bss_conf.mu_group.position, |
8c5e6889 JB |
64 | params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN, |
65 | WLAN_USER_POSITION_LEN); | |
d8675a63 | 66 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
7b7090b4 | 67 | BSS_CHANGED_MU_GROUPS); |
8c5e6889 JB |
68 | /* don't care about endianness - just check for 0 */ |
69 | memcpy(&membership, params->vht_mumimo_groups, | |
70 | WLAN_MEMBERSHIP_LEN); | |
71 | mu_mimo_groups = membership != 0; | |
72 | } | |
73 | ||
74 | if (params->vht_mumimo_follow_addr) { | |
75 | mu_mimo_follow = | |
76 | is_valid_ether_addr(params->vht_mumimo_follow_addr); | |
65f1d600 | 77 | ether_addr_copy(sdata->u.mntr.mu_follow_addr, |
8c5e6889 JB |
78 | params->vht_mumimo_follow_addr); |
79 | } | |
80 | ||
d0a9123e | 81 | sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; |
65f1d600 JB |
82 | } |
83 | ||
84 | static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata, | |
85 | struct vif_params *params) | |
86 | { | |
87 | struct ieee80211_local *local = sdata->local; | |
88 | struct ieee80211_sub_if_data *monitor_sdata; | |
89 | ||
90 | /* check flags first */ | |
91 | if (params->flags && ieee80211_sdata_running(sdata)) { | |
92 | u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE; | |
93 | ||
94 | /* | |
95 | * Prohibit MONITOR_FLAG_COOK_FRAMES and | |
96 | * MONITOR_FLAG_ACTIVE to be changed while the | |
97 | * interface is up. | |
98 | * Else we would need to add a lot of cruft | |
99 | * to update everything: | |
100 | * cooked_mntrs, monitor and all fif_* counters | |
101 | * reconfigure hardware | |
102 | */ | |
103 | if ((params->flags & mask) != (sdata->u.mntr.flags & mask)) | |
104 | return -EBUSY; | |
105 | } | |
106 | ||
107 | /* also validate MU-MIMO change */ | |
6dd23603 JB |
108 | monitor_sdata = wiphy_dereference(local->hw.wiphy, |
109 | local->monitor_sdata); | |
65f1d600 JB |
110 | |
111 | if (!monitor_sdata && | |
112 | (params->vht_mumimo_groups || params->vht_mumimo_follow_addr)) | |
113 | return -EOPNOTSUPP; | |
114 | ||
115 | /* apply all changes now - no failures allowed */ | |
116 | ||
117 | if (monitor_sdata) | |
118 | ieee80211_set_mu_mimo_follow(monitor_sdata, params); | |
119 | ||
120 | if (params->flags) { | |
121 | if (ieee80211_sdata_running(sdata)) { | |
122 | ieee80211_adjust_monitor_flags(sdata, -1); | |
123 | sdata->u.mntr.flags = params->flags; | |
124 | ieee80211_adjust_monitor_flags(sdata, 1); | |
125 | ||
126 | ieee80211_configure_filter(local); | |
127 | } else { | |
128 | /* | |
129 | * Because the interface is down, ieee80211_do_stop | |
130 | * and ieee80211_do_open take care of "everything" | |
131 | * mentioned in the comment above. | |
132 | */ | |
133 | sdata->u.mntr.flags = params->flags; | |
134 | } | |
135 | } | |
8c5e6889 JB |
136 | |
137 | return 0; | |
138 | } | |
139 | ||
17196425 | 140 | static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata, |
d9f83f22 ST |
141 | struct cfg80211_mbssid_config params, |
142 | struct ieee80211_bss_conf *link_conf) | |
17196425 JC |
143 | { |
144 | struct ieee80211_sub_if_data *tx_sdata; | |
145 | ||
146 | sdata->vif.mbssid_tx_vif = NULL; | |
d9f83f22 ST |
147 | link_conf->bssid_index = 0; |
148 | link_conf->nontransmitted = false; | |
149 | link_conf->ema_ap = false; | |
0eb38842 | 150 | link_conf->bssid_indicator = 0; |
17196425 JC |
151 | |
152 | if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev) | |
153 | return -EINVAL; | |
154 | ||
155 | tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev); | |
156 | if (!tx_sdata) | |
157 | return -EINVAL; | |
158 | ||
159 | if (tx_sdata == sdata) { | |
160 | sdata->vif.mbssid_tx_vif = &sdata->vif; | |
161 | } else { | |
162 | sdata->vif.mbssid_tx_vif = &tx_sdata->vif; | |
d9f83f22 ST |
163 | link_conf->nontransmitted = true; |
164 | link_conf->bssid_index = params.index; | |
17196425 JC |
165 | } |
166 | if (params.ema) | |
d9f83f22 | 167 | link_conf->ema_ap = true; |
17196425 JC |
168 | |
169 | return 0; | |
170 | } | |
171 | ||
552bff0c JB |
172 | static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, |
173 | const char *name, | |
6bab2e19 | 174 | unsigned char name_assign_type, |
84efbb84 | 175 | enum nl80211_iftype type, |
84efbb84 | 176 | struct vif_params *params) |
f0706e82 JB |
177 | { |
178 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
84efbb84 | 179 | struct wireless_dev *wdev; |
8cc9a739 MW |
180 | struct ieee80211_sub_if_data *sdata; |
181 | int err; | |
f0706e82 | 182 | |
6bab2e19 | 183 | err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params); |
f9e10ce4 JB |
184 | if (err) |
185 | return ERR_PTR(err); | |
8cc9a739 | 186 | |
8c5e6889 JB |
187 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
188 | ||
189 | if (type == NL80211_IFTYPE_MONITOR) { | |
65f1d600 | 190 | err = ieee80211_set_mon_options(sdata, params); |
8c5e6889 JB |
191 | if (err) { |
192 | ieee80211_if_remove(sdata); | |
193 | return NULL; | |
194 | } | |
f9e10ce4 JB |
195 | } |
196 | ||
84efbb84 | 197 | return wdev; |
f0706e82 JB |
198 | } |
199 | ||
84efbb84 | 200 | static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
f0706e82 | 201 | { |
84efbb84 | 202 | ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev)); |
f0706e82 | 203 | |
75636525 | 204 | return 0; |
f0706e82 JB |
205 | } |
206 | ||
e36d56b6 JB |
207 | static int ieee80211_change_iface(struct wiphy *wiphy, |
208 | struct net_device *dev, | |
818a986e | 209 | enum nl80211_iftype type, |
2ec600d6 | 210 | struct vif_params *params) |
42613db7 | 211 | { |
9607e6b6 | 212 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
a5d3cbdb FF |
213 | struct ieee80211_local *local = sdata->local; |
214 | struct sta_info *sta; | |
f3947e2d | 215 | int ret; |
42613db7 | 216 | |
4d3acf43 JB |
217 | lockdep_assert_wiphy(local->hw.wiphy); |
218 | ||
05c914fe | 219 | ret = ieee80211_if_change_type(sdata, type); |
f3947e2d JB |
220 | if (ret) |
221 | return ret; | |
42613db7 | 222 | |
6f527287 | 223 | if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) { |
a9b3cd7f | 224 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
49ddf8e6 | 225 | ieee80211_check_fast_rx_iface(sdata); |
6f527287 | 226 | } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) { |
a5d3cbdb FF |
227 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
228 | ||
229 | if (params->use_4addr == ifmgd->use_4addr) | |
230 | return 0; | |
231 | ||
90703ba9 | 232 | /* FIXME: no support for 4-addr MLO yet */ |
f1871abd | 233 | if (ieee80211_vif_is_mld(&sdata->vif)) |
90703ba9 JB |
234 | return -EOPNOTSUPP; |
235 | ||
9bc383de | 236 | sdata->u.mgd.use_4addr = params->use_4addr; |
a5d3cbdb FF |
237 | if (!ifmgd->associated) |
238 | return 0; | |
239 | ||
bfd8403a | 240 | sta = sta_info_get(sdata, sdata->deflink.u.mgd.bssid); |
a5d3cbdb FF |
241 | if (sta) |
242 | drv_sta_set_4addr(local, sdata, &sta->sta, | |
243 | params->use_4addr); | |
a5d3cbdb FF |
244 | |
245 | if (params->use_4addr) | |
246 | ieee80211_send_4addr_nullfunc(local, sdata); | |
49ddf8e6 | 247 | } |
9bc383de | 248 | |
42bd20d9 | 249 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
65f1d600 JB |
250 | ret = ieee80211_set_mon_options(sdata, params); |
251 | if (ret) | |
252 | return ret; | |
85416a4f | 253 | } |
f7917af9 | 254 | |
42613db7 JB |
255 | return 0; |
256 | } | |
257 | ||
f142c6b9 JB |
258 | static int ieee80211_start_p2p_device(struct wiphy *wiphy, |
259 | struct wireless_dev *wdev) | |
260 | { | |
b6a55015 LC |
261 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
262 | int ret; | |
263 | ||
5435af6e JB |
264 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
265 | ||
b6a55015 | 266 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
b6a55015 LC |
267 | if (ret < 0) |
268 | return ret; | |
269 | ||
f142c6b9 JB |
270 | return ieee80211_do_open(wdev, true); |
271 | } | |
272 | ||
273 | static void ieee80211_stop_p2p_device(struct wiphy *wiphy, | |
274 | struct wireless_dev *wdev) | |
275 | { | |
276 | ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev)); | |
277 | } | |
278 | ||
708d50ed AB |
279 | static int ieee80211_start_nan(struct wiphy *wiphy, |
280 | struct wireless_dev *wdev, | |
281 | struct cfg80211_nan_conf *conf) | |
282 | { | |
283 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
284 | int ret; | |
285 | ||
5435af6e JB |
286 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
287 | ||
708d50ed | 288 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
708d50ed AB |
289 | if (ret < 0) |
290 | return ret; | |
291 | ||
292 | ret = ieee80211_do_open(wdev, true); | |
293 | if (ret) | |
294 | return ret; | |
295 | ||
296 | ret = drv_start_nan(sdata->local, sdata, conf); | |
297 | if (ret) | |
298 | ieee80211_sdata_stop(sdata); | |
299 | ||
167e33f4 AB |
300 | sdata->u.nan.conf = *conf; |
301 | ||
708d50ed AB |
302 | return ret; |
303 | } | |
304 | ||
305 | static void ieee80211_stop_nan(struct wiphy *wiphy, | |
306 | struct wireless_dev *wdev) | |
307 | { | |
308 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
309 | ||
310 | drv_stop_nan(sdata->local, sdata); | |
311 | ieee80211_sdata_stop(sdata); | |
312 | } | |
313 | ||
5953ff6d AB |
314 | static int ieee80211_nan_change_conf(struct wiphy *wiphy, |
315 | struct wireless_dev *wdev, | |
316 | struct cfg80211_nan_conf *conf, | |
317 | u32 changes) | |
318 | { | |
319 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
320 | struct cfg80211_nan_conf new_conf; | |
321 | int ret = 0; | |
322 | ||
323 | if (sdata->vif.type != NL80211_IFTYPE_NAN) | |
324 | return -EOPNOTSUPP; | |
325 | ||
326 | if (!ieee80211_sdata_running(sdata)) | |
327 | return -ENETDOWN; | |
328 | ||
329 | new_conf = sdata->u.nan.conf; | |
330 | ||
331 | if (changes & CFG80211_NAN_CONF_CHANGED_PREF) | |
332 | new_conf.master_pref = conf->master_pref; | |
333 | ||
8585989d LC |
334 | if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) |
335 | new_conf.bands = conf->bands; | |
5953ff6d AB |
336 | |
337 | ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes); | |
338 | if (!ret) | |
339 | sdata->u.nan.conf = new_conf; | |
340 | ||
341 | return ret; | |
342 | } | |
343 | ||
167e33f4 AB |
344 | static int ieee80211_add_nan_func(struct wiphy *wiphy, |
345 | struct wireless_dev *wdev, | |
346 | struct cfg80211_nan_func *nan_func) | |
347 | { | |
348 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
349 | int ret; | |
350 | ||
351 | if (sdata->vif.type != NL80211_IFTYPE_NAN) | |
352 | return -EOPNOTSUPP; | |
353 | ||
354 | if (!ieee80211_sdata_running(sdata)) | |
355 | return -ENETDOWN; | |
356 | ||
357 | spin_lock_bh(&sdata->u.nan.func_lock); | |
358 | ||
359 | ret = idr_alloc(&sdata->u.nan.function_inst_ids, | |
360 | nan_func, 1, sdata->local->hw.max_nan_de_entries + 1, | |
361 | GFP_ATOMIC); | |
362 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
363 | ||
364 | if (ret < 0) | |
365 | return ret; | |
366 | ||
367 | nan_func->instance_id = ret; | |
368 | ||
369 | WARN_ON(nan_func->instance_id == 0); | |
370 | ||
371 | ret = drv_add_nan_func(sdata->local, sdata, nan_func); | |
372 | if (ret) { | |
373 | spin_lock_bh(&sdata->u.nan.func_lock); | |
374 | idr_remove(&sdata->u.nan.function_inst_ids, | |
375 | nan_func->instance_id); | |
376 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
377 | } | |
378 | ||
379 | return ret; | |
380 | } | |
381 | ||
382 | static struct cfg80211_nan_func * | |
383 | ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata, | |
384 | u64 cookie) | |
385 | { | |
386 | struct cfg80211_nan_func *func; | |
387 | int id; | |
388 | ||
389 | lockdep_assert_held(&sdata->u.nan.func_lock); | |
390 | ||
391 | idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) { | |
392 | if (func->cookie == cookie) | |
393 | return func; | |
394 | } | |
395 | ||
396 | return NULL; | |
397 | } | |
398 | ||
399 | static void ieee80211_del_nan_func(struct wiphy *wiphy, | |
400 | struct wireless_dev *wdev, u64 cookie) | |
401 | { | |
402 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
403 | struct cfg80211_nan_func *func; | |
404 | u8 instance_id = 0; | |
405 | ||
406 | if (sdata->vif.type != NL80211_IFTYPE_NAN || | |
407 | !ieee80211_sdata_running(sdata)) | |
408 | return; | |
409 | ||
410 | spin_lock_bh(&sdata->u.nan.func_lock); | |
411 | ||
412 | func = ieee80211_find_nan_func_by_cookie(sdata, cookie); | |
413 | if (func) | |
414 | instance_id = func->instance_id; | |
415 | ||
416 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
417 | ||
418 | if (instance_id) | |
419 | drv_del_nan_func(sdata->local, sdata, instance_id); | |
420 | } | |
421 | ||
b53be792 SW |
422 | static int ieee80211_set_noack_map(struct wiphy *wiphy, |
423 | struct net_device *dev, | |
424 | u16 noack_map) | |
425 | { | |
426 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
427 | ||
428 | sdata->noack_map = noack_map; | |
17c18bf8 JB |
429 | |
430 | ieee80211_check_fast_xmit_iface(sdata); | |
431 | ||
b53be792 SW |
432 | return 0; |
433 | } | |
434 | ||
96fc6efb AW |
435 | static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata, |
436 | const u8 *mac_addr, u8 key_idx) | |
437 | { | |
438 | struct ieee80211_local *local = sdata->local; | |
439 | struct ieee80211_key *key; | |
440 | struct sta_info *sta; | |
441 | int ret = -EINVAL; | |
442 | ||
443 | if (!wiphy_ext_feature_isset(local->hw.wiphy, | |
444 | NL80211_EXT_FEATURE_EXT_KEY_ID)) | |
445 | return -EINVAL; | |
446 | ||
447 | sta = sta_info_get_bss(sdata, mac_addr); | |
448 | ||
449 | if (!sta) | |
450 | return -EINVAL; | |
451 | ||
452 | if (sta->ptk_idx == key_idx) | |
453 | return 0; | |
454 | ||
2a8b665e | 455 | key = wiphy_dereference(local->hw.wiphy, sta->ptk[key_idx]); |
96fc6efb AW |
456 | |
457 | if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX) | |
458 | ret = ieee80211_set_tx_key(key); | |
459 | ||
96fc6efb AW |
460 | return ret; |
461 | } | |
462 | ||
e8cbb4cb | 463 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
e7a7b84e VJ |
464 | int link_id, u8 key_idx, bool pairwise, |
465 | const u8 *mac_addr, struct key_params *params) | |
e8cbb4cb | 466 | { |
26a58456 | 467 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
ccdde7c7 JB |
468 | struct ieee80211_link_data *link = |
469 | ieee80211_link_or_deflink(sdata, link_id, false); | |
2475b1cc | 470 | struct ieee80211_local *local = sdata->local; |
e8cbb4cb | 471 | struct sta_info *sta = NULL; |
db4d1169 | 472 | struct ieee80211_key *key; |
3b96766f | 473 | int err; |
4d3acf43 JB |
474 | |
475 | lockdep_assert_wiphy(local->hw.wiphy); | |
e8cbb4cb | 476 | |
26a58456 | 477 | if (!ieee80211_sdata_running(sdata)) |
ad0e2b5a JB |
478 | return -ENETDOWN; |
479 | ||
ccdde7c7 JB |
480 | if (IS_ERR(link)) |
481 | return PTR_ERR(link); | |
482 | ||
96fc6efb AW |
483 | if (pairwise && params->mode == NL80211_KEY_SET_TX) |
484 | return ieee80211_set_tx(sdata, mac_addr, key_idx); | |
485 | ||
97359d12 | 486 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
e8cbb4cb JB |
487 | switch (params->cipher) { |
488 | case WLAN_CIPHER_SUITE_WEP40: | |
e8cbb4cb | 489 | case WLAN_CIPHER_SUITE_TKIP: |
97359d12 | 490 | case WLAN_CIPHER_SUITE_WEP104: |
ccdde7c7 JB |
491 | if (link_id >= 0) |
492 | return -EINVAL; | |
5fdb3735 | 493 | if (WARN_ON_ONCE(fips_enabled)) |
97359d12 | 494 | return -EINVAL; |
aaaee2d6 | 495 | break; |
e8cbb4cb | 496 | default: |
97359d12 | 497 | break; |
e8cbb4cb JB |
498 | } |
499 | ||
97359d12 | 500 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
23a5f0af | 501 | params->key, params->seq_len, params->seq); |
1ac62ba7 BH |
502 | if (IS_ERR(key)) |
503 | return PTR_ERR(key); | |
db4d1169 | 504 | |
ccdde7c7 JB |
505 | key->conf.link_id = link_id; |
506 | ||
e31b8213 JB |
507 | if (pairwise) |
508 | key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; | |
509 | ||
96fc6efb AW |
510 | if (params->mode == NL80211_KEY_NO_TX) |
511 | key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX; | |
512 | ||
e8cbb4cb | 513 | if (mac_addr) { |
850092db | 514 | sta = sta_info_get_bss(sdata, mac_addr); |
1626e0fa JB |
515 | /* |
516 | * The ASSOC test makes sure the driver is ready to | |
517 | * receive the key. When wpa_supplicant has roamed | |
518 | * using FT, it attempts to set the key before | |
519 | * association has completed, this rejects that attempt | |
d070f913 | 520 | * so it will set the key again after association. |
1626e0fa JB |
521 | * |
522 | * TODO: accept the key if we have a station entry and | |
523 | * add it to the device after the station. | |
524 | */ | |
525 | if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) { | |
79cf2dfa | 526 | ieee80211_key_free_unused(key); |
4d3acf43 | 527 | return -ENOENT; |
db4d1169 | 528 | } |
e8cbb4cb JB |
529 | } |
530 | ||
e548c49e JB |
531 | switch (sdata->vif.type) { |
532 | case NL80211_IFTYPE_STATION: | |
533 | if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) | |
534 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; | |
535 | break; | |
536 | case NL80211_IFTYPE_AP: | |
537 | case NL80211_IFTYPE_AP_VLAN: | |
538 | /* Keys without a station are used for TX only */ | |
211710ca | 539 | if (sta && test_sta_flag(sta, WLAN_STA_MFP)) |
e548c49e JB |
540 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
541 | break; | |
542 | case NL80211_IFTYPE_ADHOC: | |
543 | /* no MFP (yet) */ | |
544 | break; | |
545 | case NL80211_IFTYPE_MESH_POINT: | |
546 | #ifdef CONFIG_MAC80211_MESH | |
547 | if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) | |
548 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; | |
549 | break; | |
550 | #endif | |
551 | case NL80211_IFTYPE_WDS: | |
552 | case NL80211_IFTYPE_MONITOR: | |
553 | case NL80211_IFTYPE_P2P_DEVICE: | |
cb3b7d87 | 554 | case NL80211_IFTYPE_NAN: |
e548c49e JB |
555 | case NL80211_IFTYPE_UNSPECIFIED: |
556 | case NUM_NL80211_IFTYPES: | |
557 | case NL80211_IFTYPE_P2P_CLIENT: | |
558 | case NL80211_IFTYPE_P2P_GO: | |
6e0bd6c3 | 559 | case NL80211_IFTYPE_OCB: |
e548c49e JB |
560 | /* shouldn't happen */ |
561 | WARN_ON_ONCE(1); | |
562 | break; | |
563 | } | |
564 | ||
ccdde7c7 | 565 | err = ieee80211_key_link(key, link, sta); |
31db78a4 JB |
566 | /* KRACK protection, shouldn't happen but just silently accept key */ |
567 | if (err == -EALREADY) | |
568 | err = 0; | |
db4d1169 | 569 | |
3b96766f | 570 | return err; |
e8cbb4cb JB |
571 | } |
572 | ||
8cbf0c2a | 573 | static struct ieee80211_key * |
ccdde7c7 | 574 | ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id, |
8cbf0c2a JB |
575 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
576 | { | |
09d838a4 | 577 | struct ieee80211_local *local __maybe_unused = sdata->local; |
ccdde7c7 | 578 | struct ieee80211_link_data *link = &sdata->deflink; |
bfd8403a | 579 | struct ieee80211_key *key; |
ccdde7c7 JB |
580 | |
581 | if (link_id >= 0) { | |
076fc877 | 582 | link = sdata_dereference(sdata->link[link_id], sdata); |
ccdde7c7 JB |
583 | if (!link) |
584 | return NULL; | |
585 | } | |
8cbf0c2a JB |
586 | |
587 | if (mac_addr) { | |
ccdde7c7 JB |
588 | struct sta_info *sta; |
589 | struct link_sta_info *link_sta; | |
590 | ||
8cbf0c2a JB |
591 | sta = sta_info_get_bss(sdata, mac_addr); |
592 | if (!sta) | |
593 | return NULL; | |
594 | ||
ccdde7c7 JB |
595 | if (link_id >= 0) { |
596 | link_sta = rcu_dereference_check(sta->link[link_id], | |
4d3acf43 | 597 | lockdep_is_held(&local->hw.wiphy->mtx)); |
ccdde7c7 JB |
598 | if (!link_sta) |
599 | return NULL; | |
600 | } else { | |
601 | link_sta = &sta->deflink; | |
602 | } | |
603 | ||
8cbf0c2a | 604 | if (pairwise && key_idx < NUM_DEFAULT_KEYS) |
2a8b665e JB |
605 | return wiphy_dereference(local->hw.wiphy, |
606 | sta->ptk[key_idx]); | |
8cbf0c2a JB |
607 | |
608 | if (!pairwise && | |
609 | key_idx < NUM_DEFAULT_KEYS + | |
610 | NUM_DEFAULT_MGMT_KEYS + | |
611 | NUM_DEFAULT_BEACON_KEYS) | |
2a8b665e JB |
612 | return wiphy_dereference(local->hw.wiphy, |
613 | link_sta->gtk[key_idx]); | |
8cbf0c2a JB |
614 | |
615 | return NULL; | |
616 | } | |
617 | ||
bfd8403a | 618 | if (pairwise && key_idx < NUM_DEFAULT_KEYS) |
2a8b665e | 619 | return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]); |
8cbf0c2a | 620 | |
2a8b665e | 621 | key = wiphy_dereference(local->hw.wiphy, link->gtk[key_idx]); |
bfd8403a JB |
622 | if (key) |
623 | return key; | |
624 | ||
e2722d27 JB |
625 | /* or maybe it was a WEP key */ |
626 | if (key_idx < NUM_DEFAULT_KEYS) | |
2a8b665e | 627 | return wiphy_dereference(local->hw.wiphy, sdata->keys[key_idx]); |
e2722d27 | 628 | |
8cbf0c2a JB |
629 | return NULL; |
630 | } | |
631 | ||
e8cbb4cb | 632 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
e7a7b84e VJ |
633 | int link_id, u8 key_idx, bool pairwise, |
634 | const u8 *mac_addr) | |
e8cbb4cb | 635 | { |
5c0c3641 JB |
636 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
637 | struct ieee80211_local *local = sdata->local; | |
8cbf0c2a | 638 | struct ieee80211_key *key; |
e8cbb4cb | 639 | |
4d3acf43 JB |
640 | lockdep_assert_wiphy(local->hw.wiphy); |
641 | ||
ccdde7c7 | 642 | key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); |
2a8b665e JB |
643 | if (!key) |
644 | return -ENOENT; | |
e8cbb4cb | 645 | |
133bf90d | 646 | ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION); |
e8cbb4cb | 647 | |
2a8b665e | 648 | return 0; |
e8cbb4cb JB |
649 | } |
650 | ||
62da92fb | 651 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
e7a7b84e VJ |
652 | int link_id, u8 key_idx, bool pairwise, |
653 | const u8 *mac_addr, void *cookie, | |
62da92fb JB |
654 | void (*callback)(void *cookie, |
655 | struct key_params *params)) | |
656 | { | |
14db74bc | 657 | struct ieee80211_sub_if_data *sdata; |
62da92fb JB |
658 | u8 seq[6] = {0}; |
659 | struct key_params params; | |
8cbf0c2a | 660 | struct ieee80211_key *key; |
aba83a0b | 661 | u64 pn64; |
62da92fb JB |
662 | u32 iv32; |
663 | u16 iv16; | |
664 | int err = -ENOENT; | |
9352c19f | 665 | struct ieee80211_key_seq kseq = {}; |
62da92fb | 666 | |
14db74bc JB |
667 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
668 | ||
3b96766f JB |
669 | rcu_read_lock(); |
670 | ||
ccdde7c7 | 671 | key = ieee80211_lookup_key(sdata, link_id, key_idx, pairwise, mac_addr); |
62da92fb JB |
672 | if (!key) |
673 | goto out; | |
674 | ||
675 | memset(¶ms, 0, sizeof(params)); | |
676 | ||
97359d12 | 677 | params.cipher = key->conf.cipher; |
62da92fb | 678 | |
97359d12 JB |
679 | switch (key->conf.cipher) { |
680 | case WLAN_CIPHER_SUITE_TKIP: | |
f8079d43 EP |
681 | pn64 = atomic64_read(&key->conf.tx_pn); |
682 | iv32 = TKIP_PN_TO_IV32(pn64); | |
683 | iv16 = TKIP_PN_TO_IV16(pn64); | |
62da92fb | 684 | |
9352c19f JB |
685 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
686 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { | |
687 | drv_get_key_seq(sdata->local, key, &kseq); | |
688 | iv32 = kseq.tkip.iv32; | |
689 | iv16 = kseq.tkip.iv16; | |
690 | } | |
62da92fb JB |
691 | |
692 | seq[0] = iv16 & 0xff; | |
693 | seq[1] = (iv16 >> 8) & 0xff; | |
694 | seq[2] = iv32 & 0xff; | |
695 | seq[3] = (iv32 >> 8) & 0xff; | |
696 | seq[4] = (iv32 >> 16) & 0xff; | |
697 | seq[5] = (iv32 >> 24) & 0xff; | |
698 | params.seq = seq; | |
699 | params.seq_len = 6; | |
700 | break; | |
97359d12 | 701 | case WLAN_CIPHER_SUITE_CCMP: |
2b2ba0db | 702 | case WLAN_CIPHER_SUITE_CCMP_256: |
97359d12 | 703 | case WLAN_CIPHER_SUITE_AES_CMAC: |
56c52da2 | 704 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
db388a56 JB |
705 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
706 | offsetof(typeof(kseq), aes_cmac)); | |
fc0561dc | 707 | fallthrough; |
8ade538b JM |
708 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
709 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
db388a56 JB |
710 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
711 | offsetof(typeof(kseq), aes_gmac)); | |
fc0561dc | 712 | fallthrough; |
00b9cfa3 JM |
713 | case WLAN_CIPHER_SUITE_GCMP: |
714 | case WLAN_CIPHER_SUITE_GCMP_256: | |
db388a56 JB |
715 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
716 | offsetof(typeof(kseq), gcmp)); | |
717 | ||
9352c19f JB |
718 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
719 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { | |
720 | drv_get_key_seq(sdata->local, key, &kseq); | |
db388a56 | 721 | memcpy(seq, kseq.ccmp.pn, 6); |
9352c19f | 722 | } else { |
db388a56 | 723 | pn64 = atomic64_read(&key->conf.tx_pn); |
9352c19f JB |
724 | seq[0] = pn64; |
725 | seq[1] = pn64 >> 8; | |
726 | seq[2] = pn64 >> 16; | |
727 | seq[3] = pn64 >> 24; | |
728 | seq[4] = pn64 >> 32; | |
729 | seq[5] = pn64 >> 40; | |
730 | } | |
00b9cfa3 JM |
731 | params.seq = seq; |
732 | params.seq_len = 6; | |
733 | break; | |
a31cf1c6 JB |
734 | default: |
735 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) | |
736 | break; | |
737 | if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) | |
738 | break; | |
739 | drv_get_key_seq(sdata->local, key, &kseq); | |
740 | params.seq = kseq.hw.seq; | |
741 | params.seq_len = kseq.hw.seq_len; | |
742 | break; | |
62da92fb JB |
743 | } |
744 | ||
745 | params.key = key->conf.key; | |
746 | params.key_len = key->conf.keylen; | |
747 | ||
748 | callback(cookie, ¶ms); | |
749 | err = 0; | |
750 | ||
751 | out: | |
3b96766f | 752 | rcu_read_unlock(); |
62da92fb JB |
753 | return err; |
754 | } | |
755 | ||
e8cbb4cb JB |
756 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
757 | struct net_device *dev, | |
e7a7b84e | 758 | int link_id, u8 key_idx, bool uni, |
dbd2fd65 | 759 | bool multi) |
e8cbb4cb | 760 | { |
ad0e2b5a | 761 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
ccdde7c7 JB |
762 | struct ieee80211_link_data *link = |
763 | ieee80211_link_or_deflink(sdata, link_id, false); | |
3b96766f | 764 | |
ccdde7c7 JB |
765 | if (IS_ERR(link)) |
766 | return PTR_ERR(link); | |
767 | ||
768 | ieee80211_set_default_key(link, key_idx, uni, multi); | |
e8cbb4cb JB |
769 | |
770 | return 0; | |
771 | } | |
772 | ||
3cfcf6ac JM |
773 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
774 | struct net_device *dev, | |
e7a7b84e | 775 | int link_id, u8 key_idx) |
3cfcf6ac | 776 | { |
66c52421 | 777 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
ccdde7c7 JB |
778 | struct ieee80211_link_data *link = |
779 | ieee80211_link_or_deflink(sdata, link_id, true); | |
3cfcf6ac | 780 | |
ccdde7c7 JB |
781 | if (IS_ERR(link)) |
782 | return PTR_ERR(link); | |
783 | ||
784 | ieee80211_set_default_mgmt_key(link, key_idx); | |
3cfcf6ac | 785 | |
3cfcf6ac JM |
786 | return 0; |
787 | } | |
788 | ||
e5473e80 JM |
789 | static int ieee80211_config_default_beacon_key(struct wiphy *wiphy, |
790 | struct net_device *dev, | |
e7a7b84e | 791 | int link_id, u8 key_idx) |
e5473e80 JM |
792 | { |
793 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
ccdde7c7 JB |
794 | struct ieee80211_link_data *link = |
795 | ieee80211_link_or_deflink(sdata, link_id, true); | |
796 | ||
797 | if (IS_ERR(link)) | |
798 | return PTR_ERR(link); | |
e5473e80 | 799 | |
ccdde7c7 | 800 | ieee80211_set_default_beacon_key(link, key_idx); |
e5473e80 JM |
801 | |
802 | return 0; | |
803 | } | |
804 | ||
6b62bf32 TP |
805 | void sta_set_rate_info_tx(struct sta_info *sta, |
806 | const struct ieee80211_tx_rate *rate, | |
807 | struct rate_info *rinfo) | |
808 | { | |
809 | rinfo->flags = 0; | |
8bc83c24 | 810 | if (rate->flags & IEEE80211_TX_RC_MCS) { |
6b62bf32 | 811 | rinfo->flags |= RATE_INFO_FLAGS_MCS; |
8bc83c24 JB |
812 | rinfo->mcs = rate->idx; |
813 | } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) { | |
814 | rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; | |
815 | rinfo->mcs = ieee80211_rate_get_vht_mcs(rate); | |
816 | rinfo->nss = ieee80211_rate_get_vht_nss(rate); | |
817 | } else { | |
818 | struct ieee80211_supported_band *sband; | |
2103dec1 | 819 | |
21a8e9dd | 820 | sband = ieee80211_get_sband(sta->sdata); |
8b783d10 | 821 | WARN_ON_ONCE(sband && !sband->bitrates); |
2400dfe2 JB |
822 | if (sband && sband->bitrates) |
823 | rinfo->legacy = sband->bitrates[rate->idx].bitrate; | |
8bc83c24 | 824 | } |
6b62bf32 | 825 | if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
b51f3bee JB |
826 | rinfo->bw = RATE_INFO_BW_40; |
827 | else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) | |
828 | rinfo->bw = RATE_INFO_BW_80; | |
829 | else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) | |
830 | rinfo->bw = RATE_INFO_BW_160; | |
831 | else | |
832 | rinfo->bw = RATE_INFO_BW_20; | |
6b62bf32 TP |
833 | if (rate->flags & IEEE80211_TX_RC_SHORT_GI) |
834 | rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; | |
6b62bf32 TP |
835 | } |
836 | ||
c5dd9c2b | 837 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
3b3a0162 | 838 | int idx, u8 *mac, struct station_info *sinfo) |
c5dd9c2b | 839 | { |
3b53fde8 | 840 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
66572cfc | 841 | struct ieee80211_local *local = sdata->local; |
c5dd9c2b | 842 | struct sta_info *sta; |
d0709a65 JB |
843 | int ret = -ENOENT; |
844 | ||
4d3acf43 | 845 | lockdep_assert_wiphy(local->hw.wiphy); |
c5dd9c2b | 846 | |
3b53fde8 | 847 | sta = sta_info_get_by_idx(sdata, idx); |
d0709a65 JB |
848 | if (sta) { |
849 | ret = 0; | |
17741cdc | 850 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
0fdf1493 | 851 | sta_set_sinfo(sta, sinfo, true); |
d0709a65 | 852 | } |
c5dd9c2b | 853 | |
d0709a65 | 854 | return ret; |
c5dd9c2b LCC |
855 | } |
856 | ||
1289723e HS |
857 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
858 | int idx, struct survey_info *survey) | |
859 | { | |
860 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
861 | ||
1289723e HS |
862 | return drv_get_survey(local, idx, survey); |
863 | } | |
864 | ||
7bbdd2d9 | 865 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
3b3a0162 | 866 | const u8 *mac, struct station_info *sinfo) |
7bbdd2d9 | 867 | { |
abe60632 | 868 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
66572cfc | 869 | struct ieee80211_local *local = sdata->local; |
7bbdd2d9 | 870 | struct sta_info *sta; |
d0709a65 | 871 | int ret = -ENOENT; |
7bbdd2d9 | 872 | |
4d3acf43 | 873 | lockdep_assert_wiphy(local->hw.wiphy); |
7bbdd2d9 | 874 | |
0e5ded5a | 875 | sta = sta_info_get_bss(sdata, mac); |
d0709a65 JB |
876 | if (sta) { |
877 | ret = 0; | |
0fdf1493 | 878 | sta_set_sinfo(sta, sinfo, true); |
d0709a65 JB |
879 | } |
880 | ||
d0709a65 | 881 | return ret; |
7bbdd2d9 JB |
882 | } |
883 | ||
55de908a | 884 | static int ieee80211_set_monitor_channel(struct wiphy *wiphy, |
683b6d3b | 885 | struct cfg80211_chan_def *chandef) |
3d9e6e12 JB |
886 | { |
887 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
55de908a | 888 | struct ieee80211_sub_if_data *sdata; |
6092077a | 889 | struct ieee80211_chan_req chanreq = { .oper = *chandef }; |
0a44dfc0 | 890 | int ret; |
3d9e6e12 | 891 | |
0cd8080e JB |
892 | lockdep_assert_wiphy(local->hw.wiphy); |
893 | ||
6092077a JB |
894 | if (cfg80211_chandef_identical(&local->monitor_chanreq.oper, |
895 | &chanreq.oper)) | |
55de908a | 896 | return 0; |
3d9e6e12 | 897 | |
0a44dfc0 JB |
898 | sdata = wiphy_dereference(local->hw.wiphy, |
899 | local->monitor_sdata); | |
900 | if (!sdata) | |
901 | goto done; | |
3d9e6e12 | 902 | |
6092077a JB |
903 | if (cfg80211_chandef_identical(&sdata->vif.bss_conf.chanreq.oper, |
904 | &chanreq.oper)) | |
0a44dfc0 | 905 | return 0; |
3d9e6e12 | 906 | |
0a44dfc0 | 907 | ieee80211_link_release_channel(&sdata->deflink); |
6092077a | 908 | ret = ieee80211_link_use_channel(&sdata->deflink, &chanreq, |
0a44dfc0 JB |
909 | IEEE80211_CHANCTX_EXCLUSIVE); |
910 | if (ret) | |
911 | return ret; | |
912 | done: | |
6092077a | 913 | local->monitor_chanreq = chanreq; |
0a44dfc0 | 914 | return 0; |
e8c9bd5b JB |
915 | } |
916 | ||
5f9404ab JC |
917 | static int |
918 | ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, | |
919 | const u8 *resp, size_t resp_len, | |
920 | const struct ieee80211_csa_settings *csa, | |
d9f83f22 ST |
921 | const struct ieee80211_color_change_settings *cca, |
922 | struct ieee80211_link_data *link) | |
02945821 | 923 | { |
aa7a0080 | 924 | struct probe_resp *new, *old; |
02945821 AN |
925 | |
926 | if (!resp || !resp_len) | |
aba4e6ff | 927 | return 1; |
02945821 | 928 | |
d9f83f22 | 929 | old = sdata_dereference(link->u.ap.probe_resp, sdata); |
02945821 | 930 | |
aa7a0080 | 931 | new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL); |
02945821 AN |
932 | if (!new) |
933 | return -ENOMEM; | |
934 | ||
aa7a0080 ES |
935 | new->len = resp_len; |
936 | memcpy(new->data, resp, resp_len); | |
02945821 | 937 | |
af296bdb | 938 | if (csa) |
8552a434 | 939 | memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp, |
af296bdb | 940 | csa->n_counter_offsets_presp * |
8552a434 | 941 | sizeof(new->cntdwn_counter_offsets[0])); |
5f9404ab JC |
942 | else if (cca) |
943 | new->cntdwn_counter_offsets[0] = cca->counter_offset_presp; | |
af296bdb | 944 | |
d9f83f22 | 945 | rcu_assign_pointer(link->u.ap.probe_resp, new); |
aa7a0080 ES |
946 | if (old) |
947 | kfree_rcu(old, rcu_head); | |
02945821 AN |
948 | |
949 | return 0; | |
950 | } | |
951 | ||
295b02c4 | 952 | static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata, |
d9f83f22 ST |
953 | struct cfg80211_fils_discovery *params, |
954 | struct ieee80211_link_data *link, | |
392d3dfd JB |
955 | struct ieee80211_bss_conf *link_conf, |
956 | u64 *changed) | |
295b02c4 AD |
957 | { |
958 | struct fils_discovery_data *new, *old = NULL; | |
959 | struct ieee80211_fils_discovery *fd; | |
960 | ||
3b1c256e AD |
961 | if (!params->update) |
962 | return 0; | |
295b02c4 | 963 | |
d9f83f22 | 964 | fd = &link_conf->fils_discovery; |
295b02c4 AD |
965 | fd->min_interval = params->min_interval; |
966 | fd->max_interval = params->max_interval; | |
967 | ||
d9f83f22 | 968 | old = sdata_dereference(link->u.ap.fils_discovery, sdata); |
295b02c4 AD |
969 | if (old) |
970 | kfree_rcu(old, rcu_head); | |
971 | ||
3b1c256e AD |
972 | if (params->tmpl && params->tmpl_len) { |
973 | new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); | |
974 | if (!new) | |
975 | return -ENOMEM; | |
976 | new->len = params->tmpl_len; | |
977 | memcpy(new->data, params->tmpl, params->tmpl_len); | |
978 | rcu_assign_pointer(link->u.ap.fils_discovery, new); | |
979 | } else { | |
980 | RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); | |
981 | } | |
982 | ||
392d3dfd JB |
983 | *changed |= BSS_CHANGED_FILS_DISCOVERY; |
984 | return 0; | |
295b02c4 AD |
985 | } |
986 | ||
632189a0 AD |
987 | static int |
988 | ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata, | |
d9f83f22 ST |
989 | struct cfg80211_unsol_bcast_probe_resp *params, |
990 | struct ieee80211_link_data *link, | |
178e9d6a JB |
991 | struct ieee80211_bss_conf *link_conf, |
992 | u64 *changed) | |
632189a0 AD |
993 | { |
994 | struct unsol_bcast_probe_resp_data *new, *old = NULL; | |
995 | ||
3b1c256e AD |
996 | if (!params->update) |
997 | return 0; | |
632189a0 | 998 | |
3b1c256e | 999 | link_conf->unsol_bcast_probe_resp_interval = params->interval; |
632189a0 | 1000 | |
3b1c256e | 1001 | old = sdata_dereference(link->u.ap.unsol_bcast_probe_resp, sdata); |
632189a0 AD |
1002 | if (old) |
1003 | kfree_rcu(old, rcu_head); | |
1004 | ||
3b1c256e AD |
1005 | if (params->tmpl && params->tmpl_len) { |
1006 | new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL); | |
1007 | if (!new) | |
1008 | return -ENOMEM; | |
1009 | new->len = params->tmpl_len; | |
1010 | memcpy(new->data, params->tmpl, params->tmpl_len); | |
1011 | rcu_assign_pointer(link->u.ap.unsol_bcast_probe_resp, new); | |
1012 | } else { | |
1013 | RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); | |
1014 | } | |
632189a0 | 1015 | |
178e9d6a JB |
1016 | *changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP; |
1017 | return 0; | |
632189a0 AD |
1018 | } |
1019 | ||
bc847970 PKC |
1020 | static int ieee80211_set_ftm_responder_params( |
1021 | struct ieee80211_sub_if_data *sdata, | |
1022 | const u8 *lci, size_t lci_len, | |
d9f83f22 ST |
1023 | const u8 *civicloc, size_t civicloc_len, |
1024 | struct ieee80211_bss_conf *link_conf) | |
bc847970 PKC |
1025 | { |
1026 | struct ieee80211_ftm_responder_params *new, *old; | |
bc847970 PKC |
1027 | u8 *pos; |
1028 | int len; | |
1029 | ||
554be833 JB |
1030 | if (!lci_len && !civicloc_len) |
1031 | return 0; | |
bc847970 | 1032 | |
d9f83f22 | 1033 | old = link_conf->ftmr_params; |
bc847970 PKC |
1034 | len = lci_len + civicloc_len; |
1035 | ||
1036 | new = kzalloc(sizeof(*new) + len, GFP_KERNEL); | |
1037 | if (!new) | |
1038 | return -ENOMEM; | |
1039 | ||
1040 | pos = (u8 *)(new + 1); | |
1041 | if (lci_len) { | |
1042 | new->lci_len = lci_len; | |
1043 | new->lci = pos; | |
1044 | memcpy(pos, lci, lci_len); | |
1045 | pos += lci_len; | |
1046 | } | |
1047 | ||
1048 | if (civicloc_len) { | |
1049 | new->civicloc_len = civicloc_len; | |
1050 | new->civicloc = pos; | |
1051 | memcpy(pos, civicloc, civicloc_len); | |
1052 | pos += civicloc_len; | |
1053 | } | |
1054 | ||
d9f83f22 | 1055 | link_conf->ftmr_params = new; |
bc847970 PKC |
1056 | kfree(old); |
1057 | ||
1058 | return 0; | |
1059 | } | |
1060 | ||
2b3171c6 LB |
1061 | static int |
1062 | ieee80211_copy_mbssid_beacon(u8 *pos, struct cfg80211_mbssid_elems *dst, | |
1063 | struct cfg80211_mbssid_elems *src) | |
1064 | { | |
1065 | int i, offset = 0; | |
1066 | ||
1067 | for (i = 0; i < src->cnt; i++) { | |
1068 | memcpy(pos + offset, src->elem[i].data, src->elem[i].len); | |
1069 | dst->elem[i].len = src->elem[i].len; | |
1070 | dst->elem[i].data = pos + offset; | |
1071 | offset += dst->elem[i].len; | |
1072 | } | |
1073 | dst->cnt = src->cnt; | |
1074 | ||
1075 | return offset; | |
1076 | } | |
1077 | ||
68b9bea2 AD |
1078 | static int |
1079 | ieee80211_copy_rnr_beacon(u8 *pos, struct cfg80211_rnr_elems *dst, | |
1080 | struct cfg80211_rnr_elems *src) | |
1081 | { | |
1082 | int i, offset = 0; | |
1083 | ||
1084 | for (i = 0; i < src->cnt; i++) { | |
1085 | memcpy(pos + offset, src->elem[i].data, src->elem[i].len); | |
1086 | dst->elem[i].len = src->elem[i].len; | |
1087 | dst->elem[i].data = pos + offset; | |
1088 | offset += dst->elem[i].len; | |
1089 | } | |
1090 | dst->cnt = src->cnt; | |
1091 | ||
1092 | return offset; | |
1093 | } | |
1094 | ||
15ddba5f A |
1095 | static int |
1096 | ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, | |
1097 | struct ieee80211_link_data *link, | |
1098 | struct cfg80211_beacon_data *params, | |
1099 | const struct ieee80211_csa_settings *csa, | |
1100 | const struct ieee80211_color_change_settings *cca, | |
1101 | u64 *changed) | |
5dfdaf58 | 1102 | { |
2b3171c6 | 1103 | struct cfg80211_mbssid_elems *mbssid = NULL; |
68b9bea2 | 1104 | struct cfg80211_rnr_elems *rnr = NULL; |
5dfdaf58 JB |
1105 | struct beacon_data *new, *old; |
1106 | int new_head_len, new_tail_len; | |
8860020e | 1107 | int size, err; |
15ddba5f | 1108 | u64 _changed = BSS_CHANGED_BEACON; |
d8675a63 | 1109 | struct ieee80211_bss_conf *link_conf = link->conf; |
5dfdaf58 | 1110 | |
d9f83f22 | 1111 | old = sdata_dereference(link->u.ap.beacon, sdata); |
5dfdaf58 | 1112 | |
5dfdaf58 JB |
1113 | /* Need to have a beacon head if we don't have one yet */ |
1114 | if (!params->head && !old) | |
8860020e | 1115 | return -EINVAL; |
5dfdaf58 JB |
1116 | |
1117 | /* new or old head? */ | |
1118 | if (params->head) | |
1119 | new_head_len = params->head_len; | |
1120 | else | |
1121 | new_head_len = old->head_len; | |
1122 | ||
1123 | /* new or old tail? */ | |
1124 | if (params->tail || !old) | |
1125 | /* params->tail_len will be zero for !params->tail */ | |
1126 | new_tail_len = params->tail_len; | |
1127 | else | |
1128 | new_tail_len = old->tail_len; | |
1129 | ||
1130 | size = sizeof(*new) + new_head_len + new_tail_len; | |
1131 | ||
2b3171c6 LB |
1132 | /* new or old multiple BSSID elements? */ |
1133 | if (params->mbssid_ies) { | |
1134 | mbssid = params->mbssid_ies; | |
1135 | size += struct_size(new->mbssid_ies, elem, mbssid->cnt); | |
68b9bea2 AD |
1136 | if (params->rnr_ies) { |
1137 | rnr = params->rnr_ies; | |
1138 | size += struct_size(new->rnr_ies, elem, rnr->cnt); | |
1139 | } | |
1140 | size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, | |
1141 | mbssid->cnt); | |
2b3171c6 LB |
1142 | } else if (old && old->mbssid_ies) { |
1143 | mbssid = old->mbssid_ies; | |
1144 | size += struct_size(new->mbssid_ies, elem, mbssid->cnt); | |
68b9bea2 AD |
1145 | if (old && old->rnr_ies) { |
1146 | rnr = old->rnr_ies; | |
1147 | size += struct_size(new->rnr_ies, elem, rnr->cnt); | |
1148 | } | |
1149 | size += ieee80211_get_mbssid_beacon_len(mbssid, rnr, | |
1150 | mbssid->cnt); | |
2b3171c6 LB |
1151 | } |
1152 | ||
5dfdaf58 JB |
1153 | new = kzalloc(size, GFP_KERNEL); |
1154 | if (!new) | |
1155 | return -ENOMEM; | |
1156 | ||
1157 | /* start filling the new info now */ | |
1158 | ||
5dfdaf58 JB |
1159 | /* |
1160 | * pointers go into the block we allocated, | |
68b9bea2 | 1161 | * memory is | beacon_data | head | tail | mbssid_ies | rnr_ies |
5dfdaf58 JB |
1162 | */ |
1163 | new->head = ((u8 *) new) + sizeof(*new); | |
1164 | new->tail = new->head + new_head_len; | |
1165 | new->head_len = new_head_len; | |
1166 | new->tail_len = new_tail_len; | |
2b3171c6 LB |
1167 | /* copy in optional mbssid_ies */ |
1168 | if (mbssid) { | |
1169 | u8 *pos = new->tail + new->tail_len; | |
1170 | ||
1171 | new->mbssid_ies = (void *)pos; | |
1172 | pos += struct_size(new->mbssid_ies, elem, mbssid->cnt); | |
68b9bea2 AD |
1173 | pos += ieee80211_copy_mbssid_beacon(pos, new->mbssid_ies, |
1174 | mbssid); | |
1175 | if (rnr) { | |
1176 | new->rnr_ies = (void *)pos; | |
1177 | pos += struct_size(new->rnr_ies, elem, rnr->cnt); | |
1178 | ieee80211_copy_rnr_beacon(pos, new->rnr_ies, rnr); | |
1179 | } | |
dde78aa5 | 1180 | /* update bssid_indicator */ |
d9f83f22 | 1181 | link_conf->bssid_indicator = |
dde78aa5 | 1182 | ilog2(__roundup_pow_of_two(mbssid->cnt + 1)); |
2b3171c6 | 1183 | } |
5dfdaf58 | 1184 | |
af296bdb | 1185 | if (csa) { |
8552a434 JC |
1186 | new->cntdwn_current_counter = csa->count; |
1187 | memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon, | |
af296bdb | 1188 | csa->n_counter_offsets_beacon * |
8552a434 | 1189 | sizeof(new->cntdwn_counter_offsets[0])); |
5f9404ab JC |
1190 | } else if (cca) { |
1191 | new->cntdwn_current_counter = cca->count; | |
1192 | new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon; | |
af296bdb MK |
1193 | } |
1194 | ||
5dfdaf58 JB |
1195 | /* copy in head */ |
1196 | if (params->head) | |
1197 | memcpy(new->head, params->head, new_head_len); | |
1198 | else | |
1199 | memcpy(new->head, old->head, new_head_len); | |
1200 | ||
1201 | /* copy in optional tail */ | |
1202 | if (params->tail) | |
1203 | memcpy(new->tail, params->tail, new_tail_len); | |
1204 | else | |
1205 | if (old) | |
1206 | memcpy(new->tail, old->tail, new_tail_len); | |
1207 | ||
02945821 | 1208 | err = ieee80211_set_probe_resp(sdata, params->probe_resp, |
d9f83f22 | 1209 | params->probe_resp_len, csa, cca, link); |
bcc27fab LB |
1210 | if (err < 0) { |
1211 | kfree(new); | |
8860020e | 1212 | return err; |
bcc27fab | 1213 | } |
8860020e | 1214 | if (err == 0) |
15ddba5f | 1215 | _changed |= BSS_CHANGED_AP_PROBE_RESP; |
02945821 | 1216 | |
bc847970 | 1217 | if (params->ftm_responder != -1) { |
d9f83f22 | 1218 | link_conf->ftm_responder = params->ftm_responder; |
bc847970 PKC |
1219 | err = ieee80211_set_ftm_responder_params(sdata, |
1220 | params->lci, | |
1221 | params->lci_len, | |
1222 | params->civicloc, | |
d9f83f22 ST |
1223 | params->civicloc_len, |
1224 | link_conf); | |
bc847970 | 1225 | |
bcc27fab LB |
1226 | if (err < 0) { |
1227 | kfree(new); | |
bc847970 | 1228 | return err; |
bcc27fab | 1229 | } |
bc847970 | 1230 | |
15ddba5f | 1231 | _changed |= BSS_CHANGED_FTM_RESPONDER; |
bc847970 PKC |
1232 | } |
1233 | ||
d9f83f22 | 1234 | rcu_assign_pointer(link->u.ap.beacon, new); |
bfd8403a | 1235 | sdata->u.ap.active = true; |
8860020e JB |
1236 | |
1237 | if (old) | |
1238 | kfree_rcu(old, rcu_head); | |
7827493b | 1239 | |
15ddba5f A |
1240 | *changed |= _changed; |
1241 | return 0; | |
5dfdaf58 JB |
1242 | } |
1243 | ||
8860020e JB |
1244 | static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, |
1245 | struct cfg80211_ap_settings *params) | |
5dfdaf58 | 1246 | { |
8860020e | 1247 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
34a3740d | 1248 | struct ieee80211_local *local = sdata->local; |
5dfdaf58 | 1249 | struct beacon_data *old; |
665c93a9 | 1250 | struct ieee80211_sub_if_data *vlan; |
2cc25e4b | 1251 | u64 changed = BSS_CHANGED_BEACON_INT | |
8860020e JB |
1252 | BSS_CHANGED_BEACON_ENABLED | |
1253 | BSS_CHANGED_BEACON | | |
4bcc56bb | 1254 | BSS_CHANGED_P2P_PS | |
a0de1ca3 | 1255 | BSS_CHANGED_TXPOWER | |
322cd27c | 1256 | BSS_CHANGED_TWT; |
08fad438 | 1257 | int i, err; |
83e37e0b | 1258 | int prev_beacon_int; |
d9f83f22 | 1259 | unsigned int link_id = params->beacon.link_id; |
d8675a63 JB |
1260 | struct ieee80211_link_data *link; |
1261 | struct ieee80211_bss_conf *link_conf; | |
6092077a | 1262 | struct ieee80211_chan_req chanreq = { .oper = params->chandef }; |
d8675a63 | 1263 | |
0cd8080e JB |
1264 | lockdep_assert_wiphy(local->hw.wiphy); |
1265 | ||
d8675a63 JB |
1266 | link = sdata_dereference(sdata->link[link_id], sdata); |
1267 | if (!link) | |
1268 | return -ENOLINK; | |
1269 | ||
1270 | link_conf = link->conf; | |
14db74bc | 1271 | |
d9f83f22 | 1272 | old = sdata_dereference(link->u.ap.beacon, sdata); |
5dfdaf58 JB |
1273 | if (old) |
1274 | return -EALREADY; | |
1275 | ||
52b4810b | 1276 | if (params->smps_mode != NL80211_SMPS_OFF) |
0528e0fd | 1277 | return -EOPNOTSUPP; |
52b4810b | 1278 | |
d9f83f22 | 1279 | link->smps_mode = IEEE80211_SMPS_OFF; |
b3dd8279 | 1280 | |
d9f83f22 | 1281 | link->needed_rx_chains = sdata->local->rx_chains; |
04ecd257 | 1282 | |
d9f83f22 ST |
1283 | prev_beacon_int = link_conf->beacon_int; |
1284 | link_conf->beacon_int = params->beacon_interval; | |
ac668afe | 1285 | |
2ad7dd94 RL |
1286 | if (params->ht_cap) |
1287 | link_conf->ht_ldpc = | |
1288 | params->ht_cap->cap_info & | |
1289 | cpu_to_le16(IEEE80211_HT_CAP_LDPC_CODING); | |
1290 | ||
42470fa0 | 1291 | if (params->vht_cap) { |
2ad7dd94 RL |
1292 | link_conf->vht_ldpc = |
1293 | params->vht_cap->vht_cap_info & | |
1294 | cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC); | |
42470fa0 MS |
1295 | link_conf->vht_su_beamformer = |
1296 | params->vht_cap->vht_cap_info & | |
1297 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
1298 | link_conf->vht_su_beamformee = | |
1299 | params->vht_cap->vht_cap_info & | |
1300 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); | |
1301 | link_conf->vht_mu_beamformer = | |
1302 | params->vht_cap->vht_cap_info & | |
1303 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
1304 | link_conf->vht_mu_beamformee = | |
1305 | params->vht_cap->vht_cap_info & | |
1306 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
1307 | } | |
1308 | ||
03efb863 | 1309 | if (params->he_cap && params->he_oper) { |
d9f83f22 ST |
1310 | link_conf->he_support = true; |
1311 | link_conf->htc_trig_based_pkt_ext = | |
03efb863 ST |
1312 | le32_get_bits(params->he_oper->he_oper_params, |
1313 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); | |
d9f83f22 | 1314 | link_conf->frame_time_rts_th = |
03efb863 ST |
1315 | le32_get_bits(params->he_oper->he_oper_params, |
1316 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); | |
322cd27c P |
1317 | changed |= BSS_CHANGED_HE_OBSS_PD; |
1318 | ||
3d48cb74 | 1319 | if (params->beacon.he_bss_color.enabled) |
322cd27c | 1320 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
03efb863 | 1321 | } |
34fb190e | 1322 | |
b1b3297d | 1323 | if (params->he_cap) { |
2ad7dd94 RL |
1324 | link_conf->he_ldpc = |
1325 | params->he_cap->phy_cap_info[1] & | |
1326 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD; | |
b1b3297d MS |
1327 | link_conf->he_su_beamformer = |
1328 | params->he_cap->phy_cap_info[3] & | |
1329 | IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER; | |
1330 | link_conf->he_su_beamformee = | |
1331 | params->he_cap->phy_cap_info[4] & | |
1332 | IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE; | |
1333 | link_conf->he_mu_beamformer = | |
1334 | params->he_cap->phy_cap_info[4] & | |
1335 | IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
1336 | link_conf->he_full_ul_mumimo = | |
1337 | params->he_cap->phy_cap_info[2] & | |
1338 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO; | |
1339 | } | |
1340 | ||
2cc25e4b | 1341 | if (params->eht_cap) { |
e3e0ca32 AD |
1342 | if (!link_conf->he_support) |
1343 | return -EOPNOTSUPP; | |
1344 | ||
1345 | link_conf->eht_support = true; | |
f4d1181e RL |
1346 | |
1347 | link_conf->eht_su_beamformer = | |
1348 | params->eht_cap->fixed.phy_cap_info[0] & | |
1349 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER; | |
1350 | link_conf->eht_su_beamformee = | |
1351 | params->eht_cap->fixed.phy_cap_info[0] & | |
1352 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE; | |
1353 | link_conf->eht_mu_beamformer = | |
1354 | params->eht_cap->fixed.phy_cap_info[7] & | |
1355 | (IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
1356 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
1357 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ); | |
1358 | } else { | |
1359 | link_conf->eht_su_beamformer = false; | |
1360 | link_conf->eht_su_beamformee = false; | |
1361 | link_conf->eht_mu_beamformer = false; | |
2cc25e4b AD |
1362 | } |
1363 | ||
17196425 JC |
1364 | if (sdata->vif.type == NL80211_IFTYPE_AP && |
1365 | params->mbssid_config.tx_wdev) { | |
1366 | err = ieee80211_set_ap_mbssid_options(sdata, | |
d9f83f22 ST |
1367 | params->mbssid_config, |
1368 | link_conf); | |
17196425 JC |
1369 | if (err) |
1370 | return err; | |
1371 | } | |
1372 | ||
6092077a | 1373 | err = ieee80211_link_use_channel(link, &chanreq, |
b4f85443 | 1374 | IEEE80211_CHANCTX_SHARED); |
4e141dad | 1375 | if (!err) |
d9f83f22 | 1376 | ieee80211_link_copy_chanctx_to_vlans(link, false); |
83e37e0b | 1377 | if (err) { |
d9f83f22 | 1378 | link_conf->beacon_int = prev_beacon_int; |
aa430da4 | 1379 | return err; |
83e37e0b | 1380 | } |
aa430da4 | 1381 | |
665c93a9 JB |
1382 | /* |
1383 | * Apply control port protocol, this allows us to | |
1384 | * not encrypt dynamic WEP control frames. | |
1385 | */ | |
1386 | sdata->control_port_protocol = params->crypto.control_port_ethertype; | |
1387 | sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; | |
018f6fbf DK |
1388 | sdata->control_port_over_nl80211 = |
1389 | params->crypto.control_port_over_nl80211; | |
7f3f96ce MT |
1390 | sdata->control_port_no_preauth = |
1391 | params->crypto.control_port_no_preauth; | |
2475b1cc | 1392 | |
665c93a9 JB |
1393 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { |
1394 | vlan->control_port_protocol = | |
1395 | params->crypto.control_port_ethertype; | |
1396 | vlan->control_port_no_encrypt = | |
1397 | params->crypto.control_port_no_encrypt; | |
018f6fbf DK |
1398 | vlan->control_port_over_nl80211 = |
1399 | params->crypto.control_port_over_nl80211; | |
7f3f96ce MT |
1400 | vlan->control_port_no_preauth = |
1401 | params->crypto.control_port_no_preauth; | |
665c93a9 JB |
1402 | } |
1403 | ||
d9f83f22 ST |
1404 | link_conf->dtim_period = params->dtim_period; |
1405 | link_conf->enable_beacon = true; | |
1406 | link_conf->allow_p2p_go_ps = sdata->vif.p2p; | |
1407 | link_conf->twt_responder = params->twt_responder; | |
1408 | link_conf->he_obss_pd = params->he_obss_pd; | |
1409 | link_conf->he_bss_color = params->beacon.he_bss_color; | |
f276e20b | 1410 | sdata->vif.cfg.s1g = params->chandef.chan->band == |
1d00ce80 | 1411 | NL80211_BAND_S1GHZ; |
8860020e | 1412 | |
f276e20b | 1413 | sdata->vif.cfg.ssid_len = params->ssid_len; |
8860020e | 1414 | if (params->ssid_len) |
f276e20b | 1415 | memcpy(sdata->vif.cfg.ssid, params->ssid, |
8860020e | 1416 | params->ssid_len); |
d9f83f22 | 1417 | link_conf->hidden_ssid = |
8860020e JB |
1418 | (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); |
1419 | ||
d9f83f22 ST |
1420 | memset(&link_conf->p2p_noa_attr, 0, |
1421 | sizeof(link_conf->p2p_noa_attr)); | |
1422 | link_conf->p2p_noa_attr.oppps_ctwindow = | |
67baf663 JD |
1423 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
1424 | if (params->p2p_opp_ps) | |
d9f83f22 | 1425 | link_conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 | 1426 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
339afbf4 | 1427 | |
08fad438 JM |
1428 | sdata->beacon_rate_set = false; |
1429 | if (wiphy_ext_feature_isset(local->hw.wiphy, | |
1430 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { | |
1431 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
1432 | sdata->beacon_rateidx_mask[i] = | |
1433 | params->beacon_rate.control[i].legacy; | |
1434 | if (sdata->beacon_rateidx_mask[i]) | |
1435 | sdata->beacon_rate_set = true; | |
1436 | } | |
1437 | } | |
1438 | ||
ba6ff70a | 1439 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) |
d9f83f22 | 1440 | link_conf->beacon_tx_rate = params->beacon_rate; |
ba6ff70a | 1441 | |
15ddba5f A |
1442 | err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL, |
1443 | &changed); | |
295b02c4 AD |
1444 | if (err < 0) |
1445 | goto error; | |
8860020e | 1446 | |
3b1c256e | 1447 | err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery, |
392d3dfd | 1448 | link, link_conf, &changed); |
3b1c256e AD |
1449 | if (err < 0) |
1450 | goto error; | |
295b02c4 | 1451 | |
3b1c256e AD |
1452 | err = ieee80211_set_unsol_bcast_probe_resp(sdata, |
1453 | ¶ms->unsol_bcast_probe_resp, | |
178e9d6a | 1454 | link, link_conf, &changed); |
3b1c256e AD |
1455 | if (err < 0) |
1456 | goto error; | |
632189a0 | 1457 | |
b327c84c | 1458 | err = drv_start_ap(sdata->local, sdata, link_conf); |
1041638f | 1459 | if (err) { |
d9f83f22 | 1460 | old = sdata_dereference(link->u.ap.beacon, sdata); |
7ca133bc | 1461 | |
1041638f JB |
1462 | if (old) |
1463 | kfree_rcu(old, rcu_head); | |
d9f83f22 | 1464 | RCU_INIT_POINTER(link->u.ap.beacon, NULL); |
bfd8403a | 1465 | sdata->u.ap.active = false; |
295b02c4 | 1466 | goto error; |
1041638f JB |
1467 | } |
1468 | ||
057d5f4b | 1469 | ieee80211_recalc_dtim(local, sdata); |
d9f83f22 | 1470 | ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID); |
d8675a63 | 1471 | ieee80211_link_info_change_notify(sdata, link, changed); |
8860020e | 1472 | |
3edaf3e6 JB |
1473 | netif_carrier_on(dev); |
1474 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) | |
1475 | netif_carrier_on(vlan->dev); | |
1476 | ||
665c93a9 | 1477 | return 0; |
295b02c4 AD |
1478 | |
1479 | error: | |
d9f83f22 | 1480 | ieee80211_link_release_channel(link); |
87a27062 | 1481 | |
295b02c4 | 1482 | return err; |
5dfdaf58 JB |
1483 | } |
1484 | ||
8860020e | 1485 | static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, |
bb55441c | 1486 | struct cfg80211_ap_update *params) |
66f85d57 | 1487 | |
5dfdaf58 | 1488 | { |
d9f83f22 | 1489 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
d8675a63 | 1490 | struct ieee80211_link_data *link; |
66f85d57 | 1491 | struct cfg80211_beacon_data *beacon = ¶ms->beacon; |
5dfdaf58 | 1492 | struct beacon_data *old; |
8860020e | 1493 | int err; |
d8675a63 | 1494 | struct ieee80211_bss_conf *link_conf; |
15ddba5f | 1495 | u64 changed = 0; |
5dfdaf58 | 1496 | |
076fc877 | 1497 | lockdep_assert_wiphy(wiphy); |
14db74bc | 1498 | |
66f85d57 | 1499 | link = sdata_dereference(sdata->link[beacon->link_id], sdata); |
d8675a63 JB |
1500 | if (!link) |
1501 | return -ENOLINK; | |
1502 | ||
1503 | link_conf = link->conf; | |
1504 | ||
5f9404ab | 1505 | /* don't allow changing the beacon while a countdown is in place - offset |
73da7d5b SW |
1506 | * of channel switch counter may change |
1507 | */ | |
d9f83f22 | 1508 | if (link_conf->csa_active || link_conf->color_change_active) |
73da7d5b SW |
1509 | return -EBUSY; |
1510 | ||
d8675a63 | 1511 | old = sdata_dereference(link->u.ap.beacon, sdata); |
5dfdaf58 JB |
1512 | if (!old) |
1513 | return -ENOENT; | |
1514 | ||
66f85d57 | 1515 | err = ieee80211_assign_beacon(sdata, link, beacon, NULL, NULL, |
15ddba5f | 1516 | &changed); |
8860020e JB |
1517 | if (err < 0) |
1518 | return err; | |
195b9a0f | 1519 | |
6bc5ddb2 | 1520 | err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery, |
392d3dfd | 1521 | link, link_conf, &changed); |
6bc5ddb2 AD |
1522 | if (err < 0) |
1523 | return err; | |
6bc5ddb2 AD |
1524 | |
1525 | err = ieee80211_set_unsol_bcast_probe_resp(sdata, | |
1526 | ¶ms->unsol_bcast_probe_resp, | |
178e9d6a | 1527 | link, link_conf, &changed); |
6bc5ddb2 AD |
1528 | if (err < 0) |
1529 | return err; | |
6bc5ddb2 | 1530 | |
66f85d57 AD |
1531 | if (beacon->he_bss_color_valid && |
1532 | beacon->he_bss_color.enabled != link_conf->he_bss_color.enabled) { | |
1533 | link_conf->he_bss_color.enabled = beacon->he_bss_color.enabled; | |
15ddba5f | 1534 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
195b9a0f LS |
1535 | } |
1536 | ||
15ddba5f | 1537 | ieee80211_link_info_change_notify(sdata, link, changed); |
8860020e | 1538 | return 0; |
5dfdaf58 JB |
1539 | } |
1540 | ||
d9f83f22 | 1541 | static void ieee80211_free_next_beacon(struct ieee80211_link_data *link) |
0baef284 | 1542 | { |
d9f83f22 | 1543 | if (!link->u.ap.next_beacon) |
0baef284 JB |
1544 | return; |
1545 | ||
d9f83f22 | 1546 | kfree(link->u.ap.next_beacon->mbssid_ies); |
68b9bea2 | 1547 | kfree(link->u.ap.next_beacon->rnr_ies); |
d9f83f22 ST |
1548 | kfree(link->u.ap.next_beacon); |
1549 | link->u.ap.next_beacon = NULL; | |
0baef284 JB |
1550 | } |
1551 | ||
7b0a0e3c JB |
1552 | static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, |
1553 | unsigned int link_id) | |
5dfdaf58 | 1554 | { |
7b20b8e8 JB |
1555 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1556 | struct ieee80211_sub_if_data *vlan; | |
1557 | struct ieee80211_local *local = sdata->local; | |
1558 | struct beacon_data *old_beacon; | |
1559 | struct probe_resp *old_probe_resp; | |
295b02c4 | 1560 | struct fils_discovery_data *old_fils_discovery; |
632189a0 | 1561 | struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp; |
d2859df5 | 1562 | struct cfg80211_chan_def chandef; |
d8675a63 JB |
1563 | struct ieee80211_link_data *link = |
1564 | sdata_dereference(sdata->link[link_id], sdata); | |
1565 | struct ieee80211_bss_conf *link_conf = link->conf; | |
1c0d21c4 | 1566 | LIST_HEAD(keys); |
14db74bc | 1567 | |
0cd8080e | 1568 | lockdep_assert_wiphy(local->hw.wiphy); |
dbd72850 | 1569 | |
d9f83f22 | 1570 | old_beacon = sdata_dereference(link->u.ap.beacon, sdata); |
7b20b8e8 | 1571 | if (!old_beacon) |
5dfdaf58 | 1572 | return -ENOENT; |
d9f83f22 | 1573 | old_probe_resp = sdata_dereference(link->u.ap.probe_resp, |
bfd8403a | 1574 | sdata); |
d9f83f22 | 1575 | old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery, |
295b02c4 | 1576 | sdata); |
632189a0 | 1577 | old_unsol_bcast_probe_resp = |
d9f83f22 | 1578 | sdata_dereference(link->u.ap.unsol_bcast_probe_resp, |
632189a0 | 1579 | sdata); |
5dfdaf58 | 1580 | |
a23d7f5b | 1581 | /* abort any running channel switch or color change */ |
d9f83f22 | 1582 | link_conf->csa_active = false; |
a23d7f5b | 1583 | link_conf->color_change_active = false; |
d9f83f22 | 1584 | if (link->csa_block_tx) { |
a46992b4 LC |
1585 | ieee80211_wake_vif_queues(local, sdata, |
1586 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
d9f83f22 | 1587 | link->csa_block_tx = false; |
a46992b4 LC |
1588 | } |
1589 | ||
d9f83f22 | 1590 | ieee80211_free_next_beacon(link); |
1f3b8a2b | 1591 | |
7b20b8e8 | 1592 | /* turn off carrier for this interface and dependent VLANs */ |
3edaf3e6 JB |
1593 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
1594 | netif_carrier_off(vlan->dev); | |
1595 | netif_carrier_off(dev); | |
1596 | ||
7b20b8e8 | 1597 | /* remove beacon and probe response */ |
bfd8403a | 1598 | sdata->u.ap.active = false; |
d9f83f22 ST |
1599 | RCU_INIT_POINTER(link->u.ap.beacon, NULL); |
1600 | RCU_INIT_POINTER(link->u.ap.probe_resp, NULL); | |
1601 | RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); | |
1602 | RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); | |
7b20b8e8 JB |
1603 | kfree_rcu(old_beacon, rcu_head); |
1604 | if (old_probe_resp) | |
1605 | kfree_rcu(old_probe_resp, rcu_head); | |
295b02c4 AD |
1606 | if (old_fils_discovery) |
1607 | kfree_rcu(old_fils_discovery, rcu_head); | |
632189a0 AD |
1608 | if (old_unsol_bcast_probe_resp) |
1609 | kfree_rcu(old_unsol_bcast_probe_resp, rcu_head); | |
8860020e | 1610 | |
d9f83f22 ST |
1611 | kfree(link_conf->ftmr_params); |
1612 | link_conf->ftmr_params = NULL; | |
bc847970 | 1613 | |
0eb38842 AD |
1614 | sdata->vif.mbssid_tx_vif = NULL; |
1615 | link_conf->bssid_index = 0; | |
1616 | link_conf->nontransmitted = false; | |
1617 | link_conf->ema_ap = false; | |
1618 | link_conf->bssid_indicator = 0; | |
1619 | ||
16405bd7 | 1620 | __sta_info_flush(sdata, true, link_id); |
1c0d21c4 RS |
1621 | |
1622 | ieee80211_remove_link_keys(link, &keys); | |
1623 | if (!list_empty(&keys)) { | |
1624 | synchronize_net(); | |
1625 | ieee80211_free_key_list(local, &keys); | |
1626 | } | |
75de9113 | 1627 | |
d9f83f22 | 1628 | link_conf->enable_beacon = false; |
08fad438 | 1629 | sdata->beacon_rate_set = false; |
f276e20b | 1630 | sdata->vif.cfg.ssid_len = 0; |
d6a83228 | 1631 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
d8675a63 | 1632 | ieee80211_link_info_change_notify(sdata, link, |
7fc83a2b | 1633 | BSS_CHANGED_BEACON_ENABLED); |
8860020e | 1634 | |
a6b368f6 | 1635 | if (sdata->wdev.cac_started) { |
6092077a | 1636 | chandef = link_conf->chanreq.oper; |
766d2601 | 1637 | wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work); |
d2859df5 JD |
1638 | cfg80211_cac_event(sdata->dev, &chandef, |
1639 | NL80211_RADAR_CAC_ABORTED, | |
a6b368f6 SW |
1640 | GFP_KERNEL); |
1641 | } | |
1642 | ||
b327c84c | 1643 | drv_stop_ap(sdata->local, sdata, link_conf); |
1041638f | 1644 | |
7b20b8e8 JB |
1645 | /* free all potentially still buffered bcast frames */ |
1646 | local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); | |
6b07d9ca | 1647 | ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf); |
7b20b8e8 | 1648 | |
d9f83f22 ST |
1649 | ieee80211_link_copy_chanctx_to_vlans(link, true); |
1650 | ieee80211_link_release_channel(link); | |
55de908a | 1651 | |
2d0ddec5 | 1652 | return 0; |
5dfdaf58 JB |
1653 | } |
1654 | ||
d582cffb JB |
1655 | static int sta_apply_auth_flags(struct ieee80211_local *local, |
1656 | struct sta_info *sta, | |
1657 | u32 mask, u32 set) | |
1658 | { | |
1659 | int ret; | |
1660 | ||
1661 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1662 | set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1663 | !test_sta_flag(sta, WLAN_STA_AUTH)) { | |
1664 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); | |
1665 | if (ret) | |
1666 | return ret; | |
1667 | } | |
1668 | ||
1669 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1670 | set & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1671 | !test_sta_flag(sta, WLAN_STA_ASSOC)) { | |
c23e31cf MP |
1672 | /* |
1673 | * When peer becomes associated, init rate control as | |
1674 | * well. Some drivers require rate control initialized | |
1675 | * before drv_sta_state() is called. | |
1676 | */ | |
44674d9c | 1677 | if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) |
c23e31cf MP |
1678 | rate_control_rate_init(sta); |
1679 | ||
d582cffb JB |
1680 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
1681 | if (ret) | |
1682 | return ret; | |
1683 | } | |
1684 | ||
1685 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
1686 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
1687 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); | |
1688 | else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
1689 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); | |
1690 | else | |
1691 | ret = 0; | |
1692 | if (ret) | |
1693 | return ret; | |
1694 | } | |
1695 | ||
1696 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1697 | !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) && | |
1698 | test_sta_flag(sta, WLAN_STA_ASSOC)) { | |
1699 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); | |
1700 | if (ret) | |
1701 | return ret; | |
1702 | } | |
1703 | ||
1704 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1705 | !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) && | |
1706 | test_sta_flag(sta, WLAN_STA_AUTH)) { | |
1707 | ret = sta_info_move_state(sta, IEEE80211_STA_NONE); | |
1708 | if (ret) | |
1709 | return ret; | |
1710 | } | |
1711 | ||
1712 | return 0; | |
1713 | } | |
1714 | ||
13657702 JB |
1715 | static void sta_apply_mesh_params(struct ieee80211_local *local, |
1716 | struct sta_info *sta, | |
1717 | struct station_parameters *params) | |
1718 | { | |
1719 | #ifdef CONFIG_MAC80211_MESH | |
1720 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
15ddba5f | 1721 | u64 changed = 0; |
13657702 JB |
1722 | |
1723 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) { | |
1724 | switch (params->plink_state) { | |
1725 | case NL80211_PLINK_ESTAB: | |
1726 | if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) | |
1727 | changed = mesh_plink_inc_estab_count(sdata); | |
1728 | sta->mesh->plink_state = params->plink_state; | |
7d27a0ba | 1729 | sta->mesh->aid = params->peer_aid; |
13657702 JB |
1730 | |
1731 | ieee80211_mps_sta_status_update(sta); | |
1732 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1733 | sdata->u.mesh.mshcfg.power_mode); | |
67fc0554 JH |
1734 | |
1735 | ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg); | |
1736 | /* init at low value */ | |
1737 | ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10); | |
1738 | ||
13657702 JB |
1739 | break; |
1740 | case NL80211_PLINK_LISTEN: | |
1741 | case NL80211_PLINK_BLOCKED: | |
1742 | case NL80211_PLINK_OPN_SNT: | |
1743 | case NL80211_PLINK_OPN_RCVD: | |
1744 | case NL80211_PLINK_CNF_RCVD: | |
1745 | case NL80211_PLINK_HOLDING: | |
1746 | if (sta->mesh->plink_state == NL80211_PLINK_ESTAB) | |
1747 | changed = mesh_plink_dec_estab_count(sdata); | |
1748 | sta->mesh->plink_state = params->plink_state; | |
1749 | ||
1750 | ieee80211_mps_sta_status_update(sta); | |
1751 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1752 | NL80211_MESH_POWER_UNKNOWN); | |
1753 | break; | |
1754 | default: | |
1755 | /* nothing */ | |
1756 | break; | |
1757 | } | |
1758 | } | |
1759 | ||
1760 | switch (params->plink_action) { | |
1761 | case NL80211_PLINK_ACTION_NO_ACTION: | |
1762 | /* nothing */ | |
1763 | break; | |
1764 | case NL80211_PLINK_ACTION_OPEN: | |
1765 | changed |= mesh_plink_open(sta); | |
1766 | break; | |
1767 | case NL80211_PLINK_ACTION_BLOCK: | |
1768 | changed |= mesh_plink_block(sta); | |
1769 | break; | |
1770 | } | |
1771 | ||
1772 | if (params->local_pm) | |
1773 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1774 | params->local_pm); | |
1775 | ||
1776 | ieee80211_mbss_info_change_notify(sdata, changed); | |
1777 | #endif | |
1778 | } | |
1779 | ||
b95eb7f0 | 1780 | static int sta_link_apply_parameters(struct ieee80211_local *local, |
9aebce6c | 1781 | struct sta_info *sta, bool new_link, |
b95eb7f0 ST |
1782 | struct link_station_parameters *params) |
1783 | { | |
1784 | int ret = 0; | |
1785 | struct ieee80211_supported_band *sband; | |
1786 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
1787 | u32 link_id = params->link_id < 0 ? 0 : params->link_id; | |
d8675a63 JB |
1788 | struct ieee80211_link_data *link = |
1789 | sdata_dereference(sdata->link[link_id], sdata); | |
b95eb7f0 ST |
1790 | struct link_sta_info *link_sta = |
1791 | rcu_dereference_protected(sta->link[link_id], | |
4d3acf43 | 1792 | lockdep_is_held(&local->hw.wiphy->mtx)); |
b95eb7f0 | 1793 | |
b303835d | 1794 | /* |
c1393c13 | 1795 | * If there are no changes, then accept a link that exist, |
b303835d JB |
1796 | * unless it's a new link. |
1797 | */ | |
c1393c13 | 1798 | if (params->link_id >= 0 && !new_link && |
b303835d JB |
1799 | !params->link_mac && !params->txpwr_set && |
1800 | !params->supported_rates_len && | |
1801 | !params->ht_capa && !params->vht_capa && | |
1802 | !params->he_capa && !params->eht_capa && | |
1803 | !params->opmode_notif_used) | |
1804 | return 0; | |
1805 | ||
d8675a63 | 1806 | if (!link || !link_sta) |
b95eb7f0 ST |
1807 | return -EINVAL; |
1808 | ||
d8675a63 | 1809 | sband = ieee80211_get_link_sband(link); |
b95eb7f0 ST |
1810 | if (!sband) |
1811 | return -EINVAL; | |
1812 | ||
1813 | if (params->link_mac) { | |
9aebce6c JB |
1814 | if (new_link) { |
1815 | memcpy(link_sta->addr, params->link_mac, ETH_ALEN); | |
1816 | memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN); | |
1817 | } else if (!ether_addr_equal(link_sta->addr, | |
1818 | params->link_mac)) { | |
1819 | return -EINVAL; | |
1820 | } | |
b303835d JB |
1821 | } else if (new_link) { |
1822 | return -EINVAL; | |
b95eb7f0 ST |
1823 | } |
1824 | ||
1825 | if (params->txpwr_set) { | |
1826 | link_sta->pub->txpwr.type = params->txpwr.type; | |
1827 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) | |
1828 | link_sta->pub->txpwr.power = params->txpwr.power; | |
1829 | ret = drv_sta_set_txpwr(local, sdata, sta); | |
1830 | if (ret) | |
1831 | return ret; | |
1832 | } | |
1833 | ||
1834 | if (params->supported_rates && | |
1835 | params->supported_rates_len) { | |
6092077a | 1836 | ieee80211_parse_bitrates(link->conf->chanreq.oper.width, |
b95eb7f0 ST |
1837 | sband, params->supported_rates, |
1838 | params->supported_rates_len, | |
1839 | &link_sta->pub->supp_rates[sband->band]); | |
1840 | } | |
1841 | ||
1842 | if (params->ht_capa) | |
1843 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, | |
1844 | params->ht_capa, link_sta); | |
1845 | ||
1846 | /* VHT can override some HT caps such as the A-MSDU max length */ | |
1847 | if (params->vht_capa) | |
1848 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, | |
084cf2ae JB |
1849 | params->vht_capa, NULL, |
1850 | link_sta); | |
b95eb7f0 ST |
1851 | |
1852 | if (params->he_capa) | |
1853 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, | |
1854 | (void *)params->he_capa, | |
1855 | params->he_capa_len, | |
1856 | (void *)params->he_6ghz_capa, | |
1857 | link_sta); | |
1858 | ||
e8edb346 | 1859 | if (params->he_capa && params->eht_capa) |
b95eb7f0 ST |
1860 | ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband, |
1861 | (u8 *)params->he_capa, | |
1862 | params->he_capa_len, | |
1863 | params->eht_capa, | |
1864 | params->eht_capa_len, | |
1865 | link_sta); | |
1866 | ||
1867 | if (params->opmode_notif_used) { | |
1868 | /* returned value is only needed for rc update, but the | |
1869 | * rc isn't initialized here yet, so ignore it | |
1870 | */ | |
1871 | __ieee80211_vht_handle_opmode(sdata, link_sta, | |
1872 | params->opmode_notif, | |
1873 | sband->band); | |
1874 | } | |
1875 | ||
a8bca3e9 | 1876 | ieee80211_sta_init_nss(link_sta); |
dd6c064c | 1877 | |
b95eb7f0 ST |
1878 | return ret; |
1879 | } | |
1880 | ||
d9a7ddb0 JB |
1881 | static int sta_apply_parameters(struct ieee80211_local *local, |
1882 | struct sta_info *sta, | |
1883 | struct station_parameters *params) | |
4fd6931e | 1884 | { |
d0709a65 | 1885 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
eccb8e8f | 1886 | u32 mask, set; |
45b12570 | 1887 | int ret = 0; |
ae5eb026 | 1888 | |
eccb8e8f JB |
1889 | mask = params->sta_flags_mask; |
1890 | set = params->sta_flags_set; | |
73651ee6 | 1891 | |
d582cffb JB |
1892 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
1893 | /* | |
1894 | * In mesh mode, ASSOCIATED isn't part of the nl80211 | |
1895 | * API but must follow AUTHENTICATED for driver state. | |
1896 | */ | |
1897 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
1898 | mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1899 | if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
1900 | set |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
77ee7c89 JB |
1901 | } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
1902 | /* | |
1903 | * TDLS -- everything follows authorized, but | |
1904 | * only becoming authorized is possible, not | |
1905 | * going back | |
1906 | */ | |
1907 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
1908 | set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
1909 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1910 | mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
1911 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1912 | } | |
eccb8e8f | 1913 | } |
4fd6931e | 1914 | |
2c44be81 JB |
1915 | if (mask & BIT(NL80211_STA_FLAG_WME) && |
1916 | local->hw.queues >= IEEE80211_NUM_ACS) | |
1917 | sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME); | |
1918 | ||
44674d9c | 1919 | /* auth flags will be set later for TDLS, |
b18dacab | 1920 | * and for unassociated stations that move to associated */ |
44674d9c AB |
1921 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
1922 | !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) && | |
1923 | (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) { | |
68885a54 AN |
1924 | ret = sta_apply_auth_flags(local, sta, mask, set); |
1925 | if (ret) | |
1926 | return ret; | |
1927 | } | |
d9a7ddb0 | 1928 | |
eccb8e8f | 1929 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
eccb8e8f | 1930 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
c2c98fde JB |
1931 | set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
1932 | else | |
1933 | clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); | |
eccb8e8f | 1934 | } |
4fd6931e | 1935 | |
eccb8e8f | 1936 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
93f0490e | 1937 | sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP)); |
eccb8e8f | 1938 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
c2c98fde JB |
1939 | set_sta_flag(sta, WLAN_STA_MFP); |
1940 | else | |
1941 | clear_sta_flag(sta, WLAN_STA_MFP); | |
4fd6931e | 1942 | } |
b39c48fa | 1943 | |
07ba55d7 | 1944 | if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { |
07ba55d7 | 1945 | if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
c2c98fde JB |
1946 | set_sta_flag(sta, WLAN_STA_TDLS_PEER); |
1947 | else | |
1948 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER); | |
07ba55d7 | 1949 | } |
4fd6931e | 1950 | |
3b220ed8 JB |
1951 | if (mask & BIT(NL80211_STA_FLAG_SPP_AMSDU)) |
1952 | sta->sta.spp_amsdu = set & BIT(NL80211_STA_FLAG_SPP_AMSDU); | |
1953 | ||
9041c1fa AN |
1954 | /* mark TDLS channel switch support, if the AP allows it */ |
1955 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && | |
ab3a830d | 1956 | !sdata->deflink.u.mgd.tdls_chan_switch_prohibited && |
9041c1fa AN |
1957 | params->ext_capab_len >= 4 && |
1958 | params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) | |
1959 | set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH); | |
1960 | ||
b98fb44f | 1961 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
82c0cc90 | 1962 | !sdata->u.mgd.tdls_wider_bw_prohibited && |
b98fb44f AN |
1963 | ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && |
1964 | params->ext_capab_len >= 8 && | |
1965 | params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) | |
1966 | set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW); | |
1967 | ||
3b9ce80c JB |
1968 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { |
1969 | sta->sta.uapsd_queues = params->uapsd_queues; | |
1970 | sta->sta.max_sp = params->max_sp; | |
1971 | } | |
9533b4ac | 1972 | |
175ad2ec JB |
1973 | ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab, |
1974 | params->ext_capab_len); | |
506bcfa8 | 1975 | |
51b50fbe JB |
1976 | /* |
1977 | * cfg80211 validates this (1-2007) and allows setting the AID | |
1978 | * only when creating a new station entry | |
1979 | */ | |
1980 | if (params->aid) | |
1981 | sta->sta.aid = params->aid; | |
1982 | ||
73651ee6 | 1983 | /* |
ba23d206 JB |
1984 | * Some of the following updates would be racy if called on an |
1985 | * existing station, via ieee80211_change_station(). However, | |
1986 | * all such changes are rejected by cfg80211 except for updates | |
1987 | * changing the supported rates on an existing but not yet used | |
1988 | * TDLS peer. | |
73651ee6 JB |
1989 | */ |
1990 | ||
4fd6931e JB |
1991 | if (params->listen_interval >= 0) |
1992 | sta->listen_interval = params->listen_interval; | |
1993 | ||
9aebce6c JB |
1994 | ret = sta_link_apply_parameters(local, sta, false, |
1995 | ¶ms->link_sta_params); | |
b95eb7f0 ST |
1996 | if (ret) |
1997 | return ret; | |
b1bce14a | 1998 | |
52cfa1d6 AB |
1999 | if (params->support_p2p_ps >= 0) |
2000 | sta->sta.support_p2p_ps = params->support_p2p_ps; | |
2001 | ||
13657702 JB |
2002 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
2003 | sta_apply_mesh_params(local, sta, params); | |
d9a7ddb0 | 2004 | |
b4809e94 | 2005 | if (params->airtime_weight) |
942741da | 2006 | sta->airtime_weight = params->airtime_weight; |
b4809e94 | 2007 | |
68885a54 | 2008 | /* set the STA state after all sta info from usermode has been set */ |
44674d9c AB |
2009 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || |
2010 | set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { | |
68885a54 AN |
2011 | ret = sta_apply_auth_flags(local, sta, mask, set); |
2012 | if (ret) | |
2013 | return ret; | |
2014 | } | |
2015 | ||
3e0278b7 AO |
2016 | /* Mark the STA as MLO if MLD MAC address is available */ |
2017 | if (params->link_sta_params.mld_mac) | |
2018 | sta->sta.mlo = true; | |
2019 | ||
d9a7ddb0 | 2020 | return 0; |
4fd6931e JB |
2021 | } |
2022 | ||
2023 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 JB |
2024 | const u8 *mac, |
2025 | struct station_parameters *params) | |
4fd6931e | 2026 | { |
14db74bc | 2027 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
2028 | struct sta_info *sta; |
2029 | struct ieee80211_sub_if_data *sdata; | |
73651ee6 | 2030 | int err; |
4fd6931e | 2031 | |
4d3acf43 JB |
2032 | lockdep_assert_wiphy(local->hw.wiphy); |
2033 | ||
4fd6931e JB |
2034 | if (params->vlan) { |
2035 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); | |
2036 | ||
05c914fe JB |
2037 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
2038 | sdata->vif.type != NL80211_IFTYPE_AP) | |
4fd6931e JB |
2039 | return -EINVAL; |
2040 | } else | |
2041 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2042 | ||
b203ca39 | 2043 | if (ether_addr_equal(mac, sdata->vif.addr)) |
03e4497e JB |
2044 | return -EINVAL; |
2045 | ||
52dba8d7 | 2046 | if (!is_valid_ether_addr(mac)) |
03e4497e JB |
2047 | return -EINVAL; |
2048 | ||
5fd2f91a JB |
2049 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) && |
2050 | sdata->vif.type == NL80211_IFTYPE_STATION && | |
2051 | !sdata->u.mgd.associated) | |
2052 | return -EINVAL; | |
2053 | ||
206c8c06 JB |
2054 | /* |
2055 | * If we have a link ID, it can be a non-MLO station on an AP MLD, | |
2056 | * but we need to have a link_mac in that case as well, so use the | |
2057 | * STA's MAC address in that case. | |
2058 | */ | |
f36fe0a2 JB |
2059 | if (params->link_sta_params.link_id >= 0) |
2060 | sta = sta_info_alloc_with_link(sdata, mac, | |
2061 | params->link_sta_params.link_id, | |
206c8c06 | 2062 | params->link_sta_params.link_mac ?: mac, |
f36fe0a2 JB |
2063 | GFP_KERNEL); |
2064 | else | |
2065 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); | |
2066 | ||
73651ee6 JB |
2067 | if (!sta) |
2068 | return -ENOMEM; | |
4fd6931e | 2069 | |
44674d9c AB |
2070 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
2071 | sta->sta.tdls = true; | |
4fd6931e | 2072 | |
b95eb7f0 ST |
2073 | /* Though the mutex is not needed here (since the station is not |
2074 | * visible yet), sta_apply_parameters (and inner functions) require | |
2075 | * the mutex due to other paths. | |
2076 | */ | |
d9a7ddb0 JB |
2077 | err = sta_apply_parameters(local, sta, params); |
2078 | if (err) { | |
2079 | sta_info_free(local, sta); | |
2080 | return err; | |
2081 | } | |
4fd6931e | 2082 | |
d64cf63e | 2083 | /* |
44674d9c AB |
2084 | * for TDLS and for unassociated station, rate control should be |
2085 | * initialized only when rates are known and station is marked | |
2086 | * authorized/associated | |
d64cf63e | 2087 | */ |
44674d9c AB |
2088 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
2089 | test_sta_flag(sta, WLAN_STA_ASSOC)) | |
d64cf63e | 2090 | rate_control_rate_init(sta); |
4fd6931e | 2091 | |
4ebdce1d | 2092 | return sta_info_insert(sta); |
4fd6931e JB |
2093 | } |
2094 | ||
2095 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, | |
89c771e5 | 2096 | struct station_del_parameters *params) |
4fd6931e | 2097 | { |
14db74bc | 2098 | struct ieee80211_sub_if_data *sdata; |
4fd6931e | 2099 | |
14db74bc JB |
2100 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2101 | ||
89c771e5 JM |
2102 | if (params->mac) |
2103 | return sta_info_destroy_addr_bss(sdata, params->mac); | |
4fd6931e | 2104 | |
ec67d6e0 | 2105 | sta_info_flush(sdata, params->link_id); |
4fd6931e JB |
2106 | return 0; |
2107 | } | |
2108 | ||
2109 | static int ieee80211_change_station(struct wiphy *wiphy, | |
3b3a0162 | 2110 | struct net_device *dev, const u8 *mac, |
4fd6931e JB |
2111 | struct station_parameters *params) |
2112 | { | |
abe60632 | 2113 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
14db74bc | 2114 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
2115 | struct sta_info *sta; |
2116 | struct ieee80211_sub_if_data *vlansdata; | |
77ee7c89 | 2117 | enum cfg80211_station_type statype; |
35b88623 | 2118 | int err; |
4fd6931e | 2119 | |
4d3acf43 | 2120 | lockdep_assert_wiphy(local->hw.wiphy); |
98dd6a57 | 2121 | |
0e5ded5a | 2122 | sta = sta_info_get_bss(sdata, mac); |
4d3acf43 JB |
2123 | if (!sta) |
2124 | return -ENOENT; | |
4fd6931e | 2125 | |
77ee7c89 JB |
2126 | switch (sdata->vif.type) { |
2127 | case NL80211_IFTYPE_MESH_POINT: | |
a6dad6a2 | 2128 | if (sdata->u.mesh.user_mpm) |
eef941e6 | 2129 | statype = CFG80211_STA_MESH_PEER_USER; |
77ee7c89 | 2130 | else |
eef941e6 | 2131 | statype = CFG80211_STA_MESH_PEER_KERNEL; |
77ee7c89 JB |
2132 | break; |
2133 | case NL80211_IFTYPE_ADHOC: | |
2134 | statype = CFG80211_STA_IBSS; | |
2135 | break; | |
2136 | case NL80211_IFTYPE_STATION: | |
2137 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { | |
2138 | statype = CFG80211_STA_AP_STA; | |
2139 | break; | |
2140 | } | |
2141 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
2142 | statype = CFG80211_STA_TDLS_PEER_ACTIVE; | |
2143 | else | |
2144 | statype = CFG80211_STA_TDLS_PEER_SETUP; | |
2145 | break; | |
2146 | case NL80211_IFTYPE_AP: | |
2147 | case NL80211_IFTYPE_AP_VLAN: | |
44674d9c AB |
2148 | if (test_sta_flag(sta, WLAN_STA_ASSOC)) |
2149 | statype = CFG80211_STA_AP_CLIENT; | |
2150 | else | |
2151 | statype = CFG80211_STA_AP_CLIENT_UNASSOC; | |
77ee7c89 JB |
2152 | break; |
2153 | default: | |
4d3acf43 | 2154 | return -EOPNOTSUPP; |
bdd90d5e JB |
2155 | } |
2156 | ||
77ee7c89 JB |
2157 | err = cfg80211_check_station_change(wiphy, params, statype); |
2158 | if (err) | |
4d3acf43 | 2159 | return err; |
77ee7c89 | 2160 | |
d0709a65 | 2161 | if (params->vlan && params->vlan != sta->sdata->dev) { |
4fd6931e JB |
2162 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
2163 | ||
9bc383de | 2164 | if (params->vlan->ieee80211_ptr->use_4addr) { |
4d3acf43 JB |
2165 | if (vlansdata->u.vlan.sta) |
2166 | return -EBUSY; | |
f14543ee | 2167 | |
cf778b00 | 2168 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); |
49ddf8e6 | 2169 | __ieee80211_check_fast_rx_iface(vlansdata); |
1ff4e8f2 | 2170 | drv_sta_set_4addr(local, sta->sdata, &sta->sta, true); |
7e3ed02c FF |
2171 | } |
2172 | ||
2173 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | |
dd0b4553 SM |
2174 | sta->sdata->u.vlan.sta) { |
2175 | ieee80211_clear_fast_rx(sta); | |
0c2bef46 | 2176 | RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); |
dd0b4553 | 2177 | } |
72f15d53 MB |
2178 | |
2179 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
2180 | ieee80211_vif_dec_num_mcast(sta->sdata); | |
f14543ee | 2181 | |
14db74bc | 2182 | sta->sdata = vlansdata; |
464daaf0 | 2183 | ieee80211_check_fast_xmit(sta); |
7e3ed02c | 2184 | |
3e493173 | 2185 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { |
72f15d53 | 2186 | ieee80211_vif_inc_num_mcast(sta->sdata); |
3e493173 JM |
2187 | cfg80211_send_layer2_update(sta->sdata->dev, |
2188 | sta->sta.addr); | |
2189 | } | |
4fd6931e JB |
2190 | } |
2191 | ||
076fc877 | 2192 | err = sta_apply_parameters(local, sta, params); |
77ee7c89 | 2193 | if (err) |
4d3acf43 | 2194 | return err; |
98dd6a57 | 2195 | |
808118cb | 2196 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
ab095877 | 2197 | params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
4a733ef1 | 2198 | ieee80211_recalc_ps(local); |
ab095877 EP |
2199 | ieee80211_recalc_ps_vif(sdata); |
2200 | } | |
77ee7c89 | 2201 | |
4fd6931e JB |
2202 | return 0; |
2203 | } | |
2204 | ||
c5dd9c2b LCC |
2205 | #ifdef CONFIG_MAC80211_MESH |
2206 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 | 2207 | const u8 *dst, const u8 *next_hop) |
c5dd9c2b | 2208 | { |
14db74bc | 2209 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2210 | struct mesh_path *mpath; |
2211 | struct sta_info *sta; | |
c5dd9c2b | 2212 | |
14db74bc JB |
2213 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2214 | ||
d0709a65 | 2215 | rcu_read_lock(); |
abe60632 | 2216 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
2217 | if (!sta) { |
2218 | rcu_read_unlock(); | |
c5dd9c2b | 2219 | return -ENOENT; |
d0709a65 | 2220 | } |
c5dd9c2b | 2221 | |
ae76eef0 BC |
2222 | mpath = mesh_path_add(sdata, dst); |
2223 | if (IS_ERR(mpath)) { | |
d0709a65 | 2224 | rcu_read_unlock(); |
ae76eef0 | 2225 | return PTR_ERR(mpath); |
d0709a65 | 2226 | } |
c5dd9c2b | 2227 | |
c5dd9c2b | 2228 | mesh_path_fix_nexthop(mpath, sta); |
d0709a65 | 2229 | |
c5dd9c2b LCC |
2230 | rcu_read_unlock(); |
2231 | return 0; | |
2232 | } | |
2233 | ||
2234 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 | 2235 | const u8 *dst) |
c5dd9c2b | 2236 | { |
f698d856 JBG |
2237 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2238 | ||
c5dd9c2b | 2239 | if (dst) |
bf7cd94d | 2240 | return mesh_path_del(sdata, dst); |
c5dd9c2b | 2241 | |
ece1a2e7 | 2242 | mesh_path_flush_by_iface(sdata); |
c5dd9c2b LCC |
2243 | return 0; |
2244 | } | |
2245 | ||
3b3a0162 JB |
2246 | static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, |
2247 | const u8 *dst, const u8 *next_hop) | |
c5dd9c2b | 2248 | { |
14db74bc | 2249 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2250 | struct mesh_path *mpath; |
2251 | struct sta_info *sta; | |
2252 | ||
14db74bc JB |
2253 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2254 | ||
d0709a65 JB |
2255 | rcu_read_lock(); |
2256 | ||
abe60632 | 2257 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
2258 | if (!sta) { |
2259 | rcu_read_unlock(); | |
c5dd9c2b | 2260 | return -ENOENT; |
d0709a65 | 2261 | } |
c5dd9c2b | 2262 | |
bf7cd94d | 2263 | mpath = mesh_path_lookup(sdata, dst); |
c5dd9c2b LCC |
2264 | if (!mpath) { |
2265 | rcu_read_unlock(); | |
c5dd9c2b LCC |
2266 | return -ENOENT; |
2267 | } | |
2268 | ||
2269 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 2270 | |
c5dd9c2b LCC |
2271 | rcu_read_unlock(); |
2272 | return 0; | |
2273 | } | |
2274 | ||
2275 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, | |
2276 | struct mpath_info *pinfo) | |
2277 | { | |
a3836e02 JB |
2278 | struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); |
2279 | ||
2280 | if (next_hop_sta) | |
2281 | memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); | |
c5dd9c2b | 2282 | else |
c84a67a2 | 2283 | eth_zero_addr(next_hop); |
c5dd9c2b | 2284 | |
7ce8c7a3 LAYS |
2285 | memset(pinfo, 0, sizeof(*pinfo)); |
2286 | ||
2bdaf386 | 2287 | pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; |
f5ea9120 | 2288 | |
c5dd9c2b | 2289 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
d19b3bf6 | 2290 | MPATH_INFO_SN | |
c5dd9c2b LCC |
2291 | MPATH_INFO_METRIC | |
2292 | MPATH_INFO_EXPTIME | | |
2293 | MPATH_INFO_DISCOVERY_TIMEOUT | | |
2294 | MPATH_INFO_DISCOVERY_RETRIES | | |
cc241636 | 2295 | MPATH_INFO_FLAGS | |
540bbcb9 JH |
2296 | MPATH_INFO_HOP_COUNT | |
2297 | MPATH_INFO_PATH_CHANGE; | |
c5dd9c2b LCC |
2298 | |
2299 | pinfo->frame_qlen = mpath->frame_queue.qlen; | |
d19b3bf6 | 2300 | pinfo->sn = mpath->sn; |
c5dd9c2b LCC |
2301 | pinfo->metric = mpath->metric; |
2302 | if (time_before(jiffies, mpath->exp_time)) | |
2303 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); | |
2304 | pinfo->discovery_timeout = | |
2305 | jiffies_to_msecs(mpath->discovery_timeout); | |
2306 | pinfo->discovery_retries = mpath->discovery_retries; | |
c5dd9c2b LCC |
2307 | if (mpath->flags & MESH_PATH_ACTIVE) |
2308 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; | |
2309 | if (mpath->flags & MESH_PATH_RESOLVING) | |
2310 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
d19b3bf6 RP |
2311 | if (mpath->flags & MESH_PATH_SN_VALID) |
2312 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; | |
c5dd9c2b LCC |
2313 | if (mpath->flags & MESH_PATH_FIXED) |
2314 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; | |
7ce8c7a3 LAYS |
2315 | if (mpath->flags & MESH_PATH_RESOLVED) |
2316 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; | |
cc241636 | 2317 | pinfo->hop_count = mpath->hop_count; |
540bbcb9 | 2318 | pinfo->path_change_count = mpath->path_change_count; |
c5dd9c2b LCC |
2319 | } |
2320 | ||
2321 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, | |
2322 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) | |
2323 | ||
2324 | { | |
14db74bc | 2325 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2326 | struct mesh_path *mpath; |
2327 | ||
14db74bc JB |
2328 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2329 | ||
c5dd9c2b | 2330 | rcu_read_lock(); |
bf7cd94d | 2331 | mpath = mesh_path_lookup(sdata, dst); |
c5dd9c2b LCC |
2332 | if (!mpath) { |
2333 | rcu_read_unlock(); | |
2334 | return -ENOENT; | |
2335 | } | |
2336 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2337 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
2338 | rcu_read_unlock(); | |
2339 | return 0; | |
2340 | } | |
2341 | ||
2342 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 JB |
2343 | int idx, u8 *dst, u8 *next_hop, |
2344 | struct mpath_info *pinfo) | |
c5dd9c2b | 2345 | { |
14db74bc | 2346 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2347 | struct mesh_path *mpath; |
2348 | ||
14db74bc JB |
2349 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2350 | ||
c5dd9c2b | 2351 | rcu_read_lock(); |
bf7cd94d | 2352 | mpath = mesh_path_lookup_by_idx(sdata, idx); |
c5dd9c2b LCC |
2353 | if (!mpath) { |
2354 | rcu_read_unlock(); | |
2355 | return -ENOENT; | |
2356 | } | |
2357 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2358 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
2359 | rcu_read_unlock(); | |
2360 | return 0; | |
2361 | } | |
93da9cc1 | 2362 | |
a2db2ed3 HR |
2363 | static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, |
2364 | struct mpath_info *pinfo) | |
2365 | { | |
2366 | memset(pinfo, 0, sizeof(*pinfo)); | |
2367 | memcpy(mpp, mpath->mpp, ETH_ALEN); | |
2368 | ||
2bdaf386 | 2369 | pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; |
a2db2ed3 HR |
2370 | } |
2371 | ||
2372 | static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, | |
2373 | u8 *dst, u8 *mpp, struct mpath_info *pinfo) | |
2374 | ||
2375 | { | |
2376 | struct ieee80211_sub_if_data *sdata; | |
2377 | struct mesh_path *mpath; | |
2378 | ||
2379 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2380 | ||
2381 | rcu_read_lock(); | |
2382 | mpath = mpp_path_lookup(sdata, dst); | |
2383 | if (!mpath) { | |
2384 | rcu_read_unlock(); | |
2385 | return -ENOENT; | |
2386 | } | |
2387 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2388 | mpp_set_pinfo(mpath, mpp, pinfo); | |
2389 | rcu_read_unlock(); | |
2390 | return 0; | |
2391 | } | |
2392 | ||
2393 | static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, | |
2394 | int idx, u8 *dst, u8 *mpp, | |
2395 | struct mpath_info *pinfo) | |
2396 | { | |
2397 | struct ieee80211_sub_if_data *sdata; | |
2398 | struct mesh_path *mpath; | |
2399 | ||
2400 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2401 | ||
2402 | rcu_read_lock(); | |
2403 | mpath = mpp_path_lookup_by_idx(sdata, idx); | |
2404 | if (!mpath) { | |
2405 | rcu_read_unlock(); | |
2406 | return -ENOENT; | |
2407 | } | |
2408 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2409 | mpp_set_pinfo(mpath, mpp, pinfo); | |
2410 | rcu_read_unlock(); | |
2411 | return 0; | |
2412 | } | |
2413 | ||
24bdd9f4 | 2414 | static int ieee80211_get_mesh_config(struct wiphy *wiphy, |
93da9cc1 | 2415 | struct net_device *dev, |
2416 | struct mesh_config *conf) | |
2417 | { | |
2418 | struct ieee80211_sub_if_data *sdata; | |
2419 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2420 | ||
93da9cc1 | 2421 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
2422 | return 0; | |
2423 | } | |
2424 | ||
2425 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) | |
2426 | { | |
2427 | return (mask >> (parm-1)) & 0x1; | |
2428 | } | |
2429 | ||
c80d545d JC |
2430 | static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, |
2431 | const struct mesh_setup *setup) | |
2432 | { | |
2433 | u8 *new_ie; | |
4bb62344 CYY |
2434 | struct ieee80211_sub_if_data *sdata = container_of(ifmsh, |
2435 | struct ieee80211_sub_if_data, u.mesh); | |
08fad438 | 2436 | int i; |
c80d545d | 2437 | |
581a8b0f | 2438 | /* allocate information elements */ |
c80d545d | 2439 | new_ie = NULL; |
c80d545d | 2440 | |
581a8b0f JC |
2441 | if (setup->ie_len) { |
2442 | new_ie = kmemdup(setup->ie, setup->ie_len, | |
c80d545d JC |
2443 | GFP_KERNEL); |
2444 | if (!new_ie) | |
2445 | return -ENOMEM; | |
2446 | } | |
581a8b0f JC |
2447 | ifmsh->ie_len = setup->ie_len; |
2448 | ifmsh->ie = new_ie; | |
c80d545d JC |
2449 | |
2450 | /* now copy the rest of the setup parameters */ | |
2451 | ifmsh->mesh_id_len = setup->mesh_id_len; | |
2452 | memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); | |
d299a1f2 | 2453 | ifmsh->mesh_sp_id = setup->sync_method; |
c80d545d JC |
2454 | ifmsh->mesh_pp_id = setup->path_sel_proto; |
2455 | ifmsh->mesh_pm_id = setup->path_metric; | |
a6dad6a2 | 2456 | ifmsh->user_mpm = setup->user_mpm; |
0d4261ad | 2457 | ifmsh->mesh_auth_id = setup->auth_id; |
b130e5ce | 2458 | ifmsh->security = IEEE80211_MESH_SEC_NONE; |
0ab2e55d | 2459 | ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; |
b130e5ce JC |
2460 | if (setup->is_authenticated) |
2461 | ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; | |
2462 | if (setup->is_secure) | |
2463 | ifmsh->security |= IEEE80211_MESH_SEC_SECURED; | |
c80d545d | 2464 | |
4bb62344 CYY |
2465 | /* mcast rate setting in Mesh Node */ |
2466 | memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, | |
2467 | sizeof(setup->mcast_rate)); | |
ffb3cf30 | 2468 | sdata->vif.bss_conf.basic_rates = setup->basic_rates; |
4bb62344 | 2469 | |
9bdbf04d MP |
2470 | sdata->vif.bss_conf.beacon_int = setup->beacon_interval; |
2471 | sdata->vif.bss_conf.dtim_period = setup->dtim_period; | |
2472 | ||
08fad438 JM |
2473 | sdata->beacon_rate_set = false; |
2474 | if (wiphy_ext_feature_isset(sdata->local->hw.wiphy, | |
2475 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { | |
2476 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
2477 | sdata->beacon_rateidx_mask[i] = | |
2478 | setup->beacon_rate.control[i].legacy; | |
2479 | if (sdata->beacon_rateidx_mask[i]) | |
2480 | sdata->beacon_rate_set = true; | |
2481 | } | |
2482 | } | |
2483 | ||
c80d545d JC |
2484 | return 0; |
2485 | } | |
2486 | ||
24bdd9f4 | 2487 | static int ieee80211_update_mesh_config(struct wiphy *wiphy, |
29cbe68c JB |
2488 | struct net_device *dev, u32 mask, |
2489 | const struct mesh_config *nconf) | |
93da9cc1 | 2490 | { |
2491 | struct mesh_config *conf; | |
2492 | struct ieee80211_sub_if_data *sdata; | |
63c5723b RP |
2493 | struct ieee80211_if_mesh *ifmsh; |
2494 | ||
93da9cc1 | 2495 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
63c5723b | 2496 | ifmsh = &sdata->u.mesh; |
93da9cc1 | 2497 | |
93da9cc1 | 2498 | /* Set the config options which we are interested in setting */ |
2499 | conf = &(sdata->u.mesh.mshcfg); | |
2500 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) | |
2501 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; | |
2502 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) | |
2503 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; | |
2504 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) | |
2505 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; | |
2506 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) | |
2507 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; | |
2508 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) | |
2509 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; | |
2510 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) | |
2511 | conf->dot11MeshTTL = nconf->dot11MeshTTL; | |
45904f21 | 2512 | if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) |
58886a90 | 2513 | conf->element_ttl = nconf->element_ttl; |
146bb483 TP |
2514 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { |
2515 | if (ifmsh->user_mpm) | |
2516 | return -EBUSY; | |
93da9cc1 | 2517 | conf->auto_open_plinks = nconf->auto_open_plinks; |
146bb483 | 2518 | } |
d299a1f2 JC |
2519 | if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) |
2520 | conf->dot11MeshNbrOffsetMaxNeighbor = | |
2521 | nconf->dot11MeshNbrOffsetMaxNeighbor; | |
93da9cc1 | 2522 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
2523 | conf->dot11MeshHWMPmaxPREQretries = | |
2524 | nconf->dot11MeshHWMPmaxPREQretries; | |
2525 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) | |
2526 | conf->path_refresh_time = nconf->path_refresh_time; | |
2527 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) | |
2528 | conf->min_discovery_timeout = nconf->min_discovery_timeout; | |
2529 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) | |
2530 | conf->dot11MeshHWMPactivePathTimeout = | |
2531 | nconf->dot11MeshHWMPactivePathTimeout; | |
2532 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) | |
2533 | conf->dot11MeshHWMPpreqMinInterval = | |
2534 | nconf->dot11MeshHWMPpreqMinInterval; | |
dca7e943 TP |
2535 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) |
2536 | conf->dot11MeshHWMPperrMinInterval = | |
2537 | nconf->dot11MeshHWMPperrMinInterval; | |
93da9cc1 | 2538 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
2539 | mask)) | |
2540 | conf->dot11MeshHWMPnetDiameterTraversalTime = | |
2541 | nconf->dot11MeshHWMPnetDiameterTraversalTime; | |
63c5723b RP |
2542 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
2543 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; | |
2544 | ieee80211_mesh_root_setup(ifmsh); | |
2545 | } | |
16dd7267 | 2546 | if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { |
c6133661 TP |
2547 | /* our current gate announcement implementation rides on root |
2548 | * announcements, so require this ifmsh to also be a root node | |
2549 | * */ | |
2550 | if (nconf->dot11MeshGateAnnouncementProtocol && | |
dbb912cd CYY |
2551 | !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { |
2552 | conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; | |
c6133661 TP |
2553 | ieee80211_mesh_root_setup(ifmsh); |
2554 | } | |
16dd7267 JC |
2555 | conf->dot11MeshGateAnnouncementProtocol = |
2556 | nconf->dot11MeshGateAnnouncementProtocol; | |
2557 | } | |
a4f606ea | 2558 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) |
0507e159 JC |
2559 | conf->dot11MeshHWMPRannInterval = |
2560 | nconf->dot11MeshHWMPRannInterval; | |
94f90656 CYY |
2561 | if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) |
2562 | conf->dot11MeshForwarding = nconf->dot11MeshForwarding; | |
55335137 AN |
2563 | if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { |
2564 | /* our RSSI threshold implementation is supported only for | |
2565 | * devices that report signal in dBm. | |
2566 | */ | |
30686bf7 | 2567 | if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) |
0528e0fd | 2568 | return -EOPNOTSUPP; |
55335137 AN |
2569 | conf->rssi_threshold = nconf->rssi_threshold; |
2570 | } | |
70c33eaa AN |
2571 | if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { |
2572 | conf->ht_opmode = nconf->ht_opmode; | |
2573 | sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; | |
d8675a63 JB |
2574 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
2575 | BSS_CHANGED_HT); | |
70c33eaa | 2576 | } |
ac1073a6 CYY |
2577 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) |
2578 | conf->dot11MeshHWMPactivePathToRootTimeout = | |
2579 | nconf->dot11MeshHWMPactivePathToRootTimeout; | |
2580 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) | |
2581 | conf->dot11MeshHWMProotInterval = | |
2582 | nconf->dot11MeshHWMProotInterval; | |
728b19e5 CYY |
2583 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) |
2584 | conf->dot11MeshHWMPconfirmationInterval = | |
2585 | nconf->dot11MeshHWMPconfirmationInterval; | |
3f52b7e3 MP |
2586 | if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { |
2587 | conf->power_mode = nconf->power_mode; | |
2588 | ieee80211_mps_local_status_update(sdata); | |
2589 | } | |
2b5e1967 | 2590 | if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) |
3f52b7e3 MP |
2591 | conf->dot11MeshAwakeWindowDuration = |
2592 | nconf->dot11MeshAwakeWindowDuration; | |
66de6713 CT |
2593 | if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) |
2594 | conf->plink_timeout = nconf->plink_timeout; | |
01d66fbd BC |
2595 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask)) |
2596 | conf->dot11MeshConnectedToMeshGate = | |
2597 | nconf->dot11MeshConnectedToMeshGate; | |
e3718a61 LL |
2598 | if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask)) |
2599 | conf->dot11MeshNolearn = nconf->dot11MeshNolearn; | |
184eebe6 MT |
2600 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask)) |
2601 | conf->dot11MeshConnectedToAuthServer = | |
2602 | nconf->dot11MeshConnectedToAuthServer; | |
2b5e1967 | 2603 | ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
93da9cc1 | 2604 | return 0; |
2605 | } | |
2606 | ||
29cbe68c JB |
2607 | static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, |
2608 | const struct mesh_config *conf, | |
2609 | const struct mesh_setup *setup) | |
2610 | { | |
2611 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 2612 | struct ieee80211_chan_req chanreq = { .oper = setup->chandef }; |
29cbe68c | 2613 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
c80d545d | 2614 | int err; |
29cbe68c | 2615 | |
0cd8080e JB |
2616 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
2617 | ||
c80d545d JC |
2618 | memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); |
2619 | err = copy_mesh_setup(ifmsh, setup); | |
2620 | if (err) | |
2621 | return err; | |
cc1d2806 | 2622 | |
018f6fbf DK |
2623 | sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; |
2624 | ||
04ecd257 | 2625 | /* can mesh use other SMPS modes? */ |
bfd8403a JB |
2626 | sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; |
2627 | sdata->deflink.needed_rx_chains = sdata->local->rx_chains; | |
04ecd257 | 2628 | |
6092077a | 2629 | err = ieee80211_link_use_channel(&sdata->deflink, &chanreq, |
b4f85443 | 2630 | IEEE80211_CHANCTX_SHARED); |
cc1d2806 JB |
2631 | if (err) |
2632 | return err; | |
2633 | ||
2b5e1967 | 2634 | return ieee80211_start_mesh(sdata); |
29cbe68c JB |
2635 | } |
2636 | ||
2637 | static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) | |
2638 | { | |
2639 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2640 | ||
0cd8080e JB |
2641 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
2642 | ||
29cbe68c | 2643 | ieee80211_stop_mesh(sdata); |
d8675a63 | 2644 | ieee80211_link_release_channel(&sdata->deflink); |
6a01afcf | 2645 | kfree(sdata->u.mesh.ie); |
29cbe68c JB |
2646 | |
2647 | return 0; | |
2648 | } | |
c5dd9c2b LCC |
2649 | #endif |
2650 | ||
9f1ba906 JM |
2651 | static int ieee80211_change_bss(struct wiphy *wiphy, |
2652 | struct net_device *dev, | |
2653 | struct bss_parameters *params) | |
2654 | { | |
55de908a | 2655 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
9a886df0 | 2656 | struct ieee80211_link_data *link; |
21a8e9dd | 2657 | struct ieee80211_supported_band *sband; |
15ddba5f | 2658 | u64 changed = 0; |
9f1ba906 | 2659 | |
9a886df0 JB |
2660 | link = ieee80211_link_or_deflink(sdata, params->link_id, true); |
2661 | if (IS_ERR(link)) | |
2662 | return PTR_ERR(link); | |
2663 | ||
2664 | if (!sdata_dereference(link->u.ap.beacon, sdata)) | |
55de908a JB |
2665 | return -ENOENT; |
2666 | ||
9a886df0 | 2667 | sband = ieee80211_get_link_sband(link); |
21a8e9dd MSS |
2668 | if (!sband) |
2669 | return -EINVAL; | |
9f1ba906 | 2670 | |
ce04abc3 | 2671 | if (params->basic_rates) { |
6092077a | 2672 | if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width, |
ce04abc3 JB |
2673 | wiphy->bands[sband->band], |
2674 | params->basic_rates, | |
2675 | params->basic_rates_len, | |
2676 | &link->conf->basic_rates)) | |
2677 | return -EINVAL; | |
2678 | changed |= BSS_CHANGED_BASIC_RATES; | |
2679 | ieee80211_check_rate_mask(link); | |
2680 | } | |
2681 | ||
9f1ba906 | 2682 | if (params->use_cts_prot >= 0) { |
9a886df0 | 2683 | link->conf->use_cts_prot = params->use_cts_prot; |
9f1ba906 JM |
2684 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
2685 | } | |
2686 | if (params->use_short_preamble >= 0) { | |
9a886df0 | 2687 | link->conf->use_short_preamble = params->use_short_preamble; |
9f1ba906 JM |
2688 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
2689 | } | |
43d35343 | 2690 | |
9a886df0 | 2691 | if (!link->conf->use_short_slot && |
07c12d61 TM |
2692 | (sband->band == NL80211_BAND_5GHZ || |
2693 | sband->band == NL80211_BAND_6GHZ)) { | |
9a886df0 | 2694 | link->conf->use_short_slot = true; |
43d35343 FF |
2695 | changed |= BSS_CHANGED_ERP_SLOT; |
2696 | } | |
2697 | ||
9f1ba906 | 2698 | if (params->use_short_slot_time >= 0) { |
9a886df0 | 2699 | link->conf->use_short_slot = params->use_short_slot_time; |
9f1ba906 JM |
2700 | changed |= BSS_CHANGED_ERP_SLOT; |
2701 | } | |
2702 | ||
7b7b5e56 FF |
2703 | if (params->ap_isolate >= 0) { |
2704 | if (params->ap_isolate) | |
2705 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
2706 | else | |
2707 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
49ddf8e6 | 2708 | ieee80211_check_fast_rx_iface(sdata); |
7b7b5e56 FF |
2709 | } |
2710 | ||
80d7e403 | 2711 | if (params->ht_opmode >= 0) { |
9a886df0 | 2712 | link->conf->ht_operation_mode = (u16)params->ht_opmode; |
80d7e403 HS |
2713 | changed |= BSS_CHANGED_HT; |
2714 | } | |
2715 | ||
339afbf4 | 2716 | if (params->p2p_ctwindow >= 0) { |
9a886df0 | 2717 | link->conf->p2p_noa_attr.oppps_ctwindow &= |
67baf663 | 2718 | ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
9a886df0 | 2719 | link->conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 | 2720 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
339afbf4 JB |
2721 | changed |= BSS_CHANGED_P2P_PS; |
2722 | } | |
2723 | ||
67baf663 | 2724 | if (params->p2p_opp_ps > 0) { |
9a886df0 | 2725 | link->conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 JD |
2726 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
2727 | changed |= BSS_CHANGED_P2P_PS; | |
2728 | } else if (params->p2p_opp_ps == 0) { | |
9a886df0 | 2729 | link->conf->p2p_noa_attr.oppps_ctwindow &= |
67baf663 | 2730 | ~IEEE80211_P2P_OPPPS_ENABLE_BIT; |
339afbf4 JB |
2731 | changed |= BSS_CHANGED_P2P_PS; |
2732 | } | |
2733 | ||
9a886df0 | 2734 | ieee80211_link_info_change_notify(sdata, link, changed); |
9f1ba906 JM |
2735 | |
2736 | return 0; | |
2737 | } | |
2738 | ||
31888487 | 2739 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
f70f01c2 | 2740 | struct net_device *dev, |
31888487 JM |
2741 | struct ieee80211_txq_params *params) |
2742 | { | |
2743 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
f6f3def3 | 2744 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
c88f1542 | 2745 | struct ieee80211_link_data *link = |
ccdde7c7 | 2746 | ieee80211_link_or_deflink(sdata, params->link_id, true); |
31888487 JM |
2747 | struct ieee80211_tx_queue_params p; |
2748 | ||
2749 | if (!local->ops->conf_tx) | |
2750 | return -EOPNOTSUPP; | |
2751 | ||
54bcbc69 JB |
2752 | if (local->hw.queues < IEEE80211_NUM_ACS) |
2753 | return -EOPNOTSUPP; | |
2754 | ||
c88f1542 ST |
2755 | if (IS_ERR(link)) |
2756 | return PTR_ERR(link); | |
2757 | ||
31888487 JM |
2758 | memset(&p, 0, sizeof(p)); |
2759 | p.aifs = params->aifs; | |
2760 | p.cw_max = params->cwmax; | |
2761 | p.cw_min = params->cwmin; | |
2762 | p.txop = params->txop; | |
ab13315a KV |
2763 | |
2764 | /* | |
2765 | * Setting tx queue params disables u-apsd because it's only | |
2766 | * called in master mode. | |
2767 | */ | |
2768 | p.uapsd = false; | |
2769 | ||
e552af05 HD |
2770 | ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); |
2771 | ||
b3e2130b JB |
2772 | link->tx_conf[params->ac] = p; |
2773 | if (drv_conf_tx(local, link, params->ac, &p)) { | |
0fb9a9ec | 2774 | wiphy_debug(local->hw.wiphy, |
a3304b0a JB |
2775 | "failed to set TX queue parameters for AC %d\n", |
2776 | params->ac); | |
31888487 JM |
2777 | return -EINVAL; |
2778 | } | |
2779 | ||
b3e2130b | 2780 | ieee80211_link_info_change_notify(sdata, link, |
d8675a63 | 2781 | BSS_CHANGED_QOS); |
7d25745d | 2782 | |
31888487 JM |
2783 | return 0; |
2784 | } | |
2785 | ||
665af4fc | 2786 | #ifdef CONFIG_PM |
ff1b6e69 JB |
2787 | static int ieee80211_suspend(struct wiphy *wiphy, |
2788 | struct cfg80211_wowlan *wowlan) | |
665af4fc | 2789 | { |
eecc4800 | 2790 | return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); |
665af4fc BC |
2791 | } |
2792 | ||
2793 | static int ieee80211_resume(struct wiphy *wiphy) | |
2794 | { | |
2795 | return __ieee80211_resume(wiphy_priv(wiphy)); | |
2796 | } | |
2797 | #else | |
2798 | #define ieee80211_suspend NULL | |
2799 | #define ieee80211_resume NULL | |
2800 | #endif | |
2801 | ||
2a519311 | 2802 | static int ieee80211_scan(struct wiphy *wiphy, |
2a519311 JB |
2803 | struct cfg80211_scan_request *req) |
2804 | { | |
fd014284 JB |
2805 | struct ieee80211_sub_if_data *sdata; |
2806 | ||
2807 | sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); | |
2a519311 | 2808 | |
2ca27bcf JB |
2809 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
2810 | case NL80211_IFTYPE_STATION: | |
2811 | case NL80211_IFTYPE_ADHOC: | |
2812 | case NL80211_IFTYPE_MESH_POINT: | |
2813 | case NL80211_IFTYPE_P2P_CLIENT: | |
f142c6b9 | 2814 | case NL80211_IFTYPE_P2P_DEVICE: |
2ca27bcf JB |
2815 | break; |
2816 | case NL80211_IFTYPE_P2P_GO: | |
2817 | if (sdata->local->ops->hw_scan) | |
2818 | break; | |
e9d7732e JB |
2819 | /* |
2820 | * FIXME: implement NoA while scanning in software, | |
2821 | * for now fall through to allow scanning only when | |
2822 | * beaconing hasn't been configured yet | |
2823 | */ | |
fc0561dc | 2824 | fallthrough; |
2ca27bcf | 2825 | case NL80211_IFTYPE_AP: |
5c95b940 AQ |
2826 | /* |
2827 | * If the scan has been forced (and the driver supports | |
2828 | * forcing), don't care about being beaconing already. | |
2829 | * This will create problems to the attached stations (e.g. all | |
71a659bf | 2830 | * the frames sent while scanning on other channel will be |
5c95b940 AQ |
2831 | * lost) |
2832 | */ | |
bfd8403a | 2833 | if (sdata->deflink.u.ap.beacon && |
5c95b940 AQ |
2834 | (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || |
2835 | !(req->flags & NL80211_SCAN_FLAG_AP))) | |
2ca27bcf JB |
2836 | return -EOPNOTSUPP; |
2837 | break; | |
cb3b7d87 | 2838 | case NL80211_IFTYPE_NAN: |
2ca27bcf JB |
2839 | default: |
2840 | return -EOPNOTSUPP; | |
2841 | } | |
2a519311 JB |
2842 | |
2843 | return ieee80211_request_scan(sdata, req); | |
2844 | } | |
2845 | ||
91f123f2 VK |
2846 | static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) |
2847 | { | |
2848 | ieee80211_scan_cancel(wiphy_priv(wiphy)); | |
2849 | } | |
2850 | ||
79f460ca LC |
2851 | static int |
2852 | ieee80211_sched_scan_start(struct wiphy *wiphy, | |
2853 | struct net_device *dev, | |
2854 | struct cfg80211_sched_scan_request *req) | |
2855 | { | |
2856 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2857 | ||
2858 | if (!sdata->local->ops->sched_scan_start) | |
2859 | return -EOPNOTSUPP; | |
2860 | ||
2861 | return ieee80211_request_sched_scan_start(sdata, req); | |
2862 | } | |
2863 | ||
2864 | static int | |
3a3ecf1d AVS |
2865 | ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, |
2866 | u64 reqid) | |
79f460ca | 2867 | { |
0d440ea2 | 2868 | struct ieee80211_local *local = wiphy_priv(wiphy); |
79f460ca | 2869 | |
0d440ea2 | 2870 | if (!local->ops->sched_scan_stop) |
79f460ca LC |
2871 | return -EOPNOTSUPP; |
2872 | ||
0d440ea2 | 2873 | return ieee80211_request_sched_scan_stop(local); |
79f460ca LC |
2874 | } |
2875 | ||
636a5d36 JM |
2876 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
2877 | struct cfg80211_auth_request *req) | |
2878 | { | |
77fdaa12 | 2879 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2880 | } |
2881 | ||
2882 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, | |
2883 | struct cfg80211_assoc_request *req) | |
2884 | { | |
77fdaa12 | 2885 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2886 | } |
2887 | ||
2888 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, | |
63c9c5e7 | 2889 | struct cfg80211_deauth_request *req) |
636a5d36 | 2890 | { |
63c9c5e7 | 2891 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2892 | } |
2893 | ||
2894 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, | |
63c9c5e7 | 2895 | struct cfg80211_disassoc_request *req) |
636a5d36 | 2896 | { |
63c9c5e7 | 2897 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2898 | } |
2899 | ||
af8cdcd8 JB |
2900 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
2901 | struct cfg80211_ibss_params *params) | |
2902 | { | |
55de908a | 2903 | return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); |
af8cdcd8 JB |
2904 | } |
2905 | ||
2906 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) | |
2907 | { | |
55de908a | 2908 | return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
af8cdcd8 JB |
2909 | } |
2910 | ||
239281f8 RL |
2911 | static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, |
2912 | struct ocb_setup *setup) | |
2913 | { | |
2914 | return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); | |
2915 | } | |
2916 | ||
2917 | static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) | |
2918 | { | |
2919 | return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); | |
2920 | } | |
2921 | ||
391e53e3 | 2922 | static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, |
57fbcce3 | 2923 | int rate[NUM_NL80211_BANDS]) |
391e53e3 AQ |
2924 | { |
2925 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2926 | ||
9887dbf5 | 2927 | memcpy(sdata->vif.bss_conf.mcast_rate, rate, |
57fbcce3 | 2928 | sizeof(int) * NUM_NL80211_BANDS); |
391e53e3 | 2929 | |
d8675a63 JB |
2930 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
2931 | BSS_CHANGED_MCAST_RATE); | |
dcbe73ca | 2932 | |
391e53e3 AQ |
2933 | return 0; |
2934 | } | |
2935 | ||
b9a5f8ca JM |
2936 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
2937 | { | |
2938 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
24487981 | 2939 | int err; |
b9a5f8ca | 2940 | |
f23a4780 | 2941 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { |
17c18bf8 JB |
2942 | ieee80211_check_fast_xmit_all(local); |
2943 | ||
f23a4780 AN |
2944 | err = drv_set_frag_threshold(local, wiphy->frag_threshold); |
2945 | ||
17c18bf8 JB |
2946 | if (err) { |
2947 | ieee80211_check_fast_xmit_all(local); | |
f23a4780 | 2948 | return err; |
17c18bf8 | 2949 | } |
f23a4780 AN |
2950 | } |
2951 | ||
a4bcaf55 LB |
2952 | if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || |
2953 | (changed & WIPHY_PARAM_DYN_ACK)) { | |
2954 | s16 coverage_class; | |
2955 | ||
2956 | coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? | |
2957 | wiphy->coverage_class : -1; | |
2958 | err = drv_set_coverage_class(local, coverage_class); | |
310bc676 LT |
2959 | |
2960 | if (err) | |
2961 | return err; | |
2962 | } | |
2963 | ||
b9a5f8ca | 2964 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
24487981 | 2965 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
b9a5f8ca | 2966 | |
24487981 JB |
2967 | if (err) |
2968 | return err; | |
b9a5f8ca JM |
2969 | } |
2970 | ||
8bc83c24 JB |
2971 | if (changed & WIPHY_PARAM_RETRY_SHORT) { |
2972 | if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) | |
2973 | return -EINVAL; | |
b9a5f8ca | 2974 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
8bc83c24 JB |
2975 | } |
2976 | if (changed & WIPHY_PARAM_RETRY_LONG) { | |
2977 | if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) | |
2978 | return -EINVAL; | |
b9a5f8ca | 2979 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
8bc83c24 | 2980 | } |
b9a5f8ca JM |
2981 | if (changed & |
2982 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) | |
2983 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); | |
2984 | ||
2fe4a29a THJ |
2985 | if (changed & (WIPHY_PARAM_TXQ_LIMIT | |
2986 | WIPHY_PARAM_TXQ_MEMORY_LIMIT | | |
2987 | WIPHY_PARAM_TXQ_QUANTUM)) | |
2988 | ieee80211_txq_set_params(local); | |
2989 | ||
b9a5f8ca JM |
2990 | return 0; |
2991 | } | |
2992 | ||
7643a2c3 | 2993 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
c8442118 | 2994 | struct wireless_dev *wdev, |
fa61cf70 | 2995 | enum nl80211_tx_power_setting type, int mbm) |
7643a2c3 JB |
2996 | { |
2997 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1ea6f9c0 | 2998 | struct ieee80211_sub_if_data *sdata; |
db82d8a9 LB |
2999 | enum nl80211_tx_power_setting txp_type = type; |
3000 | bool update_txp_type = false; | |
3a3713ec | 3001 | bool has_monitor = false; |
7643a2c3 | 3002 | |
be0df01d JB |
3003 | lockdep_assert_wiphy(local->hw.wiphy); |
3004 | ||
1ea6f9c0 JB |
3005 | if (wdev) { |
3006 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
3007 | ||
3a3713ec | 3008 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
6dd23603 JB |
3009 | sdata = wiphy_dereference(local->hw.wiphy, |
3010 | local->monitor_sdata); | |
3a3713ec PG |
3011 | if (!sdata) |
3012 | return -EOPNOTSUPP; | |
3013 | } | |
3014 | ||
1ea6f9c0 JB |
3015 | switch (type) { |
3016 | case NL80211_TX_POWER_AUTOMATIC: | |
bfd8403a JB |
3017 | sdata->deflink.user_power_level = |
3018 | IEEE80211_UNSET_POWER_LEVEL; | |
db82d8a9 | 3019 | txp_type = NL80211_TX_POWER_LIMITED; |
1ea6f9c0 JB |
3020 | break; |
3021 | case NL80211_TX_POWER_LIMITED: | |
3022 | case NL80211_TX_POWER_FIXED: | |
3023 | if (mbm < 0 || (mbm % 100)) | |
3024 | return -EOPNOTSUPP; | |
bfd8403a | 3025 | sdata->deflink.user_power_level = MBM_TO_DBM(mbm); |
1ea6f9c0 JB |
3026 | break; |
3027 | } | |
3028 | ||
db82d8a9 LB |
3029 | if (txp_type != sdata->vif.bss_conf.txpower_type) { |
3030 | update_txp_type = true; | |
3031 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3032 | } | |
3033 | ||
3034 | ieee80211_recalc_txpower(sdata, update_txp_type); | |
1ea6f9c0 JB |
3035 | |
3036 | return 0; | |
3037 | } | |
55de908a | 3038 | |
7643a2c3 | 3039 | switch (type) { |
fa61cf70 | 3040 | case NL80211_TX_POWER_AUTOMATIC: |
1ea6f9c0 | 3041 | local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
db82d8a9 | 3042 | txp_type = NL80211_TX_POWER_LIMITED; |
7643a2c3 | 3043 | break; |
fa61cf70 | 3044 | case NL80211_TX_POWER_LIMITED: |
fa61cf70 JO |
3045 | case NL80211_TX_POWER_FIXED: |
3046 | if (mbm < 0 || (mbm % 100)) | |
3047 | return -EOPNOTSUPP; | |
fa61cf70 | 3048 | local->user_power_level = MBM_TO_DBM(mbm); |
7643a2c3 | 3049 | break; |
7643a2c3 JB |
3050 | } |
3051 | ||
db82d8a9 | 3052 | list_for_each_entry(sdata, &local->interfaces, list) { |
3a3713ec PG |
3053 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
3054 | has_monitor = true; | |
3055 | continue; | |
3056 | } | |
bfd8403a | 3057 | sdata->deflink.user_power_level = local->user_power_level; |
db82d8a9 LB |
3058 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
3059 | update_txp_type = true; | |
3060 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3061 | } | |
3a3713ec PG |
3062 | list_for_each_entry(sdata, &local->interfaces, list) { |
3063 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) | |
3064 | continue; | |
db82d8a9 | 3065 | ieee80211_recalc_txpower(sdata, update_txp_type); |
3a3713ec | 3066 | } |
7643a2c3 | 3067 | |
3a3713ec | 3068 | if (has_monitor) { |
6dd23603 JB |
3069 | sdata = wiphy_dereference(local->hw.wiphy, |
3070 | local->monitor_sdata); | |
3a3713ec | 3071 | if (sdata) { |
bfd8403a | 3072 | sdata->deflink.user_power_level = local->user_power_level; |
3a3713ec PG |
3073 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
3074 | update_txp_type = true; | |
3075 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3076 | ||
3077 | ieee80211_recalc_txpower(sdata, update_txp_type); | |
3078 | } | |
3079 | } | |
3080 | ||
7643a2c3 JB |
3081 | return 0; |
3082 | } | |
3083 | ||
c8442118 JB |
3084 | static int ieee80211_get_tx_power(struct wiphy *wiphy, |
3085 | struct wireless_dev *wdev, | |
3086 | int *dbm) | |
7643a2c3 JB |
3087 | { |
3088 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1ea6f9c0 | 3089 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
7643a2c3 | 3090 | |
5b3dc42b FF |
3091 | if (local->ops->get_txpower) |
3092 | return drv_get_txpower(local, sdata, dbm); | |
3093 | ||
0a44dfc0 | 3094 | if (local->emulate_chanctx) |
1ea6f9c0 JB |
3095 | *dbm = local->hw.conf.power_level; |
3096 | else | |
3097 | *dbm = sdata->vif.bss_conf.txpower; | |
7643a2c3 | 3098 | |
e160ab85 PKS |
3099 | /* INT_MIN indicates no power level was set yet */ |
3100 | if (*dbm == INT_MIN) | |
3101 | return -EINVAL; | |
3102 | ||
7643a2c3 JB |
3103 | return 0; |
3104 | } | |
3105 | ||
1f87f7d3 JB |
3106 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
3107 | { | |
3108 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
3109 | ||
3110 | drv_rfkill_poll(local); | |
3111 | } | |
3112 | ||
aff89a9b | 3113 | #ifdef CONFIG_NL80211_TESTMODE |
fc73f11f DS |
3114 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, |
3115 | struct wireless_dev *wdev, | |
3116 | void *data, int len) | |
aff89a9b JB |
3117 | { |
3118 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
52981cd7 | 3119 | struct ieee80211_vif *vif = NULL; |
aff89a9b JB |
3120 | |
3121 | if (!local->ops->testmode_cmd) | |
3122 | return -EOPNOTSUPP; | |
3123 | ||
52981cd7 DS |
3124 | if (wdev) { |
3125 | struct ieee80211_sub_if_data *sdata; | |
3126 | ||
3127 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
3128 | if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) | |
3129 | vif = &sdata->vif; | |
3130 | } | |
3131 | ||
3132 | return local->ops->testmode_cmd(&local->hw, vif, data, len); | |
aff89a9b | 3133 | } |
71063f0e WYG |
3134 | |
3135 | static int ieee80211_testmode_dump(struct wiphy *wiphy, | |
3136 | struct sk_buff *skb, | |
3137 | struct netlink_callback *cb, | |
3138 | void *data, int len) | |
3139 | { | |
3140 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
3141 | ||
3142 | if (!local->ops->testmode_dump) | |
3143 | return -EOPNOTSUPP; | |
3144 | ||
3145 | return local->ops->testmode_dump(&local->hw, skb, cb, data, len); | |
3146 | } | |
aff89a9b JB |
3147 | #endif |
3148 | ||
687da132 | 3149 | int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, |
d8675a63 | 3150 | struct ieee80211_link_data *link, |
687da132 | 3151 | enum ieee80211_smps_mode smps_mode) |
0f78231b JB |
3152 | { |
3153 | const u8 *ap; | |
3154 | enum ieee80211_smps_mode old_req; | |
3155 | int err; | |
d51c2ea3 AN |
3156 | struct sta_info *sta; |
3157 | bool tdls_peer_found = false; | |
0f78231b | 3158 | |
076fc877 | 3159 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
243e6df4 | 3160 | |
687da132 EG |
3161 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) |
3162 | return -EINVAL; | |
3163 | ||
e665ab9c IP |
3164 | if (ieee80211_vif_is_mld(&sdata->vif) && |
3165 | !(sdata->vif.active_links & BIT(link->link_id))) | |
3166 | return 0; | |
3167 | ||
d8675a63 JB |
3168 | old_req = link->u.mgd.req_smps; |
3169 | link->u.mgd.req_smps = smps_mode; | |
0f78231b | 3170 | |
00f823b6 IP |
3171 | /* The driver indicated that EML is enabled for the interface, which |
3172 | * implies that SMPS flows towards the AP should be stopped. | |
3173 | */ | |
3174 | if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE) | |
3175 | return 0; | |
3176 | ||
0f78231b JB |
3177 | if (old_req == smps_mode && |
3178 | smps_mode != IEEE80211_SMPS_AUTOMATIC) | |
3179 | return 0; | |
3180 | ||
3181 | /* | |
3182 | * If not associated, or current association is not an HT | |
04ecd257 JB |
3183 | * association, there's no need to do anything, just store |
3184 | * the new value until we associate. | |
0f78231b JB |
3185 | */ |
3186 | if (!sdata->u.mgd.associated || | |
6092077a | 3187 | link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT) |
0f78231b | 3188 | return 0; |
0f78231b | 3189 | |
e665ab9c | 3190 | ap = sdata->vif.cfg.ap_addr; |
0f78231b | 3191 | |
d51c2ea3 AN |
3192 | rcu_read_lock(); |
3193 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { | |
3194 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || | |
3195 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
3196 | continue; | |
3197 | ||
3198 | tdls_peer_found = true; | |
3199 | break; | |
3200 | } | |
3201 | rcu_read_unlock(); | |
3202 | ||
0f78231b | 3203 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
d51c2ea3 | 3204 | if (tdls_peer_found || !sdata->u.mgd.powersave) |
0f78231b | 3205 | smps_mode = IEEE80211_SMPS_OFF; |
d51c2ea3 AN |
3206 | else |
3207 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
0f78231b JB |
3208 | } |
3209 | ||
3210 | /* send SM PS frame to AP */ | |
3211 | err = ieee80211_send_smps_action(sdata, smps_mode, | |
e665ab9c IP |
3212 | ap, ap, |
3213 | ieee80211_vif_is_mld(&sdata->vif) ? | |
3214 | link->link_id : -1); | |
0f78231b | 3215 | if (err) |
d8675a63 | 3216 | link->u.mgd.req_smps = old_req; |
d51c2ea3 AN |
3217 | else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) |
3218 | ieee80211_teardown_tdls_peers(sdata); | |
0f78231b JB |
3219 | |
3220 | return err; | |
3221 | } | |
3222 | ||
bc92afd9 JB |
3223 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
3224 | bool enabled, int timeout) | |
3225 | { | |
3226 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3227 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
e9aac179 | 3228 | unsigned int link_id; |
bc92afd9 | 3229 | |
2d3db210 | 3230 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
e5de30c9 BP |
3231 | return -EOPNOTSUPP; |
3232 | ||
30686bf7 | 3233 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
bc92afd9 JB |
3234 | return -EOPNOTSUPP; |
3235 | ||
3236 | if (enabled == sdata->u.mgd.powersave && | |
ff616381 | 3237 | timeout == local->dynamic_ps_forced_timeout) |
bc92afd9 JB |
3238 | return 0; |
3239 | ||
3240 | sdata->u.mgd.powersave = enabled; | |
ff616381 | 3241 | local->dynamic_ps_forced_timeout = timeout; |
bc92afd9 | 3242 | |
0f78231b | 3243 | /* no change, but if automatic follow powersave */ |
e9aac179 | 3244 | for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { |
d8675a63 JB |
3245 | struct ieee80211_link_data *link; |
3246 | ||
3247 | link = sdata_dereference(sdata->link[link_id], sdata); | |
3248 | ||
3249 | if (!link) | |
e9aac179 | 3250 | continue; |
d8675a63 JB |
3251 | __ieee80211_request_smps_mgd(sdata, link, |
3252 | link->u.mgd.req_smps); | |
e9aac179 | 3253 | } |
0f78231b | 3254 | |
30686bf7 | 3255 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
bc92afd9 JB |
3256 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
3257 | ||
4a733ef1 | 3258 | ieee80211_recalc_ps(local); |
ab095877 | 3259 | ieee80211_recalc_ps_vif(sdata); |
1d870162 | 3260 | ieee80211_check_fast_rx_iface(sdata); |
bc92afd9 JB |
3261 | |
3262 | return 0; | |
3263 | } | |
3264 | ||
a97c13c3 JO |
3265 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
3266 | struct net_device *dev, | |
3267 | s32 rssi_thold, u32 rssi_hyst) | |
3268 | { | |
3269 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
a97c13c3 JO |
3270 | struct ieee80211_vif *vif = &sdata->vif; |
3271 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
3272 | ||
a97c13c3 JO |
3273 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
3274 | rssi_hyst == bss_conf->cqm_rssi_hyst) | |
3275 | return 0; | |
3276 | ||
ef9be10c JB |
3277 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER && |
3278 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) | |
3279 | return -EOPNOTSUPP; | |
3280 | ||
a97c13c3 JO |
3281 | bss_conf->cqm_rssi_thold = rssi_thold; |
3282 | bss_conf->cqm_rssi_hyst = rssi_hyst; | |
2c3c5f8c AZ |
3283 | bss_conf->cqm_rssi_low = 0; |
3284 | bss_conf->cqm_rssi_high = 0; | |
bfd8403a | 3285 | sdata->deflink.u.mgd.last_cqm_event_signal = 0; |
2c3c5f8c AZ |
3286 | |
3287 | /* tell the driver upon association, unless already associated */ | |
3288 | if (sdata->u.mgd.associated && | |
3289 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) | |
d8675a63 JB |
3290 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
3291 | BSS_CHANGED_CQM); | |
2c3c5f8c AZ |
3292 | |
3293 | return 0; | |
3294 | } | |
3295 | ||
3296 | static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, | |
3297 | struct net_device *dev, | |
3298 | s32 rssi_low, s32 rssi_high) | |
3299 | { | |
3300 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3301 | struct ieee80211_vif *vif = &sdata->vif; | |
3302 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
3303 | ||
3304 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) | |
3305 | return -EOPNOTSUPP; | |
3306 | ||
3307 | bss_conf->cqm_rssi_low = rssi_low; | |
3308 | bss_conf->cqm_rssi_high = rssi_high; | |
3309 | bss_conf->cqm_rssi_thold = 0; | |
3310 | bss_conf->cqm_rssi_hyst = 0; | |
bfd8403a | 3311 | sdata->deflink.u.mgd.last_cqm_event_signal = 0; |
a97c13c3 JO |
3312 | |
3313 | /* tell the driver upon association, unless already associated */ | |
ea086359 JB |
3314 | if (sdata->u.mgd.associated && |
3315 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) | |
d8675a63 JB |
3316 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
3317 | BSS_CHANGED_CQM); | |
a97c13c3 JO |
3318 | |
3319 | return 0; | |
3320 | } | |
3321 | ||
9930380f JB |
3322 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
3323 | struct net_device *dev, | |
7b0a0e3c | 3324 | unsigned int link_id, |
9930380f JB |
3325 | const u8 *addr, |
3326 | const struct cfg80211_bitrate_mask *mask) | |
3327 | { | |
3328 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3329 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
bdbfd6b5 | 3330 | int i, ret; |
2c7e6bc9 | 3331 | |
554a43d5 EP |
3332 | if (!ieee80211_sdata_running(sdata)) |
3333 | return -ENETDOWN; | |
3334 | ||
e8e4f528 JB |
3335 | /* |
3336 | * If active validate the setting and reject it if it doesn't leave | |
3337 | * at least one basic rate usable, since we really have to be able | |
3338 | * to send something, and if we're an AP we have to be able to do | |
3339 | * so at a basic rate so that all clients can receive it. | |
3340 | */ | |
d0a9123e | 3341 | if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) && |
6092077a | 3342 | sdata->vif.bss_conf.chanreq.oper.chan) { |
e8e4f528 | 3343 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
6092077a JB |
3344 | enum nl80211_band band; |
3345 | ||
3346 | band = sdata->vif.bss_conf.chanreq.oper.chan->band; | |
e8e4f528 JB |
3347 | |
3348 | if (!(mask->control[band].legacy & basic_rates)) | |
3349 | return -EINVAL; | |
3350 | } | |
3351 | ||
e5f5ce37 JB |
3352 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
3353 | ret = drv_set_bitrate_mask(local, sdata, mask); | |
3354 | if (ret) | |
3355 | return ret; | |
3356 | } | |
3357 | ||
57fbcce3 | 3358 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
2ffbe6d3 FF |
3359 | struct ieee80211_supported_band *sband = wiphy->bands[i]; |
3360 | int j; | |
3361 | ||
37eb0b16 | 3362 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; |
d1e33e65 JD |
3363 | memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, |
3364 | sizeof(mask->control[i].ht_mcs)); | |
b119ad6e LB |
3365 | memcpy(sdata->rc_rateidx_vht_mcs_mask[i], |
3366 | mask->control[i].vht_mcs, | |
3367 | sizeof(mask->control[i].vht_mcs)); | |
2ffbe6d3 FF |
3368 | |
3369 | sdata->rc_has_mcs_mask[i] = false; | |
b119ad6e | 3370 | sdata->rc_has_vht_mcs_mask[i] = false; |
2ffbe6d3 FF |
3371 | if (!sband) |
3372 | continue; | |
3373 | ||
b119ad6e | 3374 | for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { |
1944015f | 3375 | if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) { |
2ffbe6d3 | 3376 | sdata->rc_has_mcs_mask[i] = true; |
2df1b131 JB |
3377 | break; |
3378 | } | |
3379 | } | |
b119ad6e | 3380 | |
2df1b131 | 3381 | for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { |
1944015f | 3382 | if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) { |
b119ad6e | 3383 | sdata->rc_has_vht_mcs_mask[i] = true; |
2ffbe6d3 | 3384 | break; |
2df1b131 | 3385 | } |
b119ad6e | 3386 | } |
19468413 | 3387 | } |
9930380f | 3388 | |
37eb0b16 | 3389 | return 0; |
9930380f JB |
3390 | } |
3391 | ||
164eb02d SW |
3392 | static int ieee80211_start_radar_detection(struct wiphy *wiphy, |
3393 | struct net_device *dev, | |
31559f35 JD |
3394 | struct cfg80211_chan_def *chandef, |
3395 | u32 cac_time_ms) | |
164eb02d SW |
3396 | { |
3397 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 3398 | struct ieee80211_chan_req chanreq = { .oper = *chandef }; |
164eb02d | 3399 | struct ieee80211_local *local = sdata->local; |
164eb02d SW |
3400 | int err; |
3401 | ||
0cd8080e JB |
3402 | lockdep_assert_wiphy(local->hw.wiphy); |
3403 | ||
34a3740d JB |
3404 | if (!list_empty(&local->roc_list) || local->scanning) { |
3405 | err = -EBUSY; | |
3406 | goto out_unlock; | |
3407 | } | |
164eb02d SW |
3408 | |
3409 | /* whatever, but channel contexts should not complain about that one */ | |
bfd8403a JB |
3410 | sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; |
3411 | sdata->deflink.needed_rx_chains = local->rx_chains; | |
164eb02d | 3412 | |
6092077a | 3413 | err = ieee80211_link_use_channel(&sdata->deflink, &chanreq, |
b4f85443 | 3414 | IEEE80211_CHANCTX_SHARED); |
164eb02d | 3415 | if (err) |
34a3740d | 3416 | goto out_unlock; |
164eb02d | 3417 | |
766d2601 JB |
3418 | wiphy_delayed_work_queue(wiphy, &sdata->deflink.dfs_cac_timer_work, |
3419 | msecs_to_jiffies(cac_time_ms)); | |
164eb02d | 3420 | |
34a3740d | 3421 | out_unlock: |
34a3740d | 3422 | return err; |
164eb02d SW |
3423 | } |
3424 | ||
26ec17a1 OM |
3425 | static void ieee80211_end_cac(struct wiphy *wiphy, |
3426 | struct net_device *dev) | |
3427 | { | |
3428 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3429 | struct ieee80211_local *local = sdata->local; | |
3430 | ||
0cd8080e JB |
3431 | lockdep_assert_wiphy(local->hw.wiphy); |
3432 | ||
26ec17a1 OM |
3433 | list_for_each_entry(sdata, &local->interfaces, list) { |
3434 | /* it might be waiting for the local->mtx, but then | |
3435 | * by the time it gets it, sdata->wdev.cac_started | |
3436 | * will no longer be true | |
3437 | */ | |
766d2601 JB |
3438 | wiphy_delayed_work_cancel(wiphy, |
3439 | &sdata->deflink.dfs_cac_timer_work); | |
26ec17a1 OM |
3440 | |
3441 | if (sdata->wdev.cac_started) { | |
d8675a63 | 3442 | ieee80211_link_release_channel(&sdata->deflink); |
26ec17a1 OM |
3443 | sdata->wdev.cac_started = false; |
3444 | } | |
3445 | } | |
26ec17a1 OM |
3446 | } |
3447 | ||
73da7d5b SW |
3448 | static struct cfg80211_beacon_data * |
3449 | cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) | |
3450 | { | |
3451 | struct cfg80211_beacon_data *new_beacon; | |
3452 | u8 *pos; | |
3453 | int len; | |
3454 | ||
3455 | len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + | |
3456 | beacon->proberesp_ies_len + beacon->assocresp_ies_len + | |
bd54f3c2 AD |
3457 | beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len; |
3458 | ||
3459 | if (beacon->mbssid_ies) | |
3460 | len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies, | |
68b9bea2 | 3461 | beacon->rnr_ies, |
bd54f3c2 | 3462 | beacon->mbssid_ies->cnt); |
73da7d5b SW |
3463 | |
3464 | new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); | |
3465 | if (!new_beacon) | |
3466 | return NULL; | |
3467 | ||
2b3171c6 LB |
3468 | if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { |
3469 | new_beacon->mbssid_ies = | |
3470 | kzalloc(struct_size(new_beacon->mbssid_ies, | |
3471 | elem, beacon->mbssid_ies->cnt), | |
3472 | GFP_KERNEL); | |
3473 | if (!new_beacon->mbssid_ies) { | |
3474 | kfree(new_beacon); | |
3475 | return NULL; | |
3476 | } | |
68b9bea2 AD |
3477 | |
3478 | if (beacon->rnr_ies && beacon->rnr_ies->cnt) { | |
3479 | new_beacon->rnr_ies = | |
3480 | kzalloc(struct_size(new_beacon->rnr_ies, | |
3481 | elem, beacon->rnr_ies->cnt), | |
3482 | GFP_KERNEL); | |
3483 | if (!new_beacon->rnr_ies) { | |
3484 | kfree(new_beacon->mbssid_ies); | |
3485 | kfree(new_beacon); | |
3486 | return NULL; | |
3487 | } | |
3488 | } | |
2b3171c6 LB |
3489 | } |
3490 | ||
73da7d5b SW |
3491 | pos = (u8 *)(new_beacon + 1); |
3492 | if (beacon->head_len) { | |
3493 | new_beacon->head_len = beacon->head_len; | |
3494 | new_beacon->head = pos; | |
3495 | memcpy(pos, beacon->head, beacon->head_len); | |
3496 | pos += beacon->head_len; | |
3497 | } | |
3498 | if (beacon->tail_len) { | |
3499 | new_beacon->tail_len = beacon->tail_len; | |
3500 | new_beacon->tail = pos; | |
3501 | memcpy(pos, beacon->tail, beacon->tail_len); | |
3502 | pos += beacon->tail_len; | |
3503 | } | |
3504 | if (beacon->beacon_ies_len) { | |
3505 | new_beacon->beacon_ies_len = beacon->beacon_ies_len; | |
3506 | new_beacon->beacon_ies = pos; | |
3507 | memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); | |
3508 | pos += beacon->beacon_ies_len; | |
3509 | } | |
3510 | if (beacon->proberesp_ies_len) { | |
3511 | new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; | |
3512 | new_beacon->proberesp_ies = pos; | |
3513 | memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); | |
3514 | pos += beacon->proberesp_ies_len; | |
3515 | } | |
3516 | if (beacon->assocresp_ies_len) { | |
3517 | new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; | |
3518 | new_beacon->assocresp_ies = pos; | |
3519 | memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); | |
3520 | pos += beacon->assocresp_ies_len; | |
3521 | } | |
3522 | if (beacon->probe_resp_len) { | |
3523 | new_beacon->probe_resp_len = beacon->probe_resp_len; | |
bee92d06 | 3524 | new_beacon->probe_resp = pos; |
73da7d5b SW |
3525 | memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); |
3526 | pos += beacon->probe_resp_len; | |
3527 | } | |
68b9bea2 | 3528 | if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { |
2b3171c6 LB |
3529 | pos += ieee80211_copy_mbssid_beacon(pos, |
3530 | new_beacon->mbssid_ies, | |
3531 | beacon->mbssid_ies); | |
68b9bea2 AD |
3532 | if (beacon->rnr_ies && beacon->rnr_ies->cnt) |
3533 | pos += ieee80211_copy_rnr_beacon(pos, | |
3534 | new_beacon->rnr_ies, | |
3535 | beacon->rnr_ies); | |
3536 | } | |
03b73862 JB |
3537 | |
3538 | /* might copy -1, meaning no changes requested */ | |
3539 | new_beacon->ftm_responder = beacon->ftm_responder; | |
bc847970 PKC |
3540 | if (beacon->lci) { |
3541 | new_beacon->lci_len = beacon->lci_len; | |
3542 | new_beacon->lci = pos; | |
3543 | memcpy(pos, beacon->lci, beacon->lci_len); | |
3544 | pos += beacon->lci_len; | |
3545 | } | |
3546 | if (beacon->civicloc) { | |
3547 | new_beacon->civicloc_len = beacon->civicloc_len; | |
3548 | new_beacon->civicloc = pos; | |
3549 | memcpy(pos, beacon->civicloc, beacon->civicloc_len); | |
3550 | pos += beacon->civicloc_len; | |
3551 | } | |
73da7d5b SW |
3552 | |
3553 | return new_beacon; | |
3554 | } | |
3555 | ||
04ada859 | 3556 | void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id) |
73da7d5b | 3557 | { |
66e01cf9 | 3558 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
c9eb90a5 | 3559 | struct ieee80211_local *local = sdata->local; |
04ada859 AKS |
3560 | struct ieee80211_link_data *link_data; |
3561 | ||
3562 | if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) | |
3563 | return; | |
c9eb90a5 JC |
3564 | |
3565 | rcu_read_lock(); | |
3566 | ||
04ada859 AKS |
3567 | link_data = rcu_dereference(sdata->link[link_id]); |
3568 | if (WARN_ON(!link_data)) { | |
3569 | rcu_read_unlock(); | |
3570 | return; | |
3571 | } | |
3572 | ||
3573 | /* TODO: MBSSID with MLO changes */ | |
c9eb90a5 JC |
3574 | if (vif->mbssid_tx_vif == vif) { |
3575 | /* Trigger ieee80211_csa_finish() on the non-transmitting | |
3576 | * interfaces when channel switch is received on | |
3577 | * transmitting interface | |
3578 | */ | |
3579 | struct ieee80211_sub_if_data *iter; | |
3580 | ||
3581 | list_for_each_entry_rcu(iter, &local->interfaces, list) { | |
3582 | if (!ieee80211_sdata_running(iter)) | |
3583 | continue; | |
73da7d5b | 3584 | |
c9eb90a5 JC |
3585 | if (iter == sdata || iter->vif.mbssid_tx_vif != vif) |
3586 | continue; | |
3587 | ||
d7074be6 JB |
3588 | wiphy_work_queue(iter->local->hw.wiphy, |
3589 | &iter->deflink.csa_finalize_work); | |
c9eb90a5 JC |
3590 | } |
3591 | } | |
04ada859 | 3592 | wiphy_work_queue(local->hw.wiphy, &link_data->csa_finalize_work); |
c9eb90a5 JC |
3593 | |
3594 | rcu_read_unlock(); | |
66e01cf9 LC |
3595 | } |
3596 | EXPORT_SYMBOL(ieee80211_csa_finish); | |
e487eaeb | 3597 | |
6d501764 NE |
3598 | void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx) |
3599 | { | |
3600 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
3601 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3602 | struct ieee80211_local *local = sdata->local; | |
3603 | ||
bfd8403a | 3604 | sdata->deflink.csa_block_tx = block_tx; |
6d501764 | 3605 | sdata_info(sdata, "channel switch failed, disconnecting\n"); |
4b8d43f1 | 3606 | wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work); |
6d501764 NE |
3607 | } |
3608 | EXPORT_SYMBOL(ieee80211_channel_switch_disconnect); | |
3609 | ||
a3a637a6 | 3610 | static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data, |
15ddba5f | 3611 | u64 *changed) |
66e01cf9 | 3612 | { |
a3a637a6 | 3613 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
66199506 | 3614 | int err; |
7578d575 | 3615 | |
cd7760e6 SW |
3616 | switch (sdata->vif.type) { |
3617 | case NL80211_IFTYPE_AP: | |
a3a637a6 | 3618 | if (!link_data->u.ap.next_beacon) |
450c271d LB |
3619 | return -EINVAL; |
3620 | ||
a3a637a6 AKS |
3621 | err = ieee80211_assign_beacon(sdata, link_data, |
3622 | link_data->u.ap.next_beacon, | |
15ddba5f | 3623 | NULL, NULL, changed); |
a3a637a6 | 3624 | ieee80211_free_next_beacon(link_data); |
97518af1 | 3625 | |
cd7760e6 | 3626 | if (err < 0) |
66199506 | 3627 | return err; |
cd7760e6 SW |
3628 | break; |
3629 | case NL80211_IFTYPE_ADHOC: | |
15ddba5f | 3630 | err = ieee80211_ibss_finish_csa(sdata, changed); |
faf046e7 | 3631 | if (err < 0) |
66199506 | 3632 | return err; |
cd7760e6 | 3633 | break; |
b8456a14 CYY |
3634 | #ifdef CONFIG_MAC80211_MESH |
3635 | case NL80211_IFTYPE_MESH_POINT: | |
15ddba5f | 3636 | err = ieee80211_mesh_finish_csa(sdata, changed); |
b8456a14 | 3637 | if (err < 0) |
66199506 | 3638 | return err; |
b8456a14 CYY |
3639 | break; |
3640 | #endif | |
cd7760e6 SW |
3641 | default: |
3642 | WARN_ON(1); | |
66199506 MK |
3643 | return -EINVAL; |
3644 | } | |
3645 | ||
3646 | return 0; | |
3647 | } | |
3648 | ||
a469a593 | 3649 | static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data) |
66199506 | 3650 | { |
a469a593 | 3651 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
66199506 | 3652 | struct ieee80211_local *local = sdata->local; |
1a96bb4e | 3653 | struct ieee80211_bss_conf *link_conf = link_data->conf; |
15ddba5f | 3654 | u64 changed = 0; |
66199506 MK |
3655 | int err; |
3656 | ||
5435af6e | 3657 | lockdep_assert_wiphy(local->hw.wiphy); |
66199506 | 3658 | |
03078de4 MK |
3659 | /* |
3660 | * using reservation isn't immediate as it may be deferred until later | |
3661 | * with multi-vif. once reservation is complete it will re-schedule the | |
3662 | * work with no reserved_chanctx so verify chandef to check if it | |
3663 | * completed successfully | |
3664 | */ | |
66199506 | 3665 | |
a469a593 | 3666 | if (link_data->reserved_chanctx) { |
03078de4 MK |
3667 | /* |
3668 | * with multi-vif csa driver may call ieee80211_csa_finish() | |
3669 | * many times while waiting for other interfaces to use their | |
3670 | * reservations | |
3671 | */ | |
a469a593 | 3672 | if (link_data->reserved_ready) |
03078de4 MK |
3673 | return 0; |
3674 | ||
1a96bb4e | 3675 | return ieee80211_link_use_reserved_context(link_data); |
cd7760e6 | 3676 | } |
73da7d5b | 3677 | |
1a96bb4e | 3678 | if (!cfg80211_chandef_identical(&link_conf->chanreq.oper, |
6092077a | 3679 | &link_data->csa_chanreq.oper)) |
03078de4 MK |
3680 | return -EINVAL; |
3681 | ||
1a96bb4e | 3682 | link_conf->csa_active = false; |
66199506 | 3683 | |
1a96bb4e | 3684 | err = ieee80211_set_after_csa_beacon(link_data, &changed); |
66199506 | 3685 | if (err) |
cf8767dd | 3686 | return err; |
faf046e7 | 3687 | |
86a8db67 | 3688 | ieee80211_link_info_change_notify(sdata, link_data, changed); |
59af6928 | 3689 | |
a469a593 | 3690 | if (link_data->csa_block_tx) { |
a46992b4 LC |
3691 | ieee80211_wake_vif_queues(local, sdata, |
3692 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
a469a593 | 3693 | link_data->csa_block_tx = false; |
a46992b4 | 3694 | } |
cf8767dd | 3695 | |
a469a593 | 3696 | err = drv_post_channel_switch(link_data); |
f1d65583 LC |
3697 | if (err) |
3698 | return err; | |
3699 | ||
6092077a | 3700 | cfg80211_ch_switch_notify(sdata->dev, &link_data->csa_chanreq.oper, |
b82730bf | 3701 | link_data->link_id); |
f1d65583 | 3702 | |
cf8767dd MK |
3703 | return 0; |
3704 | } | |
3705 | ||
a469a593 | 3706 | static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data) |
cf8767dd | 3707 | { |
a469a593 EG |
3708 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
3709 | ||
3710 | if (__ieee80211_csa_finalize(link_data)) { | |
1a96bb4e AKS |
3711 | sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n", |
3712 | link_data->link_id); | |
cf8767dd MK |
3713 | cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev, |
3714 | GFP_KERNEL); | |
3715 | } | |
66e01cf9 LC |
3716 | } |
3717 | ||
d7074be6 | 3718 | void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work) |
66e01cf9 | 3719 | { |
a469a593 EG |
3720 | struct ieee80211_link_data *link = |
3721 | container_of(work, struct ieee80211_link_data, csa_finalize_work); | |
3722 | struct ieee80211_sub_if_data *sdata = link->sdata; | |
59af6928 | 3723 | struct ieee80211_local *local = sdata->local; |
66e01cf9 | 3724 | |
5435af6e | 3725 | lockdep_assert_wiphy(local->hw.wiphy); |
59af6928 | 3726 | |
66e01cf9 | 3727 | /* AP might have been stopped while waiting for the lock. */ |
a469a593 | 3728 | if (!link->conf->csa_active) |
076fc877 | 3729 | return; |
66e01cf9 LC |
3730 | |
3731 | if (!ieee80211_sdata_running(sdata)) | |
076fc877 | 3732 | return; |
66e01cf9 | 3733 | |
a469a593 | 3734 | ieee80211_csa_finalize(link); |
73da7d5b SW |
3735 | } |
3736 | ||
a3a637a6 | 3737 | static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data, |
37fa2bdd | 3738 | struct cfg80211_csa_settings *params, |
15ddba5f | 3739 | u64 *changed) |
73da7d5b | 3740 | { |
a3a637a6 | 3741 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
af296bdb | 3742 | struct ieee80211_csa_settings csa = {}; |
37fa2bdd | 3743 | int err; |
73da7d5b | 3744 | |
73da7d5b SW |
3745 | switch (sdata->vif.type) { |
3746 | case NL80211_IFTYPE_AP: | |
a3a637a6 | 3747 | link_data->u.ap.next_beacon = |
cd7760e6 | 3748 | cfg80211_beacon_dup(¶ms->beacon_after); |
a3a637a6 | 3749 | if (!link_data->u.ap.next_beacon) |
cd7760e6 SW |
3750 | return -ENOMEM; |
3751 | ||
66e01cf9 LC |
3752 | /* |
3753 | * With a count of 0, we don't have to wait for any | |
3754 | * TBTT before switching, so complete the CSA | |
3755 | * immediately. In theory, with a count == 1 we | |
3756 | * should delay the switch until just before the next | |
3757 | * TBTT, but that would complicate things so we switch | |
3758 | * immediately too. If we would delay the switch | |
3759 | * until the next TBTT, we would have to set the probe | |
3760 | * response here. | |
3761 | * | |
3762 | * TODO: A channel switch with count <= 1 without | |
3763 | * sending a CSA action frame is kind of useless, | |
3764 | * because the clients won't know we're changing | |
3765 | * channels. The action frame must be implemented | |
3766 | * either here or in the userspace. | |
3767 | */ | |
3768 | if (params->count <= 1) | |
3769 | break; | |
3770 | ||
0d06d9ba | 3771 | if ((params->n_counter_offsets_beacon > |
8552a434 | 3772 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM) || |
0d06d9ba | 3773 | (params->n_counter_offsets_presp > |
2b3171c6 | 3774 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) { |
a3a637a6 | 3775 | ieee80211_free_next_beacon(link_data); |
0d06d9ba | 3776 | return -EINVAL; |
2b3171c6 | 3777 | } |
9a774c78 | 3778 | |
af296bdb MK |
3779 | csa.counter_offsets_beacon = params->counter_offsets_beacon; |
3780 | csa.counter_offsets_presp = params->counter_offsets_presp; | |
3781 | csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; | |
3782 | csa.n_counter_offsets_presp = params->n_counter_offsets_presp; | |
3783 | csa.count = params->count; | |
9a774c78 | 3784 | |
a3a637a6 | 3785 | err = ieee80211_assign_beacon(sdata, link_data, |
d8675a63 | 3786 | ¶ms->beacon_csa, &csa, |
15ddba5f | 3787 | NULL, changed); |
cd7760e6 | 3788 | if (err < 0) { |
a3a637a6 | 3789 | ieee80211_free_next_beacon(link_data); |
cd7760e6 SW |
3790 | return err; |
3791 | } | |
66e01cf9 | 3792 | |
cd7760e6 SW |
3793 | break; |
3794 | case NL80211_IFTYPE_ADHOC: | |
f276e20b | 3795 | if (!sdata->vif.cfg.ibss_joined) |
cd7760e6 SW |
3796 | return -EINVAL; |
3797 | ||
3798 | if (params->chandef.width != sdata->u.ibss.chandef.width) | |
3799 | return -EINVAL; | |
3800 | ||
3801 | switch (params->chandef.width) { | |
3802 | case NL80211_CHAN_WIDTH_40: | |
3803 | if (cfg80211_get_chandef_type(¶ms->chandef) != | |
3804 | cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) | |
3805 | return -EINVAL; | |
aaaee2d6 | 3806 | break; |
cd7760e6 SW |
3807 | case NL80211_CHAN_WIDTH_5: |
3808 | case NL80211_CHAN_WIDTH_10: | |
3809 | case NL80211_CHAN_WIDTH_20_NOHT: | |
3810 | case NL80211_CHAN_WIDTH_20: | |
3811 | break; | |
3812 | default: | |
3813 | return -EINVAL; | |
3814 | } | |
3815 | ||
3816 | /* changes into another band are not supported */ | |
3817 | if (sdata->u.ibss.chandef.chan->band != | |
3818 | params->chandef.chan->band) | |
3819 | return -EINVAL; | |
3820 | ||
66e01cf9 LC |
3821 | /* see comments in the NL80211_IFTYPE_AP block */ |
3822 | if (params->count > 1) { | |
15ddba5f | 3823 | err = ieee80211_ibss_csa_beacon(sdata, params, changed); |
66e01cf9 LC |
3824 | if (err < 0) |
3825 | return err; | |
66e01cf9 LC |
3826 | } |
3827 | ||
3828 | ieee80211_send_action_csa(sdata, params); | |
3829 | ||
73da7d5b | 3830 | break; |
c6da674a | 3831 | #ifdef CONFIG_MAC80211_MESH |
37fa2bdd MK |
3832 | case NL80211_IFTYPE_MESH_POINT: { |
3833 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
c6da674a | 3834 | |
c6da674a | 3835 | /* changes into another band are not supported */ |
6092077a | 3836 | if (sdata->vif.bss_conf.chanreq.oper.chan->band != |
c6da674a CYY |
3837 | params->chandef.chan->band) |
3838 | return -EINVAL; | |
3839 | ||
c782bf8c | 3840 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { |
0cb4d4dc | 3841 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; |
c782bf8c CYY |
3842 | if (!ifmsh->pre_value) |
3843 | ifmsh->pre_value = 1; | |
3844 | else | |
3845 | ifmsh->pre_value++; | |
3846 | } | |
0cb4d4dc | 3847 | |
66e01cf9 LC |
3848 | /* see comments in the NL80211_IFTYPE_AP block */ |
3849 | if (params->count > 1) { | |
15ddba5f | 3850 | err = ieee80211_mesh_csa_beacon(sdata, params, changed); |
66e01cf9 LC |
3851 | if (err < 0) { |
3852 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; | |
3853 | return err; | |
3854 | } | |
3f718fd8 | 3855 | } |
66e01cf9 LC |
3856 | |
3857 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) | |
3858 | ieee80211_send_action_csa(sdata, params); | |
3859 | ||
c6da674a | 3860 | break; |
37fa2bdd | 3861 | } |
c6da674a | 3862 | #endif |
73da7d5b SW |
3863 | default: |
3864 | return -EOPNOTSUPP; | |
3865 | } | |
3866 | ||
37fa2bdd MK |
3867 | return 0; |
3868 | } | |
3869 | ||
5f9404ab JC |
3870 | static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata) |
3871 | { | |
d0a9123e | 3872 | sdata->vif.bss_conf.color_change_active = false; |
0baef284 | 3873 | |
d9f83f22 | 3874 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab JC |
3875 | |
3876 | cfg80211_color_change_aborted_notify(sdata->dev); | |
3877 | } | |
3878 | ||
f29f58a9 LC |
3879 | static int |
3880 | __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, | |
3881 | struct cfg80211_csa_settings *params) | |
37fa2bdd MK |
3882 | { |
3883 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 3884 | struct ieee80211_chan_req chanreq = { .oper = params->chandef }; |
37fa2bdd | 3885 | struct ieee80211_local *local = sdata->local; |
6d027bcc | 3886 | struct ieee80211_channel_switch ch_switch; |
2b32713d | 3887 | struct ieee80211_chanctx_conf *conf; |
37fa2bdd | 3888 | struct ieee80211_chanctx *chanctx; |
1a96bb4e AKS |
3889 | struct ieee80211_bss_conf *link_conf; |
3890 | struct ieee80211_link_data *link_data; | |
15ddba5f | 3891 | u64 changed = 0; |
1a96bb4e | 3892 | u8 link_id = params->link_id; |
b08cc24e | 3893 | int err; |
37fa2bdd | 3894 | |
5435af6e | 3895 | lockdep_assert_wiphy(local->hw.wiphy); |
37fa2bdd MK |
3896 | |
3897 | if (!list_empty(&local->roc_list) || local->scanning) | |
3898 | return -EBUSY; | |
3899 | ||
3900 | if (sdata->wdev.cac_started) | |
3901 | return -EBUSY; | |
3902 | ||
1a96bb4e AKS |
3903 | if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) |
3904 | return -EINVAL; | |
3905 | ||
3906 | link_data = wiphy_dereference(wiphy, sdata->link[link_id]); | |
3907 | if (!link_data) | |
3908 | return -ENOLINK; | |
3909 | ||
3910 | link_conf = link_data->conf; | |
3911 | ||
3912 | if (chanreq.oper.punctured && !link_conf->eht_support) | |
b82730bf JB |
3913 | return -EINVAL; |
3914 | ||
03078de4 | 3915 | /* don't allow another channel switch if one is already active. */ |
1a96bb4e | 3916 | if (link_conf->csa_active) |
03078de4 MK |
3917 | return -EBUSY; |
3918 | ||
1a96bb4e | 3919 | conf = wiphy_dereference(wiphy, link_conf->chanctx_conf); |
2b32713d | 3920 | if (!conf) { |
03078de4 MK |
3921 | err = -EBUSY; |
3922 | goto out; | |
37fa2bdd MK |
3923 | } |
3924 | ||
b6011960 TP |
3925 | if (params->chandef.chan->freq_offset) { |
3926 | /* this may work, but is untested */ | |
3927 | err = -EOPNOTSUPP; | |
3928 | goto out; | |
3929 | } | |
3930 | ||
2b32713d | 3931 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
37fa2bdd | 3932 | |
000baa5d LC |
3933 | ch_switch.timestamp = 0; |
3934 | ch_switch.device_timestamp = 0; | |
3935 | ch_switch.block_tx = params->block_tx; | |
6092077a | 3936 | ch_switch.chandef = chanreq.oper; |
000baa5d LC |
3937 | ch_switch.count = params->count; |
3938 | ||
6d027bcc LC |
3939 | err = drv_pre_channel_switch(sdata, &ch_switch); |
3940 | if (err) | |
3941 | goto out; | |
3942 | ||
1a96bb4e | 3943 | err = ieee80211_link_reserve_chanctx(link_data, &chanreq, |
b4f85443 JB |
3944 | chanctx->mode, |
3945 | params->radar_required); | |
03078de4 MK |
3946 | if (err) |
3947 | goto out; | |
37fa2bdd | 3948 | |
03078de4 MK |
3949 | /* if reservation is invalid then this will fail */ |
3950 | err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0); | |
3951 | if (err) { | |
1a96bb4e | 3952 | ieee80211_link_unreserve_chanctx(link_data); |
03078de4 MK |
3953 | goto out; |
3954 | } | |
37fa2bdd | 3955 | |
5f9404ab | 3956 | /* if there is a color change in progress, abort it */ |
1a96bb4e | 3957 | if (link_conf->color_change_active) |
5f9404ab JC |
3958 | ieee80211_color_change_abort(sdata); |
3959 | ||
1a96bb4e | 3960 | err = ieee80211_set_csa_beacon(link_data, params, &changed); |
03078de4 | 3961 | if (err) { |
1a96bb4e | 3962 | ieee80211_link_unreserve_chanctx(link_data); |
03078de4 MK |
3963 | goto out; |
3964 | } | |
37fa2bdd | 3965 | |
1a96bb4e AKS |
3966 | link_data->csa_chanreq = chanreq; |
3967 | link_data->csa_block_tx = params->block_tx; | |
3968 | link_conf->csa_active = true; | |
73da7d5b | 3969 | |
1a96bb4e | 3970 | if (link_data->csa_block_tx) |
a46992b4 LC |
3971 | ieee80211_stop_vif_queues(local, sdata, |
3972 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
59af6928 | 3973 | |
bfd8403a | 3974 | cfg80211_ch_switch_started_notify(sdata->dev, |
1a96bb4e | 3975 | &link_data->csa_chanreq.oper, 0, |
b82730bf | 3976 | params->count, params->block_tx); |
2f457293 | 3977 | |
66e01cf9 | 3978 | if (changed) { |
1a96bb4e AKS |
3979 | ieee80211_link_info_change_notify(sdata, link_data, changed); |
3980 | drv_channel_switch_beacon(sdata, &link_data->csa_chanreq.oper); | |
66e01cf9 LC |
3981 | } else { |
3982 | /* if the beacon didn't change, we can finalize immediately */ | |
1a96bb4e | 3983 | ieee80211_csa_finalize(link_data); |
66e01cf9 | 3984 | } |
73da7d5b | 3985 | |
03078de4 | 3986 | out: |
03078de4 | 3987 | return err; |
73da7d5b SW |
3988 | } |
3989 | ||
59af6928 MK |
3990 | int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
3991 | struct cfg80211_csa_settings *params) | |
3992 | { | |
3993 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3994 | struct ieee80211_local *local = sdata->local; | |
59af6928 | 3995 | |
0cd8080e | 3996 | lockdep_assert_wiphy(local->hw.wiphy); |
59af6928 | 3997 | |
0cd8080e | 3998 | return __ieee80211_channel_switch(wiphy, dev, params); |
59af6928 MK |
3999 | } |
4000 | ||
a2fcfccb JB |
4001 | u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) |
4002 | { | |
0cd8080e | 4003 | lockdep_assert_wiphy(local->hw.wiphy); |
a2fcfccb JB |
4004 | |
4005 | local->roc_cookie_counter++; | |
4006 | ||
4007 | /* wow, you wrapped 64 bits ... more likely a bug */ | |
4008 | if (WARN_ON(local->roc_cookie_counter == 0)) | |
4009 | local->roc_cookie_counter++; | |
4010 | ||
4011 | return local->roc_cookie_counter; | |
4012 | } | |
4013 | ||
5ee00dbd JB |
4014 | int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, |
4015 | u64 *cookie, gfp_t gfp) | |
3b79af97 JB |
4016 | { |
4017 | unsigned long spin_flags; | |
4018 | struct sk_buff *ack_skb; | |
4019 | int id; | |
4020 | ||
4021 | ack_skb = skb_copy(skb, gfp); | |
4022 | if (!ack_skb) | |
5ee00dbd | 4023 | return -ENOMEM; |
3b79af97 JB |
4024 | |
4025 | spin_lock_irqsave(&local->ack_status_lock, spin_flags); | |
4026 | id = idr_alloc(&local->ack_status_frames, ack_skb, | |
f2b18bac | 4027 | 1, 0x2000, GFP_ATOMIC); |
3b79af97 JB |
4028 | spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); |
4029 | ||
4030 | if (id < 0) { | |
4031 | kfree_skb(ack_skb); | |
5ee00dbd | 4032 | return -ENOMEM; |
3b79af97 JB |
4033 | } |
4034 | ||
f498f6ab JB |
4035 | IEEE80211_SKB_CB(skb)->status_data_idr = 1; |
4036 | IEEE80211_SKB_CB(skb)->status_data = id; | |
3b79af97 JB |
4037 | |
4038 | *cookie = ieee80211_mgmt_tx_cookie(local); | |
4039 | IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; | |
4040 | ||
5ee00dbd | 4041 | return 0; |
3b79af97 JB |
4042 | } |
4043 | ||
6cd536fe JB |
4044 | static void |
4045 | ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy, | |
71bbc994 | 4046 | struct wireless_dev *wdev, |
6cd536fe | 4047 | struct mgmt_frame_regs *upd) |
7be5086d JB |
4048 | { |
4049 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1b09b556 | 4050 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
6cd536fe | 4051 | u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4); |
873b1cf6 | 4052 | u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4); |
6cd536fe | 4053 | bool global_change, intf_change; |
7be5086d | 4054 | |
6cd536fe | 4055 | global_change = |
873b1cf6 JM |
4056 | (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) || |
4057 | (local->rx_mcast_action_reg != | |
4058 | !!(upd->global_mcast_stypes & action_mask)); | |
6cd536fe | 4059 | local->probe_req_reg = upd->global_stypes & preq_mask; |
873b1cf6 | 4060 | local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask; |
1b09b556 | 4061 | |
873b1cf6 JM |
4062 | intf_change = (sdata->vif.probe_req_reg != |
4063 | !!(upd->interface_stypes & preq_mask)) || | |
4064 | (sdata->vif.rx_mcast_action_reg != | |
4065 | !!(upd->interface_mcast_stypes & action_mask)); | |
6cd536fe | 4066 | sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask; |
873b1cf6 JM |
4067 | sdata->vif.rx_mcast_action_reg = |
4068 | upd->interface_mcast_stypes & action_mask; | |
7be5086d | 4069 | |
6cd536fe JB |
4070 | if (!local->open_count) |
4071 | return; | |
35f5149e | 4072 | |
6cd536fe JB |
4073 | if (intf_change && ieee80211_sdata_running(sdata)) |
4074 | drv_config_iface_filter(local, sdata, | |
4075 | sdata->vif.probe_req_reg ? | |
4076 | FIF_PROBE_REQ : 0, | |
4077 | FIF_PROBE_REQ); | |
1b09b556 | 4078 | |
6cd536fe | 4079 | if (global_change) |
1b09b556 | 4080 | ieee80211_configure_filter(local); |
7be5086d JB |
4081 | } |
4082 | ||
15d96753 BR |
4083 | static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) |
4084 | { | |
4085 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2bf57b00 | 4086 | int ret; |
15d96753 BR |
4087 | |
4088 | if (local->started) | |
4089 | return -EOPNOTSUPP; | |
4090 | ||
2bf57b00 EG |
4091 | ret = drv_set_antenna(local, tx_ant, rx_ant); |
4092 | if (ret) | |
4093 | return ret; | |
4094 | ||
4095 | local->rx_chains = hweight8(rx_ant); | |
4096 | return 0; | |
15d96753 BR |
4097 | } |
4098 | ||
4099 | static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) | |
4100 | { | |
4101 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4102 | ||
4103 | return drv_get_antenna(local, tx_ant, rx_ant); | |
4104 | } | |
4105 | ||
c68f4b89 JB |
4106 | static int ieee80211_set_rekey_data(struct wiphy *wiphy, |
4107 | struct net_device *dev, | |
4108 | struct cfg80211_gtk_rekey_data *data) | |
4109 | { | |
4110 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4111 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4112 | ||
4113 | if (!local->ops->set_rekey_data) | |
4114 | return -EOPNOTSUPP; | |
4115 | ||
4116 | drv_set_rekey_data(local, sdata, data); | |
4117 | ||
4118 | return 0; | |
4119 | } | |
4120 | ||
06500736 JB |
4121 | static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, |
4122 | const u8 *peer, u64 *cookie) | |
4123 | { | |
4124 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4125 | struct ieee80211_local *local = sdata->local; | |
4126 | struct ieee80211_qos_hdr *nullfunc; | |
5ee00dbd | 4127 | struct sk_buff *skb; |
06500736 JB |
4128 | int size = sizeof(*nullfunc); |
4129 | __le16 fc; | |
4130 | bool qos; | |
4131 | struct ieee80211_tx_info *info; | |
4132 | struct sta_info *sta; | |
55de908a | 4133 | struct ieee80211_chanctx_conf *chanctx_conf; |
57fbcce3 | 4134 | enum nl80211_band band; |
3b79af97 JB |
4135 | int ret; |
4136 | ||
4137 | /* the lock is needed to assign the cookie later */ | |
0cd8080e | 4138 | lockdep_assert_wiphy(local->hw.wiphy); |
06500736 JB |
4139 | |
4140 | rcu_read_lock(); | |
67dfa589 JB |
4141 | sta = sta_info_get_bss(sdata, peer); |
4142 | if (!sta) { | |
4143 | ret = -ENOLINK; | |
4144 | goto unlock; | |
4145 | } | |
4146 | ||
4147 | qos = sta->sta.wme; | |
4148 | ||
d0a9123e | 4149 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
55de908a | 4150 | if (WARN_ON(!chanctx_conf)) { |
3b79af97 JB |
4151 | ret = -EINVAL; |
4152 | goto unlock; | |
55de908a | 4153 | } |
4bf88530 | 4154 | band = chanctx_conf->def.chan->band; |
06500736 JB |
4155 | |
4156 | if (qos) { | |
4157 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
4158 | IEEE80211_STYPE_QOS_NULLFUNC | | |
4159 | IEEE80211_FCTL_FROMDS); | |
4160 | } else { | |
4161 | size -= 2; | |
4162 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
4163 | IEEE80211_STYPE_NULLFUNC | | |
4164 | IEEE80211_FCTL_FROMDS); | |
4165 | } | |
4166 | ||
4167 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); | |
55de908a | 4168 | if (!skb) { |
3b79af97 JB |
4169 | ret = -ENOMEM; |
4170 | goto unlock; | |
55de908a | 4171 | } |
06500736 JB |
4172 | |
4173 | skb->dev = dev; | |
4174 | ||
4175 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
4176 | ||
4df864c1 | 4177 | nullfunc = skb_put(skb, size); |
06500736 JB |
4178 | nullfunc->frame_control = fc; |
4179 | nullfunc->duration_id = 0; | |
4180 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); | |
4181 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | |
4182 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); | |
4183 | nullfunc->seq_ctrl = 0; | |
4184 | ||
4185 | info = IEEE80211_SKB_CB(skb); | |
4186 | ||
4187 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | | |
4188 | IEEE80211_TX_INTFL_NL80211_FRAME_TX; | |
73c4e195 | 4189 | info->band = band; |
06500736 JB |
4190 | |
4191 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); | |
4192 | skb->priority = 7; | |
4193 | if (qos) | |
4194 | nullfunc->qos_ctrl = cpu_to_le16(7); | |
4195 | ||
5ee00dbd JB |
4196 | ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); |
4197 | if (ret) { | |
3b79af97 | 4198 | kfree_skb(skb); |
3b79af97 JB |
4199 | goto unlock; |
4200 | } | |
4201 | ||
06500736 | 4202 | local_bh_disable(); |
08aca29a | 4203 | ieee80211_xmit(sdata, sta, skb); |
06500736 | 4204 | local_bh_enable(); |
3b79af97 JB |
4205 | |
4206 | ret = 0; | |
4207 | unlock: | |
55de908a | 4208 | rcu_read_unlock(); |
06500736 | 4209 | |
3b79af97 | 4210 | return ret; |
06500736 JB |
4211 | } |
4212 | ||
683b6d3b JB |
4213 | static int ieee80211_cfg_get_channel(struct wiphy *wiphy, |
4214 | struct wireless_dev *wdev, | |
7b0a0e3c | 4215 | unsigned int link_id, |
683b6d3b | 4216 | struct cfg80211_chan_def *chandef) |
5b7ccaf3 | 4217 | { |
55de908a | 4218 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
cb601ffa | 4219 | struct ieee80211_local *local = wiphy_priv(wiphy); |
55de908a | 4220 | struct ieee80211_chanctx_conf *chanctx_conf; |
d8675a63 | 4221 | struct ieee80211_link_data *link; |
683b6d3b | 4222 | int ret = -ENODATA; |
55de908a JB |
4223 | |
4224 | rcu_read_lock(); | |
d8675a63 JB |
4225 | link = rcu_dereference(sdata->link[link_id]); |
4226 | if (!link) { | |
4227 | ret = -ENOLINK; | |
4228 | goto out; | |
4229 | } | |
4230 | ||
4231 | chanctx_conf = rcu_dereference(link->conf->chanctx_conf); | |
feda3027 | 4232 | if (chanctx_conf) { |
6092077a | 4233 | *chandef = link->conf->chanreq.oper; |
feda3027 JB |
4234 | ret = 0; |
4235 | } else if (local->open_count > 0 && | |
4236 | local->open_count == local->monitors && | |
4237 | sdata->vif.type == NL80211_IFTYPE_MONITOR) { | |
6092077a | 4238 | *chandef = local->monitor_chanreq.oper; |
683b6d3b | 4239 | ret = 0; |
55de908a | 4240 | } |
d8675a63 | 4241 | out: |
55de908a | 4242 | rcu_read_unlock(); |
5b7ccaf3 | 4243 | |
683b6d3b | 4244 | return ret; |
5b7ccaf3 JB |
4245 | } |
4246 | ||
6d52563f JB |
4247 | #ifdef CONFIG_PM |
4248 | static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) | |
4249 | { | |
4250 | drv_set_wakeup(wiphy_priv(wiphy), enabled); | |
4251 | } | |
4252 | #endif | |
4253 | ||
32db6b54 KP |
4254 | static int ieee80211_set_qos_map(struct wiphy *wiphy, |
4255 | struct net_device *dev, | |
4256 | struct cfg80211_qos_map *qos_map) | |
4257 | { | |
4258 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4259 | struct mac80211_qos_map *new_qos_map, *old_qos_map; | |
4260 | ||
4261 | if (qos_map) { | |
4262 | new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL); | |
4263 | if (!new_qos_map) | |
4264 | return -ENOMEM; | |
4265 | memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); | |
4266 | } else { | |
4267 | /* A NULL qos_map was passed to disable QoS mapping */ | |
4268 | new_qos_map = NULL; | |
4269 | } | |
4270 | ||
194ff52d | 4271 | old_qos_map = sdata_dereference(sdata->qos_map, sdata); |
32db6b54 KP |
4272 | rcu_assign_pointer(sdata->qos_map, new_qos_map); |
4273 | if (old_qos_map) | |
4274 | kfree_rcu(old_qos_map, rcu_head); | |
4275 | ||
4276 | return 0; | |
4277 | } | |
4278 | ||
3b1700bd JM |
4279 | static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, |
4280 | struct net_device *dev, | |
7b0a0e3c | 4281 | unsigned int link_id, |
3b1700bd JM |
4282 | struct cfg80211_chan_def *chandef) |
4283 | { | |
4284 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
d8675a63 | 4285 | struct ieee80211_link_data *link; |
6092077a | 4286 | struct ieee80211_chan_req chanreq = { .oper = *chandef }; |
3b1700bd | 4287 | int ret; |
aa87cd8b | 4288 | u64 changed = 0; |
3b1700bd | 4289 | |
d8675a63 JB |
4290 | link = sdata_dereference(sdata->link[link_id], sdata); |
4291 | ||
6092077a | 4292 | ret = ieee80211_link_change_chanreq(link, &chanreq, &changed); |
3b1700bd | 4293 | if (ret == 0) |
d8675a63 | 4294 | ieee80211_link_info_change_notify(sdata, link, changed); |
3b1700bd JM |
4295 | |
4296 | return ret; | |
4297 | } | |
4298 | ||
02219b3a JB |
4299 | static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
4300 | u8 tsid, const u8 *peer, u8 up, | |
4301 | u16 admitted_time) | |
4302 | { | |
4303 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4304 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
4305 | int ac = ieee802_1d_to_ac[up]; | |
4306 | ||
4307 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
4308 | return -EOPNOTSUPP; | |
4309 | ||
4310 | if (!(sdata->wmm_acm & BIT(up))) | |
4311 | return -EINVAL; | |
4312 | ||
4313 | if (ifmgd->tx_tspec[ac].admitted_time) | |
4314 | return -EBUSY; | |
4315 | ||
4316 | if (admitted_time) { | |
4317 | ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; | |
4318 | ifmgd->tx_tspec[ac].tsid = tsid; | |
4319 | ifmgd->tx_tspec[ac].up = up; | |
4320 | } | |
4321 | ||
4322 | return 0; | |
4323 | } | |
4324 | ||
4325 | static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, | |
4326 | u8 tsid, const u8 *peer) | |
4327 | { | |
4328 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4329 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
4330 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4331 | int ac; | |
4332 | ||
4333 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | |
4334 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; | |
4335 | ||
4336 | /* skip unused entries */ | |
4337 | if (!tx_tspec->admitted_time) | |
4338 | continue; | |
4339 | ||
4340 | if (tx_tspec->tsid != tsid) | |
4341 | continue; | |
4342 | ||
4343 | /* due to this new packets will be reassigned to non-ACM ACs */ | |
4344 | tx_tspec->up = -1; | |
4345 | ||
4346 | /* Make sure that all packets have been sent to avoid to | |
4347 | * restore the QoS params on packets that are still on the | |
4348 | * queues. | |
4349 | */ | |
4350 | synchronize_net(); | |
3b24f4c6 | 4351 | ieee80211_flush_queues(local, sdata, false); |
02219b3a JB |
4352 | |
4353 | /* restore the normal QoS parameters | |
4354 | * (unconditionally to avoid races) | |
4355 | */ | |
4356 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; | |
4357 | tx_tspec->downgraded = false; | |
4358 | ieee80211_sta_handle_tspec_ac_params(sdata); | |
4359 | ||
4360 | /* finally clear all the data */ | |
4361 | memset(tx_tspec, 0, sizeof(*tx_tspec)); | |
4362 | ||
4363 | return 0; | |
4364 | } | |
4365 | ||
4366 | return -ENOENT; | |
4367 | } | |
4368 | ||
167e33f4 AB |
4369 | void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, |
4370 | u8 inst_id, | |
4371 | enum nl80211_nan_func_term_reason reason, | |
4372 | gfp_t gfp) | |
4373 | { | |
4374 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4375 | struct cfg80211_nan_func *func; | |
4376 | u64 cookie; | |
4377 | ||
4378 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) | |
4379 | return; | |
4380 | ||
4381 | spin_lock_bh(&sdata->u.nan.func_lock); | |
4382 | ||
4383 | func = idr_find(&sdata->u.nan.function_inst_ids, inst_id); | |
4384 | if (WARN_ON(!func)) { | |
4385 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4386 | return; | |
4387 | } | |
4388 | ||
4389 | cookie = func->cookie; | |
4390 | idr_remove(&sdata->u.nan.function_inst_ids, inst_id); | |
4391 | ||
4392 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4393 | ||
4394 | cfg80211_free_nan_func(func); | |
4395 | ||
4396 | cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, | |
4397 | reason, cookie, gfp); | |
4398 | } | |
4399 | EXPORT_SYMBOL(ieee80211_nan_func_terminated); | |
4400 | ||
92bc43bc AB |
4401 | void ieee80211_nan_func_match(struct ieee80211_vif *vif, |
4402 | struct cfg80211_nan_match_params *match, | |
4403 | gfp_t gfp) | |
4404 | { | |
4405 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4406 | struct cfg80211_nan_func *func; | |
4407 | ||
4408 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) | |
4409 | return; | |
4410 | ||
4411 | spin_lock_bh(&sdata->u.nan.func_lock); | |
4412 | ||
4413 | func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id); | |
4414 | if (WARN_ON(!func)) { | |
4415 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4416 | return; | |
4417 | } | |
4418 | match->cookie = func->cookie; | |
4419 | ||
4420 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4421 | ||
4422 | cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); | |
4423 | } | |
4424 | EXPORT_SYMBOL(ieee80211_nan_func_match); | |
4425 | ||
ebceec86 MB |
4426 | static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, |
4427 | struct net_device *dev, | |
4428 | const bool enabled) | |
4429 | { | |
4430 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4431 | ||
4432 | sdata->u.ap.multicast_to_unicast = enabled; | |
4433 | ||
4434 | return 0; | |
4435 | } | |
4436 | ||
2fe4a29a THJ |
4437 | void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, |
4438 | struct txq_info *txqi) | |
4439 | { | |
4440 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { | |
4441 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); | |
4442 | txqstats->backlog_bytes = txqi->tin.backlog_bytes; | |
4443 | } | |
4444 | ||
4445 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { | |
4446 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); | |
4447 | txqstats->backlog_packets = txqi->tin.backlog_packets; | |
4448 | } | |
4449 | ||
4450 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { | |
4451 | txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); | |
4452 | txqstats->flows = txqi->tin.flows; | |
4453 | } | |
4454 | ||
4455 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { | |
4456 | txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); | |
4457 | txqstats->drops = txqi->cstats.drop_count; | |
4458 | } | |
4459 | ||
4460 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { | |
4461 | txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); | |
4462 | txqstats->ecn_marks = txqi->cstats.ecn_mark; | |
4463 | } | |
4464 | ||
4465 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { | |
4466 | txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); | |
4467 | txqstats->overlimit = txqi->tin.overlimit; | |
4468 | } | |
4469 | ||
4470 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { | |
4471 | txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); | |
4472 | txqstats->collisions = txqi->tin.collisions; | |
4473 | } | |
4474 | ||
4475 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { | |
4476 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); | |
4477 | txqstats->tx_bytes = txqi->tin.tx_bytes; | |
4478 | } | |
4479 | ||
4480 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { | |
4481 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); | |
4482 | txqstats->tx_packets = txqi->tin.tx_packets; | |
4483 | } | |
4484 | } | |
4485 | ||
4486 | static int ieee80211_get_txq_stats(struct wiphy *wiphy, | |
4487 | struct wireless_dev *wdev, | |
4488 | struct cfg80211_txq_stats *txqstats) | |
4489 | { | |
4490 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4491 | struct ieee80211_sub_if_data *sdata; | |
4492 | int ret = 0; | |
4493 | ||
2fe4a29a THJ |
4494 | spin_lock_bh(&local->fq.lock); |
4495 | rcu_read_lock(); | |
4496 | ||
4497 | if (wdev) { | |
4498 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
4499 | if (!sdata->vif.txq) { | |
4500 | ret = 1; | |
4501 | goto out; | |
4502 | } | |
4503 | ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); | |
4504 | } else { | |
4505 | /* phy stats */ | |
4506 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | | |
4507 | BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | | |
4508 | BIT(NL80211_TXQ_STATS_OVERLIMIT) | | |
4509 | BIT(NL80211_TXQ_STATS_OVERMEMORY) | | |
4510 | BIT(NL80211_TXQ_STATS_COLLISIONS) | | |
4511 | BIT(NL80211_TXQ_STATS_MAX_FLOWS); | |
4512 | txqstats->backlog_packets = local->fq.backlog; | |
4513 | txqstats->backlog_bytes = local->fq.memory_usage; | |
4514 | txqstats->overlimit = local->fq.overlimit; | |
4515 | txqstats->overmemory = local->fq.overmemory; | |
4516 | txqstats->collisions = local->fq.collisions; | |
4517 | txqstats->max_flows = local->fq.flows_cnt; | |
4518 | } | |
4519 | ||
4520 | out: | |
4521 | rcu_read_unlock(); | |
4522 | spin_unlock_bh(&local->fq.lock); | |
4523 | ||
4524 | return ret; | |
4525 | } | |
4526 | ||
bc847970 PKC |
4527 | static int |
4528 | ieee80211_get_ftm_responder_stats(struct wiphy *wiphy, | |
4529 | struct net_device *dev, | |
4530 | struct cfg80211_ftm_responder_stats *ftm_stats) | |
4531 | { | |
4532 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4533 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4534 | ||
4535 | return drv_get_ftm_responder_stats(local, sdata, ftm_stats); | |
4536 | } | |
4537 | ||
cee7013b JB |
4538 | static int |
4539 | ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, | |
4540 | struct cfg80211_pmsr_request *request) | |
4541 | { | |
4542 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4543 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); | |
4544 | ||
4545 | return drv_start_pmsr(local, sdata, request); | |
4546 | } | |
4547 | ||
4548 | static void | |
4549 | ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, | |
4550 | struct cfg80211_pmsr_request *request) | |
4551 | { | |
4552 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4553 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); | |
4554 | ||
4555 | return drv_abort_pmsr(local, sdata, request); | |
4556 | } | |
4557 | ||
370f51d5 T |
4558 | static int ieee80211_set_tid_config(struct wiphy *wiphy, |
4559 | struct net_device *dev, | |
4560 | struct cfg80211_tid_config *tid_conf) | |
4561 | { | |
4562 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4563 | struct sta_info *sta; | |
4d3acf43 JB |
4564 | |
4565 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
370f51d5 T |
4566 | |
4567 | if (!sdata->local->ops->set_tid_config) | |
4568 | return -EOPNOTSUPP; | |
4569 | ||
4570 | if (!tid_conf->peer) | |
4571 | return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf); | |
4572 | ||
370f51d5 | 4573 | sta = sta_info_get_bss(sdata, tid_conf->peer); |
4d3acf43 | 4574 | if (!sta) |
370f51d5 | 4575 | return -ENOENT; |
370f51d5 | 4576 | |
4d3acf43 | 4577 | return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf); |
370f51d5 T |
4578 | } |
4579 | ||
4580 | static int ieee80211_reset_tid_config(struct wiphy *wiphy, | |
4581 | struct net_device *dev, | |
60c2ef0e | 4582 | const u8 *peer, u8 tids) |
370f51d5 T |
4583 | { |
4584 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4585 | struct sta_info *sta; | |
4d3acf43 JB |
4586 | |
4587 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
370f51d5 T |
4588 | |
4589 | if (!sdata->local->ops->reset_tid_config) | |
4590 | return -EOPNOTSUPP; | |
4591 | ||
4592 | if (!peer) | |
60c2ef0e | 4593 | return drv_reset_tid_config(sdata->local, sdata, NULL, tids); |
370f51d5 | 4594 | |
370f51d5 | 4595 | sta = sta_info_get_bss(sdata, peer); |
4d3acf43 | 4596 | if (!sta) |
370f51d5 | 4597 | return -ENOENT; |
370f51d5 | 4598 | |
4d3acf43 | 4599 | return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids); |
370f51d5 T |
4600 | } |
4601 | ||
c534e093 CH |
4602 | static int ieee80211_set_sar_specs(struct wiphy *wiphy, |
4603 | struct cfg80211_sar_specs *sar) | |
4604 | { | |
4605 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4606 | ||
4607 | if (!local->ops->set_sar_specs) | |
4608 | return -EOPNOTSUPP; | |
4609 | ||
4610 | return local->ops->set_sar_specs(&local->hw, sar); | |
4611 | } | |
4612 | ||
5f9404ab JC |
4613 | static int |
4614 | ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata, | |
15ddba5f | 4615 | u64 *changed) |
5f9404ab JC |
4616 | { |
4617 | switch (sdata->vif.type) { | |
4618 | case NL80211_IFTYPE_AP: { | |
4619 | int ret; | |
4620 | ||
bfd8403a | 4621 | if (!sdata->deflink.u.ap.next_beacon) |
450c271d LB |
4622 | return -EINVAL; |
4623 | ||
d8675a63 | 4624 | ret = ieee80211_assign_beacon(sdata, &sdata->deflink, |
bfd8403a | 4625 | sdata->deflink.u.ap.next_beacon, |
15ddba5f | 4626 | NULL, NULL, changed); |
d9f83f22 | 4627 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab JC |
4628 | |
4629 | if (ret < 0) | |
4630 | return ret; | |
4631 | ||
5f9404ab JC |
4632 | break; |
4633 | } | |
4634 | default: | |
4635 | WARN_ON_ONCE(1); | |
4636 | return -EINVAL; | |
4637 | } | |
4638 | ||
4639 | return 0; | |
4640 | } | |
4641 | ||
4642 | static int | |
4643 | ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata, | |
4644 | struct cfg80211_color_change_settings *params, | |
15ddba5f | 4645 | u64 *changed) |
5f9404ab JC |
4646 | { |
4647 | struct ieee80211_color_change_settings color_change = {}; | |
4648 | int err; | |
4649 | ||
4650 | switch (sdata->vif.type) { | |
4651 | case NL80211_IFTYPE_AP: | |
bfd8403a | 4652 | sdata->deflink.u.ap.next_beacon = |
5f9404ab | 4653 | cfg80211_beacon_dup(¶ms->beacon_next); |
bfd8403a | 4654 | if (!sdata->deflink.u.ap.next_beacon) |
5f9404ab JC |
4655 | return -ENOMEM; |
4656 | ||
4657 | if (params->count <= 1) | |
4658 | break; | |
4659 | ||
4660 | color_change.counter_offset_beacon = | |
4661 | params->counter_offset_beacon; | |
4662 | color_change.counter_offset_presp = | |
4663 | params->counter_offset_presp; | |
4664 | color_change.count = params->count; | |
4665 | ||
d8675a63 JB |
4666 | err = ieee80211_assign_beacon(sdata, &sdata->deflink, |
4667 | ¶ms->beacon_color_change, | |
15ddba5f | 4668 | NULL, &color_change, changed); |
5f9404ab | 4669 | if (err < 0) { |
d9f83f22 | 4670 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab JC |
4671 | return err; |
4672 | } | |
5f9404ab JC |
4673 | break; |
4674 | default: | |
4675 | return -EOPNOTSUPP; | |
4676 | } | |
4677 | ||
4678 | return 0; | |
4679 | } | |
4680 | ||
4681 | static void | |
4682 | ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata, | |
15ddba5f | 4683 | u8 color, int enable, u64 changed) |
5f9404ab | 4684 | { |
be0df01d JB |
4685 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
4686 | ||
5f9404ab JC |
4687 | sdata->vif.bss_conf.he_bss_color.color = color; |
4688 | sdata->vif.bss_conf.he_bss_color.enabled = enable; | |
4689 | changed |= BSS_CHANGED_HE_BSS_COLOR; | |
4690 | ||
d8675a63 | 4691 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); |
eb87d3e0 JC |
4692 | |
4693 | if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) { | |
4694 | struct ieee80211_sub_if_data *child; | |
4695 | ||
eb87d3e0 JC |
4696 | list_for_each_entry(child, &sdata->local->interfaces, list) { |
4697 | if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) { | |
4698 | child->vif.bss_conf.he_bss_color.color = color; | |
4699 | child->vif.bss_conf.he_bss_color.enabled = enable; | |
d8675a63 JB |
4700 | ieee80211_link_info_change_notify(child, |
4701 | &child->deflink, | |
7b7090b4 | 4702 | BSS_CHANGED_HE_BSS_COLOR); |
eb87d3e0 JC |
4703 | } |
4704 | } | |
eb87d3e0 | 4705 | } |
5f9404ab JC |
4706 | } |
4707 | ||
4708 | static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata) | |
4709 | { | |
4710 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 4711 | u64 changed = 0; |
5f9404ab JC |
4712 | int err; |
4713 | ||
0cd8080e | 4714 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab | 4715 | |
d0a9123e | 4716 | sdata->vif.bss_conf.color_change_active = false; |
5f9404ab JC |
4717 | |
4718 | err = ieee80211_set_after_color_change_beacon(sdata, &changed); | |
4719 | if (err) { | |
4720 | cfg80211_color_change_aborted_notify(sdata->dev); | |
4721 | return err; | |
4722 | } | |
4723 | ||
4724 | ieee80211_color_change_bss_config_notify(sdata, | |
d0a9123e | 4725 | sdata->vif.bss_conf.color_change_color, |
5f9404ab JC |
4726 | 1, changed); |
4727 | cfg80211_color_change_notify(sdata->dev); | |
4728 | ||
4729 | return 0; | |
4730 | } | |
4731 | ||
b38579ae JB |
4732 | void ieee80211_color_change_finalize_work(struct wiphy *wiphy, |
4733 | struct wiphy_work *work) | |
5f9404ab JC |
4734 | { |
4735 | struct ieee80211_sub_if_data *sdata = | |
4736 | container_of(work, struct ieee80211_sub_if_data, | |
bfd8403a | 4737 | deflink.color_change_finalize_work); |
5f9404ab JC |
4738 | struct ieee80211_local *local = sdata->local; |
4739 | ||
0cd8080e | 4740 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab JC |
4741 | |
4742 | /* AP might have been stopped while waiting for the lock. */ | |
d0a9123e | 4743 | if (!sdata->vif.bss_conf.color_change_active) |
076fc877 | 4744 | return; |
5f9404ab JC |
4745 | |
4746 | if (!ieee80211_sdata_running(sdata)) | |
076fc877 | 4747 | return; |
5f9404ab JC |
4748 | |
4749 | ieee80211_color_change_finalize(sdata); | |
5f9404ab JC |
4750 | } |
4751 | ||
92881884 LB |
4752 | void ieee80211_color_collision_detection_work(struct work_struct *work) |
4753 | { | |
4754 | struct delayed_work *delayed_work = to_delayed_work(work); | |
4755 | struct ieee80211_link_data *link = | |
4756 | container_of(delayed_work, struct ieee80211_link_data, | |
4757 | color_collision_detect_work); | |
4758 | struct ieee80211_sub_if_data *sdata = link->sdata; | |
4759 | ||
935ef47b | 4760 | cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap); |
92881884 LB |
4761 | } |
4762 | ||
5f9404ab JC |
4763 | void ieee80211_color_change_finish(struct ieee80211_vif *vif) |
4764 | { | |
4765 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4766 | ||
b38579ae JB |
4767 | wiphy_work_queue(sdata->local->hw.wiphy, |
4768 | &sdata->deflink.color_change_finalize_work); | |
5f9404ab JC |
4769 | } |
4770 | EXPORT_SYMBOL_GPL(ieee80211_color_change_finish); | |
4771 | ||
4772 | void | |
82253dda | 4773 | ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif, |
6f656131 | 4774 | u64 color_bitmap) |
5f9404ab JC |
4775 | { |
4776 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
92881884 | 4777 | struct ieee80211_link_data *link = &sdata->deflink; |
5f9404ab | 4778 | |
d0a9123e | 4779 | if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) |
5f9404ab JC |
4780 | return; |
4781 | ||
92881884 LB |
4782 | if (delayed_work_pending(&link->color_collision_detect_work)) |
4783 | return; | |
4784 | ||
4785 | link->color_bitmap = color_bitmap; | |
4786 | /* queue the color collision detection event every 500 ms in order to | |
4787 | * avoid sending too much netlink messages to userspace. | |
4788 | */ | |
4789 | ieee80211_queue_delayed_work(&sdata->local->hw, | |
4790 | &link->color_collision_detect_work, | |
4791 | msecs_to_jiffies(500)); | |
5f9404ab | 4792 | } |
82253dda | 4793 | EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify); |
5f9404ab JC |
4794 | |
4795 | static int | |
4796 | ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, | |
4797 | struct cfg80211_color_change_settings *params) | |
4798 | { | |
4799 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4800 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 4801 | u64 changed = 0; |
5f9404ab JC |
4802 | int err; |
4803 | ||
0cd8080e | 4804 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab | 4805 | |
eb87d3e0 JC |
4806 | if (sdata->vif.bss_conf.nontransmitted) |
4807 | return -EINVAL; | |
4808 | ||
5f9404ab JC |
4809 | /* don't allow another color change if one is already active or if csa |
4810 | * is active | |
4811 | */ | |
d0a9123e | 4812 | if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) { |
5f9404ab JC |
4813 | err = -EBUSY; |
4814 | goto out; | |
4815 | } | |
4816 | ||
4817 | err = ieee80211_set_color_change_beacon(sdata, params, &changed); | |
4818 | if (err) | |
4819 | goto out; | |
4820 | ||
d0a9123e JB |
4821 | sdata->vif.bss_conf.color_change_active = true; |
4822 | sdata->vif.bss_conf.color_change_color = params->color; | |
5f9404ab JC |
4823 | |
4824 | cfg80211_color_change_started_notify(sdata->dev, params->count); | |
4825 | ||
4826 | if (changed) | |
4827 | ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed); | |
4828 | else | |
4829 | /* if the beacon didn't change, we can finalize immediately */ | |
4830 | ieee80211_color_change_finalize(sdata); | |
4831 | ||
4832 | out: | |
5f9404ab JC |
4833 | |
4834 | return err; | |
4835 | } | |
4836 | ||
237337c2 | 4837 | static int |
a95bfb87 LB |
4838 | ieee80211_set_radar_background(struct wiphy *wiphy, |
4839 | struct cfg80211_chan_def *chandef) | |
237337c2 LB |
4840 | { |
4841 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4842 | ||
a95bfb87 | 4843 | if (!local->ops->set_radar_background) |
237337c2 LB |
4844 | return -EOPNOTSUPP; |
4845 | ||
a95bfb87 | 4846 | return local->ops->set_radar_background(&local->hw, chandef); |
237337c2 LB |
4847 | } |
4848 | ||
0d8c4a3c JB |
4849 | static int ieee80211_add_intf_link(struct wiphy *wiphy, |
4850 | struct wireless_dev *wdev, | |
4851 | unsigned int link_id) | |
4852 | { | |
4853 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
0cd8080e JB |
4854 | |
4855 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
0d8c4a3c | 4856 | |
90703ba9 JB |
4857 | if (wdev->use_4addr) |
4858 | return -EOPNOTSUPP; | |
4859 | ||
0cd8080e | 4860 | return ieee80211_vif_set_links(sdata, wdev->valid_links, 0); |
0d8c4a3c JB |
4861 | } |
4862 | ||
4863 | static void ieee80211_del_intf_link(struct wiphy *wiphy, | |
4864 | struct wireless_dev *wdev, | |
4865 | unsigned int link_id) | |
4866 | { | |
4867 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
4868 | ||
0cd8080e JB |
4869 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
4870 | ||
6d543b34 | 4871 | ieee80211_vif_set_links(sdata, wdev->valid_links, 0); |
0d8c4a3c JB |
4872 | } |
4873 | ||
21476ad1 ST |
4874 | static int sta_add_link_station(struct ieee80211_local *local, |
4875 | struct ieee80211_sub_if_data *sdata, | |
4876 | struct link_station_parameters *params) | |
4877 | { | |
4878 | struct sta_info *sta; | |
4879 | int ret; | |
4880 | ||
4881 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
4882 | if (!sta) | |
4883 | return -ENOENT; | |
4884 | ||
956b9613 JB |
4885 | if (!sta->sta.valid_links) |
4886 | return -EINVAL; | |
4887 | ||
21476ad1 ST |
4888 | if (sta->sta.valid_links & BIT(params->link_id)) |
4889 | return -EALREADY; | |
4890 | ||
4891 | ret = ieee80211_sta_allocate_link(sta, params->link_id); | |
4892 | if (ret) | |
4893 | return ret; | |
4894 | ||
9aebce6c | 4895 | ret = sta_link_apply_parameters(local, sta, true, params); |
21476ad1 ST |
4896 | if (ret) { |
4897 | ieee80211_sta_free_link(sta, params->link_id); | |
4898 | return ret; | |
4899 | } | |
4900 | ||
4901 | /* ieee80211_sta_activate_link frees the link upon failure */ | |
4902 | return ieee80211_sta_activate_link(sta, params->link_id); | |
4903 | } | |
4904 | ||
4905 | static int | |
4906 | ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev, | |
4907 | struct link_station_parameters *params) | |
4908 | { | |
4909 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4910 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
21476ad1 | 4911 | |
4d3acf43 | 4912 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 4913 | |
4d3acf43 | 4914 | return sta_add_link_station(local, sdata, params); |
21476ad1 ST |
4915 | } |
4916 | ||
4917 | static int sta_mod_link_station(struct ieee80211_local *local, | |
4918 | struct ieee80211_sub_if_data *sdata, | |
4919 | struct link_station_parameters *params) | |
4920 | { | |
4921 | struct sta_info *sta; | |
4922 | ||
4923 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
4924 | if (!sta) | |
4925 | return -ENOENT; | |
4926 | ||
4927 | if (!(sta->sta.valid_links & BIT(params->link_id))) | |
4928 | return -EINVAL; | |
4929 | ||
9aebce6c | 4930 | return sta_link_apply_parameters(local, sta, false, params); |
21476ad1 ST |
4931 | } |
4932 | ||
4933 | static int | |
4934 | ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev, | |
4935 | struct link_station_parameters *params) | |
4936 | { | |
4937 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4938 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
21476ad1 | 4939 | |
4d3acf43 | 4940 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 4941 | |
4d3acf43 | 4942 | return sta_mod_link_station(local, sdata, params); |
21476ad1 ST |
4943 | } |
4944 | ||
4945 | static int sta_del_link_station(struct ieee80211_sub_if_data *sdata, | |
4946 | struct link_station_del_parameters *params) | |
4947 | { | |
4948 | struct sta_info *sta; | |
4949 | ||
4950 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
4951 | if (!sta) | |
4952 | return -ENOENT; | |
4953 | ||
4954 | if (!(sta->sta.valid_links & BIT(params->link_id))) | |
4955 | return -EINVAL; | |
4956 | ||
956b9613 JB |
4957 | /* must not create a STA without links */ |
4958 | if (sta->sta.valid_links == BIT(params->link_id)) | |
4959 | return -EINVAL; | |
4960 | ||
21476ad1 ST |
4961 | ieee80211_sta_remove_link(sta, params->link_id); |
4962 | ||
4963 | return 0; | |
4964 | } | |
4965 | ||
4966 | static int | |
4967 | ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev, | |
4968 | struct link_station_del_parameters *params) | |
4969 | { | |
4970 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
21476ad1 | 4971 | |
4d3acf43 | 4972 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 4973 | |
4d3acf43 | 4974 | return sta_del_link_station(sdata, params); |
21476ad1 ST |
4975 | } |
4976 | ||
81202305 AS |
4977 | static int ieee80211_set_hw_timestamp(struct wiphy *wiphy, |
4978 | struct net_device *dev, | |
4979 | struct cfg80211_set_hw_timestamp *hwts) | |
4980 | { | |
4981 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4982 | struct ieee80211_local *local = sdata->local; | |
4983 | ||
4984 | if (!local->ops->set_hw_timestamp) | |
4985 | return -EOPNOTSUPP; | |
4986 | ||
4987 | if (!check_sdata_in_driver(sdata)) | |
4988 | return -EIO; | |
4989 | ||
4990 | return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts); | |
4991 | } | |
4992 | ||
f7660b3f AB |
4993 | static int |
4994 | ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev, | |
4995 | struct cfg80211_ttlm_params *params) | |
4996 | { | |
4997 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4998 | ||
4999 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
5000 | ||
5001 | return ieee80211_req_neg_ttlm(sdata, params); | |
5002 | } | |
5003 | ||
8a47cea7 | 5004 | const struct cfg80211_ops mac80211_config_ops = { |
f0706e82 JB |
5005 | .add_virtual_intf = ieee80211_add_iface, |
5006 | .del_virtual_intf = ieee80211_del_iface, | |
42613db7 | 5007 | .change_virtual_intf = ieee80211_change_iface, |
f142c6b9 JB |
5008 | .start_p2p_device = ieee80211_start_p2p_device, |
5009 | .stop_p2p_device = ieee80211_stop_p2p_device, | |
e8cbb4cb JB |
5010 | .add_key = ieee80211_add_key, |
5011 | .del_key = ieee80211_del_key, | |
62da92fb | 5012 | .get_key = ieee80211_get_key, |
e8cbb4cb | 5013 | .set_default_key = ieee80211_config_default_key, |
3cfcf6ac | 5014 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
e5473e80 | 5015 | .set_default_beacon_key = ieee80211_config_default_beacon_key, |
8860020e JB |
5016 | .start_ap = ieee80211_start_ap, |
5017 | .change_beacon = ieee80211_change_beacon, | |
5018 | .stop_ap = ieee80211_stop_ap, | |
4fd6931e JB |
5019 | .add_station = ieee80211_add_station, |
5020 | .del_station = ieee80211_del_station, | |
5021 | .change_station = ieee80211_change_station, | |
7bbdd2d9 | 5022 | .get_station = ieee80211_get_station, |
c5dd9c2b | 5023 | .dump_station = ieee80211_dump_station, |
1289723e | 5024 | .dump_survey = ieee80211_dump_survey, |
c5dd9c2b LCC |
5025 | #ifdef CONFIG_MAC80211_MESH |
5026 | .add_mpath = ieee80211_add_mpath, | |
5027 | .del_mpath = ieee80211_del_mpath, | |
5028 | .change_mpath = ieee80211_change_mpath, | |
5029 | .get_mpath = ieee80211_get_mpath, | |
5030 | .dump_mpath = ieee80211_dump_mpath, | |
a2db2ed3 HR |
5031 | .get_mpp = ieee80211_get_mpp, |
5032 | .dump_mpp = ieee80211_dump_mpp, | |
24bdd9f4 JC |
5033 | .update_mesh_config = ieee80211_update_mesh_config, |
5034 | .get_mesh_config = ieee80211_get_mesh_config, | |
29cbe68c JB |
5035 | .join_mesh = ieee80211_join_mesh, |
5036 | .leave_mesh = ieee80211_leave_mesh, | |
c5dd9c2b | 5037 | #endif |
239281f8 RL |
5038 | .join_ocb = ieee80211_join_ocb, |
5039 | .leave_ocb = ieee80211_leave_ocb, | |
9f1ba906 | 5040 | .change_bss = ieee80211_change_bss, |
108d2022 | 5041 | .inform_bss = ieee80211_inform_bss, |
31888487 | 5042 | .set_txq_params = ieee80211_set_txq_params, |
e8c9bd5b | 5043 | .set_monitor_channel = ieee80211_set_monitor_channel, |
665af4fc BC |
5044 | .suspend = ieee80211_suspend, |
5045 | .resume = ieee80211_resume, | |
2a519311 | 5046 | .scan = ieee80211_scan, |
91f123f2 | 5047 | .abort_scan = ieee80211_abort_scan, |
79f460ca LC |
5048 | .sched_scan_start = ieee80211_sched_scan_start, |
5049 | .sched_scan_stop = ieee80211_sched_scan_stop, | |
636a5d36 JM |
5050 | .auth = ieee80211_auth, |
5051 | .assoc = ieee80211_assoc, | |
5052 | .deauth = ieee80211_deauth, | |
5053 | .disassoc = ieee80211_disassoc, | |
af8cdcd8 JB |
5054 | .join_ibss = ieee80211_join_ibss, |
5055 | .leave_ibss = ieee80211_leave_ibss, | |
391e53e3 | 5056 | .set_mcast_rate = ieee80211_set_mcast_rate, |
b9a5f8ca | 5057 | .set_wiphy_params = ieee80211_set_wiphy_params, |
7643a2c3 JB |
5058 | .set_tx_power = ieee80211_set_tx_power, |
5059 | .get_tx_power = ieee80211_get_tx_power, | |
1f87f7d3 | 5060 | .rfkill_poll = ieee80211_rfkill_poll, |
aff89a9b | 5061 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
71063f0e | 5062 | CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) |
bc92afd9 | 5063 | .set_power_mgmt = ieee80211_set_power_mgmt, |
9930380f | 5064 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
b8bc4b0a JB |
5065 | .remain_on_channel = ieee80211_remain_on_channel, |
5066 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, | |
2e161f78 | 5067 | .mgmt_tx = ieee80211_mgmt_tx, |
f30221e4 | 5068 | .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, |
a97c13c3 | 5069 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
2c3c5f8c | 5070 | .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, |
6cd536fe JB |
5071 | .update_mgmt_frame_registrations = |
5072 | ieee80211_update_mgmt_frame_registrations, | |
15d96753 BR |
5073 | .set_antenna = ieee80211_set_antenna, |
5074 | .get_antenna = ieee80211_get_antenna, | |
c68f4b89 | 5075 | .set_rekey_data = ieee80211_set_rekey_data, |
dfe018bf AN |
5076 | .tdls_oper = ieee80211_tdls_oper, |
5077 | .tdls_mgmt = ieee80211_tdls_mgmt, | |
a7a6bdd0 AN |
5078 | .tdls_channel_switch = ieee80211_tdls_channel_switch, |
5079 | .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, | |
06500736 | 5080 | .probe_client = ieee80211_probe_client, |
b53be792 | 5081 | .set_noack_map = ieee80211_set_noack_map, |
6d52563f JB |
5082 | #ifdef CONFIG_PM |
5083 | .set_wakeup = ieee80211_set_wakeup, | |
5084 | #endif | |
5b7ccaf3 | 5085 | .get_channel = ieee80211_cfg_get_channel, |
164eb02d | 5086 | .start_radar_detection = ieee80211_start_radar_detection, |
26ec17a1 | 5087 | .end_cac = ieee80211_end_cac, |
73da7d5b | 5088 | .channel_switch = ieee80211_channel_switch, |
32db6b54 | 5089 | .set_qos_map = ieee80211_set_qos_map, |
3b1700bd | 5090 | .set_ap_chanwidth = ieee80211_set_ap_chanwidth, |
02219b3a JB |
5091 | .add_tx_ts = ieee80211_add_tx_ts, |
5092 | .del_tx_ts = ieee80211_del_tx_ts, | |
708d50ed AB |
5093 | .start_nan = ieee80211_start_nan, |
5094 | .stop_nan = ieee80211_stop_nan, | |
5953ff6d | 5095 | .nan_change_conf = ieee80211_nan_change_conf, |
167e33f4 AB |
5096 | .add_nan_func = ieee80211_add_nan_func, |
5097 | .del_nan_func = ieee80211_del_nan_func, | |
ebceec86 | 5098 | .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, |
91180649 | 5099 | .tx_control_port = ieee80211_tx_control_port, |
2fe4a29a | 5100 | .get_txq_stats = ieee80211_get_txq_stats, |
bc847970 | 5101 | .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, |
cee7013b JB |
5102 | .start_pmsr = ieee80211_start_pmsr, |
5103 | .abort_pmsr = ieee80211_abort_pmsr, | |
8828f81a | 5104 | .probe_mesh_link = ieee80211_probe_mesh_link, |
370f51d5 T |
5105 | .set_tid_config = ieee80211_set_tid_config, |
5106 | .reset_tid_config = ieee80211_reset_tid_config, | |
c534e093 | 5107 | .set_sar_specs = ieee80211_set_sar_specs, |
5f9404ab | 5108 | .color_change = ieee80211_color_change, |
a95bfb87 | 5109 | .set_radar_background = ieee80211_set_radar_background, |
0d8c4a3c JB |
5110 | .add_intf_link = ieee80211_add_intf_link, |
5111 | .del_intf_link = ieee80211_del_intf_link, | |
21476ad1 ST |
5112 | .add_link_station = ieee80211_add_link_station, |
5113 | .mod_link_station = ieee80211_mod_link_station, | |
5114 | .del_link_station = ieee80211_del_link_station, | |
81202305 | 5115 | .set_hw_timestamp = ieee80211_set_hw_timestamp, |
f7660b3f | 5116 | .set_ttlm = ieee80211_set_ttlm, |
f0706e82 | 5117 | }; |