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