blob: 223e536e8426809a14df1af59e0be8330b46f2a1 [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 |
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 Berg05c914f2008-09-11 00:01:58 +0200543 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100544 return -EINVAL;
545
546 old = sdata->u.ap.beacon;
547
548 if (old)
549 return -EALREADY;
550
551 return ieee80211_config_beacon(sdata, params);
552}
553
554static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
555 struct beacon_parameters *params)
556{
Johannes Berg14db74b2008-07-29 13:22:52 +0200557 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100558 struct beacon_data *old;
559
Johannes Berg14db74b2008-07-29 13:22:52 +0200560 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
561
Johannes Berg05c914f2008-09-11 00:01:58 +0200562 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100563 return -EINVAL;
564
565 old = sdata->u.ap.beacon;
566
567 if (!old)
568 return -ENOENT;
569
570 return ieee80211_config_beacon(sdata, params);
571}
572
573static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
574{
Johannes Berg14db74b2008-07-29 13:22:52 +0200575 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100576 struct beacon_data *old;
577
Johannes Berg14db74b2008-07-29 13:22:52 +0200578 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
579
Johannes Berg05c914f2008-09-11 00:01:58 +0200580 if (sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100581 return -EINVAL;
582
583 old = sdata->u.ap.beacon;
584
585 if (!old)
586 return -ENOENT;
587
588 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
589 synchronize_rcu();
590 kfree(old);
591
Johannes Berg078e1e62009-01-22 18:07:31 +0100592 return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100593}
594
Johannes Berg4fd69312007-12-19 02:03:35 +0100595/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
596struct iapp_layer2_update {
597 u8 da[ETH_ALEN]; /* broadcast */
598 u8 sa[ETH_ALEN]; /* STA addr */
599 __be16 len; /* 6 */
600 u8 dsap; /* 0 */
601 u8 ssap; /* 0 */
602 u8 control;
603 u8 xid_info[3];
604} __attribute__ ((packed));
605
606static void ieee80211_send_layer2_update(struct sta_info *sta)
607{
608 struct iapp_layer2_update *msg;
609 struct sk_buff *skb;
610
611 /* Send Level 2 Update Frame to update forwarding tables in layer 2
612 * bridge devices */
613
614 skb = dev_alloc_skb(sizeof(*msg));
615 if (!skb)
616 return;
617 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
618
619 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
620 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
621
622 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200623 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100624 msg->len = htons(6);
625 msg->dsap = 0;
626 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
627 msg->control = 0xaf; /* XID response lsb.1111F101.
628 * F=0 (no poll command; unsolicited frame) */
629 msg->xid_info[0] = 0x81; /* XID format identifier */
630 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
631 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
632
Johannes Bergd0709a62008-02-25 16:27:46 +0100633 skb->dev = sta->sdata->dev;
634 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100635 memset(skb->cb, 0, sizeof(skb->cb));
636 netif_rx(skb);
637}
638
639static void sta_apply_parameters(struct ieee80211_local *local,
640 struct sta_info *sta,
641 struct station_parameters *params)
642{
643 u32 rates;
644 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100645 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100646 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100647
Johannes Bergae5eb022008-10-14 16:58:37 +0200648 sband = local->hw.wiphy->bands[local->oper_channel->band];
649
Johannes Berg73651ee2008-02-25 16:27:47 +0100650 /*
651 * FIXME: updating the flags is racy when this function is
652 * called from ieee80211_change_station(), this will
653 * be resolved in a future patch.
654 */
655
Johannes Berg4fd69312007-12-19 02:03:35 +0100656 if (params->station_flags & STATION_FLAG_CHANGED) {
Johannes Berg07346f812008-05-03 01:02:02 +0200657 spin_lock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100658 sta->flags &= ~WLAN_STA_AUTHORIZED;
659 if (params->station_flags & STATION_FLAG_AUTHORIZED)
660 sta->flags |= WLAN_STA_AUTHORIZED;
661
662 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
663 if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
664 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
665
666 sta->flags &= ~WLAN_STA_WME;
667 if (params->station_flags & STATION_FLAG_WME)
668 sta->flags |= WLAN_STA_WME;
Jouni Malinen5394af42009-01-08 13:31:59 +0200669
670 sta->flags &= ~WLAN_STA_MFP;
671 if (params->station_flags & STATION_FLAG_MFP)
672 sta->flags |= WLAN_STA_MFP;
Johannes Berg07346f812008-05-03 01:02:02 +0200673 spin_unlock_bh(&sta->lock);
Johannes Berg4fd69312007-12-19 02:03:35 +0100674 }
675
Johannes Berg73651ee2008-02-25 16:27:47 +0100676 /*
677 * FIXME: updating the following information is racy when this
678 * function is called from ieee80211_change_station().
679 * However, all this information should be static so
680 * maybe we should just reject attemps to change it.
681 */
682
Johannes Berg4fd69312007-12-19 02:03:35 +0100683 if (params->aid) {
Johannes Berg17741cd2008-09-11 00:02:02 +0200684 sta->sta.aid = params->aid;
685 if (sta->sta.aid > IEEE80211_MAX_AID)
686 sta->sta.aid = 0; /* XXX: should this be an error? */
Johannes Berg4fd69312007-12-19 02:03:35 +0100687 }
688
689 if (params->listen_interval >= 0)
690 sta->listen_interval = params->listen_interval;
691
692 if (params->supported_rates) {
693 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100694
Johannes Berg4fd69312007-12-19 02:03:35 +0100695 for (i = 0; i < params->supported_rates_len; i++) {
696 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100697 for (j = 0; j < sband->n_bitrates; j++) {
698 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100699 rates |= BIT(j);
700 }
701 }
Johannes Berg323ce792008-09-11 02:45:11 +0200702 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100703 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100704
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200705 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200706 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
707 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200708 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300709
Johannes Berg902acc72008-02-23 15:17:19 +0100710 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100711 switch (params->plink_action) {
712 case PLINK_ACTION_OPEN:
713 mesh_plink_open(sta);
714 break;
715 case PLINK_ACTION_BLOCK:
716 mesh_plink_block(sta);
717 break;
718 }
Johannes Berg902acc72008-02-23 15:17:19 +0100719 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100720}
721
722static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
723 u8 *mac, struct station_parameters *params)
724{
Johannes Berg14db74b2008-07-29 13:22:52 +0200725 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100726 struct sta_info *sta;
727 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100728 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200729 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100730
731 /* Prevent a race with changing the rate control algorithm */
732 if (!netif_running(dev))
733 return -ENETDOWN;
734
Johannes Berg4fd69312007-12-19 02:03:35 +0100735 if (params->vlan) {
736 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
737
Johannes Berg05c914f2008-09-11 00:01:58 +0200738 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
739 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100740 return -EINVAL;
741 } else
742 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
743
Johannes Berg03e44972008-02-27 09:56:40 +0100744 if (compare_ether_addr(mac, dev->dev_addr) == 0)
745 return -EINVAL;
746
747 if (is_multicast_ether_addr(mac))
748 return -EINVAL;
749
750 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100751 if (!sta)
752 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100753
754 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
755
756 sta_apply_parameters(local, sta, params);
757
Johannes Berg4b7679a2008-09-18 18:14:18 +0200758 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100759
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200760 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
761 sdata->vif.type == NL80211_IFTYPE_AP;
762
Johannes Berg73651ee2008-02-25 16:27:47 +0100763 rcu_read_lock();
764
765 err = sta_info_insert(sta);
766 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200767 /* STA has been freed */
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200768 if (err == -EEXIST && layer2_update) {
769 /* Need to update layer 2 devices on reassociation */
770 sta = sta_info_get(local, mac);
771 if (sta)
772 ieee80211_send_layer2_update(sta);
773 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100774 rcu_read_unlock();
775 return err;
776 }
777
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200778 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100779 ieee80211_send_layer2_update(sta);
780
781 rcu_read_unlock();
782
Johannes Berg4fd69312007-12-19 02:03:35 +0100783 return 0;
784}
785
786static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
787 u8 *mac)
788{
Johannes Berg14db74b2008-07-29 13:22:52 +0200789 struct ieee80211_local *local = wiphy_priv(wiphy);
790 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100791 struct sta_info *sta;
792
Johannes Berg14db74b2008-07-29 13:22:52 +0200793 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
794
Johannes Berg4fd69312007-12-19 02:03:35 +0100795 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200796 rcu_read_lock();
797
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 /* XXX: get sta belonging to dev */
799 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200800 if (!sta) {
801 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100802 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200803 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100804
Johannes Bergd0709a62008-02-25 16:27:46 +0100805 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200806 rcu_read_unlock();
807
Johannes Berg4f6fab42008-03-31 19:23:02 +0200808 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100809 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100810 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100811
812 return 0;
813}
814
815static int ieee80211_change_station(struct wiphy *wiphy,
816 struct net_device *dev,
817 u8 *mac,
818 struct station_parameters *params)
819{
Johannes Berg14db74b2008-07-29 13:22:52 +0200820 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100821 struct sta_info *sta;
822 struct ieee80211_sub_if_data *vlansdata;
823
Johannes Berg98dd6a52008-04-10 15:36:09 +0200824 rcu_read_lock();
825
Johannes Berg4fd69312007-12-19 02:03:35 +0100826 /* XXX: get sta belonging to dev */
827 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200828 if (!sta) {
829 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100830 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200831 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100832
Johannes Bergd0709a62008-02-25 16:27:46 +0100833 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100834 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
835
Johannes Berg05c914f2008-09-11 00:01:58 +0200836 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
837 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200838 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100839 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200840 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100841
Johannes Berg14db74b2008-07-29 13:22:52 +0200842 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100843 ieee80211_send_layer2_update(sta);
844 }
845
846 sta_apply_parameters(local, sta, params);
847
Johannes Berg98dd6a52008-04-10 15:36:09 +0200848 rcu_read_unlock();
849
Johannes Berg4fd69312007-12-19 02:03:35 +0100850 return 0;
851}
852
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853#ifdef CONFIG_MAC80211_MESH
854static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
855 u8 *dst, u8 *next_hop)
856{
Johannes Berg14db74b2008-07-29 13:22:52 +0200857 struct ieee80211_local *local = wiphy_priv(wiphy);
858 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100859 struct mesh_path *mpath;
860 struct sta_info *sta;
861 int err;
862
863 if (!netif_running(dev))
864 return -ENETDOWN;
865
Johannes Berg14db74b2008-07-29 13:22:52 +0200866 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
867
Johannes Berg05c914f2008-09-11 00:01:58 +0200868 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100869 return -ENOTSUPP;
870
Johannes Bergd0709a62008-02-25 16:27:46 +0100871 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100872 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100873 if (!sta) {
874 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100875 return -ENOENT;
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 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100879 if (err) {
880 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100881 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100882 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100883
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200884 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100885 if (!mpath) {
886 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100887 return -ENXIO;
888 }
889 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100890
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100891 rcu_read_unlock();
892 return 0;
893}
894
895static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
896 u8 *dst)
897{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200898 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100899
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200900 if (dst)
901 return mesh_path_del(dst, sdata);
902
903 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100904 return 0;
905}
906
907static int ieee80211_change_mpath(struct wiphy *wiphy,
908 struct net_device *dev,
909 u8 *dst, u8 *next_hop)
910{
Johannes Berg14db74b2008-07-29 13:22:52 +0200911 struct ieee80211_local *local = wiphy_priv(wiphy);
912 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100913 struct mesh_path *mpath;
914 struct sta_info *sta;
915
916 if (!netif_running(dev))
917 return -ENETDOWN;
918
Johannes Berg14db74b2008-07-29 13:22:52 +0200919 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
920
Johannes Berg05c914f2008-09-11 00:01:58 +0200921 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100922 return -ENOTSUPP;
923
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100924 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100925
926 sta = sta_info_get(local, next_hop);
927 if (!sta) {
928 rcu_read_unlock();
929 return -ENOENT;
930 }
931
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200932 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100933 if (!mpath) {
934 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100935 return -ENOENT;
936 }
937
938 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100939
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100940 rcu_read_unlock();
941 return 0;
942}
943
944static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
945 struct mpath_info *pinfo)
946{
947 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200948 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100949 else
950 memset(next_hop, 0, ETH_ALEN);
951
952 pinfo->filled = MPATH_INFO_FRAME_QLEN |
953 MPATH_INFO_DSN |
954 MPATH_INFO_METRIC |
955 MPATH_INFO_EXPTIME |
956 MPATH_INFO_DISCOVERY_TIMEOUT |
957 MPATH_INFO_DISCOVERY_RETRIES |
958 MPATH_INFO_FLAGS;
959
960 pinfo->frame_qlen = mpath->frame_queue.qlen;
961 pinfo->dsn = mpath->dsn;
962 pinfo->metric = mpath->metric;
963 if (time_before(jiffies, mpath->exp_time))
964 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
965 pinfo->discovery_timeout =
966 jiffies_to_msecs(mpath->discovery_timeout);
967 pinfo->discovery_retries = mpath->discovery_retries;
968 pinfo->flags = 0;
969 if (mpath->flags & MESH_PATH_ACTIVE)
970 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
971 if (mpath->flags & MESH_PATH_RESOLVING)
972 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
973 if (mpath->flags & MESH_PATH_DSN_VALID)
974 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
975 if (mpath->flags & MESH_PATH_FIXED)
976 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
977 if (mpath->flags & MESH_PATH_RESOLVING)
978 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
979
980 pinfo->flags = mpath->flags;
981}
982
983static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
984 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
985
986{
Johannes Berg14db74b2008-07-29 13:22:52 +0200987 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100988 struct mesh_path *mpath;
989
Johannes Berg14db74b2008-07-29 13:22:52 +0200990 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
991
Johannes Berg05c914f2008-09-11 00:01:58 +0200992 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100993 return -ENOTSUPP;
994
995 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200996 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100997 if (!mpath) {
998 rcu_read_unlock();
999 return -ENOENT;
1000 }
1001 memcpy(dst, mpath->dst, ETH_ALEN);
1002 mpath_set_pinfo(mpath, next_hop, pinfo);
1003 rcu_read_unlock();
1004 return 0;
1005}
1006
1007static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1008 int idx, u8 *dst, u8 *next_hop,
1009 struct mpath_info *pinfo)
1010{
Johannes Berg14db74b2008-07-29 13:22:52 +02001011 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001012 struct mesh_path *mpath;
1013
Johannes Berg14db74b2008-07-29 13:22:52 +02001014 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1015
Johannes Berg05c914f2008-09-11 00:01:58 +02001016 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001017 return -ENOTSUPP;
1018
1019 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001020 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001021 if (!mpath) {
1022 rcu_read_unlock();
1023 return -ENOENT;
1024 }
1025 memcpy(dst, mpath->dst, ETH_ALEN);
1026 mpath_set_pinfo(mpath, next_hop, pinfo);
1027 rcu_read_unlock();
1028 return 0;
1029}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001030
1031static int ieee80211_get_mesh_params(struct wiphy *wiphy,
1032 struct net_device *dev,
1033 struct mesh_config *conf)
1034{
1035 struct ieee80211_sub_if_data *sdata;
1036 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1037
1038 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1039 return -ENOTSUPP;
1040 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1041 return 0;
1042}
1043
1044static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1045{
1046 return (mask >> (parm-1)) & 0x1;
1047}
1048
1049static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1050 struct net_device *dev,
1051 const struct mesh_config *nconf, u32 mask)
1052{
1053 struct mesh_config *conf;
1054 struct ieee80211_sub_if_data *sdata;
1055 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1056
1057 if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1058 return -ENOTSUPP;
1059
1060 /* Set the config options which we are interested in setting */
1061 conf = &(sdata->u.mesh.mshcfg);
1062 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1063 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1064 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1065 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1066 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1067 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1068 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1069 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1070 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1071 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1072 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1073 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1074 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1075 conf->auto_open_plinks = nconf->auto_open_plinks;
1076 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1077 conf->dot11MeshHWMPmaxPREQretries =
1078 nconf->dot11MeshHWMPmaxPREQretries;
1079 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1080 conf->path_refresh_time = nconf->path_refresh_time;
1081 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1082 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1083 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1084 conf->dot11MeshHWMPactivePathTimeout =
1085 nconf->dot11MeshHWMPactivePathTimeout;
1086 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1087 conf->dot11MeshHWMPpreqMinInterval =
1088 nconf->dot11MeshHWMPpreqMinInterval;
1089 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1090 mask))
1091 conf->dot11MeshHWMPnetDiameterTraversalTime =
1092 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1093 return 0;
1094}
1095
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001096#endif
1097
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001098static int ieee80211_change_bss(struct wiphy *wiphy,
1099 struct net_device *dev,
1100 struct bss_parameters *params)
1101{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001102 struct ieee80211_sub_if_data *sdata;
1103 u32 changed = 0;
1104
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1106
Johannes Berg05c914f2008-09-11 00:01:58 +02001107 if (sdata->vif.type != NL80211_IFTYPE_AP)
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001108 return -EINVAL;
1109
1110 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001111 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001112 changed |= BSS_CHANGED_ERP_CTS_PROT;
1113 }
1114 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001115 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001116 params->use_short_preamble;
1117 changed |= BSS_CHANGED_ERP_PREAMBLE;
1118 }
1119 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001120 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001121 params->use_short_slot_time;
1122 changed |= BSS_CHANGED_ERP_SLOT;
1123 }
1124
Jouni Malinen90c97a02008-10-30 16:59:22 +02001125 if (params->basic_rates) {
1126 int i, j;
1127 u32 rates = 0;
1128 struct ieee80211_local *local = wiphy_priv(wiphy);
1129 struct ieee80211_supported_band *sband =
1130 wiphy->bands[local->oper_channel->band];
1131
1132 for (i = 0; i < params->basic_rates_len; i++) {
1133 int rate = (params->basic_rates[i] & 0x7f) * 5;
1134 for (j = 0; j < sband->n_bitrates; j++) {
1135 if (sband->bitrates[j].bitrate == rate)
1136 rates |= BIT(j);
1137 }
1138 }
1139 sdata->vif.bss_conf.basic_rates = rates;
1140 changed |= BSS_CHANGED_BASIC_RATES;
1141 }
1142
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001143 ieee80211_bss_info_change_notify(sdata, changed);
1144
1145 return 0;
1146}
1147
Jouni Malinen31888482008-10-30 16:59:24 +02001148static int ieee80211_set_txq_params(struct wiphy *wiphy,
1149 struct ieee80211_txq_params *params)
1150{
1151 struct ieee80211_local *local = wiphy_priv(wiphy);
1152 struct ieee80211_tx_queue_params p;
1153
1154 if (!local->ops->conf_tx)
1155 return -EOPNOTSUPP;
1156
1157 memset(&p, 0, sizeof(p));
1158 p.aifs = params->aifs;
1159 p.cw_max = params->cwmax;
1160 p.cw_min = params->cwmin;
1161 p.txop = params->txop;
1162 if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) {
1163 printk(KERN_DEBUG "%s: failed to set TX queue "
1164 "parameters for queue %d\n", local->mdev->name,
1165 params->queue);
1166 return -EINVAL;
1167 }
1168
1169 return 0;
1170}
1171
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001172static int ieee80211_set_channel(struct wiphy *wiphy,
1173 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301174 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001175{
1176 struct ieee80211_local *local = wiphy_priv(wiphy);
1177
1178 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +05301179 local->oper_channel_type = channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001180
1181 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1182}
1183
Johannes Berg60b22512009-02-10 21:25:41 +01001184static int set_mgmt_extra_ie_sta(struct ieee80211_sub_if_data *sdata,
1185 u8 subtype, u8 *ies, size_t ies_len)
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001186{
Johannes Berg60b22512009-02-10 21:25:41 +01001187 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +01001188 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
Johannes Berg60b22512009-02-10 21:25:41 +01001189
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001190 switch (subtype) {
1191 case IEEE80211_STYPE_PROBE_REQ >> 4:
Johannes Berg60b22512009-02-10 21:25:41 +01001192 if (local->ops->hw_scan)
1193 break;
Johannes Berg46900292009-02-15 12:44:28 +01001194 kfree(ifmgd->ie_probereq);
1195 ifmgd->ie_probereq = ies;
1196 ifmgd->ie_probereq_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001197 return 0;
1198 case IEEE80211_STYPE_PROBE_RESP >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001199 kfree(ifmgd->ie_proberesp);
1200 ifmgd->ie_proberesp = ies;
1201 ifmgd->ie_proberesp_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001202 return 0;
1203 case IEEE80211_STYPE_AUTH >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001204 kfree(ifmgd->ie_auth);
1205 ifmgd->ie_auth = ies;
1206 ifmgd->ie_auth_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001207 return 0;
1208 case IEEE80211_STYPE_ASSOC_REQ >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001209 kfree(ifmgd->ie_assocreq);
1210 ifmgd->ie_assocreq = ies;
1211 ifmgd->ie_assocreq_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001212 return 0;
1213 case IEEE80211_STYPE_REASSOC_REQ >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001214 kfree(ifmgd->ie_reassocreq);
1215 ifmgd->ie_reassocreq = ies;
1216 ifmgd->ie_reassocreq_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001217 return 0;
1218 case IEEE80211_STYPE_DEAUTH >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001219 kfree(ifmgd->ie_deauth);
1220 ifmgd->ie_deauth = ies;
1221 ifmgd->ie_deauth_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001222 return 0;
1223 case IEEE80211_STYPE_DISASSOC >> 4:
Johannes Berg46900292009-02-15 12:44:28 +01001224 kfree(ifmgd->ie_disassoc);
1225 ifmgd->ie_disassoc = ies;
1226 ifmgd->ie_disassoc_len = ies_len;
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001227 return 0;
1228 }
1229
1230 return -EOPNOTSUPP;
1231}
1232
1233static int ieee80211_set_mgmt_extra_ie(struct wiphy *wiphy,
1234 struct net_device *dev,
1235 struct mgmt_extra_ie_params *params)
1236{
1237 struct ieee80211_sub_if_data *sdata;
1238 u8 *ies;
1239 size_t ies_len;
1240 int ret = -EOPNOTSUPP;
1241
1242 if (params->ies) {
1243 ies = kmemdup(params->ies, params->ies_len, GFP_KERNEL);
1244 if (ies == NULL)
1245 return -ENOMEM;
1246 ies_len = params->ies_len;
1247 } else {
1248 ies = NULL;
1249 ies_len = 0;
1250 }
1251
1252 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1253
1254 switch (sdata->vif.type) {
1255 case NL80211_IFTYPE_STATION:
Johannes Berg60b22512009-02-10 21:25:41 +01001256 ret = set_mgmt_extra_ie_sta(sdata, params->subtype,
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001257 ies, ies_len);
1258 break;
1259 default:
1260 ret = -EOPNOTSUPP;
1261 break;
1262 }
1263
1264 if (ret)
1265 kfree(ies);
1266 return ret;
1267}
1268
Bob Copeland665af4f2009-01-19 11:20:53 -05001269#ifdef CONFIG_PM
1270static int ieee80211_suspend(struct wiphy *wiphy)
1271{
1272 return __ieee80211_suspend(wiphy_priv(wiphy));
1273}
1274
1275static int ieee80211_resume(struct wiphy *wiphy)
1276{
1277 return __ieee80211_resume(wiphy_priv(wiphy));
1278}
1279#else
1280#define ieee80211_suspend NULL
1281#define ieee80211_resume NULL
1282#endif
1283
Johannes Berg2a519312009-02-10 21:25:55 +01001284static int ieee80211_scan(struct wiphy *wiphy,
1285 struct net_device *dev,
1286 struct cfg80211_scan_request *req)
1287{
1288 struct ieee80211_sub_if_data *sdata;
1289
1290 if (!netif_running(dev))
1291 return -ENETDOWN;
1292
1293 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1294
1295 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1296 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1297 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
1298 return -EOPNOTSUPP;
1299
1300 return ieee80211_request_scan(sdata, req);
1301}
1302
Jouni Malinen636a5d32009-03-19 13:39:22 +02001303static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1304 struct cfg80211_auth_request *req)
1305{
1306 struct ieee80211_sub_if_data *sdata;
1307
1308 if (!netif_running(dev))
1309 return -ENETDOWN;
1310
1311 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1312
1313 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1314 return -EOPNOTSUPP;
1315
1316 switch (req->auth_type) {
1317 case NL80211_AUTHTYPE_OPEN_SYSTEM:
1318 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN;
1319 break;
1320 case NL80211_AUTHTYPE_SHARED_KEY:
1321 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY;
1322 break;
1323 case NL80211_AUTHTYPE_FT:
1324 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT;
1325 break;
1326 case NL80211_AUTHTYPE_NETWORK_EAP:
1327 sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP;
1328 break;
1329 default:
1330 return -EOPNOTSUPP;
1331 }
1332
1333 memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN);
1334 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1335 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1336
1337 /* TODO: req->chan */
1338 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1339
1340 if (req->ssid) {
1341 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1342 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1343 sdata->u.mgd.ssid_len = req->ssid_len;
1344 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1345 }
1346
1347 kfree(sdata->u.mgd.sme_auth_ie);
1348 sdata->u.mgd.sme_auth_ie = NULL;
1349 sdata->u.mgd.sme_auth_ie_len = 0;
1350 if (req->ie) {
1351 sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL);
1352 if (sdata->u.mgd.sme_auth_ie == NULL)
1353 return -ENOMEM;
1354 memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len);
1355 sdata->u.mgd.sme_auth_ie_len = req->ie_len;
1356 }
1357
1358 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1359 sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE;
1360 ieee80211_sta_req_auth(sdata);
1361 return 0;
1362}
1363
1364static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1365 struct cfg80211_assoc_request *req)
1366{
1367 struct ieee80211_sub_if_data *sdata;
1368 int ret;
1369
1370 if (!netif_running(dev))
1371 return -ENETDOWN;
1372
1373 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1374
1375 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1376 return -EOPNOTSUPP;
1377
1378 if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 ||
1379 !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED))
1380 return -ENOLINK; /* not authenticated */
1381
1382 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
1383 sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET;
1384
1385 /* TODO: req->chan */
1386 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL;
1387
1388 if (req->ssid) {
1389 sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET;
1390 memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len);
1391 sdata->u.mgd.ssid_len = req->ssid_len;
1392 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
1393 } else
1394 sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL;
1395
1396 ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len);
1397 if (ret)
1398 return ret;
1399
1400 sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME;
1401 sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE;
1402 ieee80211_sta_req_auth(sdata);
1403 return 0;
1404}
1405
1406static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1407 struct cfg80211_deauth_request *req)
1408{
1409 struct ieee80211_sub_if_data *sdata;
1410
1411 if (!netif_running(dev))
1412 return -ENETDOWN;
1413
1414 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1415 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1416 return -EOPNOTSUPP;
1417
1418 /* TODO: req->ie */
1419 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1420}
1421
1422static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1423 struct cfg80211_disassoc_request *req)
1424{
1425 struct ieee80211_sub_if_data *sdata;
1426
1427 if (!netif_running(dev))
1428 return -ENETDOWN;
1429
1430 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1431
1432 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1433 return -EOPNOTSUPP;
1434
1435 /* TODO: req->ie */
1436 return ieee80211_sta_disassociate(sdata, req->reason_code);
1437}
1438
Jiri Bencf0706e82007-05-05 11:45:53 -07001439struct cfg80211_ops mac80211_config_ops = {
1440 .add_virtual_intf = ieee80211_add_iface,
1441 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001442 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001443 .add_key = ieee80211_add_key,
1444 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001445 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001446 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001447 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001448 .add_beacon = ieee80211_add_beacon,
1449 .set_beacon = ieee80211_set_beacon,
1450 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001451 .add_station = ieee80211_add_station,
1452 .del_station = ieee80211_del_station,
1453 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001454 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001455 .dump_station = ieee80211_dump_station,
1456#ifdef CONFIG_MAC80211_MESH
1457 .add_mpath = ieee80211_add_mpath,
1458 .del_mpath = ieee80211_del_mpath,
1459 .change_mpath = ieee80211_change_mpath,
1460 .get_mpath = ieee80211_get_mpath,
1461 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001462 .set_mesh_params = ieee80211_set_mesh_params,
1463 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001464#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001465 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001466 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001467 .set_channel = ieee80211_set_channel,
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02001468 .set_mgmt_extra_ie = ieee80211_set_mgmt_extra_ie,
Bob Copeland665af4f2009-01-19 11:20:53 -05001469 .suspend = ieee80211_suspend,
1470 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001471 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001472 .auth = ieee80211_auth,
1473 .assoc = ieee80211_assoc,
1474 .deauth = ieee80211_deauth,
1475 .disassoc = ieee80211_disassoc,
Jiri Bencf0706e82007-05-05 11:45:53 -07001476};