blob: 5d22eda8a6b1e9d4f8d6f45c1c8c633a892041d3 [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>
Johannes Bergb2eb0ee2015-06-01 22:54:13 +02005 * Copyright 2013-2015 Intel Mobile Communications GmbH
Johannes Berge8e4f522017-03-08 11:12:10 +01006 * Copyright (C) 2015-2017 Intel Deutschland GmbH
Haim Dreyfusse552af02018-03-28 13:24:10 +03007 * Copyright (C) 2018 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -07008 *
9 * This file is GPLv2 as found in COPYING.
10 */
11
Johannes Berge8cbb4c2007-12-19 02:03:30 +010012#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070013#include <linux/nl80211.h>
14#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070016#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010017#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030018#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070019#include <net/cfg80211.h>
20#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020021#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040022#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010023#include "mesh.h"
Johannes Berg02219b32014-10-07 10:38:50 +030024#include "wme.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010025
Johannes Berg65f1d602017-04-12 12:36:31 +020026static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
27 struct vif_params *params)
Johannes Berg8c5e6882017-04-12 10:46:13 +020028{
Johannes Berg8c5e6882017-04-12 10:46:13 +020029 bool mu_mimo_groups = false;
30 bool mu_mimo_follow = false;
31
Johannes Berg8c5e6882017-04-12 10:46:13 +020032 if (params->vht_mumimo_groups) {
33 u64 membership;
34
35 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
36
Johannes Berg65f1d602017-04-12 12:36:31 +020037 memcpy(sdata->vif.bss_conf.mu_group.membership,
Johannes Berg8c5e6882017-04-12 10:46:13 +020038 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
Johannes Berg65f1d602017-04-12 12:36:31 +020039 memcpy(sdata->vif.bss_conf.mu_group.position,
Johannes Berg8c5e6882017-04-12 10:46:13 +020040 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
41 WLAN_USER_POSITION_LEN);
Johannes Berg65f1d602017-04-12 12:36:31 +020042 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
Johannes Berg8c5e6882017-04-12 10:46:13 +020043 /* don't care about endianness - just check for 0 */
44 memcpy(&membership, params->vht_mumimo_groups,
45 WLAN_MEMBERSHIP_LEN);
46 mu_mimo_groups = membership != 0;
47 }
48
49 if (params->vht_mumimo_follow_addr) {
50 mu_mimo_follow =
51 is_valid_ether_addr(params->vht_mumimo_follow_addr);
Johannes Berg65f1d602017-04-12 12:36:31 +020052 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
Johannes Berg8c5e6882017-04-12 10:46:13 +020053 params->vht_mumimo_follow_addr);
54 }
55
Johannes Berg65f1d602017-04-12 12:36:31 +020056 sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
57}
58
59static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
60 struct vif_params *params)
61{
62 struct ieee80211_local *local = sdata->local;
63 struct ieee80211_sub_if_data *monitor_sdata;
64
65 /* check flags first */
66 if (params->flags && ieee80211_sdata_running(sdata)) {
67 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
68
69 /*
70 * Prohibit MONITOR_FLAG_COOK_FRAMES and
71 * MONITOR_FLAG_ACTIVE to be changed while the
72 * interface is up.
73 * Else we would need to add a lot of cruft
74 * to update everything:
75 * cooked_mntrs, monitor and all fif_* counters
76 * reconfigure hardware
77 */
78 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
79 return -EBUSY;
80 }
81
82 /* also validate MU-MIMO change */
83 monitor_sdata = rtnl_dereference(local->monitor_sdata);
84
85 if (!monitor_sdata &&
86 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
87 return -EOPNOTSUPP;
88
89 /* apply all changes now - no failures allowed */
90
91 if (monitor_sdata)
92 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
93
94 if (params->flags) {
95 if (ieee80211_sdata_running(sdata)) {
96 ieee80211_adjust_monitor_flags(sdata, -1);
97 sdata->u.mntr.flags = params->flags;
98 ieee80211_adjust_monitor_flags(sdata, 1);
99
100 ieee80211_configure_filter(local);
101 } else {
102 /*
103 * Because the interface is down, ieee80211_do_stop
104 * and ieee80211_do_open take care of "everything"
105 * mentioned in the comment above.
106 */
107 sdata->u.mntr.flags = params->flags;
108 }
109 }
Johannes Berg8c5e6882017-04-12 10:46:13 +0200110
111 return 0;
112}
113
Johannes Berg552bff02012-09-19 09:26:06 +0200114static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
115 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100116 unsigned char name_assign_type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200117 enum nl80211_iftype type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200118 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -0700119{
120 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +0200121 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +0100122 struct ieee80211_sub_if_data *sdata;
123 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700124
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100125 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100126 if (err)
127 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +0100128
Johannes Berg8c5e6882017-04-12 10:46:13 +0200129 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
130
131 if (type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200132 err = ieee80211_set_mon_options(sdata, params);
Johannes Berg8c5e6882017-04-12 10:46:13 +0200133 if (err) {
134 ieee80211_if_remove(sdata);
135 return NULL;
136 }
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100137 }
138
Johannes Berg84efbb82012-06-16 00:00:26 +0200139 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -0700140}
141
Johannes Berg84efbb82012-06-16 00:00:26 +0200142static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -0700143{
Johannes Berg84efbb82012-06-16 00:00:26 +0200144 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -0700145
Johannes Berg75636522008-07-09 14:40:35 +0200146 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700147}
148
Johannes Berge36d56b2009-06-09 21:04:43 +0200149static int ieee80211_change_iface(struct wiphy *wiphy,
150 struct net_device *dev,
Johannes Berg818a9862017-04-12 11:23:28 +0200151 enum nl80211_iftype type,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100152 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +0200153{
Johannes Berg9607e6b662009-12-23 13:15:31 +0100154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +0200155 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200156
Johannes Berg05c914f2008-09-11 00:01:58 +0200157 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +0200158 if (ret)
159 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200160
Johannes Berg9bc383d2009-11-19 11:55:19 +0100161 if (type == NL80211_IFTYPE_AP_VLAN &&
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300162 params && params->use_4addr == 0) {
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000163 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300164 ieee80211_check_fast_rx_iface(sdata);
165 } else if (type == NL80211_IFTYPE_STATION &&
166 params && params->use_4addr >= 0) {
Johannes Berg9bc383d2009-11-19 11:55:19 +0100167 sdata->u.mgd.use_4addr = params->use_4addr;
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300168 }
Johannes Berg9bc383d2009-11-19 11:55:19 +0100169
Aviya Erenfeld42bd20d2016-08-29 23:25:16 +0300170 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200171 ret = ieee80211_set_mon_options(sdata, params);
172 if (ret)
173 return ret;
Christian Lamparter85416a42010-10-02 13:17:07 +0200174 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200175
Johannes Berg42613db2007-09-28 21:52:27 +0200176 return 0;
177}
178
Johannes Bergf142c6b2012-06-18 20:07:15 +0200179static int ieee80211_start_p2p_device(struct wiphy *wiphy,
180 struct wireless_dev *wdev)
181{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200182 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
183 int ret;
184
185 mutex_lock(&sdata->local->chanctx_mtx);
186 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
187 mutex_unlock(&sdata->local->chanctx_mtx);
188 if (ret < 0)
189 return ret;
190
Johannes Bergf142c6b2012-06-18 20:07:15 +0200191 return ieee80211_do_open(wdev, true);
192}
193
194static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
195 struct wireless_dev *wdev)
196{
197 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
198}
199
Ayala Beker708d50e2016-09-20 17:31:14 +0300200static int ieee80211_start_nan(struct wiphy *wiphy,
201 struct wireless_dev *wdev,
202 struct cfg80211_nan_conf *conf)
203{
204 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
205 int ret;
206
207 mutex_lock(&sdata->local->chanctx_mtx);
208 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
209 mutex_unlock(&sdata->local->chanctx_mtx);
210 if (ret < 0)
211 return ret;
212
213 ret = ieee80211_do_open(wdev, true);
214 if (ret)
215 return ret;
216
217 ret = drv_start_nan(sdata->local, sdata, conf);
218 if (ret)
219 ieee80211_sdata_stop(sdata);
220
Ayala Beker167e33f2016-09-20 17:31:20 +0300221 sdata->u.nan.conf = *conf;
222
Ayala Beker708d50e2016-09-20 17:31:14 +0300223 return ret;
224}
225
226static void ieee80211_stop_nan(struct wiphy *wiphy,
227 struct wireless_dev *wdev)
228{
229 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
230
231 drv_stop_nan(sdata->local, sdata);
232 ieee80211_sdata_stop(sdata);
233}
234
Ayala Beker5953ff62016-09-20 17:31:19 +0300235static int ieee80211_nan_change_conf(struct wiphy *wiphy,
236 struct wireless_dev *wdev,
237 struct cfg80211_nan_conf *conf,
238 u32 changes)
239{
240 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
241 struct cfg80211_nan_conf new_conf;
242 int ret = 0;
243
244 if (sdata->vif.type != NL80211_IFTYPE_NAN)
245 return -EOPNOTSUPP;
246
247 if (!ieee80211_sdata_running(sdata))
248 return -ENETDOWN;
249
250 new_conf = sdata->u.nan.conf;
251
252 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
253 new_conf.master_pref = conf->master_pref;
254
Luca Coelho85859892017-02-08 15:00:34 +0200255 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
256 new_conf.bands = conf->bands;
Ayala Beker5953ff62016-09-20 17:31:19 +0300257
258 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
259 if (!ret)
260 sdata->u.nan.conf = new_conf;
261
262 return ret;
263}
264
Ayala Beker167e33f2016-09-20 17:31:20 +0300265static int ieee80211_add_nan_func(struct wiphy *wiphy,
266 struct wireless_dev *wdev,
267 struct cfg80211_nan_func *nan_func)
268{
269 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
270 int ret;
271
272 if (sdata->vif.type != NL80211_IFTYPE_NAN)
273 return -EOPNOTSUPP;
274
275 if (!ieee80211_sdata_running(sdata))
276 return -ENETDOWN;
277
278 spin_lock_bh(&sdata->u.nan.func_lock);
279
280 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
281 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
282 GFP_ATOMIC);
283 spin_unlock_bh(&sdata->u.nan.func_lock);
284
285 if (ret < 0)
286 return ret;
287
288 nan_func->instance_id = ret;
289
290 WARN_ON(nan_func->instance_id == 0);
291
292 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
293 if (ret) {
294 spin_lock_bh(&sdata->u.nan.func_lock);
295 idr_remove(&sdata->u.nan.function_inst_ids,
296 nan_func->instance_id);
297 spin_unlock_bh(&sdata->u.nan.func_lock);
298 }
299
300 return ret;
301}
302
303static struct cfg80211_nan_func *
304ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
305 u64 cookie)
306{
307 struct cfg80211_nan_func *func;
308 int id;
309
310 lockdep_assert_held(&sdata->u.nan.func_lock);
311
312 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
313 if (func->cookie == cookie)
314 return func;
315 }
316
317 return NULL;
318}
319
320static void ieee80211_del_nan_func(struct wiphy *wiphy,
321 struct wireless_dev *wdev, u64 cookie)
322{
323 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
324 struct cfg80211_nan_func *func;
325 u8 instance_id = 0;
326
327 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
328 !ieee80211_sdata_running(sdata))
329 return;
330
331 spin_lock_bh(&sdata->u.nan.func_lock);
332
333 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
334 if (func)
335 instance_id = func->instance_id;
336
337 spin_unlock_bh(&sdata->u.nan.func_lock);
338
339 if (instance_id)
340 drv_del_nan_func(sdata->local, sdata, instance_id);
341}
342
Simon Wunderlichb53be792011-11-18 14:20:44 +0100343static int ieee80211_set_noack_map(struct wiphy *wiphy,
344 struct net_device *dev,
345 u16 noack_map)
346{
347 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
348
349 sdata->noack_map = noack_map;
Johannes Berg17c18bf2015-03-21 15:25:43 +0100350
351 ieee80211_check_fast_xmit_iface(sdata);
352
Simon Wunderlichb53be792011-11-18 14:20:44 +0100353 return 0;
354}
355
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100356static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200357 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100358 struct key_params *params)
359{
Johannes Berg26a58452010-08-27 12:35:55 +0200360 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200361 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100362 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200363 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100364 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200365 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100366
Johannes Berg26a58452010-08-27 12:35:55 +0200367 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200368 return -ENETDOWN;
369
Johannes Berg97359d12010-08-10 09:46:38 +0200370 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100371 switch (params->cipher) {
372 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100373 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200374 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200375 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200376 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200377 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200378 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200379 case WLAN_CIPHER_SUITE_CCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200380 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200381 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200382 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
383 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200384 case WLAN_CIPHER_SUITE_GCMP:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200385 case WLAN_CIPHER_SUITE_GCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200386 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100387 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200388 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200389 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100390 }
391
Johannes Berg97359d12010-08-10 09:46:38 +0200392 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200393 params->key, params->seq_len, params->seq,
394 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100395 if (IS_ERR(key))
396 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100397
Johannes Berge31b8212010-10-05 19:39:30 +0200398 if (pairwise)
399 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
400
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200401 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200402
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100403 if (mac_addr) {
Johannes Berg850092d2016-10-04 15:32:16 +0200404 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100405 /*
406 * The ASSOC test makes sure the driver is ready to
407 * receive the key. When wpa_supplicant has roamed
408 * using FT, it attempts to set the key before
409 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700410 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100411 *
412 * TODO: accept the key if we have a station entry and
413 * add it to the device after the station.
414 */
415 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100416 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200417 err = -ENOENT;
418 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100419 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100420 }
421
Johannes Berge548c492012-09-04 17:08:23 +0200422 switch (sdata->vif.type) {
423 case NL80211_IFTYPE_STATION:
424 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
425 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
426 break;
427 case NL80211_IFTYPE_AP:
428 case NL80211_IFTYPE_AP_VLAN:
429 /* Keys without a station are used for TX only */
Felix Fietkau211710c2018-09-29 16:01:58 +0200430 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
Johannes Berge548c492012-09-04 17:08:23 +0200431 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
432 break;
433 case NL80211_IFTYPE_ADHOC:
434 /* no MFP (yet) */
435 break;
436 case NL80211_IFTYPE_MESH_POINT:
437#ifdef CONFIG_MAC80211_MESH
438 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
439 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
440 break;
441#endif
442 case NL80211_IFTYPE_WDS:
443 case NL80211_IFTYPE_MONITOR:
444 case NL80211_IFTYPE_P2P_DEVICE:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300445 case NL80211_IFTYPE_NAN:
Johannes Berge548c492012-09-04 17:08:23 +0200446 case NL80211_IFTYPE_UNSPECIFIED:
447 case NUM_NL80211_IFTYPES:
448 case NL80211_IFTYPE_P2P_CLIENT:
449 case NL80211_IFTYPE_P2P_GO:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100450 case NL80211_IFTYPE_OCB:
Johannes Berge548c492012-09-04 17:08:23 +0200451 /* shouldn't happen */
452 WARN_ON_ONCE(1);
453 break;
454 }
455
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200456 if (sta)
457 sta->cipher_scheme = cs;
458
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300459 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100460
Johannes Berg3b967662008-04-08 17:56:52 +0200461 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200462 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200463
464 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100465}
466
467static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200468 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100469{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200470 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
471 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100472 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200473 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100474 int ret;
475
Johannes Berg5c0c3642011-05-12 14:31:49 +0200476 mutex_lock(&local->sta_mtx);
477 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200478
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100479 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200480 ret = -ENOENT;
481
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100482 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100483 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200484 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100485
Johannes Berg5c0c3642011-05-12 14:31:49 +0200486 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200487 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200488 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200489 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200490 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200491 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100492
Johannes Berg5c0c3642011-05-12 14:31:49 +0200493 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200494 ret = -ENOENT;
495 goto out_unlock;
496 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100497
Manikanta Pubbisetty133bf902018-07-10 16:48:27 +0530498 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100499
Johannes Berg3b967662008-04-08 17:56:52 +0200500 ret = 0;
501 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200502 mutex_unlock(&local->key_mtx);
503 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200504
505 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100506}
507
Johannes Berg62da92f2007-12-19 02:03:31 +0100508static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200509 u8 key_idx, bool pairwise, const u8 *mac_addr,
510 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100511 void (*callback)(void *cookie,
512 struct key_params *params))
513{
Johannes Berg14db74b2008-07-29 13:22:52 +0200514 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100515 struct sta_info *sta = NULL;
516 u8 seq[6] = {0};
517 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200518 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200519 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100520 u32 iv32;
521 u16 iv16;
522 int err = -ENOENT;
Johannes Berg9352c192015-04-20 18:12:41 +0200523 struct ieee80211_key_seq kseq = {};
Johannes Berg62da92f2007-12-19 02:03:31 +0100524
Johannes Berg14db74b2008-07-29 13:22:52 +0200525 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
526
Johannes Berg3b967662008-04-08 17:56:52 +0200527 rcu_read_lock();
528
Johannes Berg62da92f2007-12-19 02:03:31 +0100529 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100530 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100531 if (!sta)
532 goto out;
533
Max Stepanov354e1592013-12-08 13:30:52 +0200534 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200535 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200536 else if (!pairwise &&
537 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200538 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100539 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200540 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100541
542 if (!key)
543 goto out;
544
545 memset(&params, 0, sizeof(params));
546
Johannes Berg97359d12010-08-10 09:46:38 +0200547 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100548
Johannes Berg97359d12010-08-10 09:46:38 +0200549 switch (key->conf.cipher) {
550 case WLAN_CIPHER_SUITE_TKIP:
Eliad Pellerf8079d42016-02-14 13:56:35 +0200551 pn64 = atomic64_read(&key->conf.tx_pn);
552 iv32 = TKIP_PN_TO_IV32(pn64);
553 iv16 = TKIP_PN_TO_IV16(pn64);
Johannes Berg62da92f2007-12-19 02:03:31 +0100554
Johannes Berg9352c192015-04-20 18:12:41 +0200555 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
556 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
557 drv_get_key_seq(sdata->local, key, &kseq);
558 iv32 = kseq.tkip.iv32;
559 iv16 = kseq.tkip.iv16;
560 }
Johannes Berg62da92f2007-12-19 02:03:31 +0100561
562 seq[0] = iv16 & 0xff;
563 seq[1] = (iv16 >> 8) & 0xff;
564 seq[2] = iv32 & 0xff;
565 seq[3] = (iv32 >> 8) & 0xff;
566 seq[4] = (iv32 >> 16) & 0xff;
567 seq[5] = (iv32 >> 24) & 0xff;
568 params.seq = seq;
569 params.seq_len = 6;
570 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200571 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200572 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +0200573 case WLAN_CIPHER_SUITE_AES_CMAC:
574 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
575 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
576 offsetof(typeof(kseq), aes_cmac));
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500577 /* fall through */
Johannes Bergdb388a52015-06-01 15:36:51 +0200578 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
579 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
580 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
581 offsetof(typeof(kseq), aes_gmac));
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500582 /* fall through */
Johannes Bergdb388a52015-06-01 15:36:51 +0200583 case WLAN_CIPHER_SUITE_GCMP:
584 case WLAN_CIPHER_SUITE_GCMP_256:
585 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
586 offsetof(typeof(kseq), gcmp));
587
Johannes Berg9352c192015-04-20 18:12:41 +0200588 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
589 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
590 drv_get_key_seq(sdata->local, key, &kseq);
591 memcpy(seq, kseq.ccmp.pn, 6);
592 } else {
Johannes Bergdb388a52015-06-01 15:36:51 +0200593 pn64 = atomic64_read(&key->conf.tx_pn);
Johannes Berg9352c192015-04-20 18:12:41 +0200594 seq[0] = pn64;
595 seq[1] = pn64 >> 8;
596 seq[2] = pn64 >> 16;
597 seq[3] = pn64 >> 24;
598 seq[4] = pn64 >> 32;
599 seq[5] = pn64 >> 40;
600 }
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200601 params.seq = seq;
602 params.seq_len = 6;
603 break;
Johannes Berga31cf1c2015-04-20 18:21:58 +0200604 default:
605 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
606 break;
607 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
608 break;
609 drv_get_key_seq(sdata->local, key, &kseq);
610 params.seq = kseq.hw.seq;
611 params.seq_len = kseq.hw.seq_len;
612 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100613 }
614
615 params.key = key->conf.key;
616 params.key_len = key->conf.keylen;
617
618 callback(cookie, &params);
619 err = 0;
620
621 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200622 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100623 return err;
624}
625
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100626static int ieee80211_config_default_key(struct wiphy *wiphy,
627 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100628 u8 key_idx, bool uni,
629 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100630{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200631 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100632
Johannes Bergf7e01042010-12-09 19:49:02 +0100633 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100634
635 return 0;
636}
637
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200638static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
639 struct net_device *dev,
640 u8 key_idx)
641{
Johannes Berg66c52422010-07-22 13:58:51 +0200642 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200643
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200644 ieee80211_set_default_mgmt_key(sdata, key_idx);
645
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200646 return 0;
647}
648
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800649void sta_set_rate_info_tx(struct sta_info *sta,
650 const struct ieee80211_tx_rate *rate,
651 struct rate_info *rinfo)
652{
653 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100654 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800655 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100656 rinfo->mcs = rate->idx;
657 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
658 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
659 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
660 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
661 } else {
662 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200663 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
664 u16 brate;
665
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +0530666 sband = ieee80211_get_sband(sta->sdata);
667 if (sband) {
668 brate = sband->bitrates[rate->idx].bitrate;
669 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
670 }
Johannes Berg8bc83c22012-11-09 18:38:32 +0100671 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800672 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Johannes Bergb51f3be2015-01-15 16:14:02 +0100673 rinfo->bw = RATE_INFO_BW_40;
674 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
675 rinfo->bw = RATE_INFO_BW_80;
676 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
677 rinfo->bw = RATE_INFO_BW_160;
678 else
679 rinfo->bw = RATE_INFO_BW_20;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800680 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
681 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800682}
683
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100684static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200685 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100686{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100687 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300688 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100689 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100690 int ret = -ENOENT;
691
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300692 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100693
Johannes Berg3b53fde82009-11-16 12:00:37 +0100694 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100695 if (sta) {
696 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200697 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Berg0fdf1492018-05-18 11:40:44 +0200698 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100699 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100700
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300701 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100702
Johannes Bergd0709a62008-02-25 16:27:46 +0100703 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100704}
705
Holger Schurig12897232010-04-19 10:23:57 +0200706static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
707 int idx, struct survey_info *survey)
708{
709 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
710
Holger Schurig12897232010-04-19 10:23:57 +0200711 return drv_get_survey(local, idx, survey);
712}
713
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100714static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200715 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100716{
Johannes Bergabe60632009-11-25 17:46:18 +0100717 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300718 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100719 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100720 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100721
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300722 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100723
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100724 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100725 if (sta) {
726 ret = 0;
Johannes Berg0fdf1492018-05-18 11:40:44 +0200727 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100728 }
729
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300730 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100731
732 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100733}
734
Johannes Berge8c9bd52012-06-06 08:18:22 +0200735static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100736 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200737{
Johannes Berg55de9082012-07-26 17:24:39 +0200738 struct ieee80211_local *local = wiphy_priv(wiphy);
739 struct ieee80211_sub_if_data *sdata;
740 int ret = 0;
741
Johannes Berg4bf88532012-11-09 11:39:59 +0100742 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200743 return 0;
744
Johannes Berg34a37402013-12-18 09:43:33 +0100745 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200746 if (local->use_chanctx) {
Johannes Berg4a199062017-04-26 10:58:53 +0300747 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Berg55de9082012-07-26 17:24:39 +0200748 if (sdata) {
749 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100750 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200751 IEEE80211_CHANCTX_EXCLUSIVE);
752 }
753 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100754 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200755 ieee80211_hw_config(local, 0);
756 }
757
Johannes Berg4bf88532012-11-09 11:39:59 +0100758 if (ret == 0)
759 local->monitor_chandef = *chandef;
Johannes Berg34a37402013-12-18 09:43:33 +0100760 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200761
762 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200763}
764
Arik Nemtsov02945822011-11-10 11:28:57 +0200765static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200766 const u8 *resp, size_t resp_len,
767 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200768{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300769 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200770
771 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530772 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200773
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100774 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200775
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300776 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200777 if (!new)
778 return -ENOMEM;
779
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300780 new->len = resp_len;
781 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200782
Michal Kazioraf296bd2014-06-05 14:21:36 +0200783 if (csa)
784 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
785 csa->n_counter_offsets_presp *
786 sizeof(new->csa_counter_offsets[0]));
787
Arik Nemtsov02945822011-11-10 11:28:57 +0200788 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300789 if (old)
790 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200791
792 return 0;
793}
794
Luciano Coelho0ae07962013-12-08 09:42:25 +0200795static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200796 struct cfg80211_beacon_data *params,
797 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100798{
799 struct beacon_data *new, *old;
800 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100801 int size, err;
802 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100803
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100804 old = sdata_dereference(sdata->u.ap.beacon, sdata);
805
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100806
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100807 /* Need to have a beacon head if we don't have one yet */
808 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100809 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100810
811 /* new or old head? */
812 if (params->head)
813 new_head_len = params->head_len;
814 else
815 new_head_len = old->head_len;
816
817 /* new or old tail? */
818 if (params->tail || !old)
819 /* params->tail_len will be zero for !params->tail */
820 new_tail_len = params->tail_len;
821 else
822 new_tail_len = old->tail_len;
823
824 size = sizeof(*new) + new_head_len + new_tail_len;
825
826 new = kzalloc(size, GFP_KERNEL);
827 if (!new)
828 return -ENOMEM;
829
830 /* start filling the new info now */
831
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100832 /*
833 * pointers go into the block we allocated,
834 * memory is | beacon_data | head | tail |
835 */
836 new->head = ((u8 *) new) + sizeof(*new);
837 new->tail = new->head + new_head_len;
838 new->head_len = new_head_len;
839 new->tail_len = new_tail_len;
840
Michal Kazioraf296bd2014-06-05 14:21:36 +0200841 if (csa) {
842 new->csa_current_counter = csa->count;
843 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
844 csa->n_counter_offsets_beacon *
845 sizeof(new->csa_counter_offsets[0]));
846 }
847
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100848 /* copy in head */
849 if (params->head)
850 memcpy(new->head, params->head, new_head_len);
851 else
852 memcpy(new->head, old->head, new_head_len);
853
854 /* copy in optional tail */
855 if (params->tail)
856 memcpy(new->tail, params->tail, new_tail_len);
857 else
858 if (old)
859 memcpy(new->tail, old->tail, new_tail_len);
860
Johannes Berg88600202012-02-13 15:17:18 +0100861 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200862 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100863 if (err < 0)
864 return err;
865 if (err == 0)
866 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100867
Eric Dumazetcf778b02012-01-12 04:41:32 +0000868 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100869
Johannes Berg88600202012-02-13 15:17:18 +0100870 if (old)
871 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100872
Johannes Berg88600202012-02-13 15:17:18 +0100873 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100874}
875
Johannes Berg88600202012-02-13 15:17:18 +0100876static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
877 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100878{
Johannes Berg88600202012-02-13 15:17:18 +0100879 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100880 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100881 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100882 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100883 u32 changed = BSS_CHANGED_BEACON_INT |
884 BSS_CHANGED_BEACON_ENABLED |
885 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100886 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +0100887 BSS_CHANGED_P2P_PS |
888 BSS_CHANGED_TXPOWER;
Johannes Berg88600202012-02-13 15:17:18 +0100889 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200890
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100891 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100892 if (old)
893 return -EALREADY;
894
Eliad Pellerf6993172014-09-10 14:07:35 +0300895 switch (params->smps_mode) {
896 case NL80211_SMPS_OFF:
897 sdata->smps_mode = IEEE80211_SMPS_OFF;
898 break;
899 case NL80211_SMPS_STATIC:
900 sdata->smps_mode = IEEE80211_SMPS_STATIC;
901 break;
902 case NL80211_SMPS_DYNAMIC:
903 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
904 break;
905 default:
906 return -EINVAL;
907 }
Emmanuel Grumbachb3dd8272017-06-10 13:52:45 +0300908 sdata->u.ap.req_smps = sdata->smps_mode;
909
Johannes Berg04ecd252012-09-11 14:34:12 +0200910 sdata->needed_rx_chains = sdata->local->rx_chains;
911
Johannes Bergac668af2016-10-21 14:25:14 +0200912 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
913
Johannes Berg34a37402013-12-18 09:43:33 +0100914 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100915 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200916 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100917 if (!err)
918 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100919 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200920 if (err)
921 return err;
922
Johannes Berg665c93a2011-11-04 11:18:11 +0100923 /*
924 * Apply control port protocol, this allows us to
925 * not encrypt dynamic WEP control frames.
926 */
927 sdata->control_port_protocol = params->crypto.control_port_ethertype;
928 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -0500929 sdata->control_port_over_nl80211 =
930 params->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200931 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
932 &params->crypto,
933 sdata->vif.type);
934
Johannes Berg665c93a2011-11-04 11:18:11 +0100935 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
936 vlan->control_port_protocol =
937 params->crypto.control_port_ethertype;
938 vlan->control_port_no_encrypt =
939 params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -0500940 vlan->control_port_over_nl80211 =
941 params->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200942 vlan->encrypt_headroom =
943 ieee80211_cs_headroom(sdata->local,
944 &params->crypto,
945 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100946 }
947
Johannes Berg88600202012-02-13 15:17:18 +0100948 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100949 sdata->vif.bss_conf.enable_beacon = true;
Ayala Beker52cfa1d2016-03-17 15:41:39 +0200950 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
Johannes Berg88600202012-02-13 15:17:18 +0100951
952 sdata->vif.bss_conf.ssid_len = params->ssid_len;
953 if (params->ssid_len)
954 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
955 params->ssid_len);
956 sdata->vif.bss_conf.hidden_ssid =
957 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
958
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100959 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
960 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
961 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
962 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
963 if (params->p2p_opp_ps)
964 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
965 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100966
Michal Kazioraf296bd2014-06-05 14:21:36 +0200967 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200968 if (err < 0) {
969 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100970 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200971 }
Johannes Berg88600202012-02-13 15:17:18 +0100972 changed |= err;
973
Johannes Berg10416382012-10-19 15:44:42 +0200974 err = drv_start_ap(sdata->local, sdata);
975 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100976 old = sdata_dereference(sdata->u.ap.beacon, sdata);
977
Johannes Berg10416382012-10-19 15:44:42 +0200978 if (old)
979 kfree_rcu(old, rcu_head);
980 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200981 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200982 return err;
983 }
984
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800985 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100986 ieee80211_bss_info_change_notify(sdata, changed);
987
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200988 netif_carrier_on(dev);
989 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
990 netif_carrier_on(vlan->dev);
991
Johannes Berg665c93a2011-11-04 11:18:11 +0100992 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100993}
994
Johannes Berg88600202012-02-13 15:17:18 +0100995static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
996 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100997{
Johannes Berg14db74b2008-07-29 13:22:52 +0200998 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100999 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001000 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001001
Johannes Berg14db74b2008-07-29 13:22:52 +02001002 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +01001003 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +02001004
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001005 /* don't allow changing the beacon while CSA is in place - offset
1006 * of channel switch counter may change
1007 */
1008 if (sdata->vif.csa_active)
1009 return -EBUSY;
1010
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001011 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001012 if (!old)
1013 return -ENOENT;
1014
Michal Kazioraf296bd2014-06-05 14:21:36 +02001015 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +01001016 if (err < 0)
1017 return err;
1018 ieee80211_bss_info_change_notify(sdata, err);
1019 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001020}
1021
Johannes Berg88600202012-02-13 15:17:18 +01001022static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001023{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001024 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1025 struct ieee80211_sub_if_data *vlan;
1026 struct ieee80211_local *local = sdata->local;
1027 struct beacon_data *old_beacon;
1028 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001029 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001030
Michal Kaziordbd72852014-01-29 07:56:21 +01001031 sdata_assert_lock(sdata);
1032
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001033 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001034 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001035 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001036 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001037
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001038 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +02001039 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001040 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001041 if (sdata->csa_block_tx) {
1042 ieee80211_wake_vif_queues(local, sdata,
1043 IEEE80211_QUEUE_STOP_REASON_CSA);
1044 sdata->csa_block_tx = false;
1045 }
1046
Michal Kazior59af6922014-04-09 15:10:59 +02001047 mutex_unlock(&local->mtx);
1048
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +01001049 kfree(sdata->u.ap.next_beacon);
1050 sdata->u.ap.next_beacon = NULL;
1051
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001052 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001053 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1054 netif_carrier_off(vlan->dev);
1055 netif_carrier_off(dev);
1056
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001057 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001058 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001059 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1060 kfree_rcu(old_beacon, rcu_head);
1061 if (old_probe_resp)
1062 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +02001063 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +01001064
Johannes Berge7162512013-12-04 23:18:37 +01001065 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +01001066 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +01001067
Johannes Bergd6a83222012-12-14 14:06:28 +01001068 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001069 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001070 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001071 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001072
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001073 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001074 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001075 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001076 cfg80211_cac_event(sdata->dev, &chandef,
1077 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001078 GFP_KERNEL);
1079 }
1080
Johannes Berg10416382012-10-19 15:44:42 +02001081 drv_stop_ap(sdata->local, sdata);
1082
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001083 /* free all potentially still buffered bcast frames */
1084 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
Felix Fietkau6b07d9c2016-08-02 11:13:41 +02001085 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001086
Johannes Berg34a37402013-12-18 09:43:33 +01001087 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +01001088 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001089 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001090 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001091
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001092 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001093}
1094
Johannes Berg4fd69312007-12-19 02:03:35 +01001095/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1096struct iapp_layer2_update {
1097 u8 da[ETH_ALEN]; /* broadcast */
1098 u8 sa[ETH_ALEN]; /* STA addr */
1099 __be16 len; /* 6 */
1100 u8 dsap; /* 0 */
1101 u8 ssap; /* 0 */
1102 u8 control;
1103 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001104} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001105
1106static void ieee80211_send_layer2_update(struct sta_info *sta)
1107{
1108 struct iapp_layer2_update *msg;
1109 struct sk_buff *skb;
1110
1111 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1112 * bridge devices */
1113
1114 skb = dev_alloc_skb(sizeof(*msg));
1115 if (!skb)
1116 return;
Johannes Berg4df864c2017-06-16 14:29:21 +02001117 msg = skb_put(skb, sizeof(*msg));
Johannes Berg4fd69312007-12-19 02:03:35 +01001118
1119 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1120 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1121
Johannes Berge83e6542012-07-13 16:23:07 +02001122 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001123 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001124 msg->len = htons(6);
1125 msg->dsap = 0;
1126 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1127 msg->control = 0xaf; /* XID response lsb.1111F101.
1128 * F=0 (no poll command; unsolicited frame) */
1129 msg->xid_info[0] = 0x81; /* XID format identifier */
1130 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1131 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1132
Johannes Bergd0709a62008-02-25 16:27:46 +01001133 skb->dev = sta->sdata->dev;
1134 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001135 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001136 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001137}
1138
Johannes Bergd582cff2012-10-26 17:53:44 +02001139static int sta_apply_auth_flags(struct ieee80211_local *local,
1140 struct sta_info *sta,
1141 u32 mask, u32 set)
1142{
1143 int ret;
1144
1145 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1146 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1147 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1148 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1149 if (ret)
1150 return ret;
1151 }
1152
1153 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1154 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1155 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001156 /*
1157 * When peer becomes associated, init rate control as
1158 * well. Some drivers require rate control initialized
1159 * before drv_sta_state() is called.
1160 */
Ayala Beker44674d92015-09-23 10:41:27 +02001161 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001162 rate_control_rate_init(sta);
1163
Johannes Bergd582cff2012-10-26 17:53:44 +02001164 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1165 if (ret)
1166 return ret;
1167 }
1168
1169 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1170 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1171 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1172 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1173 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1174 else
1175 ret = 0;
1176 if (ret)
1177 return ret;
1178 }
1179
1180 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1181 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1182 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1183 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1184 if (ret)
1185 return ret;
1186 }
1187
1188 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1189 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1190 test_sta_flag(sta, WLAN_STA_AUTH)) {
1191 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1192 if (ret)
1193 return ret;
1194 }
1195
1196 return 0;
1197}
1198
Johannes Berg13657702015-06-17 10:34:54 +02001199static void sta_apply_mesh_params(struct ieee80211_local *local,
1200 struct sta_info *sta,
1201 struct station_parameters *params)
1202{
1203#ifdef CONFIG_MAC80211_MESH
1204 struct ieee80211_sub_if_data *sdata = sta->sdata;
1205 u32 changed = 0;
1206
1207 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1208 switch (params->plink_state) {
1209 case NL80211_PLINK_ESTAB:
1210 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1211 changed = mesh_plink_inc_estab_count(sdata);
1212 sta->mesh->plink_state = params->plink_state;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09001213 sta->mesh->aid = params->peer_aid;
Johannes Berg13657702015-06-17 10:34:54 +02001214
1215 ieee80211_mps_sta_status_update(sta);
1216 changed |= ieee80211_mps_set_sta_local_pm(sta,
1217 sdata->u.mesh.mshcfg.power_mode);
1218 break;
1219 case NL80211_PLINK_LISTEN:
1220 case NL80211_PLINK_BLOCKED:
1221 case NL80211_PLINK_OPN_SNT:
1222 case NL80211_PLINK_OPN_RCVD:
1223 case NL80211_PLINK_CNF_RCVD:
1224 case NL80211_PLINK_HOLDING:
1225 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1226 changed = mesh_plink_dec_estab_count(sdata);
1227 sta->mesh->plink_state = params->plink_state;
1228
1229 ieee80211_mps_sta_status_update(sta);
1230 changed |= ieee80211_mps_set_sta_local_pm(sta,
1231 NL80211_MESH_POWER_UNKNOWN);
1232 break;
1233 default:
1234 /* nothing */
1235 break;
1236 }
1237 }
1238
1239 switch (params->plink_action) {
1240 case NL80211_PLINK_ACTION_NO_ACTION:
1241 /* nothing */
1242 break;
1243 case NL80211_PLINK_ACTION_OPEN:
1244 changed |= mesh_plink_open(sta);
1245 break;
1246 case NL80211_PLINK_ACTION_BLOCK:
1247 changed |= mesh_plink_block(sta);
1248 break;
1249 }
1250
1251 if (params->local_pm)
1252 changed |= ieee80211_mps_set_sta_local_pm(sta,
1253 params->local_pm);
1254
1255 ieee80211_mbss_info_change_notify(sdata, changed);
1256#endif
1257}
1258
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001259static int sta_apply_parameters(struct ieee80211_local *local,
1260 struct sta_info *sta,
1261 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001262{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001263 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001264 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001265 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +03001266 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001267
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301268 sband = ieee80211_get_sband(sdata);
1269 if (!sband)
1270 return -EINVAL;
Johannes Bergae5eb022008-10-14 16:58:37 +02001271
Johannes Bergeccb8e82009-05-11 21:57:56 +03001272 mask = params->sta_flags_mask;
1273 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001274
Johannes Bergd582cff2012-10-26 17:53:44 +02001275 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1276 /*
1277 * In mesh mode, ASSOCIATED isn't part of the nl80211
1278 * API but must follow AUTHENTICATED for driver state.
1279 */
1280 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1281 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1282 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1283 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001284 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1285 /*
1286 * TDLS -- everything follows authorized, but
1287 * only becoming authorized is possible, not
1288 * going back
1289 */
1290 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1291 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1292 BIT(NL80211_STA_FLAG_ASSOCIATED);
1293 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1294 BIT(NL80211_STA_FLAG_ASSOCIATED);
1295 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001296 }
1297
Johannes Berg2c44be82015-03-30 15:09:20 +02001298 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1299 local->hw.queues >= IEEE80211_NUM_ACS)
1300 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1301
Ayala Beker44674d92015-09-23 10:41:27 +02001302 /* auth flags will be set later for TDLS,
1303 * and for unassociated stations that move to assocaited */
1304 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1305 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1306 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001307 ret = sta_apply_auth_flags(local, sta, mask, set);
1308 if (ret)
1309 return ret;
1310 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001311
Johannes Bergeccb8e82009-05-11 21:57:56 +03001312 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001313 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001314 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1315 else
1316 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001317 }
1318
Johannes Bergeccb8e82009-05-11 21:57:56 +03001319 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Tamizh chelvam93f04902015-10-07 10:40:04 +05301320 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
Johannes Bergeccb8e82009-05-11 21:57:56 +03001321 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001322 set_sta_flag(sta, WLAN_STA_MFP);
1323 else
1324 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001325 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001326
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001327 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001328 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001329 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1330 else
1331 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001332 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001333
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001334 /* mark TDLS channel switch support, if the AP allows it */
1335 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1336 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1337 params->ext_capab_len >= 4 &&
1338 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1339 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1340
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001341 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +03001342 !sdata->u.mgd.tdls_wider_bw_prohibited &&
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001343 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1344 params->ext_capab_len >= 8 &&
1345 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1346 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1347
Johannes Berg3b9ce802011-09-27 20:56:12 +02001348 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1349 sta->sta.uapsd_queues = params->uapsd_queues;
1350 sta->sta.max_sp = params->max_sp;
1351 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001352
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001353 /* The sender might not have sent the last bit, consider it to be 0 */
1354 if (params->ext_capab_len >= 8) {
1355 u8 val = (params->ext_capab[7] &
1356 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1357
1358 /* we did get all the bits, take the MSB as well */
1359 if (params->ext_capab_len >= 9) {
1360 u8 val_msb = params->ext_capab[8] &
1361 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1362 val_msb <<= 1;
1363 val |= val_msb;
1364 }
1365
1366 switch (val) {
1367 case 1:
1368 sta->sta.max_amsdu_subframes = 32;
1369 break;
1370 case 2:
1371 sta->sta.max_amsdu_subframes = 16;
1372 break;
1373 case 3:
1374 sta->sta.max_amsdu_subframes = 8;
1375 break;
1376 default:
1377 sta->sta.max_amsdu_subframes = 0;
1378 }
1379 }
1380
Johannes Berg73651ee2008-02-25 16:27:47 +01001381 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001382 * cfg80211 validates this (1-2007) and allows setting the AID
1383 * only when creating a new station entry
1384 */
1385 if (params->aid)
1386 sta->sta.aid = params->aid;
1387
1388 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001389 * Some of the following updates would be racy if called on an
1390 * existing station, via ieee80211_change_station(). However,
1391 * all such changes are rejected by cfg80211 except for updates
1392 * changing the supported rates on an existing but not yet used
1393 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001394 */
1395
Johannes Berg4fd69312007-12-19 02:03:35 +01001396 if (params->listen_interval >= 0)
1397 sta->listen_interval = params->listen_interval;
1398
1399 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001400 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1401 sband, params->supported_rates,
1402 params->supported_rates_len,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301403 &sta->sta.supp_rates[sband->band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001404 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001405
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001406 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001407 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001408 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001409
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001410 /* VHT can override some HT caps such as the A-MSDU max length */
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001411 if (params->vht_capa)
1412 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001413 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001414
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001415 if (params->he_capa)
1416 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1417 (void *)params->he_capa,
1418 params->he_capa_len, sta);
1419
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001420 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001421 /* returned value is only needed for rc update, but the
1422 * rc isn't initialized here yet, so ignore it
1423 */
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301424 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1425 sband->band);
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001426 }
1427
Ayala Beker52cfa1d2016-03-17 15:41:39 +02001428 if (params->support_p2p_ps >= 0)
1429 sta->sta.support_p2p_ps = params->support_p2p_ps;
1430
Johannes Berg13657702015-06-17 10:34:54 +02001431 if (ieee80211_vif_is_mesh(&sdata->vif))
1432 sta_apply_mesh_params(local, sta, params);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001433
Arik Nemtsov68885a52014-06-11 17:18:19 +03001434 /* set the STA state after all sta info from usermode has been set */
Ayala Beker44674d92015-09-23 10:41:27 +02001435 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1436 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001437 ret = sta_apply_auth_flags(local, sta, mask, set);
1438 if (ret)
1439 return ret;
1440 }
1441
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001442 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001443}
1444
1445static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001446 const u8 *mac,
1447 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001448{
Johannes Berg14db74b2008-07-29 13:22:52 +02001449 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001450 struct sta_info *sta;
1451 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001452 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001453 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001454
Johannes Berg4fd69312007-12-19 02:03:35 +01001455 if (params->vlan) {
1456 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1457
Johannes Berg05c914f2008-09-11 00:01:58 +02001458 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1459 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001460 return -EINVAL;
1461 } else
1462 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1463
Joe Perchesb203ca32012-05-08 18:56:52 +00001464 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001465 return -EINVAL;
1466
1467 if (is_multicast_ether_addr(mac))
1468 return -EINVAL;
1469
1470 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001471 if (!sta)
1472 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001473
Ayala Beker44674d92015-09-23 10:41:27 +02001474 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1475 sta->sta.tdls = true;
Johannes Berg4fd69312007-12-19 02:03:35 +01001476
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001477 err = sta_apply_parameters(local, sta, params);
1478 if (err) {
1479 sta_info_free(local, sta);
1480 return err;
1481 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001482
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001483 /*
Ayala Beker44674d92015-09-23 10:41:27 +02001484 * for TDLS and for unassociated station, rate control should be
1485 * initialized only when rates are known and station is marked
1486 * authorized/associated
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001487 */
Ayala Beker44674d92015-09-23 10:41:27 +02001488 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1489 test_sta_flag(sta, WLAN_STA_ASSOC))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001490 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001491
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001492 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1493 sdata->vif.type == NL80211_IFTYPE_AP;
1494
Johannes Berg34e89502010-02-03 13:59:58 +01001495 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001496 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001497 rcu_read_unlock();
1498 return err;
1499 }
1500
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001501 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001502 ieee80211_send_layer2_update(sta);
1503
1504 rcu_read_unlock();
1505
Johannes Berg4fd69312007-12-19 02:03:35 +01001506 return 0;
1507}
1508
1509static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001510 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001511{
Johannes Berg14db74b2008-07-29 13:22:52 +02001512 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001513
Johannes Berg14db74b2008-07-29 13:22:52 +02001514 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1515
Jouni Malinen89c771e2014-10-10 20:52:40 +03001516 if (params->mac)
1517 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001518
Johannes Bergb998e8b2012-12-13 23:07:46 +01001519 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001520 return 0;
1521}
1522
1523static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001524 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001525 struct station_parameters *params)
1526{
Johannes Bergabe60632009-11-25 17:46:18 +01001527 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001528 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001529 struct sta_info *sta;
1530 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001531 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001532 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001533
Johannes Berg87be1e12011-12-14 12:20:29 +01001534 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001535
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001536 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001537 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001538 err = -ENOENT;
1539 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001540 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001541
Johannes Berg77ee7c82013-02-15 00:48:33 +01001542 switch (sdata->vif.type) {
1543 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001544 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001545 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001546 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001547 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001548 break;
1549 case NL80211_IFTYPE_ADHOC:
1550 statype = CFG80211_STA_IBSS;
1551 break;
1552 case NL80211_IFTYPE_STATION:
1553 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1554 statype = CFG80211_STA_AP_STA;
1555 break;
1556 }
1557 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1558 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1559 else
1560 statype = CFG80211_STA_TDLS_PEER_SETUP;
1561 break;
1562 case NL80211_IFTYPE_AP:
1563 case NL80211_IFTYPE_AP_VLAN:
Ayala Beker44674d92015-09-23 10:41:27 +02001564 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1565 statype = CFG80211_STA_AP_CLIENT;
1566 else
1567 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001568 break;
1569 default:
1570 err = -EOPNOTSUPP;
1571 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001572 }
1573
Johannes Berg77ee7c82013-02-15 00:48:33 +01001574 err = cfg80211_check_station_change(wiphy, params, statype);
1575 if (err)
1576 goto out_err;
1577
Johannes Bergd0709a62008-02-25 16:27:46 +01001578 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +01001579 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1580
Johannes Berg9bc383d2009-11-19 11:55:19 +01001581 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001582 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001583 err = -EBUSY;
1584 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001585 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001586
Eric Dumazetcf778b02012-01-12 04:41:32 +00001587 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03001588 __ieee80211_check_fast_rx_iface(vlansdata);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001589 }
1590
1591 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Michael Braun72f15d52016-10-10 19:12:21 +02001592 sta->sdata->u.vlan.sta)
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301593 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Michael Braun72f15d52016-10-10 19:12:21 +02001594
1595 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1596 ieee80211_vif_dec_num_mcast(sta->sdata);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001597
Johannes Berg14db74b2008-07-29 13:22:52 +02001598 sta->sdata = vlansdata;
Michal Kazior464daaf2015-05-19 14:13:36 +02001599 ieee80211_check_fast_xmit(sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001600
Michael Braun72f15d52016-10-10 19:12:21 +02001601 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1602 ieee80211_vif_inc_num_mcast(sta->sdata);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001603
Johannes Berg4fd69312007-12-19 02:03:35 +01001604 ieee80211_send_layer2_update(sta);
1605 }
1606
Eliad Peller35b88622011-12-29 14:41:39 +02001607 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001608 if (err)
1609 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001610
Johannes Berg87be1e12011-12-14 12:20:29 +01001611 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001612
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001613 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1614 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1615 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1616 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1617 sta_info_tx_streams(sta) != 1) {
1618 ht_dbg(sta->sdata,
1619 "%pM just authorized and MIMO capable - update SMPS\n",
1620 sta->sta.addr);
1621 ieee80211_send_smps_action(sta->sdata,
1622 sta->sdata->bss->req_smps,
1623 sta->sta.addr,
1624 sta->sdata->vif.bss_conf.bssid);
1625 }
1626
Jason Young808118c2011-03-10 16:43:19 -08001627 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001628 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001629 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03001630 ieee80211_recalc_ps_vif(sdata);
1631 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001632
Johannes Berg4fd69312007-12-19 02:03:35 +01001633 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001634out_err:
1635 mutex_unlock(&local->sta_mtx);
1636 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001637}
1638
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001639#ifdef CONFIG_MAC80211_MESH
1640static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001641 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001642{
Johannes Berg14db74b2008-07-29 13:22:52 +02001643 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001644 struct mesh_path *mpath;
1645 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001646
Johannes Berg14db74b2008-07-29 13:22:52 +02001647 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1648
Johannes Bergd0709a62008-02-25 16:27:46 +01001649 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001650 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001651 if (!sta) {
1652 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001653 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001654 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001655
Bob Copelandae76eef2013-03-29 09:38:39 -04001656 mpath = mesh_path_add(sdata, dst);
1657 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001658 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001659 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001660 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001661
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001662 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001663
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001664 rcu_read_unlock();
1665 return 0;
1666}
1667
1668static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001669 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001670{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001671 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001672
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001673 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001674 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001675
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001676 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001677 return 0;
1678}
1679
Johannes Berg3b3a0162014-05-19 17:19:31 +02001680static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1681 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001682{
Johannes Berg14db74b2008-07-29 13:22:52 +02001683 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001684 struct mesh_path *mpath;
1685 struct sta_info *sta;
1686
Johannes Berg14db74b2008-07-29 13:22:52 +02001687 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1688
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001689 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001690
Johannes Bergabe60632009-11-25 17:46:18 +01001691 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001692 if (!sta) {
1693 rcu_read_unlock();
1694 return -ENOENT;
1695 }
1696
Johannes Bergbf7cd942013-02-15 14:40:31 +01001697 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001698 if (!mpath) {
1699 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001700 return -ENOENT;
1701 }
1702
1703 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001704
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001705 rcu_read_unlock();
1706 return 0;
1707}
1708
1709static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1710 struct mpath_info *pinfo)
1711{
Johannes Berga3836e02011-05-12 15:11:37 +02001712 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1713
1714 if (next_hop_sta)
1715 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001716 else
Joe Perchesc84a67a2015-03-02 19:54:57 -08001717 eth_zero_addr(next_hop);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001718
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001719 memset(pinfo, 0, sizeof(*pinfo));
1720
Bob Copeland2bdaf382016-02-28 20:03:56 -05001721 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001722
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001723 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001724 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001725 MPATH_INFO_METRIC |
1726 MPATH_INFO_EXPTIME |
1727 MPATH_INFO_DISCOVERY_TIMEOUT |
1728 MPATH_INFO_DISCOVERY_RETRIES |
1729 MPATH_INFO_FLAGS;
1730
1731 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001732 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001733 pinfo->metric = mpath->metric;
1734 if (time_before(jiffies, mpath->exp_time))
1735 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1736 pinfo->discovery_timeout =
1737 jiffies_to_msecs(mpath->discovery_timeout);
1738 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001739 if (mpath->flags & MESH_PATH_ACTIVE)
1740 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1741 if (mpath->flags & MESH_PATH_RESOLVING)
1742 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001743 if (mpath->flags & MESH_PATH_SN_VALID)
1744 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001745 if (mpath->flags & MESH_PATH_FIXED)
1746 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001747 if (mpath->flags & MESH_PATH_RESOLVED)
1748 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001749}
1750
1751static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1752 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1753
1754{
Johannes Berg14db74b2008-07-29 13:22:52 +02001755 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001756 struct mesh_path *mpath;
1757
Johannes Berg14db74b2008-07-29 13:22:52 +02001758 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1759
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001760 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001761 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001762 if (!mpath) {
1763 rcu_read_unlock();
1764 return -ENOENT;
1765 }
1766 memcpy(dst, mpath->dst, ETH_ALEN);
1767 mpath_set_pinfo(mpath, next_hop, pinfo);
1768 rcu_read_unlock();
1769 return 0;
1770}
1771
1772static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001773 int idx, u8 *dst, u8 *next_hop,
1774 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001775{
Johannes Berg14db74b2008-07-29 13:22:52 +02001776 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001777 struct mesh_path *mpath;
1778
Johannes Berg14db74b2008-07-29 13:22:52 +02001779 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1780
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001781 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001782 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001783 if (!mpath) {
1784 rcu_read_unlock();
1785 return -ENOENT;
1786 }
1787 memcpy(dst, mpath->dst, ETH_ALEN);
1788 mpath_set_pinfo(mpath, next_hop, pinfo);
1789 rcu_read_unlock();
1790 return 0;
1791}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001792
Henning Roggea2db2ed2014-09-12 08:58:50 +02001793static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1794 struct mpath_info *pinfo)
1795{
1796 memset(pinfo, 0, sizeof(*pinfo));
1797 memcpy(mpp, mpath->mpp, ETH_ALEN);
1798
Bob Copeland2bdaf382016-02-28 20:03:56 -05001799 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
Henning Roggea2db2ed2014-09-12 08:58:50 +02001800}
1801
1802static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1803 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1804
1805{
1806 struct ieee80211_sub_if_data *sdata;
1807 struct mesh_path *mpath;
1808
1809 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1810
1811 rcu_read_lock();
1812 mpath = mpp_path_lookup(sdata, dst);
1813 if (!mpath) {
1814 rcu_read_unlock();
1815 return -ENOENT;
1816 }
1817 memcpy(dst, mpath->dst, ETH_ALEN);
1818 mpp_set_pinfo(mpath, mpp, pinfo);
1819 rcu_read_unlock();
1820 return 0;
1821}
1822
1823static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1824 int idx, u8 *dst, u8 *mpp,
1825 struct mpath_info *pinfo)
1826{
1827 struct ieee80211_sub_if_data *sdata;
1828 struct mesh_path *mpath;
1829
1830 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1831
1832 rcu_read_lock();
1833 mpath = mpp_path_lookup_by_idx(sdata, idx);
1834 if (!mpath) {
1835 rcu_read_unlock();
1836 return -ENOENT;
1837 }
1838 memcpy(dst, mpath->dst, ETH_ALEN);
1839 mpp_set_pinfo(mpath, mpp, pinfo);
1840 rcu_read_unlock();
1841 return 0;
1842}
1843
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001844static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001845 struct net_device *dev,
1846 struct mesh_config *conf)
1847{
1848 struct ieee80211_sub_if_data *sdata;
1849 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1850
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001851 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1852 return 0;
1853}
1854
1855static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1856{
1857 return (mask >> (parm-1)) & 0x1;
1858}
1859
Javier Cardonac80d5452010-12-16 17:37:49 -08001860static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1861 const struct mesh_setup *setup)
1862{
1863 u8 *new_ie;
1864 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001865 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1866 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001867
Javier Cardona581a8b02011-04-07 15:08:27 -07001868 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001869 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001870 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001871
Javier Cardona581a8b02011-04-07 15:08:27 -07001872 if (setup->ie_len) {
1873 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001874 GFP_KERNEL);
1875 if (!new_ie)
1876 return -ENOMEM;
1877 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001878 ifmsh->ie_len = setup->ie_len;
1879 ifmsh->ie = new_ie;
1880 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001881
1882 /* now copy the rest of the setup parameters */
1883 ifmsh->mesh_id_len = setup->mesh_id_len;
1884 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001885 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001886 ifmsh->mesh_pp_id = setup->path_sel_proto;
1887 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001888 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001889 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001890 ifmsh->security = IEEE80211_MESH_SEC_NONE;
Benjamin Berg0ab2e552017-05-16 11:23:13 +02001891 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001892 if (setup->is_authenticated)
1893 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1894 if (setup->is_secure)
1895 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001896
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001897 /* mcast rate setting in Mesh Node */
1898 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1899 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001900 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001901
Marco Porsch9bdbf042013-01-07 16:04:51 +01001902 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1903 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1904
Javier Cardonac80d5452010-12-16 17:37:49 -08001905 return 0;
1906}
1907
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001908static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001909 struct net_device *dev, u32 mask,
1910 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001911{
1912 struct mesh_config *conf;
1913 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001914 struct ieee80211_if_mesh *ifmsh;
1915
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001916 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001917 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001918
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001919 /* Set the config options which we are interested in setting */
1920 conf = &(sdata->u.mesh.mshcfg);
1921 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1922 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1923 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1924 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1925 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1926 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1927 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1928 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1929 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1930 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1931 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1932 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001933 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001934 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001935 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1936 if (ifmsh->user_mpm)
1937 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001938 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001939 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001940 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1941 conf->dot11MeshNbrOffsetMaxNeighbor =
1942 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001943 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1944 conf->dot11MeshHWMPmaxPREQretries =
1945 nconf->dot11MeshHWMPmaxPREQretries;
1946 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1947 conf->path_refresh_time = nconf->path_refresh_time;
1948 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1949 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1950 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1951 conf->dot11MeshHWMPactivePathTimeout =
1952 nconf->dot11MeshHWMPactivePathTimeout;
1953 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1954 conf->dot11MeshHWMPpreqMinInterval =
1955 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001956 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1957 conf->dot11MeshHWMPperrMinInterval =
1958 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001959 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1960 mask))
1961 conf->dot11MeshHWMPnetDiameterTraversalTime =
1962 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001963 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1964 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1965 ieee80211_mesh_root_setup(ifmsh);
1966 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001967 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001968 /* our current gate announcement implementation rides on root
1969 * announcements, so require this ifmsh to also be a root node
1970 * */
1971 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001972 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1973 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001974 ieee80211_mesh_root_setup(ifmsh);
1975 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001976 conf->dot11MeshGateAnnouncementProtocol =
1977 nconf->dot11MeshGateAnnouncementProtocol;
1978 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001979 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001980 conf->dot11MeshHWMPRannInterval =
1981 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001982 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1983 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001984 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1985 /* our RSSI threshold implementation is supported only for
1986 * devices that report signal in dBm.
1987 */
Johannes Berg30686bf2015-06-02 21:39:54 +02001988 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
Ashok Nagarajan55335132012-02-28 17:04:08 -08001989 return -ENOTSUPP;
1990 conf->rssi_threshold = nconf->rssi_threshold;
1991 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001992 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1993 conf->ht_opmode = nconf->ht_opmode;
1994 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1995 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1996 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001997 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1998 conf->dot11MeshHWMPactivePathToRootTimeout =
1999 nconf->dot11MeshHWMPactivePathToRootTimeout;
2000 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2001 conf->dot11MeshHWMProotInterval =
2002 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08002003 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2004 conf->dot11MeshHWMPconfirmationInterval =
2005 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002006 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2007 conf->power_mode = nconf->power_mode;
2008 ieee80211_mps_local_status_update(sdata);
2009 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002010 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002011 conf->dot11MeshAwakeWindowDuration =
2012 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07002013 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2014 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002015 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002016 return 0;
2017}
2018
Johannes Berg29cbe682010-12-03 09:20:44 +01002019static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2020 const struct mesh_config *conf,
2021 const struct mesh_setup *setup)
2022{
2023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2024 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08002025 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01002026
Javier Cardonac80d5452010-12-16 17:37:49 -08002027 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2028 err = copy_mesh_setup(ifmsh, setup);
2029 if (err)
2030 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002031
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002032 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2033
Johannes Berg04ecd252012-09-11 14:34:12 +02002034 /* can mesh use other SMPS modes? */
2035 sdata->smps_mode = IEEE80211_SMPS_OFF;
2036 sdata->needed_rx_chains = sdata->local->rx_chains;
2037
Johannes Berg34a37402013-12-18 09:43:33 +01002038 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01002039 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02002040 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01002041 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002042 if (err)
2043 return err;
2044
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002045 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01002046}
2047
2048static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2049{
2050 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2051
2052 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002053 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002054 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002055 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01002056
2057 return 0;
2058}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002059#endif
2060
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002061static int ieee80211_change_bss(struct wiphy *wiphy,
2062 struct net_device *dev,
2063 struct bss_parameters *params)
2064{
Johannes Berg55de9082012-07-26 17:24:39 +02002065 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302066 struct ieee80211_supported_band *sband;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002067 u32 changed = 0;
2068
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01002069 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02002070 return -ENOENT;
2071
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302072 sband = ieee80211_get_sband(sdata);
2073 if (!sband)
2074 return -EINVAL;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002075
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002076 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002077 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002078 changed |= BSS_CHANGED_ERP_CTS_PROT;
2079 }
2080 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002081 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002082 params->use_short_preamble;
2083 changed |= BSS_CHANGED_ERP_PREAMBLE;
2084 }
Felix Fietkau43d35342010-01-15 03:00:48 +01002085
2086 if (!sdata->vif.bss_conf.use_short_slot &&
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302087 sband->band == NL80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01002088 sdata->vif.bss_conf.use_short_slot = true;
2089 changed |= BSS_CHANGED_ERP_SLOT;
2090 }
2091
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002092 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002093 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002094 params->use_short_slot_time;
2095 changed |= BSS_CHANGED_ERP_SLOT;
2096 }
2097
Jouni Malinen90c97a02008-10-30 16:59:22 +02002098 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002099 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302100 wiphy->bands[sband->band],
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002101 params->basic_rates,
2102 params->basic_rates_len,
2103 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002104 changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berge8e4f522017-03-08 11:12:10 +01002105 ieee80211_check_rate_mask(sdata);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002106 }
2107
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002108 if (params->ap_isolate >= 0) {
2109 if (params->ap_isolate)
2110 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2111 else
2112 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002113 ieee80211_check_fast_rx_iface(sdata);
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002114 }
2115
Helmut Schaa80d7e402010-11-19 12:40:26 +01002116 if (params->ht_opmode >= 0) {
2117 sdata->vif.bss_conf.ht_operation_mode =
2118 (u16) params->ht_opmode;
2119 changed |= BSS_CHANGED_HT;
2120 }
2121
Johannes Berg339afbf2012-11-14 15:21:17 +01002122 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002123 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2124 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2125 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2126 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002127 changed |= BSS_CHANGED_P2P_PS;
2128 }
2129
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002130 if (params->p2p_opp_ps > 0) {
2131 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2132 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2133 changed |= BSS_CHANGED_P2P_PS;
2134 } else if (params->p2p_opp_ps == 0) {
2135 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2136 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002137 changed |= BSS_CHANGED_P2P_PS;
2138 }
2139
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002140 ieee80211_bss_info_change_notify(sdata, changed);
2141
2142 return 0;
2143}
2144
Jouni Malinen31888482008-10-30 16:59:24 +02002145static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002146 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002147 struct ieee80211_txq_params *params)
2148{
2149 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002151 struct ieee80211_tx_queue_params p;
2152
2153 if (!local->ops->conf_tx)
2154 return -EOPNOTSUPP;
2155
Johannes Berg54bcbc62012-03-28 11:04:25 +02002156 if (local->hw.queues < IEEE80211_NUM_ACS)
2157 return -EOPNOTSUPP;
2158
Jouni Malinen31888482008-10-30 16:59:24 +02002159 memset(&p, 0, sizeof(p));
2160 p.aifs = params->aifs;
2161 p.cw_max = params->cwmax;
2162 p.cw_min = params->cwmin;
2163 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002164
2165 /*
2166 * Setting tx queue params disables u-apsd because it's only
2167 * called in master mode.
2168 */
2169 p.uapsd = false;
2170
Haim Dreyfusse552af02018-03-28 13:24:10 +03002171 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2172
Johannes Berga3304b02012-03-28 11:04:24 +02002173 sdata->tx_conf[params->ac] = p;
2174 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002175 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002176 "failed to set TX queue parameters for AC %d\n",
2177 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002178 return -EINVAL;
2179 }
2180
Johannes Berg7d257452012-07-06 17:37:43 +02002181 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2182
Jouni Malinen31888482008-10-30 16:59:24 +02002183 return 0;
2184}
2185
Bob Copeland665af4f2009-01-19 11:20:53 -05002186#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002187static int ieee80211_suspend(struct wiphy *wiphy,
2188 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002189{
Johannes Bergeecc4802011-05-04 15:37:29 +02002190 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002191}
2192
2193static int ieee80211_resume(struct wiphy *wiphy)
2194{
2195 return __ieee80211_resume(wiphy_priv(wiphy));
2196}
2197#else
2198#define ieee80211_suspend NULL
2199#define ieee80211_resume NULL
2200#endif
2201
Johannes Berg2a519312009-02-10 21:25:55 +01002202static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002203 struct cfg80211_scan_request *req)
2204{
Johannes Bergfd014282012-06-18 19:17:03 +02002205 struct ieee80211_sub_if_data *sdata;
2206
2207 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002208
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002209 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2210 case NL80211_IFTYPE_STATION:
2211 case NL80211_IFTYPE_ADHOC:
2212 case NL80211_IFTYPE_MESH_POINT:
2213 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002214 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002215 break;
2216 case NL80211_IFTYPE_P2P_GO:
2217 if (sdata->local->ops->hw_scan)
2218 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002219 /*
2220 * FIXME: implement NoA while scanning in software,
2221 * for now fall through to allow scanning only when
2222 * beaconing hasn't been configured yet
2223 */
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -05002224 /* fall through */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002225 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002226 /*
2227 * If the scan has been forced (and the driver supports
2228 * forcing), don't care about being beaconing already.
2229 * This will create problems to the attached stations (e.g. all
2230 * the frames sent while scanning on other channel will be
2231 * lost)
2232 */
2233 if (sdata->u.ap.beacon &&
2234 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2235 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002236 return -EOPNOTSUPP;
2237 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002238 case NL80211_IFTYPE_NAN:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002239 default:
2240 return -EOPNOTSUPP;
2241 }
Johannes Berg2a519312009-02-10 21:25:55 +01002242
2243 return ieee80211_request_scan(sdata, req);
2244}
2245
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05302246static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2247{
2248 ieee80211_scan_cancel(wiphy_priv(wiphy));
2249}
2250
Luciano Coelho79f460c2011-05-11 17:09:36 +03002251static int
2252ieee80211_sched_scan_start(struct wiphy *wiphy,
2253 struct net_device *dev,
2254 struct cfg80211_sched_scan_request *req)
2255{
2256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2257
2258 if (!sdata->local->ops->sched_scan_start)
2259 return -EOPNOTSUPP;
2260
2261 return ieee80211_request_sched_scan_start(sdata, req);
2262}
2263
2264static int
Arend Van Spriel3a3ecf12017-04-21 13:05:02 +01002265ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2266 u64 reqid)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002267{
Eliad Peller0d440ea2015-10-25 10:59:33 +02002268 struct ieee80211_local *local = wiphy_priv(wiphy);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002269
Eliad Peller0d440ea2015-10-25 10:59:33 +02002270 if (!local->ops->sched_scan_stop)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002271 return -EOPNOTSUPP;
2272
Eliad Peller0d440ea2015-10-25 10:59:33 +02002273 return ieee80211_request_sched_scan_stop(local);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002274}
2275
Jouni Malinen636a5d32009-03-19 13:39:22 +02002276static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2277 struct cfg80211_auth_request *req)
2278{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002279 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002280}
2281
2282static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2283 struct cfg80211_assoc_request *req)
2284{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002285 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002286}
2287
2288static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002289 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002290{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002291 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002292}
2293
2294static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002295 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002296{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002297 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002298}
2299
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002300static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2301 struct cfg80211_ibss_params *params)
2302{
Johannes Berg55de9082012-07-26 17:24:39 +02002303 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002304}
2305
2306static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2307{
Johannes Berg55de9082012-07-26 17:24:39 +02002308 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002309}
2310
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002311static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2312 struct ocb_setup *setup)
2313{
2314 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2315}
2316
2317static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2318{
2319 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2320}
2321
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002322static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002323 int rate[NUM_NL80211_BANDS])
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002324{
2325 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2326
Cong Ding9887dbf2013-02-06 17:23:45 +01002327 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002328 sizeof(int) * NUM_NL80211_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002329
Pradeep Kumar Chitrapudcbe73c2018-03-22 12:18:03 -07002330 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2331
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002332 return 0;
2333}
2334
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002335static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2336{
2337 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002338 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002339
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002340 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
Johannes Berg17c18bf2015-03-21 15:25:43 +01002341 ieee80211_check_fast_xmit_all(local);
2342
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002343 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2344
Johannes Berg17c18bf2015-03-21 15:25:43 +01002345 if (err) {
2346 ieee80211_check_fast_xmit_all(local);
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002347 return err;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002348 }
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002349 }
2350
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002351 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2352 (changed & WIPHY_PARAM_DYN_ACK)) {
2353 s16 coverage_class;
2354
2355 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2356 wiphy->coverage_class : -1;
2357 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002358
2359 if (err)
2360 return err;
2361 }
2362
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002363 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002364 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002365
Johannes Berg24487982009-04-23 18:52:52 +02002366 if (err)
2367 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002368 }
2369
Johannes Berg8bc83c22012-11-09 18:38:32 +01002370 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2371 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2372 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002373 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002374 }
2375 if (changed & WIPHY_PARAM_RETRY_LONG) {
2376 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2377 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002378 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002379 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002380 if (changed &
2381 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2382 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2383
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02002384 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2385 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2386 WIPHY_PARAM_TXQ_QUANTUM))
2387 ieee80211_txq_set_params(local);
2388
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002389 return 0;
2390}
2391
Johannes Berg7643a2c2009-06-02 13:01:39 +02002392static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002393 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002394 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002395{
2396 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002397 struct ieee80211_sub_if_data *sdata;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002398 enum nl80211_tx_power_setting txp_type = type;
2399 bool update_txp_type = false;
Peter Große3a3713e2017-12-13 18:29:46 +01002400 bool has_monitor = false;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002401
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002402 if (wdev) {
2403 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2404
Peter Große3a3713e2017-12-13 18:29:46 +01002405 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2406 sdata = rtnl_dereference(local->monitor_sdata);
2407 if (!sdata)
2408 return -EOPNOTSUPP;
2409 }
2410
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002411 switch (type) {
2412 case NL80211_TX_POWER_AUTOMATIC:
2413 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002414 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002415 break;
2416 case NL80211_TX_POWER_LIMITED:
2417 case NL80211_TX_POWER_FIXED:
2418 if (mbm < 0 || (mbm % 100))
2419 return -EOPNOTSUPP;
2420 sdata->user_power_level = MBM_TO_DBM(mbm);
2421 break;
2422 }
2423
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002424 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2425 update_txp_type = true;
2426 sdata->vif.bss_conf.txpower_type = txp_type;
2427 }
2428
2429 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002430
2431 return 0;
2432 }
Johannes Berg55de9082012-07-26 17:24:39 +02002433
Johannes Berg7643a2c2009-06-02 13:01:39 +02002434 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002435 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002436 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002437 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002438 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002439 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002440 case NL80211_TX_POWER_FIXED:
2441 if (mbm < 0 || (mbm % 100))
2442 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002443 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002444 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002445 }
2446
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002447 mutex_lock(&local->iflist_mtx);
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002448 list_for_each_entry(sdata, &local->interfaces, list) {
Peter Große3a3713e2017-12-13 18:29:46 +01002449 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2450 has_monitor = true;
2451 continue;
2452 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002453 sdata->user_power_level = local->user_power_level;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002454 if (txp_type != sdata->vif.bss_conf.txpower_type)
2455 update_txp_type = true;
2456 sdata->vif.bss_conf.txpower_type = txp_type;
2457 }
Peter Große3a3713e2017-12-13 18:29:46 +01002458 list_for_each_entry(sdata, &local->interfaces, list) {
2459 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2460 continue;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002461 ieee80211_recalc_txpower(sdata, update_txp_type);
Peter Große3a3713e2017-12-13 18:29:46 +01002462 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002463 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002464
Peter Große3a3713e2017-12-13 18:29:46 +01002465 if (has_monitor) {
2466 sdata = rtnl_dereference(local->monitor_sdata);
2467 if (sdata) {
2468 sdata->user_power_level = local->user_power_level;
2469 if (txp_type != sdata->vif.bss_conf.txpower_type)
2470 update_txp_type = true;
2471 sdata->vif.bss_conf.txpower_type = txp_type;
2472
2473 ieee80211_recalc_txpower(sdata, update_txp_type);
2474 }
2475 }
2476
Johannes Berg7643a2c2009-06-02 13:01:39 +02002477 return 0;
2478}
2479
Johannes Bergc8442112012-10-24 10:17:18 +02002480static int ieee80211_get_tx_power(struct wiphy *wiphy,
2481 struct wireless_dev *wdev,
2482 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002483{
2484 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002485 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002486
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002487 if (local->ops->get_txpower)
2488 return drv_get_txpower(local, sdata, dbm);
2489
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002490 if (!local->use_chanctx)
2491 *dbm = local->hw.conf.power_level;
2492 else
2493 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002494
Johannes Berg7643a2c2009-06-02 13:01:39 +02002495 return 0;
2496}
2497
Johannes Bergab737a42009-07-01 21:26:58 +02002498static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002499 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002500{
2501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2502
2503 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2504
2505 return 0;
2506}
2507
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002508static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2509{
2510 struct ieee80211_local *local = wiphy_priv(wiphy);
2511
2512 drv_rfkill_poll(local);
2513}
2514
Johannes Bergaff89a92009-07-01 21:26:51 +02002515#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002516static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2517 struct wireless_dev *wdev,
2518 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002519{
2520 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002521 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002522
2523 if (!local->ops->testmode_cmd)
2524 return -EOPNOTSUPP;
2525
David Spinadel52981cd2013-07-31 18:06:22 +03002526 if (wdev) {
2527 struct ieee80211_sub_if_data *sdata;
2528
2529 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2530 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2531 vif = &sdata->vif;
2532 }
2533
2534 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002535}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002536
2537static int ieee80211_testmode_dump(struct wiphy *wiphy,
2538 struct sk_buff *skb,
2539 struct netlink_callback *cb,
2540 void *data, int len)
2541{
2542 struct ieee80211_local *local = wiphy_priv(wiphy);
2543
2544 if (!local->ops->testmode_dump)
2545 return -EOPNOTSUPP;
2546
2547 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2548}
Johannes Bergaff89a92009-07-01 21:26:51 +02002549#endif
2550
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002551int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2552 enum ieee80211_smps_mode smps_mode)
2553{
2554 struct sta_info *sta;
2555 enum ieee80211_smps_mode old_req;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002556
2557 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2558 return -EINVAL;
2559
2560 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2561 return 0;
2562
2563 old_req = sdata->u.ap.req_smps;
2564 sdata->u.ap.req_smps = smps_mode;
2565
2566 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2567 if (old_req == smps_mode ||
2568 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2569 return 0;
2570
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002571 ht_dbg(sdata,
Michael Braun6a8b4ad2015-03-18 07:17:37 +01002572 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002573 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2574
2575 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002576 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2577 /*
2578 * Only stations associated to our AP and
2579 * associated VLANs
2580 */
2581 if (sta->sdata->bss != &sdata->u.ap)
2582 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002583
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002584 /* This station doesn't support MIMO - skip it */
2585 if (sta_info_tx_streams(sta) == 1)
2586 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002587
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002588 /*
2589 * Don't wake up a STA just to send the action frame
2590 * unless we are getting more restrictive.
2591 */
2592 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2593 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2594 smps_mode)) {
2595 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2596 sta->sta.addr);
2597 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002598 }
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002599
2600 /*
2601 * If the STA is not authorized, wait until it gets
2602 * authorized and the action frame will be sent then.
2603 */
2604 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2605 continue;
2606
2607 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2608 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2609 sdata->vif.bss_conf.bssid);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002610 }
2611 mutex_unlock(&sdata->local->sta_mtx);
2612
2613 sdata->smps_mode = smps_mode;
2614 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2615
2616 return 0;
2617}
2618
2619int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2620 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002621{
2622 const u8 *ap;
2623 enum ieee80211_smps_mode old_req;
2624 int err;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002625 struct sta_info *sta;
2626 bool tdls_peer_found = false;
Johannes Berg0f782312009-12-01 13:37:02 +01002627
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002628 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002629
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002630 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2631 return -EINVAL;
2632
Johannes Berg0f782312009-12-01 13:37:02 +01002633 old_req = sdata->u.mgd.req_smps;
2634 sdata->u.mgd.req_smps = smps_mode;
2635
2636 if (old_req == smps_mode &&
2637 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2638 return 0;
2639
2640 /*
2641 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002642 * association, there's no need to do anything, just store
2643 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002644 */
2645 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002646 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002647 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002648
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002649 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002650
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002651 rcu_read_lock();
2652 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2653 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2654 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2655 continue;
2656
2657 tdls_peer_found = true;
2658 break;
2659 }
2660 rcu_read_unlock();
2661
Johannes Berg0f782312009-12-01 13:37:02 +01002662 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002663 if (tdls_peer_found || !sdata->u.mgd.powersave)
Johannes Berg0f782312009-12-01 13:37:02 +01002664 smps_mode = IEEE80211_SMPS_OFF;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002665 else
2666 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg0f782312009-12-01 13:37:02 +01002667 }
2668
2669 /* send SM PS frame to AP */
2670 err = ieee80211_send_smps_action(sdata, smps_mode,
2671 ap, ap);
2672 if (err)
2673 sdata->u.mgd.req_smps = old_req;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002674 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2675 ieee80211_teardown_tdls_peers(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002676
2677 return err;
2678}
2679
Johannes Bergbc92afd2009-07-01 21:26:57 +02002680static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2681 bool enabled, int timeout)
2682{
2683 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2684 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002685
Bob Copeland2d3db212013-10-29 18:11:59 -04002686 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002687 return -EOPNOTSUPP;
2688
Johannes Berg30686bf2015-06-02 21:39:54 +02002689 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002690 return -EOPNOTSUPP;
2691
2692 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002693 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002694 return 0;
2695
2696 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002697 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002698
Johannes Berg0f782312009-12-01 13:37:02 +01002699 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002700 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002701 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002702 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002703
Johannes Berg30686bf2015-06-02 21:39:54 +02002704 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002705 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2706
Johannes Berg4a733ef2015-10-14 18:02:43 +02002707 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03002708 ieee80211_recalc_ps_vif(sdata);
Felix Fietkau1d870162018-02-23 10:06:05 +01002709 ieee80211_check_fast_rx_iface(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002710
2711 return 0;
2712}
2713
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002714static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2715 struct net_device *dev,
2716 s32 rssi_thold, u32 rssi_hyst)
2717{
2718 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002719 struct ieee80211_vif *vif = &sdata->vif;
2720 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2721
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002722 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2723 rssi_hyst == bss_conf->cqm_rssi_hyst)
2724 return 0;
2725
Johannes Bergef9be102015-08-28 10:44:20 +02002726 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2727 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2728 return -EOPNOTSUPP;
2729
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002730 bss_conf->cqm_rssi_thold = rssi_thold;
2731 bss_conf->cqm_rssi_hyst = rssi_hyst;
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01002732 bss_conf->cqm_rssi_low = 0;
2733 bss_conf->cqm_rssi_high = 0;
2734 sdata->u.mgd.last_cqm_event_signal = 0;
2735
2736 /* tell the driver upon association, unless already associated */
2737 if (sdata->u.mgd.associated &&
2738 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2739 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2740
2741 return 0;
2742}
2743
2744static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2745 struct net_device *dev,
2746 s32 rssi_low, s32 rssi_high)
2747{
2748 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2749 struct ieee80211_vif *vif = &sdata->vif;
2750 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2751
2752 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2753 return -EOPNOTSUPP;
2754
2755 bss_conf->cqm_rssi_low = rssi_low;
2756 bss_conf->cqm_rssi_high = rssi_high;
2757 bss_conf->cqm_rssi_thold = 0;
2758 bss_conf->cqm_rssi_hyst = 0;
Sara Sharonbabc305e22015-09-21 15:47:40 +03002759 sdata->u.mgd.last_cqm_event_signal = 0;
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002760
2761 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002762 if (sdata->u.mgd.associated &&
2763 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002764 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2765
2766 return 0;
2767}
2768
Johannes Berg99303802009-07-01 21:26:59 +02002769static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2770 struct net_device *dev,
2771 const u8 *addr,
2772 const struct cfg80211_bitrate_mask *mask)
2773{
2774 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302776 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002777
Eliad Peller554a43d2012-06-12 12:41:15 +03002778 if (!ieee80211_sdata_running(sdata))
2779 return -ENETDOWN;
2780
Johannes Berge8e4f522017-03-08 11:12:10 +01002781 /*
2782 * If active validate the setting and reject it if it doesn't leave
2783 * at least one basic rate usable, since we really have to be able
2784 * to send something, and if we're an AP we have to be able to do
2785 * so at a basic rate so that all clients can receive it.
2786 */
2787 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
2788 sdata->vif.bss_conf.chandef.chan) {
2789 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2790 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
2791
2792 if (!(mask->control[band].legacy & basic_rates))
2793 return -EINVAL;
2794 }
2795
Johannes Berge5f5ce32017-10-18 09:36:51 +02002796 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2797 ret = drv_set_bitrate_mask(local, sdata, mask);
2798 if (ret)
2799 return ret;
2800 }
2801
Johannes Berg57fbcce2016-04-12 15:56:15 +02002802 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002803 struct ieee80211_supported_band *sband = wiphy->bands[i];
2804 int j;
2805
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002806 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002807 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2808 sizeof(mask->control[i].ht_mcs));
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002809 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2810 mask->control[i].vht_mcs,
2811 sizeof(mask->control[i].vht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002812
2813 sdata->rc_has_mcs_mask[i] = false;
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002814 sdata->rc_has_vht_mcs_mask[i] = false;
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002815 if (!sband)
2816 continue;
2817
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002818 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
Johannes Berg2df1b132015-08-21 14:07:13 +02002819 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002820 sdata->rc_has_mcs_mask[i] = true;
2821 break;
Johannes Berg2df1b132015-08-21 14:07:13 +02002822 }
2823 }
2824
2825 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2826 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2827 sdata->rc_has_vht_mcs_mask[i] = true;
2828 break;
2829 }
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002830 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002831 }
Johannes Berg99303802009-07-01 21:26:59 +02002832
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002833 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002834}
2835
Simon Wunderlich164eb022013-02-08 18:16:20 +01002836static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2837 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002838 struct cfg80211_chan_def *chandef,
2839 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002840{
2841 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2842 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002843 int err;
2844
Johannes Berg34a37402013-12-18 09:43:33 +01002845 mutex_lock(&local->mtx);
2846 if (!list_empty(&local->roc_list) || local->scanning) {
2847 err = -EBUSY;
2848 goto out_unlock;
2849 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002850
2851 /* whatever, but channel contexts should not complain about that one */
2852 sdata->smps_mode = IEEE80211_SMPS_OFF;
2853 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002854
Simon Wunderlich164eb022013-02-08 18:16:20 +01002855 err = ieee80211_vif_use_channel(sdata, chandef,
2856 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002857 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002858 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002859
Simon Wunderlich164eb022013-02-08 18:16:20 +01002860 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002861 &sdata->dfs_cac_timer_work,
2862 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002863
Johannes Berg34a37402013-12-18 09:43:33 +01002864 out_unlock:
2865 mutex_unlock(&local->mtx);
2866 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002867}
2868
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002869static struct cfg80211_beacon_data *
2870cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2871{
2872 struct cfg80211_beacon_data *new_beacon;
2873 u8 *pos;
2874 int len;
2875
2876 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2877 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2878 beacon->probe_resp_len;
2879
2880 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2881 if (!new_beacon)
2882 return NULL;
2883
2884 pos = (u8 *)(new_beacon + 1);
2885 if (beacon->head_len) {
2886 new_beacon->head_len = beacon->head_len;
2887 new_beacon->head = pos;
2888 memcpy(pos, beacon->head, beacon->head_len);
2889 pos += beacon->head_len;
2890 }
2891 if (beacon->tail_len) {
2892 new_beacon->tail_len = beacon->tail_len;
2893 new_beacon->tail = pos;
2894 memcpy(pos, beacon->tail, beacon->tail_len);
2895 pos += beacon->tail_len;
2896 }
2897 if (beacon->beacon_ies_len) {
2898 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2899 new_beacon->beacon_ies = pos;
2900 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2901 pos += beacon->beacon_ies_len;
2902 }
2903 if (beacon->proberesp_ies_len) {
2904 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2905 new_beacon->proberesp_ies = pos;
2906 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2907 pos += beacon->proberesp_ies_len;
2908 }
2909 if (beacon->assocresp_ies_len) {
2910 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2911 new_beacon->assocresp_ies = pos;
2912 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2913 pos += beacon->assocresp_ies_len;
2914 }
2915 if (beacon->probe_resp_len) {
2916 new_beacon->probe_resp_len = beacon->probe_resp_len;
Arnd Bergmannbee92d02018-02-02 16:31:23 +01002917 new_beacon->probe_resp = pos;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002918 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2919 pos += beacon->probe_resp_len;
2920 }
2921
2922 return new_beacon;
2923}
2924
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002925void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002926{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002927 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2928
2929 ieee80211_queue_work(&sdata->local->hw,
2930 &sdata->csa_finalize_work);
2931}
2932EXPORT_SYMBOL(ieee80211_csa_finish);
2933
Michal Kazior66199502014-04-09 15:11:00 +02002934static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2935 u32 *changed)
2936{
2937 int err;
2938
2939 switch (sdata->vif.type) {
2940 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002941 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2942 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002943 kfree(sdata->u.ap.next_beacon);
2944 sdata->u.ap.next_beacon = NULL;
2945
2946 if (err < 0)
2947 return err;
2948 *changed |= err;
2949 break;
2950 case NL80211_IFTYPE_ADHOC:
2951 err = ieee80211_ibss_finish_csa(sdata);
2952 if (err < 0)
2953 return err;
2954 *changed |= err;
2955 break;
2956#ifdef CONFIG_MAC80211_MESH
2957 case NL80211_IFTYPE_MESH_POINT:
2958 err = ieee80211_mesh_finish_csa(sdata);
2959 if (err < 0)
2960 return err;
2961 *changed |= err;
2962 break;
2963#endif
2964 default:
2965 WARN_ON(1);
2966 return -EINVAL;
2967 }
2968
2969 return 0;
2970}
2971
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002972static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002973{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002974 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002975 u32 changed = 0;
2976 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002977
Michal Kaziordbd72852014-01-29 07:56:21 +01002978 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002979 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002980 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002981
Michal Kazior03078de2014-06-25 12:35:08 +02002982 /*
2983 * using reservation isn't immediate as it may be deferred until later
2984 * with multi-vif. once reservation is complete it will re-schedule the
2985 * work with no reserved_chanctx so verify chandef to check if it
2986 * completed successfully
2987 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002988
Michal Kazior03078de2014-06-25 12:35:08 +02002989 if (sdata->reserved_chanctx) {
2990 /*
2991 * with multi-vif csa driver may call ieee80211_csa_finish()
2992 * many times while waiting for other interfaces to use their
2993 * reservations
2994 */
2995 if (sdata->reserved_ready)
2996 return 0;
2997
Fabian Frederick408b18a2014-10-09 20:36:22 +02002998 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002999 }
3000
Michal Kazior03078de2014-06-25 12:35:08 +02003001 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3002 &sdata->csa_chandef))
3003 return -EINVAL;
3004
Simon Wunderliche487eae2013-11-21 18:19:51 +01003005 sdata->vif.csa_active = false;
Michal Kazior97518af12014-01-29 07:56:18 +01003006
Michal Kazior66199502014-04-09 15:11:00 +02003007 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3008 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003009 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003010
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003011 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02003012
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003013 if (sdata->csa_block_tx) {
3014 ieee80211_wake_vif_queues(local, sdata,
3015 IEEE80211_QUEUE_STOP_REASON_CSA);
3016 sdata->csa_block_tx = false;
3017 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003018
Luciano Coelhof1d65582014-10-08 09:48:38 +03003019 err = drv_post_channel_switch(sdata);
3020 if (err)
3021 return err;
3022
3023 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3024
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003025 return 0;
3026}
3027
3028static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3029{
3030 if (__ieee80211_csa_finalize(sdata)) {
3031 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3032 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3033 GFP_KERNEL);
3034 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003035}
3036
3037void ieee80211_csa_finalize_work(struct work_struct *work)
3038{
3039 struct ieee80211_sub_if_data *sdata =
3040 container_of(work, struct ieee80211_sub_if_data,
3041 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02003042 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003043
3044 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003045 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003046 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003047
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003048 /* AP might have been stopped while waiting for the lock. */
3049 if (!sdata->vif.csa_active)
3050 goto unlock;
3051
3052 if (!ieee80211_sdata_running(sdata))
3053 goto unlock;
3054
3055 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003056
3057unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02003058 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003059 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003060 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003061}
3062
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003063static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3064 struct cfg80211_csa_settings *params,
3065 u32 *changed)
3066{
Michal Kazioraf296bd2014-06-05 14:21:36 +02003067 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003068 int err;
3069
3070 switch (sdata->vif.type) {
3071 case NL80211_IFTYPE_AP:
3072 sdata->u.ap.next_beacon =
3073 cfg80211_beacon_dup(&params->beacon_after);
3074 if (!sdata->u.ap.next_beacon)
3075 return -ENOMEM;
3076
3077 /*
3078 * With a count of 0, we don't have to wait for any
3079 * TBTT before switching, so complete the CSA
3080 * immediately. In theory, with a count == 1 we
3081 * should delay the switch until just before the next
3082 * TBTT, but that would complicate things so we switch
3083 * immediately too. If we would delay the switch
3084 * until the next TBTT, we would have to set the probe
3085 * response here.
3086 *
3087 * TODO: A channel switch with count <= 1 without
3088 * sending a CSA action frame is kind of useless,
3089 * because the clients won't know we're changing
3090 * channels. The action frame must be implemented
3091 * either here or in the userspace.
3092 */
3093 if (params->count <= 1)
3094 break;
3095
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003096 if ((params->n_counter_offsets_beacon >
3097 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3098 (params->n_counter_offsets_presp >
3099 IEEE80211_MAX_CSA_COUNTERS_NUM))
3100 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003101
Michal Kazioraf296bd2014-06-05 14:21:36 +02003102 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3103 csa.counter_offsets_presp = params->counter_offsets_presp;
3104 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3105 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3106 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003107
Michal Kazioraf296bd2014-06-05 14:21:36 +02003108 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003109 if (err < 0) {
3110 kfree(sdata->u.ap.next_beacon);
3111 return err;
3112 }
3113 *changed |= err;
3114
3115 break;
3116 case NL80211_IFTYPE_ADHOC:
3117 if (!sdata->vif.bss_conf.ibss_joined)
3118 return -EINVAL;
3119
3120 if (params->chandef.width != sdata->u.ibss.chandef.width)
3121 return -EINVAL;
3122
3123 switch (params->chandef.width) {
3124 case NL80211_CHAN_WIDTH_40:
3125 if (cfg80211_get_chandef_type(&params->chandef) !=
3126 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3127 return -EINVAL;
3128 case NL80211_CHAN_WIDTH_5:
3129 case NL80211_CHAN_WIDTH_10:
3130 case NL80211_CHAN_WIDTH_20_NOHT:
3131 case NL80211_CHAN_WIDTH_20:
3132 break;
3133 default:
3134 return -EINVAL;
3135 }
3136
3137 /* changes into another band are not supported */
3138 if (sdata->u.ibss.chandef.chan->band !=
3139 params->chandef.chan->band)
3140 return -EINVAL;
3141
3142 /* see comments in the NL80211_IFTYPE_AP block */
3143 if (params->count > 1) {
3144 err = ieee80211_ibss_csa_beacon(sdata, params);
3145 if (err < 0)
3146 return err;
3147 *changed |= err;
3148 }
3149
3150 ieee80211_send_action_csa(sdata, params);
3151
3152 break;
3153#ifdef CONFIG_MAC80211_MESH
3154 case NL80211_IFTYPE_MESH_POINT: {
3155 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3156
3157 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3158 return -EINVAL;
3159
3160 /* changes into another band are not supported */
3161 if (sdata->vif.bss_conf.chandef.chan->band !=
3162 params->chandef.chan->band)
3163 return -EINVAL;
3164
3165 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3166 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3167 if (!ifmsh->pre_value)
3168 ifmsh->pre_value = 1;
3169 else
3170 ifmsh->pre_value++;
3171 }
3172
3173 /* see comments in the NL80211_IFTYPE_AP block */
3174 if (params->count > 1) {
3175 err = ieee80211_mesh_csa_beacon(sdata, params);
3176 if (err < 0) {
3177 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3178 return err;
3179 }
3180 *changed |= err;
3181 }
3182
3183 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3184 ieee80211_send_action_csa(sdata, params);
3185
3186 break;
3187 }
3188#endif
3189 default:
3190 return -EOPNOTSUPP;
3191 }
3192
3193 return 0;
3194}
3195
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003196static int
3197__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3198 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003199{
3200 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3201 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003202 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003203 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003204 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003205 u32 changed = 0;
3206 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003207
Michal Kaziordbd72852014-01-29 07:56:21 +01003208 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003209 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003210
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003211 if (!list_empty(&local->roc_list) || local->scanning)
3212 return -EBUSY;
3213
3214 if (sdata->wdev.cac_started)
3215 return -EBUSY;
3216
3217 if (cfg80211_chandef_identical(&params->chandef,
3218 &sdata->vif.bss_conf.chandef))
3219 return -EINVAL;
3220
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003221 /* don't allow another channel switch if one is already active. */
3222 if (sdata->vif.csa_active)
3223 return -EBUSY;
3224
Michal Kazior03078de2014-06-25 12:35:08 +02003225 mutex_lock(&local->chanctx_mtx);
3226 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3227 lockdep_is_held(&local->chanctx_mtx));
3228 if (!conf) {
3229 err = -EBUSY;
3230 goto out;
3231 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003232
Michal Kazior03078de2014-06-25 12:35:08 +02003233 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
Michal Kazior03078de2014-06-25 12:35:08 +02003234
Luciano Coelho000baa52014-11-07 15:28:33 +02003235 ch_switch.timestamp = 0;
3236 ch_switch.device_timestamp = 0;
3237 ch_switch.block_tx = params->block_tx;
3238 ch_switch.chandef = params->chandef;
3239 ch_switch.count = params->count;
3240
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003241 err = drv_pre_channel_switch(sdata, &ch_switch);
3242 if (err)
3243 goto out;
3244
Michal Kazior03078de2014-06-25 12:35:08 +02003245 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3246 chanctx->mode,
3247 params->radar_required);
3248 if (err)
3249 goto out;
3250
3251 /* if reservation is invalid then this will fail */
3252 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3253 if (err) {
3254 ieee80211_vif_unreserve_chanctx(sdata);
3255 goto out;
3256 }
3257
3258 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3259 if (err) {
3260 ieee80211_vif_unreserve_chanctx(sdata);
3261 goto out;
3262 }
3263
Luciano Coelho33787fc2013-11-11 20:34:54 +02003264 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003265 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003266 sdata->vif.csa_active = true;
3267
Michal Kazior59af6922014-04-09 15:10:59 +02003268 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003269 ieee80211_stop_vif_queues(local, sdata,
3270 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003271
Luciano Coelho2f457292014-11-07 14:31:36 +02003272 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3273 params->count);
3274
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003275 if (changed) {
3276 ieee80211_bss_info_change_notify(sdata, changed);
3277 drv_channel_switch_beacon(sdata, &params->chandef);
3278 } else {
3279 /* if the beacon didn't change, we can finalize immediately */
3280 ieee80211_csa_finalize(sdata);
3281 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003282
Michal Kazior03078de2014-06-25 12:35:08 +02003283out:
3284 mutex_unlock(&local->chanctx_mtx);
3285 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003286}
3287
Michal Kazior59af6922014-04-09 15:10:59 +02003288int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3289 struct cfg80211_csa_settings *params)
3290{
3291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3292 struct ieee80211_local *local = sdata->local;
3293 int err;
3294
3295 mutex_lock(&local->mtx);
3296 err = __ieee80211_channel_switch(wiphy, dev, params);
3297 mutex_unlock(&local->mtx);
3298
3299 return err;
3300}
3301
Johannes Berga2fcfccb2015-11-23 17:18:35 +01003302u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3303{
3304 lockdep_assert_held(&local->mtx);
3305
3306 local->roc_cookie_counter++;
3307
3308 /* wow, you wrapped 64 bits ... more likely a bug */
3309 if (WARN_ON(local->roc_cookie_counter == 0))
3310 local->roc_cookie_counter++;
3311
3312 return local->roc_cookie_counter;
3313}
3314
Johannes Berg5ee00db2015-11-24 14:25:49 +01003315int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3316 u64 *cookie, gfp_t gfp)
Johannes Berg3b79af92015-06-01 23:14:59 +02003317{
3318 unsigned long spin_flags;
3319 struct sk_buff *ack_skb;
3320 int id;
3321
3322 ack_skb = skb_copy(skb, gfp);
3323 if (!ack_skb)
Johannes Berg5ee00db2015-11-24 14:25:49 +01003324 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003325
3326 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3327 id = idr_alloc(&local->ack_status_frames, ack_skb,
3328 1, 0x10000, GFP_ATOMIC);
3329 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3330
3331 if (id < 0) {
3332 kfree_skb(ack_skb);
Johannes Berg5ee00db2015-11-24 14:25:49 +01003333 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003334 }
3335
3336 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3337
3338 *cookie = ieee80211_mgmt_tx_cookie(local);
3339 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3340
Johannes Berg5ee00db2015-11-24 14:25:49 +01003341 return 0;
Johannes Berg3b79af92015-06-01 23:14:59 +02003342}
3343
Johannes Berg7be50862010-10-13 12:06:24 +02003344static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003345 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003346 u16 frame_type, bool reg)
3347{
3348 struct ieee80211_local *local = wiphy_priv(wiphy);
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003349 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02003350
Will Hawkins6abe0562012-06-20 11:51:14 -04003351 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003352 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003353 if (reg) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003354 local->probe_req_reg++;
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003355 sdata->vif.probe_req_reg++;
3356 } else {
3357 if (local->probe_req_reg)
3358 local->probe_req_reg--;
3359
3360 if (sdata->vif.probe_req_reg)
3361 sdata->vif.probe_req_reg--;
3362 }
Johannes Berg7be50862010-10-13 12:06:24 +02003363
Felix Fietkau35f51492012-10-31 15:50:34 +01003364 if (!local->open_count)
3365 break;
3366
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003367 if (sdata->vif.probe_req_reg == 1)
3368 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3369 FIF_PROBE_REQ);
3370 else if (sdata->vif.probe_req_reg == 0)
3371 drv_config_iface_filter(local, sdata, 0,
3372 FIF_PROBE_REQ);
3373
3374 ieee80211_configure_filter(local);
Will Hawkins6abe0562012-06-20 11:51:14 -04003375 break;
3376 default:
3377 break;
3378 }
Johannes Berg7be50862010-10-13 12:06:24 +02003379}
3380
Bruno Randolf15d96752010-11-10 12:50:56 +09003381static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3382{
3383 struct ieee80211_local *local = wiphy_priv(wiphy);
3384
3385 if (local->started)
3386 return -EOPNOTSUPP;
3387
3388 return drv_set_antenna(local, tx_ant, rx_ant);
3389}
3390
3391static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3392{
3393 struct ieee80211_local *local = wiphy_priv(wiphy);
3394
3395 return drv_get_antenna(local, tx_ant, rx_ant);
3396}
3397
Johannes Bergc68f4b82011-07-05 16:35:41 +02003398static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3399 struct net_device *dev,
3400 struct cfg80211_gtk_rekey_data *data)
3401{
3402 struct ieee80211_local *local = wiphy_priv(wiphy);
3403 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3404
3405 if (!local->ops->set_rekey_data)
3406 return -EOPNOTSUPP;
3407
3408 drv_set_rekey_data(local, sdata, data);
3409
3410 return 0;
3411}
3412
Johannes Berg06500732011-11-04 11:18:16 +01003413static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3414 const u8 *peer, u64 *cookie)
3415{
3416 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3417 struct ieee80211_local *local = sdata->local;
3418 struct ieee80211_qos_hdr *nullfunc;
Johannes Berg5ee00db2015-11-24 14:25:49 +01003419 struct sk_buff *skb;
Johannes Berg06500732011-11-04 11:18:16 +01003420 int size = sizeof(*nullfunc);
3421 __le16 fc;
3422 bool qos;
3423 struct ieee80211_tx_info *info;
3424 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003425 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg57fbcce2016-04-12 15:56:15 +02003426 enum nl80211_band band;
Johannes Berg3b79af92015-06-01 23:14:59 +02003427 int ret;
3428
3429 /* the lock is needed to assign the cookie later */
3430 mutex_lock(&local->mtx);
Johannes Berg06500732011-11-04 11:18:16 +01003431
3432 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003433 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3434 if (WARN_ON(!chanctx_conf)) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003435 ret = -EINVAL;
3436 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003437 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003438 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003439 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003440 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003441 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003442 } else {
Johannes Berg3b79af92015-06-01 23:14:59 +02003443 ret = -ENOLINK;
3444 goto unlock;
Johannes Bergb4487c22011-11-11 20:22:30 +01003445 }
Johannes Berg06500732011-11-04 11:18:16 +01003446
3447 if (qos) {
3448 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3449 IEEE80211_STYPE_QOS_NULLFUNC |
3450 IEEE80211_FCTL_FROMDS);
3451 } else {
3452 size -= 2;
3453 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3454 IEEE80211_STYPE_NULLFUNC |
3455 IEEE80211_FCTL_FROMDS);
3456 }
3457
3458 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003459 if (!skb) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003460 ret = -ENOMEM;
3461 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003462 }
Johannes Berg06500732011-11-04 11:18:16 +01003463
3464 skb->dev = dev;
3465
3466 skb_reserve(skb, local->hw.extra_tx_headroom);
3467
Johannes Berg4df864c2017-06-16 14:29:21 +02003468 nullfunc = skb_put(skb, size);
Johannes Berg06500732011-11-04 11:18:16 +01003469 nullfunc->frame_control = fc;
3470 nullfunc->duration_id = 0;
3471 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3472 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3473 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3474 nullfunc->seq_ctrl = 0;
3475
3476 info = IEEE80211_SKB_CB(skb);
3477
3478 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3479 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003480 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003481
3482 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3483 skb->priority = 7;
3484 if (qos)
3485 nullfunc->qos_ctrl = cpu_to_le16(7);
3486
Johannes Berg5ee00db2015-11-24 14:25:49 +01003487 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3488 if (ret) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003489 kfree_skb(skb);
Johannes Berg3b79af92015-06-01 23:14:59 +02003490 goto unlock;
3491 }
3492
Johannes Berg06500732011-11-04 11:18:16 +01003493 local_bh_disable();
Johannes Bergb9771d42018-05-28 15:47:41 +02003494 ieee80211_xmit(sdata, sta, skb, 0);
Johannes Berg06500732011-11-04 11:18:16 +01003495 local_bh_enable();
3496
Johannes Berg3b79af92015-06-01 23:14:59 +02003497 ret = 0;
3498unlock:
3499 rcu_read_unlock();
3500 mutex_unlock(&local->mtx);
3501
3502 return ret;
Johannes Berg06500732011-11-04 11:18:16 +01003503}
3504
Johannes Berg683b6d32012-11-08 21:25:48 +01003505static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3506 struct wireless_dev *wdev,
3507 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003508{
Johannes Berg55de9082012-07-26 17:24:39 +02003509 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003510 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003511 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003512 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003513
Johannes Berg55de9082012-07-26 17:24:39 +02003514 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003515 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3516 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003517 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003518 ret = 0;
3519 } else if (local->open_count > 0 &&
3520 local->open_count == local->monitors &&
3521 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3522 if (local->use_chanctx)
3523 *chandef = local->monitor_chandef;
3524 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003525 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003526 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003527 }
3528 rcu_read_unlock();
3529
Johannes Berg683b6d32012-11-08 21:25:48 +01003530 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003531}
3532
Johannes Berg6d525632012-04-04 15:05:25 +02003533#ifdef CONFIG_PM
3534static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3535{
3536 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3537}
3538#endif
3539
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003540static int ieee80211_set_qos_map(struct wiphy *wiphy,
3541 struct net_device *dev,
3542 struct cfg80211_qos_map *qos_map)
3543{
3544 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3545 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3546
3547 if (qos_map) {
3548 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3549 if (!new_qos_map)
3550 return -ENOMEM;
3551 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3552 } else {
3553 /* A NULL qos_map was passed to disable QoS mapping */
3554 new_qos_map = NULL;
3555 }
3556
Johannes Berg194ff522013-12-30 23:12:37 +01003557 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003558 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3559 if (old_qos_map)
3560 kfree_rcu(old_qos_map, rcu_head);
3561
3562 return 0;
3563}
3564
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003565static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3566 struct net_device *dev,
3567 struct cfg80211_chan_def *chandef)
3568{
3569 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3570 int ret;
3571 u32 changed = 0;
3572
3573 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3574 if (ret == 0)
3575 ieee80211_bss_info_change_notify(sdata, changed);
3576
3577 return ret;
3578}
3579
Johannes Berg02219b32014-10-07 10:38:50 +03003580static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3581 u8 tsid, const u8 *peer, u8 up,
3582 u16 admitted_time)
3583{
3584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3585 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3586 int ac = ieee802_1d_to_ac[up];
3587
3588 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3589 return -EOPNOTSUPP;
3590
3591 if (!(sdata->wmm_acm & BIT(up)))
3592 return -EINVAL;
3593
3594 if (ifmgd->tx_tspec[ac].admitted_time)
3595 return -EBUSY;
3596
3597 if (admitted_time) {
3598 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3599 ifmgd->tx_tspec[ac].tsid = tsid;
3600 ifmgd->tx_tspec[ac].up = up;
3601 }
3602
3603 return 0;
3604}
3605
3606static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3607 u8 tsid, const u8 *peer)
3608{
3609 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3610 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3611 struct ieee80211_local *local = wiphy_priv(wiphy);
3612 int ac;
3613
3614 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3615 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3616
3617 /* skip unused entries */
3618 if (!tx_tspec->admitted_time)
3619 continue;
3620
3621 if (tx_tspec->tsid != tsid)
3622 continue;
3623
3624 /* due to this new packets will be reassigned to non-ACM ACs */
3625 tx_tspec->up = -1;
3626
3627 /* Make sure that all packets have been sent to avoid to
3628 * restore the QoS params on packets that are still on the
3629 * queues.
3630 */
3631 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003632 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003633
3634 /* restore the normal QoS parameters
3635 * (unconditionally to avoid races)
3636 */
3637 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3638 tx_tspec->downgraded = false;
3639 ieee80211_sta_handle_tspec_ac_params(sdata);
3640
3641 /* finally clear all the data */
3642 memset(tx_tspec, 0, sizeof(*tx_tspec));
3643
3644 return 0;
3645 }
3646
3647 return -ENOENT;
3648}
3649
Ayala Beker167e33f2016-09-20 17:31:20 +03003650void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3651 u8 inst_id,
3652 enum nl80211_nan_func_term_reason reason,
3653 gfp_t gfp)
3654{
3655 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3656 struct cfg80211_nan_func *func;
3657 u64 cookie;
3658
3659 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3660 return;
3661
3662 spin_lock_bh(&sdata->u.nan.func_lock);
3663
3664 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3665 if (WARN_ON(!func)) {
3666 spin_unlock_bh(&sdata->u.nan.func_lock);
3667 return;
3668 }
3669
3670 cookie = func->cookie;
3671 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3672
3673 spin_unlock_bh(&sdata->u.nan.func_lock);
3674
3675 cfg80211_free_nan_func(func);
3676
3677 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3678 reason, cookie, gfp);
3679}
3680EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3681
Ayala Beker92bc43b2016-09-20 17:31:21 +03003682void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3683 struct cfg80211_nan_match_params *match,
3684 gfp_t gfp)
3685{
3686 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3687 struct cfg80211_nan_func *func;
3688
3689 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3690 return;
3691
3692 spin_lock_bh(&sdata->u.nan.func_lock);
3693
3694 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3695 if (WARN_ON(!func)) {
3696 spin_unlock_bh(&sdata->u.nan.func_lock);
3697 return;
3698 }
3699 match->cookie = func->cookie;
3700
3701 spin_unlock_bh(&sdata->u.nan.func_lock);
3702
3703 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
3704}
3705EXPORT_SYMBOL(ieee80211_nan_func_match);
3706
Michael Braunebceec82016-11-22 11:52:18 +01003707static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
3708 struct net_device *dev,
3709 const bool enabled)
3710{
3711 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3712
3713 sdata->u.ap.multicast_to_unicast = enabled;
3714
3715 return 0;
3716}
3717
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02003718void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
3719 struct txq_info *txqi)
3720{
3721 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
3722 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
3723 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
3724 }
3725
3726 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
3727 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
3728 txqstats->backlog_packets = txqi->tin.backlog_packets;
3729 }
3730
3731 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
3732 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
3733 txqstats->flows = txqi->tin.flows;
3734 }
3735
3736 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
3737 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
3738 txqstats->drops = txqi->cstats.drop_count;
3739 }
3740
3741 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
3742 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
3743 txqstats->ecn_marks = txqi->cstats.ecn_mark;
3744 }
3745
3746 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
3747 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
3748 txqstats->overlimit = txqi->tin.overlimit;
3749 }
3750
3751 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
3752 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
3753 txqstats->collisions = txqi->tin.collisions;
3754 }
3755
3756 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
3757 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
3758 txqstats->tx_bytes = txqi->tin.tx_bytes;
3759 }
3760
3761 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
3762 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
3763 txqstats->tx_packets = txqi->tin.tx_packets;
3764 }
3765}
3766
3767static int ieee80211_get_txq_stats(struct wiphy *wiphy,
3768 struct wireless_dev *wdev,
3769 struct cfg80211_txq_stats *txqstats)
3770{
3771 struct ieee80211_local *local = wiphy_priv(wiphy);
3772 struct ieee80211_sub_if_data *sdata;
3773 int ret = 0;
3774
3775 if (!local->ops->wake_tx_queue)
3776 return 1;
3777
3778 spin_lock_bh(&local->fq.lock);
3779 rcu_read_lock();
3780
3781 if (wdev) {
3782 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3783 if (!sdata->vif.txq) {
3784 ret = 1;
3785 goto out;
3786 }
3787 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
3788 } else {
3789 /* phy stats */
3790 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
3791 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
3792 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
3793 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
3794 BIT(NL80211_TXQ_STATS_COLLISIONS) |
3795 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
3796 txqstats->backlog_packets = local->fq.backlog;
3797 txqstats->backlog_bytes = local->fq.memory_usage;
3798 txqstats->overlimit = local->fq.overlimit;
3799 txqstats->overmemory = local->fq.overmemory;
3800 txqstats->collisions = local->fq.collisions;
3801 txqstats->max_flows = local->fq.flows_cnt;
3802 }
3803
3804out:
3805 rcu_read_unlock();
3806 spin_unlock_bh(&local->fq.lock);
3807
3808 return ret;
3809}
3810
Johannes Berg8a47cea2014-01-20 23:55:44 +01003811const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003812 .add_virtual_intf = ieee80211_add_iface,
3813 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003814 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003815 .start_p2p_device = ieee80211_start_p2p_device,
3816 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003817 .add_key = ieee80211_add_key,
3818 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003819 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003820 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003821 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003822 .start_ap = ieee80211_start_ap,
3823 .change_beacon = ieee80211_change_beacon,
3824 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003825 .add_station = ieee80211_add_station,
3826 .del_station = ieee80211_del_station,
3827 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003828 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003829 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003830 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003831#ifdef CONFIG_MAC80211_MESH
3832 .add_mpath = ieee80211_add_mpath,
3833 .del_mpath = ieee80211_del_mpath,
3834 .change_mpath = ieee80211_change_mpath,
3835 .get_mpath = ieee80211_get_mpath,
3836 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003837 .get_mpp = ieee80211_get_mpp,
3838 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003839 .update_mesh_config = ieee80211_update_mesh_config,
3840 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003841 .join_mesh = ieee80211_join_mesh,
3842 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003843#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003844 .join_ocb = ieee80211_join_ocb,
3845 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003846 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003847 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003848 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003849 .suspend = ieee80211_suspend,
3850 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003851 .scan = ieee80211_scan,
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05303852 .abort_scan = ieee80211_abort_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003853 .sched_scan_start = ieee80211_sched_scan_start,
3854 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003855 .auth = ieee80211_auth,
3856 .assoc = ieee80211_assoc,
3857 .deauth = ieee80211_deauth,
3858 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003859 .join_ibss = ieee80211_join_ibss,
3860 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003861 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003862 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003863 .set_tx_power = ieee80211_set_tx_power,
3864 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003865 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003866 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003867 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003868 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003869 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003870 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003871 .remain_on_channel = ieee80211_remain_on_channel,
3872 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02003873 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003874 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003875 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003876 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003877 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003878 .set_antenna = ieee80211_set_antenna,
3879 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003880 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003881 .tdls_oper = ieee80211_tdls_oper,
3882 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02003883 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3884 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01003885 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003886 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003887#ifdef CONFIG_PM
3888 .set_wakeup = ieee80211_set_wakeup,
3889#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003890 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003891 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003892 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003893 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003894 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003895 .add_tx_ts = ieee80211_add_tx_ts,
3896 .del_tx_ts = ieee80211_del_tx_ts,
Ayala Beker708d50e2016-09-20 17:31:14 +03003897 .start_nan = ieee80211_start_nan,
3898 .stop_nan = ieee80211_stop_nan,
Ayala Beker5953ff62016-09-20 17:31:19 +03003899 .nan_change_conf = ieee80211_nan_change_conf,
Ayala Beker167e33f2016-09-20 17:31:20 +03003900 .add_nan_func = ieee80211_add_nan_func,
3901 .del_nan_func = ieee80211_del_nan_func,
Michael Braunebceec82016-11-22 11:52:18 +01003902 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
Denis Kenzior91180642018-03-26 12:52:50 -05003903 .tx_control_port = ieee80211_tx_control_port,
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02003904 .get_txq_stats = ieee80211_get_txq_stats,
Jiri Bencf0706e82007-05-05 11:45:53 -07003905};