blob: 297c257864c771c069c44f2b04aa68c2ad1b48c7 [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 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 Bencf0706e822007-05-05 11:45:53 -070043static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010044 enum nl80211_iftype type, u32 *flags,
45 struct vif_params *params)
Jiri Bencf0706e822007-05-05 11:45:53 -070046{
47 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg42613db2007-09-28 21:52:27 +020048 enum ieee80211_if_types itype;
Michael Wu8cc9a732008-01-31 19:48:23 +010049 struct net_device *dev;
50 struct ieee80211_sub_if_data *sdata;
51 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070052
Johannes Berg42613db2007-09-28 21:52:27 +020053 itype = nl80211_type_to_mac80211_type(type);
54 if (itype == IEEE80211_IF_TYPE_INVALID)
Jiri Bencf0706e822007-05-05 11:45:53 -070055 return -EINVAL;
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070064}
65
66static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
67{
Jiri Bencf0706e822007-05-05 11:45:53 -070068 struct net_device *dev;
Jiri Bencf0706e822007-05-05 11:45:53 -070069
Johannes Berg42613db2007-09-28 21:52:27 +020070 /* we're under RTNL */
71 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e822007-05-05 11:45:53 -070072 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020073 return -ENODEV;
Jiri Bencf0706e822007-05-05 11:45:53 -070074
Johannes Berg75636522008-07-09 14:40:35 +020075 ieee80211_if_remove(dev);
Jiri Bencf0706e822007-05-05 11:45:53 -070076
Johannes Berg75636522008-07-09 14:40:35 +020077 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070078}
79
Johannes Berg42613db2007-09-28 21:52:27 +020080static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010081 enum nl80211_iftype type, u32 *flags,
82 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020083{
Johannes Berg14db74b2008-07-29 13:22:52 +020084 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg42613db2007-09-28 21:52:27 +020085 struct net_device *dev;
86 enum ieee80211_if_types itype;
87 struct ieee80211_sub_if_data *sdata;
Johannes Bergf3947e22008-07-09 14:40:36 +020088 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020089
Johannes Berg42613db2007-09-28 21:52:27 +020090 /* we're under RTNL */
91 dev = __dev_get_by_index(&init_net, ifindex);
92 if (!dev)
93 return -ENODEV;
94
Johannes Berg42613db2007-09-28 21:52:27 +020095 itype = nl80211_type_to_mac80211_type(type);
96 if (itype == IEEE80211_IF_TYPE_INVALID)
97 return -EINVAL;
98
Johannes Berg14db74b2008-07-29 13:22:52 +020099 if (dev == local->mdev)
100 return -EOPNOTSUPP;
101
Johannes Berg42613db2007-09-28 21:52:27 +0200102 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
103
Johannes Bergf3947e22008-07-09 14:40:36 +0200104 ret = ieee80211_if_change_type(sdata, itype);
105 if (ret)
106 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200107
Johannes Berg902acc72008-02-23 15:17:19 +0100108 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
109 ieee80211_if_sta_set_mesh_id(&sdata->u.sta,
110 params->mesh_id_len,
111 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100112
Michael Wu8cc9a732008-01-31 19:48:23 +0100113 if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags)
114 return 0;
115
116 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200117 return 0;
118}
119
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
121 u8 key_idx, u8 *mac_addr,
122 struct key_params *params)
123{
Johannes Berg14db74b2008-07-29 13:22:52 +0200124 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100125 struct ieee80211_sub_if_data *sdata;
126 struct sta_info *sta = NULL;
127 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100128 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200129 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130
Johannes Berg14db74b2008-07-29 13:22:52 +0200131 if (dev == local->mdev)
132 return -EOPNOTSUPP;
133
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100134 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
135
136 switch (params->cipher) {
137 case WLAN_CIPHER_SUITE_WEP40:
138 case WLAN_CIPHER_SUITE_WEP104:
139 alg = ALG_WEP;
140 break;
141 case WLAN_CIPHER_SUITE_TKIP:
142 alg = ALG_TKIP;
143 break;
144 case WLAN_CIPHER_SUITE_CCMP:
145 alg = ALG_CCMP;
146 break;
147 default:
148 return -EINVAL;
149 }
150
Johannes Bergdb4d1162008-02-25 16:27:45 +0100151 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
152 if (!key)
153 return -ENOMEM;
154
Johannes Berg3b967662008-04-08 17:56:52 +0200155 rcu_read_lock();
156
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 if (mac_addr) {
158 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100159 if (!sta) {
160 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200161 err = -ENOENT;
162 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100163 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100164 }
165
Johannes Bergdb4d1162008-02-25 16:27:45 +0100166 ieee80211_key_link(key, sdata, sta);
167
Johannes Berg3b967662008-04-08 17:56:52 +0200168 err = 0;
169 out_unlock:
170 rcu_read_unlock();
171
172 return err;
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{
Johannes Berg14db74b2008-07-29 13:22:52 +0200178 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100179 struct ieee80211_sub_if_data *sdata;
180 struct sta_info *sta;
181 int ret;
182
Johannes Berg14db74b2008-07-29 13:22:52 +0200183 if (dev == local->mdev)
184 return -EOPNOTSUPP;
185
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100186 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
187
Johannes Berg3b967662008-04-08 17:56:52 +0200188 rcu_read_lock();
189
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100190 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200191 ret = -ENOENT;
192
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100193 sta = sta_info_get(sdata->local, mac_addr);
194 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200195 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100196
Johannes Bergdb4d1162008-02-25 16:27:45 +0100197 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100198 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100199 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200200 ret = 0;
201 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100202
Johannes Berg3b967662008-04-08 17:56:52 +0200203 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204 }
205
Johannes Berg3b967662008-04-08 17:56:52 +0200206 if (!sdata->keys[key_idx]) {
207 ret = -ENOENT;
208 goto out_unlock;
209 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100210
Johannes Bergd0709a62008-02-25 16:27:46 +0100211 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100212 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100213
Johannes Berg3b967662008-04-08 17:56:52 +0200214 ret = 0;
215 out_unlock:
216 rcu_read_unlock();
217
218 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100219}
220
Johannes Berg62da92f2007-12-19 02:03:31 +0100221static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
222 u8 key_idx, u8 *mac_addr, void *cookie,
223 void (*callback)(void *cookie,
224 struct key_params *params))
225{
Johannes Berg14db74b2008-07-29 13:22:52 +0200226 struct ieee80211_local *local = wiphy_priv(wiphy);
227 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100228 struct sta_info *sta = NULL;
229 u8 seq[6] = {0};
230 struct key_params params;
231 struct ieee80211_key *key;
232 u32 iv32;
233 u16 iv16;
234 int err = -ENOENT;
235
Johannes Berg14db74b2008-07-29 13:22:52 +0200236 if (dev == local->mdev)
237 return -EOPNOTSUPP;
238
239 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
240
Johannes Berg3b967662008-04-08 17:56:52 +0200241 rcu_read_lock();
242
Johannes Berg62da92f2007-12-19 02:03:31 +0100243 if (mac_addr) {
244 sta = sta_info_get(sdata->local, mac_addr);
245 if (!sta)
246 goto out;
247
248 key = sta->key;
249 } else
250 key = sdata->keys[key_idx];
251
252 if (!key)
253 goto out;
254
255 memset(&params, 0, sizeof(params));
256
257 switch (key->conf.alg) {
258 case ALG_TKIP:
259 params.cipher = WLAN_CIPHER_SUITE_TKIP;
260
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700261 iv32 = key->u.tkip.tx.iv32;
262 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100263
264 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
265 sdata->local->ops->get_tkip_seq)
266 sdata->local->ops->get_tkip_seq(
267 local_to_hw(sdata->local),
268 key->conf.hw_key_idx,
269 &iv32, &iv16);
270
271 seq[0] = iv16 & 0xff;
272 seq[1] = (iv16 >> 8) & 0xff;
273 seq[2] = iv32 & 0xff;
274 seq[3] = (iv32 >> 8) & 0xff;
275 seq[4] = (iv32 >> 16) & 0xff;
276 seq[5] = (iv32 >> 24) & 0xff;
277 params.seq = seq;
278 params.seq_len = 6;
279 break;
280 case ALG_CCMP:
281 params.cipher = WLAN_CIPHER_SUITE_CCMP;
282 seq[0] = key->u.ccmp.tx_pn[5];
283 seq[1] = key->u.ccmp.tx_pn[4];
284 seq[2] = key->u.ccmp.tx_pn[3];
285 seq[3] = key->u.ccmp.tx_pn[2];
286 seq[4] = key->u.ccmp.tx_pn[1];
287 seq[5] = key->u.ccmp.tx_pn[0];
288 params.seq = seq;
289 params.seq_len = 6;
290 break;
291 case ALG_WEP:
292 if (key->conf.keylen == 5)
293 params.cipher = WLAN_CIPHER_SUITE_WEP40;
294 else
295 params.cipher = WLAN_CIPHER_SUITE_WEP104;
296 break;
297 }
298
299 params.key = key->conf.key;
300 params.key_len = key->conf.keylen;
301
302 callback(cookie, &params);
303 err = 0;
304
305 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200306 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100307 return err;
308}
309
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100310static int ieee80211_config_default_key(struct wiphy *wiphy,
311 struct net_device *dev,
312 u8 key_idx)
313{
Johannes Berg14db74b2008-07-29 13:22:52 +0200314 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100315 struct ieee80211_sub_if_data *sdata;
316
Johannes Berg14db74b2008-07-29 13:22:52 +0200317 if (dev == local->mdev)
318 return -EOPNOTSUPP;
319
Johannes Berg3b967662008-04-08 17:56:52 +0200320 rcu_read_lock();
321
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100322 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
323 ieee80211_set_default_key(sdata, key_idx);
324
Johannes Berg3b967662008-04-08 17:56:52 +0200325 rcu_read_unlock();
326
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100327 return 0;
328}
329
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100330static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
331{
Johannes Bergd0709a62008-02-25 16:27:46 +0100332 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333
334 sinfo->filled = STATION_INFO_INACTIVE_TIME |
335 STATION_INFO_RX_BYTES |
336 STATION_INFO_TX_BYTES;
337
338 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
339 sinfo->rx_bytes = sta->rx_bytes;
340 sinfo->tx_bytes = sta->tx_bytes;
341
Johannes Berg902acc72008-02-23 15:17:19 +0100342 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100343#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100344 sinfo->filled |= STATION_INFO_LLID |
345 STATION_INFO_PLID |
346 STATION_INFO_PLINK_STATE;
347
348 sinfo->llid = le16_to_cpu(sta->llid);
349 sinfo->plid = le16_to_cpu(sta->plid);
350 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100351#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100352 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100353}
354
355
356static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
357 int idx, u8 *mac, struct station_info *sinfo)
358{
359 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
360 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100361 int ret = -ENOENT;
362
363 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100364
365 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100366 if (sta) {
367 ret = 0;
368 memcpy(mac, sta->addr, ETH_ALEN);
369 sta_set_sinfo(sta, sinfo);
370 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100371
Johannes Bergd0709a62008-02-25 16:27:46 +0100372 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100373
Johannes Bergd0709a62008-02-25 16:27:46 +0100374 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100375}
376
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100377static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100378 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100379{
380 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
381 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100382 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100383
Johannes Bergd0709a62008-02-25 16:27:46 +0100384 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100385
386 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100387
Johannes Bergd0709a62008-02-25 16:27:46 +0100388 sta = sta_info_get(local, mac);
389 if (sta) {
390 ret = 0;
391 sta_set_sinfo(sta, sinfo);
392 }
393
394 rcu_read_unlock();
395
396 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100397}
398
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100399/*
400 * This handles both adding a beacon and setting new beacon info
401 */
402static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
403 struct beacon_parameters *params)
404{
405 struct beacon_data *new, *old;
406 int new_head_len, new_tail_len;
407 int size;
408 int err = -EINVAL;
409
410 old = sdata->u.ap.beacon;
411
412 /* head must not be zero-length */
413 if (params->head && !params->head_len)
414 return -EINVAL;
415
416 /*
417 * This is a kludge. beacon interval should really be part
418 * of the beacon information.
419 */
420 if (params->interval) {
421 sdata->local->hw.conf.beacon_int = params->interval;
422 if (ieee80211_hw_config(sdata->local))
423 return -EINVAL;
424 /*
425 * We updated some parameter so if below bails out
426 * it's not an error.
427 */
428 err = 0;
429 }
430
431 /* Need to have a beacon head if we don't have one yet */
432 if (!params->head && !old)
433 return err;
434
435 /* sorry, no way to start beaconing without dtim period */
436 if (!params->dtim_period && !old)
437 return err;
438
439 /* new or old head? */
440 if (params->head)
441 new_head_len = params->head_len;
442 else
443 new_head_len = old->head_len;
444
445 /* new or old tail? */
446 if (params->tail || !old)
447 /* params->tail_len will be zero for !params->tail */
448 new_tail_len = params->tail_len;
449 else
450 new_tail_len = old->tail_len;
451
452 size = sizeof(*new) + new_head_len + new_tail_len;
453
454 new = kzalloc(size, GFP_KERNEL);
455 if (!new)
456 return -ENOMEM;
457
458 /* start filling the new info now */
459
460 /* new or old dtim period? */
461 if (params->dtim_period)
462 new->dtim_period = params->dtim_period;
463 else
464 new->dtim_period = old->dtim_period;
465
466 /*
467 * pointers go into the block we allocated,
468 * memory is | beacon_data | head | tail |
469 */
470 new->head = ((u8 *) new) + sizeof(*new);
471 new->tail = new->head + new_head_len;
472 new->head_len = new_head_len;
473 new->tail_len = new_tail_len;
474
475 /* copy in head */
476 if (params->head)
477 memcpy(new->head, params->head, new_head_len);
478 else
479 memcpy(new->head, old->head, new_head_len);
480
481 /* copy in optional tail */
482 if (params->tail)
483 memcpy(new->tail, params->tail, new_tail_len);
484 else
485 if (old)
486 memcpy(new->tail, old->tail, new_tail_len);
487
488 rcu_assign_pointer(sdata->u.ap.beacon, new);
489
490 synchronize_rcu();
491
492 kfree(old);
493
Johannes Berg9d139c82008-07-09 14:40:37 +0200494 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100495}
496
497static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
498 struct beacon_parameters *params)
499{
Johannes Berg14db74b2008-07-29 13:22:52 +0200500 struct ieee80211_local *local = wiphy_priv(wiphy);
501 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100502 struct beacon_data *old;
503
Johannes Berg14db74b2008-07-29 13:22:52 +0200504 if (dev == local->mdev)
505 return -EOPNOTSUPP;
506
507 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
508
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100509 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
510 return -EINVAL;
511
512 old = sdata->u.ap.beacon;
513
514 if (old)
515 return -EALREADY;
516
517 return ieee80211_config_beacon(sdata, params);
518}
519
520static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
521 struct beacon_parameters *params)
522{
Johannes Berg14db74b2008-07-29 13:22:52 +0200523 struct ieee80211_local *local = wiphy_priv(wiphy);
524 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100525 struct beacon_data *old;
526
Johannes Berg14db74b2008-07-29 13:22:52 +0200527 if (dev == local->mdev)
528 return -EOPNOTSUPP;
529
530 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
531
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100532 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
533 return -EINVAL;
534
535 old = sdata->u.ap.beacon;
536
537 if (!old)
538 return -ENOENT;
539
540 return ieee80211_config_beacon(sdata, params);
541}
542
543static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
544{
Johannes Berg14db74b2008-07-29 13:22:52 +0200545 struct ieee80211_local *local = wiphy_priv(wiphy);
546 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100547 struct beacon_data *old;
548
Johannes Berg14db74b2008-07-29 13:22:52 +0200549 if (dev == local->mdev)
550 return -EOPNOTSUPP;
551
552 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
553
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100554 if (sdata->vif.type != IEEE80211_IF_TYPE_AP)
555 return -EINVAL;
556
557 old = sdata->u.ap.beacon;
558
559 if (!old)
560 return -ENOENT;
561
562 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
563 synchronize_rcu();
564 kfree(old);
565
Johannes Berg9d139c82008-07-09 14:40:37 +0200566 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100567}
568
Johannes Berg4fd69312007-12-19 02:03:35 +0100569/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
570struct iapp_layer2_update {
571 u8 da[ETH_ALEN]; /* broadcast */
572 u8 sa[ETH_ALEN]; /* STA addr */
573 __be16 len; /* 6 */
574 u8 dsap; /* 0 */
575 u8 ssap; /* 0 */
576 u8 control;
577 u8 xid_info[3];
578} __attribute__ ((packed));
579
580static void ieee80211_send_layer2_update(struct sta_info *sta)
581{
582 struct iapp_layer2_update *msg;
583 struct sk_buff *skb;
584
585 /* Send Level 2 Update Frame to update forwarding tables in layer 2
586 * bridge devices */
587
588 skb = dev_alloc_skb(sizeof(*msg));
589 if (!skb)
590 return;
591 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
592
593 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
594 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
595
596 memset(msg->da, 0xff, ETH_ALEN);
597 memcpy(msg->sa, sta->addr, ETH_ALEN);
598 msg->len = htons(6);
599 msg->dsap = 0;
600 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
601 msg->control = 0xaf; /* XID response lsb.1111F101.
602 * F=0 (no poll command; unsolicited frame) */
603 msg->xid_info[0] = 0x81; /* XID format identifier */
604 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
605 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
606
Johannes Bergd0709a62008-02-25 16:27:46 +0100607 skb->dev = sta->sdata->dev;
608 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100609 memset(skb->cb, 0, sizeof(skb->cb));
610 netif_rx(skb);
611}
612
613static void sta_apply_parameters(struct ieee80211_local *local,
614 struct sta_info *sta,
615 struct station_parameters *params)
616{
617 u32 rates;
618 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100619 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100620 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100621
Johannes Berg73651ee2008-02-25 16:27:47 +0100622 /*
623 * FIXME: updating the flags is racy when this function is
624 * called from ieee80211_change_station(), this will
625 * be resolved in a future patch.
626 */
627
Johannes Berg4fd69312007-12-19 02:03:35 +0100628 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200629 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100630 sta->flags &= ~WLAN_STA_AUTHORIZED;
631 if (params->station_flags & STATION_FLAG_AUTHORIZED)
632 sta->flags |= WLAN_STA_AUTHORIZED;
633
634 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
635 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
636 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
637
638 sta->flags &= ~WLAN_STA_WME;
639 if (params->station_flags & STATION_FLAG_WME)
640 sta->flags |= WLAN_STA_WME;
Johannes Berg07346f812008-05-03 01:02:02 +0200641 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100642 }
643
Johannes Berg73651ee2008-02-25 16:27:47 +0100644 /*
645 * FIXME: updating the following information is racy when this
646 * function is called from ieee80211_change_station().
647 * However, all this information should be static so
648 * maybe we should just reject attemps to change it.
649 */
650
Johannes Berg4fd69312007-12-19 02:03:35 +0100651 if (params->aid) {
652 sta->aid = params->aid;
653 if (sta->aid > IEEE80211_MAX_AID)
654 sta->aid = 0; /* XXX: should this be an error? */
655 }
656
657 if (params->listen_interval >= 0)
658 sta->listen_interval = params->listen_interval;
659
660 if (params->supported_rates) {
661 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100662 sband = local->hw.wiphy->bands[local->oper_channel->band];
663
Johannes Berg4fd69312007-12-19 02:03:35 +0100664 for (i = 0; i < params->supported_rates_len; i++) {
665 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100666 for (j = 0; j < sband->n_bitrates; j++) {
667 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100668 rates |= BIT(j);
669 }
670 }
Johannes Berg8318d782008-01-24 19:38:38 +0100671 sta->supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100672 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100673
Johannes Berg902acc72008-02-23 15:17:19 +0100674 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100675 switch (params->plink_action) {
676 case PLINK_ACTION_OPEN:
677 mesh_plink_open(sta);
678 break;
679 case PLINK_ACTION_BLOCK:
680 mesh_plink_block(sta);
681 break;
682 }
Johannes Berg902acc72008-02-23 15:17:19 +0100683 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100684}
685
686static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
687 u8 *mac, struct station_parameters *params)
688{
Johannes Berg14db74b2008-07-29 13:22:52 +0200689 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100690 struct sta_info *sta;
691 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100692 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100693
Johannes Berg14db74b2008-07-29 13:22:52 +0200694 if (dev == local->mdev || params->vlan == local->mdev)
695 return -EOPNOTSUPP;
696
Johannes Berg4fd69312007-12-19 02:03:35 +0100697 /* Prevent a race with changing the rate control algorithm */
698 if (!netif_running(dev))
699 return -ENETDOWN;
700
Johannes Berg4fd69312007-12-19 02:03:35 +0100701 if (params->vlan) {
702 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
703
Nicolas Kaiser679fda12008-05-20 18:42:54 +0200704 if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN &&
Johannes Berg4fd69312007-12-19 02:03:35 +0100705 sdata->vif.type != IEEE80211_IF_TYPE_AP)
706 return -EINVAL;
707 } else
708 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
709
Johannes Berg03e44972008-02-27 09:56:40 +0100710 if (compare_ether_addr(mac, dev->dev_addr) == 0)
711 return -EINVAL;
712
713 if (is_multicast_ether_addr(mac))
714 return -EINVAL;
715
716 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100717 if (!sta)
718 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100719
720 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
721
722 sta_apply_parameters(local, sta, params);
723
724 rate_control_rate_init(sta, local);
725
Johannes Berg73651ee2008-02-25 16:27:47 +0100726 rcu_read_lock();
727
728 err = sta_info_insert(sta);
729 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200730 /* STA has been freed */
Johannes Berg73651ee2008-02-25 16:27:47 +0100731 rcu_read_unlock();
732 return err;
733 }
734
735 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN ||
736 sdata->vif.type == IEEE80211_IF_TYPE_AP)
737 ieee80211_send_layer2_update(sta);
738
739 rcu_read_unlock();
740
Johannes Berg4fd69312007-12-19 02:03:35 +0100741 return 0;
742}
743
744static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
745 u8 *mac)
746{
Johannes Berg14db74b2008-07-29 13:22:52 +0200747 struct ieee80211_local *local = wiphy_priv(wiphy);
748 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100749 struct sta_info *sta;
750
Johannes Berg14db74b2008-07-29 13:22:52 +0200751 if (dev == local->mdev)
752 return -EOPNOTSUPP;
753
754 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
755
Johannes Berg4fd69312007-12-19 02:03:35 +0100756 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200757 rcu_read_lock();
758
Johannes Berg4fd69312007-12-19 02:03:35 +0100759 /* XXX: get sta belonging to dev */
760 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200761 if (!sta) {
762 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100763 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200764 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100765
Johannes Bergd0709a62008-02-25 16:27:46 +0100766 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200767 rcu_read_unlock();
768
Johannes Berg4f6fab42008-03-31 19:23:02 +0200769 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100770 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100771 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100772
773 return 0;
774}
775
776static int ieee80211_change_station(struct wiphy *wiphy,
777 struct net_device *dev,
778 u8 *mac,
779 struct station_parameters *params)
780{
Johannes Berg14db74b2008-07-29 13:22:52 +0200781 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100782 struct sta_info *sta;
783 struct ieee80211_sub_if_data *vlansdata;
784
Johannes Berg14db74b2008-07-29 13:22:52 +0200785 if (dev == local->mdev || params->vlan == local->mdev)
786 return -EOPNOTSUPP;
787
Johannes Berg98dd6a52008-04-10 15:36:09 +0200788 rcu_read_lock();
789
Johannes Berg4fd69312007-12-19 02:03:35 +0100790 /* XXX: get sta belonging to dev */
791 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200792 if (!sta) {
793 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100794 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200795 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100796
Johannes Bergd0709a62008-02-25 16:27:46 +0100797 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
799
Nicolas Kaiser679fda12008-05-20 18:42:54 +0200800 if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN &&
Johannes Berg98dd6a52008-04-10 15:36:09 +0200801 vlansdata->vif.type != IEEE80211_IF_TYPE_AP) {
802 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100803 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200804 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100805
Johannes Berg14db74b2008-07-29 13:22:52 +0200806 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100807 ieee80211_send_layer2_update(sta);
808 }
809
810 sta_apply_parameters(local, sta, params);
811
Johannes Berg98dd6a52008-04-10 15:36:09 +0200812 rcu_read_unlock();
813
Johannes Berg4fd69312007-12-19 02:03:35 +0100814 return 0;
815}
816
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100817#ifdef CONFIG_MAC80211_MESH
818static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
819 u8 *dst, u8 *next_hop)
820{
Johannes Berg14db74b2008-07-29 13:22:52 +0200821 struct ieee80211_local *local = wiphy_priv(wiphy);
822 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100823 struct mesh_path *mpath;
824 struct sta_info *sta;
825 int err;
826
Johannes Berg14db74b2008-07-29 13:22:52 +0200827 if (dev == local->mdev)
828 return -EOPNOTSUPP;
829
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100830 if (!netif_running(dev))
831 return -ENETDOWN;
832
Johannes Berg14db74b2008-07-29 13:22:52 +0200833 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
834
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100835 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
836 return -ENOTSUPP;
837
Johannes Bergd0709a62008-02-25 16:27:46 +0100838 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100839 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100840 if (!sta) {
841 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100842 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100843 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100844
845 err = mesh_path_add(dst, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100846 if (err) {
847 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100848 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100849 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100850
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100851 mpath = mesh_path_lookup(dst, dev);
852 if (!mpath) {
853 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100854 return -ENXIO;
855 }
856 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100857
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858 rcu_read_unlock();
859 return 0;
860}
861
862static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
863 u8 *dst)
864{
865 if (dst)
Luis Carlos Cobocfa22c72008-02-29 15:04:13 -0800866 return mesh_path_del(dst, dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100867
868 mesh_path_flush(dev);
869 return 0;
870}
871
872static int ieee80211_change_mpath(struct wiphy *wiphy,
873 struct net_device *dev,
874 u8 *dst, u8 *next_hop)
875{
Johannes Berg14db74b2008-07-29 13:22:52 +0200876 struct ieee80211_local *local = wiphy_priv(wiphy);
877 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100878 struct mesh_path *mpath;
879 struct sta_info *sta;
880
Johannes Berg14db74b2008-07-29 13:22:52 +0200881 if (dev == local->mdev)
882 return -EOPNOTSUPP;
883
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100884 if (!netif_running(dev))
885 return -ENETDOWN;
886
Johannes Berg14db74b2008-07-29 13:22:52 +0200887 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
888
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100889 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
890 return -ENOTSUPP;
891
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100892 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100893
894 sta = sta_info_get(local, next_hop);
895 if (!sta) {
896 rcu_read_unlock();
897 return -ENOENT;
898 }
899
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100900 mpath = mesh_path_lookup(dst, dev);
901 if (!mpath) {
902 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 return -ENOENT;
904 }
905
906 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100907
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100908 rcu_read_unlock();
909 return 0;
910}
911
912static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
913 struct mpath_info *pinfo)
914{
915 if (mpath->next_hop)
916 memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN);
917 else
918 memset(next_hop, 0, ETH_ALEN);
919
920 pinfo->filled = MPATH_INFO_FRAME_QLEN |
921 MPATH_INFO_DSN |
922 MPATH_INFO_METRIC |
923 MPATH_INFO_EXPTIME |
924 MPATH_INFO_DISCOVERY_TIMEOUT |
925 MPATH_INFO_DISCOVERY_RETRIES |
926 MPATH_INFO_FLAGS;
927
928 pinfo->frame_qlen = mpath->frame_queue.qlen;
929 pinfo->dsn = mpath->dsn;
930 pinfo->metric = mpath->metric;
931 if (time_before(jiffies, mpath->exp_time))
932 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
933 pinfo->discovery_timeout =
934 jiffies_to_msecs(mpath->discovery_timeout);
935 pinfo->discovery_retries = mpath->discovery_retries;
936 pinfo->flags = 0;
937 if (mpath->flags & MESH_PATH_ACTIVE)
938 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
939 if (mpath->flags & MESH_PATH_RESOLVING)
940 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
941 if (mpath->flags & MESH_PATH_DSN_VALID)
942 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
943 if (mpath->flags & MESH_PATH_FIXED)
944 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
945 if (mpath->flags & MESH_PATH_RESOLVING)
946 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
947
948 pinfo->flags = mpath->flags;
949}
950
951static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
952 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
953
954{
Johannes Berg14db74b2008-07-29 13:22:52 +0200955 struct ieee80211_local *local = wiphy_priv(wiphy);
956 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100957 struct mesh_path *mpath;
958
Johannes Berg14db74b2008-07-29 13:22:52 +0200959 if (dev == local->mdev)
960 return -EOPNOTSUPP;
961
962 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
963
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100964 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
965 return -ENOTSUPP;
966
967 rcu_read_lock();
968 mpath = mesh_path_lookup(dst, dev);
969 if (!mpath) {
970 rcu_read_unlock();
971 return -ENOENT;
972 }
973 memcpy(dst, mpath->dst, ETH_ALEN);
974 mpath_set_pinfo(mpath, next_hop, pinfo);
975 rcu_read_unlock();
976 return 0;
977}
978
979static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
980 int idx, u8 *dst, u8 *next_hop,
981 struct mpath_info *pinfo)
982{
Johannes Berg14db74b2008-07-29 13:22:52 +0200983 struct ieee80211_local *local = wiphy_priv(wiphy);
984 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100985 struct mesh_path *mpath;
986
Johannes Berg14db74b2008-07-29 13:22:52 +0200987 if (dev == local->mdev)
988 return -EOPNOTSUPP;
989
990 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
991
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100992 if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT)
993 return -ENOTSUPP;
994
995 rcu_read_lock();
996 mpath = mesh_path_lookup_by_idx(idx, dev);
997 if (!mpath) {
998 rcu_read_unlock();
999 return -ENOENT;
1000 }
1001 memcpy(dst, mpath->dst, ETH_ALEN);
1002 mpath_set_pinfo(mpath, next_hop, pinfo);
1003 rcu_read_unlock();
1004 return 0;
1005}
1006#endif
1007
Jiri Bencf0706e822007-05-05 11:45:53 -07001008struct cfg80211_ops mac80211_config_ops = {
1009 .add_virtual_intf = ieee80211_add_iface,
1010 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001011 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001012 .add_key = ieee80211_add_key,
1013 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001014 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001015 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001016 .add_beacon = ieee80211_add_beacon,
1017 .set_beacon = ieee80211_set_beacon,
1018 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001019 .add_station = ieee80211_add_station,
1020 .del_station = ieee80211_del_station,
1021 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001022 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001023 .dump_station = ieee80211_dump_station,
1024#ifdef CONFIG_MAC80211_MESH
1025 .add_mpath = ieee80211_add_mpath,
1026 .del_mpath = ieee80211_del_mpath,
1027 .change_mpath = ieee80211_change_mpath,
1028 .get_mpath = ieee80211_get_mpath,
1029 .dump_mpath = ieee80211_dump_mpath,
1030#endif
Jiri Bencf0706e822007-05-05 11:45:53 -07001031};