blob: 1c1d061cff56308940bcad2c9cda9b9153d59adc [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 Berg9607e6b662009-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:
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200167 case WLAN_CIPHER_SUITE_GCMP_256:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200168 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200170 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200171 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100172 }
173
Johannes Berg97359d12010-08-10 09:46:38 +0200174 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200175 params->key, params->seq_len, params->seq,
176 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100177 if (IS_ERR(key))
178 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100179
Johannes Berge31b8212010-10-05 19:39:30 +0200180 if (pairwise)
181 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
182
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200183 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200184
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700186 if (ieee80211_vif_is_mesh(&sdata->vif))
187 sta = sta_info_get(sdata, mac_addr);
188 else
189 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100190 /*
191 * The ASSOC test makes sure the driver is ready to
192 * receive the key. When wpa_supplicant has roamed
193 * using FT, it attempts to set the key before
194 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700195 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100196 *
197 * TODO: accept the key if we have a station entry and
198 * add it to the device after the station.
199 */
200 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100201 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200202 err = -ENOENT;
203 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100204 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100205 }
206
Johannes Berge548c492012-09-04 17:08:23 +0200207 switch (sdata->vif.type) {
208 case NL80211_IFTYPE_STATION:
209 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
210 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
211 break;
212 case NL80211_IFTYPE_AP:
213 case NL80211_IFTYPE_AP_VLAN:
214 /* Keys without a station are used for TX only */
215 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
216 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
217 break;
218 case NL80211_IFTYPE_ADHOC:
219 /* no MFP (yet) */
220 break;
221 case NL80211_IFTYPE_MESH_POINT:
222#ifdef CONFIG_MAC80211_MESH
223 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
224 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
225 break;
226#endif
227 case NL80211_IFTYPE_WDS:
228 case NL80211_IFTYPE_MONITOR:
229 case NL80211_IFTYPE_P2P_DEVICE:
230 case NL80211_IFTYPE_UNSPECIFIED:
231 case NUM_NL80211_IFTYPES:
232 case NL80211_IFTYPE_P2P_CLIENT:
233 case NL80211_IFTYPE_P2P_GO:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100234 case NL80211_IFTYPE_OCB:
Johannes Berge548c492012-09-04 17:08:23 +0200235 /* shouldn't happen */
236 WARN_ON_ONCE(1);
237 break;
238 }
239
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200240 if (sta)
241 sta->cipher_scheme = cs;
242
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300243 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100244
Johannes Berg3b967662008-04-08 17:56:52 +0200245 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200246 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200247
248 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100249}
250
251static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200252 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100253{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200254 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
255 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100256 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200257 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100258 int ret;
259
Johannes Berg5c0c3642011-05-12 14:31:49 +0200260 mutex_lock(&local->sta_mtx);
261 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200262
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100263 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200264 ret = -ENOENT;
265
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100266 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100267 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200268 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100269
Johannes Berg5c0c3642011-05-12 14:31:49 +0200270 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200271 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200272 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200273 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200274 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200275 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100276
Johannes Berg5c0c3642011-05-12 14:31:49 +0200277 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200278 ret = -ENOENT;
279 goto out_unlock;
280 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100281
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100282 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100283
Johannes Berg3b967662008-04-08 17:56:52 +0200284 ret = 0;
285 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200286 mutex_unlock(&local->key_mtx);
287 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200288
289 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100290}
291
Johannes Berg62da92f2007-12-19 02:03:31 +0100292static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200293 u8 key_idx, bool pairwise, const u8 *mac_addr,
294 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100295 void (*callback)(void *cookie,
296 struct key_params *params))
297{
Johannes Berg14db74b2008-07-29 13:22:52 +0200298 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100299 struct sta_info *sta = NULL;
300 u8 seq[6] = {0};
301 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200302 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200303 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100304 u32 iv32;
305 u16 iv16;
306 int err = -ENOENT;
307
Johannes Berg14db74b2008-07-29 13:22:52 +0200308 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
309
Johannes Berg3b967662008-04-08 17:56:52 +0200310 rcu_read_lock();
311
Johannes Berg62da92f2007-12-19 02:03:31 +0100312 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100313 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100314 if (!sta)
315 goto out;
316
Max Stepanov354e1592013-12-08 13:30:52 +0200317 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200318 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200319 else if (!pairwise &&
320 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200321 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100322 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200323 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100324
325 if (!key)
326 goto out;
327
328 memset(&params, 0, sizeof(params));
329
Johannes Berg97359d12010-08-10 09:46:38 +0200330 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100331
Johannes Berg97359d12010-08-10 09:46:38 +0200332 switch (key->conf.cipher) {
333 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700334 iv32 = key->u.tkip.tx.iv32;
335 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100336
Johannes Berg24487982009-04-23 18:52:52 +0200337 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
338 drv_get_tkip_seq(sdata->local,
339 key->conf.hw_key_idx,
340 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100341
342 seq[0] = iv16 & 0xff;
343 seq[1] = (iv16 >> 8) & 0xff;
344 seq[2] = iv32 & 0xff;
345 seq[3] = (iv32 >> 8) & 0xff;
346 seq[4] = (iv32 >> 16) & 0xff;
347 seq[5] = (iv32 >> 24) & 0xff;
348 params.seq = seq;
349 params.seq_len = 6;
350 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200351 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200352 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
353 seq[0] = pn64;
354 seq[1] = pn64 >> 8;
355 seq[2] = pn64 >> 16;
356 seq[3] = pn64 >> 24;
357 seq[4] = pn64 >> 32;
358 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100359 params.seq = seq;
360 params.seq_len = 6;
361 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200362 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200363 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
364 seq[0] = pn64;
365 seq[1] = pn64 >> 8;
366 seq[2] = pn64 >> 16;
367 seq[3] = pn64 >> 24;
368 seq[4] = pn64 >> 32;
369 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200370 params.seq = seq;
371 params.seq_len = 6;
372 break;
Jouni Malinen00b9cfa2015-01-24 19:52:06 +0200373 case WLAN_CIPHER_SUITE_GCMP:
374 case WLAN_CIPHER_SUITE_GCMP_256:
375 pn64 = atomic64_read(&key->u.gcmp.tx_pn);
376 seq[0] = pn64;
377 seq[1] = pn64 >> 8;
378 seq[2] = pn64 >> 16;
379 seq[3] = pn64 >> 24;
380 seq[4] = pn64 >> 32;
381 seq[5] = pn64 >> 40;
382 params.seq = seq;
383 params.seq_len = 6;
384 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100385 }
386
387 params.key = key->conf.key;
388 params.key_len = key->conf.keylen;
389
390 callback(cookie, &params);
391 err = 0;
392
393 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200394 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100395 return err;
396}
397
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100398static int ieee80211_config_default_key(struct wiphy *wiphy,
399 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100400 u8 key_idx, bool uni,
401 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100402{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200403 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100404
Johannes Bergf7e01042010-12-09 19:49:02 +0100405 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100406
407 return 0;
408}
409
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200410static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
411 struct net_device *dev,
412 u8 key_idx)
413{
Johannes Berg66c52422010-07-22 13:58:51 +0200414 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200415
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200416 ieee80211_set_default_mgmt_key(sdata, key_idx);
417
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200418 return 0;
419}
420
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800421void sta_set_rate_info_tx(struct sta_info *sta,
422 const struct ieee80211_tx_rate *rate,
423 struct rate_info *rinfo)
424{
425 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100426 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800427 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100428 rinfo->mcs = rate->idx;
429 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
430 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
431 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
432 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
433 } else {
434 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200435 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
436 u16 brate;
437
Johannes Berg8bc83c22012-11-09 18:38:32 +0100438 sband = sta->local->hw.wiphy->bands[
439 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200440 brate = sband->bitrates[rate->idx].bitrate;
441 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100442 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800443 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
Johannes Bergb51f3be2015-01-15 16:14:02 +0100444 rinfo->bw = RATE_INFO_BW_40;
445 else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
446 rinfo->bw = RATE_INFO_BW_80;
447 else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
448 rinfo->bw = RATE_INFO_BW_160;
449 else
450 rinfo->bw = RATE_INFO_BW_20;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800451 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
452 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800453}
454
Saravana003e6762012-11-28 18:29:38 +0530455void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
456{
457 rinfo->flags = 0;
458
459 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
460 rinfo->flags |= RATE_INFO_FLAGS_MCS;
461 rinfo->mcs = sta->last_rx_rate_idx;
462 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
463 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
464 rinfo->nss = sta->last_rx_rate_vht_nss;
465 rinfo->mcs = sta->last_rx_rate_idx;
466 } else {
467 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200468 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
469 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530470
471 sband = sta->local->hw.wiphy->bands[
472 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200473 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
474 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530475 }
476
Saravana003e6762012-11-28 18:29:38 +0530477 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
478 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Johannes Bergb51f3be2015-01-15 16:14:02 +0100479
480 if (sta->last_rx_rate_flag & RX_FLAG_5MHZ)
481 rinfo->bw = RATE_INFO_BW_5;
482 else if (sta->last_rx_rate_flag & RX_FLAG_10MHZ)
483 rinfo->bw = RATE_INFO_BW_10;
484 else if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
485 rinfo->bw = RATE_INFO_BW_40;
486 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
487 rinfo->bw = RATE_INFO_BW_80;
488 else if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
489 rinfo->bw = RATE_INFO_BW_160;
490 else
491 rinfo->bw = RATE_INFO_BW_20;
Saravana003e6762012-11-28 18:29:38 +0530492}
493
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100494static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200495 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100496{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100497 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300498 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100499 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100500 int ret = -ENOENT;
501
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300502 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100503
Johannes Berg3b53fde82009-11-16 12:00:37 +0100504 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100505 if (sta) {
506 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200507 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100508 sta_set_sinfo(sta, sinfo);
509 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100510
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300511 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100512
Johannes Bergd0709a62008-02-25 16:27:46 +0100513 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100514}
515
Holger Schurig12897232010-04-19 10:23:57 +0200516static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
517 int idx, struct survey_info *survey)
518{
519 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
520
Holger Schurig12897232010-04-19 10:23:57 +0200521 return drv_get_survey(local, idx, survey);
522}
523
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100524static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200525 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100526{
Johannes Bergabe60632009-11-25 17:46:18 +0100527 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300528 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100529 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100530 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100531
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300532 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100533
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100534 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100535 if (sta) {
536 ret = 0;
537 sta_set_sinfo(sta, sinfo);
538 }
539
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300540 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100541
542 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100543}
544
Johannes Berge8c9bd52012-06-06 08:18:22 +0200545static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100546 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200547{
Johannes Berg55de9082012-07-26 17:24:39 +0200548 struct ieee80211_local *local = wiphy_priv(wiphy);
549 struct ieee80211_sub_if_data *sdata;
550 int ret = 0;
551
Johannes Berg4bf88532012-11-09 11:39:59 +0100552 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200553 return 0;
554
Johannes Berg34a37402013-12-18 09:43:33 +0100555 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200556 mutex_lock(&local->iflist_mtx);
557 if (local->use_chanctx) {
558 sdata = rcu_dereference_protected(
559 local->monitor_sdata,
560 lockdep_is_held(&local->iflist_mtx));
561 if (sdata) {
562 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100563 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200564 IEEE80211_CHANCTX_EXCLUSIVE);
565 }
566 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100567 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200568 ieee80211_hw_config(local, 0);
569 }
570
Johannes Berg4bf88532012-11-09 11:39:59 +0100571 if (ret == 0)
572 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200573 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100574 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200575
576 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200577}
578
Arik Nemtsov02945822011-11-10 11:28:57 +0200579static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200580 const u8 *resp, size_t resp_len,
581 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200582{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300583 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200584
585 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530586 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200587
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100588 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200589
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300590 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200591 if (!new)
592 return -ENOMEM;
593
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300594 new->len = resp_len;
595 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200596
Michal Kazioraf296bd2014-06-05 14:21:36 +0200597 if (csa)
598 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
599 csa->n_counter_offsets_presp *
600 sizeof(new->csa_counter_offsets[0]));
601
Arik Nemtsov02945822011-11-10 11:28:57 +0200602 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300603 if (old)
604 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200605
606 return 0;
607}
608
Luciano Coelho0ae07962013-12-08 09:42:25 +0200609static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200610 struct cfg80211_beacon_data *params,
611 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100612{
613 struct beacon_data *new, *old;
614 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100615 int size, err;
616 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100617
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100618 old = sdata_dereference(sdata->u.ap.beacon, sdata);
619
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100620
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100621 /* Need to have a beacon head if we don't have one yet */
622 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100623 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100624
625 /* new or old head? */
626 if (params->head)
627 new_head_len = params->head_len;
628 else
629 new_head_len = old->head_len;
630
631 /* new or old tail? */
632 if (params->tail || !old)
633 /* params->tail_len will be zero for !params->tail */
634 new_tail_len = params->tail_len;
635 else
636 new_tail_len = old->tail_len;
637
638 size = sizeof(*new) + new_head_len + new_tail_len;
639
640 new = kzalloc(size, GFP_KERNEL);
641 if (!new)
642 return -ENOMEM;
643
644 /* start filling the new info now */
645
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100646 /*
647 * pointers go into the block we allocated,
648 * memory is | beacon_data | head | tail |
649 */
650 new->head = ((u8 *) new) + sizeof(*new);
651 new->tail = new->head + new_head_len;
652 new->head_len = new_head_len;
653 new->tail_len = new_tail_len;
654
Michal Kazioraf296bd2014-06-05 14:21:36 +0200655 if (csa) {
656 new->csa_current_counter = csa->count;
657 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
658 csa->n_counter_offsets_beacon *
659 sizeof(new->csa_counter_offsets[0]));
660 }
661
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100662 /* copy in head */
663 if (params->head)
664 memcpy(new->head, params->head, new_head_len);
665 else
666 memcpy(new->head, old->head, new_head_len);
667
668 /* copy in optional tail */
669 if (params->tail)
670 memcpy(new->tail, params->tail, new_tail_len);
671 else
672 if (old)
673 memcpy(new->tail, old->tail, new_tail_len);
674
Johannes Berg88600202012-02-13 15:17:18 +0100675 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200676 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100677 if (err < 0)
678 return err;
679 if (err == 0)
680 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100681
Eric Dumazetcf778b02012-01-12 04:41:32 +0000682 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100683
Johannes Berg88600202012-02-13 15:17:18 +0100684 if (old)
685 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100686
Johannes Berg88600202012-02-13 15:17:18 +0100687 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100688}
689
Johannes Berg88600202012-02-13 15:17:18 +0100690static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
691 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100692{
Johannes Berg88600202012-02-13 15:17:18 +0100693 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100694 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100695 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100696 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100697 u32 changed = BSS_CHANGED_BEACON_INT |
698 BSS_CHANGED_BEACON_ENABLED |
699 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100700 BSS_CHANGED_SSID |
Johannes Berg4bcc56b2014-11-13 11:23:53 +0100701 BSS_CHANGED_P2P_PS |
702 BSS_CHANGED_TXPOWER;
Johannes Berg88600202012-02-13 15:17:18 +0100703 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200704
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100705 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100706 if (old)
707 return -EALREADY;
708
Eliad Pellerf6993172014-09-10 14:07:35 +0300709 switch (params->smps_mode) {
710 case NL80211_SMPS_OFF:
711 sdata->smps_mode = IEEE80211_SMPS_OFF;
712 break;
713 case NL80211_SMPS_STATIC:
714 sdata->smps_mode = IEEE80211_SMPS_STATIC;
715 break;
716 case NL80211_SMPS_DYNAMIC:
717 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
718 break;
719 default:
720 return -EINVAL;
721 }
Johannes Berg04ecd252012-09-11 14:34:12 +0200722 sdata->needed_rx_chains = sdata->local->rx_chains;
723
Johannes Berg34a37402013-12-18 09:43:33 +0100724 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100725 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200726 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100727 if (!err)
728 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100729 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200730 if (err)
731 return err;
732
Johannes Berg665c93a2011-11-04 11:18:11 +0100733 /*
734 * Apply control port protocol, this allows us to
735 * not encrypt dynamic WEP control frames.
736 */
737 sdata->control_port_protocol = params->crypto.control_port_ethertype;
738 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200739 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
740 &params->crypto,
741 sdata->vif.type);
742
Johannes Berg665c93a2011-11-04 11:18:11 +0100743 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
744 vlan->control_port_protocol =
745 params->crypto.control_port_ethertype;
746 vlan->control_port_no_encrypt =
747 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200748 vlan->encrypt_headroom =
749 ieee80211_cs_headroom(sdata->local,
750 &params->crypto,
751 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100752 }
753
Johannes Berg88600202012-02-13 15:17:18 +0100754 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
755 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100756 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100757
758 sdata->vif.bss_conf.ssid_len = params->ssid_len;
759 if (params->ssid_len)
760 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
761 params->ssid_len);
762 sdata->vif.bss_conf.hidden_ssid =
763 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
764
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100765 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
766 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
767 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
768 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
769 if (params->p2p_opp_ps)
770 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
771 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100772
Michal Kazioraf296bd2014-06-05 14:21:36 +0200773 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200774 if (err < 0) {
775 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100776 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200777 }
Johannes Berg88600202012-02-13 15:17:18 +0100778 changed |= err;
779
Johannes Berg10416382012-10-19 15:44:42 +0200780 err = drv_start_ap(sdata->local, sdata);
781 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100782 old = sdata_dereference(sdata->u.ap.beacon, sdata);
783
Johannes Berg10416382012-10-19 15:44:42 +0200784 if (old)
785 kfree_rcu(old, rcu_head);
786 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200787 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200788 return err;
789 }
790
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800791 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100792 ieee80211_bss_info_change_notify(sdata, changed);
793
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200794 netif_carrier_on(dev);
795 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
796 netif_carrier_on(vlan->dev);
797
Johannes Berg665c93a2011-11-04 11:18:11 +0100798 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100799}
800
Johannes Berg88600202012-02-13 15:17:18 +0100801static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
802 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100803{
Johannes Berg14db74b2008-07-29 13:22:52 +0200804 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100805 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100806 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100807
Johannes Berg14db74b2008-07-29 13:22:52 +0200808 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100809 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200810
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200811 /* don't allow changing the beacon while CSA is in place - offset
812 * of channel switch counter may change
813 */
814 if (sdata->vif.csa_active)
815 return -EBUSY;
816
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100817 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100818 if (!old)
819 return -ENOENT;
820
Michal Kazioraf296bd2014-06-05 14:21:36 +0200821 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100822 if (err < 0)
823 return err;
824 ieee80211_bss_info_change_notify(sdata, err);
825 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100826}
827
Johannes Berg88600202012-02-13 15:17:18 +0100828static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100829{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200830 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
831 struct ieee80211_sub_if_data *vlan;
832 struct ieee80211_local *local = sdata->local;
833 struct beacon_data *old_beacon;
834 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100835 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100836
Michal Kaziordbd72852014-01-29 07:56:21 +0100837 sdata_assert_lock(sdata);
838
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100839 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200840 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100841 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100842 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100843
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200844 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200845 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200846 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300847 if (sdata->csa_block_tx) {
848 ieee80211_wake_vif_queues(local, sdata,
849 IEEE80211_QUEUE_STOP_REASON_CSA);
850 sdata->csa_block_tx = false;
851 }
852
Michal Kazior59af6922014-04-09 15:10:59 +0200853 mutex_unlock(&local->mtx);
854
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100855 kfree(sdata->u.ap.next_beacon);
856 sdata->u.ap.next_beacon = NULL;
857
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200858 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200859 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
860 netif_carrier_off(vlan->dev);
861 netif_carrier_off(dev);
862
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200863 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000864 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200865 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
866 kfree_rcu(old_beacon, rcu_head);
867 if (old_probe_resp)
868 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200869 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100870
Johannes Berge7162512013-12-04 23:18:37 +0100871 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100872 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100873
Johannes Bergd6a83222012-12-14 14:06:28 +0100874 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200875 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100876 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200877 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100878
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200879 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100880 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200881 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100882 cfg80211_cac_event(sdata->dev, &chandef,
883 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200884 GFP_KERNEL);
885 }
886
Johannes Berg10416382012-10-19 15:44:42 +0200887 drv_stop_ap(sdata->local, sdata);
888
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200889 /* free all potentially still buffered bcast frames */
890 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
891 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
892
Johannes Berg34a37402013-12-18 09:43:33 +0100893 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100894 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200895 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100896 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200897
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200898 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100899}
900
Johannes Berg4fd69312007-12-19 02:03:35 +0100901/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
902struct iapp_layer2_update {
903 u8 da[ETH_ALEN]; /* broadcast */
904 u8 sa[ETH_ALEN]; /* STA addr */
905 __be16 len; /* 6 */
906 u8 dsap; /* 0 */
907 u8 ssap; /* 0 */
908 u8 control;
909 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700910} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100911
912static void ieee80211_send_layer2_update(struct sta_info *sta)
913{
914 struct iapp_layer2_update *msg;
915 struct sk_buff *skb;
916
917 /* Send Level 2 Update Frame to update forwarding tables in layer 2
918 * bridge devices */
919
920 skb = dev_alloc_skb(sizeof(*msg));
921 if (!skb)
922 return;
923 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
924
925 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
926 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
927
Johannes Berge83e6542012-07-13 16:23:07 +0200928 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200929 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100930 msg->len = htons(6);
931 msg->dsap = 0;
932 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
933 msg->control = 0xaf; /* XID response lsb.1111F101.
934 * F=0 (no poll command; unsolicited frame) */
935 msg->xid_info[0] = 0x81; /* XID format identifier */
936 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
937 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
938
Johannes Bergd0709a62008-02-25 16:27:46 +0100939 skb->dev = sta->sdata->dev;
940 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100941 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400942 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100943}
944
Johannes Bergd582cff2012-10-26 17:53:44 +0200945static int sta_apply_auth_flags(struct ieee80211_local *local,
946 struct sta_info *sta,
947 u32 mask, u32 set)
948{
949 int ret;
950
951 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
952 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
953 !test_sta_flag(sta, WLAN_STA_AUTH)) {
954 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
955 if (ret)
956 return ret;
957 }
958
959 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
960 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
961 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
962 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
963 if (ret)
964 return ret;
965 }
966
967 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
968 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
969 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
970 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
971 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
972 else
973 ret = 0;
974 if (ret)
975 return ret;
976 }
977
978 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
979 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
980 test_sta_flag(sta, WLAN_STA_ASSOC)) {
981 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
982 if (ret)
983 return ret;
984 }
985
986 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
987 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
988 test_sta_flag(sta, WLAN_STA_AUTH)) {
989 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
990 if (ret)
991 return ret;
992 }
993
994 return 0;
995}
996
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100997static int sta_apply_parameters(struct ieee80211_local *local,
998 struct sta_info *sta,
999 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001000{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001001 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001002 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001003 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001004 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001005 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001006
Johannes Berg55de9082012-07-26 17:24:39 +02001007 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001008
Johannes Bergeccb8e82009-05-11 21:57:56 +03001009 mask = params->sta_flags_mask;
1010 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001011
Johannes Bergd582cff2012-10-26 17:53:44 +02001012 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1013 /*
1014 * In mesh mode, ASSOCIATED isn't part of the nl80211
1015 * API but must follow AUTHENTICATED for driver state.
1016 */
1017 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1018 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1019 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1020 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001021 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1022 /*
1023 * TDLS -- everything follows authorized, but
1024 * only becoming authorized is possible, not
1025 * going back
1026 */
1027 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1028 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1029 BIT(NL80211_STA_FLAG_ASSOCIATED);
1030 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1031 BIT(NL80211_STA_FLAG_ASSOCIATED);
1032 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001033 }
1034
Arik Nemtsov68885a52014-06-11 17:18:19 +03001035 /* auth flags will be set later for TDLS stations */
1036 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1037 ret = sta_apply_auth_flags(local, sta, mask, set);
1038 if (ret)
1039 return ret;
1040 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001041
Johannes Bergeccb8e82009-05-11 21:57:56 +03001042 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001043 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001044 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1045 else
1046 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001047 }
1048
Johannes Berga74a8c82014-07-22 14:50:47 +02001049 if (mask & BIT(NL80211_STA_FLAG_WME))
1050 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001051
1052 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001053 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001054 set_sta_flag(sta, WLAN_STA_MFP);
1055 else
1056 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001057 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001058
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001059 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001060 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001061 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1062 else
1063 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001064 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001065
Arik Nemtsov9041c1f2014-11-09 18:50:15 +02001066 /* mark TDLS channel switch support, if the AP allows it */
1067 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1068 !sdata->u.mgd.tdls_chan_switch_prohibited &&
1069 params->ext_capab_len >= 4 &&
1070 params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH)
1071 set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH);
1072
Johannes Berg3b9ce802011-09-27 20:56:12 +02001073 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1074 sta->sta.uapsd_queues = params->uapsd_queues;
1075 sta->sta.max_sp = params->max_sp;
1076 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001077
Johannes Berg73651ee2008-02-25 16:27:47 +01001078 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001079 * cfg80211 validates this (1-2007) and allows setting the AID
1080 * only when creating a new station entry
1081 */
1082 if (params->aid)
1083 sta->sta.aid = params->aid;
1084
1085 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001086 * Some of the following updates would be racy if called on an
1087 * existing station, via ieee80211_change_station(). However,
1088 * all such changes are rejected by cfg80211 except for updates
1089 * changing the supported rates on an existing but not yet used
1090 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001091 */
1092
Johannes Berg4fd69312007-12-19 02:03:35 +01001093 if (params->listen_interval >= 0)
1094 sta->listen_interval = params->listen_interval;
1095
1096 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001097 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1098 sband, params->supported_rates,
1099 params->supported_rates_len,
1100 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001101 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001102
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001103 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001104 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001105 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001106
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001107 if (params->vht_capa)
1108 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001109 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001110
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001111 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001112 /* returned value is only needed for rc update, but the
1113 * rc isn't initialized here yet, so ignore it
1114 */
1115 __ieee80211_vht_handle_opmode(sdata, sta,
1116 params->opmode_notif,
1117 band, false);
1118 }
1119
Javier Cardona9c3990a2011-05-03 16:57:11 -07001120 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001121#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001122 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001123
1124 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001125 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001126 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001127 if (sta->plink_state != NL80211_PLINK_ESTAB)
1128 changed = mesh_plink_inc_estab_count(
1129 sdata);
1130 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001131
1132 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001133 changed |= ieee80211_mps_set_sta_local_pm(sta,
1134 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001135 break;
1136 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001137 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001138 case NL80211_PLINK_OPN_SNT:
1139 case NL80211_PLINK_OPN_RCVD:
1140 case NL80211_PLINK_CNF_RCVD:
1141 case NL80211_PLINK_HOLDING:
1142 if (sta->plink_state == NL80211_PLINK_ESTAB)
1143 changed = mesh_plink_dec_estab_count(
1144 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001145 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001146
1147 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001148 changed |= ieee80211_mps_set_sta_local_pm(sta,
1149 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001150 break;
1151 default:
1152 /* nothing */
1153 break;
1154 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001155 }
1156
1157 switch (params->plink_action) {
1158 case NL80211_PLINK_ACTION_NO_ACTION:
1159 /* nothing */
1160 break;
1161 case NL80211_PLINK_ACTION_OPEN:
1162 changed |= mesh_plink_open(sta);
1163 break;
1164 case NL80211_PLINK_ACTION_BLOCK:
1165 changed |= mesh_plink_block(sta);
1166 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001167 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001168
1169 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001170 changed |=
1171 ieee80211_mps_set_sta_local_pm(sta,
1172 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001173 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001174#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001175 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001176
Arik Nemtsov68885a52014-06-11 17:18:19 +03001177 /* set the STA state after all sta info from usermode has been set */
1178 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1179 ret = sta_apply_auth_flags(local, sta, mask, set);
1180 if (ret)
1181 return ret;
1182 }
1183
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001184 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001185}
1186
1187static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001188 const u8 *mac,
1189 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001190{
Johannes Berg14db74b2008-07-29 13:22:52 +02001191 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001192 struct sta_info *sta;
1193 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001194 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001195 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001196
Johannes Berg4fd69312007-12-19 02:03:35 +01001197 if (params->vlan) {
1198 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1199
Johannes Berg05c914f2008-09-11 00:01:58 +02001200 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1201 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001202 return -EINVAL;
1203 } else
1204 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1205
Joe Perchesb203ca32012-05-08 18:56:52 +00001206 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001207 return -EINVAL;
1208
1209 if (is_multicast_ether_addr(mac))
1210 return -EINVAL;
1211
1212 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001213 if (!sta)
1214 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001215
Johannes Bergd582cff2012-10-26 17:53:44 +02001216 /*
1217 * defaults -- if userspace wants something else we'll
1218 * change it accordingly in sta_apply_parameters()
1219 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001220 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1221 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1222 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001223 } else {
1224 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001225 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001226
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001227 err = sta_apply_parameters(local, sta, params);
1228 if (err) {
1229 sta_info_free(local, sta);
1230 return err;
1231 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001232
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001233 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001234 * for TDLS, rate control should be initialized only when
1235 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001236 */
1237 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1238 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001239
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001240 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1241 sdata->vif.type == NL80211_IFTYPE_AP;
1242
Johannes Berg34e89502010-02-03 13:59:58 +01001243 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001244 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001245 rcu_read_unlock();
1246 return err;
1247 }
1248
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001249 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001250 ieee80211_send_layer2_update(sta);
1251
1252 rcu_read_unlock();
1253
Johannes Berg4fd69312007-12-19 02:03:35 +01001254 return 0;
1255}
1256
1257static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001258 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001259{
Johannes Berg14db74b2008-07-29 13:22:52 +02001260 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001261
Johannes Berg14db74b2008-07-29 13:22:52 +02001262 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1263
Jouni Malinen89c771e2014-10-10 20:52:40 +03001264 if (params->mac)
1265 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001266
Johannes Bergb998e8b2012-12-13 23:07:46 +01001267 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001268 return 0;
1269}
1270
1271static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001272 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001273 struct station_parameters *params)
1274{
Johannes Bergabe60632009-11-25 17:46:18 +01001275 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001276 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001277 struct sta_info *sta;
1278 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001279 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001280 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001281
Johannes Berg87be1e12011-12-14 12:20:29 +01001282 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001283
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001284 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001285 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001286 err = -ENOENT;
1287 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001288 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001289
Johannes Berg77ee7c82013-02-15 00:48:33 +01001290 switch (sdata->vif.type) {
1291 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001292 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001293 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001294 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001295 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001296 break;
1297 case NL80211_IFTYPE_ADHOC:
1298 statype = CFG80211_STA_IBSS;
1299 break;
1300 case NL80211_IFTYPE_STATION:
1301 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1302 statype = CFG80211_STA_AP_STA;
1303 break;
1304 }
1305 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1306 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1307 else
1308 statype = CFG80211_STA_TDLS_PEER_SETUP;
1309 break;
1310 case NL80211_IFTYPE_AP:
1311 case NL80211_IFTYPE_AP_VLAN:
1312 statype = CFG80211_STA_AP_CLIENT;
1313 break;
1314 default:
1315 err = -EOPNOTSUPP;
1316 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001317 }
1318
Johannes Berg77ee7c82013-02-15 00:48:33 +01001319 err = cfg80211_check_station_change(wiphy, params, statype);
1320 if (err)
1321 goto out_err;
1322
Johannes Bergd0709a62008-02-25 16:27:46 +01001323 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001324 bool prev_4addr = false;
1325 bool new_4addr = false;
1326
Johannes Berg4fd69312007-12-19 02:03:35 +01001327 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1328
Johannes Berg9bc383d2009-11-19 11:55:19 +01001329 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001330 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001331 err = -EBUSY;
1332 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001333 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001334
Eric Dumazetcf778b02012-01-12 04:41:32 +00001335 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001336 new_4addr = true;
1337 }
1338
1339 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1340 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301341 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001342 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001343 }
1344
Johannes Berg14db74b2008-07-29 13:22:52 +02001345 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001346
1347 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1348 prev_4addr != new_4addr) {
1349 if (new_4addr)
1350 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1351 else
1352 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1353 }
1354
Johannes Berg4fd69312007-12-19 02:03:35 +01001355 ieee80211_send_layer2_update(sta);
1356 }
1357
Eliad Peller35b88622011-12-29 14:41:39 +02001358 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001359 if (err)
1360 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001361
Johannes Berg77ee7c82013-02-15 00:48:33 +01001362 /* When peer becomes authorized, init rate control as well */
1363 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1364 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001365 rate_control_rate_init(sta);
1366
Johannes Berg87be1e12011-12-14 12:20:29 +01001367 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001368
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001369 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1370 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1371 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1372 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1373 sta_info_tx_streams(sta) != 1) {
1374 ht_dbg(sta->sdata,
1375 "%pM just authorized and MIMO capable - update SMPS\n",
1376 sta->sta.addr);
1377 ieee80211_send_smps_action(sta->sdata,
1378 sta->sdata->bss->req_smps,
1379 sta->sta.addr,
1380 sta->sdata->vif.bss_conf.bssid);
1381 }
1382
Jason Young808118c2011-03-10 16:43:19 -08001383 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001384 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001385 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001386 ieee80211_recalc_ps_vif(sdata);
1387 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001388
Johannes Berg4fd69312007-12-19 02:03:35 +01001389 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001390out_err:
1391 mutex_unlock(&local->sta_mtx);
1392 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001393}
1394
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001395#ifdef CONFIG_MAC80211_MESH
1396static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001397 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001398{
Johannes Berg14db74b2008-07-29 13:22:52 +02001399 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001400 struct mesh_path *mpath;
1401 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001402
Johannes Berg14db74b2008-07-29 13:22:52 +02001403 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1404
Johannes Bergd0709a62008-02-25 16:27:46 +01001405 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001406 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001407 if (!sta) {
1408 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001409 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001410 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001411
Bob Copelandae76eef2013-03-29 09:38:39 -04001412 mpath = mesh_path_add(sdata, dst);
1413 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001414 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001415 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001416 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001417
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001418 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001419
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001420 rcu_read_unlock();
1421 return 0;
1422}
1423
1424static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001425 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001426{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001427 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001428
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001429 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001430 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001431
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001432 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001433 return 0;
1434}
1435
Johannes Berg3b3a0162014-05-19 17:19:31 +02001436static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1437 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001438{
Johannes Berg14db74b2008-07-29 13:22:52 +02001439 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001440 struct mesh_path *mpath;
1441 struct sta_info *sta;
1442
Johannes Berg14db74b2008-07-29 13:22:52 +02001443 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1444
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001445 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001446
Johannes Bergabe60632009-11-25 17:46:18 +01001447 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001448 if (!sta) {
1449 rcu_read_unlock();
1450 return -ENOENT;
1451 }
1452
Johannes Bergbf7cd942013-02-15 14:40:31 +01001453 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001454 if (!mpath) {
1455 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001456 return -ENOENT;
1457 }
1458
1459 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001460
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001461 rcu_read_unlock();
1462 return 0;
1463}
1464
1465static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1466 struct mpath_info *pinfo)
1467{
Johannes Berga3836e02011-05-12 15:11:37 +02001468 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1469
1470 if (next_hop_sta)
1471 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001472 else
1473 memset(next_hop, 0, ETH_ALEN);
1474
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001475 memset(pinfo, 0, sizeof(*pinfo));
1476
Johannes Bergf5ea9122009-08-07 16:17:38 +02001477 pinfo->generation = mesh_paths_generation;
1478
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001479 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001480 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001481 MPATH_INFO_METRIC |
1482 MPATH_INFO_EXPTIME |
1483 MPATH_INFO_DISCOVERY_TIMEOUT |
1484 MPATH_INFO_DISCOVERY_RETRIES |
1485 MPATH_INFO_FLAGS;
1486
1487 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001488 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001489 pinfo->metric = mpath->metric;
1490 if (time_before(jiffies, mpath->exp_time))
1491 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1492 pinfo->discovery_timeout =
1493 jiffies_to_msecs(mpath->discovery_timeout);
1494 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001495 if (mpath->flags & MESH_PATH_ACTIVE)
1496 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1497 if (mpath->flags & MESH_PATH_RESOLVING)
1498 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001499 if (mpath->flags & MESH_PATH_SN_VALID)
1500 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001501 if (mpath->flags & MESH_PATH_FIXED)
1502 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001503 if (mpath->flags & MESH_PATH_RESOLVED)
1504 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001505}
1506
1507static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1508 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1509
1510{
Johannes Berg14db74b2008-07-29 13:22:52 +02001511 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001512 struct mesh_path *mpath;
1513
Johannes Berg14db74b2008-07-29 13:22:52 +02001514 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1515
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001516 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001517 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001518 if (!mpath) {
1519 rcu_read_unlock();
1520 return -ENOENT;
1521 }
1522 memcpy(dst, mpath->dst, ETH_ALEN);
1523 mpath_set_pinfo(mpath, next_hop, pinfo);
1524 rcu_read_unlock();
1525 return 0;
1526}
1527
1528static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001529 int idx, u8 *dst, u8 *next_hop,
1530 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001531{
Johannes Berg14db74b2008-07-29 13:22:52 +02001532 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001533 struct mesh_path *mpath;
1534
Johannes Berg14db74b2008-07-29 13:22:52 +02001535 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1536
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001537 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001538 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001539 if (!mpath) {
1540 rcu_read_unlock();
1541 return -ENOENT;
1542 }
1543 memcpy(dst, mpath->dst, ETH_ALEN);
1544 mpath_set_pinfo(mpath, next_hop, pinfo);
1545 rcu_read_unlock();
1546 return 0;
1547}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001548
Henning Roggea2db2ed2014-09-12 08:58:50 +02001549static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1550 struct mpath_info *pinfo)
1551{
1552 memset(pinfo, 0, sizeof(*pinfo));
1553 memcpy(mpp, mpath->mpp, ETH_ALEN);
1554
1555 pinfo->generation = mpp_paths_generation;
1556}
1557
1558static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1559 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1560
1561{
1562 struct ieee80211_sub_if_data *sdata;
1563 struct mesh_path *mpath;
1564
1565 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1566
1567 rcu_read_lock();
1568 mpath = mpp_path_lookup(sdata, dst);
1569 if (!mpath) {
1570 rcu_read_unlock();
1571 return -ENOENT;
1572 }
1573 memcpy(dst, mpath->dst, ETH_ALEN);
1574 mpp_set_pinfo(mpath, mpp, pinfo);
1575 rcu_read_unlock();
1576 return 0;
1577}
1578
1579static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1580 int idx, u8 *dst, u8 *mpp,
1581 struct mpath_info *pinfo)
1582{
1583 struct ieee80211_sub_if_data *sdata;
1584 struct mesh_path *mpath;
1585
1586 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1587
1588 rcu_read_lock();
1589 mpath = mpp_path_lookup_by_idx(sdata, idx);
1590 if (!mpath) {
1591 rcu_read_unlock();
1592 return -ENOENT;
1593 }
1594 memcpy(dst, mpath->dst, ETH_ALEN);
1595 mpp_set_pinfo(mpath, mpp, pinfo);
1596 rcu_read_unlock();
1597 return 0;
1598}
1599
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001600static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001601 struct net_device *dev,
1602 struct mesh_config *conf)
1603{
1604 struct ieee80211_sub_if_data *sdata;
1605 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1606
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001607 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1608 return 0;
1609}
1610
1611static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1612{
1613 return (mask >> (parm-1)) & 0x1;
1614}
1615
Javier Cardonac80d5452010-12-16 17:37:49 -08001616static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1617 const struct mesh_setup *setup)
1618{
1619 u8 *new_ie;
1620 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001621 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1622 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001623
Javier Cardona581a8b02011-04-07 15:08:27 -07001624 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001625 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001626 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001627
Javier Cardona581a8b02011-04-07 15:08:27 -07001628 if (setup->ie_len) {
1629 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001630 GFP_KERNEL);
1631 if (!new_ie)
1632 return -ENOMEM;
1633 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001634 ifmsh->ie_len = setup->ie_len;
1635 ifmsh->ie = new_ie;
1636 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001637
1638 /* now copy the rest of the setup parameters */
1639 ifmsh->mesh_id_len = setup->mesh_id_len;
1640 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001641 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001642 ifmsh->mesh_pp_id = setup->path_sel_proto;
1643 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001644 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001645 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001646 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1647 if (setup->is_authenticated)
1648 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1649 if (setup->is_secure)
1650 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001651
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001652 /* mcast rate setting in Mesh Node */
1653 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1654 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001655 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001656
Marco Porsch9bdbf042013-01-07 16:04:51 +01001657 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1658 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1659
Javier Cardonac80d5452010-12-16 17:37:49 -08001660 return 0;
1661}
1662
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001663static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001664 struct net_device *dev, u32 mask,
1665 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001666{
1667 struct mesh_config *conf;
1668 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001669 struct ieee80211_if_mesh *ifmsh;
1670
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001671 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001672 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001673
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001674 /* Set the config options which we are interested in setting */
1675 conf = &(sdata->u.mesh.mshcfg);
1676 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1677 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1678 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1679 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1680 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1681 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1682 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1683 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1684 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1685 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1686 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1687 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001688 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001689 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001690 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1691 if (ifmsh->user_mpm)
1692 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001693 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001694 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001695 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1696 conf->dot11MeshNbrOffsetMaxNeighbor =
1697 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001698 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1699 conf->dot11MeshHWMPmaxPREQretries =
1700 nconf->dot11MeshHWMPmaxPREQretries;
1701 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1702 conf->path_refresh_time = nconf->path_refresh_time;
1703 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1704 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1705 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1706 conf->dot11MeshHWMPactivePathTimeout =
1707 nconf->dot11MeshHWMPactivePathTimeout;
1708 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1709 conf->dot11MeshHWMPpreqMinInterval =
1710 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001711 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1712 conf->dot11MeshHWMPperrMinInterval =
1713 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001714 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1715 mask))
1716 conf->dot11MeshHWMPnetDiameterTraversalTime =
1717 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001718 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1719 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1720 ieee80211_mesh_root_setup(ifmsh);
1721 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001722 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001723 /* our current gate announcement implementation rides on root
1724 * announcements, so require this ifmsh to also be a root node
1725 * */
1726 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001727 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1728 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001729 ieee80211_mesh_root_setup(ifmsh);
1730 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001731 conf->dot11MeshGateAnnouncementProtocol =
1732 nconf->dot11MeshGateAnnouncementProtocol;
1733 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001734 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001735 conf->dot11MeshHWMPRannInterval =
1736 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001737 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1738 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001739 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1740 /* our RSSI threshold implementation is supported only for
1741 * devices that report signal in dBm.
1742 */
1743 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1744 return -ENOTSUPP;
1745 conf->rssi_threshold = nconf->rssi_threshold;
1746 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001747 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1748 conf->ht_opmode = nconf->ht_opmode;
1749 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1750 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1751 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001752 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1753 conf->dot11MeshHWMPactivePathToRootTimeout =
1754 nconf->dot11MeshHWMPactivePathToRootTimeout;
1755 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1756 conf->dot11MeshHWMProotInterval =
1757 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001758 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1759 conf->dot11MeshHWMPconfirmationInterval =
1760 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001761 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1762 conf->power_mode = nconf->power_mode;
1763 ieee80211_mps_local_status_update(sdata);
1764 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001765 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001766 conf->dot11MeshAwakeWindowDuration =
1767 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001768 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1769 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001770 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001771 return 0;
1772}
1773
Johannes Berg29cbe682010-12-03 09:20:44 +01001774static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1775 const struct mesh_config *conf,
1776 const struct mesh_setup *setup)
1777{
1778 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1779 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001780 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001781
Javier Cardonac80d5452010-12-16 17:37:49 -08001782 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1783 err = copy_mesh_setup(ifmsh, setup);
1784 if (err)
1785 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001786
Johannes Berg04ecd252012-09-11 14:34:12 +02001787 /* can mesh use other SMPS modes? */
1788 sdata->smps_mode = IEEE80211_SMPS_OFF;
1789 sdata->needed_rx_chains = sdata->local->rx_chains;
1790
Johannes Berg34a37402013-12-18 09:43:33 +01001791 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001792 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001793 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001794 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001795 if (err)
1796 return err;
1797
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001798 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001799}
1800
1801static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1802{
1803 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1804
1805 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001806 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001807 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001808 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001809
1810 return 0;
1811}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001812#endif
1813
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001814static int ieee80211_change_bss(struct wiphy *wiphy,
1815 struct net_device *dev,
1816 struct bss_parameters *params)
1817{
Johannes Berg55de9082012-07-26 17:24:39 +02001818 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1819 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001820 u32 changed = 0;
1821
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001822 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001823 return -ENOENT;
1824
1825 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001826
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001827 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001828 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001829 changed |= BSS_CHANGED_ERP_CTS_PROT;
1830 }
1831 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001832 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001833 params->use_short_preamble;
1834 changed |= BSS_CHANGED_ERP_PREAMBLE;
1835 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001836
1837 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001838 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001839 sdata->vif.bss_conf.use_short_slot = true;
1840 changed |= BSS_CHANGED_ERP_SLOT;
1841 }
1842
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001843 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001844 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001845 params->use_short_slot_time;
1846 changed |= BSS_CHANGED_ERP_SLOT;
1847 }
1848
Jouni Malinen90c97a02008-10-30 16:59:22 +02001849 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001850 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1851 wiphy->bands[band],
1852 params->basic_rates,
1853 params->basic_rates_len,
1854 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001855 changed |= BSS_CHANGED_BASIC_RATES;
1856 }
1857
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001858 if (params->ap_isolate >= 0) {
1859 if (params->ap_isolate)
1860 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1861 else
1862 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1863 }
1864
Helmut Schaa80d7e402010-11-19 12:40:26 +01001865 if (params->ht_opmode >= 0) {
1866 sdata->vif.bss_conf.ht_operation_mode =
1867 (u16) params->ht_opmode;
1868 changed |= BSS_CHANGED_HT;
1869 }
1870
Johannes Berg339afbf2012-11-14 15:21:17 +01001871 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001872 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1873 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1874 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1875 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001876 changed |= BSS_CHANGED_P2P_PS;
1877 }
1878
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001879 if (params->p2p_opp_ps > 0) {
1880 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1881 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1882 changed |= BSS_CHANGED_P2P_PS;
1883 } else if (params->p2p_opp_ps == 0) {
1884 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1885 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001886 changed |= BSS_CHANGED_P2P_PS;
1887 }
1888
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001889 ieee80211_bss_info_change_notify(sdata, changed);
1890
1891 return 0;
1892}
1893
Jouni Malinen31888482008-10-30 16:59:24 +02001894static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001895 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001896 struct ieee80211_txq_params *params)
1897{
1898 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001899 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001900 struct ieee80211_tx_queue_params p;
1901
1902 if (!local->ops->conf_tx)
1903 return -EOPNOTSUPP;
1904
Johannes Berg54bcbc62012-03-28 11:04:25 +02001905 if (local->hw.queues < IEEE80211_NUM_ACS)
1906 return -EOPNOTSUPP;
1907
Jouni Malinen31888482008-10-30 16:59:24 +02001908 memset(&p, 0, sizeof(p));
1909 p.aifs = params->aifs;
1910 p.cw_max = params->cwmax;
1911 p.cw_min = params->cwmin;
1912 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001913
1914 /*
1915 * Setting tx queue params disables u-apsd because it's only
1916 * called in master mode.
1917 */
1918 p.uapsd = false;
1919
Johannes Berga3304b02012-03-28 11:04:24 +02001920 sdata->tx_conf[params->ac] = p;
1921 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001922 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001923 "failed to set TX queue parameters for AC %d\n",
1924 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001925 return -EINVAL;
1926 }
1927
Johannes Berg7d257452012-07-06 17:37:43 +02001928 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1929
Jouni Malinen31888482008-10-30 16:59:24 +02001930 return 0;
1931}
1932
Bob Copeland665af4f2009-01-19 11:20:53 -05001933#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001934static int ieee80211_suspend(struct wiphy *wiphy,
1935 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001936{
Johannes Bergeecc4802011-05-04 15:37:29 +02001937 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001938}
1939
1940static int ieee80211_resume(struct wiphy *wiphy)
1941{
1942 return __ieee80211_resume(wiphy_priv(wiphy));
1943}
1944#else
1945#define ieee80211_suspend NULL
1946#define ieee80211_resume NULL
1947#endif
1948
Johannes Berg2a519312009-02-10 21:25:55 +01001949static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001950 struct cfg80211_scan_request *req)
1951{
Johannes Bergfd014282012-06-18 19:17:03 +02001952 struct ieee80211_sub_if_data *sdata;
1953
1954 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001955
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001956 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1957 case NL80211_IFTYPE_STATION:
1958 case NL80211_IFTYPE_ADHOC:
1959 case NL80211_IFTYPE_MESH_POINT:
1960 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001961 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001962 break;
1963 case NL80211_IFTYPE_P2P_GO:
1964 if (sdata->local->ops->hw_scan)
1965 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001966 /*
1967 * FIXME: implement NoA while scanning in software,
1968 * for now fall through to allow scanning only when
1969 * beaconing hasn't been configured yet
1970 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001971 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001972 /*
1973 * If the scan has been forced (and the driver supports
1974 * forcing), don't care about being beaconing already.
1975 * This will create problems to the attached stations (e.g. all
1976 * the frames sent while scanning on other channel will be
1977 * lost)
1978 */
1979 if (sdata->u.ap.beacon &&
1980 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1981 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001982 return -EOPNOTSUPP;
1983 break;
1984 default:
1985 return -EOPNOTSUPP;
1986 }
Johannes Berg2a519312009-02-10 21:25:55 +01001987
1988 return ieee80211_request_scan(sdata, req);
1989}
1990
Luciano Coelho79f460c2011-05-11 17:09:36 +03001991static int
1992ieee80211_sched_scan_start(struct wiphy *wiphy,
1993 struct net_device *dev,
1994 struct cfg80211_sched_scan_request *req)
1995{
1996 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1997
1998 if (!sdata->local->ops->sched_scan_start)
1999 return -EOPNOTSUPP;
2000
2001 return ieee80211_request_sched_scan_start(sdata, req);
2002}
2003
2004static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002005ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002006{
2007 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2008
2009 if (!sdata->local->ops->sched_scan_stop)
2010 return -EOPNOTSUPP;
2011
Luciano Coelho85a99942011-05-12 16:28:29 +03002012 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002013}
2014
Jouni Malinen636a5d32009-03-19 13:39:22 +02002015static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2016 struct cfg80211_auth_request *req)
2017{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002018 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002019}
2020
2021static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2022 struct cfg80211_assoc_request *req)
2023{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002024 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002025}
2026
2027static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002028 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002029{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002030 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002031}
2032
2033static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002034 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002035{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002036 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002037}
2038
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002039static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2040 struct cfg80211_ibss_params *params)
2041{
Johannes Berg55de9082012-07-26 17:24:39 +02002042 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002043}
2044
2045static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2046{
Johannes Berg55de9082012-07-26 17:24:39 +02002047 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002048}
2049
Rostislav Lisovy239281f2014-11-03 10:33:19 +01002050static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev,
2051 struct ocb_setup *setup)
2052{
2053 return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup);
2054}
2055
2056static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev)
2057{
2058 return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev));
2059}
2060
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002061static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2062 int rate[IEEE80211_NUM_BANDS])
2063{
2064 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2065
Cong Ding9887dbf2013-02-06 17:23:45 +01002066 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2067 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002068
2069 return 0;
2070}
2071
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002072static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2073{
2074 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002075 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002076
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002077 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2078 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2079
2080 if (err)
2081 return err;
2082 }
2083
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002084 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2085 (changed & WIPHY_PARAM_DYN_ACK)) {
2086 s16 coverage_class;
2087
2088 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2089 wiphy->coverage_class : -1;
2090 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002091
2092 if (err)
2093 return err;
2094 }
2095
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002096 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002097 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002098
Johannes Berg24487982009-04-23 18:52:52 +02002099 if (err)
2100 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002101 }
2102
Johannes Berg8bc83c22012-11-09 18:38:32 +01002103 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2104 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2105 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002106 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002107 }
2108 if (changed & WIPHY_PARAM_RETRY_LONG) {
2109 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2110 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002111 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002112 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002113 if (changed &
2114 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2115 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2116
2117 return 0;
2118}
2119
Johannes Berg7643a2c2009-06-02 13:01:39 +02002120static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002121 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002122 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002123{
2124 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002125 struct ieee80211_sub_if_data *sdata;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002126 enum nl80211_tx_power_setting txp_type = type;
2127 bool update_txp_type = false;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002128
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002129 if (wdev) {
2130 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2131
2132 switch (type) {
2133 case NL80211_TX_POWER_AUTOMATIC:
2134 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002135 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002136 break;
2137 case NL80211_TX_POWER_LIMITED:
2138 case NL80211_TX_POWER_FIXED:
2139 if (mbm < 0 || (mbm % 100))
2140 return -EOPNOTSUPP;
2141 sdata->user_power_level = MBM_TO_DBM(mbm);
2142 break;
2143 }
2144
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002145 if (txp_type != sdata->vif.bss_conf.txpower_type) {
2146 update_txp_type = true;
2147 sdata->vif.bss_conf.txpower_type = txp_type;
2148 }
2149
2150 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002151
2152 return 0;
2153 }
Johannes Berg55de9082012-07-26 17:24:39 +02002154
Johannes Berg7643a2c2009-06-02 13:01:39 +02002155 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002156 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002157 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002158 txp_type = NL80211_TX_POWER_LIMITED;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002159 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002160 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002161 case NL80211_TX_POWER_FIXED:
2162 if (mbm < 0 || (mbm % 100))
2163 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002164 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002165 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002166 }
2167
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002168 mutex_lock(&local->iflist_mtx);
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002169 list_for_each_entry(sdata, &local->interfaces, list) {
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002170 sdata->user_power_level = local->user_power_level;
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002171 if (txp_type != sdata->vif.bss_conf.txpower_type)
2172 update_txp_type = true;
2173 sdata->vif.bss_conf.txpower_type = txp_type;
2174 }
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002175 list_for_each_entry(sdata, &local->interfaces, list)
Lorenzo Bianconidb82d8a2015-01-14 12:55:08 +01002176 ieee80211_recalc_txpower(sdata, update_txp_type);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002177 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002178
2179 return 0;
2180}
2181
Johannes Bergc8442112012-10-24 10:17:18 +02002182static int ieee80211_get_tx_power(struct wiphy *wiphy,
2183 struct wireless_dev *wdev,
2184 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002185{
2186 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002187 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002188
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002189 if (local->ops->get_txpower)
2190 return drv_get_txpower(local, sdata, dbm);
2191
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002192 if (!local->use_chanctx)
2193 *dbm = local->hw.conf.power_level;
2194 else
2195 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002196
Johannes Berg7643a2c2009-06-02 13:01:39 +02002197 return 0;
2198}
2199
Johannes Bergab737a42009-07-01 21:26:58 +02002200static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002201 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002202{
2203 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2204
2205 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2206
2207 return 0;
2208}
2209
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002210static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2211{
2212 struct ieee80211_local *local = wiphy_priv(wiphy);
2213
2214 drv_rfkill_poll(local);
2215}
2216
Johannes Bergaff89a92009-07-01 21:26:51 +02002217#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002218static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2219 struct wireless_dev *wdev,
2220 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002221{
2222 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002223 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002224
2225 if (!local->ops->testmode_cmd)
2226 return -EOPNOTSUPP;
2227
David Spinadel52981cd2013-07-31 18:06:22 +03002228 if (wdev) {
2229 struct ieee80211_sub_if_data *sdata;
2230
2231 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2232 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2233 vif = &sdata->vif;
2234 }
2235
2236 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002237}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002238
2239static int ieee80211_testmode_dump(struct wiphy *wiphy,
2240 struct sk_buff *skb,
2241 struct netlink_callback *cb,
2242 void *data, int len)
2243{
2244 struct ieee80211_local *local = wiphy_priv(wiphy);
2245
2246 if (!local->ops->testmode_dump)
2247 return -EOPNOTSUPP;
2248
2249 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2250}
Johannes Bergaff89a92009-07-01 21:26:51 +02002251#endif
2252
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002253int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2254 enum ieee80211_smps_mode smps_mode)
2255{
2256 struct sta_info *sta;
2257 enum ieee80211_smps_mode old_req;
2258 int i;
2259
2260 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2261 return -EINVAL;
2262
2263 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2264 return 0;
2265
2266 old_req = sdata->u.ap.req_smps;
2267 sdata->u.ap.req_smps = smps_mode;
2268
2269 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2270 if (old_req == smps_mode ||
2271 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2272 return 0;
2273
2274 /* If no associated stations, there's no need to do anything */
2275 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2276 sdata->smps_mode = smps_mode;
2277 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2278 return 0;
2279 }
2280
2281 ht_dbg(sdata,
2282 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2283 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2284
2285 mutex_lock(&sdata->local->sta_mtx);
2286 for (i = 0; i < STA_HASH_SIZE; i++) {
2287 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2288 lockdep_is_held(&sdata->local->sta_mtx));
2289 sta;
2290 sta = rcu_dereference_protected(sta->hnext,
2291 lockdep_is_held(&sdata->local->sta_mtx))) {
2292 /*
2293 * Only stations associated to our AP and
2294 * associated VLANs
2295 */
2296 if (sta->sdata->bss != &sdata->u.ap)
2297 continue;
2298
2299 /* This station doesn't support MIMO - skip it */
2300 if (sta_info_tx_streams(sta) == 1)
2301 continue;
2302
2303 /*
2304 * Don't wake up a STA just to send the action frame
2305 * unless we are getting more restrictive.
2306 */
2307 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2308 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2309 smps_mode)) {
2310 ht_dbg(sdata,
2311 "Won't send SMPS to sleeping STA %pM\n",
2312 sta->sta.addr);
2313 continue;
2314 }
2315
2316 /*
2317 * If the STA is not authorized, wait until it gets
2318 * authorized and the action frame will be sent then.
2319 */
2320 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2321 continue;
2322
2323 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2324 ieee80211_send_smps_action(sdata, smps_mode,
2325 sta->sta.addr,
2326 sdata->vif.bss_conf.bssid);
2327 }
2328 }
2329 mutex_unlock(&sdata->local->sta_mtx);
2330
2331 sdata->smps_mode = smps_mode;
2332 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2333
2334 return 0;
2335}
2336
2337int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2338 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002339{
2340 const u8 *ap;
2341 enum ieee80211_smps_mode old_req;
2342 int err;
2343
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002344 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002345
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002346 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2347 return -EINVAL;
2348
Johannes Berg0f782312009-12-01 13:37:02 +01002349 old_req = sdata->u.mgd.req_smps;
2350 sdata->u.mgd.req_smps = smps_mode;
2351
2352 if (old_req == smps_mode &&
2353 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2354 return 0;
2355
2356 /*
2357 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002358 * association, there's no need to do anything, just store
2359 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002360 */
2361 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002362 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002363 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002364
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002365 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002366
2367 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2368 if (sdata->u.mgd.powersave)
2369 smps_mode = IEEE80211_SMPS_DYNAMIC;
2370 else
2371 smps_mode = IEEE80211_SMPS_OFF;
2372 }
2373
2374 /* send SM PS frame to AP */
2375 err = ieee80211_send_smps_action(sdata, smps_mode,
2376 ap, ap);
2377 if (err)
2378 sdata->u.mgd.req_smps = old_req;
2379
2380 return err;
2381}
2382
Johannes Bergbc92afd2009-07-01 21:26:57 +02002383static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2384 bool enabled, int timeout)
2385{
2386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2387 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002388
Bob Copeland2d3db212013-10-29 18:11:59 -04002389 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002390 return -EOPNOTSUPP;
2391
Johannes Bergbc92afd2009-07-01 21:26:57 +02002392 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2393 return -EOPNOTSUPP;
2394
2395 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002396 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002397 return 0;
2398
2399 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002400 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002401
Johannes Berg0f782312009-12-01 13:37:02 +01002402 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002403 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002404 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002405 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002406
Johannes Bergbc92afd2009-07-01 21:26:57 +02002407 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2408 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2409
2410 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002411 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002412
2413 return 0;
2414}
2415
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002416static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2417 struct net_device *dev,
2418 s32 rssi_thold, u32 rssi_hyst)
2419{
2420 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002421 struct ieee80211_vif *vif = &sdata->vif;
2422 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2423
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002424 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2425 rssi_hyst == bss_conf->cqm_rssi_hyst)
2426 return 0;
2427
2428 bss_conf->cqm_rssi_thold = rssi_thold;
2429 bss_conf->cqm_rssi_hyst = rssi_hyst;
2430
2431 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002432 if (sdata->u.mgd.associated &&
2433 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002434 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2435
2436 return 0;
2437}
2438
Johannes Berg99303802009-07-01 21:26:59 +02002439static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2440 struct net_device *dev,
2441 const u8 *addr,
2442 const struct cfg80211_bitrate_mask *mask)
2443{
2444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2445 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302446 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002447
Eliad Peller554a43d2012-06-12 12:41:15 +03002448 if (!ieee80211_sdata_running(sdata))
2449 return -ENETDOWN;
2450
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302451 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2452 ret = drv_set_bitrate_mask(local, sdata, mask);
2453 if (ret)
2454 return ret;
2455 }
Johannes Berg99303802009-07-01 21:26:59 +02002456
Simon Wunderlich19468412012-01-28 17:25:33 +01002457 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002458 struct ieee80211_supported_band *sband = wiphy->bands[i];
2459 int j;
2460
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002461 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002462 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2463 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002464
2465 sdata->rc_has_mcs_mask[i] = false;
2466 if (!sband)
2467 continue;
2468
2469 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2470 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2471 sdata->rc_has_mcs_mask[i] = true;
2472 break;
2473 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002474 }
Johannes Berg99303802009-07-01 21:26:59 +02002475
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002476 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002477}
2478
Eliad Pellereaa336b2014-09-03 15:25:06 +03002479static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2480 struct ieee80211_roc_work *new_roc,
2481 struct ieee80211_roc_work *cur_roc)
2482{
2483 unsigned long j = jiffies;
2484 unsigned long cur_roc_end = cur_roc->hw_start_time +
2485 msecs_to_jiffies(cur_roc->duration);
2486 struct ieee80211_roc_work *next_roc;
2487 int new_dur;
2488
2489 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2490 return false;
2491
2492 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2493 return false;
2494
2495 ieee80211_handle_roc_started(new_roc);
2496
2497 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2498
2499 /* cur_roc is long enough - add new_roc to the dependents list. */
2500 if (new_dur <= 0) {
2501 list_add_tail(&new_roc->list, &cur_roc->dependents);
2502 return true;
2503 }
2504
2505 new_roc->duration = new_dur;
2506
2507 /*
2508 * if cur_roc was already coalesced before, we might
2509 * want to extend the next roc instead of adding
2510 * a new one.
2511 */
2512 next_roc = list_entry(cur_roc->list.next,
2513 struct ieee80211_roc_work, list);
2514 if (&next_roc->list != &local->roc_list &&
2515 next_roc->chan == new_roc->chan &&
2516 next_roc->sdata == new_roc->sdata &&
2517 !WARN_ON(next_roc->started)) {
2518 list_add_tail(&new_roc->list, &next_roc->dependents);
2519 next_roc->duration = max(next_roc->duration,
2520 new_roc->duration);
2521 next_roc->type = max(next_roc->type, new_roc->type);
2522 return true;
2523 }
2524
2525 /* add right after cur_roc */
2526 list_add(&new_roc->list, &cur_roc->list);
2527
2528 return true;
2529}
2530
Johannes Berg2eb278e2012-06-05 14:28:42 +02002531static int ieee80211_start_roc_work(struct ieee80211_local *local,
2532 struct ieee80211_sub_if_data *sdata,
2533 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002534 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002535 struct sk_buff *txskb,
2536 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002537{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002538 struct ieee80211_roc_work *roc, *tmp;
2539 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002540 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002541
2542 lockdep_assert_held(&local->mtx);
2543
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002544 if (local->use_chanctx && !local->ops->remain_on_channel)
2545 return -EOPNOTSUPP;
2546
Johannes Berg2eb278e2012-06-05 14:28:42 +02002547 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2548 if (!roc)
2549 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002550
Ilan Peer2fae0622013-12-19 13:25:29 +02002551 /*
2552 * If the duration is zero, then the driver
2553 * wouldn't actually do anything. Set it to
2554 * 10 for now.
2555 *
2556 * TODO: cancel the off-channel operation
2557 * when we get the SKB's TX status and
2558 * the wait time was zero before.
2559 */
2560 if (!duration)
2561 duration = 10;
2562
Johannes Berg2eb278e2012-06-05 14:28:42 +02002563 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002564 roc->duration = duration;
2565 roc->req_duration = duration;
2566 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002567 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002568 roc->mgmt_tx_cookie = (unsigned long)txskb;
2569 roc->sdata = sdata;
2570 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2571 INIT_LIST_HEAD(&roc->dependents);
2572
Eliad Peller2f617432014-01-12 11:06:37 +02002573 /*
2574 * cookie is either the roc cookie (for normal roc)
2575 * or the SKB (for mgmt TX)
2576 */
2577 if (!txskb) {
2578 /* local->mtx protects this */
2579 local->roc_cookie_counter++;
2580 roc->cookie = local->roc_cookie_counter;
2581 /* wow, you wrapped 64 bits ... more likely a bug */
2582 if (WARN_ON(roc->cookie == 0)) {
2583 roc->cookie = 1;
2584 local->roc_cookie_counter++;
2585 }
2586 *cookie = roc->cookie;
2587 } else {
2588 *cookie = (unsigned long)txskb;
2589 }
2590
Johannes Berg2eb278e2012-06-05 14:28:42 +02002591 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002592 if (!list_empty(&local->roc_list) ||
Eliad Peller5cbc95a2015-01-07 17:50:09 +02002593 local->scanning || ieee80211_is_radar_required(local))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002594 goto out_check_combine;
2595
2596 /* if not HW assist, just queue & schedule work */
2597 if (!local->ops->remain_on_channel) {
2598 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2599 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002600 }
2601
Johannes Berg2eb278e2012-06-05 14:28:42 +02002602 /* otherwise actually kick it off here (for error handling) */
2603
Ilan Peerd339d5c2013-02-12 09:34:13 +02002604 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002605 if (ret) {
2606 kfree(roc);
2607 return ret;
2608 }
2609
2610 roc->started = true;
2611 goto out_queue;
2612
2613 out_check_combine:
2614 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002615 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002616 continue;
2617
2618 /*
2619 * Extend this ROC if possible:
2620 *
2621 * If it hasn't started yet, just increase the duration
2622 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002623 * If the type of the new ROC has higher priority, modify the
2624 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002625 */
2626 if (!tmp->started) {
2627 list_add_tail(&roc->list, &tmp->dependents);
2628 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002629 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002630 queued = true;
2631 break;
2632 }
2633
2634 /* If it has already started, it's more difficult ... */
2635 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002636 /*
2637 * In the offloaded ROC case, if it hasn't begun, add
2638 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002639 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002640 * check that there's still a minimum time left and
2641 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002642 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002643 * a reduced time so we'll ask the driver to execute
2644 * it right after finishing the previous one, in the
2645 * hope that it'll also be executed right afterwards,
2646 * effectively extending the old one.
2647 * If there's no minimum time left, just add it to the
2648 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002649 * TODO: the ROC type is ignored here, assuming that it
2650 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002651 */
2652 if (!tmp->hw_begun) {
2653 list_add_tail(&roc->list, &tmp->dependents);
2654 queued = true;
2655 break;
2656 }
2657
Eliad Pellereaa336b2014-09-03 15:25:06 +03002658 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002659 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002660 } else if (del_timer_sync(&tmp->work.timer)) {
2661 unsigned long new_end;
2662
2663 /*
2664 * In the software ROC case, cancel the timer, if
2665 * that fails then the finish work is already
2666 * queued/pending and thus we queue the new ROC
2667 * normally, if that succeeds then we can extend
2668 * the timer duration and TX the frame (if any.)
2669 */
2670
2671 list_add_tail(&roc->list, &tmp->dependents);
2672 queued = true;
2673
2674 new_end = jiffies + msecs_to_jiffies(roc->duration);
2675
2676 /* ok, it was started & we canceled timer */
2677 if (time_after(new_end, tmp->work.timer.expires))
2678 mod_timer(&tmp->work.timer, new_end);
2679 else
2680 add_timer(&tmp->work.timer);
2681
2682 ieee80211_handle_roc_started(roc);
2683 }
2684 break;
2685 }
2686
2687 out_queue:
2688 if (!queued)
2689 list_add_tail(&roc->list, &local->roc_list);
2690
Johannes Berg2eb278e2012-06-05 14:28:42 +02002691 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002692}
2693
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002694static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002695 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002696 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002697 unsigned int duration,
2698 u64 *cookie)
2699{
Johannes Berg71bbc992012-06-15 15:30:18 +02002700 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002701 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002702 int ret;
2703
Johannes Berg2eb278e2012-06-05 14:28:42 +02002704 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002705 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002706 duration, cookie, NULL,
2707 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002708 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002709
Johannes Berg2eb278e2012-06-05 14:28:42 +02002710 return ret;
2711}
2712
2713static int ieee80211_cancel_roc(struct ieee80211_local *local,
2714 u64 cookie, bool mgmt_tx)
2715{
2716 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2717 int ret;
2718
2719 mutex_lock(&local->mtx);
2720 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002721 struct ieee80211_roc_work *dep, *tmp2;
2722
2723 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002724 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002725 continue;
2726 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2727 continue;
2728 /* found dependent item -- just remove it */
2729 list_del(&dep->list);
2730 mutex_unlock(&local->mtx);
2731
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002732 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002733 return 0;
2734 }
2735
Johannes Berg50febf62012-10-26 16:13:06 +02002736 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002737 continue;
2738 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2739 continue;
2740
2741 found = roc;
2742 break;
2743 }
2744
2745 if (!found) {
2746 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002747 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002748 }
Johannes Berg21f83582010-12-18 17:20:47 +01002749
Johannes Berge979e332012-06-11 17:09:41 +02002750 /*
2751 * We found the item to cancel, so do that. Note that it
2752 * may have dependents, which we also cancel (and send
2753 * the expired signal for.) Not doing so would be quite
2754 * tricky here, but we may need to fix it later.
2755 */
2756
Johannes Berg2eb278e2012-06-05 14:28:42 +02002757 if (local->ops->remain_on_channel) {
2758 if (found->started) {
2759 ret = drv_cancel_remain_on_channel(local);
2760 if (WARN_ON_ONCE(ret)) {
2761 mutex_unlock(&local->mtx);
2762 return ret;
2763 }
2764 }
Johannes Berg21f83582010-12-18 17:20:47 +01002765
Johannes Berg2eb278e2012-06-05 14:28:42 +02002766 list_del(&found->list);
2767
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002768 if (found->started)
2769 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002770 mutex_unlock(&local->mtx);
2771
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002772 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002773 } else {
2774 /* work may be pending so use it all the time */
2775 found->abort = true;
2776 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2777
2778 mutex_unlock(&local->mtx);
2779
2780 /* work will clean up etc */
2781 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002782 WARN_ON(!found->to_be_freed);
2783 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002784 }
Johannes Berg21f83582010-12-18 17:20:47 +01002785
Johannes Berg21f83582010-12-18 17:20:47 +01002786 return 0;
2787}
2788
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002789static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002790 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002791 u64 cookie)
2792{
Johannes Berg71bbc992012-06-15 15:30:18 +02002793 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002794 struct ieee80211_local *local = sdata->local;
2795
Johannes Berg2eb278e2012-06-05 14:28:42 +02002796 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002797}
2798
Simon Wunderlich164eb022013-02-08 18:16:20 +01002799static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2800 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002801 struct cfg80211_chan_def *chandef,
2802 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002803{
2804 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2805 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002806 int err;
2807
Johannes Berg34a37402013-12-18 09:43:33 +01002808 mutex_lock(&local->mtx);
2809 if (!list_empty(&local->roc_list) || local->scanning) {
2810 err = -EBUSY;
2811 goto out_unlock;
2812 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002813
2814 /* whatever, but channel contexts should not complain about that one */
2815 sdata->smps_mode = IEEE80211_SMPS_OFF;
2816 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002817
Simon Wunderlich164eb022013-02-08 18:16:20 +01002818 err = ieee80211_vif_use_channel(sdata, chandef,
2819 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002820 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002821 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002822
Simon Wunderlich164eb022013-02-08 18:16:20 +01002823 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002824 &sdata->dfs_cac_timer_work,
2825 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002826
Johannes Berg34a37402013-12-18 09:43:33 +01002827 out_unlock:
2828 mutex_unlock(&local->mtx);
2829 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002830}
2831
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002832static struct cfg80211_beacon_data *
2833cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2834{
2835 struct cfg80211_beacon_data *new_beacon;
2836 u8 *pos;
2837 int len;
2838
2839 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2840 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2841 beacon->probe_resp_len;
2842
2843 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2844 if (!new_beacon)
2845 return NULL;
2846
2847 pos = (u8 *)(new_beacon + 1);
2848 if (beacon->head_len) {
2849 new_beacon->head_len = beacon->head_len;
2850 new_beacon->head = pos;
2851 memcpy(pos, beacon->head, beacon->head_len);
2852 pos += beacon->head_len;
2853 }
2854 if (beacon->tail_len) {
2855 new_beacon->tail_len = beacon->tail_len;
2856 new_beacon->tail = pos;
2857 memcpy(pos, beacon->tail, beacon->tail_len);
2858 pos += beacon->tail_len;
2859 }
2860 if (beacon->beacon_ies_len) {
2861 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2862 new_beacon->beacon_ies = pos;
2863 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2864 pos += beacon->beacon_ies_len;
2865 }
2866 if (beacon->proberesp_ies_len) {
2867 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2868 new_beacon->proberesp_ies = pos;
2869 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2870 pos += beacon->proberesp_ies_len;
2871 }
2872 if (beacon->assocresp_ies_len) {
2873 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2874 new_beacon->assocresp_ies = pos;
2875 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2876 pos += beacon->assocresp_ies_len;
2877 }
2878 if (beacon->probe_resp_len) {
2879 new_beacon->probe_resp_len = beacon->probe_resp_len;
2880 beacon->probe_resp = pos;
2881 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2882 pos += beacon->probe_resp_len;
2883 }
2884
2885 return new_beacon;
2886}
2887
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002888void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002889{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002890 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2891
2892 ieee80211_queue_work(&sdata->local->hw,
2893 &sdata->csa_finalize_work);
2894}
2895EXPORT_SYMBOL(ieee80211_csa_finish);
2896
Michal Kazior66199502014-04-09 15:11:00 +02002897static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2898 u32 *changed)
2899{
2900 int err;
2901
2902 switch (sdata->vif.type) {
2903 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002904 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2905 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002906 kfree(sdata->u.ap.next_beacon);
2907 sdata->u.ap.next_beacon = NULL;
2908
2909 if (err < 0)
2910 return err;
2911 *changed |= err;
2912 break;
2913 case NL80211_IFTYPE_ADHOC:
2914 err = ieee80211_ibss_finish_csa(sdata);
2915 if (err < 0)
2916 return err;
2917 *changed |= err;
2918 break;
2919#ifdef CONFIG_MAC80211_MESH
2920 case NL80211_IFTYPE_MESH_POINT:
2921 err = ieee80211_mesh_finish_csa(sdata);
2922 if (err < 0)
2923 return err;
2924 *changed |= err;
2925 break;
2926#endif
2927 default:
2928 WARN_ON(1);
2929 return -EINVAL;
2930 }
2931
2932 return 0;
2933}
2934
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002935static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002936{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002937 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002938 u32 changed = 0;
2939 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002940
Michal Kaziordbd72852014-01-29 07:56:21 +01002941 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002942 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002943 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002944
Michal Kazior03078de2014-06-25 12:35:08 +02002945 /*
2946 * using reservation isn't immediate as it may be deferred until later
2947 * with multi-vif. once reservation is complete it will re-schedule the
2948 * work with no reserved_chanctx so verify chandef to check if it
2949 * completed successfully
2950 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002951
Michal Kazior03078de2014-06-25 12:35:08 +02002952 if (sdata->reserved_chanctx) {
2953 /*
2954 * with multi-vif csa driver may call ieee80211_csa_finish()
2955 * many times while waiting for other interfaces to use their
2956 * reservations
2957 */
2958 if (sdata->reserved_ready)
2959 return 0;
2960
Fabian Frederick408b18a2014-10-09 20:36:22 +02002961 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002962 }
2963
Michal Kazior03078de2014-06-25 12:35:08 +02002964 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2965 &sdata->csa_chandef))
2966 return -EINVAL;
2967
Simon Wunderliche487eae2013-11-21 18:19:51 +01002968 sdata->vif.csa_active = false;
Michal Kazior97518af12014-01-29 07:56:18 +01002969
Michal Kazior66199502014-04-09 15:11:00 +02002970 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2971 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002972 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002973
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002974 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002975
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002976 if (sdata->csa_block_tx) {
2977 ieee80211_wake_vif_queues(local, sdata,
2978 IEEE80211_QUEUE_STOP_REASON_CSA);
2979 sdata->csa_block_tx = false;
2980 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002981
Luciano Coelhof1d65582014-10-08 09:48:38 +03002982 err = drv_post_channel_switch(sdata);
2983 if (err)
2984 return err;
2985
2986 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2987
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002988 return 0;
2989}
2990
2991static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2992{
2993 if (__ieee80211_csa_finalize(sdata)) {
2994 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2995 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2996 GFP_KERNEL);
2997 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002998}
2999
3000void ieee80211_csa_finalize_work(struct work_struct *work)
3001{
3002 struct ieee80211_sub_if_data *sdata =
3003 container_of(work, struct ieee80211_sub_if_data,
3004 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02003005 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003006
3007 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003008 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02003009 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003010
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003011 /* AP might have been stopped while waiting for the lock. */
3012 if (!sdata->vif.csa_active)
3013 goto unlock;
3014
3015 if (!ieee80211_sdata_running(sdata))
3016 goto unlock;
3017
3018 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003019
3020unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02003021 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02003022 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003023 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003024}
3025
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003026static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3027 struct cfg80211_csa_settings *params,
3028 u32 *changed)
3029{
Michal Kazioraf296bd2014-06-05 14:21:36 +02003030 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003031 int err;
3032
3033 switch (sdata->vif.type) {
3034 case NL80211_IFTYPE_AP:
3035 sdata->u.ap.next_beacon =
3036 cfg80211_beacon_dup(&params->beacon_after);
3037 if (!sdata->u.ap.next_beacon)
3038 return -ENOMEM;
3039
3040 /*
3041 * With a count of 0, we don't have to wait for any
3042 * TBTT before switching, so complete the CSA
3043 * immediately. In theory, with a count == 1 we
3044 * should delay the switch until just before the next
3045 * TBTT, but that would complicate things so we switch
3046 * immediately too. If we would delay the switch
3047 * until the next TBTT, we would have to set the probe
3048 * response here.
3049 *
3050 * TODO: A channel switch with count <= 1 without
3051 * sending a CSA action frame is kind of useless,
3052 * because the clients won't know we're changing
3053 * channels. The action frame must be implemented
3054 * either here or in the userspace.
3055 */
3056 if (params->count <= 1)
3057 break;
3058
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003059 if ((params->n_counter_offsets_beacon >
3060 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3061 (params->n_counter_offsets_presp >
3062 IEEE80211_MAX_CSA_COUNTERS_NUM))
3063 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003064
Michal Kazioraf296bd2014-06-05 14:21:36 +02003065 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3066 csa.counter_offsets_presp = params->counter_offsets_presp;
3067 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3068 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3069 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003070
Michal Kazioraf296bd2014-06-05 14:21:36 +02003071 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003072 if (err < 0) {
3073 kfree(sdata->u.ap.next_beacon);
3074 return err;
3075 }
3076 *changed |= err;
3077
3078 break;
3079 case NL80211_IFTYPE_ADHOC:
3080 if (!sdata->vif.bss_conf.ibss_joined)
3081 return -EINVAL;
3082
3083 if (params->chandef.width != sdata->u.ibss.chandef.width)
3084 return -EINVAL;
3085
3086 switch (params->chandef.width) {
3087 case NL80211_CHAN_WIDTH_40:
3088 if (cfg80211_get_chandef_type(&params->chandef) !=
3089 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3090 return -EINVAL;
3091 case NL80211_CHAN_WIDTH_5:
3092 case NL80211_CHAN_WIDTH_10:
3093 case NL80211_CHAN_WIDTH_20_NOHT:
3094 case NL80211_CHAN_WIDTH_20:
3095 break;
3096 default:
3097 return -EINVAL;
3098 }
3099
3100 /* changes into another band are not supported */
3101 if (sdata->u.ibss.chandef.chan->band !=
3102 params->chandef.chan->band)
3103 return -EINVAL;
3104
3105 /* see comments in the NL80211_IFTYPE_AP block */
3106 if (params->count > 1) {
3107 err = ieee80211_ibss_csa_beacon(sdata, params);
3108 if (err < 0)
3109 return err;
3110 *changed |= err;
3111 }
3112
3113 ieee80211_send_action_csa(sdata, params);
3114
3115 break;
3116#ifdef CONFIG_MAC80211_MESH
3117 case NL80211_IFTYPE_MESH_POINT: {
3118 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3119
3120 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3121 return -EINVAL;
3122
3123 /* changes into another band are not supported */
3124 if (sdata->vif.bss_conf.chandef.chan->band !=
3125 params->chandef.chan->band)
3126 return -EINVAL;
3127
3128 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3129 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3130 if (!ifmsh->pre_value)
3131 ifmsh->pre_value = 1;
3132 else
3133 ifmsh->pre_value++;
3134 }
3135
3136 /* see comments in the NL80211_IFTYPE_AP block */
3137 if (params->count > 1) {
3138 err = ieee80211_mesh_csa_beacon(sdata, params);
3139 if (err < 0) {
3140 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3141 return err;
3142 }
3143 *changed |= err;
3144 }
3145
3146 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3147 ieee80211_send_action_csa(sdata, params);
3148
3149 break;
3150 }
3151#endif
3152 default:
3153 return -EOPNOTSUPP;
3154 }
3155
3156 return 0;
3157}
3158
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003159static int
3160__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3161 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003162{
3163 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3164 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003165 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003166 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003167 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003168 u32 changed = 0;
3169 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003170
Michal Kaziordbd72852014-01-29 07:56:21 +01003171 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003172 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003173
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003174 if (!list_empty(&local->roc_list) || local->scanning)
3175 return -EBUSY;
3176
3177 if (sdata->wdev.cac_started)
3178 return -EBUSY;
3179
3180 if (cfg80211_chandef_identical(&params->chandef,
3181 &sdata->vif.bss_conf.chandef))
3182 return -EINVAL;
3183
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003184 /* don't allow another channel switch if one is already active. */
3185 if (sdata->vif.csa_active)
3186 return -EBUSY;
3187
Michal Kazior03078de2014-06-25 12:35:08 +02003188 mutex_lock(&local->chanctx_mtx);
3189 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3190 lockdep_is_held(&local->chanctx_mtx));
3191 if (!conf) {
3192 err = -EBUSY;
3193 goto out;
3194 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003195
Michal Kazior03078de2014-06-25 12:35:08 +02003196 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3197 if (!chanctx) {
3198 err = -EBUSY;
3199 goto out;
3200 }
3201
Luciano Coelho000baa52014-11-07 15:28:33 +02003202 ch_switch.timestamp = 0;
3203 ch_switch.device_timestamp = 0;
3204 ch_switch.block_tx = params->block_tx;
3205 ch_switch.chandef = params->chandef;
3206 ch_switch.count = params->count;
3207
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003208 err = drv_pre_channel_switch(sdata, &ch_switch);
3209 if (err)
3210 goto out;
3211
Michal Kazior03078de2014-06-25 12:35:08 +02003212 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3213 chanctx->mode,
3214 params->radar_required);
3215 if (err)
3216 goto out;
3217
3218 /* if reservation is invalid then this will fail */
3219 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3220 if (err) {
3221 ieee80211_vif_unreserve_chanctx(sdata);
3222 goto out;
3223 }
3224
3225 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3226 if (err) {
3227 ieee80211_vif_unreserve_chanctx(sdata);
3228 goto out;
3229 }
3230
Luciano Coelho33787fc2013-11-11 20:34:54 +02003231 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003232 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003233 sdata->vif.csa_active = true;
3234
Michal Kazior59af6922014-04-09 15:10:59 +02003235 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003236 ieee80211_stop_vif_queues(local, sdata,
3237 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003238
Luciano Coelho2f457292014-11-07 14:31:36 +02003239 cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef,
3240 params->count);
3241
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003242 if (changed) {
3243 ieee80211_bss_info_change_notify(sdata, changed);
3244 drv_channel_switch_beacon(sdata, &params->chandef);
3245 } else {
3246 /* if the beacon didn't change, we can finalize immediately */
3247 ieee80211_csa_finalize(sdata);
3248 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003249
Michal Kazior03078de2014-06-25 12:35:08 +02003250out:
3251 mutex_unlock(&local->chanctx_mtx);
3252 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003253}
3254
Michal Kazior59af6922014-04-09 15:10:59 +02003255int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3256 struct cfg80211_csa_settings *params)
3257{
3258 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3259 struct ieee80211_local *local = sdata->local;
3260 int err;
3261
3262 mutex_lock(&local->mtx);
3263 err = __ieee80211_channel_switch(wiphy, dev, params);
3264 mutex_unlock(&local->mtx);
3265
3266 return err;
3267}
3268
Johannes Berg71bbc992012-06-15 15:30:18 +02003269static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003270 struct cfg80211_mgmt_tx_params *params,
3271 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003272{
Johannes Berg71bbc992012-06-15 15:30:18 +02003273 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003274 struct ieee80211_local *local = sdata->local;
3275 struct sk_buff *skb;
3276 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003277 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003278 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003279 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003280 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003281 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003282
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003283 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003284 flags = IEEE80211_TX_CTL_NO_ACK;
3285 else
3286 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3287 IEEE80211_TX_CTL_REQ_TX_STATUS;
3288
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003289 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303290 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3291
Johannes Berg9d38d852010-06-09 17:20:33 +02003292 switch (sdata->vif.type) {
3293 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003294 if (!sdata->vif.bss_conf.ibss_joined)
3295 need_offchan = true;
3296 /* fall through */
3297#ifdef CONFIG_MAC80211_MESH
3298 case NL80211_IFTYPE_MESH_POINT:
3299 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3300 !sdata->u.mesh.mesh_id_len)
3301 need_offchan = true;
3302 /* fall through */
3303#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003304 case NL80211_IFTYPE_AP:
3305 case NL80211_IFTYPE_AP_VLAN:
3306 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003307 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3308 !ieee80211_vif_is_mesh(&sdata->vif) &&
3309 !rcu_access_pointer(sdata->bss->beacon))
3310 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003311 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003312 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003313 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3314 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003315 break;
3316 rcu_read_lock();
3317 sta = sta_info_get(sdata, mgmt->da);
3318 rcu_read_unlock();
3319 if (!sta)
3320 return -ENOLINK;
3321 break;
3322 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003323 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003324 if (!sdata->u.mgd.associated)
3325 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003326 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003327 case NL80211_IFTYPE_P2P_DEVICE:
3328 need_offchan = true;
3329 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003330 default:
3331 return -EOPNOTSUPP;
3332 }
3333
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003334 /* configurations requiring offchan cannot work if no channel has been
3335 * specified
3336 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003337 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003338 return -EINVAL;
3339
Johannes Berg2eb278e2012-06-05 14:28:42 +02003340 mutex_lock(&local->mtx);
3341
3342 /* Check if the operating channel is the requested channel */
3343 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003344 struct ieee80211_chanctx_conf *chanctx_conf;
3345
3346 rcu_read_lock();
3347 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3348
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003349 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003350 need_offchan = params->chan &&
3351 (params->chan !=
3352 chanctx_conf->def.chan);
3353 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003354 ret = -EINVAL;
3355 rcu_read_unlock();
3356 goto out_unlock;
3357 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003358 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003359 }
Johannes Berg55de9082012-07-26 17:24:39 +02003360 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003361 }
3362
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003363 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003364 ret = -EBUSY;
3365 goto out_unlock;
3366 }
3367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003368 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003369 if (!skb) {
3370 ret = -ENOMEM;
3371 goto out_unlock;
3372 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003373 skb_reserve(skb, local->hw.extra_tx_headroom);
3374
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003375 data = skb_put(skb, params->len);
3376 memcpy(data, params->buf, params->len);
3377
3378 /* Update CSA counters */
3379 if (sdata->vif.csa_active &&
3380 (sdata->vif.type == NL80211_IFTYPE_AP ||
3381 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3382 params->n_csa_offsets) {
3383 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003384 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003385
Michal Kazioraf296bd2014-06-05 14:21:36 +02003386 rcu_read_lock();
3387
3388 if (sdata->vif.type == NL80211_IFTYPE_AP)
3389 beacon = rcu_dereference(sdata->u.ap.beacon);
3390 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3391 beacon = rcu_dereference(sdata->u.ibss.presp);
3392 else if (ieee80211_vif_is_mesh(&sdata->vif))
3393 beacon = rcu_dereference(sdata->u.mesh.beacon);
3394
3395 if (beacon)
3396 for (i = 0; i < params->n_csa_offsets; i++)
3397 data[params->csa_offsets[i]] =
3398 beacon->csa_current_counter;
3399
3400 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003401 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003402
3403 IEEE80211_SKB_CB(skb)->flags = flags;
3404
Johannes Berg2eb278e2012-06-05 14:28:42 +02003405 skb->dev = sdata->dev;
3406
3407 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003408 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003409 ieee80211_tx_skb(sdata, skb);
3410 ret = 0;
3411 goto out_unlock;
3412 }
3413
Seth Forshee6c17b772013-02-11 11:21:07 -06003414 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3415 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003416 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003417 IEEE80211_SKB_CB(skb)->hw_queue =
3418 local->hw.offchannel_tx_hw_queue;
3419
Johannes Berg2eb278e2012-06-05 14:28:42 +02003420 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003421 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3422 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003423 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003424 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003425 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003426 out_unlock:
3427 mutex_unlock(&local->mtx);
3428 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003429}
3430
Johannes Bergf30221e2010-11-25 10:02:30 +01003431static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003432 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003433 u64 cookie)
3434{
Johannes Berg71bbc992012-06-15 15:30:18 +02003435 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003436
Johannes Berg2eb278e2012-06-05 14:28:42 +02003437 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003438}
3439
Johannes Berg7be50862010-10-13 12:06:24 +02003440static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003441 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003442 u16 frame_type, bool reg)
3443{
3444 struct ieee80211_local *local = wiphy_priv(wiphy);
3445
Will Hawkins6abe0562012-06-20 11:51:14 -04003446 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003447 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3448 if (reg)
3449 local->probe_req_reg++;
3450 else
3451 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003452
Felix Fietkau35f51492012-10-31 15:50:34 +01003453 if (!local->open_count)
3454 break;
3455
Will Hawkins6abe0562012-06-20 11:51:14 -04003456 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3457 break;
3458 default:
3459 break;
3460 }
Johannes Berg7be50862010-10-13 12:06:24 +02003461}
3462
Bruno Randolf15d96752010-11-10 12:50:56 +09003463static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3464{
3465 struct ieee80211_local *local = wiphy_priv(wiphy);
3466
3467 if (local->started)
3468 return -EOPNOTSUPP;
3469
3470 return drv_set_antenna(local, tx_ant, rx_ant);
3471}
3472
3473static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3474{
3475 struct ieee80211_local *local = wiphy_priv(wiphy);
3476
3477 return drv_get_antenna(local, tx_ant, rx_ant);
3478}
3479
Johannes Bergc68f4b82011-07-05 16:35:41 +02003480static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3481 struct net_device *dev,
3482 struct cfg80211_gtk_rekey_data *data)
3483{
3484 struct ieee80211_local *local = wiphy_priv(wiphy);
3485 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3486
3487 if (!local->ops->set_rekey_data)
3488 return -EOPNOTSUPP;
3489
3490 drv_set_rekey_data(local, sdata, data);
3491
3492 return 0;
3493}
3494
Johannes Berg06500732011-11-04 11:18:16 +01003495static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3496 const u8 *peer, u64 *cookie)
3497{
3498 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3499 struct ieee80211_local *local = sdata->local;
3500 struct ieee80211_qos_hdr *nullfunc;
3501 struct sk_buff *skb;
3502 int size = sizeof(*nullfunc);
3503 __le16 fc;
3504 bool qos;
3505 struct ieee80211_tx_info *info;
3506 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003507 struct ieee80211_chanctx_conf *chanctx_conf;
3508 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003509
3510 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003511 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3512 if (WARN_ON(!chanctx_conf)) {
3513 rcu_read_unlock();
3514 return -EINVAL;
3515 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003516 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003517 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003518 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003519 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003520 } else {
3521 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003522 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003523 }
Johannes Berg06500732011-11-04 11:18:16 +01003524
3525 if (qos) {
3526 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3527 IEEE80211_STYPE_QOS_NULLFUNC |
3528 IEEE80211_FCTL_FROMDS);
3529 } else {
3530 size -= 2;
3531 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3532 IEEE80211_STYPE_NULLFUNC |
3533 IEEE80211_FCTL_FROMDS);
3534 }
3535
3536 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003537 if (!skb) {
3538 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003539 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003540 }
Johannes Berg06500732011-11-04 11:18:16 +01003541
3542 skb->dev = dev;
3543
3544 skb_reserve(skb, local->hw.extra_tx_headroom);
3545
3546 nullfunc = (void *) skb_put(skb, size);
3547 nullfunc->frame_control = fc;
3548 nullfunc->duration_id = 0;
3549 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3550 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3551 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3552 nullfunc->seq_ctrl = 0;
3553
3554 info = IEEE80211_SKB_CB(skb);
3555
3556 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3557 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
Johannes Berg73c4e192014-11-09 18:50:09 +02003558 info->band = band;
Johannes Berg06500732011-11-04 11:18:16 +01003559
3560 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3561 skb->priority = 7;
3562 if (qos)
3563 nullfunc->qos_ctrl = cpu_to_le16(7);
3564
3565 local_bh_disable();
Johannes Berg73c4e192014-11-09 18:50:09 +02003566 ieee80211_xmit(sdata, skb);
Johannes Berg06500732011-11-04 11:18:16 +01003567 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003568 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003569
3570 *cookie = (unsigned long) skb;
3571 return 0;
3572}
3573
Johannes Berg683b6d32012-11-08 21:25:48 +01003574static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3575 struct wireless_dev *wdev,
3576 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003577{
Johannes Berg55de9082012-07-26 17:24:39 +02003578 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003579 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003580 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003581 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003582
Johannes Berg55de9082012-07-26 17:24:39 +02003583 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003584 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3585 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003586 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003587 ret = 0;
3588 } else if (local->open_count > 0 &&
3589 local->open_count == local->monitors &&
3590 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3591 if (local->use_chanctx)
3592 *chandef = local->monitor_chandef;
3593 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003594 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003595 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003596 }
3597 rcu_read_unlock();
3598
Johannes Berg683b6d32012-11-08 21:25:48 +01003599 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003600}
3601
Johannes Berg6d525632012-04-04 15:05:25 +02003602#ifdef CONFIG_PM
3603static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3604{
3605 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3606}
3607#endif
3608
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003609static int ieee80211_set_qos_map(struct wiphy *wiphy,
3610 struct net_device *dev,
3611 struct cfg80211_qos_map *qos_map)
3612{
3613 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3614 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3615
3616 if (qos_map) {
3617 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3618 if (!new_qos_map)
3619 return -ENOMEM;
3620 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3621 } else {
3622 /* A NULL qos_map was passed to disable QoS mapping */
3623 new_qos_map = NULL;
3624 }
3625
Johannes Berg194ff522013-12-30 23:12:37 +01003626 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003627 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3628 if (old_qos_map)
3629 kfree_rcu(old_qos_map, rcu_head);
3630
3631 return 0;
3632}
3633
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003634static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3635 struct net_device *dev,
3636 struct cfg80211_chan_def *chandef)
3637{
3638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3639 int ret;
3640 u32 changed = 0;
3641
3642 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3643 if (ret == 0)
3644 ieee80211_bss_info_change_notify(sdata, changed);
3645
3646 return ret;
3647}
3648
Johannes Berg02219b32014-10-07 10:38:50 +03003649static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3650 u8 tsid, const u8 *peer, u8 up,
3651 u16 admitted_time)
3652{
3653 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3654 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3655 int ac = ieee802_1d_to_ac[up];
3656
3657 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3658 return -EOPNOTSUPP;
3659
3660 if (!(sdata->wmm_acm & BIT(up)))
3661 return -EINVAL;
3662
3663 if (ifmgd->tx_tspec[ac].admitted_time)
3664 return -EBUSY;
3665
3666 if (admitted_time) {
3667 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3668 ifmgd->tx_tspec[ac].tsid = tsid;
3669 ifmgd->tx_tspec[ac].up = up;
3670 }
3671
3672 return 0;
3673}
3674
3675static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3676 u8 tsid, const u8 *peer)
3677{
3678 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3679 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3680 struct ieee80211_local *local = wiphy_priv(wiphy);
3681 int ac;
3682
3683 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3684 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3685
3686 /* skip unused entries */
3687 if (!tx_tspec->admitted_time)
3688 continue;
3689
3690 if (tx_tspec->tsid != tsid)
3691 continue;
3692
3693 /* due to this new packets will be reassigned to non-ACM ACs */
3694 tx_tspec->up = -1;
3695
3696 /* Make sure that all packets have been sent to avoid to
3697 * restore the QoS params on packets that are still on the
3698 * queues.
3699 */
3700 synchronize_net();
Emmanuel Grumbach3b24f4c2015-01-07 15:42:39 +02003701 ieee80211_flush_queues(local, sdata, false);
Johannes Berg02219b32014-10-07 10:38:50 +03003702
3703 /* restore the normal QoS parameters
3704 * (unconditionally to avoid races)
3705 */
3706 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3707 tx_tspec->downgraded = false;
3708 ieee80211_sta_handle_tspec_ac_params(sdata);
3709
3710 /* finally clear all the data */
3711 memset(tx_tspec, 0, sizeof(*tx_tspec));
3712
3713 return 0;
3714 }
3715
3716 return -ENOENT;
3717}
3718
Johannes Berg8a47cea2014-01-20 23:55:44 +01003719const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003720 .add_virtual_intf = ieee80211_add_iface,
3721 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003722 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003723 .start_p2p_device = ieee80211_start_p2p_device,
3724 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003725 .add_key = ieee80211_add_key,
3726 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003727 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003728 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003729 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003730 .start_ap = ieee80211_start_ap,
3731 .change_beacon = ieee80211_change_beacon,
3732 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003733 .add_station = ieee80211_add_station,
3734 .del_station = ieee80211_del_station,
3735 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003736 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003737 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003738 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003739#ifdef CONFIG_MAC80211_MESH
3740 .add_mpath = ieee80211_add_mpath,
3741 .del_mpath = ieee80211_del_mpath,
3742 .change_mpath = ieee80211_change_mpath,
3743 .get_mpath = ieee80211_get_mpath,
3744 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003745 .get_mpp = ieee80211_get_mpp,
3746 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003747 .update_mesh_config = ieee80211_update_mesh_config,
3748 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003749 .join_mesh = ieee80211_join_mesh,
3750 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003751#endif
Rostislav Lisovy239281f2014-11-03 10:33:19 +01003752 .join_ocb = ieee80211_join_ocb,
3753 .leave_ocb = ieee80211_leave_ocb,
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003754 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003755 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003756 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003757 .suspend = ieee80211_suspend,
3758 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003759 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003760 .sched_scan_start = ieee80211_sched_scan_start,
3761 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003762 .auth = ieee80211_auth,
3763 .assoc = ieee80211_assoc,
3764 .deauth = ieee80211_deauth,
3765 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003766 .join_ibss = ieee80211_join_ibss,
3767 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003768 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003769 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003770 .set_tx_power = ieee80211_set_tx_power,
3771 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003772 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003773 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003774 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003775 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003776 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003777 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003778 .remain_on_channel = ieee80211_remain_on_channel,
3779 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02003780 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003781 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003782 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003783 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003784 .set_antenna = ieee80211_set_antenna,
3785 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003786 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003787 .tdls_oper = ieee80211_tdls_oper,
3788 .tdls_mgmt = ieee80211_tdls_mgmt,
Arik Nemtsova7a6bdd2014-11-09 18:50:19 +02003789 .tdls_channel_switch = ieee80211_tdls_channel_switch,
3790 .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch,
Johannes Berg06500732011-11-04 11:18:16 +01003791 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003792 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003793#ifdef CONFIG_PM
3794 .set_wakeup = ieee80211_set_wakeup,
3795#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003796 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003797 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003798 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003799 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003800 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003801 .add_tx_ts = ieee80211_add_tx_ts,
3802 .del_tx_ts = ieee80211_del_tx_ts,
Jiri Bencf0706e82007-05-05 11:45:53 -07003803};