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