]>
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" | |
e0eb6859 | 16 | #include "cfg.h" |
2c8dccc7 | 17 | #include "rate.h" |
c5dd9c2b | 18 | #include "mesh.h" |
c5dd9c2b | 19 | |
05c914fe | 20 | static bool nl80211_type_check(enum nl80211_iftype type) |
42613db7 JB |
21 | { |
22 | switch (type) { | |
42613db7 | 23 | case NL80211_IFTYPE_ADHOC: |
42613db7 | 24 | case NL80211_IFTYPE_STATION: |
42613db7 | 25 | case NL80211_IFTYPE_MONITOR: |
c5dd9c2b LCC |
26 | #ifdef CONFIG_MAC80211_MESH |
27 | case NL80211_IFTYPE_MESH_POINT: | |
c5dd9c2b | 28 | #endif |
b454048c | 29 | case NL80211_IFTYPE_WDS: |
05c914fe | 30 | return true; |
42613db7 | 31 | default: |
05c914fe | 32 | return false; |
42613db7 JB |
33 | } |
34 | } | |
35 | ||
f0706e82 | 36 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
2ec600d6 LCC |
37 | enum nl80211_iftype type, u32 *flags, |
38 | struct vif_params *params) | |
f0706e82 JB |
39 | { |
40 | struct ieee80211_local *local = wiphy_priv(wiphy); | |
8cc9a739 MW |
41 | struct net_device *dev; |
42 | struct ieee80211_sub_if_data *sdata; | |
43 | int err; | |
f0706e82 | 44 | |
05c914fe | 45 | if (!nl80211_type_check(type)) |
f0706e82 | 46 | return -EINVAL; |
f0706e82 | 47 | |
05c914fe JB |
48 | err = ieee80211_if_add(local, name, &dev, type, params); |
49 | if (err || type != NL80211_IFTYPE_MONITOR || !flags) | |
8cc9a739 MW |
50 | return err; |
51 | ||
52 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
53 | sdata->u.mntr_flags = *flags; | |
54 | return 0; | |
f0706e82 JB |
55 | } |
56 | ||
57 | static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) | |
58 | { | |
f0706e82 | 59 | struct net_device *dev; |
f698d856 | 60 | struct ieee80211_sub_if_data *sdata; |
f0706e82 | 61 | |
42613db7 JB |
62 | /* we're under RTNL */ |
63 | dev = __dev_get_by_index(&init_net, ifindex); | |
f0706e82 | 64 | if (!dev) |
75636525 | 65 | return -ENODEV; |
f0706e82 | 66 | |
f698d856 JBG |
67 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
68 | ||
69 | ieee80211_if_remove(sdata); | |
f0706e82 | 70 | |
75636525 | 71 | return 0; |
f0706e82 JB |
72 | } |
73 | ||
42613db7 | 74 | static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, |
2ec600d6 LCC |
75 | enum nl80211_iftype type, u32 *flags, |
76 | struct vif_params *params) | |
42613db7 | 77 | { |
42613db7 | 78 | struct net_device *dev; |
42613db7 | 79 | struct ieee80211_sub_if_data *sdata; |
f3947e2d | 80 | int ret; |
42613db7 | 81 | |
42613db7 JB |
82 | /* we're under RTNL */ |
83 | dev = __dev_get_by_index(&init_net, ifindex); | |
84 | if (!dev) | |
85 | return -ENODEV; | |
86 | ||
05c914fe | 87 | if (!nl80211_type_check(type)) |
42613db7 JB |
88 | return -EINVAL; |
89 | ||
90 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
91 | ||
05c914fe | 92 | ret = ieee80211_if_change_type(sdata, type); |
f3947e2d JB |
93 | if (ret) |
94 | return ret; | |
42613db7 | 95 | |
f8b25cda JB |
96 | if (netif_running(sdata->dev)) |
97 | return -EBUSY; | |
98 | ||
902acc78 | 99 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
472dbc45 JB |
100 | ieee80211_sdata_set_mesh_id(sdata, |
101 | params->mesh_id_len, | |
102 | params->mesh_id); | |
c5dd9c2b | 103 | |
05c914fe | 104 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags) |
8cc9a739 MW |
105 | return 0; |
106 | ||
107 | sdata->u.mntr_flags = *flags; | |
42613db7 JB |
108 | return 0; |
109 | } | |
110 | ||
e8cbb4cb JB |
111 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
112 | u8 key_idx, u8 *mac_addr, | |
113 | struct key_params *params) | |
114 | { | |
115 | struct ieee80211_sub_if_data *sdata; | |
116 | struct sta_info *sta = NULL; | |
117 | enum ieee80211_key_alg alg; | |
db4d1169 | 118 | struct ieee80211_key *key; |
3b96766f | 119 | int err; |
e8cbb4cb JB |
120 | |
121 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
122 | ||
123 | switch (params->cipher) { | |
124 | case WLAN_CIPHER_SUITE_WEP40: | |
125 | case WLAN_CIPHER_SUITE_WEP104: | |
126 | alg = ALG_WEP; | |
127 | break; | |
128 | case WLAN_CIPHER_SUITE_TKIP: | |
129 | alg = ALG_TKIP; | |
130 | break; | |
131 | case WLAN_CIPHER_SUITE_CCMP: | |
132 | alg = ALG_CCMP; | |
133 | break; | |
134 | default: | |
135 | return -EINVAL; | |
136 | } | |
137 | ||
db4d1169 JB |
138 | key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key); |
139 | if (!key) | |
140 | return -ENOMEM; | |
141 | ||
3b96766f JB |
142 | rcu_read_lock(); |
143 | ||
e8cbb4cb JB |
144 | if (mac_addr) { |
145 | sta = sta_info_get(sdata->local, mac_addr); | |
db4d1169 JB |
146 | if (!sta) { |
147 | ieee80211_key_free(key); | |
3b96766f JB |
148 | err = -ENOENT; |
149 | goto out_unlock; | |
db4d1169 | 150 | } |
e8cbb4cb JB |
151 | } |
152 | ||
db4d1169 JB |
153 | ieee80211_key_link(key, sdata, sta); |
154 | ||
3b96766f JB |
155 | err = 0; |
156 | out_unlock: | |
157 | rcu_read_unlock(); | |
158 | ||
159 | return err; | |
e8cbb4cb JB |
160 | } |
161 | ||
162 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, | |
163 | u8 key_idx, u8 *mac_addr) | |
164 | { | |
165 | struct ieee80211_sub_if_data *sdata; | |
166 | struct sta_info *sta; | |
167 | int ret; | |
168 | ||
169 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
170 | ||
3b96766f JB |
171 | rcu_read_lock(); |
172 | ||
e8cbb4cb | 173 | if (mac_addr) { |
3b96766f JB |
174 | ret = -ENOENT; |
175 | ||
e8cbb4cb JB |
176 | sta = sta_info_get(sdata->local, mac_addr); |
177 | if (!sta) | |
3b96766f | 178 | goto out_unlock; |
e8cbb4cb | 179 | |
db4d1169 | 180 | if (sta->key) { |
d0709a65 | 181 | ieee80211_key_free(sta->key); |
db4d1169 | 182 | WARN_ON(sta->key); |
3b96766f JB |
183 | ret = 0; |
184 | } | |
e8cbb4cb | 185 | |
3b96766f | 186 | goto out_unlock; |
e8cbb4cb JB |
187 | } |
188 | ||
3b96766f JB |
189 | if (!sdata->keys[key_idx]) { |
190 | ret = -ENOENT; | |
191 | goto out_unlock; | |
192 | } | |
e8cbb4cb | 193 | |
d0709a65 | 194 | ieee80211_key_free(sdata->keys[key_idx]); |
db4d1169 | 195 | WARN_ON(sdata->keys[key_idx]); |
e8cbb4cb | 196 | |
3b96766f JB |
197 | ret = 0; |
198 | out_unlock: | |
199 | rcu_read_unlock(); | |
200 | ||
201 | return ret; | |
e8cbb4cb JB |
202 | } |
203 | ||
62da92fb JB |
204 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
205 | u8 key_idx, u8 *mac_addr, void *cookie, | |
206 | void (*callback)(void *cookie, | |
207 | struct key_params *params)) | |
208 | { | |
14db74bc | 209 | struct ieee80211_sub_if_data *sdata; |
62da92fb JB |
210 | struct sta_info *sta = NULL; |
211 | u8 seq[6] = {0}; | |
212 | struct key_params params; | |
213 | struct ieee80211_key *key; | |
214 | u32 iv32; | |
215 | u16 iv16; | |
216 | int err = -ENOENT; | |
217 | ||
14db74bc JB |
218 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
219 | ||
3b96766f JB |
220 | rcu_read_lock(); |
221 | ||
62da92fb JB |
222 | if (mac_addr) { |
223 | sta = sta_info_get(sdata->local, mac_addr); | |
224 | if (!sta) | |
225 | goto out; | |
226 | ||
227 | key = sta->key; | |
228 | } else | |
229 | key = sdata->keys[key_idx]; | |
230 | ||
231 | if (!key) | |
232 | goto out; | |
233 | ||
234 | memset(¶ms, 0, sizeof(params)); | |
235 | ||
236 | switch (key->conf.alg) { | |
237 | case ALG_TKIP: | |
238 | params.cipher = WLAN_CIPHER_SUITE_TKIP; | |
239 | ||
b0f76b33 HH |
240 | iv32 = key->u.tkip.tx.iv32; |
241 | iv16 = key->u.tkip.tx.iv16; | |
62da92fb JB |
242 | |
243 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && | |
244 | sdata->local->ops->get_tkip_seq) | |
245 | sdata->local->ops->get_tkip_seq( | |
246 | local_to_hw(sdata->local), | |
247 | key->conf.hw_key_idx, | |
248 | &iv32, &iv16); | |
249 | ||
250 | seq[0] = iv16 & 0xff; | |
251 | seq[1] = (iv16 >> 8) & 0xff; | |
252 | seq[2] = iv32 & 0xff; | |
253 | seq[3] = (iv32 >> 8) & 0xff; | |
254 | seq[4] = (iv32 >> 16) & 0xff; | |
255 | seq[5] = (iv32 >> 24) & 0xff; | |
256 | params.seq = seq; | |
257 | params.seq_len = 6; | |
258 | break; | |
259 | case ALG_CCMP: | |
260 | params.cipher = WLAN_CIPHER_SUITE_CCMP; | |
261 | seq[0] = key->u.ccmp.tx_pn[5]; | |
262 | seq[1] = key->u.ccmp.tx_pn[4]; | |
263 | seq[2] = key->u.ccmp.tx_pn[3]; | |
264 | seq[3] = key->u.ccmp.tx_pn[2]; | |
265 | seq[4] = key->u.ccmp.tx_pn[1]; | |
266 | seq[5] = key->u.ccmp.tx_pn[0]; | |
267 | params.seq = seq; | |
268 | params.seq_len = 6; | |
269 | break; | |
270 | case ALG_WEP: | |
271 | if (key->conf.keylen == 5) | |
272 | params.cipher = WLAN_CIPHER_SUITE_WEP40; | |
273 | else | |
274 | params.cipher = WLAN_CIPHER_SUITE_WEP104; | |
275 | break; | |
276 | } | |
277 | ||
278 | params.key = key->conf.key; | |
279 | params.key_len = key->conf.keylen; | |
280 | ||
281 | callback(cookie, ¶ms); | |
282 | err = 0; | |
283 | ||
284 | out: | |
3b96766f | 285 | rcu_read_unlock(); |
62da92fb JB |
286 | return err; |
287 | } | |
288 | ||
e8cbb4cb JB |
289 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
290 | struct net_device *dev, | |
291 | u8 key_idx) | |
292 | { | |
293 | struct ieee80211_sub_if_data *sdata; | |
294 | ||
3b96766f JB |
295 | rcu_read_lock(); |
296 | ||
e8cbb4cb JB |
297 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
298 | ieee80211_set_default_key(sdata, key_idx); | |
299 | ||
3b96766f JB |
300 | rcu_read_unlock(); |
301 | ||
e8cbb4cb JB |
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 LCC |
308 | |
309 | sinfo->filled = STATION_INFO_INACTIVE_TIME | | |
310 | STATION_INFO_RX_BYTES | | |
311 | STATION_INFO_TX_BYTES; | |
312 | ||
313 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); | |
314 | sinfo->rx_bytes = sta->rx_bytes; | |
315 | sinfo->tx_bytes = sta->tx_bytes; | |
316 | ||
902acc78 | 317 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
c5dd9c2b | 318 | #ifdef CONFIG_MAC80211_MESH |
c5dd9c2b LCC |
319 | sinfo->filled |= STATION_INFO_LLID | |
320 | STATION_INFO_PLID | | |
321 | STATION_INFO_PLINK_STATE; | |
322 | ||
323 | sinfo->llid = le16_to_cpu(sta->llid); | |
324 | sinfo->plid = le16_to_cpu(sta->plid); | |
325 | sinfo->plink_state = sta->plink_state; | |
c5dd9c2b | 326 | #endif |
902acc78 | 327 | } |
c5dd9c2b LCC |
328 | } |
329 | ||
330 | ||
331 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, | |
332 | int idx, u8 *mac, struct station_info *sinfo) | |
333 | { | |
334 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
335 | struct sta_info *sta; | |
d0709a65 JB |
336 | int ret = -ENOENT; |
337 | ||
338 | rcu_read_lock(); | |
c5dd9c2b LCC |
339 | |
340 | sta = sta_info_get_by_idx(local, idx, dev); | |
d0709a65 JB |
341 | if (sta) { |
342 | ret = 0; | |
17741cdc | 343 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
d0709a65 JB |
344 | sta_set_sinfo(sta, sinfo); |
345 | } | |
c5dd9c2b | 346 | |
d0709a65 | 347 | rcu_read_unlock(); |
c5dd9c2b | 348 | |
d0709a65 | 349 | return ret; |
c5dd9c2b LCC |
350 | } |
351 | ||
7bbdd2d9 | 352 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
2ec600d6 | 353 | u8 *mac, struct station_info *sinfo) |
7bbdd2d9 JB |
354 | { |
355 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
356 | struct sta_info *sta; | |
d0709a65 | 357 | int ret = -ENOENT; |
7bbdd2d9 | 358 | |
d0709a65 | 359 | rcu_read_lock(); |
7bbdd2d9 JB |
360 | |
361 | /* XXX: verify sta->dev == dev */ | |
7bbdd2d9 | 362 | |
d0709a65 JB |
363 | sta = sta_info_get(local, mac); |
364 | if (sta) { | |
365 | ret = 0; | |
366 | sta_set_sinfo(sta, sinfo); | |
367 | } | |
368 | ||
369 | rcu_read_unlock(); | |
370 | ||
371 | return ret; | |
7bbdd2d9 JB |
372 | } |
373 | ||
5dfdaf58 JB |
374 | /* |
375 | * This handles both adding a beacon and setting new beacon info | |
376 | */ | |
377 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, | |
378 | struct beacon_parameters *params) | |
379 | { | |
380 | struct beacon_data *new, *old; | |
381 | int new_head_len, new_tail_len; | |
382 | int size; | |
383 | int err = -EINVAL; | |
384 | ||
385 | old = sdata->u.ap.beacon; | |
386 | ||
387 | /* head must not be zero-length */ | |
388 | if (params->head && !params->head_len) | |
389 | return -EINVAL; | |
390 | ||
391 | /* | |
392 | * This is a kludge. beacon interval should really be part | |
393 | * of the beacon information. | |
394 | */ | |
395 | if (params->interval) { | |
396 | sdata->local->hw.conf.beacon_int = params->interval; | |
d73782fd | 397 | ieee80211_hw_config(sdata->local); |
5dfdaf58 JB |
398 | /* |
399 | * We updated some parameter so if below bails out | |
400 | * it's not an error. | |
401 | */ | |
402 | err = 0; | |
403 | } | |
404 | ||
405 | /* Need to have a beacon head if we don't have one yet */ | |
406 | if (!params->head && !old) | |
407 | return err; | |
408 | ||
409 | /* sorry, no way to start beaconing without dtim period */ | |
410 | if (!params->dtim_period && !old) | |
411 | return err; | |
412 | ||
413 | /* new or old head? */ | |
414 | if (params->head) | |
415 | new_head_len = params->head_len; | |
416 | else | |
417 | new_head_len = old->head_len; | |
418 | ||
419 | /* new or old tail? */ | |
420 | if (params->tail || !old) | |
421 | /* params->tail_len will be zero for !params->tail */ | |
422 | new_tail_len = params->tail_len; | |
423 | else | |
424 | new_tail_len = old->tail_len; | |
425 | ||
426 | size = sizeof(*new) + new_head_len + new_tail_len; | |
427 | ||
428 | new = kzalloc(size, GFP_KERNEL); | |
429 | if (!new) | |
430 | return -ENOMEM; | |
431 | ||
432 | /* start filling the new info now */ | |
433 | ||
434 | /* new or old dtim period? */ | |
435 | if (params->dtim_period) | |
436 | new->dtim_period = params->dtim_period; | |
437 | else | |
438 | new->dtim_period = old->dtim_period; | |
439 | ||
440 | /* | |
441 | * pointers go into the block we allocated, | |
442 | * memory is | beacon_data | head | tail | | |
443 | */ | |
444 | new->head = ((u8 *) new) + sizeof(*new); | |
445 | new->tail = new->head + new_head_len; | |
446 | new->head_len = new_head_len; | |
447 | new->tail_len = new_tail_len; | |
448 | ||
449 | /* copy in head */ | |
450 | if (params->head) | |
451 | memcpy(new->head, params->head, new_head_len); | |
452 | else | |
453 | memcpy(new->head, old->head, new_head_len); | |
454 | ||
455 | /* copy in optional tail */ | |
456 | if (params->tail) | |
457 | memcpy(new->tail, params->tail, new_tail_len); | |
458 | else | |
459 | if (old) | |
460 | memcpy(new->tail, old->tail, new_tail_len); | |
461 | ||
462 | rcu_assign_pointer(sdata->u.ap.beacon, new); | |
463 | ||
464 | synchronize_rcu(); | |
465 | ||
466 | kfree(old); | |
467 | ||
9d139c81 | 468 | return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
5dfdaf58 JB |
469 | } |
470 | ||
471 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, | |
472 | struct beacon_parameters *params) | |
473 | { | |
14db74bc | 474 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
475 | struct beacon_data *old; |
476 | ||
14db74bc JB |
477 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
478 | ||
05c914fe | 479 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
5dfdaf58 JB |
480 | return -EINVAL; |
481 | ||
482 | old = sdata->u.ap.beacon; | |
483 | ||
484 | if (old) | |
485 | return -EALREADY; | |
486 | ||
487 | return ieee80211_config_beacon(sdata, params); | |
488 | } | |
489 | ||
490 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, | |
491 | struct beacon_parameters *params) | |
492 | { | |
14db74bc | 493 | struct ieee80211_sub_if_data *sdata; |
5dfdaf58 JB |
494 | struct beacon_data *old; |
495 | ||
14db74bc JB |
496 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
497 | ||
05c914fe | 498 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
5dfdaf58 JB |
499 | return -EINVAL; |
500 | ||
501 | old = sdata->u.ap.beacon; | |
502 | ||
503 | if (!old) | |
504 | return -ENOENT; | |
505 | ||
506 | return ieee80211_config_beacon(sdata, params); | |
507 | } | |
508 | ||
509 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) | |
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 | ||
05c914fe | 516 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
5dfdaf58 JB |
517 | return -EINVAL; |
518 | ||
519 | old = sdata->u.ap.beacon; | |
520 | ||
521 | if (!old) | |
522 | return -ENOENT; | |
523 | ||
524 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); | |
525 | synchronize_rcu(); | |
526 | kfree(old); | |
527 | ||
9d139c81 | 528 | return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
5dfdaf58 JB |
529 | } |
530 | ||
4fd6931e JB |
531 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
532 | struct iapp_layer2_update { | |
533 | u8 da[ETH_ALEN]; /* broadcast */ | |
534 | u8 sa[ETH_ALEN]; /* STA addr */ | |
535 | __be16 len; /* 6 */ | |
536 | u8 dsap; /* 0 */ | |
537 | u8 ssap; /* 0 */ | |
538 | u8 control; | |
539 | u8 xid_info[3]; | |
540 | } __attribute__ ((packed)); | |
541 | ||
542 | static void ieee80211_send_layer2_update(struct sta_info *sta) | |
543 | { | |
544 | struct iapp_layer2_update *msg; | |
545 | struct sk_buff *skb; | |
546 | ||
547 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 | |
548 | * bridge devices */ | |
549 | ||
550 | skb = dev_alloc_skb(sizeof(*msg)); | |
551 | if (!skb) | |
552 | return; | |
553 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); | |
554 | ||
555 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) | |
556 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ | |
557 | ||
558 | memset(msg->da, 0xff, ETH_ALEN); | |
17741cdc | 559 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
4fd6931e JB |
560 | msg->len = htons(6); |
561 | msg->dsap = 0; | |
562 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ | |
563 | msg->control = 0xaf; /* XID response lsb.1111F101. | |
564 | * F=0 (no poll command; unsolicited frame) */ | |
565 | msg->xid_info[0] = 0x81; /* XID format identifier */ | |
566 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ | |
567 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ | |
568 | ||
d0709a65 JB |
569 | skb->dev = sta->sdata->dev; |
570 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); | |
4fd6931e JB |
571 | memset(skb->cb, 0, sizeof(skb->cb)); |
572 | netif_rx(skb); | |
573 | } | |
574 | ||
575 | static void sta_apply_parameters(struct ieee80211_local *local, | |
576 | struct sta_info *sta, | |
577 | struct station_parameters *params) | |
578 | { | |
579 | u32 rates; | |
580 | int i, j; | |
8318d78a | 581 | struct ieee80211_supported_band *sband; |
d0709a65 | 582 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
4fd6931e | 583 | |
73651ee6 JB |
584 | /* |
585 | * FIXME: updating the flags is racy when this function is | |
586 | * called from ieee80211_change_station(), this will | |
587 | * be resolved in a future patch. | |
588 | */ | |
589 | ||
4fd6931e | 590 | if (params->station_flags & STATION_FLAG_CHANGED) { |
07346f81 | 591 | spin_lock_bh(&sta->lock); |
4fd6931e JB |
592 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
593 | if (params->station_flags & STATION_FLAG_AUTHORIZED) | |
594 | sta->flags |= WLAN_STA_AUTHORIZED; | |
595 | ||
596 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; | |
597 | if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE) | |
598 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; | |
599 | ||
600 | sta->flags &= ~WLAN_STA_WME; | |
601 | if (params->station_flags & STATION_FLAG_WME) | |
602 | sta->flags |= WLAN_STA_WME; | |
07346f81 | 603 | spin_unlock_bh(&sta->lock); |
4fd6931e JB |
604 | } |
605 | ||
73651ee6 JB |
606 | /* |
607 | * FIXME: updating the following information is racy when this | |
608 | * function is called from ieee80211_change_station(). | |
609 | * However, all this information should be static so | |
610 | * maybe we should just reject attemps to change it. | |
611 | */ | |
612 | ||
4fd6931e | 613 | if (params->aid) { |
17741cdc JB |
614 | sta->sta.aid = params->aid; |
615 | if (sta->sta.aid > IEEE80211_MAX_AID) | |
616 | sta->sta.aid = 0; /* XXX: should this be an error? */ | |
4fd6931e JB |
617 | } |
618 | ||
619 | if (params->listen_interval >= 0) | |
620 | sta->listen_interval = params->listen_interval; | |
621 | ||
622 | if (params->supported_rates) { | |
623 | rates = 0; | |
8318d78a JB |
624 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
625 | ||
4fd6931e JB |
626 | for (i = 0; i < params->supported_rates_len; i++) { |
627 | int rate = (params->supported_rates[i] & 0x7f) * 5; | |
8318d78a JB |
628 | for (j = 0; j < sband->n_bitrates; j++) { |
629 | if (sband->bitrates[j].bitrate == rate) | |
4fd6931e JB |
630 | rates |= BIT(j); |
631 | } | |
632 | } | |
323ce79a | 633 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
4fd6931e | 634 | } |
c5dd9c2b | 635 | |
36aedc90 JM |
636 | if (params->ht_capa) { |
637 | ieee80211_ht_cap_ie_to_ht_info(params->ht_capa, | |
687c7c08 | 638 | &sta->sta.ht_info); |
36aedc90 JM |
639 | } |
640 | ||
902acc78 | 641 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
c5dd9c2b LCC |
642 | switch (params->plink_action) { |
643 | case PLINK_ACTION_OPEN: | |
644 | mesh_plink_open(sta); | |
645 | break; | |
646 | case PLINK_ACTION_BLOCK: | |
647 | mesh_plink_block(sta); | |
648 | break; | |
649 | } | |
902acc78 | 650 | } |
4fd6931e JB |
651 | } |
652 | ||
653 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, | |
654 | u8 *mac, struct station_parameters *params) | |
655 | { | |
14db74bc | 656 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
657 | struct sta_info *sta; |
658 | struct ieee80211_sub_if_data *sdata; | |
73651ee6 | 659 | int err; |
4fd6931e JB |
660 | |
661 | /* Prevent a race with changing the rate control algorithm */ | |
662 | if (!netif_running(dev)) | |
663 | return -ENETDOWN; | |
664 | ||
4fd6931e JB |
665 | if (params->vlan) { |
666 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); | |
667 | ||
05c914fe JB |
668 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
669 | sdata->vif.type != NL80211_IFTYPE_AP) | |
4fd6931e JB |
670 | return -EINVAL; |
671 | } else | |
672 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
673 | ||
03e4497e JB |
674 | if (compare_ether_addr(mac, dev->dev_addr) == 0) |
675 | return -EINVAL; | |
676 | ||
677 | if (is_multicast_ether_addr(mac)) | |
678 | return -EINVAL; | |
679 | ||
680 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); | |
73651ee6 JB |
681 | if (!sta) |
682 | return -ENOMEM; | |
4fd6931e JB |
683 | |
684 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; | |
685 | ||
686 | sta_apply_parameters(local, sta, params); | |
687 | ||
4b7679a5 | 688 | rate_control_rate_init(sta); |
4fd6931e | 689 | |
73651ee6 JB |
690 | rcu_read_lock(); |
691 | ||
692 | err = sta_info_insert(sta); | |
693 | if (err) { | |
93e5deb1 | 694 | /* STA has been freed */ |
73651ee6 JB |
695 | rcu_read_unlock(); |
696 | return err; | |
697 | } | |
698 | ||
05c914fe JB |
699 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
700 | sdata->vif.type == NL80211_IFTYPE_AP) | |
73651ee6 JB |
701 | ieee80211_send_layer2_update(sta); |
702 | ||
703 | rcu_read_unlock(); | |
704 | ||
4fd6931e JB |
705 | return 0; |
706 | } | |
707 | ||
708 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, | |
709 | u8 *mac) | |
710 | { | |
14db74bc JB |
711 | struct ieee80211_local *local = wiphy_priv(wiphy); |
712 | struct ieee80211_sub_if_data *sdata; | |
4fd6931e JB |
713 | struct sta_info *sta; |
714 | ||
14db74bc JB |
715 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
716 | ||
4fd6931e | 717 | if (mac) { |
98dd6a57 JB |
718 | rcu_read_lock(); |
719 | ||
4fd6931e JB |
720 | /* XXX: get sta belonging to dev */ |
721 | sta = sta_info_get(local, mac); | |
98dd6a57 JB |
722 | if (!sta) { |
723 | rcu_read_unlock(); | |
4fd6931e | 724 | return -ENOENT; |
98dd6a57 | 725 | } |
4fd6931e | 726 | |
d0709a65 | 727 | sta_info_unlink(&sta); |
98dd6a57 JB |
728 | rcu_read_unlock(); |
729 | ||
4f6fab47 | 730 | sta_info_destroy(sta); |
4fd6931e | 731 | } else |
d0709a65 | 732 | sta_info_flush(local, sdata); |
4fd6931e JB |
733 | |
734 | return 0; | |
735 | } | |
736 | ||
737 | static int ieee80211_change_station(struct wiphy *wiphy, | |
738 | struct net_device *dev, | |
739 | u8 *mac, | |
740 | struct station_parameters *params) | |
741 | { | |
14db74bc | 742 | struct ieee80211_local *local = wiphy_priv(wiphy); |
4fd6931e JB |
743 | struct sta_info *sta; |
744 | struct ieee80211_sub_if_data *vlansdata; | |
745 | ||
98dd6a57 JB |
746 | rcu_read_lock(); |
747 | ||
4fd6931e JB |
748 | /* XXX: get sta belonging to dev */ |
749 | sta = sta_info_get(local, mac); | |
98dd6a57 JB |
750 | if (!sta) { |
751 | rcu_read_unlock(); | |
4fd6931e | 752 | return -ENOENT; |
98dd6a57 | 753 | } |
4fd6931e | 754 | |
d0709a65 | 755 | if (params->vlan && params->vlan != sta->sdata->dev) { |
4fd6931e JB |
756 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
757 | ||
05c914fe JB |
758 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
759 | vlansdata->vif.type != NL80211_IFTYPE_AP) { | |
98dd6a57 | 760 | rcu_read_unlock(); |
4fd6931e | 761 | return -EINVAL; |
98dd6a57 | 762 | } |
4fd6931e | 763 | |
14db74bc | 764 | sta->sdata = vlansdata; |
4fd6931e JB |
765 | ieee80211_send_layer2_update(sta); |
766 | } | |
767 | ||
768 | sta_apply_parameters(local, sta, params); | |
769 | ||
98dd6a57 JB |
770 | rcu_read_unlock(); |
771 | ||
4fd6931e JB |
772 | return 0; |
773 | } | |
774 | ||
c5dd9c2b LCC |
775 | #ifdef CONFIG_MAC80211_MESH |
776 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, | |
777 | u8 *dst, u8 *next_hop) | |
778 | { | |
14db74bc JB |
779 | struct ieee80211_local *local = wiphy_priv(wiphy); |
780 | struct ieee80211_sub_if_data *sdata; | |
c5dd9c2b LCC |
781 | struct mesh_path *mpath; |
782 | struct sta_info *sta; | |
783 | int err; | |
784 | ||
785 | if (!netif_running(dev)) | |
786 | return -ENETDOWN; | |
787 | ||
14db74bc JB |
788 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
789 | ||
05c914fe | 790 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
c5dd9c2b LCC |
791 | return -ENOTSUPP; |
792 | ||
d0709a65 | 793 | rcu_read_lock(); |
c5dd9c2b | 794 | sta = sta_info_get(local, next_hop); |
d0709a65 JB |
795 | if (!sta) { |
796 | rcu_read_unlock(); | |
c5dd9c2b | 797 | return -ENOENT; |
d0709a65 | 798 | } |
c5dd9c2b | 799 | |
f698d856 | 800 | err = mesh_path_add(dst, sdata); |
d0709a65 JB |
801 | if (err) { |
802 | rcu_read_unlock(); | |
c5dd9c2b | 803 | return err; |
d0709a65 | 804 | } |
c5dd9c2b | 805 | |
f698d856 | 806 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
807 | if (!mpath) { |
808 | rcu_read_unlock(); | |
c5dd9c2b LCC |
809 | return -ENXIO; |
810 | } | |
811 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 812 | |
c5dd9c2b LCC |
813 | rcu_read_unlock(); |
814 | return 0; | |
815 | } | |
816 | ||
817 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, | |
818 | u8 *dst) | |
819 | { | |
f698d856 JBG |
820 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
821 | ||
c5dd9c2b | 822 | if (dst) |
f698d856 | 823 | return mesh_path_del(dst, sdata); |
c5dd9c2b | 824 | |
f698d856 | 825 | mesh_path_flush(sdata); |
c5dd9c2b LCC |
826 | return 0; |
827 | } | |
828 | ||
829 | static int ieee80211_change_mpath(struct wiphy *wiphy, | |
830 | struct net_device *dev, | |
831 | u8 *dst, u8 *next_hop) | |
832 | { | |
14db74bc JB |
833 | struct ieee80211_local *local = wiphy_priv(wiphy); |
834 | struct ieee80211_sub_if_data *sdata; | |
c5dd9c2b LCC |
835 | struct mesh_path *mpath; |
836 | struct sta_info *sta; | |
837 | ||
838 | if (!netif_running(dev)) | |
839 | return -ENETDOWN; | |
840 | ||
14db74bc JB |
841 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
842 | ||
05c914fe | 843 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
c5dd9c2b LCC |
844 | return -ENOTSUPP; |
845 | ||
d0709a65 JB |
846 | rcu_read_lock(); |
847 | ||
c5dd9c2b | 848 | sta = sta_info_get(local, next_hop); |
d0709a65 JB |
849 | if (!sta) { |
850 | rcu_read_unlock(); | |
c5dd9c2b | 851 | return -ENOENT; |
d0709a65 | 852 | } |
c5dd9c2b | 853 | |
f698d856 | 854 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
855 | if (!mpath) { |
856 | rcu_read_unlock(); | |
c5dd9c2b LCC |
857 | return -ENOENT; |
858 | } | |
859 | ||
860 | mesh_path_fix_nexthop(mpath, sta); | |
d0709a65 | 861 | |
c5dd9c2b LCC |
862 | rcu_read_unlock(); |
863 | return 0; | |
864 | } | |
865 | ||
866 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, | |
867 | struct mpath_info *pinfo) | |
868 | { | |
869 | if (mpath->next_hop) | |
17741cdc | 870 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
c5dd9c2b LCC |
871 | else |
872 | memset(next_hop, 0, ETH_ALEN); | |
873 | ||
874 | pinfo->filled = MPATH_INFO_FRAME_QLEN | | |
875 | MPATH_INFO_DSN | | |
876 | MPATH_INFO_METRIC | | |
877 | MPATH_INFO_EXPTIME | | |
878 | MPATH_INFO_DISCOVERY_TIMEOUT | | |
879 | MPATH_INFO_DISCOVERY_RETRIES | | |
880 | MPATH_INFO_FLAGS; | |
881 | ||
882 | pinfo->frame_qlen = mpath->frame_queue.qlen; | |
883 | pinfo->dsn = mpath->dsn; | |
884 | pinfo->metric = mpath->metric; | |
885 | if (time_before(jiffies, mpath->exp_time)) | |
886 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); | |
887 | pinfo->discovery_timeout = | |
888 | jiffies_to_msecs(mpath->discovery_timeout); | |
889 | pinfo->discovery_retries = mpath->discovery_retries; | |
890 | pinfo->flags = 0; | |
891 | if (mpath->flags & MESH_PATH_ACTIVE) | |
892 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; | |
893 | if (mpath->flags & MESH_PATH_RESOLVING) | |
894 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
895 | if (mpath->flags & MESH_PATH_DSN_VALID) | |
896 | pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID; | |
897 | if (mpath->flags & MESH_PATH_FIXED) | |
898 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; | |
899 | if (mpath->flags & MESH_PATH_RESOLVING) | |
900 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; | |
901 | ||
902 | pinfo->flags = mpath->flags; | |
903 | } | |
904 | ||
905 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, | |
906 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) | |
907 | ||
908 | { | |
14db74bc | 909 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
910 | struct mesh_path *mpath; |
911 | ||
14db74bc JB |
912 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
913 | ||
05c914fe | 914 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
c5dd9c2b LCC |
915 | return -ENOTSUPP; |
916 | ||
917 | rcu_read_lock(); | |
f698d856 | 918 | mpath = mesh_path_lookup(dst, sdata); |
c5dd9c2b LCC |
919 | if (!mpath) { |
920 | rcu_read_unlock(); | |
921 | return -ENOENT; | |
922 | } | |
923 | memcpy(dst, mpath->dst, ETH_ALEN); | |
924 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
925 | rcu_read_unlock(); | |
926 | return 0; | |
927 | } | |
928 | ||
929 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, | |
930 | int idx, u8 *dst, u8 *next_hop, | |
931 | struct mpath_info *pinfo) | |
932 | { | |
14db74bc | 933 | struct ieee80211_sub_if_data *sdata; |
c5dd9c2b LCC |
934 | struct mesh_path *mpath; |
935 | ||
14db74bc JB |
936 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
937 | ||
05c914fe | 938 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
c5dd9c2b LCC |
939 | return -ENOTSUPP; |
940 | ||
941 | rcu_read_lock(); | |
f698d856 | 942 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
c5dd9c2b LCC |
943 | if (!mpath) { |
944 | rcu_read_unlock(); | |
945 | return -ENOENT; | |
946 | } | |
947 | memcpy(dst, mpath->dst, ETH_ALEN); | |
948 | mpath_set_pinfo(mpath, next_hop, pinfo); | |
949 | rcu_read_unlock(); | |
950 | return 0; | |
951 | } | |
952 | #endif | |
953 | ||
9f1ba906 JM |
954 | static int ieee80211_change_bss(struct wiphy *wiphy, |
955 | struct net_device *dev, | |
956 | struct bss_parameters *params) | |
957 | { | |
9f1ba906 JM |
958 | struct ieee80211_sub_if_data *sdata; |
959 | u32 changed = 0; | |
960 | ||
9f1ba906 JM |
961 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
962 | ||
05c914fe | 963 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
9f1ba906 JM |
964 | return -EINVAL; |
965 | ||
966 | if (params->use_cts_prot >= 0) { | |
967 | sdata->bss_conf.use_cts_prot = params->use_cts_prot; | |
968 | changed |= BSS_CHANGED_ERP_CTS_PROT; | |
969 | } | |
970 | if (params->use_short_preamble >= 0) { | |
971 | sdata->bss_conf.use_short_preamble = | |
972 | params->use_short_preamble; | |
973 | changed |= BSS_CHANGED_ERP_PREAMBLE; | |
974 | } | |
975 | if (params->use_short_slot_time >= 0) { | |
976 | sdata->bss_conf.use_short_slot = | |
977 | params->use_short_slot_time; | |
978 | changed |= BSS_CHANGED_ERP_SLOT; | |
979 | } | |
980 | ||
981 | ieee80211_bss_info_change_notify(sdata, changed); | |
982 | ||
983 | return 0; | |
984 | } | |
985 | ||
f0706e82 JB |
986 | struct cfg80211_ops mac80211_config_ops = { |
987 | .add_virtual_intf = ieee80211_add_iface, | |
988 | .del_virtual_intf = ieee80211_del_iface, | |
42613db7 | 989 | .change_virtual_intf = ieee80211_change_iface, |
e8cbb4cb JB |
990 | .add_key = ieee80211_add_key, |
991 | .del_key = ieee80211_del_key, | |
62da92fb | 992 | .get_key = ieee80211_get_key, |
e8cbb4cb | 993 | .set_default_key = ieee80211_config_default_key, |
5dfdaf58 JB |
994 | .add_beacon = ieee80211_add_beacon, |
995 | .set_beacon = ieee80211_set_beacon, | |
996 | .del_beacon = ieee80211_del_beacon, | |
4fd6931e JB |
997 | .add_station = ieee80211_add_station, |
998 | .del_station = ieee80211_del_station, | |
999 | .change_station = ieee80211_change_station, | |
7bbdd2d9 | 1000 | .get_station = ieee80211_get_station, |
c5dd9c2b LCC |
1001 | .dump_station = ieee80211_dump_station, |
1002 | #ifdef CONFIG_MAC80211_MESH | |
1003 | .add_mpath = ieee80211_add_mpath, | |
1004 | .del_mpath = ieee80211_del_mpath, | |
1005 | .change_mpath = ieee80211_change_mpath, | |
1006 | .get_mpath = ieee80211_get_mpath, | |
1007 | .dump_mpath = ieee80211_dump_mpath, | |
1008 | #endif | |
9f1ba906 | 1009 | .change_bss = ieee80211_change_bss, |
f0706e82 | 1010 | }; |