blob: 7693ebc77596561fed2bde25f7a7e1ecdc7a1d8a [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <net/cfg80211.h>
16#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020017#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040018#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040019#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010020#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021
Johannes Berg05c914f2008-09-11 00:01:58 +020022static bool nl80211_type_check(enum nl80211_iftype type)
Johannes Berg42613db2007-09-28 21:52:27 +020023{
24 switch (type) {
Johannes Berg42613db2007-09-28 21:52:27 +020025 case NL80211_IFTYPE_ADHOC:
Johannes Berg42613db2007-09-28 21:52:27 +020026 case NL80211_IFTYPE_STATION:
Johannes Berg42613db2007-09-28 21:52:27 +020027 case NL80211_IFTYPE_MONITOR:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010028#ifdef CONFIG_MAC80211_MESH
29 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010030#endif
Jouni Malinenfbf18922008-10-30 19:50:30 +020031 case NL80211_IFTYPE_AP:
32 case NL80211_IFTYPE_AP_VLAN:
Johannes Bergb4540482008-04-14 15:37:03 +020033 case NL80211_IFTYPE_WDS:
Johannes Berg05c914f2008-09-11 00:01:58 +020034 return true;
Johannes Berg42613db2007-09-28 21:52:27 +020035 default:
Johannes Berg05c914f2008-09-11 00:01:58 +020036 return false;
Johannes Berg42613db2007-09-28 21:52:27 +020037 }
38}
39
Felix Fietkauf14543ee2009-11-10 20:10:05 +010040static bool nl80211_params_check(enum nl80211_iftype type,
41 struct vif_params *params)
42{
43 if (!nl80211_type_check(type))
44 return false;
45
Felix Fietkauf14543ee2009-11-10 20:10:05 +010046 return true;
47}
48
Jiri Bencf0706e82007-05-05 11:45:53 -070049static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010050 enum nl80211_iftype type, u32 *flags,
51 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070052{
53 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010054 struct net_device *dev;
55 struct ieee80211_sub_if_data *sdata;
56 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070057
Felix Fietkauf14543ee2009-11-10 20:10:05 +010058 if (!nl80211_params_check(type, params))
Jiri Bencf0706e82007-05-05 11:45:53 -070059 return -EINVAL;
Jiri Bencf0706e82007-05-05 11:45:53 -070060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 err = ieee80211_if_add(local, name, &dev, type, params);
62 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010063 return err;
64
65 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
66 sdata->u.mntr_flags = *flags;
67 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070068}
69
Johannes Berg463d0182009-07-14 00:33:35 +020070static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e82007-05-05 11:45:53 -070071{
Johannes Berg463d0182009-07-14 00:33:35 +020072 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e82007-05-05 11:45:53 -070073
Johannes Berg75636522008-07-09 14:40:35 +020074 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070075}
76
Johannes Berge36d56b2009-06-09 21:04:43 +020077static int ieee80211_change_iface(struct wiphy *wiphy,
78 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010079 enum nl80211_iftype type, u32 *flags,
80 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020081{
Johannes Berg9607e6b2009-12-23 13:15:31 +010082 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020083 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020084
Johannes Berg9607e6b2009-12-23 13:15:31 +010085 if (ieee80211_sdata_running(sdata))
Johannes Bergc1f9a762009-11-01 19:25:40 +010086 return -EBUSY;
87
Felix Fietkauf14543ee2009-11-10 20:10:05 +010088 if (!nl80211_params_check(type, params))
Johannes Berg42613db2007-09-28 21:52:27 +020089 return -EINVAL;
90
Johannes Berg05c914f2008-09-11 00:01:58 +020091 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020092 if (ret)
93 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020094
Johannes Berg902acc72008-02-23 15:17:19 +010095 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020096 ieee80211_sdata_set_mesh_id(sdata,
97 params->mesh_id_len,
98 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010099
Johannes Berg9bc383d2009-11-19 11:55:19 +0100100 if (type == NL80211_IFTYPE_AP_VLAN &&
101 params && params->use_4addr == 0)
102 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
103 else if (type == NL80211_IFTYPE_STATION &&
104 params && params->use_4addr >= 0)
105 sdata->u.mgd.use_4addr = params->use_4addr;
106
Felix Fietkauf7917af2010-04-27 00:26:34 +0200107 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
108 sdata->u.mntr_flags = *flags;
109
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,
Johannes Berg4e943902009-05-09 20:06:47 +0200114 u8 key_idx, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100115 struct key_params *params)
116{
117 struct ieee80211_sub_if_data *sdata;
118 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100119 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200120 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100121
Johannes Bergad0e2b52010-06-01 10:19:19 +0200122 if (!netif_running(dev))
123 return -ENETDOWN;
124
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100125 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
126
Johannes Berg97359d12010-08-10 09:46:38 +0200127 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128 switch (params->cipher) {
129 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200131 case WLAN_CIPHER_SUITE_WEP104:
132 if (IS_ERR(sdata->local->wep_tx_tfm))
133 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200134 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100135 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200136 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100137 }
138
Johannes Berg97359d12010-08-10 09:46:38 +0200139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100141 if (IS_ERR(key))
142 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100143
Johannes Bergad0e2b52010-06-01 10:19:19 +0200144 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200145
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100147 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700149 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200150 err = -ENOENT;
151 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100152 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153 }
154
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155 ieee80211_key_link(key, sdata, sta);
156
Johannes Berg3b967662008-04-08 17:56:52 +0200157 err = 0;
158 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200159 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200160
161 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162}
163
164static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200165 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166{
167 struct ieee80211_sub_if_data *sdata;
168 struct sta_info *sta;
169 int ret;
170
171 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
172
Johannes Bergad0e2b52010-06-01 10:19:19 +0200173 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200174
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100175 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200176 ret = -ENOENT;
177
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100178 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100179 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200180 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100181
Johannes Bergdb4d1162008-02-25 16:27:45 +0100182 if (sta->key) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700183 ieee80211_key_free(sdata->local, sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100184 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200185 ret = 0;
186 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100187
Johannes Berg3b967662008-04-08 17:56:52 +0200188 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189 }
190
Johannes Berg3b967662008-04-08 17:56:52 +0200191 if (!sdata->keys[key_idx]) {
192 ret = -ENOENT;
193 goto out_unlock;
194 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195
Jouni Malinen32162a42010-07-26 15:52:03 -0700196 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100197 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100198
Johannes Berg3b967662008-04-08 17:56:52 +0200199 ret = 0;
200 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200201 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200202
203 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204}
205
Johannes Berg62da92f2007-12-19 02:03:31 +0100206static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200207 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100208 void (*callback)(void *cookie,
209 struct key_params *params))
210{
Johannes Berg14db74b2008-07-29 13:22:52 +0200211 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100212 struct sta_info *sta = NULL;
213 u8 seq[6] = {0};
214 struct key_params params;
215 struct ieee80211_key *key;
216 u32 iv32;
217 u16 iv16;
218 int err = -ENOENT;
219
Johannes Berg14db74b2008-07-29 13:22:52 +0200220 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
221
Johannes Berg3b967662008-04-08 17:56:52 +0200222 rcu_read_lock();
223
Johannes Berg62da92f2007-12-19 02:03:31 +0100224 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100225 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100226 if (!sta)
227 goto out;
228
229 key = sta->key;
230 } else
231 key = sdata->keys[key_idx];
232
233 if (!key)
234 goto out;
235
236 memset(&params, 0, sizeof(params));
237
Johannes Berg97359d12010-08-10 09:46:38 +0200238 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100239
Johannes Berg97359d12010-08-10 09:46:38 +0200240 switch (key->conf.cipher) {
241 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700242 iv32 = key->u.tkip.tx.iv32;
243 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100244
Johannes Berg24487982009-04-23 18:52:52 +0200245 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
246 drv_get_tkip_seq(sdata->local,
247 key->conf.hw_key_idx,
248 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100249
250 seq[0] = iv16 & 0xff;
251 seq[1] = (iv16 >> 8) & 0xff;
252 seq[2] = iv32 & 0xff;
253 seq[3] = (iv32 >> 8) & 0xff;
254 seq[4] = (iv32 >> 16) & 0xff;
255 seq[5] = (iv32 >> 24) & 0xff;
256 params.seq = seq;
257 params.seq_len = 6;
258 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200259 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100260 seq[0] = key->u.ccmp.tx_pn[5];
261 seq[1] = key->u.ccmp.tx_pn[4];
262 seq[2] = key->u.ccmp.tx_pn[3];
263 seq[3] = key->u.ccmp.tx_pn[2];
264 seq[4] = key->u.ccmp.tx_pn[1];
265 seq[5] = key->u.ccmp.tx_pn[0];
266 params.seq = seq;
267 params.seq_len = 6;
268 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200269 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200270 seq[0] = key->u.aes_cmac.tx_pn[5];
271 seq[1] = key->u.aes_cmac.tx_pn[4];
272 seq[2] = key->u.aes_cmac.tx_pn[3];
273 seq[3] = key->u.aes_cmac.tx_pn[2];
274 seq[4] = key->u.aes_cmac.tx_pn[1];
275 seq[5] = key->u.aes_cmac.tx_pn[0];
276 params.seq = seq;
277 params.seq_len = 6;
278 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100279 }
280
281 params.key = key->conf.key;
282 params.key_len = key->conf.keylen;
283
284 callback(cookie, &params);
285 err = 0;
286
287 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200288 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100289 return err;
290}
291
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100292static int ieee80211_config_default_key(struct wiphy *wiphy,
293 struct net_device *dev,
294 u8 key_idx)
295{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100297
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100298 ieee80211_set_default_key(sdata, key_idx);
299
300 return 0;
301}
302
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200303static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
304 struct net_device *dev,
305 u8 key_idx)
306{
Johannes Berg66c52422010-07-22 13:58:51 +0200307 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200308
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200309 ieee80211_set_default_mgmt_key(sdata, key_idx);
310
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200311 return 0;
312}
313
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100314static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
315{
Johannes Bergd0709a62008-02-25 16:27:46 +0100316 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100317
Johannes Bergf5ea9122009-08-07 16:17:38 +0200318 sinfo->generation = sdata->local->sta_generation;
319
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100320 sinfo->filled = STATION_INFO_INACTIVE_TIME |
321 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100322 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200323 STATION_INFO_RX_PACKETS |
324 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100325 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100326
327 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
328 sinfo->rx_bytes = sta->rx_bytes;
329 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200330 sinfo->rx_packets = sta->rx_packets;
331 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100332
John W. Linville19deffb2009-12-08 17:10:13 -0500333 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
334 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Henning Rogge420e7fa2008-12-11 22:04:19 +0100335 sinfo->filled |= STATION_INFO_SIGNAL;
336 sinfo->signal = (s8)sta->last_signal;
337 }
338
339 sinfo->txrate.flags = 0;
340 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
341 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
342 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
343 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
344 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
345 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
346
347 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
348 struct ieee80211_supported_band *sband;
349 sband = sta->local->hw.wiphy->bands[
350 sta->local->hw.conf.channel->band];
351 sinfo->txrate.legacy =
352 sband->bitrates[sta->last_tx_rate.idx].bitrate;
353 } else
354 sinfo->txrate.mcs = sta->last_tx_rate.idx;
355
Johannes Berg902acc72008-02-23 15:17:19 +0100356 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100357#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100358 sinfo->filled |= STATION_INFO_LLID |
359 STATION_INFO_PLID |
360 STATION_INFO_PLINK_STATE;
361
362 sinfo->llid = le16_to_cpu(sta->llid);
363 sinfo->plid = le16_to_cpu(sta->plid);
364 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100365#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100366 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100367}
368
369
370static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
371 int idx, u8 *mac, struct station_info *sinfo)
372{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100374 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100375 int ret = -ENOENT;
376
377 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100378
Johannes Berg3b53fde82009-11-16 12:00:37 +0100379 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100380 if (sta) {
381 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200382 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100383 sta_set_sinfo(sta, sinfo);
384 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100385
Johannes Bergd0709a62008-02-25 16:27:46 +0100386 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100387
Johannes Bergd0709a62008-02-25 16:27:46 +0100388 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100389}
390
Holger Schurig12897232010-04-19 10:23:57 +0200391static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
392 int idx, struct survey_info *survey)
393{
394 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
395
Holger Schurig12897232010-04-19 10:23:57 +0200396 return drv_get_survey(local, idx, survey);
397}
398
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100399static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100400 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100401{
Johannes Bergabe60632009-11-25 17:46:18 +0100402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100403 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100404 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100405
Johannes Bergd0709a62008-02-25 16:27:46 +0100406 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100407
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100408 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100409 if (sta) {
410 ret = 0;
411 sta_set_sinfo(sta, sinfo);
412 }
413
414 rcu_read_unlock();
415
416 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100417}
418
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100419/*
420 * This handles both adding a beacon and setting new beacon info
421 */
422static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
423 struct beacon_parameters *params)
424{
425 struct beacon_data *new, *old;
426 int new_head_len, new_tail_len;
427 int size;
428 int err = -EINVAL;
429
430 old = sdata->u.ap.beacon;
431
432 /* head must not be zero-length */
433 if (params->head && !params->head_len)
434 return -EINVAL;
435
436 /*
437 * This is a kludge. beacon interval should really be part
438 * of the beacon information.
439 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200440 if (params->interval &&
441 (sdata->vif.bss_conf.beacon_int != params->interval)) {
442 sdata->vif.bss_conf.beacon_int = params->interval;
443 ieee80211_bss_info_change_notify(sdata,
444 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100445 }
446
447 /* Need to have a beacon head if we don't have one yet */
448 if (!params->head && !old)
449 return err;
450
451 /* sorry, no way to start beaconing without dtim period */
452 if (!params->dtim_period && !old)
453 return err;
454
455 /* new or old head? */
456 if (params->head)
457 new_head_len = params->head_len;
458 else
459 new_head_len = old->head_len;
460
461 /* new or old tail? */
462 if (params->tail || !old)
463 /* params->tail_len will be zero for !params->tail */
464 new_tail_len = params->tail_len;
465 else
466 new_tail_len = old->tail_len;
467
468 size = sizeof(*new) + new_head_len + new_tail_len;
469
470 new = kzalloc(size, GFP_KERNEL);
471 if (!new)
472 return -ENOMEM;
473
474 /* start filling the new info now */
475
476 /* new or old dtim period? */
477 if (params->dtim_period)
478 new->dtim_period = params->dtim_period;
479 else
480 new->dtim_period = old->dtim_period;
481
482 /*
483 * pointers go into the block we allocated,
484 * memory is | beacon_data | head | tail |
485 */
486 new->head = ((u8 *) new) + sizeof(*new);
487 new->tail = new->head + new_head_len;
488 new->head_len = new_head_len;
489 new->tail_len = new_tail_len;
490
491 /* copy in head */
492 if (params->head)
493 memcpy(new->head, params->head, new_head_len);
494 else
495 memcpy(new->head, old->head, new_head_len);
496
497 /* copy in optional tail */
498 if (params->tail)
499 memcpy(new->tail, params->tail, new_tail_len);
500 else
501 if (old)
502 memcpy(new->tail, old->tail, new_tail_len);
503
Johannes Berg19885c42010-02-05 11:45:06 +0100504 sdata->vif.bss_conf.dtim_period = new->dtim_period;
505
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100506 rcu_assign_pointer(sdata->u.ap.beacon, new);
507
508 synchronize_rcu();
509
510 kfree(old);
511
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200512 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
513 BSS_CHANGED_BEACON);
514 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100515}
516
517static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
518 struct beacon_parameters *params)
519{
Johannes Berg14db74b2008-07-29 13:22:52 +0200520 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100521 struct beacon_data *old;
522
Johannes Berg14db74b2008-07-29 13:22:52 +0200523 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
524
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100525 old = sdata->u.ap.beacon;
526
527 if (old)
528 return -EALREADY;
529
530 return ieee80211_config_beacon(sdata, params);
531}
532
533static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
534 struct beacon_parameters *params)
535{
Johannes Berg14db74b2008-07-29 13:22:52 +0200536 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100537 struct beacon_data *old;
538
Johannes Berg14db74b2008-07-29 13:22:52 +0200539 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
540
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100541 old = sdata->u.ap.beacon;
542
543 if (!old)
544 return -ENOENT;
545
546 return ieee80211_config_beacon(sdata, params);
547}
548
549static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
550{
Johannes Berg14db74b2008-07-29 13:22:52 +0200551 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100552 struct beacon_data *old;
553
Johannes Berg14db74b2008-07-29 13:22:52 +0200554 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100556 old = sdata->u.ap.beacon;
557
558 if (!old)
559 return -ENOENT;
560
561 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
562 synchronize_rcu();
563 kfree(old);
564
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200565 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
566 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100567}
568
Johannes Berg4fd69312007-12-19 02:03:35 +0100569/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
570struct iapp_layer2_update {
571 u8 da[ETH_ALEN]; /* broadcast */
572 u8 sa[ETH_ALEN]; /* STA addr */
573 __be16 len; /* 6 */
574 u8 dsap; /* 0 */
575 u8 ssap; /* 0 */
576 u8 control;
577 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700578} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100579
580static void ieee80211_send_layer2_update(struct sta_info *sta)
581{
582 struct iapp_layer2_update *msg;
583 struct sk_buff *skb;
584
585 /* Send Level 2 Update Frame to update forwarding tables in layer 2
586 * bridge devices */
587
588 skb = dev_alloc_skb(sizeof(*msg));
589 if (!skb)
590 return;
591 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
592
593 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
594 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
595
596 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200597 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100598 msg->len = htons(6);
599 msg->dsap = 0;
600 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
601 msg->control = 0xaf; /* XID response lsb.1111F101.
602 * F=0 (no poll command; unsolicited frame) */
603 msg->xid_info[0] = 0x81; /* XID format identifier */
604 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
605 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
606
Johannes Bergd0709a62008-02-25 16:27:46 +0100607 skb->dev = sta->sdata->dev;
608 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100609 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400610 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100611}
612
613static void sta_apply_parameters(struct ieee80211_local *local,
614 struct sta_info *sta,
615 struct station_parameters *params)
616{
617 u32 rates;
618 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100619 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100620 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300621 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100622
Johannes Bergae5eb022008-10-14 16:58:37 +0200623 sband = local->hw.wiphy->bands[local->oper_channel->band];
624
Johannes Bergeccb8e82009-05-11 21:57:56 +0300625 spin_lock_bh(&sta->lock);
626 mask = params->sta_flags_mask;
627 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100628
Johannes Bergeccb8e82009-05-11 21:57:56 +0300629 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100630 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300631 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100632 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100633 }
634
Johannes Bergeccb8e82009-05-11 21:57:56 +0300635 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
636 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
637 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
638 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
639 }
640
641 if (mask & BIT(NL80211_STA_FLAG_WME)) {
642 sta->flags &= ~WLAN_STA_WME;
643 if (set & BIT(NL80211_STA_FLAG_WME))
644 sta->flags |= WLAN_STA_WME;
645 }
646
647 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
648 sta->flags &= ~WLAN_STA_MFP;
649 if (set & BIT(NL80211_STA_FLAG_MFP))
650 sta->flags |= WLAN_STA_MFP;
651 }
652 spin_unlock_bh(&sta->lock);
653
Johannes Berg73651ee2008-02-25 16:27:47 +0100654 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200655 * cfg80211 validates this (1-2007) and allows setting the AID
656 * only when creating a new station entry
657 */
658 if (params->aid)
659 sta->sta.aid = params->aid;
660
661 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100662 * FIXME: updating the following information is racy when this
663 * function is called from ieee80211_change_station().
664 * However, all this information should be static so
665 * maybe we should just reject attemps to change it.
666 */
667
Johannes Berg4fd69312007-12-19 02:03:35 +0100668 if (params->listen_interval >= 0)
669 sta->listen_interval = params->listen_interval;
670
671 if (params->supported_rates) {
672 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100673
Johannes Berg4fd69312007-12-19 02:03:35 +0100674 for (i = 0; i < params->supported_rates_len; i++) {
675 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100676 for (j = 0; j < sband->n_bitrates; j++) {
677 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100678 rates |= BIT(j);
679 }
680 }
Johannes Berg323ce792008-09-11 02:45:11 +0200681 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100682 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100683
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200684 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200685 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
686 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200687 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300688
Johannes Berg902acc72008-02-23 15:17:19 +0100689 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100690 switch (params->plink_action) {
691 case PLINK_ACTION_OPEN:
692 mesh_plink_open(sta);
693 break;
694 case PLINK_ACTION_BLOCK:
695 mesh_plink_block(sta);
696 break;
697 }
Johannes Berg902acc72008-02-23 15:17:19 +0100698 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100699}
700
701static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
702 u8 *mac, struct station_parameters *params)
703{
Johannes Berg14db74b2008-07-29 13:22:52 +0200704 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100705 struct sta_info *sta;
706 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100707 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200708 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100709
Johannes Berg4fd69312007-12-19 02:03:35 +0100710 if (params->vlan) {
711 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
712
Johannes Berg05c914f2008-09-11 00:01:58 +0200713 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
714 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100715 return -EINVAL;
716 } else
717 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
718
Johannes Berg47846c92009-11-25 17:46:19 +0100719 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100720 return -EINVAL;
721
722 if (is_multicast_ether_addr(mac))
723 return -EINVAL;
724
725 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100726 if (!sta)
727 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100728
729 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
730
731 sta_apply_parameters(local, sta, params);
732
Johannes Berg4b7679a2008-09-18 18:14:18 +0200733 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100734
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200735 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
736 sdata->vif.type == NL80211_IFTYPE_AP;
737
Johannes Berg34e89502010-02-03 13:59:58 +0100738 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100739 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100740 rcu_read_unlock();
741 return err;
742 }
743
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200744 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100745 ieee80211_send_layer2_update(sta);
746
747 rcu_read_unlock();
748
Johannes Berg4fd69312007-12-19 02:03:35 +0100749 return 0;
750}
751
752static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
753 u8 *mac)
754{
Johannes Berg14db74b2008-07-29 13:22:52 +0200755 struct ieee80211_local *local = wiphy_priv(wiphy);
756 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100757
Johannes Berg14db74b2008-07-29 13:22:52 +0200758 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
759
Johannes Berg34e89502010-02-03 13:59:58 +0100760 if (mac)
761 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200762
Johannes Berg34e89502010-02-03 13:59:58 +0100763 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100764 return 0;
765}
766
767static int ieee80211_change_station(struct wiphy *wiphy,
768 struct net_device *dev,
769 u8 *mac,
770 struct station_parameters *params)
771{
Johannes Bergabe60632009-11-25 17:46:18 +0100772 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200773 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100774 struct sta_info *sta;
775 struct ieee80211_sub_if_data *vlansdata;
776
Johannes Berg98dd6a52008-04-10 15:36:09 +0200777 rcu_read_lock();
778
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100779 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200780 if (!sta) {
781 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100782 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200783 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100784
Johannes Bergd0709a62008-02-25 16:27:46 +0100785 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100786 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
787
Johannes Berg05c914f2008-09-11 00:01:58 +0200788 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
789 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200790 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100791 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200792 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100793
Johannes Berg9bc383d2009-11-19 11:55:19 +0100794 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100795 if (vlansdata->u.vlan.sta) {
796 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100797 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100798 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100799
800 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
801 }
802
Johannes Berg14db74b2008-07-29 13:22:52 +0200803 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100804 ieee80211_send_layer2_update(sta);
805 }
806
807 sta_apply_parameters(local, sta, params);
808
Johannes Berg98dd6a52008-04-10 15:36:09 +0200809 rcu_read_unlock();
810
Johannes Berg4fd69312007-12-19 02:03:35 +0100811 return 0;
812}
813
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100814#ifdef CONFIG_MAC80211_MESH
815static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
816 u8 *dst, u8 *next_hop)
817{
Johannes Berg14db74b2008-07-29 13:22:52 +0200818 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100819 struct mesh_path *mpath;
820 struct sta_info *sta;
821 int err;
822
Johannes Berg14db74b2008-07-29 13:22:52 +0200823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
824
Johannes Bergd0709a62008-02-25 16:27:46 +0100825 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100826 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100827 if (!sta) {
828 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100829 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100830 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100831
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200832 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100833 if (err) {
834 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100835 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100836 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100837
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200838 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100839 if (!mpath) {
840 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100841 return -ENXIO;
842 }
843 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100844
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100845 rcu_read_unlock();
846 return 0;
847}
848
849static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
850 u8 *dst)
851{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200852 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200854 if (dst)
855 return mesh_path_del(dst, sdata);
856
857 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858 return 0;
859}
860
861static int ieee80211_change_mpath(struct wiphy *wiphy,
862 struct net_device *dev,
863 u8 *dst, u8 *next_hop)
864{
Johannes Berg14db74b2008-07-29 13:22:52 +0200865 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100866 struct mesh_path *mpath;
867 struct sta_info *sta;
868
Johannes Berg14db74b2008-07-29 13:22:52 +0200869 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
870
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100871 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100872
Johannes Bergabe60632009-11-25 17:46:18 +0100873 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100874 if (!sta) {
875 rcu_read_unlock();
876 return -ENOENT;
877 }
878
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200879 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100880 if (!mpath) {
881 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100882 return -ENOENT;
883 }
884
885 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100886
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100887 rcu_read_unlock();
888 return 0;
889}
890
891static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
892 struct mpath_info *pinfo)
893{
894 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200895 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100896 else
897 memset(next_hop, 0, ETH_ALEN);
898
Johannes Bergf5ea9122009-08-07 16:17:38 +0200899 pinfo->generation = mesh_paths_generation;
900
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100901 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000902 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 MPATH_INFO_METRIC |
904 MPATH_INFO_EXPTIME |
905 MPATH_INFO_DISCOVERY_TIMEOUT |
906 MPATH_INFO_DISCOVERY_RETRIES |
907 MPATH_INFO_FLAGS;
908
909 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000910 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100911 pinfo->metric = mpath->metric;
912 if (time_before(jiffies, mpath->exp_time))
913 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
914 pinfo->discovery_timeout =
915 jiffies_to_msecs(mpath->discovery_timeout);
916 pinfo->discovery_retries = mpath->discovery_retries;
917 pinfo->flags = 0;
918 if (mpath->flags & MESH_PATH_ACTIVE)
919 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
920 if (mpath->flags & MESH_PATH_RESOLVING)
921 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000922 if (mpath->flags & MESH_PATH_SN_VALID)
923 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100924 if (mpath->flags & MESH_PATH_FIXED)
925 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
926 if (mpath->flags & MESH_PATH_RESOLVING)
927 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
928
929 pinfo->flags = mpath->flags;
930}
931
932static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
933 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
934
935{
Johannes Berg14db74b2008-07-29 13:22:52 +0200936 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100937 struct mesh_path *mpath;
938
Johannes Berg14db74b2008-07-29 13:22:52 +0200939 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
940
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100941 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200942 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100943 if (!mpath) {
944 rcu_read_unlock();
945 return -ENOENT;
946 }
947 memcpy(dst, mpath->dst, ETH_ALEN);
948 mpath_set_pinfo(mpath, next_hop, pinfo);
949 rcu_read_unlock();
950 return 0;
951}
952
953static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
954 int idx, u8 *dst, u8 *next_hop,
955 struct mpath_info *pinfo)
956{
Johannes Berg14db74b2008-07-29 13:22:52 +0200957 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100958 struct mesh_path *mpath;
959
Johannes Berg14db74b2008-07-29 13:22:52 +0200960 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
961
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100962 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200963 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100964 if (!mpath) {
965 rcu_read_unlock();
966 return -ENOENT;
967 }
968 memcpy(dst, mpath->dst, ETH_ALEN);
969 mpath_set_pinfo(mpath, next_hop, pinfo);
970 rcu_read_unlock();
971 return 0;
972}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700973
974static int ieee80211_get_mesh_params(struct wiphy *wiphy,
975 struct net_device *dev,
976 struct mesh_config *conf)
977{
978 struct ieee80211_sub_if_data *sdata;
979 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
980
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700981 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
982 return 0;
983}
984
985static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
986{
987 return (mask >> (parm-1)) & 0x1;
988}
989
990static int ieee80211_set_mesh_params(struct wiphy *wiphy,
991 struct net_device *dev,
992 const struct mesh_config *nconf, u32 mask)
993{
994 struct mesh_config *conf;
995 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +0000996 struct ieee80211_if_mesh *ifmsh;
997
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700998 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +0000999 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001000
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001001 /* Set the config options which we are interested in setting */
1002 conf = &(sdata->u.mesh.mshcfg);
1003 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1004 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1005 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1006 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1007 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1008 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1009 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1010 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1011 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1012 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1013 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1014 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1015 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1016 conf->auto_open_plinks = nconf->auto_open_plinks;
1017 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1018 conf->dot11MeshHWMPmaxPREQretries =
1019 nconf->dot11MeshHWMPmaxPREQretries;
1020 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1021 conf->path_refresh_time = nconf->path_refresh_time;
1022 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1023 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1024 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1025 conf->dot11MeshHWMPactivePathTimeout =
1026 nconf->dot11MeshHWMPactivePathTimeout;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1028 conf->dot11MeshHWMPpreqMinInterval =
1029 nconf->dot11MeshHWMPpreqMinInterval;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1031 mask))
1032 conf->dot11MeshHWMPnetDiameterTraversalTime =
1033 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001034 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1035 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1036 ieee80211_mesh_root_setup(ifmsh);
1037 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001038 return 0;
1039}
1040
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001041#endif
1042
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001043static int ieee80211_change_bss(struct wiphy *wiphy,
1044 struct net_device *dev,
1045 struct bss_parameters *params)
1046{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001047 struct ieee80211_sub_if_data *sdata;
1048 u32 changed = 0;
1049
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001050 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1051
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001052 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001053 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001054 changed |= BSS_CHANGED_ERP_CTS_PROT;
1055 }
1056 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001057 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001058 params->use_short_preamble;
1059 changed |= BSS_CHANGED_ERP_PREAMBLE;
1060 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001061
1062 if (!sdata->vif.bss_conf.use_short_slot &&
1063 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1064 sdata->vif.bss_conf.use_short_slot = true;
1065 changed |= BSS_CHANGED_ERP_SLOT;
1066 }
1067
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001068 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001069 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001070 params->use_short_slot_time;
1071 changed |= BSS_CHANGED_ERP_SLOT;
1072 }
1073
Jouni Malinen90c97a02008-10-30 16:59:22 +02001074 if (params->basic_rates) {
1075 int i, j;
1076 u32 rates = 0;
1077 struct ieee80211_local *local = wiphy_priv(wiphy);
1078 struct ieee80211_supported_band *sband =
1079 wiphy->bands[local->oper_channel->band];
1080
1081 for (i = 0; i < params->basic_rates_len; i++) {
1082 int rate = (params->basic_rates[i] & 0x7f) * 5;
1083 for (j = 0; j < sband->n_bitrates; j++) {
1084 if (sband->bitrates[j].bitrate == rate)
1085 rates |= BIT(j);
1086 }
1087 }
1088 sdata->vif.bss_conf.basic_rates = rates;
1089 changed |= BSS_CHANGED_BASIC_RATES;
1090 }
1091
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001092 if (params->ap_isolate >= 0) {
1093 if (params->ap_isolate)
1094 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1095 else
1096 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1097 }
1098
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001099 ieee80211_bss_info_change_notify(sdata, changed);
1100
1101 return 0;
1102}
1103
Jouni Malinen31888482008-10-30 16:59:24 +02001104static int ieee80211_set_txq_params(struct wiphy *wiphy,
1105 struct ieee80211_txq_params *params)
1106{
1107 struct ieee80211_local *local = wiphy_priv(wiphy);
1108 struct ieee80211_tx_queue_params p;
1109
1110 if (!local->ops->conf_tx)
1111 return -EOPNOTSUPP;
1112
1113 memset(&p, 0, sizeof(p));
1114 p.aifs = params->aifs;
1115 p.cw_max = params->cwmax;
1116 p.cw_min = params->cwmin;
1117 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001118
1119 /*
1120 * Setting tx queue params disables u-apsd because it's only
1121 * called in master mode.
1122 */
1123 p.uapsd = false;
1124
Johannes Berg24487982009-04-23 18:52:52 +02001125 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001126 wiphy_debug(local->hw.wiphy,
1127 "failed to set TX queue parameters for queue %d\n",
1128 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001129 return -EINVAL;
1130 }
1131
1132 return 0;
1133}
1134
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001135static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001136 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001137 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301138 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001139{
1140 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001141 struct ieee80211_sub_if_data *sdata = NULL;
1142
1143 if (netdev)
1144 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001145
Johannes Bergf444de02010-05-05 15:25:02 +02001146 switch (ieee80211_get_channel_mode(local, NULL)) {
1147 case CHAN_MODE_HOPPING:
1148 return -EBUSY;
1149 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001150 if (local->oper_channel != chan)
1151 return -EBUSY;
1152 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001153 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001154 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001155 case CHAN_MODE_UNDEFINED:
1156 break;
1157 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001158
1159 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001160
Johannes Berg0aaffa92010-05-05 15:28:27 +02001161 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1162 return -EBUSY;
1163
1164 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1165 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1166 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1167
1168 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001169}
1170
Bob Copeland665af4f2009-01-19 11:20:53 -05001171#ifdef CONFIG_PM
1172static int ieee80211_suspend(struct wiphy *wiphy)
1173{
1174 return __ieee80211_suspend(wiphy_priv(wiphy));
1175}
1176
1177static int ieee80211_resume(struct wiphy *wiphy)
1178{
1179 return __ieee80211_resume(wiphy_priv(wiphy));
1180}
1181#else
1182#define ieee80211_suspend NULL
1183#define ieee80211_resume NULL
1184#endif
1185
Johannes Berg2a519312009-02-10 21:25:55 +01001186static int ieee80211_scan(struct wiphy *wiphy,
1187 struct net_device *dev,
1188 struct cfg80211_scan_request *req)
1189{
1190 struct ieee80211_sub_if_data *sdata;
1191
Johannes Berg2a519312009-02-10 21:25:55 +01001192 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1193
1194 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1195 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinen357303e2009-04-16 18:44:53 +03001196 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1197 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
Johannes Berg2a519312009-02-10 21:25:55 +01001198 return -EOPNOTSUPP;
1199
1200 return ieee80211_request_scan(sdata, req);
1201}
1202
Jouni Malinen636a5d32009-03-19 13:39:22 +02001203static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1204 struct cfg80211_auth_request *req)
1205{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001206 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001207}
1208
1209static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1210 struct cfg80211_assoc_request *req)
1211{
Johannes Bergf444de02010-05-05 15:25:02 +02001212 struct ieee80211_local *local = wiphy_priv(wiphy);
1213 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1214
1215 switch (ieee80211_get_channel_mode(local, sdata)) {
1216 case CHAN_MODE_HOPPING:
1217 return -EBUSY;
1218 case CHAN_MODE_FIXED:
1219 if (local->oper_channel == req->bss->channel)
1220 break;
1221 return -EBUSY;
1222 case CHAN_MODE_UNDEFINED:
1223 break;
1224 }
1225
Johannes Berg77fdaa12009-07-07 03:45:17 +02001226 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001227}
1228
1229static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001230 struct cfg80211_deauth_request *req,
1231 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001232{
Johannes Berg667503dd2009-07-07 03:56:11 +02001233 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1234 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001235}
1236
1237static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001238 struct cfg80211_disassoc_request *req,
1239 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001240{
Johannes Berg667503dd2009-07-07 03:56:11 +02001241 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1242 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001243}
1244
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001245static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1246 struct cfg80211_ibss_params *params)
1247{
Johannes Bergf444de02010-05-05 15:25:02 +02001248 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001249 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1250
Johannes Bergf444de02010-05-05 15:25:02 +02001251 switch (ieee80211_get_channel_mode(local, sdata)) {
1252 case CHAN_MODE_HOPPING:
1253 return -EBUSY;
1254 case CHAN_MODE_FIXED:
1255 if (!params->channel_fixed)
1256 return -EBUSY;
1257 if (local->oper_channel == params->channel)
1258 break;
1259 return -EBUSY;
1260 case CHAN_MODE_UNDEFINED:
1261 break;
1262 }
1263
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001264 return ieee80211_ibss_join(sdata, params);
1265}
1266
1267static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1268{
1269 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1270
1271 return ieee80211_ibss_leave(sdata);
1272}
1273
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001274static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1275{
1276 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001277 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001278
Lukáš Turek310bc672009-12-21 22:50:48 +01001279 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1280 err = drv_set_coverage_class(local, wiphy->coverage_class);
1281
1282 if (err)
1283 return err;
1284 }
1285
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001286 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001287 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001288
Johannes Berg24487982009-04-23 18:52:52 +02001289 if (err)
1290 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001291 }
1292
1293 if (changed & WIPHY_PARAM_RETRY_SHORT)
1294 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1295 if (changed & WIPHY_PARAM_RETRY_LONG)
1296 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1297 if (changed &
1298 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1299 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1300
1301 return 0;
1302}
1303
Johannes Berg7643a2c2009-06-02 13:01:39 +02001304static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001305 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001306{
1307 struct ieee80211_local *local = wiphy_priv(wiphy);
1308 struct ieee80211_channel *chan = local->hw.conf.channel;
1309 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001310
1311 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001312 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001313 local->user_power_level = -1;
1314 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001315 case NL80211_TX_POWER_LIMITED:
1316 if (mbm < 0 || (mbm % 100))
1317 return -EOPNOTSUPP;
1318 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001319 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001320 case NL80211_TX_POWER_FIXED:
1321 if (mbm < 0 || (mbm % 100))
1322 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001323 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001324 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001325 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001326 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001327 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001328 }
1329
1330 ieee80211_hw_config(local, changes);
1331
1332 return 0;
1333}
1334
1335static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1336{
1337 struct ieee80211_local *local = wiphy_priv(wiphy);
1338
1339 *dbm = local->hw.conf.power_level;
1340
Johannes Berg7643a2c2009-06-02 13:01:39 +02001341 return 0;
1342}
1343
Johannes Bergab737a42009-07-01 21:26:58 +02001344static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1345 u8 *addr)
1346{
1347 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1348
1349 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1350
1351 return 0;
1352}
1353
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001354static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1355{
1356 struct ieee80211_local *local = wiphy_priv(wiphy);
1357
1358 drv_rfkill_poll(local);
1359}
1360
Johannes Bergaff89a92009-07-01 21:26:51 +02001361#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001362static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001363{
1364 struct ieee80211_local *local = wiphy_priv(wiphy);
1365
1366 if (!local->ops->testmode_cmd)
1367 return -EOPNOTSUPP;
1368
1369 return local->ops->testmode_cmd(&local->hw, data, len);
1370}
1371#endif
1372
Johannes Berg0f782312009-12-01 13:37:02 +01001373int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1374 enum ieee80211_smps_mode smps_mode)
1375{
1376 const u8 *ap;
1377 enum ieee80211_smps_mode old_req;
1378 int err;
1379
1380 old_req = sdata->u.mgd.req_smps;
1381 sdata->u.mgd.req_smps = smps_mode;
1382
1383 if (old_req == smps_mode &&
1384 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1385 return 0;
1386
1387 /*
1388 * If not associated, or current association is not an HT
1389 * association, there's no need to send an action frame.
1390 */
1391 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001392 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001393 mutex_lock(&sdata->local->iflist_mtx);
1394 ieee80211_recalc_smps(sdata->local, sdata);
1395 mutex_unlock(&sdata->local->iflist_mtx);
1396 return 0;
1397 }
1398
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001399 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001400
1401 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1402 if (sdata->u.mgd.powersave)
1403 smps_mode = IEEE80211_SMPS_DYNAMIC;
1404 else
1405 smps_mode = IEEE80211_SMPS_OFF;
1406 }
1407
1408 /* send SM PS frame to AP */
1409 err = ieee80211_send_smps_action(sdata, smps_mode,
1410 ap, ap);
1411 if (err)
1412 sdata->u.mgd.req_smps = old_req;
1413
1414 return err;
1415}
1416
Johannes Bergbc92afd2009-07-01 21:26:57 +02001417static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1418 bool enabled, int timeout)
1419{
1420 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1421 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001422
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001423 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1424 return -EOPNOTSUPP;
1425
Johannes Bergbc92afd2009-07-01 21:26:57 +02001426 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1427 return -EOPNOTSUPP;
1428
1429 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001430 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001431 return 0;
1432
1433 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001434 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001435
Johannes Berg0f782312009-12-01 13:37:02 +01001436 /* no change, but if automatic follow powersave */
1437 mutex_lock(&sdata->u.mgd.mtx);
1438 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1439 mutex_unlock(&sdata->u.mgd.mtx);
1440
Johannes Bergbc92afd2009-07-01 21:26:57 +02001441 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1442 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1443
1444 ieee80211_recalc_ps(local, -1);
1445
1446 return 0;
1447}
1448
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001449static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1450 struct net_device *dev,
1451 s32 rssi_thold, u32 rssi_hyst)
1452{
1453 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1454 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1455 struct ieee80211_vif *vif = &sdata->vif;
1456 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1457
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001458 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1459 rssi_hyst == bss_conf->cqm_rssi_hyst)
1460 return 0;
1461
1462 bss_conf->cqm_rssi_thold = rssi_thold;
1463 bss_conf->cqm_rssi_hyst = rssi_hyst;
1464
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001465 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1466 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1467 return -EOPNOTSUPP;
1468 return 0;
1469 }
1470
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001471 /* tell the driver upon association, unless already associated */
1472 if (sdata->u.mgd.associated)
1473 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1474
1475 return 0;
1476}
1477
Johannes Berg99303802009-07-01 21:26:59 +02001478static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1479 struct net_device *dev,
1480 const u8 *addr,
1481 const struct cfg80211_bitrate_mask *mask)
1482{
1483 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1484 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001485 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001486
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001487 /*
1488 * This _could_ be supported by providing a hook for
1489 * drivers for this function, but at this point it
1490 * doesn't seem worth bothering.
1491 */
1492 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1493 return -EOPNOTSUPP;
1494
Johannes Berg99303802009-07-01 21:26:59 +02001495
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001496 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1497 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001498
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001499 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001500}
1501
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001502static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1503 struct net_device *dev,
1504 struct ieee80211_channel *chan,
1505 enum nl80211_channel_type channel_type,
1506 unsigned int duration,
1507 u64 *cookie)
1508{
1509 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1510
1511 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1512 duration, cookie);
1513}
1514
1515static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1516 struct net_device *dev,
1517 u64 cookie)
1518{
1519 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1520
1521 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1522}
1523
Johannes Berg2e161f72010-08-12 15:38:38 +02001524static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1525 struct ieee80211_channel *chan,
1526 enum nl80211_channel_type channel_type,
1527 bool channel_type_valid,
1528 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001529{
Johannes Berg9d38d852010-06-09 17:20:33 +02001530 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1531 struct ieee80211_local *local = sdata->local;
1532 struct sk_buff *skb;
1533 struct sta_info *sta;
1534 const struct ieee80211_mgmt *mgmt = (void *)buf;
1535 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1536 IEEE80211_TX_CTL_REQ_TX_STATUS;
1537
1538 /* Check that we are on the requested channel for transmission */
1539 if (chan != local->tmp_channel &&
1540 chan != local->oper_channel)
1541 return -EBUSY;
1542 if (channel_type_valid &&
1543 (channel_type != local->tmp_channel_type &&
1544 channel_type != local->_oper_channel_type))
1545 return -EBUSY;
1546
1547 switch (sdata->vif.type) {
1548 case NL80211_IFTYPE_ADHOC:
1549 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
1550 break;
1551 rcu_read_lock();
1552 sta = sta_info_get(sdata, mgmt->da);
1553 rcu_read_unlock();
1554 if (!sta)
1555 return -ENOLINK;
1556 break;
1557 case NL80211_IFTYPE_STATION:
Johannes Berg9d38d852010-06-09 17:20:33 +02001558 break;
1559 default:
1560 return -EOPNOTSUPP;
1561 }
1562
1563 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1564 if (!skb)
1565 return -ENOMEM;
1566 skb_reserve(skb, local->hw.extra_tx_headroom);
1567
1568 memcpy(skb_put(skb, len), buf, len);
1569
1570 IEEE80211_SKB_CB(skb)->flags = flags;
1571
1572 skb->dev = sdata->dev;
1573 ieee80211_tx_skb(sdata, skb);
1574
1575 *cookie = (unsigned long) skb;
1576 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001577}
1578
Jiri Bencf0706e82007-05-05 11:45:53 -07001579struct cfg80211_ops mac80211_config_ops = {
1580 .add_virtual_intf = ieee80211_add_iface,
1581 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001582 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001583 .add_key = ieee80211_add_key,
1584 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001585 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001586 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001587 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001588 .add_beacon = ieee80211_add_beacon,
1589 .set_beacon = ieee80211_set_beacon,
1590 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001591 .add_station = ieee80211_add_station,
1592 .del_station = ieee80211_del_station,
1593 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001594 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001595 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001596 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001597#ifdef CONFIG_MAC80211_MESH
1598 .add_mpath = ieee80211_add_mpath,
1599 .del_mpath = ieee80211_del_mpath,
1600 .change_mpath = ieee80211_change_mpath,
1601 .get_mpath = ieee80211_get_mpath,
1602 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001603 .set_mesh_params = ieee80211_set_mesh_params,
1604 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001605#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001606 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001607 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001608 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001609 .suspend = ieee80211_suspend,
1610 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001611 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001612 .auth = ieee80211_auth,
1613 .assoc = ieee80211_assoc,
1614 .deauth = ieee80211_deauth,
1615 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001616 .join_ibss = ieee80211_join_ibss,
1617 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001618 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001619 .set_tx_power = ieee80211_set_tx_power,
1620 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001621 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001622 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001623 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001624 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001625 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001626 .remain_on_channel = ieee80211_remain_on_channel,
1627 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001628 .mgmt_tx = ieee80211_mgmt_tx,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001629 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Jiri Bencf0706e82007-05-05 11:45:53 -07001630};