blob: e677b751d46857db80d163aa58bdbff04a116348 [file] [log] [blame]
Jiri Bencf0706e822007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Johannes Berg62da92f2007-12-19 02:03:31 +01004 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e822007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070012#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010013#include <linux/rcupdate.h>
Jiri Bencf0706e822007-05-05 11:45:53 -070014#include <net/cfg80211.h>
15#include "ieee80211_i.h"
Michael Wue0eb6852007-09-18 17:29:21 -040016#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040017#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010018#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010019
Johannes Berg05c914f2008-09-11 00:01:58 +020020static bool nl80211_type_check(enum nl80211_iftype type)
Johannes Berg42613db2007-09-28 21:52:27 +020021{
22 switch (type) {
Johannes Berg42613db2007-09-28 21:52:27 +020023 case NL80211_IFTYPE_ADHOC:
Johannes Berg42613db2007-09-28 21:52:27 +020024 case NL80211_IFTYPE_STATION:
Johannes Berg42613db2007-09-28 21:52:27 +020025 case NL80211_IFTYPE_MONITOR:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010026#ifdef CONFIG_MAC80211_MESH
27 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010028#endif
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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070046
Johannes Berg05c914f2008-09-11 00:01:58 +020047 if (!nl80211_type_check(type))
Jiri Bencf0706e822007-05-05 11:45:53 -070048 return -EINVAL;
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070057}
58
59static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
60{
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070066 if (!dev)
Johannes Berg75636522008-07-09 14:40:35 +020067 return -ENODEV;
Jiri Bencf0706e822007-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 Bencf0706e822007-05-05 11:45:53 -070072
Johannes Berg75636522008-07-09 14:40:35 +020073 return 0;
Jiri Bencf0706e822007-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 Malinen3cfcf6a2009-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 Malinen3cfcf6a2009-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 Malinen3cfcf6a2009-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 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200344 STATION_INFO_RX_PACKETS |
345 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100346 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100347
348 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
349 sinfo->rx_bytes = sta->rx_bytes;
350 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200351 sinfo->rx_packets = sta->rx_packets;
352 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100353
Henning Rogge420e7fa2008-12-11 22:04:19 +0100354 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
355 sinfo->filled |= STATION_INFO_SIGNAL;
356 sinfo->signal = (s8)sta->last_signal;
357 }
358
359 sinfo->txrate.flags = 0;
360 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
361 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
362 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
363 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
364 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
365 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
366
367 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
368 struct ieee80211_supported_band *sband;
369 sband = sta->local->hw.wiphy->bands[
370 sta->local->hw.conf.channel->band];
371 sinfo->txrate.legacy =
372 sband->bitrates[sta->last_tx_rate.idx].bitrate;
373 } else
374 sinfo->txrate.mcs = sta->last_tx_rate.idx;
375
Johannes Berg902acc72008-02-23 15:17:19 +0100376 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100377#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100378 sinfo->filled |= STATION_INFO_LLID |
379 STATION_INFO_PLID |
380 STATION_INFO_PLINK_STATE;
381
382 sinfo->llid = le16_to_cpu(sta->llid);
383 sinfo->plid = le16_to_cpu(sta->plid);
384 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100385#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100386 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100387}
388
389
390static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
391 int idx, u8 *mac, struct station_info *sinfo)
392{
393 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
394 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100395 int ret = -ENOENT;
396
397 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100398
399 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100400 if (sta) {
401 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200402 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100403 sta_set_sinfo(sta, sinfo);
404 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100405
Johannes Bergd0709a62008-02-25 16:27:46 +0100406 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100407
Johannes Bergd0709a62008-02-25 16:27:46 +0100408 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100409}
410
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100411static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100412 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100413{
414 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
415 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100416 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100417
Johannes Bergd0709a62008-02-25 16:27:46 +0100418 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100419
420 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100421
Johannes Bergd0709a62008-02-25 16:27:46 +0100422 sta = sta_info_get(local, mac);
423 if (sta) {
424 ret = 0;
425 sta_set_sinfo(sta, sinfo);
426 }
427
428 rcu_read_unlock();
429
430 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100431}
432
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100433/*
434 * This handles both adding a beacon and setting new beacon info
435 */
436static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
437 struct beacon_parameters *params)
438{
439 struct beacon_data *new, *old;
440 int new_head_len, new_tail_len;
441 int size;
442 int err = -EINVAL;
443
444 old = sdata->u.ap.beacon;
445
446 /* head must not be zero-length */
447 if (params->head && !params->head_len)
448 return -EINVAL;
449
450 /*
451 * This is a kludge. beacon interval should really be part
452 * of the beacon information.
453 */
Sujithe31ae052009-02-27 09:44:00 +0530454 if (params->interval && (sdata->local->hw.conf.beacon_int !=
455 params->interval)) {
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100456 sdata->local->hw.conf.beacon_int = params->interval;
Reinette Chatre447107f2008-12-04 14:49:08 -0800457 err = ieee80211_hw_config(sdata->local,
458 IEEE80211_CONF_CHANGE_BEACON_INTERVAL);
459 if (err < 0)
460 return err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100461 /*
462 * We updated some parameter so if below bails out
463 * it's not an error.
464 */
465 err = 0;
466 }
467
468 /* Need to have a beacon head if we don't have one yet */
469 if (!params->head && !old)
470 return err;
471
472 /* sorry, no way to start beaconing without dtim period */
473 if (!params->dtim_period && !old)
474 return err;
475
476 /* new or old head? */
477 if (params->head)
478 new_head_len = params->head_len;
479 else
480 new_head_len = old->head_len;
481
482 /* new or old tail? */
483 if (params->tail || !old)
484 /* params->tail_len will be zero for !params->tail */
485 new_tail_len = params->tail_len;
486 else
487 new_tail_len = old->tail_len;
488
489 size = sizeof(*new) + new_head_len + new_tail_len;
490
491 new = kzalloc(size, GFP_KERNEL);
492 if (!new)
493 return -ENOMEM;
494
495 /* start filling the new info now */
496
497 /* new or old dtim period? */
498 if (params->dtim_period)
499 new->dtim_period = params->dtim_period;
500 else
501 new->dtim_period = old->dtim_period;
502
503 /*
504 * pointers go into the block we allocated,
505 * memory is | beacon_data | head | tail |
506 */
507 new->head = ((u8 *) new) + sizeof(*new);
508 new->tail = new->head + new_head_len;
509 new->head_len = new_head_len;
510 new->tail_len = new_tail_len;
511
512 /* copy in head */
513 if (params->head)
514 memcpy(new->head, params->head, new_head_len);
515 else
516 memcpy(new->head, old->head, new_head_len);
517
518 /* copy in optional tail */
519 if (params->tail)
520 memcpy(new->tail, params->tail, new_tail_len);
521 else
522 if (old)
523 memcpy(new->tail, old->tail, new_tail_len);
524
525 rcu_assign_pointer(sdata->u.ap.beacon, new);
526
527 synchronize_rcu();
528
529 kfree(old);
530
Johannes Berg078e1e62009-01-22 18:07:31 +0100531 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
532 IEEE80211_IFCC_BEACON_ENABLED);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100533}
534
535static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
536 struct beacon_parameters *params)
537{
Johannes Berg14db74b2008-07-29 13:22:52 +0200538 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100539 struct beacon_data *old;
540
Johannes Berg14db74b2008-07-29 13:22:52 +0200541 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
542
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100543 old = sdata->u.ap.beacon;
544
545 if (old)
546 return -EALREADY;
547
548 return ieee80211_config_beacon(sdata, params);
549}
550
551static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
552 struct beacon_parameters *params)
553{
Johannes Berg14db74b2008-07-29 13:22:52 +0200554 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100555 struct beacon_data *old;
556
Johannes Berg14db74b2008-07-29 13:22:52 +0200557 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
558
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100559 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 Berg5dfdaf52007-12-19 02:03:33 +0100574 old = sdata->u.ap.beacon;
575
576 if (!old)
577 return -ENOENT;
578
579 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
580 synchronize_rcu();
581 kfree(old);
582
Johannes Berg078e1e62009-01-22 18:07:31 +0100583 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100584}
585
Johannes Berg4fd69312007-12-19 02:03:35 +0100586/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
587struct iapp_layer2_update {
588 u8 da[ETH_ALEN]; /* broadcast */
589 u8 sa[ETH_ALEN]; /* STA addr */
590 __be16 len; /* 6 */
591 u8 dsap; /* 0 */
592 u8 ssap; /* 0 */
593 u8 control;
594 u8 xid_info[3];
595} __attribute__ ((packed));
596
597static void ieee80211_send_layer2_update(struct sta_info *sta)
598{
599 struct iapp_layer2_update *msg;
600 struct sk_buff *skb;
601
602 /* Send Level 2 Update Frame to update forwarding tables in layer 2
603 * bridge devices */
604
605 skb = dev_alloc_skb(sizeof(*msg));
606 if (!skb)
607 return;
608 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
609
610 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
611 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
612
613 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200614 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100615 msg->len = htons(6);
616 msg->dsap = 0;
617 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
618 msg->control = 0xaf; /* XID response lsb.1111F101.
619 * F=0 (no poll command; unsolicited frame) */
620 msg->xid_info[0] = 0x81; /* XID format identifier */
621 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
622 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
623
Johannes Bergd0709a62008-02-25 16:27:46 +0100624 skb->dev = sta->sdata->dev;
625 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100626 memset(skb->cb, 0, sizeof(skb->cb));
627 netif_rx(skb);
628}
629
630static void sta_apply_parameters(struct ieee80211_local *local,
631 struct sta_info *sta,
632 struct station_parameters *params)
633{
634 u32 rates;
635 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100636 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100637 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100638
Johannes Bergae5eb022008-10-14 16:58:37 +0200639 sband = local->hw.wiphy->bands[local->oper_channel->band];
640
Johannes Berg73651ee2008-02-25 16:27:47 +0100641 /*
642 * FIXME: updating the flags is racy when this function is
643 * called from ieee80211_change_station(), this will
644 * be resolved in a future patch.
645 */
646
Johannes Berg4fd69312007-12-19 02:03:35 +0100647 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200648 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100649 sta->flags &= ~WLAN_STA_AUTHORIZED;
650 if (params->station_flags & STATION_FLAG_AUTHORIZED)
651 sta->flags |= WLAN_STA_AUTHORIZED;
652
653 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
654 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
655 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
656
657 sta->flags &= ~WLAN_STA_WME;
658 if (params->station_flags & STATION_FLAG_WME)
659 sta->flags |= WLAN_STA_WME;
Jouni Malinen5394af42009-01-08 13:31:59 +0200660
661 sta->flags &= ~WLAN_STA_MFP;
662 if (params->station_flags & STATION_FLAG_MFP)
663 sta->flags |= WLAN_STA_MFP;
Johannes Berg07346f812008-05-03 01:02:02 +0200664 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100665 }
666
Johannes Berg73651ee2008-02-25 16:27:47 +0100667 /*
668 * FIXME: updating the following information is racy when this
669 * function is called from ieee80211_change_station().
670 * However, all this information should be static so
671 * maybe we should just reject attemps to change it.
672 */
673
Johannes Berg4fd69312007-12-19 02:03:35 +0100674 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200675 sta->sta.aid = params->aid;
676 if (sta->sta.aid > IEEE80211_MAX_AID)
677 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100678 }
679
680 if (params->listen_interval >= 0)
681 sta->listen_interval = params->listen_interval;
682
683 if (params->supported_rates) {
684 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100685
Johannes Berg4fd69312007-12-19 02:03:35 +0100686 for (i = 0; i < params->supported_rates_len; i++) {
687 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100688 for (j = 0; j < sband->n_bitrates; j++) {
689 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100690 rates |= BIT(j);
691 }
692 }
Johannes Berg323ce792008-09-11 02:45:11 +0200693 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100694 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100695
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200696 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200697 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
698 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200699 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300700
Johannes Berg902acc72008-02-23 15:17:19 +0100701 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100702 switch (params->plink_action) {
703 case PLINK_ACTION_OPEN:
704 mesh_plink_open(sta);
705 break;
706 case PLINK_ACTION_BLOCK:
707 mesh_plink_block(sta);
708 break;
709 }
Johannes Berg902acc72008-02-23 15:17:19 +0100710 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100711}
712
713static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
714 u8 *mac, struct station_parameters *params)
715{
Johannes Berg14db74b2008-07-29 13:22:52 +0200716 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100717 struct sta_info *sta;
718 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100719 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200720 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100721
Johannes Berg4fd69312007-12-19 02:03:35 +0100722 if (params->vlan) {
723 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
724
Johannes Berg05c914f2008-09-11 00:01:58 +0200725 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
726 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100727 return -EINVAL;
728 } else
729 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
730
Johannes Berg03e44972008-02-27 09:56:40 +0100731 if (compare_ether_addr(mac, dev->dev_addr) == 0)
732 return -EINVAL;
733
734 if (is_multicast_ether_addr(mac))
735 return -EINVAL;
736
737 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100738 if (!sta)
739 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100740
741 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
742
743 sta_apply_parameters(local, sta, params);
744
Johannes Berg4b7679a2008-09-18 18:14:18 +0200745 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100746
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200747 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
748 sdata->vif.type == NL80211_IFTYPE_AP;
749
Johannes Berg73651ee2008-02-25 16:27:47 +0100750 rcu_read_lock();
751
752 err = sta_info_insert(sta);
753 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200754 /* STA has been freed */
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200755 if (err == -EEXIST && layer2_update) {
756 /* Need to update layer 2 devices on reassociation */
757 sta = sta_info_get(local, mac);
758 if (sta)
759 ieee80211_send_layer2_update(sta);
760 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100761 rcu_read_unlock();
762 return err;
763 }
764
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200765 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100766 ieee80211_send_layer2_update(sta);
767
768 rcu_read_unlock();
769
Johannes Berg4fd69312007-12-19 02:03:35 +0100770 return 0;
771}
772
773static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
774 u8 *mac)
775{
Johannes Berg14db74b2008-07-29 13:22:52 +0200776 struct ieee80211_local *local = wiphy_priv(wiphy);
777 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100778 struct sta_info *sta;
779
Johannes Berg14db74b2008-07-29 13:22:52 +0200780 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
781
Johannes Berg4fd69312007-12-19 02:03:35 +0100782 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200783 rcu_read_lock();
784
Johannes Berg4fd69312007-12-19 02:03:35 +0100785 /* XXX: get sta belonging to dev */
786 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200787 if (!sta) {
788 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100789 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200790 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100791
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200793 rcu_read_unlock();
794
Johannes Berg4f6fab42008-03-31 19:23:02 +0200795 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100796 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100797 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100798
799 return 0;
800}
801
802static int ieee80211_change_station(struct wiphy *wiphy,
803 struct net_device *dev,
804 u8 *mac,
805 struct station_parameters *params)
806{
Johannes Berg14db74b2008-07-29 13:22:52 +0200807 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100808 struct sta_info *sta;
809 struct ieee80211_sub_if_data *vlansdata;
810
Johannes Berg98dd6a52008-04-10 15:36:09 +0200811 rcu_read_lock();
812
Johannes Berg4fd69312007-12-19 02:03:35 +0100813 /* XXX: get sta belonging to dev */
814 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200815 if (!sta) {
816 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100817 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200818 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100819
Johannes Bergd0709a62008-02-25 16:27:46 +0100820 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100821 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
822
Johannes Berg05c914f2008-09-11 00:01:58 +0200823 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
824 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200825 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100826 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200827 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100828
Johannes Berg14db74b2008-07-29 13:22:52 +0200829 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100830 ieee80211_send_layer2_update(sta);
831 }
832
833 sta_apply_parameters(local, sta, params);
834
Johannes Berg98dd6a52008-04-10 15:36:09 +0200835 rcu_read_unlock();
836
Johannes Berg4fd69312007-12-19 02:03:35 +0100837 return 0;
838}
839
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100840#ifdef CONFIG_MAC80211_MESH
841static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
842 u8 *dst, u8 *next_hop)
843{
Johannes Berg14db74b2008-07-29 13:22:52 +0200844 struct ieee80211_local *local = wiphy_priv(wiphy);
845 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100846 struct mesh_path *mpath;
847 struct sta_info *sta;
848 int err;
849
Johannes Berg14db74b2008-07-29 13:22:52 +0200850 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
851
Johannes Bergd0709a62008-02-25 16:27:46 +0100852 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100854 if (!sta) {
855 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100856 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100857 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200859 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100860 if (err) {
861 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100862 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100863 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100864
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200865 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100866 if (!mpath) {
867 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100868 return -ENXIO;
869 }
870 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100871
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100872 rcu_read_unlock();
873 return 0;
874}
875
876static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
877 u8 *dst)
878{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200879 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100880
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200881 if (dst)
882 return mesh_path_del(dst, sdata);
883
884 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100885 return 0;
886}
887
888static int ieee80211_change_mpath(struct wiphy *wiphy,
889 struct net_device *dev,
890 u8 *dst, u8 *next_hop)
891{
Johannes Berg14db74b2008-07-29 13:22:52 +0200892 struct ieee80211_local *local = wiphy_priv(wiphy);
893 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100894 struct mesh_path *mpath;
895 struct sta_info *sta;
896
Johannes Berg14db74b2008-07-29 13:22:52 +0200897 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
898
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100899 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100900
901 sta = sta_info_get(local, next_hop);
902 if (!sta) {
903 rcu_read_unlock();
904 return -ENOENT;
905 }
906
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200907 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100908 if (!mpath) {
909 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100910 return -ENOENT;
911 }
912
913 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100914
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100915 rcu_read_unlock();
916 return 0;
917}
918
919static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
920 struct mpath_info *pinfo)
921{
922 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200923 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100924 else
925 memset(next_hop, 0, ETH_ALEN);
926
927 pinfo->filled = MPATH_INFO_FRAME_QLEN |
928 MPATH_INFO_DSN |
929 MPATH_INFO_METRIC |
930 MPATH_INFO_EXPTIME |
931 MPATH_INFO_DISCOVERY_TIMEOUT |
932 MPATH_INFO_DISCOVERY_RETRIES |
933 MPATH_INFO_FLAGS;
934
935 pinfo->frame_qlen = mpath->frame_queue.qlen;
936 pinfo->dsn = mpath->dsn;
937 pinfo->metric = mpath->metric;
938 if (time_before(jiffies, mpath->exp_time))
939 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
940 pinfo->discovery_timeout =
941 jiffies_to_msecs(mpath->discovery_timeout);
942 pinfo->discovery_retries = mpath->discovery_retries;
943 pinfo->flags = 0;
944 if (mpath->flags & MESH_PATH_ACTIVE)
945 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
946 if (mpath->flags & MESH_PATH_RESOLVING)
947 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
948 if (mpath->flags & MESH_PATH_DSN_VALID)
949 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
950 if (mpath->flags & MESH_PATH_FIXED)
951 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
952 if (mpath->flags & MESH_PATH_RESOLVING)
953 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
954
955 pinfo->flags = mpath->flags;
956}
957
958static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
959 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
960
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
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100967 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200968 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100969 if (!mpath) {
970 rcu_read_unlock();
971 return -ENOENT;
972 }
973 memcpy(dst, mpath->dst, ETH_ALEN);
974 mpath_set_pinfo(mpath, next_hop, pinfo);
975 rcu_read_unlock();
976 return 0;
977}
978
979static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
980 int idx, u8 *dst, u8 *next_hop,
981 struct mpath_info *pinfo)
982{
Johannes Berg14db74b2008-07-29 13:22:52 +0200983 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100984 struct mesh_path *mpath;
985
Johannes Berg14db74b2008-07-29 13:22:52 +0200986 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
987
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100988 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200989 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100990 if (!mpath) {
991 rcu_read_unlock();
992 return -ENOENT;
993 }
994 memcpy(dst, mpath->dst, ETH_ALEN);
995 mpath_set_pinfo(mpath, next_hop, pinfo);
996 rcu_read_unlock();
997 return 0;
998}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700999
1000static int ieee80211_get_mesh_params(struct wiphy *wiphy,
1001 struct net_device *dev,
1002 struct mesh_config *conf)
1003{
1004 struct ieee80211_sub_if_data *sdata;
1005 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1006
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001007 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1008 return 0;
1009}
1010
1011static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1012{
1013 return (mask >> (parm-1)) & 0x1;
1014}
1015
1016static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1017 struct net_device *dev,
1018 const struct mesh_config *nconf, u32 mask)
1019{
1020 struct mesh_config *conf;
1021 struct ieee80211_sub_if_data *sdata;
1022 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1023
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001024 /* Set the config options which we are interested in setting */
1025 conf = &(sdata->u.mesh.mshcfg);
1026 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1027 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1029 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1031 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1033 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1034 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1035 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1036 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1037 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1039 conf->auto_open_plinks = nconf->auto_open_plinks;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1041 conf->dot11MeshHWMPmaxPREQretries =
1042 nconf->dot11MeshHWMPmaxPREQretries;
1043 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1044 conf->path_refresh_time = nconf->path_refresh_time;
1045 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1046 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1047 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1048 conf->dot11MeshHWMPactivePathTimeout =
1049 nconf->dot11MeshHWMPactivePathTimeout;
1050 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1051 conf->dot11MeshHWMPpreqMinInterval =
1052 nconf->dot11MeshHWMPpreqMinInterval;
1053 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1054 mask))
1055 conf->dot11MeshHWMPnetDiameterTraversalTime =
1056 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1057 return 0;
1058}
1059
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001060#endif
1061
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001062static int ieee80211_change_bss(struct wiphy *wiphy,
1063 struct net_device *dev,
1064 struct bss_parameters *params)
1065{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001066 struct ieee80211_sub_if_data *sdata;
1067 u32 changed = 0;
1068
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001069 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1070
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001071 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001072 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001073 changed |= BSS_CHANGED_ERP_CTS_PROT;
1074 }
1075 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001076 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001077 params->use_short_preamble;
1078 changed |= BSS_CHANGED_ERP_PREAMBLE;
1079 }
1080 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001081 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001082 params->use_short_slot_time;
1083 changed |= BSS_CHANGED_ERP_SLOT;
1084 }
1085
Jouni Malinen90c97a02008-10-30 16:59:22 +02001086 if (params->basic_rates) {
1087 int i, j;
1088 u32 rates = 0;
1089 struct ieee80211_local *local = wiphy_priv(wiphy);
1090 struct ieee80211_supported_band *sband =
1091 wiphy->bands[local->oper_channel->band];
1092
1093 for (i = 0; i < params->basic_rates_len; i++) {
1094 int rate = (params->basic_rates[i] & 0x7f) * 5;
1095 for (j = 0; j < sband->n_bitrates; j++) {
1096 if (sband->bitrates[j].bitrate == rate)
1097 rates |= BIT(j);
1098 }
1099 }
1100 sdata->vif.bss_conf.basic_rates = rates;
1101 changed |= BSS_CHANGED_BASIC_RATES;
1102 }
1103
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001104 ieee80211_bss_info_change_notify(sdata, changed);
1105
1106 return 0;
1107}
1108
Jouni Malinen31888482008-10-30 16:59:24 +02001109static int ieee80211_set_txq_params(struct wiphy *wiphy,
1110 struct ieee80211_txq_params *params)
1111{
1112 struct ieee80211_local *local = wiphy_priv(wiphy);
1113 struct ieee80211_tx_queue_params p;
1114
1115 if (!local->ops->conf_tx)
1116 return -EOPNOTSUPP;
1117
1118 memset(&p, 0, sizeof(p));
1119 p.aifs = params->aifs;
1120 p.cw_max = params->cwmax;
1121 p.cw_min = params->cwmin;
1122 p.txop = params->txop;
1123 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1124 printk(KERN_DEBUG "%s: failed to set TX queue "
1125 "parameters for queue %d\n", local->mdev->name,
1126 params->queue);
1127 return -EINVAL;
1128 }
1129
1130 return 0;
1131}
1132
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001133static int ieee80211_set_channel(struct wiphy *wiphy,
1134 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301135 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001136{
1137 struct ieee80211_local *local = wiphy_priv(wiphy);
1138
1139 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +05301140 local->oper_channel_type = channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001141
1142 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1143}
1144
Bob Copeland665af4f2009-01-19 11:20:53 -05001145#ifdef CONFIG_PM
1146static int ieee80211_suspend(struct wiphy *wiphy)
1147{
1148 return __ieee80211_suspend(wiphy_priv(wiphy));
1149}
1150
1151static int ieee80211_resume(struct wiphy *wiphy)
1152{
1153 return __ieee80211_resume(wiphy_priv(wiphy));
1154}
1155#else
1156#define ieee80211_suspend NULL
1157#define ieee80211_resume NULL
1158#endif
1159
Johannes Berg2a519312009-02-10 21:25:55 +01001160static int ieee80211_scan(struct wiphy *wiphy,
1161 struct net_device *dev,
1162 struct cfg80211_scan_request *req)
1163{
1164 struct ieee80211_sub_if_data *sdata;
1165
Johannes Berg2a519312009-02-10 21:25:55 +01001166 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1167
1168 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1169 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1171 return -EOPNOTSUPP;
1172
1173 return ieee80211_request_scan(sdata, req);
1174}
1175
Jouni Malinen636a5d32009-03-19 13:39:22 +02001176static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1177 struct cfg80211_auth_request *req)
1178{
1179 struct ieee80211_sub_if_data *sdata;
1180
Jouni Malinen636a5d32009-03-19 13:39:22 +02001181 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1182
Jouni Malinen636a5d32009-03-19 13:39:22 +02001183 switch (req->auth_type) {
1184 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1185 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
1186 break;
1187 case NL80211_AUTHTYPE_SHARED_KEY:
1188 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
1189 break;
1190 case NL80211_AUTHTYPE_FT:
1191 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
1192 break;
1193 case NL80211_AUTHTYPE_NETWORK_EAP:
1194 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
1195 break;
1196 default:
1197 return -EOPNOTSUPP;
1198 }
1199
1200 memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
1201 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1202 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1203
1204 /* TODO: req->chan */
1205 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1206
1207 if (req->ssid) {
1208 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1209 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1210 sdata->u.mgd.ssid_len = req->ssid_len;
1211 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1212 }
1213
1214 kfree(sdata->u.mgd.sme_auth_ie);
1215 sdata->u.mgd.sme_auth_ie = NULL;
1216 sdata->u.mgd.sme_auth_ie_len = 0;
1217 if (req->ie) {
1218 sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
1219 if (sdata->u.mgd.sme_auth_ie == NULL)
1220 return -ENOMEM;
1221 memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
1222 sdata->u.mgd.sme_auth_ie_len = req->ie_len;
1223 }
1224
1225 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1226 sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
1227 ieee80211_sta_req_auth(sdata);
1228 return 0;
1229}
1230
1231static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1232 struct cfg80211_assoc_request *req)
1233{
1234 struct ieee80211_sub_if_data *sdata;
1235 int ret;
1236
Jouni Malinen636a5d32009-03-19 13:39:22 +02001237 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1238
Jouni Malinen636a5d32009-03-19 13:39:22 +02001239 if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
1240 !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
1241 return -ENOLINK; /* not authenticated */
1242
1243 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1244 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1245
1246 /* TODO: req->chan */
1247 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1248
1249 if (req->ssid) {
1250 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1251 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1252 sdata->u.mgd.ssid_len = req->ssid_len;
1253 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1254 } else
1255 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1256
1257 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1258 if (ret)
1259 return ret;
1260
1261 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1262 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1263 ieee80211_sta_req_auth(sdata);
1264 return 0;
1265}
1266
1267static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1268 struct cfg80211_deauth_request *req)
1269{
1270 struct ieee80211_sub_if_data *sdata;
1271
Jouni Malinen636a5d32009-03-19 13:39:22 +02001272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001273
1274 /* TODO: req->ie */
1275 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1276}
1277
1278static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1279 struct cfg80211_disassoc_request *req)
1280{
1281 struct ieee80211_sub_if_data *sdata;
1282
Jouni Malinen636a5d32009-03-19 13:39:22 +02001283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1284
Jouni Malinen636a5d32009-03-19 13:39:22 +02001285 /* TODO: req->ie */
1286 return ieee80211_sta_disassociate(sdata, req->reason_code);
1287}
1288
Jiri Bencf0706e822007-05-05 11:45:53 -07001289struct cfg80211_ops mac80211_config_ops = {
1290 .add_virtual_intf = ieee80211_add_iface,
1291 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001292 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001293 .add_key = ieee80211_add_key,
1294 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001295 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001296 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +02001297 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001298 .add_beacon = ieee80211_add_beacon,
1299 .set_beacon = ieee80211_set_beacon,
1300 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001301 .add_station = ieee80211_add_station,
1302 .del_station = ieee80211_del_station,
1303 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001304 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001305 .dump_station = ieee80211_dump_station,
1306#ifdef CONFIG_MAC80211_MESH
1307 .add_mpath = ieee80211_add_mpath,
1308 .del_mpath = ieee80211_del_mpath,
1309 .change_mpath = ieee80211_change_mpath,
1310 .get_mpath = ieee80211_get_mpath,
1311 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001312 .set_mesh_params = ieee80211_set_mesh_params,
1313 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001314#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001315 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001316 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001317 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001318 .suspend = ieee80211_suspend,
1319 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001320 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001321 .auth = ieee80211_auth,
1322 .assoc = ieee80211_assoc,
1323 .deauth = ieee80211_deauth,
1324 .disassoc = ieee80211_disassoc,
Jiri Bencf0706e822007-05-05 11:45:53 -07001325};