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