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