blob: e5e0f100389c4d810654b985aa133c2cf804690e [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergb2eb0ee2015-06-01 22:54:13 +02005 * Copyright 2013-2015 Intel Mobile Communications GmbH
Johannes Berge8e4f522017-03-08 11:12:10 +01006 * Copyright (C) 2015-2017 Intel Deutschland GmbH
Haim Dreyfusse552af02018-03-28 13:24:10 +03007 * Copyright (C) 2018 Intel Corporation
Jiri Bencf0706e82007-05-05 11:45:53 -07008 *
9 * This file is GPLv2 as found in COPYING.
10 */
11
Johannes Berge8cbb4c2007-12-19 02:03:30 +010012#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070013#include <linux/nl80211.h>
14#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070016#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010017#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030018#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070019#include <net/cfg80211.h>
20#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020021#include "driver-ops.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040022#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010023#include "mesh.h"
Johannes Berg02219b32014-10-07 10:38:50 +030024#include "wme.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010025
Johannes Berg65f1d602017-04-12 12:36:31 +020026static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata,
27 struct vif_params *params)
Johannes Berg8c5e6882017-04-12 10:46:13 +020028{
Johannes Berg8c5e6882017-04-12 10:46:13 +020029 bool mu_mimo_groups = false;
30 bool mu_mimo_follow = false;
31
Johannes Berg8c5e6882017-04-12 10:46:13 +020032 if (params->vht_mumimo_groups) {
33 u64 membership;
34
35 BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN);
36
Johannes Berg65f1d602017-04-12 12:36:31 +020037 memcpy(sdata->vif.bss_conf.mu_group.membership,
Johannes Berg8c5e6882017-04-12 10:46:13 +020038 params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN);
Johannes Berg65f1d602017-04-12 12:36:31 +020039 memcpy(sdata->vif.bss_conf.mu_group.position,
Johannes Berg8c5e6882017-04-12 10:46:13 +020040 params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN,
41 WLAN_USER_POSITION_LEN);
Johannes Berg65f1d602017-04-12 12:36:31 +020042 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS);
Johannes Berg8c5e6882017-04-12 10:46:13 +020043 /* don't care about endianness - just check for 0 */
44 memcpy(&membership, params->vht_mumimo_groups,
45 WLAN_MEMBERSHIP_LEN);
46 mu_mimo_groups = membership != 0;
47 }
48
49 if (params->vht_mumimo_follow_addr) {
50 mu_mimo_follow =
51 is_valid_ether_addr(params->vht_mumimo_follow_addr);
Johannes Berg65f1d602017-04-12 12:36:31 +020052 ether_addr_copy(sdata->u.mntr.mu_follow_addr,
Johannes Berg8c5e6882017-04-12 10:46:13 +020053 params->vht_mumimo_follow_addr);
54 }
55
Johannes Berg65f1d602017-04-12 12:36:31 +020056 sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow;
57}
58
59static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,
60 struct vif_params *params)
61{
62 struct ieee80211_local *local = sdata->local;
63 struct ieee80211_sub_if_data *monitor_sdata;
64
65 /* check flags first */
66 if (params->flags && ieee80211_sdata_running(sdata)) {
67 u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE;
68
69 /*
70 * Prohibit MONITOR_FLAG_COOK_FRAMES and
71 * MONITOR_FLAG_ACTIVE to be changed while the
72 * interface is up.
73 * Else we would need to add a lot of cruft
74 * to update everything:
75 * cooked_mntrs, monitor and all fif_* counters
76 * reconfigure hardware
77 */
78 if ((params->flags & mask) != (sdata->u.mntr.flags & mask))
79 return -EBUSY;
80 }
81
82 /* also validate MU-MIMO change */
83 monitor_sdata = rtnl_dereference(local->monitor_sdata);
84
85 if (!monitor_sdata &&
86 (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
87 return -EOPNOTSUPP;
88
89 /* apply all changes now - no failures allowed */
90
91 if (monitor_sdata)
92 ieee80211_set_mu_mimo_follow(monitor_sdata, params);
93
94 if (params->flags) {
95 if (ieee80211_sdata_running(sdata)) {
96 ieee80211_adjust_monitor_flags(sdata, -1);
97 sdata->u.mntr.flags = params->flags;
98 ieee80211_adjust_monitor_flags(sdata, 1);
99
100 ieee80211_configure_filter(local);
101 } else {
102 /*
103 * Because the interface is down, ieee80211_do_stop
104 * and ieee80211_do_open take care of "everything"
105 * mentioned in the comment above.
106 */
107 sdata->u.mntr.flags = params->flags;
108 }
109 }
Johannes Berg8c5e6882017-04-12 10:46:13 +0200110
111 return 0;
112}
113
Johannes Berg552bff02012-09-19 09:26:06 +0200114static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
115 const char *name,
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100116 unsigned char name_assign_type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200117 enum nl80211_iftype type,
Johannes Berg84efbb82012-06-16 00:00:26 +0200118 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -0700119{
120 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +0200121 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +0100122 struct ieee80211_sub_if_data *sdata;
123 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700124
Tom Gundersen6bab2e192015-03-18 11:13:39 +0100125 err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100126 if (err)
127 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +0100128
Johannes Berg8c5e6882017-04-12 10:46:13 +0200129 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
130
131 if (type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200132 err = ieee80211_set_mon_options(sdata, params);
Johannes Berg8c5e6882017-04-12 10:46:13 +0200133 if (err) {
134 ieee80211_if_remove(sdata);
135 return NULL;
136 }
Johannes Bergf9e10ce2010-12-03 09:20:42 +0100137 }
138
Johannes Berg84efbb82012-06-16 00:00:26 +0200139 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -0700140}
141
Johannes Berg84efbb82012-06-16 00:00:26 +0200142static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -0700143{
Johannes Berg84efbb82012-06-16 00:00:26 +0200144 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -0700145
Johannes Berg75636522008-07-09 14:40:35 +0200146 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700147}
148
Johannes Berge36d56b2009-06-09 21:04:43 +0200149static int ieee80211_change_iface(struct wiphy *wiphy,
150 struct net_device *dev,
Johannes Berg818a9862017-04-12 11:23:28 +0200151 enum nl80211_iftype type,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100152 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +0200153{
Johannes Berg9607e6b662009-12-23 13:15:31 +0100154 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +0200155 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200156
Johannes Berg05c914f2008-09-11 00:01:58 +0200157 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +0200158 if (ret)
159 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +0200160
Johannes Berg6f527282018-08-31 11:31:05 +0300161 if (type == NL80211_IFTYPE_AP_VLAN && params->use_4addr == 0) {
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000162 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300163 ieee80211_check_fast_rx_iface(sdata);
Johannes Berg6f527282018-08-31 11:31:05 +0300164 } else if (type == NL80211_IFTYPE_STATION && params->use_4addr >= 0) {
Johannes Berg9bc383d2009-11-19 11:55:19 +0100165 sdata->u.mgd.use_4addr = params->use_4addr;
Johannes Berg49ddf8e2016-03-31 20:02:10 +0300166 }
Johannes Berg9bc383d2009-11-19 11:55:19 +0100167
Aviya Erenfeld42bd20d2016-08-29 23:25:16 +0300168 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
Johannes Berg65f1d602017-04-12 12:36:31 +0200169 ret = ieee80211_set_mon_options(sdata, params);
170 if (ret)
171 return ret;
Christian Lamparter85416a42010-10-02 13:17:07 +0200172 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200173
Johannes Berg42613db2007-09-28 21:52:27 +0200174 return 0;
175}
176
Johannes Bergf142c6b2012-06-18 20:07:15 +0200177static int ieee80211_start_p2p_device(struct wiphy *wiphy,
178 struct wireless_dev *wdev)
179{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200180 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
181 int ret;
182
183 mutex_lock(&sdata->local->chanctx_mtx);
184 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
185 mutex_unlock(&sdata->local->chanctx_mtx);
186 if (ret < 0)
187 return ret;
188
Johannes Bergf142c6b2012-06-18 20:07:15 +0200189 return ieee80211_do_open(wdev, true);
190}
191
192static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
193 struct wireless_dev *wdev)
194{
195 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
196}
197
Ayala Beker708d50e2016-09-20 17:31:14 +0300198static int ieee80211_start_nan(struct wiphy *wiphy,
199 struct wireless_dev *wdev,
200 struct cfg80211_nan_conf *conf)
201{
202 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
203 int ret;
204
205 mutex_lock(&sdata->local->chanctx_mtx);
206 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
207 mutex_unlock(&sdata->local->chanctx_mtx);
208 if (ret < 0)
209 return ret;
210
211 ret = ieee80211_do_open(wdev, true);
212 if (ret)
213 return ret;
214
215 ret = drv_start_nan(sdata->local, sdata, conf);
216 if (ret)
217 ieee80211_sdata_stop(sdata);
218
Ayala Beker167e33f2016-09-20 17:31:20 +0300219 sdata->u.nan.conf = *conf;
220
Ayala Beker708d50e2016-09-20 17:31:14 +0300221 return ret;
222}
223
224static void ieee80211_stop_nan(struct wiphy *wiphy,
225 struct wireless_dev *wdev)
226{
227 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
228
229 drv_stop_nan(sdata->local, sdata);
230 ieee80211_sdata_stop(sdata);
231}
232
Ayala Beker5953ff62016-09-20 17:31:19 +0300233static int ieee80211_nan_change_conf(struct wiphy *wiphy,
234 struct wireless_dev *wdev,
235 struct cfg80211_nan_conf *conf,
236 u32 changes)
237{
238 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
239 struct cfg80211_nan_conf new_conf;
240 int ret = 0;
241
242 if (sdata->vif.type != NL80211_IFTYPE_NAN)
243 return -EOPNOTSUPP;
244
245 if (!ieee80211_sdata_running(sdata))
246 return -ENETDOWN;
247
248 new_conf = sdata->u.nan.conf;
249
250 if (changes & CFG80211_NAN_CONF_CHANGED_PREF)
251 new_conf.master_pref = conf->master_pref;
252
Luca Coelho85859892017-02-08 15:00:34 +0200253 if (changes & CFG80211_NAN_CONF_CHANGED_BANDS)
254 new_conf.bands = conf->bands;
Ayala Beker5953ff62016-09-20 17:31:19 +0300255
256 ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes);
257 if (!ret)
258 sdata->u.nan.conf = new_conf;
259
260 return ret;
261}
262
Ayala Beker167e33f2016-09-20 17:31:20 +0300263static int ieee80211_add_nan_func(struct wiphy *wiphy,
264 struct wireless_dev *wdev,
265 struct cfg80211_nan_func *nan_func)
266{
267 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
268 int ret;
269
270 if (sdata->vif.type != NL80211_IFTYPE_NAN)
271 return -EOPNOTSUPP;
272
273 if (!ieee80211_sdata_running(sdata))
274 return -ENETDOWN;
275
276 spin_lock_bh(&sdata->u.nan.func_lock);
277
278 ret = idr_alloc(&sdata->u.nan.function_inst_ids,
279 nan_func, 1, sdata->local->hw.max_nan_de_entries + 1,
280 GFP_ATOMIC);
281 spin_unlock_bh(&sdata->u.nan.func_lock);
282
283 if (ret < 0)
284 return ret;
285
286 nan_func->instance_id = ret;
287
288 WARN_ON(nan_func->instance_id == 0);
289
290 ret = drv_add_nan_func(sdata->local, sdata, nan_func);
291 if (ret) {
292 spin_lock_bh(&sdata->u.nan.func_lock);
293 idr_remove(&sdata->u.nan.function_inst_ids,
294 nan_func->instance_id);
295 spin_unlock_bh(&sdata->u.nan.func_lock);
296 }
297
298 return ret;
299}
300
301static struct cfg80211_nan_func *
302ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata,
303 u64 cookie)
304{
305 struct cfg80211_nan_func *func;
306 int id;
307
308 lockdep_assert_held(&sdata->u.nan.func_lock);
309
310 idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) {
311 if (func->cookie == cookie)
312 return func;
313 }
314
315 return NULL;
316}
317
318static void ieee80211_del_nan_func(struct wiphy *wiphy,
319 struct wireless_dev *wdev, u64 cookie)
320{
321 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
322 struct cfg80211_nan_func *func;
323 u8 instance_id = 0;
324
325 if (sdata->vif.type != NL80211_IFTYPE_NAN ||
326 !ieee80211_sdata_running(sdata))
327 return;
328
329 spin_lock_bh(&sdata->u.nan.func_lock);
330
331 func = ieee80211_find_nan_func_by_cookie(sdata, cookie);
332 if (func)
333 instance_id = func->instance_id;
334
335 spin_unlock_bh(&sdata->u.nan.func_lock);
336
337 if (instance_id)
338 drv_del_nan_func(sdata->local, sdata, instance_id);
339}
340
Simon Wunderlichb53be792011-11-18 14:20:44 +0100341static int ieee80211_set_noack_map(struct wiphy *wiphy,
342 struct net_device *dev,
343 u16 noack_map)
344{
345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
346
347 sdata->noack_map = noack_map;
Johannes Berg17c18bf2015-03-21 15:25:43 +0100348
349 ieee80211_check_fast_xmit_iface(sdata);
350
Simon Wunderlichb53be792011-11-18 14:20:44 +0100351 return 0;
352}
353
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100354static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200355 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100356 struct key_params *params)
357{
Johannes Berg26a58452010-08-27 12:35:55 +0200358 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200359 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100360 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200361 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100362 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200363 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100364
Johannes Berg26a58452010-08-27 12:35:55 +0200365 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200366 return -ENETDOWN;
367
Johannes Berg97359d12010-08-10 09:46:38 +0200368 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100369 switch (params->cipher) {
370 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100371 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200372 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200373 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200374 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200375 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200376 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200377 case WLAN_CIPHER_SUITE_CCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200378 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen56c52da2015-01-24 19:52:08 +0200379 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
Jouni Malinen8ade5382015-01-24 19:52:09 +0200380 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
381 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200382 case WLAN_CIPHER_SUITE_GCMP:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200383 case WLAN_CIPHER_SUITE_GCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200384 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100385 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200386 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200387 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100388 }
389
Johannes Berg97359d12010-08-10 09:46:38 +0200390 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200391 params->key, params->seq_len, params->seq,
392 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100393 if (IS_ERR(key))
394 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100395
Johannes Berge31b8212010-10-05 19:39:30 +0200396 if (pairwise)
397 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
398
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200399 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200400
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100401 if (mac_addr) {
Johannes Berg850092d2016-10-04 15:32:16 +0200402 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100403 /*
404 * The ASSOC test makes sure the driver is ready to
405 * receive the key. When wpa_supplicant has roamed
406 * using FT, it attempts to set the key before
407 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700408 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100409 *
410 * TODO: accept the key if we have a station entry and
411 * add it to the device after the station.
412 */
413 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100414 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200415 err = -ENOENT;
416 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100417 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100418 }
419
Johannes Berge548c492012-09-04 17:08:23 +0200420 switch (sdata->vif.type) {
421 case NL80211_IFTYPE_STATION:
422 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
423 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
424 break;
425 case NL80211_IFTYPE_AP:
426 case NL80211_IFTYPE_AP_VLAN:
427 /* Keys without a station are used for TX only */
Felix Fietkau211710c2018-09-29 16:01:58 +0200428 if (sta && test_sta_flag(sta, WLAN_STA_MFP))
Johannes Berge548c492012-09-04 17:08:23 +0200429 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
430 break;
431 case NL80211_IFTYPE_ADHOC:
432 /* no MFP (yet) */
433 break;
434 case NL80211_IFTYPE_MESH_POINT:
435#ifdef CONFIG_MAC80211_MESH
436 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
437 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
438 break;
439#endif
440 case NL80211_IFTYPE_WDS:
441 case NL80211_IFTYPE_MONITOR:
442 case NL80211_IFTYPE_P2P_DEVICE:
Ayala Bekercb3b7d82016-09-20 17:31:13 +0300443 case NL80211_IFTYPE_NAN:
Johannes Berge548c492012-09-04 17:08:23 +0200444 case NL80211_IFTYPE_UNSPECIFIED:
445 case NUM_NL80211_IFTYPES:
446 case NL80211_IFTYPE_P2P_CLIENT:
447 case NL80211_IFTYPE_P2P_GO:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100448 case NL80211_IFTYPE_OCB:
Johannes Berge548c492012-09-04 17:08:23 +0200449 /* shouldn't happen */
450 WARN_ON_ONCE(1);
451 break;
452 }
453
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200454 if (sta)
455 sta->cipher_scheme = cs;
456
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300457 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100458
Johannes Berg3b967662008-04-08 17:56:52 +0200459 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200460 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200461
462 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100463}
464
465static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200466 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100467{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200468 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
469 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100470 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200471 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100472 int ret;
473
Johannes Berg5c0c3642011-05-12 14:31:49 +0200474 mutex_lock(&local->sta_mtx);
475 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200476
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100477 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200478 ret = -ENOENT;
479
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100480 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100481 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200482 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100483
Johannes Berg5c0c3642011-05-12 14:31:49 +0200484 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200485 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200486 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200487 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200488 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200489 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100490
Johannes Berg5c0c3642011-05-12 14:31:49 +0200491 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200492 ret = -ENOENT;
493 goto out_unlock;
494 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100495
Manikanta Pubbisetty133bf902018-07-10 16:48:27 +0530496 ieee80211_key_free(key, sdata->vif.type == NL80211_IFTYPE_STATION);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100497
Johannes Berg3b967662008-04-08 17:56:52 +0200498 ret = 0;
499 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200500 mutex_unlock(&local->key_mtx);
501 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200502
503 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100504}
505
Johannes Berg62da92f2007-12-19 02:03:31 +0100506static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200507 u8 key_idx, bool pairwise, const u8 *mac_addr,
508 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100509 void (*callback)(void *cookie,
510 struct key_params *params))
511{
Johannes Berg14db74b2008-07-29 13:22:52 +0200512 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100513 struct sta_info *sta = NULL;
514 u8 seq[6] = {0};
515 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200516 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200517 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100518 u32 iv32;
519 u16 iv16;
520 int err = -ENOENT;
Johannes Berg9352c192015-04-20 18:12:41 +0200521 struct ieee80211_key_seq kseq = {};
Johannes Berg62da92f2007-12-19 02:03:31 +0100522
Johannes Berg14db74b2008-07-29 13:22:52 +0200523 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
524
Johannes Berg3b967662008-04-08 17:56:52 +0200525 rcu_read_lock();
526
Johannes Berg62da92f2007-12-19 02:03:31 +0100527 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100528 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100529 if (!sta)
530 goto out;
531
Max Stepanov354e1592013-12-08 13:30:52 +0200532 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200533 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200534 else if (!pairwise &&
535 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200536 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100537 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200538 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100539
540 if (!key)
541 goto out;
542
543 memset(&params, 0, sizeof(params));
544
Johannes Berg97359d12010-08-10 09:46:38 +0200545 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100546
Johannes Berg97359d12010-08-10 09:46:38 +0200547 switch (key->conf.cipher) {
548 case WLAN_CIPHER_SUITE_TKIP:
Eliad Pellerf8079d42016-02-14 13:56:35 +0200549 pn64 = atomic64_read(&key->conf.tx_pn);
550 iv32 = TKIP_PN_TO_IV32(pn64);
551 iv16 = TKIP_PN_TO_IV16(pn64);
Johannes Berg62da92f2007-12-19 02:03:31 +0100552
Johannes Berg9352c192015-04-20 18:12:41 +0200553 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
554 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
555 drv_get_key_seq(sdata->local, key, &kseq);
556 iv32 = kseq.tkip.iv32;
557 iv16 = kseq.tkip.iv16;
558 }
Johannes Berg62da92f2007-12-19 02:03:31 +0100559
560 seq[0] = iv16 & 0xff;
561 seq[1] = (iv16 >> 8) & 0xff;
562 seq[2] = iv32 & 0xff;
563 seq[3] = (iv32 >> 8) & 0xff;
564 seq[4] = (iv32 >> 16) & 0xff;
565 seq[5] = (iv32 >> 24) & 0xff;
566 params.seq = seq;
567 params.seq_len = 6;
568 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200569 case WLAN_CIPHER_SUITE_CCMP:
Jouni Malinen2b2ba0d2015-01-24 19:52:07 +0200570 case WLAN_CIPHER_SUITE_CCMP_256:
Johannes Bergdb388a52015-06-01 15:36:51 +0200571 case WLAN_CIPHER_SUITE_AES_CMAC:
572 case WLAN_CIPHER_SUITE_BIP_CMAC_256:
573 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
574 offsetof(typeof(kseq), aes_cmac));
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500575 /* fall through */
Johannes Bergdb388a52015-06-01 15:36:51 +0200576 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
577 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
578 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
579 offsetof(typeof(kseq), aes_gmac));
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -0500580 /* fall through */
Johannes Bergdb388a52015-06-01 15:36:51 +0200581 case WLAN_CIPHER_SUITE_GCMP:
582 case WLAN_CIPHER_SUITE_GCMP_256:
583 BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) !=
584 offsetof(typeof(kseq), gcmp));
585
Johannes Berg9352c192015-04-20 18:12:41 +0200586 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE &&
587 !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
588 drv_get_key_seq(sdata->local, key, &kseq);
589 memcpy(seq, kseq.ccmp.pn, 6);
590 } else {
Johannes Bergdb388a52015-06-01 15:36:51 +0200591 pn64 = atomic64_read(&key->conf.tx_pn);
Johannes Berg9352c192015-04-20 18:12:41 +0200592 seq[0] = pn64;
593 seq[1] = pn64 >> 8;
594 seq[2] = pn64 >> 16;
595 seq[3] = pn64 >> 24;
596 seq[4] = pn64 >> 32;
597 seq[5] = pn64 >> 40;
598 }
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200599 params.seq = seq;
600 params.seq_len = 6;
601 break;
Johannes Berga31cf1c2015-04-20 18:21:58 +0200602 default:
603 if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
604 break;
605 if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV))
606 break;
607 drv_get_key_seq(sdata->local, key, &kseq);
608 params.seq = kseq.hw.seq;
609 params.seq_len = kseq.hw.seq_len;
610 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100611 }
612
613 params.key = key->conf.key;
614 params.key_len = key->conf.keylen;
615
616 callback(cookie, &params);
617 err = 0;
618
619 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200620 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100621 return err;
622}
623
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100624static int ieee80211_config_default_key(struct wiphy *wiphy,
625 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100626 u8 key_idx, bool uni,
627 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100628{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200629 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100630
Johannes Bergf7e01042010-12-09 19:49:02 +0100631 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100632
633 return 0;
634}
635
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200636static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
637 struct net_device *dev,
638 u8 key_idx)
639{
Johannes Berg66c52422010-07-22 13:58:51 +0200640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200641
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200642 ieee80211_set_default_mgmt_key(sdata, key_idx);
643
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200644 return 0;
645}
646
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800647void sta_set_rate_info_tx(struct sta_info *sta,
648 const struct ieee80211_tx_rate *rate,
649 struct rate_info *rinfo)
650{
651 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100652 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800653 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100654 rinfo->mcs = rate->idx;
655 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
656 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
657 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
658 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
659 } else {
660 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200661 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
662 u16 brate;
663
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +0530664 sband = ieee80211_get_sband(sta->sdata);
665 if (sband) {
666 brate = sband->bitrates[rate->idx].bitrate;
667 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
668 }
Johannes Berg8bc83c22012-11-09 18:38:32 +0100669 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800670 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Johannes Bergb51f3be2015-01-15 16:14:02 +0100671 rinfo->bw = RATE_INFO_BW_40;
672 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
673 rinfo->bw = RATE_INFO_BW_80;
674 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
675 rinfo->bw = RATE_INFO_BW_160;
676 else
677 rinfo->bw = RATE_INFO_BW_20;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800678 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
679 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800680}
681
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100682static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200683 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100684{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100685 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300686 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100687 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100688 int ret = -ENOENT;
689
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300690 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100691
Johannes Berg3b53fde82009-11-16 12:00:37 +0100692 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100693 if (sta) {
694 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200695 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Berg0fdf1492018-05-18 11:40:44 +0200696 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100697 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100698
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300699 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100700
Johannes Bergd0709a62008-02-25 16:27:46 +0100701 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100702}
703
Holger Schurig12897232010-04-19 10:23:57 +0200704static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
705 int idx, struct survey_info *survey)
706{
707 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
708
Holger Schurig12897232010-04-19 10:23:57 +0200709 return drv_get_survey(local, idx, survey);
710}
711
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100712static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200713 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100714{
Johannes Bergabe60632009-11-25 17:46:18 +0100715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300716 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100717 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100718 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100719
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300720 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100721
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100722 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100723 if (sta) {
724 ret = 0;
Johannes Berg0fdf1492018-05-18 11:40:44 +0200725 sta_set_sinfo(sta, sinfo, true);
Johannes Bergd0709a62008-02-25 16:27:46 +0100726 }
727
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300728 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100729
730 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100731}
732
Johannes Berge8c9bd52012-06-06 08:18:22 +0200733static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100734 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200735{
Johannes Berg55de9082012-07-26 17:24:39 +0200736 struct ieee80211_local *local = wiphy_priv(wiphy);
737 struct ieee80211_sub_if_data *sdata;
738 int ret = 0;
739
Johannes Berg4bf88532012-11-09 11:39:59 +0100740 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200741 return 0;
742
Johannes Berg34a37402013-12-18 09:43:33 +0100743 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200744 if (local->use_chanctx) {
Johannes Berg4a199062017-04-26 10:58:53 +0300745 sdata = rtnl_dereference(local->monitor_sdata);
Johannes Berg55de9082012-07-26 17:24:39 +0200746 if (sdata) {
747 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100748 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200749 IEEE80211_CHANCTX_EXCLUSIVE);
750 }
751 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100752 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200753 ieee80211_hw_config(local, 0);
754 }
755
Johannes Berg4bf88532012-11-09 11:39:59 +0100756 if (ret == 0)
757 local->monitor_chandef = *chandef;
Johannes Berg34a37402013-12-18 09:43:33 +0100758 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200759
760 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200761}
762
Arik Nemtsov02945822011-11-10 11:28:57 +0200763static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200764 const u8 *resp, size_t resp_len,
765 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200766{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300767 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200768
769 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530770 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200771
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100772 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200773
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300774 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200775 if (!new)
776 return -ENOMEM;
777
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300778 new->len = resp_len;
779 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200780
Michal Kazioraf296bd2014-06-05 14:21:36 +0200781 if (csa)
782 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
783 csa->n_counter_offsets_presp *
784 sizeof(new->csa_counter_offsets[0]));
785
Arik Nemtsov02945822011-11-10 11:28:57 +0200786 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300787 if (old)
788 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200789
790 return 0;
791}
792
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -0700793static int ieee80211_set_ftm_responder_params(
794 struct ieee80211_sub_if_data *sdata,
795 const u8 *lci, size_t lci_len,
796 const u8 *civicloc, size_t civicloc_len)
797{
798 struct ieee80211_ftm_responder_params *new, *old;
799 struct ieee80211_bss_conf *bss_conf;
800 u8 *pos;
801 int len;
802
Johannes Berg554be832018-12-15 11:03:24 +0200803 if (!lci_len && !civicloc_len)
804 return 0;
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -0700805
806 bss_conf = &sdata->vif.bss_conf;
807 old = bss_conf->ftmr_params;
808 len = lci_len + civicloc_len;
809
810 new = kzalloc(sizeof(*new) + len, GFP_KERNEL);
811 if (!new)
812 return -ENOMEM;
813
814 pos = (u8 *)(new + 1);
815 if (lci_len) {
816 new->lci_len = lci_len;
817 new->lci = pos;
818 memcpy(pos, lci, lci_len);
819 pos += lci_len;
820 }
821
822 if (civicloc_len) {
823 new->civicloc_len = civicloc_len;
824 new->civicloc = pos;
825 memcpy(pos, civicloc, civicloc_len);
826 pos += civicloc_len;
827 }
828
829 bss_conf->ftmr_params = new;
830 kfree(old);
831
832 return 0;
833}
834
Luciano Coelho0ae07962013-12-08 09:42:25 +0200835static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200836 struct cfg80211_beacon_data *params,
837 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100838{
839 struct beacon_data *new, *old;
840 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100841 int size, err;
842 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100843
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100844 old = sdata_dereference(sdata->u.ap.beacon, sdata);
845
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100846
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100847 /* Need to have a beacon head if we don't have one yet */
848 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100849 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100850
851 /* new or old head? */
852 if (params->head)
853 new_head_len = params->head_len;
854 else
855 new_head_len = old->head_len;
856
857 /* new or old tail? */
858 if (params->tail || !old)
859 /* params->tail_len will be zero for !params->tail */
860 new_tail_len = params->tail_len;
861 else
862 new_tail_len = old->tail_len;
863
864 size = sizeof(*new) + new_head_len + new_tail_len;
865
866 new = kzalloc(size, GFP_KERNEL);
867 if (!new)
868 return -ENOMEM;
869
870 /* start filling the new info now */
871
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100872 /*
873 * pointers go into the block we allocated,
874 * memory is | beacon_data | head | tail |
875 */
876 new->head = ((u8 *) new) + sizeof(*new);
877 new->tail = new->head + new_head_len;
878 new->head_len = new_head_len;
879 new->tail_len = new_tail_len;
880
Michal Kazioraf296bd2014-06-05 14:21:36 +0200881 if (csa) {
882 new->csa_current_counter = csa->count;
883 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
884 csa->n_counter_offsets_beacon *
885 sizeof(new->csa_counter_offsets[0]));
886 }
887
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100888 /* copy in head */
889 if (params->head)
890 memcpy(new->head, params->head, new_head_len);
891 else
892 memcpy(new->head, old->head, new_head_len);
893
894 /* copy in optional tail */
895 if (params->tail)
896 memcpy(new->tail, params->tail, new_tail_len);
897 else
898 if (old)
899 memcpy(new->tail, old->tail, new_tail_len);
900
Johannes Berg88600202012-02-13 15:17:18 +0100901 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200902 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100903 if (err < 0)
904 return err;
905 if (err == 0)
906 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100907
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -0700908 if (params->ftm_responder != -1) {
909 sdata->vif.bss_conf.ftm_responder = params->ftm_responder;
910 err = ieee80211_set_ftm_responder_params(sdata,
911 params->lci,
912 params->lci_len,
913 params->civicloc,
914 params->civicloc_len);
915
916 if (err < 0)
917 return err;
918
919 changed |= BSS_CHANGED_FTM_RESPONDER;
920 }
921
Eric Dumazetcf778b02012-01-12 04:41:32 +0000922 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100923
Johannes Berg88600202012-02-13 15:17:18 +0100924 if (old)
925 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100926
Johannes Berg88600202012-02-13 15:17:18 +0100927 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100928}
929
Johannes Berg88600202012-02-13 15:17:18 +0100930static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
931 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100932{
Johannes Berg88600202012-02-13 15:17:18 +0100933 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100934 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100935 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100936 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100937 u32 changed = BSS_CHANGED_BEACON_INT |
938 BSS_CHANGED_BEACON_ENABLED |
939 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100940 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +0100941 BSS_CHANGED_P2P_PS |
942 BSS_CHANGED_TXPOWER;
Johannes Berg88600202012-02-13 15:17:18 +0100943 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200944
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100945 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100946 if (old)
947 return -EALREADY;
948
Eliad Pellerf6993172014-09-10 14:07:35 +0300949 switch (params->smps_mode) {
950 case NL80211_SMPS_OFF:
951 sdata->smps_mode = IEEE80211_SMPS_OFF;
952 break;
953 case NL80211_SMPS_STATIC:
954 sdata->smps_mode = IEEE80211_SMPS_STATIC;
955 break;
956 case NL80211_SMPS_DYNAMIC:
957 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
958 break;
959 default:
960 return -EINVAL;
961 }
Emmanuel Grumbachb3dd8272017-06-10 13:52:45 +0300962 sdata->u.ap.req_smps = sdata->smps_mode;
963
Johannes Berg04ecd252012-09-11 14:34:12 +0200964 sdata->needed_rx_chains = sdata->local->rx_chains;
965
Johannes Bergac668af2016-10-21 14:25:14 +0200966 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
967
Shaul Triebitz34fb1902018-08-31 11:31:15 +0300968 if (params->he_cap)
969 sdata->vif.bss_conf.he_support = true;
970
Johannes Berg34a37402013-12-18 09:43:33 +0100971 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100972 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200973 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100974 if (!err)
975 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100976 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200977 if (err)
978 return err;
979
Johannes Berg665c93a2011-11-04 11:18:11 +0100980 /*
981 * Apply control port protocol, this allows us to
982 * not encrypt dynamic WEP control frames.
983 */
984 sdata->control_port_protocol = params->crypto.control_port_ethertype;
985 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -0500986 sdata->control_port_over_nl80211 =
987 params->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200988 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
989 &params->crypto,
990 sdata->vif.type);
991
Johannes Berg665c93a2011-11-04 11:18:11 +0100992 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
993 vlan->control_port_protocol =
994 params->crypto.control_port_ethertype;
995 vlan->control_port_no_encrypt =
996 params->crypto.control_port_no_encrypt;
Denis Kenzior018f6fb2018-03-26 12:52:51 -0500997 vlan->control_port_over_nl80211 =
998 params->crypto.control_port_over_nl80211;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200999 vlan->encrypt_headroom =
1000 ieee80211_cs_headroom(sdata->local,
1001 &params->crypto,
1002 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +01001003 }
1004
Johannes Berg88600202012-02-13 15:17:18 +01001005 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +01001006 sdata->vif.bss_conf.enable_beacon = true;
Ayala Beker52cfa1d2016-03-17 15:41:39 +02001007 sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p;
Johannes Berg88600202012-02-13 15:17:18 +01001008
1009 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1010 if (params->ssid_len)
1011 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1012 params->ssid_len);
1013 sdata->vif.bss_conf.hidden_ssid =
1014 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1015
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001016 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1017 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1018 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1019 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1020 if (params->p2p_opp_ps)
1021 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1022 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001023
Michal Kazioraf296bd2014-06-05 14:21:36 +02001024 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001025 if (err < 0) {
1026 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001027 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001028 }
Johannes Berg88600202012-02-13 15:17:18 +01001029 changed |= err;
1030
Johannes Berg10416382012-10-19 15:44:42 +02001031 err = drv_start_ap(sdata->local, sdata);
1032 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001033 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1034
Johannes Berg10416382012-10-19 15:44:42 +02001035 if (old)
1036 kfree_rcu(old, rcu_head);
1037 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001038 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +02001039 return err;
1040 }
1041
Thomas Pedersen057d5f42013-12-19 10:25:15 -08001042 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001043 ieee80211_bss_info_change_notify(sdata, changed);
1044
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001045 netif_carrier_on(dev);
1046 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1047 netif_carrier_on(vlan->dev);
1048
Johannes Berg665c93a2011-11-04 11:18:11 +01001049 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001050}
1051
Johannes Berg88600202012-02-13 15:17:18 +01001052static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1053 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001054{
Johannes Berg14db74b2008-07-29 13:22:52 +02001055 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001056 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001057 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001058
Johannes Berg14db74b2008-07-29 13:22:52 +02001059 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +01001060 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +02001061
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001062 /* don't allow changing the beacon while CSA is in place - offset
1063 * of channel switch counter may change
1064 */
1065 if (sdata->vif.csa_active)
1066 return -EBUSY;
1067
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001068 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001069 if (!old)
1070 return -ENOENT;
1071
Michal Kazioraf296bd2014-06-05 14:21:36 +02001072 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +01001073 if (err < 0)
1074 return err;
1075 ieee80211_bss_info_change_notify(sdata, err);
1076 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001077}
1078
Johannes Berg88600202012-02-13 15:17:18 +01001079static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001080{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001081 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1082 struct ieee80211_sub_if_data *vlan;
1083 struct ieee80211_local *local = sdata->local;
1084 struct beacon_data *old_beacon;
1085 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001086 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001087
Michal Kaziordbd72852014-01-29 07:56:21 +01001088 sdata_assert_lock(sdata);
1089
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001090 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001091 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001092 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001093 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001094
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001095 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +02001096 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001097 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +03001098 if (sdata->csa_block_tx) {
1099 ieee80211_wake_vif_queues(local, sdata,
1100 IEEE80211_QUEUE_STOP_REASON_CSA);
1101 sdata->csa_block_tx = false;
1102 }
1103
Michal Kazior59af6922014-04-09 15:10:59 +02001104 mutex_unlock(&local->mtx);
1105
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +01001106 kfree(sdata->u.ap.next_beacon);
1107 sdata->u.ap.next_beacon = NULL;
1108
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001109 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001110 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1111 netif_carrier_off(vlan->dev);
1112 netif_carrier_off(dev);
1113
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001114 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001115 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001116 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1117 kfree_rcu(old_beacon, rcu_head);
1118 if (old_probe_resp)
1119 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +02001120 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +01001121
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07001122 kfree(sdata->vif.bss_conf.ftmr_params);
1123 sdata->vif.bss_conf.ftmr_params = NULL;
1124
Johannes Berge7162512013-12-04 23:18:37 +01001125 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +01001126 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +01001127
Johannes Bergd6a83222012-12-14 14:06:28 +01001128 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001129 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001130 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001131 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001132
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001133 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001134 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001135 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001136 cfg80211_cac_event(sdata->dev, &chandef,
1137 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001138 GFP_KERNEL);
1139 }
1140
Johannes Berg10416382012-10-19 15:44:42 +02001141 drv_stop_ap(sdata->local, sdata);
1142
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001143 /* free all potentially still buffered bcast frames */
1144 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
Felix Fietkau6b07d9c2016-08-02 11:13:41 +02001145 ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001146
Johannes Berg34a37402013-12-18 09:43:33 +01001147 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +01001148 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001149 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001150 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001151
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001152 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001153}
1154
Johannes Bergd582cff2012-10-26 17:53:44 +02001155static int sta_apply_auth_flags(struct ieee80211_local *local,
1156 struct sta_info *sta,
1157 u32 mask, u32 set)
1158{
1159 int ret;
1160
1161 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1162 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1163 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1164 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1165 if (ret)
1166 return ret;
1167 }
1168
1169 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1170 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1171 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001172 /*
1173 * When peer becomes associated, init rate control as
1174 * well. Some drivers require rate control initialized
1175 * before drv_sta_state() is called.
1176 */
Ayala Beker44674d92015-09-23 10:41:27 +02001177 if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
Marek Puzyniakc23e31c2015-03-08 18:04:22 +02001178 rate_control_rate_init(sta);
1179
Johannes Bergd582cff2012-10-26 17:53:44 +02001180 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1181 if (ret)
1182 return ret;
1183 }
1184
1185 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1186 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1187 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1188 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1189 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1190 else
1191 ret = 0;
1192 if (ret)
1193 return ret;
1194 }
1195
1196 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1197 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1198 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1199 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1200 if (ret)
1201 return ret;
1202 }
1203
1204 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1205 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1206 test_sta_flag(sta, WLAN_STA_AUTH)) {
1207 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1208 if (ret)
1209 return ret;
1210 }
1211
1212 return 0;
1213}
1214
Johannes Berg13657702015-06-17 10:34:54 +02001215static void sta_apply_mesh_params(struct ieee80211_local *local,
1216 struct sta_info *sta,
1217 struct station_parameters *params)
1218{
1219#ifdef CONFIG_MAC80211_MESH
1220 struct ieee80211_sub_if_data *sdata = sta->sdata;
1221 u32 changed = 0;
1222
1223 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
1224 switch (params->plink_state) {
1225 case NL80211_PLINK_ESTAB:
1226 if (sta->mesh->plink_state != NL80211_PLINK_ESTAB)
1227 changed = mesh_plink_inc_estab_count(sdata);
1228 sta->mesh->plink_state = params->plink_state;
Masashi Honma7d27a0b2016-07-01 10:19:34 +09001229 sta->mesh->aid = params->peer_aid;
Johannes Berg13657702015-06-17 10:34:54 +02001230
1231 ieee80211_mps_sta_status_update(sta);
1232 changed |= ieee80211_mps_set_sta_local_pm(sta,
1233 sdata->u.mesh.mshcfg.power_mode);
1234 break;
1235 case NL80211_PLINK_LISTEN:
1236 case NL80211_PLINK_BLOCKED:
1237 case NL80211_PLINK_OPN_SNT:
1238 case NL80211_PLINK_OPN_RCVD:
1239 case NL80211_PLINK_CNF_RCVD:
1240 case NL80211_PLINK_HOLDING:
1241 if (sta->mesh->plink_state == NL80211_PLINK_ESTAB)
1242 changed = mesh_plink_dec_estab_count(sdata);
1243 sta->mesh->plink_state = params->plink_state;
1244
1245 ieee80211_mps_sta_status_update(sta);
1246 changed |= ieee80211_mps_set_sta_local_pm(sta,
1247 NL80211_MESH_POWER_UNKNOWN);
1248 break;
1249 default:
1250 /* nothing */
1251 break;
1252 }
1253 }
1254
1255 switch (params->plink_action) {
1256 case NL80211_PLINK_ACTION_NO_ACTION:
1257 /* nothing */
1258 break;
1259 case NL80211_PLINK_ACTION_OPEN:
1260 changed |= mesh_plink_open(sta);
1261 break;
1262 case NL80211_PLINK_ACTION_BLOCK:
1263 changed |= mesh_plink_block(sta);
1264 break;
1265 }
1266
1267 if (params->local_pm)
1268 changed |= ieee80211_mps_set_sta_local_pm(sta,
1269 params->local_pm);
1270
1271 ieee80211_mbss_info_change_notify(sdata, changed);
1272#endif
1273}
1274
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001275static int sta_apply_parameters(struct ieee80211_local *local,
1276 struct sta_info *sta,
1277 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001278{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001279 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001280 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001281 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +03001282 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001283
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301284 sband = ieee80211_get_sband(sdata);
1285 if (!sband)
1286 return -EINVAL;
Johannes Bergae5eb022008-10-14 16:58:37 +02001287
Johannes Bergeccb8e82009-05-11 21:57:56 +03001288 mask = params->sta_flags_mask;
1289 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001290
Johannes Bergd582cff2012-10-26 17:53:44 +02001291 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1292 /*
1293 * In mesh mode, ASSOCIATED isn't part of the nl80211
1294 * API but must follow AUTHENTICATED for driver state.
1295 */
1296 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1297 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1298 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1299 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001300 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1301 /*
1302 * TDLS -- everything follows authorized, but
1303 * only becoming authorized is possible, not
1304 * going back
1305 */
1306 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1307 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1308 BIT(NL80211_STA_FLAG_ASSOCIATED);
1309 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1310 BIT(NL80211_STA_FLAG_ASSOCIATED);
1311 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001312 }
1313
Johannes Berg2c44be82015-03-30 15:09:20 +02001314 if (mask & BIT(NL80211_STA_FLAG_WME) &&
1315 local->hw.queues >= IEEE80211_NUM_ACS)
1316 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
1317
Ayala Beker44674d92015-09-23 10:41:27 +02001318 /* auth flags will be set later for TDLS,
1319 * and for unassociated stations that move to assocaited */
1320 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1321 !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1322 (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001323 ret = sta_apply_auth_flags(local, sta, mask, set);
1324 if (ret)
1325 return ret;
1326 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001327
Johannes Bergeccb8e82009-05-11 21:57:56 +03001328 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001329 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001330 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1331 else
1332 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001333 }
1334
Johannes Bergeccb8e82009-05-11 21:57:56 +03001335 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Tamizh chelvam93f04902015-10-07 10:40:04 +05301336 sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP));
Johannes Bergeccb8e82009-05-11 21:57:56 +03001337 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001338 set_sta_flag(sta, WLAN_STA_MFP);
1339 else
1340 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001341 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001342
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001343 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001344 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001345 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1346 else
1347 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001348 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001349
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001350 /* mark TDLS channel switch support, if the AP allows it */
1351 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1352 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1353 params->ext_capab_len >= 4 &&
1354 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1355 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1356
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001357 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
Arik Nemtsov82c0cc90d2015-08-15 22:39:46 +03001358 !sdata->u.mgd.tdls_wider_bw_prohibited &&
Arik Nemtsovb98fb442015-06-10 20:42:59 +03001359 ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) &&
1360 params->ext_capab_len >= 8 &&
1361 params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED)
1362 set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW);
1363
Johannes Berg3b9ce802011-09-27 20:56:12 +02001364 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1365 sta->sta.uapsd_queues = params->uapsd_queues;
1366 sta->sta.max_sp = params->max_sp;
1367 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001368
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001369 /* The sender might not have sent the last bit, consider it to be 0 */
1370 if (params->ext_capab_len >= 8) {
1371 u8 val = (params->ext_capab[7] &
1372 WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7;
1373
1374 /* we did get all the bits, take the MSB as well */
1375 if (params->ext_capab_len >= 9) {
1376 u8 val_msb = params->ext_capab[8] &
1377 WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB;
1378 val_msb <<= 1;
1379 val |= val_msb;
1380 }
1381
1382 switch (val) {
1383 case 1:
1384 sta->sta.max_amsdu_subframes = 32;
1385 break;
1386 case 2:
1387 sta->sta.max_amsdu_subframes = 16;
1388 break;
1389 case 3:
1390 sta->sta.max_amsdu_subframes = 8;
1391 break;
1392 default:
1393 sta->sta.max_amsdu_subframes = 0;
1394 }
1395 }
1396
Johannes Berg73651ee2008-02-25 16:27:47 +01001397 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001398 * cfg80211 validates this (1-2007) and allows setting the AID
1399 * only when creating a new station entry
1400 */
1401 if (params->aid)
1402 sta->sta.aid = params->aid;
1403
1404 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001405 * Some of the following updates would be racy if called on an
1406 * existing station, via ieee80211_change_station(). However,
1407 * all such changes are rejected by cfg80211 except for updates
1408 * changing the supported rates on an existing but not yet used
1409 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001410 */
1411
Johannes Berg4fd69312007-12-19 02:03:35 +01001412 if (params->listen_interval >= 0)
1413 sta->listen_interval = params->listen_interval;
1414
1415 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001416 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1417 sband, params->supported_rates,
1418 params->supported_rates_len,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301419 &sta->sta.supp_rates[sband->band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001420 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001421
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001422 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001423 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001424 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001425
Emmanuel Grumbach506bcfa2015-12-13 15:41:05 +02001426 /* VHT can override some HT caps such as the A-MSDU max length */
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001427 if (params->vht_capa)
1428 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001429 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001430
Luca Coelho41cbb0f2018-06-09 09:14:44 +03001431 if (params->he_capa)
1432 ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
1433 (void *)params->he_capa,
1434 params->he_capa_len, sta);
1435
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001436 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001437 /* returned value is only needed for rc update, but the
1438 * rc isn't initialized here yet, so ignore it
1439 */
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05301440 __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif,
1441 sband->band);
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001442 }
1443
Ayala Beker52cfa1d2016-03-17 15:41:39 +02001444 if (params->support_p2p_ps >= 0)
1445 sta->sta.support_p2p_ps = params->support_p2p_ps;
1446
Johannes Berg13657702015-06-17 10:34:54 +02001447 if (ieee80211_vif_is_mesh(&sdata->vif))
1448 sta_apply_mesh_params(local, sta, params);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001449
Toke Høiland-Jørgensenb4809e92018-12-18 17:02:08 -08001450 if (params->airtime_weight)
1451 sta->airtime_weight = params->airtime_weight;
1452
Arik Nemtsov68885a52014-06-11 17:18:19 +03001453 /* set the STA state after all sta info from usermode has been set */
Ayala Beker44674d92015-09-23 10:41:27 +02001454 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) ||
1455 set & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
Arik Nemtsov68885a52014-06-11 17:18:19 +03001456 ret = sta_apply_auth_flags(local, sta, mask, set);
1457 if (ret)
1458 return ret;
1459 }
1460
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001461 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001462}
1463
1464static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001465 const u8 *mac,
1466 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001467{
Johannes Berg14db74b2008-07-29 13:22:52 +02001468 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001469 struct sta_info *sta;
1470 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001471 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001472 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001473
Johannes Berg4fd69312007-12-19 02:03:35 +01001474 if (params->vlan) {
1475 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1476
Johannes Berg05c914f2008-09-11 00:01:58 +02001477 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1478 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001479 return -EINVAL;
1480 } else
1481 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1482
Joe Perchesb203ca32012-05-08 18:56:52 +00001483 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001484 return -EINVAL;
1485
1486 if (is_multicast_ether_addr(mac))
1487 return -EINVAL;
1488
1489 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001490 if (!sta)
1491 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001492
Ayala Beker44674d92015-09-23 10:41:27 +02001493 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
1494 sta->sta.tdls = true;
Johannes Berg4fd69312007-12-19 02:03:35 +01001495
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001496 err = sta_apply_parameters(local, sta, params);
1497 if (err) {
1498 sta_info_free(local, sta);
1499 return err;
1500 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001501
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001502 /*
Ayala Beker44674d92015-09-23 10:41:27 +02001503 * for TDLS and for unassociated station, rate control should be
1504 * initialized only when rates are known and station is marked
1505 * authorized/associated
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001506 */
Ayala Beker44674d92015-09-23 10:41:27 +02001507 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1508 test_sta_flag(sta, WLAN_STA_ASSOC))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001509 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001510
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001511 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1512 sdata->vif.type == NL80211_IFTYPE_AP;
1513
Johannes Berg34e89502010-02-03 13:59:58 +01001514 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001515 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001516 rcu_read_unlock();
1517 return err;
1518 }
1519
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001520 if (layer2_update)
Dedy Lansky30ca1aa2018-07-29 14:59:16 +03001521 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
Johannes Berg73651ee2008-02-25 16:27:47 +01001522
1523 rcu_read_unlock();
1524
Johannes Berg4fd69312007-12-19 02:03:35 +01001525 return 0;
1526}
1527
1528static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001529 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001530{
Johannes Berg14db74b2008-07-29 13:22:52 +02001531 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001532
Johannes Berg14db74b2008-07-29 13:22:52 +02001533 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1534
Jouni Malinen89c771e2014-10-10 20:52:40 +03001535 if (params->mac)
1536 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001537
Johannes Bergb998e8b2012-12-13 23:07:46 +01001538 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001539 return 0;
1540}
1541
1542static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001543 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001544 struct station_parameters *params)
1545{
Johannes Bergabe60632009-11-25 17:46:18 +01001546 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001547 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001548 struct sta_info *sta;
1549 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001550 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001551 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001552
Johannes Berg87be1e12011-12-14 12:20:29 +01001553 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001554
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001555 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001556 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001557 err = -ENOENT;
1558 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001559 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001560
Johannes Berg77ee7c82013-02-15 00:48:33 +01001561 switch (sdata->vif.type) {
1562 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001563 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001564 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001565 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001566 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001567 break;
1568 case NL80211_IFTYPE_ADHOC:
1569 statype = CFG80211_STA_IBSS;
1570 break;
1571 case NL80211_IFTYPE_STATION:
1572 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1573 statype = CFG80211_STA_AP_STA;
1574 break;
1575 }
1576 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1577 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1578 else
1579 statype = CFG80211_STA_TDLS_PEER_SETUP;
1580 break;
1581 case NL80211_IFTYPE_AP:
1582 case NL80211_IFTYPE_AP_VLAN:
Ayala Beker44674d92015-09-23 10:41:27 +02001583 if (test_sta_flag(sta, WLAN_STA_ASSOC))
1584 statype = CFG80211_STA_AP_CLIENT;
1585 else
1586 statype = CFG80211_STA_AP_CLIENT_UNASSOC;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001587 break;
1588 default:
1589 err = -EOPNOTSUPP;
1590 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001591 }
1592
Johannes Berg77ee7c82013-02-15 00:48:33 +01001593 err = cfg80211_check_station_change(wiphy, params, statype);
1594 if (err)
1595 goto out_err;
1596
Johannes Bergd0709a62008-02-25 16:27:46 +01001597 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +01001598 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1599
Johannes Berg9bc383d2009-11-19 11:55:19 +01001600 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001601 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001602 err = -EBUSY;
1603 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001604 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001605
Eric Dumazetcf778b02012-01-12 04:41:32 +00001606 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Johannes Berg49ddf8e2016-03-31 20:02:10 +03001607 __ieee80211_check_fast_rx_iface(vlansdata);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001608 }
1609
1610 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
Michael Braun72f15d52016-10-10 19:12:21 +02001611 sta->sdata->u.vlan.sta)
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301612 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Michael Braun72f15d52016-10-10 19:12:21 +02001613
1614 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1615 ieee80211_vif_dec_num_mcast(sta->sdata);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001616
Johannes Berg14db74b2008-07-29 13:22:52 +02001617 sta->sdata = vlansdata;
Michal Kazior464daaf2015-05-19 14:13:36 +02001618 ieee80211_check_fast_xmit(sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001619
Michael Braun72f15d52016-10-10 19:12:21 +02001620 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1621 ieee80211_vif_inc_num_mcast(sta->sdata);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001622
Dedy Lansky30ca1aa2018-07-29 14:59:16 +03001623 cfg80211_send_layer2_update(sta->sdata->dev, sta->sta.addr);
Johannes Berg4fd69312007-12-19 02:03:35 +01001624 }
1625
Eliad Peller35b88622011-12-29 14:41:39 +02001626 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001627 if (err)
1628 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001629
Johannes Berg87be1e12011-12-14 12:20:29 +01001630 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001631
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001632 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1633 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1634 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1635 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1636 sta_info_tx_streams(sta) != 1) {
1637 ht_dbg(sta->sdata,
1638 "%pM just authorized and MIMO capable - update SMPS\n",
1639 sta->sta.addr);
1640 ieee80211_send_smps_action(sta->sdata,
1641 sta->sdata->bss->req_smps,
1642 sta->sta.addr,
1643 sta->sdata->vif.bss_conf.bssid);
1644 }
1645
Jason Young808118c2011-03-10 16:43:19 -08001646 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001647 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4a733ef2015-10-14 18:02:43 +02001648 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03001649 ieee80211_recalc_ps_vif(sdata);
1650 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001651
Johannes Berg4fd69312007-12-19 02:03:35 +01001652 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001653out_err:
1654 mutex_unlock(&local->sta_mtx);
1655 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001656}
1657
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001658#ifdef CONFIG_MAC80211_MESH
1659static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001660 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001661{
Johannes Berg14db74b2008-07-29 13:22:52 +02001662 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001663 struct mesh_path *mpath;
1664 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001665
Johannes Berg14db74b2008-07-29 13:22:52 +02001666 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1667
Johannes Bergd0709a62008-02-25 16:27:46 +01001668 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001669 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001670 if (!sta) {
1671 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001672 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001673 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001674
Bob Copelandae76eef2013-03-29 09:38:39 -04001675 mpath = mesh_path_add(sdata, dst);
1676 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001677 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001678 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001679 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001680
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001681 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001682
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001683 rcu_read_unlock();
1684 return 0;
1685}
1686
1687static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001688 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001689{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001690 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001691
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001692 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001693 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001694
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001695 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001696 return 0;
1697}
1698
Johannes Berg3b3a0162014-05-19 17:19:31 +02001699static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1700 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001701{
Johannes Berg14db74b2008-07-29 13:22:52 +02001702 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001703 struct mesh_path *mpath;
1704 struct sta_info *sta;
1705
Johannes Berg14db74b2008-07-29 13:22:52 +02001706 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1707
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001708 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001709
Johannes Bergabe60632009-11-25 17:46:18 +01001710 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001711 if (!sta) {
1712 rcu_read_unlock();
1713 return -ENOENT;
1714 }
1715
Johannes Bergbf7cd942013-02-15 14:40:31 +01001716 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001717 if (!mpath) {
1718 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001719 return -ENOENT;
1720 }
1721
1722 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001723
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001724 rcu_read_unlock();
1725 return 0;
1726}
1727
1728static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1729 struct mpath_info *pinfo)
1730{
Johannes Berga3836e02011-05-12 15:11:37 +02001731 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1732
1733 if (next_hop_sta)
1734 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001735 else
Joe Perchesc84a67a2015-03-02 19:54:57 -08001736 eth_zero_addr(next_hop);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001737
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001738 memset(pinfo, 0, sizeof(*pinfo));
1739
Bob Copeland2bdaf382016-02-28 20:03:56 -05001740 pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation;
Johannes Bergf5ea9122009-08-07 16:17:38 +02001741
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001742 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001743 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001744 MPATH_INFO_METRIC |
1745 MPATH_INFO_EXPTIME |
1746 MPATH_INFO_DISCOVERY_TIMEOUT |
1747 MPATH_INFO_DISCOVERY_RETRIES |
Julan Hsucc241632019-01-15 15:28:42 -08001748 MPATH_INFO_FLAGS |
Julan Hsu540bbcb2019-01-15 15:28:43 -08001749 MPATH_INFO_HOP_COUNT |
1750 MPATH_INFO_PATH_CHANGE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001751
1752 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001753 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001754 pinfo->metric = mpath->metric;
1755 if (time_before(jiffies, mpath->exp_time))
1756 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1757 pinfo->discovery_timeout =
1758 jiffies_to_msecs(mpath->discovery_timeout);
1759 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001760 if (mpath->flags & MESH_PATH_ACTIVE)
1761 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1762 if (mpath->flags & MESH_PATH_RESOLVING)
1763 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001764 if (mpath->flags & MESH_PATH_SN_VALID)
1765 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001766 if (mpath->flags & MESH_PATH_FIXED)
1767 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001768 if (mpath->flags & MESH_PATH_RESOLVED)
1769 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Julan Hsucc241632019-01-15 15:28:42 -08001770 pinfo->hop_count = mpath->hop_count;
Julan Hsu540bbcb2019-01-15 15:28:43 -08001771 pinfo->path_change_count = mpath->path_change_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001772}
1773
1774static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1775 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1776
1777{
Johannes Berg14db74b2008-07-29 13:22:52 +02001778 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001779 struct mesh_path *mpath;
1780
Johannes Berg14db74b2008-07-29 13:22:52 +02001781 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1782
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001783 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001784 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001785 if (!mpath) {
1786 rcu_read_unlock();
1787 return -ENOENT;
1788 }
1789 memcpy(dst, mpath->dst, ETH_ALEN);
1790 mpath_set_pinfo(mpath, next_hop, pinfo);
1791 rcu_read_unlock();
1792 return 0;
1793}
1794
1795static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001796 int idx, u8 *dst, u8 *next_hop,
1797 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001798{
Johannes Berg14db74b2008-07-29 13:22:52 +02001799 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001800 struct mesh_path *mpath;
1801
Johannes Berg14db74b2008-07-29 13:22:52 +02001802 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1803
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001804 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001805 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001806 if (!mpath) {
1807 rcu_read_unlock();
1808 return -ENOENT;
1809 }
1810 memcpy(dst, mpath->dst, ETH_ALEN);
1811 mpath_set_pinfo(mpath, next_hop, pinfo);
1812 rcu_read_unlock();
1813 return 0;
1814}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001815
Henning Roggea2db2ed2014-09-12 08:58:50 +02001816static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1817 struct mpath_info *pinfo)
1818{
1819 memset(pinfo, 0, sizeof(*pinfo));
1820 memcpy(mpp, mpath->mpp, ETH_ALEN);
1821
Bob Copeland2bdaf382016-02-28 20:03:56 -05001822 pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation;
Henning Roggea2db2ed2014-09-12 08:58:50 +02001823}
1824
1825static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1826 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1827
1828{
1829 struct ieee80211_sub_if_data *sdata;
1830 struct mesh_path *mpath;
1831
1832 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1833
1834 rcu_read_lock();
1835 mpath = mpp_path_lookup(sdata, dst);
1836 if (!mpath) {
1837 rcu_read_unlock();
1838 return -ENOENT;
1839 }
1840 memcpy(dst, mpath->dst, ETH_ALEN);
1841 mpp_set_pinfo(mpath, mpp, pinfo);
1842 rcu_read_unlock();
1843 return 0;
1844}
1845
1846static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1847 int idx, u8 *dst, u8 *mpp,
1848 struct mpath_info *pinfo)
1849{
1850 struct ieee80211_sub_if_data *sdata;
1851 struct mesh_path *mpath;
1852
1853 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1854
1855 rcu_read_lock();
1856 mpath = mpp_path_lookup_by_idx(sdata, idx);
1857 if (!mpath) {
1858 rcu_read_unlock();
1859 return -ENOENT;
1860 }
1861 memcpy(dst, mpath->dst, ETH_ALEN);
1862 mpp_set_pinfo(mpath, mpp, pinfo);
1863 rcu_read_unlock();
1864 return 0;
1865}
1866
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001867static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001868 struct net_device *dev,
1869 struct mesh_config *conf)
1870{
1871 struct ieee80211_sub_if_data *sdata;
1872 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1873
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001874 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1875 return 0;
1876}
1877
1878static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1879{
1880 return (mask >> (parm-1)) & 0x1;
1881}
1882
Javier Cardonac80d5452010-12-16 17:37:49 -08001883static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1884 const struct mesh_setup *setup)
1885{
1886 u8 *new_ie;
1887 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001888 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1889 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001890
Javier Cardona581a8b02011-04-07 15:08:27 -07001891 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001892 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001893 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001894
Javier Cardona581a8b02011-04-07 15:08:27 -07001895 if (setup->ie_len) {
1896 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001897 GFP_KERNEL);
1898 if (!new_ie)
1899 return -ENOMEM;
1900 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001901 ifmsh->ie_len = setup->ie_len;
1902 ifmsh->ie = new_ie;
1903 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001904
1905 /* now copy the rest of the setup parameters */
1906 ifmsh->mesh_id_len = setup->mesh_id_len;
1907 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001908 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001909 ifmsh->mesh_pp_id = setup->path_sel_proto;
1910 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001911 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001912 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001913 ifmsh->security = IEEE80211_MESH_SEC_NONE;
Benjamin Berg0ab2e552017-05-16 11:23:13 +02001914 ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001915 if (setup->is_authenticated)
1916 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1917 if (setup->is_secure)
1918 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001919
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001920 /* mcast rate setting in Mesh Node */
1921 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1922 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001923 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001924
Marco Porsch9bdbf042013-01-07 16:04:51 +01001925 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1926 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1927
Javier Cardonac80d5452010-12-16 17:37:49 -08001928 return 0;
1929}
1930
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001931static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001932 struct net_device *dev, u32 mask,
1933 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001934{
1935 struct mesh_config *conf;
1936 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001937 struct ieee80211_if_mesh *ifmsh;
1938
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001939 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001940 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001941
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001942 /* Set the config options which we are interested in setting */
1943 conf = &(sdata->u.mesh.mshcfg);
1944 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1945 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1946 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1947 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1948 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1949 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1950 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1951 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1952 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1953 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1954 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1955 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001956 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001957 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001958 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1959 if (ifmsh->user_mpm)
1960 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001961 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001962 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001963 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1964 conf->dot11MeshNbrOffsetMaxNeighbor =
1965 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001966 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1967 conf->dot11MeshHWMPmaxPREQretries =
1968 nconf->dot11MeshHWMPmaxPREQretries;
1969 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1970 conf->path_refresh_time = nconf->path_refresh_time;
1971 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1972 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1973 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1974 conf->dot11MeshHWMPactivePathTimeout =
1975 nconf->dot11MeshHWMPactivePathTimeout;
1976 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1977 conf->dot11MeshHWMPpreqMinInterval =
1978 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001979 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1980 conf->dot11MeshHWMPperrMinInterval =
1981 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001982 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1983 mask))
1984 conf->dot11MeshHWMPnetDiameterTraversalTime =
1985 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001986 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1987 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1988 ieee80211_mesh_root_setup(ifmsh);
1989 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001990 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001991 /* our current gate announcement implementation rides on root
1992 * announcements, so require this ifmsh to also be a root node
1993 * */
1994 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001995 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1996 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001997 ieee80211_mesh_root_setup(ifmsh);
1998 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001999 conf->dot11MeshGateAnnouncementProtocol =
2000 nconf->dot11MeshGateAnnouncementProtocol;
2001 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08002002 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07002003 conf->dot11MeshHWMPRannInterval =
2004 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08002005 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
2006 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08002007 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
2008 /* our RSSI threshold implementation is supported only for
2009 * devices that report signal in dBm.
2010 */
Johannes Berg30686bf2015-06-02 21:39:54 +02002011 if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM))
Ashok Nagarajan55335132012-02-28 17:04:08 -08002012 return -ENOTSUPP;
2013 conf->rssi_threshold = nconf->rssi_threshold;
2014 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07002015 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
2016 conf->ht_opmode = nconf->ht_opmode;
2017 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
2018 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
2019 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08002020 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
2021 conf->dot11MeshHWMPactivePathToRootTimeout =
2022 nconf->dot11MeshHWMPactivePathToRootTimeout;
2023 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
2024 conf->dot11MeshHWMProotInterval =
2025 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08002026 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
2027 conf->dot11MeshHWMPconfirmationInterval =
2028 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002029 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
2030 conf->power_mode = nconf->power_mode;
2031 ieee80211_mps_local_status_update(sdata);
2032 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002033 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01002034 conf->dot11MeshAwakeWindowDuration =
2035 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07002036 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
2037 conf->plink_timeout = nconf->plink_timeout;
Bob Copeland01d66fb2018-10-25 17:36:34 -04002038 if (_chg_mesh_attr(NL80211_MESHCONF_CONNECTED_TO_GATE, mask))
2039 conf->dot11MeshConnectedToMeshGate =
2040 nconf->dot11MeshConnectedToMeshGate;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002041 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002042 return 0;
2043}
2044
Johannes Berg29cbe682010-12-03 09:20:44 +01002045static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
2046 const struct mesh_config *conf,
2047 const struct mesh_setup *setup)
2048{
2049 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2050 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08002051 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01002052
Javier Cardonac80d5452010-12-16 17:37:49 -08002053 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
2054 err = copy_mesh_setup(ifmsh, setup);
2055 if (err)
2056 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002057
Denis Kenzior018f6fb2018-03-26 12:52:51 -05002058 sdata->control_port_over_nl80211 = setup->control_port_over_nl80211;
2059
Johannes Berg04ecd252012-09-11 14:34:12 +02002060 /* can mesh use other SMPS modes? */
2061 sdata->smps_mode = IEEE80211_SMPS_OFF;
2062 sdata->needed_rx_chains = sdata->local->rx_chains;
2063
Johannes Berg34a37402013-12-18 09:43:33 +01002064 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01002065 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02002066 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01002067 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002068 if (err)
2069 return err;
2070
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08002071 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01002072}
2073
2074static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
2075{
2076 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2077
2078 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002079 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02002080 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01002081 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01002082
2083 return 0;
2084}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002085#endif
2086
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002087static int ieee80211_change_bss(struct wiphy *wiphy,
2088 struct net_device *dev,
2089 struct bss_parameters *params)
2090{
Johannes Berg55de9082012-07-26 17:24:39 +02002091 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302092 struct ieee80211_supported_band *sband;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002093 u32 changed = 0;
2094
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01002095 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02002096 return -ENOENT;
2097
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302098 sband = ieee80211_get_sband(sdata);
2099 if (!sband)
2100 return -EINVAL;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002101
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002102 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002103 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002104 changed |= BSS_CHANGED_ERP_CTS_PROT;
2105 }
2106 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002107 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002108 params->use_short_preamble;
2109 changed |= BSS_CHANGED_ERP_PREAMBLE;
2110 }
Felix Fietkau43d35342010-01-15 03:00:48 +01002111
2112 if (!sdata->vif.bss_conf.use_short_slot &&
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302113 sband->band == NL80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01002114 sdata->vif.bss_conf.use_short_slot = true;
2115 changed |= BSS_CHANGED_ERP_SLOT;
2116 }
2117
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002118 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002119 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002120 params->use_short_slot_time;
2121 changed |= BSS_CHANGED_ERP_SLOT;
2122 }
2123
Jouni Malinen90c97a02008-10-30 16:59:22 +02002124 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002125 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
Mohammed Shafi Shajakhan21a8e9d2017-04-27 12:45:38 +05302126 wiphy->bands[sband->band],
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002127 params->basic_rates,
2128 params->basic_rates_len,
2129 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002130 changed |= BSS_CHANGED_BASIC_RATES;
Johannes Berge8e4f522017-03-08 11:12:10 +01002131 ieee80211_check_rate_mask(sdata);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002132 }
2133
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002134 if (params->ap_isolate >= 0) {
2135 if (params->ap_isolate)
2136 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2137 else
2138 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
Johannes Berg49ddf8e2016-03-31 20:02:10 +03002139 ieee80211_check_fast_rx_iface(sdata);
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002140 }
2141
Helmut Schaa80d7e402010-11-19 12:40:26 +01002142 if (params->ht_opmode >= 0) {
2143 sdata->vif.bss_conf.ht_operation_mode =
2144 (u16) params->ht_opmode;
2145 changed |= BSS_CHANGED_HT;
2146 }
2147
Johannes Berg339afbf2012-11-14 15:21:17 +01002148 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002149 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2150 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2151 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2152 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002153 changed |= BSS_CHANGED_P2P_PS;
2154 }
2155
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002156 if (params->p2p_opp_ps > 0) {
2157 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2158 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2159 changed |= BSS_CHANGED_P2P_PS;
2160 } else if (params->p2p_opp_ps == 0) {
2161 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2162 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002163 changed |= BSS_CHANGED_P2P_PS;
2164 }
2165
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002166 ieee80211_bss_info_change_notify(sdata, changed);
2167
2168 return 0;
2169}
2170
Jouni Malinen31888482008-10-30 16:59:24 +02002171static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002172 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002173 struct ieee80211_txq_params *params)
2174{
2175 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002176 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002177 struct ieee80211_tx_queue_params p;
2178
2179 if (!local->ops->conf_tx)
2180 return -EOPNOTSUPP;
2181
Johannes Berg54bcbc62012-03-28 11:04:25 +02002182 if (local->hw.queues < IEEE80211_NUM_ACS)
2183 return -EOPNOTSUPP;
2184
Jouni Malinen31888482008-10-30 16:59:24 +02002185 memset(&p, 0, sizeof(p));
2186 p.aifs = params->aifs;
2187 p.cw_max = params->cwmax;
2188 p.cw_min = params->cwmin;
2189 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002190
2191 /*
2192 * Setting tx queue params disables u-apsd because it's only
2193 * called in master mode.
2194 */
2195 p.uapsd = false;
2196
Haim Dreyfusse552af02018-03-28 13:24:10 +03002197 ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac);
2198
Johannes Berga3304b02012-03-28 11:04:24 +02002199 sdata->tx_conf[params->ac] = p;
2200 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002201 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002202 "failed to set TX queue parameters for AC %d\n",
2203 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002204 return -EINVAL;
2205 }
2206
Johannes Berg7d257452012-07-06 17:37:43 +02002207 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2208
Jouni Malinen31888482008-10-30 16:59:24 +02002209 return 0;
2210}
2211
Bob Copeland665af4f2009-01-19 11:20:53 -05002212#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002213static int ieee80211_suspend(struct wiphy *wiphy,
2214 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002215{
Johannes Bergeecc4802011-05-04 15:37:29 +02002216 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002217}
2218
2219static int ieee80211_resume(struct wiphy *wiphy)
2220{
2221 return __ieee80211_resume(wiphy_priv(wiphy));
2222}
2223#else
2224#define ieee80211_suspend NULL
2225#define ieee80211_resume NULL
2226#endif
2227
Johannes Berg2a519312009-02-10 21:25:55 +01002228static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002229 struct cfg80211_scan_request *req)
2230{
Johannes Bergfd014282012-06-18 19:17:03 +02002231 struct ieee80211_sub_if_data *sdata;
2232
2233 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002234
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002235 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2236 case NL80211_IFTYPE_STATION:
2237 case NL80211_IFTYPE_ADHOC:
2238 case NL80211_IFTYPE_MESH_POINT:
2239 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002240 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002241 break;
2242 case NL80211_IFTYPE_P2P_GO:
2243 if (sdata->local->ops->hw_scan)
2244 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002245 /*
2246 * FIXME: implement NoA while scanning in software,
2247 * for now fall through to allow scanning only when
2248 * beaconing hasn't been configured yet
2249 */
Gustavo A. R. Silva02049ce2017-10-17 18:14:50 -05002250 /* fall through */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002251 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002252 /*
2253 * If the scan has been forced (and the driver supports
2254 * forcing), don't care about being beaconing already.
2255 * This will create problems to the attached stations (e.g. all
2256 * the frames sent while scanning on other channel will be
2257 * lost)
2258 */
2259 if (sdata->u.ap.beacon &&
2260 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2261 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002262 return -EOPNOTSUPP;
2263 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03002264 case NL80211_IFTYPE_NAN:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002265 default:
2266 return -EOPNOTSUPP;
2267 }
Johannes Berg2a519312009-02-10 21:25:55 +01002268
2269 return ieee80211_request_scan(sdata, req);
2270}
2271
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05302272static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev)
2273{
2274 ieee80211_scan_cancel(wiphy_priv(wiphy));
2275}
2276
Luciano Coelho79f460c2011-05-11 17:09:36 +03002277static int
2278ieee80211_sched_scan_start(struct wiphy *wiphy,
2279 struct net_device *dev,
2280 struct cfg80211_sched_scan_request *req)
2281{
2282 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2283
2284 if (!sdata->local->ops->sched_scan_start)
2285 return -EOPNOTSUPP;
2286
2287 return ieee80211_request_sched_scan_start(sdata, req);
2288}
2289
2290static int
Arend Van Spriel3a3ecf12017-04-21 13:05:02 +01002291ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev,
2292 u64 reqid)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002293{
Eliad Peller0d440ea2015-10-25 10:59:33 +02002294 struct ieee80211_local *local = wiphy_priv(wiphy);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002295
Eliad Peller0d440ea2015-10-25 10:59:33 +02002296 if (!local->ops->sched_scan_stop)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002297 return -EOPNOTSUPP;
2298
Eliad Peller0d440ea2015-10-25 10:59:33 +02002299 return ieee80211_request_sched_scan_stop(local);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002300}
2301
Jouni Malinen636a5d32009-03-19 13:39:22 +02002302static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2303 struct cfg80211_auth_request *req)
2304{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002305 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002306}
2307
2308static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2309 struct cfg80211_assoc_request *req)
2310{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002311 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002312}
2313
2314static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002315 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002316{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002317 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002318}
2319
2320static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002321 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002322{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002323 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002324}
2325
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002326static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2327 struct cfg80211_ibss_params *params)
2328{
Johannes Berg55de9082012-07-26 17:24:39 +02002329 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002330}
2331
2332static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2333{
Johannes Berg55de9082012-07-26 17:24:39 +02002334 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002335}
2336
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002337static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2338 struct ocb_setup *setup)
2339{
2340 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2341}
2342
2343static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2344{
2345 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2346}
2347
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002348static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002349 int rate[NUM_NL80211_BANDS])
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002350{
2351 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2352
Cong Ding9887dbf2013-02-06 17:23:45 +01002353 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002354 sizeof(int) * NUM_NL80211_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002355
Pradeep Kumar Chitrapudcbe73c2018-03-22 12:18:03 -07002356 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE);
2357
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002358 return 0;
2359}
2360
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002361static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2362{
2363 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002364 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002365
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002366 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
Johannes Berg17c18bf2015-03-21 15:25:43 +01002367 ieee80211_check_fast_xmit_all(local);
2368
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002369 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2370
Johannes Berg17c18bf2015-03-21 15:25:43 +01002371 if (err) {
2372 ieee80211_check_fast_xmit_all(local);
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002373 return err;
Johannes Berg17c18bf2015-03-21 15:25:43 +01002374 }
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002375 }
2376
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002377 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2378 (changed & WIPHY_PARAM_DYN_ACK)) {
2379 s16 coverage_class;
2380
2381 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2382 wiphy->coverage_class : -1;
2383 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002384
2385 if (err)
2386 return err;
2387 }
2388
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002389 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002390 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002391
Johannes Berg24487982009-04-23 18:52:52 +02002392 if (err)
2393 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002394 }
2395
Johannes Berg8bc83c22012-11-09 18:38:32 +01002396 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2397 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2398 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002399 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002400 }
2401 if (changed & WIPHY_PARAM_RETRY_LONG) {
2402 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2403 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002404 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002405 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002406 if (changed &
2407 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2408 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2409
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02002410 if (changed & (WIPHY_PARAM_TXQ_LIMIT |
2411 WIPHY_PARAM_TXQ_MEMORY_LIMIT |
2412 WIPHY_PARAM_TXQ_QUANTUM))
2413 ieee80211_txq_set_params(local);
2414
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002415 return 0;
2416}
2417
Johannes Berg7643a2c2009-06-02 13:01:39 +02002418static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002419 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002420 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002421{
2422 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002423 struct ieee80211_sub_if_data *sdata;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002424 enum nl80211_tx_power_setting txp_type = type;
2425 bool update_txp_type = false;
Peter Große3a3713e2017-12-13 18:29:46 +01002426 bool has_monitor = false;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002427
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002428 if (wdev) {
2429 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2430
Peter Große3a3713e2017-12-13 18:29:46 +01002431 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2432 sdata = rtnl_dereference(local->monitor_sdata);
2433 if (!sdata)
2434 return -EOPNOTSUPP;
2435 }
2436
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002437 switch (type) {
2438 case NL80211_TX_POWER_AUTOMATIC:
2439 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002440 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002441 break;
2442 case NL80211_TX_POWER_LIMITED:
2443 case NL80211_TX_POWER_FIXED:
2444 if (mbm < 0 || (mbm % 100))
2445 return -EOPNOTSUPP;
2446 sdata->user_power_level = MBM_TO_DBM(mbm);
2447 break;
2448 }
2449
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002450 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2451 update_txp_type = true;
2452 sdata->vif.bss_conf.txpower_type = txp_type;
2453 }
2454
2455 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002456
2457 return 0;
2458 }
Johannes Berg55de9082012-07-26 17:24:39 +02002459
Johannes Berg7643a2c2009-06-02 13:01:39 +02002460 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002461 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002462 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002463 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002464 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002465 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002466 case NL80211_TX_POWER_FIXED:
2467 if (mbm < 0 || (mbm % 100))
2468 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002469 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002470 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002471 }
2472
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002473 mutex_lock(&local->iflist_mtx);
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002474 list_for_each_entry(sdata, &local->interfaces, list) {
Peter Große3a3713e2017-12-13 18:29:46 +01002475 if (sdata->vif.type == NL80211_IFTYPE_MONITOR) {
2476 has_monitor = true;
2477 continue;
2478 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002479 sdata->user_power_level = local->user_power_level;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002480 if (txp_type != sdata->vif.bss_conf.txpower_type)
2481 update_txp_type = true;
2482 sdata->vif.bss_conf.txpower_type = txp_type;
2483 }
Peter Große3a3713e2017-12-13 18:29:46 +01002484 list_for_each_entry(sdata, &local->interfaces, list) {
2485 if (sdata->vif.type == NL80211_IFTYPE_MONITOR)
2486 continue;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002487 ieee80211_recalc_txpower(sdata, update_txp_type);
Peter Große3a3713e2017-12-13 18:29:46 +01002488 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002489 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002490
Peter Große3a3713e2017-12-13 18:29:46 +01002491 if (has_monitor) {
2492 sdata = rtnl_dereference(local->monitor_sdata);
2493 if (sdata) {
2494 sdata->user_power_level = local->user_power_level;
2495 if (txp_type != sdata->vif.bss_conf.txpower_type)
2496 update_txp_type = true;
2497 sdata->vif.bss_conf.txpower_type = txp_type;
2498
2499 ieee80211_recalc_txpower(sdata, update_txp_type);
2500 }
2501 }
2502
Johannes Berg7643a2c2009-06-02 13:01:39 +02002503 return 0;
2504}
2505
Johannes Bergc8442112012-10-24 10:17:18 +02002506static int ieee80211_get_tx_power(struct wiphy *wiphy,
2507 struct wireless_dev *wdev,
2508 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002509{
2510 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002511 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002512
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002513 if (local->ops->get_txpower)
2514 return drv_get_txpower(local, sdata, dbm);
2515
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002516 if (!local->use_chanctx)
2517 *dbm = local->hw.conf.power_level;
2518 else
2519 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002520
Johannes Berg7643a2c2009-06-02 13:01:39 +02002521 return 0;
2522}
2523
Johannes Bergab737a42009-07-01 21:26:58 +02002524static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002525 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002526{
2527 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2528
2529 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2530
2531 return 0;
2532}
2533
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002534static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2535{
2536 struct ieee80211_local *local = wiphy_priv(wiphy);
2537
2538 drv_rfkill_poll(local);
2539}
2540
Johannes Bergaff89a92009-07-01 21:26:51 +02002541#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002542static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2543 struct wireless_dev *wdev,
2544 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002545{
2546 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002547 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002548
2549 if (!local->ops->testmode_cmd)
2550 return -EOPNOTSUPP;
2551
David Spinadel52981cd2013-07-31 18:06:22 +03002552 if (wdev) {
2553 struct ieee80211_sub_if_data *sdata;
2554
2555 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2556 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2557 vif = &sdata->vif;
2558 }
2559
2560 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002561}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002562
2563static int ieee80211_testmode_dump(struct wiphy *wiphy,
2564 struct sk_buff *skb,
2565 struct netlink_callback *cb,
2566 void *data, int len)
2567{
2568 struct ieee80211_local *local = wiphy_priv(wiphy);
2569
2570 if (!local->ops->testmode_dump)
2571 return -EOPNOTSUPP;
2572
2573 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2574}
Johannes Bergaff89a92009-07-01 21:26:51 +02002575#endif
2576
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002577int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2578 enum ieee80211_smps_mode smps_mode)
2579{
2580 struct sta_info *sta;
2581 enum ieee80211_smps_mode old_req;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002582
2583 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2584 return -EINVAL;
2585
2586 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2587 return 0;
2588
2589 old_req = sdata->u.ap.req_smps;
2590 sdata->u.ap.req_smps = smps_mode;
2591
2592 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2593 if (old_req == smps_mode ||
2594 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2595 return 0;
2596
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002597 ht_dbg(sdata,
Michael Braun6a8b4ad2015-03-18 07:17:37 +01002598 "SMPS %d requested in AP mode, sending Action frame to %d stations\n",
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002599 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2600
2601 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002602 list_for_each_entry(sta, &sdata->local->sta_list, list) {
2603 /*
2604 * Only stations associated to our AP and
2605 * associated VLANs
2606 */
2607 if (sta->sdata->bss != &sdata->u.ap)
2608 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002609
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002610 /* This station doesn't support MIMO - skip it */
2611 if (sta_info_tx_streams(sta) == 1)
2612 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002613
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002614 /*
2615 * Don't wake up a STA just to send the action frame
2616 * unless we are getting more restrictive.
2617 */
2618 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2619 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2620 smps_mode)) {
2621 ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n",
2622 sta->sta.addr);
2623 continue;
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002624 }
Johannes Berg7d9bb2f2015-02-13 21:31:07 +01002625
2626 /*
2627 * If the STA is not authorized, wait until it gets
2628 * authorized and the action frame will be sent then.
2629 */
2630 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2631 continue;
2632
2633 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2634 ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr,
2635 sdata->vif.bss_conf.bssid);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002636 }
2637 mutex_unlock(&sdata->local->sta_mtx);
2638
2639 sdata->smps_mode = smps_mode;
2640 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2641
2642 return 0;
2643}
2644
2645int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2646 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002647{
2648 const u8 *ap;
2649 enum ieee80211_smps_mode old_req;
2650 int err;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002651 struct sta_info *sta;
2652 bool tdls_peer_found = false;
Johannes Berg0f782312009-12-01 13:37:02 +01002653
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002654 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002655
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002656 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2657 return -EINVAL;
2658
Johannes Berg0f782312009-12-01 13:37:02 +01002659 old_req = sdata->u.mgd.req_smps;
2660 sdata->u.mgd.req_smps = smps_mode;
2661
2662 if (old_req == smps_mode &&
2663 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2664 return 0;
2665
2666 /*
2667 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002668 * association, there's no need to do anything, just store
2669 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002670 */
2671 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002672 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002673 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002674
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002675 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002676
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002677 rcu_read_lock();
2678 list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) {
2679 if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded ||
2680 !test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2681 continue;
2682
2683 tdls_peer_found = true;
2684 break;
2685 }
2686 rcu_read_unlock();
2687
Johannes Berg0f782312009-12-01 13:37:02 +01002688 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002689 if (tdls_peer_found || !sdata->u.mgd.powersave)
Johannes Berg0f782312009-12-01 13:37:02 +01002690 smps_mode = IEEE80211_SMPS_OFF;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002691 else
2692 smps_mode = IEEE80211_SMPS_DYNAMIC;
Johannes Berg0f782312009-12-01 13:37:02 +01002693 }
2694
2695 /* send SM PS frame to AP */
2696 err = ieee80211_send_smps_action(sdata, smps_mode,
2697 ap, ap);
2698 if (err)
2699 sdata->u.mgd.req_smps = old_req;
Arik Nemtsovd51c2ea2015-06-14 16:53:46 +03002700 else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found)
2701 ieee80211_teardown_tdls_peers(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002702
2703 return err;
2704}
2705
Johannes Bergbc92afd2009-07-01 21:26:57 +02002706static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2707 bool enabled, int timeout)
2708{
2709 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2710 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002711
Bob Copeland2d3db212013-10-29 18:11:59 -04002712 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002713 return -EOPNOTSUPP;
2714
Johannes Berg30686bf2015-06-02 21:39:54 +02002715 if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002716 return -EOPNOTSUPP;
2717
2718 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002719 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002720 return 0;
2721
2722 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002723 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002724
Johannes Berg0f782312009-12-01 13:37:02 +01002725 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002726 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002727 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002728 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002729
Johannes Berg30686bf2015-06-02 21:39:54 +02002730 if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
Johannes Bergbc92afd2009-07-01 21:26:57 +02002731 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2732
Johannes Berg4a733ef2015-10-14 18:02:43 +02002733 ieee80211_recalc_ps(local);
Eliad Pellerab095872012-07-27 12:33:22 +03002734 ieee80211_recalc_ps_vif(sdata);
Felix Fietkau1d870162018-02-23 10:06:05 +01002735 ieee80211_check_fast_rx_iface(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002736
2737 return 0;
2738}
2739
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002740static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2741 struct net_device *dev,
2742 s32 rssi_thold, u32 rssi_hyst)
2743{
2744 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002745 struct ieee80211_vif *vif = &sdata->vif;
2746 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2747
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002748 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2749 rssi_hyst == bss_conf->cqm_rssi_hyst)
2750 return 0;
2751
Johannes Bergef9be102015-08-28 10:44:20 +02002752 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER &&
2753 !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
2754 return -EOPNOTSUPP;
2755
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002756 bss_conf->cqm_rssi_thold = rssi_thold;
2757 bss_conf->cqm_rssi_hyst = rssi_hyst;
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01002758 bss_conf->cqm_rssi_low = 0;
2759 bss_conf->cqm_rssi_high = 0;
2760 sdata->u.mgd.last_cqm_event_signal = 0;
2761
2762 /* tell the driver upon association, unless already associated */
2763 if (sdata->u.mgd.associated &&
2764 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
2765 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2766
2767 return 0;
2768}
2769
2770static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy,
2771 struct net_device *dev,
2772 s32 rssi_low, s32 rssi_high)
2773{
2774 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2775 struct ieee80211_vif *vif = &sdata->vif;
2776 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2777
2778 if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
2779 return -EOPNOTSUPP;
2780
2781 bss_conf->cqm_rssi_low = rssi_low;
2782 bss_conf->cqm_rssi_high = rssi_high;
2783 bss_conf->cqm_rssi_thold = 0;
2784 bss_conf->cqm_rssi_hyst = 0;
Sara Sharonbabc305e22015-09-21 15:47:40 +03002785 sdata->u.mgd.last_cqm_event_signal = 0;
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002786
2787 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002788 if (sdata->u.mgd.associated &&
2789 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002790 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2791
2792 return 0;
2793}
2794
Johannes Berg99303802009-07-01 21:26:59 +02002795static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2796 struct net_device *dev,
2797 const u8 *addr,
2798 const struct cfg80211_bitrate_mask *mask)
2799{
2800 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2801 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302802 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002803
Eliad Peller554a43d2012-06-12 12:41:15 +03002804 if (!ieee80211_sdata_running(sdata))
2805 return -ENETDOWN;
2806
Johannes Berge8e4f522017-03-08 11:12:10 +01002807 /*
2808 * If active validate the setting and reject it if it doesn't leave
2809 * at least one basic rate usable, since we really have to be able
2810 * to send something, and if we're an AP we have to be able to do
2811 * so at a basic rate so that all clients can receive it.
2812 */
2813 if (rcu_access_pointer(sdata->vif.chanctx_conf) &&
2814 sdata->vif.bss_conf.chandef.chan) {
2815 u32 basic_rates = sdata->vif.bss_conf.basic_rates;
2816 enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band;
2817
2818 if (!(mask->control[band].legacy & basic_rates))
2819 return -EINVAL;
2820 }
2821
Johannes Berge5f5ce32017-10-18 09:36:51 +02002822 if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
2823 ret = drv_set_bitrate_mask(local, sdata, mask);
2824 if (ret)
2825 return ret;
2826 }
2827
Johannes Berg57fbcce2016-04-12 15:56:15 +02002828 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002829 struct ieee80211_supported_band *sband = wiphy->bands[i];
2830 int j;
2831
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002832 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002833 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2834 sizeof(mask->control[i].ht_mcs));
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002835 memcpy(sdata->rc_rateidx_vht_mcs_mask[i],
2836 mask->control[i].vht_mcs,
2837 sizeof(mask->control[i].vht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002838
2839 sdata->rc_has_mcs_mask[i] = false;
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002840 sdata->rc_has_vht_mcs_mask[i] = false;
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002841 if (!sband)
2842 continue;
2843
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002844 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) {
Johannes Berg2df1b132015-08-21 14:07:13 +02002845 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002846 sdata->rc_has_mcs_mask[i] = true;
2847 break;
Johannes Berg2df1b132015-08-21 14:07:13 +02002848 }
2849 }
2850
2851 for (j = 0; j < NL80211_VHT_NSS_MAX; j++) {
2852 if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) {
2853 sdata->rc_has_vht_mcs_mask[i] = true;
2854 break;
2855 }
Lorenzo Bianconib119ad62015-08-06 23:47:33 +02002856 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002857 }
Johannes Berg99303802009-07-01 21:26:59 +02002858
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002859 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002860}
2861
Simon Wunderlich164eb022013-02-08 18:16:20 +01002862static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2863 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002864 struct cfg80211_chan_def *chandef,
2865 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002866{
2867 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2868 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002869 int err;
2870
Johannes Berg34a37402013-12-18 09:43:33 +01002871 mutex_lock(&local->mtx);
2872 if (!list_empty(&local->roc_list) || local->scanning) {
2873 err = -EBUSY;
2874 goto out_unlock;
2875 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002876
2877 /* whatever, but channel contexts should not complain about that one */
2878 sdata->smps_mode = IEEE80211_SMPS_OFF;
2879 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002880
Simon Wunderlich164eb022013-02-08 18:16:20 +01002881 err = ieee80211_vif_use_channel(sdata, chandef,
2882 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002883 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002884 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002885
Simon Wunderlich164eb022013-02-08 18:16:20 +01002886 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002887 &sdata->dfs_cac_timer_work,
2888 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002889
Johannes Berg34a37402013-12-18 09:43:33 +01002890 out_unlock:
2891 mutex_unlock(&local->mtx);
2892 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002893}
2894
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002895static struct cfg80211_beacon_data *
2896cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2897{
2898 struct cfg80211_beacon_data *new_beacon;
2899 u8 *pos;
2900 int len;
2901
2902 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2903 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
Johannes Berg03b73862018-10-30 09:17:45 +01002904 beacon->probe_resp_len + beacon->lci_len + beacon->civicloc_len;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002905
2906 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2907 if (!new_beacon)
2908 return NULL;
2909
2910 pos = (u8 *)(new_beacon + 1);
2911 if (beacon->head_len) {
2912 new_beacon->head_len = beacon->head_len;
2913 new_beacon->head = pos;
2914 memcpy(pos, beacon->head, beacon->head_len);
2915 pos += beacon->head_len;
2916 }
2917 if (beacon->tail_len) {
2918 new_beacon->tail_len = beacon->tail_len;
2919 new_beacon->tail = pos;
2920 memcpy(pos, beacon->tail, beacon->tail_len);
2921 pos += beacon->tail_len;
2922 }
2923 if (beacon->beacon_ies_len) {
2924 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2925 new_beacon->beacon_ies = pos;
2926 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2927 pos += beacon->beacon_ies_len;
2928 }
2929 if (beacon->proberesp_ies_len) {
2930 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2931 new_beacon->proberesp_ies = pos;
2932 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2933 pos += beacon->proberesp_ies_len;
2934 }
2935 if (beacon->assocresp_ies_len) {
2936 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2937 new_beacon->assocresp_ies = pos;
2938 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2939 pos += beacon->assocresp_ies_len;
2940 }
2941 if (beacon->probe_resp_len) {
2942 new_beacon->probe_resp_len = beacon->probe_resp_len;
Arnd Bergmannbee92d02018-02-02 16:31:23 +01002943 new_beacon->probe_resp = pos;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002944 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2945 pos += beacon->probe_resp_len;
2946 }
Johannes Berg03b73862018-10-30 09:17:45 +01002947
2948 /* might copy -1, meaning no changes requested */
2949 new_beacon->ftm_responder = beacon->ftm_responder;
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07002950 if (beacon->lci) {
2951 new_beacon->lci_len = beacon->lci_len;
2952 new_beacon->lci = pos;
2953 memcpy(pos, beacon->lci, beacon->lci_len);
2954 pos += beacon->lci_len;
2955 }
2956 if (beacon->civicloc) {
2957 new_beacon->civicloc_len = beacon->civicloc_len;
2958 new_beacon->civicloc = pos;
2959 memcpy(pos, beacon->civicloc, beacon->civicloc_len);
2960 pos += beacon->civicloc_len;
2961 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002962
2963 return new_beacon;
2964}
2965
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002966void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002967{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002968 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2969
2970 ieee80211_queue_work(&sdata->local->hw,
2971 &sdata->csa_finalize_work);
2972}
2973EXPORT_SYMBOL(ieee80211_csa_finish);
2974
Michal Kazior66199502014-04-09 15:11:00 +02002975static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2976 u32 *changed)
2977{
2978 int err;
2979
2980 switch (sdata->vif.type) {
2981 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002982 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2983 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002984 kfree(sdata->u.ap.next_beacon);
2985 sdata->u.ap.next_beacon = NULL;
2986
2987 if (err < 0)
2988 return err;
2989 *changed |= err;
2990 break;
2991 case NL80211_IFTYPE_ADHOC:
2992 err = ieee80211_ibss_finish_csa(sdata);
2993 if (err < 0)
2994 return err;
2995 *changed |= err;
2996 break;
2997#ifdef CONFIG_MAC80211_MESH
2998 case NL80211_IFTYPE_MESH_POINT:
2999 err = ieee80211_mesh_finish_csa(sdata);
3000 if (err < 0)
3001 return err;
3002 *changed |= err;
3003 break;
3004#endif
3005 default:
3006 WARN_ON(1);
3007 return -EINVAL;
3008 }
3009
3010 return 0;
3011}
3012
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003013static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003014{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003015 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02003016 u32 changed = 0;
3017 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003018
Michal Kaziordbd72852014-01-29 07:56:21 +01003019 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003020 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003021 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01003022
Michal Kazior03078de2014-06-25 12:35:08 +02003023 /*
3024 * using reservation isn't immediate as it may be deferred until later
3025 * with multi-vif. once reservation is complete it will re-schedule the
3026 * work with no reserved_chanctx so verify chandef to check if it
3027 * completed successfully
3028 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003029
Michal Kazior03078de2014-06-25 12:35:08 +02003030 if (sdata->reserved_chanctx) {
3031 /*
3032 * with multi-vif csa driver may call ieee80211_csa_finish()
3033 * many times while waiting for other interfaces to use their
3034 * reservations
3035 */
3036 if (sdata->reserved_ready)
3037 return 0;
3038
Fabian Frederick408b18a2014-10-09 20:36:22 +02003039 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03003040 }
3041
Michal Kazior03078de2014-06-25 12:35:08 +02003042 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
3043 &sdata->csa_chandef))
3044 return -EINVAL;
3045
Simon Wunderliche487eae2013-11-21 18:19:51 +01003046 sdata->vif.csa_active = false;
Michal Kazior97518af12014-01-29 07:56:18 +01003047
Michal Kazior66199502014-04-09 15:11:00 +02003048 err = ieee80211_set_after_csa_beacon(sdata, &changed);
3049 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003050 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003051
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003052 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02003053
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003054 if (sdata->csa_block_tx) {
3055 ieee80211_wake_vif_queues(local, sdata,
3056 IEEE80211_QUEUE_STOP_REASON_CSA);
3057 sdata->csa_block_tx = false;
3058 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003059
Luciano Coelhof1d65582014-10-08 09:48:38 +03003060 err = drv_post_channel_switch(sdata);
3061 if (err)
3062 return err;
3063
3064 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
3065
Michal Kaziorcf8767d2014-05-08 09:10:02 +02003066 return 0;
3067}
3068
3069static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3070{
3071 if (__ieee80211_csa_finalize(sdata)) {
3072 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
3073 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
3074 GFP_KERNEL);
3075 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003076}
3077
3078void ieee80211_csa_finalize_work(struct work_struct *work)
3079{
3080 struct ieee80211_sub_if_data *sdata =
3081 container_of(work, struct ieee80211_sub_if_data,
3082 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02003083 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003084
3085 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003086 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003087 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003088
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003089 /* AP might have been stopped while waiting for the lock. */
3090 if (!sdata->vif.csa_active)
3091 goto unlock;
3092
3093 if (!ieee80211_sdata_running(sdata))
3094 goto unlock;
3095
3096 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003097
3098unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02003099 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003100 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003101 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003102}
3103
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003104static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3105 struct cfg80211_csa_settings *params,
3106 u32 *changed)
3107{
Michal Kazioraf296bd2014-06-05 14:21:36 +02003108 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003109 int err;
3110
3111 switch (sdata->vif.type) {
3112 case NL80211_IFTYPE_AP:
3113 sdata->u.ap.next_beacon =
3114 cfg80211_beacon_dup(&params->beacon_after);
3115 if (!sdata->u.ap.next_beacon)
3116 return -ENOMEM;
3117
3118 /*
3119 * With a count of 0, we don't have to wait for any
3120 * TBTT before switching, so complete the CSA
3121 * immediately. In theory, with a count == 1 we
3122 * should delay the switch until just before the next
3123 * TBTT, but that would complicate things so we switch
3124 * immediately too. If we would delay the switch
3125 * until the next TBTT, we would have to set the probe
3126 * response here.
3127 *
3128 * TODO: A channel switch with count <= 1 without
3129 * sending a CSA action frame is kind of useless,
3130 * because the clients won't know we're changing
3131 * channels. The action frame must be implemented
3132 * either here or in the userspace.
3133 */
3134 if (params->count <= 1)
3135 break;
3136
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003137 if ((params->n_counter_offsets_beacon >
3138 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3139 (params->n_counter_offsets_presp >
3140 IEEE80211_MAX_CSA_COUNTERS_NUM))
3141 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003142
Michal Kazioraf296bd2014-06-05 14:21:36 +02003143 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3144 csa.counter_offsets_presp = params->counter_offsets_presp;
3145 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3146 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3147 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003148
Michal Kazioraf296bd2014-06-05 14:21:36 +02003149 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003150 if (err < 0) {
3151 kfree(sdata->u.ap.next_beacon);
3152 return err;
3153 }
3154 *changed |= err;
3155
3156 break;
3157 case NL80211_IFTYPE_ADHOC:
3158 if (!sdata->vif.bss_conf.ibss_joined)
3159 return -EINVAL;
3160
3161 if (params->chandef.width != sdata->u.ibss.chandef.width)
3162 return -EINVAL;
3163
3164 switch (params->chandef.width) {
3165 case NL80211_CHAN_WIDTH_40:
3166 if (cfg80211_get_chandef_type(&params->chandef) !=
3167 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3168 return -EINVAL;
3169 case NL80211_CHAN_WIDTH_5:
3170 case NL80211_CHAN_WIDTH_10:
3171 case NL80211_CHAN_WIDTH_20_NOHT:
3172 case NL80211_CHAN_WIDTH_20:
3173 break;
3174 default:
3175 return -EINVAL;
3176 }
3177
3178 /* changes into another band are not supported */
3179 if (sdata->u.ibss.chandef.chan->band !=
3180 params->chandef.chan->band)
3181 return -EINVAL;
3182
3183 /* see comments in the NL80211_IFTYPE_AP block */
3184 if (params->count > 1) {
3185 err = ieee80211_ibss_csa_beacon(sdata, params);
3186 if (err < 0)
3187 return err;
3188 *changed |= err;
3189 }
3190
3191 ieee80211_send_action_csa(sdata, params);
3192
3193 break;
3194#ifdef CONFIG_MAC80211_MESH
3195 case NL80211_IFTYPE_MESH_POINT: {
3196 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3197
3198 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3199 return -EINVAL;
3200
3201 /* changes into another band are not supported */
3202 if (sdata->vif.bss_conf.chandef.chan->band !=
3203 params->chandef.chan->band)
3204 return -EINVAL;
3205
3206 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3207 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3208 if (!ifmsh->pre_value)
3209 ifmsh->pre_value = 1;
3210 else
3211 ifmsh->pre_value++;
3212 }
3213
3214 /* see comments in the NL80211_IFTYPE_AP block */
3215 if (params->count > 1) {
3216 err = ieee80211_mesh_csa_beacon(sdata, params);
3217 if (err < 0) {
3218 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3219 return err;
3220 }
3221 *changed |= err;
3222 }
3223
3224 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3225 ieee80211_send_action_csa(sdata, params);
3226
3227 break;
3228 }
3229#endif
3230 default:
3231 return -EOPNOTSUPP;
3232 }
3233
3234 return 0;
3235}
3236
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003237static int
3238__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3239 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003240{
3241 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3242 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003243 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003244 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003245 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003246 u32 changed = 0;
3247 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003248
Michal Kaziordbd72852014-01-29 07:56:21 +01003249 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003250 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003251
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003252 if (!list_empty(&local->roc_list) || local->scanning)
3253 return -EBUSY;
3254
3255 if (sdata->wdev.cac_started)
3256 return -EBUSY;
3257
3258 if (cfg80211_chandef_identical(&params->chandef,
3259 &sdata->vif.bss_conf.chandef))
3260 return -EINVAL;
3261
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003262 /* don't allow another channel switch if one is already active. */
3263 if (sdata->vif.csa_active)
3264 return -EBUSY;
3265
Michal Kazior03078de2014-06-25 12:35:08 +02003266 mutex_lock(&local->chanctx_mtx);
3267 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3268 lockdep_is_held(&local->chanctx_mtx));
3269 if (!conf) {
3270 err = -EBUSY;
3271 goto out;
3272 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003273
Michal Kazior03078de2014-06-25 12:35:08 +02003274 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
Michal Kazior03078de2014-06-25 12:35:08 +02003275
Luciano Coelho000baa52014-11-07 15:28:33 +02003276 ch_switch.timestamp = 0;
3277 ch_switch.device_timestamp = 0;
3278 ch_switch.block_tx = params->block_tx;
3279 ch_switch.chandef = params->chandef;
3280 ch_switch.count = params->count;
3281
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003282 err = drv_pre_channel_switch(sdata, &ch_switch);
3283 if (err)
3284 goto out;
3285
Michal Kazior03078de2014-06-25 12:35:08 +02003286 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3287 chanctx->mode,
3288 params->radar_required);
3289 if (err)
3290 goto out;
3291
3292 /* if reservation is invalid then this will fail */
3293 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3294 if (err) {
3295 ieee80211_vif_unreserve_chanctx(sdata);
3296 goto out;
3297 }
3298
3299 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3300 if (err) {
3301 ieee80211_vif_unreserve_chanctx(sdata);
3302 goto out;
3303 }
3304
Luciano Coelho33787fc2013-11-11 20:34:54 +02003305 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003306 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003307 sdata->vif.csa_active = true;
3308
Michal Kazior59af6922014-04-09 15:10:59 +02003309 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003310 ieee80211_stop_vif_queues(local, sdata,
3311 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003312
Luciano Coelho2f457292014-11-07 14:31:36 +02003313 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3314 params->count);
3315
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003316 if (changed) {
3317 ieee80211_bss_info_change_notify(sdata, changed);
3318 drv_channel_switch_beacon(sdata, &params->chandef);
3319 } else {
3320 /* if the beacon didn't change, we can finalize immediately */
3321 ieee80211_csa_finalize(sdata);
3322 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003323
Michal Kazior03078de2014-06-25 12:35:08 +02003324out:
3325 mutex_unlock(&local->chanctx_mtx);
3326 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003327}
3328
Michal Kazior59af6922014-04-09 15:10:59 +02003329int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3330 struct cfg80211_csa_settings *params)
3331{
3332 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3333 struct ieee80211_local *local = sdata->local;
3334 int err;
3335
3336 mutex_lock(&local->mtx);
3337 err = __ieee80211_channel_switch(wiphy, dev, params);
3338 mutex_unlock(&local->mtx);
3339
3340 return err;
3341}
3342
Johannes Berga2fcfccb2015-11-23 17:18:35 +01003343u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local)
3344{
3345 lockdep_assert_held(&local->mtx);
3346
3347 local->roc_cookie_counter++;
3348
3349 /* wow, you wrapped 64 bits ... more likely a bug */
3350 if (WARN_ON(local->roc_cookie_counter == 0))
3351 local->roc_cookie_counter++;
3352
3353 return local->roc_cookie_counter;
3354}
3355
Johannes Berg5ee00db2015-11-24 14:25:49 +01003356int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb,
3357 u64 *cookie, gfp_t gfp)
Johannes Berg3b79af92015-06-01 23:14:59 +02003358{
3359 unsigned long spin_flags;
3360 struct sk_buff *ack_skb;
3361 int id;
3362
3363 ack_skb = skb_copy(skb, gfp);
3364 if (!ack_skb)
Johannes Berg5ee00db2015-11-24 14:25:49 +01003365 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003366
3367 spin_lock_irqsave(&local->ack_status_lock, spin_flags);
3368 id = idr_alloc(&local->ack_status_frames, ack_skb,
3369 1, 0x10000, GFP_ATOMIC);
3370 spin_unlock_irqrestore(&local->ack_status_lock, spin_flags);
3371
3372 if (id < 0) {
3373 kfree_skb(ack_skb);
Johannes Berg5ee00db2015-11-24 14:25:49 +01003374 return -ENOMEM;
Johannes Berg3b79af92015-06-01 23:14:59 +02003375 }
3376
3377 IEEE80211_SKB_CB(skb)->ack_frame_id = id;
3378
3379 *cookie = ieee80211_mgmt_tx_cookie(local);
3380 IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie;
3381
Johannes Berg5ee00db2015-11-24 14:25:49 +01003382 return 0;
Johannes Berg3b79af92015-06-01 23:14:59 +02003383}
3384
Johannes Berg7be50862010-10-13 12:06:24 +02003385static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003386 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003387 u16 frame_type, bool reg)
3388{
3389 struct ieee80211_local *local = wiphy_priv(wiphy);
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003390 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02003391
Will Hawkins6abe0562012-06-20 11:51:14 -04003392 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003393 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003394 if (reg) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003395 local->probe_req_reg++;
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003396 sdata->vif.probe_req_reg++;
3397 } else {
3398 if (local->probe_req_reg)
3399 local->probe_req_reg--;
3400
3401 if (sdata->vif.probe_req_reg)
3402 sdata->vif.probe_req_reg--;
3403 }
Johannes Berg7be50862010-10-13 12:06:24 +02003404
Felix Fietkau35f51492012-10-31 15:50:34 +01003405 if (!local->open_count)
3406 break;
3407
Andrei Otcheretianski1b09b552015-08-15 22:39:50 +03003408 if (sdata->vif.probe_req_reg == 1)
3409 drv_config_iface_filter(local, sdata, FIF_PROBE_REQ,
3410 FIF_PROBE_REQ);
3411 else if (sdata->vif.probe_req_reg == 0)
3412 drv_config_iface_filter(local, sdata, 0,
3413 FIF_PROBE_REQ);
3414
3415 ieee80211_configure_filter(local);
Will Hawkins6abe0562012-06-20 11:51:14 -04003416 break;
3417 default:
3418 break;
3419 }
Johannes Berg7be50862010-10-13 12:06:24 +02003420}
3421
Bruno Randolf15d96752010-11-10 12:50:56 +09003422static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3423{
3424 struct ieee80211_local *local = wiphy_priv(wiphy);
3425
3426 if (local->started)
3427 return -EOPNOTSUPP;
3428
3429 return drv_set_antenna(local, tx_ant, rx_ant);
3430}
3431
3432static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3433{
3434 struct ieee80211_local *local = wiphy_priv(wiphy);
3435
3436 return drv_get_antenna(local, tx_ant, rx_ant);
3437}
3438
Johannes Bergc68f4b82011-07-05 16:35:41 +02003439static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3440 struct net_device *dev,
3441 struct cfg80211_gtk_rekey_data *data)
3442{
3443 struct ieee80211_local *local = wiphy_priv(wiphy);
3444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3445
3446 if (!local->ops->set_rekey_data)
3447 return -EOPNOTSUPP;
3448
3449 drv_set_rekey_data(local, sdata, data);
3450
3451 return 0;
3452}
3453
Johannes Berg06500732011-11-04 11:18:16 +01003454static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3455 const u8 *peer, u64 *cookie)
3456{
3457 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3458 struct ieee80211_local *local = sdata->local;
3459 struct ieee80211_qos_hdr *nullfunc;
Johannes Berg5ee00db2015-11-24 14:25:49 +01003460 struct sk_buff *skb;
Johannes Berg06500732011-11-04 11:18:16 +01003461 int size = sizeof(*nullfunc);
3462 __le16 fc;
3463 bool qos;
3464 struct ieee80211_tx_info *info;
3465 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003466 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg57fbcce2016-04-12 15:56:15 +02003467 enum nl80211_band band;
Johannes Berg3b79af92015-06-01 23:14:59 +02003468 int ret;
3469
3470 /* the lock is needed to assign the cookie later */
3471 mutex_lock(&local->mtx);
Johannes Berg06500732011-11-04 11:18:16 +01003472
3473 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003474 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3475 if (WARN_ON(!chanctx_conf)) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003476 ret = -EINVAL;
3477 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003478 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003479 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003480 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003481 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003482 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003483 } else {
Johannes Berg3b79af92015-06-01 23:14:59 +02003484 ret = -ENOLINK;
3485 goto unlock;
Johannes Bergb4487c22011-11-11 20:22:30 +01003486 }
Johannes Berg06500732011-11-04 11:18:16 +01003487
3488 if (qos) {
3489 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3490 IEEE80211_STYPE_QOS_NULLFUNC |
3491 IEEE80211_FCTL_FROMDS);
3492 } else {
3493 size -= 2;
3494 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3495 IEEE80211_STYPE_NULLFUNC |
3496 IEEE80211_FCTL_FROMDS);
3497 }
3498
3499 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003500 if (!skb) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003501 ret = -ENOMEM;
3502 goto unlock;
Johannes Berg55de9082012-07-26 17:24:39 +02003503 }
Johannes Berg06500732011-11-04 11:18:16 +01003504
3505 skb->dev = dev;
3506
3507 skb_reserve(skb, local->hw.extra_tx_headroom);
3508
Johannes Berg4df864c2017-06-16 14:29:21 +02003509 nullfunc = skb_put(skb, size);
Johannes Berg06500732011-11-04 11:18:16 +01003510 nullfunc->frame_control = fc;
3511 nullfunc->duration_id = 0;
3512 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3513 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3514 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3515 nullfunc->seq_ctrl = 0;
3516
3517 info = IEEE80211_SKB_CB(skb);
3518
3519 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3520 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003521 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003522
3523 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3524 skb->priority = 7;
3525 if (qos)
3526 nullfunc->qos_ctrl = cpu_to_le16(7);
3527
Johannes Berg5ee00db2015-11-24 14:25:49 +01003528 ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC);
3529 if (ret) {
Johannes Berg3b79af92015-06-01 23:14:59 +02003530 kfree_skb(skb);
Johannes Berg3b79af92015-06-01 23:14:59 +02003531 goto unlock;
3532 }
3533
Johannes Berg06500732011-11-04 11:18:16 +01003534 local_bh_disable();
Johannes Bergb9771d42018-05-28 15:47:41 +02003535 ieee80211_xmit(sdata, sta, skb, 0);
Johannes Berg06500732011-11-04 11:18:16 +01003536 local_bh_enable();
3537
Johannes Berg3b79af92015-06-01 23:14:59 +02003538 ret = 0;
3539unlock:
3540 rcu_read_unlock();
3541 mutex_unlock(&local->mtx);
3542
3543 return ret;
Johannes Berg06500732011-11-04 11:18:16 +01003544}
3545
Johannes Berg683b6d32012-11-08 21:25:48 +01003546static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3547 struct wireless_dev *wdev,
3548 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003549{
Johannes Berg55de9082012-07-26 17:24:39 +02003550 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003551 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003552 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003553 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003554
Johannes Berg55de9082012-07-26 17:24:39 +02003555 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003556 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3557 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003558 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003559 ret = 0;
3560 } else if (local->open_count > 0 &&
3561 local->open_count == local->monitors &&
3562 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3563 if (local->use_chanctx)
3564 *chandef = local->monitor_chandef;
3565 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003566 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003567 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003568 }
3569 rcu_read_unlock();
3570
Johannes Berg683b6d32012-11-08 21:25:48 +01003571 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003572}
3573
Johannes Berg6d525632012-04-04 15:05:25 +02003574#ifdef CONFIG_PM
3575static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3576{
3577 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3578}
3579#endif
3580
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003581static int ieee80211_set_qos_map(struct wiphy *wiphy,
3582 struct net_device *dev,
3583 struct cfg80211_qos_map *qos_map)
3584{
3585 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3586 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3587
3588 if (qos_map) {
3589 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3590 if (!new_qos_map)
3591 return -ENOMEM;
3592 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3593 } else {
3594 /* A NULL qos_map was passed to disable QoS mapping */
3595 new_qos_map = NULL;
3596 }
3597
Johannes Berg194ff522013-12-30 23:12:37 +01003598 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003599 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3600 if (old_qos_map)
3601 kfree_rcu(old_qos_map, rcu_head);
3602
3603 return 0;
3604}
3605
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003606static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3607 struct net_device *dev,
3608 struct cfg80211_chan_def *chandef)
3609{
3610 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3611 int ret;
3612 u32 changed = 0;
3613
3614 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3615 if (ret == 0)
3616 ieee80211_bss_info_change_notify(sdata, changed);
3617
3618 return ret;
3619}
3620
Johannes Berg02219b32014-10-07 10:38:50 +03003621static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3622 u8 tsid, const u8 *peer, u8 up,
3623 u16 admitted_time)
3624{
3625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3626 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3627 int ac = ieee802_1d_to_ac[up];
3628
3629 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3630 return -EOPNOTSUPP;
3631
3632 if (!(sdata->wmm_acm & BIT(up)))
3633 return -EINVAL;
3634
3635 if (ifmgd->tx_tspec[ac].admitted_time)
3636 return -EBUSY;
3637
3638 if (admitted_time) {
3639 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3640 ifmgd->tx_tspec[ac].tsid = tsid;
3641 ifmgd->tx_tspec[ac].up = up;
3642 }
3643
3644 return 0;
3645}
3646
3647static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3648 u8 tsid, const u8 *peer)
3649{
3650 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3651 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3652 struct ieee80211_local *local = wiphy_priv(wiphy);
3653 int ac;
3654
3655 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3656 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3657
3658 /* skip unused entries */
3659 if (!tx_tspec->admitted_time)
3660 continue;
3661
3662 if (tx_tspec->tsid != tsid)
3663 continue;
3664
3665 /* due to this new packets will be reassigned to non-ACM ACs */
3666 tx_tspec->up = -1;
3667
3668 /* Make sure that all packets have been sent to avoid to
3669 * restore the QoS params on packets that are still on the
3670 * queues.
3671 */
3672 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003673 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003674
3675 /* restore the normal QoS parameters
3676 * (unconditionally to avoid races)
3677 */
3678 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3679 tx_tspec->downgraded = false;
3680 ieee80211_sta_handle_tspec_ac_params(sdata);
3681
3682 /* finally clear all the data */
3683 memset(tx_tspec, 0, sizeof(*tx_tspec));
3684
3685 return 0;
3686 }
3687
3688 return -ENOENT;
3689}
3690
Ayala Beker167e33f2016-09-20 17:31:20 +03003691void ieee80211_nan_func_terminated(struct ieee80211_vif *vif,
3692 u8 inst_id,
3693 enum nl80211_nan_func_term_reason reason,
3694 gfp_t gfp)
3695{
3696 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3697 struct cfg80211_nan_func *func;
3698 u64 cookie;
3699
3700 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3701 return;
3702
3703 spin_lock_bh(&sdata->u.nan.func_lock);
3704
3705 func = idr_find(&sdata->u.nan.function_inst_ids, inst_id);
3706 if (WARN_ON(!func)) {
3707 spin_unlock_bh(&sdata->u.nan.func_lock);
3708 return;
3709 }
3710
3711 cookie = func->cookie;
3712 idr_remove(&sdata->u.nan.function_inst_ids, inst_id);
3713
3714 spin_unlock_bh(&sdata->u.nan.func_lock);
3715
3716 cfg80211_free_nan_func(func);
3717
3718 cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id,
3719 reason, cookie, gfp);
3720}
3721EXPORT_SYMBOL(ieee80211_nan_func_terminated);
3722
Ayala Beker92bc43b2016-09-20 17:31:21 +03003723void ieee80211_nan_func_match(struct ieee80211_vif *vif,
3724 struct cfg80211_nan_match_params *match,
3725 gfp_t gfp)
3726{
3727 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3728 struct cfg80211_nan_func *func;
3729
3730 if (WARN_ON(vif->type != NL80211_IFTYPE_NAN))
3731 return;
3732
3733 spin_lock_bh(&sdata->u.nan.func_lock);
3734
3735 func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id);
3736 if (WARN_ON(!func)) {
3737 spin_unlock_bh(&sdata->u.nan.func_lock);
3738 return;
3739 }
3740 match->cookie = func->cookie;
3741
3742 spin_unlock_bh(&sdata->u.nan.func_lock);
3743
3744 cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp);
3745}
3746EXPORT_SYMBOL(ieee80211_nan_func_match);
3747
Michael Braunebceec82016-11-22 11:52:18 +01003748static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy,
3749 struct net_device *dev,
3750 const bool enabled)
3751{
3752 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3753
3754 sdata->u.ap.multicast_to_unicast = enabled;
3755
3756 return 0;
3757}
3758
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02003759void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
3760 struct txq_info *txqi)
3761{
3762 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) {
3763 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES);
3764 txqstats->backlog_bytes = txqi->tin.backlog_bytes;
3765 }
3766
3767 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) {
3768 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS);
3769 txqstats->backlog_packets = txqi->tin.backlog_packets;
3770 }
3771
3772 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) {
3773 txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS);
3774 txqstats->flows = txqi->tin.flows;
3775 }
3776
3777 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) {
3778 txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS);
3779 txqstats->drops = txqi->cstats.drop_count;
3780 }
3781
3782 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) {
3783 txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS);
3784 txqstats->ecn_marks = txqi->cstats.ecn_mark;
3785 }
3786
3787 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) {
3788 txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT);
3789 txqstats->overlimit = txqi->tin.overlimit;
3790 }
3791
3792 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) {
3793 txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS);
3794 txqstats->collisions = txqi->tin.collisions;
3795 }
3796
3797 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) {
3798 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES);
3799 txqstats->tx_bytes = txqi->tin.tx_bytes;
3800 }
3801
3802 if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) {
3803 txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS);
3804 txqstats->tx_packets = txqi->tin.tx_packets;
3805 }
3806}
3807
3808static int ieee80211_get_txq_stats(struct wiphy *wiphy,
3809 struct wireless_dev *wdev,
3810 struct cfg80211_txq_stats *txqstats)
3811{
3812 struct ieee80211_local *local = wiphy_priv(wiphy);
3813 struct ieee80211_sub_if_data *sdata;
3814 int ret = 0;
3815
3816 if (!local->ops->wake_tx_queue)
3817 return 1;
3818
3819 spin_lock_bh(&local->fq.lock);
3820 rcu_read_lock();
3821
3822 if (wdev) {
3823 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3824 if (!sdata->vif.txq) {
3825 ret = 1;
3826 goto out;
3827 }
3828 ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq));
3829 } else {
3830 /* phy stats */
3831 txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) |
3832 BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) |
3833 BIT(NL80211_TXQ_STATS_OVERLIMIT) |
3834 BIT(NL80211_TXQ_STATS_OVERMEMORY) |
3835 BIT(NL80211_TXQ_STATS_COLLISIONS) |
3836 BIT(NL80211_TXQ_STATS_MAX_FLOWS);
3837 txqstats->backlog_packets = local->fq.backlog;
3838 txqstats->backlog_bytes = local->fq.memory_usage;
3839 txqstats->overlimit = local->fq.overlimit;
3840 txqstats->overmemory = local->fq.overmemory;
3841 txqstats->collisions = local->fq.collisions;
3842 txqstats->max_flows = local->fq.flows_cnt;
3843 }
3844
3845out:
3846 rcu_read_unlock();
3847 spin_unlock_bh(&local->fq.lock);
3848
3849 return ret;
3850}
3851
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07003852static int
3853ieee80211_get_ftm_responder_stats(struct wiphy *wiphy,
3854 struct net_device *dev,
3855 struct cfg80211_ftm_responder_stats *ftm_stats)
3856{
3857 struct ieee80211_local *local = wiphy_priv(wiphy);
3858 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3859
3860 return drv_get_ftm_responder_stats(local, sdata, ftm_stats);
3861}
3862
Johannes Bergcee70132018-10-16 11:24:47 +02003863static int
3864ieee80211_start_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3865 struct cfg80211_pmsr_request *request)
3866{
3867 struct ieee80211_local *local = wiphy_priv(wiphy);
3868 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3869
3870 return drv_start_pmsr(local, sdata, request);
3871}
3872
3873static void
3874ieee80211_abort_pmsr(struct wiphy *wiphy, struct wireless_dev *dev,
3875 struct cfg80211_pmsr_request *request)
3876{
3877 struct ieee80211_local *local = wiphy_priv(wiphy);
3878 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(dev);
3879
3880 return drv_abort_pmsr(local, sdata, request);
3881}
3882
Johannes Berg8a47cea2014-01-20 23:55:44 +01003883const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003884 .add_virtual_intf = ieee80211_add_iface,
3885 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003886 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003887 .start_p2p_device = ieee80211_start_p2p_device,
3888 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003889 .add_key = ieee80211_add_key,
3890 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003891 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003892 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003893 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003894 .start_ap = ieee80211_start_ap,
3895 .change_beacon = ieee80211_change_beacon,
3896 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003897 .add_station = ieee80211_add_station,
3898 .del_station = ieee80211_del_station,
3899 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003900 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003901 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003902 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003903#ifdef CONFIG_MAC80211_MESH
3904 .add_mpath = ieee80211_add_mpath,
3905 .del_mpath = ieee80211_del_mpath,
3906 .change_mpath = ieee80211_change_mpath,
3907 .get_mpath = ieee80211_get_mpath,
3908 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003909 .get_mpp = ieee80211_get_mpp,
3910 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003911 .update_mesh_config = ieee80211_update_mesh_config,
3912 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003913 .join_mesh = ieee80211_join_mesh,
3914 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003915#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003916 .join_ocb = ieee80211_join_ocb,
3917 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003918 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003919 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003920 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003921 .suspend = ieee80211_suspend,
3922 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003923 .scan = ieee80211_scan,
Vidyullatha Kanchanapally91f123f2015-10-30 19:14:50 +05303924 .abort_scan = ieee80211_abort_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003925 .sched_scan_start = ieee80211_sched_scan_start,
3926 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003927 .auth = ieee80211_auth,
3928 .assoc = ieee80211_assoc,
3929 .deauth = ieee80211_deauth,
3930 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003931 .join_ibss = ieee80211_join_ibss,
3932 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003933 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003934 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003935 .set_tx_power = ieee80211_set_tx_power,
3936 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003937 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003938 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003939 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003940 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003941 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003942 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003943 .remain_on_channel = ieee80211_remain_on_channel,
3944 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02003945 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003946 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003947 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Andrew Zaborowski2c3c5f8c2017-02-10 04:50:22 +01003948 .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003949 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003950 .set_antenna = ieee80211_set_antenna,
3951 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003952 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003953 .tdls_oper = ieee80211_tdls_oper,
3954 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02003955 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3956 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01003957 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003958 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003959#ifdef CONFIG_PM
3960 .set_wakeup = ieee80211_set_wakeup,
3961#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003962 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003963 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003964 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003965 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003966 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003967 .add_tx_ts = ieee80211_add_tx_ts,
3968 .del_tx_ts = ieee80211_del_tx_ts,
Ayala Beker708d50e2016-09-20 17:31:14 +03003969 .start_nan = ieee80211_start_nan,
3970 .stop_nan = ieee80211_stop_nan,
Ayala Beker5953ff62016-09-20 17:31:19 +03003971 .nan_change_conf = ieee80211_nan_change_conf,
Ayala Beker167e33f2016-09-20 17:31:20 +03003972 .add_nan_func = ieee80211_add_nan_func,
3973 .del_nan_func = ieee80211_del_nan_func,
Michael Braunebceec82016-11-22 11:52:18 +01003974 .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast,
Denis Kenzior91180642018-03-26 12:52:50 -05003975 .tx_control_port = ieee80211_tx_control_port,
Toke Høiland-Jørgensen2fe4a292018-05-08 13:03:50 +02003976 .get_txq_stats = ieee80211_get_txq_stats,
Pradeep Kumar Chitrapubc847972018-10-03 20:19:20 -07003977 .get_ftm_responder_stats = ieee80211_get_ftm_responder_stats,
Johannes Bergcee70132018-10-16 11:24:47 +02003978 .start_pmsr = ieee80211_start_pmsr,
3979 .abort_pmsr = ieee80211_abort_pmsr,
Jiri Bencf0706e82007-05-05 11:45:53 -07003980};