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