blob: 6ac49231efa9eec5cbde744891e19fb782b603ec [file] [log] [blame]
Jiri Bencf0706e822007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Johannes Berg62da92f2007-12-19 02:03:31 +01004 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e822007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070012#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010013#include <linux/rcupdate.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070014#include <net/cfg80211.h>
15#include "ieee80211_i.h"
Michael Wue0eb6852007-09-18 17:29:21 -040016#include "cfg.h"
Johannes Berg4fd69312007-12-19 02:03:35 +010017#include "ieee80211_rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010018#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010019
20#define DEFAULT_RATES 0
Jiri Bencf0706e822007-05-05 11:45:53 -070021
Johannes Berg42613db2007-09-28 21:52:27 +020022static enum ieee80211_if_types
23nl80211_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;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010034#ifdef CONFIG_MAC80211_MESH
35 case NL80211_IFTYPE_MESH_POINT:
36 return IEEE80211_IF_TYPE_MESH_POINT;
37#endif
Johannes Berg42613db2007-09-28 21:52:27 +020038 default:
39 return IEEE80211_IF_TYPE_INVALID;
40 }
41}
42
Jiri Bencf0706e822007-05-05 11:45:53 -070043static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010044 enum nl80211_iftype type, u32 *flags,
45 struct vif_params *params)
Jiri Bencf0706e822007-05-05 11:45:53 -070046{
47 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg42613db2007-09-28 21:52:27 +020048 enum ieee80211_if_types itype;
Michael Wu8cc9a732008-01-31 19:48:23 +010049 struct net_device *dev;
50 struct ieee80211_sub_if_data *sdata;
51 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070052
53 if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
54 return -ENODEV;
55
Johannes Berg42613db2007-09-28 21:52:27 +020056 itype = nl80211_type_to_mac80211_type(type);
57 if (itype == IEEE80211_IF_TYPE_INVALID)
Jiri Bencf0706e822007-05-05 11:45:53 -070058 return -EINVAL;
Jiri Bencf0706e822007-05-05 11:45:53 -070059
Luis Carlos Coboee385852008-02-23 15:17:11 +010060 err = ieee80211_if_add(local->mdev, name, &dev, itype, params);
Michael Wu8cc9a732008-01-31 19:48:23 +010061 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;
Jiri Bencf0706e822007-05-05 11:45:53 -070067}
68
69static 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
Johannes Berg42613db2007-09-28 21:52:27 +020078 /* we're under RTNL */
79 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e822007-05-05 11:45:53 -070080 if (!dev)
81 return 0;
82
83 name = dev->name;
Jiri Bencf0706e822007-05-05 11:45:53 -070084
85 return ieee80211_if_remove(local->mdev, name, -1);
86}
87
Johannes Berg42613db2007-09-28 21:52:27 +020088static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010089 enum nl80211_iftype type, u32 *flags,
90 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020091{
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
Johannes Berg51fb61e2007-12-19 01:31:27 +0100114 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Johannes Berg42613db2007-09-28 21:52:27 +0200115 return -EOPNOTSUPP;
116
117 ieee80211_if_reinit(dev);
118 ieee80211_if_set_type(dev, itype);
119
Johannes Berg902acc72008-02-23 15:17:19 +0100120 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);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100124
Michael Wu8cc9a732008-01-31 19:48:23 +0100125 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
126 return 0;
127
128 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200129 return 0;
130}
131
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100132static 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;
139 int ret;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100140 struct ieee80211_key *key;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100141
142 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
143
144 switch (params->cipher) {
145 case WLAN_CIPHER_SUITE_WEP40:
146 case WLAN_CIPHER_SUITE_WEP104:
147 alg = ALG_WEP;
148 break;
149 case WLAN_CIPHER_SUITE_TKIP:
150 alg = ALG_TKIP;
151 break;
152 case WLAN_CIPHER_SUITE_CCMP:
153 alg = ALG_CCMP;
154 break;
155 default:
156 return -EINVAL;
157 }
158
Johannes Bergdb4d1162008-02-25 16:27:45 +0100159 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
160 if (!key)
161 return -ENOMEM;
162
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100163 if (mac_addr) {
164 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100165 if (!sta) {
166 ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100167 return -ENOENT;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100168 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169 }
170
Johannes Bergdb4d1162008-02-25 16:27:45 +0100171 ieee80211_key_link(key, sdata, sta);
172
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100173 ret = 0;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100174
175 if (sta)
176 sta_info_put(sta);
177
178 return ret;
179}
180
181static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
182 u8 key_idx, u8 *mac_addr)
183{
184 struct ieee80211_sub_if_data *sdata;
185 struct sta_info *sta;
186 int ret;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100187 struct ieee80211_key *key;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100188
189 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
190
191 if (mac_addr) {
192 sta = sta_info_get(sdata->local, mac_addr);
193 if (!sta)
194 return -ENOENT;
195
196 ret = 0;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100197 if (sta->key) {
198 key = sta->key;
199 ieee80211_key_free(key);
200 WARN_ON(sta->key);
201 } else
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100202 ret = -ENOENT;
203
204 sta_info_put(sta);
205 return ret;
206 }
207
208 if (!sdata->keys[key_idx])
209 return -ENOENT;
210
Johannes Bergdb4d1162008-02-25 16:27:45 +0100211 key = sdata->keys[key_idx];
212 ieee80211_key_free(key);
213 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100214
215 return 0;
216}
217
Johannes Berg62da92f2007-12-19 02:03:31 +0100218static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
219 u8 key_idx, u8 *mac_addr, void *cookie,
220 void (*callback)(void *cookie,
221 struct key_params *params))
222{
223 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
224 struct sta_info *sta = NULL;
225 u8 seq[6] = {0};
226 struct key_params params;
227 struct ieee80211_key *key;
228 u32 iv32;
229 u16 iv16;
230 int err = -ENOENT;
231
232 if (mac_addr) {
233 sta = sta_info_get(sdata->local, mac_addr);
234 if (!sta)
235 goto out;
236
237 key = sta->key;
238 } else
239 key = sdata->keys[key_idx];
240
241 if (!key)
242 goto out;
243
244 memset(&params, 0, sizeof(params));
245
246 switch (key->conf.alg) {
247 case ALG_TKIP:
248 params.cipher = WLAN_CIPHER_SUITE_TKIP;
249
250 iv32 = key->u.tkip.iv32;
251 iv16 = key->u.tkip.iv16;
252
253 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
254 sdata->local->ops->get_tkip_seq)
255 sdata->local->ops->get_tkip_seq(
256 local_to_hw(sdata->local),
257 key->conf.hw_key_idx,
258 &iv32, &iv16);
259
260 seq[0] = iv16 & 0xff;
261 seq[1] = (iv16 >> 8) & 0xff;
262 seq[2] = iv32 & 0xff;
263 seq[3] = (iv32 >> 8) & 0xff;
264 seq[4] = (iv32 >> 16) & 0xff;
265 seq[5] = (iv32 >> 24) & 0xff;
266 params.seq = seq;
267 params.seq_len = 6;
268 break;
269 case ALG_CCMP:
270 params.cipher = WLAN_CIPHER_SUITE_CCMP;
271 seq[0] = key->u.ccmp.tx_pn[5];
272 seq[1] = key->u.ccmp.tx_pn[4];
273 seq[2] = key->u.ccmp.tx_pn[3];
274 seq[3] = key->u.ccmp.tx_pn[2];
275 seq[4] = key->u.ccmp.tx_pn[1];
276 seq[5] = key->u.ccmp.tx_pn[0];
277 params.seq = seq;
278 params.seq_len = 6;
279 break;
280 case ALG_WEP:
281 if (key->conf.keylen == 5)
282 params.cipher = WLAN_CIPHER_SUITE_WEP40;
283 else
284 params.cipher = WLAN_CIPHER_SUITE_WEP104;
285 break;
286 }
287
288 params.key = key->conf.key;
289 params.key_len = key->conf.keylen;
290
291 callback(cookie, &params);
292 err = 0;
293
294 out:
295 if (sta)
296 sta_info_put(sta);
297 return err;
298}
299
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100300static int ieee80211_config_default_key(struct wiphy *wiphy,
301 struct net_device *dev,
302 u8 key_idx)
303{
304 struct ieee80211_sub_if_data *sdata;
305
306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307 ieee80211_set_default_key(sdata, key_idx);
308
309 return 0;
310}
311
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100312static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
313{
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100314 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100315
316 sinfo->filled = STATION_INFO_INACTIVE_TIME |
317 STATION_INFO_RX_BYTES |
318 STATION_INFO_TX_BYTES;
319
320 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
321 sinfo->rx_bytes = sta->rx_bytes;
322 sinfo->tx_bytes = sta->tx_bytes;
323
Johannes Berg902acc72008-02-23 15:17:19 +0100324 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100325#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100326 sinfo->filled |= STATION_INFO_LLID |
327 STATION_INFO_PLID |
328 STATION_INFO_PLINK_STATE;
329
330 sinfo->llid = le16_to_cpu(sta->llid);
331 sinfo->plid = le16_to_cpu(sta->plid);
332 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100334 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100335}
336
337
338static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
339 int idx, u8 *mac, struct station_info *sinfo)
340{
341 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
342 struct sta_info *sta;
343
344 sta = sta_info_get_by_idx(local, idx, dev);
345 if (!sta)
346 return -ENOENT;
347
348 memcpy(mac, sta->addr, ETH_ALEN);
349 sta_set_sinfo(sta, sinfo);
350 sta_info_put(sta);
351
352 return 0;
353}
354
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100355static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100356 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100357{
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
359 struct sta_info *sta;
360
361 sta = sta_info_get(local, mac);
362 if (!sta)
363 return -ENOENT;
364
365 /* XXX: verify sta->dev == dev */
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100366 sta_set_sinfo(sta, sinfo);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100367 sta_info_put(sta);
368
369 return 0;
370}
371
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100372/*
373 * This handles both adding a beacon and setting new beacon info
374 */
375static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
376 struct beacon_parameters *params)
377{
378 struct beacon_data *new, *old;
379 int new_head_len, new_tail_len;
380 int size;
381 int err = -EINVAL;
382
383 old = sdata->u.ap.beacon;
384
385 /* head must not be zero-length */
386 if (params->head && !params->head_len)
387 return -EINVAL;
388
389 /*
390 * This is a kludge. beacon interval should really be part
391 * of the beacon information.
392 */
393 if (params->interval) {
394 sdata->local->hw.conf.beacon_int = params->interval;
395 if (ieee80211_hw_config(sdata->local))
396 return -EINVAL;
397 /*
398 * We updated some parameter so if below bails out
399 * it's not an error.
400 */
401 err = 0;
402 }
403
404 /* Need to have a beacon head if we don't have one yet */
405 if (!params->head && !old)
406 return err;
407
408 /* sorry, no way to start beaconing without dtim period */
409 if (!params->dtim_period && !old)
410 return err;
411
412 /* new or old head? */
413 if (params->head)
414 new_head_len = params->head_len;
415 else
416 new_head_len = old->head_len;
417
418 /* new or old tail? */
419 if (params->tail || !old)
420 /* params->tail_len will be zero for !params->tail */
421 new_tail_len = params->tail_len;
422 else
423 new_tail_len = old->tail_len;
424
425 size = sizeof(*new) + new_head_len + new_tail_len;
426
427 new = kzalloc(size, GFP_KERNEL);
428 if (!new)
429 return -ENOMEM;
430
431 /* start filling the new info now */
432
433 /* new or old dtim period? */
434 if (params->dtim_period)
435 new->dtim_period = params->dtim_period;
436 else
437 new->dtim_period = old->dtim_period;
438
439 /*
440 * pointers go into the block we allocated,
441 * memory is | beacon_data | head | tail |
442 */
443 new->head = ((u8 *) new) + sizeof(*new);
444 new->tail = new->head + new_head_len;
445 new->head_len = new_head_len;
446 new->tail_len = new_tail_len;
447
448 /* copy in head */
449 if (params->head)
450 memcpy(new->head, params->head, new_head_len);
451 else
452 memcpy(new->head, old->head, new_head_len);
453
454 /* copy in optional tail */
455 if (params->tail)
456 memcpy(new->tail, params->tail, new_tail_len);
457 else
458 if (old)
459 memcpy(new->tail, old->tail, new_tail_len);
460
461 rcu_assign_pointer(sdata->u.ap.beacon, new);
462
463 synchronize_rcu();
464
465 kfree(old);
466
467 return ieee80211_if_config_beacon(sdata->dev);
468}
469
470static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
471 struct beacon_parameters *params)
472{
473 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
474 struct beacon_data *old;
475
476 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
477 return -EINVAL;
478
479 old = sdata->u.ap.beacon;
480
481 if (old)
482 return -EALREADY;
483
484 return ieee80211_config_beacon(sdata, params);
485}
486
487static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
488 struct beacon_parameters *params)
489{
490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
491 struct beacon_data *old;
492
493 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
494 return -EINVAL;
495
496 old = sdata->u.ap.beacon;
497
498 if (!old)
499 return -ENOENT;
500
501 return ieee80211_config_beacon(sdata, params);
502}
503
504static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
505{
506 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
507 struct beacon_data *old;
508
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 -ENOENT;
516
517 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
518 synchronize_rcu();
519 kfree(old);
520
521 return ieee80211_if_config_beacon(dev);
522}
523
Johannes Berg4fd69312007-12-19 02:03:35 +0100524/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
525struct iapp_layer2_update {
526 u8 da[ETH_ALEN]; /* broadcast */
527 u8 sa[ETH_ALEN]; /* STA addr */
528 __be16 len; /* 6 */
529 u8 dsap; /* 0 */
530 u8 ssap; /* 0 */
531 u8 control;
532 u8 xid_info[3];
533} __attribute__ ((packed));
534
535static void ieee80211_send_layer2_update(struct sta_info *sta)
536{
537 struct iapp_layer2_update *msg;
538 struct sk_buff *skb;
539
540 /* Send Level 2 Update Frame to update forwarding tables in layer 2
541 * bridge devices */
542
543 skb = dev_alloc_skb(sizeof(*msg));
544 if (!skb)
545 return;
546 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
547
548 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
549 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
550
551 memset(msg->da, 0xff, ETH_ALEN);
552 memcpy(msg->sa, sta->addr, ETH_ALEN);
553 msg->len = htons(6);
554 msg->dsap = 0;
555 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
556 msg->control = 0xaf; /* XID response lsb.1111F101.
557 * F=0 (no poll command; unsolicited frame) */
558 msg->xid_info[0] = 0x81; /* XID format identifier */
559 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
560 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
561
562 skb->dev = sta->dev;
563 skb->protocol = eth_type_trans(skb, sta->dev);
564 memset(skb->cb, 0, sizeof(skb->cb));
565 netif_rx(skb);
566}
567
568static void sta_apply_parameters(struct ieee80211_local *local,
569 struct sta_info *sta,
570 struct station_parameters *params)
571{
572 u32 rates;
573 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100574 struct ieee80211_supported_band *sband;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100576
577 if (params->station_flags & STATION_FLAG_CHANGED) {
578 sta->flags &= ~WLAN_STA_AUTHORIZED;
579 if (params->station_flags & STATION_FLAG_AUTHORIZED)
580 sta->flags |= WLAN_STA_AUTHORIZED;
581
582 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
583 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
584 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
585
586 sta->flags &= ~WLAN_STA_WME;
587 if (params->station_flags & STATION_FLAG_WME)
588 sta->flags |= WLAN_STA_WME;
589 }
590
591 if (params->aid) {
592 sta->aid = params->aid;
593 if (sta->aid > IEEE80211_MAX_AID)
594 sta->aid = 0; /* XXX: should this be an error? */
595 }
596
597 if (params->listen_interval >= 0)
598 sta->listen_interval = params->listen_interval;
599
600 if (params->supported_rates) {
601 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100602 sband = local->hw.wiphy->bands[local->oper_channel->band];
603
Johannes Berg4fd69312007-12-19 02:03:35 +0100604 for (i = 0; i < params->supported_rates_len; i++) {
605 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100606 for (j = 0; j < sband->n_bitrates; j++) {
607 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100608 rates |= BIT(j);
609 }
610 }
Johannes Berg8318d782008-01-24 19:38:38 +0100611 sta->supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100612 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100613
Johannes Berg902acc72008-02-23 15:17:19 +0100614 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100615 switch (params->plink_action) {
616 case PLINK_ACTION_OPEN:
617 mesh_plink_open(sta);
618 break;
619 case PLINK_ACTION_BLOCK:
620 mesh_plink_block(sta);
621 break;
622 }
Johannes Berg902acc72008-02-23 15:17:19 +0100623 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100624}
625
626static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
627 u8 *mac, struct station_parameters *params)
628{
629 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
630 struct sta_info *sta;
631 struct ieee80211_sub_if_data *sdata;
632
633 /* Prevent a race with changing the rate control algorithm */
634 if (!netif_running(dev))
635 return -ENETDOWN;
636
Johannes Berg4fd69312007-12-19 02:03:35 +0100637 if (params->vlan) {
638 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
639
640 if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
641 sdata->vif.type != IEEE80211_IF_TYPE_AP)
642 return -EINVAL;
643 } else
644 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
645
Johannes Berg902acc72008-02-23 15:17:19 +0100646 if (ieee80211_vif_is_mesh(&sdata->vif))
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100647 sta = mesh_plink_add(mac, DEFAULT_RATES, dev);
648 else
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100649 sta = sta_info_add(local, dev, mac, GFP_KERNEL);
650
Johannes Berg43ba7e92008-02-21 14:09:30 +0100651 if (IS_ERR(sta))
652 return PTR_ERR(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100653
654 sta->dev = sdata->dev;
655 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
656 sdata->vif.type == IEEE80211_IF_TYPE_AP)
657 ieee80211_send_layer2_update(sta);
658
659 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
660
661 sta_apply_parameters(local, sta, params);
662
663 rate_control_rate_init(sta, local);
664
665 sta_info_put(sta);
666
667 return 0;
668}
669
670static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
671 u8 *mac)
672{
673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
674 struct sta_info *sta;
675
676 if (mac) {
677 /* XXX: get sta belonging to dev */
678 sta = sta_info_get(local, mac);
679 if (!sta)
680 return -ENOENT;
681
682 sta_info_free(sta);
683 sta_info_put(sta);
684 } else
685 sta_info_flush(local, dev);
686
687 return 0;
688}
689
690static int ieee80211_change_station(struct wiphy *wiphy,
691 struct net_device *dev,
692 u8 *mac,
693 struct station_parameters *params)
694{
695 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
696 struct sta_info *sta;
697 struct ieee80211_sub_if_data *vlansdata;
698
699 /* XXX: get sta belonging to dev */
700 sta = sta_info_get(local, mac);
701 if (!sta)
702 return -ENOENT;
703
704 if (params->vlan && params->vlan != sta->dev) {
705 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
706
707 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN ||
708 vlansdata->vif.type != IEEE80211_IF_TYPE_AP)
709 return -EINVAL;
710
711 sta->dev = params->vlan;
712 ieee80211_send_layer2_update(sta);
713 }
714
715 sta_apply_parameters(local, sta, params);
716
717 sta_info_put(sta);
718
719 return 0;
720}
721
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100722#ifdef CONFIG_MAC80211_MESH
723static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
724 u8 *dst, u8 *next_hop)
725{
726 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
727 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
728 struct mesh_path *mpath;
729 struct sta_info *sta;
730 int err;
731
732 if (!netif_running(dev))
733 return -ENETDOWN;
734
735 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
736 return -ENOTSUPP;
737
738 sta = sta_info_get(local, next_hop);
739 if (!sta)
740 return -ENOENT;
741
742 err = mesh_path_add(dst, dev);
743 if (err)
744 return err;
745
746 rcu_read_lock();
747 mpath = mesh_path_lookup(dst, dev);
748 if (!mpath) {
749 rcu_read_unlock();
750 sta_info_put(sta);
751 return -ENXIO;
752 }
753 mesh_path_fix_nexthop(mpath, sta);
754 sta_info_put(sta);
755 rcu_read_unlock();
756 return 0;
757}
758
759static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
760 u8 *dst)
761{
762 if (dst)
763 return mesh_path_del(dst, dev);
764
765 mesh_path_flush(dev);
766 return 0;
767}
768
769static 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
784 sta = sta_info_get(local, next_hop);
785 if (!sta)
786 return -ENOENT;
787
788 rcu_read_lock();
789 mpath = mesh_path_lookup(dst, dev);
790 if (!mpath) {
791 rcu_read_unlock();
792 sta_info_put(sta);
793 return -ENOENT;
794 }
795
796 mesh_path_fix_nexthop(mpath, sta);
797 sta_info_put(sta);
798 rcu_read_unlock();
799 return 0;
800}
801
802static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
803 struct mpath_info *pinfo)
804{
805 if (mpath->next_hop)
806 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
807 else
808 memset(next_hop, 0, ETH_ALEN);
809
810 pinfo->filled = MPATH_INFO_FRAME_QLEN |
811 MPATH_INFO_DSN |
812 MPATH_INFO_METRIC |
813 MPATH_INFO_EXPTIME |
814 MPATH_INFO_DISCOVERY_TIMEOUT |
815 MPATH_INFO_DISCOVERY_RETRIES |
816 MPATH_INFO_FLAGS;
817
818 pinfo->frame_qlen = mpath->frame_queue.qlen;
819 pinfo->dsn = mpath->dsn;
820 pinfo->metric = mpath->metric;
821 if (time_before(jiffies, mpath->exp_time))
822 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
823 pinfo->discovery_timeout =
824 jiffies_to_msecs(mpath->discovery_timeout);
825 pinfo->discovery_retries = mpath->discovery_retries;
826 pinfo->flags = 0;
827 if (mpath->flags & MESH_PATH_ACTIVE)
828 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
829 if (mpath->flags & MESH_PATH_RESOLVING)
830 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
831 if (mpath->flags & MESH_PATH_DSN_VALID)
832 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
833 if (mpath->flags & MESH_PATH_FIXED)
834 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
835 if (mpath->flags & MESH_PATH_RESOLVING)
836 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
837
838 pinfo->flags = mpath->flags;
839}
840
841static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
842 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
843
844{
845 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
846 struct mesh_path *mpath;
847
848 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
849 return -ENOTSUPP;
850
851 rcu_read_lock();
852 mpath = mesh_path_lookup(dst, dev);
853 if (!mpath) {
854 rcu_read_unlock();
855 return -ENOENT;
856 }
857 memcpy(dst, mpath->dst, ETH_ALEN);
858 mpath_set_pinfo(mpath, next_hop, pinfo);
859 rcu_read_unlock();
860 return 0;
861}
862
863static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
864 int idx, u8 *dst, u8 *next_hop,
865 struct mpath_info *pinfo)
866{
867 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
868 struct mesh_path *mpath;
869
870 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
871 return -ENOTSUPP;
872
873 rcu_read_lock();
874 mpath = mesh_path_lookup_by_idx(idx, dev);
875 if (!mpath) {
876 rcu_read_unlock();
877 return -ENOENT;
878 }
879 memcpy(dst, mpath->dst, ETH_ALEN);
880 mpath_set_pinfo(mpath, next_hop, pinfo);
881 rcu_read_unlock();
882 return 0;
883}
884#endif
885
Jiri Bencf0706e822007-05-05 11:45:53 -0700886struct cfg80211_ops mac80211_config_ops = {
887 .add_virtual_intf = ieee80211_add_iface,
888 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +0200889 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100890 .add_key = ieee80211_add_key,
891 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +0100892 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100893 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100894 .add_beacon = ieee80211_add_beacon,
895 .set_beacon = ieee80211_set_beacon,
896 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +0100897 .add_station = ieee80211_add_station,
898 .del_station = ieee80211_del_station,
899 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100900 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100901 .dump_station = ieee80211_dump_station,
902#ifdef CONFIG_MAC80211_MESH
903 .add_mpath = ieee80211_add_mpath,
904 .del_mpath = ieee80211_del_mpath,
905 .change_mpath = ieee80211_change_mpath,
906 .get_mpath = ieee80211_get_mpath,
907 .dump_mpath = ieee80211_dump_mpath,
908#endif
Jiri Bencf0706e822007-05-05 11:45:53 -0700909};