blob: a777114d663b4a40bc3306d8615a4fa12a08a687 [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)
Johannes Bergb51f3be2015-01-15 16:14:02 +0100431 rinfo->bw = RATE_INFO_BW_40;
432 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
433 rinfo->bw = RATE_INFO_BW_80;
434 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
435 rinfo->bw = RATE_INFO_BW_160;
436 else
437 rinfo->bw = RATE_INFO_BW_20;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800438 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
439 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800440}
441
Saravana003e6762012-11-28 18:29:38 +0530442void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
443{
444 rinfo->flags = 0;
445
446 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
447 rinfo->flags |= RATE_INFO_FLAGS_MCS;
448 rinfo->mcs = sta->last_rx_rate_idx;
449 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
450 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
451 rinfo->nss = sta->last_rx_rate_vht_nss;
452 rinfo->mcs = sta->last_rx_rate_idx;
453 } else {
454 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200455 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
456 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530457
458 sband = sta->local->hw.wiphy->bands[
459 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200460 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
461 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530462 }
463
Saravana003e6762012-11-28 18:29:38 +0530464 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
465 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Johannes Bergb51f3be2015-01-15 16:14:02 +0100466
467 if (sta->last_rx_rate_flag & RX_FLAG_5MHZ)
468 rinfo->bw = RATE_INFO_BW_5;
469 else if (sta->last_rx_rate_flag & RX_FLAG_10MHZ)
470 rinfo->bw = RATE_INFO_BW_10;
471 else if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
472 rinfo->bw = RATE_INFO_BW_40;
473 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
474 rinfo->bw = RATE_INFO_BW_80;
475 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
476 rinfo->bw = RATE_INFO_BW_160;
477 else
478 rinfo->bw = RATE_INFO_BW_20;
Saravana003e6762012-11-28 18:29:38 +0530479}
480
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100481static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200482 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100483{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100484 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300485 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100486 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100487 int ret = -ENOENT;
488
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300489 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100490
Johannes Berg3b53fde82009-11-16 12:00:37 +0100491 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100492 if (sta) {
493 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200494 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100495 sta_set_sinfo(sta, sinfo);
496 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100497
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300498 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100499
Johannes Bergd0709a62008-02-25 16:27:46 +0100500 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100501}
502
Holger Schurig12897232010-04-19 10:23:57 +0200503static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
504 int idx, struct survey_info *survey)
505{
506 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
507
Holger Schurig12897232010-04-19 10:23:57 +0200508 return drv_get_survey(local, idx, survey);
509}
510
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100511static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200512 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100513{
Johannes Bergabe60632009-11-25 17:46:18 +0100514 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300515 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100516 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100517 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100518
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300519 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100520
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100521 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100522 if (sta) {
523 ret = 0;
524 sta_set_sinfo(sta, sinfo);
525 }
526
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300527 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100528
529 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100530}
531
Johannes Berge8c9bd52012-06-06 08:18:22 +0200532static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100533 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200534{
Johannes Berg55de9082012-07-26 17:24:39 +0200535 struct ieee80211_local *local = wiphy_priv(wiphy);
536 struct ieee80211_sub_if_data *sdata;
537 int ret = 0;
538
Johannes Berg4bf88532012-11-09 11:39:59 +0100539 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200540 return 0;
541
Johannes Berg34a37402013-12-18 09:43:33 +0100542 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200543 mutex_lock(&local->iflist_mtx);
544 if (local->use_chanctx) {
545 sdata = rcu_dereference_protected(
546 local->monitor_sdata,
547 lockdep_is_held(&local->iflist_mtx));
548 if (sdata) {
549 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100550 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200551 IEEE80211_CHANCTX_EXCLUSIVE);
552 }
553 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100554 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200555 ieee80211_hw_config(local, 0);
556 }
557
Johannes Berg4bf88532012-11-09 11:39:59 +0100558 if (ret == 0)
559 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200560 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100561 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200562
563 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200564}
565
Arik Nemtsov02945822011-11-10 11:28:57 +0200566static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200567 const u8 *resp, size_t resp_len,
568 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200569{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300570 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200571
572 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530573 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200574
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100575 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200576
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300577 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200578 if (!new)
579 return -ENOMEM;
580
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300581 new->len = resp_len;
582 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200583
Michal Kazioraf296bd2014-06-05 14:21:36 +0200584 if (csa)
585 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
586 csa->n_counter_offsets_presp *
587 sizeof(new->csa_counter_offsets[0]));
588
Arik Nemtsov02945822011-11-10 11:28:57 +0200589 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300590 if (old)
591 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200592
593 return 0;
594}
595
Luciano Coelho0ae07962013-12-08 09:42:25 +0200596static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200597 struct cfg80211_beacon_data *params,
598 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100599{
600 struct beacon_data *new, *old;
601 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100602 int size, err;
603 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100604
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100605 old = sdata_dereference(sdata->u.ap.beacon, sdata);
606
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100607
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100608 /* Need to have a beacon head if we don't have one yet */
609 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100610 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100611
612 /* new or old head? */
613 if (params->head)
614 new_head_len = params->head_len;
615 else
616 new_head_len = old->head_len;
617
618 /* new or old tail? */
619 if (params->tail || !old)
620 /* params->tail_len will be zero for !params->tail */
621 new_tail_len = params->tail_len;
622 else
623 new_tail_len = old->tail_len;
624
625 size = sizeof(*new) + new_head_len + new_tail_len;
626
627 new = kzalloc(size, GFP_KERNEL);
628 if (!new)
629 return -ENOMEM;
630
631 /* start filling the new info now */
632
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100633 /*
634 * pointers go into the block we allocated,
635 * memory is | beacon_data | head | tail |
636 */
637 new->head = ((u8 *) new) + sizeof(*new);
638 new->tail = new->head + new_head_len;
639 new->head_len = new_head_len;
640 new->tail_len = new_tail_len;
641
Michal Kazioraf296bd2014-06-05 14:21:36 +0200642 if (csa) {
643 new->csa_current_counter = csa->count;
644 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
645 csa->n_counter_offsets_beacon *
646 sizeof(new->csa_counter_offsets[0]));
647 }
648
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100649 /* copy in head */
650 if (params->head)
651 memcpy(new->head, params->head, new_head_len);
652 else
653 memcpy(new->head, old->head, new_head_len);
654
655 /* copy in optional tail */
656 if (params->tail)
657 memcpy(new->tail, params->tail, new_tail_len);
658 else
659 if (old)
660 memcpy(new->tail, old->tail, new_tail_len);
661
Johannes Berg88600202012-02-13 15:17:18 +0100662 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200663 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100664 if (err < 0)
665 return err;
666 if (err == 0)
667 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100668
Eric Dumazetcf778b02012-01-12 04:41:32 +0000669 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100670
Johannes Berg88600202012-02-13 15:17:18 +0100671 if (old)
672 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100673
Johannes Berg88600202012-02-13 15:17:18 +0100674 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100675}
676
Johannes Berg88600202012-02-13 15:17:18 +0100677static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
678 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100679{
Johannes Berg88600202012-02-13 15:17:18 +0100680 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100681 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100682 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100683 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100684 u32 changed = BSS_CHANGED_BEACON_INT |
685 BSS_CHANGED_BEACON_ENABLED |
686 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100687 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +0100688 BSS_CHANGED_P2P_PS |
689 BSS_CHANGED_TXPOWER;
Johannes Berg88600202012-02-13 15:17:18 +0100690 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200691
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100692 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100693 if (old)
694 return -EALREADY;
695
Eliad Pellerf6993172014-09-10 14:07:35 +0300696 switch (params->smps_mode) {
697 case NL80211_SMPS_OFF:
698 sdata->smps_mode = IEEE80211_SMPS_OFF;
699 break;
700 case NL80211_SMPS_STATIC:
701 sdata->smps_mode = IEEE80211_SMPS_STATIC;
702 break;
703 case NL80211_SMPS_DYNAMIC:
704 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
705 break;
706 default:
707 return -EINVAL;
708 }
Johannes Berg04ecd252012-09-11 14:34:12 +0200709 sdata->needed_rx_chains = sdata->local->rx_chains;
710
Johannes Berg34a37402013-12-18 09:43:33 +0100711 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100712 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200713 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100714 if (!err)
715 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100716 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200717 if (err)
718 return err;
719
Johannes Berg665c93a2011-11-04 11:18:11 +0100720 /*
721 * Apply control port protocol, this allows us to
722 * not encrypt dynamic WEP control frames.
723 */
724 sdata->control_port_protocol = params->crypto.control_port_ethertype;
725 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200726 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
727 &params->crypto,
728 sdata->vif.type);
729
Johannes Berg665c93a2011-11-04 11:18:11 +0100730 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
731 vlan->control_port_protocol =
732 params->crypto.control_port_ethertype;
733 vlan->control_port_no_encrypt =
734 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200735 vlan->encrypt_headroom =
736 ieee80211_cs_headroom(sdata->local,
737 &params->crypto,
738 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100739 }
740
Johannes Berg88600202012-02-13 15:17:18 +0100741 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
742 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100743 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100744
745 sdata->vif.bss_conf.ssid_len = params->ssid_len;
746 if (params->ssid_len)
747 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
748 params->ssid_len);
749 sdata->vif.bss_conf.hidden_ssid =
750 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
751
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100752 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
753 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
754 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
755 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
756 if (params->p2p_opp_ps)
757 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
758 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100759
Michal Kazioraf296bd2014-06-05 14:21:36 +0200760 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200761 if (err < 0) {
762 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100763 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200764 }
Johannes Berg88600202012-02-13 15:17:18 +0100765 changed |= err;
766
Johannes Berg10416382012-10-19 15:44:42 +0200767 err = drv_start_ap(sdata->local, sdata);
768 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100769 old = sdata_dereference(sdata->u.ap.beacon, sdata);
770
Johannes Berg10416382012-10-19 15:44:42 +0200771 if (old)
772 kfree_rcu(old, rcu_head);
773 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200774 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200775 return err;
776 }
777
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800778 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100779 ieee80211_bss_info_change_notify(sdata, changed);
780
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200781 netif_carrier_on(dev);
782 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
783 netif_carrier_on(vlan->dev);
784
Johannes Berg665c93a2011-11-04 11:18:11 +0100785 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100786}
787
Johannes Berg88600202012-02-13 15:17:18 +0100788static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
789 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100790{
Johannes Berg14db74b2008-07-29 13:22:52 +0200791 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100792 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100793 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100794
Johannes Berg14db74b2008-07-29 13:22:52 +0200795 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100796 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200797
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200798 /* don't allow changing the beacon while CSA is in place - offset
799 * of channel switch counter may change
800 */
801 if (sdata->vif.csa_active)
802 return -EBUSY;
803
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100804 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100805 if (!old)
806 return -ENOENT;
807
Michal Kazioraf296bd2014-06-05 14:21:36 +0200808 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100809 if (err < 0)
810 return err;
811 ieee80211_bss_info_change_notify(sdata, err);
812 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100813}
814
Johannes Berg88600202012-02-13 15:17:18 +0100815static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100816{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200817 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
818 struct ieee80211_sub_if_data *vlan;
819 struct ieee80211_local *local = sdata->local;
820 struct beacon_data *old_beacon;
821 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100822 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100823
Michal Kaziordbd72852014-01-29 07:56:21 +0100824 sdata_assert_lock(sdata);
825
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100826 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200827 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100828 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100829 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100830
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200831 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200832 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200833 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300834 if (sdata->csa_block_tx) {
835 ieee80211_wake_vif_queues(local, sdata,
836 IEEE80211_QUEUE_STOP_REASON_CSA);
837 sdata->csa_block_tx = false;
838 }
839
Michal Kazior59af6922014-04-09 15:10:59 +0200840 mutex_unlock(&local->mtx);
841
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100842 kfree(sdata->u.ap.next_beacon);
843 sdata->u.ap.next_beacon = NULL;
844
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200845 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200846 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
847 netif_carrier_off(vlan->dev);
848 netif_carrier_off(dev);
849
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200850 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000851 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200852 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
853 kfree_rcu(old_beacon, rcu_head);
854 if (old_probe_resp)
855 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200856 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100857
Johannes Berge7162512013-12-04 23:18:37 +0100858 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100859 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100860
Johannes Bergd6a83222012-12-14 14:06:28 +0100861 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200862 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100863 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200864 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100865
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200866 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100867 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200868 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100869 cfg80211_cac_event(sdata->dev, &chandef,
870 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200871 GFP_KERNEL);
872 }
873
Johannes Berg10416382012-10-19 15:44:42 +0200874 drv_stop_ap(sdata->local, sdata);
875
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200876 /* free all potentially still buffered bcast frames */
877 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
878 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
879
Johannes Berg34a37402013-12-18 09:43:33 +0100880 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100881 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200882 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100883 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200884
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200885 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100886}
887
Johannes Berg4fd69312007-12-19 02:03:35 +0100888/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
889struct iapp_layer2_update {
890 u8 da[ETH_ALEN]; /* broadcast */
891 u8 sa[ETH_ALEN]; /* STA addr */
892 __be16 len; /* 6 */
893 u8 dsap; /* 0 */
894 u8 ssap; /* 0 */
895 u8 control;
896 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700897} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100898
899static void ieee80211_send_layer2_update(struct sta_info *sta)
900{
901 struct iapp_layer2_update *msg;
902 struct sk_buff *skb;
903
904 /* Send Level 2 Update Frame to update forwarding tables in layer 2
905 * bridge devices */
906
907 skb = dev_alloc_skb(sizeof(*msg));
908 if (!skb)
909 return;
910 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
911
912 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
913 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
914
Johannes Berge83e6542012-07-13 16:23:07 +0200915 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200916 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100917 msg->len = htons(6);
918 msg->dsap = 0;
919 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
920 msg->control = 0xaf; /* XID response lsb.1111F101.
921 * F=0 (no poll command; unsolicited frame) */
922 msg->xid_info[0] = 0x81; /* XID format identifier */
923 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
924 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
925
Johannes Bergd0709a62008-02-25 16:27:46 +0100926 skb->dev = sta->sdata->dev;
927 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100928 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400929 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100930}
931
Johannes Bergd582cff2012-10-26 17:53:44 +0200932static int sta_apply_auth_flags(struct ieee80211_local *local,
933 struct sta_info *sta,
934 u32 mask, u32 set)
935{
936 int ret;
937
938 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
939 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
940 !test_sta_flag(sta, WLAN_STA_AUTH)) {
941 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
942 if (ret)
943 return ret;
944 }
945
946 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
947 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
948 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
949 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
950 if (ret)
951 return ret;
952 }
953
954 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
955 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
956 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
957 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
958 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
959 else
960 ret = 0;
961 if (ret)
962 return ret;
963 }
964
965 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
966 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
967 test_sta_flag(sta, WLAN_STA_ASSOC)) {
968 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
969 if (ret)
970 return ret;
971 }
972
973 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
974 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
975 test_sta_flag(sta, WLAN_STA_AUTH)) {
976 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
977 if (ret)
978 return ret;
979 }
980
981 return 0;
982}
983
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100984static int sta_apply_parameters(struct ieee80211_local *local,
985 struct sta_info *sta,
986 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100987{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100988 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100989 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100990 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +0200991 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300992 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100993
Johannes Berg55de9082012-07-26 17:24:39 +0200994 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +0200995
Johannes Bergeccb8e82009-05-11 21:57:56 +0300996 mask = params->sta_flags_mask;
997 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100998
Johannes Bergd582cff2012-10-26 17:53:44 +0200999 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1000 /*
1001 * In mesh mode, ASSOCIATED isn't part of the nl80211
1002 * API but must follow AUTHENTICATED for driver state.
1003 */
1004 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1005 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1006 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1007 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001008 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1009 /*
1010 * TDLS -- everything follows authorized, but
1011 * only becoming authorized is possible, not
1012 * going back
1013 */
1014 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1015 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1016 BIT(NL80211_STA_FLAG_ASSOCIATED);
1017 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1018 BIT(NL80211_STA_FLAG_ASSOCIATED);
1019 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001020 }
1021
Arik Nemtsov68885a52014-06-11 17:18:19 +03001022 /* auth flags will be set later for TDLS stations */
1023 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1024 ret = sta_apply_auth_flags(local, sta, mask, set);
1025 if (ret)
1026 return ret;
1027 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001028
Johannes Bergeccb8e82009-05-11 21:57:56 +03001029 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001030 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001031 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1032 else
1033 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001034 }
1035
Johannes Berga74a8c82014-07-22 14:50:47 +02001036 if (mask & BIT(NL80211_STA_FLAG_WME))
1037 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001038
1039 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001040 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001041 set_sta_flag(sta, WLAN_STA_MFP);
1042 else
1043 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001044 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001045
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001046 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001047 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001048 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1049 else
1050 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001051 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001052
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001053 /* mark TDLS channel switch support, if the AP allows it */
1054 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1055 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1056 params->ext_capab_len >= 4 &&
1057 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1058 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1059
Johannes Berg3b9ce802011-09-27 20:56:12 +02001060 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1061 sta->sta.uapsd_queues = params->uapsd_queues;
1062 sta->sta.max_sp = params->max_sp;
1063 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001064
Johannes Berg73651ee2008-02-25 16:27:47 +01001065 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001066 * cfg80211 validates this (1-2007) and allows setting the AID
1067 * only when creating a new station entry
1068 */
1069 if (params->aid)
1070 sta->sta.aid = params->aid;
1071
1072 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001073 * Some of the following updates would be racy if called on an
1074 * existing station, via ieee80211_change_station(). However,
1075 * all such changes are rejected by cfg80211 except for updates
1076 * changing the supported rates on an existing but not yet used
1077 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001078 */
1079
Johannes Berg4fd69312007-12-19 02:03:35 +01001080 if (params->listen_interval >= 0)
1081 sta->listen_interval = params->listen_interval;
1082
1083 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001084 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1085 sband, params->supported_rates,
1086 params->supported_rates_len,
1087 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001088 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001089
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001090 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001091 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001092 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001093
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001094 if (params->vht_capa)
1095 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001096 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001097
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001098 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001099 /* returned value is only needed for rc update, but the
1100 * rc isn't initialized here yet, so ignore it
1101 */
1102 __ieee80211_vht_handle_opmode(sdata, sta,
1103 params->opmode_notif,
1104 band, false);
1105 }
1106
Javier Cardona9c3990a2011-05-03 16:57:11 -07001107 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001108#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001109 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001110
1111 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001112 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001113 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001114 if (sta->plink_state != NL80211_PLINK_ESTAB)
1115 changed = mesh_plink_inc_estab_count(
1116 sdata);
1117 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001118
1119 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001120 changed |= ieee80211_mps_set_sta_local_pm(sta,
1121 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001122 break;
1123 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001124 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001125 case NL80211_PLINK_OPN_SNT:
1126 case NL80211_PLINK_OPN_RCVD:
1127 case NL80211_PLINK_CNF_RCVD:
1128 case NL80211_PLINK_HOLDING:
1129 if (sta->plink_state == NL80211_PLINK_ESTAB)
1130 changed = mesh_plink_dec_estab_count(
1131 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001132 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001133
1134 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001135 changed |= ieee80211_mps_set_sta_local_pm(sta,
1136 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001137 break;
1138 default:
1139 /* nothing */
1140 break;
1141 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001142 }
1143
1144 switch (params->plink_action) {
1145 case NL80211_PLINK_ACTION_NO_ACTION:
1146 /* nothing */
1147 break;
1148 case NL80211_PLINK_ACTION_OPEN:
1149 changed |= mesh_plink_open(sta);
1150 break;
1151 case NL80211_PLINK_ACTION_BLOCK:
1152 changed |= mesh_plink_block(sta);
1153 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001154 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001155
1156 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001157 changed |=
1158 ieee80211_mps_set_sta_local_pm(sta,
1159 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001160 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001161#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001162 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001163
Arik Nemtsov68885a52014-06-11 17:18:19 +03001164 /* set the STA state after all sta info from usermode has been set */
1165 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1166 ret = sta_apply_auth_flags(local, sta, mask, set);
1167 if (ret)
1168 return ret;
1169 }
1170
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001171 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001172}
1173
1174static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001175 const u8 *mac,
1176 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001177{
Johannes Berg14db74b2008-07-29 13:22:52 +02001178 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001179 struct sta_info *sta;
1180 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001181 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001182 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001183
Johannes Berg4fd69312007-12-19 02:03:35 +01001184 if (params->vlan) {
1185 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1186
Johannes Berg05c914f2008-09-11 00:01:58 +02001187 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1188 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001189 return -EINVAL;
1190 } else
1191 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1192
Joe Perchesb203ca32012-05-08 18:56:52 +00001193 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001194 return -EINVAL;
1195
1196 if (is_multicast_ether_addr(mac))
1197 return -EINVAL;
1198
1199 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001200 if (!sta)
1201 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001202
Johannes Bergd582cff2012-10-26 17:53:44 +02001203 /*
1204 * defaults -- if userspace wants something else we'll
1205 * change it accordingly in sta_apply_parameters()
1206 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001207 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1208 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1209 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001210 } else {
1211 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001212 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001213
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001214 err = sta_apply_parameters(local, sta, params);
1215 if (err) {
1216 sta_info_free(local, sta);
1217 return err;
1218 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001219
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001220 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001221 * for TDLS, rate control should be initialized only when
1222 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001223 */
1224 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1225 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001226
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001227 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1228 sdata->vif.type == NL80211_IFTYPE_AP;
1229
Johannes Berg34e89502010-02-03 13:59:58 +01001230 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001231 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001232 rcu_read_unlock();
1233 return err;
1234 }
1235
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001236 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001237 ieee80211_send_layer2_update(sta);
1238
1239 rcu_read_unlock();
1240
Johannes Berg4fd69312007-12-19 02:03:35 +01001241 return 0;
1242}
1243
1244static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001245 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001246{
Johannes Berg14db74b2008-07-29 13:22:52 +02001247 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001248
Johannes Berg14db74b2008-07-29 13:22:52 +02001249 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1250
Jouni Malinen89c771e2014-10-10 20:52:40 +03001251 if (params->mac)
1252 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001253
Johannes Bergb998e8b2012-12-13 23:07:46 +01001254 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001255 return 0;
1256}
1257
1258static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001259 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001260 struct station_parameters *params)
1261{
Johannes Bergabe60632009-11-25 17:46:18 +01001262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001263 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001264 struct sta_info *sta;
1265 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001266 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001267 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001268
Johannes Berg87be1e12011-12-14 12:20:29 +01001269 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001270
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001271 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001272 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001273 err = -ENOENT;
1274 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001275 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001276
Johannes Berg77ee7c82013-02-15 00:48:33 +01001277 switch (sdata->vif.type) {
1278 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001279 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001280 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001281 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001282 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001283 break;
1284 case NL80211_IFTYPE_ADHOC:
1285 statype = CFG80211_STA_IBSS;
1286 break;
1287 case NL80211_IFTYPE_STATION:
1288 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1289 statype = CFG80211_STA_AP_STA;
1290 break;
1291 }
1292 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1293 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1294 else
1295 statype = CFG80211_STA_TDLS_PEER_SETUP;
1296 break;
1297 case NL80211_IFTYPE_AP:
1298 case NL80211_IFTYPE_AP_VLAN:
1299 statype = CFG80211_STA_AP_CLIENT;
1300 break;
1301 default:
1302 err = -EOPNOTSUPP;
1303 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001304 }
1305
Johannes Berg77ee7c82013-02-15 00:48:33 +01001306 err = cfg80211_check_station_change(wiphy, params, statype);
1307 if (err)
1308 goto out_err;
1309
Johannes Bergd0709a62008-02-25 16:27:46 +01001310 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001311 bool prev_4addr = false;
1312 bool new_4addr = false;
1313
Johannes Berg4fd69312007-12-19 02:03:35 +01001314 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1315
Johannes Berg9bc383d2009-11-19 11:55:19 +01001316 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001317 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001318 err = -EBUSY;
1319 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001320 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001321
Eric Dumazetcf778b02012-01-12 04:41:32 +00001322 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001323 new_4addr = true;
1324 }
1325
1326 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1327 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301328 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001329 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001330 }
1331
Johannes Berg14db74b2008-07-29 13:22:52 +02001332 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001333
1334 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1335 prev_4addr != new_4addr) {
1336 if (new_4addr)
1337 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1338 else
1339 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1340 }
1341
Johannes Berg4fd69312007-12-19 02:03:35 +01001342 ieee80211_send_layer2_update(sta);
1343 }
1344
Eliad Peller35b88622011-12-29 14:41:39 +02001345 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001346 if (err)
1347 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001348
Johannes Berg77ee7c82013-02-15 00:48:33 +01001349 /* When peer becomes authorized, init rate control as well */
1350 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1351 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001352 rate_control_rate_init(sta);
1353
Johannes Berg87be1e12011-12-14 12:20:29 +01001354 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001355
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001356 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1357 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1358 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1359 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1360 sta_info_tx_streams(sta) != 1) {
1361 ht_dbg(sta->sdata,
1362 "%pM just authorized and MIMO capable - update SMPS\n",
1363 sta->sta.addr);
1364 ieee80211_send_smps_action(sta->sdata,
1365 sta->sdata->bss->req_smps,
1366 sta->sta.addr,
1367 sta->sdata->vif.bss_conf.bssid);
1368 }
1369
Jason Young808118c2011-03-10 16:43:19 -08001370 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001371 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001372 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001373 ieee80211_recalc_ps_vif(sdata);
1374 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001375
Johannes Berg4fd69312007-12-19 02:03:35 +01001376 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001377out_err:
1378 mutex_unlock(&local->sta_mtx);
1379 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001380}
1381
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001382#ifdef CONFIG_MAC80211_MESH
1383static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001384 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001385{
Johannes Berg14db74b2008-07-29 13:22:52 +02001386 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001387 struct mesh_path *mpath;
1388 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389
Johannes Berg14db74b2008-07-29 13:22:52 +02001390 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1391
Johannes Bergd0709a62008-02-25 16:27:46 +01001392 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001393 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001394 if (!sta) {
1395 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001396 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001397 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001398
Bob Copelandae76eef2013-03-29 09:38:39 -04001399 mpath = mesh_path_add(sdata, dst);
1400 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001401 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001402 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001403 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001404
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001405 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001406
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001407 rcu_read_unlock();
1408 return 0;
1409}
1410
1411static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001412 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001413{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001414 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001415
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001416 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001417 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001418
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001419 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001420 return 0;
1421}
1422
Johannes Berg3b3a0162014-05-19 17:19:31 +02001423static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1424 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001425{
Johannes Berg14db74b2008-07-29 13:22:52 +02001426 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001427 struct mesh_path *mpath;
1428 struct sta_info *sta;
1429
Johannes Berg14db74b2008-07-29 13:22:52 +02001430 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1431
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001432 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001433
Johannes Bergabe60632009-11-25 17:46:18 +01001434 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001435 if (!sta) {
1436 rcu_read_unlock();
1437 return -ENOENT;
1438 }
1439
Johannes Bergbf7cd942013-02-15 14:40:31 +01001440 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001441 if (!mpath) {
1442 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001443 return -ENOENT;
1444 }
1445
1446 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001447
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001448 rcu_read_unlock();
1449 return 0;
1450}
1451
1452static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1453 struct mpath_info *pinfo)
1454{
Johannes Berga3836e02011-05-12 15:11:37 +02001455 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1456
1457 if (next_hop_sta)
1458 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001459 else
1460 memset(next_hop, 0, ETH_ALEN);
1461
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001462 memset(pinfo, 0, sizeof(*pinfo));
1463
Johannes Bergf5ea9122009-08-07 16:17:38 +02001464 pinfo->generation = mesh_paths_generation;
1465
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001466 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001467 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001468 MPATH_INFO_METRIC |
1469 MPATH_INFO_EXPTIME |
1470 MPATH_INFO_DISCOVERY_TIMEOUT |
1471 MPATH_INFO_DISCOVERY_RETRIES |
1472 MPATH_INFO_FLAGS;
1473
1474 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001475 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001476 pinfo->metric = mpath->metric;
1477 if (time_before(jiffies, mpath->exp_time))
1478 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1479 pinfo->discovery_timeout =
1480 jiffies_to_msecs(mpath->discovery_timeout);
1481 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001482 if (mpath->flags & MESH_PATH_ACTIVE)
1483 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1484 if (mpath->flags & MESH_PATH_RESOLVING)
1485 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001486 if (mpath->flags & MESH_PATH_SN_VALID)
1487 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001488 if (mpath->flags & MESH_PATH_FIXED)
1489 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001490 if (mpath->flags & MESH_PATH_RESOLVED)
1491 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001492}
1493
1494static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1495 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1496
1497{
Johannes Berg14db74b2008-07-29 13:22:52 +02001498 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001499 struct mesh_path *mpath;
1500
Johannes Berg14db74b2008-07-29 13:22:52 +02001501 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1502
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001503 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001504 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001505 if (!mpath) {
1506 rcu_read_unlock();
1507 return -ENOENT;
1508 }
1509 memcpy(dst, mpath->dst, ETH_ALEN);
1510 mpath_set_pinfo(mpath, next_hop, pinfo);
1511 rcu_read_unlock();
1512 return 0;
1513}
1514
1515static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001516 int idx, u8 *dst, u8 *next_hop,
1517 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001518{
Johannes Berg14db74b2008-07-29 13:22:52 +02001519 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001520 struct mesh_path *mpath;
1521
Johannes Berg14db74b2008-07-29 13:22:52 +02001522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1523
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001524 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001525 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001526 if (!mpath) {
1527 rcu_read_unlock();
1528 return -ENOENT;
1529 }
1530 memcpy(dst, mpath->dst, ETH_ALEN);
1531 mpath_set_pinfo(mpath, next_hop, pinfo);
1532 rcu_read_unlock();
1533 return 0;
1534}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001535
Henning Roggea2db2ed2014-09-12 08:58:50 +02001536static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1537 struct mpath_info *pinfo)
1538{
1539 memset(pinfo, 0, sizeof(*pinfo));
1540 memcpy(mpp, mpath->mpp, ETH_ALEN);
1541
1542 pinfo->generation = mpp_paths_generation;
1543}
1544
1545static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1546 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1547
1548{
1549 struct ieee80211_sub_if_data *sdata;
1550 struct mesh_path *mpath;
1551
1552 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1553
1554 rcu_read_lock();
1555 mpath = mpp_path_lookup(sdata, dst);
1556 if (!mpath) {
1557 rcu_read_unlock();
1558 return -ENOENT;
1559 }
1560 memcpy(dst, mpath->dst, ETH_ALEN);
1561 mpp_set_pinfo(mpath, mpp, pinfo);
1562 rcu_read_unlock();
1563 return 0;
1564}
1565
1566static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1567 int idx, u8 *dst, u8 *mpp,
1568 struct mpath_info *pinfo)
1569{
1570 struct ieee80211_sub_if_data *sdata;
1571 struct mesh_path *mpath;
1572
1573 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1574
1575 rcu_read_lock();
1576 mpath = mpp_path_lookup_by_idx(sdata, idx);
1577 if (!mpath) {
1578 rcu_read_unlock();
1579 return -ENOENT;
1580 }
1581 memcpy(dst, mpath->dst, ETH_ALEN);
1582 mpp_set_pinfo(mpath, mpp, pinfo);
1583 rcu_read_unlock();
1584 return 0;
1585}
1586
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001587static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001588 struct net_device *dev,
1589 struct mesh_config *conf)
1590{
1591 struct ieee80211_sub_if_data *sdata;
1592 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001594 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1595 return 0;
1596}
1597
1598static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1599{
1600 return (mask >> (parm-1)) & 0x1;
1601}
1602
Javier Cardonac80d5452010-12-16 17:37:49 -08001603static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1604 const struct mesh_setup *setup)
1605{
1606 u8 *new_ie;
1607 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001608 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1609 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001610
Javier Cardona581a8b02011-04-07 15:08:27 -07001611 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001612 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001613 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001614
Javier Cardona581a8b02011-04-07 15:08:27 -07001615 if (setup->ie_len) {
1616 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001617 GFP_KERNEL);
1618 if (!new_ie)
1619 return -ENOMEM;
1620 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001621 ifmsh->ie_len = setup->ie_len;
1622 ifmsh->ie = new_ie;
1623 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001624
1625 /* now copy the rest of the setup parameters */
1626 ifmsh->mesh_id_len = setup->mesh_id_len;
1627 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001628 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001629 ifmsh->mesh_pp_id = setup->path_sel_proto;
1630 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001631 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001632 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001633 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1634 if (setup->is_authenticated)
1635 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1636 if (setup->is_secure)
1637 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001638
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001639 /* mcast rate setting in Mesh Node */
1640 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1641 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001642 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001643
Marco Porsch9bdbf042013-01-07 16:04:51 +01001644 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1645 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1646
Javier Cardonac80d5452010-12-16 17:37:49 -08001647 return 0;
1648}
1649
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001650static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001651 struct net_device *dev, u32 mask,
1652 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001653{
1654 struct mesh_config *conf;
1655 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001656 struct ieee80211_if_mesh *ifmsh;
1657
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001658 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001659 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001660
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001661 /* Set the config options which we are interested in setting */
1662 conf = &(sdata->u.mesh.mshcfg);
1663 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1664 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1665 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1666 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1667 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1668 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1669 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1670 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1671 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1672 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1673 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1674 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001675 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001676 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001677 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1678 if (ifmsh->user_mpm)
1679 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001680 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001681 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001682 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1683 conf->dot11MeshNbrOffsetMaxNeighbor =
1684 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001685 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1686 conf->dot11MeshHWMPmaxPREQretries =
1687 nconf->dot11MeshHWMPmaxPREQretries;
1688 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1689 conf->path_refresh_time = nconf->path_refresh_time;
1690 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1691 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1692 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1693 conf->dot11MeshHWMPactivePathTimeout =
1694 nconf->dot11MeshHWMPactivePathTimeout;
1695 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1696 conf->dot11MeshHWMPpreqMinInterval =
1697 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001698 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1699 conf->dot11MeshHWMPperrMinInterval =
1700 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001701 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1702 mask))
1703 conf->dot11MeshHWMPnetDiameterTraversalTime =
1704 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001705 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1706 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1707 ieee80211_mesh_root_setup(ifmsh);
1708 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001709 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001710 /* our current gate announcement implementation rides on root
1711 * announcements, so require this ifmsh to also be a root node
1712 * */
1713 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001714 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1715 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001716 ieee80211_mesh_root_setup(ifmsh);
1717 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001718 conf->dot11MeshGateAnnouncementProtocol =
1719 nconf->dot11MeshGateAnnouncementProtocol;
1720 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001721 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001722 conf->dot11MeshHWMPRannInterval =
1723 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001724 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1725 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001726 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1727 /* our RSSI threshold implementation is supported only for
1728 * devices that report signal in dBm.
1729 */
1730 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1731 return -ENOTSUPP;
1732 conf->rssi_threshold = nconf->rssi_threshold;
1733 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001734 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1735 conf->ht_opmode = nconf->ht_opmode;
1736 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1737 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1738 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001739 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1740 conf->dot11MeshHWMPactivePathToRootTimeout =
1741 nconf->dot11MeshHWMPactivePathToRootTimeout;
1742 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1743 conf->dot11MeshHWMProotInterval =
1744 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001745 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1746 conf->dot11MeshHWMPconfirmationInterval =
1747 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001748 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1749 conf->power_mode = nconf->power_mode;
1750 ieee80211_mps_local_status_update(sdata);
1751 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001752 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001753 conf->dot11MeshAwakeWindowDuration =
1754 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001755 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1756 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001757 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001758 return 0;
1759}
1760
Johannes Berg29cbe682010-12-03 09:20:44 +01001761static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1762 const struct mesh_config *conf,
1763 const struct mesh_setup *setup)
1764{
1765 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1766 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001767 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001768
Javier Cardonac80d5452010-12-16 17:37:49 -08001769 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1770 err = copy_mesh_setup(ifmsh, setup);
1771 if (err)
1772 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001773
Johannes Berg04ecd252012-09-11 14:34:12 +02001774 /* can mesh use other SMPS modes? */
1775 sdata->smps_mode = IEEE80211_SMPS_OFF;
1776 sdata->needed_rx_chains = sdata->local->rx_chains;
1777
Johannes Berg34a37402013-12-18 09:43:33 +01001778 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001779 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001780 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001781 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001782 if (err)
1783 return err;
1784
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001785 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001786}
1787
1788static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1789{
1790 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1791
1792 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001793 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001794 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001795 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001796
1797 return 0;
1798}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001799#endif
1800
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001801static int ieee80211_change_bss(struct wiphy *wiphy,
1802 struct net_device *dev,
1803 struct bss_parameters *params)
1804{
Johannes Berg55de9082012-07-26 17:24:39 +02001805 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1806 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001807 u32 changed = 0;
1808
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001809 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001810 return -ENOENT;
1811
1812 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001813
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001814 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001815 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001816 changed |= BSS_CHANGED_ERP_CTS_PROT;
1817 }
1818 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001819 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001820 params->use_short_preamble;
1821 changed |= BSS_CHANGED_ERP_PREAMBLE;
1822 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001823
1824 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001825 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001826 sdata->vif.bss_conf.use_short_slot = true;
1827 changed |= BSS_CHANGED_ERP_SLOT;
1828 }
1829
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001830 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001831 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001832 params->use_short_slot_time;
1833 changed |= BSS_CHANGED_ERP_SLOT;
1834 }
1835
Jouni Malinen90c97a02008-10-30 16:59:22 +02001836 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001837 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1838 wiphy->bands[band],
1839 params->basic_rates,
1840 params->basic_rates_len,
1841 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001842 changed |= BSS_CHANGED_BASIC_RATES;
1843 }
1844
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001845 if (params->ap_isolate >= 0) {
1846 if (params->ap_isolate)
1847 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1848 else
1849 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1850 }
1851
Helmut Schaa80d7e402010-11-19 12:40:26 +01001852 if (params->ht_opmode >= 0) {
1853 sdata->vif.bss_conf.ht_operation_mode =
1854 (u16) params->ht_opmode;
1855 changed |= BSS_CHANGED_HT;
1856 }
1857
Johannes Berg339afbf2012-11-14 15:21:17 +01001858 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001859 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1860 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1861 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1862 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001863 changed |= BSS_CHANGED_P2P_PS;
1864 }
1865
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001866 if (params->p2p_opp_ps > 0) {
1867 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1868 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1869 changed |= BSS_CHANGED_P2P_PS;
1870 } else if (params->p2p_opp_ps == 0) {
1871 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1872 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001873 changed |= BSS_CHANGED_P2P_PS;
1874 }
1875
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001876 ieee80211_bss_info_change_notify(sdata, changed);
1877
1878 return 0;
1879}
1880
Jouni Malinen31888482008-10-30 16:59:24 +02001881static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001882 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001883 struct ieee80211_txq_params *params)
1884{
1885 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001886 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001887 struct ieee80211_tx_queue_params p;
1888
1889 if (!local->ops->conf_tx)
1890 return -EOPNOTSUPP;
1891
Johannes Berg54bcbc62012-03-28 11:04:25 +02001892 if (local->hw.queues < IEEE80211_NUM_ACS)
1893 return -EOPNOTSUPP;
1894
Jouni Malinen31888482008-10-30 16:59:24 +02001895 memset(&p, 0, sizeof(p));
1896 p.aifs = params->aifs;
1897 p.cw_max = params->cwmax;
1898 p.cw_min = params->cwmin;
1899 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001900
1901 /*
1902 * Setting tx queue params disables u-apsd because it's only
1903 * called in master mode.
1904 */
1905 p.uapsd = false;
1906
Johannes Berga3304b02012-03-28 11:04:24 +02001907 sdata->tx_conf[params->ac] = p;
1908 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001909 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001910 "failed to set TX queue parameters for AC %d\n",
1911 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001912 return -EINVAL;
1913 }
1914
Johannes Berg7d257452012-07-06 17:37:43 +02001915 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1916
Jouni Malinen31888482008-10-30 16:59:24 +02001917 return 0;
1918}
1919
Bob Copeland665af4f2009-01-19 11:20:53 -05001920#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001921static int ieee80211_suspend(struct wiphy *wiphy,
1922 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001923{
Johannes Bergeecc4802011-05-04 15:37:29 +02001924 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001925}
1926
1927static int ieee80211_resume(struct wiphy *wiphy)
1928{
1929 return __ieee80211_resume(wiphy_priv(wiphy));
1930}
1931#else
1932#define ieee80211_suspend NULL
1933#define ieee80211_resume NULL
1934#endif
1935
Johannes Berg2a519312009-02-10 21:25:55 +01001936static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001937 struct cfg80211_scan_request *req)
1938{
Johannes Bergfd014282012-06-18 19:17:03 +02001939 struct ieee80211_sub_if_data *sdata;
1940
1941 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001942
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001943 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1944 case NL80211_IFTYPE_STATION:
1945 case NL80211_IFTYPE_ADHOC:
1946 case NL80211_IFTYPE_MESH_POINT:
1947 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001948 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001949 break;
1950 case NL80211_IFTYPE_P2P_GO:
1951 if (sdata->local->ops->hw_scan)
1952 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001953 /*
1954 * FIXME: implement NoA while scanning in software,
1955 * for now fall through to allow scanning only when
1956 * beaconing hasn't been configured yet
1957 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001958 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001959 /*
1960 * If the scan has been forced (and the driver supports
1961 * forcing), don't care about being beaconing already.
1962 * This will create problems to the attached stations (e.g. all
1963 * the frames sent while scanning on other channel will be
1964 * lost)
1965 */
1966 if (sdata->u.ap.beacon &&
1967 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1968 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001969 return -EOPNOTSUPP;
1970 break;
1971 default:
1972 return -EOPNOTSUPP;
1973 }
Johannes Berg2a519312009-02-10 21:25:55 +01001974
1975 return ieee80211_request_scan(sdata, req);
1976}
1977
Luciano Coelho79f460c2011-05-11 17:09:36 +03001978static int
1979ieee80211_sched_scan_start(struct wiphy *wiphy,
1980 struct net_device *dev,
1981 struct cfg80211_sched_scan_request *req)
1982{
1983 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1984
1985 if (!sdata->local->ops->sched_scan_start)
1986 return -EOPNOTSUPP;
1987
1988 return ieee80211_request_sched_scan_start(sdata, req);
1989}
1990
1991static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001992ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001993{
1994 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1995
1996 if (!sdata->local->ops->sched_scan_stop)
1997 return -EOPNOTSUPP;
1998
Luciano Coelho85a99942011-05-12 16:28:29 +03001999 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002000}
2001
Jouni Malinen636a5d32009-03-19 13:39:22 +02002002static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2003 struct cfg80211_auth_request *req)
2004{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002005 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002006}
2007
2008static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2009 struct cfg80211_assoc_request *req)
2010{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002011 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002012}
2013
2014static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002015 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002016{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002017 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002018}
2019
2020static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002021 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002022{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002023 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002024}
2025
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002026static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2027 struct cfg80211_ibss_params *params)
2028{
Johannes Berg55de9082012-07-26 17:24:39 +02002029 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002030}
2031
2032static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2033{
Johannes Berg55de9082012-07-26 17:24:39 +02002034 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002035}
2036
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002037static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2038 struct ocb_setup *setup)
2039{
2040 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2041}
2042
2043static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2044{
2045 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2046}
2047
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002048static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2049 int rate[IEEE80211_NUM_BANDS])
2050{
2051 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2052
Cong Ding9887dbf2013-02-06 17:23:45 +01002053 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2054 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002055
2056 return 0;
2057}
2058
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002059static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2060{
2061 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002062 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002063
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002064 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2065 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2066
2067 if (err)
2068 return err;
2069 }
2070
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002071 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2072 (changed & WIPHY_PARAM_DYN_ACK)) {
2073 s16 coverage_class;
2074
2075 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2076 wiphy->coverage_class : -1;
2077 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002078
2079 if (err)
2080 return err;
2081 }
2082
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002083 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002084 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002085
Johannes Berg24487982009-04-23 18:52:52 +02002086 if (err)
2087 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002088 }
2089
Johannes Berg8bc83c22012-11-09 18:38:32 +01002090 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2091 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2092 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002093 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002094 }
2095 if (changed & WIPHY_PARAM_RETRY_LONG) {
2096 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2097 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002098 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002099 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002100 if (changed &
2101 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2102 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2103
2104 return 0;
2105}
2106
Johannes Berg7643a2c2009-06-02 13:01:39 +02002107static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002108 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002109 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002110{
2111 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002112 struct ieee80211_sub_if_data *sdata;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002113 enum nl80211_tx_power_setting txp_type = type;
2114 bool update_txp_type = false;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002115
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002116 if (wdev) {
2117 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2118
2119 switch (type) {
2120 case NL80211_TX_POWER_AUTOMATIC:
2121 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002122 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002123 break;
2124 case NL80211_TX_POWER_LIMITED:
2125 case NL80211_TX_POWER_FIXED:
2126 if (mbm < 0 || (mbm % 100))
2127 return -EOPNOTSUPP;
2128 sdata->user_power_level = MBM_TO_DBM(mbm);
2129 break;
2130 }
2131
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002132 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2133 update_txp_type = true;
2134 sdata->vif.bss_conf.txpower_type = txp_type;
2135 }
2136
2137 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002138
2139 return 0;
2140 }
Johannes Berg55de9082012-07-26 17:24:39 +02002141
Johannes Berg7643a2c2009-06-02 13:01:39 +02002142 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002143 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002144 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002145 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002146 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002147 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002148 case NL80211_TX_POWER_FIXED:
2149 if (mbm < 0 || (mbm % 100))
2150 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002151 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002152 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002153 }
2154
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002155 mutex_lock(&local->iflist_mtx);
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002156 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002157 sdata->user_power_level = local->user_power_level;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002158 if (txp_type != sdata->vif.bss_conf.txpower_type)
2159 update_txp_type = true;
2160 sdata->vif.bss_conf.txpower_type = txp_type;
2161 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002162 list_for_each_entry(sdata, &local->interfaces, list)
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002163 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002164 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002165
2166 return 0;
2167}
2168
Johannes Bergc8442112012-10-24 10:17:18 +02002169static int ieee80211_get_tx_power(struct wiphy *wiphy,
2170 struct wireless_dev *wdev,
2171 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002172{
2173 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002174 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002175
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002176 if (local->ops->get_txpower)
2177 return drv_get_txpower(local, sdata, dbm);
2178
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002179 if (!local->use_chanctx)
2180 *dbm = local->hw.conf.power_level;
2181 else
2182 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002183
Johannes Berg7643a2c2009-06-02 13:01:39 +02002184 return 0;
2185}
2186
Johannes Bergab737a42009-07-01 21:26:58 +02002187static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002188 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002189{
2190 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2191
2192 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2193
2194 return 0;
2195}
2196
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002197static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2198{
2199 struct ieee80211_local *local = wiphy_priv(wiphy);
2200
2201 drv_rfkill_poll(local);
2202}
2203
Johannes Bergaff89a92009-07-01 21:26:51 +02002204#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002205static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2206 struct wireless_dev *wdev,
2207 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002208{
2209 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002210 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002211
2212 if (!local->ops->testmode_cmd)
2213 return -EOPNOTSUPP;
2214
David Spinadel52981cd2013-07-31 18:06:22 +03002215 if (wdev) {
2216 struct ieee80211_sub_if_data *sdata;
2217
2218 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2219 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2220 vif = &sdata->vif;
2221 }
2222
2223 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002224}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002225
2226static int ieee80211_testmode_dump(struct wiphy *wiphy,
2227 struct sk_buff *skb,
2228 struct netlink_callback *cb,
2229 void *data, int len)
2230{
2231 struct ieee80211_local *local = wiphy_priv(wiphy);
2232
2233 if (!local->ops->testmode_dump)
2234 return -EOPNOTSUPP;
2235
2236 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2237}
Johannes Bergaff89a92009-07-01 21:26:51 +02002238#endif
2239
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002240int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2241 enum ieee80211_smps_mode smps_mode)
2242{
2243 struct sta_info *sta;
2244 enum ieee80211_smps_mode old_req;
2245 int i;
2246
2247 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2248 return -EINVAL;
2249
2250 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2251 return 0;
2252
2253 old_req = sdata->u.ap.req_smps;
2254 sdata->u.ap.req_smps = smps_mode;
2255
2256 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2257 if (old_req == smps_mode ||
2258 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2259 return 0;
2260
2261 /* If no associated stations, there's no need to do anything */
2262 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2263 sdata->smps_mode = smps_mode;
2264 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2265 return 0;
2266 }
2267
2268 ht_dbg(sdata,
2269 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2270 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2271
2272 mutex_lock(&sdata->local->sta_mtx);
2273 for (i = 0; i < STA_HASH_SIZE; i++) {
2274 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2275 lockdep_is_held(&sdata->local->sta_mtx));
2276 sta;
2277 sta = rcu_dereference_protected(sta->hnext,
2278 lockdep_is_held(&sdata->local->sta_mtx))) {
2279 /*
2280 * Only stations associated to our AP and
2281 * associated VLANs
2282 */
2283 if (sta->sdata->bss != &sdata->u.ap)
2284 continue;
2285
2286 /* This station doesn't support MIMO - skip it */
2287 if (sta_info_tx_streams(sta) == 1)
2288 continue;
2289
2290 /*
2291 * Don't wake up a STA just to send the action frame
2292 * unless we are getting more restrictive.
2293 */
2294 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2295 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2296 smps_mode)) {
2297 ht_dbg(sdata,
2298 "Won't send SMPS to sleeping STA %pM\n",
2299 sta->sta.addr);
2300 continue;
2301 }
2302
2303 /*
2304 * If the STA is not authorized, wait until it gets
2305 * authorized and the action frame will be sent then.
2306 */
2307 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2308 continue;
2309
2310 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2311 ieee80211_send_smps_action(sdata, smps_mode,
2312 sta->sta.addr,
2313 sdata->vif.bss_conf.bssid);
2314 }
2315 }
2316 mutex_unlock(&sdata->local->sta_mtx);
2317
2318 sdata->smps_mode = smps_mode;
2319 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2320
2321 return 0;
2322}
2323
2324int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2325 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002326{
2327 const u8 *ap;
2328 enum ieee80211_smps_mode old_req;
2329 int err;
2330
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002331 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002332
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002333 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2334 return -EINVAL;
2335
Johannes Berg0f782312009-12-01 13:37:02 +01002336 old_req = sdata->u.mgd.req_smps;
2337 sdata->u.mgd.req_smps = smps_mode;
2338
2339 if (old_req == smps_mode &&
2340 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2341 return 0;
2342
2343 /*
2344 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002345 * association, there's no need to do anything, just store
2346 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002347 */
2348 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002349 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002350 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002351
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002352 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002353
2354 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2355 if (sdata->u.mgd.powersave)
2356 smps_mode = IEEE80211_SMPS_DYNAMIC;
2357 else
2358 smps_mode = IEEE80211_SMPS_OFF;
2359 }
2360
2361 /* send SM PS frame to AP */
2362 err = ieee80211_send_smps_action(sdata, smps_mode,
2363 ap, ap);
2364 if (err)
2365 sdata->u.mgd.req_smps = old_req;
2366
2367 return err;
2368}
2369
Johannes Bergbc92afd2009-07-01 21:26:57 +02002370static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2371 bool enabled, int timeout)
2372{
2373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2374 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002375
Bob Copeland2d3db212013-10-29 18:11:59 -04002376 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002377 return -EOPNOTSUPP;
2378
Johannes Bergbc92afd2009-07-01 21:26:57 +02002379 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2380 return -EOPNOTSUPP;
2381
2382 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002383 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002384 return 0;
2385
2386 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002387 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002388
Johannes Berg0f782312009-12-01 13:37:02 +01002389 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002390 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002391 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002392 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002393
Johannes Bergbc92afd2009-07-01 21:26:57 +02002394 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2395 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2396
2397 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002398 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002399
2400 return 0;
2401}
2402
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002403static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2404 struct net_device *dev,
2405 s32 rssi_thold, u32 rssi_hyst)
2406{
2407 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002408 struct ieee80211_vif *vif = &sdata->vif;
2409 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2410
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002411 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2412 rssi_hyst == bss_conf->cqm_rssi_hyst)
2413 return 0;
2414
2415 bss_conf->cqm_rssi_thold = rssi_thold;
2416 bss_conf->cqm_rssi_hyst = rssi_hyst;
2417
2418 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002419 if (sdata->u.mgd.associated &&
2420 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002421 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2422
2423 return 0;
2424}
2425
Johannes Berg99303802009-07-01 21:26:59 +02002426static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2427 struct net_device *dev,
2428 const u8 *addr,
2429 const struct cfg80211_bitrate_mask *mask)
2430{
2431 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2432 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302433 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002434
Eliad Peller554a43d2012-06-12 12:41:15 +03002435 if (!ieee80211_sdata_running(sdata))
2436 return -ENETDOWN;
2437
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302438 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2439 ret = drv_set_bitrate_mask(local, sdata, mask);
2440 if (ret)
2441 return ret;
2442 }
Johannes Berg99303802009-07-01 21:26:59 +02002443
Simon Wunderlich19468412012-01-28 17:25:33 +01002444 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002445 struct ieee80211_supported_band *sband = wiphy->bands[i];
2446 int j;
2447
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002448 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002449 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2450 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002451
2452 sdata->rc_has_mcs_mask[i] = false;
2453 if (!sband)
2454 continue;
2455
2456 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2457 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2458 sdata->rc_has_mcs_mask[i] = true;
2459 break;
2460 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002461 }
Johannes Berg99303802009-07-01 21:26:59 +02002462
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002463 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002464}
2465
Eliad Pellereaa336b2014-09-03 15:25:06 +03002466static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2467 struct ieee80211_roc_work *new_roc,
2468 struct ieee80211_roc_work *cur_roc)
2469{
2470 unsigned long j = jiffies;
2471 unsigned long cur_roc_end = cur_roc->hw_start_time +
2472 msecs_to_jiffies(cur_roc->duration);
2473 struct ieee80211_roc_work *next_roc;
2474 int new_dur;
2475
2476 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2477 return false;
2478
2479 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2480 return false;
2481
2482 ieee80211_handle_roc_started(new_roc);
2483
2484 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2485
2486 /* cur_roc is long enough - add new_roc to the dependents list. */
2487 if (new_dur <= 0) {
2488 list_add_tail(&new_roc->list, &cur_roc->dependents);
2489 return true;
2490 }
2491
2492 new_roc->duration = new_dur;
2493
2494 /*
2495 * if cur_roc was already coalesced before, we might
2496 * want to extend the next roc instead of adding
2497 * a new one.
2498 */
2499 next_roc = list_entry(cur_roc->list.next,
2500 struct ieee80211_roc_work, list);
2501 if (&next_roc->list != &local->roc_list &&
2502 next_roc->chan == new_roc->chan &&
2503 next_roc->sdata == new_roc->sdata &&
2504 !WARN_ON(next_roc->started)) {
2505 list_add_tail(&new_roc->list, &next_roc->dependents);
2506 next_roc->duration = max(next_roc->duration,
2507 new_roc->duration);
2508 next_roc->type = max(next_roc->type, new_roc->type);
2509 return true;
2510 }
2511
2512 /* add right after cur_roc */
2513 list_add(&new_roc->list, &cur_roc->list);
2514
2515 return true;
2516}
2517
Johannes Berg2eb278e2012-06-05 14:28:42 +02002518static int ieee80211_start_roc_work(struct ieee80211_local *local,
2519 struct ieee80211_sub_if_data *sdata,
2520 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002521 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002522 struct sk_buff *txskb,
2523 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002524{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002525 struct ieee80211_roc_work *roc, *tmp;
2526 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002527 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002528
2529 lockdep_assert_held(&local->mtx);
2530
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002531 if (local->use_chanctx && !local->ops->remain_on_channel)
2532 return -EOPNOTSUPP;
2533
Johannes Berg2eb278e2012-06-05 14:28:42 +02002534 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2535 if (!roc)
2536 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002537
Ilan Peer2fae0622013-12-19 13:25:29 +02002538 /*
2539 * If the duration is zero, then the driver
2540 * wouldn't actually do anything. Set it to
2541 * 10 for now.
2542 *
2543 * TODO: cancel the off-channel operation
2544 * when we get the SKB's TX status and
2545 * the wait time was zero before.
2546 */
2547 if (!duration)
2548 duration = 10;
2549
Johannes Berg2eb278e2012-06-05 14:28:42 +02002550 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002551 roc->duration = duration;
2552 roc->req_duration = duration;
2553 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002554 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002555 roc->mgmt_tx_cookie = (unsigned long)txskb;
2556 roc->sdata = sdata;
2557 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2558 INIT_LIST_HEAD(&roc->dependents);
2559
Eliad Peller2f617432014-01-12 11:06:37 +02002560 /*
2561 * cookie is either the roc cookie (for normal roc)
2562 * or the SKB (for mgmt TX)
2563 */
2564 if (!txskb) {
2565 /* local->mtx protects this */
2566 local->roc_cookie_counter++;
2567 roc->cookie = local->roc_cookie_counter;
2568 /* wow, you wrapped 64 bits ... more likely a bug */
2569 if (WARN_ON(roc->cookie == 0)) {
2570 roc->cookie = 1;
2571 local->roc_cookie_counter++;
2572 }
2573 *cookie = roc->cookie;
2574 } else {
2575 *cookie = (unsigned long)txskb;
2576 }
2577
Johannes Berg2eb278e2012-06-05 14:28:42 +02002578 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002579 if (!list_empty(&local->roc_list) ||
Eliad Peller5cbc95a2015-01-07 17:50:09 +02002580 local->scanning || ieee80211_is_radar_required(local))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002581 goto out_check_combine;
2582
2583 /* if not HW assist, just queue & schedule work */
2584 if (!local->ops->remain_on_channel) {
2585 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2586 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002587 }
2588
Johannes Berg2eb278e2012-06-05 14:28:42 +02002589 /* otherwise actually kick it off here (for error handling) */
2590
Ilan Peerd339d5c2013-02-12 09:34:13 +02002591 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002592 if (ret) {
2593 kfree(roc);
2594 return ret;
2595 }
2596
2597 roc->started = true;
2598 goto out_queue;
2599
2600 out_check_combine:
2601 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002602 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002603 continue;
2604
2605 /*
2606 * Extend this ROC if possible:
2607 *
2608 * If it hasn't started yet, just increase the duration
2609 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002610 * If the type of the new ROC has higher priority, modify the
2611 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002612 */
2613 if (!tmp->started) {
2614 list_add_tail(&roc->list, &tmp->dependents);
2615 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002616 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002617 queued = true;
2618 break;
2619 }
2620
2621 /* If it has already started, it's more difficult ... */
2622 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002623 /*
2624 * In the offloaded ROC case, if it hasn't begun, add
2625 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002626 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002627 * check that there's still a minimum time left and
2628 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002629 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002630 * a reduced time so we'll ask the driver to execute
2631 * it right after finishing the previous one, in the
2632 * hope that it'll also be executed right afterwards,
2633 * effectively extending the old one.
2634 * If there's no minimum time left, just add it to the
2635 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002636 * TODO: the ROC type is ignored here, assuming that it
2637 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002638 */
2639 if (!tmp->hw_begun) {
2640 list_add_tail(&roc->list, &tmp->dependents);
2641 queued = true;
2642 break;
2643 }
2644
Eliad Pellereaa336b2014-09-03 15:25:06 +03002645 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002646 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002647 } else if (del_timer_sync(&tmp->work.timer)) {
2648 unsigned long new_end;
2649
2650 /*
2651 * In the software ROC case, cancel the timer, if
2652 * that fails then the finish work is already
2653 * queued/pending and thus we queue the new ROC
2654 * normally, if that succeeds then we can extend
2655 * the timer duration and TX the frame (if any.)
2656 */
2657
2658 list_add_tail(&roc->list, &tmp->dependents);
2659 queued = true;
2660
2661 new_end = jiffies + msecs_to_jiffies(roc->duration);
2662
2663 /* ok, it was started & we canceled timer */
2664 if (time_after(new_end, tmp->work.timer.expires))
2665 mod_timer(&tmp->work.timer, new_end);
2666 else
2667 add_timer(&tmp->work.timer);
2668
2669 ieee80211_handle_roc_started(roc);
2670 }
2671 break;
2672 }
2673
2674 out_queue:
2675 if (!queued)
2676 list_add_tail(&roc->list, &local->roc_list);
2677
Johannes Berg2eb278e2012-06-05 14:28:42 +02002678 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002679}
2680
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002681static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002682 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002683 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002684 unsigned int duration,
2685 u64 *cookie)
2686{
Johannes Berg71bbc992012-06-15 15:30:18 +02002687 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002688 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002689 int ret;
2690
Johannes Berg2eb278e2012-06-05 14:28:42 +02002691 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002692 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002693 duration, cookie, NULL,
2694 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002695 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002696
Johannes Berg2eb278e2012-06-05 14:28:42 +02002697 return ret;
2698}
2699
2700static int ieee80211_cancel_roc(struct ieee80211_local *local,
2701 u64 cookie, bool mgmt_tx)
2702{
2703 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2704 int ret;
2705
2706 mutex_lock(&local->mtx);
2707 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002708 struct ieee80211_roc_work *dep, *tmp2;
2709
2710 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002711 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002712 continue;
2713 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2714 continue;
2715 /* found dependent item -- just remove it */
2716 list_del(&dep->list);
2717 mutex_unlock(&local->mtx);
2718
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002719 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002720 return 0;
2721 }
2722
Johannes Berg50febf62012-10-26 16:13:06 +02002723 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002724 continue;
2725 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2726 continue;
2727
2728 found = roc;
2729 break;
2730 }
2731
2732 if (!found) {
2733 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002734 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002735 }
Johannes Berg21f83582010-12-18 17:20:47 +01002736
Johannes Berge979e332012-06-11 17:09:41 +02002737 /*
2738 * We found the item to cancel, so do that. Note that it
2739 * may have dependents, which we also cancel (and send
2740 * the expired signal for.) Not doing so would be quite
2741 * tricky here, but we may need to fix it later.
2742 */
2743
Johannes Berg2eb278e2012-06-05 14:28:42 +02002744 if (local->ops->remain_on_channel) {
2745 if (found->started) {
2746 ret = drv_cancel_remain_on_channel(local);
2747 if (WARN_ON_ONCE(ret)) {
2748 mutex_unlock(&local->mtx);
2749 return ret;
2750 }
2751 }
Johannes Berg21f83582010-12-18 17:20:47 +01002752
Johannes Berg2eb278e2012-06-05 14:28:42 +02002753 list_del(&found->list);
2754
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002755 if (found->started)
2756 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002757 mutex_unlock(&local->mtx);
2758
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002759 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002760 } else {
2761 /* work may be pending so use it all the time */
2762 found->abort = true;
2763 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2764
2765 mutex_unlock(&local->mtx);
2766
2767 /* work will clean up etc */
2768 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002769 WARN_ON(!found->to_be_freed);
2770 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002771 }
Johannes Berg21f83582010-12-18 17:20:47 +01002772
Johannes Berg21f83582010-12-18 17:20:47 +01002773 return 0;
2774}
2775
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002776static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002777 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002778 u64 cookie)
2779{
Johannes Berg71bbc992012-06-15 15:30:18 +02002780 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002781 struct ieee80211_local *local = sdata->local;
2782
Johannes Berg2eb278e2012-06-05 14:28:42 +02002783 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002784}
2785
Simon Wunderlich164eb022013-02-08 18:16:20 +01002786static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2787 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002788 struct cfg80211_chan_def *chandef,
2789 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002790{
2791 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2792 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002793 int err;
2794
Johannes Berg34a37402013-12-18 09:43:33 +01002795 mutex_lock(&local->mtx);
2796 if (!list_empty(&local->roc_list) || local->scanning) {
2797 err = -EBUSY;
2798 goto out_unlock;
2799 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002800
2801 /* whatever, but channel contexts should not complain about that one */
2802 sdata->smps_mode = IEEE80211_SMPS_OFF;
2803 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002804
Simon Wunderlich164eb022013-02-08 18:16:20 +01002805 err = ieee80211_vif_use_channel(sdata, chandef,
2806 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002807 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002808 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002809
Simon Wunderlich164eb022013-02-08 18:16:20 +01002810 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002811 &sdata->dfs_cac_timer_work,
2812 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002813
Johannes Berg34a37402013-12-18 09:43:33 +01002814 out_unlock:
2815 mutex_unlock(&local->mtx);
2816 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002817}
2818
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002819static struct cfg80211_beacon_data *
2820cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2821{
2822 struct cfg80211_beacon_data *new_beacon;
2823 u8 *pos;
2824 int len;
2825
2826 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2827 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2828 beacon->probe_resp_len;
2829
2830 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2831 if (!new_beacon)
2832 return NULL;
2833
2834 pos = (u8 *)(new_beacon + 1);
2835 if (beacon->head_len) {
2836 new_beacon->head_len = beacon->head_len;
2837 new_beacon->head = pos;
2838 memcpy(pos, beacon->head, beacon->head_len);
2839 pos += beacon->head_len;
2840 }
2841 if (beacon->tail_len) {
2842 new_beacon->tail_len = beacon->tail_len;
2843 new_beacon->tail = pos;
2844 memcpy(pos, beacon->tail, beacon->tail_len);
2845 pos += beacon->tail_len;
2846 }
2847 if (beacon->beacon_ies_len) {
2848 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2849 new_beacon->beacon_ies = pos;
2850 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2851 pos += beacon->beacon_ies_len;
2852 }
2853 if (beacon->proberesp_ies_len) {
2854 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2855 new_beacon->proberesp_ies = pos;
2856 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2857 pos += beacon->proberesp_ies_len;
2858 }
2859 if (beacon->assocresp_ies_len) {
2860 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2861 new_beacon->assocresp_ies = pos;
2862 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2863 pos += beacon->assocresp_ies_len;
2864 }
2865 if (beacon->probe_resp_len) {
2866 new_beacon->probe_resp_len = beacon->probe_resp_len;
2867 beacon->probe_resp = pos;
2868 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2869 pos += beacon->probe_resp_len;
2870 }
2871
2872 return new_beacon;
2873}
2874
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002875void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002876{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002877 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2878
2879 ieee80211_queue_work(&sdata->local->hw,
2880 &sdata->csa_finalize_work);
2881}
2882EXPORT_SYMBOL(ieee80211_csa_finish);
2883
Michal Kazior66199502014-04-09 15:11:00 +02002884static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2885 u32 *changed)
2886{
2887 int err;
2888
2889 switch (sdata->vif.type) {
2890 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002891 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2892 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002893 kfree(sdata->u.ap.next_beacon);
2894 sdata->u.ap.next_beacon = NULL;
2895
2896 if (err < 0)
2897 return err;
2898 *changed |= err;
2899 break;
2900 case NL80211_IFTYPE_ADHOC:
2901 err = ieee80211_ibss_finish_csa(sdata);
2902 if (err < 0)
2903 return err;
2904 *changed |= err;
2905 break;
2906#ifdef CONFIG_MAC80211_MESH
2907 case NL80211_IFTYPE_MESH_POINT:
2908 err = ieee80211_mesh_finish_csa(sdata);
2909 if (err < 0)
2910 return err;
2911 *changed |= err;
2912 break;
2913#endif
2914 default:
2915 WARN_ON(1);
2916 return -EINVAL;
2917 }
2918
2919 return 0;
2920}
2921
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002922static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002923{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002924 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002925 u32 changed = 0;
2926 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002927
Michal Kaziordbd72852014-01-29 07:56:21 +01002928 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002929 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002930 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002931
Michal Kazior03078de2014-06-25 12:35:08 +02002932 /*
2933 * using reservation isn't immediate as it may be deferred until later
2934 * with multi-vif. once reservation is complete it will re-schedule the
2935 * work with no reserved_chanctx so verify chandef to check if it
2936 * completed successfully
2937 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002938
Michal Kazior03078de2014-06-25 12:35:08 +02002939 if (sdata->reserved_chanctx) {
2940 /*
2941 * with multi-vif csa driver may call ieee80211_csa_finish()
2942 * many times while waiting for other interfaces to use their
2943 * reservations
2944 */
2945 if (sdata->reserved_ready)
2946 return 0;
2947
Fabian Frederick408b18a2014-10-09 20:36:22 +02002948 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002949 }
2950
Michal Kazior03078de2014-06-25 12:35:08 +02002951 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2952 &sdata->csa_chandef))
2953 return -EINVAL;
2954
Simon Wunderliche487eae2013-11-21 18:19:51 +01002955 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01002956
Michal Kazior66199502014-04-09 15:11:00 +02002957 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2958 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002959 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002960
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002961 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002962
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002963 if (sdata->csa_block_tx) {
2964 ieee80211_wake_vif_queues(local, sdata,
2965 IEEE80211_QUEUE_STOP_REASON_CSA);
2966 sdata->csa_block_tx = false;
2967 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002968
Luciano Coelhof1d65582014-10-08 09:48:38 +03002969 err = drv_post_channel_switch(sdata);
2970 if (err)
2971 return err;
2972
2973 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2974
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002975 return 0;
2976}
2977
2978static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2979{
2980 if (__ieee80211_csa_finalize(sdata)) {
2981 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2982 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2983 GFP_KERNEL);
2984 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002985}
2986
2987void ieee80211_csa_finalize_work(struct work_struct *work)
2988{
2989 struct ieee80211_sub_if_data *sdata =
2990 container_of(work, struct ieee80211_sub_if_data,
2991 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02002992 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002993
2994 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002995 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002996 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002997
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002998 /* AP might have been stopped while waiting for the lock. */
2999 if (!sdata->vif.csa_active)
3000 goto unlock;
3001
3002 if (!ieee80211_sdata_running(sdata))
3003 goto unlock;
3004
3005 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003006
3007unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02003008 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003009 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003010 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003011}
3012
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003013static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3014 struct cfg80211_csa_settings *params,
3015 u32 *changed)
3016{
Michal Kazioraf296bd2014-06-05 14:21:36 +02003017 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003018 int err;
3019
3020 switch (sdata->vif.type) {
3021 case NL80211_IFTYPE_AP:
3022 sdata->u.ap.next_beacon =
3023 cfg80211_beacon_dup(&params->beacon_after);
3024 if (!sdata->u.ap.next_beacon)
3025 return -ENOMEM;
3026
3027 /*
3028 * With a count of 0, we don't have to wait for any
3029 * TBTT before switching, so complete the CSA
3030 * immediately. In theory, with a count == 1 we
3031 * should delay the switch until just before the next
3032 * TBTT, but that would complicate things so we switch
3033 * immediately too. If we would delay the switch
3034 * until the next TBTT, we would have to set the probe
3035 * response here.
3036 *
3037 * TODO: A channel switch with count <= 1 without
3038 * sending a CSA action frame is kind of useless,
3039 * because the clients won't know we're changing
3040 * channels. The action frame must be implemented
3041 * either here or in the userspace.
3042 */
3043 if (params->count <= 1)
3044 break;
3045
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003046 if ((params->n_counter_offsets_beacon >
3047 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3048 (params->n_counter_offsets_presp >
3049 IEEE80211_MAX_CSA_COUNTERS_NUM))
3050 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003051
Michal Kazioraf296bd2014-06-05 14:21:36 +02003052 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3053 csa.counter_offsets_presp = params->counter_offsets_presp;
3054 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3055 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3056 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003057
Michal Kazioraf296bd2014-06-05 14:21:36 +02003058 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003059 if (err < 0) {
3060 kfree(sdata->u.ap.next_beacon);
3061 return err;
3062 }
3063 *changed |= err;
3064
3065 break;
3066 case NL80211_IFTYPE_ADHOC:
3067 if (!sdata->vif.bss_conf.ibss_joined)
3068 return -EINVAL;
3069
3070 if (params->chandef.width != sdata->u.ibss.chandef.width)
3071 return -EINVAL;
3072
3073 switch (params->chandef.width) {
3074 case NL80211_CHAN_WIDTH_40:
3075 if (cfg80211_get_chandef_type(&params->chandef) !=
3076 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3077 return -EINVAL;
3078 case NL80211_CHAN_WIDTH_5:
3079 case NL80211_CHAN_WIDTH_10:
3080 case NL80211_CHAN_WIDTH_20_NOHT:
3081 case NL80211_CHAN_WIDTH_20:
3082 break;
3083 default:
3084 return -EINVAL;
3085 }
3086
3087 /* changes into another band are not supported */
3088 if (sdata->u.ibss.chandef.chan->band !=
3089 params->chandef.chan->band)
3090 return -EINVAL;
3091
3092 /* see comments in the NL80211_IFTYPE_AP block */
3093 if (params->count > 1) {
3094 err = ieee80211_ibss_csa_beacon(sdata, params);
3095 if (err < 0)
3096 return err;
3097 *changed |= err;
3098 }
3099
3100 ieee80211_send_action_csa(sdata, params);
3101
3102 break;
3103#ifdef CONFIG_MAC80211_MESH
3104 case NL80211_IFTYPE_MESH_POINT: {
3105 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3106
3107 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3108 return -EINVAL;
3109
3110 /* changes into another band are not supported */
3111 if (sdata->vif.bss_conf.chandef.chan->band !=
3112 params->chandef.chan->band)
3113 return -EINVAL;
3114
3115 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3116 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3117 if (!ifmsh->pre_value)
3118 ifmsh->pre_value = 1;
3119 else
3120 ifmsh->pre_value++;
3121 }
3122
3123 /* see comments in the NL80211_IFTYPE_AP block */
3124 if (params->count > 1) {
3125 err = ieee80211_mesh_csa_beacon(sdata, params);
3126 if (err < 0) {
3127 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3128 return err;
3129 }
3130 *changed |= err;
3131 }
3132
3133 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3134 ieee80211_send_action_csa(sdata, params);
3135
3136 break;
3137 }
3138#endif
3139 default:
3140 return -EOPNOTSUPP;
3141 }
3142
3143 return 0;
3144}
3145
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003146static int
3147__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3148 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003149{
3150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3151 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003152 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003153 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003154 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003155 u32 changed = 0;
3156 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003157
Michal Kaziordbd72852014-01-29 07:56:21 +01003158 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003159 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003160
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003161 if (!list_empty(&local->roc_list) || local->scanning)
3162 return -EBUSY;
3163
3164 if (sdata->wdev.cac_started)
3165 return -EBUSY;
3166
3167 if (cfg80211_chandef_identical(&params->chandef,
3168 &sdata->vif.bss_conf.chandef))
3169 return -EINVAL;
3170
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003171 /* don't allow another channel switch if one is already active. */
3172 if (sdata->vif.csa_active)
3173 return -EBUSY;
3174
Michal Kazior03078de2014-06-25 12:35:08 +02003175 mutex_lock(&local->chanctx_mtx);
3176 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3177 lockdep_is_held(&local->chanctx_mtx));
3178 if (!conf) {
3179 err = -EBUSY;
3180 goto out;
3181 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003182
Michal Kazior03078de2014-06-25 12:35:08 +02003183 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3184 if (!chanctx) {
3185 err = -EBUSY;
3186 goto out;
3187 }
3188
Luciano Coelho000baa52014-11-07 15:28:33 +02003189 ch_switch.timestamp = 0;
3190 ch_switch.device_timestamp = 0;
3191 ch_switch.block_tx = params->block_tx;
3192 ch_switch.chandef = params->chandef;
3193 ch_switch.count = params->count;
3194
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003195 err = drv_pre_channel_switch(sdata, &ch_switch);
3196 if (err)
3197 goto out;
3198
Michal Kazior03078de2014-06-25 12:35:08 +02003199 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3200 chanctx->mode,
3201 params->radar_required);
3202 if (err)
3203 goto out;
3204
3205 /* if reservation is invalid then this will fail */
3206 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3207 if (err) {
3208 ieee80211_vif_unreserve_chanctx(sdata);
3209 goto out;
3210 }
3211
3212 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3213 if (err) {
3214 ieee80211_vif_unreserve_chanctx(sdata);
3215 goto out;
3216 }
3217
Luciano Coelho33787fc2013-11-11 20:34:54 +02003218 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003219 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003220 sdata->vif.csa_active = true;
3221
Michal Kazior59af6922014-04-09 15:10:59 +02003222 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003223 ieee80211_stop_vif_queues(local, sdata,
3224 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003225
Luciano Coelho2f457292014-11-07 14:31:36 +02003226 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3227 params->count);
3228
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003229 if (changed) {
3230 ieee80211_bss_info_change_notify(sdata, changed);
3231 drv_channel_switch_beacon(sdata, &params->chandef);
3232 } else {
3233 /* if the beacon didn't change, we can finalize immediately */
3234 ieee80211_csa_finalize(sdata);
3235 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003236
Michal Kazior03078de2014-06-25 12:35:08 +02003237out:
3238 mutex_unlock(&local->chanctx_mtx);
3239 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003240}
3241
Michal Kazior59af6922014-04-09 15:10:59 +02003242int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3243 struct cfg80211_csa_settings *params)
3244{
3245 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3246 struct ieee80211_local *local = sdata->local;
3247 int err;
3248
3249 mutex_lock(&local->mtx);
3250 err = __ieee80211_channel_switch(wiphy, dev, params);
3251 mutex_unlock(&local->mtx);
3252
3253 return err;
3254}
3255
Johannes Berg71bbc992012-06-15 15:30:18 +02003256static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003257 struct cfg80211_mgmt_tx_params *params,
3258 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003259{
Johannes Berg71bbc992012-06-15 15:30:18 +02003260 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003261 struct ieee80211_local *local = sdata->local;
3262 struct sk_buff *skb;
3263 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003264 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003265 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003266 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003267 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003268 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003269
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003270 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003271 flags = IEEE80211_TX_CTL_NO_ACK;
3272 else
3273 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3274 IEEE80211_TX_CTL_REQ_TX_STATUS;
3275
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003276 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303277 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3278
Johannes Berg9d38d852010-06-09 17:20:33 +02003279 switch (sdata->vif.type) {
3280 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003281 if (!sdata->vif.bss_conf.ibss_joined)
3282 need_offchan = true;
3283 /* fall through */
3284#ifdef CONFIG_MAC80211_MESH
3285 case NL80211_IFTYPE_MESH_POINT:
3286 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3287 !sdata->u.mesh.mesh_id_len)
3288 need_offchan = true;
3289 /* fall through */
3290#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003291 case NL80211_IFTYPE_AP:
3292 case NL80211_IFTYPE_AP_VLAN:
3293 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003294 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3295 !ieee80211_vif_is_mesh(&sdata->vif) &&
3296 !rcu_access_pointer(sdata->bss->beacon))
3297 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003298 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003299 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003300 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3301 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003302 break;
3303 rcu_read_lock();
3304 sta = sta_info_get(sdata, mgmt->da);
3305 rcu_read_unlock();
3306 if (!sta)
3307 return -ENOLINK;
3308 break;
3309 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003310 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003311 if (!sdata->u.mgd.associated)
3312 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003313 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003314 case NL80211_IFTYPE_P2P_DEVICE:
3315 need_offchan = true;
3316 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003317 default:
3318 return -EOPNOTSUPP;
3319 }
3320
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003321 /* configurations requiring offchan cannot work if no channel has been
3322 * specified
3323 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003324 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003325 return -EINVAL;
3326
Johannes Berg2eb278e2012-06-05 14:28:42 +02003327 mutex_lock(&local->mtx);
3328
3329 /* Check if the operating channel is the requested channel */
3330 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003331 struct ieee80211_chanctx_conf *chanctx_conf;
3332
3333 rcu_read_lock();
3334 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3335
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003336 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003337 need_offchan = params->chan &&
3338 (params->chan !=
3339 chanctx_conf->def.chan);
3340 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003341 ret = -EINVAL;
3342 rcu_read_unlock();
3343 goto out_unlock;
3344 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003345 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003346 }
Johannes Berg55de9082012-07-26 17:24:39 +02003347 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003348 }
3349
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003350 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003351 ret = -EBUSY;
3352 goto out_unlock;
3353 }
3354
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003355 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003356 if (!skb) {
3357 ret = -ENOMEM;
3358 goto out_unlock;
3359 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003360 skb_reserve(skb, local->hw.extra_tx_headroom);
3361
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003362 data = skb_put(skb, params->len);
3363 memcpy(data, params->buf, params->len);
3364
3365 /* Update CSA counters */
3366 if (sdata->vif.csa_active &&
3367 (sdata->vif.type == NL80211_IFTYPE_AP ||
3368 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3369 params->n_csa_offsets) {
3370 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003371 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003372
Michal Kazioraf296bd2014-06-05 14:21:36 +02003373 rcu_read_lock();
3374
3375 if (sdata->vif.type == NL80211_IFTYPE_AP)
3376 beacon = rcu_dereference(sdata->u.ap.beacon);
3377 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3378 beacon = rcu_dereference(sdata->u.ibss.presp);
3379 else if (ieee80211_vif_is_mesh(&sdata->vif))
3380 beacon = rcu_dereference(sdata->u.mesh.beacon);
3381
3382 if (beacon)
3383 for (i = 0; i < params->n_csa_offsets; i++)
3384 data[params->csa_offsets[i]] =
3385 beacon->csa_current_counter;
3386
3387 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003388 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003389
3390 IEEE80211_SKB_CB(skb)->flags = flags;
3391
Johannes Berg2eb278e2012-06-05 14:28:42 +02003392 skb->dev = sdata->dev;
3393
3394 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003395 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003396 ieee80211_tx_skb(sdata, skb);
3397 ret = 0;
3398 goto out_unlock;
3399 }
3400
Seth Forshee6c17b772013-02-11 11:21:07 -06003401 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3402 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003403 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003404 IEEE80211_SKB_CB(skb)->hw_queue =
3405 local->hw.offchannel_tx_hw_queue;
3406
Johannes Berg2eb278e2012-06-05 14:28:42 +02003407 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003408 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3409 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003410 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003411 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003412 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003413 out_unlock:
3414 mutex_unlock(&local->mtx);
3415 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003416}
3417
Johannes Bergf30221e2010-11-25 10:02:30 +01003418static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003419 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003420 u64 cookie)
3421{
Johannes Berg71bbc992012-06-15 15:30:18 +02003422 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003423
Johannes Berg2eb278e2012-06-05 14:28:42 +02003424 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003425}
3426
Johannes Berg7be50862010-10-13 12:06:24 +02003427static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003428 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003429 u16 frame_type, bool reg)
3430{
3431 struct ieee80211_local *local = wiphy_priv(wiphy);
3432
Will Hawkins6abe0562012-06-20 11:51:14 -04003433 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003434 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3435 if (reg)
3436 local->probe_req_reg++;
3437 else
3438 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003439
Felix Fietkau35f51492012-10-31 15:50:34 +01003440 if (!local->open_count)
3441 break;
3442
Will Hawkins6abe0562012-06-20 11:51:14 -04003443 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3444 break;
3445 default:
3446 break;
3447 }
Johannes Berg7be50862010-10-13 12:06:24 +02003448}
3449
Bruno Randolf15d96752010-11-10 12:50:56 +09003450static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3451{
3452 struct ieee80211_local *local = wiphy_priv(wiphy);
3453
3454 if (local->started)
3455 return -EOPNOTSUPP;
3456
3457 return drv_set_antenna(local, tx_ant, rx_ant);
3458}
3459
3460static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3461{
3462 struct ieee80211_local *local = wiphy_priv(wiphy);
3463
3464 return drv_get_antenna(local, tx_ant, rx_ant);
3465}
3466
Johannes Bergc68f4b82011-07-05 16:35:41 +02003467static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3468 struct net_device *dev,
3469 struct cfg80211_gtk_rekey_data *data)
3470{
3471 struct ieee80211_local *local = wiphy_priv(wiphy);
3472 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3473
3474 if (!local->ops->set_rekey_data)
3475 return -EOPNOTSUPP;
3476
3477 drv_set_rekey_data(local, sdata, data);
3478
3479 return 0;
3480}
3481
Johannes Berg06500732011-11-04 11:18:16 +01003482static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3483 const u8 *peer, u64 *cookie)
3484{
3485 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3486 struct ieee80211_local *local = sdata->local;
3487 struct ieee80211_qos_hdr *nullfunc;
3488 struct sk_buff *skb;
3489 int size = sizeof(*nullfunc);
3490 __le16 fc;
3491 bool qos;
3492 struct ieee80211_tx_info *info;
3493 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003494 struct ieee80211_chanctx_conf *chanctx_conf;
3495 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003496
3497 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003498 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3499 if (WARN_ON(!chanctx_conf)) {
3500 rcu_read_unlock();
3501 return -EINVAL;
3502 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003503 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003504 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003505 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003506 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003507 } else {
3508 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003509 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003510 }
Johannes Berg06500732011-11-04 11:18:16 +01003511
3512 if (qos) {
3513 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3514 IEEE80211_STYPE_QOS_NULLFUNC |
3515 IEEE80211_FCTL_FROMDS);
3516 } else {
3517 size -= 2;
3518 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3519 IEEE80211_STYPE_NULLFUNC |
3520 IEEE80211_FCTL_FROMDS);
3521 }
3522
3523 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003524 if (!skb) {
3525 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003526 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003527 }
Johannes Berg06500732011-11-04 11:18:16 +01003528
3529 skb->dev = dev;
3530
3531 skb_reserve(skb, local->hw.extra_tx_headroom);
3532
3533 nullfunc = (void *) skb_put(skb, size);
3534 nullfunc->frame_control = fc;
3535 nullfunc->duration_id = 0;
3536 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3537 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3538 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3539 nullfunc->seq_ctrl = 0;
3540
3541 info = IEEE80211_SKB_CB(skb);
3542
3543 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3544 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003545 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003546
3547 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3548 skb->priority = 7;
3549 if (qos)
3550 nullfunc->qos_ctrl = cpu_to_le16(7);
3551
3552 local_bh_disable();
Johannes Berg73c4e192014-11-09 18:50:09 +02003553 ieee80211_xmit(sdata, skb);
Johannes Berg06500732011-11-04 11:18:16 +01003554 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003555 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003556
3557 *cookie = (unsigned long) skb;
3558 return 0;
3559}
3560
Johannes Berg683b6d32012-11-08 21:25:48 +01003561static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3562 struct wireless_dev *wdev,
3563 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003564{
Johannes Berg55de9082012-07-26 17:24:39 +02003565 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003566 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003567 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003568 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003569
Johannes Berg55de9082012-07-26 17:24:39 +02003570 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003571 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3572 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003573 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003574 ret = 0;
3575 } else if (local->open_count > 0 &&
3576 local->open_count == local->monitors &&
3577 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3578 if (local->use_chanctx)
3579 *chandef = local->monitor_chandef;
3580 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003581 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003582 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003583 }
3584 rcu_read_unlock();
3585
Johannes Berg683b6d32012-11-08 21:25:48 +01003586 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003587}
3588
Johannes Berg6d525632012-04-04 15:05:25 +02003589#ifdef CONFIG_PM
3590static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3591{
3592 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3593}
3594#endif
3595
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003596static int ieee80211_set_qos_map(struct wiphy *wiphy,
3597 struct net_device *dev,
3598 struct cfg80211_qos_map *qos_map)
3599{
3600 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3601 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3602
3603 if (qos_map) {
3604 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3605 if (!new_qos_map)
3606 return -ENOMEM;
3607 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3608 } else {
3609 /* A NULL qos_map was passed to disable QoS mapping */
3610 new_qos_map = NULL;
3611 }
3612
Johannes Berg194ff522013-12-30 23:12:37 +01003613 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003614 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3615 if (old_qos_map)
3616 kfree_rcu(old_qos_map, rcu_head);
3617
3618 return 0;
3619}
3620
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003621static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3622 struct net_device *dev,
3623 struct cfg80211_chan_def *chandef)
3624{
3625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3626 int ret;
3627 u32 changed = 0;
3628
3629 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3630 if (ret == 0)
3631 ieee80211_bss_info_change_notify(sdata, changed);
3632
3633 return ret;
3634}
3635
Johannes Berg02219b32014-10-07 10:38:50 +03003636static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3637 u8 tsid, const u8 *peer, u8 up,
3638 u16 admitted_time)
3639{
3640 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3641 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3642 int ac = ieee802_1d_to_ac[up];
3643
3644 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3645 return -EOPNOTSUPP;
3646
3647 if (!(sdata->wmm_acm & BIT(up)))
3648 return -EINVAL;
3649
3650 if (ifmgd->tx_tspec[ac].admitted_time)
3651 return -EBUSY;
3652
3653 if (admitted_time) {
3654 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3655 ifmgd->tx_tspec[ac].tsid = tsid;
3656 ifmgd->tx_tspec[ac].up = up;
3657 }
3658
3659 return 0;
3660}
3661
3662static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3663 u8 tsid, const u8 *peer)
3664{
3665 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3666 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3667 struct ieee80211_local *local = wiphy_priv(wiphy);
3668 int ac;
3669
3670 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3671 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3672
3673 /* skip unused entries */
3674 if (!tx_tspec->admitted_time)
3675 continue;
3676
3677 if (tx_tspec->tsid != tsid)
3678 continue;
3679
3680 /* due to this new packets will be reassigned to non-ACM ACs */
3681 tx_tspec->up = -1;
3682
3683 /* Make sure that all packets have been sent to avoid to
3684 * restore the QoS params on packets that are still on the
3685 * queues.
3686 */
3687 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003688 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003689
3690 /* restore the normal QoS parameters
3691 * (unconditionally to avoid races)
3692 */
3693 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3694 tx_tspec->downgraded = false;
3695 ieee80211_sta_handle_tspec_ac_params(sdata);
3696
3697 /* finally clear all the data */
3698 memset(tx_tspec, 0, sizeof(*tx_tspec));
3699
3700 return 0;
3701 }
3702
3703 return -ENOENT;
3704}
3705
Johannes Berg8a47cea2014-01-20 23:55:44 +01003706const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003707 .add_virtual_intf = ieee80211_add_iface,
3708 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003709 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003710 .start_p2p_device = ieee80211_start_p2p_device,
3711 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003712 .add_key = ieee80211_add_key,
3713 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003714 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003715 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003716 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003717 .start_ap = ieee80211_start_ap,
3718 .change_beacon = ieee80211_change_beacon,
3719 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003720 .add_station = ieee80211_add_station,
3721 .del_station = ieee80211_del_station,
3722 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003723 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003724 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003725 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003726#ifdef CONFIG_MAC80211_MESH
3727 .add_mpath = ieee80211_add_mpath,
3728 .del_mpath = ieee80211_del_mpath,
3729 .change_mpath = ieee80211_change_mpath,
3730 .get_mpath = ieee80211_get_mpath,
3731 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003732 .get_mpp = ieee80211_get_mpp,
3733 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003734 .update_mesh_config = ieee80211_update_mesh_config,
3735 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003736 .join_mesh = ieee80211_join_mesh,
3737 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003738#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003739 .join_ocb = ieee80211_join_ocb,
3740 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003741 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003742 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003743 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003744 .suspend = ieee80211_suspend,
3745 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003746 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003747 .sched_scan_start = ieee80211_sched_scan_start,
3748 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003749 .auth = ieee80211_auth,
3750 .assoc = ieee80211_assoc,
3751 .deauth = ieee80211_deauth,
3752 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003753 .join_ibss = ieee80211_join_ibss,
3754 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003755 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003756 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003757 .set_tx_power = ieee80211_set_tx_power,
3758 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003759 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003760 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003761 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003762 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003763 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003764 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003765 .remain_on_channel = ieee80211_remain_on_channel,
3766 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003767 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003768 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003769 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003770 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003771 .set_antenna = ieee80211_set_antenna,
3772 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003773 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003774 .tdls_oper = ieee80211_tdls_oper,
3775 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02003776 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3777 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01003778 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003779 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003780#ifdef CONFIG_PM
3781 .set_wakeup = ieee80211_set_wakeup,
3782#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003783 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003784 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003785 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003786 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003787 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003788 .add_tx_ts = ieee80211_add_tx_ts,
3789 .del_tx_ts = ieee80211_del_tx_ts,
Jiri Bencf0706e82007-05-05 11:45:53 -07003790};