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