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