blob: 3527de22cafbed0b628d57643d51dfeb414dfb82 [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;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200136 case WLAN_CIPHER_SUITE_AES_CMAC:
137 alg = ALG_AES_CMAC;
138 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100139 default:
140 return -EINVAL;
141 }
142
Johannes Bergdb4d1162008-02-25 16:27:45 +0100143 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key);
144 if (!key)
145 return -ENOMEM;
146
Johannes Berg3b967662008-04-08 17:56:52 +0200147 rcu_read_lock();
148
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149 if (mac_addr) {
150 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100151 if (!sta) {
152 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200153 err = -ENOENT;
154 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100156 }
157
Johannes Bergdb4d1162008-02-25 16:27:45 +0100158 ieee80211_key_link(key, sdata, sta);
159
Johannes Berg3b967662008-04-08 17:56:52 +0200160 err = 0;
161 out_unlock:
162 rcu_read_unlock();
163
164 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100165}
166
167static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
168 u8 key_idx, u8 *mac_addr)
169{
170 struct ieee80211_sub_if_data *sdata;
171 struct sta_info *sta;
172 int ret;
173
174 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
175
Johannes Berg3b967662008-04-08 17:56:52 +0200176 rcu_read_lock();
177
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100178 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200179 ret = -ENOENT;
180
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100181 sta = sta_info_get(sdata->local, mac_addr);
182 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200183 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100184
Johannes Bergdb4d1162008-02-25 16:27:45 +0100185 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100186 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100187 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200188 ret = 0;
189 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100190
Johannes Berg3b967662008-04-08 17:56:52 +0200191 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100192 }
193
Johannes Berg3b967662008-04-08 17:56:52 +0200194 if (!sdata->keys[key_idx]) {
195 ret = -ENOENT;
196 goto out_unlock;
197 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100198
Johannes Bergd0709a62008-02-25 16:27:46 +0100199 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100200 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100201
Johannes Berg3b967662008-04-08 17:56:52 +0200202 ret = 0;
203 out_unlock:
204 rcu_read_unlock();
205
206 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100207}
208
Johannes Berg62da92f2007-12-19 02:03:31 +0100209static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
210 u8 key_idx, u8 *mac_addr, void *cookie,
211 void (*callback)(void *cookie,
212 struct key_params *params))
213{
Johannes Berg14db74b2008-07-29 13:22:52 +0200214 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100215 struct sta_info *sta = NULL;
216 u8 seq[6] = {0};
217 struct key_params params;
218 struct ieee80211_key *key;
219 u32 iv32;
220 u16 iv16;
221 int err = -ENOENT;
222
Johannes Berg14db74b2008-07-29 13:22:52 +0200223 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
224
Johannes Berg3b967662008-04-08 17:56:52 +0200225 rcu_read_lock();
226
Johannes Berg62da92f2007-12-19 02:03:31 +0100227 if (mac_addr) {
228 sta = sta_info_get(sdata->local, mac_addr);
229 if (!sta)
230 goto out;
231
232 key = sta->key;
233 } else
234 key = sdata->keys[key_idx];
235
236 if (!key)
237 goto out;
238
239 memset(&params, 0, sizeof(params));
240
241 switch (key->conf.alg) {
242 case ALG_TKIP:
243 params.cipher = WLAN_CIPHER_SUITE_TKIP;
244
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700245 iv32 = key->u.tkip.tx.iv32;
246 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100247
248 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
249 sdata->local->ops->get_tkip_seq)
250 sdata->local->ops->get_tkip_seq(
251 local_to_hw(sdata->local),
252 key->conf.hw_key_idx,
253 &iv32, &iv16);
254
255 seq[0] = iv16 & 0xff;
256 seq[1] = (iv16 >> 8) & 0xff;
257 seq[2] = iv32 & 0xff;
258 seq[3] = (iv32 >> 8) & 0xff;
259 seq[4] = (iv32 >> 16) & 0xff;
260 seq[5] = (iv32 >> 24) & 0xff;
261 params.seq = seq;
262 params.seq_len = 6;
263 break;
264 case ALG_CCMP:
265 params.cipher = WLAN_CIPHER_SUITE_CCMP;
266 seq[0] = key->u.ccmp.tx_pn[5];
267 seq[1] = key->u.ccmp.tx_pn[4];
268 seq[2] = key->u.ccmp.tx_pn[3];
269 seq[3] = key->u.ccmp.tx_pn[2];
270 seq[4] = key->u.ccmp.tx_pn[1];
271 seq[5] = key->u.ccmp.tx_pn[0];
272 params.seq = seq;
273 params.seq_len = 6;
274 break;
275 case ALG_WEP:
276 if (key->conf.keylen == 5)
277 params.cipher = WLAN_CIPHER_SUITE_WEP40;
278 else
279 params.cipher = WLAN_CIPHER_SUITE_WEP104;
280 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200281 case ALG_AES_CMAC:
282 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
283 seq[0] = key->u.aes_cmac.tx_pn[5];
284 seq[1] = key->u.aes_cmac.tx_pn[4];
285 seq[2] = key->u.aes_cmac.tx_pn[3];
286 seq[3] = key->u.aes_cmac.tx_pn[2];
287 seq[4] = key->u.aes_cmac.tx_pn[1];
288 seq[5] = key->u.aes_cmac.tx_pn[0];
289 params.seq = seq;
290 params.seq_len = 6;
291 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100292 }
293
294 params.key = key->conf.key;
295 params.key_len = key->conf.keylen;
296
297 callback(cookie, &params);
298 err = 0;
299
300 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200301 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100302 return err;
303}
304
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100305static int ieee80211_config_default_key(struct wiphy *wiphy,
306 struct net_device *dev,
307 u8 key_idx)
308{
309 struct ieee80211_sub_if_data *sdata;
310
Johannes Berg3b967662008-04-08 17:56:52 +0200311 rcu_read_lock();
312
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100313 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
314 ieee80211_set_default_key(sdata, key_idx);
315
Johannes Berg3b967662008-04-08 17:56:52 +0200316 rcu_read_unlock();
317
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100318 return 0;
319}
320
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200321static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
322 struct net_device *dev,
323 u8 key_idx)
324{
325 struct ieee80211_sub_if_data *sdata;
326
327 rcu_read_lock();
328
329 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
330 ieee80211_set_default_mgmt_key(sdata, key_idx);
331
332 rcu_read_unlock();
333
334 return 0;
335}
336
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100337static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
338{
Johannes Bergd0709a62008-02-25 16:27:46 +0100339 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100340
341 sinfo->filled = STATION_INFO_INACTIVE_TIME |
342 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100343 STATION_INFO_TX_BYTES |
344 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100345
346 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
347 sinfo->rx_bytes = sta->rx_bytes;
348 sinfo->tx_bytes = sta->tx_bytes;
349
Henning Rogge420e7fa2008-12-11 22:04:19 +0100350 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
351 sinfo->filled |= STATION_INFO_SIGNAL;
352 sinfo->signal = (s8)sta->last_signal;
353 }
354
355 sinfo->txrate.flags = 0;
356 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
357 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
358 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
359 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
360 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
361 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
362
363 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
364 struct ieee80211_supported_band *sband;
365 sband = sta->local->hw.wiphy->bands[
366 sta->local->hw.conf.channel->band];
367 sinfo->txrate.legacy =
368 sband->bitrates[sta->last_tx_rate.idx].bitrate;
369 } else
370 sinfo->txrate.mcs = sta->last_tx_rate.idx;
371
Johannes Berg902acc72008-02-23 15:17:19 +0100372 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100373#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100374 sinfo->filled |= STATION_INFO_LLID |
375 STATION_INFO_PLID |
376 STATION_INFO_PLINK_STATE;
377
378 sinfo->llid = le16_to_cpu(sta->llid);
379 sinfo->plid = le16_to_cpu(sta->plid);
380 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100381#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100382 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100383}
384
385
386static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
387 int idx, u8 *mac, struct station_info *sinfo)
388{
389 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
390 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100391 int ret = -ENOENT;
392
393 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100394
395 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100396 if (sta) {
397 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200398 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100399 sta_set_sinfo(sta, sinfo);
400 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100401
Johannes Bergd0709a62008-02-25 16:27:46 +0100402 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100403
Johannes Bergd0709a62008-02-25 16:27:46 +0100404 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100405}
406
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100407static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100408 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100409{
410 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
411 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100412 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100413
Johannes Bergd0709a62008-02-25 16:27:46 +0100414 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100415
416 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100417
Johannes Bergd0709a62008-02-25 16:27:46 +0100418 sta = sta_info_get(local, mac);
419 if (sta) {
420 ret = 0;
421 sta_set_sinfo(sta, sinfo);
422 }
423
424 rcu_read_unlock();
425
426 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100427}
428
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100429/*
430 * This handles both adding a beacon and setting new beacon info
431 */
432static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
433 struct beacon_parameters *params)
434{
435 struct beacon_data *new, *old;
436 int new_head_len, new_tail_len;
437 int size;
438 int err = -EINVAL;
439
440 old = sdata->u.ap.beacon;
441
442 /* head must not be zero-length */
443 if (params->head && !params->head_len)
444 return -EINVAL;
445
446 /*
447 * This is a kludge. beacon interval should really be part
448 * of the beacon information.
449 */
450 if (params->interval) {
451 sdata->local->hw.conf.beacon_int = params->interval;
Reinette Chatre447107f2008-12-04 14:49:08 -0800452 err = ieee80211_hw_config(sdata->local,
453 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
454 if (err < 0)
455 return err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100456 /*
457 * We updated some parameter so if below bails out
458 * it's not an error.
459 */
460 err = 0;
461 }
462
463 /* Need to have a beacon head if we don't have one yet */
464 if (!params->head && !old)
465 return err;
466
467 /* sorry, no way to start beaconing without dtim period */
468 if (!params->dtim_period && !old)
469 return err;
470
471 /* new or old head? */
472 if (params->head)
473 new_head_len = params->head_len;
474 else
475 new_head_len = old->head_len;
476
477 /* new or old tail? */
478 if (params->tail || !old)
479 /* params->tail_len will be zero for !params->tail */
480 new_tail_len = params->tail_len;
481 else
482 new_tail_len = old->tail_len;
483
484 size = sizeof(*new) + new_head_len + new_tail_len;
485
486 new = kzalloc(size, GFP_KERNEL);
487 if (!new)
488 return -ENOMEM;
489
490 /* start filling the new info now */
491
492 /* new or old dtim period? */
493 if (params->dtim_period)
494 new->dtim_period = params->dtim_period;
495 else
496 new->dtim_period = old->dtim_period;
497
498 /*
499 * pointers go into the block we allocated,
500 * memory is | beacon_data | head | tail |
501 */
502 new->head = ((u8 *) new) + sizeof(*new);
503 new->tail = new->head + new_head_len;
504 new->head_len = new_head_len;
505 new->tail_len = new_tail_len;
506
507 /* copy in head */
508 if (params->head)
509 memcpy(new->head, params->head, new_head_len);
510 else
511 memcpy(new->head, old->head, new_head_len);
512
513 /* copy in optional tail */
514 if (params->tail)
515 memcpy(new->tail, params->tail, new_tail_len);
516 else
517 if (old)
518 memcpy(new->tail, old->tail, new_tail_len);
519
520 rcu_assign_pointer(sdata->u.ap.beacon, new);
521
522 synchronize_rcu();
523
524 kfree(old);
525
Johannes Berg9d139c82008-07-09 14:40:37 +0200526 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100527}
528
529static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
530 struct beacon_parameters *params)
531{
Johannes Berg14db74b2008-07-29 13:22:52 +0200532 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100533 struct beacon_data *old;
534
Johannes Berg14db74b2008-07-29 13:22:52 +0200535 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
536
Johannes Berg05c914f2008-09-11 00:01:58 +0200537 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100538 return -EINVAL;
539
540 old = sdata->u.ap.beacon;
541
542 if (old)
543 return -EALREADY;
544
545 return ieee80211_config_beacon(sdata, params);
546}
547
548static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
549 struct beacon_parameters *params)
550{
Johannes Berg14db74b2008-07-29 13:22:52 +0200551 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100552 struct beacon_data *old;
553
Johannes Berg14db74b2008-07-29 13:22:52 +0200554 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555
Johannes Berg05c914f2008-09-11 00:01:58 +0200556 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100557 return -EINVAL;
558
559 old = sdata->u.ap.beacon;
560
561 if (!old)
562 return -ENOENT;
563
564 return ieee80211_config_beacon(sdata, params);
565}
566
567static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
568{
Johannes Berg14db74b2008-07-29 13:22:52 +0200569 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100570 struct beacon_data *old;
571
Johannes Berg14db74b2008-07-29 13:22:52 +0200572 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
573
Johannes Berg05c914f2008-09-11 00:01:58 +0200574 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100575 return -EINVAL;
576
577 old = sdata->u.ap.beacon;
578
579 if (!old)
580 return -ENOENT;
581
582 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
583 synchronize_rcu();
584 kfree(old);
585
Johannes Berg9d139c82008-07-09 14:40:37 +0200586 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100587}
588
Johannes Berg4fd69312007-12-19 02:03:35 +0100589/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
590struct iapp_layer2_update {
591 u8 da[ETH_ALEN]; /* broadcast */
592 u8 sa[ETH_ALEN]; /* STA addr */
593 __be16 len; /* 6 */
594 u8 dsap; /* 0 */
595 u8 ssap; /* 0 */
596 u8 control;
597 u8 xid_info[3];
598} __attribute__ ((packed));
599
600static void ieee80211_send_layer2_update(struct sta_info *sta)
601{
602 struct iapp_layer2_update *msg;
603 struct sk_buff *skb;
604
605 /* Send Level 2 Update Frame to update forwarding tables in layer 2
606 * bridge devices */
607
608 skb = dev_alloc_skb(sizeof(*msg));
609 if (!skb)
610 return;
611 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
612
613 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
614 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
615
616 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200617 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100618 msg->len = htons(6);
619 msg->dsap = 0;
620 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
621 msg->control = 0xaf; /* XID response lsb.1111F101.
622 * F=0 (no poll command; unsolicited frame) */
623 msg->xid_info[0] = 0x81; /* XID format identifier */
624 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
625 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
626
Johannes Bergd0709a62008-02-25 16:27:46 +0100627 skb->dev = sta->sdata->dev;
628 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100629 memset(skb->cb, 0, sizeof(skb->cb));
630 netif_rx(skb);
631}
632
633static void sta_apply_parameters(struct ieee80211_local *local,
634 struct sta_info *sta,
635 struct station_parameters *params)
636{
637 u32 rates;
638 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100639 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100640 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100641
Johannes Bergae5eb022008-10-14 16:58:37 +0200642 sband = local->hw.wiphy->bands[local->oper_channel->band];
643
Johannes Berg73651ee2008-02-25 16:27:47 +0100644 /*
645 * FIXME: updating the flags is racy when this function is
646 * called from ieee80211_change_station(), this will
647 * be resolved in a future patch.
648 */
649
Johannes Berg4fd69312007-12-19 02:03:35 +0100650 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200651 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100652 sta->flags &= ~WLAN_STA_AUTHORIZED;
653 if (params->station_flags & STATION_FLAG_AUTHORIZED)
654 sta->flags |= WLAN_STA_AUTHORIZED;
655
656 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
657 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
658 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
659
660 sta->flags &= ~WLAN_STA_WME;
661 if (params->station_flags & STATION_FLAG_WME)
662 sta->flags |= WLAN_STA_WME;
Jouni Malinen5394af42009-01-08 13:31:59 +0200663
664 sta->flags &= ~WLAN_STA_MFP;
665 if (params->station_flags & STATION_FLAG_MFP)
666 sta->flags |= WLAN_STA_MFP;
Johannes Berg07346f812008-05-03 01:02:02 +0200667 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100668 }
669
Johannes Berg73651ee2008-02-25 16:27:47 +0100670 /*
671 * FIXME: updating the following information is racy when this
672 * function is called from ieee80211_change_station().
673 * However, all this information should be static so
674 * maybe we should just reject attemps to change it.
675 */
676
Johannes Berg4fd69312007-12-19 02:03:35 +0100677 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200678 sta->sta.aid = params->aid;
679 if (sta->sta.aid > IEEE80211_MAX_AID)
680 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100681 }
682
683 if (params->listen_interval >= 0)
684 sta->listen_interval = params->listen_interval;
685
686 if (params->supported_rates) {
687 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100688
Johannes Berg4fd69312007-12-19 02:03:35 +0100689 for (i = 0; i < params->supported_rates_len; i++) {
690 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100691 for (j = 0; j < sband->n_bitrates; j++) {
692 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100693 rates |= BIT(j);
694 }
695 }
Johannes Berg323ce792008-09-11 02:45:11 +0200696 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100697 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100698
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200699 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200700 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
701 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200702 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300703
Johannes Berg902acc72008-02-23 15:17:19 +0100704 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100705 switch (params->plink_action) {
706 case PLINK_ACTION_OPEN:
707 mesh_plink_open(sta);
708 break;
709 case PLINK_ACTION_BLOCK:
710 mesh_plink_block(sta);
711 break;
712 }
Johannes Berg902acc72008-02-23 15:17:19 +0100713 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100714}
715
716static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
717 u8 *mac, struct station_parameters *params)
718{
Johannes Berg14db74b2008-07-29 13:22:52 +0200719 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100720 struct sta_info *sta;
721 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100722 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200723 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100724
725 /* Prevent a race with changing the rate control algorithm */
726 if (!netif_running(dev))
727 return -ENETDOWN;
728
Johannes Berg4fd69312007-12-19 02:03:35 +0100729 if (params->vlan) {
730 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
731
Johannes Berg05c914f2008-09-11 00:01:58 +0200732 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
733 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100734 return -EINVAL;
735 } else
736 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
737
Johannes Berg03e44972008-02-27 09:56:40 +0100738 if (compare_ether_addr(mac, dev->dev_addr) == 0)
739 return -EINVAL;
740
741 if (is_multicast_ether_addr(mac))
742 return -EINVAL;
743
744 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100745 if (!sta)
746 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100747
748 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
749
750 sta_apply_parameters(local, sta, params);
751
Johannes Berg4b7679a2008-09-18 18:14:18 +0200752 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100753
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200754 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
755 sdata->vif.type == NL80211_IFTYPE_AP;
756
Johannes Berg73651ee2008-02-25 16:27:47 +0100757 rcu_read_lock();
758
759 err = sta_info_insert(sta);
760 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200761 /* STA has been freed */
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200762 if (err == -EEXIST && layer2_update) {
763 /* Need to update layer 2 devices on reassociation */
764 sta = sta_info_get(local, mac);
765 if (sta)
766 ieee80211_send_layer2_update(sta);
767 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100768 rcu_read_unlock();
769 return err;
770 }
771
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200772 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100773 ieee80211_send_layer2_update(sta);
774
775 rcu_read_unlock();
776
Johannes Berg4fd69312007-12-19 02:03:35 +0100777 return 0;
778}
779
780static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
781 u8 *mac)
782{
Johannes Berg14db74b2008-07-29 13:22:52 +0200783 struct ieee80211_local *local = wiphy_priv(wiphy);
784 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100785 struct sta_info *sta;
786
Johannes Berg14db74b2008-07-29 13:22:52 +0200787 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
788
Johannes Berg4fd69312007-12-19 02:03:35 +0100789 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200790 rcu_read_lock();
791
Johannes Berg4fd69312007-12-19 02:03:35 +0100792 /* XXX: get sta belonging to dev */
793 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200794 if (!sta) {
795 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100796 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200797 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100798
Johannes Bergd0709a62008-02-25 16:27:46 +0100799 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200800 rcu_read_unlock();
801
Johannes Berg4f6fab42008-03-31 19:23:02 +0200802 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100803 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100804 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100805
806 return 0;
807}
808
809static int ieee80211_change_station(struct wiphy *wiphy,
810 struct net_device *dev,
811 u8 *mac,
812 struct station_parameters *params)
813{
Johannes Berg14db74b2008-07-29 13:22:52 +0200814 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100815 struct sta_info *sta;
816 struct ieee80211_sub_if_data *vlansdata;
817
Johannes Berg98dd6a52008-04-10 15:36:09 +0200818 rcu_read_lock();
819
Johannes Berg4fd69312007-12-19 02:03:35 +0100820 /* XXX: get sta belonging to dev */
821 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200822 if (!sta) {
823 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100824 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200825 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100826
Johannes Bergd0709a62008-02-25 16:27:46 +0100827 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100828 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
829
Johannes Berg05c914f2008-09-11 00:01:58 +0200830 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
831 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200832 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100833 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200834 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100835
Johannes Berg14db74b2008-07-29 13:22:52 +0200836 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100837 ieee80211_send_layer2_update(sta);
838 }
839
840 sta_apply_parameters(local, sta, params);
841
Johannes Berg98dd6a52008-04-10 15:36:09 +0200842 rcu_read_unlock();
843
Johannes Berg4fd69312007-12-19 02:03:35 +0100844 return 0;
845}
846
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100847#ifdef CONFIG_MAC80211_MESH
848static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
849 u8 *dst, u8 *next_hop)
850{
Johannes Berg14db74b2008-07-29 13:22:52 +0200851 struct ieee80211_local *local = wiphy_priv(wiphy);
852 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853 struct mesh_path *mpath;
854 struct sta_info *sta;
855 int err;
856
857 if (!netif_running(dev))
858 return -ENETDOWN;
859
Johannes Berg14db74b2008-07-29 13:22:52 +0200860 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
861
Johannes Berg05c914f2008-09-11 00:01:58 +0200862 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100863 return -ENOTSUPP;
864
Johannes Bergd0709a62008-02-25 16:27:46 +0100865 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100866 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100867 if (!sta) {
868 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100869 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100870 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100871
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200872 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100873 if (err) {
874 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100875 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100876 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100877
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200878 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100879 if (!mpath) {
880 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100881 return -ENXIO;
882 }
883 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100884
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100885 rcu_read_unlock();
886 return 0;
887}
888
889static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
890 u8 *dst)
891{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200892 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100893
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200894 if (dst)
895 return mesh_path_del(dst, sdata);
896
897 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100898 return 0;
899}
900
901static int ieee80211_change_mpath(struct wiphy *wiphy,
902 struct net_device *dev,
903 u8 *dst, u8 *next_hop)
904{
Johannes Berg14db74b2008-07-29 13:22:52 +0200905 struct ieee80211_local *local = wiphy_priv(wiphy);
906 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100907 struct mesh_path *mpath;
908 struct sta_info *sta;
909
910 if (!netif_running(dev))
911 return -ENETDOWN;
912
Johannes Berg14db74b2008-07-29 13:22:52 +0200913 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
914
Johannes Berg05c914f2008-09-11 00:01:58 +0200915 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100916 return -ENOTSUPP;
917
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100918 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100919
920 sta = sta_info_get(local, next_hop);
921 if (!sta) {
922 rcu_read_unlock();
923 return -ENOENT;
924 }
925
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200926 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100927 if (!mpath) {
928 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100929 return -ENOENT;
930 }
931
932 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100933
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100934 rcu_read_unlock();
935 return 0;
936}
937
938static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
939 struct mpath_info *pinfo)
940{
941 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200942 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100943 else
944 memset(next_hop, 0, ETH_ALEN);
945
946 pinfo->filled = MPATH_INFO_FRAME_QLEN |
947 MPATH_INFO_DSN |
948 MPATH_INFO_METRIC |
949 MPATH_INFO_EXPTIME |
950 MPATH_INFO_DISCOVERY_TIMEOUT |
951 MPATH_INFO_DISCOVERY_RETRIES |
952 MPATH_INFO_FLAGS;
953
954 pinfo->frame_qlen = mpath->frame_queue.qlen;
955 pinfo->dsn = mpath->dsn;
956 pinfo->metric = mpath->metric;
957 if (time_before(jiffies, mpath->exp_time))
958 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
959 pinfo->discovery_timeout =
960 jiffies_to_msecs(mpath->discovery_timeout);
961 pinfo->discovery_retries = mpath->discovery_retries;
962 pinfo->flags = 0;
963 if (mpath->flags & MESH_PATH_ACTIVE)
964 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
965 if (mpath->flags & MESH_PATH_RESOLVING)
966 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
967 if (mpath->flags & MESH_PATH_DSN_VALID)
968 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
969 if (mpath->flags & MESH_PATH_FIXED)
970 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
971 if (mpath->flags & MESH_PATH_RESOLVING)
972 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
973
974 pinfo->flags = mpath->flags;
975}
976
977static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
978 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
979
980{
Johannes Berg14db74b2008-07-29 13:22:52 +0200981 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100982 struct mesh_path *mpath;
983
Johannes Berg14db74b2008-07-29 13:22:52 +0200984 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
985
Johannes Berg05c914f2008-09-11 00:01:58 +0200986 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100987 return -ENOTSUPP;
988
989 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200990 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100991 if (!mpath) {
992 rcu_read_unlock();
993 return -ENOENT;
994 }
995 memcpy(dst, mpath->dst, ETH_ALEN);
996 mpath_set_pinfo(mpath, next_hop, pinfo);
997 rcu_read_unlock();
998 return 0;
999}
1000
1001static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1002 int idx, u8 *dst, u8 *next_hop,
1003 struct mpath_info *pinfo)
1004{
Johannes Berg14db74b2008-07-29 13:22:52 +02001005 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001006 struct mesh_path *mpath;
1007
Johannes Berg14db74b2008-07-29 13:22:52 +02001008 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1009
Johannes Berg05c914f2008-09-11 00:01:58 +02001010 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001011 return -ENOTSUPP;
1012
1013 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001014 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001015 if (!mpath) {
1016 rcu_read_unlock();
1017 return -ENOENT;
1018 }
1019 memcpy(dst, mpath->dst, ETH_ALEN);
1020 mpath_set_pinfo(mpath, next_hop, pinfo);
1021 rcu_read_unlock();
1022 return 0;
1023}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001024
1025static int ieee80211_get_mesh_params(struct wiphy *wiphy,
1026 struct net_device *dev,
1027 struct mesh_config *conf)
1028{
1029 struct ieee80211_sub_if_data *sdata;
1030 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1031
1032 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1033 return -ENOTSUPP;
1034 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1035 return 0;
1036}
1037
1038static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1039{
1040 return (mask >> (parm-1)) & 0x1;
1041}
1042
1043static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1044 struct net_device *dev,
1045 const struct mesh_config *nconf, u32 mask)
1046{
1047 struct mesh_config *conf;
1048 struct ieee80211_sub_if_data *sdata;
1049 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1050
1051 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1052 return -ENOTSUPP;
1053
1054 /* Set the config options which we are interested in setting */
1055 conf = &(sdata->u.mesh.mshcfg);
1056 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1057 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1058 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1059 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1060 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1061 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1062 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1063 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1064 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1065 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1066 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1067 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1068 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1069 conf->auto_open_plinks = nconf->auto_open_plinks;
1070 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1071 conf->dot11MeshHWMPmaxPREQretries =
1072 nconf->dot11MeshHWMPmaxPREQretries;
1073 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1074 conf->path_refresh_time = nconf->path_refresh_time;
1075 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1076 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1077 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1078 conf->dot11MeshHWMPactivePathTimeout =
1079 nconf->dot11MeshHWMPactivePathTimeout;
1080 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1081 conf->dot11MeshHWMPpreqMinInterval =
1082 nconf->dot11MeshHWMPpreqMinInterval;
1083 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1084 mask))
1085 conf->dot11MeshHWMPnetDiameterTraversalTime =
1086 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1087 return 0;
1088}
1089
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001090#endif
1091
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001092static int ieee80211_change_bss(struct wiphy *wiphy,
1093 struct net_device *dev,
1094 struct bss_parameters *params)
1095{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001096 struct ieee80211_sub_if_data *sdata;
1097 u32 changed = 0;
1098
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001099 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1100
Johannes Berg05c914f2008-09-11 00:01:58 +02001101 if (sdata->vif.type != NL80211_IFTYPE_AP)
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001102 return -EINVAL;
1103
1104 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001105 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001106 changed |= BSS_CHANGED_ERP_CTS_PROT;
1107 }
1108 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001109 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001110 params->use_short_preamble;
1111 changed |= BSS_CHANGED_ERP_PREAMBLE;
1112 }
1113 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001114 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001115 params->use_short_slot_time;
1116 changed |= BSS_CHANGED_ERP_SLOT;
1117 }
1118
Jouni Malinen90c97a02008-10-30 16:59:22 +02001119 if (params->basic_rates) {
1120 int i, j;
1121 u32 rates = 0;
1122 struct ieee80211_local *local = wiphy_priv(wiphy);
1123 struct ieee80211_supported_band *sband =
1124 wiphy->bands[local->oper_channel->band];
1125
1126 for (i = 0; i < params->basic_rates_len; i++) {
1127 int rate = (params->basic_rates[i] & 0x7f) * 5;
1128 for (j = 0; j < sband->n_bitrates; j++) {
1129 if (sband->bitrates[j].bitrate == rate)
1130 rates |= BIT(j);
1131 }
1132 }
1133 sdata->vif.bss_conf.basic_rates = rates;
1134 changed |= BSS_CHANGED_BASIC_RATES;
1135 }
1136
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001137 ieee80211_bss_info_change_notify(sdata, changed);
1138
1139 return 0;
1140}
1141
Jouni Malinen31888482008-10-30 16:59:24 +02001142static int ieee80211_set_txq_params(struct wiphy *wiphy,
1143 struct ieee80211_txq_params *params)
1144{
1145 struct ieee80211_local *local = wiphy_priv(wiphy);
1146 struct ieee80211_tx_queue_params p;
1147
1148 if (!local->ops->conf_tx)
1149 return -EOPNOTSUPP;
1150
1151 memset(&p, 0, sizeof(p));
1152 p.aifs = params->aifs;
1153 p.cw_max = params->cwmax;
1154 p.cw_min = params->cwmin;
1155 p.txop = params->txop;
1156 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1157 printk(KERN_DEBUG "%s: failed to set TX queue "
1158 "parameters for queue %d\n", local->mdev->name,
1159 params->queue);
1160 return -EINVAL;
1161 }
1162
1163 return 0;
1164}
1165
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001166static int ieee80211_set_channel(struct wiphy *wiphy,
1167 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301168 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001169{
1170 struct ieee80211_local *local = wiphy_priv(wiphy);
1171
1172 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +05301173 local->oper_channel_type = channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001174
1175 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1176}
1177
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001178static int set_mgmt_extra_ie_sta(struct ieee80211_if_sta *ifsta, u8 subtype,
1179 u8 *ies, size_t ies_len)
1180{
1181 switch (subtype) {
1182 case IEEE80211_STYPE_PROBE_REQ >> 4:
1183 kfree(ifsta->ie_probereq);
1184 ifsta->ie_probereq = ies;
1185 ifsta->ie_probereq_len = ies_len;
1186 return 0;
1187 case IEEE80211_STYPE_PROBE_RESP >> 4:
1188 kfree(ifsta->ie_proberesp);
1189 ifsta->ie_proberesp = ies;
1190 ifsta->ie_proberesp_len = ies_len;
1191 return 0;
1192 case IEEE80211_STYPE_AUTH >> 4:
1193 kfree(ifsta->ie_auth);
1194 ifsta->ie_auth = ies;
1195 ifsta->ie_auth_len = ies_len;
1196 return 0;
1197 case IEEE80211_STYPE_ASSOC_REQ >> 4:
1198 kfree(ifsta->ie_assocreq);
1199 ifsta->ie_assocreq = ies;
1200 ifsta->ie_assocreq_len = ies_len;
1201 return 0;
1202 case IEEE80211_STYPE_REASSOC_REQ >> 4:
1203 kfree(ifsta->ie_reassocreq);
1204 ifsta->ie_reassocreq = ies;
1205 ifsta->ie_reassocreq_len = ies_len;
1206 return 0;
1207 case IEEE80211_STYPE_DEAUTH >> 4:
1208 kfree(ifsta->ie_deauth);
1209 ifsta->ie_deauth = ies;
1210 ifsta->ie_deauth_len = ies_len;
1211 return 0;
1212 case IEEE80211_STYPE_DISASSOC >> 4:
1213 kfree(ifsta->ie_disassoc);
1214 ifsta->ie_disassoc = ies;
1215 ifsta->ie_disassoc_len = ies_len;
1216 return 0;
1217 }
1218
1219 return -EOPNOTSUPP;
1220}
1221
1222static int ieee80211_set_mgmt_extra_ie(struct wiphy *wiphy,
1223 struct net_device *dev,
1224 struct mgmt_extra_ie_params *params)
1225{
1226 struct ieee80211_sub_if_data *sdata;
1227 u8 *ies;
1228 size_t ies_len;
1229 int ret = -EOPNOTSUPP;
1230
1231 if (params->ies) {
1232 ies = kmemdup(params->ies, params->ies_len, GFP_KERNEL);
1233 if (ies == NULL)
1234 return -ENOMEM;
1235 ies_len = params->ies_len;
1236 } else {
1237 ies = NULL;
1238 ies_len = 0;
1239 }
1240
1241 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1242
1243 switch (sdata->vif.type) {
1244 case NL80211_IFTYPE_STATION:
1245 case NL80211_IFTYPE_ADHOC:
1246 ret = set_mgmt_extra_ie_sta(&sdata->u.sta, params->subtype,
1247 ies, ies_len);
1248 break;
1249 default:
1250 ret = -EOPNOTSUPP;
1251 break;
1252 }
1253
1254 if (ret)
1255 kfree(ies);
1256 return ret;
1257}
1258
Bob Copeland665af4f2009-01-19 11:20:53 -05001259#ifdef CONFIG_PM
1260static int ieee80211_suspend(struct wiphy *wiphy)
1261{
1262 return __ieee80211_suspend(wiphy_priv(wiphy));
1263}
1264
1265static int ieee80211_resume(struct wiphy *wiphy)
1266{
1267 return __ieee80211_resume(wiphy_priv(wiphy));
1268}
1269#else
1270#define ieee80211_suspend NULL
1271#define ieee80211_resume NULL
1272#endif
1273
Jiri Bencf0706e82007-05-05 11:45:53 -07001274struct cfg80211_ops mac80211_config_ops = {
1275 .add_virtual_intf = ieee80211_add_iface,
1276 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001277 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001278 .add_key = ieee80211_add_key,
1279 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001280 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001281 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001282 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001283 .add_beacon = ieee80211_add_beacon,
1284 .set_beacon = ieee80211_set_beacon,
1285 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001286 .add_station = ieee80211_add_station,
1287 .del_station = ieee80211_del_station,
1288 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001289 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001290 .dump_station = ieee80211_dump_station,
1291#ifdef CONFIG_MAC80211_MESH
1292 .add_mpath = ieee80211_add_mpath,
1293 .del_mpath = ieee80211_del_mpath,
1294 .change_mpath = ieee80211_change_mpath,
1295 .get_mpath = ieee80211_get_mpath,
1296 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001297 .set_mesh_params = ieee80211_set_mesh_params,
1298 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001299#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001300 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001301 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001302 .set_channel = ieee80211_set_channel,
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001303 .set_mgmt_extra_ie = ieee80211_set_mgmt_extra_ie,
Bob Copeland665af4f2009-01-19 11:20:53 -05001304 .suspend = ieee80211_suspend,
1305 .resume = ieee80211_resume,
Jiri Bencf0706e82007-05-05 11:45:53 -07001306};