blob: 581438255d7e949dc67d4a518b4c36caaa24e6ed [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{
84 struct ieee80211_sub_if_data *sdata;
85 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 Bergad0e2b52010-06-01 10:19:19 +020089 if (!netif_running(dev))
90 return -ENETDOWN;
91
Johannes Berge8cbb4c2007-12-19 02:03:30 +010092 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
93
Johannes Berg97359d12010-08-10 09:46:38 +020094 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +010095 switch (params->cipher) {
96 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +010097 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +020098 case WLAN_CIPHER_SUITE_WEP104:
99 if (IS_ERR(sdata->local->wep_tx_tfm))
100 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200101 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100102 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200103 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100104 }
105
Johannes Berg97359d12010-08-10 09:46:38 +0200106 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
107 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100108 if (IS_ERR(key))
109 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100110
Johannes Bergad0e2b52010-06-01 10:19:19 +0200111 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200112
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100113 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100114 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100115 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700116 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200117 err = -ENOENT;
118 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100119 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120 }
121
Johannes Bergdb4d1162008-02-25 16:27:45 +0100122 ieee80211_key_link(key, sdata, sta);
123
Johannes Berg3b967662008-04-08 17:56:52 +0200124 err = 0;
125 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200126 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200127
128 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100129}
130
131static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200132 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133{
134 struct ieee80211_sub_if_data *sdata;
135 struct sta_info *sta;
136 int ret;
137
138 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
139
Johannes Bergad0e2b52010-06-01 10:19:19 +0200140 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200141
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200143 ret = -ENOENT;
144
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100145 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200147 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100148
Johannes Bergdb4d1162008-02-25 16:27:45 +0100149 if (sta->key) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700150 ieee80211_key_free(sdata->local, sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100151 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200152 ret = 0;
153 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100154
Johannes Berg3b967662008-04-08 17:56:52 +0200155 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100156 }
157
Johannes Berg3b967662008-04-08 17:56:52 +0200158 if (!sdata->keys[key_idx]) {
159 ret = -ENOENT;
160 goto out_unlock;
161 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162
Jouni Malinen32162a42010-07-26 15:52:03 -0700163 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100164 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100165
Johannes Berg3b967662008-04-08 17:56:52 +0200166 ret = 0;
167 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200168 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200169
170 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171}
172
Johannes Berg62da92f2007-12-19 02:03:31 +0100173static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200174 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100175 void (*callback)(void *cookie,
176 struct key_params *params))
177{
Johannes Berg14db74b2008-07-29 13:22:52 +0200178 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100179 struct sta_info *sta = NULL;
180 u8 seq[6] = {0};
181 struct key_params params;
182 struct ieee80211_key *key;
183 u32 iv32;
184 u16 iv16;
185 int err = -ENOENT;
186
Johannes Berg14db74b2008-07-29 13:22:52 +0200187 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
188
Johannes Berg3b967662008-04-08 17:56:52 +0200189 rcu_read_lock();
190
Johannes Berg62da92f2007-12-19 02:03:31 +0100191 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100192 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100193 if (!sta)
194 goto out;
195
196 key = sta->key;
197 } else
198 key = sdata->keys[key_idx];
199
200 if (!key)
201 goto out;
202
203 memset(&params, 0, sizeof(params));
204
Johannes Berg97359d12010-08-10 09:46:38 +0200205 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100206
Johannes Berg97359d12010-08-10 09:46:38 +0200207 switch (key->conf.cipher) {
208 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700209 iv32 = key->u.tkip.tx.iv32;
210 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100211
Johannes Berg24487982009-04-23 18:52:52 +0200212 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
213 drv_get_tkip_seq(sdata->local,
214 key->conf.hw_key_idx,
215 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100216
217 seq[0] = iv16 & 0xff;
218 seq[1] = (iv16 >> 8) & 0xff;
219 seq[2] = iv32 & 0xff;
220 seq[3] = (iv32 >> 8) & 0xff;
221 seq[4] = (iv32 >> 16) & 0xff;
222 seq[5] = (iv32 >> 24) & 0xff;
223 params.seq = seq;
224 params.seq_len = 6;
225 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200226 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100227 seq[0] = key->u.ccmp.tx_pn[5];
228 seq[1] = key->u.ccmp.tx_pn[4];
229 seq[2] = key->u.ccmp.tx_pn[3];
230 seq[3] = key->u.ccmp.tx_pn[2];
231 seq[4] = key->u.ccmp.tx_pn[1];
232 seq[5] = key->u.ccmp.tx_pn[0];
233 params.seq = seq;
234 params.seq_len = 6;
235 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200236 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200237 seq[0] = key->u.aes_cmac.tx_pn[5];
238 seq[1] = key->u.aes_cmac.tx_pn[4];
239 seq[2] = key->u.aes_cmac.tx_pn[3];
240 seq[3] = key->u.aes_cmac.tx_pn[2];
241 seq[4] = key->u.aes_cmac.tx_pn[1];
242 seq[5] = key->u.aes_cmac.tx_pn[0];
243 params.seq = seq;
244 params.seq_len = 6;
245 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100246 }
247
248 params.key = key->conf.key;
249 params.key_len = key->conf.keylen;
250
251 callback(cookie, &params);
252 err = 0;
253
254 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200255 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100256 return err;
257}
258
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100259static int ieee80211_config_default_key(struct wiphy *wiphy,
260 struct net_device *dev,
261 u8 key_idx)
262{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200263 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100264
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265 ieee80211_set_default_key(sdata, key_idx);
266
267 return 0;
268}
269
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200270static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
271 struct net_device *dev,
272 u8 key_idx)
273{
Johannes Berg66c52422010-07-22 13:58:51 +0200274 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200275
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200276 ieee80211_set_default_mgmt_key(sdata, key_idx);
277
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200278 return 0;
279}
280
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100281static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
282{
Johannes Bergd0709a62008-02-25 16:27:46 +0100283 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100284
Johannes Bergf5ea9122009-08-07 16:17:38 +0200285 sinfo->generation = sdata->local->sta_generation;
286
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100287 sinfo->filled = STATION_INFO_INACTIVE_TIME |
288 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100289 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200290 STATION_INFO_RX_PACKETS |
291 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100292 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100293
294 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
295 sinfo->rx_bytes = sta->rx_bytes;
296 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200297 sinfo->rx_packets = sta->rx_packets;
298 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100299
John W. Linville19deffb2009-12-08 17:10:13 -0500300 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
301 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Henning Rogge420e7fa2008-12-11 22:04:19 +0100302 sinfo->filled |= STATION_INFO_SIGNAL;
303 sinfo->signal = (s8)sta->last_signal;
304 }
305
306 sinfo->txrate.flags = 0;
307 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
308 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
309 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
310 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
311 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
312 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
313
314 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
315 struct ieee80211_supported_band *sband;
316 sband = sta->local->hw.wiphy->bands[
317 sta->local->hw.conf.channel->band];
318 sinfo->txrate.legacy =
319 sband->bitrates[sta->last_tx_rate.idx].bitrate;
320 } else
321 sinfo->txrate.mcs = sta->last_tx_rate.idx;
322
Johannes Berg902acc72008-02-23 15:17:19 +0100323 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100324#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100325 sinfo->filled |= STATION_INFO_LLID |
326 STATION_INFO_PLID |
327 STATION_INFO_PLINK_STATE;
328
329 sinfo->llid = le16_to_cpu(sta->llid);
330 sinfo->plid = le16_to_cpu(sta->plid);
331 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100332#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100333 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100334}
335
336
337static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
338 int idx, u8 *mac, struct station_info *sinfo)
339{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100340 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100341 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100342 int ret = -ENOENT;
343
344 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100345
Johannes Berg3b53fde82009-11-16 12:00:37 +0100346 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100347 if (sta) {
348 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200349 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100350 sta_set_sinfo(sta, sinfo);
351 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100352
Johannes Bergd0709a62008-02-25 16:27:46 +0100353 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100354
Johannes Bergd0709a62008-02-25 16:27:46 +0100355 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100356}
357
Holger Schurig12897232010-04-19 10:23:57 +0200358static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
359 int idx, struct survey_info *survey)
360{
361 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
362
Holger Schurig12897232010-04-19 10:23:57 +0200363 return drv_get_survey(local, idx, survey);
364}
365
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100366static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100367 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100368{
Johannes Bergabe60632009-11-25 17:46:18 +0100369 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100370 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100371 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100372
Johannes Bergd0709a62008-02-25 16:27:46 +0100373 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100374
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100375 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100376 if (sta) {
377 ret = 0;
378 sta_set_sinfo(sta, sinfo);
379 }
380
381 rcu_read_unlock();
382
383 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100384}
385
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100386/*
387 * This handles both adding a beacon and setting new beacon info
388 */
389static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
390 struct beacon_parameters *params)
391{
392 struct beacon_data *new, *old;
393 int new_head_len, new_tail_len;
394 int size;
395 int err = -EINVAL;
396
397 old = sdata->u.ap.beacon;
398
399 /* head must not be zero-length */
400 if (params->head && !params->head_len)
401 return -EINVAL;
402
403 /*
404 * This is a kludge. beacon interval should really be part
405 * of the beacon information.
406 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200407 if (params->interval &&
408 (sdata->vif.bss_conf.beacon_int != params->interval)) {
409 sdata->vif.bss_conf.beacon_int = params->interval;
410 ieee80211_bss_info_change_notify(sdata,
411 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100412 }
413
414 /* Need to have a beacon head if we don't have one yet */
415 if (!params->head && !old)
416 return err;
417
418 /* sorry, no way to start beaconing without dtim period */
419 if (!params->dtim_period && !old)
420 return err;
421
422 /* new or old head? */
423 if (params->head)
424 new_head_len = params->head_len;
425 else
426 new_head_len = old->head_len;
427
428 /* new or old tail? */
429 if (params->tail || !old)
430 /* params->tail_len will be zero for !params->tail */
431 new_tail_len = params->tail_len;
432 else
433 new_tail_len = old->tail_len;
434
435 size = sizeof(*new) + new_head_len + new_tail_len;
436
437 new = kzalloc(size, GFP_KERNEL);
438 if (!new)
439 return -ENOMEM;
440
441 /* start filling the new info now */
442
443 /* new or old dtim period? */
444 if (params->dtim_period)
445 new->dtim_period = params->dtim_period;
446 else
447 new->dtim_period = old->dtim_period;
448
449 /*
450 * pointers go into the block we allocated,
451 * memory is | beacon_data | head | tail |
452 */
453 new->head = ((u8 *) new) + sizeof(*new);
454 new->tail = new->head + new_head_len;
455 new->head_len = new_head_len;
456 new->tail_len = new_tail_len;
457
458 /* copy in head */
459 if (params->head)
460 memcpy(new->head, params->head, new_head_len);
461 else
462 memcpy(new->head, old->head, new_head_len);
463
464 /* copy in optional tail */
465 if (params->tail)
466 memcpy(new->tail, params->tail, new_tail_len);
467 else
468 if (old)
469 memcpy(new->tail, old->tail, new_tail_len);
470
Johannes Berg19885c42010-02-05 11:45:06 +0100471 sdata->vif.bss_conf.dtim_period = new->dtim_period;
472
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100473 rcu_assign_pointer(sdata->u.ap.beacon, new);
474
475 synchronize_rcu();
476
477 kfree(old);
478
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200479 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
480 BSS_CHANGED_BEACON);
481 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100482}
483
484static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
485 struct beacon_parameters *params)
486{
Johannes Berg14db74b2008-07-29 13:22:52 +0200487 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100488 struct beacon_data *old;
489
Johannes Berg14db74b2008-07-29 13:22:52 +0200490 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
491
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100492 old = sdata->u.ap.beacon;
493
494 if (old)
495 return -EALREADY;
496
497 return ieee80211_config_beacon(sdata, params);
498}
499
500static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
501 struct beacon_parameters *params)
502{
Johannes Berg14db74b2008-07-29 13:22:52 +0200503 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100504 struct beacon_data *old;
505
Johannes Berg14db74b2008-07-29 13:22:52 +0200506 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
507
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100508 old = sdata->u.ap.beacon;
509
510 if (!old)
511 return -ENOENT;
512
513 return ieee80211_config_beacon(sdata, params);
514}
515
516static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
517{
Johannes Berg14db74b2008-07-29 13:22:52 +0200518 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100519 struct beacon_data *old;
520
Johannes Berg14db74b2008-07-29 13:22:52 +0200521 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
522
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100523 old = sdata->u.ap.beacon;
524
525 if (!old)
526 return -ENOENT;
527
528 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
529 synchronize_rcu();
530 kfree(old);
531
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200532 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
533 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100534}
535
Johannes Berg4fd69312007-12-19 02:03:35 +0100536/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
537struct iapp_layer2_update {
538 u8 da[ETH_ALEN]; /* broadcast */
539 u8 sa[ETH_ALEN]; /* STA addr */
540 __be16 len; /* 6 */
541 u8 dsap; /* 0 */
542 u8 ssap; /* 0 */
543 u8 control;
544 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700545} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100546
547static void ieee80211_send_layer2_update(struct sta_info *sta)
548{
549 struct iapp_layer2_update *msg;
550 struct sk_buff *skb;
551
552 /* Send Level 2 Update Frame to update forwarding tables in layer 2
553 * bridge devices */
554
555 skb = dev_alloc_skb(sizeof(*msg));
556 if (!skb)
557 return;
558 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
559
560 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
561 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
562
563 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200564 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100565 msg->len = htons(6);
566 msg->dsap = 0;
567 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
568 msg->control = 0xaf; /* XID response lsb.1111F101.
569 * F=0 (no poll command; unsolicited frame) */
570 msg->xid_info[0] = 0x81; /* XID format identifier */
571 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
572 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
573
Johannes Bergd0709a62008-02-25 16:27:46 +0100574 skb->dev = sta->sdata->dev;
575 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100576 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400577 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100578}
579
580static void sta_apply_parameters(struct ieee80211_local *local,
581 struct sta_info *sta,
582 struct station_parameters *params)
583{
584 u32 rates;
585 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100586 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100587 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300588 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100589
Johannes Bergae5eb022008-10-14 16:58:37 +0200590 sband = local->hw.wiphy->bands[local->oper_channel->band];
591
Johannes Bergeccb8e82009-05-11 21:57:56 +0300592 spin_lock_bh(&sta->lock);
593 mask = params->sta_flags_mask;
594 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100595
Johannes Bergeccb8e82009-05-11 21:57:56 +0300596 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100597 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300598 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100599 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100600 }
601
Johannes Bergeccb8e82009-05-11 21:57:56 +0300602 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
603 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
604 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
605 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
606 }
607
608 if (mask & BIT(NL80211_STA_FLAG_WME)) {
609 sta->flags &= ~WLAN_STA_WME;
610 if (set & BIT(NL80211_STA_FLAG_WME))
611 sta->flags |= WLAN_STA_WME;
612 }
613
614 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
615 sta->flags &= ~WLAN_STA_MFP;
616 if (set & BIT(NL80211_STA_FLAG_MFP))
617 sta->flags |= WLAN_STA_MFP;
618 }
619 spin_unlock_bh(&sta->lock);
620
Johannes Berg73651ee2008-02-25 16:27:47 +0100621 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200622 * cfg80211 validates this (1-2007) and allows setting the AID
623 * only when creating a new station entry
624 */
625 if (params->aid)
626 sta->sta.aid = params->aid;
627
628 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100629 * FIXME: updating the following information is racy when this
630 * function is called from ieee80211_change_station().
631 * However, all this information should be static so
632 * maybe we should just reject attemps to change it.
633 */
634
Johannes Berg4fd69312007-12-19 02:03:35 +0100635 if (params->listen_interval >= 0)
636 sta->listen_interval = params->listen_interval;
637
638 if (params->supported_rates) {
639 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100640
Johannes Berg4fd69312007-12-19 02:03:35 +0100641 for (i = 0; i < params->supported_rates_len; i++) {
642 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100643 for (j = 0; j < sband->n_bitrates; j++) {
644 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100645 rates |= BIT(j);
646 }
647 }
Johannes Berg323ce792008-09-11 02:45:11 +0200648 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100649 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100650
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200651 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200652 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
653 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200654 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300655
Johannes Berg902acc72008-02-23 15:17:19 +0100656 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100657 switch (params->plink_action) {
658 case PLINK_ACTION_OPEN:
659 mesh_plink_open(sta);
660 break;
661 case PLINK_ACTION_BLOCK:
662 mesh_plink_block(sta);
663 break;
664 }
Johannes Berg902acc72008-02-23 15:17:19 +0100665 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100666}
667
668static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
669 u8 *mac, struct station_parameters *params)
670{
Johannes Berg14db74b2008-07-29 13:22:52 +0200671 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100672 struct sta_info *sta;
673 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100674 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200675 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100676
Johannes Berg4fd69312007-12-19 02:03:35 +0100677 if (params->vlan) {
678 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
679
Johannes Berg05c914f2008-09-11 00:01:58 +0200680 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
681 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100682 return -EINVAL;
683 } else
684 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
685
Johannes Berg47846c92009-11-25 17:46:19 +0100686 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100687 return -EINVAL;
688
689 if (is_multicast_ether_addr(mac))
690 return -EINVAL;
691
692 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100693 if (!sta)
694 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100695
696 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
697
698 sta_apply_parameters(local, sta, params);
699
Johannes Berg4b7679a2008-09-18 18:14:18 +0200700 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100701
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200702 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
703 sdata->vif.type == NL80211_IFTYPE_AP;
704
Johannes Berg34e89502010-02-03 13:59:58 +0100705 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100706 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100707 rcu_read_unlock();
708 return err;
709 }
710
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200711 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100712 ieee80211_send_layer2_update(sta);
713
714 rcu_read_unlock();
715
Johannes Berg4fd69312007-12-19 02:03:35 +0100716 return 0;
717}
718
719static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
720 u8 *mac)
721{
Johannes Berg14db74b2008-07-29 13:22:52 +0200722 struct ieee80211_local *local = wiphy_priv(wiphy);
723 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100724
Johannes Berg14db74b2008-07-29 13:22:52 +0200725 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
726
Johannes Berg34e89502010-02-03 13:59:58 +0100727 if (mac)
728 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200729
Johannes Berg34e89502010-02-03 13:59:58 +0100730 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100731 return 0;
732}
733
734static int ieee80211_change_station(struct wiphy *wiphy,
735 struct net_device *dev,
736 u8 *mac,
737 struct station_parameters *params)
738{
Johannes Bergabe60632009-11-25 17:46:18 +0100739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200740 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100741 struct sta_info *sta;
742 struct ieee80211_sub_if_data *vlansdata;
743
Johannes Berg98dd6a52008-04-10 15:36:09 +0200744 rcu_read_lock();
745
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100746 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200747 if (!sta) {
748 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100749 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200750 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100751
Johannes Bergd0709a62008-02-25 16:27:46 +0100752 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100753 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
754
Johannes Berg05c914f2008-09-11 00:01:58 +0200755 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
756 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200757 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100758 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200759 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100760
Johannes Berg9bc383d2009-11-19 11:55:19 +0100761 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100762 if (vlansdata->u.vlan.sta) {
763 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100764 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100765 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100766
767 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
768 }
769
Johannes Berg14db74b2008-07-29 13:22:52 +0200770 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100771 ieee80211_send_layer2_update(sta);
772 }
773
774 sta_apply_parameters(local, sta, params);
775
Johannes Berg98dd6a52008-04-10 15:36:09 +0200776 rcu_read_unlock();
777
Johannes Berg4fd69312007-12-19 02:03:35 +0100778 return 0;
779}
780
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100781#ifdef CONFIG_MAC80211_MESH
782static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
783 u8 *dst, u8 *next_hop)
784{
Johannes Berg14db74b2008-07-29 13:22:52 +0200785 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100786 struct mesh_path *mpath;
787 struct sta_info *sta;
788 int err;
789
Johannes Berg14db74b2008-07-29 13:22:52 +0200790 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
791
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100793 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100794 if (!sta) {
795 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100796 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100797 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100798
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200799 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100800 if (err) {
801 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100802 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100803 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100804
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200805 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100806 if (!mpath) {
807 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100808 return -ENXIO;
809 }
810 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100811
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100812 rcu_read_unlock();
813 return 0;
814}
815
816static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
817 u8 *dst)
818{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200819 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100820
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200821 if (dst)
822 return mesh_path_del(dst, sdata);
823
824 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100825 return 0;
826}
827
828static int ieee80211_change_mpath(struct wiphy *wiphy,
829 struct net_device *dev,
830 u8 *dst, u8 *next_hop)
831{
Johannes Berg14db74b2008-07-29 13:22:52 +0200832 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100833 struct mesh_path *mpath;
834 struct sta_info *sta;
835
Johannes Berg14db74b2008-07-29 13:22:52 +0200836 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
837
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100838 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100839
Johannes Bergabe60632009-11-25 17:46:18 +0100840 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100841 if (!sta) {
842 rcu_read_unlock();
843 return -ENOENT;
844 }
845
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200846 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100847 if (!mpath) {
848 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100849 return -ENOENT;
850 }
851
852 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100853
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100854 rcu_read_unlock();
855 return 0;
856}
857
858static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
859 struct mpath_info *pinfo)
860{
861 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200862 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100863 else
864 memset(next_hop, 0, ETH_ALEN);
865
Johannes Bergf5ea9122009-08-07 16:17:38 +0200866 pinfo->generation = mesh_paths_generation;
867
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100868 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000869 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100870 MPATH_INFO_METRIC |
871 MPATH_INFO_EXPTIME |
872 MPATH_INFO_DISCOVERY_TIMEOUT |
873 MPATH_INFO_DISCOVERY_RETRIES |
874 MPATH_INFO_FLAGS;
875
876 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000877 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100878 pinfo->metric = mpath->metric;
879 if (time_before(jiffies, mpath->exp_time))
880 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
881 pinfo->discovery_timeout =
882 jiffies_to_msecs(mpath->discovery_timeout);
883 pinfo->discovery_retries = mpath->discovery_retries;
884 pinfo->flags = 0;
885 if (mpath->flags & MESH_PATH_ACTIVE)
886 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
887 if (mpath->flags & MESH_PATH_RESOLVING)
888 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000889 if (mpath->flags & MESH_PATH_SN_VALID)
890 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100891 if (mpath->flags & MESH_PATH_FIXED)
892 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
893 if (mpath->flags & MESH_PATH_RESOLVING)
894 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
895
896 pinfo->flags = mpath->flags;
897}
898
899static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
900 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
901
902{
Johannes Berg14db74b2008-07-29 13:22:52 +0200903 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100904 struct mesh_path *mpath;
905
Johannes Berg14db74b2008-07-29 13:22:52 +0200906 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
907
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100908 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200909 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100910 if (!mpath) {
911 rcu_read_unlock();
912 return -ENOENT;
913 }
914 memcpy(dst, mpath->dst, ETH_ALEN);
915 mpath_set_pinfo(mpath, next_hop, pinfo);
916 rcu_read_unlock();
917 return 0;
918}
919
920static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
921 int idx, u8 *dst, u8 *next_hop,
922 struct mpath_info *pinfo)
923{
Johannes Berg14db74b2008-07-29 13:22:52 +0200924 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100925 struct mesh_path *mpath;
926
Johannes Berg14db74b2008-07-29 13:22:52 +0200927 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
928
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100929 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200930 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100931 if (!mpath) {
932 rcu_read_unlock();
933 return -ENOENT;
934 }
935 memcpy(dst, mpath->dst, ETH_ALEN);
936 mpath_set_pinfo(mpath, next_hop, pinfo);
937 rcu_read_unlock();
938 return 0;
939}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700940
941static int ieee80211_get_mesh_params(struct wiphy *wiphy,
942 struct net_device *dev,
943 struct mesh_config *conf)
944{
945 struct ieee80211_sub_if_data *sdata;
946 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
947
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700948 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
949 return 0;
950}
951
952static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
953{
954 return (mask >> (parm-1)) & 0x1;
955}
956
957static int ieee80211_set_mesh_params(struct wiphy *wiphy,
958 struct net_device *dev,
959 const struct mesh_config *nconf, u32 mask)
960{
961 struct mesh_config *conf;
962 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +0000963 struct ieee80211_if_mesh *ifmsh;
964
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700965 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +0000966 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700967
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700968 /* Set the config options which we are interested in setting */
969 conf = &(sdata->u.mesh.mshcfg);
970 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
971 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
972 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
973 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
974 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
975 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
976 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
977 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
978 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
979 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
980 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
981 conf->dot11MeshTTL = nconf->dot11MeshTTL;
982 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
983 conf->auto_open_plinks = nconf->auto_open_plinks;
984 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
985 conf->dot11MeshHWMPmaxPREQretries =
986 nconf->dot11MeshHWMPmaxPREQretries;
987 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
988 conf->path_refresh_time = nconf->path_refresh_time;
989 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
990 conf->min_discovery_timeout = nconf->min_discovery_timeout;
991 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
992 conf->dot11MeshHWMPactivePathTimeout =
993 nconf->dot11MeshHWMPactivePathTimeout;
994 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
995 conf->dot11MeshHWMPpreqMinInterval =
996 nconf->dot11MeshHWMPpreqMinInterval;
997 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
998 mask))
999 conf->dot11MeshHWMPnetDiameterTraversalTime =
1000 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001001 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1002 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1003 ieee80211_mesh_root_setup(ifmsh);
1004 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001005 return 0;
1006}
1007
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001008#endif
1009
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001010static int ieee80211_change_bss(struct wiphy *wiphy,
1011 struct net_device *dev,
1012 struct bss_parameters *params)
1013{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001014 struct ieee80211_sub_if_data *sdata;
1015 u32 changed = 0;
1016
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001017 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1018
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001019 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001020 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001021 changed |= BSS_CHANGED_ERP_CTS_PROT;
1022 }
1023 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001024 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001025 params->use_short_preamble;
1026 changed |= BSS_CHANGED_ERP_PREAMBLE;
1027 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001028
1029 if (!sdata->vif.bss_conf.use_short_slot &&
1030 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1031 sdata->vif.bss_conf.use_short_slot = true;
1032 changed |= BSS_CHANGED_ERP_SLOT;
1033 }
1034
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001035 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001036 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001037 params->use_short_slot_time;
1038 changed |= BSS_CHANGED_ERP_SLOT;
1039 }
1040
Jouni Malinen90c97a02008-10-30 16:59:22 +02001041 if (params->basic_rates) {
1042 int i, j;
1043 u32 rates = 0;
1044 struct ieee80211_local *local = wiphy_priv(wiphy);
1045 struct ieee80211_supported_band *sband =
1046 wiphy->bands[local->oper_channel->band];
1047
1048 for (i = 0; i < params->basic_rates_len; i++) {
1049 int rate = (params->basic_rates[i] & 0x7f) * 5;
1050 for (j = 0; j < sband->n_bitrates; j++) {
1051 if (sband->bitrates[j].bitrate == rate)
1052 rates |= BIT(j);
1053 }
1054 }
1055 sdata->vif.bss_conf.basic_rates = rates;
1056 changed |= BSS_CHANGED_BASIC_RATES;
1057 }
1058
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001059 if (params->ap_isolate >= 0) {
1060 if (params->ap_isolate)
1061 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1062 else
1063 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1064 }
1065
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001066 ieee80211_bss_info_change_notify(sdata, changed);
1067
1068 return 0;
1069}
1070
Jouni Malinen31888482008-10-30 16:59:24 +02001071static int ieee80211_set_txq_params(struct wiphy *wiphy,
1072 struct ieee80211_txq_params *params)
1073{
1074 struct ieee80211_local *local = wiphy_priv(wiphy);
1075 struct ieee80211_tx_queue_params p;
1076
1077 if (!local->ops->conf_tx)
1078 return -EOPNOTSUPP;
1079
1080 memset(&p, 0, sizeof(p));
1081 p.aifs = params->aifs;
1082 p.cw_max = params->cwmax;
1083 p.cw_min = params->cwmin;
1084 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001085
1086 /*
1087 * Setting tx queue params disables u-apsd because it's only
1088 * called in master mode.
1089 */
1090 p.uapsd = false;
1091
Johannes Berg24487982009-04-23 18:52:52 +02001092 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001093 wiphy_debug(local->hw.wiphy,
1094 "failed to set TX queue parameters for queue %d\n",
1095 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001096 return -EINVAL;
1097 }
1098
1099 return 0;
1100}
1101
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001102static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001103 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001104 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301105 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001106{
1107 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001108 struct ieee80211_sub_if_data *sdata = NULL;
1109
1110 if (netdev)
1111 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001112
Johannes Bergf444de02010-05-05 15:25:02 +02001113 switch (ieee80211_get_channel_mode(local, NULL)) {
1114 case CHAN_MODE_HOPPING:
1115 return -EBUSY;
1116 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001117 if (local->oper_channel != chan)
1118 return -EBUSY;
1119 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001120 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001121 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001122 case CHAN_MODE_UNDEFINED:
1123 break;
1124 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001125
1126 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001127
Johannes Berg0aaffa92010-05-05 15:28:27 +02001128 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1129 return -EBUSY;
1130
1131 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1132 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1133 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1134
1135 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001136}
1137
Bob Copeland665af4f2009-01-19 11:20:53 -05001138#ifdef CONFIG_PM
1139static int ieee80211_suspend(struct wiphy *wiphy)
1140{
1141 return __ieee80211_suspend(wiphy_priv(wiphy));
1142}
1143
1144static int ieee80211_resume(struct wiphy *wiphy)
1145{
1146 return __ieee80211_resume(wiphy_priv(wiphy));
1147}
1148#else
1149#define ieee80211_suspend NULL
1150#define ieee80211_resume NULL
1151#endif
1152
Johannes Berg2a519312009-02-10 21:25:55 +01001153static int ieee80211_scan(struct wiphy *wiphy,
1154 struct net_device *dev,
1155 struct cfg80211_scan_request *req)
1156{
1157 struct ieee80211_sub_if_data *sdata;
1158
Johannes Berg2a519312009-02-10 21:25:55 +01001159 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1160
1161 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1162 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinen357303e2009-04-16 18:44:53 +03001163 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1164 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
Johannes Berg2a519312009-02-10 21:25:55 +01001165 return -EOPNOTSUPP;
1166
1167 return ieee80211_request_scan(sdata, req);
1168}
1169
Jouni Malinen636a5d32009-03-19 13:39:22 +02001170static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1171 struct cfg80211_auth_request *req)
1172{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001173 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001174}
1175
1176static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1177 struct cfg80211_assoc_request *req)
1178{
Johannes Bergf444de02010-05-05 15:25:02 +02001179 struct ieee80211_local *local = wiphy_priv(wiphy);
1180 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1181
1182 switch (ieee80211_get_channel_mode(local, sdata)) {
1183 case CHAN_MODE_HOPPING:
1184 return -EBUSY;
1185 case CHAN_MODE_FIXED:
1186 if (local->oper_channel == req->bss->channel)
1187 break;
1188 return -EBUSY;
1189 case CHAN_MODE_UNDEFINED:
1190 break;
1191 }
1192
Johannes Berg77fdaa12009-07-07 03:45:17 +02001193 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001194}
1195
1196static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001197 struct cfg80211_deauth_request *req,
1198 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001199{
Johannes Berg667503d2009-07-07 03:56:11 +02001200 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1201 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001202}
1203
1204static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001205 struct cfg80211_disassoc_request *req,
1206 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001207{
Johannes Berg667503d2009-07-07 03:56:11 +02001208 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1209 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001210}
1211
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001212static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1213 struct cfg80211_ibss_params *params)
1214{
Johannes Bergf444de02010-05-05 15:25:02 +02001215 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001216 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1217
Johannes Bergf444de02010-05-05 15:25:02 +02001218 switch (ieee80211_get_channel_mode(local, sdata)) {
1219 case CHAN_MODE_HOPPING:
1220 return -EBUSY;
1221 case CHAN_MODE_FIXED:
1222 if (!params->channel_fixed)
1223 return -EBUSY;
1224 if (local->oper_channel == params->channel)
1225 break;
1226 return -EBUSY;
1227 case CHAN_MODE_UNDEFINED:
1228 break;
1229 }
1230
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001231 return ieee80211_ibss_join(sdata, params);
1232}
1233
1234static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1235{
1236 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1237
1238 return ieee80211_ibss_leave(sdata);
1239}
1240
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001241static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1242{
1243 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001244 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001245
Lukáš Turek310bc672009-12-21 22:50:48 +01001246 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1247 err = drv_set_coverage_class(local, wiphy->coverage_class);
1248
1249 if (err)
1250 return err;
1251 }
1252
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001253 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001254 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001255
Johannes Berg24487982009-04-23 18:52:52 +02001256 if (err)
1257 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001258 }
1259
1260 if (changed & WIPHY_PARAM_RETRY_SHORT)
1261 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1262 if (changed & WIPHY_PARAM_RETRY_LONG)
1263 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1264 if (changed &
1265 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1266 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1267
1268 return 0;
1269}
1270
Johannes Berg7643a2c2009-06-02 13:01:39 +02001271static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001272 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001273{
1274 struct ieee80211_local *local = wiphy_priv(wiphy);
1275 struct ieee80211_channel *chan = local->hw.conf.channel;
1276 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001277
1278 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001279 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001280 local->user_power_level = -1;
1281 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001282 case NL80211_TX_POWER_LIMITED:
1283 if (mbm < 0 || (mbm % 100))
1284 return -EOPNOTSUPP;
1285 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001286 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001287 case NL80211_TX_POWER_FIXED:
1288 if (mbm < 0 || (mbm % 100))
1289 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001290 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001291 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001292 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001293 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001294 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001295 }
1296
1297 ieee80211_hw_config(local, changes);
1298
1299 return 0;
1300}
1301
1302static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1303{
1304 struct ieee80211_local *local = wiphy_priv(wiphy);
1305
1306 *dbm = local->hw.conf.power_level;
1307
Johannes Berg7643a2c2009-06-02 13:01:39 +02001308 return 0;
1309}
1310
Johannes Bergab737a42009-07-01 21:26:58 +02001311static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1312 u8 *addr)
1313{
1314 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1315
1316 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1317
1318 return 0;
1319}
1320
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001321static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1322{
1323 struct ieee80211_local *local = wiphy_priv(wiphy);
1324
1325 drv_rfkill_poll(local);
1326}
1327
Johannes Bergaff89a92009-07-01 21:26:51 +02001328#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001329static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001330{
1331 struct ieee80211_local *local = wiphy_priv(wiphy);
1332
1333 if (!local->ops->testmode_cmd)
1334 return -EOPNOTSUPP;
1335
1336 return local->ops->testmode_cmd(&local->hw, data, len);
1337}
1338#endif
1339
Johannes Berg0f782312009-12-01 13:37:02 +01001340int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1341 enum ieee80211_smps_mode smps_mode)
1342{
1343 const u8 *ap;
1344 enum ieee80211_smps_mode old_req;
1345 int err;
1346
1347 old_req = sdata->u.mgd.req_smps;
1348 sdata->u.mgd.req_smps = smps_mode;
1349
1350 if (old_req == smps_mode &&
1351 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1352 return 0;
1353
1354 /*
1355 * If not associated, or current association is not an HT
1356 * association, there's no need to send an action frame.
1357 */
1358 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001359 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001360 mutex_lock(&sdata->local->iflist_mtx);
1361 ieee80211_recalc_smps(sdata->local, sdata);
1362 mutex_unlock(&sdata->local->iflist_mtx);
1363 return 0;
1364 }
1365
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001366 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001367
1368 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1369 if (sdata->u.mgd.powersave)
1370 smps_mode = IEEE80211_SMPS_DYNAMIC;
1371 else
1372 smps_mode = IEEE80211_SMPS_OFF;
1373 }
1374
1375 /* send SM PS frame to AP */
1376 err = ieee80211_send_smps_action(sdata, smps_mode,
1377 ap, ap);
1378 if (err)
1379 sdata->u.mgd.req_smps = old_req;
1380
1381 return err;
1382}
1383
Johannes Bergbc92afd2009-07-01 21:26:57 +02001384static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1385 bool enabled, int timeout)
1386{
1387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1388 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001389
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001390 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1391 return -EOPNOTSUPP;
1392
Johannes Bergbc92afd2009-07-01 21:26:57 +02001393 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1394 return -EOPNOTSUPP;
1395
1396 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001397 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001398 return 0;
1399
1400 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001401 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001402
Johannes Berg0f782312009-12-01 13:37:02 +01001403 /* no change, but if automatic follow powersave */
1404 mutex_lock(&sdata->u.mgd.mtx);
1405 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1406 mutex_unlock(&sdata->u.mgd.mtx);
1407
Johannes Bergbc92afd2009-07-01 21:26:57 +02001408 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1409 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1410
1411 ieee80211_recalc_ps(local, -1);
1412
1413 return 0;
1414}
1415
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001416static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1417 struct net_device *dev,
1418 s32 rssi_thold, u32 rssi_hyst)
1419{
1420 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1421 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1422 struct ieee80211_vif *vif = &sdata->vif;
1423 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1424
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001425 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1426 rssi_hyst == bss_conf->cqm_rssi_hyst)
1427 return 0;
1428
1429 bss_conf->cqm_rssi_thold = rssi_thold;
1430 bss_conf->cqm_rssi_hyst = rssi_hyst;
1431
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001432 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1433 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1434 return -EOPNOTSUPP;
1435 return 0;
1436 }
1437
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001438 /* tell the driver upon association, unless already associated */
1439 if (sdata->u.mgd.associated)
1440 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1441
1442 return 0;
1443}
1444
Johannes Berg99303802009-07-01 21:26:59 +02001445static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1446 struct net_device *dev,
1447 const u8 *addr,
1448 const struct cfg80211_bitrate_mask *mask)
1449{
1450 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1451 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001452 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001453
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001454 /*
1455 * This _could_ be supported by providing a hook for
1456 * drivers for this function, but at this point it
1457 * doesn't seem worth bothering.
1458 */
1459 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1460 return -EOPNOTSUPP;
1461
Johannes Berg99303802009-07-01 21:26:59 +02001462
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001463 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1464 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001465
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001466 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001467}
1468
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001469static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1470 struct net_device *dev,
1471 struct ieee80211_channel *chan,
1472 enum nl80211_channel_type channel_type,
1473 unsigned int duration,
1474 u64 *cookie)
1475{
1476 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1477
1478 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1479 duration, cookie);
1480}
1481
1482static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1483 struct net_device *dev,
1484 u64 cookie)
1485{
1486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1487
1488 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1489}
1490
Johannes Berg2e161f72010-08-12 15:38:38 +02001491static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1492 struct ieee80211_channel *chan,
1493 enum nl80211_channel_type channel_type,
1494 bool channel_type_valid,
1495 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001496{
Johannes Berg9d38d852010-06-09 17:20:33 +02001497 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1498 struct ieee80211_local *local = sdata->local;
1499 struct sk_buff *skb;
1500 struct sta_info *sta;
1501 const struct ieee80211_mgmt *mgmt = (void *)buf;
1502 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1503 IEEE80211_TX_CTL_REQ_TX_STATUS;
1504
1505 /* Check that we are on the requested channel for transmission */
1506 if (chan != local->tmp_channel &&
1507 chan != local->oper_channel)
1508 return -EBUSY;
1509 if (channel_type_valid &&
1510 (channel_type != local->tmp_channel_type &&
1511 channel_type != local->_oper_channel_type))
1512 return -EBUSY;
1513
1514 switch (sdata->vif.type) {
1515 case NL80211_IFTYPE_ADHOC:
1516 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
1517 break;
1518 rcu_read_lock();
1519 sta = sta_info_get(sdata, mgmt->da);
1520 rcu_read_unlock();
1521 if (!sta)
1522 return -ENOLINK;
1523 break;
1524 case NL80211_IFTYPE_STATION:
Johannes Berg9d38d852010-06-09 17:20:33 +02001525 break;
1526 default:
1527 return -EOPNOTSUPP;
1528 }
1529
1530 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1531 if (!skb)
1532 return -ENOMEM;
1533 skb_reserve(skb, local->hw.extra_tx_headroom);
1534
1535 memcpy(skb_put(skb, len), buf, len);
1536
1537 IEEE80211_SKB_CB(skb)->flags = flags;
1538
1539 skb->dev = sdata->dev;
1540 ieee80211_tx_skb(sdata, skb);
1541
1542 *cookie = (unsigned long) skb;
1543 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001544}
1545
Jiri Bencf0706e82007-05-05 11:45:53 -07001546struct cfg80211_ops mac80211_config_ops = {
1547 .add_virtual_intf = ieee80211_add_iface,
1548 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001549 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001550 .add_key = ieee80211_add_key,
1551 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001552 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001553 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001554 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001555 .add_beacon = ieee80211_add_beacon,
1556 .set_beacon = ieee80211_set_beacon,
1557 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001558 .add_station = ieee80211_add_station,
1559 .del_station = ieee80211_del_station,
1560 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001561 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001562 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001563 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001564#ifdef CONFIG_MAC80211_MESH
1565 .add_mpath = ieee80211_add_mpath,
1566 .del_mpath = ieee80211_del_mpath,
1567 .change_mpath = ieee80211_change_mpath,
1568 .get_mpath = ieee80211_get_mpath,
1569 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001570 .set_mesh_params = ieee80211_set_mesh_params,
1571 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001572#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001573 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001574 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001575 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001576 .suspend = ieee80211_suspend,
1577 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001578 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001579 .auth = ieee80211_auth,
1580 .assoc = ieee80211_assoc,
1581 .deauth = ieee80211_deauth,
1582 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001583 .join_ibss = ieee80211_join_ibss,
1584 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001585 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001586 .set_tx_power = ieee80211_set_tx_power,
1587 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001588 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001589 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001590 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001591 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001592 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001593 .remain_on_channel = ieee80211_remain_on_channel,
1594 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001595 .mgmt_tx = ieee80211_mgmt_tx,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001596 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Jiri Bencf0706e82007-05-05 11:45:53 -07001597};