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 | ||
5fcc7c51 AKS |
1244 | static u8 ieee80211_num_beaconing_links(struct ieee80211_sub_if_data *sdata) |
1245 | { | |
1246 | struct ieee80211_link_data *link; | |
1247 | u8 link_id, num = 0; | |
1248 | ||
1249 | if (sdata->vif.type != NL80211_IFTYPE_AP && | |
1250 | sdata->vif.type != NL80211_IFTYPE_P2P_GO) | |
1251 | return num; | |
1252 | ||
1253 | if (!sdata->vif.valid_links) | |
1254 | return num; | |
1255 | ||
1256 | for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { | |
1257 | link = sdata_dereference(sdata->link[link_id], sdata); | |
1258 | if (!link) | |
1259 | continue; | |
1260 | ||
1261 | if (sdata_dereference(link->u.ap.beacon, sdata)) | |
1262 | num++; | |
1263 | } | |
1264 | ||
1265 | return num; | |
1266 | } | |
1267 | ||
8860020e JB |
1268 | static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, |
1269 | struct cfg80211_ap_settings *params) | |
5dfdaf58 | 1270 | { |
8860020e | 1271 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
34a3740d | 1272 | struct ieee80211_local *local = sdata->local; |
5dfdaf58 | 1273 | struct beacon_data *old; |
665c93a9 | 1274 | struct ieee80211_sub_if_data *vlan; |
2cc25e4b | 1275 | u64 changed = BSS_CHANGED_BEACON_INT | |
8860020e JB |
1276 | BSS_CHANGED_BEACON_ENABLED | |
1277 | BSS_CHANGED_BEACON | | |
4bcc56bb | 1278 | BSS_CHANGED_P2P_PS | |
a0de1ca3 | 1279 | BSS_CHANGED_TXPOWER | |
322cd27c | 1280 | BSS_CHANGED_TWT; |
08fad438 | 1281 | int i, err; |
83e37e0b | 1282 | int prev_beacon_int; |
d9f83f22 | 1283 | unsigned int link_id = params->beacon.link_id; |
d8675a63 JB |
1284 | struct ieee80211_link_data *link; |
1285 | struct ieee80211_bss_conf *link_conf; | |
6092077a | 1286 | struct ieee80211_chan_req chanreq = { .oper = params->chandef }; |
d8675a63 | 1287 | |
0cd8080e JB |
1288 | lockdep_assert_wiphy(local->hw.wiphy); |
1289 | ||
d8675a63 JB |
1290 | link = sdata_dereference(sdata->link[link_id], sdata); |
1291 | if (!link) | |
1292 | return -ENOLINK; | |
1293 | ||
1294 | link_conf = link->conf; | |
14db74bc | 1295 | |
d9f83f22 | 1296 | old = sdata_dereference(link->u.ap.beacon, sdata); |
5dfdaf58 JB |
1297 | if (old) |
1298 | return -EALREADY; | |
1299 | ||
52b4810b | 1300 | if (params->smps_mode != NL80211_SMPS_OFF) |
0528e0fd | 1301 | return -EOPNOTSUPP; |
52b4810b | 1302 | |
d9f83f22 | 1303 | link->smps_mode = IEEE80211_SMPS_OFF; |
b3dd8279 | 1304 | |
d9f83f22 | 1305 | link->needed_rx_chains = sdata->local->rx_chains; |
04ecd257 | 1306 | |
d9f83f22 ST |
1307 | prev_beacon_int = link_conf->beacon_int; |
1308 | link_conf->beacon_int = params->beacon_interval; | |
ac668afe | 1309 | |
2ad7dd94 RL |
1310 | if (params->ht_cap) |
1311 | link_conf->ht_ldpc = | |
1312 | params->ht_cap->cap_info & | |
1313 | cpu_to_le16(IEEE80211_HT_CAP_LDPC_CODING); | |
1314 | ||
42470fa0 | 1315 | if (params->vht_cap) { |
2ad7dd94 RL |
1316 | link_conf->vht_ldpc = |
1317 | params->vht_cap->vht_cap_info & | |
1318 | cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC); | |
42470fa0 MS |
1319 | link_conf->vht_su_beamformer = |
1320 | params->vht_cap->vht_cap_info & | |
1321 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); | |
1322 | link_conf->vht_su_beamformee = | |
1323 | params->vht_cap->vht_cap_info & | |
1324 | cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); | |
1325 | link_conf->vht_mu_beamformer = | |
1326 | params->vht_cap->vht_cap_info & | |
1327 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); | |
1328 | link_conf->vht_mu_beamformee = | |
1329 | params->vht_cap->vht_cap_info & | |
1330 | cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); | |
1331 | } | |
1332 | ||
03efb863 | 1333 | if (params->he_cap && params->he_oper) { |
d9f83f22 ST |
1334 | link_conf->he_support = true; |
1335 | link_conf->htc_trig_based_pkt_ext = | |
03efb863 ST |
1336 | le32_get_bits(params->he_oper->he_oper_params, |
1337 | IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK); | |
d9f83f22 | 1338 | link_conf->frame_time_rts_th = |
03efb863 ST |
1339 | le32_get_bits(params->he_oper->he_oper_params, |
1340 | IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK); | |
322cd27c P |
1341 | changed |= BSS_CHANGED_HE_OBSS_PD; |
1342 | ||
3d48cb74 | 1343 | if (params->beacon.he_bss_color.enabled) |
322cd27c | 1344 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
03efb863 | 1345 | } |
34fb190e | 1346 | |
b1b3297d | 1347 | if (params->he_cap) { |
2ad7dd94 RL |
1348 | link_conf->he_ldpc = |
1349 | params->he_cap->phy_cap_info[1] & | |
1350 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD; | |
b1b3297d MS |
1351 | link_conf->he_su_beamformer = |
1352 | params->he_cap->phy_cap_info[3] & | |
1353 | IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER; | |
1354 | link_conf->he_su_beamformee = | |
1355 | params->he_cap->phy_cap_info[4] & | |
1356 | IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE; | |
1357 | link_conf->he_mu_beamformer = | |
1358 | params->he_cap->phy_cap_info[4] & | |
1359 | IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; | |
1360 | link_conf->he_full_ul_mumimo = | |
1361 | params->he_cap->phy_cap_info[2] & | |
1362 | IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO; | |
1363 | } | |
1364 | ||
2cc25e4b | 1365 | if (params->eht_cap) { |
e3e0ca32 AD |
1366 | if (!link_conf->he_support) |
1367 | return -EOPNOTSUPP; | |
1368 | ||
1369 | link_conf->eht_support = true; | |
f4d1181e RL |
1370 | |
1371 | link_conf->eht_su_beamformer = | |
1372 | params->eht_cap->fixed.phy_cap_info[0] & | |
1373 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMER; | |
1374 | link_conf->eht_su_beamformee = | |
1375 | params->eht_cap->fixed.phy_cap_info[0] & | |
1376 | IEEE80211_EHT_PHY_CAP0_SU_BEAMFORMEE; | |
1377 | link_conf->eht_mu_beamformer = | |
1378 | params->eht_cap->fixed.phy_cap_info[7] & | |
1379 | (IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_80MHZ | | |
1380 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_160MHZ | | |
1381 | IEEE80211_EHT_PHY_CAP7_MU_BEAMFORMER_320MHZ); | |
1382 | } else { | |
1383 | link_conf->eht_su_beamformer = false; | |
1384 | link_conf->eht_su_beamformee = false; | |
1385 | link_conf->eht_mu_beamformer = false; | |
2cc25e4b AD |
1386 | } |
1387 | ||
17196425 JC |
1388 | if (sdata->vif.type == NL80211_IFTYPE_AP && |
1389 | params->mbssid_config.tx_wdev) { | |
1390 | err = ieee80211_set_ap_mbssid_options(sdata, | |
d9f83f22 ST |
1391 | params->mbssid_config, |
1392 | link_conf); | |
17196425 JC |
1393 | if (err) |
1394 | return err; | |
1395 | } | |
1396 | ||
6092077a | 1397 | err = ieee80211_link_use_channel(link, &chanreq, |
b4f85443 | 1398 | IEEE80211_CHANCTX_SHARED); |
4e141dad | 1399 | if (!err) |
d9f83f22 | 1400 | ieee80211_link_copy_chanctx_to_vlans(link, false); |
83e37e0b | 1401 | if (err) { |
d9f83f22 | 1402 | link_conf->beacon_int = prev_beacon_int; |
aa430da4 | 1403 | return err; |
83e37e0b | 1404 | } |
aa430da4 | 1405 | |
665c93a9 JB |
1406 | /* |
1407 | * Apply control port protocol, this allows us to | |
1408 | * not encrypt dynamic WEP control frames. | |
1409 | */ | |
1410 | sdata->control_port_protocol = params->crypto.control_port_ethertype; | |
1411 | sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; | |
018f6fbf DK |
1412 | sdata->control_port_over_nl80211 = |
1413 | params->crypto.control_port_over_nl80211; | |
7f3f96ce MT |
1414 | sdata->control_port_no_preauth = |
1415 | params->crypto.control_port_no_preauth; | |
2475b1cc | 1416 | |
665c93a9 JB |
1417 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { |
1418 | vlan->control_port_protocol = | |
1419 | params->crypto.control_port_ethertype; | |
1420 | vlan->control_port_no_encrypt = | |
1421 | params->crypto.control_port_no_encrypt; | |
018f6fbf DK |
1422 | vlan->control_port_over_nl80211 = |
1423 | params->crypto.control_port_over_nl80211; | |
7f3f96ce MT |
1424 | vlan->control_port_no_preauth = |
1425 | params->crypto.control_port_no_preauth; | |
665c93a9 JB |
1426 | } |
1427 | ||
d9f83f22 ST |
1428 | link_conf->dtim_period = params->dtim_period; |
1429 | link_conf->enable_beacon = true; | |
1430 | link_conf->allow_p2p_go_ps = sdata->vif.p2p; | |
1431 | link_conf->twt_responder = params->twt_responder; | |
1432 | link_conf->he_obss_pd = params->he_obss_pd; | |
1433 | link_conf->he_bss_color = params->beacon.he_bss_color; | |
f276e20b | 1434 | sdata->vif.cfg.s1g = params->chandef.chan->band == |
1d00ce80 | 1435 | NL80211_BAND_S1GHZ; |
8860020e | 1436 | |
f276e20b | 1437 | sdata->vif.cfg.ssid_len = params->ssid_len; |
8860020e | 1438 | if (params->ssid_len) |
f276e20b | 1439 | memcpy(sdata->vif.cfg.ssid, params->ssid, |
8860020e | 1440 | params->ssid_len); |
d9f83f22 | 1441 | link_conf->hidden_ssid = |
8860020e JB |
1442 | (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); |
1443 | ||
d9f83f22 ST |
1444 | memset(&link_conf->p2p_noa_attr, 0, |
1445 | sizeof(link_conf->p2p_noa_attr)); | |
1446 | link_conf->p2p_noa_attr.oppps_ctwindow = | |
67baf663 JD |
1447 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
1448 | if (params->p2p_opp_ps) | |
d9f83f22 | 1449 | link_conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 | 1450 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
339afbf4 | 1451 | |
08fad438 JM |
1452 | sdata->beacon_rate_set = false; |
1453 | if (wiphy_ext_feature_isset(local->hw.wiphy, | |
1454 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { | |
1455 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
1456 | sdata->beacon_rateidx_mask[i] = | |
1457 | params->beacon_rate.control[i].legacy; | |
1458 | if (sdata->beacon_rateidx_mask[i]) | |
1459 | sdata->beacon_rate_set = true; | |
1460 | } | |
1461 | } | |
1462 | ||
ba6ff70a | 1463 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) |
d9f83f22 | 1464 | link_conf->beacon_tx_rate = params->beacon_rate; |
ba6ff70a | 1465 | |
15ddba5f A |
1466 | err = ieee80211_assign_beacon(sdata, link, ¶ms->beacon, NULL, NULL, |
1467 | &changed); | |
295b02c4 AD |
1468 | if (err < 0) |
1469 | goto error; | |
8860020e | 1470 | |
3b1c256e | 1471 | err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery, |
392d3dfd | 1472 | link, link_conf, &changed); |
3b1c256e AD |
1473 | if (err < 0) |
1474 | goto error; | |
295b02c4 | 1475 | |
3b1c256e AD |
1476 | err = ieee80211_set_unsol_bcast_probe_resp(sdata, |
1477 | ¶ms->unsol_bcast_probe_resp, | |
178e9d6a | 1478 | link, link_conf, &changed); |
3b1c256e AD |
1479 | if (err < 0) |
1480 | goto error; | |
632189a0 | 1481 | |
b327c84c | 1482 | err = drv_start_ap(sdata->local, sdata, link_conf); |
1041638f | 1483 | if (err) { |
d9f83f22 | 1484 | old = sdata_dereference(link->u.ap.beacon, sdata); |
7ca133bc | 1485 | |
1041638f JB |
1486 | if (old) |
1487 | kfree_rcu(old, rcu_head); | |
d9f83f22 | 1488 | RCU_INIT_POINTER(link->u.ap.beacon, NULL); |
6d4ed5b3 AKS |
1489 | |
1490 | if (ieee80211_num_beaconing_links(sdata) == 0) | |
1491 | sdata->u.ap.active = false; | |
1492 | ||
295b02c4 | 1493 | goto error; |
1041638f JB |
1494 | } |
1495 | ||
057d5f4b | 1496 | ieee80211_recalc_dtim(local, sdata); |
d9f83f22 | 1497 | ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_SSID); |
d8675a63 | 1498 | ieee80211_link_info_change_notify(sdata, link, changed); |
8860020e | 1499 | |
5fcc7c51 AKS |
1500 | if (ieee80211_num_beaconing_links(sdata) <= 1) |
1501 | netif_carrier_on(dev); | |
1502 | ||
3edaf3e6 JB |
1503 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
1504 | netif_carrier_on(vlan->dev); | |
1505 | ||
665c93a9 | 1506 | return 0; |
295b02c4 AD |
1507 | |
1508 | error: | |
d9f83f22 | 1509 | ieee80211_link_release_channel(link); |
87a27062 | 1510 | |
295b02c4 | 1511 | return err; |
5dfdaf58 JB |
1512 | } |
1513 | ||
8860020e | 1514 | static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, |
bb55441c | 1515 | struct cfg80211_ap_update *params) |
66f85d57 | 1516 | |
5dfdaf58 | 1517 | { |
d9f83f22 | 1518 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
d8675a63 | 1519 | struct ieee80211_link_data *link; |
66f85d57 | 1520 | struct cfg80211_beacon_data *beacon = ¶ms->beacon; |
5dfdaf58 | 1521 | struct beacon_data *old; |
8860020e | 1522 | int err; |
d8675a63 | 1523 | struct ieee80211_bss_conf *link_conf; |
15ddba5f | 1524 | u64 changed = 0; |
5dfdaf58 | 1525 | |
076fc877 | 1526 | lockdep_assert_wiphy(wiphy); |
14db74bc | 1527 | |
66f85d57 | 1528 | link = sdata_dereference(sdata->link[beacon->link_id], sdata); |
d8675a63 JB |
1529 | if (!link) |
1530 | return -ENOLINK; | |
1531 | ||
1532 | link_conf = link->conf; | |
1533 | ||
5f9404ab | 1534 | /* don't allow changing the beacon while a countdown is in place - offset |
73da7d5b SW |
1535 | * of channel switch counter may change |
1536 | */ | |
d9f83f22 | 1537 | if (link_conf->csa_active || link_conf->color_change_active) |
73da7d5b SW |
1538 | return -EBUSY; |
1539 | ||
d8675a63 | 1540 | old = sdata_dereference(link->u.ap.beacon, sdata); |
5dfdaf58 JB |
1541 | if (!old) |
1542 | return -ENOENT; | |
1543 | ||
66f85d57 | 1544 | err = ieee80211_assign_beacon(sdata, link, beacon, NULL, NULL, |
15ddba5f | 1545 | &changed); |
8860020e JB |
1546 | if (err < 0) |
1547 | return err; | |
195b9a0f | 1548 | |
6bc5ddb2 | 1549 | err = ieee80211_set_fils_discovery(sdata, ¶ms->fils_discovery, |
392d3dfd | 1550 | link, link_conf, &changed); |
6bc5ddb2 AD |
1551 | if (err < 0) |
1552 | return err; | |
6bc5ddb2 AD |
1553 | |
1554 | err = ieee80211_set_unsol_bcast_probe_resp(sdata, | |
1555 | ¶ms->unsol_bcast_probe_resp, | |
178e9d6a | 1556 | link, link_conf, &changed); |
6bc5ddb2 AD |
1557 | if (err < 0) |
1558 | return err; | |
6bc5ddb2 | 1559 | |
66f85d57 AD |
1560 | if (beacon->he_bss_color_valid && |
1561 | beacon->he_bss_color.enabled != link_conf->he_bss_color.enabled) { | |
1562 | link_conf->he_bss_color.enabled = beacon->he_bss_color.enabled; | |
15ddba5f | 1563 | changed |= BSS_CHANGED_HE_BSS_COLOR; |
195b9a0f LS |
1564 | } |
1565 | ||
15ddba5f | 1566 | ieee80211_link_info_change_notify(sdata, link, changed); |
8860020e | 1567 | return 0; |
5dfdaf58 JB |
1568 | } |
1569 | ||
d9f83f22 | 1570 | static void ieee80211_free_next_beacon(struct ieee80211_link_data *link) |
0baef284 | 1571 | { |
d9f83f22 | 1572 | if (!link->u.ap.next_beacon) |
0baef284 JB |
1573 | return; |
1574 | ||
d9f83f22 | 1575 | kfree(link->u.ap.next_beacon->mbssid_ies); |
68b9bea2 | 1576 | kfree(link->u.ap.next_beacon->rnr_ies); |
d9f83f22 ST |
1577 | kfree(link->u.ap.next_beacon); |
1578 | link->u.ap.next_beacon = NULL; | |
0baef284 JB |
1579 | } |
1580 | ||
7b0a0e3c JB |
1581 | static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev, |
1582 | unsigned int link_id) | |
5dfdaf58 | 1583 | { |
7b20b8e8 JB |
1584 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1585 | struct ieee80211_sub_if_data *vlan; | |
1586 | struct ieee80211_local *local = sdata->local; | |
1587 | struct beacon_data *old_beacon; | |
1588 | struct probe_resp *old_probe_resp; | |
295b02c4 | 1589 | struct fils_discovery_data *old_fils_discovery; |
632189a0 | 1590 | struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp; |
d2859df5 | 1591 | struct cfg80211_chan_def chandef; |
d8675a63 JB |
1592 | struct ieee80211_link_data *link = |
1593 | sdata_dereference(sdata->link[link_id], sdata); | |
1594 | struct ieee80211_bss_conf *link_conf = link->conf; | |
1c0d21c4 | 1595 | LIST_HEAD(keys); |
14db74bc | 1596 | |
0cd8080e | 1597 | lockdep_assert_wiphy(local->hw.wiphy); |
dbd72850 | 1598 | |
d9f83f22 | 1599 | old_beacon = sdata_dereference(link->u.ap.beacon, sdata); |
7b20b8e8 | 1600 | if (!old_beacon) |
5dfdaf58 | 1601 | return -ENOENT; |
d9f83f22 | 1602 | old_probe_resp = sdata_dereference(link->u.ap.probe_resp, |
bfd8403a | 1603 | sdata); |
d9f83f22 | 1604 | old_fils_discovery = sdata_dereference(link->u.ap.fils_discovery, |
295b02c4 | 1605 | sdata); |
632189a0 | 1606 | old_unsol_bcast_probe_resp = |
d9f83f22 | 1607 | sdata_dereference(link->u.ap.unsol_bcast_probe_resp, |
632189a0 | 1608 | sdata); |
5dfdaf58 | 1609 | |
a23d7f5b | 1610 | /* abort any running channel switch or color change */ |
d9f83f22 | 1611 | link_conf->csa_active = false; |
a23d7f5b | 1612 | link_conf->color_change_active = false; |
570944a0 | 1613 | if (sdata->csa_blocked_queues) { |
a46992b4 LC |
1614 | ieee80211_wake_vif_queues(local, sdata, |
1615 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
570944a0 | 1616 | sdata->csa_blocked_queues = false; |
a46992b4 LC |
1617 | } |
1618 | ||
d9f83f22 | 1619 | ieee80211_free_next_beacon(link); |
1f3b8a2b | 1620 | |
7b20b8e8 | 1621 | /* turn off carrier for this interface and dependent VLANs */ |
3edaf3e6 JB |
1622 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
1623 | netif_carrier_off(vlan->dev); | |
5fcc7c51 | 1624 | |
6d4ed5b3 | 1625 | if (ieee80211_num_beaconing_links(sdata) <= 1) { |
5fcc7c51 | 1626 | netif_carrier_off(dev); |
6d4ed5b3 AKS |
1627 | sdata->u.ap.active = false; |
1628 | } | |
3edaf3e6 | 1629 | |
7b20b8e8 | 1630 | /* remove beacon and probe response */ |
d9f83f22 ST |
1631 | RCU_INIT_POINTER(link->u.ap.beacon, NULL); |
1632 | RCU_INIT_POINTER(link->u.ap.probe_resp, NULL); | |
1633 | RCU_INIT_POINTER(link->u.ap.fils_discovery, NULL); | |
1634 | RCU_INIT_POINTER(link->u.ap.unsol_bcast_probe_resp, NULL); | |
7b20b8e8 JB |
1635 | kfree_rcu(old_beacon, rcu_head); |
1636 | if (old_probe_resp) | |
1637 | kfree_rcu(old_probe_resp, rcu_head); | |
295b02c4 AD |
1638 | if (old_fils_discovery) |
1639 | kfree_rcu(old_fils_discovery, rcu_head); | |
632189a0 AD |
1640 | if (old_unsol_bcast_probe_resp) |
1641 | kfree_rcu(old_unsol_bcast_probe_resp, rcu_head); | |
8860020e | 1642 | |
d9f83f22 ST |
1643 | kfree(link_conf->ftmr_params); |
1644 | link_conf->ftmr_params = NULL; | |
bc847970 | 1645 | |
0eb38842 AD |
1646 | sdata->vif.mbssid_tx_vif = NULL; |
1647 | link_conf->bssid_index = 0; | |
1648 | link_conf->nontransmitted = false; | |
1649 | link_conf->ema_ap = false; | |
1650 | link_conf->bssid_indicator = 0; | |
1651 | ||
16405bd7 | 1652 | __sta_info_flush(sdata, true, link_id); |
1c0d21c4 RS |
1653 | |
1654 | ieee80211_remove_link_keys(link, &keys); | |
1655 | if (!list_empty(&keys)) { | |
1656 | synchronize_net(); | |
1657 | ieee80211_free_key_list(local, &keys); | |
1658 | } | |
75de9113 | 1659 | |
d9f83f22 | 1660 | link_conf->enable_beacon = false; |
08fad438 | 1661 | sdata->beacon_rate_set = false; |
f276e20b | 1662 | sdata->vif.cfg.ssid_len = 0; |
d6a83228 | 1663 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
d8675a63 | 1664 | ieee80211_link_info_change_notify(sdata, link, |
7fc83a2b | 1665 | BSS_CHANGED_BEACON_ENABLED); |
8860020e | 1666 | |
a6b368f6 | 1667 | if (sdata->wdev.cac_started) { |
6092077a | 1668 | chandef = link_conf->chanreq.oper; |
766d2601 | 1669 | wiphy_delayed_work_cancel(wiphy, &link->dfs_cac_timer_work); |
d2859df5 JD |
1670 | cfg80211_cac_event(sdata->dev, &chandef, |
1671 | NL80211_RADAR_CAC_ABORTED, | |
a6b368f6 SW |
1672 | GFP_KERNEL); |
1673 | } | |
1674 | ||
b327c84c | 1675 | drv_stop_ap(sdata->local, sdata, link_conf); |
1041638f | 1676 | |
7b20b8e8 JB |
1677 | /* free all potentially still buffered bcast frames */ |
1678 | local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); | |
6b07d9ca | 1679 | ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf); |
7b20b8e8 | 1680 | |
d9f83f22 ST |
1681 | ieee80211_link_copy_chanctx_to_vlans(link, true); |
1682 | ieee80211_link_release_channel(link); | |
55de908a | 1683 | |
2d0ddec5 | 1684 | return 0; |
5dfdaf58 JB |
1685 | } |
1686 | ||
d582cffb JB |
1687 | static int sta_apply_auth_flags(struct ieee80211_local *local, |
1688 | struct sta_info *sta, | |
1689 | u32 mask, u32 set) | |
1690 | { | |
1691 | int ret; | |
1692 | ||
1693 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1694 | set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1695 | !test_sta_flag(sta, WLAN_STA_AUTH)) { | |
1696 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); | |
1697 | if (ret) | |
1698 | return ret; | |
1699 | } | |
1700 | ||
1701 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1702 | set & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1703 | !test_sta_flag(sta, WLAN_STA_ASSOC)) { | |
c23e31cf MP |
1704 | /* |
1705 | * When peer becomes associated, init rate control as | |
1706 | * well. Some drivers require rate control initialized | |
1707 | * before drv_sta_state() is called. | |
1708 | */ | |
44674d9c | 1709 | if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) |
c23e31cf MP |
1710 | rate_control_rate_init(sta); |
1711 | ||
d582cffb JB |
1712 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
1713 | if (ret) | |
1714 | return ret; | |
1715 | } | |
1716 | ||
1717 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
1718 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
1719 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); | |
1720 | else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
1721 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); | |
1722 | else | |
1723 | ret = 0; | |
1724 | if (ret) | |
1725 | return ret; | |
1726 | } | |
1727 | ||
1728 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && | |
1729 | !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) && | |
1730 | test_sta_flag(sta, WLAN_STA_ASSOC)) { | |
1731 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); | |
1732 | if (ret) | |
1733 | return ret; | |
1734 | } | |
1735 | ||
1736 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && | |
1737 | !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) && | |
1738 | test_sta_flag(sta, WLAN_STA_AUTH)) { | |
1739 | ret = sta_info_move_state(sta, IEEE80211_STA_NONE); | |
1740 | if (ret) | |
1741 | return ret; | |
1742 | } | |
1743 | ||
1744 | return 0; | |
1745 | } | |
1746 | ||
13657702 JB |
1747 | static void sta_apply_mesh_params(struct ieee80211_local *local, |
1748 | struct sta_info *sta, | |
1749 | struct station_parameters *params) | |
1750 | { | |
1751 | #ifdef CONFIG_MAC80211_MESH | |
1752 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
15ddba5f | 1753 | u64 changed = 0; |
13657702 JB |
1754 | |
1755 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) { | |
1756 | switch (params->plink_state) { | |
1757 | case NL80211_PLINK_ESTAB: | |
1758 | if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) | |
1759 | changed = mesh_plink_inc_estab_count(sdata); | |
1760 | sta->mesh->plink_state = params->plink_state; | |
7d27a0ba | 1761 | sta->mesh->aid = params->peer_aid; |
13657702 JB |
1762 | |
1763 | ieee80211_mps_sta_status_update(sta); | |
1764 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1765 | sdata->u.mesh.mshcfg.power_mode); | |
67fc0554 JH |
1766 | |
1767 | ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg); | |
1768 | /* init at low value */ | |
1769 | ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10); | |
1770 | ||
13657702 JB |
1771 | break; |
1772 | case NL80211_PLINK_LISTEN: | |
1773 | case NL80211_PLINK_BLOCKED: | |
1774 | case NL80211_PLINK_OPN_SNT: | |
1775 | case NL80211_PLINK_OPN_RCVD: | |
1776 | case NL80211_PLINK_CNF_RCVD: | |
1777 | case NL80211_PLINK_HOLDING: | |
1778 | if (sta->mesh->plink_state == NL80211_PLINK_ESTAB) | |
1779 | changed = mesh_plink_dec_estab_count(sdata); | |
1780 | sta->mesh->plink_state = params->plink_state; | |
1781 | ||
1782 | ieee80211_mps_sta_status_update(sta); | |
1783 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1784 | NL80211_MESH_POWER_UNKNOWN); | |
1785 | break; | |
1786 | default: | |
1787 | /* nothing */ | |
1788 | break; | |
1789 | } | |
1790 | } | |
1791 | ||
1792 | switch (params->plink_action) { | |
1793 | case NL80211_PLINK_ACTION_NO_ACTION: | |
1794 | /* nothing */ | |
1795 | break; | |
1796 | case NL80211_PLINK_ACTION_OPEN: | |
1797 | changed |= mesh_plink_open(sta); | |
1798 | break; | |
1799 | case NL80211_PLINK_ACTION_BLOCK: | |
1800 | changed |= mesh_plink_block(sta); | |
1801 | break; | |
1802 | } | |
1803 | ||
1804 | if (params->local_pm) | |
1805 | changed |= ieee80211_mps_set_sta_local_pm(sta, | |
1806 | params->local_pm); | |
1807 | ||
1808 | ieee80211_mbss_info_change_notify(sdata, changed); | |
1809 | #endif | |
1810 | } | |
1811 | ||
b95eb7f0 | 1812 | static int sta_link_apply_parameters(struct ieee80211_local *local, |
9aebce6c | 1813 | struct sta_info *sta, bool new_link, |
b95eb7f0 ST |
1814 | struct link_station_parameters *params) |
1815 | { | |
1816 | int ret = 0; | |
1817 | struct ieee80211_supported_band *sband; | |
1818 | struct ieee80211_sub_if_data *sdata = sta->sdata; | |
1819 | u32 link_id = params->link_id < 0 ? 0 : params->link_id; | |
d8675a63 JB |
1820 | struct ieee80211_link_data *link = |
1821 | sdata_dereference(sdata->link[link_id], sdata); | |
b95eb7f0 ST |
1822 | struct link_sta_info *link_sta = |
1823 | rcu_dereference_protected(sta->link[link_id], | |
4d3acf43 | 1824 | lockdep_is_held(&local->hw.wiphy->mtx)); |
b95eb7f0 | 1825 | |
b303835d | 1826 | /* |
c1393c13 | 1827 | * If there are no changes, then accept a link that exist, |
b303835d JB |
1828 | * unless it's a new link. |
1829 | */ | |
c1393c13 | 1830 | if (params->link_id >= 0 && !new_link && |
b303835d JB |
1831 | !params->link_mac && !params->txpwr_set && |
1832 | !params->supported_rates_len && | |
1833 | !params->ht_capa && !params->vht_capa && | |
1834 | !params->he_capa && !params->eht_capa && | |
1835 | !params->opmode_notif_used) | |
1836 | return 0; | |
1837 | ||
d8675a63 | 1838 | if (!link || !link_sta) |
b95eb7f0 ST |
1839 | return -EINVAL; |
1840 | ||
d8675a63 | 1841 | sband = ieee80211_get_link_sband(link); |
b95eb7f0 ST |
1842 | if (!sband) |
1843 | return -EINVAL; | |
1844 | ||
1845 | if (params->link_mac) { | |
9aebce6c JB |
1846 | if (new_link) { |
1847 | memcpy(link_sta->addr, params->link_mac, ETH_ALEN); | |
1848 | memcpy(link_sta->pub->addr, params->link_mac, ETH_ALEN); | |
1849 | } else if (!ether_addr_equal(link_sta->addr, | |
1850 | params->link_mac)) { | |
1851 | return -EINVAL; | |
1852 | } | |
b303835d JB |
1853 | } else if (new_link) { |
1854 | return -EINVAL; | |
b95eb7f0 ST |
1855 | } |
1856 | ||
1857 | if (params->txpwr_set) { | |
1858 | link_sta->pub->txpwr.type = params->txpwr.type; | |
1859 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) | |
1860 | link_sta->pub->txpwr.power = params->txpwr.power; | |
1861 | ret = drv_sta_set_txpwr(local, sdata, sta); | |
1862 | if (ret) | |
1863 | return ret; | |
1864 | } | |
1865 | ||
1866 | if (params->supported_rates && | |
1867 | params->supported_rates_len) { | |
6092077a | 1868 | ieee80211_parse_bitrates(link->conf->chanreq.oper.width, |
b95eb7f0 ST |
1869 | sband, params->supported_rates, |
1870 | params->supported_rates_len, | |
1871 | &link_sta->pub->supp_rates[sband->band]); | |
1872 | } | |
1873 | ||
1874 | if (params->ht_capa) | |
1875 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, | |
1876 | params->ht_capa, link_sta); | |
1877 | ||
1878 | /* VHT can override some HT caps such as the A-MSDU max length */ | |
1879 | if (params->vht_capa) | |
1880 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, | |
084cf2ae JB |
1881 | params->vht_capa, NULL, |
1882 | link_sta); | |
b95eb7f0 ST |
1883 | |
1884 | if (params->he_capa) | |
1885 | ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband, | |
1886 | (void *)params->he_capa, | |
1887 | params->he_capa_len, | |
1888 | (void *)params->he_6ghz_capa, | |
1889 | link_sta); | |
1890 | ||
e8edb346 | 1891 | if (params->he_capa && params->eht_capa) |
b95eb7f0 ST |
1892 | ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband, |
1893 | (u8 *)params->he_capa, | |
1894 | params->he_capa_len, | |
1895 | params->eht_capa, | |
1896 | params->eht_capa_len, | |
1897 | link_sta); | |
1898 | ||
1899 | if (params->opmode_notif_used) { | |
1900 | /* returned value is only needed for rc update, but the | |
1901 | * rc isn't initialized here yet, so ignore it | |
1902 | */ | |
1903 | __ieee80211_vht_handle_opmode(sdata, link_sta, | |
1904 | params->opmode_notif, | |
1905 | sband->band); | |
1906 | } | |
1907 | ||
a8bca3e9 | 1908 | ieee80211_sta_init_nss(link_sta); |
dd6c064c | 1909 | |
b95eb7f0 ST |
1910 | return ret; |
1911 | } | |
1912 | ||
d9a7ddb0 JB |
1913 | static int sta_apply_parameters(struct ieee80211_local *local, |
1914 | struct sta_info *sta, | |
1915 | struct station_parameters *params) | |
4fd6931e | 1916 | { |
d0709a65 | 1917 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
eccb8e8f | 1918 | u32 mask, set; |
45b12570 | 1919 | int ret = 0; |
ae5eb026 | 1920 | |
eccb8e8f JB |
1921 | mask = params->sta_flags_mask; |
1922 | set = params->sta_flags_set; | |
73651ee6 | 1923 | |
d582cffb JB |
1924 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
1925 | /* | |
1926 | * In mesh mode, ASSOCIATED isn't part of the nl80211 | |
1927 | * API but must follow AUTHENTICATED for driver state. | |
1928 | */ | |
1929 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
1930 | mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1931 | if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
1932 | set |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
77ee7c89 JB |
1933 | } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
1934 | /* | |
1935 | * TDLS -- everything follows authorized, but | |
1936 | * only becoming authorized is possible, not | |
1937 | * going back | |
1938 | */ | |
1939 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
1940 | set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
1941 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1942 | mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
1943 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
1944 | } | |
eccb8e8f | 1945 | } |
4fd6931e | 1946 | |
2c44be81 JB |
1947 | if (mask & BIT(NL80211_STA_FLAG_WME) && |
1948 | local->hw.queues >= IEEE80211_NUM_ACS) | |
1949 | sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME); | |
1950 | ||
44674d9c | 1951 | /* auth flags will be set later for TDLS, |
b18dacab | 1952 | * and for unassociated stations that move to associated */ |
44674d9c AB |
1953 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
1954 | !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) && | |
1955 | (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) { | |
68885a54 AN |
1956 | ret = sta_apply_auth_flags(local, sta, mask, set); |
1957 | if (ret) | |
1958 | return ret; | |
1959 | } | |
d9a7ddb0 | 1960 | |
eccb8e8f | 1961 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
eccb8e8f | 1962 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
c2c98fde JB |
1963 | set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
1964 | else | |
1965 | clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); | |
eccb8e8f | 1966 | } |
4fd6931e | 1967 | |
eccb8e8f | 1968 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
93f0490e | 1969 | sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP)); |
eccb8e8f | 1970 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
c2c98fde JB |
1971 | set_sta_flag(sta, WLAN_STA_MFP); |
1972 | else | |
1973 | clear_sta_flag(sta, WLAN_STA_MFP); | |
4fd6931e | 1974 | } |
b39c48fa | 1975 | |
07ba55d7 | 1976 | if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { |
07ba55d7 | 1977 | if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
c2c98fde JB |
1978 | set_sta_flag(sta, WLAN_STA_TDLS_PEER); |
1979 | else | |
1980 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER); | |
07ba55d7 | 1981 | } |
4fd6931e | 1982 | |
3b220ed8 JB |
1983 | if (mask & BIT(NL80211_STA_FLAG_SPP_AMSDU)) |
1984 | sta->sta.spp_amsdu = set & BIT(NL80211_STA_FLAG_SPP_AMSDU); | |
1985 | ||
9041c1fa AN |
1986 | /* mark TDLS channel switch support, if the AP allows it */ |
1987 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && | |
ab3a830d | 1988 | !sdata->deflink.u.mgd.tdls_chan_switch_prohibited && |
9041c1fa AN |
1989 | params->ext_capab_len >= 4 && |
1990 | params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) | |
1991 | set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH); | |
1992 | ||
b98fb44f | 1993 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
82c0cc90 | 1994 | !sdata->u.mgd.tdls_wider_bw_prohibited && |
b98fb44f AN |
1995 | ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && |
1996 | params->ext_capab_len >= 8 && | |
1997 | params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) | |
1998 | set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW); | |
1999 | ||
3b9ce80c JB |
2000 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { |
2001 | sta->sta.uapsd_queues = params->uapsd_queues; | |
2002 | sta->sta.max_sp = params->max_sp; | |
2003 | } | |
9533b4ac | 2004 | |
175ad2ec JB |
2005 | ieee80211_sta_set_max_amsdu_subframes(sta, params->ext_capab, |
2006 | params->ext_capab_len); | |
506bcfa8 | 2007 | |
51b50fbe JB |
2008 | /* |
2009 | * cfg80211 validates this (1-2007) and allows setting the AID | |
2010 | * only when creating a new station entry | |
2011 | */ | |
2012 | if (params->aid) | |
2013 | sta->sta.aid = params->aid; | |
2014 | ||
73651ee6 | 2015 | /* |
ba23d206 JB |
2016 | * Some of the following updates would be racy if called on an |
2017 | * existing station, via ieee80211_change_station(). However, | |
2018 | * all such changes are rejected by cfg80211 except for updates | |
2019 | * changing the supported rates on an existing but not yet used | |
2020 | * TDLS peer. | |
73651ee6 JB |
2021 | */ |
2022 | ||
4fd6931e JB |
2023 | if (params->listen_interval >= 0) |
2024 | sta->listen_interval = params->listen_interval; | |
2025 | ||
9aebce6c JB |
2026 | ret = sta_link_apply_parameters(local, sta, false, |
2027 | ¶ms->link_sta_params); | |
b95eb7f0 ST |
2028 | if (ret) |
2029 | return ret; | |
b1bce14a | 2030 | |
52cfa1d6 AB |
2031 | if (params->support_p2p_ps >= 0) |
2032 | sta->sta.support_p2p_ps = params->support_p2p_ps; | |
2033 | ||
13657702 JB |
2034 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
2035 | sta_apply_mesh_params(local, sta, params); | |
d9a7ddb0 | 2036 | |
b4809e94 | 2037 | if (params->airtime_weight) |
942741da | 2038 | sta->airtime_weight = params->airtime_weight; |
b4809e94 | 2039 | |
68885a54 | 2040 | /* set the STA state after all sta info from usermode has been set */ |
44674d9c AB |
2041 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || |
2042 | set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { | |
68885a54 AN |
2043 | ret = sta_apply_auth_flags(local, sta, mask, set); |
2044 | if (ret) | |
2045 | return ret; | |
2046 | } | |
2047 | ||
3e0278b7 AO |
2048 | /* Mark the STA as MLO if MLD MAC address is available */ |
2049 | if (params->link_sta_params.mld_mac) | |
2050 | sta->sta.mlo = true; | |
2051 | ||
d9a7ddb0 | 2052 | return 0; |
4fd6931e JB |
2053 | } |
2054 | ||
2055 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 JB |
2056 | const u8 *mac, |
2057 | struct station_parameters *params) | |
4fd6931e | 2058 | { |
14db74bc | 2059 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
2060 | struct sta_info *sta; |
2061 | struct ieee80211_sub_if_data *sdata; | |
73651ee6 | 2062 | int err; |
4fd6931e | 2063 | |
4d3acf43 JB |
2064 | lockdep_assert_wiphy(local->hw.wiphy); |
2065 | ||
4fd6931e JB |
2066 | if (params->vlan) { |
2067 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); | |
2068 | ||
05c914fe JB |
2069 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
2070 | sdata->vif.type != NL80211_IFTYPE_AP) | |
4fd6931e JB |
2071 | return -EINVAL; |
2072 | } else | |
2073 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2074 | ||
b203ca39 | 2075 | if (ether_addr_equal(mac, sdata->vif.addr)) |
03e4497e JB |
2076 | return -EINVAL; |
2077 | ||
52dba8d7 | 2078 | if (!is_valid_ether_addr(mac)) |
03e4497e JB |
2079 | return -EINVAL; |
2080 | ||
5fd2f91a JB |
2081 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) && |
2082 | sdata->vif.type == NL80211_IFTYPE_STATION && | |
2083 | !sdata->u.mgd.associated) | |
2084 | return -EINVAL; | |
2085 | ||
206c8c06 JB |
2086 | /* |
2087 | * If we have a link ID, it can be a non-MLO station on an AP MLD, | |
2088 | * but we need to have a link_mac in that case as well, so use the | |
2089 | * STA's MAC address in that case. | |
2090 | */ | |
f36fe0a2 JB |
2091 | if (params->link_sta_params.link_id >= 0) |
2092 | sta = sta_info_alloc_with_link(sdata, mac, | |
2093 | params->link_sta_params.link_id, | |
206c8c06 | 2094 | params->link_sta_params.link_mac ?: mac, |
f36fe0a2 JB |
2095 | GFP_KERNEL); |
2096 | else | |
2097 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); | |
2098 | ||
73651ee6 JB |
2099 | if (!sta) |
2100 | return -ENOMEM; | |
4fd6931e | 2101 | |
44674d9c AB |
2102 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
2103 | sta->sta.tdls = true; | |
4fd6931e | 2104 | |
b95eb7f0 ST |
2105 | /* Though the mutex is not needed here (since the station is not |
2106 | * visible yet), sta_apply_parameters (and inner functions) require | |
2107 | * the mutex due to other paths. | |
2108 | */ | |
d9a7ddb0 JB |
2109 | err = sta_apply_parameters(local, sta, params); |
2110 | if (err) { | |
2111 | sta_info_free(local, sta); | |
2112 | return err; | |
2113 | } | |
4fd6931e | 2114 | |
d64cf63e | 2115 | /* |
44674d9c AB |
2116 | * for TDLS and for unassociated station, rate control should be |
2117 | * initialized only when rates are known and station is marked | |
2118 | * authorized/associated | |
d64cf63e | 2119 | */ |
44674d9c AB |
2120 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
2121 | test_sta_flag(sta, WLAN_STA_ASSOC)) | |
d64cf63e | 2122 | rate_control_rate_init(sta); |
4fd6931e | 2123 | |
4ebdce1d | 2124 | return sta_info_insert(sta); |
4fd6931e JB |
2125 | } |
2126 | ||
2127 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, | |
89c771e5 | 2128 | struct station_del_parameters *params) |
4fd6931e | 2129 | { |
14db74bc | 2130 | struct ieee80211_sub_if_data *sdata; |
4fd6931e | 2131 | |
14db74bc JB |
2132 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2133 | ||
89c771e5 JM |
2134 | if (params->mac) |
2135 | return sta_info_destroy_addr_bss(sdata, params->mac); | |
4fd6931e | 2136 | |
ec67d6e0 | 2137 | sta_info_flush(sdata, params->link_id); |
4fd6931e JB |
2138 | return 0; |
2139 | } | |
2140 | ||
2141 | static int ieee80211_change_station(struct wiphy *wiphy, | |
3b3a0162 | 2142 | struct net_device *dev, const u8 *mac, |
4fd6931e JB |
2143 | struct station_parameters *params) |
2144 | { | |
abe60632 | 2145 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
14db74bc | 2146 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
2147 | struct sta_info *sta; |
2148 | struct ieee80211_sub_if_data *vlansdata; | |
77ee7c89 | 2149 | enum cfg80211_station_type statype; |
35b88623 | 2150 | int err; |
4fd6931e | 2151 | |
4d3acf43 | 2152 | lockdep_assert_wiphy(local->hw.wiphy); |
98dd6a57 | 2153 | |
0e5ded5a | 2154 | sta = sta_info_get_bss(sdata, mac); |
4d3acf43 JB |
2155 | if (!sta) |
2156 | return -ENOENT; | |
4fd6931e | 2157 | |
77ee7c89 JB |
2158 | switch (sdata->vif.type) { |
2159 | case NL80211_IFTYPE_MESH_POINT: | |
a6dad6a2 | 2160 | if (sdata->u.mesh.user_mpm) |
eef941e6 | 2161 | statype = CFG80211_STA_MESH_PEER_USER; |
77ee7c89 | 2162 | else |
eef941e6 | 2163 | statype = CFG80211_STA_MESH_PEER_KERNEL; |
77ee7c89 JB |
2164 | break; |
2165 | case NL80211_IFTYPE_ADHOC: | |
2166 | statype = CFG80211_STA_IBSS; | |
2167 | break; | |
2168 | case NL80211_IFTYPE_STATION: | |
2169 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { | |
2170 | statype = CFG80211_STA_AP_STA; | |
2171 | break; | |
2172 | } | |
2173 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
2174 | statype = CFG80211_STA_TDLS_PEER_ACTIVE; | |
2175 | else | |
2176 | statype = CFG80211_STA_TDLS_PEER_SETUP; | |
2177 | break; | |
2178 | case NL80211_IFTYPE_AP: | |
2179 | case NL80211_IFTYPE_AP_VLAN: | |
44674d9c AB |
2180 | if (test_sta_flag(sta, WLAN_STA_ASSOC)) |
2181 | statype = CFG80211_STA_AP_CLIENT; | |
2182 | else | |
2183 | statype = CFG80211_STA_AP_CLIENT_UNASSOC; | |
77ee7c89 JB |
2184 | break; |
2185 | default: | |
4d3acf43 | 2186 | return -EOPNOTSUPP; |
bdd90d5e JB |
2187 | } |
2188 | ||
77ee7c89 JB |
2189 | err = cfg80211_check_station_change(wiphy, params, statype); |
2190 | if (err) | |
4d3acf43 | 2191 | return err; |
77ee7c89 | 2192 | |
d0709a65 | 2193 | if (params->vlan && params->vlan != sta->sdata->dev) { |
4fd6931e JB |
2194 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
2195 | ||
9bc383de | 2196 | if (params->vlan->ieee80211_ptr->use_4addr) { |
4d3acf43 JB |
2197 | if (vlansdata->u.vlan.sta) |
2198 | return -EBUSY; | |
f14543ee | 2199 | |
cf778b00 | 2200 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); |
49ddf8e6 | 2201 | __ieee80211_check_fast_rx_iface(vlansdata); |
1ff4e8f2 | 2202 | drv_sta_set_4addr(local, sta->sdata, &sta->sta, true); |
7e3ed02c FF |
2203 | } |
2204 | ||
2205 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && | |
4f2bdb3c | 2206 | sta->sdata->u.vlan.sta) |
0c2bef46 | 2207 | RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); |
72f15d53 MB |
2208 | |
2209 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
2210 | ieee80211_vif_dec_num_mcast(sta->sdata); | |
f14543ee | 2211 | |
14db74bc | 2212 | sta->sdata = vlansdata; |
4f2bdb3c | 2213 | ieee80211_check_fast_rx(sta); |
464daaf0 | 2214 | ieee80211_check_fast_xmit(sta); |
7e3ed02c | 2215 | |
3e493173 | 2216 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) { |
72f15d53 | 2217 | ieee80211_vif_inc_num_mcast(sta->sdata); |
3e493173 JM |
2218 | cfg80211_send_layer2_update(sta->sdata->dev, |
2219 | sta->sta.addr); | |
2220 | } | |
4fd6931e JB |
2221 | } |
2222 | ||
076fc877 | 2223 | err = sta_apply_parameters(local, sta, params); |
77ee7c89 | 2224 | if (err) |
4d3acf43 | 2225 | return err; |
98dd6a57 | 2226 | |
808118cb | 2227 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
ab095877 | 2228 | params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
4a733ef1 | 2229 | ieee80211_recalc_ps(local); |
ab095877 EP |
2230 | ieee80211_recalc_ps_vif(sdata); |
2231 | } | |
77ee7c89 | 2232 | |
4fd6931e JB |
2233 | return 0; |
2234 | } | |
2235 | ||
c5dd9c2b LCC |
2236 | #ifdef CONFIG_MAC80211_MESH |
2237 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 | 2238 | const u8 *dst, const u8 *next_hop) |
c5dd9c2b | 2239 | { |
14db74bc | 2240 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2241 | struct mesh_path *mpath; |
2242 | struct sta_info *sta; | |
c5dd9c2b | 2243 | |
14db74bc JB |
2244 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2245 | ||
d0709a65 | 2246 | rcu_read_lock(); |
abe60632 | 2247 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
2248 | if (!sta) { |
2249 | rcu_read_unlock(); | |
c5dd9c2b | 2250 | return -ENOENT; |
d0709a65 | 2251 | } |
c5dd9c2b | 2252 | |
ae76eef0 BC |
2253 | mpath = mesh_path_add(sdata, dst); |
2254 | if (IS_ERR(mpath)) { | |
d0709a65 | 2255 | rcu_read_unlock(); |
ae76eef0 | 2256 | return PTR_ERR(mpath); |
d0709a65 | 2257 | } |
c5dd9c2b | 2258 | |
c5dd9c2b | 2259 | mesh_path_fix_nexthop(mpath, sta); |
d0709a65 | 2260 | |
c5dd9c2b LCC |
2261 | rcu_read_unlock(); |
2262 | return 0; | |
2263 | } | |
2264 | ||
2265 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 | 2266 | const u8 *dst) |
c5dd9c2b | 2267 | { |
f698d856 JBG |
2268 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2269 | ||
c5dd9c2b | 2270 | if (dst) |
bf7cd94d | 2271 | return mesh_path_del(sdata, dst); |
c5dd9c2b | 2272 | |
ece1a2e7 | 2273 | mesh_path_flush_by_iface(sdata); |
c5dd9c2b LCC |
2274 | return 0; |
2275 | } | |
2276 | ||
3b3a0162 JB |
2277 | static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, |
2278 | const u8 *dst, const u8 *next_hop) | |
c5dd9c2b | 2279 | { |
14db74bc | 2280 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2281 | struct mesh_path *mpath; |
2282 | struct sta_info *sta; | |
2283 | ||
14db74bc JB |
2284 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2285 | ||
d0709a65 JB |
2286 | rcu_read_lock(); |
2287 | ||
abe60632 | 2288 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
2289 | if (!sta) { |
2290 | rcu_read_unlock(); | |
c5dd9c2b | 2291 | return -ENOENT; |
d0709a65 | 2292 | } |
c5dd9c2b | 2293 | |
bf7cd94d | 2294 | mpath = mesh_path_lookup(sdata, dst); |
c5dd9c2b LCC |
2295 | if (!mpath) { |
2296 | rcu_read_unlock(); | |
c5dd9c2b LCC |
2297 | return -ENOENT; |
2298 | } | |
2299 | ||
2300 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 2301 | |
c5dd9c2b LCC |
2302 | rcu_read_unlock(); |
2303 | return 0; | |
2304 | } | |
2305 | ||
2306 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, | |
2307 | struct mpath_info *pinfo) | |
2308 | { | |
a3836e02 JB |
2309 | struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); |
2310 | ||
2311 | if (next_hop_sta) | |
2312 | memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); | |
c5dd9c2b | 2313 | else |
c84a67a2 | 2314 | eth_zero_addr(next_hop); |
c5dd9c2b | 2315 | |
7ce8c7a3 LAYS |
2316 | memset(pinfo, 0, sizeof(*pinfo)); |
2317 | ||
2bdaf386 | 2318 | pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; |
f5ea9120 | 2319 | |
c5dd9c2b | 2320 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
d19b3bf6 | 2321 | MPATH_INFO_SN | |
c5dd9c2b LCC |
2322 | MPATH_INFO_METRIC | |
2323 | MPATH_INFO_EXPTIME | | |
2324 | MPATH_INFO_DISCOVERY_TIMEOUT | | |
2325 | MPATH_INFO_DISCOVERY_RETRIES | | |
cc241636 | 2326 | MPATH_INFO_FLAGS | |
540bbcb9 JH |
2327 | MPATH_INFO_HOP_COUNT | |
2328 | MPATH_INFO_PATH_CHANGE; | |
c5dd9c2b LCC |
2329 | |
2330 | pinfo->frame_qlen = mpath->frame_queue.qlen; | |
d19b3bf6 | 2331 | pinfo->sn = mpath->sn; |
c5dd9c2b LCC |
2332 | pinfo->metric = mpath->metric; |
2333 | if (time_before(jiffies, mpath->exp_time)) | |
2334 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); | |
2335 | pinfo->discovery_timeout = | |
2336 | jiffies_to_msecs(mpath->discovery_timeout); | |
2337 | pinfo->discovery_retries = mpath->discovery_retries; | |
c5dd9c2b LCC |
2338 | if (mpath->flags & MESH_PATH_ACTIVE) |
2339 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; | |
2340 | if (mpath->flags & MESH_PATH_RESOLVING) | |
2341 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
d19b3bf6 RP |
2342 | if (mpath->flags & MESH_PATH_SN_VALID) |
2343 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; | |
c5dd9c2b LCC |
2344 | if (mpath->flags & MESH_PATH_FIXED) |
2345 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; | |
7ce8c7a3 LAYS |
2346 | if (mpath->flags & MESH_PATH_RESOLVED) |
2347 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; | |
cc241636 | 2348 | pinfo->hop_count = mpath->hop_count; |
540bbcb9 | 2349 | pinfo->path_change_count = mpath->path_change_count; |
c5dd9c2b LCC |
2350 | } |
2351 | ||
2352 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, | |
2353 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) | |
2354 | ||
2355 | { | |
14db74bc | 2356 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2357 | struct mesh_path *mpath; |
2358 | ||
14db74bc JB |
2359 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2360 | ||
c5dd9c2b | 2361 | rcu_read_lock(); |
bf7cd94d | 2362 | mpath = mesh_path_lookup(sdata, dst); |
c5dd9c2b LCC |
2363 | if (!mpath) { |
2364 | rcu_read_unlock(); | |
2365 | return -ENOENT; | |
2366 | } | |
2367 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2368 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
2369 | rcu_read_unlock(); | |
2370 | return 0; | |
2371 | } | |
2372 | ||
2373 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, | |
3b3a0162 JB |
2374 | int idx, u8 *dst, u8 *next_hop, |
2375 | struct mpath_info *pinfo) | |
c5dd9c2b | 2376 | { |
14db74bc | 2377 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
2378 | struct mesh_path *mpath; |
2379 | ||
14db74bc JB |
2380 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2381 | ||
c5dd9c2b | 2382 | rcu_read_lock(); |
bf7cd94d | 2383 | mpath = mesh_path_lookup_by_idx(sdata, idx); |
c5dd9c2b LCC |
2384 | if (!mpath) { |
2385 | rcu_read_unlock(); | |
2386 | return -ENOENT; | |
2387 | } | |
2388 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2389 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
2390 | rcu_read_unlock(); | |
2391 | return 0; | |
2392 | } | |
93da9cc1 | 2393 | |
a2db2ed3 HR |
2394 | static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, |
2395 | struct mpath_info *pinfo) | |
2396 | { | |
2397 | memset(pinfo, 0, sizeof(*pinfo)); | |
2398 | memcpy(mpp, mpath->mpp, ETH_ALEN); | |
2399 | ||
2bdaf386 | 2400 | pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; |
a2db2ed3 HR |
2401 | } |
2402 | ||
2403 | static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, | |
2404 | u8 *dst, u8 *mpp, struct mpath_info *pinfo) | |
2405 | ||
2406 | { | |
2407 | struct ieee80211_sub_if_data *sdata; | |
2408 | struct mesh_path *mpath; | |
2409 | ||
2410 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2411 | ||
2412 | rcu_read_lock(); | |
2413 | mpath = mpp_path_lookup(sdata, dst); | |
2414 | if (!mpath) { | |
2415 | rcu_read_unlock(); | |
2416 | return -ENOENT; | |
2417 | } | |
2418 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2419 | mpp_set_pinfo(mpath, mpp, pinfo); | |
2420 | rcu_read_unlock(); | |
2421 | return 0; | |
2422 | } | |
2423 | ||
2424 | static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, | |
2425 | int idx, u8 *dst, u8 *mpp, | |
2426 | struct mpath_info *pinfo) | |
2427 | { | |
2428 | struct ieee80211_sub_if_data *sdata; | |
2429 | struct mesh_path *mpath; | |
2430 | ||
2431 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2432 | ||
2433 | rcu_read_lock(); | |
2434 | mpath = mpp_path_lookup_by_idx(sdata, idx); | |
2435 | if (!mpath) { | |
2436 | rcu_read_unlock(); | |
2437 | return -ENOENT; | |
2438 | } | |
2439 | memcpy(dst, mpath->dst, ETH_ALEN); | |
2440 | mpp_set_pinfo(mpath, mpp, pinfo); | |
2441 | rcu_read_unlock(); | |
2442 | return 0; | |
2443 | } | |
2444 | ||
24bdd9f4 | 2445 | static int ieee80211_get_mesh_config(struct wiphy *wiphy, |
93da9cc1 | 2446 | struct net_device *dev, |
2447 | struct mesh_config *conf) | |
2448 | { | |
2449 | struct ieee80211_sub_if_data *sdata; | |
2450 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2451 | ||
93da9cc1 | 2452 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
2453 | return 0; | |
2454 | } | |
2455 | ||
2456 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) | |
2457 | { | |
2458 | return (mask >> (parm-1)) & 0x1; | |
2459 | } | |
2460 | ||
c80d545d JC |
2461 | static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, |
2462 | const struct mesh_setup *setup) | |
2463 | { | |
2464 | u8 *new_ie; | |
4bb62344 CYY |
2465 | struct ieee80211_sub_if_data *sdata = container_of(ifmsh, |
2466 | struct ieee80211_sub_if_data, u.mesh); | |
08fad438 | 2467 | int i; |
c80d545d | 2468 | |
581a8b0f | 2469 | /* allocate information elements */ |
c80d545d | 2470 | new_ie = NULL; |
c80d545d | 2471 | |
581a8b0f JC |
2472 | if (setup->ie_len) { |
2473 | new_ie = kmemdup(setup->ie, setup->ie_len, | |
c80d545d JC |
2474 | GFP_KERNEL); |
2475 | if (!new_ie) | |
2476 | return -ENOMEM; | |
2477 | } | |
581a8b0f JC |
2478 | ifmsh->ie_len = setup->ie_len; |
2479 | ifmsh->ie = new_ie; | |
c80d545d JC |
2480 | |
2481 | /* now copy the rest of the setup parameters */ | |
2482 | ifmsh->mesh_id_len = setup->mesh_id_len; | |
2483 | memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); | |
d299a1f2 | 2484 | ifmsh->mesh_sp_id = setup->sync_method; |
c80d545d JC |
2485 | ifmsh->mesh_pp_id = setup->path_sel_proto; |
2486 | ifmsh->mesh_pm_id = setup->path_metric; | |
a6dad6a2 | 2487 | ifmsh->user_mpm = setup->user_mpm; |
0d4261ad | 2488 | ifmsh->mesh_auth_id = setup->auth_id; |
b130e5ce | 2489 | ifmsh->security = IEEE80211_MESH_SEC_NONE; |
0ab2e55d | 2490 | ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; |
b130e5ce JC |
2491 | if (setup->is_authenticated) |
2492 | ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; | |
2493 | if (setup->is_secure) | |
2494 | ifmsh->security |= IEEE80211_MESH_SEC_SECURED; | |
c80d545d | 2495 | |
4bb62344 CYY |
2496 | /* mcast rate setting in Mesh Node */ |
2497 | memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, | |
2498 | sizeof(setup->mcast_rate)); | |
ffb3cf30 | 2499 | sdata->vif.bss_conf.basic_rates = setup->basic_rates; |
4bb62344 | 2500 | |
9bdbf04d MP |
2501 | sdata->vif.bss_conf.beacon_int = setup->beacon_interval; |
2502 | sdata->vif.bss_conf.dtim_period = setup->dtim_period; | |
2503 | ||
08fad438 JM |
2504 | sdata->beacon_rate_set = false; |
2505 | if (wiphy_ext_feature_isset(sdata->local->hw.wiphy, | |
2506 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) { | |
2507 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
2508 | sdata->beacon_rateidx_mask[i] = | |
2509 | setup->beacon_rate.control[i].legacy; | |
2510 | if (sdata->beacon_rateidx_mask[i]) | |
2511 | sdata->beacon_rate_set = true; | |
2512 | } | |
2513 | } | |
2514 | ||
c80d545d JC |
2515 | return 0; |
2516 | } | |
2517 | ||
24bdd9f4 | 2518 | static int ieee80211_update_mesh_config(struct wiphy *wiphy, |
29cbe68c JB |
2519 | struct net_device *dev, u32 mask, |
2520 | const struct mesh_config *nconf) | |
93da9cc1 | 2521 | { |
2522 | struct mesh_config *conf; | |
2523 | struct ieee80211_sub_if_data *sdata; | |
63c5723b RP |
2524 | struct ieee80211_if_mesh *ifmsh; |
2525 | ||
93da9cc1 | 2526 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
63c5723b | 2527 | ifmsh = &sdata->u.mesh; |
93da9cc1 | 2528 | |
93da9cc1 | 2529 | /* Set the config options which we are interested in setting */ |
2530 | conf = &(sdata->u.mesh.mshcfg); | |
2531 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) | |
2532 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; | |
2533 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) | |
2534 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; | |
2535 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) | |
2536 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; | |
2537 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) | |
2538 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; | |
2539 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) | |
2540 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; | |
2541 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) | |
2542 | conf->dot11MeshTTL = nconf->dot11MeshTTL; | |
45904f21 | 2543 | if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) |
58886a90 | 2544 | conf->element_ttl = nconf->element_ttl; |
146bb483 TP |
2545 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { |
2546 | if (ifmsh->user_mpm) | |
2547 | return -EBUSY; | |
93da9cc1 | 2548 | conf->auto_open_plinks = nconf->auto_open_plinks; |
146bb483 | 2549 | } |
d299a1f2 JC |
2550 | if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) |
2551 | conf->dot11MeshNbrOffsetMaxNeighbor = | |
2552 | nconf->dot11MeshNbrOffsetMaxNeighbor; | |
93da9cc1 | 2553 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
2554 | conf->dot11MeshHWMPmaxPREQretries = | |
2555 | nconf->dot11MeshHWMPmaxPREQretries; | |
2556 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) | |
2557 | conf->path_refresh_time = nconf->path_refresh_time; | |
2558 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) | |
2559 | conf->min_discovery_timeout = nconf->min_discovery_timeout; | |
2560 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) | |
2561 | conf->dot11MeshHWMPactivePathTimeout = | |
2562 | nconf->dot11MeshHWMPactivePathTimeout; | |
2563 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) | |
2564 | conf->dot11MeshHWMPpreqMinInterval = | |
2565 | nconf->dot11MeshHWMPpreqMinInterval; | |
dca7e943 TP |
2566 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) |
2567 | conf->dot11MeshHWMPperrMinInterval = | |
2568 | nconf->dot11MeshHWMPperrMinInterval; | |
93da9cc1 | 2569 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
2570 | mask)) | |
2571 | conf->dot11MeshHWMPnetDiameterTraversalTime = | |
2572 | nconf->dot11MeshHWMPnetDiameterTraversalTime; | |
63c5723b RP |
2573 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
2574 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; | |
2575 | ieee80211_mesh_root_setup(ifmsh); | |
2576 | } | |
16dd7267 | 2577 | if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { |
c6133661 TP |
2578 | /* our current gate announcement implementation rides on root |
2579 | * announcements, so require this ifmsh to also be a root node | |
2580 | * */ | |
2581 | if (nconf->dot11MeshGateAnnouncementProtocol && | |
dbb912cd CYY |
2582 | !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { |
2583 | conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; | |
c6133661 TP |
2584 | ieee80211_mesh_root_setup(ifmsh); |
2585 | } | |
16dd7267 JC |
2586 | conf->dot11MeshGateAnnouncementProtocol = |
2587 | nconf->dot11MeshGateAnnouncementProtocol; | |
2588 | } | |
a4f606ea | 2589 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) |
0507e159 JC |
2590 | conf->dot11MeshHWMPRannInterval = |
2591 | nconf->dot11MeshHWMPRannInterval; | |
94f90656 CYY |
2592 | if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) |
2593 | conf->dot11MeshForwarding = nconf->dot11MeshForwarding; | |
55335137 AN |
2594 | if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { |
2595 | /* our RSSI threshold implementation is supported only for | |
2596 | * devices that report signal in dBm. | |
2597 | */ | |
30686bf7 | 2598 | if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) |
0528e0fd | 2599 | return -EOPNOTSUPP; |
55335137 AN |
2600 | conf->rssi_threshold = nconf->rssi_threshold; |
2601 | } | |
70c33eaa AN |
2602 | if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { |
2603 | conf->ht_opmode = nconf->ht_opmode; | |
2604 | sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; | |
d8675a63 JB |
2605 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
2606 | BSS_CHANGED_HT); | |
70c33eaa | 2607 | } |
ac1073a6 CYY |
2608 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) |
2609 | conf->dot11MeshHWMPactivePathToRootTimeout = | |
2610 | nconf->dot11MeshHWMPactivePathToRootTimeout; | |
2611 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) | |
2612 | conf->dot11MeshHWMProotInterval = | |
2613 | nconf->dot11MeshHWMProotInterval; | |
728b19e5 CYY |
2614 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) |
2615 | conf->dot11MeshHWMPconfirmationInterval = | |
2616 | nconf->dot11MeshHWMPconfirmationInterval; | |
3f52b7e3 MP |
2617 | if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { |
2618 | conf->power_mode = nconf->power_mode; | |
2619 | ieee80211_mps_local_status_update(sdata); | |
2620 | } | |
2b5e1967 | 2621 | if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) |
3f52b7e3 MP |
2622 | conf->dot11MeshAwakeWindowDuration = |
2623 | nconf->dot11MeshAwakeWindowDuration; | |
66de6713 CT |
2624 | if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) |
2625 | conf->plink_timeout = nconf->plink_timeout; | |
01d66fbd BC |
2626 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask)) |
2627 | conf->dot11MeshConnectedToMeshGate = | |
2628 | nconf->dot11MeshConnectedToMeshGate; | |
e3718a61 LL |
2629 | if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask)) |
2630 | conf->dot11MeshNolearn = nconf->dot11MeshNolearn; | |
184eebe6 MT |
2631 | if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask)) |
2632 | conf->dot11MeshConnectedToAuthServer = | |
2633 | nconf->dot11MeshConnectedToAuthServer; | |
2b5e1967 | 2634 | ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
93da9cc1 | 2635 | return 0; |
2636 | } | |
2637 | ||
29cbe68c JB |
2638 | static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, |
2639 | const struct mesh_config *conf, | |
2640 | const struct mesh_setup *setup) | |
2641 | { | |
2642 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 2643 | struct ieee80211_chan_req chanreq = { .oper = setup->chandef }; |
29cbe68c | 2644 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
c80d545d | 2645 | int err; |
29cbe68c | 2646 | |
0cd8080e JB |
2647 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
2648 | ||
c80d545d JC |
2649 | memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); |
2650 | err = copy_mesh_setup(ifmsh, setup); | |
2651 | if (err) | |
2652 | return err; | |
cc1d2806 | 2653 | |
018f6fbf DK |
2654 | sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; |
2655 | ||
04ecd257 | 2656 | /* can mesh use other SMPS modes? */ |
bfd8403a JB |
2657 | sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; |
2658 | sdata->deflink.needed_rx_chains = sdata->local->rx_chains; | |
04ecd257 | 2659 | |
6092077a | 2660 | err = ieee80211_link_use_channel(&sdata->deflink, &chanreq, |
b4f85443 | 2661 | IEEE80211_CHANCTX_SHARED); |
cc1d2806 JB |
2662 | if (err) |
2663 | return err; | |
2664 | ||
2b5e1967 | 2665 | return ieee80211_start_mesh(sdata); |
29cbe68c JB |
2666 | } |
2667 | ||
2668 | static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) | |
2669 | { | |
2670 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2671 | ||
0cd8080e JB |
2672 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
2673 | ||
29cbe68c | 2674 | ieee80211_stop_mesh(sdata); |
d8675a63 | 2675 | ieee80211_link_release_channel(&sdata->deflink); |
6a01afcf | 2676 | kfree(sdata->u.mesh.ie); |
29cbe68c JB |
2677 | |
2678 | return 0; | |
2679 | } | |
c5dd9c2b LCC |
2680 | #endif |
2681 | ||
9f1ba906 JM |
2682 | static int ieee80211_change_bss(struct wiphy *wiphy, |
2683 | struct net_device *dev, | |
2684 | struct bss_parameters *params) | |
2685 | { | |
55de908a | 2686 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
9a886df0 | 2687 | struct ieee80211_link_data *link; |
21a8e9dd | 2688 | struct ieee80211_supported_band *sband; |
15ddba5f | 2689 | u64 changed = 0; |
9f1ba906 | 2690 | |
9a886df0 JB |
2691 | link = ieee80211_link_or_deflink(sdata, params->link_id, true); |
2692 | if (IS_ERR(link)) | |
2693 | return PTR_ERR(link); | |
2694 | ||
2695 | if (!sdata_dereference(link->u.ap.beacon, sdata)) | |
55de908a JB |
2696 | return -ENOENT; |
2697 | ||
9a886df0 | 2698 | sband = ieee80211_get_link_sband(link); |
21a8e9dd MSS |
2699 | if (!sband) |
2700 | return -EINVAL; | |
9f1ba906 | 2701 | |
ce04abc3 | 2702 | if (params->basic_rates) { |
6092077a | 2703 | if (!ieee80211_parse_bitrates(link->conf->chanreq.oper.width, |
ce04abc3 JB |
2704 | wiphy->bands[sband->band], |
2705 | params->basic_rates, | |
2706 | params->basic_rates_len, | |
2707 | &link->conf->basic_rates)) | |
2708 | return -EINVAL; | |
2709 | changed |= BSS_CHANGED_BASIC_RATES; | |
2710 | ieee80211_check_rate_mask(link); | |
2711 | } | |
2712 | ||
9f1ba906 | 2713 | if (params->use_cts_prot >= 0) { |
9a886df0 | 2714 | link->conf->use_cts_prot = params->use_cts_prot; |
9f1ba906 JM |
2715 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
2716 | } | |
2717 | if (params->use_short_preamble >= 0) { | |
9a886df0 | 2718 | link->conf->use_short_preamble = params->use_short_preamble; |
9f1ba906 JM |
2719 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
2720 | } | |
43d35343 | 2721 | |
9a886df0 | 2722 | if (!link->conf->use_short_slot && |
07c12d61 TM |
2723 | (sband->band == NL80211_BAND_5GHZ || |
2724 | sband->band == NL80211_BAND_6GHZ)) { | |
9a886df0 | 2725 | link->conf->use_short_slot = true; |
43d35343 FF |
2726 | changed |= BSS_CHANGED_ERP_SLOT; |
2727 | } | |
2728 | ||
9f1ba906 | 2729 | if (params->use_short_slot_time >= 0) { |
9a886df0 | 2730 | link->conf->use_short_slot = params->use_short_slot_time; |
9f1ba906 JM |
2731 | changed |= BSS_CHANGED_ERP_SLOT; |
2732 | } | |
2733 | ||
7b7b5e56 FF |
2734 | if (params->ap_isolate >= 0) { |
2735 | if (params->ap_isolate) | |
2736 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
2737 | else | |
2738 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
49ddf8e6 | 2739 | ieee80211_check_fast_rx_iface(sdata); |
7b7b5e56 FF |
2740 | } |
2741 | ||
80d7e403 | 2742 | if (params->ht_opmode >= 0) { |
9a886df0 | 2743 | link->conf->ht_operation_mode = (u16)params->ht_opmode; |
80d7e403 HS |
2744 | changed |= BSS_CHANGED_HT; |
2745 | } | |
2746 | ||
339afbf4 | 2747 | if (params->p2p_ctwindow >= 0) { |
9a886df0 | 2748 | link->conf->p2p_noa_attr.oppps_ctwindow &= |
67baf663 | 2749 | ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
9a886df0 | 2750 | link->conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 | 2751 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
339afbf4 JB |
2752 | changed |= BSS_CHANGED_P2P_PS; |
2753 | } | |
2754 | ||
67baf663 | 2755 | if (params->p2p_opp_ps > 0) { |
9a886df0 | 2756 | link->conf->p2p_noa_attr.oppps_ctwindow |= |
67baf663 JD |
2757 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
2758 | changed |= BSS_CHANGED_P2P_PS; | |
2759 | } else if (params->p2p_opp_ps == 0) { | |
9a886df0 | 2760 | link->conf->p2p_noa_attr.oppps_ctwindow &= |
67baf663 | 2761 | ~IEEE80211_P2P_OPPPS_ENABLE_BIT; |
339afbf4 JB |
2762 | changed |= BSS_CHANGED_P2P_PS; |
2763 | } | |
2764 | ||
9a886df0 | 2765 | ieee80211_link_info_change_notify(sdata, link, changed); |
9f1ba906 JM |
2766 | |
2767 | return 0; | |
2768 | } | |
2769 | ||
31888487 | 2770 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
f70f01c2 | 2771 | struct net_device *dev, |
31888487 JM |
2772 | struct ieee80211_txq_params *params) |
2773 | { | |
2774 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
f6f3def3 | 2775 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
c88f1542 | 2776 | struct ieee80211_link_data *link = |
ccdde7c7 | 2777 | ieee80211_link_or_deflink(sdata, params->link_id, true); |
31888487 JM |
2778 | struct ieee80211_tx_queue_params p; |
2779 | ||
2780 | if (!local->ops->conf_tx) | |
2781 | return -EOPNOTSUPP; | |
2782 | ||
54bcbc69 JB |
2783 | if (local->hw.queues < IEEE80211_NUM_ACS) |
2784 | return -EOPNOTSUPP; | |
2785 | ||
c88f1542 ST |
2786 | if (IS_ERR(link)) |
2787 | return PTR_ERR(link); | |
2788 | ||
31888487 JM |
2789 | memset(&p, 0, sizeof(p)); |
2790 | p.aifs = params->aifs; | |
2791 | p.cw_max = params->cwmax; | |
2792 | p.cw_min = params->cwmin; | |
2793 | p.txop = params->txop; | |
ab13315a KV |
2794 | |
2795 | /* | |
2796 | * Setting tx queue params disables u-apsd because it's only | |
2797 | * called in master mode. | |
2798 | */ | |
2799 | p.uapsd = false; | |
2800 | ||
e552af05 HD |
2801 | ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); |
2802 | ||
b3e2130b JB |
2803 | link->tx_conf[params->ac] = p; |
2804 | if (drv_conf_tx(local, link, params->ac, &p)) { | |
0fb9a9ec | 2805 | wiphy_debug(local->hw.wiphy, |
a3304b0a JB |
2806 | "failed to set TX queue parameters for AC %d\n", |
2807 | params->ac); | |
31888487 JM |
2808 | return -EINVAL; |
2809 | } | |
2810 | ||
b3e2130b | 2811 | ieee80211_link_info_change_notify(sdata, link, |
d8675a63 | 2812 | BSS_CHANGED_QOS); |
7d25745d | 2813 | |
31888487 JM |
2814 | return 0; |
2815 | } | |
2816 | ||
665af4fc | 2817 | #ifdef CONFIG_PM |
ff1b6e69 JB |
2818 | static int ieee80211_suspend(struct wiphy *wiphy, |
2819 | struct cfg80211_wowlan *wowlan) | |
665af4fc | 2820 | { |
eecc4800 | 2821 | return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); |
665af4fc BC |
2822 | } |
2823 | ||
2824 | static int ieee80211_resume(struct wiphy *wiphy) | |
2825 | { | |
2826 | return __ieee80211_resume(wiphy_priv(wiphy)); | |
2827 | } | |
2828 | #else | |
2829 | #define ieee80211_suspend NULL | |
2830 | #define ieee80211_resume NULL | |
2831 | #endif | |
2832 | ||
2a519311 | 2833 | static int ieee80211_scan(struct wiphy *wiphy, |
2a519311 JB |
2834 | struct cfg80211_scan_request *req) |
2835 | { | |
fd014284 JB |
2836 | struct ieee80211_sub_if_data *sdata; |
2837 | ||
2838 | sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); | |
2a519311 | 2839 | |
2ca27bcf JB |
2840 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
2841 | case NL80211_IFTYPE_STATION: | |
2842 | case NL80211_IFTYPE_ADHOC: | |
2843 | case NL80211_IFTYPE_MESH_POINT: | |
2844 | case NL80211_IFTYPE_P2P_CLIENT: | |
f142c6b9 | 2845 | case NL80211_IFTYPE_P2P_DEVICE: |
2ca27bcf JB |
2846 | break; |
2847 | case NL80211_IFTYPE_P2P_GO: | |
2848 | if (sdata->local->ops->hw_scan) | |
2849 | break; | |
e9d7732e JB |
2850 | /* |
2851 | * FIXME: implement NoA while scanning in software, | |
2852 | * for now fall through to allow scanning only when | |
2853 | * beaconing hasn't been configured yet | |
2854 | */ | |
fc0561dc | 2855 | fallthrough; |
2ca27bcf | 2856 | case NL80211_IFTYPE_AP: |
5c95b940 AQ |
2857 | /* |
2858 | * If the scan has been forced (and the driver supports | |
2859 | * forcing), don't care about being beaconing already. | |
2860 | * This will create problems to the attached stations (e.g. all | |
71a659bf | 2861 | * the frames sent while scanning on other channel will be |
5c95b940 AQ |
2862 | * lost) |
2863 | */ | |
bfd8403a | 2864 | if (sdata->deflink.u.ap.beacon && |
5c95b940 AQ |
2865 | (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || |
2866 | !(req->flags & NL80211_SCAN_FLAG_AP))) | |
2ca27bcf JB |
2867 | return -EOPNOTSUPP; |
2868 | break; | |
cb3b7d87 | 2869 | case NL80211_IFTYPE_NAN: |
2ca27bcf JB |
2870 | default: |
2871 | return -EOPNOTSUPP; | |
2872 | } | |
2a519311 JB |
2873 | |
2874 | return ieee80211_request_scan(sdata, req); | |
2875 | } | |
2876 | ||
91f123f2 VK |
2877 | static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) |
2878 | { | |
2879 | ieee80211_scan_cancel(wiphy_priv(wiphy)); | |
2880 | } | |
2881 | ||
79f460ca LC |
2882 | static int |
2883 | ieee80211_sched_scan_start(struct wiphy *wiphy, | |
2884 | struct net_device *dev, | |
2885 | struct cfg80211_sched_scan_request *req) | |
2886 | { | |
2887 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2888 | ||
2889 | if (!sdata->local->ops->sched_scan_start) | |
2890 | return -EOPNOTSUPP; | |
2891 | ||
2892 | return ieee80211_request_sched_scan_start(sdata, req); | |
2893 | } | |
2894 | ||
2895 | static int | |
3a3ecf1d AVS |
2896 | ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, |
2897 | u64 reqid) | |
79f460ca | 2898 | { |
0d440ea2 | 2899 | struct ieee80211_local *local = wiphy_priv(wiphy); |
79f460ca | 2900 | |
0d440ea2 | 2901 | if (!local->ops->sched_scan_stop) |
79f460ca LC |
2902 | return -EOPNOTSUPP; |
2903 | ||
0d440ea2 | 2904 | return ieee80211_request_sched_scan_stop(local); |
79f460ca LC |
2905 | } |
2906 | ||
636a5d36 JM |
2907 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
2908 | struct cfg80211_auth_request *req) | |
2909 | { | |
77fdaa12 | 2910 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2911 | } |
2912 | ||
2913 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, | |
2914 | struct cfg80211_assoc_request *req) | |
2915 | { | |
77fdaa12 | 2916 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2917 | } |
2918 | ||
2919 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, | |
63c9c5e7 | 2920 | struct cfg80211_deauth_request *req) |
636a5d36 | 2921 | { |
63c9c5e7 | 2922 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2923 | } |
2924 | ||
2925 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, | |
63c9c5e7 | 2926 | struct cfg80211_disassoc_request *req) |
636a5d36 | 2927 | { |
63c9c5e7 | 2928 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
2929 | } |
2930 | ||
af8cdcd8 JB |
2931 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
2932 | struct cfg80211_ibss_params *params) | |
2933 | { | |
55de908a | 2934 | return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); |
af8cdcd8 JB |
2935 | } |
2936 | ||
2937 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) | |
2938 | { | |
55de908a | 2939 | return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
af8cdcd8 JB |
2940 | } |
2941 | ||
239281f8 RL |
2942 | static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, |
2943 | struct ocb_setup *setup) | |
2944 | { | |
2945 | return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); | |
2946 | } | |
2947 | ||
2948 | static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) | |
2949 | { | |
2950 | return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); | |
2951 | } | |
2952 | ||
391e53e3 | 2953 | static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, |
57fbcce3 | 2954 | int rate[NUM_NL80211_BANDS]) |
391e53e3 AQ |
2955 | { |
2956 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2957 | ||
9887dbf5 | 2958 | memcpy(sdata->vif.bss_conf.mcast_rate, rate, |
57fbcce3 | 2959 | sizeof(int) * NUM_NL80211_BANDS); |
391e53e3 | 2960 | |
d8675a63 JB |
2961 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, |
2962 | BSS_CHANGED_MCAST_RATE); | |
dcbe73ca | 2963 | |
391e53e3 AQ |
2964 | return 0; |
2965 | } | |
2966 | ||
b9a5f8ca JM |
2967 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
2968 | { | |
2969 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
24487981 | 2970 | int err; |
b9a5f8ca | 2971 | |
f23a4780 | 2972 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { |
17c18bf8 JB |
2973 | ieee80211_check_fast_xmit_all(local); |
2974 | ||
f23a4780 AN |
2975 | err = drv_set_frag_threshold(local, wiphy->frag_threshold); |
2976 | ||
17c18bf8 JB |
2977 | if (err) { |
2978 | ieee80211_check_fast_xmit_all(local); | |
f23a4780 | 2979 | return err; |
17c18bf8 | 2980 | } |
f23a4780 AN |
2981 | } |
2982 | ||
a4bcaf55 LB |
2983 | if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || |
2984 | (changed & WIPHY_PARAM_DYN_ACK)) { | |
2985 | s16 coverage_class; | |
2986 | ||
2987 | coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? | |
2988 | wiphy->coverage_class : -1; | |
2989 | err = drv_set_coverage_class(local, coverage_class); | |
310bc676 LT |
2990 | |
2991 | if (err) | |
2992 | return err; | |
2993 | } | |
2994 | ||
b9a5f8ca | 2995 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
24487981 | 2996 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
b9a5f8ca | 2997 | |
24487981 JB |
2998 | if (err) |
2999 | return err; | |
b9a5f8ca JM |
3000 | } |
3001 | ||
8bc83c24 JB |
3002 | if (changed & WIPHY_PARAM_RETRY_SHORT) { |
3003 | if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) | |
3004 | return -EINVAL; | |
b9a5f8ca | 3005 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
8bc83c24 JB |
3006 | } |
3007 | if (changed & WIPHY_PARAM_RETRY_LONG) { | |
3008 | if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) | |
3009 | return -EINVAL; | |
b9a5f8ca | 3010 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
8bc83c24 | 3011 | } |
b9a5f8ca JM |
3012 | if (changed & |
3013 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) | |
3014 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); | |
3015 | ||
2fe4a29a THJ |
3016 | if (changed & (WIPHY_PARAM_TXQ_LIMIT | |
3017 | WIPHY_PARAM_TXQ_MEMORY_LIMIT | | |
3018 | WIPHY_PARAM_TXQ_QUANTUM)) | |
3019 | ieee80211_txq_set_params(local); | |
3020 | ||
b9a5f8ca JM |
3021 | return 0; |
3022 | } | |
3023 | ||
7643a2c3 | 3024 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
c8442118 | 3025 | struct wireless_dev *wdev, |
fa61cf70 | 3026 | enum nl80211_tx_power_setting type, int mbm) |
7643a2c3 JB |
3027 | { |
3028 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1ea6f9c0 | 3029 | struct ieee80211_sub_if_data *sdata; |
db82d8a9 LB |
3030 | enum nl80211_tx_power_setting txp_type = type; |
3031 | bool update_txp_type = false; | |
3a3713ec | 3032 | bool has_monitor = false; |
7643a2c3 | 3033 | |
be0df01d JB |
3034 | lockdep_assert_wiphy(local->hw.wiphy); |
3035 | ||
1ea6f9c0 JB |
3036 | if (wdev) { |
3037 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
3038 | ||
3a3713ec | 3039 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
6dd23603 JB |
3040 | sdata = wiphy_dereference(local->hw.wiphy, |
3041 | local->monitor_sdata); | |
3a3713ec PG |
3042 | if (!sdata) |
3043 | return -EOPNOTSUPP; | |
3044 | } | |
3045 | ||
1ea6f9c0 JB |
3046 | switch (type) { |
3047 | case NL80211_TX_POWER_AUTOMATIC: | |
bfd8403a JB |
3048 | sdata->deflink.user_power_level = |
3049 | IEEE80211_UNSET_POWER_LEVEL; | |
db82d8a9 | 3050 | txp_type = NL80211_TX_POWER_LIMITED; |
1ea6f9c0 JB |
3051 | break; |
3052 | case NL80211_TX_POWER_LIMITED: | |
3053 | case NL80211_TX_POWER_FIXED: | |
3054 | if (mbm < 0 || (mbm % 100)) | |
3055 | return -EOPNOTSUPP; | |
bfd8403a | 3056 | sdata->deflink.user_power_level = MBM_TO_DBM(mbm); |
1ea6f9c0 JB |
3057 | break; |
3058 | } | |
3059 | ||
db82d8a9 LB |
3060 | if (txp_type != sdata->vif.bss_conf.txpower_type) { |
3061 | update_txp_type = true; | |
3062 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3063 | } | |
3064 | ||
3065 | ieee80211_recalc_txpower(sdata, update_txp_type); | |
1ea6f9c0 JB |
3066 | |
3067 | return 0; | |
3068 | } | |
55de908a | 3069 | |
7643a2c3 | 3070 | switch (type) { |
fa61cf70 | 3071 | case NL80211_TX_POWER_AUTOMATIC: |
1ea6f9c0 | 3072 | local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
db82d8a9 | 3073 | txp_type = NL80211_TX_POWER_LIMITED; |
7643a2c3 | 3074 | break; |
fa61cf70 | 3075 | case NL80211_TX_POWER_LIMITED: |
fa61cf70 JO |
3076 | case NL80211_TX_POWER_FIXED: |
3077 | if (mbm < 0 || (mbm % 100)) | |
3078 | return -EOPNOTSUPP; | |
fa61cf70 | 3079 | local->user_power_level = MBM_TO_DBM(mbm); |
7643a2c3 | 3080 | break; |
7643a2c3 JB |
3081 | } |
3082 | ||
db82d8a9 | 3083 | list_for_each_entry(sdata, &local->interfaces, list) { |
3a3713ec PG |
3084 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
3085 | has_monitor = true; | |
3086 | continue; | |
3087 | } | |
bfd8403a | 3088 | sdata->deflink.user_power_level = local->user_power_level; |
db82d8a9 LB |
3089 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
3090 | update_txp_type = true; | |
3091 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3092 | } | |
3a3713ec PG |
3093 | list_for_each_entry(sdata, &local->interfaces, list) { |
3094 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) | |
3095 | continue; | |
db82d8a9 | 3096 | ieee80211_recalc_txpower(sdata, update_txp_type); |
3a3713ec | 3097 | } |
7643a2c3 | 3098 | |
3a3713ec | 3099 | if (has_monitor) { |
6dd23603 JB |
3100 | sdata = wiphy_dereference(local->hw.wiphy, |
3101 | local->monitor_sdata); | |
3a3713ec | 3102 | if (sdata) { |
bfd8403a | 3103 | sdata->deflink.user_power_level = local->user_power_level; |
3a3713ec PG |
3104 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
3105 | update_txp_type = true; | |
3106 | sdata->vif.bss_conf.txpower_type = txp_type; | |
3107 | ||
3108 | ieee80211_recalc_txpower(sdata, update_txp_type); | |
3109 | } | |
3110 | } | |
3111 | ||
7643a2c3 JB |
3112 | return 0; |
3113 | } | |
3114 | ||
c8442118 JB |
3115 | static int ieee80211_get_tx_power(struct wiphy *wiphy, |
3116 | struct wireless_dev *wdev, | |
3117 | int *dbm) | |
7643a2c3 JB |
3118 | { |
3119 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1ea6f9c0 | 3120 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
7643a2c3 | 3121 | |
5b3dc42b FF |
3122 | if (local->ops->get_txpower) |
3123 | return drv_get_txpower(local, sdata, dbm); | |
3124 | ||
0a44dfc0 | 3125 | if (local->emulate_chanctx) |
1ea6f9c0 JB |
3126 | *dbm = local->hw.conf.power_level; |
3127 | else | |
3128 | *dbm = sdata->vif.bss_conf.txpower; | |
7643a2c3 | 3129 | |
e160ab85 PKS |
3130 | /* INT_MIN indicates no power level was set yet */ |
3131 | if (*dbm == INT_MIN) | |
3132 | return -EINVAL; | |
3133 | ||
7643a2c3 JB |
3134 | return 0; |
3135 | } | |
3136 | ||
1f87f7d3 JB |
3137 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
3138 | { | |
3139 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
3140 | ||
3141 | drv_rfkill_poll(local); | |
3142 | } | |
3143 | ||
aff89a9b | 3144 | #ifdef CONFIG_NL80211_TESTMODE |
fc73f11f DS |
3145 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, |
3146 | struct wireless_dev *wdev, | |
3147 | void *data, int len) | |
aff89a9b JB |
3148 | { |
3149 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
52981cd7 | 3150 | struct ieee80211_vif *vif = NULL; |
aff89a9b JB |
3151 | |
3152 | if (!local->ops->testmode_cmd) | |
3153 | return -EOPNOTSUPP; | |
3154 | ||
52981cd7 DS |
3155 | if (wdev) { |
3156 | struct ieee80211_sub_if_data *sdata; | |
3157 | ||
3158 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
3159 | if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) | |
3160 | vif = &sdata->vif; | |
3161 | } | |
3162 | ||
3163 | return local->ops->testmode_cmd(&local->hw, vif, data, len); | |
aff89a9b | 3164 | } |
71063f0e WYG |
3165 | |
3166 | static int ieee80211_testmode_dump(struct wiphy *wiphy, | |
3167 | struct sk_buff *skb, | |
3168 | struct netlink_callback *cb, | |
3169 | void *data, int len) | |
3170 | { | |
3171 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
3172 | ||
3173 | if (!local->ops->testmode_dump) | |
3174 | return -EOPNOTSUPP; | |
3175 | ||
3176 | return local->ops->testmode_dump(&local->hw, skb, cb, data, len); | |
3177 | } | |
aff89a9b JB |
3178 | #endif |
3179 | ||
687da132 | 3180 | int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, |
d8675a63 | 3181 | struct ieee80211_link_data *link, |
687da132 | 3182 | enum ieee80211_smps_mode smps_mode) |
0f78231b JB |
3183 | { |
3184 | const u8 *ap; | |
3185 | enum ieee80211_smps_mode old_req; | |
3186 | int err; | |
d51c2ea3 AN |
3187 | struct sta_info *sta; |
3188 | bool tdls_peer_found = false; | |
0f78231b | 3189 | |
076fc877 | 3190 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
243e6df4 | 3191 | |
687da132 EG |
3192 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) |
3193 | return -EINVAL; | |
3194 | ||
68f6c6af | 3195 | if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) |
e665ab9c IP |
3196 | return 0; |
3197 | ||
d8675a63 JB |
3198 | old_req = link->u.mgd.req_smps; |
3199 | link->u.mgd.req_smps = smps_mode; | |
0f78231b | 3200 | |
00f823b6 IP |
3201 | /* The driver indicated that EML is enabled for the interface, which |
3202 | * implies that SMPS flows towards the AP should be stopped. | |
3203 | */ | |
3204 | if (sdata->vif.driver_flags & IEEE80211_VIF_EML_ACTIVE) | |
3205 | return 0; | |
3206 | ||
0f78231b JB |
3207 | if (old_req == smps_mode && |
3208 | smps_mode != IEEE80211_SMPS_AUTOMATIC) | |
3209 | return 0; | |
3210 | ||
3211 | /* | |
3212 | * If not associated, or current association is not an HT | |
04ecd257 JB |
3213 | * association, there's no need to do anything, just store |
3214 | * the new value until we associate. | |
0f78231b JB |
3215 | */ |
3216 | if (!sdata->u.mgd.associated || | |
6092077a | 3217 | link->conf->chanreq.oper.width == NL80211_CHAN_WIDTH_20_NOHT) |
0f78231b | 3218 | return 0; |
0f78231b | 3219 | |
e665ab9c | 3220 | ap = sdata->vif.cfg.ap_addr; |
0f78231b | 3221 | |
d51c2ea3 AN |
3222 | rcu_read_lock(); |
3223 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { | |
3224 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || | |
3225 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) | |
3226 | continue; | |
3227 | ||
3228 | tdls_peer_found = true; | |
3229 | break; | |
3230 | } | |
3231 | rcu_read_unlock(); | |
3232 | ||
0f78231b | 3233 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
d51c2ea3 | 3234 | if (tdls_peer_found || !sdata->u.mgd.powersave) |
0f78231b | 3235 | smps_mode = IEEE80211_SMPS_OFF; |
d51c2ea3 AN |
3236 | else |
3237 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
0f78231b JB |
3238 | } |
3239 | ||
3240 | /* send SM PS frame to AP */ | |
3241 | err = ieee80211_send_smps_action(sdata, smps_mode, | |
e665ab9c IP |
3242 | ap, ap, |
3243 | ieee80211_vif_is_mld(&sdata->vif) ? | |
3244 | link->link_id : -1); | |
0f78231b | 3245 | if (err) |
d8675a63 | 3246 | link->u.mgd.req_smps = old_req; |
d51c2ea3 | 3247 | else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) |
85977fc0 | 3248 | ieee80211_teardown_tdls_peers(link); |
0f78231b JB |
3249 | |
3250 | return err; | |
3251 | } | |
3252 | ||
bc92afd9 JB |
3253 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
3254 | bool enabled, int timeout) | |
3255 | { | |
3256 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3257 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
e9aac179 | 3258 | unsigned int link_id; |
bc92afd9 | 3259 | |
2d3db210 | 3260 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
e5de30c9 BP |
3261 | return -EOPNOTSUPP; |
3262 | ||
30686bf7 | 3263 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
bc92afd9 JB |
3264 | return -EOPNOTSUPP; |
3265 | ||
3266 | if (enabled == sdata->u.mgd.powersave && | |
ff616381 | 3267 | timeout == local->dynamic_ps_forced_timeout) |
bc92afd9 JB |
3268 | return 0; |
3269 | ||
3270 | sdata->u.mgd.powersave = enabled; | |
ff616381 | 3271 | local->dynamic_ps_forced_timeout = timeout; |
bc92afd9 | 3272 | |
0f78231b | 3273 | /* no change, but if automatic follow powersave */ |
e9aac179 | 3274 | for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) { |
d8675a63 JB |
3275 | struct ieee80211_link_data *link; |
3276 | ||
3277 | link = sdata_dereference(sdata->link[link_id], sdata); | |
3278 | ||
3279 | if (!link) | |
e9aac179 | 3280 | continue; |
d8675a63 JB |
3281 | __ieee80211_request_smps_mgd(sdata, link, |
3282 | link->u.mgd.req_smps); | |
e9aac179 | 3283 | } |
0f78231b | 3284 | |
30686bf7 | 3285 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
bc92afd9 JB |
3286 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
3287 | ||
4a733ef1 | 3288 | ieee80211_recalc_ps(local); |
ab095877 | 3289 | ieee80211_recalc_ps_vif(sdata); |
1d870162 | 3290 | ieee80211_check_fast_rx_iface(sdata); |
bc92afd9 JB |
3291 | |
3292 | return 0; | |
3293 | } | |
3294 | ||
0e3a2238 IP |
3295 | static void ieee80211_set_cqm_rssi_link(struct ieee80211_sub_if_data *sdata, |
3296 | struct ieee80211_link_data *link, | |
3297 | s32 rssi_thold, u32 rssi_hyst, | |
3298 | s32 rssi_low, s32 rssi_high) | |
3299 | { | |
3300 | struct ieee80211_bss_conf *conf; | |
3301 | ||
3302 | if (!link || !link->conf) | |
3303 | return; | |
3304 | ||
3305 | conf = link->conf; | |
3306 | ||
3307 | if (rssi_thold && rssi_hyst && | |
3308 | rssi_thold == conf->cqm_rssi_thold && | |
3309 | rssi_hyst == conf->cqm_rssi_hyst) | |
3310 | return; | |
3311 | ||
3312 | conf->cqm_rssi_thold = rssi_thold; | |
3313 | conf->cqm_rssi_hyst = rssi_hyst; | |
3314 | conf->cqm_rssi_low = rssi_low; | |
3315 | conf->cqm_rssi_high = rssi_high; | |
3316 | link->u.mgd.last_cqm_event_signal = 0; | |
3317 | ||
3318 | if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) | |
3319 | return; | |
3320 | ||
3321 | if (sdata->u.mgd.associated && | |
3322 | (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) | |
3323 | ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_CQM); | |
3324 | } | |
3325 | ||
a97c13c3 JO |
3326 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
3327 | struct net_device *dev, | |
3328 | s32 rssi_thold, u32 rssi_hyst) | |
3329 | { | |
3330 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
a97c13c3 | 3331 | struct ieee80211_vif *vif = &sdata->vif; |
0e3a2238 | 3332 | int link_id; |
a97c13c3 | 3333 | |
0e3a2238 IP |
3334 | if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER && |
3335 | !(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) | |
ef9be10c JB |
3336 | return -EOPNOTSUPP; |
3337 | ||
0e3a2238 IP |
3338 | /* For MLD, handle CQM change on all the active links */ |
3339 | for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { | |
3340 | struct ieee80211_link_data *link = | |
3341 | sdata_dereference(sdata->link[link_id], sdata); | |
2c3c5f8c | 3342 | |
0e3a2238 IP |
3343 | ieee80211_set_cqm_rssi_link(sdata, link, rssi_thold, rssi_hyst, |
3344 | 0, 0); | |
3345 | } | |
2c3c5f8c AZ |
3346 | |
3347 | return 0; | |
3348 | } | |
3349 | ||
3350 | static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, | |
3351 | struct net_device *dev, | |
3352 | s32 rssi_low, s32 rssi_high) | |
3353 | { | |
3354 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3355 | struct ieee80211_vif *vif = &sdata->vif; | |
0e3a2238 | 3356 | int link_id; |
2c3c5f8c | 3357 | |
0e3a2238 | 3358 | if (vif->driver_flags & IEEE80211_VIF_BEACON_FILTER) |
2c3c5f8c AZ |
3359 | return -EOPNOTSUPP; |
3360 | ||
0e3a2238 IP |
3361 | /* For MLD, handle CQM change on all the active links */ |
3362 | for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) { | |
3363 | struct ieee80211_link_data *link = | |
3364 | sdata_dereference(sdata->link[link_id], sdata); | |
a97c13c3 | 3365 | |
0e3a2238 IP |
3366 | ieee80211_set_cqm_rssi_link(sdata, link, 0, 0, |
3367 | rssi_low, rssi_high); | |
3368 | } | |
a97c13c3 JO |
3369 | |
3370 | return 0; | |
3371 | } | |
3372 | ||
9930380f JB |
3373 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
3374 | struct net_device *dev, | |
7b0a0e3c | 3375 | unsigned int link_id, |
9930380f JB |
3376 | const u8 *addr, |
3377 | const struct cfg80211_bitrate_mask *mask) | |
3378 | { | |
3379 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3380 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
bdbfd6b5 | 3381 | int i, ret; |
2c7e6bc9 | 3382 | |
554a43d5 EP |
3383 | if (!ieee80211_sdata_running(sdata)) |
3384 | return -ENETDOWN; | |
3385 | ||
e8e4f528 JB |
3386 | /* |
3387 | * If active validate the setting and reject it if it doesn't leave | |
3388 | * at least one basic rate usable, since we really have to be able | |
3389 | * to send something, and if we're an AP we have to be able to do | |
3390 | * so at a basic rate so that all clients can receive it. | |
3391 | */ | |
d0a9123e | 3392 | if (rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf) && |
6092077a | 3393 | sdata->vif.bss_conf.chanreq.oper.chan) { |
e8e4f528 | 3394 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
6092077a JB |
3395 | enum nl80211_band band; |
3396 | ||
3397 | band = sdata->vif.bss_conf.chanreq.oper.chan->band; | |
e8e4f528 JB |
3398 | |
3399 | if (!(mask->control[band].legacy & basic_rates)) | |
3400 | return -EINVAL; | |
3401 | } | |
3402 | ||
e5f5ce37 JB |
3403 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
3404 | ret = drv_set_bitrate_mask(local, sdata, mask); | |
3405 | if (ret) | |
3406 | return ret; | |
3407 | } | |
3408 | ||
57fbcce3 | 3409 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
2ffbe6d3 FF |
3410 | struct ieee80211_supported_band *sband = wiphy->bands[i]; |
3411 | int j; | |
3412 | ||
37eb0b16 | 3413 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; |
d1e33e65 JD |
3414 | memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, |
3415 | sizeof(mask->control[i].ht_mcs)); | |
b119ad6e LB |
3416 | memcpy(sdata->rc_rateidx_vht_mcs_mask[i], |
3417 | mask->control[i].vht_mcs, | |
3418 | sizeof(mask->control[i].vht_mcs)); | |
2ffbe6d3 FF |
3419 | |
3420 | sdata->rc_has_mcs_mask[i] = false; | |
b119ad6e | 3421 | sdata->rc_has_vht_mcs_mask[i] = false; |
2ffbe6d3 FF |
3422 | if (!sband) |
3423 | continue; | |
3424 | ||
b119ad6e | 3425 | for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { |
1944015f | 3426 | if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) { |
2ffbe6d3 | 3427 | sdata->rc_has_mcs_mask[i] = true; |
2df1b131 JB |
3428 | break; |
3429 | } | |
3430 | } | |
b119ad6e | 3431 | |
2df1b131 | 3432 | for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { |
1944015f | 3433 | if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) { |
b119ad6e | 3434 | sdata->rc_has_vht_mcs_mask[i] = true; |
2ffbe6d3 | 3435 | break; |
2df1b131 | 3436 | } |
b119ad6e | 3437 | } |
19468413 | 3438 | } |
9930380f | 3439 | |
37eb0b16 | 3440 | return 0; |
9930380f JB |
3441 | } |
3442 | ||
164eb02d SW |
3443 | static int ieee80211_start_radar_detection(struct wiphy *wiphy, |
3444 | struct net_device *dev, | |
31559f35 JD |
3445 | struct cfg80211_chan_def *chandef, |
3446 | u32 cac_time_ms) | |
164eb02d SW |
3447 | { |
3448 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 3449 | struct ieee80211_chan_req chanreq = { .oper = *chandef }; |
164eb02d | 3450 | struct ieee80211_local *local = sdata->local; |
164eb02d SW |
3451 | int err; |
3452 | ||
0cd8080e JB |
3453 | lockdep_assert_wiphy(local->hw.wiphy); |
3454 | ||
34a3740d JB |
3455 | if (!list_empty(&local->roc_list) || local->scanning) { |
3456 | err = -EBUSY; | |
3457 | goto out_unlock; | |
3458 | } | |
164eb02d SW |
3459 | |
3460 | /* whatever, but channel contexts should not complain about that one */ | |
bfd8403a JB |
3461 | sdata->deflink.smps_mode = IEEE80211_SMPS_OFF; |
3462 | sdata->deflink.needed_rx_chains = local->rx_chains; | |
164eb02d | 3463 | |
6092077a | 3464 | err = ieee80211_link_use_channel(&sdata->deflink, &chanreq, |
b4f85443 | 3465 | IEEE80211_CHANCTX_SHARED); |
164eb02d | 3466 | if (err) |
34a3740d | 3467 | goto out_unlock; |
164eb02d | 3468 | |
766d2601 JB |
3469 | wiphy_delayed_work_queue(wiphy, &sdata->deflink.dfs_cac_timer_work, |
3470 | msecs_to_jiffies(cac_time_ms)); | |
164eb02d | 3471 | |
34a3740d | 3472 | out_unlock: |
34a3740d | 3473 | return err; |
164eb02d SW |
3474 | } |
3475 | ||
26ec17a1 OM |
3476 | static void ieee80211_end_cac(struct wiphy *wiphy, |
3477 | struct net_device *dev) | |
3478 | { | |
3479 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
3480 | struct ieee80211_local *local = sdata->local; | |
3481 | ||
0cd8080e JB |
3482 | lockdep_assert_wiphy(local->hw.wiphy); |
3483 | ||
26ec17a1 OM |
3484 | list_for_each_entry(sdata, &local->interfaces, list) { |
3485 | /* it might be waiting for the local->mtx, but then | |
3486 | * by the time it gets it, sdata->wdev.cac_started | |
3487 | * will no longer be true | |
3488 | */ | |
766d2601 JB |
3489 | wiphy_delayed_work_cancel(wiphy, |
3490 | &sdata->deflink.dfs_cac_timer_work); | |
26ec17a1 OM |
3491 | |
3492 | if (sdata->wdev.cac_started) { | |
d8675a63 | 3493 | ieee80211_link_release_channel(&sdata->deflink); |
26ec17a1 OM |
3494 | sdata->wdev.cac_started = false; |
3495 | } | |
3496 | } | |
26ec17a1 OM |
3497 | } |
3498 | ||
73da7d5b SW |
3499 | static struct cfg80211_beacon_data * |
3500 | cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) | |
3501 | { | |
3502 | struct cfg80211_beacon_data *new_beacon; | |
3503 | u8 *pos; | |
3504 | int len; | |
3505 | ||
3506 | len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + | |
3507 | beacon->proberesp_ies_len + beacon->assocresp_ies_len + | |
bd54f3c2 AD |
3508 | beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len; |
3509 | ||
3510 | if (beacon->mbssid_ies) | |
3511 | len += ieee80211_get_mbssid_beacon_len(beacon->mbssid_ies, | |
68b9bea2 | 3512 | beacon->rnr_ies, |
bd54f3c2 | 3513 | beacon->mbssid_ies->cnt); |
73da7d5b SW |
3514 | |
3515 | new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); | |
3516 | if (!new_beacon) | |
3517 | return NULL; | |
3518 | ||
2b3171c6 LB |
3519 | if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { |
3520 | new_beacon->mbssid_ies = | |
3521 | kzalloc(struct_size(new_beacon->mbssid_ies, | |
3522 | elem, beacon->mbssid_ies->cnt), | |
3523 | GFP_KERNEL); | |
3524 | if (!new_beacon->mbssid_ies) { | |
3525 | kfree(new_beacon); | |
3526 | return NULL; | |
3527 | } | |
68b9bea2 AD |
3528 | |
3529 | if (beacon->rnr_ies && beacon->rnr_ies->cnt) { | |
3530 | new_beacon->rnr_ies = | |
3531 | kzalloc(struct_size(new_beacon->rnr_ies, | |
3532 | elem, beacon->rnr_ies->cnt), | |
3533 | GFP_KERNEL); | |
3534 | if (!new_beacon->rnr_ies) { | |
3535 | kfree(new_beacon->mbssid_ies); | |
3536 | kfree(new_beacon); | |
3537 | return NULL; | |
3538 | } | |
3539 | } | |
2b3171c6 LB |
3540 | } |
3541 | ||
73da7d5b SW |
3542 | pos = (u8 *)(new_beacon + 1); |
3543 | if (beacon->head_len) { | |
3544 | new_beacon->head_len = beacon->head_len; | |
3545 | new_beacon->head = pos; | |
3546 | memcpy(pos, beacon->head, beacon->head_len); | |
3547 | pos += beacon->head_len; | |
3548 | } | |
3549 | if (beacon->tail_len) { | |
3550 | new_beacon->tail_len = beacon->tail_len; | |
3551 | new_beacon->tail = pos; | |
3552 | memcpy(pos, beacon->tail, beacon->tail_len); | |
3553 | pos += beacon->tail_len; | |
3554 | } | |
3555 | if (beacon->beacon_ies_len) { | |
3556 | new_beacon->beacon_ies_len = beacon->beacon_ies_len; | |
3557 | new_beacon->beacon_ies = pos; | |
3558 | memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); | |
3559 | pos += beacon->beacon_ies_len; | |
3560 | } | |
3561 | if (beacon->proberesp_ies_len) { | |
3562 | new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; | |
3563 | new_beacon->proberesp_ies = pos; | |
3564 | memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); | |
3565 | pos += beacon->proberesp_ies_len; | |
3566 | } | |
3567 | if (beacon->assocresp_ies_len) { | |
3568 | new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; | |
3569 | new_beacon->assocresp_ies = pos; | |
3570 | memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); | |
3571 | pos += beacon->assocresp_ies_len; | |
3572 | } | |
3573 | if (beacon->probe_resp_len) { | |
3574 | new_beacon->probe_resp_len = beacon->probe_resp_len; | |
bee92d06 | 3575 | new_beacon->probe_resp = pos; |
73da7d5b SW |
3576 | memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); |
3577 | pos += beacon->probe_resp_len; | |
3578 | } | |
68b9bea2 | 3579 | if (beacon->mbssid_ies && beacon->mbssid_ies->cnt) { |
2b3171c6 LB |
3580 | pos += ieee80211_copy_mbssid_beacon(pos, |
3581 | new_beacon->mbssid_ies, | |
3582 | beacon->mbssid_ies); | |
68b9bea2 AD |
3583 | if (beacon->rnr_ies && beacon->rnr_ies->cnt) |
3584 | pos += ieee80211_copy_rnr_beacon(pos, | |
3585 | new_beacon->rnr_ies, | |
3586 | beacon->rnr_ies); | |
3587 | } | |
03b73862 JB |
3588 | |
3589 | /* might copy -1, meaning no changes requested */ | |
3590 | new_beacon->ftm_responder = beacon->ftm_responder; | |
bc847970 PKC |
3591 | if (beacon->lci) { |
3592 | new_beacon->lci_len = beacon->lci_len; | |
3593 | new_beacon->lci = pos; | |
3594 | memcpy(pos, beacon->lci, beacon->lci_len); | |
3595 | pos += beacon->lci_len; | |
3596 | } | |
3597 | if (beacon->civicloc) { | |
3598 | new_beacon->civicloc_len = beacon->civicloc_len; | |
3599 | new_beacon->civicloc = pos; | |
3600 | memcpy(pos, beacon->civicloc, beacon->civicloc_len); | |
3601 | pos += beacon->civicloc_len; | |
3602 | } | |
73da7d5b SW |
3603 | |
3604 | return new_beacon; | |
3605 | } | |
3606 | ||
04ada859 | 3607 | void ieee80211_csa_finish(struct ieee80211_vif *vif, unsigned int link_id) |
73da7d5b | 3608 | { |
66e01cf9 | 3609 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
c9eb90a5 | 3610 | struct ieee80211_local *local = sdata->local; |
04ada859 AKS |
3611 | struct ieee80211_link_data *link_data; |
3612 | ||
3613 | if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) | |
3614 | return; | |
c9eb90a5 JC |
3615 | |
3616 | rcu_read_lock(); | |
3617 | ||
04ada859 AKS |
3618 | link_data = rcu_dereference(sdata->link[link_id]); |
3619 | if (WARN_ON(!link_data)) { | |
3620 | rcu_read_unlock(); | |
3621 | return; | |
3622 | } | |
3623 | ||
3624 | /* TODO: MBSSID with MLO changes */ | |
c9eb90a5 JC |
3625 | if (vif->mbssid_tx_vif == vif) { |
3626 | /* Trigger ieee80211_csa_finish() on the non-transmitting | |
3627 | * interfaces when channel switch is received on | |
3628 | * transmitting interface | |
3629 | */ | |
3630 | struct ieee80211_sub_if_data *iter; | |
3631 | ||
3632 | list_for_each_entry_rcu(iter, &local->interfaces, list) { | |
3633 | if (!ieee80211_sdata_running(iter)) | |
3634 | continue; | |
73da7d5b | 3635 | |
c9eb90a5 JC |
3636 | if (iter == sdata || iter->vif.mbssid_tx_vif != vif) |
3637 | continue; | |
3638 | ||
d7074be6 JB |
3639 | wiphy_work_queue(iter->local->hw.wiphy, |
3640 | &iter->deflink.csa_finalize_work); | |
c9eb90a5 JC |
3641 | } |
3642 | } | |
04ada859 | 3643 | wiphy_work_queue(local->hw.wiphy, &link_data->csa_finalize_work); |
c9eb90a5 JC |
3644 | |
3645 | rcu_read_unlock(); | |
66e01cf9 LC |
3646 | } |
3647 | EXPORT_SYMBOL(ieee80211_csa_finish); | |
e487eaeb | 3648 | |
6d501764 NE |
3649 | void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx) |
3650 | { | |
3651 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
3652 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
3653 | struct ieee80211_local *local = sdata->local; | |
3654 | ||
570944a0 | 3655 | sdata->csa_blocked_queues = block_tx; |
6d501764 | 3656 | sdata_info(sdata, "channel switch failed, disconnecting\n"); |
4b8d43f1 | 3657 | wiphy_work_queue(local->hw.wiphy, &ifmgd->csa_connection_drop_work); |
6d501764 NE |
3658 | } |
3659 | EXPORT_SYMBOL(ieee80211_channel_switch_disconnect); | |
3660 | ||
a3a637a6 | 3661 | static int ieee80211_set_after_csa_beacon(struct ieee80211_link_data *link_data, |
15ddba5f | 3662 | u64 *changed) |
66e01cf9 | 3663 | { |
a3a637a6 | 3664 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
66199506 | 3665 | int err; |
7578d575 | 3666 | |
cd7760e6 SW |
3667 | switch (sdata->vif.type) { |
3668 | case NL80211_IFTYPE_AP: | |
a3a637a6 | 3669 | if (!link_data->u.ap.next_beacon) |
450c271d LB |
3670 | return -EINVAL; |
3671 | ||
a3a637a6 AKS |
3672 | err = ieee80211_assign_beacon(sdata, link_data, |
3673 | link_data->u.ap.next_beacon, | |
15ddba5f | 3674 | NULL, NULL, changed); |
a3a637a6 | 3675 | ieee80211_free_next_beacon(link_data); |
97518af1 | 3676 | |
cd7760e6 | 3677 | if (err < 0) |
66199506 | 3678 | return err; |
cd7760e6 SW |
3679 | break; |
3680 | case NL80211_IFTYPE_ADHOC: | |
15ddba5f | 3681 | err = ieee80211_ibss_finish_csa(sdata, changed); |
faf046e7 | 3682 | if (err < 0) |
66199506 | 3683 | return err; |
cd7760e6 | 3684 | break; |
b8456a14 CYY |
3685 | #ifdef CONFIG_MAC80211_MESH |
3686 | case NL80211_IFTYPE_MESH_POINT: | |
15ddba5f | 3687 | err = ieee80211_mesh_finish_csa(sdata, changed); |
b8456a14 | 3688 | if (err < 0) |
66199506 | 3689 | return err; |
b8456a14 CYY |
3690 | break; |
3691 | #endif | |
cd7760e6 SW |
3692 | default: |
3693 | WARN_ON(1); | |
66199506 MK |
3694 | return -EINVAL; |
3695 | } | |
3696 | ||
3697 | return 0; | |
3698 | } | |
3699 | ||
a469a593 | 3700 | static int __ieee80211_csa_finalize(struct ieee80211_link_data *link_data) |
66199506 | 3701 | { |
a469a593 | 3702 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
66199506 | 3703 | struct ieee80211_local *local = sdata->local; |
1a96bb4e | 3704 | struct ieee80211_bss_conf *link_conf = link_data->conf; |
15ddba5f | 3705 | u64 changed = 0; |
66199506 MK |
3706 | int err; |
3707 | ||
5435af6e | 3708 | lockdep_assert_wiphy(local->hw.wiphy); |
66199506 | 3709 | |
03078de4 MK |
3710 | /* |
3711 | * using reservation isn't immediate as it may be deferred until later | |
3712 | * with multi-vif. once reservation is complete it will re-schedule the | |
3713 | * work with no reserved_chanctx so verify chandef to check if it | |
3714 | * completed successfully | |
3715 | */ | |
66199506 | 3716 | |
a469a593 | 3717 | if (link_data->reserved_chanctx) { |
03078de4 MK |
3718 | /* |
3719 | * with multi-vif csa driver may call ieee80211_csa_finish() | |
3720 | * many times while waiting for other interfaces to use their | |
3721 | * reservations | |
3722 | */ | |
a469a593 | 3723 | if (link_data->reserved_ready) |
03078de4 MK |
3724 | return 0; |
3725 | ||
1a96bb4e | 3726 | return ieee80211_link_use_reserved_context(link_data); |
cd7760e6 | 3727 | } |
73da7d5b | 3728 | |
1a96bb4e | 3729 | if (!cfg80211_chandef_identical(&link_conf->chanreq.oper, |
6092077a | 3730 | &link_data->csa_chanreq.oper)) |
03078de4 MK |
3731 | return -EINVAL; |
3732 | ||
1a96bb4e | 3733 | link_conf->csa_active = false; |
66199506 | 3734 | |
1a96bb4e | 3735 | err = ieee80211_set_after_csa_beacon(link_data, &changed); |
66199506 | 3736 | if (err) |
cf8767dd | 3737 | return err; |
faf046e7 | 3738 | |
86a8db67 | 3739 | ieee80211_link_info_change_notify(sdata, link_data, changed); |
59af6928 | 3740 | |
570944a0 | 3741 | if (sdata->csa_blocked_queues) { |
a46992b4 LC |
3742 | ieee80211_wake_vif_queues(local, sdata, |
3743 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
570944a0 | 3744 | sdata->csa_blocked_queues = false; |
a46992b4 | 3745 | } |
cf8767dd | 3746 | |
a469a593 | 3747 | err = drv_post_channel_switch(link_data); |
f1d65583 LC |
3748 | if (err) |
3749 | return err; | |
3750 | ||
6092077a | 3751 | cfg80211_ch_switch_notify(sdata->dev, &link_data->csa_chanreq.oper, |
b82730bf | 3752 | link_data->link_id); |
f1d65583 | 3753 | |
cf8767dd MK |
3754 | return 0; |
3755 | } | |
3756 | ||
a469a593 | 3757 | static void ieee80211_csa_finalize(struct ieee80211_link_data *link_data) |
cf8767dd | 3758 | { |
a469a593 EG |
3759 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
3760 | ||
3761 | if (__ieee80211_csa_finalize(link_data)) { | |
1a96bb4e AKS |
3762 | sdata_info(sdata, "failed to finalize CSA on link %d, disconnecting\n", |
3763 | link_data->link_id); | |
cf8767dd MK |
3764 | cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev, |
3765 | GFP_KERNEL); | |
3766 | } | |
66e01cf9 LC |
3767 | } |
3768 | ||
d7074be6 | 3769 | void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work) |
66e01cf9 | 3770 | { |
a469a593 EG |
3771 | struct ieee80211_link_data *link = |
3772 | container_of(work, struct ieee80211_link_data, csa_finalize_work); | |
3773 | struct ieee80211_sub_if_data *sdata = link->sdata; | |
59af6928 | 3774 | struct ieee80211_local *local = sdata->local; |
66e01cf9 | 3775 | |
5435af6e | 3776 | lockdep_assert_wiphy(local->hw.wiphy); |
59af6928 | 3777 | |
66e01cf9 | 3778 | /* AP might have been stopped while waiting for the lock. */ |
a469a593 | 3779 | if (!link->conf->csa_active) |
076fc877 | 3780 | return; |
66e01cf9 LC |
3781 | |
3782 | if (!ieee80211_sdata_running(sdata)) | |
076fc877 | 3783 | return; |
66e01cf9 | 3784 | |
a469a593 | 3785 | ieee80211_csa_finalize(link); |
73da7d5b SW |
3786 | } |
3787 | ||
a3a637a6 | 3788 | static int ieee80211_set_csa_beacon(struct ieee80211_link_data *link_data, |
37fa2bdd | 3789 | struct cfg80211_csa_settings *params, |
15ddba5f | 3790 | u64 *changed) |
73da7d5b | 3791 | { |
a3a637a6 | 3792 | struct ieee80211_sub_if_data *sdata = link_data->sdata; |
af296bdb | 3793 | struct ieee80211_csa_settings csa = {}; |
37fa2bdd | 3794 | int err; |
73da7d5b | 3795 | |
73da7d5b SW |
3796 | switch (sdata->vif.type) { |
3797 | case NL80211_IFTYPE_AP: | |
a3a637a6 | 3798 | link_data->u.ap.next_beacon = |
cd7760e6 | 3799 | cfg80211_beacon_dup(¶ms->beacon_after); |
a3a637a6 | 3800 | if (!link_data->u.ap.next_beacon) |
cd7760e6 SW |
3801 | return -ENOMEM; |
3802 | ||
66e01cf9 LC |
3803 | /* |
3804 | * With a count of 0, we don't have to wait for any | |
3805 | * TBTT before switching, so complete the CSA | |
3806 | * immediately. In theory, with a count == 1 we | |
3807 | * should delay the switch until just before the next | |
3808 | * TBTT, but that would complicate things so we switch | |
3809 | * immediately too. If we would delay the switch | |
3810 | * until the next TBTT, we would have to set the probe | |
3811 | * response here. | |
3812 | * | |
3813 | * TODO: A channel switch with count <= 1 without | |
3814 | * sending a CSA action frame is kind of useless, | |
3815 | * because the clients won't know we're changing | |
3816 | * channels. The action frame must be implemented | |
3817 | * either here or in the userspace. | |
3818 | */ | |
3819 | if (params->count <= 1) | |
3820 | break; | |
3821 | ||
0d06d9ba | 3822 | if ((params->n_counter_offsets_beacon > |
8552a434 | 3823 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM) || |
0d06d9ba | 3824 | (params->n_counter_offsets_presp > |
2b3171c6 | 3825 | IEEE80211_MAX_CNTDWN_COUNTERS_NUM)) { |
a3a637a6 | 3826 | ieee80211_free_next_beacon(link_data); |
0d06d9ba | 3827 | return -EINVAL; |
2b3171c6 | 3828 | } |
9a774c78 | 3829 | |
af296bdb MK |
3830 | csa.counter_offsets_beacon = params->counter_offsets_beacon; |
3831 | csa.counter_offsets_presp = params->counter_offsets_presp; | |
3832 | csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; | |
3833 | csa.n_counter_offsets_presp = params->n_counter_offsets_presp; | |
3834 | csa.count = params->count; | |
9a774c78 | 3835 | |
a3a637a6 | 3836 | err = ieee80211_assign_beacon(sdata, link_data, |
d8675a63 | 3837 | ¶ms->beacon_csa, &csa, |
15ddba5f | 3838 | NULL, changed); |
cd7760e6 | 3839 | if (err < 0) { |
a3a637a6 | 3840 | ieee80211_free_next_beacon(link_data); |
cd7760e6 SW |
3841 | return err; |
3842 | } | |
66e01cf9 | 3843 | |
cd7760e6 SW |
3844 | break; |
3845 | case NL80211_IFTYPE_ADHOC: | |
f276e20b | 3846 | if (!sdata->vif.cfg.ibss_joined) |
cd7760e6 SW |
3847 | return -EINVAL; |
3848 | ||
3849 | if (params->chandef.width != sdata->u.ibss.chandef.width) | |
3850 | return -EINVAL; | |
3851 | ||
3852 | switch (params->chandef.width) { | |
3853 | case NL80211_CHAN_WIDTH_40: | |
3854 | if (cfg80211_get_chandef_type(¶ms->chandef) != | |
3855 | cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) | |
3856 | return -EINVAL; | |
aaaee2d6 | 3857 | break; |
cd7760e6 SW |
3858 | case NL80211_CHAN_WIDTH_5: |
3859 | case NL80211_CHAN_WIDTH_10: | |
3860 | case NL80211_CHAN_WIDTH_20_NOHT: | |
3861 | case NL80211_CHAN_WIDTH_20: | |
3862 | break; | |
3863 | default: | |
3864 | return -EINVAL; | |
3865 | } | |
3866 | ||
3867 | /* changes into another band are not supported */ | |
3868 | if (sdata->u.ibss.chandef.chan->band != | |
3869 | params->chandef.chan->band) | |
3870 | return -EINVAL; | |
3871 | ||
66e01cf9 LC |
3872 | /* see comments in the NL80211_IFTYPE_AP block */ |
3873 | if (params->count > 1) { | |
15ddba5f | 3874 | err = ieee80211_ibss_csa_beacon(sdata, params, changed); |
66e01cf9 LC |
3875 | if (err < 0) |
3876 | return err; | |
66e01cf9 LC |
3877 | } |
3878 | ||
3879 | ieee80211_send_action_csa(sdata, params); | |
3880 | ||
73da7d5b | 3881 | break; |
c6da674a | 3882 | #ifdef CONFIG_MAC80211_MESH |
37fa2bdd MK |
3883 | case NL80211_IFTYPE_MESH_POINT: { |
3884 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
c6da674a | 3885 | |
c6da674a | 3886 | /* changes into another band are not supported */ |
6092077a | 3887 | if (sdata->vif.bss_conf.chanreq.oper.chan->band != |
c6da674a CYY |
3888 | params->chandef.chan->band) |
3889 | return -EINVAL; | |
3890 | ||
c782bf8c | 3891 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { |
0cb4d4dc | 3892 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; |
c782bf8c CYY |
3893 | if (!ifmsh->pre_value) |
3894 | ifmsh->pre_value = 1; | |
3895 | else | |
3896 | ifmsh->pre_value++; | |
3897 | } | |
0cb4d4dc | 3898 | |
66e01cf9 LC |
3899 | /* see comments in the NL80211_IFTYPE_AP block */ |
3900 | if (params->count > 1) { | |
15ddba5f | 3901 | err = ieee80211_mesh_csa_beacon(sdata, params, changed); |
66e01cf9 LC |
3902 | if (err < 0) { |
3903 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; | |
3904 | return err; | |
3905 | } | |
3f718fd8 | 3906 | } |
66e01cf9 LC |
3907 | |
3908 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) | |
3909 | ieee80211_send_action_csa(sdata, params); | |
3910 | ||
c6da674a | 3911 | break; |
37fa2bdd | 3912 | } |
c6da674a | 3913 | #endif |
73da7d5b SW |
3914 | default: |
3915 | return -EOPNOTSUPP; | |
3916 | } | |
3917 | ||
37fa2bdd MK |
3918 | return 0; |
3919 | } | |
3920 | ||
5f9404ab JC |
3921 | static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata) |
3922 | { | |
d0a9123e | 3923 | sdata->vif.bss_conf.color_change_active = false; |
0baef284 | 3924 | |
d9f83f22 | 3925 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab | 3926 | |
91d2b6ee | 3927 | cfg80211_color_change_aborted_notify(sdata->dev, 0); |
5f9404ab JC |
3928 | } |
3929 | ||
f29f58a9 LC |
3930 | static int |
3931 | __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, | |
3932 | struct cfg80211_csa_settings *params) | |
37fa2bdd MK |
3933 | { |
3934 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
6092077a | 3935 | struct ieee80211_chan_req chanreq = { .oper = params->chandef }; |
37fa2bdd | 3936 | struct ieee80211_local *local = sdata->local; |
e6ee3a37 JB |
3937 | struct ieee80211_channel_switch ch_switch = { |
3938 | .link_id = params->link_id, | |
3939 | }; | |
2b32713d | 3940 | struct ieee80211_chanctx_conf *conf; |
37fa2bdd | 3941 | struct ieee80211_chanctx *chanctx; |
1a96bb4e AKS |
3942 | struct ieee80211_bss_conf *link_conf; |
3943 | struct ieee80211_link_data *link_data; | |
15ddba5f | 3944 | u64 changed = 0; |
1a96bb4e | 3945 | u8 link_id = params->link_id; |
b08cc24e | 3946 | int err; |
37fa2bdd | 3947 | |
5435af6e | 3948 | lockdep_assert_wiphy(local->hw.wiphy); |
37fa2bdd MK |
3949 | |
3950 | if (!list_empty(&local->roc_list) || local->scanning) | |
3951 | return -EBUSY; | |
3952 | ||
3953 | if (sdata->wdev.cac_started) | |
3954 | return -EBUSY; | |
3955 | ||
1a96bb4e AKS |
3956 | if (WARN_ON(link_id >= IEEE80211_MLD_MAX_NUM_LINKS)) |
3957 | return -EINVAL; | |
3958 | ||
3959 | link_data = wiphy_dereference(wiphy, sdata->link[link_id]); | |
3960 | if (!link_data) | |
3961 | return -ENOLINK; | |
3962 | ||
3963 | link_conf = link_data->conf; | |
3964 | ||
3965 | if (chanreq.oper.punctured && !link_conf->eht_support) | |
b82730bf JB |
3966 | return -EINVAL; |
3967 | ||
03078de4 | 3968 | /* don't allow another channel switch if one is already active. */ |
1a96bb4e | 3969 | if (link_conf->csa_active) |
03078de4 MK |
3970 | return -EBUSY; |
3971 | ||
1a96bb4e | 3972 | conf = wiphy_dereference(wiphy, link_conf->chanctx_conf); |
2b32713d | 3973 | if (!conf) { |
03078de4 MK |
3974 | err = -EBUSY; |
3975 | goto out; | |
37fa2bdd MK |
3976 | } |
3977 | ||
b6011960 TP |
3978 | if (params->chandef.chan->freq_offset) { |
3979 | /* this may work, but is untested */ | |
3980 | err = -EOPNOTSUPP; | |
3981 | goto out; | |
3982 | } | |
3983 | ||
2b32713d | 3984 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
37fa2bdd | 3985 | |
000baa5d LC |
3986 | ch_switch.timestamp = 0; |
3987 | ch_switch.device_timestamp = 0; | |
3988 | ch_switch.block_tx = params->block_tx; | |
6092077a | 3989 | ch_switch.chandef = chanreq.oper; |
000baa5d LC |
3990 | ch_switch.count = params->count; |
3991 | ||
6d027bcc LC |
3992 | err = drv_pre_channel_switch(sdata, &ch_switch); |
3993 | if (err) | |
3994 | goto out; | |
3995 | ||
1a96bb4e | 3996 | err = ieee80211_link_reserve_chanctx(link_data, &chanreq, |
b4f85443 JB |
3997 | chanctx->mode, |
3998 | params->radar_required); | |
03078de4 MK |
3999 | if (err) |
4000 | goto out; | |
37fa2bdd | 4001 | |
03078de4 MK |
4002 | /* if reservation is invalid then this will fail */ |
4003 | err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0); | |
4004 | if (err) { | |
1a96bb4e | 4005 | ieee80211_link_unreserve_chanctx(link_data); |
03078de4 MK |
4006 | goto out; |
4007 | } | |
37fa2bdd | 4008 | |
5f9404ab | 4009 | /* if there is a color change in progress, abort it */ |
1a96bb4e | 4010 | if (link_conf->color_change_active) |
5f9404ab JC |
4011 | ieee80211_color_change_abort(sdata); |
4012 | ||
1a96bb4e | 4013 | err = ieee80211_set_csa_beacon(link_data, params, &changed); |
03078de4 | 4014 | if (err) { |
1a96bb4e | 4015 | ieee80211_link_unreserve_chanctx(link_data); |
03078de4 MK |
4016 | goto out; |
4017 | } | |
37fa2bdd | 4018 | |
1a96bb4e | 4019 | link_data->csa_chanreq = chanreq; |
1a96bb4e | 4020 | link_conf->csa_active = true; |
73da7d5b | 4021 | |
6f0107d1 JB |
4022 | if (params->block_tx && |
4023 | !ieee80211_hw_check(&local->hw, HANDLES_QUIET_CSA)) { | |
a46992b4 LC |
4024 | ieee80211_stop_vif_queues(local, sdata, |
4025 | IEEE80211_QUEUE_STOP_REASON_CSA); | |
570944a0 | 4026 | sdata->csa_blocked_queues = true; |
6f0107d1 | 4027 | } |
59af6928 | 4028 | |
bfd8403a | 4029 | cfg80211_ch_switch_started_notify(sdata->dev, |
1a96bb4e | 4030 | &link_data->csa_chanreq.oper, 0, |
b82730bf | 4031 | params->count, params->block_tx); |
2f457293 | 4032 | |
66e01cf9 | 4033 | if (changed) { |
1a96bb4e AKS |
4034 | ieee80211_link_info_change_notify(sdata, link_data, changed); |
4035 | drv_channel_switch_beacon(sdata, &link_data->csa_chanreq.oper); | |
66e01cf9 LC |
4036 | } else { |
4037 | /* if the beacon didn't change, we can finalize immediately */ | |
1a96bb4e | 4038 | ieee80211_csa_finalize(link_data); |
66e01cf9 | 4039 | } |
73da7d5b | 4040 | |
03078de4 | 4041 | out: |
03078de4 | 4042 | return err; |
73da7d5b SW |
4043 | } |
4044 | ||
59af6928 MK |
4045 | int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
4046 | struct cfg80211_csa_settings *params) | |
4047 | { | |
4048 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4049 | struct ieee80211_local *local = sdata->local; | |
59af6928 | 4050 | |
0cd8080e | 4051 | lockdep_assert_wiphy(local->hw.wiphy); |
59af6928 | 4052 | |
0cd8080e | 4053 | return __ieee80211_channel_switch(wiphy, dev, params); |
59af6928 MK |
4054 | } |
4055 | ||
a2fcfccb JB |
4056 | u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) |
4057 | { | |
0cd8080e | 4058 | lockdep_assert_wiphy(local->hw.wiphy); |
a2fcfccb JB |
4059 | |
4060 | local->roc_cookie_counter++; | |
4061 | ||
4062 | /* wow, you wrapped 64 bits ... more likely a bug */ | |
4063 | if (WARN_ON(local->roc_cookie_counter == 0)) | |
4064 | local->roc_cookie_counter++; | |
4065 | ||
4066 | return local->roc_cookie_counter; | |
4067 | } | |
4068 | ||
5ee00dbd JB |
4069 | int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, |
4070 | u64 *cookie, gfp_t gfp) | |
3b79af97 JB |
4071 | { |
4072 | unsigned long spin_flags; | |
4073 | struct sk_buff *ack_skb; | |
4074 | int id; | |
4075 | ||
4076 | ack_skb = skb_copy(skb, gfp); | |
4077 | if (!ack_skb) | |
5ee00dbd | 4078 | return -ENOMEM; |
3b79af97 JB |
4079 | |
4080 | spin_lock_irqsave(&local->ack_status_lock, spin_flags); | |
4081 | id = idr_alloc(&local->ack_status_frames, ack_skb, | |
f2b18bac | 4082 | 1, 0x2000, GFP_ATOMIC); |
3b79af97 JB |
4083 | spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); |
4084 | ||
4085 | if (id < 0) { | |
4086 | kfree_skb(ack_skb); | |
5ee00dbd | 4087 | return -ENOMEM; |
3b79af97 JB |
4088 | } |
4089 | ||
f498f6ab JB |
4090 | IEEE80211_SKB_CB(skb)->status_data_idr = 1; |
4091 | IEEE80211_SKB_CB(skb)->status_data = id; | |
3b79af97 JB |
4092 | |
4093 | *cookie = ieee80211_mgmt_tx_cookie(local); | |
4094 | IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; | |
4095 | ||
5ee00dbd | 4096 | return 0; |
3b79af97 JB |
4097 | } |
4098 | ||
6cd536fe JB |
4099 | static void |
4100 | ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy, | |
71bbc994 | 4101 | struct wireless_dev *wdev, |
6cd536fe | 4102 | struct mgmt_frame_regs *upd) |
7be5086d JB |
4103 | { |
4104 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1b09b556 | 4105 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
6cd536fe | 4106 | u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4); |
873b1cf6 | 4107 | u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4); |
6cd536fe | 4108 | bool global_change, intf_change; |
7be5086d | 4109 | |
6cd536fe | 4110 | global_change = |
873b1cf6 JM |
4111 | (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) || |
4112 | (local->rx_mcast_action_reg != | |
4113 | !!(upd->global_mcast_stypes & action_mask)); | |
6cd536fe | 4114 | local->probe_req_reg = upd->global_stypes & preq_mask; |
873b1cf6 | 4115 | local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask; |
1b09b556 | 4116 | |
873b1cf6 JM |
4117 | intf_change = (sdata->vif.probe_req_reg != |
4118 | !!(upd->interface_stypes & preq_mask)) || | |
4119 | (sdata->vif.rx_mcast_action_reg != | |
4120 | !!(upd->interface_mcast_stypes & action_mask)); | |
6cd536fe | 4121 | sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask; |
873b1cf6 JM |
4122 | sdata->vif.rx_mcast_action_reg = |
4123 | upd->interface_mcast_stypes & action_mask; | |
7be5086d | 4124 | |
6cd536fe JB |
4125 | if (!local->open_count) |
4126 | return; | |
35f5149e | 4127 | |
6cd536fe JB |
4128 | if (intf_change && ieee80211_sdata_running(sdata)) |
4129 | drv_config_iface_filter(local, sdata, | |
4130 | sdata->vif.probe_req_reg ? | |
4131 | FIF_PROBE_REQ : 0, | |
4132 | FIF_PROBE_REQ); | |
1b09b556 | 4133 | |
6cd536fe | 4134 | if (global_change) |
1b09b556 | 4135 | ieee80211_configure_filter(local); |
7be5086d JB |
4136 | } |
4137 | ||
15d96753 BR |
4138 | static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) |
4139 | { | |
4140 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2bf57b00 | 4141 | int ret; |
15d96753 BR |
4142 | |
4143 | if (local->started) | |
4144 | return -EOPNOTSUPP; | |
4145 | ||
2bf57b00 EG |
4146 | ret = drv_set_antenna(local, tx_ant, rx_ant); |
4147 | if (ret) | |
4148 | return ret; | |
4149 | ||
4150 | local->rx_chains = hweight8(rx_ant); | |
4151 | return 0; | |
15d96753 BR |
4152 | } |
4153 | ||
4154 | static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) | |
4155 | { | |
4156 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4157 | ||
4158 | return drv_get_antenna(local, tx_ant, rx_ant); | |
4159 | } | |
4160 | ||
c68f4b89 JB |
4161 | static int ieee80211_set_rekey_data(struct wiphy *wiphy, |
4162 | struct net_device *dev, | |
4163 | struct cfg80211_gtk_rekey_data *data) | |
4164 | { | |
4165 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4166 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4167 | ||
4168 | if (!local->ops->set_rekey_data) | |
4169 | return -EOPNOTSUPP; | |
4170 | ||
4171 | drv_set_rekey_data(local, sdata, data); | |
4172 | ||
4173 | return 0; | |
4174 | } | |
4175 | ||
06500736 JB |
4176 | static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, |
4177 | const u8 *peer, u64 *cookie) | |
4178 | { | |
4179 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4180 | struct ieee80211_local *local = sdata->local; | |
4181 | struct ieee80211_qos_hdr *nullfunc; | |
5ee00dbd | 4182 | struct sk_buff *skb; |
06500736 JB |
4183 | int size = sizeof(*nullfunc); |
4184 | __le16 fc; | |
4185 | bool qos; | |
4186 | struct ieee80211_tx_info *info; | |
4187 | struct sta_info *sta; | |
55de908a | 4188 | struct ieee80211_chanctx_conf *chanctx_conf; |
57fbcce3 | 4189 | enum nl80211_band band; |
3b79af97 JB |
4190 | int ret; |
4191 | ||
4192 | /* the lock is needed to assign the cookie later */ | |
0cd8080e | 4193 | lockdep_assert_wiphy(local->hw.wiphy); |
06500736 JB |
4194 | |
4195 | rcu_read_lock(); | |
67dfa589 JB |
4196 | sta = sta_info_get_bss(sdata, peer); |
4197 | if (!sta) { | |
4198 | ret = -ENOLINK; | |
4199 | goto unlock; | |
4200 | } | |
4201 | ||
4202 | qos = sta->sta.wme; | |
4203 | ||
d0a9123e | 4204 | chanctx_conf = rcu_dereference(sdata->vif.bss_conf.chanctx_conf); |
55de908a | 4205 | if (WARN_ON(!chanctx_conf)) { |
3b79af97 JB |
4206 | ret = -EINVAL; |
4207 | goto unlock; | |
55de908a | 4208 | } |
4bf88530 | 4209 | band = chanctx_conf->def.chan->band; |
06500736 JB |
4210 | |
4211 | if (qos) { | |
4212 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
4213 | IEEE80211_STYPE_QOS_NULLFUNC | | |
4214 | IEEE80211_FCTL_FROMDS); | |
4215 | } else { | |
4216 | size -= 2; | |
4217 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
4218 | IEEE80211_STYPE_NULLFUNC | | |
4219 | IEEE80211_FCTL_FROMDS); | |
4220 | } | |
4221 | ||
4222 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); | |
55de908a | 4223 | if (!skb) { |
3b79af97 JB |
4224 | ret = -ENOMEM; |
4225 | goto unlock; | |
55de908a | 4226 | } |
06500736 JB |
4227 | |
4228 | skb->dev = dev; | |
4229 | ||
4230 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
4231 | ||
4df864c1 | 4232 | nullfunc = skb_put(skb, size); |
06500736 JB |
4233 | nullfunc->frame_control = fc; |
4234 | nullfunc->duration_id = 0; | |
4235 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); | |
4236 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | |
4237 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); | |
4238 | nullfunc->seq_ctrl = 0; | |
4239 | ||
4240 | info = IEEE80211_SKB_CB(skb); | |
4241 | ||
4242 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | | |
4243 | IEEE80211_TX_INTFL_NL80211_FRAME_TX; | |
73c4e195 | 4244 | info->band = band; |
06500736 JB |
4245 | |
4246 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); | |
4247 | skb->priority = 7; | |
4248 | if (qos) | |
4249 | nullfunc->qos_ctrl = cpu_to_le16(7); | |
4250 | ||
5ee00dbd JB |
4251 | ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); |
4252 | if (ret) { | |
3b79af97 | 4253 | kfree_skb(skb); |
3b79af97 JB |
4254 | goto unlock; |
4255 | } | |
4256 | ||
06500736 | 4257 | local_bh_disable(); |
08aca29a | 4258 | ieee80211_xmit(sdata, sta, skb); |
06500736 | 4259 | local_bh_enable(); |
3b79af97 JB |
4260 | |
4261 | ret = 0; | |
4262 | unlock: | |
55de908a | 4263 | rcu_read_unlock(); |
06500736 | 4264 | |
3b79af97 | 4265 | return ret; |
06500736 JB |
4266 | } |
4267 | ||
683b6d3b JB |
4268 | static int ieee80211_cfg_get_channel(struct wiphy *wiphy, |
4269 | struct wireless_dev *wdev, | |
7b0a0e3c | 4270 | unsigned int link_id, |
683b6d3b | 4271 | struct cfg80211_chan_def *chandef) |
5b7ccaf3 | 4272 | { |
55de908a | 4273 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
cb601ffa | 4274 | struct ieee80211_local *local = wiphy_priv(wiphy); |
55de908a | 4275 | struct ieee80211_chanctx_conf *chanctx_conf; |
d8675a63 | 4276 | struct ieee80211_link_data *link; |
683b6d3b | 4277 | int ret = -ENODATA; |
55de908a JB |
4278 | |
4279 | rcu_read_lock(); | |
d8675a63 JB |
4280 | link = rcu_dereference(sdata->link[link_id]); |
4281 | if (!link) { | |
4282 | ret = -ENOLINK; | |
4283 | goto out; | |
4284 | } | |
4285 | ||
4286 | chanctx_conf = rcu_dereference(link->conf->chanctx_conf); | |
feda3027 | 4287 | if (chanctx_conf) { |
6092077a | 4288 | *chandef = link->conf->chanreq.oper; |
feda3027 JB |
4289 | ret = 0; |
4290 | } else if (local->open_count > 0 && | |
4291 | local->open_count == local->monitors && | |
4292 | sdata->vif.type == NL80211_IFTYPE_MONITOR) { | |
6092077a | 4293 | *chandef = local->monitor_chanreq.oper; |
683b6d3b | 4294 | ret = 0; |
55de908a | 4295 | } |
d8675a63 | 4296 | out: |
55de908a | 4297 | rcu_read_unlock(); |
5b7ccaf3 | 4298 | |
683b6d3b | 4299 | return ret; |
5b7ccaf3 JB |
4300 | } |
4301 | ||
6d52563f JB |
4302 | #ifdef CONFIG_PM |
4303 | static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) | |
4304 | { | |
4305 | drv_set_wakeup(wiphy_priv(wiphy), enabled); | |
4306 | } | |
4307 | #endif | |
4308 | ||
32db6b54 KP |
4309 | static int ieee80211_set_qos_map(struct wiphy *wiphy, |
4310 | struct net_device *dev, | |
4311 | struct cfg80211_qos_map *qos_map) | |
4312 | { | |
4313 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4314 | struct mac80211_qos_map *new_qos_map, *old_qos_map; | |
4315 | ||
4316 | if (qos_map) { | |
4317 | new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL); | |
4318 | if (!new_qos_map) | |
4319 | return -ENOMEM; | |
4320 | memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); | |
4321 | } else { | |
4322 | /* A NULL qos_map was passed to disable QoS mapping */ | |
4323 | new_qos_map = NULL; | |
4324 | } | |
4325 | ||
194ff52d | 4326 | old_qos_map = sdata_dereference(sdata->qos_map, sdata); |
32db6b54 KP |
4327 | rcu_assign_pointer(sdata->qos_map, new_qos_map); |
4328 | if (old_qos_map) | |
4329 | kfree_rcu(old_qos_map, rcu_head); | |
4330 | ||
4331 | return 0; | |
4332 | } | |
4333 | ||
3b1700bd JM |
4334 | static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, |
4335 | struct net_device *dev, | |
7b0a0e3c | 4336 | unsigned int link_id, |
3b1700bd JM |
4337 | struct cfg80211_chan_def *chandef) |
4338 | { | |
4339 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
d8675a63 | 4340 | struct ieee80211_link_data *link; |
6092077a | 4341 | struct ieee80211_chan_req chanreq = { .oper = *chandef }; |
3b1700bd | 4342 | int ret; |
aa87cd8b | 4343 | u64 changed = 0; |
3b1700bd | 4344 | |
d8675a63 JB |
4345 | link = sdata_dereference(sdata->link[link_id], sdata); |
4346 | ||
6092077a | 4347 | ret = ieee80211_link_change_chanreq(link, &chanreq, &changed); |
3b1700bd | 4348 | if (ret == 0) |
d8675a63 | 4349 | ieee80211_link_info_change_notify(sdata, link, changed); |
3b1700bd JM |
4350 | |
4351 | return ret; | |
4352 | } | |
4353 | ||
02219b3a JB |
4354 | static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
4355 | u8 tsid, const u8 *peer, u8 up, | |
4356 | u16 admitted_time) | |
4357 | { | |
4358 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4359 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
4360 | int ac = ieee802_1d_to_ac[up]; | |
4361 | ||
4362 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
4363 | return -EOPNOTSUPP; | |
4364 | ||
4365 | if (!(sdata->wmm_acm & BIT(up))) | |
4366 | return -EINVAL; | |
4367 | ||
4368 | if (ifmgd->tx_tspec[ac].admitted_time) | |
4369 | return -EBUSY; | |
4370 | ||
4371 | if (admitted_time) { | |
4372 | ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; | |
4373 | ifmgd->tx_tspec[ac].tsid = tsid; | |
4374 | ifmgd->tx_tspec[ac].up = up; | |
4375 | } | |
4376 | ||
4377 | return 0; | |
4378 | } | |
4379 | ||
4380 | static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, | |
4381 | u8 tsid, const u8 *peer) | |
4382 | { | |
4383 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4384 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; | |
4385 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4386 | int ac; | |
4387 | ||
4388 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | |
4389 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; | |
4390 | ||
4391 | /* skip unused entries */ | |
4392 | if (!tx_tspec->admitted_time) | |
4393 | continue; | |
4394 | ||
4395 | if (tx_tspec->tsid != tsid) | |
4396 | continue; | |
4397 | ||
4398 | /* due to this new packets will be reassigned to non-ACM ACs */ | |
4399 | tx_tspec->up = -1; | |
4400 | ||
4401 | /* Make sure that all packets have been sent to avoid to | |
4402 | * restore the QoS params on packets that are still on the | |
4403 | * queues. | |
4404 | */ | |
4405 | synchronize_net(); | |
3b24f4c6 | 4406 | ieee80211_flush_queues(local, sdata, false); |
02219b3a JB |
4407 | |
4408 | /* restore the normal QoS parameters | |
4409 | * (unconditionally to avoid races) | |
4410 | */ | |
4411 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; | |
4412 | tx_tspec->downgraded = false; | |
4413 | ieee80211_sta_handle_tspec_ac_params(sdata); | |
4414 | ||
4415 | /* finally clear all the data */ | |
4416 | memset(tx_tspec, 0, sizeof(*tx_tspec)); | |
4417 | ||
4418 | return 0; | |
4419 | } | |
4420 | ||
4421 | return -ENOENT; | |
4422 | } | |
4423 | ||
167e33f4 AB |
4424 | void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, |
4425 | u8 inst_id, | |
4426 | enum nl80211_nan_func_term_reason reason, | |
4427 | gfp_t gfp) | |
4428 | { | |
4429 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4430 | struct cfg80211_nan_func *func; | |
4431 | u64 cookie; | |
4432 | ||
4433 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) | |
4434 | return; | |
4435 | ||
4436 | spin_lock_bh(&sdata->u.nan.func_lock); | |
4437 | ||
4438 | func = idr_find(&sdata->u.nan.function_inst_ids, inst_id); | |
4439 | if (WARN_ON(!func)) { | |
4440 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4441 | return; | |
4442 | } | |
4443 | ||
4444 | cookie = func->cookie; | |
4445 | idr_remove(&sdata->u.nan.function_inst_ids, inst_id); | |
4446 | ||
4447 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4448 | ||
4449 | cfg80211_free_nan_func(func); | |
4450 | ||
4451 | cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, | |
4452 | reason, cookie, gfp); | |
4453 | } | |
4454 | EXPORT_SYMBOL(ieee80211_nan_func_terminated); | |
4455 | ||
92bc43bc AB |
4456 | void ieee80211_nan_func_match(struct ieee80211_vif *vif, |
4457 | struct cfg80211_nan_match_params *match, | |
4458 | gfp_t gfp) | |
4459 | { | |
4460 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4461 | struct cfg80211_nan_func *func; | |
4462 | ||
4463 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) | |
4464 | return; | |
4465 | ||
4466 | spin_lock_bh(&sdata->u.nan.func_lock); | |
4467 | ||
4468 | func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id); | |
4469 | if (WARN_ON(!func)) { | |
4470 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4471 | return; | |
4472 | } | |
4473 | match->cookie = func->cookie; | |
4474 | ||
4475 | spin_unlock_bh(&sdata->u.nan.func_lock); | |
4476 | ||
4477 | cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); | |
4478 | } | |
4479 | EXPORT_SYMBOL(ieee80211_nan_func_match); | |
4480 | ||
ebceec86 MB |
4481 | static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, |
4482 | struct net_device *dev, | |
4483 | const bool enabled) | |
4484 | { | |
4485 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4486 | ||
4487 | sdata->u.ap.multicast_to_unicast = enabled; | |
4488 | ||
4489 | return 0; | |
4490 | } | |
4491 | ||
2fe4a29a THJ |
4492 | void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, |
4493 | struct txq_info *txqi) | |
4494 | { | |
4495 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { | |
4496 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); | |
4497 | txqstats->backlog_bytes = txqi->tin.backlog_bytes; | |
4498 | } | |
4499 | ||
4500 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { | |
4501 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); | |
4502 | txqstats->backlog_packets = txqi->tin.backlog_packets; | |
4503 | } | |
4504 | ||
4505 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { | |
4506 | txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); | |
4507 | txqstats->flows = txqi->tin.flows; | |
4508 | } | |
4509 | ||
4510 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { | |
4511 | txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); | |
4512 | txqstats->drops = txqi->cstats.drop_count; | |
4513 | } | |
4514 | ||
4515 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { | |
4516 | txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); | |
4517 | txqstats->ecn_marks = txqi->cstats.ecn_mark; | |
4518 | } | |
4519 | ||
4520 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { | |
4521 | txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); | |
4522 | txqstats->overlimit = txqi->tin.overlimit; | |
4523 | } | |
4524 | ||
4525 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { | |
4526 | txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); | |
4527 | txqstats->collisions = txqi->tin.collisions; | |
4528 | } | |
4529 | ||
4530 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { | |
4531 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); | |
4532 | txqstats->tx_bytes = txqi->tin.tx_bytes; | |
4533 | } | |
4534 | ||
4535 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { | |
4536 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); | |
4537 | txqstats->tx_packets = txqi->tin.tx_packets; | |
4538 | } | |
4539 | } | |
4540 | ||
4541 | static int ieee80211_get_txq_stats(struct wiphy *wiphy, | |
4542 | struct wireless_dev *wdev, | |
4543 | struct cfg80211_txq_stats *txqstats) | |
4544 | { | |
4545 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4546 | struct ieee80211_sub_if_data *sdata; | |
4547 | int ret = 0; | |
4548 | ||
2fe4a29a THJ |
4549 | spin_lock_bh(&local->fq.lock); |
4550 | rcu_read_lock(); | |
4551 | ||
4552 | if (wdev) { | |
4553 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
4554 | if (!sdata->vif.txq) { | |
4555 | ret = 1; | |
4556 | goto out; | |
4557 | } | |
4558 | ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); | |
4559 | } else { | |
4560 | /* phy stats */ | |
4561 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | | |
4562 | BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | | |
4563 | BIT(NL80211_TXQ_STATS_OVERLIMIT) | | |
4564 | BIT(NL80211_TXQ_STATS_OVERMEMORY) | | |
4565 | BIT(NL80211_TXQ_STATS_COLLISIONS) | | |
4566 | BIT(NL80211_TXQ_STATS_MAX_FLOWS); | |
4567 | txqstats->backlog_packets = local->fq.backlog; | |
4568 | txqstats->backlog_bytes = local->fq.memory_usage; | |
4569 | txqstats->overlimit = local->fq.overlimit; | |
4570 | txqstats->overmemory = local->fq.overmemory; | |
4571 | txqstats->collisions = local->fq.collisions; | |
4572 | txqstats->max_flows = local->fq.flows_cnt; | |
4573 | } | |
4574 | ||
4575 | out: | |
4576 | rcu_read_unlock(); | |
4577 | spin_unlock_bh(&local->fq.lock); | |
4578 | ||
4579 | return ret; | |
4580 | } | |
4581 | ||
bc847970 PKC |
4582 | static int |
4583 | ieee80211_get_ftm_responder_stats(struct wiphy *wiphy, | |
4584 | struct net_device *dev, | |
4585 | struct cfg80211_ftm_responder_stats *ftm_stats) | |
4586 | { | |
4587 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4588 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4589 | ||
4590 | return drv_get_ftm_responder_stats(local, sdata, ftm_stats); | |
4591 | } | |
4592 | ||
cee7013b JB |
4593 | static int |
4594 | ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, | |
4595 | struct cfg80211_pmsr_request *request) | |
4596 | { | |
4597 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4598 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); | |
4599 | ||
4600 | return drv_start_pmsr(local, sdata, request); | |
4601 | } | |
4602 | ||
4603 | static void | |
4604 | ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev, | |
4605 | struct cfg80211_pmsr_request *request) | |
4606 | { | |
4607 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4608 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev); | |
4609 | ||
4610 | return drv_abort_pmsr(local, sdata, request); | |
4611 | } | |
4612 | ||
370f51d5 T |
4613 | static int ieee80211_set_tid_config(struct wiphy *wiphy, |
4614 | struct net_device *dev, | |
4615 | struct cfg80211_tid_config *tid_conf) | |
4616 | { | |
4617 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4618 | struct sta_info *sta; | |
4d3acf43 JB |
4619 | |
4620 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
370f51d5 T |
4621 | |
4622 | if (!sdata->local->ops->set_tid_config) | |
4623 | return -EOPNOTSUPP; | |
4624 | ||
4625 | if (!tid_conf->peer) | |
4626 | return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf); | |
4627 | ||
370f51d5 | 4628 | sta = sta_info_get_bss(sdata, tid_conf->peer); |
4d3acf43 | 4629 | if (!sta) |
370f51d5 | 4630 | return -ENOENT; |
370f51d5 | 4631 | |
4d3acf43 | 4632 | return drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf); |
370f51d5 T |
4633 | } |
4634 | ||
4635 | static int ieee80211_reset_tid_config(struct wiphy *wiphy, | |
4636 | struct net_device *dev, | |
60c2ef0e | 4637 | const u8 *peer, u8 tids) |
370f51d5 T |
4638 | { |
4639 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4640 | struct sta_info *sta; | |
4d3acf43 JB |
4641 | |
4642 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
370f51d5 T |
4643 | |
4644 | if (!sdata->local->ops->reset_tid_config) | |
4645 | return -EOPNOTSUPP; | |
4646 | ||
4647 | if (!peer) | |
60c2ef0e | 4648 | return drv_reset_tid_config(sdata->local, sdata, NULL, tids); |
370f51d5 | 4649 | |
370f51d5 | 4650 | sta = sta_info_get_bss(sdata, peer); |
4d3acf43 | 4651 | if (!sta) |
370f51d5 | 4652 | return -ENOENT; |
370f51d5 | 4653 | |
4d3acf43 | 4654 | return drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids); |
370f51d5 T |
4655 | } |
4656 | ||
c534e093 CH |
4657 | static int ieee80211_set_sar_specs(struct wiphy *wiphy, |
4658 | struct cfg80211_sar_specs *sar) | |
4659 | { | |
4660 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4661 | ||
4662 | if (!local->ops->set_sar_specs) | |
4663 | return -EOPNOTSUPP; | |
4664 | ||
4665 | return local->ops->set_sar_specs(&local->hw, sar); | |
4666 | } | |
4667 | ||
5f9404ab JC |
4668 | static int |
4669 | ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata, | |
15ddba5f | 4670 | u64 *changed) |
5f9404ab JC |
4671 | { |
4672 | switch (sdata->vif.type) { | |
4673 | case NL80211_IFTYPE_AP: { | |
4674 | int ret; | |
4675 | ||
bfd8403a | 4676 | if (!sdata->deflink.u.ap.next_beacon) |
450c271d LB |
4677 | return -EINVAL; |
4678 | ||
d8675a63 | 4679 | ret = ieee80211_assign_beacon(sdata, &sdata->deflink, |
bfd8403a | 4680 | sdata->deflink.u.ap.next_beacon, |
15ddba5f | 4681 | NULL, NULL, changed); |
d9f83f22 | 4682 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab JC |
4683 | |
4684 | if (ret < 0) | |
4685 | return ret; | |
4686 | ||
5f9404ab JC |
4687 | break; |
4688 | } | |
4689 | default: | |
4690 | WARN_ON_ONCE(1); | |
4691 | return -EINVAL; | |
4692 | } | |
4693 | ||
4694 | return 0; | |
4695 | } | |
4696 | ||
4697 | static int | |
4698 | ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata, | |
4699 | struct cfg80211_color_change_settings *params, | |
15ddba5f | 4700 | u64 *changed) |
5f9404ab JC |
4701 | { |
4702 | struct ieee80211_color_change_settings color_change = {}; | |
4703 | int err; | |
4704 | ||
4705 | switch (sdata->vif.type) { | |
4706 | case NL80211_IFTYPE_AP: | |
bfd8403a | 4707 | sdata->deflink.u.ap.next_beacon = |
5f9404ab | 4708 | cfg80211_beacon_dup(¶ms->beacon_next); |
bfd8403a | 4709 | if (!sdata->deflink.u.ap.next_beacon) |
5f9404ab JC |
4710 | return -ENOMEM; |
4711 | ||
4712 | if (params->count <= 1) | |
4713 | break; | |
4714 | ||
4715 | color_change.counter_offset_beacon = | |
4716 | params->counter_offset_beacon; | |
4717 | color_change.counter_offset_presp = | |
4718 | params->counter_offset_presp; | |
4719 | color_change.count = params->count; | |
4720 | ||
d8675a63 JB |
4721 | err = ieee80211_assign_beacon(sdata, &sdata->deflink, |
4722 | ¶ms->beacon_color_change, | |
15ddba5f | 4723 | NULL, &color_change, changed); |
5f9404ab | 4724 | if (err < 0) { |
d9f83f22 | 4725 | ieee80211_free_next_beacon(&sdata->deflink); |
5f9404ab JC |
4726 | return err; |
4727 | } | |
5f9404ab JC |
4728 | break; |
4729 | default: | |
4730 | return -EOPNOTSUPP; | |
4731 | } | |
4732 | ||
4733 | return 0; | |
4734 | } | |
4735 | ||
4736 | static void | |
4737 | ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata, | |
15ddba5f | 4738 | u8 color, int enable, u64 changed) |
5f9404ab | 4739 | { |
be0df01d JB |
4740 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
4741 | ||
5f9404ab JC |
4742 | sdata->vif.bss_conf.he_bss_color.color = color; |
4743 | sdata->vif.bss_conf.he_bss_color.enabled = enable; | |
4744 | changed |= BSS_CHANGED_HE_BSS_COLOR; | |
4745 | ||
d8675a63 | 4746 | ieee80211_link_info_change_notify(sdata, &sdata->deflink, changed); |
eb87d3e0 JC |
4747 | |
4748 | if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) { | |
4749 | struct ieee80211_sub_if_data *child; | |
4750 | ||
eb87d3e0 JC |
4751 | list_for_each_entry(child, &sdata->local->interfaces, list) { |
4752 | if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) { | |
4753 | child->vif.bss_conf.he_bss_color.color = color; | |
4754 | child->vif.bss_conf.he_bss_color.enabled = enable; | |
d8675a63 JB |
4755 | ieee80211_link_info_change_notify(child, |
4756 | &child->deflink, | |
7b7090b4 | 4757 | BSS_CHANGED_HE_BSS_COLOR); |
eb87d3e0 JC |
4758 | } |
4759 | } | |
eb87d3e0 | 4760 | } |
5f9404ab JC |
4761 | } |
4762 | ||
4763 | static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata) | |
4764 | { | |
4765 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 4766 | u64 changed = 0; |
5f9404ab JC |
4767 | int err; |
4768 | ||
0cd8080e | 4769 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab | 4770 | |
d0a9123e | 4771 | sdata->vif.bss_conf.color_change_active = false; |
5f9404ab JC |
4772 | |
4773 | err = ieee80211_set_after_color_change_beacon(sdata, &changed); | |
4774 | if (err) { | |
91d2b6ee | 4775 | cfg80211_color_change_aborted_notify(sdata->dev, 0); |
5f9404ab JC |
4776 | return err; |
4777 | } | |
4778 | ||
4779 | ieee80211_color_change_bss_config_notify(sdata, | |
d0a9123e | 4780 | sdata->vif.bss_conf.color_change_color, |
5f9404ab | 4781 | 1, changed); |
91d2b6ee | 4782 | cfg80211_color_change_notify(sdata->dev, 0); |
5f9404ab JC |
4783 | |
4784 | return 0; | |
4785 | } | |
4786 | ||
b38579ae JB |
4787 | void ieee80211_color_change_finalize_work(struct wiphy *wiphy, |
4788 | struct wiphy_work *work) | |
5f9404ab JC |
4789 | { |
4790 | struct ieee80211_sub_if_data *sdata = | |
4791 | container_of(work, struct ieee80211_sub_if_data, | |
bfd8403a | 4792 | deflink.color_change_finalize_work); |
5f9404ab JC |
4793 | struct ieee80211_local *local = sdata->local; |
4794 | ||
0cd8080e | 4795 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab JC |
4796 | |
4797 | /* AP might have been stopped while waiting for the lock. */ | |
d0a9123e | 4798 | if (!sdata->vif.bss_conf.color_change_active) |
076fc877 | 4799 | return; |
5f9404ab JC |
4800 | |
4801 | if (!ieee80211_sdata_running(sdata)) | |
076fc877 | 4802 | return; |
5f9404ab JC |
4803 | |
4804 | ieee80211_color_change_finalize(sdata); | |
5f9404ab JC |
4805 | } |
4806 | ||
92881884 LB |
4807 | void ieee80211_color_collision_detection_work(struct work_struct *work) |
4808 | { | |
4809 | struct delayed_work *delayed_work = to_delayed_work(work); | |
4810 | struct ieee80211_link_data *link = | |
4811 | container_of(delayed_work, struct ieee80211_link_data, | |
4812 | color_collision_detect_work); | |
4813 | struct ieee80211_sub_if_data *sdata = link->sdata; | |
4814 | ||
91d2b6ee | 4815 | cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap, 0); |
92881884 LB |
4816 | } |
4817 | ||
5f9404ab JC |
4818 | void ieee80211_color_change_finish(struct ieee80211_vif *vif) |
4819 | { | |
4820 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
4821 | ||
b38579ae JB |
4822 | wiphy_work_queue(sdata->local->hw.wiphy, |
4823 | &sdata->deflink.color_change_finalize_work); | |
5f9404ab JC |
4824 | } |
4825 | EXPORT_SYMBOL_GPL(ieee80211_color_change_finish); | |
4826 | ||
4827 | void | |
82253dda | 4828 | ieee80211_obss_color_collision_notify(struct ieee80211_vif *vif, |
6f656131 | 4829 | u64 color_bitmap) |
5f9404ab JC |
4830 | { |
4831 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); | |
92881884 | 4832 | struct ieee80211_link_data *link = &sdata->deflink; |
5f9404ab | 4833 | |
d0a9123e | 4834 | if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) |
5f9404ab JC |
4835 | return; |
4836 | ||
92881884 LB |
4837 | if (delayed_work_pending(&link->color_collision_detect_work)) |
4838 | return; | |
4839 | ||
4840 | link->color_bitmap = color_bitmap; | |
4841 | /* queue the color collision detection event every 500 ms in order to | |
4842 | * avoid sending too much netlink messages to userspace. | |
4843 | */ | |
4844 | ieee80211_queue_delayed_work(&sdata->local->hw, | |
4845 | &link->color_collision_detect_work, | |
4846 | msecs_to_jiffies(500)); | |
5f9404ab | 4847 | } |
82253dda | 4848 | EXPORT_SYMBOL_GPL(ieee80211_obss_color_collision_notify); |
5f9404ab JC |
4849 | |
4850 | static int | |
4851 | ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev, | |
4852 | struct cfg80211_color_change_settings *params) | |
4853 | { | |
4854 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4855 | struct ieee80211_local *local = sdata->local; | |
15ddba5f | 4856 | u64 changed = 0; |
5f9404ab JC |
4857 | int err; |
4858 | ||
0cd8080e | 4859 | lockdep_assert_wiphy(local->hw.wiphy); |
5f9404ab | 4860 | |
eb87d3e0 JC |
4861 | if (sdata->vif.bss_conf.nontransmitted) |
4862 | return -EINVAL; | |
4863 | ||
5f9404ab JC |
4864 | /* don't allow another color change if one is already active or if csa |
4865 | * is active | |
4866 | */ | |
d0a9123e | 4867 | if (sdata->vif.bss_conf.color_change_active || sdata->vif.bss_conf.csa_active) { |
5f9404ab JC |
4868 | err = -EBUSY; |
4869 | goto out; | |
4870 | } | |
4871 | ||
4872 | err = ieee80211_set_color_change_beacon(sdata, params, &changed); | |
4873 | if (err) | |
4874 | goto out; | |
4875 | ||
d0a9123e JB |
4876 | sdata->vif.bss_conf.color_change_active = true; |
4877 | sdata->vif.bss_conf.color_change_color = params->color; | |
5f9404ab | 4878 | |
91d2b6ee | 4879 | cfg80211_color_change_started_notify(sdata->dev, params->count, 0); |
5f9404ab JC |
4880 | |
4881 | if (changed) | |
4882 | ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed); | |
4883 | else | |
4884 | /* if the beacon didn't change, we can finalize immediately */ | |
4885 | ieee80211_color_change_finalize(sdata); | |
4886 | ||
4887 | out: | |
5f9404ab JC |
4888 | |
4889 | return err; | |
4890 | } | |
4891 | ||
237337c2 | 4892 | static int |
a95bfb87 LB |
4893 | ieee80211_set_radar_background(struct wiphy *wiphy, |
4894 | struct cfg80211_chan_def *chandef) | |
237337c2 LB |
4895 | { |
4896 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
4897 | ||
a95bfb87 | 4898 | if (!local->ops->set_radar_background) |
237337c2 LB |
4899 | return -EOPNOTSUPP; |
4900 | ||
a95bfb87 | 4901 | return local->ops->set_radar_background(&local->hw, chandef); |
237337c2 LB |
4902 | } |
4903 | ||
0d8c4a3c JB |
4904 | static int ieee80211_add_intf_link(struct wiphy *wiphy, |
4905 | struct wireless_dev *wdev, | |
4906 | unsigned int link_id) | |
4907 | { | |
4908 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
0cd8080e JB |
4909 | |
4910 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
0d8c4a3c | 4911 | |
90703ba9 JB |
4912 | if (wdev->use_4addr) |
4913 | return -EOPNOTSUPP; | |
4914 | ||
0cd8080e | 4915 | return ieee80211_vif_set_links(sdata, wdev->valid_links, 0); |
0d8c4a3c JB |
4916 | } |
4917 | ||
4918 | static void ieee80211_del_intf_link(struct wiphy *wiphy, | |
4919 | struct wireless_dev *wdev, | |
4920 | unsigned int link_id) | |
4921 | { | |
4922 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); | |
4923 | ||
0cd8080e JB |
4924 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
4925 | ||
6d543b34 | 4926 | ieee80211_vif_set_links(sdata, wdev->valid_links, 0); |
0d8c4a3c JB |
4927 | } |
4928 | ||
21476ad1 ST |
4929 | static int sta_add_link_station(struct ieee80211_local *local, |
4930 | struct ieee80211_sub_if_data *sdata, | |
4931 | struct link_station_parameters *params) | |
4932 | { | |
4933 | struct sta_info *sta; | |
4934 | int ret; | |
4935 | ||
4936 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
4937 | if (!sta) | |
4938 | return -ENOENT; | |
4939 | ||
956b9613 JB |
4940 | if (!sta->sta.valid_links) |
4941 | return -EINVAL; | |
4942 | ||
21476ad1 ST |
4943 | if (sta->sta.valid_links & BIT(params->link_id)) |
4944 | return -EALREADY; | |
4945 | ||
4946 | ret = ieee80211_sta_allocate_link(sta, params->link_id); | |
4947 | if (ret) | |
4948 | return ret; | |
4949 | ||
9aebce6c | 4950 | ret = sta_link_apply_parameters(local, sta, true, params); |
21476ad1 ST |
4951 | if (ret) { |
4952 | ieee80211_sta_free_link(sta, params->link_id); | |
4953 | return ret; | |
4954 | } | |
4955 | ||
4956 | /* ieee80211_sta_activate_link frees the link upon failure */ | |
4957 | return ieee80211_sta_activate_link(sta, params->link_id); | |
4958 | } | |
4959 | ||
4960 | static int | |
4961 | ieee80211_add_link_station(struct wiphy *wiphy, struct net_device *dev, | |
4962 | struct link_station_parameters *params) | |
4963 | { | |
4964 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4965 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
21476ad1 | 4966 | |
4d3acf43 | 4967 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 4968 | |
4d3acf43 | 4969 | return sta_add_link_station(local, sdata, params); |
21476ad1 ST |
4970 | } |
4971 | ||
4972 | static int sta_mod_link_station(struct ieee80211_local *local, | |
4973 | struct ieee80211_sub_if_data *sdata, | |
4974 | struct link_station_parameters *params) | |
4975 | { | |
4976 | struct sta_info *sta; | |
4977 | ||
4978 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
4979 | if (!sta) | |
4980 | return -ENOENT; | |
4981 | ||
4982 | if (!(sta->sta.valid_links & BIT(params->link_id))) | |
4983 | return -EINVAL; | |
4984 | ||
9aebce6c | 4985 | return sta_link_apply_parameters(local, sta, false, params); |
21476ad1 ST |
4986 | } |
4987 | ||
4988 | static int | |
4989 | ieee80211_mod_link_station(struct wiphy *wiphy, struct net_device *dev, | |
4990 | struct link_station_parameters *params) | |
4991 | { | |
4992 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
4993 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
21476ad1 | 4994 | |
4d3acf43 | 4995 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 4996 | |
4d3acf43 | 4997 | return sta_mod_link_station(local, sdata, params); |
21476ad1 ST |
4998 | } |
4999 | ||
5000 | static int sta_del_link_station(struct ieee80211_sub_if_data *sdata, | |
5001 | struct link_station_del_parameters *params) | |
5002 | { | |
5003 | struct sta_info *sta; | |
5004 | ||
5005 | sta = sta_info_get_bss(sdata, params->mld_mac); | |
5006 | if (!sta) | |
5007 | return -ENOENT; | |
5008 | ||
5009 | if (!(sta->sta.valid_links & BIT(params->link_id))) | |
5010 | return -EINVAL; | |
5011 | ||
956b9613 JB |
5012 | /* must not create a STA without links */ |
5013 | if (sta->sta.valid_links == BIT(params->link_id)) | |
5014 | return -EINVAL; | |
5015 | ||
21476ad1 ST |
5016 | ieee80211_sta_remove_link(sta, params->link_id); |
5017 | ||
5018 | return 0; | |
5019 | } | |
5020 | ||
5021 | static int | |
5022 | ieee80211_del_link_station(struct wiphy *wiphy, struct net_device *dev, | |
5023 | struct link_station_del_parameters *params) | |
5024 | { | |
5025 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
21476ad1 | 5026 | |
4d3acf43 | 5027 | lockdep_assert_wiphy(sdata->local->hw.wiphy); |
21476ad1 | 5028 | |
4d3acf43 | 5029 | return sta_del_link_station(sdata, params); |
21476ad1 ST |
5030 | } |
5031 | ||
81202305 AS |
5032 | static int ieee80211_set_hw_timestamp(struct wiphy *wiphy, |
5033 | struct net_device *dev, | |
5034 | struct cfg80211_set_hw_timestamp *hwts) | |
5035 | { | |
5036 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
5037 | struct ieee80211_local *local = sdata->local; | |
5038 | ||
5039 | if (!local->ops->set_hw_timestamp) | |
5040 | return -EOPNOTSUPP; | |
5041 | ||
5042 | if (!check_sdata_in_driver(sdata)) | |
5043 | return -EIO; | |
5044 | ||
5045 | return local->ops->set_hw_timestamp(&local->hw, &sdata->vif, hwts); | |
5046 | } | |
5047 | ||
f7660b3f AB |
5048 | static int |
5049 | ieee80211_set_ttlm(struct wiphy *wiphy, struct net_device *dev, | |
5050 | struct cfg80211_ttlm_params *params) | |
5051 | { | |
5052 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
5053 | ||
5054 | lockdep_assert_wiphy(sdata->local->hw.wiphy); | |
5055 | ||
5056 | return ieee80211_req_neg_ttlm(sdata, params); | |
5057 | } | |
5058 | ||
8a47cea7 | 5059 | const struct cfg80211_ops mac80211_config_ops = { |
f0706e82 JB |
5060 | .add_virtual_intf = ieee80211_add_iface, |
5061 | .del_virtual_intf = ieee80211_del_iface, | |
42613db7 | 5062 | .change_virtual_intf = ieee80211_change_iface, |
f142c6b9 JB |
5063 | .start_p2p_device = ieee80211_start_p2p_device, |
5064 | .stop_p2p_device = ieee80211_stop_p2p_device, | |
e8cbb4cb JB |
5065 | .add_key = ieee80211_add_key, |
5066 | .del_key = ieee80211_del_key, | |
62da92fb | 5067 | .get_key = ieee80211_get_key, |
e8cbb4cb | 5068 | .set_default_key = ieee80211_config_default_key, |
3cfcf6ac | 5069 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
e5473e80 | 5070 | .set_default_beacon_key = ieee80211_config_default_beacon_key, |
8860020e JB |
5071 | .start_ap = ieee80211_start_ap, |
5072 | .change_beacon = ieee80211_change_beacon, | |
5073 | .stop_ap = ieee80211_stop_ap, | |
4fd6931e JB |
5074 | .add_station = ieee80211_add_station, |
5075 | .del_station = ieee80211_del_station, | |
5076 | .change_station = ieee80211_change_station, | |
7bbdd2d9 | 5077 | .get_station = ieee80211_get_station, |
c5dd9c2b | 5078 | .dump_station = ieee80211_dump_station, |
1289723e | 5079 | .dump_survey = ieee80211_dump_survey, |
c5dd9c2b LCC |
5080 | #ifdef CONFIG_MAC80211_MESH |
5081 | .add_mpath = ieee80211_add_mpath, | |
5082 | .del_mpath = ieee80211_del_mpath, | |
5083 | .change_mpath = ieee80211_change_mpath, | |
5084 | .get_mpath = ieee80211_get_mpath, | |
5085 | .dump_mpath = ieee80211_dump_mpath, | |
a2db2ed3 HR |
5086 | .get_mpp = ieee80211_get_mpp, |
5087 | .dump_mpp = ieee80211_dump_mpp, | |
24bdd9f4 JC |
5088 | .update_mesh_config = ieee80211_update_mesh_config, |
5089 | .get_mesh_config = ieee80211_get_mesh_config, | |
29cbe68c JB |
5090 | .join_mesh = ieee80211_join_mesh, |
5091 | .leave_mesh = ieee80211_leave_mesh, | |
c5dd9c2b | 5092 | #endif |
239281f8 RL |
5093 | .join_ocb = ieee80211_join_ocb, |
5094 | .leave_ocb = ieee80211_leave_ocb, | |
9f1ba906 | 5095 | .change_bss = ieee80211_change_bss, |
108d2022 | 5096 | .inform_bss = ieee80211_inform_bss, |
31888487 | 5097 | .set_txq_params = ieee80211_set_txq_params, |
e8c9bd5b | 5098 | .set_monitor_channel = ieee80211_set_monitor_channel, |
665af4fc BC |
5099 | .suspend = ieee80211_suspend, |
5100 | .resume = ieee80211_resume, | |
2a519311 | 5101 | .scan = ieee80211_scan, |
91f123f2 | 5102 | .abort_scan = ieee80211_abort_scan, |
79f460ca LC |
5103 | .sched_scan_start = ieee80211_sched_scan_start, |
5104 | .sched_scan_stop = ieee80211_sched_scan_stop, | |
636a5d36 JM |
5105 | .auth = ieee80211_auth, |
5106 | .assoc = ieee80211_assoc, | |
5107 | .deauth = ieee80211_deauth, | |
5108 | .disassoc = ieee80211_disassoc, | |
af8cdcd8 JB |
5109 | .join_ibss = ieee80211_join_ibss, |
5110 | .leave_ibss = ieee80211_leave_ibss, | |
391e53e3 | 5111 | .set_mcast_rate = ieee80211_set_mcast_rate, |
b9a5f8ca | 5112 | .set_wiphy_params = ieee80211_set_wiphy_params, |
7643a2c3 JB |
5113 | .set_tx_power = ieee80211_set_tx_power, |
5114 | .get_tx_power = ieee80211_get_tx_power, | |
1f87f7d3 | 5115 | .rfkill_poll = ieee80211_rfkill_poll, |
aff89a9b | 5116 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
71063f0e | 5117 | CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) |
bc92afd9 | 5118 | .set_power_mgmt = ieee80211_set_power_mgmt, |
9930380f | 5119 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
b8bc4b0a JB |
5120 | .remain_on_channel = ieee80211_remain_on_channel, |
5121 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, | |
2e161f78 | 5122 | .mgmt_tx = ieee80211_mgmt_tx, |
f30221e4 | 5123 | .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, |
a97c13c3 | 5124 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
2c3c5f8c | 5125 | .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, |
6cd536fe JB |
5126 | .update_mgmt_frame_registrations = |
5127 | ieee80211_update_mgmt_frame_registrations, | |
15d96753 BR |
5128 | .set_antenna = ieee80211_set_antenna, |
5129 | .get_antenna = ieee80211_get_antenna, | |
c68f4b89 | 5130 | .set_rekey_data = ieee80211_set_rekey_data, |
dfe018bf AN |
5131 | .tdls_oper = ieee80211_tdls_oper, |
5132 | .tdls_mgmt = ieee80211_tdls_mgmt, | |
a7a6bdd0 AN |
5133 | .tdls_channel_switch = ieee80211_tdls_channel_switch, |
5134 | .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, | |
06500736 | 5135 | .probe_client = ieee80211_probe_client, |
b53be792 | 5136 | .set_noack_map = ieee80211_set_noack_map, |
6d52563f JB |
5137 | #ifdef CONFIG_PM |
5138 | .set_wakeup = ieee80211_set_wakeup, | |
5139 | #endif | |
5b7ccaf3 | 5140 | .get_channel = ieee80211_cfg_get_channel, |
164eb02d | 5141 | .start_radar_detection = ieee80211_start_radar_detection, |
26ec17a1 | 5142 | .end_cac = ieee80211_end_cac, |
73da7d5b | 5143 | .channel_switch = ieee80211_channel_switch, |
32db6b54 | 5144 | .set_qos_map = ieee80211_set_qos_map, |
3b1700bd | 5145 | .set_ap_chanwidth = ieee80211_set_ap_chanwidth, |
02219b3a JB |
5146 | .add_tx_ts = ieee80211_add_tx_ts, |
5147 | .del_tx_ts = ieee80211_del_tx_ts, | |
708d50ed AB |
5148 | .start_nan = ieee80211_start_nan, |
5149 | .stop_nan = ieee80211_stop_nan, | |
5953ff6d | 5150 | .nan_change_conf = ieee80211_nan_change_conf, |
167e33f4 AB |
5151 | .add_nan_func = ieee80211_add_nan_func, |
5152 | .del_nan_func = ieee80211_del_nan_func, | |
ebceec86 | 5153 | .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, |
91180649 | 5154 | .tx_control_port = ieee80211_tx_control_port, |
2fe4a29a | 5155 | .get_txq_stats = ieee80211_get_txq_stats, |
bc847970 | 5156 | .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats, |
cee7013b JB |
5157 | .start_pmsr = ieee80211_start_pmsr, |
5158 | .abort_pmsr = ieee80211_abort_pmsr, | |
8828f81a | 5159 | .probe_mesh_link = ieee80211_probe_mesh_link, |
370f51d5 T |
5160 | .set_tid_config = ieee80211_set_tid_config, |
5161 | .reset_tid_config = ieee80211_reset_tid_config, | |
c534e093 | 5162 | .set_sar_specs = ieee80211_set_sar_specs, |
5f9404ab | 5163 | .color_change = ieee80211_color_change, |
a95bfb87 | 5164 | .set_radar_background = ieee80211_set_radar_background, |
0d8c4a3c JB |
5165 | .add_intf_link = ieee80211_add_intf_link, |
5166 | .del_intf_link = ieee80211_del_intf_link, | |
21476ad1 ST |
5167 | .add_link_station = ieee80211_add_link_station, |
5168 | .mod_link_station = ieee80211_mod_link_station, | |
5169 | .del_link_station = ieee80211_del_link_station, | |
81202305 | 5170 | .set_hw_timestamp = ieee80211_set_hw_timestamp, |
f7660b3f | 5171 | .set_ttlm = ieee80211_set_ttlm, |
f0706e82 | 5172 | }; |