blob: f82b18e996b23a0ec9ae2c3b2ffc83603b50efb3 [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
Jiri Bencf0706e82007-05-05 11:45:53 -070022static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010023 enum nl80211_iftype type, u32 *flags,
24 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070025{
26 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010027 struct net_device *dev;
28 struct ieee80211_sub_if_data *sdata;
29 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070030
Johannes Berg05c914f2008-09-11 00:01:58 +020031 err = ieee80211_if_add(local, name, &dev, type, params);
32 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010033 return err;
34
35 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
36 sdata->u.mntr_flags = *flags;
37 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070038}
39
Johannes Berg463d0182009-07-14 00:33:35 +020040static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e82007-05-05 11:45:53 -070041{
Johannes Berg463d0182009-07-14 00:33:35 +020042 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e82007-05-05 11:45:53 -070043
Johannes Berg75636522008-07-09 14:40:35 +020044 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070045}
46
Johannes Berge36d56b2009-06-09 21:04:43 +020047static int ieee80211_change_iface(struct wiphy *wiphy,
48 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010049 enum nl80211_iftype type, u32 *flags,
50 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020051{
Johannes Berg9607e6b2009-12-23 13:15:31 +010052 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020053 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020054
Johannes Berg9607e6b2009-12-23 13:15:31 +010055 if (ieee80211_sdata_running(sdata))
Johannes Bergc1f9a762009-11-01 19:25:40 +010056 return -EBUSY;
57
Johannes Berg05c914f2008-09-11 00:01:58 +020058 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 if (ret)
60 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020061
Johannes Berg902acc72008-02-23 15:17:19 +010062 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020063 ieee80211_sdata_set_mesh_id(sdata,
64 params->mesh_id_len,
65 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010066
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0)
69 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
70 else if (type == NL80211_IFTYPE_STATION &&
71 params && params->use_4addr >= 0)
72 sdata->u.mgd.use_4addr = params->use_4addr;
73
Felix Fietkauf7917af2010-04-27 00:26:34 +020074 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
75 sdata->u.mntr_flags = *flags;
76
Johannes Berg42613db2007-09-28 21:52:27 +020077 return 0;
78}
79
Johannes Berge8cbb4c2007-12-19 02:03:30 +010080static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +020081 u8 key_idx, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +010082 struct key_params *params)
83{
Johannes Berg26a58452010-08-27 12:35:55 +020084 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +010085 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +010086 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +020087 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +010088
Johannes Berg26a58452010-08-27 12:35:55 +020089 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +020090 return -ENETDOWN;
91
Johannes Berg97359d12010-08-10 09:46:38 +020092 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +010093 switch (params->cipher) {
94 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +010095 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +020096 case WLAN_CIPHER_SUITE_WEP104:
97 if (IS_ERR(sdata->local->wep_tx_tfm))
98 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +020099 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100100 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200101 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100102 }
103
Johannes Berg97359d12010-08-10 09:46:38 +0200104 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
105 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100106 if (IS_ERR(key))
107 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100108
Johannes Bergad0e2b52010-06-01 10:19:19 +0200109 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200110
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100111 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100112 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100113 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700114 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200115 err = -ENOENT;
116 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100117 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100118 }
119
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300120 err = ieee80211_key_link(key, sdata, sta);
121 if (err)
122 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100123
Johannes Berg3b967662008-04-08 17:56:52 +0200124 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200125 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200126
127 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128}
129
130static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200131 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100132{
133 struct ieee80211_sub_if_data *sdata;
134 struct sta_info *sta;
135 int ret;
136
137 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
138
Johannes Bergad0e2b52010-06-01 10:19:19 +0200139 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200140
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100141 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200142 ret = -ENOENT;
143
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100144 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100145 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200146 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100147
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 if (sta->key) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700149 ieee80211_key_free(sdata->local, sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200151 ret = 0;
152 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153
Johannes Berg3b967662008-04-08 17:56:52 +0200154 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100155 }
156
Johannes Berg3b967662008-04-08 17:56:52 +0200157 if (!sdata->keys[key_idx]) {
158 ret = -ENOENT;
159 goto out_unlock;
160 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100161
Jouni Malinen32162a42010-07-26 15:52:03 -0700162 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100163 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100164
Johannes Berg3b967662008-04-08 17:56:52 +0200165 ret = 0;
166 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200167 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200168
169 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100170}
171
Johannes Berg62da92f2007-12-19 02:03:31 +0100172static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200173 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100174 void (*callback)(void *cookie,
175 struct key_params *params))
176{
Johannes Berg14db74b2008-07-29 13:22:52 +0200177 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100178 struct sta_info *sta = NULL;
179 u8 seq[6] = {0};
180 struct key_params params;
181 struct ieee80211_key *key;
182 u32 iv32;
183 u16 iv16;
184 int err = -ENOENT;
185
Johannes Berg14db74b2008-07-29 13:22:52 +0200186 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
187
Johannes Berg3b967662008-04-08 17:56:52 +0200188 rcu_read_lock();
189
Johannes Berg62da92f2007-12-19 02:03:31 +0100190 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100191 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100192 if (!sta)
193 goto out;
194
195 key = sta->key;
196 } else
197 key = sdata->keys[key_idx];
198
199 if (!key)
200 goto out;
201
202 memset(&params, 0, sizeof(params));
203
Johannes Berg97359d12010-08-10 09:46:38 +0200204 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100205
Johannes Berg97359d12010-08-10 09:46:38 +0200206 switch (key->conf.cipher) {
207 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700208 iv32 = key->u.tkip.tx.iv32;
209 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100210
Johannes Berg24487982009-04-23 18:52:52 +0200211 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
212 drv_get_tkip_seq(sdata->local,
213 key->conf.hw_key_idx,
214 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100215
216 seq[0] = iv16 & 0xff;
217 seq[1] = (iv16 >> 8) & 0xff;
218 seq[2] = iv32 & 0xff;
219 seq[3] = (iv32 >> 8) & 0xff;
220 seq[4] = (iv32 >> 16) & 0xff;
221 seq[5] = (iv32 >> 24) & 0xff;
222 params.seq = seq;
223 params.seq_len = 6;
224 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200225 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100226 seq[0] = key->u.ccmp.tx_pn[5];
227 seq[1] = key->u.ccmp.tx_pn[4];
228 seq[2] = key->u.ccmp.tx_pn[3];
229 seq[3] = key->u.ccmp.tx_pn[2];
230 seq[4] = key->u.ccmp.tx_pn[1];
231 seq[5] = key->u.ccmp.tx_pn[0];
232 params.seq = seq;
233 params.seq_len = 6;
234 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200235 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200236 seq[0] = key->u.aes_cmac.tx_pn[5];
237 seq[1] = key->u.aes_cmac.tx_pn[4];
238 seq[2] = key->u.aes_cmac.tx_pn[3];
239 seq[3] = key->u.aes_cmac.tx_pn[2];
240 seq[4] = key->u.aes_cmac.tx_pn[1];
241 seq[5] = key->u.aes_cmac.tx_pn[0];
242 params.seq = seq;
243 params.seq_len = 6;
244 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100245 }
246
247 params.key = key->conf.key;
248 params.key_len = key->conf.keylen;
249
250 callback(cookie, &params);
251 err = 0;
252
253 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200254 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100255 return err;
256}
257
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100258static int ieee80211_config_default_key(struct wiphy *wiphy,
259 struct net_device *dev,
260 u8 key_idx)
261{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100263
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100264 ieee80211_set_default_key(sdata, key_idx);
265
266 return 0;
267}
268
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200269static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
270 struct net_device *dev,
271 u8 key_idx)
272{
Johannes Berg66c52422010-07-22 13:58:51 +0200273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200274
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200275 ieee80211_set_default_mgmt_key(sdata, key_idx);
276
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200277 return 0;
278}
279
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100280static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
281{
Johannes Bergd0709a62008-02-25 16:27:46 +0100282 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100283
Johannes Bergf5ea9122009-08-07 16:17:38 +0200284 sinfo->generation = sdata->local->sta_generation;
285
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100286 sinfo->filled = STATION_INFO_INACTIVE_TIME |
287 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100288 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200289 STATION_INFO_RX_PACKETS |
290 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100291 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100292
293 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
294 sinfo->rx_bytes = sta->rx_bytes;
295 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200296 sinfo->rx_packets = sta->rx_packets;
297 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100298
John W. Linville19deffb2009-12-08 17:10:13 -0500299 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
300 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Henning Rogge420e7fa2008-12-11 22:04:19 +0100301 sinfo->filled |= STATION_INFO_SIGNAL;
302 sinfo->signal = (s8)sta->last_signal;
303 }
304
305 sinfo->txrate.flags = 0;
306 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
307 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
308 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
309 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
310 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
311 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
312
313 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
314 struct ieee80211_supported_band *sband;
315 sband = sta->local->hw.wiphy->bands[
316 sta->local->hw.conf.channel->band];
317 sinfo->txrate.legacy =
318 sband->bitrates[sta->last_tx_rate.idx].bitrate;
319 } else
320 sinfo->txrate.mcs = sta->last_tx_rate.idx;
321
Johannes Berg902acc72008-02-23 15:17:19 +0100322 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100323#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100324 sinfo->filled |= STATION_INFO_LLID |
325 STATION_INFO_PLID |
326 STATION_INFO_PLINK_STATE;
327
328 sinfo->llid = le16_to_cpu(sta->llid);
329 sinfo->plid = le16_to_cpu(sta->plid);
330 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100331#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100332 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333}
334
335
336static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
337 int idx, u8 *mac, struct station_info *sinfo)
338{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100339 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100340 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100341 int ret = -ENOENT;
342
343 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100344
Johannes Berg3b53fde82009-11-16 12:00:37 +0100345 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100346 if (sta) {
347 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200348 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100349 sta_set_sinfo(sta, sinfo);
350 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100351
Johannes Bergd0709a62008-02-25 16:27:46 +0100352 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100353
Johannes Bergd0709a62008-02-25 16:27:46 +0100354 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100355}
356
Holger Schurig12897232010-04-19 10:23:57 +0200357static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
358 int idx, struct survey_info *survey)
359{
360 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
361
Holger Schurig12897232010-04-19 10:23:57 +0200362 return drv_get_survey(local, idx, survey);
363}
364
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100365static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100366 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100367{
Johannes Bergabe60632009-11-25 17:46:18 +0100368 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100369 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100370 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100371
Johannes Bergd0709a62008-02-25 16:27:46 +0100372 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100373
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100374 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100375 if (sta) {
376 ret = 0;
377 sta_set_sinfo(sta, sinfo);
378 }
379
380 rcu_read_unlock();
381
382 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100383}
384
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100385/*
386 * This handles both adding a beacon and setting new beacon info
387 */
388static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
389 struct beacon_parameters *params)
390{
391 struct beacon_data *new, *old;
392 int new_head_len, new_tail_len;
393 int size;
394 int err = -EINVAL;
395
396 old = sdata->u.ap.beacon;
397
398 /* head must not be zero-length */
399 if (params->head && !params->head_len)
400 return -EINVAL;
401
402 /*
403 * This is a kludge. beacon interval should really be part
404 * of the beacon information.
405 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200406 if (params->interval &&
407 (sdata->vif.bss_conf.beacon_int != params->interval)) {
408 sdata->vif.bss_conf.beacon_int = params->interval;
409 ieee80211_bss_info_change_notify(sdata,
410 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100411 }
412
413 /* Need to have a beacon head if we don't have one yet */
414 if (!params->head && !old)
415 return err;
416
417 /* sorry, no way to start beaconing without dtim period */
418 if (!params->dtim_period && !old)
419 return err;
420
421 /* new or old head? */
422 if (params->head)
423 new_head_len = params->head_len;
424 else
425 new_head_len = old->head_len;
426
427 /* new or old tail? */
428 if (params->tail || !old)
429 /* params->tail_len will be zero for !params->tail */
430 new_tail_len = params->tail_len;
431 else
432 new_tail_len = old->tail_len;
433
434 size = sizeof(*new) + new_head_len + new_tail_len;
435
436 new = kzalloc(size, GFP_KERNEL);
437 if (!new)
438 return -ENOMEM;
439
440 /* start filling the new info now */
441
442 /* new or old dtim period? */
443 if (params->dtim_period)
444 new->dtim_period = params->dtim_period;
445 else
446 new->dtim_period = old->dtim_period;
447
448 /*
449 * pointers go into the block we allocated,
450 * memory is | beacon_data | head | tail |
451 */
452 new->head = ((u8 *) new) + sizeof(*new);
453 new->tail = new->head + new_head_len;
454 new->head_len = new_head_len;
455 new->tail_len = new_tail_len;
456
457 /* copy in head */
458 if (params->head)
459 memcpy(new->head, params->head, new_head_len);
460 else
461 memcpy(new->head, old->head, new_head_len);
462
463 /* copy in optional tail */
464 if (params->tail)
465 memcpy(new->tail, params->tail, new_tail_len);
466 else
467 if (old)
468 memcpy(new->tail, old->tail, new_tail_len);
469
Johannes Berg19885c42010-02-05 11:45:06 +0100470 sdata->vif.bss_conf.dtim_period = new->dtim_period;
471
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100472 rcu_assign_pointer(sdata->u.ap.beacon, new);
473
474 synchronize_rcu();
475
476 kfree(old);
477
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200478 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
479 BSS_CHANGED_BEACON);
480 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100481}
482
483static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
484 struct beacon_parameters *params)
485{
Johannes Berg14db74b2008-07-29 13:22:52 +0200486 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100487 struct beacon_data *old;
488
Johannes Berg14db74b2008-07-29 13:22:52 +0200489 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
490
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100491 old = sdata->u.ap.beacon;
492
493 if (old)
494 return -EALREADY;
495
496 return ieee80211_config_beacon(sdata, params);
497}
498
499static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
500 struct beacon_parameters *params)
501{
Johannes Berg14db74b2008-07-29 13:22:52 +0200502 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100503 struct beacon_data *old;
504
Johannes Berg14db74b2008-07-29 13:22:52 +0200505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
506
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100507 old = sdata->u.ap.beacon;
508
509 if (!old)
510 return -ENOENT;
511
512 return ieee80211_config_beacon(sdata, params);
513}
514
515static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
516{
Johannes Berg14db74b2008-07-29 13:22:52 +0200517 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100518 struct beacon_data *old;
519
Johannes Berg14db74b2008-07-29 13:22:52 +0200520 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
521
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100522 old = sdata->u.ap.beacon;
523
524 if (!old)
525 return -ENOENT;
526
527 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
528 synchronize_rcu();
529 kfree(old);
530
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200531 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
532 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100533}
534
Johannes Berg4fd69312007-12-19 02:03:35 +0100535/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
536struct iapp_layer2_update {
537 u8 da[ETH_ALEN]; /* broadcast */
538 u8 sa[ETH_ALEN]; /* STA addr */
539 __be16 len; /* 6 */
540 u8 dsap; /* 0 */
541 u8 ssap; /* 0 */
542 u8 control;
543 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700544} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100545
546static void ieee80211_send_layer2_update(struct sta_info *sta)
547{
548 struct iapp_layer2_update *msg;
549 struct sk_buff *skb;
550
551 /* Send Level 2 Update Frame to update forwarding tables in layer 2
552 * bridge devices */
553
554 skb = dev_alloc_skb(sizeof(*msg));
555 if (!skb)
556 return;
557 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
558
559 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
560 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
561
562 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200563 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100564 msg->len = htons(6);
565 msg->dsap = 0;
566 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
567 msg->control = 0xaf; /* XID response lsb.1111F101.
568 * F=0 (no poll command; unsolicited frame) */
569 msg->xid_info[0] = 0x81; /* XID format identifier */
570 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
571 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
572
Johannes Bergd0709a62008-02-25 16:27:46 +0100573 skb->dev = sta->sdata->dev;
574 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100575 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400576 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100577}
578
579static void sta_apply_parameters(struct ieee80211_local *local,
580 struct sta_info *sta,
581 struct station_parameters *params)
582{
583 u32 rates;
584 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100585 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100586 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300587 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100588
Johannes Bergae5eb022008-10-14 16:58:37 +0200589 sband = local->hw.wiphy->bands[local->oper_channel->band];
590
Johannes Bergeccb8e82009-05-11 21:57:56 +0300591 spin_lock_bh(&sta->lock);
592 mask = params->sta_flags_mask;
593 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100594
Johannes Bergeccb8e82009-05-11 21:57:56 +0300595 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100596 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300597 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100598 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100599 }
600
Johannes Bergeccb8e82009-05-11 21:57:56 +0300601 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
602 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
603 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
604 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
605 }
606
607 if (mask & BIT(NL80211_STA_FLAG_WME)) {
608 sta->flags &= ~WLAN_STA_WME;
609 if (set & BIT(NL80211_STA_FLAG_WME))
610 sta->flags |= WLAN_STA_WME;
611 }
612
613 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
614 sta->flags &= ~WLAN_STA_MFP;
615 if (set & BIT(NL80211_STA_FLAG_MFP))
616 sta->flags |= WLAN_STA_MFP;
617 }
618 spin_unlock_bh(&sta->lock);
619
Johannes Berg73651ee2008-02-25 16:27:47 +0100620 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200621 * cfg80211 validates this (1-2007) and allows setting the AID
622 * only when creating a new station entry
623 */
624 if (params->aid)
625 sta->sta.aid = params->aid;
626
627 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100628 * FIXME: updating the following information is racy when this
629 * function is called from ieee80211_change_station().
630 * However, all this information should be static so
631 * maybe we should just reject attemps to change it.
632 */
633
Johannes Berg4fd69312007-12-19 02:03:35 +0100634 if (params->listen_interval >= 0)
635 sta->listen_interval = params->listen_interval;
636
637 if (params->supported_rates) {
638 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100639
Johannes Berg4fd69312007-12-19 02:03:35 +0100640 for (i = 0; i < params->supported_rates_len; i++) {
641 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100642 for (j = 0; j < sband->n_bitrates; j++) {
643 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100644 rates |= BIT(j);
645 }
646 }
Johannes Berg323ce792008-09-11 02:45:11 +0200647 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100648 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100649
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200650 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200651 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
652 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200653 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300654
Johannes Berg902acc72008-02-23 15:17:19 +0100655 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100656 switch (params->plink_action) {
657 case PLINK_ACTION_OPEN:
658 mesh_plink_open(sta);
659 break;
660 case PLINK_ACTION_BLOCK:
661 mesh_plink_block(sta);
662 break;
663 }
Johannes Berg902acc72008-02-23 15:17:19 +0100664 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100665}
666
667static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
668 u8 *mac, struct station_parameters *params)
669{
Johannes Berg14db74b2008-07-29 13:22:52 +0200670 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100671 struct sta_info *sta;
672 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100673 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200674 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100675
Johannes Berg4fd69312007-12-19 02:03:35 +0100676 if (params->vlan) {
677 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
678
Johannes Berg05c914f2008-09-11 00:01:58 +0200679 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
680 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100681 return -EINVAL;
682 } else
683 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
684
Johannes Berg47846c92009-11-25 17:46:19 +0100685 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100686 return -EINVAL;
687
688 if (is_multicast_ether_addr(mac))
689 return -EINVAL;
690
691 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100692 if (!sta)
693 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100694
695 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
696
697 sta_apply_parameters(local, sta, params);
698
Johannes Berg4b7679a2008-09-18 18:14:18 +0200699 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100700
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200701 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
702 sdata->vif.type == NL80211_IFTYPE_AP;
703
Johannes Berg34e89502010-02-03 13:59:58 +0100704 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100705 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100706 rcu_read_unlock();
707 return err;
708 }
709
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200710 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100711 ieee80211_send_layer2_update(sta);
712
713 rcu_read_unlock();
714
Johannes Berg4fd69312007-12-19 02:03:35 +0100715 return 0;
716}
717
718static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
719 u8 *mac)
720{
Johannes Berg14db74b2008-07-29 13:22:52 +0200721 struct ieee80211_local *local = wiphy_priv(wiphy);
722 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100723
Johannes Berg14db74b2008-07-29 13:22:52 +0200724 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
725
Johannes Berg34e89502010-02-03 13:59:58 +0100726 if (mac)
727 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200728
Johannes Berg34e89502010-02-03 13:59:58 +0100729 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100730 return 0;
731}
732
733static int ieee80211_change_station(struct wiphy *wiphy,
734 struct net_device *dev,
735 u8 *mac,
736 struct station_parameters *params)
737{
Johannes Bergabe60632009-11-25 17:46:18 +0100738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200739 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100740 struct sta_info *sta;
741 struct ieee80211_sub_if_data *vlansdata;
742
Johannes Berg98dd6a52008-04-10 15:36:09 +0200743 rcu_read_lock();
744
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100745 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200746 if (!sta) {
747 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100748 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200749 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100750
Johannes Bergd0709a62008-02-25 16:27:46 +0100751 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100752 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
753
Johannes Berg05c914f2008-09-11 00:01:58 +0200754 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
755 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200756 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100757 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200758 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100759
Johannes Berg9bc383d2009-11-19 11:55:19 +0100760 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100761 if (vlansdata->u.vlan.sta) {
762 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100763 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100764 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100765
766 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
767 }
768
Johannes Berg14db74b2008-07-29 13:22:52 +0200769 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100770 ieee80211_send_layer2_update(sta);
771 }
772
773 sta_apply_parameters(local, sta, params);
774
Johannes Berg98dd6a52008-04-10 15:36:09 +0200775 rcu_read_unlock();
776
Johannes Berg4fd69312007-12-19 02:03:35 +0100777 return 0;
778}
779
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100780#ifdef CONFIG_MAC80211_MESH
781static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
782 u8 *dst, u8 *next_hop)
783{
Johannes Berg14db74b2008-07-29 13:22:52 +0200784 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100785 struct mesh_path *mpath;
786 struct sta_info *sta;
787 int err;
788
Johannes Berg14db74b2008-07-29 13:22:52 +0200789 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
790
Johannes Bergd0709a62008-02-25 16:27:46 +0100791 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100792 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100793 if (!sta) {
794 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100795 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100796 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200798 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100799 if (err) {
800 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100801 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100802 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100803
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200804 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100805 if (!mpath) {
806 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100807 return -ENXIO;
808 }
809 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100810
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100811 rcu_read_unlock();
812 return 0;
813}
814
815static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
816 u8 *dst)
817{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200818 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100819
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200820 if (dst)
821 return mesh_path_del(dst, sdata);
822
823 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100824 return 0;
825}
826
827static int ieee80211_change_mpath(struct wiphy *wiphy,
828 struct net_device *dev,
829 u8 *dst, u8 *next_hop)
830{
Johannes Berg14db74b2008-07-29 13:22:52 +0200831 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100832 struct mesh_path *mpath;
833 struct sta_info *sta;
834
Johannes Berg14db74b2008-07-29 13:22:52 +0200835 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
836
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100837 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100838
Johannes Bergabe60632009-11-25 17:46:18 +0100839 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100840 if (!sta) {
841 rcu_read_unlock();
842 return -ENOENT;
843 }
844
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200845 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100846 if (!mpath) {
847 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100848 return -ENOENT;
849 }
850
851 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100852
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853 rcu_read_unlock();
854 return 0;
855}
856
857static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
858 struct mpath_info *pinfo)
859{
860 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200861 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100862 else
863 memset(next_hop, 0, ETH_ALEN);
864
Johannes Bergf5ea9122009-08-07 16:17:38 +0200865 pinfo->generation = mesh_paths_generation;
866
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100867 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000868 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100869 MPATH_INFO_METRIC |
870 MPATH_INFO_EXPTIME |
871 MPATH_INFO_DISCOVERY_TIMEOUT |
872 MPATH_INFO_DISCOVERY_RETRIES |
873 MPATH_INFO_FLAGS;
874
875 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000876 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100877 pinfo->metric = mpath->metric;
878 if (time_before(jiffies, mpath->exp_time))
879 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
880 pinfo->discovery_timeout =
881 jiffies_to_msecs(mpath->discovery_timeout);
882 pinfo->discovery_retries = mpath->discovery_retries;
883 pinfo->flags = 0;
884 if (mpath->flags & MESH_PATH_ACTIVE)
885 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
886 if (mpath->flags & MESH_PATH_RESOLVING)
887 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000888 if (mpath->flags & MESH_PATH_SN_VALID)
889 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100890 if (mpath->flags & MESH_PATH_FIXED)
891 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
892 if (mpath->flags & MESH_PATH_RESOLVING)
893 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
894
895 pinfo->flags = mpath->flags;
896}
897
898static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
899 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
900
901{
Johannes Berg14db74b2008-07-29 13:22:52 +0200902 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 struct mesh_path *mpath;
904
Johannes Berg14db74b2008-07-29 13:22:52 +0200905 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
906
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100907 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200908 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100909 if (!mpath) {
910 rcu_read_unlock();
911 return -ENOENT;
912 }
913 memcpy(dst, mpath->dst, ETH_ALEN);
914 mpath_set_pinfo(mpath, next_hop, pinfo);
915 rcu_read_unlock();
916 return 0;
917}
918
919static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
920 int idx, u8 *dst, u8 *next_hop,
921 struct mpath_info *pinfo)
922{
Johannes Berg14db74b2008-07-29 13:22:52 +0200923 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100924 struct mesh_path *mpath;
925
Johannes Berg14db74b2008-07-29 13:22:52 +0200926 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
927
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100928 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200929 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100930 if (!mpath) {
931 rcu_read_unlock();
932 return -ENOENT;
933 }
934 memcpy(dst, mpath->dst, ETH_ALEN);
935 mpath_set_pinfo(mpath, next_hop, pinfo);
936 rcu_read_unlock();
937 return 0;
938}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700939
940static int ieee80211_get_mesh_params(struct wiphy *wiphy,
941 struct net_device *dev,
942 struct mesh_config *conf)
943{
944 struct ieee80211_sub_if_data *sdata;
945 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
946
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700947 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
948 return 0;
949}
950
951static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
952{
953 return (mask >> (parm-1)) & 0x1;
954}
955
956static int ieee80211_set_mesh_params(struct wiphy *wiphy,
957 struct net_device *dev,
958 const struct mesh_config *nconf, u32 mask)
959{
960 struct mesh_config *conf;
961 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +0000962 struct ieee80211_if_mesh *ifmsh;
963
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700964 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +0000965 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700966
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700967 /* Set the config options which we are interested in setting */
968 conf = &(sdata->u.mesh.mshcfg);
969 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
970 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
971 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
972 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
973 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
974 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
975 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
976 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
977 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
978 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
979 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
980 conf->dot11MeshTTL = nconf->dot11MeshTTL;
981 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
982 conf->auto_open_plinks = nconf->auto_open_plinks;
983 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
984 conf->dot11MeshHWMPmaxPREQretries =
985 nconf->dot11MeshHWMPmaxPREQretries;
986 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
987 conf->path_refresh_time = nconf->path_refresh_time;
988 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
989 conf->min_discovery_timeout = nconf->min_discovery_timeout;
990 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
991 conf->dot11MeshHWMPactivePathTimeout =
992 nconf->dot11MeshHWMPactivePathTimeout;
993 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
994 conf->dot11MeshHWMPpreqMinInterval =
995 nconf->dot11MeshHWMPpreqMinInterval;
996 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
997 mask))
998 conf->dot11MeshHWMPnetDiameterTraversalTime =
999 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001000 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1001 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1002 ieee80211_mesh_root_setup(ifmsh);
1003 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001004 return 0;
1005}
1006
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001007#endif
1008
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001009static int ieee80211_change_bss(struct wiphy *wiphy,
1010 struct net_device *dev,
1011 struct bss_parameters *params)
1012{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001013 struct ieee80211_sub_if_data *sdata;
1014 u32 changed = 0;
1015
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001016 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1017
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001018 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001019 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001020 changed |= BSS_CHANGED_ERP_CTS_PROT;
1021 }
1022 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001023 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001024 params->use_short_preamble;
1025 changed |= BSS_CHANGED_ERP_PREAMBLE;
1026 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001027
1028 if (!sdata->vif.bss_conf.use_short_slot &&
1029 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1030 sdata->vif.bss_conf.use_short_slot = true;
1031 changed |= BSS_CHANGED_ERP_SLOT;
1032 }
1033
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001034 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001035 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001036 params->use_short_slot_time;
1037 changed |= BSS_CHANGED_ERP_SLOT;
1038 }
1039
Jouni Malinen90c97a02008-10-30 16:59:22 +02001040 if (params->basic_rates) {
1041 int i, j;
1042 u32 rates = 0;
1043 struct ieee80211_local *local = wiphy_priv(wiphy);
1044 struct ieee80211_supported_band *sband =
1045 wiphy->bands[local->oper_channel->band];
1046
1047 for (i = 0; i < params->basic_rates_len; i++) {
1048 int rate = (params->basic_rates[i] & 0x7f) * 5;
1049 for (j = 0; j < sband->n_bitrates; j++) {
1050 if (sband->bitrates[j].bitrate == rate)
1051 rates |= BIT(j);
1052 }
1053 }
1054 sdata->vif.bss_conf.basic_rates = rates;
1055 changed |= BSS_CHANGED_BASIC_RATES;
1056 }
1057
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001058 if (params->ap_isolate >= 0) {
1059 if (params->ap_isolate)
1060 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1061 else
1062 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1063 }
1064
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001065 ieee80211_bss_info_change_notify(sdata, changed);
1066
1067 return 0;
1068}
1069
Jouni Malinen31888482008-10-30 16:59:24 +02001070static int ieee80211_set_txq_params(struct wiphy *wiphy,
1071 struct ieee80211_txq_params *params)
1072{
1073 struct ieee80211_local *local = wiphy_priv(wiphy);
1074 struct ieee80211_tx_queue_params p;
1075
1076 if (!local->ops->conf_tx)
1077 return -EOPNOTSUPP;
1078
1079 memset(&p, 0, sizeof(p));
1080 p.aifs = params->aifs;
1081 p.cw_max = params->cwmax;
1082 p.cw_min = params->cwmin;
1083 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001084
1085 /*
1086 * Setting tx queue params disables u-apsd because it's only
1087 * called in master mode.
1088 */
1089 p.uapsd = false;
1090
Johannes Berg24487982009-04-23 18:52:52 +02001091 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001092 wiphy_debug(local->hw.wiphy,
1093 "failed to set TX queue parameters for queue %d\n",
1094 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001095 return -EINVAL;
1096 }
1097
1098 return 0;
1099}
1100
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001101static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001102 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001103 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301104 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001105{
1106 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001107 struct ieee80211_sub_if_data *sdata = NULL;
1108
1109 if (netdev)
1110 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001111
Johannes Bergf444de02010-05-05 15:25:02 +02001112 switch (ieee80211_get_channel_mode(local, NULL)) {
1113 case CHAN_MODE_HOPPING:
1114 return -EBUSY;
1115 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001116 if (local->oper_channel != chan)
1117 return -EBUSY;
1118 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001119 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001120 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001121 case CHAN_MODE_UNDEFINED:
1122 break;
1123 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001124
1125 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001126
Johannes Berg0aaffa92010-05-05 15:28:27 +02001127 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1128 return -EBUSY;
1129
1130 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1131 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1132 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1133
1134 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001135}
1136
Bob Copeland665af4f2009-01-19 11:20:53 -05001137#ifdef CONFIG_PM
1138static int ieee80211_suspend(struct wiphy *wiphy)
1139{
1140 return __ieee80211_suspend(wiphy_priv(wiphy));
1141}
1142
1143static int ieee80211_resume(struct wiphy *wiphy)
1144{
1145 return __ieee80211_resume(wiphy_priv(wiphy));
1146}
1147#else
1148#define ieee80211_suspend NULL
1149#define ieee80211_resume NULL
1150#endif
1151
Johannes Berg2a519312009-02-10 21:25:55 +01001152static int ieee80211_scan(struct wiphy *wiphy,
1153 struct net_device *dev,
1154 struct cfg80211_scan_request *req)
1155{
1156 struct ieee80211_sub_if_data *sdata;
1157
Johannes Berg2a519312009-02-10 21:25:55 +01001158 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1159
1160 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1161 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinen357303e2009-04-16 18:44:53 +03001162 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1163 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
Johannes Berg2a519312009-02-10 21:25:55 +01001164 return -EOPNOTSUPP;
1165
1166 return ieee80211_request_scan(sdata, req);
1167}
1168
Jouni Malinen636a5d32009-03-19 13:39:22 +02001169static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1170 struct cfg80211_auth_request *req)
1171{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001172 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001173}
1174
1175static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1176 struct cfg80211_assoc_request *req)
1177{
Johannes Bergf444de02010-05-05 15:25:02 +02001178 struct ieee80211_local *local = wiphy_priv(wiphy);
1179 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1180
1181 switch (ieee80211_get_channel_mode(local, sdata)) {
1182 case CHAN_MODE_HOPPING:
1183 return -EBUSY;
1184 case CHAN_MODE_FIXED:
1185 if (local->oper_channel == req->bss->channel)
1186 break;
1187 return -EBUSY;
1188 case CHAN_MODE_UNDEFINED:
1189 break;
1190 }
1191
Johannes Berg77fdaa12009-07-07 03:45:17 +02001192 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001193}
1194
1195static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001196 struct cfg80211_deauth_request *req,
1197 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001198{
Johannes Berg667503dd2009-07-07 03:56:11 +02001199 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1200 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001201}
1202
1203static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001204 struct cfg80211_disassoc_request *req,
1205 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001206{
Johannes Berg667503dd2009-07-07 03:56:11 +02001207 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1208 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001209}
1210
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001211static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1212 struct cfg80211_ibss_params *params)
1213{
Johannes Bergf444de02010-05-05 15:25:02 +02001214 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001215 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1216
Johannes Bergf444de02010-05-05 15:25:02 +02001217 switch (ieee80211_get_channel_mode(local, sdata)) {
1218 case CHAN_MODE_HOPPING:
1219 return -EBUSY;
1220 case CHAN_MODE_FIXED:
1221 if (!params->channel_fixed)
1222 return -EBUSY;
1223 if (local->oper_channel == params->channel)
1224 break;
1225 return -EBUSY;
1226 case CHAN_MODE_UNDEFINED:
1227 break;
1228 }
1229
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001230 return ieee80211_ibss_join(sdata, params);
1231}
1232
1233static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1234{
1235 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1236
1237 return ieee80211_ibss_leave(sdata);
1238}
1239
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001240static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1241{
1242 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001243 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001244
Lukáš Turek310bc672009-12-21 22:50:48 +01001245 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1246 err = drv_set_coverage_class(local, wiphy->coverage_class);
1247
1248 if (err)
1249 return err;
1250 }
1251
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001252 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001253 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001254
Johannes Berg24487982009-04-23 18:52:52 +02001255 if (err)
1256 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001257 }
1258
1259 if (changed & WIPHY_PARAM_RETRY_SHORT)
1260 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1261 if (changed & WIPHY_PARAM_RETRY_LONG)
1262 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1263 if (changed &
1264 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1265 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1266
1267 return 0;
1268}
1269
Johannes Berg7643a2c2009-06-02 13:01:39 +02001270static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001271 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001272{
1273 struct ieee80211_local *local = wiphy_priv(wiphy);
1274 struct ieee80211_channel *chan = local->hw.conf.channel;
1275 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001276
1277 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001278 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001279 local->user_power_level = -1;
1280 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001281 case NL80211_TX_POWER_LIMITED:
1282 if (mbm < 0 || (mbm % 100))
1283 return -EOPNOTSUPP;
1284 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001285 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001286 case NL80211_TX_POWER_FIXED:
1287 if (mbm < 0 || (mbm % 100))
1288 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001289 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001290 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001291 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001292 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001293 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001294 }
1295
1296 ieee80211_hw_config(local, changes);
1297
1298 return 0;
1299}
1300
1301static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1302{
1303 struct ieee80211_local *local = wiphy_priv(wiphy);
1304
1305 *dbm = local->hw.conf.power_level;
1306
Johannes Berg7643a2c2009-06-02 13:01:39 +02001307 return 0;
1308}
1309
Johannes Bergab737a42009-07-01 21:26:58 +02001310static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1311 u8 *addr)
1312{
1313 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1314
1315 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1316
1317 return 0;
1318}
1319
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001320static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1321{
1322 struct ieee80211_local *local = wiphy_priv(wiphy);
1323
1324 drv_rfkill_poll(local);
1325}
1326
Johannes Bergaff89a92009-07-01 21:26:51 +02001327#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001328static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001329{
1330 struct ieee80211_local *local = wiphy_priv(wiphy);
1331
1332 if (!local->ops->testmode_cmd)
1333 return -EOPNOTSUPP;
1334
1335 return local->ops->testmode_cmd(&local->hw, data, len);
1336}
1337#endif
1338
Johannes Berg0f782312009-12-01 13:37:02 +01001339int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1340 enum ieee80211_smps_mode smps_mode)
1341{
1342 const u8 *ap;
1343 enum ieee80211_smps_mode old_req;
1344 int err;
1345
1346 old_req = sdata->u.mgd.req_smps;
1347 sdata->u.mgd.req_smps = smps_mode;
1348
1349 if (old_req == smps_mode &&
1350 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1351 return 0;
1352
1353 /*
1354 * If not associated, or current association is not an HT
1355 * association, there's no need to send an action frame.
1356 */
1357 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001358 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001359 mutex_lock(&sdata->local->iflist_mtx);
1360 ieee80211_recalc_smps(sdata->local, sdata);
1361 mutex_unlock(&sdata->local->iflist_mtx);
1362 return 0;
1363 }
1364
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001365 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001366
1367 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1368 if (sdata->u.mgd.powersave)
1369 smps_mode = IEEE80211_SMPS_DYNAMIC;
1370 else
1371 smps_mode = IEEE80211_SMPS_OFF;
1372 }
1373
1374 /* send SM PS frame to AP */
1375 err = ieee80211_send_smps_action(sdata, smps_mode,
1376 ap, ap);
1377 if (err)
1378 sdata->u.mgd.req_smps = old_req;
1379
1380 return err;
1381}
1382
Johannes Bergbc92afd2009-07-01 21:26:57 +02001383static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1384 bool enabled, int timeout)
1385{
1386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1387 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001388
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001389 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1390 return -EOPNOTSUPP;
1391
Johannes Bergbc92afd2009-07-01 21:26:57 +02001392 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1393 return -EOPNOTSUPP;
1394
1395 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001396 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001397 return 0;
1398
1399 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001400 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001401
Johannes Berg0f782312009-12-01 13:37:02 +01001402 /* no change, but if automatic follow powersave */
1403 mutex_lock(&sdata->u.mgd.mtx);
1404 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1405 mutex_unlock(&sdata->u.mgd.mtx);
1406
Johannes Bergbc92afd2009-07-01 21:26:57 +02001407 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1408 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1409
1410 ieee80211_recalc_ps(local, -1);
1411
1412 return 0;
1413}
1414
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001415static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1416 struct net_device *dev,
1417 s32 rssi_thold, u32 rssi_hyst)
1418{
1419 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1420 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1421 struct ieee80211_vif *vif = &sdata->vif;
1422 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1423
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001424 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1425 rssi_hyst == bss_conf->cqm_rssi_hyst)
1426 return 0;
1427
1428 bss_conf->cqm_rssi_thold = rssi_thold;
1429 bss_conf->cqm_rssi_hyst = rssi_hyst;
1430
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001431 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1432 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1433 return -EOPNOTSUPP;
1434 return 0;
1435 }
1436
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001437 /* tell the driver upon association, unless already associated */
1438 if (sdata->u.mgd.associated)
1439 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1440
1441 return 0;
1442}
1443
Johannes Berg99303802009-07-01 21:26:59 +02001444static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1445 struct net_device *dev,
1446 const u8 *addr,
1447 const struct cfg80211_bitrate_mask *mask)
1448{
1449 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1450 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001451 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001452
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001453 /*
1454 * This _could_ be supported by providing a hook for
1455 * drivers for this function, but at this point it
1456 * doesn't seem worth bothering.
1457 */
1458 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1459 return -EOPNOTSUPP;
1460
Johannes Berg99303802009-07-01 21:26:59 +02001461
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001462 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1463 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001464
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001465 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001466}
1467
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001468static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1469 struct net_device *dev,
1470 struct ieee80211_channel *chan,
1471 enum nl80211_channel_type channel_type,
1472 unsigned int duration,
1473 u64 *cookie)
1474{
1475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1476
1477 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1478 duration, cookie);
1479}
1480
1481static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1482 struct net_device *dev,
1483 u64 cookie)
1484{
1485 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1486
1487 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1488}
1489
Johannes Berg2e161f72010-08-12 15:38:38 +02001490static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1491 struct ieee80211_channel *chan,
1492 enum nl80211_channel_type channel_type,
1493 bool channel_type_valid,
1494 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001495{
Johannes Berg9d38d852010-06-09 17:20:33 +02001496 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1497 struct ieee80211_local *local = sdata->local;
1498 struct sk_buff *skb;
1499 struct sta_info *sta;
1500 const struct ieee80211_mgmt *mgmt = (void *)buf;
1501 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1502 IEEE80211_TX_CTL_REQ_TX_STATUS;
1503
1504 /* Check that we are on the requested channel for transmission */
1505 if (chan != local->tmp_channel &&
1506 chan != local->oper_channel)
1507 return -EBUSY;
1508 if (channel_type_valid &&
1509 (channel_type != local->tmp_channel_type &&
1510 channel_type != local->_oper_channel_type))
1511 return -EBUSY;
1512
1513 switch (sdata->vif.type) {
1514 case NL80211_IFTYPE_ADHOC:
1515 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
1516 break;
1517 rcu_read_lock();
1518 sta = sta_info_get(sdata, mgmt->da);
1519 rcu_read_unlock();
1520 if (!sta)
1521 return -ENOLINK;
1522 break;
1523 case NL80211_IFTYPE_STATION:
Johannes Berg9d38d852010-06-09 17:20:33 +02001524 break;
1525 default:
1526 return -EOPNOTSUPP;
1527 }
1528
1529 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1530 if (!skb)
1531 return -ENOMEM;
1532 skb_reserve(skb, local->hw.extra_tx_headroom);
1533
1534 memcpy(skb_put(skb, len), buf, len);
1535
1536 IEEE80211_SKB_CB(skb)->flags = flags;
1537
1538 skb->dev = sdata->dev;
1539 ieee80211_tx_skb(sdata, skb);
1540
1541 *cookie = (unsigned long) skb;
1542 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001543}
1544
Jiri Bencf0706e82007-05-05 11:45:53 -07001545struct cfg80211_ops mac80211_config_ops = {
1546 .add_virtual_intf = ieee80211_add_iface,
1547 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001548 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001549 .add_key = ieee80211_add_key,
1550 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001551 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001552 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001553 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001554 .add_beacon = ieee80211_add_beacon,
1555 .set_beacon = ieee80211_set_beacon,
1556 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001557 .add_station = ieee80211_add_station,
1558 .del_station = ieee80211_del_station,
1559 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001560 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001561 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001562 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001563#ifdef CONFIG_MAC80211_MESH
1564 .add_mpath = ieee80211_add_mpath,
1565 .del_mpath = ieee80211_del_mpath,
1566 .change_mpath = ieee80211_change_mpath,
1567 .get_mpath = ieee80211_get_mpath,
1568 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001569 .set_mesh_params = ieee80211_set_mesh_params,
1570 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001571#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001572 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001573 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001574 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001575 .suspend = ieee80211_suspend,
1576 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001577 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001578 .auth = ieee80211_auth,
1579 .assoc = ieee80211_assoc,
1580 .deauth = ieee80211_deauth,
1581 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001582 .join_ibss = ieee80211_join_ibss,
1583 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001584 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001585 .set_tx_power = ieee80211_set_tx_power,
1586 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001587 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001588 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001589 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001590 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001591 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001592 .remain_on_channel = ieee80211_remain_on_channel,
1593 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001594 .mgmt_tx = ieee80211_mgmt_tx,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001595 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Jiri Bencf0706e82007-05-05 11:45:53 -07001596};