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