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