blob: 8ea30902d5db1d26a797320ae82bb9c5ba737fa0 [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 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 Berg05c914f2008-09-11 00:01:58 +020020static bool nl80211_type_check(enum nl80211_iftype type)
Johannes Berg42613db2007-09-28 21:52:27 +020021{
22 switch (type) {
Johannes Berg42613db2007-09-28 21:52:27 +020023 case NL80211_IFTYPE_ADHOC:
Johannes Berg42613db2007-09-28 21:52:27 +020024 case NL80211_IFTYPE_STATION:
Johannes Berg42613db2007-09-28 21:52:27 +020025 case NL80211_IFTYPE_MONITOR:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010026#ifdef CONFIG_MAC80211_MESH
27 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010028#endif
Johannes Bergb4540482008-04-14 15:37:03 +020029 case NL80211_IFTYPE_WDS:
Johannes Berg05c914f2008-09-11 00:01:58 +020030 return true;
Johannes Berg42613db2007-09-28 21:52:27 +020031 default:
Johannes Berg05c914f2008-09-11 00:01:58 +020032 return false;
Johannes Berg42613db2007-09-28 21:52:27 +020033 }
34}
35
Jiri Bencf0706e822007-05-05 11:45:53 -070036static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010037 enum nl80211_iftype type, u32 *flags,
38 struct vif_params *params)
Jiri Bencf0706e822007-05-05 11:45:53 -070039{
40 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010041 struct net_device *dev;
42 struct ieee80211_sub_if_data *sdata;
43 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070044
Johannes Berg05c914f2008-09-11 00:01:58 +020045 if (!nl80211_type_check(type))
Jiri Bencf0706e822007-05-05 11:45:53 -070046 return -EINVAL;
Jiri Bencf0706e822007-05-05 11:45:53 -070047
Johannes Berg05c914f2008-09-11 00:01:58 +020048 err = ieee80211_if_add(local, name, &dev, type, params);
49 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010050 return err;
51
52 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
53 sdata->u.mntr_flags = *flags;
54 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070055}
56
57static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
58{
Jiri Bencf0706e822007-05-05 11:45:53 -070059 struct net_device *dev;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120060 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e822007-05-05 11:45:53 -070061
Johannes Berg42613db2007-09-28 21:52:27 +020062 /* we're under RTNL */
63 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e822007-05-05 11:45:53 -070064 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020065 return -ENODEV;
Jiri Bencf0706e822007-05-05 11:45:53 -070066
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120067 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
68
69 ieee80211_if_remove(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -070070
Johannes Berg75636522008-07-09 14:40:35 +020071 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070072}
73
Johannes Berg42613db2007-09-28 21:52:27 +020074static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010075 enum nl80211_iftype type, u32 *flags,
76 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020077{
Johannes Berg42613db2007-09-28 21:52:27 +020078 struct net_device *dev;
Johannes Berg42613db2007-09-28 21:52:27 +020079 struct ieee80211_sub_if_data *sdata;
Johannes Bergf3947e22008-07-09 14:40:36 +020080 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020081
Johannes Berg42613db2007-09-28 21:52:27 +020082 /* we're under RTNL */
83 dev = __dev_get_by_index(&init_net, ifindex);
84 if (!dev)
85 return -ENODEV;
86
Johannes Berg05c914f2008-09-11 00:01:58 +020087 if (!nl80211_type_check(type))
Johannes Berg42613db2007-09-28 21:52:27 +020088 return -EINVAL;
89
90 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
91
Johannes Berg05c914f2008-09-11 00:01:58 +020092 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020093 if (ret)
94 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020095
Johannes Bergf8b25cd2008-09-16 20:22:21 +020096 if (netif_running(sdata->dev))
97 return -EBUSY;
98
Johannes Berg902acc72008-02-23 15:17:19 +010099 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +0200100 ieee80211_sdata_set_mesh_id(sdata,
101 params->mesh_id_len,
102 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100103
Johannes Berg05c914f2008-09-11 00:01:58 +0200104 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +0100105 return 0;
106
107 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200108 return 0;
109}
110
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100111static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
112 u8 key_idx, u8 *mac_addr,
113 struct key_params *params)
114{
115 struct ieee80211_sub_if_data *sdata;
116 struct sta_info *sta = NULL;
117 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100118 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200119 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120
121 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
122
123 switch (params->cipher) {
124 case WLAN_CIPHER_SUITE_WEP40:
125 case WLAN_CIPHER_SUITE_WEP104:
126 alg = ALG_WEP;
127 break;
128 case WLAN_CIPHER_SUITE_TKIP:
129 alg = ALG_TKIP;
130 break;
131 case WLAN_CIPHER_SUITE_CCMP:
132 alg = ALG_CCMP;
133 break;
134 default:
135 return -EINVAL;
136 }
137
Johannes Bergdb4d1162008-02-25 16:27:45 +0100138 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
139 if (!key)
140 return -ENOMEM;
141
Johannes Berg3b967662008-04-08 17:56:52 +0200142 rcu_read_lock();
143
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100144 if (mac_addr) {
145 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100146 if (!sta) {
147 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200148 err = -ENOENT;
149 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100151 }
152
Johannes Bergdb4d1162008-02-25 16:27:45 +0100153 ieee80211_key_link(key, sdata, sta);
154
Johannes Berg3b967662008-04-08 17:56:52 +0200155 err = 0;
156 out_unlock:
157 rcu_read_unlock();
158
159 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100160}
161
162static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
163 u8 key_idx, u8 *mac_addr)
164{
165 struct ieee80211_sub_if_data *sdata;
166 struct sta_info *sta;
167 int ret;
168
169 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
170
Johannes Berg3b967662008-04-08 17:56:52 +0200171 rcu_read_lock();
172
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100173 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200174 ret = -ENOENT;
175
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100176 sta = sta_info_get(sdata->local, mac_addr);
177 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200178 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100179
Johannes Bergdb4d1162008-02-25 16:27:45 +0100180 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100181 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100182 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200183 ret = 0;
184 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185
Johannes Berg3b967662008-04-08 17:56:52 +0200186 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100187 }
188
Johannes Berg3b967662008-04-08 17:56:52 +0200189 if (!sdata->keys[key_idx]) {
190 ret = -ENOENT;
191 goto out_unlock;
192 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100193
Johannes Bergd0709a62008-02-25 16:27:46 +0100194 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100195 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100196
Johannes Berg3b967662008-04-08 17:56:52 +0200197 ret = 0;
198 out_unlock:
199 rcu_read_unlock();
200
201 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100202}
203
Johannes Berg62da92f2007-12-19 02:03:31 +0100204static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
205 u8 key_idx, u8 *mac_addr, void *cookie,
206 void (*callback)(void *cookie,
207 struct key_params *params))
208{
Johannes Berg14db74b2008-07-29 13:22:52 +0200209 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100210 struct sta_info *sta = NULL;
211 u8 seq[6] = {0};
212 struct key_params params;
213 struct ieee80211_key *key;
214 u32 iv32;
215 u16 iv16;
216 int err = -ENOENT;
217
Johannes Berg14db74b2008-07-29 13:22:52 +0200218 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
219
Johannes Berg3b967662008-04-08 17:56:52 +0200220 rcu_read_lock();
221
Johannes Berg62da92f2007-12-19 02:03:31 +0100222 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
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700240 iv32 = key->u.tkip.tx.iv32;
241 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100242
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 Berg3b967662008-04-08 17:56:52 +0200285 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100286 return err;
287}
288
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100289static int ieee80211_config_default_key(struct wiphy *wiphy,
290 struct net_device *dev,
291 u8 key_idx)
292{
293 struct ieee80211_sub_if_data *sdata;
294
Johannes Berg3b967662008-04-08 17:56:52 +0200295 rcu_read_lock();
296
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100297 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
298 ieee80211_set_default_key(sdata, key_idx);
299
Johannes Berg3b967662008-04-08 17:56:52 +0200300 rcu_read_unlock();
301
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100302 return 0;
303}
304
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100305static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
306{
Johannes Bergd0709a62008-02-25 16:27:46 +0100307 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100308
309 sinfo->filled = STATION_INFO_INACTIVE_TIME |
310 STATION_INFO_RX_BYTES |
311 STATION_INFO_TX_BYTES;
312
313 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
314 sinfo->rx_bytes = sta->rx_bytes;
315 sinfo->tx_bytes = sta->tx_bytes;
316
Johannes Berg902acc72008-02-23 15:17:19 +0100317 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100318#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100319 sinfo->filled |= STATION_INFO_LLID |
320 STATION_INFO_PLID |
321 STATION_INFO_PLINK_STATE;
322
323 sinfo->llid = le16_to_cpu(sta->llid);
324 sinfo->plid = le16_to_cpu(sta->plid);
325 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100326#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100327 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100328}
329
330
331static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
332 int idx, u8 *mac, struct station_info *sinfo)
333{
334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
335 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100336 int ret = -ENOENT;
337
338 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100339
340 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100341 if (sta) {
342 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200343 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100344 sta_set_sinfo(sta, sinfo);
345 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100346
Johannes Bergd0709a62008-02-25 16:27:46 +0100347 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100348
Johannes Bergd0709a62008-02-25 16:27:46 +0100349 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100350}
351
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100352static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100353 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100354{
355 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
356 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100357 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100358
Johannes Bergd0709a62008-02-25 16:27:46 +0100359 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100360
361 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100362
Johannes Bergd0709a62008-02-25 16:27:46 +0100363 sta = sta_info_get(local, mac);
364 if (sta) {
365 ret = 0;
366 sta_set_sinfo(sta, sinfo);
367 }
368
369 rcu_read_unlock();
370
371 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100372}
373
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100374/*
375 * This handles both adding a beacon and setting new beacon info
376 */
377static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
378 struct beacon_parameters *params)
379{
380 struct beacon_data *new, *old;
381 int new_head_len, new_tail_len;
382 int size;
383 int err = -EINVAL;
384
385 old = sdata->u.ap.beacon;
386
387 /* head must not be zero-length */
388 if (params->head && !params->head_len)
389 return -EINVAL;
390
391 /*
392 * This is a kludge. beacon interval should really be part
393 * of the beacon information.
394 */
395 if (params->interval) {
396 sdata->local->hw.conf.beacon_int = params->interval;
Johannes Berge8975582008-10-09 12:18:51 +0200397 ieee80211_hw_config(sdata->local,
398 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100399 /*
400 * We updated some parameter so if below bails out
401 * it's not an error.
402 */
403 err = 0;
404 }
405
406 /* Need to have a beacon head if we don't have one yet */
407 if (!params->head && !old)
408 return err;
409
410 /* sorry, no way to start beaconing without dtim period */
411 if (!params->dtim_period && !old)
412 return err;
413
414 /* new or old head? */
415 if (params->head)
416 new_head_len = params->head_len;
417 else
418 new_head_len = old->head_len;
419
420 /* new or old tail? */
421 if (params->tail || !old)
422 /* params->tail_len will be zero for !params->tail */
423 new_tail_len = params->tail_len;
424 else
425 new_tail_len = old->tail_len;
426
427 size = sizeof(*new) + new_head_len + new_tail_len;
428
429 new = kzalloc(size, GFP_KERNEL);
430 if (!new)
431 return -ENOMEM;
432
433 /* start filling the new info now */
434
435 /* new or old dtim period? */
436 if (params->dtim_period)
437 new->dtim_period = params->dtim_period;
438 else
439 new->dtim_period = old->dtim_period;
440
441 /*
442 * pointers go into the block we allocated,
443 * memory is | beacon_data | head | tail |
444 */
445 new->head = ((u8 *) new) + sizeof(*new);
446 new->tail = new->head + new_head_len;
447 new->head_len = new_head_len;
448 new->tail_len = new_tail_len;
449
450 /* copy in head */
451 if (params->head)
452 memcpy(new->head, params->head, new_head_len);
453 else
454 memcpy(new->head, old->head, new_head_len);
455
456 /* copy in optional tail */
457 if (params->tail)
458 memcpy(new->tail, params->tail, new_tail_len);
459 else
460 if (old)
461 memcpy(new->tail, old->tail, new_tail_len);
462
463 rcu_assign_pointer(sdata->u.ap.beacon, new);
464
465 synchronize_rcu();
466
467 kfree(old);
468
Johannes Berg9d139c82008-07-09 14:40:37 +0200469 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100470}
471
472static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
473 struct beacon_parameters *params)
474{
Johannes Berg14db74b2008-07-29 13:22:52 +0200475 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100476 struct beacon_data *old;
477
Johannes Berg14db74b2008-07-29 13:22:52 +0200478 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
479
Johannes Berg05c914f2008-09-11 00:01:58 +0200480 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100481 return -EINVAL;
482
483 old = sdata->u.ap.beacon;
484
485 if (old)
486 return -EALREADY;
487
488 return ieee80211_config_beacon(sdata, params);
489}
490
491static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
492 struct beacon_parameters *params)
493{
Johannes Berg14db74b2008-07-29 13:22:52 +0200494 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100495 struct beacon_data *old;
496
Johannes Berg14db74b2008-07-29 13:22:52 +0200497 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
498
Johannes Berg05c914f2008-09-11 00:01:58 +0200499 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100500 return -EINVAL;
501
502 old = sdata->u.ap.beacon;
503
504 if (!old)
505 return -ENOENT;
506
507 return ieee80211_config_beacon(sdata, params);
508}
509
510static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
511{
Johannes Berg14db74b2008-07-29 13:22:52 +0200512 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100513 struct beacon_data *old;
514
Johannes Berg14db74b2008-07-29 13:22:52 +0200515 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
516
Johannes Berg05c914f2008-09-11 00:01:58 +0200517 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100518 return -EINVAL;
519
520 old = sdata->u.ap.beacon;
521
522 if (!old)
523 return -ENOENT;
524
525 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
526 synchronize_rcu();
527 kfree(old);
528
Johannes Berg9d139c82008-07-09 14:40:37 +0200529 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100530}
531
Johannes Berg4fd69312007-12-19 02:03:35 +0100532/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
533struct iapp_layer2_update {
534 u8 da[ETH_ALEN]; /* broadcast */
535 u8 sa[ETH_ALEN]; /* STA addr */
536 __be16 len; /* 6 */
537 u8 dsap; /* 0 */
538 u8 ssap; /* 0 */
539 u8 control;
540 u8 xid_info[3];
541} __attribute__ ((packed));
542
543static void ieee80211_send_layer2_update(struct sta_info *sta)
544{
545 struct iapp_layer2_update *msg;
546 struct sk_buff *skb;
547
548 /* Send Level 2 Update Frame to update forwarding tables in layer 2
549 * bridge devices */
550
551 skb = dev_alloc_skb(sizeof(*msg));
552 if (!skb)
553 return;
554 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
555
556 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
557 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
558
559 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200560 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100561 msg->len = htons(6);
562 msg->dsap = 0;
563 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
564 msg->control = 0xaf; /* XID response lsb.1111F101.
565 * F=0 (no poll command; unsolicited frame) */
566 msg->xid_info[0] = 0x81; /* XID format identifier */
567 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
568 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
569
Johannes Bergd0709a62008-02-25 16:27:46 +0100570 skb->dev = sta->sdata->dev;
571 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100572 memset(skb->cb, 0, sizeof(skb->cb));
573 netif_rx(skb);
574}
575
576static void sta_apply_parameters(struct ieee80211_local *local,
577 struct sta_info *sta,
578 struct station_parameters *params)
579{
580 u32 rates;
581 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100582 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100583 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100584
Johannes Berg73651ee2008-02-25 16:27:47 +0100585 /*
586 * FIXME: updating the flags is racy when this function is
587 * called from ieee80211_change_station(), this will
588 * be resolved in a future patch.
589 */
590
Johannes Berg4fd69312007-12-19 02:03:35 +0100591 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200592 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100593 sta->flags &= ~WLAN_STA_AUTHORIZED;
594 if (params->station_flags & STATION_FLAG_AUTHORIZED)
595 sta->flags |= WLAN_STA_AUTHORIZED;
596
597 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
598 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
599 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
600
601 sta->flags &= ~WLAN_STA_WME;
602 if (params->station_flags & STATION_FLAG_WME)
603 sta->flags |= WLAN_STA_WME;
Johannes Berg07346f812008-05-03 01:02:02 +0200604 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100605 }
606
Johannes Berg73651ee2008-02-25 16:27:47 +0100607 /*
608 * FIXME: updating the following information is racy when this
609 * function is called from ieee80211_change_station().
610 * However, all this information should be static so
611 * maybe we should just reject attemps to change it.
612 */
613
Johannes Berg4fd69312007-12-19 02:03:35 +0100614 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200615 sta->sta.aid = params->aid;
616 if (sta->sta.aid > IEEE80211_MAX_AID)
617 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100618 }
619
620 if (params->listen_interval >= 0)
621 sta->listen_interval = params->listen_interval;
622
623 if (params->supported_rates) {
624 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100625 sband = local->hw.wiphy->bands[local->oper_channel->band];
626
Johannes Berg4fd69312007-12-19 02:03:35 +0100627 for (i = 0; i < params->supported_rates_len; i++) {
628 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100629 for (j = 0; j < sband->n_bitrates; j++) {
630 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100631 rates |= BIT(j);
632 }
633 }
Johannes Berg323ce792008-09-11 02:45:11 +0200634 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100635 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100636
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200637 if (params->ht_capa)
638 ieee80211_ht_cap_ie_to_sta_ht_cap(params->ht_capa,
639 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300640
Johannes Berg902acc72008-02-23 15:17:19 +0100641 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100642 switch (params->plink_action) {
643 case PLINK_ACTION_OPEN:
644 mesh_plink_open(sta);
645 break;
646 case PLINK_ACTION_BLOCK:
647 mesh_plink_block(sta);
648 break;
649 }
Johannes Berg902acc72008-02-23 15:17:19 +0100650 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100651}
652
653static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
654 u8 *mac, struct station_parameters *params)
655{
Johannes Berg14db74b2008-07-29 13:22:52 +0200656 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100657 struct sta_info *sta;
658 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100659 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100660
661 /* Prevent a race with changing the rate control algorithm */
662 if (!netif_running(dev))
663 return -ENETDOWN;
664
Johannes Berg4fd69312007-12-19 02:03:35 +0100665 if (params->vlan) {
666 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
667
Johannes Berg05c914f2008-09-11 00:01:58 +0200668 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
669 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100670 return -EINVAL;
671 } else
672 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
673
Johannes Berg03e44972008-02-27 09:56:40 +0100674 if (compare_ether_addr(mac, dev->dev_addr) == 0)
675 return -EINVAL;
676
677 if (is_multicast_ether_addr(mac))
678 return -EINVAL;
679
680 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100681 if (!sta)
682 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100683
684 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
685
686 sta_apply_parameters(local, sta, params);
687
Johannes Berg4b7679a2008-09-18 18:14:18 +0200688 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100689
Johannes Berg73651ee2008-02-25 16:27:47 +0100690 rcu_read_lock();
691
692 err = sta_info_insert(sta);
693 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200694 /* STA has been freed */
Johannes Berg73651ee2008-02-25 16:27:47 +0100695 rcu_read_unlock();
696 return err;
697 }
698
Johannes Berg05c914f2008-09-11 00:01:58 +0200699 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
700 sdata->vif.type == NL80211_IFTYPE_AP)
Johannes Berg73651ee2008-02-25 16:27:47 +0100701 ieee80211_send_layer2_update(sta);
702
703 rcu_read_unlock();
704
Johannes Berg4fd69312007-12-19 02:03:35 +0100705 return 0;
706}
707
708static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
709 u8 *mac)
710{
Johannes Berg14db74b2008-07-29 13:22:52 +0200711 struct ieee80211_local *local = wiphy_priv(wiphy);
712 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100713 struct sta_info *sta;
714
Johannes Berg14db74b2008-07-29 13:22:52 +0200715 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
716
Johannes Berg4fd69312007-12-19 02:03:35 +0100717 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200718 rcu_read_lock();
719
Johannes Berg4fd69312007-12-19 02:03:35 +0100720 /* XXX: get sta belonging to dev */
721 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200722 if (!sta) {
723 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100724 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200725 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100726
Johannes Bergd0709a62008-02-25 16:27:46 +0100727 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200728 rcu_read_unlock();
729
Johannes Berg4f6fab42008-03-31 19:23:02 +0200730 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100731 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100732 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100733
734 return 0;
735}
736
737static int ieee80211_change_station(struct wiphy *wiphy,
738 struct net_device *dev,
739 u8 *mac,
740 struct station_parameters *params)
741{
Johannes Berg14db74b2008-07-29 13:22:52 +0200742 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100743 struct sta_info *sta;
744 struct ieee80211_sub_if_data *vlansdata;
745
Johannes Berg98dd6a52008-04-10 15:36:09 +0200746 rcu_read_lock();
747
Johannes Berg4fd69312007-12-19 02:03:35 +0100748 /* XXX: get sta belonging to dev */
749 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200750 if (!sta) {
751 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100752 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200753 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100754
Johannes Bergd0709a62008-02-25 16:27:46 +0100755 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100756 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
757
Johannes Berg05c914f2008-09-11 00:01:58 +0200758 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
759 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200760 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100761 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200762 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100763
Johannes Berg14db74b2008-07-29 13:22:52 +0200764 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100765 ieee80211_send_layer2_update(sta);
766 }
767
768 sta_apply_parameters(local, sta, params);
769
Johannes Berg98dd6a52008-04-10 15:36:09 +0200770 rcu_read_unlock();
771
Johannes Berg4fd69312007-12-19 02:03:35 +0100772 return 0;
773}
774
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100775#ifdef CONFIG_MAC80211_MESH
776static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
777 u8 *dst, u8 *next_hop)
778{
Johannes Berg14db74b2008-07-29 13:22:52 +0200779 struct ieee80211_local *local = wiphy_priv(wiphy);
780 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100781 struct mesh_path *mpath;
782 struct sta_info *sta;
783 int err;
784
785 if (!netif_running(dev))
786 return -ENETDOWN;
787
Johannes Berg14db74b2008-07-29 13:22:52 +0200788 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
789
Johannes Berg05c914f2008-09-11 00:01:58 +0200790 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100791 return -ENOTSUPP;
792
Johannes Bergd0709a62008-02-25 16:27:46 +0100793 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100794 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100795 if (!sta) {
796 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100798 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100799
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200800 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100801 if (err) {
802 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100803 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100804 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100805
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200806 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100807 if (!mpath) {
808 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100809 return -ENXIO;
810 }
811 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100812
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100813 rcu_read_unlock();
814 return 0;
815}
816
817static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
818 u8 *dst)
819{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200820 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100821
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200822 if (dst)
823 return mesh_path_del(dst, sdata);
824
825 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100826 return 0;
827}
828
829static int ieee80211_change_mpath(struct wiphy *wiphy,
830 struct net_device *dev,
831 u8 *dst, u8 *next_hop)
832{
Johannes Berg14db74b2008-07-29 13:22:52 +0200833 struct ieee80211_local *local = wiphy_priv(wiphy);
834 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100835 struct mesh_path *mpath;
836 struct sta_info *sta;
837
838 if (!netif_running(dev))
839 return -ENETDOWN;
840
Johannes Berg14db74b2008-07-29 13:22:52 +0200841 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
842
Johannes Berg05c914f2008-09-11 00:01:58 +0200843 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100844 return -ENOTSUPP;
845
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100846 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100847
848 sta = sta_info_get(local, next_hop);
849 if (!sta) {
850 rcu_read_unlock();
851 return -ENOENT;
852 }
853
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200854 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100855 if (!mpath) {
856 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100857 return -ENOENT;
858 }
859
860 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100861
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100862 rcu_read_unlock();
863 return 0;
864}
865
866static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
867 struct mpath_info *pinfo)
868{
869 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200870 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100871 else
872 memset(next_hop, 0, ETH_ALEN);
873
874 pinfo->filled = MPATH_INFO_FRAME_QLEN |
875 MPATH_INFO_DSN |
876 MPATH_INFO_METRIC |
877 MPATH_INFO_EXPTIME |
878 MPATH_INFO_DISCOVERY_TIMEOUT |
879 MPATH_INFO_DISCOVERY_RETRIES |
880 MPATH_INFO_FLAGS;
881
882 pinfo->frame_qlen = mpath->frame_queue.qlen;
883 pinfo->dsn = mpath->dsn;
884 pinfo->metric = mpath->metric;
885 if (time_before(jiffies, mpath->exp_time))
886 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
887 pinfo->discovery_timeout =
888 jiffies_to_msecs(mpath->discovery_timeout);
889 pinfo->discovery_retries = mpath->discovery_retries;
890 pinfo->flags = 0;
891 if (mpath->flags & MESH_PATH_ACTIVE)
892 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
893 if (mpath->flags & MESH_PATH_RESOLVING)
894 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
895 if (mpath->flags & MESH_PATH_DSN_VALID)
896 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
897 if (mpath->flags & MESH_PATH_FIXED)
898 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
899 if (mpath->flags & MESH_PATH_RESOLVING)
900 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
901
902 pinfo->flags = mpath->flags;
903}
904
905static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
906 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
907
908{
Johannes Berg14db74b2008-07-29 13:22:52 +0200909 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100910 struct mesh_path *mpath;
911
Johannes Berg14db74b2008-07-29 13:22:52 +0200912 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
913
Johannes Berg05c914f2008-09-11 00:01:58 +0200914 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100915 return -ENOTSUPP;
916
917 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200918 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100919 if (!mpath) {
920 rcu_read_unlock();
921 return -ENOENT;
922 }
923 memcpy(dst, mpath->dst, ETH_ALEN);
924 mpath_set_pinfo(mpath, next_hop, pinfo);
925 rcu_read_unlock();
926 return 0;
927}
928
929static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
930 int idx, u8 *dst, u8 *next_hop,
931 struct mpath_info *pinfo)
932{
Johannes Berg14db74b2008-07-29 13:22:52 +0200933 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100934 struct mesh_path *mpath;
935
Johannes Berg14db74b2008-07-29 13:22:52 +0200936 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
937
Johannes Berg05c914f2008-09-11 00:01:58 +0200938 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100939 return -ENOTSUPP;
940
941 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200942 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100943 if (!mpath) {
944 rcu_read_unlock();
945 return -ENOENT;
946 }
947 memcpy(dst, mpath->dst, ETH_ALEN);
948 mpath_set_pinfo(mpath, next_hop, pinfo);
949 rcu_read_unlock();
950 return 0;
951}
952#endif
953
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300954static int ieee80211_change_bss(struct wiphy *wiphy,
955 struct net_device *dev,
956 struct bss_parameters *params)
957{
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300958 struct ieee80211_sub_if_data *sdata;
959 u32 changed = 0;
960
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300961 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
962
Johannes Berg05c914f2008-09-11 00:01:58 +0200963 if (sdata->vif.type != NL80211_IFTYPE_AP)
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300964 return -EINVAL;
965
966 if (params->use_cts_prot >= 0) {
967 sdata->bss_conf.use_cts_prot = params->use_cts_prot;
968 changed |= BSS_CHANGED_ERP_CTS_PROT;
969 }
970 if (params->use_short_preamble >= 0) {
971 sdata->bss_conf.use_short_preamble =
972 params->use_short_preamble;
973 changed |= BSS_CHANGED_ERP_PREAMBLE;
974 }
975 if (params->use_short_slot_time >= 0) {
976 sdata->bss_conf.use_short_slot =
977 params->use_short_slot_time;
978 changed |= BSS_CHANGED_ERP_SLOT;
979 }
980
981 ieee80211_bss_info_change_notify(sdata, changed);
982
983 return 0;
984}
985
Jiri Bencf0706e822007-05-05 11:45:53 -0700986struct cfg80211_ops mac80211_config_ops = {
987 .add_virtual_intf = ieee80211_add_iface,
988 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +0200989 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100990 .add_key = ieee80211_add_key,
991 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +0100992 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100993 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100994 .add_beacon = ieee80211_add_beacon,
995 .set_beacon = ieee80211_set_beacon,
996 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +0100997 .add_station = ieee80211_add_station,
998 .del_station = ieee80211_del_station,
999 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001000 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001001 .dump_station = ieee80211_dump_station,
1002#ifdef CONFIG_MAC80211_MESH
1003 .add_mpath = ieee80211_add_mpath,
1004 .del_mpath = ieee80211_del_mpath,
1005 .change_mpath = ieee80211_change_mpath,
1006 .get_mpath = ieee80211_get_mpath,
1007 .dump_mpath = ieee80211_dump_mpath,
1008#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001009 .change_bss = ieee80211_change_bss,
Jiri Bencf0706e822007-05-05 11:45:53 -07001010};