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