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> |
f0706e82 JB |
15 | #include <net/cfg80211.h> |
16 | #include "ieee80211_i.h" | |
24487981 | 17 | #include "driver-ops.h" |
e0eb6859 | 18 | #include "cfg.h" |
2c8dccc7 | 19 | #include "rate.h" |
c5dd9c2b | 20 | #include "mesh.h" |
c5dd9c2b | 21 | |
05c914fe | 22 | static bool nl80211_type_check(enum nl80211_iftype type) |
42613db7 JB |
23 | { |
24 | switch (type) { | |
42613db7 | 25 | case NL80211_IFTYPE_ADHOC: |
42613db7 | 26 | case NL80211_IFTYPE_STATION: |
42613db7 | 27 | case NL80211_IFTYPE_MONITOR: |
c5dd9c2b LCC |
28 | #ifdef CONFIG_MAC80211_MESH |
29 | case NL80211_IFTYPE_MESH_POINT: | |
c5dd9c2b | 30 | #endif |
fbf18927 JM |
31 | case NL80211_IFTYPE_AP: |
32 | case NL80211_IFTYPE_AP_VLAN: | |
b454048c | 33 | case NL80211_IFTYPE_WDS: |
05c914fe | 34 | return true; |
42613db7 | 35 | default: |
05c914fe | 36 | return false; |
42613db7 JB |
37 | } |
38 | } | |
39 | ||
f14543ee FF |
40 | static bool nl80211_params_check(enum nl80211_iftype type, |
41 | struct vif_params *params) | |
42 | { | |
43 | if (!nl80211_type_check(type)) | |
44 | return false; | |
45 | ||
f14543ee FF |
46 | return true; |
47 | } | |
48 | ||
f0706e82 | 49 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
2ec600d6 LCC |
50 | enum nl80211_iftype type, u32 *flags, |
51 | struct vif_params *params) | |
f0706e82 JB |
52 | { |
53 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
8cc9a739 MW |
54 | struct net_device *dev; |
55 | struct ieee80211_sub_if_data *sdata; | |
56 | int err; | |
f0706e82 | 57 | |
f14543ee | 58 | if (!nl80211_params_check(type, params)) |
f0706e82 | 59 | return -EINVAL; |
f0706e82 | 60 | |
05c914fe JB |
61 | err = ieee80211_if_add(local, name, &dev, type, params); |
62 | if (err || type != NL80211_IFTYPE_MONITOR || !flags) | |
8cc9a739 MW |
63 | return err; |
64 | ||
65 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
66 | sdata->u.mntr_flags = *flags; | |
67 | return 0; | |
f0706e82 JB |
68 | } |
69 | ||
463d0183 | 70 | static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev) |
f0706e82 | 71 | { |
463d0183 | 72 | ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev)); |
f0706e82 | 73 | |
75636525 | 74 | return 0; |
f0706e82 JB |
75 | } |
76 | ||
e36d56b6 JB |
77 | static int ieee80211_change_iface(struct wiphy *wiphy, |
78 | struct net_device *dev, | |
2ec600d6 LCC |
79 | enum nl80211_iftype type, u32 *flags, |
80 | struct vif_params *params) | |
42613db7 | 81 | { |
9607e6b6 | 82 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
f3947e2d | 83 | int ret; |
42613db7 | 84 | |
9607e6b6 | 85 | if (ieee80211_sdata_running(sdata)) |
c1f9a764 JB |
86 | return -EBUSY; |
87 | ||
f14543ee | 88 | if (!nl80211_params_check(type, params)) |
42613db7 JB |
89 | return -EINVAL; |
90 | ||
05c914fe | 91 | ret = ieee80211_if_change_type(sdata, type); |
f3947e2d JB |
92 | if (ret) |
93 | return ret; | |
42613db7 | 94 | |
902acc78 | 95 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
472dbc45 JB |
96 | ieee80211_sdata_set_mesh_id(sdata, |
97 | params->mesh_id_len, | |
98 | params->mesh_id); | |
c5dd9c2b | 99 | |
9bc383de JB |
100 | if (type == NL80211_IFTYPE_AP_VLAN && |
101 | params && params->use_4addr == 0) | |
102 | rcu_assign_pointer(sdata->u.vlan.sta, NULL); | |
103 | else if (type == NL80211_IFTYPE_STATION && | |
104 | params && params->use_4addr >= 0) | |
105 | sdata->u.mgd.use_4addr = params->use_4addr; | |
106 | ||
f7917af9 FF |
107 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) |
108 | sdata->u.mntr_flags = *flags; | |
109 | ||
42613db7 JB |
110 | return 0; |
111 | } | |
112 | ||
e8cbb4cb | 113 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
4e943900 | 114 | u8 key_idx, const u8 *mac_addr, |
e8cbb4cb JB |
115 | struct key_params *params) |
116 | { | |
117 | struct ieee80211_sub_if_data *sdata; | |
118 | struct sta_info *sta = NULL; | |
db4d1169 | 119 | struct ieee80211_key *key; |
3b96766f | 120 | int err; |
e8cbb4cb | 121 | |
ad0e2b5a JB |
122 | if (!netif_running(dev)) |
123 | return -ENETDOWN; | |
124 | ||
e8cbb4cb JB |
125 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
126 | ||
97359d12 | 127 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
e8cbb4cb JB |
128 | switch (params->cipher) { |
129 | case WLAN_CIPHER_SUITE_WEP40: | |
e8cbb4cb | 130 | case WLAN_CIPHER_SUITE_TKIP: |
97359d12 JB |
131 | case WLAN_CIPHER_SUITE_WEP104: |
132 | if (IS_ERR(sdata->local->wep_tx_tfm)) | |
133 | return -EINVAL; | |
3cfcf6ac | 134 | break; |
e8cbb4cb | 135 | default: |
97359d12 | 136 | break; |
e8cbb4cb JB |
137 | } |
138 | ||
97359d12 JB |
139 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
140 | params->key, params->seq_len, params->seq); | |
1ac62ba7 BH |
141 | if (IS_ERR(key)) |
142 | return PTR_ERR(key); | |
db4d1169 | 143 | |
ad0e2b5a | 144 | mutex_lock(&sdata->local->sta_mtx); |
3b96766f | 145 | |
e8cbb4cb | 146 | if (mac_addr) { |
0e5ded5a | 147 | sta = sta_info_get_bss(sdata, mac_addr); |
db4d1169 | 148 | if (!sta) { |
32162a4d | 149 | ieee80211_key_free(sdata->local, key); |
3b96766f JB |
150 | err = -ENOENT; |
151 | goto out_unlock; | |
db4d1169 | 152 | } |
e8cbb4cb JB |
153 | } |
154 | ||
db4d1169 JB |
155 | ieee80211_key_link(key, sdata, sta); |
156 | ||
3b96766f JB |
157 | err = 0; |
158 | out_unlock: | |
ad0e2b5a | 159 | mutex_unlock(&sdata->local->sta_mtx); |
3b96766f JB |
160 | |
161 | return err; | |
e8cbb4cb JB |
162 | } |
163 | ||
164 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, | |
4e943900 | 165 | u8 key_idx, const u8 *mac_addr) |
e8cbb4cb JB |
166 | { |
167 | struct ieee80211_sub_if_data *sdata; | |
168 | struct sta_info *sta; | |
169 | int ret; | |
170 | ||
171 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
172 | ||
ad0e2b5a | 173 | mutex_lock(&sdata->local->sta_mtx); |
3b96766f | 174 | |
e8cbb4cb | 175 | if (mac_addr) { |
3b96766f JB |
176 | ret = -ENOENT; |
177 | ||
0e5ded5a | 178 | sta = sta_info_get_bss(sdata, mac_addr); |
e8cbb4cb | 179 | if (!sta) |
3b96766f | 180 | goto out_unlock; |
e8cbb4cb | 181 | |
db4d1169 | 182 | if (sta->key) { |
32162a4d | 183 | ieee80211_key_free(sdata->local, sta->key); |
db4d1169 | 184 | WARN_ON(sta->key); |
3b96766f JB |
185 | ret = 0; |
186 | } | |
e8cbb4cb | 187 | |
3b96766f | 188 | goto out_unlock; |
e8cbb4cb JB |
189 | } |
190 | ||
3b96766f JB |
191 | if (!sdata->keys[key_idx]) { |
192 | ret = -ENOENT; | |
193 | goto out_unlock; | |
194 | } | |
e8cbb4cb | 195 | |
32162a4d | 196 | ieee80211_key_free(sdata->local, sdata->keys[key_idx]); |
db4d1169 | 197 | WARN_ON(sdata->keys[key_idx]); |
e8cbb4cb | 198 | |
3b96766f JB |
199 | ret = 0; |
200 | out_unlock: | |
ad0e2b5a | 201 | mutex_unlock(&sdata->local->sta_mtx); |
3b96766f JB |
202 | |
203 | return ret; | |
e8cbb4cb JB |
204 | } |
205 | ||
62da92fb | 206 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
4e943900 | 207 | u8 key_idx, const u8 *mac_addr, void *cookie, |
62da92fb JB |
208 | void (*callback)(void *cookie, |
209 | struct key_params *params)) | |
210 | { | |
14db74bc | 211 | struct ieee80211_sub_if_data *sdata; |
62da92fb JB |
212 | struct sta_info *sta = NULL; |
213 | u8 seq[6] = {0}; | |
214 | struct key_params params; | |
215 | struct ieee80211_key *key; | |
216 | u32 iv32; | |
217 | u16 iv16; | |
218 | int err = -ENOENT; | |
219 | ||
14db74bc JB |
220 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
221 | ||
3b96766f JB |
222 | rcu_read_lock(); |
223 | ||
62da92fb | 224 | if (mac_addr) { |
0e5ded5a | 225 | sta = sta_info_get_bss(sdata, mac_addr); |
62da92fb JB |
226 | if (!sta) |
227 | goto out; | |
228 | ||
229 | key = sta->key; | |
230 | } else | |
231 | key = sdata->keys[key_idx]; | |
232 | ||
233 | if (!key) | |
234 | goto out; | |
235 | ||
236 | memset(¶ms, 0, sizeof(params)); | |
237 | ||
97359d12 | 238 | params.cipher = key->conf.cipher; |
62da92fb | 239 | |
97359d12 JB |
240 | switch (key->conf.cipher) { |
241 | case WLAN_CIPHER_SUITE_TKIP: | |
b0f76b33 HH |
242 | iv32 = key->u.tkip.tx.iv32; |
243 | iv16 = key->u.tkip.tx.iv16; | |
62da92fb | 244 | |
24487981 JB |
245 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
246 | drv_get_tkip_seq(sdata->local, | |
247 | key->conf.hw_key_idx, | |
248 | &iv32, &iv16); | |
62da92fb JB |
249 | |
250 | seq[0] = iv16 & 0xff; | |
251 | seq[1] = (iv16 >> 8) & 0xff; | |
252 | seq[2] = iv32 & 0xff; | |
253 | seq[3] = (iv32 >> 8) & 0xff; | |
254 | seq[4] = (iv32 >> 16) & 0xff; | |
255 | seq[5] = (iv32 >> 24) & 0xff; | |
256 | params.seq = seq; | |
257 | params.seq_len = 6; | |
258 | break; | |
97359d12 | 259 | case WLAN_CIPHER_SUITE_CCMP: |
62da92fb JB |
260 | seq[0] = key->u.ccmp.tx_pn[5]; |
261 | seq[1] = key->u.ccmp.tx_pn[4]; | |
262 | seq[2] = key->u.ccmp.tx_pn[3]; | |
263 | seq[3] = key->u.ccmp.tx_pn[2]; | |
264 | seq[4] = key->u.ccmp.tx_pn[1]; | |
265 | seq[5] = key->u.ccmp.tx_pn[0]; | |
266 | params.seq = seq; | |
267 | params.seq_len = 6; | |
268 | break; | |
97359d12 | 269 | case WLAN_CIPHER_SUITE_AES_CMAC: |
3cfcf6ac JM |
270 | seq[0] = key->u.aes_cmac.tx_pn[5]; |
271 | seq[1] = key->u.aes_cmac.tx_pn[4]; | |
272 | seq[2] = key->u.aes_cmac.tx_pn[3]; | |
273 | seq[3] = key->u.aes_cmac.tx_pn[2]; | |
274 | seq[4] = key->u.aes_cmac.tx_pn[1]; | |
275 | seq[5] = key->u.aes_cmac.tx_pn[0]; | |
276 | params.seq = seq; | |
277 | params.seq_len = 6; | |
278 | break; | |
62da92fb JB |
279 | } |
280 | ||
281 | params.key = key->conf.key; | |
282 | params.key_len = key->conf.keylen; | |
283 | ||
284 | callback(cookie, ¶ms); | |
285 | err = 0; | |
286 | ||
287 | out: | |
3b96766f | 288 | rcu_read_unlock(); |
62da92fb JB |
289 | return err; |
290 | } | |
291 | ||
e8cbb4cb JB |
292 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
293 | struct net_device *dev, | |
294 | u8 key_idx) | |
295 | { | |
ad0e2b5a | 296 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
3b96766f | 297 | |
e8cbb4cb JB |
298 | ieee80211_set_default_key(sdata, key_idx); |
299 | ||
300 | return 0; | |
301 | } | |
302 | ||
3cfcf6ac JM |
303 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
304 | struct net_device *dev, | |
305 | u8 key_idx) | |
306 | { | |
66c52421 | 307 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
3cfcf6ac | 308 | |
3cfcf6ac JM |
309 | ieee80211_set_default_mgmt_key(sdata, key_idx); |
310 | ||
3cfcf6ac JM |
311 | return 0; |
312 | } | |
313 | ||
c5dd9c2b LCC |
314 | static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) |
315 | { | |
d0709a65 | 316 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
c5dd9c2b | 317 | |
f5ea9120 JB |
318 | sinfo->generation = sdata->local->sta_generation; |
319 | ||
c5dd9c2b LCC |
320 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
321 | STATION_INFO_RX_BYTES | | |
420e7fab | 322 | STATION_INFO_TX_BYTES | |
98c8a60a JM |
323 | STATION_INFO_RX_PACKETS | |
324 | STATION_INFO_TX_PACKETS | | |
420e7fab | 325 | STATION_INFO_TX_BITRATE; |
c5dd9c2b LCC |
326 | |
327 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); | |
328 | sinfo->rx_bytes = sta->rx_bytes; | |
329 | sinfo->tx_bytes = sta->tx_bytes; | |
98c8a60a JM |
330 | sinfo->rx_packets = sta->rx_packets; |
331 | sinfo->tx_packets = sta->tx_packets; | |
c5dd9c2b | 332 | |
19deffbe JL |
333 | if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) || |
334 | (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) { | |
420e7fab HR |
335 | sinfo->filled |= STATION_INFO_SIGNAL; |
336 | sinfo->signal = (s8)sta->last_signal; | |
337 | } | |
338 | ||
339 | sinfo->txrate.flags = 0; | |
340 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS) | |
341 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; | |
342 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH) | |
343 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; | |
344 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI) | |
345 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; | |
346 | ||
347 | if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) { | |
348 | struct ieee80211_supported_band *sband; | |
349 | sband = sta->local->hw.wiphy->bands[ | |
350 | sta->local->hw.conf.channel->band]; | |
351 | sinfo->txrate.legacy = | |
352 | sband->bitrates[sta->last_tx_rate.idx].bitrate; | |
353 | } else | |
354 | sinfo->txrate.mcs = sta->last_tx_rate.idx; | |
355 | ||
902acc78 | 356 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
c5dd9c2b | 357 | #ifdef CONFIG_MAC80211_MESH |
c5dd9c2b LCC |
358 | sinfo->filled |= STATION_INFO_LLID | |
359 | STATION_INFO_PLID | | |
360 | STATION_INFO_PLINK_STATE; | |
361 | ||
362 | sinfo->llid = le16_to_cpu(sta->llid); | |
363 | sinfo->plid = le16_to_cpu(sta->plid); | |
364 | sinfo->plink_state = sta->plink_state; | |
c5dd9c2b | 365 | #endif |
902acc78 | 366 | } |
c5dd9c2b LCC |
367 | } |
368 | ||
369 | ||
370 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, | |
371 | int idx, u8 *mac, struct station_info *sinfo) | |
372 | { | |
3b53fde8 | 373 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
c5dd9c2b | 374 | struct sta_info *sta; |
d0709a65 JB |
375 | int ret = -ENOENT; |
376 | ||
377 | rcu_read_lock(); | |
c5dd9c2b | 378 | |
3b53fde8 | 379 | sta = sta_info_get_by_idx(sdata, idx); |
d0709a65 JB |
380 | if (sta) { |
381 | ret = 0; | |
17741cdc | 382 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
d0709a65 JB |
383 | sta_set_sinfo(sta, sinfo); |
384 | } | |
c5dd9c2b | 385 | |
d0709a65 | 386 | rcu_read_unlock(); |
c5dd9c2b | 387 | |
d0709a65 | 388 | return ret; |
c5dd9c2b LCC |
389 | } |
390 | ||
1289723e HS |
391 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
392 | int idx, struct survey_info *survey) | |
393 | { | |
394 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
395 | ||
1289723e HS |
396 | return drv_get_survey(local, idx, survey); |
397 | } | |
398 | ||
7bbdd2d9 | 399 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
2ec600d6 | 400 | u8 *mac, struct station_info *sinfo) |
7bbdd2d9 | 401 | { |
abe60632 | 402 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
7bbdd2d9 | 403 | struct sta_info *sta; |
d0709a65 | 404 | int ret = -ENOENT; |
7bbdd2d9 | 405 | |
d0709a65 | 406 | rcu_read_lock(); |
7bbdd2d9 | 407 | |
0e5ded5a | 408 | sta = sta_info_get_bss(sdata, mac); |
d0709a65 JB |
409 | if (sta) { |
410 | ret = 0; | |
411 | sta_set_sinfo(sta, sinfo); | |
412 | } | |
413 | ||
414 | rcu_read_unlock(); | |
415 | ||
416 | return ret; | |
7bbdd2d9 JB |
417 | } |
418 | ||
5dfdaf58 JB |
419 | /* |
420 | * This handles both adding a beacon and setting new beacon info | |
421 | */ | |
422 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, | |
423 | struct beacon_parameters *params) | |
424 | { | |
425 | struct beacon_data *new, *old; | |
426 | int new_head_len, new_tail_len; | |
427 | int size; | |
428 | int err = -EINVAL; | |
429 | ||
430 | old = sdata->u.ap.beacon; | |
431 | ||
432 | /* head must not be zero-length */ | |
433 | if (params->head && !params->head_len) | |
434 | return -EINVAL; | |
435 | ||
436 | /* | |
437 | * This is a kludge. beacon interval should really be part | |
438 | * of the beacon information. | |
439 | */ | |
57c4d7b4 JB |
440 | if (params->interval && |
441 | (sdata->vif.bss_conf.beacon_int != params->interval)) { | |
442 | sdata->vif.bss_conf.beacon_int = params->interval; | |
443 | ieee80211_bss_info_change_notify(sdata, | |
444 | BSS_CHANGED_BEACON_INT); | |
5dfdaf58 JB |
445 | } |
446 | ||
447 | /* Need to have a beacon head if we don't have one yet */ | |
448 | if (!params->head && !old) | |
449 | return err; | |
450 | ||
451 | /* sorry, no way to start beaconing without dtim period */ | |
452 | if (!params->dtim_period && !old) | |
453 | return err; | |
454 | ||
455 | /* new or old head? */ | |
456 | if (params->head) | |
457 | new_head_len = params->head_len; | |
458 | else | |
459 | new_head_len = old->head_len; | |
460 | ||
461 | /* new or old tail? */ | |
462 | if (params->tail || !old) | |
463 | /* params->tail_len will be zero for !params->tail */ | |
464 | new_tail_len = params->tail_len; | |
465 | else | |
466 | new_tail_len = old->tail_len; | |
467 | ||
468 | size = sizeof(*new) + new_head_len + new_tail_len; | |
469 | ||
470 | new = kzalloc(size, GFP_KERNEL); | |
471 | if (!new) | |
472 | return -ENOMEM; | |
473 | ||
474 | /* start filling the new info now */ | |
475 | ||
476 | /* new or old dtim period? */ | |
477 | if (params->dtim_period) | |
478 | new->dtim_period = params->dtim_period; | |
479 | else | |
480 | new->dtim_period = old->dtim_period; | |
481 | ||
482 | /* | |
483 | * pointers go into the block we allocated, | |
484 | * memory is | beacon_data | head | tail | | |
485 | */ | |
486 | new->head = ((u8 *) new) + sizeof(*new); | |
487 | new->tail = new->head + new_head_len; | |
488 | new->head_len = new_head_len; | |
489 | new->tail_len = new_tail_len; | |
490 | ||
491 | /* copy in head */ | |
492 | if (params->head) | |
493 | memcpy(new->head, params->head, new_head_len); | |
494 | else | |
495 | memcpy(new->head, old->head, new_head_len); | |
496 | ||
497 | /* copy in optional tail */ | |
498 | if (params->tail) | |
499 | memcpy(new->tail, params->tail, new_tail_len); | |
500 | else | |
501 | if (old) | |
502 | memcpy(new->tail, old->tail, new_tail_len); | |
503 | ||
19885c4f JB |
504 | sdata->vif.bss_conf.dtim_period = new->dtim_period; |
505 | ||
5dfdaf58 JB |
506 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
507 | ||
508 | synchronize_rcu(); | |
509 | ||
510 | kfree(old); | |
511 | ||
2d0ddec5 JB |
512 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
513 | BSS_CHANGED_BEACON); | |
514 | return 0; | |
5dfdaf58 JB |
515 | } |
516 | ||
517 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, | |
518 | struct beacon_parameters *params) | |
519 | { | |
14db74bc | 520 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
521 | struct beacon_data *old; |
522 | ||
14db74bc JB |
523 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
524 | ||
5dfdaf58 JB |
525 | old = sdata->u.ap.beacon; |
526 | ||
527 | if (old) | |
528 | return -EALREADY; | |
529 | ||
530 | return ieee80211_config_beacon(sdata, params); | |
531 | } | |
532 | ||
533 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, | |
534 | struct beacon_parameters *params) | |
535 | { | |
14db74bc | 536 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
537 | struct beacon_data *old; |
538 | ||
14db74bc JB |
539 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
540 | ||
5dfdaf58 JB |
541 | old = sdata->u.ap.beacon; |
542 | ||
543 | if (!old) | |
544 | return -ENOENT; | |
545 | ||
546 | return ieee80211_config_beacon(sdata, params); | |
547 | } | |
548 | ||
549 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) | |
550 | { | |
14db74bc | 551 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
552 | struct beacon_data *old; |
553 | ||
14db74bc JB |
554 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
555 | ||
5dfdaf58 JB |
556 | old = sdata->u.ap.beacon; |
557 | ||
558 | if (!old) | |
559 | return -ENOENT; | |
560 | ||
561 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | |
562 | synchronize_rcu(); | |
563 | kfree(old); | |
564 | ||
2d0ddec5 JB |
565 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
566 | return 0; | |
5dfdaf58 JB |
567 | } |
568 | ||
4fd6931e JB |
569 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
570 | struct iapp_layer2_update { | |
571 | u8 da[ETH_ALEN]; /* broadcast */ | |
572 | u8 sa[ETH_ALEN]; /* STA addr */ | |
573 | __be16 len; /* 6 */ | |
574 | u8 dsap; /* 0 */ | |
575 | u8 ssap; /* 0 */ | |
576 | u8 control; | |
577 | u8 xid_info[3]; | |
bc10502d | 578 | } __packed; |
4fd6931e JB |
579 | |
580 | static void ieee80211_send_layer2_update(struct sta_info *sta) | |
581 | { | |
582 | struct iapp_layer2_update *msg; | |
583 | struct sk_buff *skb; | |
584 | ||
585 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 | |
586 | * bridge devices */ | |
587 | ||
588 | skb = dev_alloc_skb(sizeof(*msg)); | |
589 | if (!skb) | |
590 | return; | |
591 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); | |
592 | ||
593 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) | |
594 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ | |
595 | ||
596 | memset(msg->da, 0xff, ETH_ALEN); | |
17741cdc | 597 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
4fd6931e JB |
598 | msg->len = htons(6); |
599 | msg->dsap = 0; | |
600 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ | |
601 | msg->control = 0xaf; /* XID response lsb.1111F101. | |
602 | * F=0 (no poll command; unsolicited frame) */ | |
603 | msg->xid_info[0] = 0x81; /* XID format identifier */ | |
604 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ | |
605 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ | |
606 | ||
d0709a65 JB |
607 | skb->dev = sta->sdata->dev; |
608 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); | |
4fd6931e | 609 | memset(skb->cb, 0, sizeof(skb->cb)); |
06ee1c26 | 610 | netif_rx_ni(skb); |
4fd6931e JB |
611 | } |
612 | ||
613 | static void sta_apply_parameters(struct ieee80211_local *local, | |
614 | struct sta_info *sta, | |
615 | struct station_parameters *params) | |
616 | { | |
617 | u32 rates; | |
618 | int i, j; | |
8318d78a | 619 | struct ieee80211_supported_band *sband; |
d0709a65 | 620 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
eccb8e8f | 621 | u32 mask, set; |
4fd6931e | 622 | |
ae5eb026 JB |
623 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
624 | ||
eccb8e8f JB |
625 | spin_lock_bh(&sta->lock); |
626 | mask = params->sta_flags_mask; | |
627 | set = params->sta_flags_set; | |
73651ee6 | 628 | |
eccb8e8f | 629 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
4fd6931e | 630 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
eccb8e8f | 631 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
4fd6931e | 632 | sta->flags |= WLAN_STA_AUTHORIZED; |
eccb8e8f | 633 | } |
4fd6931e | 634 | |
eccb8e8f | 635 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
4fd6931e | 636 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
eccb8e8f | 637 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
4fd6931e | 638 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
eccb8e8f | 639 | } |
4fd6931e | 640 | |
eccb8e8f | 641 | if (mask & BIT(NL80211_STA_FLAG_WME)) { |
4fd6931e | 642 | sta->flags &= ~WLAN_STA_WME; |
eccb8e8f | 643 | if (set & BIT(NL80211_STA_FLAG_WME)) |
4fd6931e | 644 | sta->flags |= WLAN_STA_WME; |
eccb8e8f | 645 | } |
5394af4d | 646 | |
eccb8e8f | 647 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
5394af4d | 648 | sta->flags &= ~WLAN_STA_MFP; |
eccb8e8f | 649 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
5394af4d | 650 | sta->flags |= WLAN_STA_MFP; |
4fd6931e | 651 | } |
eccb8e8f | 652 | spin_unlock_bh(&sta->lock); |
4fd6931e | 653 | |
51b50fbe JB |
654 | /* |
655 | * cfg80211 validates this (1-2007) and allows setting the AID | |
656 | * only when creating a new station entry | |
657 | */ | |
658 | if (params->aid) | |
659 | sta->sta.aid = params->aid; | |
660 | ||
73651ee6 JB |
661 | /* |
662 | * FIXME: updating the following information is racy when this | |
663 | * function is called from ieee80211_change_station(). | |
664 | * However, all this information should be static so | |
665 | * maybe we should just reject attemps to change it. | |
666 | */ | |
667 | ||
4fd6931e JB |
668 | if (params->listen_interval >= 0) |
669 | sta->listen_interval = params->listen_interval; | |
670 | ||
671 | if (params->supported_rates) { | |
672 | rates = 0; | |
8318d78a | 673 | |
4fd6931e JB |
674 | for (i = 0; i < params->supported_rates_len; i++) { |
675 | int rate = (params->supported_rates[i] & 0x7f) * 5; | |
8318d78a JB |
676 | for (j = 0; j < sband->n_bitrates; j++) { |
677 | if (sband->bitrates[j].bitrate == rate) | |
4fd6931e JB |
678 | rates |= BIT(j); |
679 | } | |
680 | } | |
323ce79a | 681 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
4fd6931e | 682 | } |
c5dd9c2b | 683 | |
d9fe60de | 684 | if (params->ht_capa) |
ae5eb026 JB |
685 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
686 | params->ht_capa, | |
d9fe60de | 687 | &sta->sta.ht_cap); |
36aedc90 | 688 | |
902acc78 | 689 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
c5dd9c2b LCC |
690 | switch (params->plink_action) { |
691 | case PLINK_ACTION_OPEN: | |
692 | mesh_plink_open(sta); | |
693 | break; | |
694 | case PLINK_ACTION_BLOCK: | |
695 | mesh_plink_block(sta); | |
696 | break; | |
697 | } | |
902acc78 | 698 | } |
4fd6931e JB |
699 | } |
700 | ||
701 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |
702 | u8 *mac, struct station_parameters *params) | |
703 | { | |
14db74bc | 704 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
705 | struct sta_info *sta; |
706 | struct ieee80211_sub_if_data *sdata; | |
73651ee6 | 707 | int err; |
b8d476c8 | 708 | int layer2_update; |
4fd6931e | 709 | |
4fd6931e JB |
710 | if (params->vlan) { |
711 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); | |
712 | ||
05c914fe JB |
713 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
714 | sdata->vif.type != NL80211_IFTYPE_AP) | |
4fd6931e JB |
715 | return -EINVAL; |
716 | } else | |
717 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
718 | ||
47846c9b | 719 | if (compare_ether_addr(mac, sdata->vif.addr) == 0) |
03e4497e JB |
720 | return -EINVAL; |
721 | ||
722 | if (is_multicast_ether_addr(mac)) | |
723 | return -EINVAL; | |
724 | ||
725 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); | |
73651ee6 JB |
726 | if (!sta) |
727 | return -ENOMEM; | |
4fd6931e JB |
728 | |
729 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
730 | ||
731 | sta_apply_parameters(local, sta, params); | |
732 | ||
4b7679a5 | 733 | rate_control_rate_init(sta); |
4fd6931e | 734 | |
b8d476c8 JM |
735 | layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
736 | sdata->vif.type == NL80211_IFTYPE_AP; | |
737 | ||
34e89507 | 738 | err = sta_info_insert_rcu(sta); |
73651ee6 | 739 | if (err) { |
73651ee6 JB |
740 | rcu_read_unlock(); |
741 | return err; | |
742 | } | |
743 | ||
b8d476c8 | 744 | if (layer2_update) |
73651ee6 JB |
745 | ieee80211_send_layer2_update(sta); |
746 | ||
747 | rcu_read_unlock(); | |
748 | ||
4fd6931e JB |
749 | return 0; |
750 | } | |
751 | ||
752 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, | |
753 | u8 *mac) | |
754 | { | |
14db74bc JB |
755 | struct ieee80211_local *local = wiphy_priv(wiphy); |
756 | struct ieee80211_sub_if_data *sdata; | |
4fd6931e | 757 | |
14db74bc JB |
758 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
759 | ||
34e89507 JB |
760 | if (mac) |
761 | return sta_info_destroy_addr_bss(sdata, mac); | |
4fd6931e | 762 | |
34e89507 | 763 | sta_info_flush(local, sdata); |
4fd6931e JB |
764 | return 0; |
765 | } | |
766 | ||
767 | static int ieee80211_change_station(struct wiphy *wiphy, | |
768 | struct net_device *dev, | |
769 | u8 *mac, | |
770 | struct station_parameters *params) | |
771 | { | |
abe60632 | 772 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
14db74bc | 773 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
774 | struct sta_info *sta; |
775 | struct ieee80211_sub_if_data *vlansdata; | |
776 | ||
98dd6a57 JB |
777 | rcu_read_lock(); |
778 | ||
0e5ded5a | 779 | sta = sta_info_get_bss(sdata, mac); |
98dd6a57 JB |
780 | if (!sta) { |
781 | rcu_read_unlock(); | |
4fd6931e | 782 | return -ENOENT; |
98dd6a57 | 783 | } |
4fd6931e | 784 | |
d0709a65 | 785 | if (params->vlan && params->vlan != sta->sdata->dev) { |
4fd6931e JB |
786 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
787 | ||
05c914fe JB |
788 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
789 | vlansdata->vif.type != NL80211_IFTYPE_AP) { | |
98dd6a57 | 790 | rcu_read_unlock(); |
4fd6931e | 791 | return -EINVAL; |
98dd6a57 | 792 | } |
4fd6931e | 793 | |
9bc383de | 794 | if (params->vlan->ieee80211_ptr->use_4addr) { |
3305443c JB |
795 | if (vlansdata->u.vlan.sta) { |
796 | rcu_read_unlock(); | |
f14543ee | 797 | return -EBUSY; |
3305443c | 798 | } |
f14543ee FF |
799 | |
800 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); | |
801 | } | |
802 | ||
14db74bc | 803 | sta->sdata = vlansdata; |
4fd6931e JB |
804 | ieee80211_send_layer2_update(sta); |
805 | } | |
806 | ||
807 | sta_apply_parameters(local, sta, params); | |
808 | ||
98dd6a57 JB |
809 | rcu_read_unlock(); |
810 | ||
4fd6931e JB |
811 | return 0; |
812 | } | |
813 | ||
c5dd9c2b LCC |
814 | #ifdef CONFIG_MAC80211_MESH |
815 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, | |
816 | u8 *dst, u8 *next_hop) | |
817 | { | |
14db74bc | 818 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
819 | struct mesh_path *mpath; |
820 | struct sta_info *sta; | |
821 | int err; | |
822 | ||
14db74bc JB |
823 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
824 | ||
d0709a65 | 825 | rcu_read_lock(); |
abe60632 | 826 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
827 | if (!sta) { |
828 | rcu_read_unlock(); | |
c5dd9c2b | 829 | return -ENOENT; |
d0709a65 | 830 | } |
c5dd9c2b | 831 | |
f698d856 | 832 | err = mesh_path_add(dst, sdata); |
d0709a65 JB |
833 | if (err) { |
834 | rcu_read_unlock(); | |
c5dd9c2b | 835 | return err; |
d0709a65 | 836 | } |
c5dd9c2b | 837 | |
f698d856 | 838 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
839 | if (!mpath) { |
840 | rcu_read_unlock(); | |
c5dd9c2b LCC |
841 | return -ENXIO; |
842 | } | |
843 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 844 | |
c5dd9c2b LCC |
845 | rcu_read_unlock(); |
846 | return 0; | |
847 | } | |
848 | ||
849 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, | |
850 | u8 *dst) | |
851 | { | |
f698d856 JBG |
852 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
853 | ||
c5dd9c2b | 854 | if (dst) |
f698d856 | 855 | return mesh_path_del(dst, sdata); |
c5dd9c2b | 856 | |
f698d856 | 857 | mesh_path_flush(sdata); |
c5dd9c2b LCC |
858 | return 0; |
859 | } | |
860 | ||
861 | static int ieee80211_change_mpath(struct wiphy *wiphy, | |
862 | struct net_device *dev, | |
863 | u8 *dst, u8 *next_hop) | |
864 | { | |
14db74bc | 865 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
866 | struct mesh_path *mpath; |
867 | struct sta_info *sta; | |
868 | ||
14db74bc JB |
869 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
870 | ||
d0709a65 JB |
871 | rcu_read_lock(); |
872 | ||
abe60632 | 873 | sta = sta_info_get(sdata, next_hop); |
d0709a65 JB |
874 | if (!sta) { |
875 | rcu_read_unlock(); | |
c5dd9c2b | 876 | return -ENOENT; |
d0709a65 | 877 | } |
c5dd9c2b | 878 | |
f698d856 | 879 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
880 | if (!mpath) { |
881 | rcu_read_unlock(); | |
c5dd9c2b LCC |
882 | return -ENOENT; |
883 | } | |
884 | ||
885 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 886 | |
c5dd9c2b LCC |
887 | rcu_read_unlock(); |
888 | return 0; | |
889 | } | |
890 | ||
891 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, | |
892 | struct mpath_info *pinfo) | |
893 | { | |
894 | if (mpath->next_hop) | |
17741cdc | 895 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
c5dd9c2b LCC |
896 | else |
897 | memset(next_hop, 0, ETH_ALEN); | |
898 | ||
f5ea9120 JB |
899 | pinfo->generation = mesh_paths_generation; |
900 | ||
c5dd9c2b | 901 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
d19b3bf6 | 902 | MPATH_INFO_SN | |
c5dd9c2b LCC |
903 | MPATH_INFO_METRIC | |
904 | MPATH_INFO_EXPTIME | | |
905 | MPATH_INFO_DISCOVERY_TIMEOUT | | |
906 | MPATH_INFO_DISCOVERY_RETRIES | | |
907 | MPATH_INFO_FLAGS; | |
908 | ||
909 | pinfo->frame_qlen = mpath->frame_queue.qlen; | |
d19b3bf6 | 910 | pinfo->sn = mpath->sn; |
c5dd9c2b LCC |
911 | pinfo->metric = mpath->metric; |
912 | if (time_before(jiffies, mpath->exp_time)) | |
913 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); | |
914 | pinfo->discovery_timeout = | |
915 | jiffies_to_msecs(mpath->discovery_timeout); | |
916 | pinfo->discovery_retries = mpath->discovery_retries; | |
917 | pinfo->flags = 0; | |
918 | if (mpath->flags & MESH_PATH_ACTIVE) | |
919 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; | |
920 | if (mpath->flags & MESH_PATH_RESOLVING) | |
921 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
d19b3bf6 RP |
922 | if (mpath->flags & MESH_PATH_SN_VALID) |
923 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; | |
c5dd9c2b LCC |
924 | if (mpath->flags & MESH_PATH_FIXED) |
925 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; | |
926 | if (mpath->flags & MESH_PATH_RESOLVING) | |
927 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
928 | ||
929 | pinfo->flags = mpath->flags; | |
930 | } | |
931 | ||
932 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, | |
933 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) | |
934 | ||
935 | { | |
14db74bc | 936 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
937 | struct mesh_path *mpath; |
938 | ||
14db74bc JB |
939 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
940 | ||
c5dd9c2b | 941 | rcu_read_lock(); |
f698d856 | 942 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
943 | if (!mpath) { |
944 | rcu_read_unlock(); | |
945 | return -ENOENT; | |
946 | } | |
947 | memcpy(dst, mpath->dst, ETH_ALEN); | |
948 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
949 | rcu_read_unlock(); | |
950 | return 0; | |
951 | } | |
952 | ||
953 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, | |
954 | int idx, u8 *dst, u8 *next_hop, | |
955 | struct mpath_info *pinfo) | |
956 | { | |
14db74bc | 957 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
958 | struct mesh_path *mpath; |
959 | ||
14db74bc JB |
960 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
961 | ||
c5dd9c2b | 962 | rcu_read_lock(); |
f698d856 | 963 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
c5dd9c2b LCC |
964 | if (!mpath) { |
965 | rcu_read_unlock(); | |
966 | return -ENOENT; | |
967 | } | |
968 | memcpy(dst, mpath->dst, ETH_ALEN); | |
969 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
970 | rcu_read_unlock(); | |
971 | return 0; | |
972 | } | |
93da9cc1 | 973 | |
974 | static int ieee80211_get_mesh_params(struct wiphy *wiphy, | |
975 | struct net_device *dev, | |
976 | struct mesh_config *conf) | |
977 | { | |
978 | struct ieee80211_sub_if_data *sdata; | |
979 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
980 | ||
93da9cc1 | 981 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
982 | return 0; | |
983 | } | |
984 | ||
985 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) | |
986 | { | |
987 | return (mask >> (parm-1)) & 0x1; | |
988 | } | |
989 | ||
990 | static int ieee80211_set_mesh_params(struct wiphy *wiphy, | |
991 | struct net_device *dev, | |
992 | const struct mesh_config *nconf, u32 mask) | |
993 | { | |
994 | struct mesh_config *conf; | |
995 | struct ieee80211_sub_if_data *sdata; | |
63c5723b RP |
996 | struct ieee80211_if_mesh *ifmsh; |
997 | ||
93da9cc1 | 998 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
63c5723b | 999 | ifmsh = &sdata->u.mesh; |
93da9cc1 | 1000 | |
93da9cc1 | 1001 | /* Set the config options which we are interested in setting */ |
1002 | conf = &(sdata->u.mesh.mshcfg); | |
1003 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) | |
1004 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; | |
1005 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) | |
1006 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; | |
1007 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) | |
1008 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; | |
1009 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) | |
1010 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; | |
1011 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) | |
1012 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; | |
1013 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) | |
1014 | conf->dot11MeshTTL = nconf->dot11MeshTTL; | |
1015 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) | |
1016 | conf->auto_open_plinks = nconf->auto_open_plinks; | |
1017 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) | |
1018 | conf->dot11MeshHWMPmaxPREQretries = | |
1019 | nconf->dot11MeshHWMPmaxPREQretries; | |
1020 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) | |
1021 | conf->path_refresh_time = nconf->path_refresh_time; | |
1022 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) | |
1023 | conf->min_discovery_timeout = nconf->min_discovery_timeout; | |
1024 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) | |
1025 | conf->dot11MeshHWMPactivePathTimeout = | |
1026 | nconf->dot11MeshHWMPactivePathTimeout; | |
1027 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) | |
1028 | conf->dot11MeshHWMPpreqMinInterval = | |
1029 | nconf->dot11MeshHWMPpreqMinInterval; | |
1030 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
1031 | mask)) | |
1032 | conf->dot11MeshHWMPnetDiameterTraversalTime = | |
1033 | nconf->dot11MeshHWMPnetDiameterTraversalTime; | |
63c5723b RP |
1034 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
1035 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; | |
1036 | ieee80211_mesh_root_setup(ifmsh); | |
1037 | } | |
93da9cc1 | 1038 | return 0; |
1039 | } | |
1040 | ||
c5dd9c2b LCC |
1041 | #endif |
1042 | ||
9f1ba906 JM |
1043 | static int ieee80211_change_bss(struct wiphy *wiphy, |
1044 | struct net_device *dev, | |
1045 | struct bss_parameters *params) | |
1046 | { | |
9f1ba906 JM |
1047 | struct ieee80211_sub_if_data *sdata; |
1048 | u32 changed = 0; | |
1049 | ||
9f1ba906 JM |
1050 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1051 | ||
9f1ba906 | 1052 | if (params->use_cts_prot >= 0) { |
bda3933a | 1053 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
9f1ba906 JM |
1054 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
1055 | } | |
1056 | if (params->use_short_preamble >= 0) { | |
bda3933a | 1057 | sdata->vif.bss_conf.use_short_preamble = |
9f1ba906 JM |
1058 | params->use_short_preamble; |
1059 | changed |= BSS_CHANGED_ERP_PREAMBLE; | |
1060 | } | |
43d35343 FF |
1061 | |
1062 | if (!sdata->vif.bss_conf.use_short_slot && | |
1063 | sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) { | |
1064 | sdata->vif.bss_conf.use_short_slot = true; | |
1065 | changed |= BSS_CHANGED_ERP_SLOT; | |
1066 | } | |
1067 | ||
9f1ba906 | 1068 | if (params->use_short_slot_time >= 0) { |
bda3933a | 1069 | sdata->vif.bss_conf.use_short_slot = |
9f1ba906 JM |
1070 | params->use_short_slot_time; |
1071 | changed |= BSS_CHANGED_ERP_SLOT; | |
1072 | } | |
1073 | ||
90c97a04 JM |
1074 | if (params->basic_rates) { |
1075 | int i, j; | |
1076 | u32 rates = 0; | |
1077 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1078 | struct ieee80211_supported_band *sband = | |
1079 | wiphy->bands[local->oper_channel->band]; | |
1080 | ||
1081 | for (i = 0; i < params->basic_rates_len; i++) { | |
1082 | int rate = (params->basic_rates[i] & 0x7f) * 5; | |
1083 | for (j = 0; j < sband->n_bitrates; j++) { | |
1084 | if (sband->bitrates[j].bitrate == rate) | |
1085 | rates |= BIT(j); | |
1086 | } | |
1087 | } | |
1088 | sdata->vif.bss_conf.basic_rates = rates; | |
1089 | changed |= BSS_CHANGED_BASIC_RATES; | |
1090 | } | |
1091 | ||
7b7b5e56 FF |
1092 | if (params->ap_isolate >= 0) { |
1093 | if (params->ap_isolate) | |
1094 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
1095 | else | |
1096 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; | |
1097 | } | |
1098 | ||
9f1ba906 JM |
1099 | ieee80211_bss_info_change_notify(sdata, changed); |
1100 | ||
1101 | return 0; | |
1102 | } | |
1103 | ||
31888487 JM |
1104 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
1105 | struct ieee80211_txq_params *params) | |
1106 | { | |
1107 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1108 | struct ieee80211_tx_queue_params p; | |
1109 | ||
1110 | if (!local->ops->conf_tx) | |
1111 | return -EOPNOTSUPP; | |
1112 | ||
1113 | memset(&p, 0, sizeof(p)); | |
1114 | p.aifs = params->aifs; | |
1115 | p.cw_max = params->cwmax; | |
1116 | p.cw_min = params->cwmin; | |
1117 | p.txop = params->txop; | |
ab13315a KV |
1118 | |
1119 | /* | |
1120 | * Setting tx queue params disables u-apsd because it's only | |
1121 | * called in master mode. | |
1122 | */ | |
1123 | p.uapsd = false; | |
1124 | ||
24487981 | 1125 | if (drv_conf_tx(local, params->queue, &p)) { |
31888487 | 1126 | printk(KERN_DEBUG "%s: failed to set TX queue " |
0bffe40f JB |
1127 | "parameters for queue %d\n", |
1128 | wiphy_name(local->hw.wiphy), params->queue); | |
31888487 JM |
1129 | return -EINVAL; |
1130 | } | |
1131 | ||
1132 | return 0; | |
1133 | } | |
1134 | ||
72bdcf34 | 1135 | static int ieee80211_set_channel(struct wiphy *wiphy, |
f444de05 | 1136 | struct net_device *netdev, |
72bdcf34 | 1137 | struct ieee80211_channel *chan, |
094d05dc | 1138 | enum nl80211_channel_type channel_type) |
72bdcf34 JM |
1139 | { |
1140 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
0aaffa9b JB |
1141 | struct ieee80211_sub_if_data *sdata = NULL; |
1142 | ||
1143 | if (netdev) | |
1144 | sdata = IEEE80211_DEV_TO_SUB_IF(netdev); | |
72bdcf34 | 1145 | |
f444de05 JB |
1146 | switch (ieee80211_get_channel_mode(local, NULL)) { |
1147 | case CHAN_MODE_HOPPING: | |
1148 | return -EBUSY; | |
1149 | case CHAN_MODE_FIXED: | |
0aaffa9b JB |
1150 | if (local->oper_channel != chan) |
1151 | return -EBUSY; | |
1152 | if (!sdata && local->_oper_channel_type == channel_type) | |
f444de05 | 1153 | return 0; |
0aaffa9b | 1154 | break; |
f444de05 JB |
1155 | case CHAN_MODE_UNDEFINED: |
1156 | break; | |
1157 | } | |
72bdcf34 JM |
1158 | |
1159 | local->oper_channel = chan; | |
72bdcf34 | 1160 | |
0aaffa9b JB |
1161 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) |
1162 | return -EBUSY; | |
1163 | ||
1164 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); | |
1165 | if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) | |
1166 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); | |
1167 | ||
1168 | return 0; | |
72bdcf34 JM |
1169 | } |
1170 | ||
665af4fc BC |
1171 | #ifdef CONFIG_PM |
1172 | static int ieee80211_suspend(struct wiphy *wiphy) | |
1173 | { | |
1174 | return __ieee80211_suspend(wiphy_priv(wiphy)); | |
1175 | } | |
1176 | ||
1177 | static int ieee80211_resume(struct wiphy *wiphy) | |
1178 | { | |
1179 | return __ieee80211_resume(wiphy_priv(wiphy)); | |
1180 | } | |
1181 | #else | |
1182 | #define ieee80211_suspend NULL | |
1183 | #define ieee80211_resume NULL | |
1184 | #endif | |
1185 | ||
2a519311 JB |
1186 | static int ieee80211_scan(struct wiphy *wiphy, |
1187 | struct net_device *dev, | |
1188 | struct cfg80211_scan_request *req) | |
1189 | { | |
1190 | struct ieee80211_sub_if_data *sdata; | |
1191 | ||
2a519311 JB |
1192 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1193 | ||
1194 | if (sdata->vif.type != NL80211_IFTYPE_STATION && | |
1195 | sdata->vif.type != NL80211_IFTYPE_ADHOC && | |
357303e2 JM |
1196 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
1197 | (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon)) | |
2a519311 JB |
1198 | return -EOPNOTSUPP; |
1199 | ||
1200 | return ieee80211_request_scan(sdata, req); | |
1201 | } | |
1202 | ||
636a5d36 JM |
1203 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
1204 | struct cfg80211_auth_request *req) | |
1205 | { | |
77fdaa12 | 1206 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
1207 | } |
1208 | ||
1209 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, | |
1210 | struct cfg80211_assoc_request *req) | |
1211 | { | |
f444de05 JB |
1212 | struct ieee80211_local *local = wiphy_priv(wiphy); |
1213 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1214 | ||
1215 | switch (ieee80211_get_channel_mode(local, sdata)) { | |
1216 | case CHAN_MODE_HOPPING: | |
1217 | return -EBUSY; | |
1218 | case CHAN_MODE_FIXED: | |
1219 | if (local->oper_channel == req->bss->channel) | |
1220 | break; | |
1221 | return -EBUSY; | |
1222 | case CHAN_MODE_UNDEFINED: | |
1223 | break; | |
1224 | } | |
1225 | ||
77fdaa12 | 1226 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
636a5d36 JM |
1227 | } |
1228 | ||
1229 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, | |
667503dd JB |
1230 | struct cfg80211_deauth_request *req, |
1231 | void *cookie) | |
636a5d36 | 1232 | { |
667503dd JB |
1233 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), |
1234 | req, cookie); | |
636a5d36 JM |
1235 | } |
1236 | ||
1237 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, | |
667503dd JB |
1238 | struct cfg80211_disassoc_request *req, |
1239 | void *cookie) | |
636a5d36 | 1240 | { |
667503dd JB |
1241 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), |
1242 | req, cookie); | |
636a5d36 JM |
1243 | } |
1244 | ||
af8cdcd8 JB |
1245 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
1246 | struct cfg80211_ibss_params *params) | |
1247 | { | |
f444de05 | 1248 | struct ieee80211_local *local = wiphy_priv(wiphy); |
af8cdcd8 JB |
1249 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1250 | ||
f444de05 JB |
1251 | switch (ieee80211_get_channel_mode(local, sdata)) { |
1252 | case CHAN_MODE_HOPPING: | |
1253 | return -EBUSY; | |
1254 | case CHAN_MODE_FIXED: | |
1255 | if (!params->channel_fixed) | |
1256 | return -EBUSY; | |
1257 | if (local->oper_channel == params->channel) | |
1258 | break; | |
1259 | return -EBUSY; | |
1260 | case CHAN_MODE_UNDEFINED: | |
1261 | break; | |
1262 | } | |
1263 | ||
af8cdcd8 JB |
1264 | return ieee80211_ibss_join(sdata, params); |
1265 | } | |
1266 | ||
1267 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) | |
1268 | { | |
1269 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1270 | ||
1271 | return ieee80211_ibss_leave(sdata); | |
1272 | } | |
1273 | ||
b9a5f8ca JM |
1274 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
1275 | { | |
1276 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
24487981 | 1277 | int err; |
b9a5f8ca | 1278 | |
310bc676 LT |
1279 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) { |
1280 | err = drv_set_coverage_class(local, wiphy->coverage_class); | |
1281 | ||
1282 | if (err) | |
1283 | return err; | |
1284 | } | |
1285 | ||
b9a5f8ca | 1286 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
24487981 | 1287 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
b9a5f8ca | 1288 | |
24487981 JB |
1289 | if (err) |
1290 | return err; | |
b9a5f8ca JM |
1291 | } |
1292 | ||
1293 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1294 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; | |
1295 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1296 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; | |
1297 | if (changed & | |
1298 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) | |
1299 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); | |
1300 | ||
1301 | return 0; | |
1302 | } | |
1303 | ||
7643a2c3 | 1304 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
fa61cf70 | 1305 | enum nl80211_tx_power_setting type, int mbm) |
7643a2c3 JB |
1306 | { |
1307 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1308 | struct ieee80211_channel *chan = local->hw.conf.channel; | |
1309 | u32 changes = 0; | |
7643a2c3 JB |
1310 | |
1311 | switch (type) { | |
fa61cf70 | 1312 | case NL80211_TX_POWER_AUTOMATIC: |
7643a2c3 JB |
1313 | local->user_power_level = -1; |
1314 | break; | |
fa61cf70 JO |
1315 | case NL80211_TX_POWER_LIMITED: |
1316 | if (mbm < 0 || (mbm % 100)) | |
1317 | return -EOPNOTSUPP; | |
1318 | local->user_power_level = MBM_TO_DBM(mbm); | |
7643a2c3 | 1319 | break; |
fa61cf70 JO |
1320 | case NL80211_TX_POWER_FIXED: |
1321 | if (mbm < 0 || (mbm % 100)) | |
1322 | return -EOPNOTSUPP; | |
7643a2c3 | 1323 | /* TODO: move to cfg80211 when it knows the channel */ |
fa61cf70 | 1324 | if (MBM_TO_DBM(mbm) > chan->max_power) |
7643a2c3 | 1325 | return -EINVAL; |
fa61cf70 | 1326 | local->user_power_level = MBM_TO_DBM(mbm); |
7643a2c3 | 1327 | break; |
7643a2c3 JB |
1328 | } |
1329 | ||
1330 | ieee80211_hw_config(local, changes); | |
1331 | ||
1332 | return 0; | |
1333 | } | |
1334 | ||
1335 | static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) | |
1336 | { | |
1337 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1338 | ||
1339 | *dbm = local->hw.conf.power_level; | |
1340 | ||
7643a2c3 JB |
1341 | return 0; |
1342 | } | |
1343 | ||
ab737a4f JB |
1344 | static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev, |
1345 | u8 *addr) | |
1346 | { | |
1347 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1348 | ||
1349 | memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN); | |
1350 | ||
1351 | return 0; | |
1352 | } | |
1353 | ||
1f87f7d3 JB |
1354 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
1355 | { | |
1356 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1357 | ||
1358 | drv_rfkill_poll(local); | |
1359 | } | |
1360 | ||
aff89a9b | 1361 | #ifdef CONFIG_NL80211_TESTMODE |
99783e2c | 1362 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len) |
aff89a9b JB |
1363 | { |
1364 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
1365 | ||
1366 | if (!local->ops->testmode_cmd) | |
1367 | return -EOPNOTSUPP; | |
1368 | ||
1369 | return local->ops->testmode_cmd(&local->hw, data, len); | |
1370 | } | |
1371 | #endif | |
1372 | ||
0f78231b JB |
1373 | int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata, |
1374 | enum ieee80211_smps_mode smps_mode) | |
1375 | { | |
1376 | const u8 *ap; | |
1377 | enum ieee80211_smps_mode old_req; | |
1378 | int err; | |
1379 | ||
1380 | old_req = sdata->u.mgd.req_smps; | |
1381 | sdata->u.mgd.req_smps = smps_mode; | |
1382 | ||
1383 | if (old_req == smps_mode && | |
1384 | smps_mode != IEEE80211_SMPS_AUTOMATIC) | |
1385 | return 0; | |
1386 | ||
1387 | /* | |
1388 | * If not associated, or current association is not an HT | |
1389 | * association, there's no need to send an action frame. | |
1390 | */ | |
1391 | if (!sdata->u.mgd.associated || | |
0aaffa9b | 1392 | sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) { |
0f78231b JB |
1393 | mutex_lock(&sdata->local->iflist_mtx); |
1394 | ieee80211_recalc_smps(sdata->local, sdata); | |
1395 | mutex_unlock(&sdata->local->iflist_mtx); | |
1396 | return 0; | |
1397 | } | |
1398 | ||
0c1ad2ca | 1399 | ap = sdata->u.mgd.associated->bssid; |
0f78231b JB |
1400 | |
1401 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { | |
1402 | if (sdata->u.mgd.powersave) | |
1403 | smps_mode = IEEE80211_SMPS_DYNAMIC; | |
1404 | else | |
1405 | smps_mode = IEEE80211_SMPS_OFF; | |
1406 | } | |
1407 | ||
1408 | /* send SM PS frame to AP */ | |
1409 | err = ieee80211_send_smps_action(sdata, smps_mode, | |
1410 | ap, ap); | |
1411 | if (err) | |
1412 | sdata->u.mgd.req_smps = old_req; | |
1413 | ||
1414 | return err; | |
1415 | } | |
1416 | ||
bc92afd9 JB |
1417 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
1418 | bool enabled, int timeout) | |
1419 | { | |
1420 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1421 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
bc92afd9 | 1422 | |
e5de30c9 BP |
1423 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
1424 | return -EOPNOTSUPP; | |
1425 | ||
bc92afd9 JB |
1426 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
1427 | return -EOPNOTSUPP; | |
1428 | ||
1429 | if (enabled == sdata->u.mgd.powersave && | |
ff616381 | 1430 | timeout == local->dynamic_ps_forced_timeout) |
bc92afd9 JB |
1431 | return 0; |
1432 | ||
1433 | sdata->u.mgd.powersave = enabled; | |
ff616381 | 1434 | local->dynamic_ps_forced_timeout = timeout; |
bc92afd9 | 1435 | |
0f78231b JB |
1436 | /* no change, but if automatic follow powersave */ |
1437 | mutex_lock(&sdata->u.mgd.mtx); | |
1438 | __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps); | |
1439 | mutex_unlock(&sdata->u.mgd.mtx); | |
1440 | ||
bc92afd9 JB |
1441 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
1442 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
1443 | ||
1444 | ieee80211_recalc_ps(local, -1); | |
1445 | ||
1446 | return 0; | |
1447 | } | |
1448 | ||
a97c13c3 JO |
1449 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
1450 | struct net_device *dev, | |
1451 | s32 rssi_thold, u32 rssi_hyst) | |
1452 | { | |
1453 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1454 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1455 | struct ieee80211_vif *vif = &sdata->vif; | |
1456 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
1457 | ||
a97c13c3 JO |
1458 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
1459 | rssi_hyst == bss_conf->cqm_rssi_hyst) | |
1460 | return 0; | |
1461 | ||
1462 | bss_conf->cqm_rssi_thold = rssi_thold; | |
1463 | bss_conf->cqm_rssi_hyst = rssi_hyst; | |
1464 | ||
17e4ec14 JM |
1465 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) { |
1466 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | |
1467 | return -EOPNOTSUPP; | |
1468 | return 0; | |
1469 | } | |
1470 | ||
a97c13c3 JO |
1471 | /* tell the driver upon association, unless already associated */ |
1472 | if (sdata->u.mgd.associated) | |
1473 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); | |
1474 | ||
1475 | return 0; | |
1476 | } | |
1477 | ||
9930380f JB |
1478 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
1479 | struct net_device *dev, | |
1480 | const u8 *addr, | |
1481 | const struct cfg80211_bitrate_mask *mask) | |
1482 | { | |
1483 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1484 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
2c7e6bc9 | 1485 | int i; |
9930380f | 1486 | |
2c7e6bc9 JB |
1487 | /* |
1488 | * This _could_ be supported by providing a hook for | |
1489 | * drivers for this function, but at this point it | |
1490 | * doesn't seem worth bothering. | |
1491 | */ | |
1492 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) | |
1493 | return -EOPNOTSUPP; | |
1494 | ||
9930380f | 1495 | |
37eb0b16 JM |
1496 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
1497 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; | |
9930380f | 1498 | |
37eb0b16 | 1499 | return 0; |
9930380f JB |
1500 | } |
1501 | ||
b8bc4b0a JB |
1502 | static int ieee80211_remain_on_channel(struct wiphy *wiphy, |
1503 | struct net_device *dev, | |
1504 | struct ieee80211_channel *chan, | |
1505 | enum nl80211_channel_type channel_type, | |
1506 | unsigned int duration, | |
1507 | u64 *cookie) | |
1508 | { | |
1509 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1510 | ||
1511 | return ieee80211_wk_remain_on_channel(sdata, chan, channel_type, | |
1512 | duration, cookie); | |
1513 | } | |
1514 | ||
1515 | static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, | |
1516 | struct net_device *dev, | |
1517 | u64 cookie) | |
1518 | { | |
1519 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1520 | ||
1521 | return ieee80211_wk_cancel_remain_on_channel(sdata, cookie); | |
1522 | } | |
1523 | ||
2e161f78 JB |
1524 | static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, |
1525 | struct ieee80211_channel *chan, | |
1526 | enum nl80211_channel_type channel_type, | |
1527 | bool channel_type_valid, | |
1528 | const u8 *buf, size_t len, u64 *cookie) | |
026331c4 | 1529 | { |
9d38d85d JB |
1530 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
1531 | struct ieee80211_local *local = sdata->local; | |
1532 | struct sk_buff *skb; | |
1533 | struct sta_info *sta; | |
1534 | const struct ieee80211_mgmt *mgmt = (void *)buf; | |
1535 | u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | | |
1536 | IEEE80211_TX_CTL_REQ_TX_STATUS; | |
1537 | ||
1538 | /* Check that we are on the requested channel for transmission */ | |
1539 | if (chan != local->tmp_channel && | |
1540 | chan != local->oper_channel) | |
1541 | return -EBUSY; | |
1542 | if (channel_type_valid && | |
1543 | (channel_type != local->tmp_channel_type && | |
1544 | channel_type != local->_oper_channel_type)) | |
1545 | return -EBUSY; | |
1546 | ||
1547 | switch (sdata->vif.type) { | |
1548 | case NL80211_IFTYPE_ADHOC: | |
1549 | if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) | |
1550 | break; | |
1551 | rcu_read_lock(); | |
1552 | sta = sta_info_get(sdata, mgmt->da); | |
1553 | rcu_read_unlock(); | |
1554 | if (!sta) | |
1555 | return -ENOLINK; | |
1556 | break; | |
1557 | case NL80211_IFTYPE_STATION: | |
9d38d85d JB |
1558 | break; |
1559 | default: | |
1560 | return -EOPNOTSUPP; | |
1561 | } | |
1562 | ||
1563 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + len); | |
1564 | if (!skb) | |
1565 | return -ENOMEM; | |
1566 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1567 | ||
1568 | memcpy(skb_put(skb, len), buf, len); | |
1569 | ||
1570 | IEEE80211_SKB_CB(skb)->flags = flags; | |
1571 | ||
1572 | skb->dev = sdata->dev; | |
1573 | ieee80211_tx_skb(sdata, skb); | |
1574 | ||
1575 | *cookie = (unsigned long) skb; | |
1576 | return 0; | |
026331c4 JM |
1577 | } |
1578 | ||
f0706e82 JB |
1579 | struct cfg80211_ops mac80211_config_ops = { |
1580 | .add_virtual_intf = ieee80211_add_iface, | |
1581 | .del_virtual_intf = ieee80211_del_iface, | |
42613db7 | 1582 | .change_virtual_intf = ieee80211_change_iface, |
e8cbb4cb JB |
1583 | .add_key = ieee80211_add_key, |
1584 | .del_key = ieee80211_del_key, | |
62da92fb | 1585 | .get_key = ieee80211_get_key, |
e8cbb4cb | 1586 | .set_default_key = ieee80211_config_default_key, |
3cfcf6ac | 1587 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
5dfdaf58 JB |
1588 | .add_beacon = ieee80211_add_beacon, |
1589 | .set_beacon = ieee80211_set_beacon, | |
1590 | .del_beacon = ieee80211_del_beacon, | |
4fd6931e JB |
1591 | .add_station = ieee80211_add_station, |
1592 | .del_station = ieee80211_del_station, | |
1593 | .change_station = ieee80211_change_station, | |
7bbdd2d9 | 1594 | .get_station = ieee80211_get_station, |
c5dd9c2b | 1595 | .dump_station = ieee80211_dump_station, |
1289723e | 1596 | .dump_survey = ieee80211_dump_survey, |
c5dd9c2b LCC |
1597 | #ifdef CONFIG_MAC80211_MESH |
1598 | .add_mpath = ieee80211_add_mpath, | |
1599 | .del_mpath = ieee80211_del_mpath, | |
1600 | .change_mpath = ieee80211_change_mpath, | |
1601 | .get_mpath = ieee80211_get_mpath, | |
1602 | .dump_mpath = ieee80211_dump_mpath, | |
93da9cc1 | 1603 | .set_mesh_params = ieee80211_set_mesh_params, |
1604 | .get_mesh_params = ieee80211_get_mesh_params, | |
c5dd9c2b | 1605 | #endif |
9f1ba906 | 1606 | .change_bss = ieee80211_change_bss, |
31888487 | 1607 | .set_txq_params = ieee80211_set_txq_params, |
72bdcf34 | 1608 | .set_channel = ieee80211_set_channel, |
665af4fc BC |
1609 | .suspend = ieee80211_suspend, |
1610 | .resume = ieee80211_resume, | |
2a519311 | 1611 | .scan = ieee80211_scan, |
636a5d36 JM |
1612 | .auth = ieee80211_auth, |
1613 | .assoc = ieee80211_assoc, | |
1614 | .deauth = ieee80211_deauth, | |
1615 | .disassoc = ieee80211_disassoc, | |
af8cdcd8 JB |
1616 | .join_ibss = ieee80211_join_ibss, |
1617 | .leave_ibss = ieee80211_leave_ibss, | |
b9a5f8ca | 1618 | .set_wiphy_params = ieee80211_set_wiphy_params, |
7643a2c3 JB |
1619 | .set_tx_power = ieee80211_set_tx_power, |
1620 | .get_tx_power = ieee80211_get_tx_power, | |
ab737a4f | 1621 | .set_wds_peer = ieee80211_set_wds_peer, |
1f87f7d3 | 1622 | .rfkill_poll = ieee80211_rfkill_poll, |
aff89a9b | 1623 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
bc92afd9 | 1624 | .set_power_mgmt = ieee80211_set_power_mgmt, |
9930380f | 1625 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
b8bc4b0a JB |
1626 | .remain_on_channel = ieee80211_remain_on_channel, |
1627 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, | |
2e161f78 | 1628 | .mgmt_tx = ieee80211_mgmt_tx, |
a97c13c3 | 1629 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
f0706e82 | 1630 | }; |