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