blob: e9ba6fcc0e45754a42cc27ec7cd93d2744a5399a [file] [log] [blame]
Jiri Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -070058 return -EINVAL;
Jiri Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -070080 if (!dev)
81 return 0;
82
83 name = dev->name;
Jiri Bencf0706e82007-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;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100139 struct ieee80211_key *key;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100140
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
Johannes Bergdb4d1162008-02-25 16:27:45 +0100158 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
159 if (!key)
160 return -ENOMEM;
161
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162 if (mac_addr) {
163 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100164 if (!sta) {
165 ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166 return -ENOENT;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100167 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100168 }
169
Johannes Bergdb4d1162008-02-25 16:27:45 +0100170 ieee80211_key_link(key, sdata, sta);
171
Johannes Bergd0709a62008-02-25 16:27:46 +0100172 return 0;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100173}
174
175static 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;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100190 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100191 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100192 WARN_ON(sta->key);
193 } else
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100194 ret = -ENOENT;
195
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100196 return ret;
197 }
198
199 if (!sdata->keys[key_idx])
200 return -ENOENT;
201
Johannes Bergd0709a62008-02-25 16:27:46 +0100202 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100203 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204
205 return 0;
206}
207
Johannes Berg62da92f2007-12-19 02:03:31 +0100208static 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(&params, 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, &params);
282 err = 0;
283
284 out:
Johannes Berg62da92f2007-12-19 02:03:31 +0100285 return err;
286}
287
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100288static 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
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100300static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
301{
Johannes Bergd0709a62008-02-25 16:27:46 +0100302 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100303
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
Johannes Berg902acc72008-02-23 15:17:19 +0100312 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100313#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100314 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;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100321#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100322 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100323}
324
325
326static 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;
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 int ret = -ENOENT;
332
333 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100334
335 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100336 if (sta) {
337 ret = 0;
338 memcpy(mac, sta->addr, ETH_ALEN);
339 sta_set_sinfo(sta, sinfo);
340 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100341
Johannes Bergd0709a62008-02-25 16:27:46 +0100342 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100343
Johannes Bergd0709a62008-02-25 16:27:46 +0100344 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100345}
346
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100347static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100348 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100349{
350 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
351 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100352 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100353
Johannes Bergd0709a62008-02-25 16:27:46 +0100354 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100355
356 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100357
Johannes Bergd0709a62008-02-25 16:27:46 +0100358 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;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100367}
368
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100369/*
370 * This handles both adding a beacon and setting new beacon info
371 */
372static 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
467static 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
484static 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
501static 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
Johannes Berg4fd69312007-12-19 02:03:35 +0100521/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
522struct 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
532static 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
Johannes Bergd0709a62008-02-25 16:27:46 +0100559 skb->dev = sta->sdata->dev;
560 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100561 memset(skb->cb, 0, sizeof(skb->cb));
562 netif_rx(skb);
563}
564
565static 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;
Johannes Berg8318d782008-01-24 19:38:38 +0100571 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100572 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100573
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;
Johannes Berg8318d782008-01-24 19:38:38 +0100599 sband = local->hw.wiphy->bands[local->oper_channel->band];
600
Johannes Berg4fd69312007-12-19 02:03:35 +0100601 for (i = 0; i < params->supported_rates_len; i++) {
602 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100603 for (j = 0; j < sband->n_bitrates; j++) {
604 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100605 rates |= BIT(j);
606 }
607 }
Johannes Berg8318d782008-01-24 19:38:38 +0100608 sta->supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100609 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100610
Johannes Berg902acc72008-02-23 15:17:19 +0100611 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100612 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 }
Johannes Berg902acc72008-02-23 15:17:19 +0100620 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100621}
622
623static 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
Johannes Berg4fd69312007-12-19 02:03:35 +0100634 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
Johannes Berg902acc72008-02-23 15:17:19 +0100643 if (ieee80211_vif_is_mesh(&sdata->vif))
Johannes Bergd0709a62008-02-25 16:27:46 +0100644 sta = mesh_plink_add(mac, DEFAULT_RATES, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100645 else
Johannes Bergd0709a62008-02-25 16:27:46 +0100646 sta = sta_info_add(sdata, mac);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100647
Johannes Berg43ba7e92008-02-21 14:09:30 +0100648 if (IS_ERR(sta))
649 return PTR_ERR(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100650
Johannes Berg4fd69312007-12-19 02:03:35 +0100651 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
Johannes Berg4fd69312007-12-19 02:03:35 +0100661 return 0;
662}
663
664static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
665 u8 *mac)
666{
Johannes Bergd0709a62008-02-25 16:27:46 +0100667 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
668 struct ieee80211_local *local = sdata->local;
Johannes Berg4fd69312007-12-19 02:03:35 +0100669 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
Johannes Bergd0709a62008-02-25 16:27:46 +0100677 sta_info_unlink(&sta);
678
679 if (sta) {
680 synchronize_rcu();
681 sta_info_destroy(sta);
682 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100683 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100684 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100685
686 return 0;
687}
688
689static 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
Johannes Bergd0709a62008-02-25 16:27:46 +0100703 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100704 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
Johannes Bergd0709a62008-02-25 16:27:46 +0100710 sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
Johannes Berg4fd69312007-12-19 02:03:35 +0100711 ieee80211_send_layer2_update(sta);
712 }
713
714 sta_apply_parameters(local, sta, params);
715
Johannes Berg4fd69312007-12-19 02:03:35 +0100716 return 0;
717}
718
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100719#ifdef CONFIG_MAC80211_MESH
720static 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
Johannes Bergd0709a62008-02-25 16:27:46 +0100735 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100736 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100737 if (!sta) {
738 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100739 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100740 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100741
742 err = mesh_path_add(dst, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100743 if (err) {
744 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100745 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100746 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100747
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100748 mpath = mesh_path_lookup(dst, dev);
749 if (!mpath) {
750 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100751 return -ENXIO;
752 }
753 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100754
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100755 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)
Johannes Bergd0709a62008-02-25 16:27:46 +0100763 return mesh_path_del(dst, dev, false);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100764
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
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100784 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100785
786 sta = sta_info_get(local, next_hop);
787 if (!sta) {
788 rcu_read_unlock();
789 return -ENOENT;
790 }
791
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100792 mpath = mesh_path_lookup(dst, dev);
793 if (!mpath) {
794 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100795 return -ENOENT;
796 }
797
798 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100799
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100800 rcu_read_unlock();
801 return 0;
802}
803
804static 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
843static 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
865static 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
Jiri Bencf0706e82007-05-05 11:45:53 -0700888struct cfg80211_ops mac80211_config_ops = {
889 .add_virtual_intf = ieee80211_add_iface,
890 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +0200891 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100892 .add_key = ieee80211_add_key,
893 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +0100894 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100895 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100896 .add_beacon = ieee80211_add_beacon,
897 .set_beacon = ieee80211_set_beacon,
898 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +0100899 .add_station = ieee80211_add_station,
900 .del_station = ieee80211_del_station,
901 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100902 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 .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
Jiri Bencf0706e82007-05-05 11:45:53 -0700911};