blob: 928813ce08e214c49c861b0979b762099690ddb6 [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 Berg2c8dccc2008-04-08 15:14:40 -040017#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010018#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010019
Johannes Berg42613db2007-09-28 21:52:27 +020020static enum ieee80211_if_types
21nl80211_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;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010032#ifdef CONFIG_MAC80211_MESH
33 case NL80211_IFTYPE_MESH_POINT:
34 return IEEE80211_IF_TYPE_MESH_POINT;
35#endif
Johannes Bergb4540482008-04-14 15:37:03 +020036 case NL80211_IFTYPE_WDS:
37 return IEEE80211_IF_TYPE_WDS;
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
Johannes Berg42613db2007-09-28 21:52:27 +020053 itype = nl80211_type_to_mac80211_type(type);
54 if (itype == IEEE80211_IF_TYPE_INVALID)
Jiri Bencf0706e82007-05-05 11:45:53 -070055 return -EINVAL;
Jiri Bencf0706e82007-05-05 11:45:53 -070056
Johannes Berg3e122be2008-07-09 14:40:34 +020057 err = ieee80211_if_add(local, name, &dev, itype, params);
Michael Wu8cc9a732008-01-31 19:48:23 +010058 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;
Jiri Bencf0706e82007-05-05 11:45:53 -070064}
65
66static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
67{
Jiri Bencf0706e82007-05-05 11:45:53 -070068 struct net_device *dev;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120069 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -070070
Johannes Berg42613db2007-09-28 21:52:27 +020071 /* we're under RTNL */
72 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e82007-05-05 11:45:53 -070073 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020074 return -ENODEV;
Jiri Bencf0706e82007-05-05 11:45:53 -070075
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120076 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
77
78 ieee80211_if_remove(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -070079
Johannes Berg75636522008-07-09 14:40:35 +020080 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070081}
82
Johannes Berg42613db2007-09-28 21:52:27 +020083static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010084 enum nl80211_iftype type, u32 *flags,
85 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020086{
Johannes Berg14db74b2008-07-29 13:22:52 +020087 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg42613db2007-09-28 21:52:27 +020088 struct net_device *dev;
89 enum ieee80211_if_types itype;
90 struct ieee80211_sub_if_data *sdata;
Johannes Bergf3947e22008-07-09 14:40:36 +020091 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020092
Johannes Berg42613db2007-09-28 21:52:27 +020093 /* we're under RTNL */
94 dev = __dev_get_by_index(&init_net, ifindex);
95 if (!dev)
96 return -ENODEV;
97
Johannes Berg42613db2007-09-28 21:52:27 +020098 itype = nl80211_type_to_mac80211_type(type);
99 if (itype == IEEE80211_IF_TYPE_INVALID)
100 return -EINVAL;
101
Johannes Berg14db74b2008-07-29 13:22:52 +0200102 if (dev == local->mdev)
103 return -EOPNOTSUPP;
104
Johannes Berg42613db2007-09-28 21:52:27 +0200105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
106
Johannes Bergf3947e22008-07-09 14:40:36 +0200107 ret = ieee80211_if_change_type(sdata, itype);
108 if (ret)
109 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200110
Johannes Berg902acc72008-02-23 15:17:19 +0100111 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
112 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
113 params->mesh_id_len,
114 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100115
Michael Wu8cc9a732008-01-31 19:48:23 +0100116 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
117 return 0;
118
119 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200120 return 0;
121}
122
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100123static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
124 u8 key_idx, u8 *mac_addr,
125 struct key_params *params)
126{
Johannes Berg14db74b2008-07-29 13:22:52 +0200127 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128 struct ieee80211_sub_if_data *sdata;
129 struct sta_info *sta = NULL;
130 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100131 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200132 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133
Johannes Berg14db74b2008-07-29 13:22:52 +0200134 if (dev == local->mdev)
135 return -EOPNOTSUPP;
136
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100137 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
138
139 switch (params->cipher) {
140 case WLAN_CIPHER_SUITE_WEP40:
141 case WLAN_CIPHER_SUITE_WEP104:
142 alg = ALG_WEP;
143 break;
144 case WLAN_CIPHER_SUITE_TKIP:
145 alg = ALG_TKIP;
146 break;
147 case WLAN_CIPHER_SUITE_CCMP:
148 alg = ALG_CCMP;
149 break;
150 default:
151 return -EINVAL;
152 }
153
Johannes Bergdb4d1162008-02-25 16:27:45 +0100154 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
155 if (!key)
156 return -ENOMEM;
157
Johannes Berg3b967662008-04-08 17:56:52 +0200158 rcu_read_lock();
159
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100160 if (mac_addr) {
161 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100162 if (!sta) {
163 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200164 err = -ENOENT;
165 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100166 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100167 }
168
Johannes Bergdb4d1162008-02-25 16:27:45 +0100169 ieee80211_key_link(key, sdata, sta);
170
Johannes Berg3b967662008-04-08 17:56:52 +0200171 err = 0;
172 out_unlock:
173 rcu_read_unlock();
174
175 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100176}
177
178static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
179 u8 key_idx, u8 *mac_addr)
180{
Johannes Berg14db74b2008-07-29 13:22:52 +0200181 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100182 struct ieee80211_sub_if_data *sdata;
183 struct sta_info *sta;
184 int ret;
185
Johannes Berg14db74b2008-07-29 13:22:52 +0200186 if (dev == local->mdev)
187 return -EOPNOTSUPP;
188
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
190
Johannes Berg3b967662008-04-08 17:56:52 +0200191 rcu_read_lock();
192
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100193 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200194 ret = -ENOENT;
195
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100196 sta = sta_info_get(sdata->local, mac_addr);
197 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200198 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100199
Johannes Bergdb4d1162008-02-25 16:27:45 +0100200 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100201 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100202 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200203 ret = 0;
204 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100205
Johannes Berg3b967662008-04-08 17:56:52 +0200206 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100207 }
208
Johannes Berg3b967662008-04-08 17:56:52 +0200209 if (!sdata->keys[key_idx]) {
210 ret = -ENOENT;
211 goto out_unlock;
212 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100213
Johannes Bergd0709a62008-02-25 16:27:46 +0100214 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100215 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100216
Johannes Berg3b967662008-04-08 17:56:52 +0200217 ret = 0;
218 out_unlock:
219 rcu_read_unlock();
220
221 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100222}
223
Johannes Berg62da92f2007-12-19 02:03:31 +0100224static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
225 u8 key_idx, u8 *mac_addr, void *cookie,
226 void (*callback)(void *cookie,
227 struct key_params *params))
228{
Johannes Berg14db74b2008-07-29 13:22:52 +0200229 struct ieee80211_local *local = wiphy_priv(wiphy);
230 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100231 struct sta_info *sta = NULL;
232 u8 seq[6] = {0};
233 struct key_params params;
234 struct ieee80211_key *key;
235 u32 iv32;
236 u16 iv16;
237 int err = -ENOENT;
238
Johannes Berg14db74b2008-07-29 13:22:52 +0200239 if (dev == local->mdev)
240 return -EOPNOTSUPP;
241
242 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
243
Johannes Berg3b967662008-04-08 17:56:52 +0200244 rcu_read_lock();
245
Johannes Berg62da92f2007-12-19 02:03:31 +0100246 if (mac_addr) {
247 sta = sta_info_get(sdata->local, mac_addr);
248 if (!sta)
249 goto out;
250
251 key = sta->key;
252 } else
253 key = sdata->keys[key_idx];
254
255 if (!key)
256 goto out;
257
258 memset(&params, 0, sizeof(params));
259
260 switch (key->conf.alg) {
261 case ALG_TKIP:
262 params.cipher = WLAN_CIPHER_SUITE_TKIP;
263
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700264 iv32 = key->u.tkip.tx.iv32;
265 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100266
267 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
268 sdata->local->ops->get_tkip_seq)
269 sdata->local->ops->get_tkip_seq(
270 local_to_hw(sdata->local),
271 key->conf.hw_key_idx,
272 &iv32, &iv16);
273
274 seq[0] = iv16 & 0xff;
275 seq[1] = (iv16 >> 8) & 0xff;
276 seq[2] = iv32 & 0xff;
277 seq[3] = (iv32 >> 8) & 0xff;
278 seq[4] = (iv32 >> 16) & 0xff;
279 seq[5] = (iv32 >> 24) & 0xff;
280 params.seq = seq;
281 params.seq_len = 6;
282 break;
283 case ALG_CCMP:
284 params.cipher = WLAN_CIPHER_SUITE_CCMP;
285 seq[0] = key->u.ccmp.tx_pn[5];
286 seq[1] = key->u.ccmp.tx_pn[4];
287 seq[2] = key->u.ccmp.tx_pn[3];
288 seq[3] = key->u.ccmp.tx_pn[2];
289 seq[4] = key->u.ccmp.tx_pn[1];
290 seq[5] = key->u.ccmp.tx_pn[0];
291 params.seq = seq;
292 params.seq_len = 6;
293 break;
294 case ALG_WEP:
295 if (key->conf.keylen == 5)
296 params.cipher = WLAN_CIPHER_SUITE_WEP40;
297 else
298 params.cipher = WLAN_CIPHER_SUITE_WEP104;
299 break;
300 }
301
302 params.key = key->conf.key;
303 params.key_len = key->conf.keylen;
304
305 callback(cookie, &params);
306 err = 0;
307
308 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200309 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100310 return err;
311}
312
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100313static int ieee80211_config_default_key(struct wiphy *wiphy,
314 struct net_device *dev,
315 u8 key_idx)
316{
Johannes Berg14db74b2008-07-29 13:22:52 +0200317 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100318 struct ieee80211_sub_if_data *sdata;
319
Johannes Berg14db74b2008-07-29 13:22:52 +0200320 if (dev == local->mdev)
321 return -EOPNOTSUPP;
322
Johannes Berg3b967662008-04-08 17:56:52 +0200323 rcu_read_lock();
324
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100325 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
326 ieee80211_set_default_key(sdata, key_idx);
327
Johannes Berg3b967662008-04-08 17:56:52 +0200328 rcu_read_unlock();
329
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100330 return 0;
331}
332
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
334{
Johannes Bergd0709a62008-02-25 16:27:46 +0100335 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100336
337 sinfo->filled = STATION_INFO_INACTIVE_TIME |
338 STATION_INFO_RX_BYTES |
339 STATION_INFO_TX_BYTES;
340
341 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
342 sinfo->rx_bytes = sta->rx_bytes;
343 sinfo->tx_bytes = sta->tx_bytes;
344
Johannes Berg902acc72008-02-23 15:17:19 +0100345 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100346#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100347 sinfo->filled |= STATION_INFO_LLID |
348 STATION_INFO_PLID |
349 STATION_INFO_PLINK_STATE;
350
351 sinfo->llid = le16_to_cpu(sta->llid);
352 sinfo->plid = le16_to_cpu(sta->plid);
353 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100354#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100355 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100356}
357
358
359static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
360 int idx, u8 *mac, struct station_info *sinfo)
361{
362 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
363 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100364 int ret = -ENOENT;
365
366 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100367
368 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100369 if (sta) {
370 ret = 0;
371 memcpy(mac, sta->addr, ETH_ALEN);
372 sta_set_sinfo(sta, sinfo);
373 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100374
Johannes Bergd0709a62008-02-25 16:27:46 +0100375 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100376
Johannes Bergd0709a62008-02-25 16:27:46 +0100377 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100378}
379
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100380static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100381 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100382{
383 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
384 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100385 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100386
Johannes Bergd0709a62008-02-25 16:27:46 +0100387 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100388
389 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100390
Johannes Bergd0709a62008-02-25 16:27:46 +0100391 sta = sta_info_get(local, mac);
392 if (sta) {
393 ret = 0;
394 sta_set_sinfo(sta, sinfo);
395 }
396
397 rcu_read_unlock();
398
399 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100400}
401
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100402/*
403 * This handles both adding a beacon and setting new beacon info
404 */
405static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
406 struct beacon_parameters *params)
407{
408 struct beacon_data *new, *old;
409 int new_head_len, new_tail_len;
410 int size;
411 int err = -EINVAL;
412
413 old = sdata->u.ap.beacon;
414
415 /* head must not be zero-length */
416 if (params->head && !params->head_len)
417 return -EINVAL;
418
419 /*
420 * This is a kludge. beacon interval should really be part
421 * of the beacon information.
422 */
423 if (params->interval) {
424 sdata->local->hw.conf.beacon_int = params->interval;
425 if (ieee80211_hw_config(sdata->local))
426 return -EINVAL;
427 /*
428 * We updated some parameter so if below bails out
429 * it's not an error.
430 */
431 err = 0;
432 }
433
434 /* Need to have a beacon head if we don't have one yet */
435 if (!params->head && !old)
436 return err;
437
438 /* sorry, no way to start beaconing without dtim period */
439 if (!params->dtim_period && !old)
440 return err;
441
442 /* new or old head? */
443 if (params->head)
444 new_head_len = params->head_len;
445 else
446 new_head_len = old->head_len;
447
448 /* new or old tail? */
449 if (params->tail || !old)
450 /* params->tail_len will be zero for !params->tail */
451 new_tail_len = params->tail_len;
452 else
453 new_tail_len = old->tail_len;
454
455 size = sizeof(*new) + new_head_len + new_tail_len;
456
457 new = kzalloc(size, GFP_KERNEL);
458 if (!new)
459 return -ENOMEM;
460
461 /* start filling the new info now */
462
463 /* new or old dtim period? */
464 if (params->dtim_period)
465 new->dtim_period = params->dtim_period;
466 else
467 new->dtim_period = old->dtim_period;
468
469 /*
470 * pointers go into the block we allocated,
471 * memory is | beacon_data | head | tail |
472 */
473 new->head = ((u8 *) new) + sizeof(*new);
474 new->tail = new->head + new_head_len;
475 new->head_len = new_head_len;
476 new->tail_len = new_tail_len;
477
478 /* copy in head */
479 if (params->head)
480 memcpy(new->head, params->head, new_head_len);
481 else
482 memcpy(new->head, old->head, new_head_len);
483
484 /* copy in optional tail */
485 if (params->tail)
486 memcpy(new->tail, params->tail, new_tail_len);
487 else
488 if (old)
489 memcpy(new->tail, old->tail, new_tail_len);
490
491 rcu_assign_pointer(sdata->u.ap.beacon, new);
492
493 synchronize_rcu();
494
495 kfree(old);
496
Johannes Berg9d139c82008-07-09 14:40:37 +0200497 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100498}
499
500static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
501 struct beacon_parameters *params)
502{
Johannes Berg14db74b2008-07-29 13:22:52 +0200503 struct ieee80211_local *local = wiphy_priv(wiphy);
504 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100505 struct beacon_data *old;
506
Johannes Berg14db74b2008-07-29 13:22:52 +0200507 if (dev == local->mdev)
508 return -EOPNOTSUPP;
509
510 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
511
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100512 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
513 return -EINVAL;
514
515 old = sdata->u.ap.beacon;
516
517 if (old)
518 return -EALREADY;
519
520 return ieee80211_config_beacon(sdata, params);
521}
522
523static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
524 struct beacon_parameters *params)
525{
Johannes Berg14db74b2008-07-29 13:22:52 +0200526 struct ieee80211_local *local = wiphy_priv(wiphy);
527 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100528 struct beacon_data *old;
529
Johannes Berg14db74b2008-07-29 13:22:52 +0200530 if (dev == local->mdev)
531 return -EOPNOTSUPP;
532
533 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
534
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100535 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
536 return -EINVAL;
537
538 old = sdata->u.ap.beacon;
539
540 if (!old)
541 return -ENOENT;
542
543 return ieee80211_config_beacon(sdata, params);
544}
545
546static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
547{
Johannes Berg14db74b2008-07-29 13:22:52 +0200548 struct ieee80211_local *local = wiphy_priv(wiphy);
549 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100550 struct beacon_data *old;
551
Johannes Berg14db74b2008-07-29 13:22:52 +0200552 if (dev == local->mdev)
553 return -EOPNOTSUPP;
554
555 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
556
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100557 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
558 return -EINVAL;
559
560 old = sdata->u.ap.beacon;
561
562 if (!old)
563 return -ENOENT;
564
565 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
566 synchronize_rcu();
567 kfree(old);
568
Johannes Berg9d139c82008-07-09 14:40:37 +0200569 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100570}
571
Johannes Berg4fd69312007-12-19 02:03:35 +0100572/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
573struct iapp_layer2_update {
574 u8 da[ETH_ALEN]; /* broadcast */
575 u8 sa[ETH_ALEN]; /* STA addr */
576 __be16 len; /* 6 */
577 u8 dsap; /* 0 */
578 u8 ssap; /* 0 */
579 u8 control;
580 u8 xid_info[3];
581} __attribute__ ((packed));
582
583static void ieee80211_send_layer2_update(struct sta_info *sta)
584{
585 struct iapp_layer2_update *msg;
586 struct sk_buff *skb;
587
588 /* Send Level 2 Update Frame to update forwarding tables in layer 2
589 * bridge devices */
590
591 skb = dev_alloc_skb(sizeof(*msg));
592 if (!skb)
593 return;
594 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
595
596 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
597 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
598
599 memset(msg->da, 0xff, ETH_ALEN);
600 memcpy(msg->sa, sta->addr, ETH_ALEN);
601 msg->len = htons(6);
602 msg->dsap = 0;
603 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
604 msg->control = 0xaf; /* XID response lsb.1111F101.
605 * F=0 (no poll command; unsolicited frame) */
606 msg->xid_info[0] = 0x81; /* XID format identifier */
607 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
608 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
609
Johannes Bergd0709a62008-02-25 16:27:46 +0100610 skb->dev = sta->sdata->dev;
611 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100612 memset(skb->cb, 0, sizeof(skb->cb));
613 netif_rx(skb);
614}
615
616static void sta_apply_parameters(struct ieee80211_local *local,
617 struct sta_info *sta,
618 struct station_parameters *params)
619{
620 u32 rates;
621 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100622 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100623 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100624
Johannes Berg73651ee2008-02-25 16:27:47 +0100625 /*
626 * FIXME: updating the flags is racy when this function is
627 * called from ieee80211_change_station(), this will
628 * be resolved in a future patch.
629 */
630
Johannes Berg4fd69312007-12-19 02:03:35 +0100631 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200632 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100633 sta->flags &= ~WLAN_STA_AUTHORIZED;
634 if (params->station_flags & STATION_FLAG_AUTHORIZED)
635 sta->flags |= WLAN_STA_AUTHORIZED;
636
637 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
638 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
639 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
640
641 sta->flags &= ~WLAN_STA_WME;
642 if (params->station_flags & STATION_FLAG_WME)
643 sta->flags |= WLAN_STA_WME;
Johannes Berg07346f812008-05-03 01:02:02 +0200644 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100645 }
646
Johannes Berg73651ee2008-02-25 16:27:47 +0100647 /*
648 * FIXME: updating the following information is racy when this
649 * function is called from ieee80211_change_station().
650 * However, all this information should be static so
651 * maybe we should just reject attemps to change it.
652 */
653
Johannes Berg4fd69312007-12-19 02:03:35 +0100654 if (params->aid) {
655 sta->aid = params->aid;
656 if (sta->aid > IEEE80211_MAX_AID)
657 sta->aid = 0; /* XXX: should this be an error? */
658 }
659
660 if (params->listen_interval >= 0)
661 sta->listen_interval = params->listen_interval;
662
663 if (params->supported_rates) {
664 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100665 sband = local->hw.wiphy->bands[local->oper_channel->band];
666
Johannes Berg4fd69312007-12-19 02:03:35 +0100667 for (i = 0; i < params->supported_rates_len; i++) {
668 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100669 for (j = 0; j < sband->n_bitrates; j++) {
670 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100671 rates |= BIT(j);
672 }
673 }
Johannes Berg8318d782008-01-24 19:38:38 +0100674 sta->supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100675 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100676
Jouni Malinen36aedc902008-08-25 11:58:58 +0300677 if (params->ht_capa) {
678 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa,
679 &sta->ht_info);
680 }
681
Johannes Berg902acc72008-02-23 15:17:19 +0100682 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100683 switch (params->plink_action) {
684 case PLINK_ACTION_OPEN:
685 mesh_plink_open(sta);
686 break;
687 case PLINK_ACTION_BLOCK:
688 mesh_plink_block(sta);
689 break;
690 }
Johannes Berg902acc72008-02-23 15:17:19 +0100691 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100692}
693
694static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
695 u8 *mac, struct station_parameters *params)
696{
Johannes Berg14db74b2008-07-29 13:22:52 +0200697 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100698 struct sta_info *sta;
699 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100700 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100701
Johannes Berg14db74b2008-07-29 13:22:52 +0200702 if (dev == local->mdev || params->vlan == local->mdev)
703 return -EOPNOTSUPP;
704
Johannes Berg4fd69312007-12-19 02:03:35 +0100705 /* Prevent a race with changing the rate control algorithm */
706 if (!netif_running(dev))
707 return -ENETDOWN;
708
Johannes Berg4fd69312007-12-19 02:03:35 +0100709 if (params->vlan) {
710 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
711
Nicolas Kaiser679fda12008-05-20 18:42:54 +0200712 if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN &&
Johannes Berg4fd69312007-12-19 02:03:35 +0100713 sdata->vif.type != IEEE80211_IF_TYPE_AP)
714 return -EINVAL;
715 } else
716 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
717
Johannes Berg03e44972008-02-27 09:56:40 +0100718 if (compare_ether_addr(mac, dev->dev_addr) == 0)
719 return -EINVAL;
720
721 if (is_multicast_ether_addr(mac))
722 return -EINVAL;
723
724 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100725 if (!sta)
726 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100727
728 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
729
730 sta_apply_parameters(local, sta, params);
731
732 rate_control_rate_init(sta, local);
733
Johannes Berg73651ee2008-02-25 16:27:47 +0100734 rcu_read_lock();
735
736 err = sta_info_insert(sta);
737 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200738 /* STA has been freed */
Johannes Berg73651ee2008-02-25 16:27:47 +0100739 rcu_read_unlock();
740 return err;
741 }
742
743 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
744 sdata->vif.type == IEEE80211_IF_TYPE_AP)
745 ieee80211_send_layer2_update(sta);
746
747 rcu_read_unlock();
748
Johannes Berg4fd69312007-12-19 02:03:35 +0100749 return 0;
750}
751
752static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
753 u8 *mac)
754{
Johannes Berg14db74b2008-07-29 13:22:52 +0200755 struct ieee80211_local *local = wiphy_priv(wiphy);
756 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100757 struct sta_info *sta;
758
Johannes Berg14db74b2008-07-29 13:22:52 +0200759 if (dev == local->mdev)
760 return -EOPNOTSUPP;
761
762 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
763
Johannes Berg4fd69312007-12-19 02:03:35 +0100764 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200765 rcu_read_lock();
766
Johannes Berg4fd69312007-12-19 02:03:35 +0100767 /* XXX: get sta belonging to dev */
768 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200769 if (!sta) {
770 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100771 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200772 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100773
Johannes Bergd0709a62008-02-25 16:27:46 +0100774 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200775 rcu_read_unlock();
776
Johannes Berg4f6fab42008-03-31 19:23:02 +0200777 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100778 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100779 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100780
781 return 0;
782}
783
784static int ieee80211_change_station(struct wiphy *wiphy,
785 struct net_device *dev,
786 u8 *mac,
787 struct station_parameters *params)
788{
Johannes Berg14db74b2008-07-29 13:22:52 +0200789 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100790 struct sta_info *sta;
791 struct ieee80211_sub_if_data *vlansdata;
792
Johannes Berg14db74b2008-07-29 13:22:52 +0200793 if (dev == local->mdev || params->vlan == local->mdev)
794 return -EOPNOTSUPP;
795
Johannes Berg98dd6a52008-04-10 15:36:09 +0200796 rcu_read_lock();
797
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 /* XXX: get sta belonging to dev */
799 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200800 if (!sta) {
801 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100802 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200803 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100804
Johannes Bergd0709a62008-02-25 16:27:46 +0100805 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100806 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
807
Nicolas Kaiser679fda12008-05-20 18:42:54 +0200808 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN &&
Johannes Berg98dd6a52008-04-10 15:36:09 +0200809 vlansdata->vif.type != IEEE80211_IF_TYPE_AP) {
810 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100811 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200812 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100813
Johannes Berg14db74b2008-07-29 13:22:52 +0200814 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100815 ieee80211_send_layer2_update(sta);
816 }
817
818 sta_apply_parameters(local, sta, params);
819
Johannes Berg98dd6a52008-04-10 15:36:09 +0200820 rcu_read_unlock();
821
Johannes Berg4fd69312007-12-19 02:03:35 +0100822 return 0;
823}
824
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100825#ifdef CONFIG_MAC80211_MESH
826static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
827 u8 *dst, u8 *next_hop)
828{
Johannes Berg14db74b2008-07-29 13:22:52 +0200829 struct ieee80211_local *local = wiphy_priv(wiphy);
830 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100831 struct mesh_path *mpath;
832 struct sta_info *sta;
833 int err;
834
Johannes Berg14db74b2008-07-29 13:22:52 +0200835 if (dev == local->mdev)
836 return -EOPNOTSUPP;
837
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100838 if (!netif_running(dev))
839 return -ENETDOWN;
840
Johannes Berg14db74b2008-07-29 13:22:52 +0200841 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
842
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100843 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
844 return -ENOTSUPP;
845
Johannes Bergd0709a62008-02-25 16:27:46 +0100846 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100847 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100848 if (!sta) {
849 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100850 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100851 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100852
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200853 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100854 if (err) {
855 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100856 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100857 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200859 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100860 if (!mpath) {
861 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100862 return -ENXIO;
863 }
864 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100865
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100866 rcu_read_unlock();
867 return 0;
868}
869
870static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
871 u8 *dst)
872{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200873 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100874
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200875 if (dst)
876 return mesh_path_del(dst, sdata);
877
878 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100879 return 0;
880}
881
882static int ieee80211_change_mpath(struct wiphy *wiphy,
883 struct net_device *dev,
884 u8 *dst, u8 *next_hop)
885{
Johannes Berg14db74b2008-07-29 13:22:52 +0200886 struct ieee80211_local *local = wiphy_priv(wiphy);
887 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100888 struct mesh_path *mpath;
889 struct sta_info *sta;
890
Johannes Berg14db74b2008-07-29 13:22:52 +0200891 if (dev == local->mdev)
892 return -EOPNOTSUPP;
893
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100894 if (!netif_running(dev))
895 return -ENETDOWN;
896
Johannes Berg14db74b2008-07-29 13:22:52 +0200897 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
898
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100899 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
900 return -ENOTSUPP;
901
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100902 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100903
904 sta = sta_info_get(local, next_hop);
905 if (!sta) {
906 rcu_read_unlock();
907 return -ENOENT;
908 }
909
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200910 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100911 if (!mpath) {
912 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100913 return -ENOENT;
914 }
915
916 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100917
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100918 rcu_read_unlock();
919 return 0;
920}
921
922static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
923 struct mpath_info *pinfo)
924{
925 if (mpath->next_hop)
926 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
927 else
928 memset(next_hop, 0, ETH_ALEN);
929
930 pinfo->filled = MPATH_INFO_FRAME_QLEN |
931 MPATH_INFO_DSN |
932 MPATH_INFO_METRIC |
933 MPATH_INFO_EXPTIME |
934 MPATH_INFO_DISCOVERY_TIMEOUT |
935 MPATH_INFO_DISCOVERY_RETRIES |
936 MPATH_INFO_FLAGS;
937
938 pinfo->frame_qlen = mpath->frame_queue.qlen;
939 pinfo->dsn = mpath->dsn;
940 pinfo->metric = mpath->metric;
941 if (time_before(jiffies, mpath->exp_time))
942 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
943 pinfo->discovery_timeout =
944 jiffies_to_msecs(mpath->discovery_timeout);
945 pinfo->discovery_retries = mpath->discovery_retries;
946 pinfo->flags = 0;
947 if (mpath->flags & MESH_PATH_ACTIVE)
948 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
949 if (mpath->flags & MESH_PATH_RESOLVING)
950 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
951 if (mpath->flags & MESH_PATH_DSN_VALID)
952 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
953 if (mpath->flags & MESH_PATH_FIXED)
954 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
955 if (mpath->flags & MESH_PATH_RESOLVING)
956 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
957
958 pinfo->flags = mpath->flags;
959}
960
961static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
962 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
963
964{
Johannes Berg14db74b2008-07-29 13:22:52 +0200965 struct ieee80211_local *local = wiphy_priv(wiphy);
966 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100967 struct mesh_path *mpath;
968
Johannes Berg14db74b2008-07-29 13:22:52 +0200969 if (dev == local->mdev)
970 return -EOPNOTSUPP;
971
972 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
973
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100974 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
975 return -ENOTSUPP;
976
977 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200978 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100979 if (!mpath) {
980 rcu_read_unlock();
981 return -ENOENT;
982 }
983 memcpy(dst, mpath->dst, ETH_ALEN);
984 mpath_set_pinfo(mpath, next_hop, pinfo);
985 rcu_read_unlock();
986 return 0;
987}
988
989static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
990 int idx, u8 *dst, u8 *next_hop,
991 struct mpath_info *pinfo)
992{
Johannes Berg14db74b2008-07-29 13:22:52 +0200993 struct ieee80211_local *local = wiphy_priv(wiphy);
994 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100995 struct mesh_path *mpath;
996
Johannes Berg14db74b2008-07-29 13:22:52 +0200997 if (dev == local->mdev)
998 return -EOPNOTSUPP;
999
1000 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001002 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
1003 return -ENOTSUPP;
1004
1005 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001006 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001007 if (!mpath) {
1008 rcu_read_unlock();
1009 return -ENOENT;
1010 }
1011 memcpy(dst, mpath->dst, ETH_ALEN);
1012 mpath_set_pinfo(mpath, next_hop, pinfo);
1013 rcu_read_unlock();
1014 return 0;
1015}
1016#endif
1017
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001018static int ieee80211_change_bss(struct wiphy *wiphy,
1019 struct net_device *dev,
1020 struct bss_parameters *params)
1021{
1022 struct ieee80211_local *local = wiphy_priv(wiphy);
1023 struct ieee80211_sub_if_data *sdata;
1024 u32 changed = 0;
1025
1026 if (dev == local->mdev)
1027 return -EOPNOTSUPP;
1028
1029 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1030
1031 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
1032 return -EINVAL;
1033
1034 if (params->use_cts_prot >= 0) {
1035 sdata->bss_conf.use_cts_prot = params->use_cts_prot;
1036 changed |= BSS_CHANGED_ERP_CTS_PROT;
1037 }
1038 if (params->use_short_preamble >= 0) {
1039 sdata->bss_conf.use_short_preamble =
1040 params->use_short_preamble;
1041 changed |= BSS_CHANGED_ERP_PREAMBLE;
1042 }
1043 if (params->use_short_slot_time >= 0) {
1044 sdata->bss_conf.use_short_slot =
1045 params->use_short_slot_time;
1046 changed |= BSS_CHANGED_ERP_SLOT;
1047 }
1048
1049 ieee80211_bss_info_change_notify(sdata, changed);
1050
1051 return 0;
1052}
1053
Jiri Bencf0706e82007-05-05 11:45:53 -07001054struct cfg80211_ops mac80211_config_ops = {
1055 .add_virtual_intf = ieee80211_add_iface,
1056 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001057 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001058 .add_key = ieee80211_add_key,
1059 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001060 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001061 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001062 .add_beacon = ieee80211_add_beacon,
1063 .set_beacon = ieee80211_set_beacon,
1064 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001065 .add_station = ieee80211_add_station,
1066 .del_station = ieee80211_del_station,
1067 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001068 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001069 .dump_station = ieee80211_dump_station,
1070#ifdef CONFIG_MAC80211_MESH
1071 .add_mpath = ieee80211_add_mpath,
1072 .del_mpath = ieee80211_del_mpath,
1073 .change_mpath = ieee80211_change_mpath,
1074 .get_mpath = ieee80211_get_mpath,
1075 .dump_mpath = ieee80211_dump_mpath,
1076#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001077 .change_bss = ieee80211_change_bss,
Jiri Bencf0706e82007-05-05 11:45:53 -07001078};