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