blob: fd6860d7f55734c1c98a55763c30394f8faf46b2 [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 Bergd98ad832014-09-03 15:24:57 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Jiri Bencf0706e82007-05-05 11:45:53 -07006 *
7 * This file is GPLv2 as found in COPYING.
8 */
9
Johannes Berge8cbb4c2007-12-19 02:03:30 +010010#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070011#include <linux/nl80211.h>
12#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070014#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010015#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030016#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <net/cfg80211.h>
18#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020019#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040020#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040021#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022#include "mesh.h"
Johannes Berg02219b32014-10-07 10:38:50 +030023#include "wme.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010024
Johannes Berg552bff02012-09-19 09:26:06 +020025static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
26 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020027 enum nl80211_iftype type,
28 u32 *flags,
29 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070030{
31 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020032 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010033 struct ieee80211_sub_if_data *sdata;
34 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg84efbb82012-06-16 00:00:26 +020036 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (err)
38 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010039
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020041 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010042 sdata->u.mntr_flags = *flags;
43 }
44
Johannes Berg84efbb82012-06-16 00:00:26 +020045 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070046}
47
Johannes Berg84efbb82012-06-16 00:00:26 +020048static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070049{
Johannes Berg84efbb82012-06-16 00:00:26 +020050 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070051
Johannes Berg75636522008-07-09 14:40:35 +020052 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070053}
54
Johannes Berge36d56b2009-06-09 21:04:43 +020055static int ieee80211_change_iface(struct wiphy *wiphy,
56 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010057 enum nl80211_iftype type, u32 *flags,
58 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020059{
Johannes Berg9607e6b2009-12-23 13:15:31 +010060 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020061 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020062
Johannes Berg05c914f2008-09-11 00:01:58 +020063 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020064 if (ret)
65 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020066
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000069 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010070 else if (type == NL80211_IFTYPE_STATION &&
71 params && params->use_4addr >= 0)
72 sdata->u.mgd.use_4addr = params->use_4addr;
73
Christian Lamparter85416a42010-10-02 13:17:07 +020074 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
75 struct ieee80211_local *local = sdata->local;
76
77 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020078 u32 mask = MONITOR_FLAG_COOK_FRAMES |
79 MONITOR_FLAG_ACTIVE;
80
Christian Lamparter85416a42010-10-02 13:17:07 +020081 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020082 * Prohibit MONITOR_FLAG_COOK_FRAMES and
83 * MONITOR_FLAG_ACTIVE to be changed while the
84 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020085 * Else we would need to add a lot of cruft
86 * to update everything:
87 * cooked_mntrs, monitor and all fif_* counters
88 * reconfigure hardware
89 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020090 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020091 return -EBUSY;
92
93 ieee80211_adjust_monitor_flags(sdata, -1);
94 sdata->u.mntr_flags = *flags;
95 ieee80211_adjust_monitor_flags(sdata, 1);
96
97 ieee80211_configure_filter(local);
98 } else {
99 /*
100 * Because the interface is down, ieee80211_do_stop
101 * and ieee80211_do_open take care of "everything"
102 * mentioned in the comment above.
103 */
104 sdata->u.mntr_flags = *flags;
105 }
106 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200107
Johannes Berg42613db2007-09-28 21:52:27 +0200108 return 0;
109}
110
Johannes Bergf142c6b2012-06-18 20:07:15 +0200111static int ieee80211_start_p2p_device(struct wiphy *wiphy,
112 struct wireless_dev *wdev)
113{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200114 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
115 int ret;
116
117 mutex_lock(&sdata->local->chanctx_mtx);
118 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
119 mutex_unlock(&sdata->local->chanctx_mtx);
120 if (ret < 0)
121 return ret;
122
Johannes Bergf142c6b2012-06-18 20:07:15 +0200123 return ieee80211_do_open(wdev, true);
124}
125
126static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
127 struct wireless_dev *wdev)
128{
129 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
130}
131
Simon Wunderlichb53be792011-11-18 14:20:44 +0100132static int ieee80211_set_noack_map(struct wiphy *wiphy,
133 struct net_device *dev,
134 u16 noack_map)
135{
136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
137
138 sdata->noack_map = noack_map;
139 return 0;
140}
141
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200143 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100144 struct key_params *params)
145{
Johannes Berg26a58452010-08-27 12:35:55 +0200146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200147 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100148 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200149 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200151 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100152
Johannes Berg26a58452010-08-27 12:35:55 +0200153 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200154 return -ENETDOWN;
155
Johannes Berg97359d12010-08-10 09:46:38 +0200156 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 switch (params->cipher) {
158 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100159 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200160 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200161 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200162 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200163 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200164 case WLAN_CIPHER_SUITE_CCMP:
165 case WLAN_CIPHER_SUITE_AES_CMAC:
166 case WLAN_CIPHER_SUITE_GCMP:
167 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100168 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200169 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200170 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171 }
172
Johannes Berg97359d12010-08-10 09:46:38 +0200173 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200174 params->key, params->seq_len, params->seq,
175 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100176 if (IS_ERR(key))
177 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100178
Johannes Berge31b8212010-10-05 19:39:30 +0200179 if (pairwise)
180 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
181
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200182 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200183
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100184 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700185 if (ieee80211_vif_is_mesh(&sdata->vif))
186 sta = sta_info_get(sdata, mac_addr);
187 else
188 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100189 /*
190 * The ASSOC test makes sure the driver is ready to
191 * receive the key. When wpa_supplicant has roamed
192 * using FT, it attempts to set the key before
193 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700194 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100195 *
196 * TODO: accept the key if we have a station entry and
197 * add it to the device after the station.
198 */
199 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100200 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200201 err = -ENOENT;
202 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100203 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204 }
205
Johannes Berge548c492012-09-04 17:08:23 +0200206 switch (sdata->vif.type) {
207 case NL80211_IFTYPE_STATION:
208 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
209 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
210 break;
211 case NL80211_IFTYPE_AP:
212 case NL80211_IFTYPE_AP_VLAN:
213 /* Keys without a station are used for TX only */
214 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
215 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
216 break;
217 case NL80211_IFTYPE_ADHOC:
218 /* no MFP (yet) */
219 break;
220 case NL80211_IFTYPE_MESH_POINT:
221#ifdef CONFIG_MAC80211_MESH
222 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
223 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
224 break;
225#endif
226 case NL80211_IFTYPE_WDS:
227 case NL80211_IFTYPE_MONITOR:
228 case NL80211_IFTYPE_P2P_DEVICE:
229 case NL80211_IFTYPE_UNSPECIFIED:
230 case NUM_NL80211_IFTYPES:
231 case NL80211_IFTYPE_P2P_CLIENT:
232 case NL80211_IFTYPE_P2P_GO:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100233 case NL80211_IFTYPE_OCB:
Johannes Berge548c492012-09-04 17:08:23 +0200234 /* shouldn't happen */
235 WARN_ON_ONCE(1);
236 break;
237 }
238
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200239 if (sta)
240 sta->cipher_scheme = cs;
241
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300242 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100243
Johannes Berg3b967662008-04-08 17:56:52 +0200244 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200245 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200246
247 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100248}
249
250static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200251 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100252{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200253 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
254 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100255 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200256 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100257 int ret;
258
Johannes Berg5c0c3642011-05-12 14:31:49 +0200259 mutex_lock(&local->sta_mtx);
260 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200261
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100262 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200263 ret = -ENOENT;
264
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100265 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100266 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200267 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100268
Johannes Berg5c0c3642011-05-12 14:31:49 +0200269 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200270 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200271 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200272 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200273 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200274 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100275
Johannes Berg5c0c3642011-05-12 14:31:49 +0200276 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200277 ret = -ENOENT;
278 goto out_unlock;
279 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100280
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100281 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100282
Johannes Berg3b967662008-04-08 17:56:52 +0200283 ret = 0;
284 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200285 mutex_unlock(&local->key_mtx);
286 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200287
288 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100289}
290
Johannes Berg62da92f2007-12-19 02:03:31 +0100291static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200292 u8 key_idx, bool pairwise, const u8 *mac_addr,
293 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100294 void (*callback)(void *cookie,
295 struct key_params *params))
296{
Johannes Berg14db74b2008-07-29 13:22:52 +0200297 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100298 struct sta_info *sta = NULL;
299 u8 seq[6] = {0};
300 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200301 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200302 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100303 u32 iv32;
304 u16 iv16;
305 int err = -ENOENT;
306
Johannes Berg14db74b2008-07-29 13:22:52 +0200307 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
308
Johannes Berg3b967662008-04-08 17:56:52 +0200309 rcu_read_lock();
310
Johannes Berg62da92f2007-12-19 02:03:31 +0100311 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100312 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100313 if (!sta)
314 goto out;
315
Max Stepanov354e1592013-12-08 13:30:52 +0200316 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200317 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200318 else if (!pairwise &&
319 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200320 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100321 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200322 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100323
324 if (!key)
325 goto out;
326
327 memset(&params, 0, sizeof(params));
328
Johannes Berg97359d12010-08-10 09:46:38 +0200329 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100330
Johannes Berg97359d12010-08-10 09:46:38 +0200331 switch (key->conf.cipher) {
332 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700333 iv32 = key->u.tkip.tx.iv32;
334 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100335
Johannes Berg24487982009-04-23 18:52:52 +0200336 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
337 drv_get_tkip_seq(sdata->local,
338 key->conf.hw_key_idx,
339 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100340
341 seq[0] = iv16 & 0xff;
342 seq[1] = (iv16 >> 8) & 0xff;
343 seq[2] = iv32 & 0xff;
344 seq[3] = (iv32 >> 8) & 0xff;
345 seq[4] = (iv32 >> 16) & 0xff;
346 seq[5] = (iv32 >> 24) & 0xff;
347 params.seq = seq;
348 params.seq_len = 6;
349 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200350 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200351 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
352 seq[0] = pn64;
353 seq[1] = pn64 >> 8;
354 seq[2] = pn64 >> 16;
355 seq[3] = pn64 >> 24;
356 seq[4] = pn64 >> 32;
357 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100358 params.seq = seq;
359 params.seq_len = 6;
360 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200361 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200362 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
363 seq[0] = pn64;
364 seq[1] = pn64 >> 8;
365 seq[2] = pn64 >> 16;
366 seq[3] = pn64 >> 24;
367 seq[4] = pn64 >> 32;
368 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200369 params.seq = seq;
370 params.seq_len = 6;
371 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100372 }
373
374 params.key = key->conf.key;
375 params.key_len = key->conf.keylen;
376
377 callback(cookie, &params);
378 err = 0;
379
380 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200381 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100382 return err;
383}
384
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100385static int ieee80211_config_default_key(struct wiphy *wiphy,
386 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100387 u8 key_idx, bool uni,
388 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100389{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200390 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100391
Johannes Bergf7e01042010-12-09 19:49:02 +0100392 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100393
394 return 0;
395}
396
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200397static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
398 struct net_device *dev,
399 u8 key_idx)
400{
Johannes Berg66c52422010-07-22 13:58:51 +0200401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200402
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200403 ieee80211_set_default_mgmt_key(sdata, key_idx);
404
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200405 return 0;
406}
407
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800408void sta_set_rate_info_tx(struct sta_info *sta,
409 const struct ieee80211_tx_rate *rate,
410 struct rate_info *rinfo)
411{
412 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100413 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800414 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100415 rinfo->mcs = rate->idx;
416 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
417 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
418 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
419 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
420 } else {
421 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200422 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
423 u16 brate;
424
Johannes Berg8bc83c22012-11-09 18:38:32 +0100425 sband = sta->local->hw.wiphy->bands[
426 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200427 brate = sband->bitrates[rate->idx].bitrate;
428 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100429 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800430 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
431 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100432 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
433 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
434 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
435 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800436 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
437 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800438}
439
Saravana003e6762012-11-28 18:29:38 +0530440void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
441{
442 rinfo->flags = 0;
443
444 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
445 rinfo->flags |= RATE_INFO_FLAGS_MCS;
446 rinfo->mcs = sta->last_rx_rate_idx;
447 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
448 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
449 rinfo->nss = sta->last_rx_rate_vht_nss;
450 rinfo->mcs = sta->last_rx_rate_idx;
451 } else {
452 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200453 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
454 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530455
456 sband = sta->local->hw.wiphy->bands[
457 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200458 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
459 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530460 }
461
462 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
463 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
464 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
465 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200466 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530467 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200468 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530469 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200470 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
Saravana003e6762012-11-28 18:29:38 +0530471 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
472}
473
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100474static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200475 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100476{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100477 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300478 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100479 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100480 int ret = -ENOENT;
481
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300482 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100483
Johannes Berg3b53fde82009-11-16 12:00:37 +0100484 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100485 if (sta) {
486 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200487 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100488 sta_set_sinfo(sta, sinfo);
489 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100490
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300491 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100492
Johannes Bergd0709a62008-02-25 16:27:46 +0100493 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100494}
495
Holger Schurig12897232010-04-19 10:23:57 +0200496static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
497 int idx, struct survey_info *survey)
498{
499 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
500
Holger Schurig12897232010-04-19 10:23:57 +0200501 return drv_get_survey(local, idx, survey);
502}
503
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100504static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200505 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100506{
Johannes Bergabe60632009-11-25 17:46:18 +0100507 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300508 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100509 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100510 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100511
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300512 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100513
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100514 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100515 if (sta) {
516 ret = 0;
517 sta_set_sinfo(sta, sinfo);
518 }
519
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300520 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100521
522 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100523}
524
Johannes Berge8c9bd52012-06-06 08:18:22 +0200525static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100526 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200527{
Johannes Berg55de9082012-07-26 17:24:39 +0200528 struct ieee80211_local *local = wiphy_priv(wiphy);
529 struct ieee80211_sub_if_data *sdata;
530 int ret = 0;
531
Johannes Berg4bf88532012-11-09 11:39:59 +0100532 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200533 return 0;
534
Johannes Berg34a37402013-12-18 09:43:33 +0100535 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200536 mutex_lock(&local->iflist_mtx);
537 if (local->use_chanctx) {
538 sdata = rcu_dereference_protected(
539 local->monitor_sdata,
540 lockdep_is_held(&local->iflist_mtx));
541 if (sdata) {
542 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100543 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200544 IEEE80211_CHANCTX_EXCLUSIVE);
545 }
546 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100547 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200548 ieee80211_hw_config(local, 0);
549 }
550
Johannes Berg4bf88532012-11-09 11:39:59 +0100551 if (ret == 0)
552 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200553 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100554 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200555
556 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200557}
558
Arik Nemtsov02945822011-11-10 11:28:57 +0200559static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200560 const u8 *resp, size_t resp_len,
561 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200562{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300563 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200564
565 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530566 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200567
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100568 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200569
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300570 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200571 if (!new)
572 return -ENOMEM;
573
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300574 new->len = resp_len;
575 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200576
Michal Kazioraf296bd2014-06-05 14:21:36 +0200577 if (csa)
578 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
579 csa->n_counter_offsets_presp *
580 sizeof(new->csa_counter_offsets[0]));
581
Arik Nemtsov02945822011-11-10 11:28:57 +0200582 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300583 if (old)
584 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200585
586 return 0;
587}
588
Luciano Coelho0ae07962013-12-08 09:42:25 +0200589static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200590 struct cfg80211_beacon_data *params,
591 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100592{
593 struct beacon_data *new, *old;
594 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100595 int size, err;
596 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100597
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100598 old = sdata_dereference(sdata->u.ap.beacon, sdata);
599
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100600
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100601 /* Need to have a beacon head if we don't have one yet */
602 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100603 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100604
605 /* new or old head? */
606 if (params->head)
607 new_head_len = params->head_len;
608 else
609 new_head_len = old->head_len;
610
611 /* new or old tail? */
612 if (params->tail || !old)
613 /* params->tail_len will be zero for !params->tail */
614 new_tail_len = params->tail_len;
615 else
616 new_tail_len = old->tail_len;
617
618 size = sizeof(*new) + new_head_len + new_tail_len;
619
620 new = kzalloc(size, GFP_KERNEL);
621 if (!new)
622 return -ENOMEM;
623
624 /* start filling the new info now */
625
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100626 /*
627 * pointers go into the block we allocated,
628 * memory is | beacon_data | head | tail |
629 */
630 new->head = ((u8 *) new) + sizeof(*new);
631 new->tail = new->head + new_head_len;
632 new->head_len = new_head_len;
633 new->tail_len = new_tail_len;
634
Michal Kazioraf296bd2014-06-05 14:21:36 +0200635 if (csa) {
636 new->csa_current_counter = csa->count;
637 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
638 csa->n_counter_offsets_beacon *
639 sizeof(new->csa_counter_offsets[0]));
640 }
641
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100642 /* copy in head */
643 if (params->head)
644 memcpy(new->head, params->head, new_head_len);
645 else
646 memcpy(new->head, old->head, new_head_len);
647
648 /* copy in optional tail */
649 if (params->tail)
650 memcpy(new->tail, params->tail, new_tail_len);
651 else
652 if (old)
653 memcpy(new->tail, old->tail, new_tail_len);
654
Johannes Berg88600202012-02-13 15:17:18 +0100655 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200656 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100657 if (err < 0)
658 return err;
659 if (err == 0)
660 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100661
Eric Dumazetcf778b02012-01-12 04:41:32 +0000662 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100663
Johannes Berg88600202012-02-13 15:17:18 +0100664 if (old)
665 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100666
Johannes Berg88600202012-02-13 15:17:18 +0100667 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100668}
669
Johannes Berg88600202012-02-13 15:17:18 +0100670static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
671 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100672{
Johannes Berg88600202012-02-13 15:17:18 +0100673 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100674 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100675 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100676 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100677 u32 changed = BSS_CHANGED_BEACON_INT |
678 BSS_CHANGED_BEACON_ENABLED |
679 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100680 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +0100681 BSS_CHANGED_P2P_PS |
682 BSS_CHANGED_TXPOWER;
Johannes Berg88600202012-02-13 15:17:18 +0100683 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200684
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100685 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100686 if (old)
687 return -EALREADY;
688
Eliad Pellerf6993172014-09-10 14:07:35 +0300689 switch (params->smps_mode) {
690 case NL80211_SMPS_OFF:
691 sdata->smps_mode = IEEE80211_SMPS_OFF;
692 break;
693 case NL80211_SMPS_STATIC:
694 sdata->smps_mode = IEEE80211_SMPS_STATIC;
695 break;
696 case NL80211_SMPS_DYNAMIC:
697 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
698 break;
699 default:
700 return -EINVAL;
701 }
Johannes Berg04ecd252012-09-11 14:34:12 +0200702 sdata->needed_rx_chains = sdata->local->rx_chains;
703
Johannes Berg34a37402013-12-18 09:43:33 +0100704 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100705 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200706 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100707 if (!err)
708 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100709 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200710 if (err)
711 return err;
712
Johannes Berg665c93a2011-11-04 11:18:11 +0100713 /*
714 * Apply control port protocol, this allows us to
715 * not encrypt dynamic WEP control frames.
716 */
717 sdata->control_port_protocol = params->crypto.control_port_ethertype;
718 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200719 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
720 &params->crypto,
721 sdata->vif.type);
722
Johannes Berg665c93a2011-11-04 11:18:11 +0100723 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
724 vlan->control_port_protocol =
725 params->crypto.control_port_ethertype;
726 vlan->control_port_no_encrypt =
727 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200728 vlan->encrypt_headroom =
729 ieee80211_cs_headroom(sdata->local,
730 &params->crypto,
731 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100732 }
733
Johannes Berg88600202012-02-13 15:17:18 +0100734 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
735 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100736 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100737
738 sdata->vif.bss_conf.ssid_len = params->ssid_len;
739 if (params->ssid_len)
740 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
741 params->ssid_len);
742 sdata->vif.bss_conf.hidden_ssid =
743 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
744
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100745 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
746 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
747 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
748 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
749 if (params->p2p_opp_ps)
750 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
751 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100752
Michal Kazioraf296bd2014-06-05 14:21:36 +0200753 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200754 if (err < 0) {
755 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100756 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200757 }
Johannes Berg88600202012-02-13 15:17:18 +0100758 changed |= err;
759
Johannes Berg10416382012-10-19 15:44:42 +0200760 err = drv_start_ap(sdata->local, sdata);
761 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100762 old = sdata_dereference(sdata->u.ap.beacon, sdata);
763
Johannes Berg10416382012-10-19 15:44:42 +0200764 if (old)
765 kfree_rcu(old, rcu_head);
766 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200767 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200768 return err;
769 }
770
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800771 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100772 ieee80211_bss_info_change_notify(sdata, changed);
773
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200774 netif_carrier_on(dev);
775 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
776 netif_carrier_on(vlan->dev);
777
Johannes Berg665c93a2011-11-04 11:18:11 +0100778 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100779}
780
Johannes Berg88600202012-02-13 15:17:18 +0100781static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
782 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100783{
Johannes Berg14db74b2008-07-29 13:22:52 +0200784 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100785 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100786 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100787
Johannes Berg14db74b2008-07-29 13:22:52 +0200788 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100789 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200790
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200791 /* don't allow changing the beacon while CSA is in place - offset
792 * of channel switch counter may change
793 */
794 if (sdata->vif.csa_active)
795 return -EBUSY;
796
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100797 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100798 if (!old)
799 return -ENOENT;
800
Michal Kazioraf296bd2014-06-05 14:21:36 +0200801 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100802 if (err < 0)
803 return err;
804 ieee80211_bss_info_change_notify(sdata, err);
805 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100806}
807
Johannes Berg88600202012-02-13 15:17:18 +0100808static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100809{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200810 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
811 struct ieee80211_sub_if_data *vlan;
812 struct ieee80211_local *local = sdata->local;
813 struct beacon_data *old_beacon;
814 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100815 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100816
Michal Kaziordbd72852014-01-29 07:56:21 +0100817 sdata_assert_lock(sdata);
818
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100819 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200820 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100821 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100822 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100823
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200824 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200825 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200826 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300827 if (sdata->csa_block_tx) {
828 ieee80211_wake_vif_queues(local, sdata,
829 IEEE80211_QUEUE_STOP_REASON_CSA);
830 sdata->csa_block_tx = false;
831 }
832
Michal Kazior59af6922014-04-09 15:10:59 +0200833 mutex_unlock(&local->mtx);
834
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100835 kfree(sdata->u.ap.next_beacon);
836 sdata->u.ap.next_beacon = NULL;
837
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200838 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200839 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
840 netif_carrier_off(vlan->dev);
841 netif_carrier_off(dev);
842
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200843 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000844 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200845 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
846 kfree_rcu(old_beacon, rcu_head);
847 if (old_probe_resp)
848 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200849 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100850
Johannes Berge7162512013-12-04 23:18:37 +0100851 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100852 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100853
Johannes Bergd6a83222012-12-14 14:06:28 +0100854 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200855 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100856 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200857 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100858
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200859 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100860 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200861 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100862 cfg80211_cac_event(sdata->dev, &chandef,
863 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200864 GFP_KERNEL);
865 }
866
Johannes Berg10416382012-10-19 15:44:42 +0200867 drv_stop_ap(sdata->local, sdata);
868
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200869 /* free all potentially still buffered bcast frames */
870 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
871 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
872
Johannes Berg34a37402013-12-18 09:43:33 +0100873 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100874 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200875 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100876 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200877
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200878 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100879}
880
Johannes Berg4fd69312007-12-19 02:03:35 +0100881/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
882struct iapp_layer2_update {
883 u8 da[ETH_ALEN]; /* broadcast */
884 u8 sa[ETH_ALEN]; /* STA addr */
885 __be16 len; /* 6 */
886 u8 dsap; /* 0 */
887 u8 ssap; /* 0 */
888 u8 control;
889 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700890} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100891
892static void ieee80211_send_layer2_update(struct sta_info *sta)
893{
894 struct iapp_layer2_update *msg;
895 struct sk_buff *skb;
896
897 /* Send Level 2 Update Frame to update forwarding tables in layer 2
898 * bridge devices */
899
900 skb = dev_alloc_skb(sizeof(*msg));
901 if (!skb)
902 return;
903 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
904
905 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
906 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
907
Johannes Berge83e6542012-07-13 16:23:07 +0200908 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200909 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100910 msg->len = htons(6);
911 msg->dsap = 0;
912 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
913 msg->control = 0xaf; /* XID response lsb.1111F101.
914 * F=0 (no poll command; unsolicited frame) */
915 msg->xid_info[0] = 0x81; /* XID format identifier */
916 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
917 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
918
Johannes Bergd0709a62008-02-25 16:27:46 +0100919 skb->dev = sta->sdata->dev;
920 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100921 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400922 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100923}
924
Johannes Bergd582cff2012-10-26 17:53:44 +0200925static int sta_apply_auth_flags(struct ieee80211_local *local,
926 struct sta_info *sta,
927 u32 mask, u32 set)
928{
929 int ret;
930
931 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
932 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
933 !test_sta_flag(sta, WLAN_STA_AUTH)) {
934 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
935 if (ret)
936 return ret;
937 }
938
939 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
940 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
941 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
942 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
943 if (ret)
944 return ret;
945 }
946
947 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
948 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
949 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
950 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
951 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
952 else
953 ret = 0;
954 if (ret)
955 return ret;
956 }
957
958 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
959 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
960 test_sta_flag(sta, WLAN_STA_ASSOC)) {
961 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
962 if (ret)
963 return ret;
964 }
965
966 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
967 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
968 test_sta_flag(sta, WLAN_STA_AUTH)) {
969 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
970 if (ret)
971 return ret;
972 }
973
974 return 0;
975}
976
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100977static int sta_apply_parameters(struct ieee80211_local *local,
978 struct sta_info *sta,
979 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100980{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100981 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100982 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100983 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +0200984 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300985 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100986
Johannes Berg55de9082012-07-26 17:24:39 +0200987 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +0200988
Johannes Bergeccb8e82009-05-11 21:57:56 +0300989 mask = params->sta_flags_mask;
990 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100991
Johannes Bergd582cff2012-10-26 17:53:44 +0200992 if (ieee80211_vif_is_mesh(&sdata->vif)) {
993 /*
994 * In mesh mode, ASSOCIATED isn't part of the nl80211
995 * API but must follow AUTHENTICATED for driver state.
996 */
997 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
998 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
999 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1000 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001001 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1002 /*
1003 * TDLS -- everything follows authorized, but
1004 * only becoming authorized is possible, not
1005 * going back
1006 */
1007 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1008 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1009 BIT(NL80211_STA_FLAG_ASSOCIATED);
1010 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1011 BIT(NL80211_STA_FLAG_ASSOCIATED);
1012 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001013 }
1014
Arik Nemtsov68885a52014-06-11 17:18:19 +03001015 /* auth flags will be set later for TDLS stations */
1016 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1017 ret = sta_apply_auth_flags(local, sta, mask, set);
1018 if (ret)
1019 return ret;
1020 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001021
Johannes Bergeccb8e82009-05-11 21:57:56 +03001022 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001023 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001024 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1025 else
1026 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001027 }
1028
Johannes Berga74a8c82014-07-22 14:50:47 +02001029 if (mask & BIT(NL80211_STA_FLAG_WME))
1030 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001031
1032 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001033 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001034 set_sta_flag(sta, WLAN_STA_MFP);
1035 else
1036 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001037 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001038
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001039 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001040 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001041 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1042 else
1043 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001044 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001045
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001046 /* mark TDLS channel switch support, if the AP allows it */
1047 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1048 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1049 params->ext_capab_len >= 4 &&
1050 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1051 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1052
Johannes Berg3b9ce802011-09-27 20:56:12 +02001053 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1054 sta->sta.uapsd_queues = params->uapsd_queues;
1055 sta->sta.max_sp = params->max_sp;
1056 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001057
Johannes Berg73651ee2008-02-25 16:27:47 +01001058 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001059 * cfg80211 validates this (1-2007) and allows setting the AID
1060 * only when creating a new station entry
1061 */
1062 if (params->aid)
1063 sta->sta.aid = params->aid;
1064
1065 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001066 * Some of the following updates would be racy if called on an
1067 * existing station, via ieee80211_change_station(). However,
1068 * all such changes are rejected by cfg80211 except for updates
1069 * changing the supported rates on an existing but not yet used
1070 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001071 */
1072
Johannes Berg4fd69312007-12-19 02:03:35 +01001073 if (params->listen_interval >= 0)
1074 sta->listen_interval = params->listen_interval;
1075
1076 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001077 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1078 sband, params->supported_rates,
1079 params->supported_rates_len,
1080 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001081 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001082
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001083 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001084 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001085 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001086
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001087 if (params->vht_capa)
1088 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001089 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001090
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001091 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001092 /* returned value is only needed for rc update, but the
1093 * rc isn't initialized here yet, so ignore it
1094 */
1095 __ieee80211_vht_handle_opmode(sdata, sta,
1096 params->opmode_notif,
1097 band, false);
1098 }
1099
Javier Cardona9c3990a2011-05-03 16:57:11 -07001100 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001101#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001102 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001103
1104 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001105 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001106 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001107 if (sta->plink_state != NL80211_PLINK_ESTAB)
1108 changed = mesh_plink_inc_estab_count(
1109 sdata);
1110 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001111
1112 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001113 changed |= ieee80211_mps_set_sta_local_pm(sta,
1114 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001115 break;
1116 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001117 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001118 case NL80211_PLINK_OPN_SNT:
1119 case NL80211_PLINK_OPN_RCVD:
1120 case NL80211_PLINK_CNF_RCVD:
1121 case NL80211_PLINK_HOLDING:
1122 if (sta->plink_state == NL80211_PLINK_ESTAB)
1123 changed = mesh_plink_dec_estab_count(
1124 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001125 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001126
1127 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001128 changed |= ieee80211_mps_set_sta_local_pm(sta,
1129 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001130 break;
1131 default:
1132 /* nothing */
1133 break;
1134 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001135 }
1136
1137 switch (params->plink_action) {
1138 case NL80211_PLINK_ACTION_NO_ACTION:
1139 /* nothing */
1140 break;
1141 case NL80211_PLINK_ACTION_OPEN:
1142 changed |= mesh_plink_open(sta);
1143 break;
1144 case NL80211_PLINK_ACTION_BLOCK:
1145 changed |= mesh_plink_block(sta);
1146 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001147 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001148
1149 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001150 changed |=
1151 ieee80211_mps_set_sta_local_pm(sta,
1152 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001153 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001154#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001155 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001156
Arik Nemtsov68885a52014-06-11 17:18:19 +03001157 /* set the STA state after all sta info from usermode has been set */
1158 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1159 ret = sta_apply_auth_flags(local, sta, mask, set);
1160 if (ret)
1161 return ret;
1162 }
1163
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001164 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001165}
1166
1167static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001168 const u8 *mac,
1169 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001170{
Johannes Berg14db74b2008-07-29 13:22:52 +02001171 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001172 struct sta_info *sta;
1173 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001174 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001175 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001176
Johannes Berg4fd69312007-12-19 02:03:35 +01001177 if (params->vlan) {
1178 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1179
Johannes Berg05c914f2008-09-11 00:01:58 +02001180 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1181 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001182 return -EINVAL;
1183 } else
1184 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1185
Joe Perchesb203ca32012-05-08 18:56:52 +00001186 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001187 return -EINVAL;
1188
1189 if (is_multicast_ether_addr(mac))
1190 return -EINVAL;
1191
1192 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001193 if (!sta)
1194 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001195
Johannes Bergd582cff2012-10-26 17:53:44 +02001196 /*
1197 * defaults -- if userspace wants something else we'll
1198 * change it accordingly in sta_apply_parameters()
1199 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001200 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1201 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1202 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001203 } else {
1204 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001205 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001206
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001207 err = sta_apply_parameters(local, sta, params);
1208 if (err) {
1209 sta_info_free(local, sta);
1210 return err;
1211 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001212
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001213 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001214 * for TDLS, rate control should be initialized only when
1215 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001216 */
1217 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1218 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001219
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001220 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1221 sdata->vif.type == NL80211_IFTYPE_AP;
1222
Johannes Berg34e89502010-02-03 13:59:58 +01001223 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001224 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001225 rcu_read_unlock();
1226 return err;
1227 }
1228
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001229 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001230 ieee80211_send_layer2_update(sta);
1231
1232 rcu_read_unlock();
1233
Johannes Berg4fd69312007-12-19 02:03:35 +01001234 return 0;
1235}
1236
1237static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001238 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001239{
Johannes Berg14db74b2008-07-29 13:22:52 +02001240 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001241
Johannes Berg14db74b2008-07-29 13:22:52 +02001242 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1243
Jouni Malinen89c771e2014-10-10 20:52:40 +03001244 if (params->mac)
1245 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001246
Johannes Bergb998e8b2012-12-13 23:07:46 +01001247 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001248 return 0;
1249}
1250
1251static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001252 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001253 struct station_parameters *params)
1254{
Johannes Bergabe60632009-11-25 17:46:18 +01001255 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001256 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001257 struct sta_info *sta;
1258 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001259 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001260 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001261
Johannes Berg87be1e12011-12-14 12:20:29 +01001262 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001263
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001264 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001265 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001266 err = -ENOENT;
1267 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001268 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001269
Johannes Berg77ee7c82013-02-15 00:48:33 +01001270 switch (sdata->vif.type) {
1271 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001272 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001273 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001274 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001275 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001276 break;
1277 case NL80211_IFTYPE_ADHOC:
1278 statype = CFG80211_STA_IBSS;
1279 break;
1280 case NL80211_IFTYPE_STATION:
1281 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1282 statype = CFG80211_STA_AP_STA;
1283 break;
1284 }
1285 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1286 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1287 else
1288 statype = CFG80211_STA_TDLS_PEER_SETUP;
1289 break;
1290 case NL80211_IFTYPE_AP:
1291 case NL80211_IFTYPE_AP_VLAN:
1292 statype = CFG80211_STA_AP_CLIENT;
1293 break;
1294 default:
1295 err = -EOPNOTSUPP;
1296 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001297 }
1298
Johannes Berg77ee7c82013-02-15 00:48:33 +01001299 err = cfg80211_check_station_change(wiphy, params, statype);
1300 if (err)
1301 goto out_err;
1302
Johannes Bergd0709a62008-02-25 16:27:46 +01001303 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001304 bool prev_4addr = false;
1305 bool new_4addr = false;
1306
Johannes Berg4fd69312007-12-19 02:03:35 +01001307 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1308
Johannes Berg9bc383d2009-11-19 11:55:19 +01001309 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001310 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001311 err = -EBUSY;
1312 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001313 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001314
Eric Dumazetcf778b02012-01-12 04:41:32 +00001315 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001316 new_4addr = true;
1317 }
1318
1319 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1320 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301321 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001322 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001323 }
1324
Johannes Berg14db74b2008-07-29 13:22:52 +02001325 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001326
1327 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1328 prev_4addr != new_4addr) {
1329 if (new_4addr)
1330 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1331 else
1332 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1333 }
1334
Johannes Berg4fd69312007-12-19 02:03:35 +01001335 ieee80211_send_layer2_update(sta);
1336 }
1337
Eliad Peller35b88622011-12-29 14:41:39 +02001338 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001339 if (err)
1340 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001341
Johannes Berg77ee7c82013-02-15 00:48:33 +01001342 /* When peer becomes authorized, init rate control as well */
1343 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1344 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001345 rate_control_rate_init(sta);
1346
Johannes Berg87be1e12011-12-14 12:20:29 +01001347 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001348
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001349 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1350 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1351 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1352 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1353 sta_info_tx_streams(sta) != 1) {
1354 ht_dbg(sta->sdata,
1355 "%pM just authorized and MIMO capable - update SMPS\n",
1356 sta->sta.addr);
1357 ieee80211_send_smps_action(sta->sdata,
1358 sta->sdata->bss->req_smps,
1359 sta->sta.addr,
1360 sta->sdata->vif.bss_conf.bssid);
1361 }
1362
Jason Young808118c2011-03-10 16:43:19 -08001363 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001364 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001365 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001366 ieee80211_recalc_ps_vif(sdata);
1367 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001368
Johannes Berg4fd69312007-12-19 02:03:35 +01001369 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001370out_err:
1371 mutex_unlock(&local->sta_mtx);
1372 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001373}
1374
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001375#ifdef CONFIG_MAC80211_MESH
1376static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001377 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001378{
Johannes Berg14db74b2008-07-29 13:22:52 +02001379 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001380 struct mesh_path *mpath;
1381 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001382
Johannes Berg14db74b2008-07-29 13:22:52 +02001383 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1384
Johannes Bergd0709a62008-02-25 16:27:46 +01001385 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001386 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001387 if (!sta) {
1388 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001390 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001391
Bob Copelandae76eef2013-03-29 09:38:39 -04001392 mpath = mesh_path_add(sdata, dst);
1393 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001394 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001395 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001396 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001397
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001398 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001399
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001400 rcu_read_unlock();
1401 return 0;
1402}
1403
1404static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001405 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001406{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001407 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001408
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001409 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001410 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001411
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001412 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001413 return 0;
1414}
1415
Johannes Berg3b3a0162014-05-19 17:19:31 +02001416static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1417 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001418{
Johannes Berg14db74b2008-07-29 13:22:52 +02001419 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001420 struct mesh_path *mpath;
1421 struct sta_info *sta;
1422
Johannes Berg14db74b2008-07-29 13:22:52 +02001423 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1424
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001425 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001426
Johannes Bergabe60632009-11-25 17:46:18 +01001427 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001428 if (!sta) {
1429 rcu_read_unlock();
1430 return -ENOENT;
1431 }
1432
Johannes Bergbf7cd942013-02-15 14:40:31 +01001433 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001434 if (!mpath) {
1435 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001436 return -ENOENT;
1437 }
1438
1439 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001440
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001441 rcu_read_unlock();
1442 return 0;
1443}
1444
1445static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1446 struct mpath_info *pinfo)
1447{
Johannes Berga3836e02011-05-12 15:11:37 +02001448 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1449
1450 if (next_hop_sta)
1451 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001452 else
1453 memset(next_hop, 0, ETH_ALEN);
1454
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001455 memset(pinfo, 0, sizeof(*pinfo));
1456
Johannes Bergf5ea9122009-08-07 16:17:38 +02001457 pinfo->generation = mesh_paths_generation;
1458
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001459 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001460 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001461 MPATH_INFO_METRIC |
1462 MPATH_INFO_EXPTIME |
1463 MPATH_INFO_DISCOVERY_TIMEOUT |
1464 MPATH_INFO_DISCOVERY_RETRIES |
1465 MPATH_INFO_FLAGS;
1466
1467 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001468 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001469 pinfo->metric = mpath->metric;
1470 if (time_before(jiffies, mpath->exp_time))
1471 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1472 pinfo->discovery_timeout =
1473 jiffies_to_msecs(mpath->discovery_timeout);
1474 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001475 if (mpath->flags & MESH_PATH_ACTIVE)
1476 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1477 if (mpath->flags & MESH_PATH_RESOLVING)
1478 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001479 if (mpath->flags & MESH_PATH_SN_VALID)
1480 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001481 if (mpath->flags & MESH_PATH_FIXED)
1482 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001483 if (mpath->flags & MESH_PATH_RESOLVED)
1484 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001485}
1486
1487static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1488 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1489
1490{
Johannes Berg14db74b2008-07-29 13:22:52 +02001491 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001492 struct mesh_path *mpath;
1493
Johannes Berg14db74b2008-07-29 13:22:52 +02001494 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1495
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001496 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001497 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001498 if (!mpath) {
1499 rcu_read_unlock();
1500 return -ENOENT;
1501 }
1502 memcpy(dst, mpath->dst, ETH_ALEN);
1503 mpath_set_pinfo(mpath, next_hop, pinfo);
1504 rcu_read_unlock();
1505 return 0;
1506}
1507
1508static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001509 int idx, u8 *dst, u8 *next_hop,
1510 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001511{
Johannes Berg14db74b2008-07-29 13:22:52 +02001512 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001513 struct mesh_path *mpath;
1514
Johannes Berg14db74b2008-07-29 13:22:52 +02001515 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1516
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001517 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001518 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001519 if (!mpath) {
1520 rcu_read_unlock();
1521 return -ENOENT;
1522 }
1523 memcpy(dst, mpath->dst, ETH_ALEN);
1524 mpath_set_pinfo(mpath, next_hop, pinfo);
1525 rcu_read_unlock();
1526 return 0;
1527}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001528
Henning Roggea2db2ed2014-09-12 08:58:50 +02001529static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1530 struct mpath_info *pinfo)
1531{
1532 memset(pinfo, 0, sizeof(*pinfo));
1533 memcpy(mpp, mpath->mpp, ETH_ALEN);
1534
1535 pinfo->generation = mpp_paths_generation;
1536}
1537
1538static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1539 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1540
1541{
1542 struct ieee80211_sub_if_data *sdata;
1543 struct mesh_path *mpath;
1544
1545 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1546
1547 rcu_read_lock();
1548 mpath = mpp_path_lookup(sdata, dst);
1549 if (!mpath) {
1550 rcu_read_unlock();
1551 return -ENOENT;
1552 }
1553 memcpy(dst, mpath->dst, ETH_ALEN);
1554 mpp_set_pinfo(mpath, mpp, pinfo);
1555 rcu_read_unlock();
1556 return 0;
1557}
1558
1559static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1560 int idx, u8 *dst, u8 *mpp,
1561 struct mpath_info *pinfo)
1562{
1563 struct ieee80211_sub_if_data *sdata;
1564 struct mesh_path *mpath;
1565
1566 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1567
1568 rcu_read_lock();
1569 mpath = mpp_path_lookup_by_idx(sdata, idx);
1570 if (!mpath) {
1571 rcu_read_unlock();
1572 return -ENOENT;
1573 }
1574 memcpy(dst, mpath->dst, ETH_ALEN);
1575 mpp_set_pinfo(mpath, mpp, pinfo);
1576 rcu_read_unlock();
1577 return 0;
1578}
1579
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001580static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001581 struct net_device *dev,
1582 struct mesh_config *conf)
1583{
1584 struct ieee80211_sub_if_data *sdata;
1585 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1586
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001587 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1588 return 0;
1589}
1590
1591static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1592{
1593 return (mask >> (parm-1)) & 0x1;
1594}
1595
Javier Cardonac80d5452010-12-16 17:37:49 -08001596static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1597 const struct mesh_setup *setup)
1598{
1599 u8 *new_ie;
1600 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001601 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1602 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001603
Javier Cardona581a8b02011-04-07 15:08:27 -07001604 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001605 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001606 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001607
Javier Cardona581a8b02011-04-07 15:08:27 -07001608 if (setup->ie_len) {
1609 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001610 GFP_KERNEL);
1611 if (!new_ie)
1612 return -ENOMEM;
1613 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001614 ifmsh->ie_len = setup->ie_len;
1615 ifmsh->ie = new_ie;
1616 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001617
1618 /* now copy the rest of the setup parameters */
1619 ifmsh->mesh_id_len = setup->mesh_id_len;
1620 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001621 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001622 ifmsh->mesh_pp_id = setup->path_sel_proto;
1623 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001624 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001625 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001626 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1627 if (setup->is_authenticated)
1628 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1629 if (setup->is_secure)
1630 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001631
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001632 /* mcast rate setting in Mesh Node */
1633 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1634 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001635 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001636
Marco Porsch9bdbf042013-01-07 16:04:51 +01001637 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1638 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1639
Javier Cardonac80d5452010-12-16 17:37:49 -08001640 return 0;
1641}
1642
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001643static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001644 struct net_device *dev, u32 mask,
1645 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001646{
1647 struct mesh_config *conf;
1648 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001649 struct ieee80211_if_mesh *ifmsh;
1650
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001651 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001652 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001653
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001654 /* Set the config options which we are interested in setting */
1655 conf = &(sdata->u.mesh.mshcfg);
1656 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1657 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1658 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1659 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1660 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1661 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1662 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1663 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1664 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1665 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1666 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1667 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001668 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001669 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001670 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1671 if (ifmsh->user_mpm)
1672 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001673 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001674 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001675 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1676 conf->dot11MeshNbrOffsetMaxNeighbor =
1677 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001678 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1679 conf->dot11MeshHWMPmaxPREQretries =
1680 nconf->dot11MeshHWMPmaxPREQretries;
1681 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1682 conf->path_refresh_time = nconf->path_refresh_time;
1683 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1684 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1685 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1686 conf->dot11MeshHWMPactivePathTimeout =
1687 nconf->dot11MeshHWMPactivePathTimeout;
1688 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1689 conf->dot11MeshHWMPpreqMinInterval =
1690 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001691 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1692 conf->dot11MeshHWMPperrMinInterval =
1693 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001694 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1695 mask))
1696 conf->dot11MeshHWMPnetDiameterTraversalTime =
1697 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001698 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1699 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1700 ieee80211_mesh_root_setup(ifmsh);
1701 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001702 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001703 /* our current gate announcement implementation rides on root
1704 * announcements, so require this ifmsh to also be a root node
1705 * */
1706 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001707 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1708 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001709 ieee80211_mesh_root_setup(ifmsh);
1710 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001711 conf->dot11MeshGateAnnouncementProtocol =
1712 nconf->dot11MeshGateAnnouncementProtocol;
1713 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001714 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001715 conf->dot11MeshHWMPRannInterval =
1716 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001717 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1718 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001719 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1720 /* our RSSI threshold implementation is supported only for
1721 * devices that report signal in dBm.
1722 */
1723 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1724 return -ENOTSUPP;
1725 conf->rssi_threshold = nconf->rssi_threshold;
1726 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001727 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1728 conf->ht_opmode = nconf->ht_opmode;
1729 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1730 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1731 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001732 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1733 conf->dot11MeshHWMPactivePathToRootTimeout =
1734 nconf->dot11MeshHWMPactivePathToRootTimeout;
1735 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1736 conf->dot11MeshHWMProotInterval =
1737 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001738 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1739 conf->dot11MeshHWMPconfirmationInterval =
1740 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001741 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1742 conf->power_mode = nconf->power_mode;
1743 ieee80211_mps_local_status_update(sdata);
1744 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001745 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001746 conf->dot11MeshAwakeWindowDuration =
1747 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001748 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1749 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001750 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001751 return 0;
1752}
1753
Johannes Berg29cbe682010-12-03 09:20:44 +01001754static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1755 const struct mesh_config *conf,
1756 const struct mesh_setup *setup)
1757{
1758 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1759 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001760 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001761
Javier Cardonac80d5452010-12-16 17:37:49 -08001762 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1763 err = copy_mesh_setup(ifmsh, setup);
1764 if (err)
1765 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001766
Johannes Berg04ecd252012-09-11 14:34:12 +02001767 /* can mesh use other SMPS modes? */
1768 sdata->smps_mode = IEEE80211_SMPS_OFF;
1769 sdata->needed_rx_chains = sdata->local->rx_chains;
1770
Johannes Berg34a37402013-12-18 09:43:33 +01001771 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001772 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001773 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001774 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001775 if (err)
1776 return err;
1777
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001778 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001779}
1780
1781static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1782{
1783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1784
1785 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001786 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001787 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001788 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001789
1790 return 0;
1791}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001792#endif
1793
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001794static int ieee80211_change_bss(struct wiphy *wiphy,
1795 struct net_device *dev,
1796 struct bss_parameters *params)
1797{
Johannes Berg55de9082012-07-26 17:24:39 +02001798 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1799 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001800 u32 changed = 0;
1801
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001802 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001803 return -ENOENT;
1804
1805 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001806
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001807 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001808 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001809 changed |= BSS_CHANGED_ERP_CTS_PROT;
1810 }
1811 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001812 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001813 params->use_short_preamble;
1814 changed |= BSS_CHANGED_ERP_PREAMBLE;
1815 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001816
1817 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001818 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001819 sdata->vif.bss_conf.use_short_slot = true;
1820 changed |= BSS_CHANGED_ERP_SLOT;
1821 }
1822
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001823 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001824 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001825 params->use_short_slot_time;
1826 changed |= BSS_CHANGED_ERP_SLOT;
1827 }
1828
Jouni Malinen90c97a02008-10-30 16:59:22 +02001829 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001830 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1831 wiphy->bands[band],
1832 params->basic_rates,
1833 params->basic_rates_len,
1834 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001835 changed |= BSS_CHANGED_BASIC_RATES;
1836 }
1837
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001838 if (params->ap_isolate >= 0) {
1839 if (params->ap_isolate)
1840 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1841 else
1842 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1843 }
1844
Helmut Schaa80d7e402010-11-19 12:40:26 +01001845 if (params->ht_opmode >= 0) {
1846 sdata->vif.bss_conf.ht_operation_mode =
1847 (u16) params->ht_opmode;
1848 changed |= BSS_CHANGED_HT;
1849 }
1850
Johannes Berg339afbf2012-11-14 15:21:17 +01001851 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001852 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1853 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1854 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1855 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001856 changed |= BSS_CHANGED_P2P_PS;
1857 }
1858
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001859 if (params->p2p_opp_ps > 0) {
1860 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1861 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1862 changed |= BSS_CHANGED_P2P_PS;
1863 } else if (params->p2p_opp_ps == 0) {
1864 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1865 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001866 changed |= BSS_CHANGED_P2P_PS;
1867 }
1868
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001869 ieee80211_bss_info_change_notify(sdata, changed);
1870
1871 return 0;
1872}
1873
Jouni Malinen31888482008-10-30 16:59:24 +02001874static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001875 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001876 struct ieee80211_txq_params *params)
1877{
1878 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001879 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001880 struct ieee80211_tx_queue_params p;
1881
1882 if (!local->ops->conf_tx)
1883 return -EOPNOTSUPP;
1884
Johannes Berg54bcbc62012-03-28 11:04:25 +02001885 if (local->hw.queues < IEEE80211_NUM_ACS)
1886 return -EOPNOTSUPP;
1887
Jouni Malinen31888482008-10-30 16:59:24 +02001888 memset(&p, 0, sizeof(p));
1889 p.aifs = params->aifs;
1890 p.cw_max = params->cwmax;
1891 p.cw_min = params->cwmin;
1892 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001893
1894 /*
1895 * Setting tx queue params disables u-apsd because it's only
1896 * called in master mode.
1897 */
1898 p.uapsd = false;
1899
Johannes Berga3304b02012-03-28 11:04:24 +02001900 sdata->tx_conf[params->ac] = p;
1901 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001902 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001903 "failed to set TX queue parameters for AC %d\n",
1904 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001905 return -EINVAL;
1906 }
1907
Johannes Berg7d257452012-07-06 17:37:43 +02001908 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1909
Jouni Malinen31888482008-10-30 16:59:24 +02001910 return 0;
1911}
1912
Bob Copeland665af4f2009-01-19 11:20:53 -05001913#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001914static int ieee80211_suspend(struct wiphy *wiphy,
1915 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001916{
Johannes Bergeecc4802011-05-04 15:37:29 +02001917 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001918}
1919
1920static int ieee80211_resume(struct wiphy *wiphy)
1921{
1922 return __ieee80211_resume(wiphy_priv(wiphy));
1923}
1924#else
1925#define ieee80211_suspend NULL
1926#define ieee80211_resume NULL
1927#endif
1928
Johannes Berg2a519312009-02-10 21:25:55 +01001929static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001930 struct cfg80211_scan_request *req)
1931{
Johannes Bergfd014282012-06-18 19:17:03 +02001932 struct ieee80211_sub_if_data *sdata;
1933
1934 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001935
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001936 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1937 case NL80211_IFTYPE_STATION:
1938 case NL80211_IFTYPE_ADHOC:
1939 case NL80211_IFTYPE_MESH_POINT:
1940 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001941 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001942 break;
1943 case NL80211_IFTYPE_P2P_GO:
1944 if (sdata->local->ops->hw_scan)
1945 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001946 /*
1947 * FIXME: implement NoA while scanning in software,
1948 * for now fall through to allow scanning only when
1949 * beaconing hasn't been configured yet
1950 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001951 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001952 /*
1953 * If the scan has been forced (and the driver supports
1954 * forcing), don't care about being beaconing already.
1955 * This will create problems to the attached stations (e.g. all
1956 * the frames sent while scanning on other channel will be
1957 * lost)
1958 */
1959 if (sdata->u.ap.beacon &&
1960 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1961 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001962 return -EOPNOTSUPP;
1963 break;
1964 default:
1965 return -EOPNOTSUPP;
1966 }
Johannes Berg2a519312009-02-10 21:25:55 +01001967
1968 return ieee80211_request_scan(sdata, req);
1969}
1970
Luciano Coelho79f460c2011-05-11 17:09:36 +03001971static int
1972ieee80211_sched_scan_start(struct wiphy *wiphy,
1973 struct net_device *dev,
1974 struct cfg80211_sched_scan_request *req)
1975{
1976 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1977
1978 if (!sdata->local->ops->sched_scan_start)
1979 return -EOPNOTSUPP;
1980
1981 return ieee80211_request_sched_scan_start(sdata, req);
1982}
1983
1984static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001985ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001986{
1987 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1988
1989 if (!sdata->local->ops->sched_scan_stop)
1990 return -EOPNOTSUPP;
1991
Luciano Coelho85a99942011-05-12 16:28:29 +03001992 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001993}
1994
Jouni Malinen636a5d32009-03-19 13:39:22 +02001995static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1996 struct cfg80211_auth_request *req)
1997{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001998 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001999}
2000
2001static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2002 struct cfg80211_assoc_request *req)
2003{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002004 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002005}
2006
2007static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002008 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002009{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002010 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002011}
2012
2013static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002014 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002015{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002016 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002017}
2018
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002019static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2020 struct cfg80211_ibss_params *params)
2021{
Johannes Berg55de9082012-07-26 17:24:39 +02002022 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002023}
2024
2025static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2026{
Johannes Berg55de9082012-07-26 17:24:39 +02002027 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002028}
2029
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002030static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2031 struct ocb_setup *setup)
2032{
2033 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2034}
2035
2036static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2037{
2038 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2039}
2040
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002041static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2042 int rate[IEEE80211_NUM_BANDS])
2043{
2044 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2045
Cong Ding9887dbf2013-02-06 17:23:45 +01002046 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2047 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002048
2049 return 0;
2050}
2051
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002052static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2053{
2054 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002055 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002057 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2058 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2059
2060 if (err)
2061 return err;
2062 }
2063
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002064 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2065 (changed & WIPHY_PARAM_DYN_ACK)) {
2066 s16 coverage_class;
2067
2068 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2069 wiphy->coverage_class : -1;
2070 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002071
2072 if (err)
2073 return err;
2074 }
2075
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002076 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002077 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002078
Johannes Berg24487982009-04-23 18:52:52 +02002079 if (err)
2080 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002081 }
2082
Johannes Berg8bc83c22012-11-09 18:38:32 +01002083 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2084 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2085 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002086 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002087 }
2088 if (changed & WIPHY_PARAM_RETRY_LONG) {
2089 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2090 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002091 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002092 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002093 if (changed &
2094 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2095 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2096
2097 return 0;
2098}
2099
Johannes Berg7643a2c2009-06-02 13:01:39 +02002100static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002101 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002102 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002103{
2104 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002105 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002106
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002107 if (wdev) {
2108 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2109
2110 switch (type) {
2111 case NL80211_TX_POWER_AUTOMATIC:
2112 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2113 break;
2114 case NL80211_TX_POWER_LIMITED:
2115 case NL80211_TX_POWER_FIXED:
2116 if (mbm < 0 || (mbm % 100))
2117 return -EOPNOTSUPP;
2118 sdata->user_power_level = MBM_TO_DBM(mbm);
2119 break;
2120 }
2121
2122 ieee80211_recalc_txpower(sdata);
2123
2124 return 0;
2125 }
Johannes Berg55de9082012-07-26 17:24:39 +02002126
Johannes Berg7643a2c2009-06-02 13:01:39 +02002127 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002128 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002129 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002130 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002131 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002132 case NL80211_TX_POWER_FIXED:
2133 if (mbm < 0 || (mbm % 100))
2134 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002135 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002136 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002137 }
2138
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002139 mutex_lock(&local->iflist_mtx);
2140 list_for_each_entry(sdata, &local->interfaces, list)
2141 sdata->user_power_level = local->user_power_level;
2142 list_for_each_entry(sdata, &local->interfaces, list)
2143 ieee80211_recalc_txpower(sdata);
2144 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002145
2146 return 0;
2147}
2148
Johannes Bergc8442112012-10-24 10:17:18 +02002149static int ieee80211_get_tx_power(struct wiphy *wiphy,
2150 struct wireless_dev *wdev,
2151 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002152{
2153 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002154 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002155
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002156 if (local->ops->get_txpower)
2157 return drv_get_txpower(local, sdata, dbm);
2158
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002159 if (!local->use_chanctx)
2160 *dbm = local->hw.conf.power_level;
2161 else
2162 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002163
Johannes Berg7643a2c2009-06-02 13:01:39 +02002164 return 0;
2165}
2166
Johannes Bergab737a42009-07-01 21:26:58 +02002167static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002168 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002169{
2170 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2171
2172 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2173
2174 return 0;
2175}
2176
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002177static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2178{
2179 struct ieee80211_local *local = wiphy_priv(wiphy);
2180
2181 drv_rfkill_poll(local);
2182}
2183
Johannes Bergaff89a92009-07-01 21:26:51 +02002184#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002185static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2186 struct wireless_dev *wdev,
2187 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002188{
2189 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002190 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002191
2192 if (!local->ops->testmode_cmd)
2193 return -EOPNOTSUPP;
2194
David Spinadel52981cd2013-07-31 18:06:22 +03002195 if (wdev) {
2196 struct ieee80211_sub_if_data *sdata;
2197
2198 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2199 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2200 vif = &sdata->vif;
2201 }
2202
2203 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002204}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002205
2206static int ieee80211_testmode_dump(struct wiphy *wiphy,
2207 struct sk_buff *skb,
2208 struct netlink_callback *cb,
2209 void *data, int len)
2210{
2211 struct ieee80211_local *local = wiphy_priv(wiphy);
2212
2213 if (!local->ops->testmode_dump)
2214 return -EOPNOTSUPP;
2215
2216 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2217}
Johannes Bergaff89a92009-07-01 21:26:51 +02002218#endif
2219
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002220int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2221 enum ieee80211_smps_mode smps_mode)
2222{
2223 struct sta_info *sta;
2224 enum ieee80211_smps_mode old_req;
2225 int i;
2226
2227 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2228 return -EINVAL;
2229
2230 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2231 return 0;
2232
2233 old_req = sdata->u.ap.req_smps;
2234 sdata->u.ap.req_smps = smps_mode;
2235
2236 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2237 if (old_req == smps_mode ||
2238 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2239 return 0;
2240
2241 /* If no associated stations, there's no need to do anything */
2242 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2243 sdata->smps_mode = smps_mode;
2244 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2245 return 0;
2246 }
2247
2248 ht_dbg(sdata,
2249 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2250 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2251
2252 mutex_lock(&sdata->local->sta_mtx);
2253 for (i = 0; i < STA_HASH_SIZE; i++) {
2254 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2255 lockdep_is_held(&sdata->local->sta_mtx));
2256 sta;
2257 sta = rcu_dereference_protected(sta->hnext,
2258 lockdep_is_held(&sdata->local->sta_mtx))) {
2259 /*
2260 * Only stations associated to our AP and
2261 * associated VLANs
2262 */
2263 if (sta->sdata->bss != &sdata->u.ap)
2264 continue;
2265
2266 /* This station doesn't support MIMO - skip it */
2267 if (sta_info_tx_streams(sta) == 1)
2268 continue;
2269
2270 /*
2271 * Don't wake up a STA just to send the action frame
2272 * unless we are getting more restrictive.
2273 */
2274 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2275 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2276 smps_mode)) {
2277 ht_dbg(sdata,
2278 "Won't send SMPS to sleeping STA %pM\n",
2279 sta->sta.addr);
2280 continue;
2281 }
2282
2283 /*
2284 * If the STA is not authorized, wait until it gets
2285 * authorized and the action frame will be sent then.
2286 */
2287 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2288 continue;
2289
2290 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2291 ieee80211_send_smps_action(sdata, smps_mode,
2292 sta->sta.addr,
2293 sdata->vif.bss_conf.bssid);
2294 }
2295 }
2296 mutex_unlock(&sdata->local->sta_mtx);
2297
2298 sdata->smps_mode = smps_mode;
2299 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2300
2301 return 0;
2302}
2303
2304int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2305 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002306{
2307 const u8 *ap;
2308 enum ieee80211_smps_mode old_req;
2309 int err;
2310
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002311 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002312
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002313 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2314 return -EINVAL;
2315
Johannes Berg0f782312009-12-01 13:37:02 +01002316 old_req = sdata->u.mgd.req_smps;
2317 sdata->u.mgd.req_smps = smps_mode;
2318
2319 if (old_req == smps_mode &&
2320 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2321 return 0;
2322
2323 /*
2324 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002325 * association, there's no need to do anything, just store
2326 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002327 */
2328 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002329 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002330 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002331
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002332 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002333
2334 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2335 if (sdata->u.mgd.powersave)
2336 smps_mode = IEEE80211_SMPS_DYNAMIC;
2337 else
2338 smps_mode = IEEE80211_SMPS_OFF;
2339 }
2340
2341 /* send SM PS frame to AP */
2342 err = ieee80211_send_smps_action(sdata, smps_mode,
2343 ap, ap);
2344 if (err)
2345 sdata->u.mgd.req_smps = old_req;
2346
2347 return err;
2348}
2349
Johannes Bergbc92afd2009-07-01 21:26:57 +02002350static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2351 bool enabled, int timeout)
2352{
2353 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2354 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002355
Bob Copeland2d3db212013-10-29 18:11:59 -04002356 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002357 return -EOPNOTSUPP;
2358
Johannes Bergbc92afd2009-07-01 21:26:57 +02002359 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2360 return -EOPNOTSUPP;
2361
2362 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002363 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002364 return 0;
2365
2366 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002367 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002368
Johannes Berg0f782312009-12-01 13:37:02 +01002369 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002370 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002371 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002372 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002373
Johannes Bergbc92afd2009-07-01 21:26:57 +02002374 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2375 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2376
2377 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002378 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002379
2380 return 0;
2381}
2382
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002383static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2384 struct net_device *dev,
2385 s32 rssi_thold, u32 rssi_hyst)
2386{
2387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002388 struct ieee80211_vif *vif = &sdata->vif;
2389 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2390
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002391 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2392 rssi_hyst == bss_conf->cqm_rssi_hyst)
2393 return 0;
2394
2395 bss_conf->cqm_rssi_thold = rssi_thold;
2396 bss_conf->cqm_rssi_hyst = rssi_hyst;
2397
2398 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002399 if (sdata->u.mgd.associated &&
2400 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002401 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2402
2403 return 0;
2404}
2405
Johannes Berg99303802009-07-01 21:26:59 +02002406static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2407 struct net_device *dev,
2408 const u8 *addr,
2409 const struct cfg80211_bitrate_mask *mask)
2410{
2411 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2412 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302413 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002414
Eliad Peller554a43d2012-06-12 12:41:15 +03002415 if (!ieee80211_sdata_running(sdata))
2416 return -ENETDOWN;
2417
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302418 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2419 ret = drv_set_bitrate_mask(local, sdata, mask);
2420 if (ret)
2421 return ret;
2422 }
Johannes Berg99303802009-07-01 21:26:59 +02002423
Simon Wunderlich19468412012-01-28 17:25:33 +01002424 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002425 struct ieee80211_supported_band *sband = wiphy->bands[i];
2426 int j;
2427
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002428 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002429 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2430 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002431
2432 sdata->rc_has_mcs_mask[i] = false;
2433 if (!sband)
2434 continue;
2435
2436 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2437 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2438 sdata->rc_has_mcs_mask[i] = true;
2439 break;
2440 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002441 }
Johannes Berg99303802009-07-01 21:26:59 +02002442
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002443 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002444}
2445
Eliad Pellereaa336b2014-09-03 15:25:06 +03002446static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2447 struct ieee80211_roc_work *new_roc,
2448 struct ieee80211_roc_work *cur_roc)
2449{
2450 unsigned long j = jiffies;
2451 unsigned long cur_roc_end = cur_roc->hw_start_time +
2452 msecs_to_jiffies(cur_roc->duration);
2453 struct ieee80211_roc_work *next_roc;
2454 int new_dur;
2455
2456 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2457 return false;
2458
2459 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2460 return false;
2461
2462 ieee80211_handle_roc_started(new_roc);
2463
2464 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2465
2466 /* cur_roc is long enough - add new_roc to the dependents list. */
2467 if (new_dur <= 0) {
2468 list_add_tail(&new_roc->list, &cur_roc->dependents);
2469 return true;
2470 }
2471
2472 new_roc->duration = new_dur;
2473
2474 /*
2475 * if cur_roc was already coalesced before, we might
2476 * want to extend the next roc instead of adding
2477 * a new one.
2478 */
2479 next_roc = list_entry(cur_roc->list.next,
2480 struct ieee80211_roc_work, list);
2481 if (&next_roc->list != &local->roc_list &&
2482 next_roc->chan == new_roc->chan &&
2483 next_roc->sdata == new_roc->sdata &&
2484 !WARN_ON(next_roc->started)) {
2485 list_add_tail(&new_roc->list, &next_roc->dependents);
2486 next_roc->duration = max(next_roc->duration,
2487 new_roc->duration);
2488 next_roc->type = max(next_roc->type, new_roc->type);
2489 return true;
2490 }
2491
2492 /* add right after cur_roc */
2493 list_add(&new_roc->list, &cur_roc->list);
2494
2495 return true;
2496}
2497
Johannes Berg2eb278e2012-06-05 14:28:42 +02002498static int ieee80211_start_roc_work(struct ieee80211_local *local,
2499 struct ieee80211_sub_if_data *sdata,
2500 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002501 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002502 struct sk_buff *txskb,
2503 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002504{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002505 struct ieee80211_roc_work *roc, *tmp;
2506 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002507 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002508
2509 lockdep_assert_held(&local->mtx);
2510
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002511 if (local->use_chanctx && !local->ops->remain_on_channel)
2512 return -EOPNOTSUPP;
2513
Johannes Berg2eb278e2012-06-05 14:28:42 +02002514 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2515 if (!roc)
2516 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002517
Ilan Peer2fae0622013-12-19 13:25:29 +02002518 /*
2519 * If the duration is zero, then the driver
2520 * wouldn't actually do anything. Set it to
2521 * 10 for now.
2522 *
2523 * TODO: cancel the off-channel operation
2524 * when we get the SKB's TX status and
2525 * the wait time was zero before.
2526 */
2527 if (!duration)
2528 duration = 10;
2529
Johannes Berg2eb278e2012-06-05 14:28:42 +02002530 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002531 roc->duration = duration;
2532 roc->req_duration = duration;
2533 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002534 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002535 roc->mgmt_tx_cookie = (unsigned long)txskb;
2536 roc->sdata = sdata;
2537 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2538 INIT_LIST_HEAD(&roc->dependents);
2539
Eliad Peller2f617432014-01-12 11:06:37 +02002540 /*
2541 * cookie is either the roc cookie (for normal roc)
2542 * or the SKB (for mgmt TX)
2543 */
2544 if (!txskb) {
2545 /* local->mtx protects this */
2546 local->roc_cookie_counter++;
2547 roc->cookie = local->roc_cookie_counter;
2548 /* wow, you wrapped 64 bits ... more likely a bug */
2549 if (WARN_ON(roc->cookie == 0)) {
2550 roc->cookie = 1;
2551 local->roc_cookie_counter++;
2552 }
2553 *cookie = roc->cookie;
2554 } else {
2555 *cookie = (unsigned long)txskb;
2556 }
2557
Johannes Berg2eb278e2012-06-05 14:28:42 +02002558 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002559 if (!list_empty(&local->roc_list) ||
Eliad Peller5cbc95a2015-01-07 17:50:09 +02002560 local->scanning || ieee80211_is_radar_required(local))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002561 goto out_check_combine;
2562
2563 /* if not HW assist, just queue & schedule work */
2564 if (!local->ops->remain_on_channel) {
2565 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2566 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002567 }
2568
Johannes Berg2eb278e2012-06-05 14:28:42 +02002569 /* otherwise actually kick it off here (for error handling) */
2570
Ilan Peerd339d5c2013-02-12 09:34:13 +02002571 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002572 if (ret) {
2573 kfree(roc);
2574 return ret;
2575 }
2576
2577 roc->started = true;
2578 goto out_queue;
2579
2580 out_check_combine:
2581 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002582 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002583 continue;
2584
2585 /*
2586 * Extend this ROC if possible:
2587 *
2588 * If it hasn't started yet, just increase the duration
2589 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002590 * If the type of the new ROC has higher priority, modify the
2591 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002592 */
2593 if (!tmp->started) {
2594 list_add_tail(&roc->list, &tmp->dependents);
2595 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002596 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002597 queued = true;
2598 break;
2599 }
2600
2601 /* If it has already started, it's more difficult ... */
2602 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002603 /*
2604 * In the offloaded ROC case, if it hasn't begun, add
2605 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002606 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002607 * check that there's still a minimum time left and
2608 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002609 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002610 * a reduced time so we'll ask the driver to execute
2611 * it right after finishing the previous one, in the
2612 * hope that it'll also be executed right afterwards,
2613 * effectively extending the old one.
2614 * If there's no minimum time left, just add it to the
2615 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002616 * TODO: the ROC type is ignored here, assuming that it
2617 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002618 */
2619 if (!tmp->hw_begun) {
2620 list_add_tail(&roc->list, &tmp->dependents);
2621 queued = true;
2622 break;
2623 }
2624
Eliad Pellereaa336b2014-09-03 15:25:06 +03002625 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002626 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002627 } else if (del_timer_sync(&tmp->work.timer)) {
2628 unsigned long new_end;
2629
2630 /*
2631 * In the software ROC case, cancel the timer, if
2632 * that fails then the finish work is already
2633 * queued/pending and thus we queue the new ROC
2634 * normally, if that succeeds then we can extend
2635 * the timer duration and TX the frame (if any.)
2636 */
2637
2638 list_add_tail(&roc->list, &tmp->dependents);
2639 queued = true;
2640
2641 new_end = jiffies + msecs_to_jiffies(roc->duration);
2642
2643 /* ok, it was started & we canceled timer */
2644 if (time_after(new_end, tmp->work.timer.expires))
2645 mod_timer(&tmp->work.timer, new_end);
2646 else
2647 add_timer(&tmp->work.timer);
2648
2649 ieee80211_handle_roc_started(roc);
2650 }
2651 break;
2652 }
2653
2654 out_queue:
2655 if (!queued)
2656 list_add_tail(&roc->list, &local->roc_list);
2657
Johannes Berg2eb278e2012-06-05 14:28:42 +02002658 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002659}
2660
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002661static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002662 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002663 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002664 unsigned int duration,
2665 u64 *cookie)
2666{
Johannes Berg71bbc992012-06-15 15:30:18 +02002667 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002668 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002669 int ret;
2670
Johannes Berg2eb278e2012-06-05 14:28:42 +02002671 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002672 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002673 duration, cookie, NULL,
2674 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002675 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002676
Johannes Berg2eb278e2012-06-05 14:28:42 +02002677 return ret;
2678}
2679
2680static int ieee80211_cancel_roc(struct ieee80211_local *local,
2681 u64 cookie, bool mgmt_tx)
2682{
2683 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2684 int ret;
2685
2686 mutex_lock(&local->mtx);
2687 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002688 struct ieee80211_roc_work *dep, *tmp2;
2689
2690 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002691 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002692 continue;
2693 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2694 continue;
2695 /* found dependent item -- just remove it */
2696 list_del(&dep->list);
2697 mutex_unlock(&local->mtx);
2698
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002699 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002700 return 0;
2701 }
2702
Johannes Berg50febf62012-10-26 16:13:06 +02002703 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002704 continue;
2705 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2706 continue;
2707
2708 found = roc;
2709 break;
2710 }
2711
2712 if (!found) {
2713 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002714 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002715 }
Johannes Berg21f83582010-12-18 17:20:47 +01002716
Johannes Berge979e332012-06-11 17:09:41 +02002717 /*
2718 * We found the item to cancel, so do that. Note that it
2719 * may have dependents, which we also cancel (and send
2720 * the expired signal for.) Not doing so would be quite
2721 * tricky here, but we may need to fix it later.
2722 */
2723
Johannes Berg2eb278e2012-06-05 14:28:42 +02002724 if (local->ops->remain_on_channel) {
2725 if (found->started) {
2726 ret = drv_cancel_remain_on_channel(local);
2727 if (WARN_ON_ONCE(ret)) {
2728 mutex_unlock(&local->mtx);
2729 return ret;
2730 }
2731 }
Johannes Berg21f83582010-12-18 17:20:47 +01002732
Johannes Berg2eb278e2012-06-05 14:28:42 +02002733 list_del(&found->list);
2734
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002735 if (found->started)
2736 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002737 mutex_unlock(&local->mtx);
2738
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002739 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002740 } else {
2741 /* work may be pending so use it all the time */
2742 found->abort = true;
2743 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2744
2745 mutex_unlock(&local->mtx);
2746
2747 /* work will clean up etc */
2748 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002749 WARN_ON(!found->to_be_freed);
2750 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002751 }
Johannes Berg21f83582010-12-18 17:20:47 +01002752
Johannes Berg21f83582010-12-18 17:20:47 +01002753 return 0;
2754}
2755
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002756static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002757 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002758 u64 cookie)
2759{
Johannes Berg71bbc992012-06-15 15:30:18 +02002760 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002761 struct ieee80211_local *local = sdata->local;
2762
Johannes Berg2eb278e2012-06-05 14:28:42 +02002763 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002764}
2765
Simon Wunderlich164eb022013-02-08 18:16:20 +01002766static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2767 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002768 struct cfg80211_chan_def *chandef,
2769 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002770{
2771 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2772 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002773 int err;
2774
Johannes Berg34a37402013-12-18 09:43:33 +01002775 mutex_lock(&local->mtx);
2776 if (!list_empty(&local->roc_list) || local->scanning) {
2777 err = -EBUSY;
2778 goto out_unlock;
2779 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002780
2781 /* whatever, but channel contexts should not complain about that one */
2782 sdata->smps_mode = IEEE80211_SMPS_OFF;
2783 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002784
Simon Wunderlich164eb022013-02-08 18:16:20 +01002785 err = ieee80211_vif_use_channel(sdata, chandef,
2786 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002787 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002788 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002789
Simon Wunderlich164eb022013-02-08 18:16:20 +01002790 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002791 &sdata->dfs_cac_timer_work,
2792 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002793
Johannes Berg34a37402013-12-18 09:43:33 +01002794 out_unlock:
2795 mutex_unlock(&local->mtx);
2796 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002797}
2798
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002799static struct cfg80211_beacon_data *
2800cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2801{
2802 struct cfg80211_beacon_data *new_beacon;
2803 u8 *pos;
2804 int len;
2805
2806 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2807 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2808 beacon->probe_resp_len;
2809
2810 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2811 if (!new_beacon)
2812 return NULL;
2813
2814 pos = (u8 *)(new_beacon + 1);
2815 if (beacon->head_len) {
2816 new_beacon->head_len = beacon->head_len;
2817 new_beacon->head = pos;
2818 memcpy(pos, beacon->head, beacon->head_len);
2819 pos += beacon->head_len;
2820 }
2821 if (beacon->tail_len) {
2822 new_beacon->tail_len = beacon->tail_len;
2823 new_beacon->tail = pos;
2824 memcpy(pos, beacon->tail, beacon->tail_len);
2825 pos += beacon->tail_len;
2826 }
2827 if (beacon->beacon_ies_len) {
2828 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2829 new_beacon->beacon_ies = pos;
2830 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2831 pos += beacon->beacon_ies_len;
2832 }
2833 if (beacon->proberesp_ies_len) {
2834 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2835 new_beacon->proberesp_ies = pos;
2836 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2837 pos += beacon->proberesp_ies_len;
2838 }
2839 if (beacon->assocresp_ies_len) {
2840 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2841 new_beacon->assocresp_ies = pos;
2842 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2843 pos += beacon->assocresp_ies_len;
2844 }
2845 if (beacon->probe_resp_len) {
2846 new_beacon->probe_resp_len = beacon->probe_resp_len;
2847 beacon->probe_resp = pos;
2848 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2849 pos += beacon->probe_resp_len;
2850 }
2851
2852 return new_beacon;
2853}
2854
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002855void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002856{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002857 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2858
2859 ieee80211_queue_work(&sdata->local->hw,
2860 &sdata->csa_finalize_work);
2861}
2862EXPORT_SYMBOL(ieee80211_csa_finish);
2863
Michal Kazior66199502014-04-09 15:11:00 +02002864static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2865 u32 *changed)
2866{
2867 int err;
2868
2869 switch (sdata->vif.type) {
2870 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002871 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2872 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002873 kfree(sdata->u.ap.next_beacon);
2874 sdata->u.ap.next_beacon = NULL;
2875
2876 if (err < 0)
2877 return err;
2878 *changed |= err;
2879 break;
2880 case NL80211_IFTYPE_ADHOC:
2881 err = ieee80211_ibss_finish_csa(sdata);
2882 if (err < 0)
2883 return err;
2884 *changed |= err;
2885 break;
2886#ifdef CONFIG_MAC80211_MESH
2887 case NL80211_IFTYPE_MESH_POINT:
2888 err = ieee80211_mesh_finish_csa(sdata);
2889 if (err < 0)
2890 return err;
2891 *changed |= err;
2892 break;
2893#endif
2894 default:
2895 WARN_ON(1);
2896 return -EINVAL;
2897 }
2898
2899 return 0;
2900}
2901
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002902static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002903{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002904 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002905 u32 changed = 0;
2906 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002907
Michal Kaziordbd72852014-01-29 07:56:21 +01002908 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002909 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002910 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002911
Michal Kazior03078de2014-06-25 12:35:08 +02002912 /*
2913 * using reservation isn't immediate as it may be deferred until later
2914 * with multi-vif. once reservation is complete it will re-schedule the
2915 * work with no reserved_chanctx so verify chandef to check if it
2916 * completed successfully
2917 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002918
Michal Kazior03078de2014-06-25 12:35:08 +02002919 if (sdata->reserved_chanctx) {
2920 /*
2921 * with multi-vif csa driver may call ieee80211_csa_finish()
2922 * many times while waiting for other interfaces to use their
2923 * reservations
2924 */
2925 if (sdata->reserved_ready)
2926 return 0;
2927
Fabian Frederick408b18a2014-10-09 20:36:22 +02002928 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002929 }
2930
Michal Kazior03078de2014-06-25 12:35:08 +02002931 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2932 &sdata->csa_chandef))
2933 return -EINVAL;
2934
Simon Wunderliche487eae2013-11-21 18:19:51 +01002935 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01002936
Michal Kazior66199502014-04-09 15:11:00 +02002937 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2938 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002939 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002940
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002941 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002942
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002943 if (sdata->csa_block_tx) {
2944 ieee80211_wake_vif_queues(local, sdata,
2945 IEEE80211_QUEUE_STOP_REASON_CSA);
2946 sdata->csa_block_tx = false;
2947 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002948
Luciano Coelhof1d65582014-10-08 09:48:38 +03002949 err = drv_post_channel_switch(sdata);
2950 if (err)
2951 return err;
2952
2953 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2954
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002955 return 0;
2956}
2957
2958static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2959{
2960 if (__ieee80211_csa_finalize(sdata)) {
2961 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2962 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2963 GFP_KERNEL);
2964 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002965}
2966
2967void ieee80211_csa_finalize_work(struct work_struct *work)
2968{
2969 struct ieee80211_sub_if_data *sdata =
2970 container_of(work, struct ieee80211_sub_if_data,
2971 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02002972 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002973
2974 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002975 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002976 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002977
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002978 /* AP might have been stopped while waiting for the lock. */
2979 if (!sdata->vif.csa_active)
2980 goto unlock;
2981
2982 if (!ieee80211_sdata_running(sdata))
2983 goto unlock;
2984
2985 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002986
2987unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02002988 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002989 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002990 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002991}
2992
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002993static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2994 struct cfg80211_csa_settings *params,
2995 u32 *changed)
2996{
Michal Kazioraf296bd2014-06-05 14:21:36 +02002997 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002998 int err;
2999
3000 switch (sdata->vif.type) {
3001 case NL80211_IFTYPE_AP:
3002 sdata->u.ap.next_beacon =
3003 cfg80211_beacon_dup(&params->beacon_after);
3004 if (!sdata->u.ap.next_beacon)
3005 return -ENOMEM;
3006
3007 /*
3008 * With a count of 0, we don't have to wait for any
3009 * TBTT before switching, so complete the CSA
3010 * immediately. In theory, with a count == 1 we
3011 * should delay the switch until just before the next
3012 * TBTT, but that would complicate things so we switch
3013 * immediately too. If we would delay the switch
3014 * until the next TBTT, we would have to set the probe
3015 * response here.
3016 *
3017 * TODO: A channel switch with count <= 1 without
3018 * sending a CSA action frame is kind of useless,
3019 * because the clients won't know we're changing
3020 * channels. The action frame must be implemented
3021 * either here or in the userspace.
3022 */
3023 if (params->count <= 1)
3024 break;
3025
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003026 if ((params->n_counter_offsets_beacon >
3027 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3028 (params->n_counter_offsets_presp >
3029 IEEE80211_MAX_CSA_COUNTERS_NUM))
3030 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003031
Michal Kazioraf296bd2014-06-05 14:21:36 +02003032 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3033 csa.counter_offsets_presp = params->counter_offsets_presp;
3034 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3035 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3036 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003037
Michal Kazioraf296bd2014-06-05 14:21:36 +02003038 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003039 if (err < 0) {
3040 kfree(sdata->u.ap.next_beacon);
3041 return err;
3042 }
3043 *changed |= err;
3044
3045 break;
3046 case NL80211_IFTYPE_ADHOC:
3047 if (!sdata->vif.bss_conf.ibss_joined)
3048 return -EINVAL;
3049
3050 if (params->chandef.width != sdata->u.ibss.chandef.width)
3051 return -EINVAL;
3052
3053 switch (params->chandef.width) {
3054 case NL80211_CHAN_WIDTH_40:
3055 if (cfg80211_get_chandef_type(&params->chandef) !=
3056 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3057 return -EINVAL;
3058 case NL80211_CHAN_WIDTH_5:
3059 case NL80211_CHAN_WIDTH_10:
3060 case NL80211_CHAN_WIDTH_20_NOHT:
3061 case NL80211_CHAN_WIDTH_20:
3062 break;
3063 default:
3064 return -EINVAL;
3065 }
3066
3067 /* changes into another band are not supported */
3068 if (sdata->u.ibss.chandef.chan->band !=
3069 params->chandef.chan->band)
3070 return -EINVAL;
3071
3072 /* see comments in the NL80211_IFTYPE_AP block */
3073 if (params->count > 1) {
3074 err = ieee80211_ibss_csa_beacon(sdata, params);
3075 if (err < 0)
3076 return err;
3077 *changed |= err;
3078 }
3079
3080 ieee80211_send_action_csa(sdata, params);
3081
3082 break;
3083#ifdef CONFIG_MAC80211_MESH
3084 case NL80211_IFTYPE_MESH_POINT: {
3085 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3086
3087 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3088 return -EINVAL;
3089
3090 /* changes into another band are not supported */
3091 if (sdata->vif.bss_conf.chandef.chan->band !=
3092 params->chandef.chan->band)
3093 return -EINVAL;
3094
3095 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3096 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3097 if (!ifmsh->pre_value)
3098 ifmsh->pre_value = 1;
3099 else
3100 ifmsh->pre_value++;
3101 }
3102
3103 /* see comments in the NL80211_IFTYPE_AP block */
3104 if (params->count > 1) {
3105 err = ieee80211_mesh_csa_beacon(sdata, params);
3106 if (err < 0) {
3107 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3108 return err;
3109 }
3110 *changed |= err;
3111 }
3112
3113 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3114 ieee80211_send_action_csa(sdata, params);
3115
3116 break;
3117 }
3118#endif
3119 default:
3120 return -EOPNOTSUPP;
3121 }
3122
3123 return 0;
3124}
3125
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003126static int
3127__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3128 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003129{
3130 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3131 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003132 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003133 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003134 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003135 u32 changed = 0;
3136 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003137
Michal Kaziordbd72852014-01-29 07:56:21 +01003138 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003139 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003140
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003141 if (!list_empty(&local->roc_list) || local->scanning)
3142 return -EBUSY;
3143
3144 if (sdata->wdev.cac_started)
3145 return -EBUSY;
3146
3147 if (cfg80211_chandef_identical(&params->chandef,
3148 &sdata->vif.bss_conf.chandef))
3149 return -EINVAL;
3150
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003151 /* don't allow another channel switch if one is already active. */
3152 if (sdata->vif.csa_active)
3153 return -EBUSY;
3154
Michal Kazior03078de2014-06-25 12:35:08 +02003155 mutex_lock(&local->chanctx_mtx);
3156 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3157 lockdep_is_held(&local->chanctx_mtx));
3158 if (!conf) {
3159 err = -EBUSY;
3160 goto out;
3161 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003162
Michal Kazior03078de2014-06-25 12:35:08 +02003163 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3164 if (!chanctx) {
3165 err = -EBUSY;
3166 goto out;
3167 }
3168
Luciano Coelho000baa52014-11-07 15:28:33 +02003169 ch_switch.timestamp = 0;
3170 ch_switch.device_timestamp = 0;
3171 ch_switch.block_tx = params->block_tx;
3172 ch_switch.chandef = params->chandef;
3173 ch_switch.count = params->count;
3174
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003175 err = drv_pre_channel_switch(sdata, &ch_switch);
3176 if (err)
3177 goto out;
3178
Michal Kazior03078de2014-06-25 12:35:08 +02003179 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3180 chanctx->mode,
3181 params->radar_required);
3182 if (err)
3183 goto out;
3184
3185 /* if reservation is invalid then this will fail */
3186 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3187 if (err) {
3188 ieee80211_vif_unreserve_chanctx(sdata);
3189 goto out;
3190 }
3191
3192 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3193 if (err) {
3194 ieee80211_vif_unreserve_chanctx(sdata);
3195 goto out;
3196 }
3197
Luciano Coelho33787fc2013-11-11 20:34:54 +02003198 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003199 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003200 sdata->vif.csa_active = true;
3201
Michal Kazior59af6922014-04-09 15:10:59 +02003202 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003203 ieee80211_stop_vif_queues(local, sdata,
3204 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003205
Luciano Coelho2f457292014-11-07 14:31:36 +02003206 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3207 params->count);
3208
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003209 if (changed) {
3210 ieee80211_bss_info_change_notify(sdata, changed);
3211 drv_channel_switch_beacon(sdata, &params->chandef);
3212 } else {
3213 /* if the beacon didn't change, we can finalize immediately */
3214 ieee80211_csa_finalize(sdata);
3215 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003216
Michal Kazior03078de2014-06-25 12:35:08 +02003217out:
3218 mutex_unlock(&local->chanctx_mtx);
3219 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003220}
3221
Michal Kazior59af6922014-04-09 15:10:59 +02003222int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3223 struct cfg80211_csa_settings *params)
3224{
3225 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3226 struct ieee80211_local *local = sdata->local;
3227 int err;
3228
3229 mutex_lock(&local->mtx);
3230 err = __ieee80211_channel_switch(wiphy, dev, params);
3231 mutex_unlock(&local->mtx);
3232
3233 return err;
3234}
3235
Johannes Berg71bbc992012-06-15 15:30:18 +02003236static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003237 struct cfg80211_mgmt_tx_params *params,
3238 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003239{
Johannes Berg71bbc992012-06-15 15:30:18 +02003240 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003241 struct ieee80211_local *local = sdata->local;
3242 struct sk_buff *skb;
3243 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003244 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003245 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003246 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003247 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003248 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003249
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003250 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003251 flags = IEEE80211_TX_CTL_NO_ACK;
3252 else
3253 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3254 IEEE80211_TX_CTL_REQ_TX_STATUS;
3255
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003256 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303257 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3258
Johannes Berg9d38d852010-06-09 17:20:33 +02003259 switch (sdata->vif.type) {
3260 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003261 if (!sdata->vif.bss_conf.ibss_joined)
3262 need_offchan = true;
3263 /* fall through */
3264#ifdef CONFIG_MAC80211_MESH
3265 case NL80211_IFTYPE_MESH_POINT:
3266 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3267 !sdata->u.mesh.mesh_id_len)
3268 need_offchan = true;
3269 /* fall through */
3270#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003271 case NL80211_IFTYPE_AP:
3272 case NL80211_IFTYPE_AP_VLAN:
3273 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003274 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3275 !ieee80211_vif_is_mesh(&sdata->vif) &&
3276 !rcu_access_pointer(sdata->bss->beacon))
3277 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003278 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003279 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003280 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3281 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003282 break;
3283 rcu_read_lock();
3284 sta = sta_info_get(sdata, mgmt->da);
3285 rcu_read_unlock();
3286 if (!sta)
3287 return -ENOLINK;
3288 break;
3289 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003290 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003291 if (!sdata->u.mgd.associated)
3292 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003293 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003294 case NL80211_IFTYPE_P2P_DEVICE:
3295 need_offchan = true;
3296 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003297 default:
3298 return -EOPNOTSUPP;
3299 }
3300
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003301 /* configurations requiring offchan cannot work if no channel has been
3302 * specified
3303 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003304 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003305 return -EINVAL;
3306
Johannes Berg2eb278e2012-06-05 14:28:42 +02003307 mutex_lock(&local->mtx);
3308
3309 /* Check if the operating channel is the requested channel */
3310 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003311 struct ieee80211_chanctx_conf *chanctx_conf;
3312
3313 rcu_read_lock();
3314 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3315
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003316 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003317 need_offchan = params->chan &&
3318 (params->chan !=
3319 chanctx_conf->def.chan);
3320 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003321 ret = -EINVAL;
3322 rcu_read_unlock();
3323 goto out_unlock;
3324 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003325 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003326 }
Johannes Berg55de9082012-07-26 17:24:39 +02003327 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003328 }
3329
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003330 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003331 ret = -EBUSY;
3332 goto out_unlock;
3333 }
3334
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003335 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003336 if (!skb) {
3337 ret = -ENOMEM;
3338 goto out_unlock;
3339 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003340 skb_reserve(skb, local->hw.extra_tx_headroom);
3341
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003342 data = skb_put(skb, params->len);
3343 memcpy(data, params->buf, params->len);
3344
3345 /* Update CSA counters */
3346 if (sdata->vif.csa_active &&
3347 (sdata->vif.type == NL80211_IFTYPE_AP ||
3348 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3349 params->n_csa_offsets) {
3350 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003351 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003352
Michal Kazioraf296bd2014-06-05 14:21:36 +02003353 rcu_read_lock();
3354
3355 if (sdata->vif.type == NL80211_IFTYPE_AP)
3356 beacon = rcu_dereference(sdata->u.ap.beacon);
3357 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3358 beacon = rcu_dereference(sdata->u.ibss.presp);
3359 else if (ieee80211_vif_is_mesh(&sdata->vif))
3360 beacon = rcu_dereference(sdata->u.mesh.beacon);
3361
3362 if (beacon)
3363 for (i = 0; i < params->n_csa_offsets; i++)
3364 data[params->csa_offsets[i]] =
3365 beacon->csa_current_counter;
3366
3367 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003368 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003369
3370 IEEE80211_SKB_CB(skb)->flags = flags;
3371
Johannes Berg2eb278e2012-06-05 14:28:42 +02003372 skb->dev = sdata->dev;
3373
3374 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003375 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003376 ieee80211_tx_skb(sdata, skb);
3377 ret = 0;
3378 goto out_unlock;
3379 }
3380
Seth Forshee6c17b772013-02-11 11:21:07 -06003381 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3382 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003383 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003384 IEEE80211_SKB_CB(skb)->hw_queue =
3385 local->hw.offchannel_tx_hw_queue;
3386
Johannes Berg2eb278e2012-06-05 14:28:42 +02003387 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003388 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3389 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003390 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003391 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003392 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003393 out_unlock:
3394 mutex_unlock(&local->mtx);
3395 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003396}
3397
Johannes Bergf30221e2010-11-25 10:02:30 +01003398static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003399 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003400 u64 cookie)
3401{
Johannes Berg71bbc992012-06-15 15:30:18 +02003402 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003403
Johannes Berg2eb278e2012-06-05 14:28:42 +02003404 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003405}
3406
Johannes Berg7be50862010-10-13 12:06:24 +02003407static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003408 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003409 u16 frame_type, bool reg)
3410{
3411 struct ieee80211_local *local = wiphy_priv(wiphy);
3412
Will Hawkins6abe0562012-06-20 11:51:14 -04003413 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003414 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3415 if (reg)
3416 local->probe_req_reg++;
3417 else
3418 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003419
Felix Fietkau35f51492012-10-31 15:50:34 +01003420 if (!local->open_count)
3421 break;
3422
Will Hawkins6abe0562012-06-20 11:51:14 -04003423 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3424 break;
3425 default:
3426 break;
3427 }
Johannes Berg7be50862010-10-13 12:06:24 +02003428}
3429
Bruno Randolf15d96752010-11-10 12:50:56 +09003430static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3431{
3432 struct ieee80211_local *local = wiphy_priv(wiphy);
3433
3434 if (local->started)
3435 return -EOPNOTSUPP;
3436
3437 return drv_set_antenna(local, tx_ant, rx_ant);
3438}
3439
3440static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3441{
3442 struct ieee80211_local *local = wiphy_priv(wiphy);
3443
3444 return drv_get_antenna(local, tx_ant, rx_ant);
3445}
3446
Johannes Bergc68f4b82011-07-05 16:35:41 +02003447static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3448 struct net_device *dev,
3449 struct cfg80211_gtk_rekey_data *data)
3450{
3451 struct ieee80211_local *local = wiphy_priv(wiphy);
3452 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3453
3454 if (!local->ops->set_rekey_data)
3455 return -EOPNOTSUPP;
3456
3457 drv_set_rekey_data(local, sdata, data);
3458
3459 return 0;
3460}
3461
Johannes Berg06500732011-11-04 11:18:16 +01003462static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3463 const u8 *peer, u64 *cookie)
3464{
3465 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3466 struct ieee80211_local *local = sdata->local;
3467 struct ieee80211_qos_hdr *nullfunc;
3468 struct sk_buff *skb;
3469 int size = sizeof(*nullfunc);
3470 __le16 fc;
3471 bool qos;
3472 struct ieee80211_tx_info *info;
3473 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003474 struct ieee80211_chanctx_conf *chanctx_conf;
3475 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003476
3477 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003478 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3479 if (WARN_ON(!chanctx_conf)) {
3480 rcu_read_unlock();
3481 return -EINVAL;
3482 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003483 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003484 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003485 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003486 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003487 } else {
3488 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003489 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003490 }
Johannes Berg06500732011-11-04 11:18:16 +01003491
3492 if (qos) {
3493 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3494 IEEE80211_STYPE_QOS_NULLFUNC |
3495 IEEE80211_FCTL_FROMDS);
3496 } else {
3497 size -= 2;
3498 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3499 IEEE80211_STYPE_NULLFUNC |
3500 IEEE80211_FCTL_FROMDS);
3501 }
3502
3503 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003504 if (!skb) {
3505 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003506 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003507 }
Johannes Berg06500732011-11-04 11:18:16 +01003508
3509 skb->dev = dev;
3510
3511 skb_reserve(skb, local->hw.extra_tx_headroom);
3512
3513 nullfunc = (void *) skb_put(skb, size);
3514 nullfunc->frame_control = fc;
3515 nullfunc->duration_id = 0;
3516 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3517 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3518 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3519 nullfunc->seq_ctrl = 0;
3520
3521 info = IEEE80211_SKB_CB(skb);
3522
3523 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3524 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003525 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003526
3527 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3528 skb->priority = 7;
3529 if (qos)
3530 nullfunc->qos_ctrl = cpu_to_le16(7);
3531
3532 local_bh_disable();
Johannes Berg73c4e192014-11-09 18:50:09 +02003533 ieee80211_xmit(sdata, skb);
Johannes Berg06500732011-11-04 11:18:16 +01003534 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003535 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003536
3537 *cookie = (unsigned long) skb;
3538 return 0;
3539}
3540
Johannes Berg683b6d32012-11-08 21:25:48 +01003541static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3542 struct wireless_dev *wdev,
3543 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003544{
Johannes Berg55de9082012-07-26 17:24:39 +02003545 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003546 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003547 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003548 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003549
Johannes Berg55de9082012-07-26 17:24:39 +02003550 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003551 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3552 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003553 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003554 ret = 0;
3555 } else if (local->open_count > 0 &&
3556 local->open_count == local->monitors &&
3557 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3558 if (local->use_chanctx)
3559 *chandef = local->monitor_chandef;
3560 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003561 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003562 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003563 }
3564 rcu_read_unlock();
3565
Johannes Berg683b6d32012-11-08 21:25:48 +01003566 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003567}
3568
Johannes Berg6d525632012-04-04 15:05:25 +02003569#ifdef CONFIG_PM
3570static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3571{
3572 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3573}
3574#endif
3575
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003576static int ieee80211_set_qos_map(struct wiphy *wiphy,
3577 struct net_device *dev,
3578 struct cfg80211_qos_map *qos_map)
3579{
3580 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3581 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3582
3583 if (qos_map) {
3584 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3585 if (!new_qos_map)
3586 return -ENOMEM;
3587 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3588 } else {
3589 /* A NULL qos_map was passed to disable QoS mapping */
3590 new_qos_map = NULL;
3591 }
3592
Johannes Berg194ff522013-12-30 23:12:37 +01003593 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003594 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3595 if (old_qos_map)
3596 kfree_rcu(old_qos_map, rcu_head);
3597
3598 return 0;
3599}
3600
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003601static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3602 struct net_device *dev,
3603 struct cfg80211_chan_def *chandef)
3604{
3605 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3606 int ret;
3607 u32 changed = 0;
3608
3609 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3610 if (ret == 0)
3611 ieee80211_bss_info_change_notify(sdata, changed);
3612
3613 return ret;
3614}
3615
Johannes Berg02219b32014-10-07 10:38:50 +03003616static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3617 u8 tsid, const u8 *peer, u8 up,
3618 u16 admitted_time)
3619{
3620 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3621 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3622 int ac = ieee802_1d_to_ac[up];
3623
3624 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3625 return -EOPNOTSUPP;
3626
3627 if (!(sdata->wmm_acm & BIT(up)))
3628 return -EINVAL;
3629
3630 if (ifmgd->tx_tspec[ac].admitted_time)
3631 return -EBUSY;
3632
3633 if (admitted_time) {
3634 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3635 ifmgd->tx_tspec[ac].tsid = tsid;
3636 ifmgd->tx_tspec[ac].up = up;
3637 }
3638
3639 return 0;
3640}
3641
3642static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3643 u8 tsid, const u8 *peer)
3644{
3645 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3646 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3647 struct ieee80211_local *local = wiphy_priv(wiphy);
3648 int ac;
3649
3650 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3651 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3652
3653 /* skip unused entries */
3654 if (!tx_tspec->admitted_time)
3655 continue;
3656
3657 if (tx_tspec->tsid != tsid)
3658 continue;
3659
3660 /* due to this new packets will be reassigned to non-ACM ACs */
3661 tx_tspec->up = -1;
3662
3663 /* Make sure that all packets have been sent to avoid to
3664 * restore the QoS params on packets that are still on the
3665 * queues.
3666 */
3667 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003668 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003669
3670 /* restore the normal QoS parameters
3671 * (unconditionally to avoid races)
3672 */
3673 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3674 tx_tspec->downgraded = false;
3675 ieee80211_sta_handle_tspec_ac_params(sdata);
3676
3677 /* finally clear all the data */
3678 memset(tx_tspec, 0, sizeof(*tx_tspec));
3679
3680 return 0;
3681 }
3682
3683 return -ENOENT;
3684}
3685
Johannes Berg8a47cea2014-01-20 23:55:44 +01003686const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003687 .add_virtual_intf = ieee80211_add_iface,
3688 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003689 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003690 .start_p2p_device = ieee80211_start_p2p_device,
3691 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003692 .add_key = ieee80211_add_key,
3693 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003694 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003695 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003696 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003697 .start_ap = ieee80211_start_ap,
3698 .change_beacon = ieee80211_change_beacon,
3699 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003700 .add_station = ieee80211_add_station,
3701 .del_station = ieee80211_del_station,
3702 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003703 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003704 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003705 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003706#ifdef CONFIG_MAC80211_MESH
3707 .add_mpath = ieee80211_add_mpath,
3708 .del_mpath = ieee80211_del_mpath,
3709 .change_mpath = ieee80211_change_mpath,
3710 .get_mpath = ieee80211_get_mpath,
3711 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003712 .get_mpp = ieee80211_get_mpp,
3713 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003714 .update_mesh_config = ieee80211_update_mesh_config,
3715 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003716 .join_mesh = ieee80211_join_mesh,
3717 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003718#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003719 .join_ocb = ieee80211_join_ocb,
3720 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003721 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003722 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003723 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003724 .suspend = ieee80211_suspend,
3725 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003726 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003727 .sched_scan_start = ieee80211_sched_scan_start,
3728 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003729 .auth = ieee80211_auth,
3730 .assoc = ieee80211_assoc,
3731 .deauth = ieee80211_deauth,
3732 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003733 .join_ibss = ieee80211_join_ibss,
3734 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003735 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003736 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003737 .set_tx_power = ieee80211_set_tx_power,
3738 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003739 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003740 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003741 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003742 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003743 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003744 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003745 .remain_on_channel = ieee80211_remain_on_channel,
3746 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003747 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003748 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003749 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003750 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003751 .set_antenna = ieee80211_set_antenna,
3752 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003753 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003754 .tdls_oper = ieee80211_tdls_oper,
3755 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02003756 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3757 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01003758 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003759 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003760#ifdef CONFIG_PM
3761 .set_wakeup = ieee80211_set_wakeup,
3762#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003763 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003764 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003765 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003766 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003767 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003768 .add_tx_ts = ieee80211_add_tx_ts,
3769 .del_tx_ts = ieee80211_del_tx_ts,
Jiri Bencf0706e82007-05-05 11:45:53 -07003770};