blob: 87a208089caf756efdad67db71c08ad8c29904f7 [file] [log] [blame]
Thomas Gleixner28c61a62019-06-01 10:08:46 +02001// SPDX-License-Identifier: GPL-2.0-only
Jiri Bencf0706e82007-05-05 11:45:53 -07002/*
3 * mac80211 configuration hooks for cfg80211
4 *
Jouni Malinen026331c2010-02-15 12:53:10 +02005 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergb2eb0ee2015-06-01 22:54:13 +02006 * Copyright 2013-2015 Intel Mobile Communications GmbH
Johannes Berge8e4f522017-03-08 11:12:10 +01007 * Copyright (C) 2015-2017 Intel Deutschland GmbH
Nathan Errera6d501762021-11-29 15:32:38 +02008 * Copyright (C) 2018-2021 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -07009 */
10
Johannes Berge8cbb4c2007-12-19 02:03:30 +010011#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070012#include <linux/nl80211.h>
13#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070015#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010016#include <linux/rcupdate.h>
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +020017#include <linux/fips.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 */
Johannes Berg6dd236032021-11-12 13:51:44 +010083 monitor_sdata = wiphy_dereference(local->hw.wiphy,
84 local->monitor_sdata);
Johannes Berg65f1d602017-04-12 12:36:31 +020085
86 if (!monitor_sdata &&
87 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
88 return -EOPNOTSUPP;
89
90 /* apply all changes now - no failures allowed */
91
92 if (monitor_sdata)
93 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
94
95 if (params->flags) {
96 if (ieee80211_sdata_running(sdata)) {
97 ieee80211_adjust_monitor_flags(sdata, -1);
98 sdata->u.mntr.flags = params->flags;
99 ieee80211_adjust_monitor_flags(sdata, 1);
100
101 ieee80211_configure_filter(local);
102 } else {
103 /*
104 * Because the interface is down, ieee80211_do_stop
105 * and ieee80211_do_open take care of "everything"
106 * mentioned in the comment above.
107 */
108 sdata->u.mntr.flags = params->flags;
109 }
110 }
Johannes Berg8c5e6882017-04-12 10:46:13 +0200111
112 return 0;
113}
114
John Crispin17196422021-09-15 19:54:35 -0700115static int ieee80211_set_ap_mbssid_options(struct ieee80211_sub_if_data *sdata,
116 struct cfg80211_mbssid_config params)
117{
118 struct ieee80211_sub_if_data *tx_sdata;
119
120 sdata->vif.mbssid_tx_vif = NULL;
121 sdata->vif.bss_conf.bssid_index = 0;
122 sdata->vif.bss_conf.nontransmitted = false;
123 sdata->vif.bss_conf.ema_ap = false;
124
125 if (sdata->vif.type != NL80211_IFTYPE_AP || !params.tx_wdev)
126 return -EINVAL;
127
128 tx_sdata = IEEE80211_WDEV_TO_SUB_IF(params.tx_wdev);
129 if (!tx_sdata)
130 return -EINVAL;
131
132 if (tx_sdata == sdata) {
133 sdata->vif.mbssid_tx_vif = &sdata->vif;
134 } else {
135 sdata->vif.mbssid_tx_vif = &tx_sdata->vif;
136 sdata->vif.bss_conf.nontransmitted = true;
137 sdata->vif.bss_conf.bssid_index = params.index;
138 }
139 if (params.ema)
140 sdata->vif.bss_conf.ema_ap = true;
141
142 return 0;
143}
144
Johannes Berg552bff02012-09-19 09:26:06 +0200145static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
146 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100147 unsigned char name_assign_type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200148 enum nl80211_iftype type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200149 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -0700150{
151 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +0200152 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +0100153 struct ieee80211_sub_if_data *sdata;
154 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700155
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100156 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100157 if (err)
158 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +0100159
Johannes Berg8c5e6882017-04-12 10:46:13 +0200160 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
161
162 if (type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200163 err = ieee80211_set_mon_options(sdata, params);
Johannes Berg8c5e6882017-04-12 10:46:13 +0200164 if (err) {
165 ieee80211_if_remove(sdata);
166 return NULL;
167 }
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100168 }
169
Johannes Berg84efbb82012-06-16 00:00:26 +0200170 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -0700171}
172
Johannes Berg84efbb82012-06-16 00:00:26 +0200173static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -0700174{
Johannes Berg84efbb82012-06-16 00:00:26 +0200175 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -0700176
Johannes Berg75636522008-07-09 14:40:35 +0200177 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700178}
179
Johannes Berge36d56b2009-06-09 21:04:43 +0200180static int ieee80211_change_iface(struct wiphy *wiphy,
181 struct net_device *dev,
Johannes Berg818a9862017-04-12 11:23:28 +0200182 enum nl80211_iftype type,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100183 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +0200184{
Johannes Berg9607e6b662009-12-23 13:15:31 +0100185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Felix Fietkaua5d3cbd2021-07-02 07:01:11 +0200186 struct ieee80211_local *local = sdata->local;
187 struct sta_info *sta;
Johannes Bergf3947e22008-07-09 14:40:36 +0200188 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200189
Johannes Berg05c914f2008-09-11 00:01:58 +0200190 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +0200191 if (ret)
192 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200193
Johannes Berg6f527282018-08-31 11:31:05 +0300194 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000195 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300196 ieee80211_check_fast_rx_iface(sdata);
Johannes Berg6f527282018-08-31 11:31:05 +0300197 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
Felix Fietkaua5d3cbd2021-07-02 07:01:11 +0200198 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
199
200 if (params->use_4addr == ifmgd->use_4addr)
201 return 0;
202
Johannes Berg9bc383d2009-11-19 11:55:19 +0100203 sdata->u.mgd.use_4addr = params->use_4addr;
Felix Fietkaua5d3cbd2021-07-02 07:01:11 +0200204 if (!ifmgd->associated)
205 return 0;
206
207 mutex_lock(&local->sta_mtx);
208 sta = sta_info_get(sdata, ifmgd->bssid);
209 if (sta)
210 drv_sta_set_4addr(local, sdata, &sta->sta,
211 params->use_4addr);
212 mutex_unlock(&local->sta_mtx);
213
214 if (params->use_4addr)
215 ieee80211_send_4addr_nullfunc(local, sdata);
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300216 }
Johannes Berg9bc383d2009-11-19 11:55:19 +0100217
Aviya Erenfeld42bd20d2016-08-29 23:25:16 +0300218 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200219 ret = ieee80211_set_mon_options(sdata, params);
220 if (ret)
221 return ret;
Christian Lamparter85416a42010-10-02 13:17:07 +0200222 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200223
Johannes Berg42613db2007-09-28 21:52:27 +0200224 return 0;
225}
226
Johannes Bergf142c6b2012-06-18 20:07:15 +0200227static int ieee80211_start_p2p_device(struct wiphy *wiphy,
228 struct wireless_dev *wdev)
229{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200230 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
231 int ret;
232
233 mutex_lock(&sdata->local->chanctx_mtx);
234 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
235 mutex_unlock(&sdata->local->chanctx_mtx);
236 if (ret < 0)
237 return ret;
238
Johannes Bergf142c6b2012-06-18 20:07:15 +0200239 return ieee80211_do_open(wdev, true);
240}
241
242static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
243 struct wireless_dev *wdev)
244{
245 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
246}
247
Ayala Beker708d50e2016-09-20 17:31:14 +0300248static int ieee80211_start_nan(struct wiphy *wiphy,
249 struct wireless_dev *wdev,
250 struct cfg80211_nan_conf *conf)
251{
252 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
253 int ret;
254
255 mutex_lock(&sdata->local->chanctx_mtx);
256 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
257 mutex_unlock(&sdata->local->chanctx_mtx);
258 if (ret < 0)
259 return ret;
260
261 ret = ieee80211_do_open(wdev, true);
262 if (ret)
263 return ret;
264
265 ret = drv_start_nan(sdata->local, sdata, conf);
266 if (ret)
267 ieee80211_sdata_stop(sdata);
268
Ayala Beker167e33f2016-09-20 17:31:20 +0300269 sdata->u.nan.conf = *conf;
270
Ayala Beker708d50e2016-09-20 17:31:14 +0300271 return ret;
272}
273
274static void ieee80211_stop_nan(struct wiphy *wiphy,
275 struct wireless_dev *wdev)
276{
277 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
278
279 drv_stop_nan(sdata->local, sdata);
280 ieee80211_sdata_stop(sdata);
281}
282
Ayala Beker5953ff62016-09-20 17:31:19 +0300283static int ieee80211_nan_change_conf(struct wiphy *wiphy,
284 struct wireless_dev *wdev,
285 struct cfg80211_nan_conf *conf,
286 u32 changes)
287{
288 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
289 struct cfg80211_nan_conf new_conf;
290 int ret = 0;
291
292 if (sdata->vif.type != NL80211_IFTYPE_NAN)
293 return -EOPNOTSUPP;
294
295 if (!ieee80211_sdata_running(sdata))
296 return -ENETDOWN;
297
298 new_conf = sdata->u.nan.conf;
299
300 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
301 new_conf.master_pref = conf->master_pref;
302
Luca Coelho85859892017-02-08 15:00:34 +0200303 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
304 new_conf.bands = conf->bands;
Ayala Beker5953ff62016-09-20 17:31:19 +0300305
306 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
307 if (!ret)
308 sdata->u.nan.conf = new_conf;
309
310 return ret;
311}
312
Ayala Beker167e33f2016-09-20 17:31:20 +0300313static int ieee80211_add_nan_func(struct wiphy *wiphy,
314 struct wireless_dev *wdev,
315 struct cfg80211_nan_func *nan_func)
316{
317 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
318 int ret;
319
320 if (sdata->vif.type != NL80211_IFTYPE_NAN)
321 return -EOPNOTSUPP;
322
323 if (!ieee80211_sdata_running(sdata))
324 return -ENETDOWN;
325
326 spin_lock_bh(&sdata->u.nan.func_lock);
327
328 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
329 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
330 GFP_ATOMIC);
331 spin_unlock_bh(&sdata->u.nan.func_lock);
332
333 if (ret < 0)
334 return ret;
335
336 nan_func->instance_id = ret;
337
338 WARN_ON(nan_func->instance_id == 0);
339
340 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
341 if (ret) {
342 spin_lock_bh(&sdata->u.nan.func_lock);
343 idr_remove(&sdata->u.nan.function_inst_ids,
344 nan_func->instance_id);
345 spin_unlock_bh(&sdata->u.nan.func_lock);
346 }
347
348 return ret;
349}
350
351static struct cfg80211_nan_func *
352ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
353 u64 cookie)
354{
355 struct cfg80211_nan_func *func;
356 int id;
357
358 lockdep_assert_held(&sdata->u.nan.func_lock);
359
360 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
361 if (func->cookie == cookie)
362 return func;
363 }
364
365 return NULL;
366}
367
368static void ieee80211_del_nan_func(struct wiphy *wiphy,
369 struct wireless_dev *wdev, u64 cookie)
370{
371 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
372 struct cfg80211_nan_func *func;
373 u8 instance_id = 0;
374
375 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
376 !ieee80211_sdata_running(sdata))
377 return;
378
379 spin_lock_bh(&sdata->u.nan.func_lock);
380
381 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
382 if (func)
383 instance_id = func->instance_id;
384
385 spin_unlock_bh(&sdata->u.nan.func_lock);
386
387 if (instance_id)
388 drv_del_nan_func(sdata->local, sdata, instance_id);
389}
390
Simon Wunderlichb53be792011-11-18 14:20:44 +0100391static int ieee80211_set_noack_map(struct wiphy *wiphy,
392 struct net_device *dev,
393 u16 noack_map)
394{
395 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
396
397 sdata->noack_map = noack_map;
Johannes Berg17c18bf2015-03-21 15:25:43 +0100398
399 ieee80211_check_fast_xmit_iface(sdata);
400
Simon Wunderlichb53be792011-11-18 14:20:44 +0100401 return 0;
402}
403
Alexander Wetzel96fc6ef2019-03-19 21:34:08 +0100404static int ieee80211_set_tx(struct ieee80211_sub_if_data *sdata,
405 const u8 *mac_addr, u8 key_idx)
406{
407 struct ieee80211_local *local = sdata->local;
408 struct ieee80211_key *key;
409 struct sta_info *sta;
410 int ret = -EINVAL;
411
412 if (!wiphy_ext_feature_isset(local->hw.wiphy,
413 NL80211_EXT_FEATURE_EXT_KEY_ID))
414 return -EINVAL;
415
416 sta = sta_info_get_bss(sdata, mac_addr);
417
418 if (!sta)
419 return -EINVAL;
420
421 if (sta->ptk_idx == key_idx)
422 return 0;
423
424 mutex_lock(&local->key_mtx);
425 key = key_mtx_dereference(local, sta->ptk[key_idx]);
426
427 if (key && key->conf.flags & IEEE80211_KEY_FLAG_NO_AUTO_TX)
428 ret = ieee80211_set_tx_key(key);
429
430 mutex_unlock(&local->key_mtx);
431 return ret;
432}
433
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100434static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200435 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100436 struct key_params *params)
437{
Johannes Berg26a58452010-08-27 12:35:55 +0200438 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200439 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100440 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200441 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100442 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200443 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100444
Johannes Berg26a58452010-08-27 12:35:55 +0200445 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200446 return -ENETDOWN;
447
Alexander Wetzel96fc6ef2019-03-19 21:34:08 +0100448 if (pairwise && params->mode == NL80211_KEY_SET_TX)
449 return ieee80211_set_tx(sdata, mac_addr, key_idx);
450
Johannes Berg97359d12010-08-10 09:46:38 +0200451 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100452 switch (params->cipher) {
453 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100454 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200455 case WLAN_CIPHER_SUITE_WEP104:
Ard Biesheuvel5fdb3732019-06-12 18:19:54 +0200456 if (WARN_ON_ONCE(fips_enabled))
Johannes Berg97359d12010-08-10 09:46:38 +0200457 return -EINVAL;
Gustavo A. R. Silvaaaaee2d2020-11-20 12:36:45 -0600458 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200459 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200460 case WLAN_CIPHER_SUITE_CCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200461 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200462 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200463 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
464 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200465 case WLAN_CIPHER_SUITE_GCMP:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200466 case WLAN_CIPHER_SUITE_GCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200467 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100468 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200469 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200470 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100471 }
472
Johannes Berg97359d12010-08-10 09:46:38 +0200473 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200474 params->key, params->seq_len, params->seq,
475 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100476 if (IS_ERR(key))
477 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100478
Johannes Berge31b8212010-10-05 19:39:30 +0200479 if (pairwise)
480 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
481
Alexander Wetzel96fc6ef2019-03-19 21:34:08 +0100482 if (params->mode == NL80211_KEY_NO_TX)
483 key->conf.flags |= IEEE80211_KEY_FLAG_NO_AUTO_TX;
484
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200485 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200486
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100487 if (mac_addr) {
Johannes Berg850092d2016-10-04 15:32:16 +0200488 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100489 /*
490 * The ASSOC test makes sure the driver is ready to
491 * receive the key. When wpa_supplicant has roamed
492 * using FT, it attempts to set the key before
493 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700494 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100495 *
496 * TODO: accept the key if we have a station entry and
497 * add it to the device after the station.
498 */
499 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100500 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200501 err = -ENOENT;
502 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100503 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100504 }
505
Johannes Berge548c492012-09-04 17:08:23 +0200506 switch (sdata->vif.type) {
507 case NL80211_IFTYPE_STATION:
508 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
509 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
510 break;
511 case NL80211_IFTYPE_AP:
512 case NL80211_IFTYPE_AP_VLAN:
513 /* Keys without a station are used for TX only */
Felix Fietkau211710c2018-09-29 16:01:58 +0200514 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
Johannes Berge548c492012-09-04 17:08:23 +0200515 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
516 break;
517 case NL80211_IFTYPE_ADHOC:
518 /* no MFP (yet) */
519 break;
520 case NL80211_IFTYPE_MESH_POINT:
521#ifdef CONFIG_MAC80211_MESH
522 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
523 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
524 break;
525#endif
526 case NL80211_IFTYPE_WDS:
527 case NL80211_IFTYPE_MONITOR:
528 case NL80211_IFTYPE_P2P_DEVICE:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300529 case NL80211_IFTYPE_NAN:
Johannes Berge548c492012-09-04 17:08:23 +0200530 case NL80211_IFTYPE_UNSPECIFIED:
531 case NUM_NL80211_IFTYPES:
532 case NL80211_IFTYPE_P2P_CLIENT:
533 case NL80211_IFTYPE_P2P_GO:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100534 case NL80211_IFTYPE_OCB:
Johannes Berge548c492012-09-04 17:08:23 +0200535 /* shouldn't happen */
536 WARN_ON_ONCE(1);
537 break;
538 }
539
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200540 if (sta)
541 sta->cipher_scheme = cs;
542
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300543 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100544
Johannes Berg3b967662008-04-08 17:56:52 +0200545 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200546 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200547
548 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100549}
550
551static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200552 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100553{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200554 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100556 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200557 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100558 int ret;
559
Johannes Berg5c0c3642011-05-12 14:31:49 +0200560 mutex_lock(&local->sta_mtx);
561 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200562
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100563 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200564 ret = -ENOENT;
565
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100566 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100567 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200568 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100569
Johannes Berg5c0c3642011-05-12 14:31:49 +0200570 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200571 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200572 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200573 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200574 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200575 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100576
Johannes Berg5c0c3642011-05-12 14:31:49 +0200577 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200578 ret = -ENOENT;
579 goto out_unlock;
580 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100581
Manikanta Pubbisetty133bf902018-07-10 16:48:27 +0530582 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100583
Johannes Berg3b967662008-04-08 17:56:52 +0200584 ret = 0;
585 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200586 mutex_unlock(&local->key_mtx);
587 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200588
589 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100590}
591
Johannes Berg62da92f2007-12-19 02:03:31 +0100592static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200593 u8 key_idx, bool pairwise, const u8 *mac_addr,
594 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100595 void (*callback)(void *cookie,
596 struct key_params *params))
597{
Johannes Berg14db74b2008-07-29 13:22:52 +0200598 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100599 struct sta_info *sta = NULL;
600 u8 seq[6] = {0};
601 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200602 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200603 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100604 u32 iv32;
605 u16 iv16;
606 int err = -ENOENT;
Johannes Berg9352c192015-04-20 18:12:41 +0200607 struct ieee80211_key_seq kseq = {};
Johannes Berg62da92f2007-12-19 02:03:31 +0100608
Johannes Berg14db74b2008-07-29 13:22:52 +0200609 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
610
Johannes Berg3b967662008-04-08 17:56:52 +0200611 rcu_read_lock();
612
Johannes Berg62da92f2007-12-19 02:03:31 +0100613 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100614 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100615 if (!sta)
616 goto out;
617
Max Stepanov354e1592013-12-08 13:30:52 +0200618 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200619 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200620 else if (!pairwise &&
Jouni Malinene5473e82020-02-22 15:25:44 +0200621 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
622 NUM_DEFAULT_BEACON_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200623 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100624 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200625 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100626
627 if (!key)
628 goto out;
629
630 memset(&params, 0, sizeof(params));
631
Johannes Berg97359d12010-08-10 09:46:38 +0200632 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100633
Johannes Berg97359d12010-08-10 09:46:38 +0200634 switch (key->conf.cipher) {
635 case WLAN_CIPHER_SUITE_TKIP:
Eliad Pellerf8079d42016-02-14 13:56:35 +0200636 pn64 = atomic64_read(&key->conf.tx_pn);
637 iv32 = TKIP_PN_TO_IV32(pn64);
638 iv16 = TKIP_PN_TO_IV16(pn64);
Johannes Berg62da92f2007-12-19 02:03:31 +0100639
Johannes Berg9352c192015-04-20 18:12:41 +0200640 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
641 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
642 drv_get_key_seq(sdata->local, key, &kseq);
643 iv32 = kseq.tkip.iv32;
644 iv16 = kseq.tkip.iv16;
645 }
Johannes Berg62da92f2007-12-19 02:03:31 +0100646
647 seq[0] = iv16 & 0xff;
648 seq[1] = (iv16 >> 8) & 0xff;
649 seq[2] = iv32 & 0xff;
650 seq[3] = (iv32 >> 8) & 0xff;
651 seq[4] = (iv32 >> 16) & 0xff;
652 seq[5] = (iv32 >> 24) & 0xff;
653 params.seq = seq;
654 params.seq_len = 6;
655 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200656 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200657 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +0200658 case WLAN_CIPHER_SUITE_AES_CMAC:
659 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
660 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
661 offsetof(typeof(kseq), aes_cmac));
Gustavo A. R. Silvafc0561d2020-07-07 15:45:48 -0500662 fallthrough;
Johannes Bergdb388a52015-06-01 15:36:51 +0200663 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
664 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
665 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
666 offsetof(typeof(kseq), aes_gmac));
Gustavo A. R. Silvafc0561d2020-07-07 15:45:48 -0500667 fallthrough;
Johannes Bergdb388a52015-06-01 15:36:51 +0200668 case WLAN_CIPHER_SUITE_GCMP:
669 case WLAN_CIPHER_SUITE_GCMP_256:
670 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
671 offsetof(typeof(kseq), gcmp));
672
Johannes Berg9352c192015-04-20 18:12:41 +0200673 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
674 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
675 drv_get_key_seq(sdata->local, key, &kseq);
676 memcpy(seq, kseq.ccmp.pn, 6);
677 } else {
Johannes Bergdb388a52015-06-01 15:36:51 +0200678 pn64 = atomic64_read(&key->conf.tx_pn);
Johannes Berg9352c192015-04-20 18:12:41 +0200679 seq[0] = pn64;
680 seq[1] = pn64 >> 8;
681 seq[2] = pn64 >> 16;
682 seq[3] = pn64 >> 24;
683 seq[4] = pn64 >> 32;
684 seq[5] = pn64 >> 40;
685 }
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200686 params.seq = seq;
687 params.seq_len = 6;
688 break;
Johannes Berga31cf1c2015-04-20 18:21:58 +0200689 default:
690 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
691 break;
692 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
693 break;
694 drv_get_key_seq(sdata->local, key, &kseq);
695 params.seq = kseq.hw.seq;
696 params.seq_len = kseq.hw.seq_len;
697 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100698 }
699
700 params.key = key->conf.key;
701 params.key_len = key->conf.keylen;
702
703 callback(cookie, &params);
704 err = 0;
705
706 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200707 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100708 return err;
709}
710
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100711static int ieee80211_config_default_key(struct wiphy *wiphy,
712 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 u8 key_idx, bool uni,
714 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100715{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200716 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100717
Johannes Bergf7e01042010-12-09 19:49:02 +0100718 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100719
720 return 0;
721}
722
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200723static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
724 struct net_device *dev,
725 u8 key_idx)
726{
Johannes Berg66c52422010-07-22 13:58:51 +0200727 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200728
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200729 ieee80211_set_default_mgmt_key(sdata, key_idx);
730
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200731 return 0;
732}
733
Jouni Malinene5473e82020-02-22 15:25:44 +0200734static int ieee80211_config_default_beacon_key(struct wiphy *wiphy,
735 struct net_device *dev,
736 u8 key_idx)
737{
738 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
739
740 ieee80211_set_default_beacon_key(sdata, key_idx);
741
742 return 0;
743}
744
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800745void sta_set_rate_info_tx(struct sta_info *sta,
746 const struct ieee80211_tx_rate *rate,
747 struct rate_info *rinfo)
748{
749 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100750 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800751 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100752 rinfo->mcs = rate->idx;
753 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
754 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
755 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
756 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
757 } else {
758 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200759 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
760 u16 brate;
761
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +0530762 sband = ieee80211_get_sband(sta->sdata);
Thomas Pedersen8b783d12020-10-05 09:45:21 -0700763 WARN_ON_ONCE(sband && !sband->bitrates);
764 if (sband && sband->bitrates) {
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +0530765 brate = sband->bitrates[rate->idx].bitrate;
766 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
767 }
Johannes Berg8bc83c22012-11-09 18:38:32 +0100768 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800769 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Johannes Bergb51f3be2015-01-15 16:14:02 +0100770 rinfo->bw = RATE_INFO_BW_40;
771 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
772 rinfo->bw = RATE_INFO_BW_80;
773 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
774 rinfo->bw = RATE_INFO_BW_160;
775 else
776 rinfo->bw = RATE_INFO_BW_20;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800777 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
778 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800779}
780
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100781static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200782 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100783{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100784 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300785 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100786 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100787 int ret = -ENOENT;
788
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300789 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100790
Johannes Berg3b53fde82009-11-16 12:00:37 +0100791 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 if (sta) {
793 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200794 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Berg0fdf1492018-05-18 11:40:44 +0200795 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100796 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300798 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100799
Johannes Bergd0709a62008-02-25 16:27:46 +0100800 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100801}
802
Holger Schurig12897232010-04-19 10:23:57 +0200803static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
804 int idx, struct survey_info *survey)
805{
806 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
807
Holger Schurig12897232010-04-19 10:23:57 +0200808 return drv_get_survey(local, idx, survey);
809}
810
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100811static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200812 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100813{
Johannes Bergabe60632009-11-25 17:46:18 +0100814 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300815 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100816 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100817 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100818
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300819 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100820
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100821 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100822 if (sta) {
823 ret = 0;
Johannes Berg0fdf1492018-05-18 11:40:44 +0200824 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100825 }
826
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300827 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100828
829 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100830}
831
Johannes Berge8c9bd52012-06-06 08:18:22 +0200832static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100833 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200834{
Johannes Berg55de9082012-07-26 17:24:39 +0200835 struct ieee80211_local *local = wiphy_priv(wiphy);
836 struct ieee80211_sub_if_data *sdata;
837 int ret = 0;
838
Johannes Berg4bf88532012-11-09 11:39:59 +0100839 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200840 return 0;
841
Johannes Berg34a37402013-12-18 09:43:33 +0100842 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200843 if (local->use_chanctx) {
Johannes Berg6dd236032021-11-12 13:51:44 +0100844 sdata = wiphy_dereference(local->hw.wiphy,
845 local->monitor_sdata);
Johannes Berg55de9082012-07-26 17:24:39 +0200846 if (sdata) {
847 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100848 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200849 IEEE80211_CHANCTX_EXCLUSIVE);
850 }
851 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100852 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200853 ieee80211_hw_config(local, 0);
854 }
855
Johannes Berg4bf88532012-11-09 11:39:59 +0100856 if (ret == 0)
857 local->monitor_chandef = *chandef;
Johannes Berg34a37402013-12-18 09:43:33 +0100858 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200859
860 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200861}
862
John Crispin5f9404a2021-07-02 19:44:08 +0200863static int
864ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
865 const u8 *resp, size_t resp_len,
866 const struct ieee80211_csa_settings *csa,
867 const struct ieee80211_color_change_settings *cca)
Arik Nemtsov02945822011-11-10 11:28:57 +0200868{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300869 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200870
871 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530872 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200873
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100874 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200875
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300876 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200877 if (!new)
878 return -ENOMEM;
879
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300880 new->len = resp_len;
881 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200882
Michal Kazioraf296bd2014-06-05 14:21:36 +0200883 if (csa)
John Crispin8552a432020-08-11 10:01:04 +0200884 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_presp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200885 csa->n_counter_offsets_presp *
John Crispin8552a432020-08-11 10:01:04 +0200886 sizeof(new->cntdwn_counter_offsets[0]));
John Crispin5f9404a2021-07-02 19:44:08 +0200887 else if (cca)
888 new->cntdwn_counter_offsets[0] = cca->counter_offset_presp;
Michal Kazioraf296bd2014-06-05 14:21:36 +0200889
Arik Nemtsov02945822011-11-10 11:28:57 +0200890 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300891 if (old)
892 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200893
894 return 0;
895}
896
Aloka Dixit295b02c2020-09-11 00:05:31 +0000897static int ieee80211_set_fils_discovery(struct ieee80211_sub_if_data *sdata,
898 struct cfg80211_fils_discovery *params)
899{
900 struct fils_discovery_data *new, *old = NULL;
901 struct ieee80211_fils_discovery *fd;
902
903 if (!params->tmpl || !params->tmpl_len)
904 return -EINVAL;
905
906 fd = &sdata->vif.bss_conf.fils_discovery;
907 fd->min_interval = params->min_interval;
908 fd->max_interval = params->max_interval;
909
910 old = sdata_dereference(sdata->u.ap.fils_discovery, sdata);
911 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
912 if (!new)
913 return -ENOMEM;
914 new->len = params->tmpl_len;
915 memcpy(new->data, params->tmpl, params->tmpl_len);
916 rcu_assign_pointer(sdata->u.ap.fils_discovery, new);
917
918 if (old)
919 kfree_rcu(old, rcu_head);
920
921 return 0;
922}
923
Aloka Dixit632189a2020-09-11 00:33:01 +0000924static int
925ieee80211_set_unsol_bcast_probe_resp(struct ieee80211_sub_if_data *sdata,
926 struct cfg80211_unsol_bcast_probe_resp *params)
927{
928 struct unsol_bcast_probe_resp_data *new, *old = NULL;
929
930 if (!params->tmpl || !params->tmpl_len)
931 return -EINVAL;
932
933 old = sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp, sdata);
934 new = kzalloc(sizeof(*new) + params->tmpl_len, GFP_KERNEL);
935 if (!new)
936 return -ENOMEM;
937 new->len = params->tmpl_len;
938 memcpy(new->data, params->tmpl, params->tmpl_len);
939 rcu_assign_pointer(sdata->u.ap.unsol_bcast_probe_resp, new);
940
941 if (old)
942 kfree_rcu(old, rcu_head);
943
944 sdata->vif.bss_conf.unsol_bcast_probe_resp_interval =
945 params->interval;
946
947 return 0;
948}
949
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -0700950static int ieee80211_set_ftm_responder_params(
951 struct ieee80211_sub_if_data *sdata,
952 const u8 *lci, size_t lci_len,
953 const u8 *civicloc, size_t civicloc_len)
954{
955 struct ieee80211_ftm_responder_params *new, *old;
956 struct ieee80211_bss_conf *bss_conf;
957 u8 *pos;
958 int len;
959
Johannes Berg554be832018-12-15 11:03:24 +0200960 if (!lci_len && !civicloc_len)
961 return 0;
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -0700962
963 bss_conf = &sdata->vif.bss_conf;
964 old = bss_conf->ftmr_params;
965 len = lci_len + civicloc_len;
966
967 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
968 if (!new)
969 return -ENOMEM;
970
971 pos = (u8 *)(new + 1);
972 if (lci_len) {
973 new->lci_len = lci_len;
974 new->lci = pos;
975 memcpy(pos, lci, lci_len);
976 pos += lci_len;
977 }
978
979 if (civicloc_len) {
980 new->civicloc_len = civicloc_len;
981 new->civicloc = pos;
982 memcpy(pos, civicloc, civicloc_len);
983 pos += civicloc_len;
984 }
985
986 bss_conf->ftmr_params = new;
987 kfree(old);
988
989 return 0;
990}
991
Luciano Coelho0ae07962013-12-08 09:42:25 +0200992static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200993 struct cfg80211_beacon_data *params,
John Crispin5f9404a2021-07-02 19:44:08 +0200994 const struct ieee80211_csa_settings *csa,
995 const struct ieee80211_color_change_settings *cca)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100996{
997 struct beacon_data *new, *old;
998 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100999 int size, err;
1000 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001001
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001002 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1003
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001004
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001005 /* Need to have a beacon head if we don't have one yet */
1006 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +01001007 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001008
1009 /* new or old head? */
1010 if (params->head)
1011 new_head_len = params->head_len;
1012 else
1013 new_head_len = old->head_len;
1014
1015 /* new or old tail? */
1016 if (params->tail || !old)
1017 /* params->tail_len will be zero for !params->tail */
1018 new_tail_len = params->tail_len;
1019 else
1020 new_tail_len = old->tail_len;
1021
1022 size = sizeof(*new) + new_head_len + new_tail_len;
1023
1024 new = kzalloc(size, GFP_KERNEL);
1025 if (!new)
1026 return -ENOMEM;
1027
1028 /* start filling the new info now */
1029
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001030 /*
1031 * pointers go into the block we allocated,
1032 * memory is | beacon_data | head | tail |
1033 */
1034 new->head = ((u8 *) new) + sizeof(*new);
1035 new->tail = new->head + new_head_len;
1036 new->head_len = new_head_len;
1037 new->tail_len = new_tail_len;
1038
Michal Kazioraf296bd2014-06-05 14:21:36 +02001039 if (csa) {
John Crispin8552a432020-08-11 10:01:04 +02001040 new->cntdwn_current_counter = csa->count;
1041 memcpy(new->cntdwn_counter_offsets, csa->counter_offsets_beacon,
Michal Kazioraf296bd2014-06-05 14:21:36 +02001042 csa->n_counter_offsets_beacon *
John Crispin8552a432020-08-11 10:01:04 +02001043 sizeof(new->cntdwn_counter_offsets[0]));
John Crispin5f9404a2021-07-02 19:44:08 +02001044 } else if (cca) {
1045 new->cntdwn_current_counter = cca->count;
1046 new->cntdwn_counter_offsets[0] = cca->counter_offset_beacon;
Michal Kazioraf296bd2014-06-05 14:21:36 +02001047 }
1048
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001049 /* copy in head */
1050 if (params->head)
1051 memcpy(new->head, params->head, new_head_len);
1052 else
1053 memcpy(new->head, old->head, new_head_len);
1054
1055 /* copy in optional tail */
1056 if (params->tail)
1057 memcpy(new->tail, params->tail, new_tail_len);
1058 else
1059 if (old)
1060 memcpy(new->tail, old->tail, new_tail_len);
1061
Johannes Berg88600202012-02-13 15:17:18 +01001062 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
John Crispin5f9404a2021-07-02 19:44:08 +02001063 params->probe_resp_len, csa, cca);
Lorenzo Bianconibcc27fa2019-07-03 00:29:47 +02001064 if (err < 0) {
1065 kfree(new);
Johannes Berg88600202012-02-13 15:17:18 +01001066 return err;
Lorenzo Bianconibcc27fa2019-07-03 00:29:47 +02001067 }
Johannes Berg88600202012-02-13 15:17:18 +01001068 if (err == 0)
1069 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +01001070
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07001071 if (params->ftm_responder != -1) {
1072 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
1073 err = ieee80211_set_ftm_responder_params(sdata,
1074 params->lci,
1075 params->lci_len,
1076 params->civicloc,
1077 params->civicloc_len);
1078
Lorenzo Bianconibcc27fa2019-07-03 00:29:47 +02001079 if (err < 0) {
1080 kfree(new);
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07001081 return err;
Lorenzo Bianconibcc27fa2019-07-03 00:29:47 +02001082 }
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07001083
1084 changed |= BSS_CHANGED_FTM_RESPONDER;
1085 }
1086
Eric Dumazetcf778b02012-01-12 04:41:32 +00001087 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001088
Johannes Berg88600202012-02-13 15:17:18 +01001089 if (old)
1090 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001091
Johannes Berg88600202012-02-13 15:17:18 +01001092 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001093}
1094
Johannes Berg88600202012-02-13 15:17:18 +01001095static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
1096 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001097{
Johannes Berg88600202012-02-13 15:17:18 +01001098 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +01001099 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001100 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +01001101 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +01001102 u32 changed = BSS_CHANGED_BEACON_INT |
1103 BSS_CHANGED_BEACON_ENABLED |
1104 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +01001105 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +01001106 BSS_CHANGED_P2P_PS |
John Crispina0de1ca32019-05-28 13:49:48 +02001107 BSS_CHANGED_TXPOWER |
P Praneesh322cd272020-07-09 08:16:21 +05301108 BSS_CHANGED_TWT;
Jouni Malinen08fad432020-04-25 18:57:12 +03001109 int i, err;
Rakesh Pillai83e37e02019-02-15 14:16:02 +05301110 int prev_beacon_int;
Johannes Berg14db74b2008-07-29 13:22:52 +02001111
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001112 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001113 if (old)
1114 return -EALREADY;
1115
Ilan Peer52b48102020-01-31 13:12:56 +02001116 if (params->smps_mode != NL80211_SMPS_OFF)
1117 return -ENOTSUPP;
1118
1119 sdata->smps_mode = IEEE80211_SMPS_OFF;
Emmanuel Grumbachb3dd8272017-06-10 13:52:45 +03001120
Johannes Berg04ecd252012-09-11 14:34:12 +02001121 sdata->needed_rx_chains = sdata->local->rx_chains;
1122
Rakesh Pillai83e37e02019-02-15 14:16:02 +05301123 prev_beacon_int = sdata->vif.bss_conf.beacon_int;
Johannes Bergac668af2016-10-21 14:25:14 +02001124 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1125
Shaul Triebitz03efb862020-01-31 13:12:55 +02001126 if (params->he_cap && params->he_oper) {
Shaul Triebitz34fb1902018-08-31 11:31:15 +03001127 sdata->vif.bss_conf.he_support = true;
Shaul Triebitz03efb862020-01-31 13:12:55 +02001128 sdata->vif.bss_conf.htc_trig_based_pkt_ext =
1129 le32_get_bits(params->he_oper->he_oper_params,
1130 IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
1131 sdata->vif.bss_conf.frame_time_rts_th =
1132 le32_get_bits(params->he_oper->he_oper_params,
1133 IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
P Praneesh322cd272020-07-09 08:16:21 +05301134 changed |= BSS_CHANGED_HE_OBSS_PD;
1135
Johannes Berg75e6b592020-07-30 13:00:52 +02001136 if (params->he_bss_color.enabled)
P Praneesh322cd272020-07-09 08:16:21 +05301137 changed |= BSS_CHANGED_HE_BSS_COLOR;
Shaul Triebitz03efb862020-01-31 13:12:55 +02001138 }
Shaul Triebitz34fb1902018-08-31 11:31:15 +03001139
John Crispin17196422021-09-15 19:54:35 -07001140 if (sdata->vif.type == NL80211_IFTYPE_AP &&
1141 params->mbssid_config.tx_wdev) {
1142 err = ieee80211_set_ap_mbssid_options(sdata,
1143 params->mbssid_config);
1144 if (err)
1145 return err;
1146 }
1147
Johannes Berg34a37402013-12-18 09:43:33 +01001148 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001149 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001150 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +01001151 if (!err)
1152 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +01001153 mutex_unlock(&local->mtx);
Rakesh Pillai83e37e02019-02-15 14:16:02 +05301154 if (err) {
1155 sdata->vif.bss_conf.beacon_int = prev_beacon_int;
Johannes Bergaa430da2012-05-16 23:50:18 +02001156 return err;
Rakesh Pillai83e37e02019-02-15 14:16:02 +05301157 }
Johannes Bergaa430da2012-05-16 23:50:18 +02001158
Johannes Berg665c93a2011-11-04 11:18:11 +01001159 /*
1160 * Apply control port protocol, this allows us to
1161 * not encrypt dynamic WEP control frames.
1162 */
1163 sdata->control_port_protocol = params->crypto.control_port_ethertype;
1164 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05001165 sdata->control_port_over_nl80211 =
1166 params->crypto.control_port_over_nl80211;
Markus Theil7f3f96c2020-03-12 10:10:54 +01001167 sdata->control_port_no_preauth =
1168 params->crypto.control_port_no_preauth;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001169 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
1170 &params->crypto,
1171 sdata->vif.type);
1172
Johannes Berg665c93a2011-11-04 11:18:11 +01001173 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1174 vlan->control_port_protocol =
1175 params->crypto.control_port_ethertype;
1176 vlan->control_port_no_encrypt =
1177 params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -05001178 vlan->control_port_over_nl80211 =
1179 params->crypto.control_port_over_nl80211;
Markus Theil7f3f96c2020-03-12 10:10:54 +01001180 vlan->control_port_no_preauth =
1181 params->crypto.control_port_no_preauth;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001182 vlan->encrypt_headroom =
1183 ieee80211_cs_headroom(sdata->local,
1184 &params->crypto,
1185 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +01001186 }
1187
Johannes Berg88600202012-02-13 15:17:18 +01001188 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +01001189 sdata->vif.bss_conf.enable_beacon = true;
Ayala Beker52cfa1d2016-03-17 15:41:39 +02001190 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
John Crispina0de1ca32019-05-28 13:49:48 +02001191 sdata->vif.bss_conf.twt_responder = params->twt_responder;
Johannes Berga5a55032020-12-06 14:54:41 +02001192 sdata->vif.bss_conf.he_obss_pd = params->he_obss_pd;
Johannes Berg539a36b2020-12-06 14:54:40 +02001193 sdata->vif.bss_conf.he_bss_color = params->he_bss_color;
Thomas Pedersen1d00ce82020-09-21 19:28:15 -07001194 sdata->vif.bss_conf.s1g = params->chandef.chan->band ==
1195 NL80211_BAND_S1GHZ;
Johannes Berg88600202012-02-13 15:17:18 +01001196
1197 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1198 if (params->ssid_len)
1199 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1200 params->ssid_len);
1201 sdata->vif.bss_conf.hidden_ssid =
1202 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1203
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001204 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1205 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1206 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1207 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1208 if (params->p2p_opp_ps)
1209 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1210 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001211
Jouni Malinen08fad432020-04-25 18:57:12 +03001212 sdata->beacon_rate_set = false;
1213 if (wiphy_ext_feature_isset(local->hw.wiphy,
1214 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
1215 for (i = 0; i < NUM_NL80211_BANDS; i++) {
1216 sdata->beacon_rateidx_mask[i] =
1217 params->beacon_rate.control[i].legacy;
1218 if (sdata->beacon_rateidx_mask[i])
1219 sdata->beacon_rate_set = true;
1220 }
1221 }
1222
Rajkumar Manoharanba6ff702020-10-03 15:04:18 -07001223 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL))
1224 sdata->vif.bss_conf.beacon_tx_rate = params->beacon_rate;
1225
John Crispin5f9404a2021-07-02 19:44:08 +02001226 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL, NULL);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001227 if (err < 0)
1228 goto error;
Johannes Berg88600202012-02-13 15:17:18 +01001229 changed |= err;
1230
Aloka Dixit295b02c2020-09-11 00:05:31 +00001231 if (params->fils_discovery.max_interval) {
1232 err = ieee80211_set_fils_discovery(sdata,
1233 &params->fils_discovery);
1234 if (err < 0)
1235 goto error;
1236 changed |= BSS_CHANGED_FILS_DISCOVERY;
1237 }
1238
Aloka Dixit632189a2020-09-11 00:33:01 +00001239 if (params->unsol_bcast_probe_resp.interval) {
1240 err = ieee80211_set_unsol_bcast_probe_resp(sdata,
1241 &params->unsol_bcast_probe_resp);
1242 if (err < 0)
1243 goto error;
1244 changed |= BSS_CHANGED_UNSOL_BCAST_PROBE_RESP;
1245 }
1246
Johannes Berg10416382012-10-19 15:44:42 +02001247 err = drv_start_ap(sdata->local, sdata);
1248 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001249 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1250
Johannes Berg10416382012-10-19 15:44:42 +02001251 if (old)
1252 kfree_rcu(old, rcu_head);
1253 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001254 goto error;
Johannes Berg10416382012-10-19 15:44:42 +02001255 }
1256
Thomas Pedersen057d5f42013-12-19 10:25:15 -08001257 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001258 ieee80211_bss_info_change_notify(sdata, changed);
1259
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001260 netif_carrier_on(dev);
1261 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1262 netif_carrier_on(vlan->dev);
1263
Johannes Berg665c93a2011-11-04 11:18:11 +01001264 return 0;
Aloka Dixit295b02c2020-09-11 00:05:31 +00001265
1266error:
Johannes Berg87a27062021-12-20 10:22:40 +01001267 mutex_lock(&local->mtx);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001268 ieee80211_vif_release_channel(sdata);
Johannes Berg87a27062021-12-20 10:22:40 +01001269 mutex_unlock(&local->mtx);
1270
Aloka Dixit295b02c2020-09-11 00:05:31 +00001271 return err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001272}
1273
Johannes Berg88600202012-02-13 15:17:18 +01001274static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1275 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001276{
Johannes Berg14db74b2008-07-29 13:22:52 +02001277 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001278 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001279 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001280
Johannes Berg14db74b2008-07-29 13:22:52 +02001281 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +01001282 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +02001283
John Crispin5f9404a2021-07-02 19:44:08 +02001284 /* don't allow changing the beacon while a countdown is in place - offset
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001285 * of channel switch counter may change
1286 */
John Crispin5f9404a2021-07-02 19:44:08 +02001287 if (sdata->vif.csa_active || sdata->vif.color_change_active)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001288 return -EBUSY;
1289
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001290 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001291 if (!old)
1292 return -ENOENT;
1293
John Crispin5f9404a2021-07-02 19:44:08 +02001294 err = ieee80211_assign_beacon(sdata, params, NULL, NULL);
Johannes Berg88600202012-02-13 15:17:18 +01001295 if (err < 0)
1296 return err;
1297 ieee80211_bss_info_change_notify(sdata, err);
1298 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001299}
1300
Johannes Berg88600202012-02-13 15:17:18 +01001301static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001302{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001303 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1304 struct ieee80211_sub_if_data *vlan;
1305 struct ieee80211_local *local = sdata->local;
1306 struct beacon_data *old_beacon;
1307 struct probe_resp *old_probe_resp;
Aloka Dixit295b02c2020-09-11 00:05:31 +00001308 struct fils_discovery_data *old_fils_discovery;
Aloka Dixit632189a2020-09-11 00:33:01 +00001309 struct unsol_bcast_probe_resp_data *old_unsol_bcast_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001310 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001311
Michal Kaziordbd72852014-01-29 07:56:21 +01001312 sdata_assert_lock(sdata);
1313
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001314 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001315 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001316 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001317 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001318 old_fils_discovery = sdata_dereference(sdata->u.ap.fils_discovery,
1319 sdata);
Aloka Dixit632189a2020-09-11 00:33:01 +00001320 old_unsol_bcast_probe_resp =
1321 sdata_dereference(sdata->u.ap.unsol_bcast_probe_resp,
1322 sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001323
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001324 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +02001325 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001326 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001327 if (sdata->csa_block_tx) {
1328 ieee80211_wake_vif_queues(local, sdata,
1329 IEEE80211_QUEUE_STOP_REASON_CSA);
1330 sdata->csa_block_tx = false;
1331 }
1332
Michal Kazior59af6922014-04-09 15:10:59 +02001333 mutex_unlock(&local->mtx);
1334
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +01001335 kfree(sdata->u.ap.next_beacon);
1336 sdata->u.ap.next_beacon = NULL;
1337
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001338 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001339 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1340 netif_carrier_off(vlan->dev);
1341 netif_carrier_off(dev);
1342
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001343 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001344 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001345 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001346 RCU_INIT_POINTER(sdata->u.ap.fils_discovery, NULL);
Aloka Dixit632189a2020-09-11 00:33:01 +00001347 RCU_INIT_POINTER(sdata->u.ap.unsol_bcast_probe_resp, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001348 kfree_rcu(old_beacon, rcu_head);
1349 if (old_probe_resp)
1350 kfree_rcu(old_probe_resp, rcu_head);
Aloka Dixit295b02c2020-09-11 00:05:31 +00001351 if (old_fils_discovery)
1352 kfree_rcu(old_fils_discovery, rcu_head);
Aloka Dixit632189a2020-09-11 00:33:01 +00001353 if (old_unsol_bcast_probe_resp)
1354 kfree_rcu(old_unsol_bcast_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001355
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07001356 kfree(sdata->vif.bss_conf.ftmr_params);
1357 sdata->vif.bss_conf.ftmr_params = NULL;
1358
Johannes Berge7162512013-12-04 23:18:37 +01001359 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +01001360 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +01001361
Johannes Bergd6a83222012-12-14 14:06:28 +01001362 sdata->vif.bss_conf.enable_beacon = false;
Jouni Malinen08fad432020-04-25 18:57:12 +03001363 sdata->beacon_rate_set = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001364 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001365 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001366 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001367
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001368 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001369 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001370 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001371 cfg80211_cac_event(sdata->dev, &chandef,
1372 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001373 GFP_KERNEL);
1374 }
1375
Johannes Berg10416382012-10-19 15:44:42 +02001376 drv_stop_ap(sdata->local, sdata);
1377
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001378 /* free all potentially still buffered bcast frames */
1379 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
Felix Fietkau6b07d9c2016-08-02 11:13:41 +02001380 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001381
Johannes Berg34a37402013-12-18 09:43:33 +01001382 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +01001383 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001384 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001385 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001386
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001387 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001388}
1389
Johannes Bergd582cff2012-10-26 17:53:44 +02001390static int sta_apply_auth_flags(struct ieee80211_local *local,
1391 struct sta_info *sta,
1392 u32 mask, u32 set)
1393{
1394 int ret;
1395
1396 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1397 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1398 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1399 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1400 if (ret)
1401 return ret;
1402 }
1403
1404 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1405 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1406 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001407 /*
1408 * When peer becomes associated, init rate control as
1409 * well. Some drivers require rate control initialized
1410 * before drv_sta_state() is called.
1411 */
Ayala Beker44674d92015-09-23 10:41:27 +02001412 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001413 rate_control_rate_init(sta);
1414
Johannes Bergd582cff2012-10-26 17:53:44 +02001415 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1416 if (ret)
1417 return ret;
1418 }
1419
1420 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1421 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1422 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1423 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1424 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1425 else
1426 ret = 0;
1427 if (ret)
1428 return ret;
1429 }
1430
1431 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1432 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1433 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1434 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1435 if (ret)
1436 return ret;
1437 }
1438
1439 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1440 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1441 test_sta_flag(sta, WLAN_STA_AUTH)) {
1442 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1443 if (ret)
1444 return ret;
1445 }
1446
1447 return 0;
1448}
1449
Johannes Berg13657702015-06-17 10:34:54 +02001450static void sta_apply_mesh_params(struct ieee80211_local *local,
1451 struct sta_info *sta,
1452 struct station_parameters *params)
1453{
1454#ifdef CONFIG_MAC80211_MESH
1455 struct ieee80211_sub_if_data *sdata = sta->sdata;
1456 u32 changed = 0;
1457
1458 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1459 switch (params->plink_state) {
1460 case NL80211_PLINK_ESTAB:
1461 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1462 changed = mesh_plink_inc_estab_count(sdata);
1463 sta->mesh->plink_state = params->plink_state;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09001464 sta->mesh->aid = params->peer_aid;
Johannes Berg13657702015-06-17 10:34:54 +02001465
1466 ieee80211_mps_sta_status_update(sta);
1467 changed |= ieee80211_mps_set_sta_local_pm(sta,
1468 sdata->u.mesh.mshcfg.power_mode);
Julan Hsu67fc0552019-01-15 15:31:56 -08001469
1470 ewma_mesh_tx_rate_avg_init(&sta->mesh->tx_rate_avg);
1471 /* init at low value */
1472 ewma_mesh_tx_rate_avg_add(&sta->mesh->tx_rate_avg, 10);
1473
Johannes Berg13657702015-06-17 10:34:54 +02001474 break;
1475 case NL80211_PLINK_LISTEN:
1476 case NL80211_PLINK_BLOCKED:
1477 case NL80211_PLINK_OPN_SNT:
1478 case NL80211_PLINK_OPN_RCVD:
1479 case NL80211_PLINK_CNF_RCVD:
1480 case NL80211_PLINK_HOLDING:
1481 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1482 changed = mesh_plink_dec_estab_count(sdata);
1483 sta->mesh->plink_state = params->plink_state;
1484
1485 ieee80211_mps_sta_status_update(sta);
1486 changed |= ieee80211_mps_set_sta_local_pm(sta,
1487 NL80211_MESH_POWER_UNKNOWN);
1488 break;
1489 default:
1490 /* nothing */
1491 break;
1492 }
1493 }
1494
1495 switch (params->plink_action) {
1496 case NL80211_PLINK_ACTION_NO_ACTION:
1497 /* nothing */
1498 break;
1499 case NL80211_PLINK_ACTION_OPEN:
1500 changed |= mesh_plink_open(sta);
1501 break;
1502 case NL80211_PLINK_ACTION_BLOCK:
1503 changed |= mesh_plink_block(sta);
1504 break;
1505 }
1506
1507 if (params->local_pm)
1508 changed |= ieee80211_mps_set_sta_local_pm(sta,
1509 params->local_pm);
1510
1511 ieee80211_mbss_info_change_notify(sdata, changed);
1512#endif
1513}
1514
Toke Høiland-Jørgensen24336472021-06-23 15:47:55 +02001515static void sta_apply_airtime_params(struct ieee80211_local *local,
1516 struct sta_info *sta,
1517 struct station_parameters *params)
1518{
1519 u8 ac;
1520
1521 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
1522 struct airtime_sched_info *air_sched = &local->airtime[ac];
1523 struct airtime_info *air_info = &sta->airtime[ac];
1524 struct txq_info *txqi;
1525 u8 tid;
1526
1527 spin_lock_bh(&air_sched->lock);
1528 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
1529 if (air_info->weight == params->airtime_weight ||
1530 !sta->sta.txq[tid] ||
1531 ac != ieee80211_ac_from_tid(tid))
1532 continue;
1533
1534 airtime_weight_set(air_info, params->airtime_weight);
1535
1536 txqi = to_txq_info(sta->sta.txq[tid]);
1537 if (RB_EMPTY_NODE(&txqi->schedule_order))
1538 continue;
1539
1540 ieee80211_update_airtime_weight(local, air_sched,
1541 0, true);
1542 }
1543 spin_unlock_bh(&air_sched->lock);
1544 }
1545}
1546
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001547static int sta_apply_parameters(struct ieee80211_local *local,
1548 struct sta_info *sta,
1549 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001550{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001551 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001552 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001553 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +03001554 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001555
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301556 sband = ieee80211_get_sband(sdata);
1557 if (!sband)
1558 return -EINVAL;
Johannes Bergae5eb022008-10-14 16:58:37 +02001559
Johannes Bergeccb8e82009-05-11 21:57:56 +03001560 mask = params->sta_flags_mask;
1561 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001562
Johannes Bergd582cff2012-10-26 17:53:44 +02001563 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1564 /*
1565 * In mesh mode, ASSOCIATED isn't part of the nl80211
1566 * API but must follow AUTHENTICATED for driver state.
1567 */
1568 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1569 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1570 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1571 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001572 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1573 /*
1574 * TDLS -- everything follows authorized, but
1575 * only becoming authorized is possible, not
1576 * going back
1577 */
1578 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1579 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1580 BIT(NL80211_STA_FLAG_ASSOCIATED);
1581 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1582 BIT(NL80211_STA_FLAG_ASSOCIATED);
1583 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001584 }
1585
Johannes Berg2c44be82015-03-30 15:09:20 +02001586 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1587 local->hw.queues >= IEEE80211_NUM_ACS)
1588 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1589
Ayala Beker44674d92015-09-23 10:41:27 +02001590 /* auth flags will be set later for TDLS,
Bhaskar Chowdhuryb18daca2021-03-27 04:42:45 +05301591 * and for unassociated stations that move to associated */
Ayala Beker44674d92015-09-23 10:41:27 +02001592 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1593 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1594 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001595 ret = sta_apply_auth_flags(local, sta, mask, set);
1596 if (ret)
1597 return ret;
1598 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001599
Johannes Bergeccb8e82009-05-11 21:57:56 +03001600 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001601 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001602 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1603 else
1604 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001605 }
1606
Johannes Bergeccb8e82009-05-11 21:57:56 +03001607 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Tamizh chelvam93f04902015-10-07 10:40:04 +05301608 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
Johannes Bergeccb8e82009-05-11 21:57:56 +03001609 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001610 set_sta_flag(sta, WLAN_STA_MFP);
1611 else
1612 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001613 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001614
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001615 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001616 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001617 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1618 else
1619 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001620 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001621
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001622 /* mark TDLS channel switch support, if the AP allows it */
1623 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1624 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1625 params->ext_capab_len >= 4 &&
1626 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1627 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1628
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001629 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +03001630 !sdata->u.mgd.tdls_wider_bw_prohibited &&
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001631 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1632 params->ext_capab_len >= 8 &&
1633 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1634 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1635
Johannes Berg3b9ce802011-09-27 20:56:12 +02001636 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1637 sta->sta.uapsd_queues = params->uapsd_queues;
1638 sta->sta.max_sp = params->max_sp;
1639 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001640
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001641 /* The sender might not have sent the last bit, consider it to be 0 */
1642 if (params->ext_capab_len >= 8) {
1643 u8 val = (params->ext_capab[7] &
1644 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1645
1646 /* we did get all the bits, take the MSB as well */
1647 if (params->ext_capab_len >= 9) {
1648 u8 val_msb = params->ext_capab[8] &
1649 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1650 val_msb <<= 1;
1651 val |= val_msb;
1652 }
1653
1654 switch (val) {
1655 case 1:
1656 sta->sta.max_amsdu_subframes = 32;
1657 break;
1658 case 2:
1659 sta->sta.max_amsdu_subframes = 16;
1660 break;
1661 case 3:
1662 sta->sta.max_amsdu_subframes = 8;
1663 break;
1664 default:
1665 sta->sta.max_amsdu_subframes = 0;
1666 }
1667 }
1668
Johannes Berg73651ee2008-02-25 16:27:47 +01001669 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001670 * cfg80211 validates this (1-2007) and allows setting the AID
1671 * only when creating a new station entry
1672 */
1673 if (params->aid)
1674 sta->sta.aid = params->aid;
1675
1676 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001677 * Some of the following updates would be racy if called on an
1678 * existing station, via ieee80211_change_station(). However,
1679 * all such changes are rejected by cfg80211 except for updates
1680 * changing the supported rates on an existing but not yet used
1681 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001682 */
1683
Johannes Berg4fd69312007-12-19 02:03:35 +01001684 if (params->listen_interval >= 0)
1685 sta->listen_interval = params->listen_interval;
1686
Ashok Raj Nagarajanba905bf2019-03-29 16:19:09 +05301687 if (params->sta_modify_mask & STATION_PARAM_APPLY_STA_TXPOWER) {
1688 sta->sta.txpwr.type = params->txpwr.type;
1689 if (params->txpwr.type == NL80211_TX_POWER_LIMITED)
1690 sta->sta.txpwr.power = params->txpwr.power;
1691 ret = drv_sta_set_txpwr(local, sdata, sta);
1692 if (ret)
1693 return ret;
1694 }
1695
Johannes Bergbd718fc2019-05-29 15:25:35 +03001696 if (params->supported_rates && params->supported_rates_len) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001697 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1698 sband, params->supported_rates,
1699 params->supported_rates_len,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301700 &sta->sta.supp_rates[sband->band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001701 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001702
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001703 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001704 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001705 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001706
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001707 /* VHT can override some HT caps such as the A-MSDU max length */
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001708 if (params->vht_capa)
1709 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001710 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001711
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001712 if (params->he_capa)
1713 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1714 (void *)params->he_capa,
Johannes Berg1bb9a8a2020-05-28 21:34:38 +02001715 params->he_capa_len,
1716 (void *)params->he_6ghz_capa,
1717 sta);
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001718
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001719 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001720 /* returned value is only needed for rc update, but the
1721 * rc isn't initialized here yet, so ignore it
1722 */
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301723 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1724 sband->band);
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001725 }
1726
Ayala Beker52cfa1d2016-03-17 15:41:39 +02001727 if (params->support_p2p_ps >= 0)
1728 sta->sta.support_p2p_ps = params->support_p2p_ps;
1729
Johannes Berg13657702015-06-17 10:34:54 +02001730 if (ieee80211_vif_is_mesh(&sdata->vif))
1731 sta_apply_mesh_params(local, sta, params);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001732
Toke Høiland-Jørgensenb4809e92018-12-18 17:02:08 -08001733 if (params->airtime_weight)
Toke Høiland-Jørgensen24336472021-06-23 15:47:55 +02001734 sta_apply_airtime_params(local, sta, params);
1735
Toke Høiland-Jørgensenb4809e92018-12-18 17:02:08 -08001736
Arik Nemtsov68885a52014-06-11 17:18:19 +03001737 /* set the STA state after all sta info from usermode has been set */
Ayala Beker44674d92015-09-23 10:41:27 +02001738 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1739 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001740 ret = sta_apply_auth_flags(local, sta, mask, set);
1741 if (ret)
1742 return ret;
1743 }
1744
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001745 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001746}
1747
1748static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001749 const u8 *mac,
1750 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001751{
Johannes Berg14db74b2008-07-29 13:22:52 +02001752 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001753 struct sta_info *sta;
1754 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001755 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001756
Johannes Berg4fd69312007-12-19 02:03:35 +01001757 if (params->vlan) {
1758 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1759
Johannes Berg05c914f2008-09-11 00:01:58 +02001760 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1761 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001762 return -EINVAL;
1763 } else
1764 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1765
Joe Perchesb203ca32012-05-08 18:56:52 +00001766 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001767 return -EINVAL;
1768
Karthikeyan Periyasamy52dba8d2019-07-24 14:46:10 +05301769 if (!is_valid_ether_addr(mac))
Johannes Berg03e44972008-02-27 09:56:40 +01001770 return -EINVAL;
1771
Johannes Berg5fd2f91a2019-08-01 09:30:33 +02001772 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER) &&
1773 sdata->vif.type == NL80211_IFTYPE_STATION &&
1774 !sdata->u.mgd.associated)
1775 return -EINVAL;
1776
Johannes Berg03e44972008-02-27 09:56:40 +01001777 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001778 if (!sta)
1779 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001780
Ayala Beker44674d92015-09-23 10:41:27 +02001781 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1782 sta->sta.tdls = true;
Johannes Berg4fd69312007-12-19 02:03:35 +01001783
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001784 err = sta_apply_parameters(local, sta, params);
1785 if (err) {
1786 sta_info_free(local, sta);
1787 return err;
1788 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001789
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001790 /*
Ayala Beker44674d92015-09-23 10:41:27 +02001791 * for TDLS and for unassociated station, rate control should be
1792 * initialized only when rates are known and station is marked
1793 * authorized/associated
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001794 */
Ayala Beker44674d92015-09-23 10:41:27 +02001795 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1796 test_sta_flag(sta, WLAN_STA_ASSOC))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001797 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001798
Johannes Berg4ebdce12021-05-17 23:07:57 +02001799 return sta_info_insert(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001800}
1801
1802static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001803 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001804{
Johannes Berg14db74b2008-07-29 13:22:52 +02001805 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001806
Johannes Berg14db74b2008-07-29 13:22:52 +02001807 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1808
Jouni Malinen89c771e2014-10-10 20:52:40 +03001809 if (params->mac)
1810 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001811
Johannes Bergb998e8b2012-12-13 23:07:46 +01001812 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001813 return 0;
1814}
1815
1816static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001817 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001818 struct station_parameters *params)
1819{
Johannes Bergabe60632009-11-25 17:46:18 +01001820 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001821 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001822 struct sta_info *sta;
1823 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001824 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001825 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001826
Johannes Berg87be1e12011-12-14 12:20:29 +01001827 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001828
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001829 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001830 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001831 err = -ENOENT;
1832 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001833 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001834
Johannes Berg77ee7c82013-02-15 00:48:33 +01001835 switch (sdata->vif.type) {
1836 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001837 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001838 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001839 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001840 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001841 break;
1842 case NL80211_IFTYPE_ADHOC:
1843 statype = CFG80211_STA_IBSS;
1844 break;
1845 case NL80211_IFTYPE_STATION:
1846 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1847 statype = CFG80211_STA_AP_STA;
1848 break;
1849 }
1850 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1851 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1852 else
1853 statype = CFG80211_STA_TDLS_PEER_SETUP;
1854 break;
1855 case NL80211_IFTYPE_AP:
1856 case NL80211_IFTYPE_AP_VLAN:
Ayala Beker44674d92015-09-23 10:41:27 +02001857 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1858 statype = CFG80211_STA_AP_CLIENT;
1859 else
1860 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001861 break;
1862 default:
1863 err = -EOPNOTSUPP;
1864 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001865 }
1866
Johannes Berg77ee7c82013-02-15 00:48:33 +01001867 err = cfg80211_check_station_change(wiphy, params, statype);
1868 if (err)
1869 goto out_err;
1870
Johannes Bergd0709a62008-02-25 16:27:46 +01001871 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +01001872 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1873
Johannes Berg9bc383d2009-11-19 11:55:19 +01001874 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001875 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001876 err = -EBUSY;
1877 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001878 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001879
Eric Dumazetcf778b02012-01-12 04:41:32 +00001880 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03001881 __ieee80211_check_fast_rx_iface(vlansdata);
Felix Fietkau1ff4e8f2020-09-08 14:37:01 +02001882 drv_sta_set_4addr(local, sta->sdata, &sta->sta, true);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001883 }
1884
1885 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Seevalamuthu Mariappandd0b4552021-03-19 19:48:52 +05301886 sta->sdata->u.vlan.sta) {
1887 ieee80211_clear_fast_rx(sta);
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301888 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Seevalamuthu Mariappandd0b4552021-03-19 19:48:52 +05301889 }
Michael Braun72f15d52016-10-10 19:12:21 +02001890
1891 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1892 ieee80211_vif_dec_num_mcast(sta->sdata);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001893
Johannes Berg14db74b2008-07-29 13:22:52 +02001894 sta->sdata = vlansdata;
Michal Kazior464daaf2015-05-19 14:13:36 +02001895 ieee80211_check_fast_xmit(sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001896
Jouni Malinen3e493172019-09-11 16:03:05 +03001897 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
Michael Braun72f15d52016-10-10 19:12:21 +02001898 ieee80211_vif_inc_num_mcast(sta->sdata);
Jouni Malinen3e493172019-09-11 16:03:05 +03001899 cfg80211_send_layer2_update(sta->sdata->dev,
1900 sta->sta.addr);
1901 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001902 }
1903
Eliad Peller35b88622011-12-29 14:41:39 +02001904 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001905 if (err)
1906 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001907
Johannes Berg87be1e12011-12-14 12:20:29 +01001908 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001909
Jason Young808118c2011-03-10 16:43:19 -08001910 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001911 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001912 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03001913 ieee80211_recalc_ps_vif(sdata);
1914 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001915
Johannes Berg4fd69312007-12-19 02:03:35 +01001916 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001917out_err:
1918 mutex_unlock(&local->sta_mtx);
1919 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001920}
1921
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001922#ifdef CONFIG_MAC80211_MESH
1923static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001924 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001925{
Johannes Berg14db74b2008-07-29 13:22:52 +02001926 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001927 struct mesh_path *mpath;
1928 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001929
Johannes Berg14db74b2008-07-29 13:22:52 +02001930 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1931
Johannes Bergd0709a62008-02-25 16:27:46 +01001932 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001933 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001934 if (!sta) {
1935 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001936 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001937 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001938
Bob Copelandae76eef2013-03-29 09:38:39 -04001939 mpath = mesh_path_add(sdata, dst);
1940 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001941 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001942 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001943 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001944
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001945 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001946
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001947 rcu_read_unlock();
1948 return 0;
1949}
1950
1951static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001952 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001953{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001955
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001956 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001957 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001958
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001959 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001960 return 0;
1961}
1962
Johannes Berg3b3a0162014-05-19 17:19:31 +02001963static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1964 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001965{
Johannes Berg14db74b2008-07-29 13:22:52 +02001966 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001967 struct mesh_path *mpath;
1968 struct sta_info *sta;
1969
Johannes Berg14db74b2008-07-29 13:22:52 +02001970 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1971
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001972 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001973
Johannes Bergabe60632009-11-25 17:46:18 +01001974 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001975 if (!sta) {
1976 rcu_read_unlock();
1977 return -ENOENT;
1978 }
1979
Johannes Bergbf7cd942013-02-15 14:40:31 +01001980 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001981 if (!mpath) {
1982 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001983 return -ENOENT;
1984 }
1985
1986 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001987
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001988 rcu_read_unlock();
1989 return 0;
1990}
1991
1992static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1993 struct mpath_info *pinfo)
1994{
Johannes Berga3836e02011-05-12 15:11:37 +02001995 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1996
1997 if (next_hop_sta)
1998 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001999 else
Joe Perchesc84a67a2015-03-02 19:54:57 -08002000 eth_zero_addr(next_hop);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002001
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09002002 memset(pinfo, 0, sizeof(*pinfo));
2003
Bob Copeland2bdaf382016-02-28 20:03:56 -05002004 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002005
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002006 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00002007 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002008 MPATH_INFO_METRIC |
2009 MPATH_INFO_EXPTIME |
2010 MPATH_INFO_DISCOVERY_TIMEOUT |
2011 MPATH_INFO_DISCOVERY_RETRIES |
Julan Hsucc241632019-01-15 15:28:42 -08002012 MPATH_INFO_FLAGS |
Julan Hsu540bbcb2019-01-15 15:28:43 -08002013 MPATH_INFO_HOP_COUNT |
2014 MPATH_INFO_PATH_CHANGE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002015
2016 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00002017 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002018 pinfo->metric = mpath->metric;
2019 if (time_before(jiffies, mpath->exp_time))
2020 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
2021 pinfo->discovery_timeout =
2022 jiffies_to_msecs(mpath->discovery_timeout);
2023 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002024 if (mpath->flags & MESH_PATH_ACTIVE)
2025 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
2026 if (mpath->flags & MESH_PATH_RESOLVING)
2027 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00002028 if (mpath->flags & MESH_PATH_SN_VALID)
2029 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002030 if (mpath->flags & MESH_PATH_FIXED)
2031 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09002032 if (mpath->flags & MESH_PATH_RESOLVED)
2033 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Julan Hsucc241632019-01-15 15:28:42 -08002034 pinfo->hop_count = mpath->hop_count;
Julan Hsu540bbcb2019-01-15 15:28:43 -08002035 pinfo->path_change_count = mpath->path_change_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002036}
2037
2038static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
2039 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
2040
2041{
Johannes Berg14db74b2008-07-29 13:22:52 +02002042 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002043 struct mesh_path *mpath;
2044
Johannes Berg14db74b2008-07-29 13:22:52 +02002045 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2046
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002047 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01002048 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002049 if (!mpath) {
2050 rcu_read_unlock();
2051 return -ENOENT;
2052 }
2053 memcpy(dst, mpath->dst, ETH_ALEN);
2054 mpath_set_pinfo(mpath, next_hop, pinfo);
2055 rcu_read_unlock();
2056 return 0;
2057}
2058
2059static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02002060 int idx, u8 *dst, u8 *next_hop,
2061 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002062{
Johannes Berg14db74b2008-07-29 13:22:52 +02002063 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002064 struct mesh_path *mpath;
2065
Johannes Berg14db74b2008-07-29 13:22:52 +02002066 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2067
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002068 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01002069 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002070 if (!mpath) {
2071 rcu_read_unlock();
2072 return -ENOENT;
2073 }
2074 memcpy(dst, mpath->dst, ETH_ALEN);
2075 mpath_set_pinfo(mpath, next_hop, pinfo);
2076 rcu_read_unlock();
2077 return 0;
2078}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002079
Henning Roggea2db2ed2014-09-12 08:58:50 +02002080static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
2081 struct mpath_info *pinfo)
2082{
2083 memset(pinfo, 0, sizeof(*pinfo));
2084 memcpy(mpp, mpath->mpp, ETH_ALEN);
2085
Bob Copeland2bdaf382016-02-28 20:03:56 -05002086 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
Henning Roggea2db2ed2014-09-12 08:58:50 +02002087}
2088
2089static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
2090 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
2091
2092{
2093 struct ieee80211_sub_if_data *sdata;
2094 struct mesh_path *mpath;
2095
2096 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2097
2098 rcu_read_lock();
2099 mpath = mpp_path_lookup(sdata, dst);
2100 if (!mpath) {
2101 rcu_read_unlock();
2102 return -ENOENT;
2103 }
2104 memcpy(dst, mpath->dst, ETH_ALEN);
2105 mpp_set_pinfo(mpath, mpp, pinfo);
2106 rcu_read_unlock();
2107 return 0;
2108}
2109
2110static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
2111 int idx, u8 *dst, u8 *mpp,
2112 struct mpath_info *pinfo)
2113{
2114 struct ieee80211_sub_if_data *sdata;
2115 struct mesh_path *mpath;
2116
2117 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2118
2119 rcu_read_lock();
2120 mpath = mpp_path_lookup_by_idx(sdata, idx);
2121 if (!mpath) {
2122 rcu_read_unlock();
2123 return -ENOENT;
2124 }
2125 memcpy(dst, mpath->dst, ETH_ALEN);
2126 mpp_set_pinfo(mpath, mpp, pinfo);
2127 rcu_read_unlock();
2128 return 0;
2129}
2130
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002131static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002132 struct net_device *dev,
2133 struct mesh_config *conf)
2134{
2135 struct ieee80211_sub_if_data *sdata;
2136 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2137
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002138 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
2139 return 0;
2140}
2141
2142static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
2143{
2144 return (mask >> (parm-1)) & 0x1;
2145}
2146
Javier Cardonac80d5452010-12-16 17:37:49 -08002147static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
2148 const struct mesh_setup *setup)
2149{
2150 u8 *new_ie;
2151 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08002152 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
2153 struct ieee80211_sub_if_data, u.mesh);
Jouni Malinen08fad432020-04-25 18:57:12 +03002154 int i;
Javier Cardonac80d5452010-12-16 17:37:49 -08002155
Javier Cardona581a8b02011-04-07 15:08:27 -07002156 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08002157 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07002158 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08002159
Javier Cardona581a8b02011-04-07 15:08:27 -07002160 if (setup->ie_len) {
2161 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08002162 GFP_KERNEL);
2163 if (!new_ie)
2164 return -ENOMEM;
2165 }
Javier Cardona581a8b02011-04-07 15:08:27 -07002166 ifmsh->ie_len = setup->ie_len;
2167 ifmsh->ie = new_ie;
2168 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08002169
2170 /* now copy the rest of the setup parameters */
2171 ifmsh->mesh_id_len = setup->mesh_id_len;
2172 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07002173 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08002174 ifmsh->mesh_pp_id = setup->path_sel_proto;
2175 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08002176 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07002177 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07002178 ifmsh->security = IEEE80211_MESH_SEC_NONE;
Benjamin Berg0ab2e552017-05-16 11:23:13 +02002179 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
Javier Cardonab130e5c2011-05-03 16:57:07 -07002180 if (setup->is_authenticated)
2181 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
2182 if (setup->is_secure)
2183 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08002184
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08002185 /* mcast rate setting in Mesh Node */
2186 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
2187 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07002188 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08002189
Marco Porsch9bdbf042013-01-07 16:04:51 +01002190 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
2191 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
2192
Jouni Malinen08fad432020-04-25 18:57:12 +03002193 sdata->beacon_rate_set = false;
2194 if (wiphy_ext_feature_isset(sdata->local->hw.wiphy,
2195 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) {
2196 for (i = 0; i < NUM_NL80211_BANDS; i++) {
2197 sdata->beacon_rateidx_mask[i] =
2198 setup->beacon_rate.control[i].legacy;
2199 if (sdata->beacon_rateidx_mask[i])
2200 sdata->beacon_rate_set = true;
2201 }
2202 }
2203
Javier Cardonac80d5452010-12-16 17:37:49 -08002204 return 0;
2205}
2206
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002207static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01002208 struct net_device *dev, u32 mask,
2209 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002210{
2211 struct mesh_config *conf;
2212 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00002213 struct ieee80211_if_mesh *ifmsh;
2214
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002215 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00002216 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002217
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002218 /* Set the config options which we are interested in setting */
2219 conf = &(sdata->u.mesh.mshcfg);
2220 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
2221 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
2222 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
2223 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
2224 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
2225 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
2226 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
2227 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
2228 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
2229 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
2230 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
2231 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01002232 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08002233 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08002234 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
2235 if (ifmsh->user_mpm)
2236 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002237 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08002238 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07002239 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
2240 conf->dot11MeshNbrOffsetMaxNeighbor =
2241 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002242 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
2243 conf->dot11MeshHWMPmaxPREQretries =
2244 nconf->dot11MeshHWMPmaxPREQretries;
2245 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
2246 conf->path_refresh_time = nconf->path_refresh_time;
2247 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
2248 conf->min_discovery_timeout = nconf->min_discovery_timeout;
2249 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
2250 conf->dot11MeshHWMPactivePathTimeout =
2251 nconf->dot11MeshHWMPactivePathTimeout;
2252 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
2253 conf->dot11MeshHWMPpreqMinInterval =
2254 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08002255 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
2256 conf->dot11MeshHWMPperrMinInterval =
2257 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002258 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2259 mask))
2260 conf->dot11MeshHWMPnetDiameterTraversalTime =
2261 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00002262 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
2263 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
2264 ieee80211_mesh_root_setup(ifmsh);
2265 }
Javier Cardona16dd7262011-08-09 16:45:11 -07002266 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07002267 /* our current gate announcement implementation rides on root
2268 * announcements, so require this ifmsh to also be a root node
2269 * */
2270 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08002271 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
2272 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07002273 ieee80211_mesh_root_setup(ifmsh);
2274 }
Javier Cardona16dd7262011-08-09 16:45:11 -07002275 conf->dot11MeshGateAnnouncementProtocol =
2276 nconf->dot11MeshGateAnnouncementProtocol;
2277 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08002278 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07002279 conf->dot11MeshHWMPRannInterval =
2280 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08002281 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2282 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08002283 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2284 /* our RSSI threshold implementation is supported only for
2285 * devices that report signal in dBm.
2286 */
Johannes Berg30686bf2015-06-02 21:39:54 +02002287 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
Ashok Nagarajan55335132012-02-28 17:04:08 -08002288 return -ENOTSUPP;
2289 conf->rssi_threshold = nconf->rssi_threshold;
2290 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07002291 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2292 conf->ht_opmode = nconf->ht_opmode;
2293 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2294 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2295 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08002296 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2297 conf->dot11MeshHWMPactivePathToRootTimeout =
2298 nconf->dot11MeshHWMPactivePathToRootTimeout;
2299 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2300 conf->dot11MeshHWMProotInterval =
2301 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08002302 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2303 conf->dot11MeshHWMPconfirmationInterval =
2304 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002305 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2306 conf->power_mode = nconf->power_mode;
2307 ieee80211_mps_local_status_update(sdata);
2308 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002309 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002310 conf->dot11MeshAwakeWindowDuration =
2311 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07002312 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2313 conf->plink_timeout = nconf->plink_timeout;
Bob Copeland01d66fb2018-10-25 17:36:34 -04002314 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2315 conf->dot11MeshConnectedToMeshGate =
2316 nconf->dot11MeshConnectedToMeshGate;
Linus Lüssinge3718a62020-06-17 09:30:33 +02002317 if (_chg_mesh_attr(NL80211_MESHCONF_NOLEARN, mask))
2318 conf->dot11MeshNolearn = nconf->dot11MeshNolearn;
Markus Theil184eebe2020-06-11 16:02:37 +02002319 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_AS, mask))
2320 conf->dot11MeshConnectedToAuthServer =
2321 nconf->dot11MeshConnectedToAuthServer;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002322 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002323 return 0;
2324}
2325
Johannes Berg29cbe682010-12-03 09:20:44 +01002326static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2327 const struct mesh_config *conf,
2328 const struct mesh_setup *setup)
2329{
2330 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2331 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08002332 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01002333
Javier Cardonac80d5452010-12-16 17:37:49 -08002334 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2335 err = copy_mesh_setup(ifmsh, setup);
2336 if (err)
2337 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002338
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002339 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2340
Johannes Berg04ecd252012-09-11 14:34:12 +02002341 /* can mesh use other SMPS modes? */
2342 sdata->smps_mode = IEEE80211_SMPS_OFF;
2343 sdata->needed_rx_chains = sdata->local->rx_chains;
2344
Johannes Berg34a37402013-12-18 09:43:33 +01002345 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01002346 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02002347 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01002348 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002349 if (err)
2350 return err;
2351
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002352 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01002353}
2354
2355static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2356{
2357 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2358
2359 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002360 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002361 ieee80211_vif_release_channel(sdata);
Remi Pommarel6a01afc2020-07-04 15:50:07 +02002362 kfree(sdata->u.mesh.ie);
Johannes Berg34a37402013-12-18 09:43:33 +01002363 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01002364
2365 return 0;
2366}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002367#endif
2368
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002369static int ieee80211_change_bss(struct wiphy *wiphy,
2370 struct net_device *dev,
2371 struct bss_parameters *params)
2372{
Johannes Berg55de9082012-07-26 17:24:39 +02002373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302374 struct ieee80211_supported_band *sband;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002375 u32 changed = 0;
2376
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01002377 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02002378 return -ENOENT;
2379
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302380 sband = ieee80211_get_sband(sdata);
2381 if (!sband)
2382 return -EINVAL;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002383
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002384 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002385 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002386 changed |= BSS_CHANGED_ERP_CTS_PROT;
2387 }
2388 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002389 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002390 params->use_short_preamble;
2391 changed |= BSS_CHANGED_ERP_PREAMBLE;
2392 }
Felix Fietkau43d35342010-01-15 03:00:48 +01002393
2394 if (!sdata->vif.bss_conf.use_short_slot &&
Tova Mussai07c12d62020-05-28 21:34:46 +02002395 (sband->band == NL80211_BAND_5GHZ ||
2396 sband->band == NL80211_BAND_6GHZ)) {
Felix Fietkau43d35342010-01-15 03:00:48 +01002397 sdata->vif.bss_conf.use_short_slot = true;
2398 changed |= BSS_CHANGED_ERP_SLOT;
2399 }
2400
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002401 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002402 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002403 params->use_short_slot_time;
2404 changed |= BSS_CHANGED_ERP_SLOT;
2405 }
2406
Jouni Malinen90c97a02008-10-30 16:59:22 +02002407 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002408 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302409 wiphy->bands[sband->band],
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002410 params->basic_rates,
2411 params->basic_rates_len,
2412 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002413 changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berge8e4f522017-03-08 11:12:10 +01002414 ieee80211_check_rate_mask(sdata);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002415 }
2416
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002417 if (params->ap_isolate >= 0) {
2418 if (params->ap_isolate)
2419 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2420 else
2421 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002422 ieee80211_check_fast_rx_iface(sdata);
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002423 }
2424
Helmut Schaa80d7e402010-11-19 12:40:26 +01002425 if (params->ht_opmode >= 0) {
2426 sdata->vif.bss_conf.ht_operation_mode =
2427 (u16) params->ht_opmode;
2428 changed |= BSS_CHANGED_HT;
2429 }
2430
Johannes Berg339afbf2012-11-14 15:21:17 +01002431 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002432 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2433 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2434 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2435 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002436 changed |= BSS_CHANGED_P2P_PS;
2437 }
2438
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002439 if (params->p2p_opp_ps > 0) {
2440 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2441 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2442 changed |= BSS_CHANGED_P2P_PS;
2443 } else if (params->p2p_opp_ps == 0) {
2444 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2445 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002446 changed |= BSS_CHANGED_P2P_PS;
2447 }
2448
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002449 ieee80211_bss_info_change_notify(sdata, changed);
2450
2451 return 0;
2452}
2453
Jouni Malinen31888482008-10-30 16:59:24 +02002454static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002455 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002456 struct ieee80211_txq_params *params)
2457{
2458 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002459 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002460 struct ieee80211_tx_queue_params p;
2461
2462 if (!local->ops->conf_tx)
2463 return -EOPNOTSUPP;
2464
Johannes Berg54bcbc62012-03-28 11:04:25 +02002465 if (local->hw.queues < IEEE80211_NUM_ACS)
2466 return -EOPNOTSUPP;
2467
Jouni Malinen31888482008-10-30 16:59:24 +02002468 memset(&p, 0, sizeof(p));
2469 p.aifs = params->aifs;
2470 p.cw_max = params->cwmax;
2471 p.cw_min = params->cwmin;
2472 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002473
2474 /*
2475 * Setting tx queue params disables u-apsd because it's only
2476 * called in master mode.
2477 */
2478 p.uapsd = false;
2479
Haim Dreyfusse552af02018-03-28 13:24:10 +03002480 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2481
Johannes Berga3304b02012-03-28 11:04:24 +02002482 sdata->tx_conf[params->ac] = p;
2483 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002484 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002485 "failed to set TX queue parameters for AC %d\n",
2486 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002487 return -EINVAL;
2488 }
2489
Johannes Berg7d257452012-07-06 17:37:43 +02002490 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2491
Jouni Malinen31888482008-10-30 16:59:24 +02002492 return 0;
2493}
2494
Bob Copeland665af4f2009-01-19 11:20:53 -05002495#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002496static int ieee80211_suspend(struct wiphy *wiphy,
2497 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002498{
Johannes Bergeecc4802011-05-04 15:37:29 +02002499 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002500}
2501
2502static int ieee80211_resume(struct wiphy *wiphy)
2503{
2504 return __ieee80211_resume(wiphy_priv(wiphy));
2505}
2506#else
2507#define ieee80211_suspend NULL
2508#define ieee80211_resume NULL
2509#endif
2510
Johannes Berg2a519312009-02-10 21:25:55 +01002511static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002512 struct cfg80211_scan_request *req)
2513{
Johannes Bergfd014282012-06-18 19:17:03 +02002514 struct ieee80211_sub_if_data *sdata;
2515
2516 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002517
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002518 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2519 case NL80211_IFTYPE_STATION:
2520 case NL80211_IFTYPE_ADHOC:
2521 case NL80211_IFTYPE_MESH_POINT:
2522 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002523 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002524 break;
2525 case NL80211_IFTYPE_P2P_GO:
2526 if (sdata->local->ops->hw_scan)
2527 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002528 /*
2529 * FIXME: implement NoA while scanning in software,
2530 * for now fall through to allow scanning only when
2531 * beaconing hasn't been configured yet
2532 */
Gustavo A. R. Silvafc0561d2020-07-07 15:45:48 -05002533 fallthrough;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002534 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002535 /*
2536 * If the scan has been forced (and the driver supports
2537 * forcing), don't care about being beaconing already.
2538 * This will create problems to the attached stations (e.g. all
2539 * the frames sent while scanning on other channel will be
2540 * lost)
2541 */
2542 if (sdata->u.ap.beacon &&
2543 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2544 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002545 return -EOPNOTSUPP;
2546 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002547 case NL80211_IFTYPE_NAN:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002548 default:
2549 return -EOPNOTSUPP;
2550 }
Johannes Berg2a519312009-02-10 21:25:55 +01002551
2552 return ieee80211_request_scan(sdata, req);
2553}
2554
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05302555static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2556{
2557 ieee80211_scan_cancel(wiphy_priv(wiphy));
2558}
2559
Luciano Coelho79f460c2011-05-11 17:09:36 +03002560static int
2561ieee80211_sched_scan_start(struct wiphy *wiphy,
2562 struct net_device *dev,
2563 struct cfg80211_sched_scan_request *req)
2564{
2565 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2566
2567 if (!sdata->local->ops->sched_scan_start)
2568 return -EOPNOTSUPP;
2569
2570 return ieee80211_request_sched_scan_start(sdata, req);
2571}
2572
2573static int
Arend Van Spriel3a3ecf12017-04-21 13:05:02 +01002574ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2575 u64 reqid)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002576{
Eliad Peller0d440ea2015-10-25 10:59:33 +02002577 struct ieee80211_local *local = wiphy_priv(wiphy);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002578
Eliad Peller0d440ea2015-10-25 10:59:33 +02002579 if (!local->ops->sched_scan_stop)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002580 return -EOPNOTSUPP;
2581
Eliad Peller0d440ea2015-10-25 10:59:33 +02002582 return ieee80211_request_sched_scan_stop(local);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002583}
2584
Jouni Malinen636a5d32009-03-19 13:39:22 +02002585static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2586 struct cfg80211_auth_request *req)
2587{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002588 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002589}
2590
2591static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2592 struct cfg80211_assoc_request *req)
2593{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002594 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002595}
2596
2597static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002598 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002599{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002600 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002601}
2602
2603static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002604 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002605{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002606 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002607}
2608
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002609static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2610 struct cfg80211_ibss_params *params)
2611{
Johannes Berg55de9082012-07-26 17:24:39 +02002612 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002613}
2614
2615static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2616{
Johannes Berg55de9082012-07-26 17:24:39 +02002617 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002618}
2619
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002620static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2621 struct ocb_setup *setup)
2622{
2623 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2624}
2625
2626static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2627{
2628 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2629}
2630
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002631static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002632 int rate[NUM_NL80211_BANDS])
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002633{
2634 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2635
Cong Ding9887dbf2013-02-06 17:23:45 +01002636 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002637 sizeof(int) * NUM_NL80211_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002638
Pradeep Kumar Chitrapudcbe73c2018-03-22 12:18:03 -07002639 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2640
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002641 return 0;
2642}
2643
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002644static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2645{
2646 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002647 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002648
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002649 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
Johannes Berg17c18bf2015-03-21 15:25:43 +01002650 ieee80211_check_fast_xmit_all(local);
2651
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002652 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2653
Johannes Berg17c18bf2015-03-21 15:25:43 +01002654 if (err) {
2655 ieee80211_check_fast_xmit_all(local);
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002656 return err;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002657 }
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002658 }
2659
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002660 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2661 (changed & WIPHY_PARAM_DYN_ACK)) {
2662 s16 coverage_class;
2663
2664 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2665 wiphy->coverage_class : -1;
2666 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002667
2668 if (err)
2669 return err;
2670 }
2671
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002672 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002673 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002674
Johannes Berg24487982009-04-23 18:52:52 +02002675 if (err)
2676 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002677 }
2678
Johannes Berg8bc83c22012-11-09 18:38:32 +01002679 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2680 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2681 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002682 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002683 }
2684 if (changed & WIPHY_PARAM_RETRY_LONG) {
2685 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2686 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002687 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002688 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002689 if (changed &
2690 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2691 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2692
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02002693 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2694 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2695 WIPHY_PARAM_TXQ_QUANTUM))
2696 ieee80211_txq_set_params(local);
2697
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002698 return 0;
2699}
2700
Johannes Berg7643a2c2009-06-02 13:01:39 +02002701static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002702 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002703 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002704{
2705 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002706 struct ieee80211_sub_if_data *sdata;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002707 enum nl80211_tx_power_setting txp_type = type;
2708 bool update_txp_type = false;
Peter Große3a3713e2017-12-13 18:29:46 +01002709 bool has_monitor = false;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002710
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002711 if (wdev) {
2712 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2713
Peter Große3a3713e2017-12-13 18:29:46 +01002714 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Berg6dd236032021-11-12 13:51:44 +01002715 sdata = wiphy_dereference(local->hw.wiphy,
2716 local->monitor_sdata);
Peter Große3a3713e2017-12-13 18:29:46 +01002717 if (!sdata)
2718 return -EOPNOTSUPP;
2719 }
2720
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002721 switch (type) {
2722 case NL80211_TX_POWER_AUTOMATIC:
2723 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002724 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002725 break;
2726 case NL80211_TX_POWER_LIMITED:
2727 case NL80211_TX_POWER_FIXED:
2728 if (mbm < 0 || (mbm % 100))
2729 return -EOPNOTSUPP;
2730 sdata->user_power_level = MBM_TO_DBM(mbm);
2731 break;
2732 }
2733
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002734 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2735 update_txp_type = true;
2736 sdata->vif.bss_conf.txpower_type = txp_type;
2737 }
2738
2739 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002740
2741 return 0;
2742 }
Johannes Berg55de9082012-07-26 17:24:39 +02002743
Johannes Berg7643a2c2009-06-02 13:01:39 +02002744 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002745 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002746 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002747 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002748 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002749 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002750 case NL80211_TX_POWER_FIXED:
2751 if (mbm < 0 || (mbm % 100))
2752 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002753 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002754 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002755 }
2756
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002757 mutex_lock(&local->iflist_mtx);
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002758 list_for_each_entry(sdata, &local->interfaces, list) {
Peter Große3a3713e2017-12-13 18:29:46 +01002759 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2760 has_monitor = true;
2761 continue;
2762 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002763 sdata->user_power_level = local->user_power_level;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002764 if (txp_type != sdata->vif.bss_conf.txpower_type)
2765 update_txp_type = true;
2766 sdata->vif.bss_conf.txpower_type = txp_type;
2767 }
Peter Große3a3713e2017-12-13 18:29:46 +01002768 list_for_each_entry(sdata, &local->interfaces, list) {
2769 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2770 continue;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002771 ieee80211_recalc_txpower(sdata, update_txp_type);
Peter Große3a3713e2017-12-13 18:29:46 +01002772 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002773 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002774
Peter Große3a3713e2017-12-13 18:29:46 +01002775 if (has_monitor) {
Johannes Berg6dd236032021-11-12 13:51:44 +01002776 sdata = wiphy_dereference(local->hw.wiphy,
2777 local->monitor_sdata);
Peter Große3a3713e2017-12-13 18:29:46 +01002778 if (sdata) {
2779 sdata->user_power_level = local->user_power_level;
2780 if (txp_type != sdata->vif.bss_conf.txpower_type)
2781 update_txp_type = true;
2782 sdata->vif.bss_conf.txpower_type = txp_type;
2783
2784 ieee80211_recalc_txpower(sdata, update_txp_type);
2785 }
2786 }
2787
Johannes Berg7643a2c2009-06-02 13:01:39 +02002788 return 0;
2789}
2790
Johannes Bergc8442112012-10-24 10:17:18 +02002791static int ieee80211_get_tx_power(struct wiphy *wiphy,
2792 struct wireless_dev *wdev,
2793 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002794{
2795 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002796 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002797
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002798 if (local->ops->get_txpower)
2799 return drv_get_txpower(local, sdata, dbm);
2800
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002801 if (!local->use_chanctx)
2802 *dbm = local->hw.conf.power_level;
2803 else
2804 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002805
Johannes Berg7643a2c2009-06-02 13:01:39 +02002806 return 0;
2807}
2808
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002809static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2810{
2811 struct ieee80211_local *local = wiphy_priv(wiphy);
2812
2813 drv_rfkill_poll(local);
2814}
2815
Johannes Bergaff89a92009-07-01 21:26:51 +02002816#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002817static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2818 struct wireless_dev *wdev,
2819 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002820{
2821 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002822 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002823
2824 if (!local->ops->testmode_cmd)
2825 return -EOPNOTSUPP;
2826
David Spinadel52981cd2013-07-31 18:06:22 +03002827 if (wdev) {
2828 struct ieee80211_sub_if_data *sdata;
2829
2830 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2831 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2832 vif = &sdata->vif;
2833 }
2834
2835 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002836}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002837
2838static int ieee80211_testmode_dump(struct wiphy *wiphy,
2839 struct sk_buff *skb,
2840 struct netlink_callback *cb,
2841 void *data, int len)
2842{
2843 struct ieee80211_local *local = wiphy_priv(wiphy);
2844
2845 if (!local->ops->testmode_dump)
2846 return -EOPNOTSUPP;
2847
2848 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2849}
Johannes Bergaff89a92009-07-01 21:26:51 +02002850#endif
2851
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002852int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2853 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002854{
2855 const u8 *ap;
2856 enum ieee80211_smps_mode old_req;
2857 int err;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002858 struct sta_info *sta;
2859 bool tdls_peer_found = false;
Johannes Berg0f782312009-12-01 13:37:02 +01002860
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002861 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002862
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002863 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2864 return -EINVAL;
2865
Johannes Berg0f782312009-12-01 13:37:02 +01002866 old_req = sdata->u.mgd.req_smps;
2867 sdata->u.mgd.req_smps = smps_mode;
2868
2869 if (old_req == smps_mode &&
2870 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2871 return 0;
2872
2873 /*
2874 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002875 * association, there's no need to do anything, just store
2876 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002877 */
2878 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002879 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002880 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002881
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002882 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002883
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002884 rcu_read_lock();
2885 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2886 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2887 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2888 continue;
2889
2890 tdls_peer_found = true;
2891 break;
2892 }
2893 rcu_read_unlock();
2894
Johannes Berg0f782312009-12-01 13:37:02 +01002895 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002896 if (tdls_peer_found || !sdata->u.mgd.powersave)
Johannes Berg0f782312009-12-01 13:37:02 +01002897 smps_mode = IEEE80211_SMPS_OFF;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002898 else
2899 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg0f782312009-12-01 13:37:02 +01002900 }
2901
2902 /* send SM PS frame to AP */
2903 err = ieee80211_send_smps_action(sdata, smps_mode,
2904 ap, ap);
2905 if (err)
2906 sdata->u.mgd.req_smps = old_req;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002907 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2908 ieee80211_teardown_tdls_peers(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002909
2910 return err;
2911}
2912
Johannes Bergbc92afd2009-07-01 21:26:57 +02002913static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2914 bool enabled, int timeout)
2915{
2916 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2917 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002918
Bob Copeland2d3db212013-10-29 18:11:59 -04002919 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002920 return -EOPNOTSUPP;
2921
Johannes Berg30686bf2015-06-02 21:39:54 +02002922 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002923 return -EOPNOTSUPP;
2924
2925 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002926 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002927 return 0;
2928
2929 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002930 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002931
Johannes Berg0f782312009-12-01 13:37:02 +01002932 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002933 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002934 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002935 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002936
Johannes Berg30686bf2015-06-02 21:39:54 +02002937 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002938 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2939
Johannes Berg4a733ef2015-10-14 18:02:43 +02002940 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03002941 ieee80211_recalc_ps_vif(sdata);
Felix Fietkau1d870162018-02-23 10:06:05 +01002942 ieee80211_check_fast_rx_iface(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002943
2944 return 0;
2945}
2946
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002947static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2948 struct net_device *dev,
2949 s32 rssi_thold, u32 rssi_hyst)
2950{
2951 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002952 struct ieee80211_vif *vif = &sdata->vif;
2953 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2954
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002955 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2956 rssi_hyst == bss_conf->cqm_rssi_hyst)
2957 return 0;
2958
Johannes Bergef9be102015-08-28 10:44:20 +02002959 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2960 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2961 return -EOPNOTSUPP;
2962
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002963 bss_conf->cqm_rssi_thold = rssi_thold;
2964 bss_conf->cqm_rssi_hyst = rssi_hyst;
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01002965 bss_conf->cqm_rssi_low = 0;
2966 bss_conf->cqm_rssi_high = 0;
2967 sdata->u.mgd.last_cqm_event_signal = 0;
2968
2969 /* tell the driver upon association, unless already associated */
2970 if (sdata->u.mgd.associated &&
2971 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2972 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2973
2974 return 0;
2975}
2976
2977static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2978 struct net_device *dev,
2979 s32 rssi_low, s32 rssi_high)
2980{
2981 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2982 struct ieee80211_vif *vif = &sdata->vif;
2983 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2984
2985 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2986 return -EOPNOTSUPP;
2987
2988 bss_conf->cqm_rssi_low = rssi_low;
2989 bss_conf->cqm_rssi_high = rssi_high;
2990 bss_conf->cqm_rssi_thold = 0;
2991 bss_conf->cqm_rssi_hyst = 0;
Sara Sharonbabc305e22015-09-21 15:47:40 +03002992 sdata->u.mgd.last_cqm_event_signal = 0;
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002993
2994 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002995 if (sdata->u.mgd.associated &&
2996 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002997 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2998
2999 return 0;
3000}
3001
Johannes Berg99303802009-07-01 21:26:59 +02003002static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
3003 struct net_device *dev,
3004 const u8 *addr,
3005 const struct cfg80211_bitrate_mask *mask)
3006{
3007 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3008 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05303009 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02003010
Eliad Peller554a43d2012-06-12 12:41:15 +03003011 if (!ieee80211_sdata_running(sdata))
3012 return -ENETDOWN;
3013
Johannes Berge8e4f522017-03-08 11:12:10 +01003014 /*
3015 * If active validate the setting and reject it if it doesn't leave
3016 * at least one basic rate usable, since we really have to be able
3017 * to send something, and if we're an AP we have to be able to do
3018 * so at a basic rate so that all clients can receive it.
3019 */
3020 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
3021 sdata->vif.bss_conf.chandef.chan) {
3022 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
3023 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
3024
3025 if (!(mask->control[band].legacy & basic_rates))
3026 return -EINVAL;
3027 }
3028
Johannes Berge5f5ce32017-10-18 09:36:51 +02003029 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
3030 ret = drv_set_bitrate_mask(local, sdata, mask);
3031 if (ret)
3032 return ret;
3033 }
3034
Johannes Berg57fbcce2016-04-12 15:56:15 +02003035 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02003036 struct ieee80211_supported_band *sband = wiphy->bands[i];
3037 int j;
3038
Jouni Malinen37eb0b12010-01-06 13:09:08 +02003039 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01003040 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
3041 sizeof(mask->control[i].ht_mcs));
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02003042 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
3043 mask->control[i].vht_mcs,
3044 sizeof(mask->control[i].vht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02003045
3046 sdata->rc_has_mcs_mask[i] = false;
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02003047 sdata->rc_has_vht_mcs_mask[i] = false;
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02003048 if (!sband)
3049 continue;
3050
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02003051 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
Johannes Berg19440152021-02-12 11:22:14 +01003052 if (sdata->rc_rateidx_mcs_mask[i][j] != 0xff) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02003053 sdata->rc_has_mcs_mask[i] = true;
3054 break;
Johannes Berg2df1b132015-08-21 14:07:13 +02003055 }
3056 }
3057
3058 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
Johannes Berg19440152021-02-12 11:22:14 +01003059 if (sdata->rc_rateidx_vht_mcs_mask[i][j] != 0xffff) {
Johannes Berg2df1b132015-08-21 14:07:13 +02003060 sdata->rc_has_vht_mcs_mask[i] = true;
3061 break;
3062 }
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02003063 }
Simon Wunderlich19468412012-01-28 17:25:33 +01003064 }
Johannes Berg99303802009-07-01 21:26:59 +02003065
Jouni Malinen37eb0b12010-01-06 13:09:08 +02003066 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02003067}
3068
Simon Wunderlich164eb022013-02-08 18:16:20 +01003069static int ieee80211_start_radar_detection(struct wiphy *wiphy,
3070 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01003071 struct cfg80211_chan_def *chandef,
3072 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01003073{
3074 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3075 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01003076 int err;
3077
Johannes Berg34a37402013-12-18 09:43:33 +01003078 mutex_lock(&local->mtx);
3079 if (!list_empty(&local->roc_list) || local->scanning) {
3080 err = -EBUSY;
3081 goto out_unlock;
3082 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01003083
3084 /* whatever, but channel contexts should not complain about that one */
3085 sdata->smps_mode = IEEE80211_SMPS_OFF;
3086 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01003087
Simon Wunderlich164eb022013-02-08 18:16:20 +01003088 err = ieee80211_vif_use_channel(sdata, chandef,
3089 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01003090 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01003091 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01003092
Simon Wunderlich164eb022013-02-08 18:16:20 +01003093 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01003094 &sdata->dfs_cac_timer_work,
3095 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01003096
Johannes Berg34a37402013-12-18 09:43:33 +01003097 out_unlock:
3098 mutex_unlock(&local->mtx);
3099 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01003100}
3101
Orr Mazor26ec17a2019-12-22 14:55:31 +00003102static void ieee80211_end_cac(struct wiphy *wiphy,
3103 struct net_device *dev)
3104{
3105 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3106 struct ieee80211_local *local = sdata->local;
3107
3108 mutex_lock(&local->mtx);
3109 list_for_each_entry(sdata, &local->interfaces, list) {
3110 /* it might be waiting for the local->mtx, but then
3111 * by the time it gets it, sdata->wdev.cac_started
3112 * will no longer be true
3113 */
3114 cancel_delayed_work(&sdata->dfs_cac_timer_work);
3115
3116 if (sdata->wdev.cac_started) {
3117 ieee80211_vif_release_channel(sdata);
3118 sdata->wdev.cac_started = false;
3119 }
3120 }
3121 mutex_unlock(&local->mtx);
3122}
3123
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003124static struct cfg80211_beacon_data *
3125cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
3126{
3127 struct cfg80211_beacon_data *new_beacon;
3128 u8 *pos;
3129 int len;
3130
3131 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
3132 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
Johannes Berg03b73862018-10-30 09:17:45 +01003133 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003134
3135 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
3136 if (!new_beacon)
3137 return NULL;
3138
3139 pos = (u8 *)(new_beacon + 1);
3140 if (beacon->head_len) {
3141 new_beacon->head_len = beacon->head_len;
3142 new_beacon->head = pos;
3143 memcpy(pos, beacon->head, beacon->head_len);
3144 pos += beacon->head_len;
3145 }
3146 if (beacon->tail_len) {
3147 new_beacon->tail_len = beacon->tail_len;
3148 new_beacon->tail = pos;
3149 memcpy(pos, beacon->tail, beacon->tail_len);
3150 pos += beacon->tail_len;
3151 }
3152 if (beacon->beacon_ies_len) {
3153 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
3154 new_beacon->beacon_ies = pos;
3155 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
3156 pos += beacon->beacon_ies_len;
3157 }
3158 if (beacon->proberesp_ies_len) {
3159 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
3160 new_beacon->proberesp_ies = pos;
3161 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
3162 pos += beacon->proberesp_ies_len;
3163 }
3164 if (beacon->assocresp_ies_len) {
3165 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3166 new_beacon->assocresp_ies = pos;
3167 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3168 pos += beacon->assocresp_ies_len;
3169 }
3170 if (beacon->probe_resp_len) {
3171 new_beacon->probe_resp_len = beacon->probe_resp_len;
Arnd Bergmannbee92d02018-02-02 16:31:23 +01003172 new_beacon->probe_resp = pos;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003173 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3174 pos += beacon->probe_resp_len;
3175 }
Johannes Berg03b73862018-10-30 09:17:45 +01003176
3177 /* might copy -1, meaning no changes requested */
3178 new_beacon->ftm_responder = beacon->ftm_responder;
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07003179 if (beacon->lci) {
3180 new_beacon->lci_len = beacon->lci_len;
3181 new_beacon->lci = pos;
3182 memcpy(pos, beacon->lci, beacon->lci_len);
3183 pos += beacon->lci_len;
3184 }
3185 if (beacon->civicloc) {
3186 new_beacon->civicloc_len = beacon->civicloc_len;
3187 new_beacon->civicloc = pos;
3188 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
3189 pos += beacon->civicloc_len;
3190 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003191
3192 return new_beacon;
3193}
3194
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003195void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003196{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003197 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3198
3199 ieee80211_queue_work(&sdata->local->hw,
3200 &sdata->csa_finalize_work);
3201}
3202EXPORT_SYMBOL(ieee80211_csa_finish);
3203
Nathan Errera6d501762021-11-29 15:32:38 +02003204void ieee80211_channel_switch_disconnect(struct ieee80211_vif *vif, bool block_tx)
3205{
3206 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3207 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3208 struct ieee80211_local *local = sdata->local;
3209
3210 sdata->csa_block_tx = block_tx;
3211 sdata_info(sdata, "channel switch failed, disconnecting\n");
3212 ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
3213}
3214EXPORT_SYMBOL(ieee80211_channel_switch_disconnect);
3215
Michal Kazior66199502014-04-09 15:11:00 +02003216static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
3217 u32 *changed)
3218{
3219 int err;
3220
3221 switch (sdata->vif.type) {
3222 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02003223 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
John Crispin5f9404a2021-07-02 19:44:08 +02003224 NULL, NULL);
Michal Kazior66199502014-04-09 15:11:00 +02003225 kfree(sdata->u.ap.next_beacon);
3226 sdata->u.ap.next_beacon = NULL;
3227
3228 if (err < 0)
3229 return err;
3230 *changed |= err;
3231 break;
3232 case NL80211_IFTYPE_ADHOC:
3233 err = ieee80211_ibss_finish_csa(sdata);
3234 if (err < 0)
3235 return err;
3236 *changed |= err;
3237 break;
3238#ifdef CONFIG_MAC80211_MESH
3239 case NL80211_IFTYPE_MESH_POINT:
3240 err = ieee80211_mesh_finish_csa(sdata);
3241 if (err < 0)
3242 return err;
3243 *changed |= err;
3244 break;
3245#endif
3246 default:
3247 WARN_ON(1);
3248 return -EINVAL;
3249 }
3250
3251 return 0;
3252}
3253
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003254static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003255{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003256 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02003257 u32 changed = 0;
3258 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003259
Michal Kaziordbd72852014-01-29 07:56:21 +01003260 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003261 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003262 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01003263
Michal Kazior03078de2014-06-25 12:35:08 +02003264 /*
3265 * using reservation isn't immediate as it may be deferred until later
3266 * with multi-vif. once reservation is complete it will re-schedule the
3267 * work with no reserved_chanctx so verify chandef to check if it
3268 * completed successfully
3269 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003270
Michal Kazior03078de2014-06-25 12:35:08 +02003271 if (sdata->reserved_chanctx) {
3272 /*
3273 * with multi-vif csa driver may call ieee80211_csa_finish()
3274 * many times while waiting for other interfaces to use their
3275 * reservations
3276 */
3277 if (sdata->reserved_ready)
3278 return 0;
3279
Fabian Frederick408b18a2014-10-09 20:36:22 +02003280 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03003281 }
3282
Michal Kazior03078de2014-06-25 12:35:08 +02003283 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3284 &sdata->csa_chandef))
3285 return -EINVAL;
3286
Simon Wunderliche487eae2013-11-21 18:19:51 +01003287 sdata->vif.csa_active = false;
Michal Kazior97518af12014-01-29 07:56:18 +01003288
Michal Kazior66199502014-04-09 15:11:00 +02003289 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3290 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003291 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003292
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003293 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02003294
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003295 if (sdata->csa_block_tx) {
3296 ieee80211_wake_vif_queues(local, sdata,
3297 IEEE80211_QUEUE_STOP_REASON_CSA);
3298 sdata->csa_block_tx = false;
3299 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003300
Luciano Coelhof1d65582014-10-08 09:48:38 +03003301 err = drv_post_channel_switch(sdata);
3302 if (err)
3303 return err;
3304
3305 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3306
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003307 return 0;
3308}
3309
3310static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3311{
3312 if (__ieee80211_csa_finalize(sdata)) {
3313 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3314 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3315 GFP_KERNEL);
3316 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003317}
3318
3319void ieee80211_csa_finalize_work(struct work_struct *work)
3320{
3321 struct ieee80211_sub_if_data *sdata =
3322 container_of(work, struct ieee80211_sub_if_data,
3323 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02003324 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003325
3326 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003327 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003328 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003329
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003330 /* AP might have been stopped while waiting for the lock. */
3331 if (!sdata->vif.csa_active)
3332 goto unlock;
3333
3334 if (!ieee80211_sdata_running(sdata))
3335 goto unlock;
3336
3337 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003338
3339unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02003340 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003341 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003342 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003343}
3344
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003345static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3346 struct cfg80211_csa_settings *params,
3347 u32 *changed)
3348{
Michal Kazioraf296bd2014-06-05 14:21:36 +02003349 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003350 int err;
3351
3352 switch (sdata->vif.type) {
3353 case NL80211_IFTYPE_AP:
3354 sdata->u.ap.next_beacon =
3355 cfg80211_beacon_dup(&params->beacon_after);
3356 if (!sdata->u.ap.next_beacon)
3357 return -ENOMEM;
3358
3359 /*
3360 * With a count of 0, we don't have to wait for any
3361 * TBTT before switching, so complete the CSA
3362 * immediately. In theory, with a count == 1 we
3363 * should delay the switch until just before the next
3364 * TBTT, but that would complicate things so we switch
3365 * immediately too. If we would delay the switch
3366 * until the next TBTT, we would have to set the probe
3367 * response here.
3368 *
3369 * TODO: A channel switch with count <= 1 without
3370 * sending a CSA action frame is kind of useless,
3371 * because the clients won't know we're changing
3372 * channels. The action frame must be implemented
3373 * either here or in the userspace.
3374 */
3375 if (params->count <= 1)
3376 break;
3377
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003378 if ((params->n_counter_offsets_beacon >
John Crispin8552a432020-08-11 10:01:04 +02003379 IEEE80211_MAX_CNTDWN_COUNTERS_NUM) ||
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003380 (params->n_counter_offsets_presp >
John Crispin8552a432020-08-11 10:01:04 +02003381 IEEE80211_MAX_CNTDWN_COUNTERS_NUM))
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003382 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003383
Michal Kazioraf296bd2014-06-05 14:21:36 +02003384 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3385 csa.counter_offsets_presp = params->counter_offsets_presp;
3386 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3387 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3388 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003389
John Crispin5f9404a2021-07-02 19:44:08 +02003390 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa, NULL);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003391 if (err < 0) {
3392 kfree(sdata->u.ap.next_beacon);
3393 return err;
3394 }
3395 *changed |= err;
3396
3397 break;
3398 case NL80211_IFTYPE_ADHOC:
3399 if (!sdata->vif.bss_conf.ibss_joined)
3400 return -EINVAL;
3401
3402 if (params->chandef.width != sdata->u.ibss.chandef.width)
3403 return -EINVAL;
3404
3405 switch (params->chandef.width) {
3406 case NL80211_CHAN_WIDTH_40:
3407 if (cfg80211_get_chandef_type(&params->chandef) !=
3408 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3409 return -EINVAL;
Gustavo A. R. Silvaaaaee2d2020-11-20 12:36:45 -06003410 break;
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003411 case NL80211_CHAN_WIDTH_5:
3412 case NL80211_CHAN_WIDTH_10:
3413 case NL80211_CHAN_WIDTH_20_NOHT:
3414 case NL80211_CHAN_WIDTH_20:
3415 break;
3416 default:
3417 return -EINVAL;
3418 }
3419
3420 /* changes into another band are not supported */
3421 if (sdata->u.ibss.chandef.chan->band !=
3422 params->chandef.chan->band)
3423 return -EINVAL;
3424
3425 /* see comments in the NL80211_IFTYPE_AP block */
3426 if (params->count > 1) {
3427 err = ieee80211_ibss_csa_beacon(sdata, params);
3428 if (err < 0)
3429 return err;
3430 *changed |= err;
3431 }
3432
3433 ieee80211_send_action_csa(sdata, params);
3434
3435 break;
3436#ifdef CONFIG_MAC80211_MESH
3437 case NL80211_IFTYPE_MESH_POINT: {
3438 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3439
3440 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3441 return -EINVAL;
3442
3443 /* changes into another band are not supported */
3444 if (sdata->vif.bss_conf.chandef.chan->band !=
3445 params->chandef.chan->band)
3446 return -EINVAL;
3447
3448 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3449 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3450 if (!ifmsh->pre_value)
3451 ifmsh->pre_value = 1;
3452 else
3453 ifmsh->pre_value++;
3454 }
3455
3456 /* see comments in the NL80211_IFTYPE_AP block */
3457 if (params->count > 1) {
3458 err = ieee80211_mesh_csa_beacon(sdata, params);
3459 if (err < 0) {
3460 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3461 return err;
3462 }
3463 *changed |= err;
3464 }
3465
3466 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3467 ieee80211_send_action_csa(sdata, params);
3468
3469 break;
3470 }
3471#endif
3472 default:
3473 return -EOPNOTSUPP;
3474 }
3475
3476 return 0;
3477}
3478
John Crispin5f9404a2021-07-02 19:44:08 +02003479static void ieee80211_color_change_abort(struct ieee80211_sub_if_data *sdata)
3480{
3481 sdata->vif.color_change_active = false;
3482 kfree(sdata->u.ap.next_beacon);
3483 sdata->u.ap.next_beacon = NULL;
3484
3485 cfg80211_color_change_aborted_notify(sdata->dev);
3486}
3487
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003488static int
3489__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3490 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003491{
3492 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3493 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003494 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003495 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003496 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003497 u32 changed = 0;
3498 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003499
Michal Kaziordbd72852014-01-29 07:56:21 +01003500 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003501 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003502
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003503 if (!list_empty(&local->roc_list) || local->scanning)
3504 return -EBUSY;
3505
3506 if (sdata->wdev.cac_started)
3507 return -EBUSY;
3508
3509 if (cfg80211_chandef_identical(&params->chandef,
3510 &sdata->vif.bss_conf.chandef))
3511 return -EINVAL;
3512
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003513 /* don't allow another channel switch if one is already active. */
3514 if (sdata->vif.csa_active)
3515 return -EBUSY;
3516
Michal Kazior03078de2014-06-25 12:35:08 +02003517 mutex_lock(&local->chanctx_mtx);
3518 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3519 lockdep_is_held(&local->chanctx_mtx));
3520 if (!conf) {
3521 err = -EBUSY;
3522 goto out;
3523 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003524
Thomas Pedersenb60119602020-04-01 18:18:04 -07003525 if (params->chandef.chan->freq_offset) {
3526 /* this may work, but is untested */
3527 err = -EOPNOTSUPP;
3528 goto out;
3529 }
3530
Michal Kazior03078de2014-06-25 12:35:08 +02003531 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
Michal Kazior03078de2014-06-25 12:35:08 +02003532
Luciano Coelho000baa52014-11-07 15:28:33 +02003533 ch_switch.timestamp = 0;
3534 ch_switch.device_timestamp = 0;
3535 ch_switch.block_tx = params->block_tx;
3536 ch_switch.chandef = params->chandef;
3537 ch_switch.count = params->count;
3538
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003539 err = drv_pre_channel_switch(sdata, &ch_switch);
3540 if (err)
3541 goto out;
3542
Michal Kazior03078de2014-06-25 12:35:08 +02003543 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3544 chanctx->mode,
3545 params->radar_required);
3546 if (err)
3547 goto out;
3548
3549 /* if reservation is invalid then this will fail */
3550 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3551 if (err) {
3552 ieee80211_vif_unreserve_chanctx(sdata);
3553 goto out;
3554 }
3555
John Crispin5f9404a2021-07-02 19:44:08 +02003556 /* if there is a color change in progress, abort it */
3557 if (sdata->vif.color_change_active)
3558 ieee80211_color_change_abort(sdata);
3559
Michal Kazior03078de2014-06-25 12:35:08 +02003560 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3561 if (err) {
3562 ieee80211_vif_unreserve_chanctx(sdata);
3563 goto out;
3564 }
3565
Luciano Coelho33787fc2013-11-11 20:34:54 +02003566 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003567 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003568 sdata->vif.csa_active = true;
3569
Michal Kazior59af6922014-04-09 15:10:59 +02003570 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003571 ieee80211_stop_vif_queues(local, sdata,
3572 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003573
Luciano Coelho2f457292014-11-07 14:31:36 +02003574 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
Johannes Berg669b8412020-11-29 17:30:55 +02003575 params->count, params->block_tx);
Luciano Coelho2f457292014-11-07 14:31:36 +02003576
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003577 if (changed) {
3578 ieee80211_bss_info_change_notify(sdata, changed);
3579 drv_channel_switch_beacon(sdata, &params->chandef);
3580 } else {
3581 /* if the beacon didn't change, we can finalize immediately */
3582 ieee80211_csa_finalize(sdata);
3583 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003584
Michal Kazior03078de2014-06-25 12:35:08 +02003585out:
3586 mutex_unlock(&local->chanctx_mtx);
3587 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003588}
3589
Michal Kazior59af6922014-04-09 15:10:59 +02003590int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3591 struct cfg80211_csa_settings *params)
3592{
3593 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3594 struct ieee80211_local *local = sdata->local;
3595 int err;
3596
3597 mutex_lock(&local->mtx);
3598 err = __ieee80211_channel_switch(wiphy, dev, params);
3599 mutex_unlock(&local->mtx);
3600
3601 return err;
3602}
3603
Johannes Berga2fcfccb2015-11-23 17:18:35 +01003604u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3605{
3606 lockdep_assert_held(&local->mtx);
3607
3608 local->roc_cookie_counter++;
3609
3610 /* wow, you wrapped 64 bits ... more likely a bug */
3611 if (WARN_ON(local->roc_cookie_counter == 0))
3612 local->roc_cookie_counter++;
3613
3614 return local->roc_cookie_counter;
3615}
3616
Johannes Berg5ee00db2015-11-24 14:25:49 +01003617int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3618 u64 *cookie, gfp_t gfp)
Johannes Berg3b79af92015-06-01 23:14:59 +02003619{
3620 unsigned long spin_flags;
3621 struct sk_buff *ack_skb;
3622 int id;
3623
3624 ack_skb = skb_copy(skb, gfp);
3625 if (!ack_skb)
Johannes Berg5ee00db2015-11-24 14:25:49 +01003626 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003627
3628 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3629 id = idr_alloc(&local->ack_status_frames, ack_skb,
Johannes Bergf2b18ba2020-01-15 12:25:50 +01003630 1, 0x2000, GFP_ATOMIC);
Johannes Berg3b79af92015-06-01 23:14:59 +02003631 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3632
3633 if (id < 0) {
3634 kfree_skb(ack_skb);
Johannes Berg5ee00db2015-11-24 14:25:49 +01003635 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003636 }
3637
3638 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3639
3640 *cookie = ieee80211_mgmt_tx_cookie(local);
3641 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3642
Johannes Berg5ee00db2015-11-24 14:25:49 +01003643 return 0;
Johannes Berg3b79af92015-06-01 23:14:59 +02003644}
3645
Johannes Berg6cd536f2020-04-17 12:43:01 +02003646static void
3647ieee80211_update_mgmt_frame_registrations(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003648 struct wireless_dev *wdev,
Johannes Berg6cd536f2020-04-17 12:43:01 +02003649 struct mgmt_frame_regs *upd)
Johannes Berg7be50862010-10-13 12:06:24 +02003650{
3651 struct ieee80211_local *local = wiphy_priv(wiphy);
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003652 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg6cd536f2020-04-17 12:43:01 +02003653 u32 preq_mask = BIT(IEEE80211_STYPE_PROBE_REQ >> 4);
Jouni Malinen873b1cf2020-04-21 17:48:15 +03003654 u32 action_mask = BIT(IEEE80211_STYPE_ACTION >> 4);
Johannes Berg6cd536f2020-04-17 12:43:01 +02003655 bool global_change, intf_change;
Johannes Berg7be50862010-10-13 12:06:24 +02003656
Johannes Berg6cd536f2020-04-17 12:43:01 +02003657 global_change =
Jouni Malinen873b1cf2020-04-21 17:48:15 +03003658 (local->probe_req_reg != !!(upd->global_stypes & preq_mask)) ||
3659 (local->rx_mcast_action_reg !=
3660 !!(upd->global_mcast_stypes & action_mask));
Johannes Berg6cd536f2020-04-17 12:43:01 +02003661 local->probe_req_reg = upd->global_stypes & preq_mask;
Jouni Malinen873b1cf2020-04-21 17:48:15 +03003662 local->rx_mcast_action_reg = upd->global_mcast_stypes & action_mask;
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003663
Jouni Malinen873b1cf2020-04-21 17:48:15 +03003664 intf_change = (sdata->vif.probe_req_reg !=
3665 !!(upd->interface_stypes & preq_mask)) ||
3666 (sdata->vif.rx_mcast_action_reg !=
3667 !!(upd->interface_mcast_stypes & action_mask));
Johannes Berg6cd536f2020-04-17 12:43:01 +02003668 sdata->vif.probe_req_reg = upd->interface_stypes & preq_mask;
Jouni Malinen873b1cf2020-04-21 17:48:15 +03003669 sdata->vif.rx_mcast_action_reg =
3670 upd->interface_mcast_stypes & action_mask;
Johannes Berg7be50862010-10-13 12:06:24 +02003671
Johannes Berg6cd536f2020-04-17 12:43:01 +02003672 if (!local->open_count)
3673 return;
Felix Fietkau35f51492012-10-31 15:50:34 +01003674
Johannes Berg6cd536f2020-04-17 12:43:01 +02003675 if (intf_change && ieee80211_sdata_running(sdata))
3676 drv_config_iface_filter(local, sdata,
3677 sdata->vif.probe_req_reg ?
3678 FIF_PROBE_REQ : 0,
3679 FIF_PROBE_REQ);
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003680
Johannes Berg6cd536f2020-04-17 12:43:01 +02003681 if (global_change)
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003682 ieee80211_configure_filter(local);
Johannes Berg7be50862010-10-13 12:06:24 +02003683}
3684
Bruno Randolf15d96752010-11-10 12:50:56 +09003685static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3686{
3687 struct ieee80211_local *local = wiphy_priv(wiphy);
3688
3689 if (local->started)
3690 return -EOPNOTSUPP;
3691
3692 return drv_set_antenna(local, tx_ant, rx_ant);
3693}
3694
3695static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3696{
3697 struct ieee80211_local *local = wiphy_priv(wiphy);
3698
3699 return drv_get_antenna(local, tx_ant, rx_ant);
3700}
3701
Johannes Bergc68f4b82011-07-05 16:35:41 +02003702static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3703 struct net_device *dev,
3704 struct cfg80211_gtk_rekey_data *data)
3705{
3706 struct ieee80211_local *local = wiphy_priv(wiphy);
3707 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3708
3709 if (!local->ops->set_rekey_data)
3710 return -EOPNOTSUPP;
3711
3712 drv_set_rekey_data(local, sdata, data);
3713
3714 return 0;
3715}
3716
Johannes Berg06500732011-11-04 11:18:16 +01003717static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3718 const u8 *peer, u64 *cookie)
3719{
3720 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3721 struct ieee80211_local *local = sdata->local;
3722 struct ieee80211_qos_hdr *nullfunc;
Johannes Berg5ee00db2015-11-24 14:25:49 +01003723 struct sk_buff *skb;
Johannes Berg06500732011-11-04 11:18:16 +01003724 int size = sizeof(*nullfunc);
3725 __le16 fc;
3726 bool qos;
3727 struct ieee80211_tx_info *info;
3728 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003729 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg57fbcce2016-04-12 15:56:15 +02003730 enum nl80211_band band;
Johannes Berg3b79af92015-06-01 23:14:59 +02003731 int ret;
3732
3733 /* the lock is needed to assign the cookie later */
3734 mutex_lock(&local->mtx);
Johannes Berg06500732011-11-04 11:18:16 +01003735
3736 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003737 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3738 if (WARN_ON(!chanctx_conf)) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003739 ret = -EINVAL;
3740 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003741 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003742 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003743 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003744 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003745 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003746 } else {
Johannes Berg3b79af92015-06-01 23:14:59 +02003747 ret = -ENOLINK;
3748 goto unlock;
Johannes Bergb4487c22011-11-11 20:22:30 +01003749 }
Johannes Berg06500732011-11-04 11:18:16 +01003750
3751 if (qos) {
3752 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3753 IEEE80211_STYPE_QOS_NULLFUNC |
3754 IEEE80211_FCTL_FROMDS);
3755 } else {
3756 size -= 2;
3757 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3758 IEEE80211_STYPE_NULLFUNC |
3759 IEEE80211_FCTL_FROMDS);
3760 }
3761
3762 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003763 if (!skb) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003764 ret = -ENOMEM;
3765 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003766 }
Johannes Berg06500732011-11-04 11:18:16 +01003767
3768 skb->dev = dev;
3769
3770 skb_reserve(skb, local->hw.extra_tx_headroom);
3771
Johannes Berg4df864c2017-06-16 14:29:21 +02003772 nullfunc = skb_put(skb, size);
Johannes Berg06500732011-11-04 11:18:16 +01003773 nullfunc->frame_control = fc;
3774 nullfunc->duration_id = 0;
3775 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3776 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3777 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3778 nullfunc->seq_ctrl = 0;
3779
3780 info = IEEE80211_SKB_CB(skb);
3781
3782 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3783 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003784 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003785
3786 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3787 skb->priority = 7;
3788 if (qos)
3789 nullfunc->qos_ctrl = cpu_to_le16(7);
3790
Johannes Berg5ee00db2015-11-24 14:25:49 +01003791 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3792 if (ret) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003793 kfree_skb(skb);
Johannes Berg3b79af92015-06-01 23:14:59 +02003794 goto unlock;
3795 }
3796
Johannes Berg06500732011-11-04 11:18:16 +01003797 local_bh_disable();
Mathy Vanhoef08aca292020-07-23 14:01:52 +04003798 ieee80211_xmit(sdata, sta, skb);
Johannes Berg06500732011-11-04 11:18:16 +01003799 local_bh_enable();
3800
Johannes Berg3b79af92015-06-01 23:14:59 +02003801 ret = 0;
3802unlock:
3803 rcu_read_unlock();
3804 mutex_unlock(&local->mtx);
3805
3806 return ret;
Johannes Berg06500732011-11-04 11:18:16 +01003807}
3808
Johannes Berg683b6d32012-11-08 21:25:48 +01003809static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3810 struct wireless_dev *wdev,
3811 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003812{
Johannes Berg55de9082012-07-26 17:24:39 +02003813 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003814 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003815 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003816 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003817
Johannes Berg55de9082012-07-26 17:24:39 +02003818 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003819 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3820 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003821 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003822 ret = 0;
3823 } else if (local->open_count > 0 &&
3824 local->open_count == local->monitors &&
3825 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3826 if (local->use_chanctx)
3827 *chandef = local->monitor_chandef;
3828 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003829 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003830 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003831 }
3832 rcu_read_unlock();
3833
Johannes Berg683b6d32012-11-08 21:25:48 +01003834 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003835}
3836
Johannes Berg6d525632012-04-04 15:05:25 +02003837#ifdef CONFIG_PM
3838static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3839{
3840 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3841}
3842#endif
3843
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003844static int ieee80211_set_qos_map(struct wiphy *wiphy,
3845 struct net_device *dev,
3846 struct cfg80211_qos_map *qos_map)
3847{
3848 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3849 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3850
3851 if (qos_map) {
3852 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3853 if (!new_qos_map)
3854 return -ENOMEM;
3855 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3856 } else {
3857 /* A NULL qos_map was passed to disable QoS mapping */
3858 new_qos_map = NULL;
3859 }
3860
Johannes Berg194ff522013-12-30 23:12:37 +01003861 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003862 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3863 if (old_qos_map)
3864 kfree_rcu(old_qos_map, rcu_head);
3865
3866 return 0;
3867}
3868
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003869static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3870 struct net_device *dev,
3871 struct cfg80211_chan_def *chandef)
3872{
3873 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3874 int ret;
3875 u32 changed = 0;
3876
3877 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3878 if (ret == 0)
3879 ieee80211_bss_info_change_notify(sdata, changed);
3880
3881 return ret;
3882}
3883
Johannes Berg02219b32014-10-07 10:38:50 +03003884static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3885 u8 tsid, const u8 *peer, u8 up,
3886 u16 admitted_time)
3887{
3888 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3889 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3890 int ac = ieee802_1d_to_ac[up];
3891
3892 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3893 return -EOPNOTSUPP;
3894
3895 if (!(sdata->wmm_acm & BIT(up)))
3896 return -EINVAL;
3897
3898 if (ifmgd->tx_tspec[ac].admitted_time)
3899 return -EBUSY;
3900
3901 if (admitted_time) {
3902 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3903 ifmgd->tx_tspec[ac].tsid = tsid;
3904 ifmgd->tx_tspec[ac].up = up;
3905 }
3906
3907 return 0;
3908}
3909
3910static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3911 u8 tsid, const u8 *peer)
3912{
3913 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3914 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3915 struct ieee80211_local *local = wiphy_priv(wiphy);
3916 int ac;
3917
3918 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3919 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3920
3921 /* skip unused entries */
3922 if (!tx_tspec->admitted_time)
3923 continue;
3924
3925 if (tx_tspec->tsid != tsid)
3926 continue;
3927
3928 /* due to this new packets will be reassigned to non-ACM ACs */
3929 tx_tspec->up = -1;
3930
3931 /* Make sure that all packets have been sent to avoid to
3932 * restore the QoS params on packets that are still on the
3933 * queues.
3934 */
3935 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003936 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003937
3938 /* restore the normal QoS parameters
3939 * (unconditionally to avoid races)
3940 */
3941 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3942 tx_tspec->downgraded = false;
3943 ieee80211_sta_handle_tspec_ac_params(sdata);
3944
3945 /* finally clear all the data */
3946 memset(tx_tspec, 0, sizeof(*tx_tspec));
3947
3948 return 0;
3949 }
3950
3951 return -ENOENT;
3952}
3953
Ayala Beker167e33f2016-09-20 17:31:20 +03003954void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3955 u8 inst_id,
3956 enum nl80211_nan_func_term_reason reason,
3957 gfp_t gfp)
3958{
3959 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3960 struct cfg80211_nan_func *func;
3961 u64 cookie;
3962
3963 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3964 return;
3965
3966 spin_lock_bh(&sdata->u.nan.func_lock);
3967
3968 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3969 if (WARN_ON(!func)) {
3970 spin_unlock_bh(&sdata->u.nan.func_lock);
3971 return;
3972 }
3973
3974 cookie = func->cookie;
3975 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3976
3977 spin_unlock_bh(&sdata->u.nan.func_lock);
3978
3979 cfg80211_free_nan_func(func);
3980
3981 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3982 reason, cookie, gfp);
3983}
3984EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3985
Ayala Beker92bc43b2016-09-20 17:31:21 +03003986void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3987 struct cfg80211_nan_match_params *match,
3988 gfp_t gfp)
3989{
3990 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3991 struct cfg80211_nan_func *func;
3992
3993 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3994 return;
3995
3996 spin_lock_bh(&sdata->u.nan.func_lock);
3997
3998 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3999 if (WARN_ON(!func)) {
4000 spin_unlock_bh(&sdata->u.nan.func_lock);
4001 return;
4002 }
4003 match->cookie = func->cookie;
4004
4005 spin_unlock_bh(&sdata->u.nan.func_lock);
4006
4007 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
4008}
4009EXPORT_SYMBOL(ieee80211_nan_func_match);
4010
Michael Braunebceec82016-11-22 11:52:18 +01004011static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
4012 struct net_device *dev,
4013 const bool enabled)
4014{
4015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4016
4017 sdata->u.ap.multicast_to_unicast = enabled;
4018
4019 return 0;
4020}
4021
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02004022void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
4023 struct txq_info *txqi)
4024{
4025 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
4026 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
4027 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
4028 }
4029
4030 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
4031 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
4032 txqstats->backlog_packets = txqi->tin.backlog_packets;
4033 }
4034
4035 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
4036 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
4037 txqstats->flows = txqi->tin.flows;
4038 }
4039
4040 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
4041 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
4042 txqstats->drops = txqi->cstats.drop_count;
4043 }
4044
4045 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
4046 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
4047 txqstats->ecn_marks = txqi->cstats.ecn_mark;
4048 }
4049
4050 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
4051 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
4052 txqstats->overlimit = txqi->tin.overlimit;
4053 }
4054
4055 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
4056 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
4057 txqstats->collisions = txqi->tin.collisions;
4058 }
4059
4060 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
4061 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
4062 txqstats->tx_bytes = txqi->tin.tx_bytes;
4063 }
4064
4065 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
4066 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
4067 txqstats->tx_packets = txqi->tin.tx_packets;
4068 }
4069}
4070
4071static int ieee80211_get_txq_stats(struct wiphy *wiphy,
4072 struct wireless_dev *wdev,
4073 struct cfg80211_txq_stats *txqstats)
4074{
4075 struct ieee80211_local *local = wiphy_priv(wiphy);
4076 struct ieee80211_sub_if_data *sdata;
4077 int ret = 0;
4078
4079 if (!local->ops->wake_tx_queue)
4080 return 1;
4081
4082 spin_lock_bh(&local->fq.lock);
4083 rcu_read_lock();
4084
4085 if (wdev) {
4086 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
4087 if (!sdata->vif.txq) {
4088 ret = 1;
4089 goto out;
4090 }
4091 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
4092 } else {
4093 /* phy stats */
4094 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
4095 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
4096 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
4097 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
4098 BIT(NL80211_TXQ_STATS_COLLISIONS) |
4099 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
4100 txqstats->backlog_packets = local->fq.backlog;
4101 txqstats->backlog_bytes = local->fq.memory_usage;
4102 txqstats->overlimit = local->fq.overlimit;
4103 txqstats->overmemory = local->fq.overmemory;
4104 txqstats->collisions = local->fq.collisions;
4105 txqstats->max_flows = local->fq.flows_cnt;
4106 }
4107
4108out:
4109 rcu_read_unlock();
4110 spin_unlock_bh(&local->fq.lock);
4111
4112 return ret;
4113}
4114
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07004115static int
4116ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
4117 struct net_device *dev,
4118 struct cfg80211_ftm_responder_stats *ftm_stats)
4119{
4120 struct ieee80211_local *local = wiphy_priv(wiphy);
4121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4122
4123 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
4124}
4125
Johannes Bergcee70132018-10-16 11:24:47 +02004126static int
4127ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4128 struct cfg80211_pmsr_request *request)
4129{
4130 struct ieee80211_local *local = wiphy_priv(wiphy);
4131 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4132
4133 return drv_start_pmsr(local, sdata, request);
4134}
4135
4136static void
4137ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
4138 struct cfg80211_pmsr_request *request)
4139{
4140 struct ieee80211_local *local = wiphy_priv(wiphy);
4141 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
4142
4143 return drv_abort_pmsr(local, sdata, request);
4144}
4145
Tamizh chelvam370f51d2020-01-20 13:21:27 +05304146static int ieee80211_set_tid_config(struct wiphy *wiphy,
4147 struct net_device *dev,
4148 struct cfg80211_tid_config *tid_conf)
4149{
4150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4151 struct sta_info *sta;
4152 int ret;
4153
4154 if (!sdata->local->ops->set_tid_config)
4155 return -EOPNOTSUPP;
4156
4157 if (!tid_conf->peer)
4158 return drv_set_tid_config(sdata->local, sdata, NULL, tid_conf);
4159
4160 mutex_lock(&sdata->local->sta_mtx);
4161 sta = sta_info_get_bss(sdata, tid_conf->peer);
4162 if (!sta) {
4163 mutex_unlock(&sdata->local->sta_mtx);
4164 return -ENOENT;
4165 }
4166
4167 ret = drv_set_tid_config(sdata->local, sdata, &sta->sta, tid_conf);
4168 mutex_unlock(&sdata->local->sta_mtx);
4169
4170 return ret;
4171}
4172
4173static int ieee80211_reset_tid_config(struct wiphy *wiphy,
4174 struct net_device *dev,
Sergey Matyukevich60c2ef02020-04-24 14:29:02 +03004175 const u8 *peer, u8 tids)
Tamizh chelvam370f51d2020-01-20 13:21:27 +05304176{
4177 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4178 struct sta_info *sta;
4179 int ret;
4180
4181 if (!sdata->local->ops->reset_tid_config)
4182 return -EOPNOTSUPP;
4183
4184 if (!peer)
Sergey Matyukevich60c2ef02020-04-24 14:29:02 +03004185 return drv_reset_tid_config(sdata->local, sdata, NULL, tids);
Tamizh chelvam370f51d2020-01-20 13:21:27 +05304186
4187 mutex_lock(&sdata->local->sta_mtx);
4188 sta = sta_info_get_bss(sdata, peer);
4189 if (!sta) {
4190 mutex_unlock(&sdata->local->sta_mtx);
4191 return -ENOENT;
4192 }
4193
Sergey Matyukevich60c2ef02020-04-24 14:29:02 +03004194 ret = drv_reset_tid_config(sdata->local, sdata, &sta->sta, tids);
Tamizh chelvam370f51d2020-01-20 13:21:27 +05304195 mutex_unlock(&sdata->local->sta_mtx);
4196
4197 return ret;
4198}
4199
Carl Huangc534e092020-12-03 05:37:27 -05004200static int ieee80211_set_sar_specs(struct wiphy *wiphy,
4201 struct cfg80211_sar_specs *sar)
4202{
4203 struct ieee80211_local *local = wiphy_priv(wiphy);
4204
4205 if (!local->ops->set_sar_specs)
4206 return -EOPNOTSUPP;
4207
4208 return local->ops->set_sar_specs(&local->hw, sar);
4209}
4210
John Crispin5f9404a2021-07-02 19:44:08 +02004211static int
4212ieee80211_set_after_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4213 u32 *changed)
4214{
4215 switch (sdata->vif.type) {
4216 case NL80211_IFTYPE_AP: {
4217 int ret;
4218
4219 ret = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
4220 NULL, NULL);
4221 kfree(sdata->u.ap.next_beacon);
4222 sdata->u.ap.next_beacon = NULL;
4223
4224 if (ret < 0)
4225 return ret;
4226
4227 *changed |= ret;
4228 break;
4229 }
4230 default:
4231 WARN_ON_ONCE(1);
4232 return -EINVAL;
4233 }
4234
4235 return 0;
4236}
4237
4238static int
4239ieee80211_set_color_change_beacon(struct ieee80211_sub_if_data *sdata,
4240 struct cfg80211_color_change_settings *params,
4241 u32 *changed)
4242{
4243 struct ieee80211_color_change_settings color_change = {};
4244 int err;
4245
4246 switch (sdata->vif.type) {
4247 case NL80211_IFTYPE_AP:
4248 sdata->u.ap.next_beacon =
4249 cfg80211_beacon_dup(&params->beacon_next);
4250 if (!sdata->u.ap.next_beacon)
4251 return -ENOMEM;
4252
4253 if (params->count <= 1)
4254 break;
4255
4256 color_change.counter_offset_beacon =
4257 params->counter_offset_beacon;
4258 color_change.counter_offset_presp =
4259 params->counter_offset_presp;
4260 color_change.count = params->count;
4261
4262 err = ieee80211_assign_beacon(sdata, &params->beacon_color_change,
4263 NULL, &color_change);
4264 if (err < 0) {
4265 kfree(sdata->u.ap.next_beacon);
4266 return err;
4267 }
4268 *changed |= err;
4269 break;
4270 default:
4271 return -EOPNOTSUPP;
4272 }
4273
4274 return 0;
4275}
4276
4277static void
4278ieee80211_color_change_bss_config_notify(struct ieee80211_sub_if_data *sdata,
4279 u8 color, int enable, u32 changed)
4280{
4281 sdata->vif.bss_conf.he_bss_color.color = color;
4282 sdata->vif.bss_conf.he_bss_color.enabled = enable;
4283 changed |= BSS_CHANGED_HE_BSS_COLOR;
4284
4285 ieee80211_bss_info_change_notify(sdata, changed);
John Crispineb87d3e2021-11-17 16:27:27 +05304286
4287 if (!sdata->vif.bss_conf.nontransmitted && sdata->vif.mbssid_tx_vif) {
4288 struct ieee80211_sub_if_data *child;
4289
4290 mutex_lock(&sdata->local->iflist_mtx);
4291 list_for_each_entry(child, &sdata->local->interfaces, list) {
4292 if (child != sdata && child->vif.mbssid_tx_vif == &sdata->vif) {
4293 child->vif.bss_conf.he_bss_color.color = color;
4294 child->vif.bss_conf.he_bss_color.enabled = enable;
4295 ieee80211_bss_info_change_notify(child,
4296 BSS_CHANGED_HE_BSS_COLOR);
4297 }
4298 }
4299 mutex_unlock(&sdata->local->iflist_mtx);
4300 }
John Crispin5f9404a2021-07-02 19:44:08 +02004301}
4302
4303static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
4304{
4305 struct ieee80211_local *local = sdata->local;
4306 u32 changed = 0;
4307 int err;
4308
4309 sdata_assert_lock(sdata);
4310 lockdep_assert_held(&local->mtx);
4311
4312 sdata->vif.color_change_active = false;
4313
4314 err = ieee80211_set_after_color_change_beacon(sdata, &changed);
4315 if (err) {
4316 cfg80211_color_change_aborted_notify(sdata->dev);
4317 return err;
4318 }
4319
4320 ieee80211_color_change_bss_config_notify(sdata,
4321 sdata->vif.color_change_color,
4322 1, changed);
4323 cfg80211_color_change_notify(sdata->dev);
4324
4325 return 0;
4326}
4327
4328void ieee80211_color_change_finalize_work(struct work_struct *work)
4329{
4330 struct ieee80211_sub_if_data *sdata =
4331 container_of(work, struct ieee80211_sub_if_data,
4332 color_change_finalize_work);
4333 struct ieee80211_local *local = sdata->local;
4334
4335 sdata_lock(sdata);
4336 mutex_lock(&local->mtx);
4337
4338 /* AP might have been stopped while waiting for the lock. */
4339 if (!sdata->vif.color_change_active)
4340 goto unlock;
4341
4342 if (!ieee80211_sdata_running(sdata))
4343 goto unlock;
4344
4345 ieee80211_color_change_finalize(sdata);
4346
4347unlock:
4348 mutex_unlock(&local->mtx);
4349 sdata_unlock(sdata);
4350}
4351
4352void ieee80211_color_change_finish(struct ieee80211_vif *vif)
4353{
4354 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4355
4356 ieee80211_queue_work(&sdata->local->hw,
4357 &sdata->color_change_finalize_work);
4358}
4359EXPORT_SYMBOL_GPL(ieee80211_color_change_finish);
4360
4361void
4362ieeee80211_obss_color_collision_notify(struct ieee80211_vif *vif,
4363 u64 color_bitmap)
4364{
4365 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
4366
4367 if (sdata->vif.color_change_active || sdata->vif.csa_active)
4368 return;
4369
4370 cfg80211_obss_color_collision_notify(sdata->dev, color_bitmap);
4371}
4372EXPORT_SYMBOL_GPL(ieeee80211_obss_color_collision_notify);
4373
4374static int
4375ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
4376 struct cfg80211_color_change_settings *params)
4377{
4378 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4379 struct ieee80211_local *local = sdata->local;
4380 u32 changed = 0;
4381 int err;
4382
4383 sdata_assert_lock(sdata);
4384
John Crispineb87d3e2021-11-17 16:27:27 +05304385 if (sdata->vif.bss_conf.nontransmitted)
4386 return -EINVAL;
4387
John Crispin5f9404a2021-07-02 19:44:08 +02004388 mutex_lock(&local->mtx);
4389
4390 /* don't allow another color change if one is already active or if csa
4391 * is active
4392 */
4393 if (sdata->vif.color_change_active || sdata->vif.csa_active) {
4394 err = -EBUSY;
4395 goto out;
4396 }
4397
4398 err = ieee80211_set_color_change_beacon(sdata, params, &changed);
4399 if (err)
4400 goto out;
4401
4402 sdata->vif.color_change_active = true;
4403 sdata->vif.color_change_color = params->color;
4404
4405 cfg80211_color_change_started_notify(sdata->dev, params->count);
4406
4407 if (changed)
4408 ieee80211_color_change_bss_config_notify(sdata, 0, 0, changed);
4409 else
4410 /* if the beacon didn't change, we can finalize immediately */
4411 ieee80211_color_change_finalize(sdata);
4412
4413out:
4414 mutex_unlock(&local->mtx);
4415
4416 return err;
4417}
4418
Lorenzo Bianconi237337c22021-10-23 11:10:51 +02004419static int
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +01004420ieee80211_set_radar_background(struct wiphy *wiphy,
4421 struct cfg80211_chan_def *chandef)
Lorenzo Bianconi237337c22021-10-23 11:10:51 +02004422{
4423 struct ieee80211_local *local = wiphy_priv(wiphy);
4424
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +01004425 if (!local->ops->set_radar_background)
Lorenzo Bianconi237337c22021-10-23 11:10:51 +02004426 return -EOPNOTSUPP;
4427
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +01004428 return local->ops->set_radar_background(&local->hw, chandef);
Lorenzo Bianconi237337c22021-10-23 11:10:51 +02004429}
4430
Johannes Berg8a47cea2014-01-20 23:55:44 +01004431const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07004432 .add_virtual_intf = ieee80211_add_iface,
4433 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02004434 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02004435 .start_p2p_device = ieee80211_start_p2p_device,
4436 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01004437 .add_key = ieee80211_add_key,
4438 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01004439 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01004440 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02004441 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Jouni Malinene5473e82020-02-22 15:25:44 +02004442 .set_default_beacon_key = ieee80211_config_default_beacon_key,
Johannes Berg88600202012-02-13 15:17:18 +01004443 .start_ap = ieee80211_start_ap,
4444 .change_beacon = ieee80211_change_beacon,
4445 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01004446 .add_station = ieee80211_add_station,
4447 .del_station = ieee80211_del_station,
4448 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01004449 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01004450 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02004451 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01004452#ifdef CONFIG_MAC80211_MESH
4453 .add_mpath = ieee80211_add_mpath,
4454 .del_mpath = ieee80211_del_mpath,
4455 .change_mpath = ieee80211_change_mpath,
4456 .get_mpath = ieee80211_get_mpath,
4457 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02004458 .get_mpp = ieee80211_get_mpp,
4459 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004460 .update_mesh_config = ieee80211_update_mesh_config,
4461 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01004462 .join_mesh = ieee80211_join_mesh,
4463 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01004464#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01004465 .join_ocb = ieee80211_join_ocb,
4466 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004467 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02004468 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02004469 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05004470 .suspend = ieee80211_suspend,
4471 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01004472 .scan = ieee80211_scan,
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05304473 .abort_scan = ieee80211_abort_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03004474 .sched_scan_start = ieee80211_sched_scan_start,
4475 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004476 .auth = ieee80211_auth,
4477 .assoc = ieee80211_assoc,
4478 .deauth = ieee80211_deauth,
4479 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02004480 .join_ibss = ieee80211_join_ibss,
4481 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01004482 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02004483 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02004484 .set_tx_power = ieee80211_set_tx_power,
4485 .get_tx_power = ieee80211_get_tx_power,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02004486 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02004487 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004488 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02004489 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02004490 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01004491 .remain_on_channel = ieee80211_remain_on_channel,
4492 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02004493 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01004494 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004495 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01004496 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
Johannes Berg6cd536f2020-04-17 12:43:01 +02004497 .update_mgmt_frame_registrations =
4498 ieee80211_update_mgmt_frame_registrations,
Bruno Randolf15d96752010-11-10 12:50:56 +09004499 .set_antenna = ieee80211_set_antenna,
4500 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02004501 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03004502 .tdls_oper = ieee80211_tdls_oper,
4503 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02004504 .tdls_channel_switch = ieee80211_tdls_channel_switch,
4505 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01004506 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01004507 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02004508#ifdef CONFIG_PM
4509 .set_wakeup = ieee80211_set_wakeup,
4510#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02004511 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01004512 .start_radar_detection = ieee80211_start_radar_detection,
Orr Mazor26ec17a2019-12-22 14:55:31 +00004513 .end_cac = ieee80211_end_cac,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02004514 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08004515 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03004516 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03004517 .add_tx_ts = ieee80211_add_tx_ts,
4518 .del_tx_ts = ieee80211_del_tx_ts,
Ayala Beker708d50e2016-09-20 17:31:14 +03004519 .start_nan = ieee80211_start_nan,
4520 .stop_nan = ieee80211_stop_nan,
Ayala Beker5953ff62016-09-20 17:31:19 +03004521 .nan_change_conf = ieee80211_nan_change_conf,
Ayala Beker167e33f2016-09-20 17:31:20 +03004522 .add_nan_func = ieee80211_add_nan_func,
4523 .del_nan_func = ieee80211_del_nan_func,
Michael Braunebceec82016-11-22 11:52:18 +01004524 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
Denis Kenzior91180642018-03-26 12:52:50 -05004525 .tx_control_port = ieee80211_tx_control_port,
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02004526 .get_txq_stats = ieee80211_get_txq_stats,
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07004527 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
Johannes Bergcee70132018-10-16 11:24:47 +02004528 .start_pmsr = ieee80211_start_pmsr,
4529 .abort_pmsr = ieee80211_abort_pmsr,
Rajkumar Manoharan8828f812019-04-11 13:47:26 -07004530 .probe_mesh_link = ieee80211_probe_mesh_link,
Tamizh chelvam370f51d2020-01-20 13:21:27 +05304531 .set_tid_config = ieee80211_set_tid_config,
4532 .reset_tid_config = ieee80211_reset_tid_config,
Carl Huangc534e092020-12-03 05:37:27 -05004533 .set_sar_specs = ieee80211_set_sar_specs,
John Crispin5f9404a2021-07-02 19:44:08 +02004534 .color_change = ieee80211_color_change,
Lorenzo Bianconia95bfb82021-11-29 14:11:24 +01004535 .set_radar_background = ieee80211_set_radar_background,
Jiri Bencf0706e82007-05-05 11:45:53 -07004536};