blob: e2574885db4aba5414aa82722ca9deaffab04275 [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
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070020struct ieee80211_hw *wiphy_to_hw(struct wiphy *wiphy)
21{
22 struct ieee80211_local *local = wiphy_priv(wiphy);
23 return &local->hw;
24}
25EXPORT_SYMBOL(wiphy_to_hw);
26
Johannes Berg05c914f2008-09-11 00:01:58 +020027static bool nl80211_type_check(enum nl80211_iftype type)
Johannes Berg42613db2007-09-28 21:52:27 +020028{
29 switch (type) {
Johannes Berg42613db2007-09-28 21:52:27 +020030 case NL80211_IFTYPE_ADHOC:
Johannes Berg42613db2007-09-28 21:52:27 +020031 case NL80211_IFTYPE_STATION:
Johannes Berg42613db2007-09-28 21:52:27 +020032 case NL80211_IFTYPE_MONITOR:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010033#ifdef CONFIG_MAC80211_MESH
34 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010035#endif
Johannes Bergb4540482008-04-14 15:37:03 +020036 case NL80211_IFTYPE_WDS:
Johannes Berg05c914f2008-09-11 00:01:58 +020037 return true;
Johannes Berg42613db2007-09-28 21:52:27 +020038 default:
Johannes Berg05c914f2008-09-11 00:01:58 +020039 return false;
Johannes Berg42613db2007-09-28 21:52:27 +020040 }
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);
Michael Wu8cc9a732008-01-31 19:48:23 +010048 struct net_device *dev;
49 struct ieee80211_sub_if_data *sdata;
50 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070051
Johannes Berg05c914f2008-09-11 00:01:58 +020052 if (!nl80211_type_check(type))
Jiri Bencf0706e822007-05-05 11:45:53 -070053 return -EINVAL;
Jiri Bencf0706e822007-05-05 11:45:53 -070054
Johannes Berg05c914f2008-09-11 00:01:58 +020055 err = ieee80211_if_add(local, name, &dev, type, params);
56 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010057 return err;
58
59 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
60 sdata->u.mntr_flags = *flags;
61 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070062}
63
64static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
65{
Jiri Bencf0706e822007-05-05 11:45:53 -070066 struct net_device *dev;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120067 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e822007-05-05 11:45:53 -070068
Johannes Berg42613db2007-09-28 21:52:27 +020069 /* we're under RTNL */
70 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e822007-05-05 11:45:53 -070071 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020072 return -ENODEV;
Jiri Bencf0706e822007-05-05 11:45:53 -070073
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120074 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
75
76 ieee80211_if_remove(sdata);
Jiri Bencf0706e822007-05-05 11:45:53 -070077
Johannes Berg75636522008-07-09 14:40:35 +020078 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070079}
80
Johannes Berg42613db2007-09-28 21:52:27 +020081static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010082 enum nl80211_iftype type, u32 *flags,
83 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020084{
Johannes Berg14db74b2008-07-29 13:22:52 +020085 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg42613db2007-09-28 21:52:27 +020086 struct net_device *dev;
Johannes Berg42613db2007-09-28 21:52:27 +020087 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 Berg05c914f2008-09-11 00:01:58 +020095 if (!nl80211_type_check(type))
Johannes Berg42613db2007-09-28 21:52:27 +020096 return -EINVAL;
97
Johannes Berg14db74b2008-07-29 13:22:52 +020098 if (dev == local->mdev)
99 return -EOPNOTSUPP;
100
Johannes Berg42613db2007-09-28 21:52:27 +0200101 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
102
Johannes Berg05c914f2008-09-11 00:01:58 +0200103 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +0200104 if (ret)
105 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200106
Johannes Berg902acc72008-02-23 15:17:19 +0100107 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +0200108 ieee80211_sdata_set_mesh_id(sdata,
109 params->mesh_id_len,
110 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100111
Johannes Berg05c914f2008-09-11 00:01:58 +0200112 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +0100113 return 0;
114
115 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200116 return 0;
117}
118
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100119static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
120 u8 key_idx, u8 *mac_addr,
121 struct key_params *params)
122{
Johannes Berg14db74b2008-07-29 13:22:52 +0200123 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100124 struct ieee80211_sub_if_data *sdata;
125 struct sta_info *sta = NULL;
126 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100127 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200128 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100129
Johannes Berg14db74b2008-07-29 13:22:52 +0200130 if (dev == local->mdev)
131 return -EOPNOTSUPP;
132
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
134
135 switch (params->cipher) {
136 case WLAN_CIPHER_SUITE_WEP40:
137 case WLAN_CIPHER_SUITE_WEP104:
138 alg = ALG_WEP;
139 break;
140 case WLAN_CIPHER_SUITE_TKIP:
141 alg = ALG_TKIP;
142 break;
143 case WLAN_CIPHER_SUITE_CCMP:
144 alg = ALG_CCMP;
145 break;
146 default:
147 return -EINVAL;
148 }
149
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
151 if (!key)
152 return -ENOMEM;
153
Johannes Berg3b967662008-04-08 17:56:52 +0200154 rcu_read_lock();
155
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100156 if (mac_addr) {
157 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100158 if (!sta) {
159 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200160 err = -ENOENT;
161 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100162 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100163 }
164
Johannes Bergdb4d1162008-02-25 16:27:45 +0100165 ieee80211_key_link(key, sdata, sta);
166
Johannes Berg3b967662008-04-08 17:56:52 +0200167 err = 0;
168 out_unlock:
169 rcu_read_unlock();
170
171 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100172}
173
174static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
175 u8 key_idx, u8 *mac_addr)
176{
Johannes Berg14db74b2008-07-29 13:22:52 +0200177 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100178 struct ieee80211_sub_if_data *sdata;
179 struct sta_info *sta;
180 int ret;
181
Johannes Berg14db74b2008-07-29 13:22:52 +0200182 if (dev == local->mdev)
183 return -EOPNOTSUPP;
184
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
186
Johannes Berg3b967662008-04-08 17:56:52 +0200187 rcu_read_lock();
188
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200190 ret = -ENOENT;
191
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100192 sta = sta_info_get(sdata->local, mac_addr);
193 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200194 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195
Johannes Bergdb4d1162008-02-25 16:27:45 +0100196 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100197 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100198 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200199 ret = 0;
200 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100201
Johannes Berg3b967662008-04-08 17:56:52 +0200202 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100203 }
204
Johannes Berg3b967662008-04-08 17:56:52 +0200205 if (!sdata->keys[key_idx]) {
206 ret = -ENOENT;
207 goto out_unlock;
208 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100209
Johannes Bergd0709a62008-02-25 16:27:46 +0100210 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100211 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100212
Johannes Berg3b967662008-04-08 17:56:52 +0200213 ret = 0;
214 out_unlock:
215 rcu_read_unlock();
216
217 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100218}
219
Johannes Berg62da92f2007-12-19 02:03:31 +0100220static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
221 u8 key_idx, u8 *mac_addr, void *cookie,
222 void (*callback)(void *cookie,
223 struct key_params *params))
224{
Johannes Berg14db74b2008-07-29 13:22:52 +0200225 struct ieee80211_local *local = wiphy_priv(wiphy);
226 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100227 struct sta_info *sta = NULL;
228 u8 seq[6] = {0};
229 struct key_params params;
230 struct ieee80211_key *key;
231 u32 iv32;
232 u16 iv16;
233 int err = -ENOENT;
234
Johannes Berg14db74b2008-07-29 13:22:52 +0200235 if (dev == local->mdev)
236 return -EOPNOTSUPP;
237
238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239
Johannes Berg3b967662008-04-08 17:56:52 +0200240 rcu_read_lock();
241
Johannes Berg62da92f2007-12-19 02:03:31 +0100242 if (mac_addr) {
243 sta = sta_info_get(sdata->local, mac_addr);
244 if (!sta)
245 goto out;
246
247 key = sta->key;
248 } else
249 key = sdata->keys[key_idx];
250
251 if (!key)
252 goto out;
253
254 memset(&params, 0, sizeof(params));
255
256 switch (key->conf.alg) {
257 case ALG_TKIP:
258 params.cipher = WLAN_CIPHER_SUITE_TKIP;
259
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700260 iv32 = key->u.tkip.tx.iv32;
261 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100262
263 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
264 sdata->local->ops->get_tkip_seq)
265 sdata->local->ops->get_tkip_seq(
266 local_to_hw(sdata->local),
267 key->conf.hw_key_idx,
268 &iv32, &iv16);
269
270 seq[0] = iv16 & 0xff;
271 seq[1] = (iv16 >> 8) & 0xff;
272 seq[2] = iv32 & 0xff;
273 seq[3] = (iv32 >> 8) & 0xff;
274 seq[4] = (iv32 >> 16) & 0xff;
275 seq[5] = (iv32 >> 24) & 0xff;
276 params.seq = seq;
277 params.seq_len = 6;
278 break;
279 case ALG_CCMP:
280 params.cipher = WLAN_CIPHER_SUITE_CCMP;
281 seq[0] = key->u.ccmp.tx_pn[5];
282 seq[1] = key->u.ccmp.tx_pn[4];
283 seq[2] = key->u.ccmp.tx_pn[3];
284 seq[3] = key->u.ccmp.tx_pn[2];
285 seq[4] = key->u.ccmp.tx_pn[1];
286 seq[5] = key->u.ccmp.tx_pn[0];
287 params.seq = seq;
288 params.seq_len = 6;
289 break;
290 case ALG_WEP:
291 if (key->conf.keylen == 5)
292 params.cipher = WLAN_CIPHER_SUITE_WEP40;
293 else
294 params.cipher = WLAN_CIPHER_SUITE_WEP104;
295 break;
296 }
297
298 params.key = key->conf.key;
299 params.key_len = key->conf.keylen;
300
301 callback(cookie, &params);
302 err = 0;
303
304 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200305 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100306 return err;
307}
308
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100309static int ieee80211_config_default_key(struct wiphy *wiphy,
310 struct net_device *dev,
311 u8 key_idx)
312{
Johannes Berg14db74b2008-07-29 13:22:52 +0200313 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100314 struct ieee80211_sub_if_data *sdata;
315
Johannes Berg14db74b2008-07-29 13:22:52 +0200316 if (dev == local->mdev)
317 return -EOPNOTSUPP;
318
Johannes Berg3b967662008-04-08 17:56:52 +0200319 rcu_read_lock();
320
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100321 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
322 ieee80211_set_default_key(sdata, key_idx);
323
Johannes Berg3b967662008-04-08 17:56:52 +0200324 rcu_read_unlock();
325
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100326 return 0;
327}
328
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100329static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
330{
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100332
333 sinfo->filled = STATION_INFO_INACTIVE_TIME |
334 STATION_INFO_RX_BYTES |
335 STATION_INFO_TX_BYTES;
336
337 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
338 sinfo->rx_bytes = sta->rx_bytes;
339 sinfo->tx_bytes = sta->tx_bytes;
340
Johannes Berg902acc72008-02-23 15:17:19 +0100341 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100342#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100343 sinfo->filled |= STATION_INFO_LLID |
344 STATION_INFO_PLID |
345 STATION_INFO_PLINK_STATE;
346
347 sinfo->llid = le16_to_cpu(sta->llid);
348 sinfo->plid = le16_to_cpu(sta->plid);
349 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100350#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100351 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100352}
353
354
355static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
356 int idx, u8 *mac, struct station_info *sinfo)
357{
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
359 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100360 int ret = -ENOENT;
361
362 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100363
364 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100365 if (sta) {
366 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200367 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100368 sta_set_sinfo(sta, sinfo);
369 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100370
Johannes Bergd0709a62008-02-25 16:27:46 +0100371 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100372
Johannes Bergd0709a62008-02-25 16:27:46 +0100373 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100374}
375
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100376static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100377 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100378{
379 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
380 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100381 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100382
Johannes Bergd0709a62008-02-25 16:27:46 +0100383 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100384
385 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100386
Johannes Bergd0709a62008-02-25 16:27:46 +0100387 sta = sta_info_get(local, mac);
388 if (sta) {
389 ret = 0;
390 sta_set_sinfo(sta, sinfo);
391 }
392
393 rcu_read_unlock();
394
395 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100396}
397
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100398/*
399 * This handles both adding a beacon and setting new beacon info
400 */
401static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
402 struct beacon_parameters *params)
403{
404 struct beacon_data *new, *old;
405 int new_head_len, new_tail_len;
406 int size;
407 int err = -EINVAL;
408
409 old = sdata->u.ap.beacon;
410
411 /* head must not be zero-length */
412 if (params->head && !params->head_len)
413 return -EINVAL;
414
415 /*
416 * This is a kludge. beacon interval should really be part
417 * of the beacon information.
418 */
419 if (params->interval) {
420 sdata->local->hw.conf.beacon_int = params->interval;
421 if (ieee80211_hw_config(sdata->local))
422 return -EINVAL;
423 /*
424 * We updated some parameter so if below bails out
425 * it's not an error.
426 */
427 err = 0;
428 }
429
430 /* Need to have a beacon head if we don't have one yet */
431 if (!params->head && !old)
432 return err;
433
434 /* sorry, no way to start beaconing without dtim period */
435 if (!params->dtim_period && !old)
436 return err;
437
438 /* new or old head? */
439 if (params->head)
440 new_head_len = params->head_len;
441 else
442 new_head_len = old->head_len;
443
444 /* new or old tail? */
445 if (params->tail || !old)
446 /* params->tail_len will be zero for !params->tail */
447 new_tail_len = params->tail_len;
448 else
449 new_tail_len = old->tail_len;
450
451 size = sizeof(*new) + new_head_len + new_tail_len;
452
453 new = kzalloc(size, GFP_KERNEL);
454 if (!new)
455 return -ENOMEM;
456
457 /* start filling the new info now */
458
459 /* new or old dtim period? */
460 if (params->dtim_period)
461 new->dtim_period = params->dtim_period;
462 else
463 new->dtim_period = old->dtim_period;
464
465 /*
466 * pointers go into the block we allocated,
467 * memory is | beacon_data | head | tail |
468 */
469 new->head = ((u8 *) new) + sizeof(*new);
470 new->tail = new->head + new_head_len;
471 new->head_len = new_head_len;
472 new->tail_len = new_tail_len;
473
474 /* copy in head */
475 if (params->head)
476 memcpy(new->head, params->head, new_head_len);
477 else
478 memcpy(new->head, old->head, new_head_len);
479
480 /* copy in optional tail */
481 if (params->tail)
482 memcpy(new->tail, params->tail, new_tail_len);
483 else
484 if (old)
485 memcpy(new->tail, old->tail, new_tail_len);
486
487 rcu_assign_pointer(sdata->u.ap.beacon, new);
488
489 synchronize_rcu();
490
491 kfree(old);
492
Johannes Berg9d139c82008-07-09 14:40:37 +0200493 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100494}
495
496static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
497 struct beacon_parameters *params)
498{
Johannes Berg14db74b2008-07-29 13:22:52 +0200499 struct ieee80211_local *local = wiphy_priv(wiphy);
500 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100501 struct beacon_data *old;
502
Johannes Berg14db74b2008-07-29 13:22:52 +0200503 if (dev == local->mdev)
504 return -EOPNOTSUPP;
505
506 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
507
Johannes Berg05c914f2008-09-11 00:01:58 +0200508 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100509 return -EINVAL;
510
511 old = sdata->u.ap.beacon;
512
513 if (old)
514 return -EALREADY;
515
516 return ieee80211_config_beacon(sdata, params);
517}
518
519static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
520 struct beacon_parameters *params)
521{
Johannes Berg14db74b2008-07-29 13:22:52 +0200522 struct ieee80211_local *local = wiphy_priv(wiphy);
523 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100524 struct beacon_data *old;
525
Johannes Berg14db74b2008-07-29 13:22:52 +0200526 if (dev == local->mdev)
527 return -EOPNOTSUPP;
528
529 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
530
Johannes Berg05c914f2008-09-11 00:01:58 +0200531 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100532 return -EINVAL;
533
534 old = sdata->u.ap.beacon;
535
536 if (!old)
537 return -ENOENT;
538
539 return ieee80211_config_beacon(sdata, params);
540}
541
542static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
543{
Johannes Berg14db74b2008-07-29 13:22:52 +0200544 struct ieee80211_local *local = wiphy_priv(wiphy);
545 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100546 struct beacon_data *old;
547
Johannes Berg14db74b2008-07-29 13:22:52 +0200548 if (dev == local->mdev)
549 return -EOPNOTSUPP;
550
551 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
552
Johannes Berg05c914f2008-09-11 00:01:58 +0200553 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100554 return -EINVAL;
555
556 old = sdata->u.ap.beacon;
557
558 if (!old)
559 return -ENOENT;
560
561 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
562 synchronize_rcu();
563 kfree(old);
564
Johannes Berg9d139c82008-07-09 14:40:37 +0200565 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100566}
567
Johannes Berg4fd69312007-12-19 02:03:35 +0100568/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
569struct iapp_layer2_update {
570 u8 da[ETH_ALEN]; /* broadcast */
571 u8 sa[ETH_ALEN]; /* STA addr */
572 __be16 len; /* 6 */
573 u8 dsap; /* 0 */
574 u8 ssap; /* 0 */
575 u8 control;
576 u8 xid_info[3];
577} __attribute__ ((packed));
578
579static void ieee80211_send_layer2_update(struct sta_info *sta)
580{
581 struct iapp_layer2_update *msg;
582 struct sk_buff *skb;
583
584 /* Send Level 2 Update Frame to update forwarding tables in layer 2
585 * bridge devices */
586
587 skb = dev_alloc_skb(sizeof(*msg));
588 if (!skb)
589 return;
590 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
591
592 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
593 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
594
595 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200596 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100597 msg->len = htons(6);
598 msg->dsap = 0;
599 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
600 msg->control = 0xaf; /* XID response lsb.1111F101.
601 * F=0 (no poll command; unsolicited frame) */
602 msg->xid_info[0] = 0x81; /* XID format identifier */
603 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
604 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
605
Johannes Bergd0709a62008-02-25 16:27:46 +0100606 skb->dev = sta->sdata->dev;
607 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100608 memset(skb->cb, 0, sizeof(skb->cb));
609 netif_rx(skb);
610}
611
612static void sta_apply_parameters(struct ieee80211_local *local,
613 struct sta_info *sta,
614 struct station_parameters *params)
615{
616 u32 rates;
617 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100618 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100619 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100620
Johannes Berg73651ee2008-02-25 16:27:47 +0100621 /*
622 * FIXME: updating the flags is racy when this function is
623 * called from ieee80211_change_station(), this will
624 * be resolved in a future patch.
625 */
626
Johannes Berg4fd69312007-12-19 02:03:35 +0100627 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200628 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100629 sta->flags &= ~WLAN_STA_AUTHORIZED;
630 if (params->station_flags & STATION_FLAG_AUTHORIZED)
631 sta->flags |= WLAN_STA_AUTHORIZED;
632
633 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
634 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
635 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
636
637 sta->flags &= ~WLAN_STA_WME;
638 if (params->station_flags & STATION_FLAG_WME)
639 sta->flags |= WLAN_STA_WME;
Johannes Berg07346f812008-05-03 01:02:02 +0200640 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100641 }
642
Johannes Berg73651ee2008-02-25 16:27:47 +0100643 /*
644 * FIXME: updating the following information is racy when this
645 * function is called from ieee80211_change_station().
646 * However, all this information should be static so
647 * maybe we should just reject attemps to change it.
648 */
649
Johannes Berg4fd69312007-12-19 02:03:35 +0100650 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200651 sta->sta.aid = params->aid;
652 if (sta->sta.aid > IEEE80211_MAX_AID)
653 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100654 }
655
656 if (params->listen_interval >= 0)
657 sta->listen_interval = params->listen_interval;
658
659 if (params->supported_rates) {
660 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100661 sband = local->hw.wiphy->bands[local->oper_channel->band];
662
Johannes Berg4fd69312007-12-19 02:03:35 +0100663 for (i = 0; i < params->supported_rates_len; i++) {
664 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100665 for (j = 0; j < sband->n_bitrates; j++) {
666 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100667 rates |= BIT(j);
668 }
669 }
Johannes Berg323ce792008-09-11 02:45:11 +0200670 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100671 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100672
Jouni Malinen36aedc92008-08-25 11:58:58 +0300673 if (params->ht_capa) {
674 ieee80211_ht_cap_ie_to_ht_info(params->ht_capa,
Johannes Berg687c7c02008-09-11 03:14:11 +0200675 &sta->sta.ht_info);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300676 }
677
Johannes Berg902acc72008-02-23 15:17:19 +0100678 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100679 switch (params->plink_action) {
680 case PLINK_ACTION_OPEN:
681 mesh_plink_open(sta);
682 break;
683 case PLINK_ACTION_BLOCK:
684 mesh_plink_block(sta);
685 break;
686 }
Johannes Berg902acc72008-02-23 15:17:19 +0100687 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100688}
689
690static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
691 u8 *mac, struct station_parameters *params)
692{
Johannes Berg14db74b2008-07-29 13:22:52 +0200693 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100694 struct sta_info *sta;
695 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100696 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100697
Johannes Berg14db74b2008-07-29 13:22:52 +0200698 if (dev == local->mdev || params->vlan == local->mdev)
699 return -EOPNOTSUPP;
700
Johannes Berg4fd69312007-12-19 02:03:35 +0100701 /* Prevent a race with changing the rate control algorithm */
702 if (!netif_running(dev))
703 return -ENETDOWN;
704
Johannes Berg4fd69312007-12-19 02:03:35 +0100705 if (params->vlan) {
706 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
707
Johannes Berg05c914f2008-09-11 00:01:58 +0200708 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
709 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100710 return -EINVAL;
711 } else
712 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
713
Johannes Berg03e44972008-02-27 09:56:40 +0100714 if (compare_ether_addr(mac, dev->dev_addr) == 0)
715 return -EINVAL;
716
717 if (is_multicast_ether_addr(mac))
718 return -EINVAL;
719
720 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100721 if (!sta)
722 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100723
724 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
725
726 sta_apply_parameters(local, sta, params);
727
728 rate_control_rate_init(sta, local);
729
Johannes Berg73651ee2008-02-25 16:27:47 +0100730 rcu_read_lock();
731
732 err = sta_info_insert(sta);
733 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200734 /* STA has been freed */
Johannes Berg73651ee2008-02-25 16:27:47 +0100735 rcu_read_unlock();
736 return err;
737 }
738
Johannes Berg05c914f2008-09-11 00:01:58 +0200739 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
740 sdata->vif.type == NL80211_IFTYPE_AP)
Johannes Berg73651ee2008-02-25 16:27:47 +0100741 ieee80211_send_layer2_update(sta);
742
743 rcu_read_unlock();
744
Johannes Berg4fd69312007-12-19 02:03:35 +0100745 return 0;
746}
747
748static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
749 u8 *mac)
750{
Johannes Berg14db74b2008-07-29 13:22:52 +0200751 struct ieee80211_local *local = wiphy_priv(wiphy);
752 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100753 struct sta_info *sta;
754
Johannes Berg14db74b2008-07-29 13:22:52 +0200755 if (dev == local->mdev)
756 return -EOPNOTSUPP;
757
758 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
759
Johannes Berg4fd69312007-12-19 02:03:35 +0100760 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200761 rcu_read_lock();
762
Johannes Berg4fd69312007-12-19 02:03:35 +0100763 /* XXX: get sta belonging to dev */
764 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200765 if (!sta) {
766 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100767 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200768 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100769
Johannes Bergd0709a62008-02-25 16:27:46 +0100770 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200771 rcu_read_unlock();
772
Johannes Berg4f6fab42008-03-31 19:23:02 +0200773 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100774 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100775 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100776
777 return 0;
778}
779
780static int ieee80211_change_station(struct wiphy *wiphy,
781 struct net_device *dev,
782 u8 *mac,
783 struct station_parameters *params)
784{
Johannes Berg14db74b2008-07-29 13:22:52 +0200785 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100786 struct sta_info *sta;
787 struct ieee80211_sub_if_data *vlansdata;
788
Johannes Berg14db74b2008-07-29 13:22:52 +0200789 if (dev == local->mdev || params->vlan == local->mdev)
790 return -EOPNOTSUPP;
791
Johannes Berg98dd6a52008-04-10 15:36:09 +0200792 rcu_read_lock();
793
Johannes Berg4fd69312007-12-19 02:03:35 +0100794 /* XXX: get sta belonging to dev */
795 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200796 if (!sta) {
797 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200799 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100800
Johannes Bergd0709a62008-02-25 16:27:46 +0100801 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100802 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
803
Johannes Berg05c914f2008-09-11 00:01:58 +0200804 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
805 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200806 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100807 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200808 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100809
Johannes Berg14db74b2008-07-29 13:22:52 +0200810 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100811 ieee80211_send_layer2_update(sta);
812 }
813
814 sta_apply_parameters(local, sta, params);
815
Johannes Berg98dd6a52008-04-10 15:36:09 +0200816 rcu_read_unlock();
817
Johannes Berg4fd69312007-12-19 02:03:35 +0100818 return 0;
819}
820
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100821#ifdef CONFIG_MAC80211_MESH
822static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
823 u8 *dst, u8 *next_hop)
824{
Johannes Berg14db74b2008-07-29 13:22:52 +0200825 struct ieee80211_local *local = wiphy_priv(wiphy);
826 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100827 struct mesh_path *mpath;
828 struct sta_info *sta;
829 int err;
830
Johannes Berg14db74b2008-07-29 13:22:52 +0200831 if (dev == local->mdev)
832 return -EOPNOTSUPP;
833
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100834 if (!netif_running(dev))
835 return -ENETDOWN;
836
Johannes Berg14db74b2008-07-29 13:22:52 +0200837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838
Johannes Berg05c914f2008-09-11 00:01:58 +0200839 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100840 return -ENOTSUPP;
841
Johannes Bergd0709a62008-02-25 16:27:46 +0100842 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100843 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100844 if (!sta) {
845 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100846 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100847 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100848
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200849 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100850 if (err) {
851 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100852 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100853 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100854
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200855 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100856 if (!mpath) {
857 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858 return -ENXIO;
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 int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
867 u8 *dst)
868{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100870
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200871 if (dst)
872 return mesh_path_del(dst, sdata);
873
874 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100875 return 0;
876}
877
878static int ieee80211_change_mpath(struct wiphy *wiphy,
879 struct net_device *dev,
880 u8 *dst, u8 *next_hop)
881{
Johannes Berg14db74b2008-07-29 13:22:52 +0200882 struct ieee80211_local *local = wiphy_priv(wiphy);
883 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100884 struct mesh_path *mpath;
885 struct sta_info *sta;
886
Johannes Berg14db74b2008-07-29 13:22:52 +0200887 if (dev == local->mdev)
888 return -EOPNOTSUPP;
889
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100890 if (!netif_running(dev))
891 return -ENETDOWN;
892
Johannes Berg14db74b2008-07-29 13:22:52 +0200893 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
894
Johannes Berg05c914f2008-09-11 00:01:58 +0200895 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100896 return -ENOTSUPP;
897
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100898 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100899
900 sta = sta_info_get(local, next_hop);
901 if (!sta) {
902 rcu_read_unlock();
903 return -ENOENT;
904 }
905
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200906 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100907 if (!mpath) {
908 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100909 return -ENOENT;
910 }
911
912 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100913
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100914 rcu_read_unlock();
915 return 0;
916}
917
918static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
919 struct mpath_info *pinfo)
920{
921 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200922 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100923 else
924 memset(next_hop, 0, ETH_ALEN);
925
926 pinfo->filled = MPATH_INFO_FRAME_QLEN |
927 MPATH_INFO_DSN |
928 MPATH_INFO_METRIC |
929 MPATH_INFO_EXPTIME |
930 MPATH_INFO_DISCOVERY_TIMEOUT |
931 MPATH_INFO_DISCOVERY_RETRIES |
932 MPATH_INFO_FLAGS;
933
934 pinfo->frame_qlen = mpath->frame_queue.qlen;
935 pinfo->dsn = mpath->dsn;
936 pinfo->metric = mpath->metric;
937 if (time_before(jiffies, mpath->exp_time))
938 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
939 pinfo->discovery_timeout =
940 jiffies_to_msecs(mpath->discovery_timeout);
941 pinfo->discovery_retries = mpath->discovery_retries;
942 pinfo->flags = 0;
943 if (mpath->flags & MESH_PATH_ACTIVE)
944 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
945 if (mpath->flags & MESH_PATH_RESOLVING)
946 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
947 if (mpath->flags & MESH_PATH_DSN_VALID)
948 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
949 if (mpath->flags & MESH_PATH_FIXED)
950 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
951 if (mpath->flags & MESH_PATH_RESOLVING)
952 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
953
954 pinfo->flags = mpath->flags;
955}
956
957static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
958 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
959
960{
Johannes Berg14db74b2008-07-29 13:22:52 +0200961 struct ieee80211_local *local = wiphy_priv(wiphy);
962 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100963 struct mesh_path *mpath;
964
Johannes Berg14db74b2008-07-29 13:22:52 +0200965 if (dev == local->mdev)
966 return -EOPNOTSUPP;
967
968 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
969
Johannes Berg05c914f2008-09-11 00:01:58 +0200970 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100971 return -ENOTSUPP;
972
973 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200974 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100975 if (!mpath) {
976 rcu_read_unlock();
977 return -ENOENT;
978 }
979 memcpy(dst, mpath->dst, ETH_ALEN);
980 mpath_set_pinfo(mpath, next_hop, pinfo);
981 rcu_read_unlock();
982 return 0;
983}
984
985static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
986 int idx, u8 *dst, u8 *next_hop,
987 struct mpath_info *pinfo)
988{
Johannes Berg14db74b2008-07-29 13:22:52 +0200989 struct ieee80211_local *local = wiphy_priv(wiphy);
990 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100991 struct mesh_path *mpath;
992
Johannes Berg14db74b2008-07-29 13:22:52 +0200993 if (dev == local->mdev)
994 return -EOPNOTSUPP;
995
996 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
997
Johannes Berg05c914f2008-09-11 00:01:58 +0200998 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100999 return -ENOTSUPP;
1000
1001 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001002 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001003 if (!mpath) {
1004 rcu_read_unlock();
1005 return -ENOENT;
1006 }
1007 memcpy(dst, mpath->dst, ETH_ALEN);
1008 mpath_set_pinfo(mpath, next_hop, pinfo);
1009 rcu_read_unlock();
1010 return 0;
1011}
1012#endif
1013
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001014static int ieee80211_change_bss(struct wiphy *wiphy,
1015 struct net_device *dev,
1016 struct bss_parameters *params)
1017{
1018 struct ieee80211_local *local = wiphy_priv(wiphy);
1019 struct ieee80211_sub_if_data *sdata;
1020 u32 changed = 0;
1021
1022 if (dev == local->mdev)
1023 return -EOPNOTSUPP;
1024
1025 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1026
Johannes Berg05c914f2008-09-11 00:01:58 +02001027 if (sdata->vif.type != NL80211_IFTYPE_AP)
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001028 return -EINVAL;
1029
1030 if (params->use_cts_prot >= 0) {
1031 sdata->bss_conf.use_cts_prot = params->use_cts_prot;
1032 changed |= BSS_CHANGED_ERP_CTS_PROT;
1033 }
1034 if (params->use_short_preamble >= 0) {
1035 sdata->bss_conf.use_short_preamble =
1036 params->use_short_preamble;
1037 changed |= BSS_CHANGED_ERP_PREAMBLE;
1038 }
1039 if (params->use_short_slot_time >= 0) {
1040 sdata->bss_conf.use_short_slot =
1041 params->use_short_slot_time;
1042 changed |= BSS_CHANGED_ERP_SLOT;
1043 }
1044
1045 ieee80211_bss_info_change_notify(sdata, changed);
1046
1047 return 0;
1048}
1049
Jiri Bencf0706e822007-05-05 11:45:53 -07001050struct cfg80211_ops mac80211_config_ops = {
1051 .add_virtual_intf = ieee80211_add_iface,
1052 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001053 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001054 .add_key = ieee80211_add_key,
1055 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001056 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001057 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001058 .add_beacon = ieee80211_add_beacon,
1059 .set_beacon = ieee80211_set_beacon,
1060 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001061 .add_station = ieee80211_add_station,
1062 .del_station = ieee80211_del_station,
1063 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001064 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001065 .dump_station = ieee80211_dump_station,
1066#ifdef CONFIG_MAC80211_MESH
1067 .add_mpath = ieee80211_add_mpath,
1068 .del_mpath = ieee80211_del_mpath,
1069 .change_mpath = ieee80211_change_mpath,
1070 .get_mpath = ieee80211_get_mpath,
1071 .dump_mpath = ieee80211_dump_mpath,
1072#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001073 .change_bss = ieee80211_change_bss,
Jiri Bencf0706e822007-05-05 11:45:53 -07001074};