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