]>
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 | |
f9e10ce4 JB |
23 | static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name, |
24 | enum nl80211_iftype type, | |
25 | u32 *flags, | |
26 | struct vif_params *params) | |
f0706e82 JB |
27 | { |
28 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
8cc9a739 MW |
29 | struct net_device *dev; |
30 | struct ieee80211_sub_if_data *sdata; | |
31 | int err; | |
f0706e82 | 32 | |
05c914fe | 33 | err = ieee80211_if_add(local, name, &dev, type, params); |
f9e10ce4 JB |
34 | if (err) |
35 | return ERR_PTR(err); | |
8cc9a739 | 36 | |
f9e10ce4 JB |
37 | if (type == NL80211_IFTYPE_MONITOR && flags) { |
38 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
39 | sdata->u.mntr_flags = *flags; | |
40 | } | |
41 | ||
42 | return dev; | |
f0706e82 JB |
43 | } |
44 | ||
463d0183 | 45 | static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev) |
f0706e82 | 46 | { |
463d0183 | 47 | ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev)); |
f0706e82 | 48 | |
75636525 | 49 | return 0; |
f0706e82 JB |
50 | } |
51 | ||
e36d56b6 JB |
52 | static int ieee80211_change_iface(struct wiphy *wiphy, |
53 | struct net_device *dev, | |
2ec600d6 LCC |
54 | enum nl80211_iftype type, u32 *flags, |
55 | struct vif_params *params) | |
42613db7 | 56 | { |
9607e6b6 | 57 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
f3947e2d | 58 | int ret; |
42613db7 | 59 | |
05c914fe | 60 | ret = ieee80211_if_change_type(sdata, type); |
f3947e2d JB |
61 | if (ret) |
62 | return ret; | |
42613db7 | 63 | |
9bc383de JB |
64 | if (type == NL80211_IFTYPE_AP_VLAN && |
65 | params && params->use_4addr == 0) | |
a9b3cd7f | 66 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
9bc383de JB |
67 | else if (type == NL80211_IFTYPE_STATION && |
68 | params && params->use_4addr >= 0) | |
69 | sdata->u.mgd.use_4addr = params->use_4addr; | |
70 | ||
85416a4f CL |
71 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) { |
72 | struct ieee80211_local *local = sdata->local; | |
73 | ||
74 | if (ieee80211_sdata_running(sdata)) { | |
75 | /* | |
76 | * Prohibit MONITOR_FLAG_COOK_FRAMES to be | |
77 | * changed while the interface is up. | |
78 | * Else we would need to add a lot of cruft | |
79 | * to update everything: | |
80 | * cooked_mntrs, monitor and all fif_* counters | |
81 | * reconfigure hardware | |
82 | */ | |
83 | if ((*flags & MONITOR_FLAG_COOK_FRAMES) != | |
84 | (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) | |
85 | return -EBUSY; | |
86 | ||
87 | ieee80211_adjust_monitor_flags(sdata, -1); | |
88 | sdata->u.mntr_flags = *flags; | |
89 | ieee80211_adjust_monitor_flags(sdata, 1); | |
90 | ||
91 | ieee80211_configure_filter(local); | |
92 | } else { | |
93 | /* | |
94 | * Because the interface is down, ieee80211_do_stop | |
95 | * and ieee80211_do_open take care of "everything" | |
96 | * mentioned in the comment above. | |
97 | */ | |
98 | sdata->u.mntr_flags = *flags; | |
99 | } | |
100 | } | |
f7917af9 | 101 | |
42613db7 JB |
102 | return 0; |
103 | } | |
104 | ||
b53be792 SW |
105 | static int ieee80211_set_noack_map(struct wiphy *wiphy, |
106 | struct net_device *dev, | |
107 | u16 noack_map) | |
108 | { | |
109 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
110 | ||
111 | sdata->noack_map = noack_map; | |
112 | return 0; | |
113 | } | |
114 | ||
e8cbb4cb | 115 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
e31b8213 | 116 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
e8cbb4cb JB |
117 | struct key_params *params) |
118 | { | |
26a58456 | 119 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
e8cbb4cb | 120 | struct sta_info *sta = NULL; |
db4d1169 | 121 | struct ieee80211_key *key; |
3b96766f | 122 | int err; |
e8cbb4cb | 123 | |
26a58456 | 124 | if (!ieee80211_sdata_running(sdata)) |
ad0e2b5a JB |
125 | return -ENETDOWN; |
126 | ||
97359d12 | 127 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
e8cbb4cb JB |
128 | switch (params->cipher) { |
129 | case WLAN_CIPHER_SUITE_WEP40: | |
e8cbb4cb | 130 | case WLAN_CIPHER_SUITE_TKIP: |
97359d12 JB |
131 | case WLAN_CIPHER_SUITE_WEP104: |
132 | if (IS_ERR(sdata->local->wep_tx_tfm)) | |
133 | return -EINVAL; | |
3cfcf6ac | 134 | break; |
e8cbb4cb | 135 | default: |
97359d12 | 136 | break; |
e8cbb4cb JB |
137 | } |
138 | ||
97359d12 JB |
139 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
140 | params->key, params->seq_len, params->seq); | |
1ac62ba7 BH |
141 | if (IS_ERR(key)) |
142 | return PTR_ERR(key); | |
db4d1169 | 143 | |
e31b8213 JB |
144 | if (pairwise) |
145 | key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; | |
146 | ||
ad0e2b5a | 147 | mutex_lock(&sdata->local->sta_mtx); |
3b96766f | 148 | |
e8cbb4cb | 149 | if (mac_addr) { |
ff973af7 TP |
150 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
151 | sta = sta_info_get(sdata, mac_addr); | |
152 | else | |
153 | sta = sta_info_get_bss(sdata, mac_addr); | |
db4d1169 | 154 | if (!sta) { |
32162a4d | 155 | ieee80211_key_free(sdata->local, key); |
3b96766f JB |
156 | err = -ENOENT; |
157 | goto out_unlock; | |
db4d1169 | 158 | } |
e8cbb4cb JB |
159 | } |
160 | ||
3ffc2a90 JB |
161 | err = ieee80211_key_link(key, sdata, sta); |
162 | if (err) | |
163 | ieee80211_key_free(sdata->local, key); | |
db4d1169 | 164 | |
3b96766f | 165 | out_unlock: |
ad0e2b5a | 166 | mutex_unlock(&sdata->local->sta_mtx); |
3b96766f JB |
167 | |
168 | return err; | |
e8cbb4cb JB |
169 | } |
170 | ||
171 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, | |
e31b8213 | 172 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
e8cbb4cb | 173 | { |
5c0c3641 JB |
174 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
175 | struct ieee80211_local *local = sdata->local; | |
e8cbb4cb | 176 | struct sta_info *sta; |
5c0c3641 | 177 | struct ieee80211_key *key = NULL; |
e8cbb4cb JB |
178 | int ret; |
179 | ||
5c0c3641 JB |
180 | mutex_lock(&local->sta_mtx); |
181 | mutex_lock(&local->key_mtx); | |
3b96766f | 182 | |
e8cbb4cb | 183 | if (mac_addr) { |
3b96766f JB |
184 | ret = -ENOENT; |
185 | ||
0e5ded5a | 186 | sta = sta_info_get_bss(sdata, mac_addr); |
e8cbb4cb | 187 | if (!sta) |
3b96766f | 188 | goto out_unlock; |
e8cbb4cb | 189 | |
5c0c3641 | 190 | if (pairwise) |
40b275b6 | 191 | key = key_mtx_dereference(local, sta->ptk); |
5c0c3641 | 192 | else |
40b275b6 | 193 | key = key_mtx_dereference(local, sta->gtk[key_idx]); |
5c0c3641 | 194 | } else |
40b275b6 | 195 | key = key_mtx_dereference(local, sdata->keys[key_idx]); |
e8cbb4cb | 196 | |
5c0c3641 | 197 | if (!key) { |
3b96766f JB |
198 | ret = -ENOENT; |
199 | goto out_unlock; | |
200 | } | |
e8cbb4cb | 201 | |
5c0c3641 | 202 | __ieee80211_key_free(key); |
e8cbb4cb | 203 | |
3b96766f JB |
204 | ret = 0; |
205 | out_unlock: | |
5c0c3641 JB |
206 | mutex_unlock(&local->key_mtx); |
207 | mutex_unlock(&local->sta_mtx); | |
3b96766f JB |
208 | |
209 | return ret; | |
e8cbb4cb JB |
210 | } |
211 | ||
62da92fb | 212 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
e31b8213 JB |
213 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
214 | void *cookie, | |
62da92fb JB |
215 | void (*callback)(void *cookie, |
216 | struct key_params *params)) | |
217 | { | |
14db74bc | 218 | struct ieee80211_sub_if_data *sdata; |
62da92fb JB |
219 | struct sta_info *sta = NULL; |
220 | u8 seq[6] = {0}; | |
221 | struct key_params params; | |
e31b8213 | 222 | struct ieee80211_key *key = NULL; |
aba83a0b | 223 | u64 pn64; |
62da92fb JB |
224 | u32 iv32; |
225 | u16 iv16; | |
226 | int err = -ENOENT; | |
227 | ||
14db74bc JB |
228 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
229 | ||
3b96766f JB |
230 | rcu_read_lock(); |
231 | ||
62da92fb | 232 | if (mac_addr) { |
0e5ded5a | 233 | sta = sta_info_get_bss(sdata, mac_addr); |
62da92fb JB |
234 | if (!sta) |
235 | goto out; | |
236 | ||
e31b8213 | 237 | if (pairwise) |
a3836e02 | 238 | key = rcu_dereference(sta->ptk); |
e31b8213 | 239 | else if (key_idx < NUM_DEFAULT_KEYS) |
a3836e02 | 240 | key = rcu_dereference(sta->gtk[key_idx]); |
62da92fb | 241 | } else |
a3836e02 | 242 | key = rcu_dereference(sdata->keys[key_idx]); |
62da92fb JB |
243 | |
244 | if (!key) | |
245 | goto out; | |
246 | ||
247 | memset(¶ms, 0, sizeof(params)); | |
248 | ||
97359d12 | 249 | params.cipher = key->conf.cipher; |
62da92fb | 250 | |
97359d12 JB |
251 | switch (key->conf.cipher) { |
252 | case WLAN_CIPHER_SUITE_TKIP: | |
b0f76b33 HH |
253 | iv32 = key->u.tkip.tx.iv32; |
254 | iv16 = key->u.tkip.tx.iv16; | |
62da92fb | 255 | |
24487981 JB |
256 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
257 | drv_get_tkip_seq(sdata->local, | |
258 | key->conf.hw_key_idx, | |
259 | &iv32, &iv16); | |
62da92fb JB |
260 | |
261 | seq[0] = iv16 & 0xff; | |
262 | seq[1] = (iv16 >> 8) & 0xff; | |
263 | seq[2] = iv32 & 0xff; | |
264 | seq[3] = (iv32 >> 8) & 0xff; | |
265 | seq[4] = (iv32 >> 16) & 0xff; | |
266 | seq[5] = (iv32 >> 24) & 0xff; | |
267 | params.seq = seq; | |
268 | params.seq_len = 6; | |
269 | break; | |
97359d12 | 270 | case WLAN_CIPHER_SUITE_CCMP: |
aba83a0b JB |
271 | pn64 = atomic64_read(&key->u.ccmp.tx_pn); |
272 | seq[0] = pn64; | |
273 | seq[1] = pn64 >> 8; | |
274 | seq[2] = pn64 >> 16; | |
275 | seq[3] = pn64 >> 24; | |
276 | seq[4] = pn64 >> 32; | |
277 | seq[5] = pn64 >> 40; | |
62da92fb JB |
278 | params.seq = seq; |
279 | params.seq_len = 6; | |
280 | break; | |
97359d12 | 281 | case WLAN_CIPHER_SUITE_AES_CMAC: |
75396ae6 JB |
282 | pn64 = atomic64_read(&key->u.aes_cmac.tx_pn); |
283 | seq[0] = pn64; | |
284 | seq[1] = pn64 >> 8; | |
285 | seq[2] = pn64 >> 16; | |
286 | seq[3] = pn64 >> 24; | |
287 | seq[4] = pn64 >> 32; | |
288 | seq[5] = pn64 >> 40; | |
3cfcf6ac JM |
289 | params.seq = seq; |
290 | params.seq_len = 6; | |
291 | break; | |
62da92fb JB |
292 | } |
293 | ||
294 | params.key = key->conf.key; | |
295 | params.key_len = key->conf.keylen; | |
296 | ||
297 | callback(cookie, ¶ms); | |
298 | err = 0; | |
299 | ||
300 | out: | |
3b96766f | 301 | rcu_read_unlock(); |
62da92fb JB |
302 | return err; |
303 | } | |
304 | ||
e8cbb4cb JB |
305 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
306 | struct net_device *dev, | |
dbd2fd65 JB |
307 | u8 key_idx, bool uni, |
308 | bool multi) | |
e8cbb4cb | 309 | { |
ad0e2b5a | 310 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
3b96766f | 311 | |
f7e0104c | 312 | ieee80211_set_default_key(sdata, key_idx, uni, multi); |
e8cbb4cb JB |
313 | |
314 | return 0; | |
315 | } | |
316 | ||
3cfcf6ac JM |
317 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
318 | struct net_device *dev, | |
319 | u8 key_idx) | |
320 | { | |
66c52421 | 321 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
3cfcf6ac | 322 | |
3cfcf6ac JM |
323 | ieee80211_set_default_mgmt_key(sdata, key_idx); |
324 | ||
3cfcf6ac JM |
325 | return 0; |
326 | } | |
327 | ||
3af6334c FF |
328 | static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx) |
329 | { | |
330 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) { | |
331 | struct ieee80211_supported_band *sband; | |
332 | sband = sta->local->hw.wiphy->bands[ | |
333 | sta->local->hw.conf.channel->band]; | |
334 | rate->legacy = sband->bitrates[idx].bitrate; | |
335 | } else | |
336 | rate->mcs = idx; | |
337 | } | |
338 | ||
c5dd9c2b LCC |
339 | static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) |
340 | { | |
d0709a65 | 341 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
ebe27c91 | 342 | struct timespec uptime; |
c5dd9c2b | 343 | |
f5ea9120 JB |
344 | sinfo->generation = sdata->local->sta_generation; |
345 | ||
c5dd9c2b LCC |
346 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
347 | STATION_INFO_RX_BYTES | | |
420e7fab | 348 | STATION_INFO_TX_BYTES | |
98c8a60a JM |
349 | STATION_INFO_RX_PACKETS | |
350 | STATION_INFO_TX_PACKETS | | |
b206b4ef BR |
351 | STATION_INFO_TX_RETRIES | |
352 | STATION_INFO_TX_FAILED | | |
5a5c731a | 353 | STATION_INFO_TX_BITRATE | |
3af6334c | 354 | STATION_INFO_RX_BITRATE | |
f4263c98 | 355 | STATION_INFO_RX_DROP_MISC | |
ebe27c91 | 356 | STATION_INFO_BSS_PARAM | |
7a724767 HS |
357 | STATION_INFO_CONNECTED_TIME | |
358 | STATION_INFO_STA_FLAGS; | |
ebe27c91 MSS |
359 | |
360 | do_posix_clock_monotonic_gettime(&uptime); | |
361 | sinfo->connected_time = uptime.tv_sec - sta->last_connected; | |
c5dd9c2b LCC |
362 | |
363 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); | |
364 | sinfo->rx_bytes = sta->rx_bytes; | |
365 | sinfo->tx_bytes = sta->tx_bytes; | |
98c8a60a JM |
366 | sinfo->rx_packets = sta->rx_packets; |
367 | sinfo->tx_packets = sta->tx_packets; | |
b206b4ef BR |
368 | sinfo->tx_retries = sta->tx_retry_count; |
369 | sinfo->tx_failed = sta->tx_retry_failed; | |
5a5c731a | 370 | sinfo->rx_dropped_misc = sta->rx_dropped; |
c5dd9c2b | 371 | |
19deffbe JL |
372 | if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) || |
373 | (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) { | |
541a45a1 | 374 | sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG; |
420e7fab | 375 | sinfo->signal = (s8)sta->last_signal; |
541a45a1 | 376 | sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal); |
420e7fab HR |
377 | } |
378 | ||
379 | sinfo->txrate.flags = 0; | |
380 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS) | |
381 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; | |
382 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
383 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
384 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI) | |
385 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
3af6334c FF |
386 | rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx); |
387 | ||
388 | sinfo->rxrate.flags = 0; | |
389 | if (sta->last_rx_rate_flag & RX_FLAG_HT) | |
390 | sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS; | |
391 | if (sta->last_rx_rate_flag & RX_FLAG_40MHZ) | |
392 | sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
393 | if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI) | |
394 | sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
395 | rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx); | |
420e7fab | 396 | |
902acc78 | 397 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
c5dd9c2b | 398 | #ifdef CONFIG_MAC80211_MESH |
c5dd9c2b LCC |
399 | sinfo->filled |= STATION_INFO_LLID | |
400 | STATION_INFO_PLID | | |
401 | STATION_INFO_PLINK_STATE; | |
402 | ||
403 | sinfo->llid = le16_to_cpu(sta->llid); | |
404 | sinfo->plid = le16_to_cpu(sta->plid); | |
405 | sinfo->plink_state = sta->plink_state; | |
c5dd9c2b | 406 | #endif |
902acc78 | 407 | } |
f4263c98 PS |
408 | |
409 | sinfo->bss_param.flags = 0; | |
410 | if (sdata->vif.bss_conf.use_cts_prot) | |
411 | sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT; | |
412 | if (sdata->vif.bss_conf.use_short_preamble) | |
413 | sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE; | |
414 | if (sdata->vif.bss_conf.use_short_slot) | |
415 | sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME; | |
416 | sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period; | |
417 | sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int; | |
7a724767 HS |
418 | |
419 | sinfo->sta_flags.set = 0; | |
420 | sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
421 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
422 | BIT(NL80211_STA_FLAG_WME) | | |
423 | BIT(NL80211_STA_FLAG_MFP) | | |
e4121562 HS |
424 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
425 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a724767 HS |
426 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
427 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
428 | if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE)) | |
429 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
430 | if (test_sta_flag(sta, WLAN_STA_WME)) | |
431 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME); | |
432 | if (test_sta_flag(sta, WLAN_STA_MFP)) | |
433 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP); | |
434 | if (test_sta_flag(sta, WLAN_STA_AUTH)) | |
435 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
e4121562 HS |
436 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) |
437 | sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
c5dd9c2b LCC |
438 | } |
439 | ||
440 | ||
441 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, | |
442 | int idx, u8 *mac, struct station_info *sinfo) | |
443 | { | |
3b53fde8 | 444 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
c5dd9c2b | 445 | struct sta_info *sta; |
d0709a65 JB |
446 | int ret = -ENOENT; |
447 | ||
448 | rcu_read_lock(); | |
c5dd9c2b | 449 | |
3b53fde8 | 450 | sta = sta_info_get_by_idx(sdata, idx); |
d0709a65 JB |
451 | if (sta) { |
452 | ret = 0; | |
17741cdc | 453 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
d0709a65 JB |
454 | sta_set_sinfo(sta, sinfo); |
455 | } | |
c5dd9c2b | 456 | |
d0709a65 | 457 | rcu_read_unlock(); |
c5dd9c2b | 458 | |
d0709a65 | 459 | return ret; |
c5dd9c2b LCC |
460 | } |
461 | ||
1289723e HS |
462 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
463 | int idx, struct survey_info *survey) | |
464 | { | |
465 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
466 | ||
1289723e HS |
467 | return drv_get_survey(local, idx, survey); |
468 | } | |
469 | ||
7bbdd2d9 | 470 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
2ec600d6 | 471 | u8 *mac, struct station_info *sinfo) |
7bbdd2d9 | 472 | { |
abe60632 | 473 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
7bbdd2d9 | 474 | struct sta_info *sta; |
d0709a65 | 475 | int ret = -ENOENT; |
7bbdd2d9 | 476 | |
d0709a65 | 477 | rcu_read_lock(); |
7bbdd2d9 | 478 | |
0e5ded5a | 479 | sta = sta_info_get_bss(sdata, mac); |
d0709a65 JB |
480 | if (sta) { |
481 | ret = 0; | |
482 | sta_set_sinfo(sta, sinfo); | |
483 | } | |
484 | ||
485 | rcu_read_unlock(); | |
486 | ||
487 | return ret; | |
7bbdd2d9 JB |
488 | } |
489 | ||
7827493b AN |
490 | static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata, |
491 | struct beacon_parameters *params) | |
492 | { | |
493 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; | |
494 | ||
495 | bss_conf->ssid_len = params->ssid_len; | |
496 | ||
497 | if (params->ssid_len) | |
498 | memcpy(bss_conf->ssid, params->ssid, params->ssid_len); | |
499 | ||
500 | bss_conf->hidden_ssid = | |
501 | (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); | |
502 | } | |
503 | ||
02945821 AN |
504 | static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, |
505 | u8 *resp, size_t resp_len) | |
506 | { | |
507 | struct sk_buff *new, *old; | |
508 | ||
509 | if (!resp || !resp_len) | |
510 | return -EINVAL; | |
511 | ||
f724828b | 512 | old = rtnl_dereference(sdata->u.ap.probe_resp); |
02945821 AN |
513 | |
514 | new = dev_alloc_skb(resp_len); | |
515 | if (!new) | |
516 | return -ENOMEM; | |
517 | ||
518 | memcpy(skb_put(new, resp_len), resp, resp_len); | |
519 | ||
520 | rcu_assign_pointer(sdata->u.ap.probe_resp, new); | |
521 | synchronize_rcu(); | |
522 | ||
523 | if (old) | |
524 | dev_kfree_skb(old); | |
525 | ||
526 | return 0; | |
527 | } | |
528 | ||
5dfdaf58 JB |
529 | /* |
530 | * This handles both adding a beacon and setting new beacon info | |
531 | */ | |
532 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, | |
533 | struct beacon_parameters *params) | |
534 | { | |
535 | struct beacon_data *new, *old; | |
536 | int new_head_len, new_tail_len; | |
537 | int size; | |
538 | int err = -EINVAL; | |
02945821 | 539 | u32 changed = 0; |
5dfdaf58 | 540 | |
40b275b6 | 541 | old = rtnl_dereference(sdata->u.ap.beacon); |
5dfdaf58 JB |
542 | |
543 | /* head must not be zero-length */ | |
544 | if (params->head && !params->head_len) | |
545 | return -EINVAL; | |
546 | ||
547 | /* | |
548 | * This is a kludge. beacon interval should really be part | |
549 | * of the beacon information. | |
550 | */ | |
57c4d7b4 JB |
551 | if (params->interval && |
552 | (sdata->vif.bss_conf.beacon_int != params->interval)) { | |
553 | sdata->vif.bss_conf.beacon_int = params->interval; | |
554 | ieee80211_bss_info_change_notify(sdata, | |
555 | BSS_CHANGED_BEACON_INT); | |
5dfdaf58 JB |
556 | } |
557 | ||
558 | /* Need to have a beacon head if we don't have one yet */ | |
559 | if (!params->head && !old) | |
560 | return err; | |
561 | ||
562 | /* sorry, no way to start beaconing without dtim period */ | |
563 | if (!params->dtim_period && !old) | |
564 | return err; | |
565 | ||
566 | /* new or old head? */ | |
567 | if (params->head) | |
568 | new_head_len = params->head_len; | |
569 | else | |
570 | new_head_len = old->head_len; | |
571 | ||
572 | /* new or old tail? */ | |
573 | if (params->tail || !old) | |
574 | /* params->tail_len will be zero for !params->tail */ | |
575 | new_tail_len = params->tail_len; | |
576 | else | |
577 | new_tail_len = old->tail_len; | |
578 | ||
579 | size = sizeof(*new) + new_head_len + new_tail_len; | |
580 | ||
581 | new = kzalloc(size, GFP_KERNEL); | |
582 | if (!new) | |
583 | return -ENOMEM; | |
584 | ||
585 | /* start filling the new info now */ | |
586 | ||
587 | /* new or old dtim period? */ | |
588 | if (params->dtim_period) | |
589 | new->dtim_period = params->dtim_period; | |
590 | else | |
591 | new->dtim_period = old->dtim_period; | |
592 | ||
593 | /* | |
594 | * pointers go into the block we allocated, | |
595 | * memory is | beacon_data | head | tail | | |
596 | */ | |
597 | new->head = ((u8 *) new) + sizeof(*new); | |
598 | new->tail = new->head + new_head_len; | |
599 | new->head_len = new_head_len; | |
600 | new->tail_len = new_tail_len; | |
601 | ||
602 | /* copy in head */ | |
603 | if (params->head) | |
604 | memcpy(new->head, params->head, new_head_len); | |
605 | else | |
606 | memcpy(new->head, old->head, new_head_len); | |
607 | ||
608 | /* copy in optional tail */ | |
609 | if (params->tail) | |
610 | memcpy(new->tail, params->tail, new_tail_len); | |
611 | else | |
612 | if (old) | |
613 | memcpy(new->tail, old->tail, new_tail_len); | |
614 | ||
19885c4f JB |
615 | sdata->vif.bss_conf.dtim_period = new->dtim_period; |
616 | ||
a9b3cd7f | 617 | RCU_INIT_POINTER(sdata->u.ap.beacon, new); |
5dfdaf58 JB |
618 | |
619 | synchronize_rcu(); | |
620 | ||
621 | kfree(old); | |
622 | ||
02945821 AN |
623 | err = ieee80211_set_probe_resp(sdata, params->probe_resp, |
624 | params->probe_resp_len); | |
625 | if (!err) | |
626 | changed |= BSS_CHANGED_AP_PROBE_RESP; | |
627 | ||
7827493b | 628 | ieee80211_config_ap_ssid(sdata, params); |
02945821 AN |
629 | changed |= BSS_CHANGED_BEACON_ENABLED | |
630 | BSS_CHANGED_BEACON | | |
631 | BSS_CHANGED_SSID; | |
7827493b | 632 | |
02945821 | 633 | ieee80211_bss_info_change_notify(sdata, changed); |
2d0ddec5 | 634 | return 0; |
5dfdaf58 JB |
635 | } |
636 | ||
637 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, | |
638 | struct beacon_parameters *params) | |
639 | { | |
14db74bc | 640 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 | 641 | struct beacon_data *old; |
665c93a9 JB |
642 | struct ieee80211_sub_if_data *vlan; |
643 | int ret; | |
5dfdaf58 | 644 | |
14db74bc JB |
645 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
646 | ||
40b275b6 | 647 | old = rtnl_dereference(sdata->u.ap.beacon); |
5dfdaf58 JB |
648 | if (old) |
649 | return -EALREADY; | |
650 | ||
665c93a9 JB |
651 | ret = ieee80211_config_beacon(sdata, params); |
652 | if (ret) | |
653 | return ret; | |
654 | ||
655 | /* | |
656 | * Apply control port protocol, this allows us to | |
657 | * not encrypt dynamic WEP control frames. | |
658 | */ | |
659 | sdata->control_port_protocol = params->crypto.control_port_ethertype; | |
660 | sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; | |
661 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { | |
662 | vlan->control_port_protocol = | |
663 | params->crypto.control_port_ethertype; | |
664 | vlan->control_port_no_encrypt = | |
665 | params->crypto.control_port_no_encrypt; | |
666 | } | |
667 | ||
668 | return 0; | |
5dfdaf58 JB |
669 | } |
670 | ||
671 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, | |
672 | struct beacon_parameters *params) | |
673 | { | |
14db74bc | 674 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
675 | struct beacon_data *old; |
676 | ||
14db74bc JB |
677 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
678 | ||
40b275b6 | 679 | old = rtnl_dereference(sdata->u.ap.beacon); |
5dfdaf58 JB |
680 | if (!old) |
681 | return -ENOENT; | |
682 | ||
683 | return ieee80211_config_beacon(sdata, params); | |
684 | } | |
685 | ||
686 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) | |
687 | { | |
14db74bc | 688 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
689 | struct beacon_data *old; |
690 | ||
14db74bc JB |
691 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
692 | ||
40b275b6 | 693 | old = rtnl_dereference(sdata->u.ap.beacon); |
5dfdaf58 JB |
694 | if (!old) |
695 | return -ENOENT; | |
696 | ||
a9b3cd7f | 697 | RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); |
5dfdaf58 JB |
698 | synchronize_rcu(); |
699 | kfree(old); | |
700 | ||
2d0ddec5 JB |
701 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
702 | return 0; | |
5dfdaf58 JB |
703 | } |
704 | ||
4fd6931e JB |
705 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
706 | struct iapp_layer2_update { | |
707 | u8 da[ETH_ALEN]; /* broadcast */ | |
708 | u8 sa[ETH_ALEN]; /* STA addr */ | |
709 | __be16 len; /* 6 */ | |
710 | u8 dsap; /* 0 */ | |
711 | u8 ssap; /* 0 */ | |
712 | u8 control; | |
713 | u8 xid_info[3]; | |
bc10502d | 714 | } __packed; |
4fd6931e JB |
715 | |
716 | static void ieee80211_send_layer2_update(struct sta_info *sta) | |
717 | { | |
718 | struct iapp_layer2_update *msg; | |
719 | struct sk_buff *skb; | |
720 | ||
721 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 | |
722 | * bridge devices */ | |
723 | ||
724 | skb = dev_alloc_skb(sizeof(*msg)); | |
725 | if (!skb) | |
726 | return; | |
727 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); | |
728 | ||
729 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) | |
730 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ | |
731 | ||
732 | memset(msg->da, 0xff, ETH_ALEN); | |
17741cdc | 733 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
4fd6931e JB |
734 | msg->len = htons(6); |
735 | msg->dsap = 0; | |
736 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ | |
737 | msg->control = 0xaf; /* XID response lsb.1111F101. | |
738 | * F=0 (no poll command; unsolicited frame) */ | |
739 | msg->xid_info[0] = 0x81; /* XID format identifier */ | |
740 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ | |
741 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ | |
742 | ||
d0709a65 JB |
743 | skb->dev = sta->sdata->dev; |
744 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); | |
4fd6931e | 745 | memset(skb->cb, 0, sizeof(skb->cb)); |
06ee1c26 | 746 | netif_rx_ni(skb); |
4fd6931e JB |
747 | } |
748 | ||
749 | static void sta_apply_parameters(struct ieee80211_local *local, | |
750 | struct sta_info *sta, | |
751 | struct station_parameters *params) | |
752 | { | |
753 | u32 rates; | |
754 | int i, j; | |
8318d78a | 755 | struct ieee80211_supported_band *sband; |
d0709a65 | 756 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
eccb8e8f | 757 | u32 mask, set; |
4fd6931e | 758 | |
ae5eb026 JB |
759 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
760 | ||
eccb8e8f JB |
761 | mask = params->sta_flags_mask; |
762 | set = params->sta_flags_set; | |
73651ee6 | 763 | |
eccb8e8f | 764 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
eccb8e8f | 765 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
c2c98fde JB |
766 | set_sta_flag(sta, WLAN_STA_AUTHORIZED); |
767 | else | |
768 | clear_sta_flag(sta, WLAN_STA_AUTHORIZED); | |
eccb8e8f | 769 | } |
4fd6931e | 770 | |
eccb8e8f | 771 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
eccb8e8f | 772 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
c2c98fde JB |
773 | set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
774 | else | |
775 | clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); | |
eccb8e8f | 776 | } |
4fd6931e | 777 | |
eccb8e8f | 778 | if (mask & BIT(NL80211_STA_FLAG_WME)) { |
39df600a | 779 | if (set & BIT(NL80211_STA_FLAG_WME)) { |
c2c98fde | 780 | set_sta_flag(sta, WLAN_STA_WME); |
39df600a | 781 | sta->sta.wme = true; |
c2c98fde JB |
782 | } else { |
783 | clear_sta_flag(sta, WLAN_STA_WME); | |
784 | sta->sta.wme = false; | |
39df600a | 785 | } |
eccb8e8f | 786 | } |
5394af4d | 787 | |
eccb8e8f | 788 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
eccb8e8f | 789 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
c2c98fde JB |
790 | set_sta_flag(sta, WLAN_STA_MFP); |
791 | else | |
792 | clear_sta_flag(sta, WLAN_STA_MFP); | |
4fd6931e | 793 | } |
b39c48fa JC |
794 | |
795 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
b39c48fa | 796 | if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) |
c2c98fde JB |
797 | set_sta_flag(sta, WLAN_STA_AUTH); |
798 | else | |
799 | clear_sta_flag(sta, WLAN_STA_AUTH); | |
b39c48fa | 800 | } |
4fd6931e | 801 | |
07ba55d7 | 802 | if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { |
07ba55d7 | 803 | if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
c2c98fde JB |
804 | set_sta_flag(sta, WLAN_STA_TDLS_PEER); |
805 | else | |
806 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER); | |
07ba55d7 | 807 | } |
4fd6931e | 808 | |
3b9ce80c JB |
809 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { |
810 | sta->sta.uapsd_queues = params->uapsd_queues; | |
811 | sta->sta.max_sp = params->max_sp; | |
812 | } | |
9533b4ac | 813 | |
51b50fbe JB |
814 | /* |
815 | * cfg80211 validates this (1-2007) and allows setting the AID | |
816 | * only when creating a new station entry | |
817 | */ | |
818 | if (params->aid) | |
819 | sta->sta.aid = params->aid; | |
820 | ||
73651ee6 JB |
821 | /* |
822 | * FIXME: updating the following information is racy when this | |
823 | * function is called from ieee80211_change_station(). | |
824 | * However, all this information should be static so | |
825 | * maybe we should just reject attemps to change it. | |
826 | */ | |
827 | ||
4fd6931e JB |
828 | if (params->listen_interval >= 0) |
829 | sta->listen_interval = params->listen_interval; | |
830 | ||
831 | if (params->supported_rates) { | |
832 | rates = 0; | |
8318d78a | 833 | |
4fd6931e JB |
834 | for (i = 0; i < params->supported_rates_len; i++) { |
835 | int rate = (params->supported_rates[i] & 0x7f) * 5; | |
8318d78a JB |
836 | for (j = 0; j < sband->n_bitrates; j++) { |
837 | if (sband->bitrates[j].bitrate == rate) | |
4fd6931e JB |
838 | rates |= BIT(j); |
839 | } | |
840 | } | |
323ce79a | 841 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
4fd6931e | 842 | } |
c5dd9c2b | 843 | |
d9fe60de | 844 | if (params->ht_capa) |
ef96a842 | 845 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
ae5eb026 | 846 | params->ht_capa, |
d9fe60de | 847 | &sta->sta.ht_cap); |
36aedc90 | 848 | |
9c3990aa | 849 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
4daf50f2 | 850 | #ifdef CONFIG_MAC80211_MESH |
9c3990aa JC |
851 | if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED) |
852 | switch (params->plink_state) { | |
57cf8043 JC |
853 | case NL80211_PLINK_LISTEN: |
854 | case NL80211_PLINK_ESTAB: | |
855 | case NL80211_PLINK_BLOCKED: | |
9c3990aa JC |
856 | sta->plink_state = params->plink_state; |
857 | break; | |
858 | default: | |
859 | /* nothing */ | |
860 | break; | |
861 | } | |
862 | else | |
863 | switch (params->plink_action) { | |
864 | case PLINK_ACTION_OPEN: | |
865 | mesh_plink_open(sta); | |
866 | break; | |
867 | case PLINK_ACTION_BLOCK: | |
868 | mesh_plink_block(sta); | |
869 | break; | |
870 | } | |
4daf50f2 | 871 | #endif |
902acc78 | 872 | } |
4fd6931e JB |
873 | } |
874 | ||
875 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |
876 | u8 *mac, struct station_parameters *params) | |
877 | { | |
14db74bc | 878 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
879 | struct sta_info *sta; |
880 | struct ieee80211_sub_if_data *sdata; | |
73651ee6 | 881 | int err; |
b8d476c8 | 882 | int layer2_update; |
4fd6931e | 883 | |
4fd6931e JB |
884 | if (params->vlan) { |
885 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); | |
886 | ||
05c914fe JB |
887 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
888 | sdata->vif.type != NL80211_IFTYPE_AP) | |
4fd6931e JB |
889 | return -EINVAL; |
890 | } else | |
891 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
892 | ||
47846c9b | 893 | if (compare_ether_addr(mac, sdata->vif.addr) == 0) |
03e4497e JB |
894 | return -EINVAL; |
895 | ||
896 | if (is_multicast_ether_addr(mac)) | |
897 | return -EINVAL; | |
898 | ||
899 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); | |
73651ee6 JB |
900 | if (!sta) |
901 | return -ENOMEM; | |
4fd6931e | 902 | |
c2c98fde JB |
903 | set_sta_flag(sta, WLAN_STA_AUTH); |
904 | set_sta_flag(sta, WLAN_STA_ASSOC); | |
4fd6931e JB |
905 | |
906 | sta_apply_parameters(local, sta, params); | |
907 | ||
d64cf63e AN |
908 | /* |
909 | * for TDLS, rate control should be initialized only when supported | |
910 | * rates are known. | |
911 | */ | |
912 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) | |
913 | rate_control_rate_init(sta); | |
4fd6931e | 914 | |
b8d476c8 JM |
915 | layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
916 | sdata->vif.type == NL80211_IFTYPE_AP; | |
917 | ||
34e89507 | 918 | err = sta_info_insert_rcu(sta); |
73651ee6 | 919 | if (err) { |
73651ee6 JB |
920 | rcu_read_unlock(); |
921 | return err; | |
922 | } | |
923 | ||
b8d476c8 | 924 | if (layer2_update) |
73651ee6 JB |
925 | ieee80211_send_layer2_update(sta); |
926 | ||
927 | rcu_read_unlock(); | |
928 | ||
4fd6931e JB |
929 | return 0; |
930 | } | |
931 | ||
932 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, | |
933 | u8 *mac) | |
934 | { | |
14db74bc JB |
935 | struct ieee80211_local *local = wiphy_priv(wiphy); |
936 | struct ieee80211_sub_if_data *sdata; | |
4fd6931e | 937 | |
14db74bc JB |
938 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
939 | ||
34e89507 JB |
940 | if (mac) |
941 | return sta_info_destroy_addr_bss(sdata, mac); | |
4fd6931e | 942 | |
34e89507 | 943 | sta_info_flush(local, sdata); |
4fd6931e JB |
944 | return 0; |
945 | } | |
946 | ||
947 | static int ieee80211_change_station(struct wiphy *wiphy, | |
948 | struct net_device *dev, | |
949 | u8 *mac, | |
950 | struct station_parameters *params) | |
951 | { | |
abe60632 | 952 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
14db74bc | 953 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
954 | struct sta_info *sta; |
955 | struct ieee80211_sub_if_data *vlansdata; | |
956 | ||
98dd6a57 JB |
957 | rcu_read_lock(); |
958 | ||
0e5ded5a | 959 | sta = sta_info_get_bss(sdata, mac); |
98dd6a57 JB |
960 | if (!sta) { |
961 | rcu_read_unlock(); | |
4fd6931e | 962 | return -ENOENT; |
98dd6a57 | 963 | } |
4fd6931e | 964 | |
bdd90d5e JB |
965 | /* in station mode, supported rates are only valid with TDLS */ |
966 | if (sdata->vif.type == NL80211_IFTYPE_STATION && | |
967 | params->supported_rates && | |
968 | !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { | |
969 | rcu_read_unlock(); | |
970 | return -EINVAL; | |
971 | } | |
972 | ||
d0709a65 | 973 | if (params->vlan && params->vlan != sta->sdata->dev) { |
4fd6931e JB |
974 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
975 | ||
05c914fe JB |
976 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
977 | vlansdata->vif.type != NL80211_IFTYPE_AP) { | |
98dd6a57 | 978 | rcu_read_unlock(); |
4fd6931e | 979 | return -EINVAL; |
98dd6a57 | 980 | } |
4fd6931e | 981 | |
9bc383de | 982 | if (params->vlan->ieee80211_ptr->use_4addr) { |
3305443c JB |
983 | if (vlansdata->u.vlan.sta) { |
984 | rcu_read_unlock(); | |
f14543ee | 985 | return -EBUSY; |
3305443c | 986 | } |
f14543ee | 987 | |
a9b3cd7f | 988 | RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta); |
f14543ee FF |
989 | } |
990 | ||
14db74bc | 991 | sta->sdata = vlansdata; |
4fd6931e JB |
992 | ieee80211_send_layer2_update(sta); |
993 | } | |
994 | ||
995 | sta_apply_parameters(local, sta, params); | |
996 | ||
d64cf63e AN |
997 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates) |
998 | rate_control_rate_init(sta); | |
999 | ||
98dd6a57 JB |
1000 | rcu_read_unlock(); |
1001 | ||
808118cb JY |
1002 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
1003 | params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
1004 | ieee80211_recalc_ps(local, -1); | |
1005 | ||
4fd6931e JB |
1006 | return 0; |
1007 | } | |
1008 | ||
c5dd9c2b LCC |
1009 | #ifdef CONFIG_MAC80211_MESH |
1010 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, | |
1011 | u8 *dst, u8 *next_hop) | |
1012 | { | |
14db74bc | 1013 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
1014 | struct mesh_path *mpath; |
1015 | struct sta_info *sta; | |
1016 | int err; | |
1017 | ||
14db74bc JB |
1018 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1019 | ||
d0709a65 | 1020 | rcu_read_lock(); |
abe60632 | 1021 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
1022 | if (!sta) { |
1023 | rcu_read_unlock(); | |
c5dd9c2b | 1024 | return -ENOENT; |
d0709a65 | 1025 | } |
c5dd9c2b | 1026 | |
f698d856 | 1027 | err = mesh_path_add(dst, sdata); |
d0709a65 JB |
1028 | if (err) { |
1029 | rcu_read_unlock(); | |
c5dd9c2b | 1030 | return err; |
d0709a65 | 1031 | } |
c5dd9c2b | 1032 | |
f698d856 | 1033 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
1034 | if (!mpath) { |
1035 | rcu_read_unlock(); | |
c5dd9c2b LCC |
1036 | return -ENXIO; |
1037 | } | |
1038 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 1039 | |
c5dd9c2b LCC |
1040 | rcu_read_unlock(); |
1041 | return 0; | |
1042 | } | |
1043 | ||
1044 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, | |
1045 | u8 *dst) | |
1046 | { | |
f698d856 JBG |
1047 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1048 | ||
c5dd9c2b | 1049 | if (dst) |
f698d856 | 1050 | return mesh_path_del(dst, sdata); |
c5dd9c2b | 1051 | |
ece1a2e7 | 1052 | mesh_path_flush_by_iface(sdata); |
c5dd9c2b LCC |
1053 | return 0; |
1054 | } | |
1055 | ||
1056 | static int ieee80211_change_mpath(struct wiphy *wiphy, | |
1057 | struct net_device *dev, | |
1058 | u8 *dst, u8 *next_hop) | |
1059 | { | |
14db74bc | 1060 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
1061 | struct mesh_path *mpath; |
1062 | struct sta_info *sta; | |
1063 | ||
14db74bc JB |
1064 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1065 | ||
d0709a65 JB |
1066 | rcu_read_lock(); |
1067 | ||
abe60632 | 1068 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
1069 | if (!sta) { |
1070 | rcu_read_unlock(); | |
c5dd9c2b | 1071 | return -ENOENT; |
d0709a65 | 1072 | } |
c5dd9c2b | 1073 | |
f698d856 | 1074 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
1075 | if (!mpath) { |
1076 | rcu_read_unlock(); | |
c5dd9c2b LCC |
1077 | return -ENOENT; |
1078 | } | |
1079 | ||
1080 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 1081 | |
c5dd9c2b LCC |
1082 | rcu_read_unlock(); |
1083 | return 0; | |
1084 | } | |
1085 | ||
1086 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, | |
1087 | struct mpath_info *pinfo) | |
1088 | { | |
a3836e02 JB |
1089 | struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); |
1090 | ||
1091 | if (next_hop_sta) | |
1092 | memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); | |
c5dd9c2b LCC |
1093 | else |
1094 | memset(next_hop, 0, ETH_ALEN); | |
1095 | ||
f5ea9120 JB |
1096 | pinfo->generation = mesh_paths_generation; |
1097 | ||
c5dd9c2b | 1098 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
d19b3bf6 | 1099 | MPATH_INFO_SN | |
c5dd9c2b LCC |
1100 | MPATH_INFO_METRIC | |
1101 | MPATH_INFO_EXPTIME | | |
1102 | MPATH_INFO_DISCOVERY_TIMEOUT | | |
1103 | MPATH_INFO_DISCOVERY_RETRIES | | |
1104 | MPATH_INFO_FLAGS; | |
1105 | ||
1106 | pinfo->frame_qlen = mpath->frame_queue.qlen; | |
d19b3bf6 | 1107 | pinfo->sn = mpath->sn; |
c5dd9c2b LCC |
1108 | pinfo->metric = mpath->metric; |
1109 | if (time_before(jiffies, mpath->exp_time)) | |
1110 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); | |
1111 | pinfo->discovery_timeout = | |
1112 | jiffies_to_msecs(mpath->discovery_timeout); | |
1113 | pinfo->discovery_retries = mpath->discovery_retries; | |
1114 | pinfo->flags = 0; | |
1115 | if (mpath->flags & MESH_PATH_ACTIVE) | |
1116 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; | |
1117 | if (mpath->flags & MESH_PATH_RESOLVING) | |
1118 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
d19b3bf6 RP |
1119 | if (mpath->flags & MESH_PATH_SN_VALID) |
1120 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; | |
c5dd9c2b LCC |
1121 | if (mpath->flags & MESH_PATH_FIXED) |
1122 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; | |
1123 | if (mpath->flags & MESH_PATH_RESOLVING) | |
1124 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
1125 | ||
1126 | pinfo->flags = mpath->flags; | |
1127 | } | |
1128 | ||
1129 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, | |
1130 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) | |
1131 | ||
1132 | { | |
14db74bc | 1133 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
1134 | struct mesh_path *mpath; |
1135 | ||
14db74bc JB |
1136 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1137 | ||
c5dd9c2b | 1138 | rcu_read_lock(); |
f698d856 | 1139 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
1140 | if (!mpath) { |
1141 | rcu_read_unlock(); | |
1142 | return -ENOENT; | |
1143 | } | |
1144 | memcpy(dst, mpath->dst, ETH_ALEN); | |
1145 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
1146 | rcu_read_unlock(); | |
1147 | return 0; | |
1148 | } | |
1149 | ||
1150 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, | |
1151 | int idx, u8 *dst, u8 *next_hop, | |
1152 | struct mpath_info *pinfo) | |
1153 | { | |
14db74bc | 1154 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
1155 | struct mesh_path *mpath; |
1156 | ||
14db74bc JB |
1157 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1158 | ||
c5dd9c2b | 1159 | rcu_read_lock(); |
f698d856 | 1160 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
c5dd9c2b LCC |
1161 | if (!mpath) { |
1162 | rcu_read_unlock(); | |
1163 | return -ENOENT; | |
1164 | } | |
1165 | memcpy(dst, mpath->dst, ETH_ALEN); | |
1166 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
1167 | rcu_read_unlock(); | |
1168 | return 0; | |
1169 | } | |
93da9cc1 | 1170 | |
24bdd9f4 | 1171 | static int ieee80211_get_mesh_config(struct wiphy *wiphy, |
93da9cc1 | 1172 | struct net_device *dev, |
1173 | struct mesh_config *conf) | |
1174 | { | |
1175 | struct ieee80211_sub_if_data *sdata; | |
1176 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1177 | ||
93da9cc1 | 1178 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
1179 | return 0; | |
1180 | } | |
1181 | ||
1182 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) | |
1183 | { | |
1184 | return (mask >> (parm-1)) & 0x1; | |
1185 | } | |
1186 | ||
c80d545d JC |
1187 | static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, |
1188 | const struct mesh_setup *setup) | |
1189 | { | |
1190 | u8 *new_ie; | |
1191 | const u8 *old_ie; | |
4bb62344 CYY |
1192 | struct ieee80211_sub_if_data *sdata = container_of(ifmsh, |
1193 | struct ieee80211_sub_if_data, u.mesh); | |
c80d545d | 1194 | |
581a8b0f | 1195 | /* allocate information elements */ |
c80d545d | 1196 | new_ie = NULL; |
581a8b0f | 1197 | old_ie = ifmsh->ie; |
c80d545d | 1198 | |
581a8b0f JC |
1199 | if (setup->ie_len) { |
1200 | new_ie = kmemdup(setup->ie, setup->ie_len, | |
c80d545d JC |
1201 | GFP_KERNEL); |
1202 | if (!new_ie) | |
1203 | return -ENOMEM; | |
1204 | } | |
581a8b0f JC |
1205 | ifmsh->ie_len = setup->ie_len; |
1206 | ifmsh->ie = new_ie; | |
1207 | kfree(old_ie); | |
c80d545d JC |
1208 | |
1209 | /* now copy the rest of the setup parameters */ | |
1210 | ifmsh->mesh_id_len = setup->mesh_id_len; | |
1211 | memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); | |
1212 | ifmsh->mesh_pp_id = setup->path_sel_proto; | |
1213 | ifmsh->mesh_pm_id = setup->path_metric; | |
b130e5ce JC |
1214 | ifmsh->security = IEEE80211_MESH_SEC_NONE; |
1215 | if (setup->is_authenticated) | |
1216 | ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; | |
1217 | if (setup->is_secure) | |
1218 | ifmsh->security |= IEEE80211_MESH_SEC_SECURED; | |
c80d545d | 1219 | |
4bb62344 CYY |
1220 | /* mcast rate setting in Mesh Node */ |
1221 | memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, | |
1222 | sizeof(setup->mcast_rate)); | |
1223 | ||
c80d545d JC |
1224 | return 0; |
1225 | } | |
1226 | ||
24bdd9f4 | 1227 | static int ieee80211_update_mesh_config(struct wiphy *wiphy, |
29cbe68c JB |
1228 | struct net_device *dev, u32 mask, |
1229 | const struct mesh_config *nconf) | |
93da9cc1 | 1230 | { |
1231 | struct mesh_config *conf; | |
1232 | struct ieee80211_sub_if_data *sdata; | |
63c5723b RP |
1233 | struct ieee80211_if_mesh *ifmsh; |
1234 | ||
93da9cc1 | 1235 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
63c5723b | 1236 | ifmsh = &sdata->u.mesh; |
93da9cc1 | 1237 | |
93da9cc1 | 1238 | /* Set the config options which we are interested in setting */ |
1239 | conf = &(sdata->u.mesh.mshcfg); | |
1240 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) | |
1241 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; | |
1242 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) | |
1243 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; | |
1244 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) | |
1245 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; | |
1246 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) | |
1247 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; | |
1248 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) | |
1249 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; | |
1250 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) | |
1251 | conf->dot11MeshTTL = nconf->dot11MeshTTL; | |
45904f21 JC |
1252 | if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) |
1253 | conf->dot11MeshTTL = nconf->element_ttl; | |
93da9cc1 | 1254 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) |
1255 | conf->auto_open_plinks = nconf->auto_open_plinks; | |
1256 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) | |
1257 | conf->dot11MeshHWMPmaxPREQretries = | |
1258 | nconf->dot11MeshHWMPmaxPREQretries; | |
1259 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) | |
1260 | conf->path_refresh_time = nconf->path_refresh_time; | |
1261 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) | |
1262 | conf->min_discovery_timeout = nconf->min_discovery_timeout; | |
1263 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) | |
1264 | conf->dot11MeshHWMPactivePathTimeout = | |
1265 | nconf->dot11MeshHWMPactivePathTimeout; | |
1266 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) | |
1267 | conf->dot11MeshHWMPpreqMinInterval = | |
1268 | nconf->dot11MeshHWMPpreqMinInterval; | |
dca7e943 TP |
1269 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) |
1270 | conf->dot11MeshHWMPperrMinInterval = | |
1271 | nconf->dot11MeshHWMPperrMinInterval; | |
93da9cc1 | 1272 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
1273 | mask)) | |
1274 | conf->dot11MeshHWMPnetDiameterTraversalTime = | |
1275 | nconf->dot11MeshHWMPnetDiameterTraversalTime; | |
63c5723b RP |
1276 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
1277 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; | |
1278 | ieee80211_mesh_root_setup(ifmsh); | |
1279 | } | |
16dd7267 | 1280 | if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { |
c6133661 TP |
1281 | /* our current gate announcement implementation rides on root |
1282 | * announcements, so require this ifmsh to also be a root node | |
1283 | * */ | |
1284 | if (nconf->dot11MeshGateAnnouncementProtocol && | |
1285 | !conf->dot11MeshHWMPRootMode) { | |
1286 | conf->dot11MeshHWMPRootMode = 1; | |
1287 | ieee80211_mesh_root_setup(ifmsh); | |
1288 | } | |
16dd7267 JC |
1289 | conf->dot11MeshGateAnnouncementProtocol = |
1290 | nconf->dot11MeshGateAnnouncementProtocol; | |
1291 | } | |
0507e159 JC |
1292 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) { |
1293 | conf->dot11MeshHWMPRannInterval = | |
1294 | nconf->dot11MeshHWMPRannInterval; | |
1295 | } | |
93da9cc1 | 1296 | return 0; |
1297 | } | |
1298 | ||
29cbe68c JB |
1299 | static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, |
1300 | const struct mesh_config *conf, | |
1301 | const struct mesh_setup *setup) | |
1302 | { | |
1303 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1304 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | |
c80d545d | 1305 | int err; |
29cbe68c | 1306 | |
c80d545d JC |
1307 | memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); |
1308 | err = copy_mesh_setup(ifmsh, setup); | |
1309 | if (err) | |
1310 | return err; | |
29cbe68c JB |
1311 | ieee80211_start_mesh(sdata); |
1312 | ||
1313 | return 0; | |
1314 | } | |
1315 | ||
1316 | static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) | |
1317 | { | |
1318 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1319 | ||
1320 | ieee80211_stop_mesh(sdata); | |
1321 | ||
1322 | return 0; | |
1323 | } | |
c5dd9c2b LCC |
1324 | #endif |
1325 | ||
9f1ba906 JM |
1326 | static int ieee80211_change_bss(struct wiphy *wiphy, |
1327 | struct net_device *dev, | |
1328 | struct bss_parameters *params) | |
1329 | { | |
9f1ba906 JM |
1330 | struct ieee80211_sub_if_data *sdata; |
1331 | u32 changed = 0; | |
1332 | ||
9f1ba906 JM |
1333 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1334 | ||
9f1ba906 | 1335 | if (params->use_cts_prot >= 0) { |
bda3933a | 1336 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
9f1ba906 JM |
1337 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
1338 | } | |
1339 | if (params->use_short_preamble >= 0) { | |
bda3933a | 1340 | sdata->vif.bss_conf.use_short_preamble = |
9f1ba906 JM |
1341 | params->use_short_preamble; |
1342 | changed |= BSS_CHANGED_ERP_PREAMBLE; | |
1343 | } | |
43d35343 FF |
1344 | |
1345 | if (!sdata->vif.bss_conf.use_short_slot && | |
1346 | sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) { | |
1347 | sdata->vif.bss_conf.use_short_slot = true; | |
1348 | changed |= BSS_CHANGED_ERP_SLOT; | |
1349 | } | |
1350 | ||
9f1ba906 | 1351 | if (params->use_short_slot_time >= 0) { |
bda3933a | 1352 | sdata->vif.bss_conf.use_short_slot = |
9f1ba906 JM |
1353 | params->use_short_slot_time; |
1354 | changed |= BSS_CHANGED_ERP_SLOT; | |
1355 | } | |
1356 | ||
90c97a04 JM |
1357 | if (params->basic_rates) { |
1358 | int i, j; | |
1359 | u32 rates = 0; | |
1360 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1361 | struct ieee80211_supported_band *sband = | |
1362 | wiphy->bands[local->oper_channel->band]; | |
1363 | ||
1364 | for (i = 0; i < params->basic_rates_len; i++) { | |
1365 | int rate = (params->basic_rates[i] & 0x7f) * 5; | |
1366 | for (j = 0; j < sband->n_bitrates; j++) { | |
1367 | if (sband->bitrates[j].bitrate == rate) | |
1368 | rates |= BIT(j); | |
1369 | } | |
1370 | } | |
1371 | sdata->vif.bss_conf.basic_rates = rates; | |
1372 | changed |= BSS_CHANGED_BASIC_RATES; | |
1373 | } | |
1374 | ||
7b7b5e56 FF |
1375 | if (params->ap_isolate >= 0) { |
1376 | if (params->ap_isolate) | |
1377 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
1378 | else | |
1379 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
1380 | } | |
1381 | ||
80d7e403 HS |
1382 | if (params->ht_opmode >= 0) { |
1383 | sdata->vif.bss_conf.ht_operation_mode = | |
1384 | (u16) params->ht_opmode; | |
1385 | changed |= BSS_CHANGED_HT; | |
1386 | } | |
1387 | ||
9f1ba906 JM |
1388 | ieee80211_bss_info_change_notify(sdata, changed); |
1389 | ||
1390 | return 0; | |
1391 | } | |
1392 | ||
31888487 | 1393 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
f70f01c2 | 1394 | struct net_device *dev, |
31888487 JM |
1395 | struct ieee80211_txq_params *params) |
1396 | { | |
1397 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
f6f3def3 | 1398 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
31888487 JM |
1399 | struct ieee80211_tx_queue_params p; |
1400 | ||
1401 | if (!local->ops->conf_tx) | |
1402 | return -EOPNOTSUPP; | |
1403 | ||
1404 | memset(&p, 0, sizeof(p)); | |
1405 | p.aifs = params->aifs; | |
1406 | p.cw_max = params->cwmax; | |
1407 | p.cw_min = params->cwmin; | |
1408 | p.txop = params->txop; | |
ab13315a KV |
1409 | |
1410 | /* | |
1411 | * Setting tx queue params disables u-apsd because it's only | |
1412 | * called in master mode. | |
1413 | */ | |
1414 | p.uapsd = false; | |
1415 | ||
2683d65b EP |
1416 | if (params->queue >= local->hw.queues) |
1417 | return -EINVAL; | |
1418 | ||
f6f3def3 EP |
1419 | sdata->tx_conf[params->queue] = p; |
1420 | if (drv_conf_tx(local, sdata, params->queue, &p)) { | |
0fb9a9ec JP |
1421 | wiphy_debug(local->hw.wiphy, |
1422 | "failed to set TX queue parameters for queue %d\n", | |
1423 | params->queue); | |
31888487 JM |
1424 | return -EINVAL; |
1425 | } | |
1426 | ||
1427 | return 0; | |
1428 | } | |
1429 | ||
72bdcf34 | 1430 | static int ieee80211_set_channel(struct wiphy *wiphy, |
f444de05 | 1431 | struct net_device *netdev, |
72bdcf34 | 1432 | struct ieee80211_channel *chan, |
094d05dc | 1433 | enum nl80211_channel_type channel_type) |
72bdcf34 JM |
1434 | { |
1435 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
0aaffa9b | 1436 | struct ieee80211_sub_if_data *sdata = NULL; |
eeabee7e BG |
1437 | struct ieee80211_channel *old_oper; |
1438 | enum nl80211_channel_type old_oper_type; | |
1439 | enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT; | |
0aaffa9b JB |
1440 | |
1441 | if (netdev) | |
1442 | sdata = IEEE80211_DEV_TO_SUB_IF(netdev); | |
72bdcf34 | 1443 | |
f444de05 JB |
1444 | switch (ieee80211_get_channel_mode(local, NULL)) { |
1445 | case CHAN_MODE_HOPPING: | |
1446 | return -EBUSY; | |
1447 | case CHAN_MODE_FIXED: | |
0aaffa9b JB |
1448 | if (local->oper_channel != chan) |
1449 | return -EBUSY; | |
1450 | if (!sdata && local->_oper_channel_type == channel_type) | |
f444de05 | 1451 | return 0; |
0aaffa9b | 1452 | break; |
f444de05 JB |
1453 | case CHAN_MODE_UNDEFINED: |
1454 | break; | |
1455 | } | |
72bdcf34 | 1456 | |
eeabee7e BG |
1457 | if (sdata) |
1458 | old_vif_oper_type = sdata->vif.bss_conf.channel_type; | |
1459 | old_oper_type = local->_oper_channel_type; | |
72bdcf34 | 1460 | |
0aaffa9b JB |
1461 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) |
1462 | return -EBUSY; | |
1463 | ||
eeabee7e BG |
1464 | old_oper = local->oper_channel; |
1465 | local->oper_channel = chan; | |
1466 | ||
1467 | /* Update driver if changes were actually made. */ | |
1468 | if ((old_oper != local->oper_channel) || | |
1469 | (old_oper_type != local->_oper_channel_type)) | |
1470 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); | |
1471 | ||
ef5af747 | 1472 | if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR && |
eeabee7e | 1473 | old_vif_oper_type != sdata->vif.bss_conf.channel_type) |
0aaffa9b JB |
1474 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); |
1475 | ||
1476 | return 0; | |
72bdcf34 JM |
1477 | } |
1478 | ||
665af4fc | 1479 | #ifdef CONFIG_PM |
ff1b6e69 JB |
1480 | static int ieee80211_suspend(struct wiphy *wiphy, |
1481 | struct cfg80211_wowlan *wowlan) | |
665af4fc | 1482 | { |
eecc4800 | 1483 | return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); |
665af4fc BC |
1484 | } |
1485 | ||
1486 | static int ieee80211_resume(struct wiphy *wiphy) | |
1487 | { | |
1488 | return __ieee80211_resume(wiphy_priv(wiphy)); | |
1489 | } | |
1490 | #else | |
1491 | #define ieee80211_suspend NULL | |
1492 | #define ieee80211_resume NULL | |
1493 | #endif | |
1494 | ||
2a519311 JB |
1495 | static int ieee80211_scan(struct wiphy *wiphy, |
1496 | struct net_device *dev, | |
1497 | struct cfg80211_scan_request *req) | |
1498 | { | |
2ca27bcf | 1499 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2a519311 | 1500 | |
2ca27bcf JB |
1501 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
1502 | case NL80211_IFTYPE_STATION: | |
1503 | case NL80211_IFTYPE_ADHOC: | |
1504 | case NL80211_IFTYPE_MESH_POINT: | |
1505 | case NL80211_IFTYPE_P2P_CLIENT: | |
1506 | break; | |
1507 | case NL80211_IFTYPE_P2P_GO: | |
1508 | if (sdata->local->ops->hw_scan) | |
1509 | break; | |
e9d7732e JB |
1510 | /* |
1511 | * FIXME: implement NoA while scanning in software, | |
1512 | * for now fall through to allow scanning only when | |
1513 | * beaconing hasn't been configured yet | |
1514 | */ | |
2ca27bcf JB |
1515 | case NL80211_IFTYPE_AP: |
1516 | if (sdata->u.ap.beacon) | |
1517 | return -EOPNOTSUPP; | |
1518 | break; | |
1519 | default: | |
1520 | return -EOPNOTSUPP; | |
1521 | } | |
2a519311 JB |
1522 | |
1523 | return ieee80211_request_scan(sdata, req); | |
1524 | } | |
1525 | ||
79f460ca LC |
1526 | static int |
1527 | ieee80211_sched_scan_start(struct wiphy *wiphy, | |
1528 | struct net_device *dev, | |
1529 | struct cfg80211_sched_scan_request *req) | |
1530 | { | |
1531 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1532 | ||
1533 | if (!sdata->local->ops->sched_scan_start) | |
1534 | return -EOPNOTSUPP; | |
1535 | ||
1536 | return ieee80211_request_sched_scan_start(sdata, req); | |
1537 | } | |
1538 | ||
1539 | static int | |
85a9994a | 1540 | ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev) |
79f460ca LC |
1541 | { |
1542 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1543 | ||
1544 | if (!sdata->local->ops->sched_scan_stop) | |
1545 | return -EOPNOTSUPP; | |
1546 | ||
85a9994a | 1547 | return ieee80211_request_sched_scan_stop(sdata); |
79f460ca LC |
1548 | } |
1549 | ||
636a5d36 JM |
1550 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
1551 | struct cfg80211_auth_request *req) | |
1552 | { | |
77fdaa12 | 1553 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
1554 | } |
1555 | ||
1556 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, | |
1557 | struct cfg80211_assoc_request *req) | |
1558 | { | |
f444de05 JB |
1559 | struct ieee80211_local *local = wiphy_priv(wiphy); |
1560 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1561 | ||
1562 | switch (ieee80211_get_channel_mode(local, sdata)) { | |
1563 | case CHAN_MODE_HOPPING: | |
1564 | return -EBUSY; | |
1565 | case CHAN_MODE_FIXED: | |
1566 | if (local->oper_channel == req->bss->channel) | |
1567 | break; | |
1568 | return -EBUSY; | |
1569 | case CHAN_MODE_UNDEFINED: | |
1570 | break; | |
1571 | } | |
1572 | ||
77fdaa12 | 1573 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
1574 | } |
1575 | ||
1576 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, | |
667503dd JB |
1577 | struct cfg80211_deauth_request *req, |
1578 | void *cookie) | |
636a5d36 | 1579 | { |
667503dd JB |
1580 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), |
1581 | req, cookie); | |
636a5d36 JM |
1582 | } |
1583 | ||
1584 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, | |
667503dd JB |
1585 | struct cfg80211_disassoc_request *req, |
1586 | void *cookie) | |
636a5d36 | 1587 | { |
667503dd JB |
1588 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), |
1589 | req, cookie); | |
636a5d36 JM |
1590 | } |
1591 | ||
af8cdcd8 JB |
1592 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
1593 | struct cfg80211_ibss_params *params) | |
1594 | { | |
f444de05 | 1595 | struct ieee80211_local *local = wiphy_priv(wiphy); |
af8cdcd8 JB |
1596 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1597 | ||
f444de05 JB |
1598 | switch (ieee80211_get_channel_mode(local, sdata)) { |
1599 | case CHAN_MODE_HOPPING: | |
1600 | return -EBUSY; | |
1601 | case CHAN_MODE_FIXED: | |
1602 | if (!params->channel_fixed) | |
1603 | return -EBUSY; | |
1604 | if (local->oper_channel == params->channel) | |
1605 | break; | |
1606 | return -EBUSY; | |
1607 | case CHAN_MODE_UNDEFINED: | |
1608 | break; | |
1609 | } | |
1610 | ||
af8cdcd8 JB |
1611 | return ieee80211_ibss_join(sdata, params); |
1612 | } | |
1613 | ||
1614 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) | |
1615 | { | |
1616 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1617 | ||
1618 | return ieee80211_ibss_leave(sdata); | |
1619 | } | |
1620 | ||
b9a5f8ca JM |
1621 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
1622 | { | |
1623 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
24487981 | 1624 | int err; |
b9a5f8ca | 1625 | |
f23a4780 AN |
1626 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { |
1627 | err = drv_set_frag_threshold(local, wiphy->frag_threshold); | |
1628 | ||
1629 | if (err) | |
1630 | return err; | |
1631 | } | |
1632 | ||
310bc676 LT |
1633 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) { |
1634 | err = drv_set_coverage_class(local, wiphy->coverage_class); | |
1635 | ||
1636 | if (err) | |
1637 | return err; | |
1638 | } | |
1639 | ||
b9a5f8ca | 1640 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
24487981 | 1641 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
b9a5f8ca | 1642 | |
24487981 JB |
1643 | if (err) |
1644 | return err; | |
b9a5f8ca JM |
1645 | } |
1646 | ||
1647 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1648 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; | |
1649 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1650 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; | |
1651 | if (changed & | |
1652 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) | |
1653 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); | |
1654 | ||
1655 | return 0; | |
1656 | } | |
1657 | ||
7643a2c3 | 1658 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
fa61cf70 | 1659 | enum nl80211_tx_power_setting type, int mbm) |
7643a2c3 JB |
1660 | { |
1661 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1662 | struct ieee80211_channel *chan = local->hw.conf.channel; | |
1663 | u32 changes = 0; | |
7643a2c3 JB |
1664 | |
1665 | switch (type) { | |
fa61cf70 | 1666 | case NL80211_TX_POWER_AUTOMATIC: |
7643a2c3 JB |
1667 | local->user_power_level = -1; |
1668 | break; | |
fa61cf70 JO |
1669 | case NL80211_TX_POWER_LIMITED: |
1670 | if (mbm < 0 || (mbm % 100)) | |
1671 | return -EOPNOTSUPP; | |
1672 | local->user_power_level = MBM_TO_DBM(mbm); | |
7643a2c3 | 1673 | break; |
fa61cf70 JO |
1674 | case NL80211_TX_POWER_FIXED: |
1675 | if (mbm < 0 || (mbm % 100)) | |
1676 | return -EOPNOTSUPP; | |
7643a2c3 | 1677 | /* TODO: move to cfg80211 when it knows the channel */ |
fa61cf70 | 1678 | if (MBM_TO_DBM(mbm) > chan->max_power) |
7643a2c3 | 1679 | return -EINVAL; |
fa61cf70 | 1680 | local->user_power_level = MBM_TO_DBM(mbm); |
7643a2c3 | 1681 | break; |
7643a2c3 JB |
1682 | } |
1683 | ||
1684 | ieee80211_hw_config(local, changes); | |
1685 | ||
1686 | return 0; | |
1687 | } | |
1688 | ||
1689 | static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) | |
1690 | { | |
1691 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1692 | ||
1693 | *dbm = local->hw.conf.power_level; | |
1694 | ||
7643a2c3 JB |
1695 | return 0; |
1696 | } | |
1697 | ||
ab737a4f | 1698 | static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev, |
388ac775 | 1699 | const u8 *addr) |
ab737a4f JB |
1700 | { |
1701 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1702 | ||
1703 | memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN); | |
1704 | ||
1705 | return 0; | |
1706 | } | |
1707 | ||
1f87f7d3 JB |
1708 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
1709 | { | |
1710 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1711 | ||
1712 | drv_rfkill_poll(local); | |
1713 | } | |
1714 | ||
aff89a9b | 1715 | #ifdef CONFIG_NL80211_TESTMODE |
99783e2c | 1716 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len) |
aff89a9b JB |
1717 | { |
1718 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1719 | ||
1720 | if (!local->ops->testmode_cmd) | |
1721 | return -EOPNOTSUPP; | |
1722 | ||
1723 | return local->ops->testmode_cmd(&local->hw, data, len); | |
1724 | } | |
71063f0e WYG |
1725 | |
1726 | static int ieee80211_testmode_dump(struct wiphy *wiphy, | |
1727 | struct sk_buff *skb, | |
1728 | struct netlink_callback *cb, | |
1729 | void *data, int len) | |
1730 | { | |
1731 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1732 | ||
1733 | if (!local->ops->testmode_dump) | |
1734 | return -EOPNOTSUPP; | |
1735 | ||
1736 | return local->ops->testmode_dump(&local->hw, skb, cb, data, len); | |
1737 | } | |
aff89a9b JB |
1738 | #endif |
1739 | ||
0f78231b JB |
1740 | int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata, |
1741 | enum ieee80211_smps_mode smps_mode) | |
1742 | { | |
1743 | const u8 *ap; | |
1744 | enum ieee80211_smps_mode old_req; | |
1745 | int err; | |
1746 | ||
243e6df4 JB |
1747 | lockdep_assert_held(&sdata->u.mgd.mtx); |
1748 | ||
0f78231b JB |
1749 | old_req = sdata->u.mgd.req_smps; |
1750 | sdata->u.mgd.req_smps = smps_mode; | |
1751 | ||
1752 | if (old_req == smps_mode && | |
1753 | smps_mode != IEEE80211_SMPS_AUTOMATIC) | |
1754 | return 0; | |
1755 | ||
1756 | /* | |
1757 | * If not associated, or current association is not an HT | |
1758 | * association, there's no need to send an action frame. | |
1759 | */ | |
1760 | if (!sdata->u.mgd.associated || | |
0aaffa9b | 1761 | sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) { |
0f78231b | 1762 | mutex_lock(&sdata->local->iflist_mtx); |
025e6be2 | 1763 | ieee80211_recalc_smps(sdata->local); |
0f78231b JB |
1764 | mutex_unlock(&sdata->local->iflist_mtx); |
1765 | return 0; | |
1766 | } | |
1767 | ||
0c1ad2ca | 1768 | ap = sdata->u.mgd.associated->bssid; |
0f78231b JB |
1769 | |
1770 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { | |
1771 | if (sdata->u.mgd.powersave) | |
1772 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
1773 | else | |
1774 | smps_mode = IEEE80211_SMPS_OFF; | |
1775 | } | |
1776 | ||
1777 | /* send SM PS frame to AP */ | |
1778 | err = ieee80211_send_smps_action(sdata, smps_mode, | |
1779 | ap, ap); | |
1780 | if (err) | |
1781 | sdata->u.mgd.req_smps = old_req; | |
1782 | ||
1783 | return err; | |
1784 | } | |
1785 | ||
bc92afd9 JB |
1786 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
1787 | bool enabled, int timeout) | |
1788 | { | |
1789 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1790 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
bc92afd9 | 1791 | |
e5de30c9 BP |
1792 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
1793 | return -EOPNOTSUPP; | |
1794 | ||
bc92afd9 JB |
1795 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
1796 | return -EOPNOTSUPP; | |
1797 | ||
1798 | if (enabled == sdata->u.mgd.powersave && | |
ff616381 | 1799 | timeout == local->dynamic_ps_forced_timeout) |
bc92afd9 JB |
1800 | return 0; |
1801 | ||
1802 | sdata->u.mgd.powersave = enabled; | |
ff616381 | 1803 | local->dynamic_ps_forced_timeout = timeout; |
bc92afd9 | 1804 | |
0f78231b JB |
1805 | /* no change, but if automatic follow powersave */ |
1806 | mutex_lock(&sdata->u.mgd.mtx); | |
1807 | __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps); | |
1808 | mutex_unlock(&sdata->u.mgd.mtx); | |
1809 | ||
bc92afd9 JB |
1810 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
1811 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
1812 | ||
1813 | ieee80211_recalc_ps(local, -1); | |
1814 | ||
1815 | return 0; | |
1816 | } | |
1817 | ||
a97c13c3 JO |
1818 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
1819 | struct net_device *dev, | |
1820 | s32 rssi_thold, u32 rssi_hyst) | |
1821 | { | |
1822 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1823 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1824 | struct ieee80211_vif *vif = &sdata->vif; | |
1825 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
1826 | ||
a97c13c3 JO |
1827 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
1828 | rssi_hyst == bss_conf->cqm_rssi_hyst) | |
1829 | return 0; | |
1830 | ||
1831 | bss_conf->cqm_rssi_thold = rssi_thold; | |
1832 | bss_conf->cqm_rssi_hyst = rssi_hyst; | |
1833 | ||
17e4ec14 JM |
1834 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) { |
1835 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
1836 | return -EOPNOTSUPP; | |
1837 | return 0; | |
1838 | } | |
1839 | ||
a97c13c3 JO |
1840 | /* tell the driver upon association, unless already associated */ |
1841 | if (sdata->u.mgd.associated) | |
1842 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); | |
1843 | ||
1844 | return 0; | |
1845 | } | |
1846 | ||
9930380f JB |
1847 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
1848 | struct net_device *dev, | |
1849 | const u8 *addr, | |
1850 | const struct cfg80211_bitrate_mask *mask) | |
1851 | { | |
1852 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1853 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
bdbfd6b5 | 1854 | int i, ret; |
2c7e6bc9 | 1855 | |
bdbfd6b5 SM |
1856 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) { |
1857 | ret = drv_set_bitrate_mask(local, sdata, mask); | |
1858 | if (ret) | |
1859 | return ret; | |
1860 | } | |
9930380f | 1861 | |
37eb0b16 JM |
1862 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
1863 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; | |
9930380f | 1864 | |
37eb0b16 | 1865 | return 0; |
9930380f JB |
1866 | } |
1867 | ||
21f83589 JB |
1868 | static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local, |
1869 | struct net_device *dev, | |
1870 | struct ieee80211_channel *chan, | |
1871 | enum nl80211_channel_type chantype, | |
1872 | unsigned int duration, u64 *cookie) | |
1873 | { | |
1874 | int ret; | |
1875 | u32 random_cookie; | |
1876 | ||
1877 | lockdep_assert_held(&local->mtx); | |
1878 | ||
1879 | if (local->hw_roc_cookie) | |
1880 | return -EBUSY; | |
1881 | /* must be nonzero */ | |
1882 | random_cookie = random32() | 1; | |
1883 | ||
1884 | *cookie = random_cookie; | |
1885 | local->hw_roc_dev = dev; | |
1886 | local->hw_roc_cookie = random_cookie; | |
1887 | local->hw_roc_channel = chan; | |
1888 | local->hw_roc_channel_type = chantype; | |
1889 | local->hw_roc_duration = duration; | |
1890 | ret = drv_remain_on_channel(local, chan, chantype, duration); | |
1891 | if (ret) { | |
1892 | local->hw_roc_channel = NULL; | |
1893 | local->hw_roc_cookie = 0; | |
1894 | } | |
1895 | ||
1896 | return ret; | |
1897 | } | |
1898 | ||
b8bc4b0a JB |
1899 | static int ieee80211_remain_on_channel(struct wiphy *wiphy, |
1900 | struct net_device *dev, | |
1901 | struct ieee80211_channel *chan, | |
1902 | enum nl80211_channel_type channel_type, | |
1903 | unsigned int duration, | |
1904 | u64 *cookie) | |
1905 | { | |
1906 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
21f83589 JB |
1907 | struct ieee80211_local *local = sdata->local; |
1908 | ||
1909 | if (local->ops->remain_on_channel) { | |
1910 | int ret; | |
1911 | ||
1912 | mutex_lock(&local->mtx); | |
1913 | ret = ieee80211_remain_on_channel_hw(local, dev, | |
1914 | chan, channel_type, | |
1915 | duration, cookie); | |
90fc4b3a | 1916 | local->hw_roc_for_tx = false; |
21f83589 JB |
1917 | mutex_unlock(&local->mtx); |
1918 | ||
1919 | return ret; | |
1920 | } | |
b8bc4b0a JB |
1921 | |
1922 | return ieee80211_wk_remain_on_channel(sdata, chan, channel_type, | |
1923 | duration, cookie); | |
1924 | } | |
1925 | ||
21f83589 JB |
1926 | static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local, |
1927 | u64 cookie) | |
1928 | { | |
1929 | int ret; | |
1930 | ||
1931 | lockdep_assert_held(&local->mtx); | |
1932 | ||
1933 | if (local->hw_roc_cookie != cookie) | |
1934 | return -ENOENT; | |
1935 | ||
1936 | ret = drv_cancel_remain_on_channel(local); | |
1937 | if (ret) | |
1938 | return ret; | |
1939 | ||
1940 | local->hw_roc_cookie = 0; | |
1941 | local->hw_roc_channel = NULL; | |
1942 | ||
1943 | ieee80211_recalc_idle(local); | |
1944 | ||
1945 | return 0; | |
1946 | } | |
1947 | ||
b8bc4b0a JB |
1948 | static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, |
1949 | struct net_device *dev, | |
1950 | u64 cookie) | |
1951 | { | |
1952 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
21f83589 JB |
1953 | struct ieee80211_local *local = sdata->local; |
1954 | ||
1955 | if (local->ops->cancel_remain_on_channel) { | |
1956 | int ret; | |
1957 | ||
1958 | mutex_lock(&local->mtx); | |
1959 | ret = ieee80211_cancel_remain_on_channel_hw(local, cookie); | |
1960 | mutex_unlock(&local->mtx); | |
1961 | ||
1962 | return ret; | |
1963 | } | |
b8bc4b0a JB |
1964 | |
1965 | return ieee80211_wk_cancel_remain_on_channel(sdata, cookie); | |
1966 | } | |
1967 | ||
f30221e4 JB |
1968 | static enum work_done_result |
1969 | ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb) | |
1970 | { | |
1971 | /* | |
1972 | * Use the data embedded in the work struct for reporting | |
1973 | * here so if the driver mangled the SKB before dropping | |
1974 | * it (which is the only way we really should get here) | |
1975 | * then we don't report mangled data. | |
1976 | * | |
1977 | * If there was no wait time, then by the time we get here | |
1978 | * the driver will likely not have reported the status yet, | |
1979 | * so in that case userspace will have to deal with it. | |
1980 | */ | |
1981 | ||
28a1bcdb | 1982 | if (wk->offchan_tx.wait && !wk->offchan_tx.status) |
f30221e4 JB |
1983 | cfg80211_mgmt_tx_status(wk->sdata->dev, |
1984 | (unsigned long) wk->offchan_tx.frame, | |
1985 | wk->ie, wk->ie_len, false, GFP_KERNEL); | |
1986 | ||
1987 | return WORK_DONE_DESTROY; | |
1988 | } | |
1989 | ||
2e161f78 | 1990 | static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, |
f7ca38df | 1991 | struct ieee80211_channel *chan, bool offchan, |
2e161f78 | 1992 | enum nl80211_channel_type channel_type, |
f7ca38df | 1993 | bool channel_type_valid, unsigned int wait, |
e9f935e3 | 1994 | const u8 *buf, size_t len, bool no_cck, |
e247bd90 | 1995 | bool dont_wait_for_ack, u64 *cookie) |
026331c4 | 1996 | { |
9d38d85d JB |
1997 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1998 | struct ieee80211_local *local = sdata->local; | |
1999 | struct sk_buff *skb; | |
2000 | struct sta_info *sta; | |
f30221e4 | 2001 | struct ieee80211_work *wk; |
9d38d85d | 2002 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
e247bd90 | 2003 | u32 flags; |
f30221e4 | 2004 | bool is_offchan = false; |
f7ca38df | 2005 | |
e247bd90 JB |
2006 | if (dont_wait_for_ack) |
2007 | flags = IEEE80211_TX_CTL_NO_ACK; | |
2008 | else | |
2009 | flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | | |
2010 | IEEE80211_TX_CTL_REQ_TX_STATUS; | |
2011 | ||
9d38d85d JB |
2012 | /* Check that we are on the requested channel for transmission */ |
2013 | if (chan != local->tmp_channel && | |
2014 | chan != local->oper_channel) | |
f30221e4 | 2015 | is_offchan = true; |
9d38d85d JB |
2016 | if (channel_type_valid && |
2017 | (channel_type != local->tmp_channel_type && | |
2018 | channel_type != local->_oper_channel_type)) | |
f30221e4 JB |
2019 | is_offchan = true; |
2020 | ||
21f83589 JB |
2021 | if (chan == local->hw_roc_channel) { |
2022 | /* TODO: check channel type? */ | |
2023 | is_offchan = false; | |
2024 | flags |= IEEE80211_TX_CTL_TX_OFFCHAN; | |
2025 | } | |
2026 | ||
aad14ceb RM |
2027 | if (no_cck) |
2028 | flags |= IEEE80211_TX_CTL_NO_CCK_RATE; | |
2029 | ||
f30221e4 | 2030 | if (is_offchan && !offchan) |
9d38d85d JB |
2031 | return -EBUSY; |
2032 | ||
2033 | switch (sdata->vif.type) { | |
2034 | case NL80211_IFTYPE_ADHOC: | |
663fcafd JB |
2035 | case NL80211_IFTYPE_AP: |
2036 | case NL80211_IFTYPE_AP_VLAN: | |
2037 | case NL80211_IFTYPE_P2P_GO: | |
c7108a71 | 2038 | case NL80211_IFTYPE_MESH_POINT: |
663fcafd JB |
2039 | if (!ieee80211_is_action(mgmt->frame_control) || |
2040 | mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) | |
9d38d85d JB |
2041 | break; |
2042 | rcu_read_lock(); | |
2043 | sta = sta_info_get(sdata, mgmt->da); | |
2044 | rcu_read_unlock(); | |
2045 | if (!sta) | |
2046 | return -ENOLINK; | |
2047 | break; | |
2048 | case NL80211_IFTYPE_STATION: | |
663fcafd | 2049 | case NL80211_IFTYPE_P2P_CLIENT: |
9d38d85d JB |
2050 | break; |
2051 | default: | |
2052 | return -EOPNOTSUPP; | |
2053 | } | |
2054 | ||
2055 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + len); | |
2056 | if (!skb) | |
2057 | return -ENOMEM; | |
2058 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
2059 | ||
2060 | memcpy(skb_put(skb, len), buf, len); | |
2061 | ||
2062 | IEEE80211_SKB_CB(skb)->flags = flags; | |
2063 | ||
2064 | skb->dev = sdata->dev; | |
9d38d85d JB |
2065 | |
2066 | *cookie = (unsigned long) skb; | |
f30221e4 | 2067 | |
90fc4b3a JB |
2068 | if (is_offchan && local->ops->remain_on_channel) { |
2069 | unsigned int duration; | |
2070 | int ret; | |
2071 | ||
2072 | mutex_lock(&local->mtx); | |
2073 | /* | |
2074 | * If the duration is zero, then the driver | |
2075 | * wouldn't actually do anything. Set it to | |
2076 | * 100 for now. | |
2077 | * | |
2078 | * TODO: cancel the off-channel operation | |
2079 | * when we get the SKB's TX status and | |
2080 | * the wait time was zero before. | |
2081 | */ | |
2082 | duration = 100; | |
2083 | if (wait) | |
2084 | duration = wait; | |
2085 | ret = ieee80211_remain_on_channel_hw(local, dev, chan, | |
2086 | channel_type, | |
2087 | duration, cookie); | |
2088 | if (ret) { | |
2089 | kfree_skb(skb); | |
2090 | mutex_unlock(&local->mtx); | |
2091 | return ret; | |
2092 | } | |
2093 | ||
2094 | local->hw_roc_for_tx = true; | |
2095 | local->hw_roc_duration = wait; | |
2096 | ||
2097 | /* | |
2098 | * queue up frame for transmission after | |
2099 | * ieee80211_ready_on_channel call | |
2100 | */ | |
2101 | ||
2102 | /* modify cookie to prevent API mismatches */ | |
2103 | *cookie ^= 2; | |
2104 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN; | |
2105 | local->hw_roc_skb = skb; | |
4334ec85 | 2106 | local->hw_roc_skb_for_status = skb; |
90fc4b3a JB |
2107 | mutex_unlock(&local->mtx); |
2108 | ||
2109 | return 0; | |
2110 | } | |
2111 | ||
f30221e4 JB |
2112 | /* |
2113 | * Can transmit right away if the channel was the | |
2114 | * right one and there's no wait involved... If a | |
2115 | * wait is involved, we might otherwise not be on | |
2116 | * the right channel for long enough! | |
2117 | */ | |
2118 | if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) { | |
2119 | ieee80211_tx_skb(sdata, skb); | |
2120 | return 0; | |
2121 | } | |
2122 | ||
2123 | wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL); | |
2124 | if (!wk) { | |
2125 | kfree_skb(skb); | |
2126 | return -ENOMEM; | |
2127 | } | |
2128 | ||
2129 | wk->type = IEEE80211_WORK_OFFCHANNEL_TX; | |
2130 | wk->chan = chan; | |
4d51e149 | 2131 | wk->chan_type = channel_type; |
f30221e4 JB |
2132 | wk->sdata = sdata; |
2133 | wk->done = ieee80211_offchan_tx_done; | |
2134 | wk->offchan_tx.frame = skb; | |
2135 | wk->offchan_tx.wait = wait; | |
2136 | wk->ie_len = len; | |
2137 | memcpy(wk->ie, buf, len); | |
2138 | ||
2139 | ieee80211_add_work(wk); | |
9d38d85d | 2140 | return 0; |
026331c4 JM |
2141 | } |
2142 | ||
f30221e4 JB |
2143 | static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, |
2144 | struct net_device *dev, | |
2145 | u64 cookie) | |
2146 | { | |
2147 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2148 | struct ieee80211_local *local = sdata->local; | |
2149 | struct ieee80211_work *wk; | |
2150 | int ret = -ENOENT; | |
2151 | ||
2152 | mutex_lock(&local->mtx); | |
90fc4b3a JB |
2153 | |
2154 | if (local->ops->cancel_remain_on_channel) { | |
2155 | cookie ^= 2; | |
2156 | ret = ieee80211_cancel_remain_on_channel_hw(local, cookie); | |
2157 | ||
2158 | if (ret == 0) { | |
2159 | kfree_skb(local->hw_roc_skb); | |
2160 | local->hw_roc_skb = NULL; | |
4334ec85 | 2161 | local->hw_roc_skb_for_status = NULL; |
90fc4b3a JB |
2162 | } |
2163 | ||
2164 | mutex_unlock(&local->mtx); | |
2165 | ||
2166 | return ret; | |
2167 | } | |
2168 | ||
f30221e4 JB |
2169 | list_for_each_entry(wk, &local->work_list, list) { |
2170 | if (wk->sdata != sdata) | |
2171 | continue; | |
2172 | ||
2173 | if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX) | |
2174 | continue; | |
2175 | ||
2176 | if (cookie != (unsigned long) wk->offchan_tx.frame) | |
2177 | continue; | |
2178 | ||
2179 | wk->timeout = jiffies; | |
2180 | ||
2181 | ieee80211_queue_work(&local->hw, &local->work_work); | |
2182 | ret = 0; | |
2183 | break; | |
2184 | } | |
2185 | mutex_unlock(&local->mtx); | |
2186 | ||
2187 | return ret; | |
2188 | } | |
2189 | ||
7be5086d JB |
2190 | static void ieee80211_mgmt_frame_register(struct wiphy *wiphy, |
2191 | struct net_device *dev, | |
2192 | u16 frame_type, bool reg) | |
2193 | { | |
2194 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2195 | ||
2196 | if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ)) | |
2197 | return; | |
2198 | ||
2199 | if (reg) | |
2200 | local->probe_req_reg++; | |
2201 | else | |
2202 | local->probe_req_reg--; | |
2203 | ||
2204 | ieee80211_queue_work(&local->hw, &local->reconfig_filter); | |
2205 | } | |
2206 | ||
15d96753 BR |
2207 | static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) |
2208 | { | |
2209 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2210 | ||
2211 | if (local->started) | |
2212 | return -EOPNOTSUPP; | |
2213 | ||
2214 | return drv_set_antenna(local, tx_ant, rx_ant); | |
2215 | } | |
2216 | ||
2217 | static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) | |
2218 | { | |
2219 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2220 | ||
2221 | return drv_get_antenna(local, tx_ant, rx_ant); | |
2222 | } | |
2223 | ||
38c09159 JL |
2224 | static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx) |
2225 | { | |
2226 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2227 | ||
2228 | return drv_set_ringparam(local, tx, rx); | |
2229 | } | |
2230 | ||
2231 | static void ieee80211_get_ringparam(struct wiphy *wiphy, | |
2232 | u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max) | |
2233 | { | |
2234 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2235 | ||
2236 | drv_get_ringparam(local, tx, tx_max, rx, rx_max); | |
2237 | } | |
2238 | ||
c68f4b89 JB |
2239 | static int ieee80211_set_rekey_data(struct wiphy *wiphy, |
2240 | struct net_device *dev, | |
2241 | struct cfg80211_gtk_rekey_data *data) | |
2242 | { | |
2243 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2244 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2245 | ||
2246 | if (!local->ops->set_rekey_data) | |
2247 | return -EOPNOTSUPP; | |
2248 | ||
2249 | drv_set_rekey_data(local, sdata, data); | |
2250 | ||
2251 | return 0; | |
2252 | } | |
2253 | ||
dfe018bf AN |
2254 | static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb) |
2255 | { | |
2256 | u8 *pos = (void *)skb_put(skb, 7); | |
2257 | ||
2258 | *pos++ = WLAN_EID_EXT_CAPABILITY; | |
2259 | *pos++ = 5; /* len */ | |
2260 | *pos++ = 0x0; | |
2261 | *pos++ = 0x0; | |
2262 | *pos++ = 0x0; | |
2263 | *pos++ = 0x0; | |
2264 | *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED; | |
2265 | } | |
2266 | ||
2267 | static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata) | |
2268 | { | |
2269 | struct ieee80211_local *local = sdata->local; | |
2270 | u16 capab; | |
2271 | ||
2272 | capab = 0; | |
2273 | if (local->oper_channel->band != IEEE80211_BAND_2GHZ) | |
2274 | return capab; | |
2275 | ||
2276 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) | |
2277 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; | |
2278 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) | |
2279 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; | |
2280 | ||
2281 | return capab; | |
2282 | } | |
2283 | ||
2284 | static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr, | |
2285 | u8 *peer, u8 *bssid) | |
2286 | { | |
2287 | struct ieee80211_tdls_lnkie *lnkid; | |
2288 | ||
2289 | lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie)); | |
2290 | ||
2291 | lnkid->ie_type = WLAN_EID_LINK_ID; | |
2292 | lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2; | |
2293 | ||
2294 | memcpy(lnkid->bssid, bssid, ETH_ALEN); | |
2295 | memcpy(lnkid->init_sta, src_addr, ETH_ALEN); | |
2296 | memcpy(lnkid->resp_sta, peer, ETH_ALEN); | |
2297 | } | |
2298 | ||
2299 | static int | |
2300 | ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev, | |
2301 | u8 *peer, u8 action_code, u8 dialog_token, | |
2302 | u16 status_code, struct sk_buff *skb) | |
2303 | { | |
2304 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2305 | struct ieee80211_tdls_data *tf; | |
2306 | ||
2307 | tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u)); | |
2308 | ||
2309 | memcpy(tf->da, peer, ETH_ALEN); | |
2310 | memcpy(tf->sa, sdata->vif.addr, ETH_ALEN); | |
2311 | tf->ether_type = cpu_to_be16(ETH_P_TDLS); | |
2312 | tf->payload_type = WLAN_TDLS_SNAP_RFTYPE; | |
2313 | ||
2314 | switch (action_code) { | |
2315 | case WLAN_TDLS_SETUP_REQUEST: | |
2316 | tf->category = WLAN_CATEGORY_TDLS; | |
2317 | tf->action_code = WLAN_TDLS_SETUP_REQUEST; | |
2318 | ||
2319 | skb_put(skb, sizeof(tf->u.setup_req)); | |
2320 | tf->u.setup_req.dialog_token = dialog_token; | |
2321 | tf->u.setup_req.capability = | |
2322 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); | |
2323 | ||
2324 | ieee80211_add_srates_ie(&sdata->vif, skb); | |
2325 | ieee80211_add_ext_srates_ie(&sdata->vif, skb); | |
2326 | ieee80211_tdls_add_ext_capab(skb); | |
2327 | break; | |
2328 | case WLAN_TDLS_SETUP_RESPONSE: | |
2329 | tf->category = WLAN_CATEGORY_TDLS; | |
2330 | tf->action_code = WLAN_TDLS_SETUP_RESPONSE; | |
2331 | ||
2332 | skb_put(skb, sizeof(tf->u.setup_resp)); | |
2333 | tf->u.setup_resp.status_code = cpu_to_le16(status_code); | |
2334 | tf->u.setup_resp.dialog_token = dialog_token; | |
2335 | tf->u.setup_resp.capability = | |
2336 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); | |
2337 | ||
2338 | ieee80211_add_srates_ie(&sdata->vif, skb); | |
2339 | ieee80211_add_ext_srates_ie(&sdata->vif, skb); | |
2340 | ieee80211_tdls_add_ext_capab(skb); | |
2341 | break; | |
2342 | case WLAN_TDLS_SETUP_CONFIRM: | |
2343 | tf->category = WLAN_CATEGORY_TDLS; | |
2344 | tf->action_code = WLAN_TDLS_SETUP_CONFIRM; | |
2345 | ||
2346 | skb_put(skb, sizeof(tf->u.setup_cfm)); | |
2347 | tf->u.setup_cfm.status_code = cpu_to_le16(status_code); | |
2348 | tf->u.setup_cfm.dialog_token = dialog_token; | |
2349 | break; | |
2350 | case WLAN_TDLS_TEARDOWN: | |
2351 | tf->category = WLAN_CATEGORY_TDLS; | |
2352 | tf->action_code = WLAN_TDLS_TEARDOWN; | |
2353 | ||
2354 | skb_put(skb, sizeof(tf->u.teardown)); | |
2355 | tf->u.teardown.reason_code = cpu_to_le16(status_code); | |
2356 | break; | |
2357 | case WLAN_TDLS_DISCOVERY_REQUEST: | |
2358 | tf->category = WLAN_CATEGORY_TDLS; | |
2359 | tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST; | |
2360 | ||
2361 | skb_put(skb, sizeof(tf->u.discover_req)); | |
2362 | tf->u.discover_req.dialog_token = dialog_token; | |
2363 | break; | |
2364 | default: | |
2365 | return -EINVAL; | |
2366 | } | |
2367 | ||
2368 | return 0; | |
2369 | } | |
2370 | ||
2371 | static int | |
2372 | ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev, | |
2373 | u8 *peer, u8 action_code, u8 dialog_token, | |
2374 | u16 status_code, struct sk_buff *skb) | |
2375 | { | |
2376 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2377 | struct ieee80211_mgmt *mgmt; | |
2378 | ||
2379 | mgmt = (void *)skb_put(skb, 24); | |
2380 | memset(mgmt, 0, 24); | |
2381 | memcpy(mgmt->da, peer, ETH_ALEN); | |
2382 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); | |
2383 | memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); | |
2384 | ||
2385 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
2386 | IEEE80211_STYPE_ACTION); | |
2387 | ||
2388 | switch (action_code) { | |
2389 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: | |
2390 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp)); | |
2391 | mgmt->u.action.category = WLAN_CATEGORY_PUBLIC; | |
2392 | mgmt->u.action.u.tdls_discover_resp.action_code = | |
2393 | WLAN_PUB_ACTION_TDLS_DISCOVER_RES; | |
2394 | mgmt->u.action.u.tdls_discover_resp.dialog_token = | |
2395 | dialog_token; | |
2396 | mgmt->u.action.u.tdls_discover_resp.capability = | |
2397 | cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata)); | |
2398 | ||
2399 | ieee80211_add_srates_ie(&sdata->vif, skb); | |
2400 | ieee80211_add_ext_srates_ie(&sdata->vif, skb); | |
2401 | ieee80211_tdls_add_ext_capab(skb); | |
2402 | break; | |
2403 | default: | |
2404 | return -EINVAL; | |
2405 | } | |
2406 | ||
2407 | return 0; | |
2408 | } | |
2409 | ||
2410 | static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev, | |
2411 | u8 *peer, u8 action_code, u8 dialog_token, | |
2412 | u16 status_code, const u8 *extra_ies, | |
2413 | size_t extra_ies_len) | |
2414 | { | |
2415 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2416 | struct ieee80211_local *local = sdata->local; | |
2417 | struct ieee80211_tx_info *info; | |
2418 | struct sk_buff *skb = NULL; | |
2419 | bool send_direct; | |
2420 | int ret; | |
2421 | ||
2422 | if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
2423 | return -ENOTSUPP; | |
2424 | ||
2425 | /* make sure we are in managed mode, and associated */ | |
2426 | if (sdata->vif.type != NL80211_IFTYPE_STATION || | |
2427 | !sdata->u.mgd.associated) | |
2428 | return -EINVAL; | |
2429 | ||
2430 | #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG | |
2431 | printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer); | |
2432 | #endif | |
2433 | ||
2434 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + | |
2435 | max(sizeof(struct ieee80211_mgmt), | |
2436 | sizeof(struct ieee80211_tdls_data)) + | |
2437 | 50 + /* supported rates */ | |
2438 | 7 + /* ext capab */ | |
2439 | extra_ies_len + | |
2440 | sizeof(struct ieee80211_tdls_lnkie)); | |
2441 | if (!skb) | |
2442 | return -ENOMEM; | |
2443 | ||
2444 | info = IEEE80211_SKB_CB(skb); | |
2445 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
2446 | ||
2447 | switch (action_code) { | |
2448 | case WLAN_TDLS_SETUP_REQUEST: | |
2449 | case WLAN_TDLS_SETUP_RESPONSE: | |
2450 | case WLAN_TDLS_SETUP_CONFIRM: | |
2451 | case WLAN_TDLS_TEARDOWN: | |
2452 | case WLAN_TDLS_DISCOVERY_REQUEST: | |
2453 | ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer, | |
2454 | action_code, dialog_token, | |
2455 | status_code, skb); | |
2456 | send_direct = false; | |
2457 | break; | |
2458 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: | |
2459 | ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code, | |
2460 | dialog_token, status_code, | |
2461 | skb); | |
2462 | send_direct = true; | |
2463 | break; | |
2464 | default: | |
2465 | ret = -ENOTSUPP; | |
2466 | break; | |
2467 | } | |
2468 | ||
2469 | if (ret < 0) | |
2470 | goto fail; | |
2471 | ||
2472 | if (extra_ies_len) | |
2473 | memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len); | |
2474 | ||
2475 | /* the TDLS link IE is always added last */ | |
2476 | switch (action_code) { | |
2477 | case WLAN_TDLS_SETUP_REQUEST: | |
2478 | case WLAN_TDLS_SETUP_CONFIRM: | |
2479 | case WLAN_TDLS_TEARDOWN: | |
2480 | case WLAN_TDLS_DISCOVERY_REQUEST: | |
2481 | /* we are the initiator */ | |
2482 | ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer, | |
2483 | sdata->u.mgd.bssid); | |
2484 | break; | |
2485 | case WLAN_TDLS_SETUP_RESPONSE: | |
2486 | case WLAN_PUB_ACTION_TDLS_DISCOVER_RES: | |
2487 | /* we are the responder */ | |
2488 | ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr, | |
2489 | sdata->u.mgd.bssid); | |
2490 | break; | |
2491 | default: | |
2492 | ret = -ENOTSUPP; | |
2493 | goto fail; | |
2494 | } | |
2495 | ||
2496 | if (send_direct) { | |
2497 | ieee80211_tx_skb(sdata, skb); | |
2498 | return 0; | |
2499 | } | |
2500 | ||
2501 | /* | |
2502 | * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise | |
2503 | * we should default to AC_VI. | |
2504 | */ | |
2505 | switch (action_code) { | |
2506 | case WLAN_TDLS_SETUP_REQUEST: | |
2507 | case WLAN_TDLS_SETUP_RESPONSE: | |
2508 | skb_set_queue_mapping(skb, IEEE80211_AC_BK); | |
2509 | skb->priority = 2; | |
2510 | break; | |
2511 | default: | |
2512 | skb_set_queue_mapping(skb, IEEE80211_AC_VI); | |
2513 | skb->priority = 5; | |
2514 | break; | |
2515 | } | |
2516 | ||
2517 | /* disable bottom halves when entering the Tx path */ | |
2518 | local_bh_disable(); | |
2519 | ret = ieee80211_subif_start_xmit(skb, dev); | |
2520 | local_bh_enable(); | |
2521 | ||
2522 | return ret; | |
2523 | ||
2524 | fail: | |
2525 | dev_kfree_skb(skb); | |
2526 | return ret; | |
2527 | } | |
2528 | ||
2529 | static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev, | |
2530 | u8 *peer, enum nl80211_tdls_operation oper) | |
2531 | { | |
941c93cd | 2532 | struct sta_info *sta; |
dfe018bf AN |
2533 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
2534 | ||
2535 | if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
2536 | return -ENOTSUPP; | |
2537 | ||
2538 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
2539 | return -EINVAL; | |
2540 | ||
2541 | #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG | |
2542 | printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer); | |
2543 | #endif | |
2544 | ||
2545 | switch (oper) { | |
2546 | case NL80211_TDLS_ENABLE_LINK: | |
941c93cd AN |
2547 | rcu_read_lock(); |
2548 | sta = sta_info_get(sdata, peer); | |
2549 | if (!sta) { | |
2550 | rcu_read_unlock(); | |
2551 | return -ENOLINK; | |
2552 | } | |
2553 | ||
c2c98fde | 2554 | set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH); |
941c93cd | 2555 | rcu_read_unlock(); |
dfe018bf AN |
2556 | break; |
2557 | case NL80211_TDLS_DISABLE_LINK: | |
2558 | return sta_info_destroy_addr(sdata, peer); | |
2559 | case NL80211_TDLS_TEARDOWN: | |
2560 | case NL80211_TDLS_SETUP: | |
2561 | case NL80211_TDLS_DISCOVERY_REQ: | |
2562 | /* We don't support in-driver setup/teardown/discovery */ | |
2563 | return -ENOTSUPP; | |
2564 | default: | |
2565 | return -ENOTSUPP; | |
2566 | } | |
2567 | ||
2568 | return 0; | |
2569 | } | |
2570 | ||
06500736 JB |
2571 | static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, |
2572 | const u8 *peer, u64 *cookie) | |
2573 | { | |
2574 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
2575 | struct ieee80211_local *local = sdata->local; | |
2576 | struct ieee80211_qos_hdr *nullfunc; | |
2577 | struct sk_buff *skb; | |
2578 | int size = sizeof(*nullfunc); | |
2579 | __le16 fc; | |
2580 | bool qos; | |
2581 | struct ieee80211_tx_info *info; | |
2582 | struct sta_info *sta; | |
2583 | ||
2584 | rcu_read_lock(); | |
2585 | sta = sta_info_get(sdata, peer); | |
b4487c2d | 2586 | if (sta) { |
06500736 | 2587 | qos = test_sta_flag(sta, WLAN_STA_WME); |
b4487c2d JB |
2588 | rcu_read_unlock(); |
2589 | } else { | |
2590 | rcu_read_unlock(); | |
06500736 | 2591 | return -ENOLINK; |
b4487c2d | 2592 | } |
06500736 JB |
2593 | |
2594 | if (qos) { | |
2595 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
2596 | IEEE80211_STYPE_QOS_NULLFUNC | | |
2597 | IEEE80211_FCTL_FROMDS); | |
2598 | } else { | |
2599 | size -= 2; | |
2600 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
2601 | IEEE80211_STYPE_NULLFUNC | | |
2602 | IEEE80211_FCTL_FROMDS); | |
2603 | } | |
2604 | ||
2605 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); | |
2606 | if (!skb) | |
2607 | return -ENOMEM; | |
2608 | ||
2609 | skb->dev = dev; | |
2610 | ||
2611 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
2612 | ||
2613 | nullfunc = (void *) skb_put(skb, size); | |
2614 | nullfunc->frame_control = fc; | |
2615 | nullfunc->duration_id = 0; | |
2616 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); | |
2617 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | |
2618 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); | |
2619 | nullfunc->seq_ctrl = 0; | |
2620 | ||
2621 | info = IEEE80211_SKB_CB(skb); | |
2622 | ||
2623 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | | |
2624 | IEEE80211_TX_INTFL_NL80211_FRAME_TX; | |
2625 | ||
2626 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); | |
2627 | skb->priority = 7; | |
2628 | if (qos) | |
2629 | nullfunc->qos_ctrl = cpu_to_le16(7); | |
2630 | ||
2631 | local_bh_disable(); | |
2632 | ieee80211_xmit(sdata, skb); | |
2633 | local_bh_enable(); | |
2634 | ||
2635 | *cookie = (unsigned long) skb; | |
2636 | return 0; | |
2637 | } | |
2638 | ||
e999882a JB |
2639 | static struct ieee80211_channel * |
2640 | ieee80211_wiphy_get_channel(struct wiphy *wiphy) | |
2641 | { | |
2642 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
2643 | ||
2644 | return local->oper_channel; | |
2645 | } | |
2646 | ||
f0706e82 JB |
2647 | struct cfg80211_ops mac80211_config_ops = { |
2648 | .add_virtual_intf = ieee80211_add_iface, | |
2649 | .del_virtual_intf = ieee80211_del_iface, | |
42613db7 | 2650 | .change_virtual_intf = ieee80211_change_iface, |
e8cbb4cb JB |
2651 | .add_key = ieee80211_add_key, |
2652 | .del_key = ieee80211_del_key, | |
62da92fb | 2653 | .get_key = ieee80211_get_key, |
e8cbb4cb | 2654 | .set_default_key = ieee80211_config_default_key, |
3cfcf6ac | 2655 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
5dfdaf58 JB |
2656 | .add_beacon = ieee80211_add_beacon, |
2657 | .set_beacon = ieee80211_set_beacon, | |
2658 | .del_beacon = ieee80211_del_beacon, | |
4fd6931e JB |
2659 | .add_station = ieee80211_add_station, |
2660 | .del_station = ieee80211_del_station, | |
2661 | .change_station = ieee80211_change_station, | |
7bbdd2d9 | 2662 | .get_station = ieee80211_get_station, |
c5dd9c2b | 2663 | .dump_station = ieee80211_dump_station, |
1289723e | 2664 | .dump_survey = ieee80211_dump_survey, |
c5dd9c2b LCC |
2665 | #ifdef CONFIG_MAC80211_MESH |
2666 | .add_mpath = ieee80211_add_mpath, | |
2667 | .del_mpath = ieee80211_del_mpath, | |
2668 | .change_mpath = ieee80211_change_mpath, | |
2669 | .get_mpath = ieee80211_get_mpath, | |
2670 | .dump_mpath = ieee80211_dump_mpath, | |
24bdd9f4 JC |
2671 | .update_mesh_config = ieee80211_update_mesh_config, |
2672 | .get_mesh_config = ieee80211_get_mesh_config, | |
29cbe68c JB |
2673 | .join_mesh = ieee80211_join_mesh, |
2674 | .leave_mesh = ieee80211_leave_mesh, | |
c5dd9c2b | 2675 | #endif |
9f1ba906 | 2676 | .change_bss = ieee80211_change_bss, |
31888487 | 2677 | .set_txq_params = ieee80211_set_txq_params, |
72bdcf34 | 2678 | .set_channel = ieee80211_set_channel, |
665af4fc BC |
2679 | .suspend = ieee80211_suspend, |
2680 | .resume = ieee80211_resume, | |
2a519311 | 2681 | .scan = ieee80211_scan, |
79f460ca LC |
2682 | .sched_scan_start = ieee80211_sched_scan_start, |
2683 | .sched_scan_stop = ieee80211_sched_scan_stop, | |
636a5d36 JM |
2684 | .auth = ieee80211_auth, |
2685 | .assoc = ieee80211_assoc, | |
2686 | .deauth = ieee80211_deauth, | |
2687 | .disassoc = ieee80211_disassoc, | |
af8cdcd8 JB |
2688 | .join_ibss = ieee80211_join_ibss, |
2689 | .leave_ibss = ieee80211_leave_ibss, | |
b9a5f8ca | 2690 | .set_wiphy_params = ieee80211_set_wiphy_params, |
7643a2c3 JB |
2691 | .set_tx_power = ieee80211_set_tx_power, |
2692 | .get_tx_power = ieee80211_get_tx_power, | |
ab737a4f | 2693 | .set_wds_peer = ieee80211_set_wds_peer, |
1f87f7d3 | 2694 | .rfkill_poll = ieee80211_rfkill_poll, |
aff89a9b | 2695 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
71063f0e | 2696 | CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) |
bc92afd9 | 2697 | .set_power_mgmt = ieee80211_set_power_mgmt, |
9930380f | 2698 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
b8bc4b0a JB |
2699 | .remain_on_channel = ieee80211_remain_on_channel, |
2700 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, | |
2e161f78 | 2701 | .mgmt_tx = ieee80211_mgmt_tx, |
f30221e4 | 2702 | .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, |
a97c13c3 | 2703 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
7be5086d | 2704 | .mgmt_frame_register = ieee80211_mgmt_frame_register, |
15d96753 BR |
2705 | .set_antenna = ieee80211_set_antenna, |
2706 | .get_antenna = ieee80211_get_antenna, | |
38c09159 JL |
2707 | .set_ringparam = ieee80211_set_ringparam, |
2708 | .get_ringparam = ieee80211_get_ringparam, | |
c68f4b89 | 2709 | .set_rekey_data = ieee80211_set_rekey_data, |
dfe018bf AN |
2710 | .tdls_oper = ieee80211_tdls_oper, |
2711 | .tdls_mgmt = ieee80211_tdls_mgmt, | |
06500736 | 2712 | .probe_client = ieee80211_probe_client, |
e999882a | 2713 | .get_channel = ieee80211_wiphy_get_channel, |
b53be792 | 2714 | .set_noack_map = ieee80211_set_noack_map, |
f0706e82 | 2715 | }; |