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