blob: 3ea0884c9432ba850127d4356a7af443004cc0bd [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Johannes Berg62da92f2007-12-19 02:03:31 +01004 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070012#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010013#include <linux/rcupdate.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070014#include <net/cfg80211.h>
15#include "ieee80211_i.h"
Michael Wue0eb6852007-09-18 17:29:21 -040016#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040017#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010018#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010019
Johannes 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
Jouni Malinenfbf18922008-10-30 19:50:30 +020029 case NL80211_IFTYPE_AP:
30 case NL80211_IFTYPE_AP_VLAN:
Johannes Bergb4540482008-04-14 15:37:03 +020031 case NL80211_IFTYPE_WDS:
Johannes Berg05c914f2008-09-11 00:01:58 +020032 return true;
Johannes Berg42613db2007-09-28 21:52:27 +020033 default:
Johannes Berg05c914f2008-09-11 00:01:58 +020034 return false;
Johannes Berg42613db2007-09-28 21:52:27 +020035 }
36}
37
Jiri Bencf0706e82007-05-05 11:45:53 -070038static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010039 enum nl80211_iftype type, u32 *flags,
40 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070041{
42 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010043 struct net_device *dev;
44 struct ieee80211_sub_if_data *sdata;
45 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070046
Johannes Berg05c914f2008-09-11 00:01:58 +020047 if (!nl80211_type_check(type))
Jiri Bencf0706e82007-05-05 11:45:53 -070048 return -EINVAL;
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg05c914f2008-09-11 00:01:58 +020050 err = ieee80211_if_add(local, name, &dev, type, params);
51 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010052 return err;
53
54 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
55 sdata->u.mntr_flags = *flags;
56 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070057}
58
59static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
60{
Jiri Bencf0706e82007-05-05 11:45:53 -070061 struct net_device *dev;
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120062 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -070063
Johannes Berg42613db2007-09-28 21:52:27 +020064 /* we're under RTNL */
65 dev = __dev_get_by_index(&init_net, ifindex);
Jiri Bencf0706e82007-05-05 11:45:53 -070066 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020067 return -ENODEV;
Jiri Bencf0706e82007-05-05 11:45:53 -070068
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +120069 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
70
71 ieee80211_if_remove(sdata);
Jiri Bencf0706e82007-05-05 11:45:53 -070072
Johannes Berg75636522008-07-09 14:40:35 +020073 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070074}
75
Johannes Berg42613db2007-09-28 21:52:27 +020076static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010077 enum nl80211_iftype type, u32 *flags,
78 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020079{
Johannes Berg42613db2007-09-28 21:52:27 +020080 struct net_device *dev;
Johannes Berg42613db2007-09-28 21:52:27 +020081 struct ieee80211_sub_if_data *sdata;
Johannes Bergf3947e22008-07-09 14:40:36 +020082 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020083
Johannes Berg42613db2007-09-28 21:52:27 +020084 /* we're under RTNL */
85 dev = __dev_get_by_index(&init_net, ifindex);
86 if (!dev)
87 return -ENODEV;
88
Johannes Berg05c914f2008-09-11 00:01:58 +020089 if (!nl80211_type_check(type))
Johannes Berg42613db2007-09-28 21:52:27 +020090 return -EINVAL;
91
92 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
93
Johannes Berg05c914f2008-09-11 00:01:58 +020094 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020095 if (ret)
96 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020097
Johannes Bergf8b25cd2008-09-16 20:22:21 +020098 if (netif_running(sdata->dev))
99 return -EBUSY;
100
Johannes Berg902acc72008-02-23 15:17:19 +0100101 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +0200102 ieee80211_sdata_set_mesh_id(sdata,
103 params->mesh_id_len,
104 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100105
Johannes Berg05c914f2008-09-11 00:01:58 +0200106 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +0100107 return 0;
108
109 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +0200110 return 0;
111}
112
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100113static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
114 u8 key_idx, u8 *mac_addr,
115 struct key_params *params)
116{
117 struct ieee80211_sub_if_data *sdata;
118 struct sta_info *sta = NULL;
119 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100120 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200121 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100122
123 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
124
125 switch (params->cipher) {
126 case WLAN_CIPHER_SUITE_WEP40:
127 case WLAN_CIPHER_SUITE_WEP104:
128 alg = ALG_WEP;
129 break;
130 case WLAN_CIPHER_SUITE_TKIP:
131 alg = ALG_TKIP;
132 break;
133 case WLAN_CIPHER_SUITE_CCMP:
134 alg = ALG_CCMP;
135 break;
136 default:
137 return -EINVAL;
138 }
139
Johannes Bergdb4d1162008-02-25 16:27:45 +0100140 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
141 if (!key)
142 return -ENOMEM;
143
Johannes Berg3b967662008-04-08 17:56:52 +0200144 rcu_read_lock();
145
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 if (mac_addr) {
147 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 if (!sta) {
149 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200150 err = -ENOENT;
151 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100152 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153 }
154
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155 ieee80211_key_link(key, sdata, sta);
156
Johannes Berg3b967662008-04-08 17:56:52 +0200157 err = 0;
158 out_unlock:
159 rcu_read_unlock();
160
161 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162}
163
164static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
165 u8 key_idx, u8 *mac_addr)
166{
167 struct ieee80211_sub_if_data *sdata;
168 struct sta_info *sta;
169 int ret;
170
171 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
172
Johannes Berg3b967662008-04-08 17:56:52 +0200173 rcu_read_lock();
174
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100175 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200176 ret = -ENOENT;
177
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100178 sta = sta_info_get(sdata->local, mac_addr);
179 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200180 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100181
Johannes Bergdb4d1162008-02-25 16:27:45 +0100182 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100183 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100184 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200185 ret = 0;
186 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100187
Johannes Berg3b967662008-04-08 17:56:52 +0200188 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189 }
190
Johannes Berg3b967662008-04-08 17:56:52 +0200191 if (!sdata->keys[key_idx]) {
192 ret = -ENOENT;
193 goto out_unlock;
194 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195
Johannes Bergd0709a62008-02-25 16:27:46 +0100196 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100197 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100198
Johannes Berg3b967662008-04-08 17:56:52 +0200199 ret = 0;
200 out_unlock:
201 rcu_read_unlock();
202
203 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204}
205
Johannes Berg62da92f2007-12-19 02:03:31 +0100206static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
207 u8 key_idx, u8 *mac_addr, void *cookie,
208 void (*callback)(void *cookie,
209 struct key_params *params))
210{
Johannes Berg14db74b2008-07-29 13:22:52 +0200211 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100212 struct sta_info *sta = NULL;
213 u8 seq[6] = {0};
214 struct key_params params;
215 struct ieee80211_key *key;
216 u32 iv32;
217 u16 iv16;
218 int err = -ENOENT;
219
Johannes Berg14db74b2008-07-29 13:22:52 +0200220 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
221
Johannes Berg3b967662008-04-08 17:56:52 +0200222 rcu_read_lock();
223
Johannes Berg62da92f2007-12-19 02:03:31 +0100224 if (mac_addr) {
225 sta = sta_info_get(sdata->local, mac_addr);
226 if (!sta)
227 goto out;
228
229 key = sta->key;
230 } else
231 key = sdata->keys[key_idx];
232
233 if (!key)
234 goto out;
235
236 memset(&params, 0, sizeof(params));
237
238 switch (key->conf.alg) {
239 case ALG_TKIP:
240 params.cipher = WLAN_CIPHER_SUITE_TKIP;
241
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700242 iv32 = key->u.tkip.tx.iv32;
243 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100244
245 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
246 sdata->local->ops->get_tkip_seq)
247 sdata->local->ops->get_tkip_seq(
248 local_to_hw(sdata->local),
249 key->conf.hw_key_idx,
250 &iv32, &iv16);
251
252 seq[0] = iv16 & 0xff;
253 seq[1] = (iv16 >> 8) & 0xff;
254 seq[2] = iv32 & 0xff;
255 seq[3] = (iv32 >> 8) & 0xff;
256 seq[4] = (iv32 >> 16) & 0xff;
257 seq[5] = (iv32 >> 24) & 0xff;
258 params.seq = seq;
259 params.seq_len = 6;
260 break;
261 case ALG_CCMP:
262 params.cipher = WLAN_CIPHER_SUITE_CCMP;
263 seq[0] = key->u.ccmp.tx_pn[5];
264 seq[1] = key->u.ccmp.tx_pn[4];
265 seq[2] = key->u.ccmp.tx_pn[3];
266 seq[3] = key->u.ccmp.tx_pn[2];
267 seq[4] = key->u.ccmp.tx_pn[1];
268 seq[5] = key->u.ccmp.tx_pn[0];
269 params.seq = seq;
270 params.seq_len = 6;
271 break;
272 case ALG_WEP:
273 if (key->conf.keylen == 5)
274 params.cipher = WLAN_CIPHER_SUITE_WEP40;
275 else
276 params.cipher = WLAN_CIPHER_SUITE_WEP104;
277 break;
278 }
279
280 params.key = key->conf.key;
281 params.key_len = key->conf.keylen;
282
283 callback(cookie, &params);
284 err = 0;
285
286 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200287 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100288 return err;
289}
290
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100291static int ieee80211_config_default_key(struct wiphy *wiphy,
292 struct net_device *dev,
293 u8 key_idx)
294{
295 struct ieee80211_sub_if_data *sdata;
296
Johannes Berg3b967662008-04-08 17:56:52 +0200297 rcu_read_lock();
298
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100299 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
300 ieee80211_set_default_key(sdata, key_idx);
301
Johannes Berg3b967662008-04-08 17:56:52 +0200302 rcu_read_unlock();
303
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100304 return 0;
305}
306
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100307static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
308{
Johannes Bergd0709a62008-02-25 16:27:46 +0100309 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100310
311 sinfo->filled = STATION_INFO_INACTIVE_TIME |
312 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100313 STATION_INFO_TX_BYTES |
314 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100315
316 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
317 sinfo->rx_bytes = sta->rx_bytes;
318 sinfo->tx_bytes = sta->tx_bytes;
319
Henning Rogge420e7fa2008-12-11 22:04:19 +0100320 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
321 sinfo->filled |= STATION_INFO_SIGNAL;
322 sinfo->signal = (s8)sta->last_signal;
323 }
324
325 sinfo->txrate.flags = 0;
326 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
327 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
328 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
329 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
330 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
331 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
332
333 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
334 struct ieee80211_supported_band *sband;
335 sband = sta->local->hw.wiphy->bands[
336 sta->local->hw.conf.channel->band];
337 sinfo->txrate.legacy =
338 sband->bitrates[sta->last_tx_rate.idx].bitrate;
339 } else
340 sinfo->txrate.mcs = sta->last_tx_rate.idx;
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;
Johannes Berg17741cd2008-09-11 00:02:02 +0200368 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100369 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;
Reinette Chatre447107f2008-12-04 14:49:08 -0800422 err = ieee80211_hw_config(sdata->local,
423 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
424 if (err < 0)
425 return err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100426 /*
427 * We updated some parameter so if below bails out
428 * it's not an error.
429 */
430 err = 0;
431 }
432
433 /* Need to have a beacon head if we don't have one yet */
434 if (!params->head && !old)
435 return err;
436
437 /* sorry, no way to start beaconing without dtim period */
438 if (!params->dtim_period && !old)
439 return err;
440
441 /* new or old head? */
442 if (params->head)
443 new_head_len = params->head_len;
444 else
445 new_head_len = old->head_len;
446
447 /* new or old tail? */
448 if (params->tail || !old)
449 /* params->tail_len will be zero for !params->tail */
450 new_tail_len = params->tail_len;
451 else
452 new_tail_len = old->tail_len;
453
454 size = sizeof(*new) + new_head_len + new_tail_len;
455
456 new = kzalloc(size, GFP_KERNEL);
457 if (!new)
458 return -ENOMEM;
459
460 /* start filling the new info now */
461
462 /* new or old dtim period? */
463 if (params->dtim_period)
464 new->dtim_period = params->dtim_period;
465 else
466 new->dtim_period = old->dtim_period;
467
468 /*
469 * pointers go into the block we allocated,
470 * memory is | beacon_data | head | tail |
471 */
472 new->head = ((u8 *) new) + sizeof(*new);
473 new->tail = new->head + new_head_len;
474 new->head_len = new_head_len;
475 new->tail_len = new_tail_len;
476
477 /* copy in head */
478 if (params->head)
479 memcpy(new->head, params->head, new_head_len);
480 else
481 memcpy(new->head, old->head, new_head_len);
482
483 /* copy in optional tail */
484 if (params->tail)
485 memcpy(new->tail, params->tail, new_tail_len);
486 else
487 if (old)
488 memcpy(new->tail, old->tail, new_tail_len);
489
490 rcu_assign_pointer(sdata->u.ap.beacon, new);
491
492 synchronize_rcu();
493
494 kfree(old);
495
Johannes Berg9d139c82008-07-09 14:40:37 +0200496 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100497}
498
499static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
500 struct beacon_parameters *params)
501{
Johannes Berg14db74b2008-07-29 13:22:52 +0200502 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100503 struct beacon_data *old;
504
Johannes Berg14db74b2008-07-29 13:22:52 +0200505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
506
Johannes Berg05c914f2008-09-11 00:01:58 +0200507 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100508 return -EINVAL;
509
510 old = sdata->u.ap.beacon;
511
512 if (old)
513 return -EALREADY;
514
515 return ieee80211_config_beacon(sdata, params);
516}
517
518static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
519 struct beacon_parameters *params)
520{
Johannes Berg14db74b2008-07-29 13:22:52 +0200521 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100522 struct beacon_data *old;
523
Johannes Berg14db74b2008-07-29 13:22:52 +0200524 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
525
Johannes Berg05c914f2008-09-11 00:01:58 +0200526 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100527 return -EINVAL;
528
529 old = sdata->u.ap.beacon;
530
531 if (!old)
532 return -ENOENT;
533
534 return ieee80211_config_beacon(sdata, params);
535}
536
537static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
538{
Johannes Berg14db74b2008-07-29 13:22:52 +0200539 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100540 struct beacon_data *old;
541
Johannes Berg14db74b2008-07-29 13:22:52 +0200542 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
543
Johannes Berg05c914f2008-09-11 00:01:58 +0200544 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100545 return -EINVAL;
546
547 old = sdata->u.ap.beacon;
548
549 if (!old)
550 return -ENOENT;
551
552 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
553 synchronize_rcu();
554 kfree(old);
555
Johannes Berg9d139c82008-07-09 14:40:37 +0200556 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100557}
558
Johannes Berg4fd69312007-12-19 02:03:35 +0100559/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
560struct iapp_layer2_update {
561 u8 da[ETH_ALEN]; /* broadcast */
562 u8 sa[ETH_ALEN]; /* STA addr */
563 __be16 len; /* 6 */
564 u8 dsap; /* 0 */
565 u8 ssap; /* 0 */
566 u8 control;
567 u8 xid_info[3];
568} __attribute__ ((packed));
569
570static void ieee80211_send_layer2_update(struct sta_info *sta)
571{
572 struct iapp_layer2_update *msg;
573 struct sk_buff *skb;
574
575 /* Send Level 2 Update Frame to update forwarding tables in layer 2
576 * bridge devices */
577
578 skb = dev_alloc_skb(sizeof(*msg));
579 if (!skb)
580 return;
581 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
582
583 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
584 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
585
586 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200587 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100588 msg->len = htons(6);
589 msg->dsap = 0;
590 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
591 msg->control = 0xaf; /* XID response lsb.1111F101.
592 * F=0 (no poll command; unsolicited frame) */
593 msg->xid_info[0] = 0x81; /* XID format identifier */
594 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
595 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
596
Johannes Bergd0709a62008-02-25 16:27:46 +0100597 skb->dev = sta->sdata->dev;
598 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100599 memset(skb->cb, 0, sizeof(skb->cb));
600 netif_rx(skb);
601}
602
603static void sta_apply_parameters(struct ieee80211_local *local,
604 struct sta_info *sta,
605 struct station_parameters *params)
606{
607 u32 rates;
608 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100609 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100610 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100611
Johannes Bergae5eb022008-10-14 16:58:37 +0200612 sband = local->hw.wiphy->bands[local->oper_channel->band];
613
Johannes Berg73651ee2008-02-25 16:27:47 +0100614 /*
615 * FIXME: updating the flags is racy when this function is
616 * called from ieee80211_change_station(), this will
617 * be resolved in a future patch.
618 */
619
Johannes Berg4fd69312007-12-19 02:03:35 +0100620 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200621 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100622 sta->flags &= ~WLAN_STA_AUTHORIZED;
623 if (params->station_flags & STATION_FLAG_AUTHORIZED)
624 sta->flags |= WLAN_STA_AUTHORIZED;
625
626 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
627 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
628 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
629
630 sta->flags &= ~WLAN_STA_WME;
631 if (params->station_flags & STATION_FLAG_WME)
632 sta->flags |= WLAN_STA_WME;
Johannes Berg07346f812008-05-03 01:02:02 +0200633 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100634 }
635
Johannes Berg73651ee2008-02-25 16:27:47 +0100636 /*
637 * FIXME: updating the following information is racy when this
638 * function is called from ieee80211_change_station().
639 * However, all this information should be static so
640 * maybe we should just reject attemps to change it.
641 */
642
Johannes Berg4fd69312007-12-19 02:03:35 +0100643 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200644 sta->sta.aid = params->aid;
645 if (sta->sta.aid > IEEE80211_MAX_AID)
646 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100647 }
648
649 if (params->listen_interval >= 0)
650 sta->listen_interval = params->listen_interval;
651
652 if (params->supported_rates) {
653 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100654
Johannes Berg4fd69312007-12-19 02:03:35 +0100655 for (i = 0; i < params->supported_rates_len; i++) {
656 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100657 for (j = 0; j < sband->n_bitrates; j++) {
658 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100659 rates |= BIT(j);
660 }
661 }
Johannes Berg323ce792008-09-11 02:45:11 +0200662 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100663 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100664
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200665 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200666 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
667 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200668 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300669
Johannes Berg902acc72008-02-23 15:17:19 +0100670 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100671 switch (params->plink_action) {
672 case PLINK_ACTION_OPEN:
673 mesh_plink_open(sta);
674 break;
675 case PLINK_ACTION_BLOCK:
676 mesh_plink_block(sta);
677 break;
678 }
Johannes Berg902acc72008-02-23 15:17:19 +0100679 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100680}
681
682static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
683 u8 *mac, struct station_parameters *params)
684{
Johannes Berg14db74b2008-07-29 13:22:52 +0200685 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100686 struct sta_info *sta;
687 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100688 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100689
690 /* Prevent a race with changing the rate control algorithm */
691 if (!netif_running(dev))
692 return -ENETDOWN;
693
Johannes Berg4fd69312007-12-19 02:03:35 +0100694 if (params->vlan) {
695 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
696
Johannes Berg05c914f2008-09-11 00:01:58 +0200697 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
698 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100699 return -EINVAL;
700 } else
701 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
702
Johannes Berg03e44972008-02-27 09:56:40 +0100703 if (compare_ether_addr(mac, dev->dev_addr) == 0)
704 return -EINVAL;
705
706 if (is_multicast_ether_addr(mac))
707 return -EINVAL;
708
709 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100710 if (!sta)
711 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100712
713 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
714
715 sta_apply_parameters(local, sta, params);
716
Johannes Berg4b7679a2008-09-18 18:14:18 +0200717 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100718
Johannes Berg73651ee2008-02-25 16:27:47 +0100719 rcu_read_lock();
720
721 err = sta_info_insert(sta);
722 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200723 /* STA has been freed */
Johannes Berg73651ee2008-02-25 16:27:47 +0100724 rcu_read_unlock();
725 return err;
726 }
727
Johannes Berg05c914f2008-09-11 00:01:58 +0200728 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
729 sdata->vif.type == NL80211_IFTYPE_AP)
Johannes Berg73651ee2008-02-25 16:27:47 +0100730 ieee80211_send_layer2_update(sta);
731
732 rcu_read_unlock();
733
Johannes Berg4fd69312007-12-19 02:03:35 +0100734 return 0;
735}
736
737static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
738 u8 *mac)
739{
Johannes Berg14db74b2008-07-29 13:22:52 +0200740 struct ieee80211_local *local = wiphy_priv(wiphy);
741 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100742 struct sta_info *sta;
743
Johannes Berg14db74b2008-07-29 13:22:52 +0200744 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
745
Johannes Berg4fd69312007-12-19 02:03:35 +0100746 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200747 rcu_read_lock();
748
Johannes Berg4fd69312007-12-19 02:03:35 +0100749 /* XXX: get sta belonging to dev */
750 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200751 if (!sta) {
752 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100753 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200754 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100755
Johannes Bergd0709a62008-02-25 16:27:46 +0100756 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200757 rcu_read_unlock();
758
Johannes Berg4f6fab42008-03-31 19:23:02 +0200759 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100760 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100761 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100762
763 return 0;
764}
765
766static int ieee80211_change_station(struct wiphy *wiphy,
767 struct net_device *dev,
768 u8 *mac,
769 struct station_parameters *params)
770{
Johannes Berg14db74b2008-07-29 13:22:52 +0200771 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100772 struct sta_info *sta;
773 struct ieee80211_sub_if_data *vlansdata;
774
Johannes Berg98dd6a52008-04-10 15:36:09 +0200775 rcu_read_lock();
776
Johannes Berg4fd69312007-12-19 02:03:35 +0100777 /* XXX: get sta belonging to dev */
778 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200779 if (!sta) {
780 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100781 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200782 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100783
Johannes Bergd0709a62008-02-25 16:27:46 +0100784 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100785 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
786
Johannes Berg05c914f2008-09-11 00:01:58 +0200787 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
788 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200789 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100790 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200791 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100792
Johannes Berg14db74b2008-07-29 13:22:52 +0200793 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100794 ieee80211_send_layer2_update(sta);
795 }
796
797 sta_apply_parameters(local, sta, params);
798
Johannes Berg98dd6a52008-04-10 15:36:09 +0200799 rcu_read_unlock();
800
Johannes Berg4fd69312007-12-19 02:03:35 +0100801 return 0;
802}
803
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100804#ifdef CONFIG_MAC80211_MESH
805static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
806 u8 *dst, u8 *next_hop)
807{
Johannes Berg14db74b2008-07-29 13:22:52 +0200808 struct ieee80211_local *local = wiphy_priv(wiphy);
809 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100810 struct mesh_path *mpath;
811 struct sta_info *sta;
812 int err;
813
814 if (!netif_running(dev))
815 return -ENETDOWN;
816
Johannes Berg14db74b2008-07-29 13:22:52 +0200817 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
818
Johannes Berg05c914f2008-09-11 00:01:58 +0200819 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100820 return -ENOTSUPP;
821
Johannes Bergd0709a62008-02-25 16:27:46 +0100822 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100823 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100824 if (!sta) {
825 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100826 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100827 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100828
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200829 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100830 if (err) {
831 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100832 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100833 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100834
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200835 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100836 if (!mpath) {
837 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100838 return -ENXIO;
839 }
840 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100841
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100842 rcu_read_unlock();
843 return 0;
844}
845
846static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
847 u8 *dst)
848{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200849 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100850
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200851 if (dst)
852 return mesh_path_del(dst, sdata);
853
854 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100855 return 0;
856}
857
858static int ieee80211_change_mpath(struct wiphy *wiphy,
859 struct net_device *dev,
860 u8 *dst, u8 *next_hop)
861{
Johannes Berg14db74b2008-07-29 13:22:52 +0200862 struct ieee80211_local *local = wiphy_priv(wiphy);
863 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100864 struct mesh_path *mpath;
865 struct sta_info *sta;
866
867 if (!netif_running(dev))
868 return -ENETDOWN;
869
Johannes Berg14db74b2008-07-29 13:22:52 +0200870 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
871
Johannes Berg05c914f2008-09-11 00:01:58 +0200872 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100873 return -ENOTSUPP;
874
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100875 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100876
877 sta = sta_info_get(local, next_hop);
878 if (!sta) {
879 rcu_read_unlock();
880 return -ENOENT;
881 }
882
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200883 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100884 if (!mpath) {
885 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100886 return -ENOENT;
887 }
888
889 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100890
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100891 rcu_read_unlock();
892 return 0;
893}
894
895static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
896 struct mpath_info *pinfo)
897{
898 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200899 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100900 else
901 memset(next_hop, 0, ETH_ALEN);
902
903 pinfo->filled = MPATH_INFO_FRAME_QLEN |
904 MPATH_INFO_DSN |
905 MPATH_INFO_METRIC |
906 MPATH_INFO_EXPTIME |
907 MPATH_INFO_DISCOVERY_TIMEOUT |
908 MPATH_INFO_DISCOVERY_RETRIES |
909 MPATH_INFO_FLAGS;
910
911 pinfo->frame_qlen = mpath->frame_queue.qlen;
912 pinfo->dsn = mpath->dsn;
913 pinfo->metric = mpath->metric;
914 if (time_before(jiffies, mpath->exp_time))
915 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
916 pinfo->discovery_timeout =
917 jiffies_to_msecs(mpath->discovery_timeout);
918 pinfo->discovery_retries = mpath->discovery_retries;
919 pinfo->flags = 0;
920 if (mpath->flags & MESH_PATH_ACTIVE)
921 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
922 if (mpath->flags & MESH_PATH_RESOLVING)
923 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
924 if (mpath->flags & MESH_PATH_DSN_VALID)
925 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
926 if (mpath->flags & MESH_PATH_FIXED)
927 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
928 if (mpath->flags & MESH_PATH_RESOLVING)
929 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
930
931 pinfo->flags = mpath->flags;
932}
933
934static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
935 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
936
937{
Johannes Berg14db74b2008-07-29 13:22:52 +0200938 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100939 struct mesh_path *mpath;
940
Johannes Berg14db74b2008-07-29 13:22:52 +0200941 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
942
Johannes Berg05c914f2008-09-11 00:01:58 +0200943 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100944 return -ENOTSUPP;
945
946 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200947 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100948 if (!mpath) {
949 rcu_read_unlock();
950 return -ENOENT;
951 }
952 memcpy(dst, mpath->dst, ETH_ALEN);
953 mpath_set_pinfo(mpath, next_hop, pinfo);
954 rcu_read_unlock();
955 return 0;
956}
957
958static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
959 int idx, u8 *dst, u8 *next_hop,
960 struct mpath_info *pinfo)
961{
Johannes Berg14db74b2008-07-29 13:22:52 +0200962 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 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
966
Johannes Berg05c914f2008-09-11 00:01:58 +0200967 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100968 return -ENOTSUPP;
969
970 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200971 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100972 if (!mpath) {
973 rcu_read_unlock();
974 return -ENOENT;
975 }
976 memcpy(dst, mpath->dst, ETH_ALEN);
977 mpath_set_pinfo(mpath, next_hop, pinfo);
978 rcu_read_unlock();
979 return 0;
980}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700981
982static int ieee80211_get_mesh_params(struct wiphy *wiphy,
983 struct net_device *dev,
984 struct mesh_config *conf)
985{
986 struct ieee80211_sub_if_data *sdata;
987 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
988
989 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
990 return -ENOTSUPP;
991 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
992 return 0;
993}
994
995static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
996{
997 return (mask >> (parm-1)) & 0x1;
998}
999
1000static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1001 struct net_device *dev,
1002 const struct mesh_config *nconf, u32 mask)
1003{
1004 struct mesh_config *conf;
1005 struct ieee80211_sub_if_data *sdata;
1006 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1007
1008 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1009 return -ENOTSUPP;
1010
1011 /* Set the config options which we are interested in setting */
1012 conf = &(sdata->u.mesh.mshcfg);
1013 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1014 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1015 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1016 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1017 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1018 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1019 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1020 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1022 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1024 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1026 conf->auto_open_plinks = nconf->auto_open_plinks;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1028 conf->dot11MeshHWMPmaxPREQretries =
1029 nconf->dot11MeshHWMPmaxPREQretries;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1031 conf->path_refresh_time = nconf->path_refresh_time;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1033 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1034 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1035 conf->dot11MeshHWMPactivePathTimeout =
1036 nconf->dot11MeshHWMPactivePathTimeout;
1037 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1038 conf->dot11MeshHWMPpreqMinInterval =
1039 nconf->dot11MeshHWMPpreqMinInterval;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1041 mask))
1042 conf->dot11MeshHWMPnetDiameterTraversalTime =
1043 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1044 return 0;
1045}
1046
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001047#endif
1048
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001049static int ieee80211_change_bss(struct wiphy *wiphy,
1050 struct net_device *dev,
1051 struct bss_parameters *params)
1052{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001053 struct ieee80211_sub_if_data *sdata;
1054 u32 changed = 0;
1055
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001056 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1057
Johannes Berg05c914f2008-09-11 00:01:58 +02001058 if (sdata->vif.type != NL80211_IFTYPE_AP)
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001059 return -EINVAL;
1060
1061 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001062 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001063 changed |= BSS_CHANGED_ERP_CTS_PROT;
1064 }
1065 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001066 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001067 params->use_short_preamble;
1068 changed |= BSS_CHANGED_ERP_PREAMBLE;
1069 }
1070 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001071 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001072 params->use_short_slot_time;
1073 changed |= BSS_CHANGED_ERP_SLOT;
1074 }
1075
Jouni Malinen90c97a02008-10-30 16:59:22 +02001076 if (params->basic_rates) {
1077 int i, j;
1078 u32 rates = 0;
1079 struct ieee80211_local *local = wiphy_priv(wiphy);
1080 struct ieee80211_supported_band *sband =
1081 wiphy->bands[local->oper_channel->band];
1082
1083 for (i = 0; i < params->basic_rates_len; i++) {
1084 int rate = (params->basic_rates[i] & 0x7f) * 5;
1085 for (j = 0; j < sband->n_bitrates; j++) {
1086 if (sband->bitrates[j].bitrate == rate)
1087 rates |= BIT(j);
1088 }
1089 }
1090 sdata->vif.bss_conf.basic_rates = rates;
1091 changed |= BSS_CHANGED_BASIC_RATES;
1092 }
1093
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001094 ieee80211_bss_info_change_notify(sdata, changed);
1095
1096 return 0;
1097}
1098
Jouni Malinen31888482008-10-30 16:59:24 +02001099static int ieee80211_set_txq_params(struct wiphy *wiphy,
1100 struct ieee80211_txq_params *params)
1101{
1102 struct ieee80211_local *local = wiphy_priv(wiphy);
1103 struct ieee80211_tx_queue_params p;
1104
1105 if (!local->ops->conf_tx)
1106 return -EOPNOTSUPP;
1107
1108 memset(&p, 0, sizeof(p));
1109 p.aifs = params->aifs;
1110 p.cw_max = params->cwmax;
1111 p.cw_min = params->cwmin;
1112 p.txop = params->txop;
1113 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1114 printk(KERN_DEBUG "%s: failed to set TX queue "
1115 "parameters for queue %d\n", local->mdev->name,
1116 params->queue);
1117 return -EINVAL;
1118 }
1119
1120 return 0;
1121}
1122
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001123static int ieee80211_set_channel(struct wiphy *wiphy,
1124 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301125 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001126{
1127 struct ieee80211_local *local = wiphy_priv(wiphy);
1128
1129 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +05301130 local->oper_channel_type = channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001131
1132 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1133}
1134
Jiri Bencf0706e82007-05-05 11:45:53 -07001135struct cfg80211_ops mac80211_config_ops = {
1136 .add_virtual_intf = ieee80211_add_iface,
1137 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001138 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001139 .add_key = ieee80211_add_key,
1140 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001141 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001142 .set_default_key = ieee80211_config_default_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001143 .add_beacon = ieee80211_add_beacon,
1144 .set_beacon = ieee80211_set_beacon,
1145 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001146 .add_station = ieee80211_add_station,
1147 .del_station = ieee80211_del_station,
1148 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001149 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001150 .dump_station = ieee80211_dump_station,
1151#ifdef CONFIG_MAC80211_MESH
1152 .add_mpath = ieee80211_add_mpath,
1153 .del_mpath = ieee80211_del_mpath,
1154 .change_mpath = ieee80211_change_mpath,
1155 .get_mpath = ieee80211_get_mpath,
1156 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001157 .set_mesh_params = ieee80211_set_mesh_params,
1158 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001159#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001160 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001161 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001162 .set_channel = ieee80211_set_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07001163};