blob: 592f4b152ba8a51e4d1c3b3bc3360286959ff1e0 [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>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b2009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914fe2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020076 u32 mask = MONITOR_FLAG_COOK_FRAMES |
77 MONITOR_FLAG_ACTIVE;
78
Christian Lamparter85416a42010-10-02 13:17:07 +020079 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020080 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
82 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020083 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
87 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020088 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020089 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200105
Johannes Berg42613db2007-09-28 21:52:27 +0200106 return 0;
107}
108
Johannes Bergf142c6b2012-06-18 20:07:15 +0200109static int ieee80211_start_p2p_device(struct wiphy *wiphy,
110 struct wireless_dev *wdev)
111{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200112 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
113 int ret;
114
115 mutex_lock(&sdata->local->chanctx_mtx);
116 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
117 mutex_unlock(&sdata->local->chanctx_mtx);
118 if (ret < 0)
119 return ret;
120
Johannes Bergf142c6b2012-06-18 20:07:15 +0200121 return ieee80211_do_open(wdev, true);
122}
123
124static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
125 struct wireless_dev *wdev)
126{
127 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
128}
129
Simon Wunderlichb53be792011-11-18 14:20:44 +0100130static int ieee80211_set_noack_map(struct wiphy *wiphy,
131 struct net_device *dev,
132 u16 noack_map)
133{
134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
135
136 sdata->noack_map = noack_map;
137 return 0;
138}
139
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100140static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200141 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142 struct key_params *params)
143{
Johannes Berg26a58452010-08-27 12:35:55 +0200144 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200145 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200147 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200149 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100150
Johannes Berg26a58452010-08-27 12:35:55 +0200151 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200152 return -ENETDOWN;
153
Johannes Berg97359d12010-08-10 09:46:38 +0200154 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100155 switch (params->cipher) {
156 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200158 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200159 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200160 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200161 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200162 case WLAN_CIPHER_SUITE_CCMP:
163 case WLAN_CIPHER_SUITE_AES_CMAC:
164 case WLAN_CIPHER_SUITE_GCMP:
165 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200167 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200168 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169 }
170
Johannes Berg97359d12010-08-10 09:46:38 +0200171 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200172 params->key, params->seq_len, params->seq,
173 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100174 if (IS_ERR(key))
175 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100176
Johannes Berge31b8212010-10-05 19:39:30 +0200177 if (pairwise)
178 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
179
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200180 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200181
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100182 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700183 if (ieee80211_vif_is_mesh(&sdata->vif))
184 sta = sta_info_get(sdata, mac_addr);
185 else
186 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100187 /*
188 * The ASSOC test makes sure the driver is ready to
189 * receive the key. When wpa_supplicant has roamed
190 * using FT, it attempts to set the key before
191 * association has completed, this rejects that attempt
192 * so it will set the key again after assocation.
193 *
194 * TODO: accept the key if we have a station entry and
195 * add it to the device after the station.
196 */
197 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100198 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200199 err = -ENOENT;
200 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100201 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100202 }
203
Johannes Berge548c492012-09-04 17:08:23 +0200204 switch (sdata->vif.type) {
205 case NL80211_IFTYPE_STATION:
206 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
207 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
208 break;
209 case NL80211_IFTYPE_AP:
210 case NL80211_IFTYPE_AP_VLAN:
211 /* Keys without a station are used for TX only */
212 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
213 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
214 break;
215 case NL80211_IFTYPE_ADHOC:
216 /* no MFP (yet) */
217 break;
218 case NL80211_IFTYPE_MESH_POINT:
219#ifdef CONFIG_MAC80211_MESH
220 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
221 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
222 break;
223#endif
224 case NL80211_IFTYPE_WDS:
225 case NL80211_IFTYPE_MONITOR:
226 case NL80211_IFTYPE_P2P_DEVICE:
227 case NL80211_IFTYPE_UNSPECIFIED:
228 case NUM_NL80211_IFTYPES:
229 case NL80211_IFTYPE_P2P_CLIENT:
230 case NL80211_IFTYPE_P2P_GO:
231 /* shouldn't happen */
232 WARN_ON_ONCE(1);
233 break;
234 }
235
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200236 if (sta)
237 sta->cipher_scheme = cs;
238
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300239 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100240
Johannes Berg3b967662008-04-08 17:56:52 +0200241 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200242 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200243
244 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100245}
246
247static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200248 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100249{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
251 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100252 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200253 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100254 int ret;
255
Johannes Berg5c0c3642011-05-12 14:31:49 +0200256 mutex_lock(&local->sta_mtx);
257 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200258
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100259 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200260 ret = -ENOENT;
261
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100262 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100263 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200264 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265
Johannes Berg5c0c3642011-05-12 14:31:49 +0200266 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200267 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200268 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200269 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200270 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200271 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100272
Johannes Berg5c0c3642011-05-12 14:31:49 +0200273 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200274 ret = -ENOENT;
275 goto out_unlock;
276 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100277
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100278 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100279
Johannes Berg3b967662008-04-08 17:56:52 +0200280 ret = 0;
281 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200282 mutex_unlock(&local->key_mtx);
283 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200284
285 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100286}
287
Johannes Berg62da92f2007-12-19 02:03:31 +0100288static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200289 u8 key_idx, bool pairwise, const u8 *mac_addr,
290 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100291 void (*callback)(void *cookie,
292 struct key_params *params))
293{
Johannes Berg14db74b2008-07-29 13:22:52 +0200294 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100295 struct sta_info *sta = NULL;
296 u8 seq[6] = {0};
297 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200298 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200299 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100300 u32 iv32;
301 u16 iv16;
302 int err = -ENOENT;
303
Johannes Berg14db74b2008-07-29 13:22:52 +0200304 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
305
Johannes Berg3b967662008-04-08 17:56:52 +0200306 rcu_read_lock();
307
Johannes Berg62da92f2007-12-19 02:03:31 +0100308 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100309 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100310 if (!sta)
311 goto out;
312
Max Stepanov354e1592013-12-08 13:30:52 +0200313 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200314 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200315 else if (!pairwise &&
316 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200317 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100318 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200319 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100320
321 if (!key)
322 goto out;
323
324 memset(&params, 0, sizeof(params));
325
Johannes Berg97359d12010-08-10 09:46:38 +0200326 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100327
Johannes Berg97359d12010-08-10 09:46:38 +0200328 switch (key->conf.cipher) {
329 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700330 iv32 = key->u.tkip.tx.iv32;
331 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100332
Johannes Berg24487982009-04-23 18:52:52 +0200333 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
334 drv_get_tkip_seq(sdata->local,
335 key->conf.hw_key_idx,
336 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100337
338 seq[0] = iv16 & 0xff;
339 seq[1] = (iv16 >> 8) & 0xff;
340 seq[2] = iv32 & 0xff;
341 seq[3] = (iv32 >> 8) & 0xff;
342 seq[4] = (iv32 >> 16) & 0xff;
343 seq[5] = (iv32 >> 24) & 0xff;
344 params.seq = seq;
345 params.seq_len = 6;
346 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200347 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200348 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
349 seq[0] = pn64;
350 seq[1] = pn64 >> 8;
351 seq[2] = pn64 >> 16;
352 seq[3] = pn64 >> 24;
353 seq[4] = pn64 >> 32;
354 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100355 params.seq = seq;
356 params.seq_len = 6;
357 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200358 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200359 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
360 seq[0] = pn64;
361 seq[1] = pn64 >> 8;
362 seq[2] = pn64 >> 16;
363 seq[3] = pn64 >> 24;
364 seq[4] = pn64 >> 32;
365 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200366 params.seq = seq;
367 params.seq_len = 6;
368 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100369 }
370
371 params.key = key->conf.key;
372 params.key_len = key->conf.keylen;
373
374 callback(cookie, &params);
375 err = 0;
376
377 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200378 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100379 return err;
380}
381
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100382static int ieee80211_config_default_key(struct wiphy *wiphy,
383 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100384 u8 key_idx, bool uni,
385 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100386{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100388
Johannes Bergf7e01042010-12-09 19:49:02 +0100389 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100390
391 return 0;
392}
393
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200394static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
395 struct net_device *dev,
396 u8 key_idx)
397{
Johannes Berg66c52422010-07-22 13:58:51 +0200398 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200399
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200400 ieee80211_set_default_mgmt_key(sdata, key_idx);
401
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200402 return 0;
403}
404
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800405void sta_set_rate_info_tx(struct sta_info *sta,
406 const struct ieee80211_tx_rate *rate,
407 struct rate_info *rinfo)
408{
409 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100410 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800411 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100412 rinfo->mcs = rate->idx;
413 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
414 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
415 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
416 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
417 } else {
418 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200419 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
420 u16 brate;
421
Johannes Berg8bc83c22012-11-09 18:38:32 +0100422 sband = sta->local->hw.wiphy->bands[
423 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200424 brate = sband->bitrates[rate->idx].bitrate;
425 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100426 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800427 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
428 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100429 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
430 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
431 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
432 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800433 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
434 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800435}
436
Saravana003e6762012-11-28 18:29:38 +0530437void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
438{
439 rinfo->flags = 0;
440
441 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
442 rinfo->flags |= RATE_INFO_FLAGS_MCS;
443 rinfo->mcs = sta->last_rx_rate_idx;
444 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
445 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
446 rinfo->nss = sta->last_rx_rate_vht_nss;
447 rinfo->mcs = sta->last_rx_rate_idx;
448 } else {
449 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200450 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
451 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530452
453 sband = sta->local->hw.wiphy->bands[
454 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200455 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
456 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530457 }
458
459 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
460 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
461 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
462 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200463 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530464 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200465 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530466 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200467 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
Saravana003e6762012-11-28 18:29:38 +0530468 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
469}
470
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100471static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
472{
Johannes Bergd0709a62008-02-25 16:27:46 +0100473 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300474 struct ieee80211_local *local = sdata->local;
Felix Fietkaufa8f1362014-07-22 21:00:26 +0200475 struct rate_control_ref *ref = NULL;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530476 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100477 u64 packets = 0;
Antonio Quartullicca674d2014-05-19 21:53:20 +0200478 u32 thr = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200479 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100480
Felix Fietkaufa8f1362014-07-22 21:00:26 +0200481 if (test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
482 ref = local->rate_ctrl;
483
Johannes Bergf5ea9122009-08-07 16:17:38 +0200484 sinfo->generation = sdata->local->sta_generation;
485
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100486 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100487 STATION_INFO_RX_BYTES64 |
488 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200489 STATION_INFO_RX_PACKETS |
490 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900491 STATION_INFO_TX_RETRIES |
492 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700493 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100494 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700495 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530496 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200497 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800498 STATION_INFO_STA_FLAGS |
499 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530500
501 do_posix_clock_monotonic_gettime(&uptime);
502 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100503
504 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100505 sinfo->tx_bytes = 0;
506 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
507 sinfo->tx_bytes += sta->tx_bytes[ac];
508 packets += sta->tx_packets[ac];
509 }
510 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100511 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200512 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900513 sinfo->tx_retries = sta->tx_retry_count;
514 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700515 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800516 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100517
John W. Linville19deffb2009-12-08 17:10:13 -0500518 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
519 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900520 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300521 if (!local->ops->get_rssi ||
522 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
523 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900524 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100525 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200526 if (sta->chains) {
527 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
528 STATION_INFO_CHAIN_SIGNAL_AVG;
529
530 sinfo->chains = sta->chains;
531 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
532 sinfo->chain_signal[i] = sta->chain_signal_last[i];
533 sinfo->chain_signal_avg[i] =
534 (s8) -ewma_read(&sta->chain_signal_avg[i]);
535 }
536 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100537
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800538 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530539 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100540
Johannes Berg902acc72008-02-23 15:17:19 +0100541 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100542#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100543 sinfo->filled |= STATION_INFO_LLID |
544 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100545 STATION_INFO_PLINK_STATE |
546 STATION_INFO_LOCAL_PM |
547 STATION_INFO_PEER_PM |
548 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100549
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800550 sinfo->llid = sta->llid;
551 sinfo->plid = sta->plid;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100552 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700553 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
554 sinfo->filled |= STATION_INFO_T_OFFSET;
555 sinfo->t_offset = sta->t_offset;
556 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100557 sinfo->local_pm = sta->local_pm;
558 sinfo->peer_pm = sta->peer_pm;
559 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100560#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100561 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700562
563 sinfo->bss_param.flags = 0;
564 if (sdata->vif.bss_conf.use_cts_prot)
565 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
566 if (sdata->vif.bss_conf.use_short_preamble)
567 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
568 if (sdata->vif.bss_conf.use_short_slot)
569 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
570 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
571 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200572
573 sinfo->sta_flags.set = 0;
574 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
575 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
576 BIT(NL80211_STA_FLAG_WME) |
577 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100578 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200579 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100580 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200581 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
582 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
583 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
584 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
585 if (test_sta_flag(sta, WLAN_STA_WME))
586 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
587 if (test_sta_flag(sta, WLAN_STA_MFP))
588 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
589 if (test_sta_flag(sta, WLAN_STA_AUTH))
590 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200591 if (test_sta_flag(sta, WLAN_STA_ASSOC))
592 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100593 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
594 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Antonio Quartullicca674d2014-05-19 21:53:20 +0200595
596 /* check if the driver has a SW RC implementation */
597 if (ref && ref->ops->get_expected_throughput)
598 thr = ref->ops->get_expected_throughput(sta->rate_ctrl_priv);
599 else
600 thr = drv_get_expected_throughput(local, &sta->sta);
601
602 if (thr != 0) {
603 sinfo->filled |= STATION_INFO_EXPECTED_THROUGHPUT;
604 sinfo->expected_throughput = thr;
605 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100606}
607
Ben Greearb1ab7922012-04-23 12:50:30 -0700608static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
609 "rx_packets", "rx_bytes", "wep_weak_iv_count",
610 "rx_duplicates", "rx_fragments", "rx_dropped",
611 "tx_packets", "tx_bytes", "tx_fragments",
612 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700613 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
614 "channel", "noise", "ch_time", "ch_time_busy",
615 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700616};
617#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
618
619static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
620 struct net_device *dev,
621 int sset)
622{
Ben Greeare3521142012-04-23 12:50:31 -0700623 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
624 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700625
Ben Greeare3521142012-04-23 12:50:31 -0700626 if (sset == ETH_SS_STATS)
627 rv += STA_STATS_LEN;
628
629 rv += drv_get_et_sset_count(sdata, sset);
630
631 if (rv == 0)
632 return -EOPNOTSUPP;
633 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700634}
635
636static void ieee80211_get_et_stats(struct wiphy *wiphy,
637 struct net_device *dev,
638 struct ethtool_stats *stats,
639 u64 *data)
640{
641 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200642 struct ieee80211_chanctx_conf *chanctx_conf;
643 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700644 struct sta_info *sta;
645 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700646 struct station_info sinfo;
647 struct survey_info survey;
648 int i, q;
649#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700650
651 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
652
653#define ADD_STA_STATS(sta) \
654 do { \
655 data[i++] += sta->rx_packets; \
656 data[i++] += sta->rx_bytes; \
657 data[i++] += sta->wep_weak_iv_count; \
658 data[i++] += sta->num_duplicates; \
659 data[i++] += sta->rx_fragments; \
660 data[i++] += sta->rx_dropped; \
661 \
Johannes Berg560d2682013-02-05 10:55:21 +0100662 data[i++] += sinfo.tx_packets; \
663 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700664 data[i++] += sta->tx_fragments; \
665 data[i++] += sta->tx_filtered_count; \
666 data[i++] += sta->tx_retry_failed; \
667 data[i++] += sta->tx_retry_count; \
668 data[i++] += sta->beacon_loss_count; \
669 } while (0)
670
671 /* For Managed stations, find the single station based on BSSID
672 * and use that. For interface types, iterate through all available
673 * stations and add stats for any station that is assigned to this
674 * network device.
675 */
676
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300677 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700678
679 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
680 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700681
682 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
683 goto do_survey;
684
Johannes Berg560d2682013-02-05 10:55:21 +0100685 sinfo.filled = 0;
686 sta_set_sinfo(sta, &sinfo);
687
Ben Greear3073a7c2012-04-23 12:50:32 -0700688 i = 0;
689 ADD_STA_STATS(sta);
690
691 data[i++] = sta->sta_state;
692
Ben Greear3073a7c2012-04-23 12:50:32 -0700693
Joe Perches52042672012-05-30 13:25:54 -0700694 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700695 data[i] = 100000 *
696 cfg80211_calculate_bitrate(&sinfo.txrate);
697 i++;
Joe Perches52042672012-05-30 13:25:54 -0700698 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700699 data[i] = 100000 *
700 cfg80211_calculate_bitrate(&sinfo.rxrate);
701 i++;
702
Joe Perches52042672012-05-30 13:25:54 -0700703 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700704 data[i] = (u8)sinfo.signal_avg;
705 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700706 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300707 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700708 /* Make sure this station belongs to the proper dev */
709 if (sta->sdata->dev != dev)
710 continue;
711
Johannes Berge13bae42013-07-08 10:43:31 +0200712 sinfo.filled = 0;
713 sta_set_sinfo(sta, &sinfo);
Ben Greearb1ab7922012-04-23 12:50:30 -0700714 i = 0;
715 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700716 }
717 }
718
Ben Greear3073a7c2012-04-23 12:50:32 -0700719do_survey:
720 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
721 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200722 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700723
Johannes Berg55de9082012-07-26 17:24:39 +0200724 rcu_read_lock();
725 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
726 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100727 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200728 else
729 channel = NULL;
730 rcu_read_unlock();
731
732 if (channel) {
733 q = 0;
734 do {
735 survey.filled = 0;
736 if (drv_get_survey(local, q, &survey) != 0) {
737 survey.filled = 0;
738 break;
739 }
740 q++;
741 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700742 }
743
744 if (survey.filled)
745 data[i++] = survey.channel->center_freq;
746 else
747 data[i++] = 0;
748 if (survey.filled & SURVEY_INFO_NOISE_DBM)
749 data[i++] = (u8)survey.noise;
750 else
751 data[i++] = -1LL;
752 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
753 data[i++] = survey.channel_time;
754 else
755 data[i++] = -1LL;
756 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
757 data[i++] = survey.channel_time_busy;
758 else
759 data[i++] = -1LL;
760 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
761 data[i++] = survey.channel_time_ext_busy;
762 else
763 data[i++] = -1LL;
764 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
765 data[i++] = survey.channel_time_rx;
766 else
767 data[i++] = -1LL;
768 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
769 data[i++] = survey.channel_time_tx;
770 else
771 data[i++] = -1LL;
772
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300773 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700774
Ben Greear3073a7c2012-04-23 12:50:32 -0700775 if (WARN_ON(i != STA_STATS_LEN))
776 return;
777
Ben Greeare3521142012-04-23 12:50:31 -0700778 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700779}
780
781static void ieee80211_get_et_strings(struct wiphy *wiphy,
782 struct net_device *dev,
783 u32 sset, u8 *data)
784{
Ben Greeare3521142012-04-23 12:50:31 -0700785 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
786 int sz_sta_stats = 0;
787
Ben Greearb1ab7922012-04-23 12:50:30 -0700788 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700789 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200790 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700791 }
Ben Greeare3521142012-04-23 12:50:31 -0700792 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700793}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100794
795static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200796 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100798 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300799 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100800 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100801 int ret = -ENOENT;
802
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300803 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100804
Johannes Berg3b53fde82009-11-16 12:00:37 +0100805 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100806 if (sta) {
807 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200808 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100809 sta_set_sinfo(sta, sinfo);
810 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100811
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300812 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100813
Johannes Bergd0709a62008-02-25 16:27:46 +0100814 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100815}
816
Holger Schurig12897232010-04-19 10:23:57 +0200817static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
818 int idx, struct survey_info *survey)
819{
820 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
821
Holger Schurig12897232010-04-19 10:23:57 +0200822 return drv_get_survey(local, idx, survey);
823}
824
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100825static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200826 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100827{
Johannes Bergabe60632009-11-25 17:46:18 +0100828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300829 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100830 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100831 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100832
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300833 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100834
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100835 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100836 if (sta) {
837 ret = 0;
838 sta_set_sinfo(sta, sinfo);
839 }
840
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300841 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100842
843 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100844}
845
Johannes Berge8c9bd52012-06-06 08:18:22 +0200846static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100847 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200848{
Johannes Berg55de9082012-07-26 17:24:39 +0200849 struct ieee80211_local *local = wiphy_priv(wiphy);
850 struct ieee80211_sub_if_data *sdata;
851 int ret = 0;
852
Johannes Berg4bf88532012-11-09 11:39:59 +0100853 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200854 return 0;
855
Johannes Berg34a37402013-12-18 09:43:33 +0100856 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200857 mutex_lock(&local->iflist_mtx);
858 if (local->use_chanctx) {
859 sdata = rcu_dereference_protected(
860 local->monitor_sdata,
861 lockdep_is_held(&local->iflist_mtx));
862 if (sdata) {
863 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100864 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200865 IEEE80211_CHANCTX_EXCLUSIVE);
866 }
867 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100868 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200869 ieee80211_hw_config(local, 0);
870 }
871
Johannes Berg4bf88532012-11-09 11:39:59 +0100872 if (ret == 0)
873 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200874 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100875 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200876
877 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200878}
879
Arik Nemtsov02945822011-11-10 11:28:57 +0200880static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100881 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200882{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300883 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200884
885 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530886 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200887
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100888 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200889
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300890 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200891 if (!new)
892 return -ENOMEM;
893
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300894 new->len = resp_len;
895 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200896
897 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300898 if (old)
899 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200900
901 return 0;
902}
903
Luciano Coelho0ae07962013-12-08 09:42:25 +0200904static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
905 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100906{
907 struct beacon_data *new, *old;
908 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100909 int size, err;
910 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100911
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100912 old = sdata_dereference(sdata->u.ap.beacon, sdata);
913
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100914
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100915 /* Need to have a beacon head if we don't have one yet */
916 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100917 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100918
919 /* new or old head? */
920 if (params->head)
921 new_head_len = params->head_len;
922 else
923 new_head_len = old->head_len;
924
925 /* new or old tail? */
926 if (params->tail || !old)
927 /* params->tail_len will be zero for !params->tail */
928 new_tail_len = params->tail_len;
929 else
930 new_tail_len = old->tail_len;
931
932 size = sizeof(*new) + new_head_len + new_tail_len;
933
934 new = kzalloc(size, GFP_KERNEL);
935 if (!new)
936 return -ENOMEM;
937
938 /* start filling the new info now */
939
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100940 /*
941 * pointers go into the block we allocated,
942 * memory is | beacon_data | head | tail |
943 */
944 new->head = ((u8 *) new) + sizeof(*new);
945 new->tail = new->head + new_head_len;
946 new->head_len = new_head_len;
947 new->tail_len = new_tail_len;
948
949 /* copy in head */
950 if (params->head)
951 memcpy(new->head, params->head, new_head_len);
952 else
953 memcpy(new->head, old->head, new_head_len);
954
955 /* copy in optional tail */
956 if (params->tail)
957 memcpy(new->tail, params->tail, new_tail_len);
958 else
959 if (old)
960 memcpy(new->tail, old->tail, new_tail_len);
961
Johannes Berg88600202012-02-13 15:17:18 +0100962 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
963 params->probe_resp_len);
964 if (err < 0)
965 return err;
966 if (err == 0)
967 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100968
Eric Dumazetcf778b02012-01-12 04:41:32 +0000969 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100970
Johannes Berg88600202012-02-13 15:17:18 +0100971 if (old)
972 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100973
Johannes Berg88600202012-02-13 15:17:18 +0100974 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100975}
976
Johannes Berg88600202012-02-13 15:17:18 +0100977static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
978 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100979{
Johannes Berg88600202012-02-13 15:17:18 +0100980 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100981 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100982 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100983 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100984 u32 changed = BSS_CHANGED_BEACON_INT |
985 BSS_CHANGED_BEACON_ENABLED |
986 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100987 BSS_CHANGED_SSID |
988 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100989 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200990
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100991 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100992 if (old)
993 return -EALREADY;
994
Johannes Berg04ecd252012-09-11 14:34:12 +0200995 /* TODO: make hostapd tell us what it wants */
996 sdata->smps_mode = IEEE80211_SMPS_OFF;
997 sdata->needed_rx_chains = sdata->local->rx_chains;
998
Johannes Berg34a37402013-12-18 09:43:33 +0100999 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001000 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001001 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +01001002 if (!err)
1003 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +01001004 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +02001005 if (err)
1006 return err;
1007
Johannes Berg665c93a2011-11-04 11:18:11 +01001008 /*
1009 * Apply control port protocol, this allows us to
1010 * not encrypt dynamic WEP control frames.
1011 */
1012 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1013 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001014 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
1015 &params->crypto,
1016 sdata->vif.type);
1017
Johannes Berg665c93a2011-11-04 11:18:11 +01001018 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1019 vlan->control_port_protocol =
1020 params->crypto.control_port_ethertype;
1021 vlan->control_port_no_encrypt =
1022 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001023 vlan->encrypt_headroom =
1024 ieee80211_cs_headroom(sdata->local,
1025 &params->crypto,
1026 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +01001027 }
1028
Johannes Berg88600202012-02-13 15:17:18 +01001029 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1030 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +01001031 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +01001032
1033 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1034 if (params->ssid_len)
1035 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1036 params->ssid_len);
1037 sdata->vif.bss_conf.hidden_ssid =
1038 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1039
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001040 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1041 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1042 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1043 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1044 if (params->p2p_opp_ps)
1045 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1046 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001047
Johannes Berg88600202012-02-13 15:17:18 +01001048 err = ieee80211_assign_beacon(sdata, &params->beacon);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001049 if (err < 0) {
1050 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001051 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001052 }
Johannes Berg88600202012-02-13 15:17:18 +01001053 changed |= err;
1054
Johannes Berg10416382012-10-19 15:44:42 +02001055 err = drv_start_ap(sdata->local, sdata);
1056 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001057 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1058
Johannes Berg10416382012-10-19 15:44:42 +02001059 if (old)
1060 kfree_rcu(old, rcu_head);
1061 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001062 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +02001063 return err;
1064 }
1065
Thomas Pedersen057d5f42013-12-19 10:25:15 -08001066 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001067 ieee80211_bss_info_change_notify(sdata, changed);
1068
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001069 netif_carrier_on(dev);
1070 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1071 netif_carrier_on(vlan->dev);
1072
Johannes Berg665c93a2011-11-04 11:18:11 +01001073 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001074}
1075
Johannes Berg88600202012-02-13 15:17:18 +01001076static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1077 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001078{
Johannes Berg14db74b2008-07-29 13:22:52 +02001079 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001080 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001081 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001082
Johannes Berg14db74b2008-07-29 13:22:52 +02001083 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +01001084 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +02001085
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001086 /* don't allow changing the beacon while CSA is in place - offset
1087 * of channel switch counter may change
1088 */
1089 if (sdata->vif.csa_active)
1090 return -EBUSY;
1091
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001092 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001093 if (!old)
1094 return -ENOENT;
1095
Johannes Berg88600202012-02-13 15:17:18 +01001096 err = ieee80211_assign_beacon(sdata, params);
1097 if (err < 0)
1098 return err;
1099 ieee80211_bss_info_change_notify(sdata, err);
1100 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001101}
1102
Michal Kazior59af6922014-04-09 15:10:59 +02001103bool ieee80211_csa_needs_block_tx(struct ieee80211_local *local)
1104{
1105 struct ieee80211_sub_if_data *sdata;
1106
1107 lockdep_assert_held(&local->mtx);
1108
1109 rcu_read_lock();
1110 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
1111 if (!ieee80211_sdata_running(sdata))
1112 continue;
1113
1114 if (!sdata->vif.csa_active)
1115 continue;
1116
1117 if (!sdata->csa_block_tx)
1118 continue;
1119
1120 rcu_read_unlock();
1121 return true;
1122 }
1123 rcu_read_unlock();
1124
1125 return false;
1126}
1127
Johannes Berg88600202012-02-13 15:17:18 +01001128static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001129{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1131 struct ieee80211_sub_if_data *vlan;
1132 struct ieee80211_local *local = sdata->local;
1133 struct beacon_data *old_beacon;
1134 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001135 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001136
Michal Kaziordbd72852014-01-29 07:56:21 +01001137 sdata_assert_lock(sdata);
1138
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001139 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001140 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001141 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001142 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001143
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001144 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +02001145 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001146 sdata->vif.csa_active = false;
Michal Kazior59af6922014-04-09 15:10:59 +02001147 if (!ieee80211_csa_needs_block_tx(local))
1148 ieee80211_wake_queues_by_reason(&local->hw,
1149 IEEE80211_MAX_QUEUE_MAP,
1150 IEEE80211_QUEUE_STOP_REASON_CSA);
1151 mutex_unlock(&local->mtx);
1152
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +01001153 kfree(sdata->u.ap.next_beacon);
1154 sdata->u.ap.next_beacon = NULL;
1155
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001156 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001157 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1158 netif_carrier_off(vlan->dev);
1159 netif_carrier_off(dev);
1160
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001161 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001162 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001163 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1164 kfree_rcu(old_beacon, rcu_head);
1165 if (old_probe_resp)
1166 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +02001167 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +01001168
Johannes Berge7162512013-12-04 23:18:37 +01001169 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +01001170 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +01001171
Johannes Bergd6a83222012-12-14 14:06:28 +01001172 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001173 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001174 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001175 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001176
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001177 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001178 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001179 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001180 cfg80211_cac_event(sdata->dev, &chandef,
1181 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001182 GFP_KERNEL);
1183 }
1184
Johannes Berg10416382012-10-19 15:44:42 +02001185 drv_stop_ap(sdata->local, sdata);
1186
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001187 /* free all potentially still buffered bcast frames */
1188 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1189 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1190
Johannes Berg34a37402013-12-18 09:43:33 +01001191 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +01001192 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001193 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001194 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001195
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001196 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001197}
1198
Johannes Berg4fd69312007-12-19 02:03:35 +01001199/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1200struct iapp_layer2_update {
1201 u8 da[ETH_ALEN]; /* broadcast */
1202 u8 sa[ETH_ALEN]; /* STA addr */
1203 __be16 len; /* 6 */
1204 u8 dsap; /* 0 */
1205 u8 ssap; /* 0 */
1206 u8 control;
1207 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001208} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001209
1210static void ieee80211_send_layer2_update(struct sta_info *sta)
1211{
1212 struct iapp_layer2_update *msg;
1213 struct sk_buff *skb;
1214
1215 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1216 * bridge devices */
1217
1218 skb = dev_alloc_skb(sizeof(*msg));
1219 if (!skb)
1220 return;
1221 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1222
1223 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1224 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1225
Johannes Berge83e6542012-07-13 16:23:07 +02001226 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001227 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001228 msg->len = htons(6);
1229 msg->dsap = 0;
1230 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1231 msg->control = 0xaf; /* XID response lsb.1111F101.
1232 * F=0 (no poll command; unsolicited frame) */
1233 msg->xid_info[0] = 0x81; /* XID format identifier */
1234 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1235 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1236
Johannes Bergd0709a62008-02-25 16:27:46 +01001237 skb->dev = sta->sdata->dev;
1238 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001239 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001240 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001241}
1242
Johannes Bergd582cff2012-10-26 17:53:44 +02001243static int sta_apply_auth_flags(struct ieee80211_local *local,
1244 struct sta_info *sta,
1245 u32 mask, u32 set)
1246{
1247 int ret;
1248
1249 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1250 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1251 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1252 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1253 if (ret)
1254 return ret;
1255 }
1256
1257 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1258 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1259 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1260 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1261 if (ret)
1262 return ret;
1263 }
1264
1265 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1266 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1267 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1268 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1269 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1270 else
1271 ret = 0;
1272 if (ret)
1273 return ret;
1274 }
1275
1276 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1277 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1278 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1279 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1280 if (ret)
1281 return ret;
1282 }
1283
1284 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1285 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1286 test_sta_flag(sta, WLAN_STA_AUTH)) {
1287 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1288 if (ret)
1289 return ret;
1290 }
1291
1292 return 0;
1293}
1294
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001295static int sta_apply_parameters(struct ieee80211_local *local,
1296 struct sta_info *sta,
1297 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001298{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001299 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001300 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001301 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001302 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001303 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001304
Johannes Berg55de9082012-07-26 17:24:39 +02001305 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001306
Johannes Bergeccb8e82009-05-11 21:57:56 +03001307 mask = params->sta_flags_mask;
1308 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001309
Johannes Bergd582cff2012-10-26 17:53:44 +02001310 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1311 /*
1312 * In mesh mode, ASSOCIATED isn't part of the nl80211
1313 * API but must follow AUTHENTICATED for driver state.
1314 */
1315 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1316 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1317 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1318 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001319 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1320 /*
1321 * TDLS -- everything follows authorized, but
1322 * only becoming authorized is possible, not
1323 * going back
1324 */
1325 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1326 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1327 BIT(NL80211_STA_FLAG_ASSOCIATED);
1328 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1329 BIT(NL80211_STA_FLAG_ASSOCIATED);
1330 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001331 }
1332
Johannes Bergd582cff2012-10-26 17:53:44 +02001333 ret = sta_apply_auth_flags(local, sta, mask, set);
1334 if (ret)
1335 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001336
Johannes Bergeccb8e82009-05-11 21:57:56 +03001337 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001338 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001339 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1340 else
1341 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001342 }
1343
1344 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001345 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001346 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001347 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001348 } else {
1349 clear_sta_flag(sta, WLAN_STA_WME);
1350 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001351 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001352 }
1353
1354 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001355 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001356 set_sta_flag(sta, WLAN_STA_MFP);
1357 else
1358 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001359 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001360
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001361 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001362 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001363 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1364 else
1365 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001366 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001367
Johannes Berg3b9ce802011-09-27 20:56:12 +02001368 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1369 sta->sta.uapsd_queues = params->uapsd_queues;
1370 sta->sta.max_sp = params->max_sp;
1371 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001372
Johannes Berg73651ee2008-02-25 16:27:47 +01001373 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001374 * cfg80211 validates this (1-2007) and allows setting the AID
1375 * only when creating a new station entry
1376 */
1377 if (params->aid)
1378 sta->sta.aid = params->aid;
1379
1380 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001381 * Some of the following updates would be racy if called on an
1382 * existing station, via ieee80211_change_station(). However,
1383 * all such changes are rejected by cfg80211 except for updates
1384 * changing the supported rates on an existing but not yet used
1385 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001386 */
1387
Johannes Berg4fd69312007-12-19 02:03:35 +01001388 if (params->listen_interval >= 0)
1389 sta->listen_interval = params->listen_interval;
1390
1391 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001392 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1393 sband, params->supported_rates,
1394 params->supported_rates_len,
1395 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001396 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001397
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001398 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001399 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001400 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001401
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001402 if (params->vht_capa)
1403 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001404 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001405
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001406 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001407 /* returned value is only needed for rc update, but the
1408 * rc isn't initialized here yet, so ignore it
1409 */
1410 __ieee80211_vht_handle_opmode(sdata, sta,
1411 params->opmode_notif,
1412 band, false);
1413 }
1414
Javier Cardona9c3990a2011-05-03 16:57:11 -07001415 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001416#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001417 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001418
1419 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001420 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001421 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001422 if (sta->plink_state != NL80211_PLINK_ESTAB)
1423 changed = mesh_plink_inc_estab_count(
1424 sdata);
1425 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001426
1427 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001428 changed |= ieee80211_mps_set_sta_local_pm(sta,
1429 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001430 break;
1431 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001432 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001433 case NL80211_PLINK_OPN_SNT:
1434 case NL80211_PLINK_OPN_RCVD:
1435 case NL80211_PLINK_CNF_RCVD:
1436 case NL80211_PLINK_HOLDING:
1437 if (sta->plink_state == NL80211_PLINK_ESTAB)
1438 changed = mesh_plink_dec_estab_count(
1439 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001440 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001441
1442 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001443 changed |= ieee80211_mps_set_sta_local_pm(sta,
1444 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001445 break;
1446 default:
1447 /* nothing */
1448 break;
1449 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001450 }
1451
1452 switch (params->plink_action) {
1453 case NL80211_PLINK_ACTION_NO_ACTION:
1454 /* nothing */
1455 break;
1456 case NL80211_PLINK_ACTION_OPEN:
1457 changed |= mesh_plink_open(sta);
1458 break;
1459 case NL80211_PLINK_ACTION_BLOCK:
1460 changed |= mesh_plink_block(sta);
1461 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001462 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001463
1464 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001465 changed |=
1466 ieee80211_mps_set_sta_local_pm(sta,
1467 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001468 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001469#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001470 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001471
1472 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001473}
1474
1475static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001476 const u8 *mac,
1477 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001478{
Johannes Berg14db74b2008-07-29 13:22:52 +02001479 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001480 struct sta_info *sta;
1481 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001482 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001483 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001484
Johannes Berg4fd69312007-12-19 02:03:35 +01001485 if (params->vlan) {
1486 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1487
Johannes Berg05c914fe2008-09-11 00:01:58 +02001488 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1489 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001490 return -EINVAL;
1491 } else
1492 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1493
Joe Perchesb203ca32012-05-08 18:56:52 +00001494 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001495 return -EINVAL;
1496
1497 if (is_multicast_ether_addr(mac))
1498 return -EINVAL;
1499
1500 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001501 if (!sta)
1502 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001503
Johannes Bergd582cff2012-10-26 17:53:44 +02001504 /*
1505 * defaults -- if userspace wants something else we'll
1506 * change it accordingly in sta_apply_parameters()
1507 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001508 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1509 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1510 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001511 } else {
1512 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001513 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001514
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001515 err = sta_apply_parameters(local, sta, params);
1516 if (err) {
1517 sta_info_free(local, sta);
1518 return err;
1519 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001520
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001521 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001522 * for TDLS, rate control should be initialized only when
1523 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001524 */
1525 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1526 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001527
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001528 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1529 sdata->vif.type == NL80211_IFTYPE_AP;
1530
Johannes Berg34e89502010-02-03 13:59:58 +01001531 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001532 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001533 rcu_read_unlock();
1534 return err;
1535 }
1536
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001537 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001538 ieee80211_send_layer2_update(sta);
1539
1540 rcu_read_unlock();
1541
Johannes Berg4fd69312007-12-19 02:03:35 +01001542 return 0;
1543}
1544
1545static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001546 const u8 *mac)
Johannes Berg4fd69312007-12-19 02:03:35 +01001547{
Johannes Berg14db74b2008-07-29 13:22:52 +02001548 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001549
Johannes Berg14db74b2008-07-29 13:22:52 +02001550 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1551
Johannes Berg34e89502010-02-03 13:59:58 +01001552 if (mac)
1553 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001554
Johannes Bergb998e8b2012-12-13 23:07:46 +01001555 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001556 return 0;
1557}
1558
1559static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001560 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001561 struct station_parameters *params)
1562{
Johannes Bergabe60632009-11-25 17:46:18 +01001563 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001564 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001565 struct sta_info *sta;
1566 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001567 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001568 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001569
Johannes Berg87be1e12011-12-14 12:20:29 +01001570 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001571
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001572 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001573 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001574 err = -ENOENT;
1575 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001576 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001577
Johannes Berg77ee7c82013-02-15 00:48:33 +01001578 switch (sdata->vif.type) {
1579 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001580 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001581 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001582 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001583 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001584 break;
1585 case NL80211_IFTYPE_ADHOC:
1586 statype = CFG80211_STA_IBSS;
1587 break;
1588 case NL80211_IFTYPE_STATION:
1589 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1590 statype = CFG80211_STA_AP_STA;
1591 break;
1592 }
1593 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1594 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1595 else
1596 statype = CFG80211_STA_TDLS_PEER_SETUP;
1597 break;
1598 case NL80211_IFTYPE_AP:
1599 case NL80211_IFTYPE_AP_VLAN:
1600 statype = CFG80211_STA_AP_CLIENT;
1601 break;
1602 default:
1603 err = -EOPNOTSUPP;
1604 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001605 }
1606
Johannes Berg77ee7c82013-02-15 00:48:33 +01001607 err = cfg80211_check_station_change(wiphy, params, statype);
1608 if (err)
1609 goto out_err;
1610
Johannes Bergd0709a62008-02-25 16:27:46 +01001611 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001612 bool prev_4addr = false;
1613 bool new_4addr = false;
1614
Johannes Berg4fd69312007-12-19 02:03:35 +01001615 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1616
Johannes Berg9bc383d2009-11-19 11:55:19 +01001617 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001618 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001619 err = -EBUSY;
1620 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001621 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001622
Eric Dumazetcf778b02012-01-12 04:41:32 +00001623 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001624 new_4addr = true;
1625 }
1626
1627 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1628 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301629 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001630 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001631 }
1632
Johannes Berg14db74b2008-07-29 13:22:52 +02001633 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001634
1635 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1636 prev_4addr != new_4addr) {
1637 if (new_4addr)
1638 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1639 else
1640 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1641 }
1642
Johannes Berg4fd69312007-12-19 02:03:35 +01001643 ieee80211_send_layer2_update(sta);
1644 }
1645
Eliad Peller35b88622011-12-29 14:41:39 +02001646 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001647 if (err)
1648 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001649
Johannes Berg77ee7c82013-02-15 00:48:33 +01001650 /* When peer becomes authorized, init rate control as well */
1651 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1652 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001653 rate_control_rate_init(sta);
1654
Johannes Berg87be1e12011-12-14 12:20:29 +01001655 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001656
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001657 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1658 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1659 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1660 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1661 sta_info_tx_streams(sta) != 1) {
1662 ht_dbg(sta->sdata,
1663 "%pM just authorized and MIMO capable - update SMPS\n",
1664 sta->sta.addr);
1665 ieee80211_send_smps_action(sta->sdata,
1666 sta->sdata->bss->req_smps,
1667 sta->sta.addr,
1668 sta->sdata->vif.bss_conf.bssid);
1669 }
1670
Jason Young808118c2011-03-10 16:43:19 -08001671 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001672 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001673 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001674 ieee80211_recalc_ps_vif(sdata);
1675 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001676
Johannes Berg4fd69312007-12-19 02:03:35 +01001677 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001678out_err:
1679 mutex_unlock(&local->sta_mtx);
1680 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001681}
1682
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001683#ifdef CONFIG_MAC80211_MESH
1684static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001685 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001686{
Johannes Berg14db74b2008-07-29 13:22:52 +02001687 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001688 struct mesh_path *mpath;
1689 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001690
Johannes Berg14db74b2008-07-29 13:22:52 +02001691 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1692
Johannes Bergd0709a62008-02-25 16:27:46 +01001693 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001694 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001695 if (!sta) {
1696 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001697 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001698 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001699
Bob Copelandae76eef2013-03-29 09:38:39 -04001700 mpath = mesh_path_add(sdata, dst);
1701 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001702 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001703 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001704 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001705
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001706 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001707
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001708 rcu_read_unlock();
1709 return 0;
1710}
1711
1712static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001713 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001714{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001716
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001717 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001718 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001719
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001720 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001721 return 0;
1722}
1723
Johannes Berg3b3a0162014-05-19 17:19:31 +02001724static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1725 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001726{
Johannes Berg14db74b2008-07-29 13:22:52 +02001727 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001728 struct mesh_path *mpath;
1729 struct sta_info *sta;
1730
Johannes Berg14db74b2008-07-29 13:22:52 +02001731 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1732
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001733 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001734
Johannes Bergabe60632009-11-25 17:46:18 +01001735 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001736 if (!sta) {
1737 rcu_read_unlock();
1738 return -ENOENT;
1739 }
1740
Johannes Bergbf7cd942013-02-15 14:40:31 +01001741 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001742 if (!mpath) {
1743 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001744 return -ENOENT;
1745 }
1746
1747 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001748
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001749 rcu_read_unlock();
1750 return 0;
1751}
1752
1753static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1754 struct mpath_info *pinfo)
1755{
Johannes Berga3836e02011-05-12 15:11:37 +02001756 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1757
1758 if (next_hop_sta)
1759 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001760 else
1761 memset(next_hop, 0, ETH_ALEN);
1762
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001763 memset(pinfo, 0, sizeof(*pinfo));
1764
Johannes Bergf5ea9122009-08-07 16:17:38 +02001765 pinfo->generation = mesh_paths_generation;
1766
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001767 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001768 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001769 MPATH_INFO_METRIC |
1770 MPATH_INFO_EXPTIME |
1771 MPATH_INFO_DISCOVERY_TIMEOUT |
1772 MPATH_INFO_DISCOVERY_RETRIES |
1773 MPATH_INFO_FLAGS;
1774
1775 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001776 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001777 pinfo->metric = mpath->metric;
1778 if (time_before(jiffies, mpath->exp_time))
1779 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1780 pinfo->discovery_timeout =
1781 jiffies_to_msecs(mpath->discovery_timeout);
1782 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001783 if (mpath->flags & MESH_PATH_ACTIVE)
1784 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1785 if (mpath->flags & MESH_PATH_RESOLVING)
1786 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001787 if (mpath->flags & MESH_PATH_SN_VALID)
1788 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001789 if (mpath->flags & MESH_PATH_FIXED)
1790 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001791 if (mpath->flags & MESH_PATH_RESOLVED)
1792 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001793}
1794
1795static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1796 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1797
1798{
Johannes Berg14db74b2008-07-29 13:22:52 +02001799 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001800 struct mesh_path *mpath;
1801
Johannes Berg14db74b2008-07-29 13:22:52 +02001802 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1803
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001804 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001805 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001806 if (!mpath) {
1807 rcu_read_unlock();
1808 return -ENOENT;
1809 }
1810 memcpy(dst, mpath->dst, ETH_ALEN);
1811 mpath_set_pinfo(mpath, next_hop, pinfo);
1812 rcu_read_unlock();
1813 return 0;
1814}
1815
1816static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001817 int idx, u8 *dst, u8 *next_hop,
1818 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001819{
Johannes Berg14db74b2008-07-29 13:22:52 +02001820 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001821 struct mesh_path *mpath;
1822
Johannes Berg14db74b2008-07-29 13:22:52 +02001823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1824
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001825 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001826 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001827 if (!mpath) {
1828 rcu_read_unlock();
1829 return -ENOENT;
1830 }
1831 memcpy(dst, mpath->dst, ETH_ALEN);
1832 mpath_set_pinfo(mpath, next_hop, pinfo);
1833 rcu_read_unlock();
1834 return 0;
1835}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001836
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001837static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001838 struct net_device *dev,
1839 struct mesh_config *conf)
1840{
1841 struct ieee80211_sub_if_data *sdata;
1842 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1843
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001844 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1845 return 0;
1846}
1847
1848static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1849{
1850 return (mask >> (parm-1)) & 0x1;
1851}
1852
Javier Cardonac80d5452010-12-16 17:37:49 -08001853static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1854 const struct mesh_setup *setup)
1855{
1856 u8 *new_ie;
1857 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001858 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1859 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001860
Javier Cardona581a8b02011-04-07 15:08:27 -07001861 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001862 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001863 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001864
Javier Cardona581a8b02011-04-07 15:08:27 -07001865 if (setup->ie_len) {
1866 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001867 GFP_KERNEL);
1868 if (!new_ie)
1869 return -ENOMEM;
1870 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001871 ifmsh->ie_len = setup->ie_len;
1872 ifmsh->ie = new_ie;
1873 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001874
1875 /* now copy the rest of the setup parameters */
1876 ifmsh->mesh_id_len = setup->mesh_id_len;
1877 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001878 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001879 ifmsh->mesh_pp_id = setup->path_sel_proto;
1880 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001881 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001882 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001883 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1884 if (setup->is_authenticated)
1885 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1886 if (setup->is_secure)
1887 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001888
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001889 /* mcast rate setting in Mesh Node */
1890 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1891 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001892 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001893
Marco Porsch9bdbf042013-01-07 16:04:51 +01001894 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1895 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1896
Javier Cardonac80d5452010-12-16 17:37:49 -08001897 return 0;
1898}
1899
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001900static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001901 struct net_device *dev, u32 mask,
1902 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001903{
1904 struct mesh_config *conf;
1905 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001906 struct ieee80211_if_mesh *ifmsh;
1907
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001908 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001909 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001910
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001911 /* Set the config options which we are interested in setting */
1912 conf = &(sdata->u.mesh.mshcfg);
1913 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1914 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1915 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1916 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1917 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1918 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1919 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1920 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1921 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1922 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1923 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1924 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001925 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001926 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001927 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1928 if (ifmsh->user_mpm)
1929 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001930 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001931 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001932 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1933 conf->dot11MeshNbrOffsetMaxNeighbor =
1934 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001935 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1936 conf->dot11MeshHWMPmaxPREQretries =
1937 nconf->dot11MeshHWMPmaxPREQretries;
1938 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1939 conf->path_refresh_time = nconf->path_refresh_time;
1940 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1941 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1942 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1943 conf->dot11MeshHWMPactivePathTimeout =
1944 nconf->dot11MeshHWMPactivePathTimeout;
1945 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1946 conf->dot11MeshHWMPpreqMinInterval =
1947 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001948 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1949 conf->dot11MeshHWMPperrMinInterval =
1950 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001951 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1952 mask))
1953 conf->dot11MeshHWMPnetDiameterTraversalTime =
1954 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001955 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1956 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1957 ieee80211_mesh_root_setup(ifmsh);
1958 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001959 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001960 /* our current gate announcement implementation rides on root
1961 * announcements, so require this ifmsh to also be a root node
1962 * */
1963 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001964 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1965 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001966 ieee80211_mesh_root_setup(ifmsh);
1967 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001968 conf->dot11MeshGateAnnouncementProtocol =
1969 nconf->dot11MeshGateAnnouncementProtocol;
1970 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001971 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001972 conf->dot11MeshHWMPRannInterval =
1973 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001974 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1975 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001976 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1977 /* our RSSI threshold implementation is supported only for
1978 * devices that report signal in dBm.
1979 */
1980 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1981 return -ENOTSUPP;
1982 conf->rssi_threshold = nconf->rssi_threshold;
1983 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001984 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1985 conf->ht_opmode = nconf->ht_opmode;
1986 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1987 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1988 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001989 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1990 conf->dot11MeshHWMPactivePathToRootTimeout =
1991 nconf->dot11MeshHWMPactivePathToRootTimeout;
1992 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1993 conf->dot11MeshHWMProotInterval =
1994 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1996 conf->dot11MeshHWMPconfirmationInterval =
1997 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001998 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1999 conf->power_mode = nconf->power_mode;
2000 ieee80211_mps_local_status_update(sdata);
2001 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002002 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002003 conf->dot11MeshAwakeWindowDuration =
2004 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07002005 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2006 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002007 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002008 return 0;
2009}
2010
Johannes Berg29cbe682010-12-03 09:20:44 +01002011static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2012 const struct mesh_config *conf,
2013 const struct mesh_setup *setup)
2014{
2015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2016 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08002017 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01002018
Javier Cardonac80d5452010-12-16 17:37:49 -08002019 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2020 err = copy_mesh_setup(ifmsh, setup);
2021 if (err)
2022 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002023
Johannes Berg04ecd252012-09-11 14:34:12 +02002024 /* can mesh use other SMPS modes? */
2025 sdata->smps_mode = IEEE80211_SMPS_OFF;
2026 sdata->needed_rx_chains = sdata->local->rx_chains;
2027
Johannes Berg34a37402013-12-18 09:43:33 +01002028 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01002029 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02002030 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01002031 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002032 if (err)
2033 return err;
2034
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002035 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01002036}
2037
2038static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2039{
2040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2041
2042 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002043 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002044 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002045 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01002046
2047 return 0;
2048}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002049#endif
2050
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002051static int ieee80211_change_bss(struct wiphy *wiphy,
2052 struct net_device *dev,
2053 struct bss_parameters *params)
2054{
Johannes Berg55de9082012-07-26 17:24:39 +02002055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2056 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002057 u32 changed = 0;
2058
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01002059 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02002060 return -ENOENT;
2061
2062 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002063
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002064 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002065 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002066 changed |= BSS_CHANGED_ERP_CTS_PROT;
2067 }
2068 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002069 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002070 params->use_short_preamble;
2071 changed |= BSS_CHANGED_ERP_PREAMBLE;
2072 }
Felix Fietkau43d35342010-01-15 03:00:48 +01002073
2074 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02002075 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01002076 sdata->vif.bss_conf.use_short_slot = true;
2077 changed |= BSS_CHANGED_ERP_SLOT;
2078 }
2079
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002080 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002081 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002082 params->use_short_slot_time;
2083 changed |= BSS_CHANGED_ERP_SLOT;
2084 }
2085
Jouni Malinen90c97a02008-10-30 16:59:22 +02002086 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002087 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2088 wiphy->bands[band],
2089 params->basic_rates,
2090 params->basic_rates_len,
2091 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002092 changed |= BSS_CHANGED_BASIC_RATES;
2093 }
2094
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002095 if (params->ap_isolate >= 0) {
2096 if (params->ap_isolate)
2097 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2098 else
2099 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2100 }
2101
Helmut Schaa80d7e402010-11-19 12:40:26 +01002102 if (params->ht_opmode >= 0) {
2103 sdata->vif.bss_conf.ht_operation_mode =
2104 (u16) params->ht_opmode;
2105 changed |= BSS_CHANGED_HT;
2106 }
2107
Johannes Berg339afbf2012-11-14 15:21:17 +01002108 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002109 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2110 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2111 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2112 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002113 changed |= BSS_CHANGED_P2P_PS;
2114 }
2115
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002116 if (params->p2p_opp_ps > 0) {
2117 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2118 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2119 changed |= BSS_CHANGED_P2P_PS;
2120 } else if (params->p2p_opp_ps == 0) {
2121 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2122 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002123 changed |= BSS_CHANGED_P2P_PS;
2124 }
2125
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002126 ieee80211_bss_info_change_notify(sdata, changed);
2127
2128 return 0;
2129}
2130
Jouni Malinen31888482008-10-30 16:59:24 +02002131static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002132 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002133 struct ieee80211_txq_params *params)
2134{
2135 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002137 struct ieee80211_tx_queue_params p;
2138
2139 if (!local->ops->conf_tx)
2140 return -EOPNOTSUPP;
2141
Johannes Berg54bcbc62012-03-28 11:04:25 +02002142 if (local->hw.queues < IEEE80211_NUM_ACS)
2143 return -EOPNOTSUPP;
2144
Jouni Malinen31888482008-10-30 16:59:24 +02002145 memset(&p, 0, sizeof(p));
2146 p.aifs = params->aifs;
2147 p.cw_max = params->cwmax;
2148 p.cw_min = params->cwmin;
2149 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002150
2151 /*
2152 * Setting tx queue params disables u-apsd because it's only
2153 * called in master mode.
2154 */
2155 p.uapsd = false;
2156
Johannes Berga3304b02012-03-28 11:04:24 +02002157 sdata->tx_conf[params->ac] = p;
2158 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002159 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002160 "failed to set TX queue parameters for AC %d\n",
2161 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002162 return -EINVAL;
2163 }
2164
Johannes Berg7d257452012-07-06 17:37:43 +02002165 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2166
Jouni Malinen31888482008-10-30 16:59:24 +02002167 return 0;
2168}
2169
Bob Copeland665af4f2009-01-19 11:20:53 -05002170#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002171static int ieee80211_suspend(struct wiphy *wiphy,
2172 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002173{
Johannes Bergeecc4802011-05-04 15:37:29 +02002174 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002175}
2176
2177static int ieee80211_resume(struct wiphy *wiphy)
2178{
2179 return __ieee80211_resume(wiphy_priv(wiphy));
2180}
2181#else
2182#define ieee80211_suspend NULL
2183#define ieee80211_resume NULL
2184#endif
2185
Johannes Berg2a519312009-02-10 21:25:55 +01002186static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002187 struct cfg80211_scan_request *req)
2188{
Johannes Bergfd014282012-06-18 19:17:03 +02002189 struct ieee80211_sub_if_data *sdata;
2190
2191 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002192
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002193 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2194 case NL80211_IFTYPE_STATION:
2195 case NL80211_IFTYPE_ADHOC:
2196 case NL80211_IFTYPE_MESH_POINT:
2197 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002198 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002199 break;
2200 case NL80211_IFTYPE_P2P_GO:
2201 if (sdata->local->ops->hw_scan)
2202 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002203 /*
2204 * FIXME: implement NoA while scanning in software,
2205 * for now fall through to allow scanning only when
2206 * beaconing hasn't been configured yet
2207 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002208 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002209 /*
2210 * If the scan has been forced (and the driver supports
2211 * forcing), don't care about being beaconing already.
2212 * This will create problems to the attached stations (e.g. all
2213 * the frames sent while scanning on other channel will be
2214 * lost)
2215 */
2216 if (sdata->u.ap.beacon &&
2217 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2218 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002219 return -EOPNOTSUPP;
2220 break;
2221 default:
2222 return -EOPNOTSUPP;
2223 }
Johannes Berg2a519312009-02-10 21:25:55 +01002224
2225 return ieee80211_request_scan(sdata, req);
2226}
2227
Luciano Coelho79f460c2011-05-11 17:09:36 +03002228static int
2229ieee80211_sched_scan_start(struct wiphy *wiphy,
2230 struct net_device *dev,
2231 struct cfg80211_sched_scan_request *req)
2232{
2233 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2234
2235 if (!sdata->local->ops->sched_scan_start)
2236 return -EOPNOTSUPP;
2237
2238 return ieee80211_request_sched_scan_start(sdata, req);
2239}
2240
2241static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002242ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002243{
2244 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2245
2246 if (!sdata->local->ops->sched_scan_stop)
2247 return -EOPNOTSUPP;
2248
Luciano Coelho85a99942011-05-12 16:28:29 +03002249 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002250}
2251
Jouni Malinen636a5d32009-03-19 13:39:22 +02002252static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2253 struct cfg80211_auth_request *req)
2254{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002255 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002256}
2257
2258static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2259 struct cfg80211_assoc_request *req)
2260{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002261 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002262}
2263
2264static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002265 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002266{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002267 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002268}
2269
2270static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002271 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002272{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002273 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002274}
2275
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002276static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2277 struct cfg80211_ibss_params *params)
2278{
Johannes Berg55de9082012-07-26 17:24:39 +02002279 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002280}
2281
2282static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2283{
Johannes Berg55de9082012-07-26 17:24:39 +02002284 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002285}
2286
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002287static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2288 int rate[IEEE80211_NUM_BANDS])
2289{
2290 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2291
Cong Ding9887dbf2013-02-06 17:23:45 +01002292 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2293 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002294
2295 return 0;
2296}
2297
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002298static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2299{
2300 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002301 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002302
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002303 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2304 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2305
2306 if (err)
2307 return err;
2308 }
2309
Lukáš Turek310bc672009-12-21 22:50:48 +01002310 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2311 err = drv_set_coverage_class(local, wiphy->coverage_class);
2312
2313 if (err)
2314 return err;
2315 }
2316
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002318 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002319
Johannes Berg24487982009-04-23 18:52:52 +02002320 if (err)
2321 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002322 }
2323
Johannes Berg8bc83c22012-11-09 18:38:32 +01002324 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2325 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2326 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002327 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002328 }
2329 if (changed & WIPHY_PARAM_RETRY_LONG) {
2330 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2331 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002332 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002333 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002334 if (changed &
2335 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2336 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2337
2338 return 0;
2339}
2340
Johannes Berg7643a2c2009-06-02 13:01:39 +02002341static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002342 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002343 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002344{
2345 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002346 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002347
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002348 if (wdev) {
2349 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2350
2351 switch (type) {
2352 case NL80211_TX_POWER_AUTOMATIC:
2353 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2354 break;
2355 case NL80211_TX_POWER_LIMITED:
2356 case NL80211_TX_POWER_FIXED:
2357 if (mbm < 0 || (mbm % 100))
2358 return -EOPNOTSUPP;
2359 sdata->user_power_level = MBM_TO_DBM(mbm);
2360 break;
2361 }
2362
2363 ieee80211_recalc_txpower(sdata);
2364
2365 return 0;
2366 }
Johannes Berg55de9082012-07-26 17:24:39 +02002367
Johannes Berg7643a2c2009-06-02 13:01:39 +02002368 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002369 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002370 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002371 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002372 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002373 case NL80211_TX_POWER_FIXED:
2374 if (mbm < 0 || (mbm % 100))
2375 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002376 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002377 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002378 }
2379
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002380 mutex_lock(&local->iflist_mtx);
2381 list_for_each_entry(sdata, &local->interfaces, list)
2382 sdata->user_power_level = local->user_power_level;
2383 list_for_each_entry(sdata, &local->interfaces, list)
2384 ieee80211_recalc_txpower(sdata);
2385 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002386
2387 return 0;
2388}
2389
Johannes Bergc8442112012-10-24 10:17:18 +02002390static int ieee80211_get_tx_power(struct wiphy *wiphy,
2391 struct wireless_dev *wdev,
2392 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002393{
2394 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002395 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002396
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002397 if (!local->use_chanctx)
2398 *dbm = local->hw.conf.power_level;
2399 else
2400 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002401
Johannes Berg7643a2c2009-06-02 13:01:39 +02002402 return 0;
2403}
2404
Johannes Bergab737a42009-07-01 21:26:58 +02002405static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002406 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002407{
2408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2409
2410 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2411
2412 return 0;
2413}
2414
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002415static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2416{
2417 struct ieee80211_local *local = wiphy_priv(wiphy);
2418
2419 drv_rfkill_poll(local);
2420}
2421
Johannes Bergaff89a92009-07-01 21:26:51 +02002422#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002423static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2424 struct wireless_dev *wdev,
2425 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002426{
2427 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002428 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002429
2430 if (!local->ops->testmode_cmd)
2431 return -EOPNOTSUPP;
2432
David Spinadel52981cd2013-07-31 18:06:22 +03002433 if (wdev) {
2434 struct ieee80211_sub_if_data *sdata;
2435
2436 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2437 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2438 vif = &sdata->vif;
2439 }
2440
2441 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002442}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002443
2444static int ieee80211_testmode_dump(struct wiphy *wiphy,
2445 struct sk_buff *skb,
2446 struct netlink_callback *cb,
2447 void *data, int len)
2448{
2449 struct ieee80211_local *local = wiphy_priv(wiphy);
2450
2451 if (!local->ops->testmode_dump)
2452 return -EOPNOTSUPP;
2453
2454 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2455}
Johannes Bergaff89a92009-07-01 21:26:51 +02002456#endif
2457
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002458int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2459 enum ieee80211_smps_mode smps_mode)
2460{
2461 struct sta_info *sta;
2462 enum ieee80211_smps_mode old_req;
2463 int i;
2464
2465 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2466 return -EINVAL;
2467
2468 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2469 return 0;
2470
2471 old_req = sdata->u.ap.req_smps;
2472 sdata->u.ap.req_smps = smps_mode;
2473
2474 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2475 if (old_req == smps_mode ||
2476 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2477 return 0;
2478
2479 /* If no associated stations, there's no need to do anything */
2480 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2481 sdata->smps_mode = smps_mode;
2482 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2483 return 0;
2484 }
2485
2486 ht_dbg(sdata,
2487 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2488 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2489
2490 mutex_lock(&sdata->local->sta_mtx);
2491 for (i = 0; i < STA_HASH_SIZE; i++) {
2492 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2493 lockdep_is_held(&sdata->local->sta_mtx));
2494 sta;
2495 sta = rcu_dereference_protected(sta->hnext,
2496 lockdep_is_held(&sdata->local->sta_mtx))) {
2497 /*
2498 * Only stations associated to our AP and
2499 * associated VLANs
2500 */
2501 if (sta->sdata->bss != &sdata->u.ap)
2502 continue;
2503
2504 /* This station doesn't support MIMO - skip it */
2505 if (sta_info_tx_streams(sta) == 1)
2506 continue;
2507
2508 /*
2509 * Don't wake up a STA just to send the action frame
2510 * unless we are getting more restrictive.
2511 */
2512 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2513 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2514 smps_mode)) {
2515 ht_dbg(sdata,
2516 "Won't send SMPS to sleeping STA %pM\n",
2517 sta->sta.addr);
2518 continue;
2519 }
2520
2521 /*
2522 * If the STA is not authorized, wait until it gets
2523 * authorized and the action frame will be sent then.
2524 */
2525 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2526 continue;
2527
2528 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2529 ieee80211_send_smps_action(sdata, smps_mode,
2530 sta->sta.addr,
2531 sdata->vif.bss_conf.bssid);
2532 }
2533 }
2534 mutex_unlock(&sdata->local->sta_mtx);
2535
2536 sdata->smps_mode = smps_mode;
2537 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2538
2539 return 0;
2540}
2541
2542int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2543 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002544{
2545 const u8 *ap;
2546 enum ieee80211_smps_mode old_req;
2547 int err;
2548
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002549 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002550
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002551 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2552 return -EINVAL;
2553
Johannes Berg0f782312009-12-01 13:37:02 +01002554 old_req = sdata->u.mgd.req_smps;
2555 sdata->u.mgd.req_smps = smps_mode;
2556
2557 if (old_req == smps_mode &&
2558 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2559 return 0;
2560
2561 /*
2562 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002563 * association, there's no need to do anything, just store
2564 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002565 */
2566 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002567 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002568 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002569
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002570 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002571
2572 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2573 if (sdata->u.mgd.powersave)
2574 smps_mode = IEEE80211_SMPS_DYNAMIC;
2575 else
2576 smps_mode = IEEE80211_SMPS_OFF;
2577 }
2578
2579 /* send SM PS frame to AP */
2580 err = ieee80211_send_smps_action(sdata, smps_mode,
2581 ap, ap);
2582 if (err)
2583 sdata->u.mgd.req_smps = old_req;
2584
2585 return err;
2586}
2587
Johannes Bergbc92afd2009-07-01 21:26:57 +02002588static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2589 bool enabled, int timeout)
2590{
2591 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2592 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002593
Bob Copeland2d3db212013-10-29 18:11:59 -04002594 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002595 return -EOPNOTSUPP;
2596
Johannes Bergbc92afd2009-07-01 21:26:57 +02002597 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2598 return -EOPNOTSUPP;
2599
2600 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002601 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002602 return 0;
2603
2604 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002605 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002606
Johannes Berg0f782312009-12-01 13:37:02 +01002607 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002608 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002609 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002610 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002611
Johannes Bergbc92afd2009-07-01 21:26:57 +02002612 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2613 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2614
2615 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002616 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002617
2618 return 0;
2619}
2620
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002621static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2622 struct net_device *dev,
2623 s32 rssi_thold, u32 rssi_hyst)
2624{
2625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002626 struct ieee80211_vif *vif = &sdata->vif;
2627 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2628
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002629 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2630 rssi_hyst == bss_conf->cqm_rssi_hyst)
2631 return 0;
2632
2633 bss_conf->cqm_rssi_thold = rssi_thold;
2634 bss_conf->cqm_rssi_hyst = rssi_hyst;
2635
2636 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002637 if (sdata->u.mgd.associated &&
2638 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002639 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2640
2641 return 0;
2642}
2643
Johannes Berg99303802009-07-01 21:26:59 +02002644static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2645 struct net_device *dev,
2646 const u8 *addr,
2647 const struct cfg80211_bitrate_mask *mask)
2648{
2649 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2650 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302651 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002652
Eliad Peller554a43d2012-06-12 12:41:15 +03002653 if (!ieee80211_sdata_running(sdata))
2654 return -ENETDOWN;
2655
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302656 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2657 ret = drv_set_bitrate_mask(local, sdata, mask);
2658 if (ret)
2659 return ret;
2660 }
Johannes Berg99303802009-07-01 21:26:59 +02002661
Simon Wunderlich19468412012-01-28 17:25:33 +01002662 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002663 struct ieee80211_supported_band *sband = wiphy->bands[i];
2664 int j;
2665
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002666 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002667 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2668 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002669
2670 sdata->rc_has_mcs_mask[i] = false;
2671 if (!sband)
2672 continue;
2673
2674 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2675 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2676 sdata->rc_has_mcs_mask[i] = true;
2677 break;
2678 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002679 }
Johannes Berg99303802009-07-01 21:26:59 +02002680
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002681 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002682}
2683
Johannes Berg2eb278e2012-06-05 14:28:42 +02002684static int ieee80211_start_roc_work(struct ieee80211_local *local,
2685 struct ieee80211_sub_if_data *sdata,
2686 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002687 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002688 struct sk_buff *txskb,
2689 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002690{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002691 struct ieee80211_roc_work *roc, *tmp;
2692 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002693 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002694
2695 lockdep_assert_held(&local->mtx);
2696
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002697 if (local->use_chanctx && !local->ops->remain_on_channel)
2698 return -EOPNOTSUPP;
2699
Johannes Berg2eb278e2012-06-05 14:28:42 +02002700 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2701 if (!roc)
2702 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002703
Ilan Peer2fae0622013-12-19 13:25:29 +02002704 /*
2705 * If the duration is zero, then the driver
2706 * wouldn't actually do anything. Set it to
2707 * 10 for now.
2708 *
2709 * TODO: cancel the off-channel operation
2710 * when we get the SKB's TX status and
2711 * the wait time was zero before.
2712 */
2713 if (!duration)
2714 duration = 10;
2715
Johannes Berg2eb278e2012-06-05 14:28:42 +02002716 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002717 roc->duration = duration;
2718 roc->req_duration = duration;
2719 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002720 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002721 roc->mgmt_tx_cookie = (unsigned long)txskb;
2722 roc->sdata = sdata;
2723 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2724 INIT_LIST_HEAD(&roc->dependents);
2725
Eliad Peller2f617432014-01-12 11:06:37 +02002726 /*
2727 * cookie is either the roc cookie (for normal roc)
2728 * or the SKB (for mgmt TX)
2729 */
2730 if (!txskb) {
2731 /* local->mtx protects this */
2732 local->roc_cookie_counter++;
2733 roc->cookie = local->roc_cookie_counter;
2734 /* wow, you wrapped 64 bits ... more likely a bug */
2735 if (WARN_ON(roc->cookie == 0)) {
2736 roc->cookie = 1;
2737 local->roc_cookie_counter++;
2738 }
2739 *cookie = roc->cookie;
2740 } else {
2741 *cookie = (unsigned long)txskb;
2742 }
2743
Johannes Berg2eb278e2012-06-05 14:28:42 +02002744 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002745 if (!list_empty(&local->roc_list) ||
2746 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002747 goto out_check_combine;
2748
2749 /* if not HW assist, just queue & schedule work */
2750 if (!local->ops->remain_on_channel) {
2751 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2752 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002753 }
2754
Johannes Berg2eb278e2012-06-05 14:28:42 +02002755 /* otherwise actually kick it off here (for error handling) */
2756
Ilan Peerd339d5c2013-02-12 09:34:13 +02002757 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002758 if (ret) {
2759 kfree(roc);
2760 return ret;
2761 }
2762
2763 roc->started = true;
2764 goto out_queue;
2765
2766 out_check_combine:
2767 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002768 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002769 continue;
2770
2771 /*
2772 * Extend this ROC if possible:
2773 *
2774 * If it hasn't started yet, just increase the duration
2775 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002776 * If the type of the new ROC has higher priority, modify the
2777 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002778 */
2779 if (!tmp->started) {
2780 list_add_tail(&roc->list, &tmp->dependents);
2781 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002782 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002783 queued = true;
2784 break;
2785 }
2786
2787 /* If it has already started, it's more difficult ... */
2788 if (local->ops->remain_on_channel) {
2789 unsigned long j = jiffies;
2790
2791 /*
2792 * In the offloaded ROC case, if it hasn't begun, add
2793 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002794 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002795 * check that there's still a minimum time left and
2796 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002797 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002798 * a reduced time so we'll ask the driver to execute
2799 * it right after finishing the previous one, in the
2800 * hope that it'll also be executed right afterwards,
2801 * effectively extending the old one.
2802 * If there's no minimum time left, just add it to the
2803 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002804 * TODO: the ROC type is ignored here, assuming that it
2805 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002806 */
2807 if (!tmp->hw_begun) {
2808 list_add_tail(&roc->list, &tmp->dependents);
2809 queued = true;
2810 break;
2811 }
2812
2813 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2814 tmp->hw_start_time +
2815 msecs_to_jiffies(tmp->duration))) {
2816 int new_dur;
2817
2818 ieee80211_handle_roc_started(roc);
2819
2820 new_dur = roc->duration -
2821 jiffies_to_msecs(tmp->hw_start_time +
2822 msecs_to_jiffies(
2823 tmp->duration) -
2824 j);
2825
2826 if (new_dur > 0) {
2827 /* add right after tmp */
2828 list_add(&roc->list, &tmp->list);
2829 } else {
2830 list_add_tail(&roc->list,
2831 &tmp->dependents);
2832 }
2833 queued = true;
2834 }
2835 } else if (del_timer_sync(&tmp->work.timer)) {
2836 unsigned long new_end;
2837
2838 /*
2839 * In the software ROC case, cancel the timer, if
2840 * that fails then the finish work is already
2841 * queued/pending and thus we queue the new ROC
2842 * normally, if that succeeds then we can extend
2843 * the timer duration and TX the frame (if any.)
2844 */
2845
2846 list_add_tail(&roc->list, &tmp->dependents);
2847 queued = true;
2848
2849 new_end = jiffies + msecs_to_jiffies(roc->duration);
2850
2851 /* ok, it was started & we canceled timer */
2852 if (time_after(new_end, tmp->work.timer.expires))
2853 mod_timer(&tmp->work.timer, new_end);
2854 else
2855 add_timer(&tmp->work.timer);
2856
2857 ieee80211_handle_roc_started(roc);
2858 }
2859 break;
2860 }
2861
2862 out_queue:
2863 if (!queued)
2864 list_add_tail(&roc->list, &local->roc_list);
2865
Johannes Berg2eb278e2012-06-05 14:28:42 +02002866 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002867}
2868
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002869static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002870 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002871 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002872 unsigned int duration,
2873 u64 *cookie)
2874{
Johannes Berg71bbc992012-06-15 15:30:18 +02002875 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002876 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002877 int ret;
2878
Johannes Berg2eb278e2012-06-05 14:28:42 +02002879 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002880 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002881 duration, cookie, NULL,
2882 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002883 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002884
Johannes Berg2eb278e2012-06-05 14:28:42 +02002885 return ret;
2886}
2887
2888static int ieee80211_cancel_roc(struct ieee80211_local *local,
2889 u64 cookie, bool mgmt_tx)
2890{
2891 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2892 int ret;
2893
2894 mutex_lock(&local->mtx);
2895 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002896 struct ieee80211_roc_work *dep, *tmp2;
2897
2898 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002899 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002900 continue;
2901 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2902 continue;
2903 /* found dependent item -- just remove it */
2904 list_del(&dep->list);
2905 mutex_unlock(&local->mtx);
2906
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002907 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002908 return 0;
2909 }
2910
Johannes Berg50febf62012-10-26 16:13:06 +02002911 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002912 continue;
2913 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2914 continue;
2915
2916 found = roc;
2917 break;
2918 }
2919
2920 if (!found) {
2921 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002922 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002923 }
Johannes Berg21f83582010-12-18 17:20:47 +01002924
Johannes Berge979e332012-06-11 17:09:41 +02002925 /*
2926 * We found the item to cancel, so do that. Note that it
2927 * may have dependents, which we also cancel (and send
2928 * the expired signal for.) Not doing so would be quite
2929 * tricky here, but we may need to fix it later.
2930 */
2931
Johannes Berg2eb278e2012-06-05 14:28:42 +02002932 if (local->ops->remain_on_channel) {
2933 if (found->started) {
2934 ret = drv_cancel_remain_on_channel(local);
2935 if (WARN_ON_ONCE(ret)) {
2936 mutex_unlock(&local->mtx);
2937 return ret;
2938 }
2939 }
Johannes Berg21f83582010-12-18 17:20:47 +01002940
Johannes Berg2eb278e2012-06-05 14:28:42 +02002941 list_del(&found->list);
2942
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002943 if (found->started)
2944 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002945 mutex_unlock(&local->mtx);
2946
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002947 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002948 } else {
2949 /* work may be pending so use it all the time */
2950 found->abort = true;
2951 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2952
2953 mutex_unlock(&local->mtx);
2954
2955 /* work will clean up etc */
2956 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002957 WARN_ON(!found->to_be_freed);
2958 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002959 }
Johannes Berg21f83582010-12-18 17:20:47 +01002960
Johannes Berg21f83582010-12-18 17:20:47 +01002961 return 0;
2962}
2963
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002964static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002965 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002966 u64 cookie)
2967{
Johannes Berg71bbc992012-06-15 15:30:18 +02002968 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002969 struct ieee80211_local *local = sdata->local;
2970
Johannes Berg2eb278e2012-06-05 14:28:42 +02002971 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002972}
2973
Simon Wunderlich164eb022013-02-08 18:16:20 +01002974static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2975 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002976 struct cfg80211_chan_def *chandef,
2977 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002978{
2979 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2980 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002981 int err;
2982
Johannes Berg34a37402013-12-18 09:43:33 +01002983 mutex_lock(&local->mtx);
2984 if (!list_empty(&local->roc_list) || local->scanning) {
2985 err = -EBUSY;
2986 goto out_unlock;
2987 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002988
2989 /* whatever, but channel contexts should not complain about that one */
2990 sdata->smps_mode = IEEE80211_SMPS_OFF;
2991 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002992
Simon Wunderlich164eb022013-02-08 18:16:20 +01002993 err = ieee80211_vif_use_channel(sdata, chandef,
2994 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002995 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002996 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002997
Simon Wunderlich164eb022013-02-08 18:16:20 +01002998 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002999 &sdata->dfs_cac_timer_work,
3000 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01003001
Johannes Berg34a37402013-12-18 09:43:33 +01003002 out_unlock:
3003 mutex_unlock(&local->mtx);
3004 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01003005}
3006
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003007static struct cfg80211_beacon_data *
3008cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3009{
3010 struct cfg80211_beacon_data *new_beacon;
3011 u8 *pos;
3012 int len;
3013
3014 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3015 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
3016 beacon->probe_resp_len;
3017
3018 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3019 if (!new_beacon)
3020 return NULL;
3021
3022 pos = (u8 *)(new_beacon + 1);
3023 if (beacon->head_len) {
3024 new_beacon->head_len = beacon->head_len;
3025 new_beacon->head = pos;
3026 memcpy(pos, beacon->head, beacon->head_len);
3027 pos += beacon->head_len;
3028 }
3029 if (beacon->tail_len) {
3030 new_beacon->tail_len = beacon->tail_len;
3031 new_beacon->tail = pos;
3032 memcpy(pos, beacon->tail, beacon->tail_len);
3033 pos += beacon->tail_len;
3034 }
3035 if (beacon->beacon_ies_len) {
3036 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3037 new_beacon->beacon_ies = pos;
3038 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3039 pos += beacon->beacon_ies_len;
3040 }
3041 if (beacon->proberesp_ies_len) {
3042 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3043 new_beacon->proberesp_ies = pos;
3044 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3045 pos += beacon->proberesp_ies_len;
3046 }
3047 if (beacon->assocresp_ies_len) {
3048 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3049 new_beacon->assocresp_ies = pos;
3050 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3051 pos += beacon->assocresp_ies_len;
3052 }
3053 if (beacon->probe_resp_len) {
3054 new_beacon->probe_resp_len = beacon->probe_resp_len;
3055 beacon->probe_resp = pos;
3056 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3057 pos += beacon->probe_resp_len;
3058 }
3059
3060 return new_beacon;
3061}
3062
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003063void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003064{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003065 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3066
3067 ieee80211_queue_work(&sdata->local->hw,
3068 &sdata->csa_finalize_work);
3069}
3070EXPORT_SYMBOL(ieee80211_csa_finish);
3071
Michal Kazior66199502014-04-09 15:11:00 +02003072static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3073 u32 *changed)
3074{
3075 int err;
3076
3077 switch (sdata->vif.type) {
3078 case NL80211_IFTYPE_AP:
3079 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
3080 kfree(sdata->u.ap.next_beacon);
3081 sdata->u.ap.next_beacon = NULL;
3082
3083 if (err < 0)
3084 return err;
3085 *changed |= err;
3086 break;
3087 case NL80211_IFTYPE_ADHOC:
3088 err = ieee80211_ibss_finish_csa(sdata);
3089 if (err < 0)
3090 return err;
3091 *changed |= err;
3092 break;
3093#ifdef CONFIG_MAC80211_MESH
3094 case NL80211_IFTYPE_MESH_POINT:
3095 err = ieee80211_mesh_finish_csa(sdata);
3096 if (err < 0)
3097 return err;
3098 *changed |= err;
3099 break;
3100#endif
3101 default:
3102 WARN_ON(1);
3103 return -EINVAL;
3104 }
3105
3106 return 0;
3107}
3108
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003109static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003110{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003111 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02003112 u32 changed = 0;
3113 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003114
Michal Kaziordbd72852014-01-29 07:56:21 +01003115 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003116 lockdep_assert_held(&local->mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01003117
Michal Kaziorcc901de2014-01-29 07:56:20 +01003118 sdata->radar_required = sdata->csa_radar_required;
Luciano Coelho33787fc2013-11-11 20:34:54 +02003119 err = ieee80211_vif_change_channel(sdata, &changed);
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003120 if (err < 0)
3121 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003122
Arik Nemtsov7578d572013-09-01 17:15:51 +03003123 if (!local->use_chanctx) {
Luciano Coelho33787fc2013-11-11 20:34:54 +02003124 local->_oper_chandef = sdata->csa_chandef;
Arik Nemtsov7578d572013-09-01 17:15:51 +03003125 ieee80211_hw_config(local, 0);
3126 }
3127
Simon Wunderliche487eae2013-11-21 18:19:51 +01003128 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01003129
Michal Kazior66199502014-04-09 15:11:00 +02003130 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3131 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003132 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003133
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003134 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02003135 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3136
3137 if (!ieee80211_csa_needs_block_tx(local))
3138 ieee80211_wake_queues_by_reason(&local->hw,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003139 IEEE80211_MAX_QUEUE_MAP,
3140 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003141
3142 return 0;
3143}
3144
3145static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3146{
3147 if (__ieee80211_csa_finalize(sdata)) {
3148 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3149 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3150 GFP_KERNEL);
3151 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003152}
3153
3154void ieee80211_csa_finalize_work(struct work_struct *work)
3155{
3156 struct ieee80211_sub_if_data *sdata =
3157 container_of(work, struct ieee80211_sub_if_data,
3158 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02003159 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003160
3161 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003162 mutex_lock(&local->mtx);
3163
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003164 /* AP might have been stopped while waiting for the lock. */
3165 if (!sdata->vif.csa_active)
3166 goto unlock;
3167
3168 if (!ieee80211_sdata_running(sdata))
3169 goto unlock;
3170
3171 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003172
3173unlock:
Michal Kazior59af6922014-04-09 15:10:59 +02003174 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003175 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003176}
3177
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003178static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3179 struct cfg80211_csa_settings *params,
3180 u32 *changed)
3181{
3182 int err;
3183
3184 switch (sdata->vif.type) {
3185 case NL80211_IFTYPE_AP:
3186 sdata->u.ap.next_beacon =
3187 cfg80211_beacon_dup(&params->beacon_after);
3188 if (!sdata->u.ap.next_beacon)
3189 return -ENOMEM;
3190
3191 /*
3192 * With a count of 0, we don't have to wait for any
3193 * TBTT before switching, so complete the CSA
3194 * immediately. In theory, with a count == 1 we
3195 * should delay the switch until just before the next
3196 * TBTT, but that would complicate things so we switch
3197 * immediately too. If we would delay the switch
3198 * until the next TBTT, we would have to set the probe
3199 * response here.
3200 *
3201 * TODO: A channel switch with count <= 1 without
3202 * sending a CSA action frame is kind of useless,
3203 * because the clients won't know we're changing
3204 * channels. The action frame must be implemented
3205 * either here or in the userspace.
3206 */
3207 if (params->count <= 1)
3208 break;
3209
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003210 if ((params->n_counter_offsets_beacon >
3211 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3212 (params->n_counter_offsets_presp >
3213 IEEE80211_MAX_CSA_COUNTERS_NUM))
3214 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003215
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003216 /* make sure we don't have garbage in other counters */
3217 memset(sdata->csa_counter_offset_beacon, 0,
3218 sizeof(sdata->csa_counter_offset_beacon));
3219 memset(sdata->csa_counter_offset_presp, 0,
3220 sizeof(sdata->csa_counter_offset_presp));
3221
3222 memcpy(sdata->csa_counter_offset_beacon,
3223 params->counter_offsets_beacon,
3224 params->n_counter_offsets_beacon * sizeof(u16));
3225 memcpy(sdata->csa_counter_offset_presp,
3226 params->counter_offsets_presp,
3227 params->n_counter_offsets_presp * sizeof(u16));
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003228
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003229 err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
3230 if (err < 0) {
3231 kfree(sdata->u.ap.next_beacon);
3232 return err;
3233 }
3234 *changed |= err;
3235
3236 break;
3237 case NL80211_IFTYPE_ADHOC:
3238 if (!sdata->vif.bss_conf.ibss_joined)
3239 return -EINVAL;
3240
3241 if (params->chandef.width != sdata->u.ibss.chandef.width)
3242 return -EINVAL;
3243
3244 switch (params->chandef.width) {
3245 case NL80211_CHAN_WIDTH_40:
3246 if (cfg80211_get_chandef_type(&params->chandef) !=
3247 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3248 return -EINVAL;
3249 case NL80211_CHAN_WIDTH_5:
3250 case NL80211_CHAN_WIDTH_10:
3251 case NL80211_CHAN_WIDTH_20_NOHT:
3252 case NL80211_CHAN_WIDTH_20:
3253 break;
3254 default:
3255 return -EINVAL;
3256 }
3257
3258 /* changes into another band are not supported */
3259 if (sdata->u.ibss.chandef.chan->band !=
3260 params->chandef.chan->band)
3261 return -EINVAL;
3262
3263 /* see comments in the NL80211_IFTYPE_AP block */
3264 if (params->count > 1) {
3265 err = ieee80211_ibss_csa_beacon(sdata, params);
3266 if (err < 0)
3267 return err;
3268 *changed |= err;
3269 }
3270
3271 ieee80211_send_action_csa(sdata, params);
3272
3273 break;
3274#ifdef CONFIG_MAC80211_MESH
3275 case NL80211_IFTYPE_MESH_POINT: {
3276 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3277
3278 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3279 return -EINVAL;
3280
3281 /* changes into another band are not supported */
3282 if (sdata->vif.bss_conf.chandef.chan->band !=
3283 params->chandef.chan->band)
3284 return -EINVAL;
3285
3286 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3287 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3288 if (!ifmsh->pre_value)
3289 ifmsh->pre_value = 1;
3290 else
3291 ifmsh->pre_value++;
3292 }
3293
3294 /* see comments in the NL80211_IFTYPE_AP block */
3295 if (params->count > 1) {
3296 err = ieee80211_mesh_csa_beacon(sdata, params);
3297 if (err < 0) {
3298 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3299 return err;
3300 }
3301 *changed |= err;
3302 }
3303
3304 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3305 ieee80211_send_action_csa(sdata, params);
3306
3307 break;
3308 }
3309#endif
3310 default:
3311 return -EOPNOTSUPP;
3312 }
3313
3314 return 0;
3315}
3316
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003317static int
3318__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3319 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003320{
3321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3322 struct ieee80211_local *local = sdata->local;
Michal Kazior2b327132014-04-09 15:29:32 +02003323 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003324 struct ieee80211_chanctx *chanctx;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003325 int err, num_chanctx, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003326
Michal Kaziordbd72852014-01-29 07:56:21 +01003327 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003328 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003329
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003330 if (!list_empty(&local->roc_list) || local->scanning)
3331 return -EBUSY;
3332
3333 if (sdata->wdev.cac_started)
3334 return -EBUSY;
3335
3336 if (cfg80211_chandef_identical(&params->chandef,
3337 &sdata->vif.bss_conf.chandef))
3338 return -EINVAL;
3339
Michal Kazior2b327132014-04-09 15:29:32 +02003340 mutex_lock(&local->chanctx_mtx);
3341 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3342 lockdep_is_held(&local->chanctx_mtx));
3343 if (!conf) {
3344 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003345 return -EBUSY;
3346 }
3347
3348 /* don't handle for multi-VIF cases */
Michal Kazior2b327132014-04-09 15:29:32 +02003349 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
Michal Kaziorc0166da2014-04-09 15:29:33 +02003350 if (ieee80211_chanctx_refcount(local, chanctx) > 1) {
Michal Kazior2b327132014-04-09 15:29:32 +02003351 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003352 return -EBUSY;
3353 }
3354 num_chanctx = 0;
3355 list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3356 num_chanctx++;
Michal Kazior2b327132014-04-09 15:29:32 +02003357 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003358
3359 if (num_chanctx > 1)
3360 return -EBUSY;
3361
3362 /* don't allow another channel switch if one is already active. */
3363 if (sdata->vif.csa_active)
3364 return -EBUSY;
3365
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003366 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3367 if (err)
3368 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003369
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003370 sdata->csa_radar_required = params->radar_required;
Luciano Coelho33787fc2013-11-11 20:34:54 +02003371 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003372 sdata->csa_block_tx = params->block_tx;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003373 sdata->csa_current_counter = params->count;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003374 sdata->vif.csa_active = true;
3375
Michal Kazior59af6922014-04-09 15:10:59 +02003376 if (sdata->csa_block_tx)
3377 ieee80211_stop_queues_by_reason(&local->hw,
3378 IEEE80211_MAX_QUEUE_MAP,
3379 IEEE80211_QUEUE_STOP_REASON_CSA);
3380
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003381 if (changed) {
3382 ieee80211_bss_info_change_notify(sdata, changed);
3383 drv_channel_switch_beacon(sdata, &params->chandef);
3384 } else {
3385 /* if the beacon didn't change, we can finalize immediately */
3386 ieee80211_csa_finalize(sdata);
3387 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003388
3389 return 0;
3390}
3391
Michal Kazior59af6922014-04-09 15:10:59 +02003392int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3393 struct cfg80211_csa_settings *params)
3394{
3395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3396 struct ieee80211_local *local = sdata->local;
3397 int err;
3398
3399 mutex_lock(&local->mtx);
3400 err = __ieee80211_channel_switch(wiphy, dev, params);
3401 mutex_unlock(&local->mtx);
3402
3403 return err;
3404}
3405
Johannes Berg71bbc992012-06-15 15:30:18 +02003406static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003407 struct cfg80211_mgmt_tx_params *params,
3408 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003409{
Johannes Berg71bbc992012-06-15 15:30:18 +02003410 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003411 struct ieee80211_local *local = sdata->local;
3412 struct sk_buff *skb;
3413 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003414 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003415 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003416 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003417 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003418 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003419
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003420 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003421 flags = IEEE80211_TX_CTL_NO_ACK;
3422 else
3423 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3424 IEEE80211_TX_CTL_REQ_TX_STATUS;
3425
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003426 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303427 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3428
Johannes Berg9d38d852010-06-09 17:20:33 +02003429 switch (sdata->vif.type) {
3430 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003431 if (!sdata->vif.bss_conf.ibss_joined)
3432 need_offchan = true;
3433 /* fall through */
3434#ifdef CONFIG_MAC80211_MESH
3435 case NL80211_IFTYPE_MESH_POINT:
3436 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3437 !sdata->u.mesh.mesh_id_len)
3438 need_offchan = true;
3439 /* fall through */
3440#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003441 case NL80211_IFTYPE_AP:
3442 case NL80211_IFTYPE_AP_VLAN:
3443 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003444 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3445 !ieee80211_vif_is_mesh(&sdata->vif) &&
3446 !rcu_access_pointer(sdata->bss->beacon))
3447 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003448 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003449 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003450 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3451 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003452 break;
3453 rcu_read_lock();
3454 sta = sta_info_get(sdata, mgmt->da);
3455 rcu_read_unlock();
3456 if (!sta)
3457 return -ENOLINK;
3458 break;
3459 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003460 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003461 if (!sdata->u.mgd.associated)
3462 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003463 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003464 case NL80211_IFTYPE_P2P_DEVICE:
3465 need_offchan = true;
3466 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003467 default:
3468 return -EOPNOTSUPP;
3469 }
3470
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003471 /* configurations requiring offchan cannot work if no channel has been
3472 * specified
3473 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003474 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003475 return -EINVAL;
3476
Johannes Berg2eb278e2012-06-05 14:28:42 +02003477 mutex_lock(&local->mtx);
3478
3479 /* Check if the operating channel is the requested channel */
3480 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003481 struct ieee80211_chanctx_conf *chanctx_conf;
3482
3483 rcu_read_lock();
3484 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3485
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003486 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003487 need_offchan = params->chan &&
3488 (params->chan !=
3489 chanctx_conf->def.chan);
3490 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003491 ret = -EINVAL;
3492 rcu_read_unlock();
3493 goto out_unlock;
3494 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003495 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003496 }
Johannes Berg55de9082012-07-26 17:24:39 +02003497 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003498 }
3499
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003500 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003501 ret = -EBUSY;
3502 goto out_unlock;
3503 }
3504
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003505 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003506 if (!skb) {
3507 ret = -ENOMEM;
3508 goto out_unlock;
3509 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003510 skb_reserve(skb, local->hw.extra_tx_headroom);
3511
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003512 data = skb_put(skb, params->len);
3513 memcpy(data, params->buf, params->len);
3514
3515 /* Update CSA counters */
3516 if (sdata->vif.csa_active &&
3517 (sdata->vif.type == NL80211_IFTYPE_AP ||
3518 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3519 params->n_csa_offsets) {
3520 int i;
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003521 u8 c = sdata->csa_current_counter;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003522
3523 for (i = 0; i < params->n_csa_offsets; i++)
Andrei Otcheretianski1af586c2014-05-09 14:11:50 +03003524 data[params->csa_offsets[i]] = c;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003525 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003526
3527 IEEE80211_SKB_CB(skb)->flags = flags;
3528
Johannes Berg2eb278e2012-06-05 14:28:42 +02003529 skb->dev = sdata->dev;
3530
3531 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003532 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003533 ieee80211_tx_skb(sdata, skb);
3534 ret = 0;
3535 goto out_unlock;
3536 }
3537
Seth Forshee6c17b772013-02-11 11:21:07 -06003538 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3539 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003540 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003541 IEEE80211_SKB_CB(skb)->hw_queue =
3542 local->hw.offchannel_tx_hw_queue;
3543
Johannes Berg2eb278e2012-06-05 14:28:42 +02003544 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003545 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3546 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003547 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003548 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003549 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003550 out_unlock:
3551 mutex_unlock(&local->mtx);
3552 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003553}
3554
Johannes Bergf30221e2010-11-25 10:02:30 +01003555static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003556 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003557 u64 cookie)
3558{
Johannes Berg71bbc992012-06-15 15:30:18 +02003559 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003560
Johannes Berg2eb278e2012-06-05 14:28:42 +02003561 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003562}
3563
Johannes Berg7be50862010-10-13 12:06:24 +02003564static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003565 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003566 u16 frame_type, bool reg)
3567{
3568 struct ieee80211_local *local = wiphy_priv(wiphy);
3569
Will Hawkins6abe0562012-06-20 11:51:14 -04003570 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003571 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3572 if (reg)
3573 local->probe_req_reg++;
3574 else
3575 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003576
Felix Fietkau35f51492012-10-31 15:50:34 +01003577 if (!local->open_count)
3578 break;
3579
Will Hawkins6abe0562012-06-20 11:51:14 -04003580 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3581 break;
3582 default:
3583 break;
3584 }
Johannes Berg7be50862010-10-13 12:06:24 +02003585}
3586
Bruno Randolf15d96752010-11-10 12:50:56 +09003587static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3588{
3589 struct ieee80211_local *local = wiphy_priv(wiphy);
3590
3591 if (local->started)
3592 return -EOPNOTSUPP;
3593
3594 return drv_set_antenna(local, tx_ant, rx_ant);
3595}
3596
3597static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3598{
3599 struct ieee80211_local *local = wiphy_priv(wiphy);
3600
3601 return drv_get_antenna(local, tx_ant, rx_ant);
3602}
3603
John W. Linville38c09152011-03-07 16:19:18 -05003604static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
3605{
3606 struct ieee80211_local *local = wiphy_priv(wiphy);
3607
3608 return drv_set_ringparam(local, tx, rx);
3609}
3610
3611static void ieee80211_get_ringparam(struct wiphy *wiphy,
3612 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
3613{
3614 struct ieee80211_local *local = wiphy_priv(wiphy);
3615
3616 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
3617}
3618
Johannes Bergc68f4b82011-07-05 16:35:41 +02003619static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3620 struct net_device *dev,
3621 struct cfg80211_gtk_rekey_data *data)
3622{
3623 struct ieee80211_local *local = wiphy_priv(wiphy);
3624 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3625
3626 if (!local->ops->set_rekey_data)
3627 return -EOPNOTSUPP;
3628
3629 drv_set_rekey_data(local, sdata, data);
3630
3631 return 0;
3632}
3633
Johannes Berg06500732011-11-04 11:18:16 +01003634static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3635 const u8 *peer, u64 *cookie)
3636{
3637 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3638 struct ieee80211_local *local = sdata->local;
3639 struct ieee80211_qos_hdr *nullfunc;
3640 struct sk_buff *skb;
3641 int size = sizeof(*nullfunc);
3642 __le16 fc;
3643 bool qos;
3644 struct ieee80211_tx_info *info;
3645 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003646 struct ieee80211_chanctx_conf *chanctx_conf;
3647 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003648
3649 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003650 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3651 if (WARN_ON(!chanctx_conf)) {
3652 rcu_read_unlock();
3653 return -EINVAL;
3654 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003655 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003656 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003657 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003658 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003659 } else {
3660 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003661 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003662 }
Johannes Berg06500732011-11-04 11:18:16 +01003663
3664 if (qos) {
3665 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3666 IEEE80211_STYPE_QOS_NULLFUNC |
3667 IEEE80211_FCTL_FROMDS);
3668 } else {
3669 size -= 2;
3670 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3671 IEEE80211_STYPE_NULLFUNC |
3672 IEEE80211_FCTL_FROMDS);
3673 }
3674
3675 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003676 if (!skb) {
3677 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003678 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003679 }
Johannes Berg06500732011-11-04 11:18:16 +01003680
3681 skb->dev = dev;
3682
3683 skb_reserve(skb, local->hw.extra_tx_headroom);
3684
3685 nullfunc = (void *) skb_put(skb, size);
3686 nullfunc->frame_control = fc;
3687 nullfunc->duration_id = 0;
3688 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3689 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3690 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3691 nullfunc->seq_ctrl = 0;
3692
3693 info = IEEE80211_SKB_CB(skb);
3694
3695 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3696 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3697
3698 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3699 skb->priority = 7;
3700 if (qos)
3701 nullfunc->qos_ctrl = cpu_to_le16(7);
3702
3703 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003704 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003705 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003706 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003707
3708 *cookie = (unsigned long) skb;
3709 return 0;
3710}
3711
Johannes Berg683b6d32012-11-08 21:25:48 +01003712static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3713 struct wireless_dev *wdev,
3714 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003715{
Johannes Berg55de9082012-07-26 17:24:39 +02003716 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003717 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003718 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003719 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003720
Johannes Berg55de9082012-07-26 17:24:39 +02003721 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003722 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3723 if (chanctx_conf) {
3724 *chandef = chanctx_conf->def;
3725 ret = 0;
3726 } else if (local->open_count > 0 &&
3727 local->open_count == local->monitors &&
3728 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3729 if (local->use_chanctx)
3730 *chandef = local->monitor_chandef;
3731 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003732 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003733 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003734 }
3735 rcu_read_unlock();
3736
Johannes Berg683b6d32012-11-08 21:25:48 +01003737 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003738}
3739
Johannes Berg6d525632012-04-04 15:05:25 +02003740#ifdef CONFIG_PM
3741static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3742{
3743 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3744}
3745#endif
3746
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003747static int ieee80211_set_qos_map(struct wiphy *wiphy,
3748 struct net_device *dev,
3749 struct cfg80211_qos_map *qos_map)
3750{
3751 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3752 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3753
3754 if (qos_map) {
3755 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3756 if (!new_qos_map)
3757 return -ENOMEM;
3758 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3759 } else {
3760 /* A NULL qos_map was passed to disable QoS mapping */
3761 new_qos_map = NULL;
3762 }
3763
Johannes Berg194ff522013-12-30 23:12:37 +01003764 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003765 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3766 if (old_qos_map)
3767 kfree_rcu(old_qos_map, rcu_head);
3768
3769 return 0;
3770}
3771
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003772static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3773 struct net_device *dev,
3774 struct cfg80211_chan_def *chandef)
3775{
3776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3777 int ret;
3778 u32 changed = 0;
3779
3780 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3781 if (ret == 0)
3782 ieee80211_bss_info_change_notify(sdata, changed);
3783
3784 return ret;
3785}
3786
Johannes Berg8a47cea2014-01-20 23:55:44 +01003787const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003788 .add_virtual_intf = ieee80211_add_iface,
3789 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003790 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003791 .start_p2p_device = ieee80211_start_p2p_device,
3792 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003793 .add_key = ieee80211_add_key,
3794 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003795 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003796 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003797 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003798 .start_ap = ieee80211_start_ap,
3799 .change_beacon = ieee80211_change_beacon,
3800 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003801 .add_station = ieee80211_add_station,
3802 .del_station = ieee80211_del_station,
3803 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003804 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003805 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003806 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003807#ifdef CONFIG_MAC80211_MESH
3808 .add_mpath = ieee80211_add_mpath,
3809 .del_mpath = ieee80211_del_mpath,
3810 .change_mpath = ieee80211_change_mpath,
3811 .get_mpath = ieee80211_get_mpath,
3812 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003813 .update_mesh_config = ieee80211_update_mesh_config,
3814 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003815 .join_mesh = ieee80211_join_mesh,
3816 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003817#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003818 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003819 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003820 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003821 .suspend = ieee80211_suspend,
3822 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003823 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003824 .sched_scan_start = ieee80211_sched_scan_start,
3825 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003826 .auth = ieee80211_auth,
3827 .assoc = ieee80211_assoc,
3828 .deauth = ieee80211_deauth,
3829 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003830 .join_ibss = ieee80211_join_ibss,
3831 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003832 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003833 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003834 .set_tx_power = ieee80211_set_tx_power,
3835 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003836 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003837 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003838 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003839 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003840 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003841 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003842 .remain_on_channel = ieee80211_remain_on_channel,
3843 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003844 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003845 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003846 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003847 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003848 .set_antenna = ieee80211_set_antenna,
3849 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003850 .set_ringparam = ieee80211_set_ringparam,
3851 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003852 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003853 .tdls_oper = ieee80211_tdls_oper,
3854 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003855 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003856 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003857#ifdef CONFIG_PM
3858 .set_wakeup = ieee80211_set_wakeup,
3859#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003860 .get_et_sset_count = ieee80211_get_et_sset_count,
3861 .get_et_stats = ieee80211_get_et_stats,
3862 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003863 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003864 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003865 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003866 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003867 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Jiri Bencf0706e82007-05-05 11:45:53 -07003868};